Prepare new settings
This commit is contained in:
parent
f2abcc44c5
commit
f5409b9e69
|
@ -14,40 +14,30 @@
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
package app.fedilab.android.activities;
|
package app.fedilab.android.activities;
|
||||||
|
|
||||||
import android.animation.Animator;
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewAnimationUtils;
|
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.animation.AccelerateInterpolator;
|
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.drawerlayout.widget.DrawerLayout;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||||
|
import androidx.viewpager.widget.PagerAdapter;
|
||||||
|
import androidx.viewpager.widget.ViewPager;
|
||||||
|
|
||||||
|
import com.google.android.material.tabs.TabLayout;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import app.fedilab.android.R;
|
import app.fedilab.android.R;
|
||||||
import app.fedilab.android.animatemenu.interfaces.Resourceble;
|
|
||||||
import app.fedilab.android.animatemenu.interfaces.ScreenShotable;
|
|
||||||
import app.fedilab.android.animatemenu.model.SlideMenuItem;
|
|
||||||
import app.fedilab.android.animatemenu.util.ViewAnimator;
|
|
||||||
import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
|
|
||||||
import app.fedilab.android.fragments.ContentSettingsFragment;
|
import app.fedilab.android.fragments.ContentSettingsFragment;
|
||||||
import app.fedilab.android.helper.Helper;
|
import app.fedilab.android.helper.Helper;
|
||||||
|
|
||||||
|
@ -56,16 +46,8 @@ import app.fedilab.android.helper.Helper;
|
||||||
* Settings activity
|
* Settings activity
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class SettingsActivity extends BaseActivity implements ViewAnimator.ViewAnimatorListener {
|
public class SettingsActivity extends BaseActivity {
|
||||||
|
|
||||||
private int res = R.drawable.ic_timeline_menu_s;
|
|
||||||
private LinearLayout linearLayout;
|
|
||||||
private ViewAnimator viewAnimator;
|
|
||||||
private DrawerLayout drawerLayout;
|
|
||||||
private ActionBarDrawerToggle drawerToggle;
|
|
||||||
private List<SlideMenuItem> list = new ArrayList<>();
|
|
||||||
public static int position = 1;
|
|
||||||
private ContentSettingsFragment.type previous;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -74,18 +56,17 @@ public class SettingsActivity extends BaseActivity implements ViewAnimator.ViewA
|
||||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||||
switch (theme) {
|
switch (theme) {
|
||||||
case Helper.THEME_LIGHT:
|
case Helper.THEME_LIGHT:
|
||||||
setTheme(R.style.AppTheme_NoActionBar_Fedilab);
|
setTheme(R.style.AppTheme);
|
||||||
break;
|
break;
|
||||||
case Helper.THEME_DARK:
|
case Helper.THEME_DARK:
|
||||||
setTheme(R.style.AppThemeDark_NoActionBar);
|
setTheme(R.style.AppThemeDark);
|
||||||
break;
|
break;
|
||||||
case Helper.THEME_BLACK:
|
case Helper.THEME_BLACK:
|
||||||
setTheme(R.style.AppThemeBlack_NoActionBar);
|
setTheme(R.style.AppThemeBlack);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
setTheme(R.style.AppThemeDark_NoActionBar);
|
setTheme(R.style.AppThemeDark);
|
||||||
}
|
}
|
||||||
position = 1;
|
|
||||||
if (getSupportActionBar() != null)
|
if (getSupportActionBar() != null)
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
ActionBar actionBar = getSupportActionBar();
|
ActionBar actionBar = getSupportActionBar();
|
||||||
|
@ -103,67 +84,100 @@ public class SettingsActivity extends BaseActivity implements ViewAnimator.ViewA
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
toolbar_title.setText(R.string.action_about);
|
toolbar_title.setText(R.string.settings);
|
||||||
if (theme == Helper.THEME_LIGHT) {
|
if (theme == Helper.THEME_LIGHT) {
|
||||||
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
|
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
|
||||||
Helper.colorizeToolbar(toolbar, R.color.black, SettingsActivity.this);
|
Helper.colorizeToolbar(toolbar, R.color.black, SettingsActivity.this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setContentView(R.layout.activity_settings);
|
setContentView(R.layout.activity_settings);
|
||||||
ContentSettingsFragment contentSettingsFragment = ContentSettingsFragment.newInstance(R.drawable.ic_list_timeline);
|
|
||||||
getSupportFragmentManager().beginTransaction()
|
|
||||||
.replace(R.id.content_frame, contentSettingsFragment)
|
ViewPager mPager = findViewById(R.id.settings_viewpager);
|
||||||
.commit();
|
TabLayout tabLayout = findViewById(R.id.settings_tablayout);
|
||||||
drawerLayout = findViewById(R.id.drawer_layout);
|
|
||||||
drawerLayout.setScrimColor(Color.TRANSPARENT);
|
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.settings_category_label_timelines)));
|
||||||
linearLayout = findViewById(R.id.left_drawer);
|
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.notifications)));
|
||||||
linearLayout.setOnClickListener(new View.OnClickListener() {
|
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.settings_category_label_interface)));
|
||||||
|
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.compose)));
|
||||||
|
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.hide_menu_items)));
|
||||||
|
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.administration)));
|
||||||
|
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.languages)));
|
||||||
|
PagerAdapter mPagerAdapter = new SettingsPagerAdapter(getSupportFragmentManager());
|
||||||
|
mPager.setAdapter(mPagerAdapter);
|
||||||
|
|
||||||
|
mPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||||
drawerLayout.closeDrawers();
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPageSelected(int position) {
|
||||||
|
TabLayout.Tab tab = tabLayout.getTabAt(position);
|
||||||
|
if (tab != null)
|
||||||
|
tab.select();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPageScrollStateChanged(int state) {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
setActionBar();
|
|
||||||
createMenuList();
|
|
||||||
viewAnimator = new ViewAnimator<>(this, list, contentSettingsFragment, drawerLayout, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setActionBar() {
|
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
|
||||||
setSupportActionBar(toolbar);
|
|
||||||
Objects.requireNonNull(getSupportActionBar()).setHomeButtonEnabled(true);
|
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
||||||
drawerToggle = new ActionBarDrawerToggle(
|
|
||||||
this,
|
|
||||||
drawerLayout,
|
|
||||||
toolbar,
|
|
||||||
R.string.close,
|
|
||||||
R.string.open_menu
|
|
||||||
) {
|
|
||||||
|
|
||||||
/** Called when a drawer has settled in a completely closed state. */
|
|
||||||
public void onDrawerClosed(View view) {
|
private class SettingsPagerAdapter extends FragmentStatePagerAdapter {
|
||||||
super.onDrawerClosed(view);
|
|
||||||
linearLayout.removeAllViews();
|
SettingsPagerAdapter(FragmentManager fm) {
|
||||||
linearLayout.invalidate();
|
super(fm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Fragment getItem(int position) {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
ContentSettingsFragment.type typeOfSettings;
|
||||||
|
switch (position) {
|
||||||
|
case 0:
|
||||||
|
typeOfSettings = ContentSettingsFragment.type.TIMELINES;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
typeOfSettings = ContentSettingsFragment.type.NOTIFICATIONS;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
typeOfSettings = ContentSettingsFragment.type.INTERFACE;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
typeOfSettings = ContentSettingsFragment.type.COMPOSE;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
typeOfSettings = ContentSettingsFragment.type.MENU;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
typeOfSettings = ContentSettingsFragment.type.ADMIN;
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
typeOfSettings = ContentSettingsFragment.type.LANGUAGE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
typeOfSettings = ContentSettingsFragment.type.TIMELINES;
|
||||||
|
|
||||||
|
}
|
||||||
|
ContentSettingsFragment contentSettingsFragment = new ContentSettingsFragment();
|
||||||
|
bundle.putSerializable("typeOfSettings", typeOfSettings);
|
||||||
|
contentSettingsFragment.setArguments(bundle);
|
||||||
|
return contentSettingsFragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDrawerSlide(View drawerView, float slideOffset) {
|
public int getCount() {
|
||||||
super.onDrawerSlide(drawerView, slideOffset);
|
return 7;
|
||||||
if (slideOffset > 0.6 && linearLayout.getChildCount() == 0)
|
|
||||||
viewAnimator.showMenuContent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Called when a drawer has settled in a completely open state. */
|
|
||||||
public void onDrawerOpened(View drawerView) {
|
|
||||||
super.onDrawerOpened(drawerView);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
drawerLayout.addDrawerListener(drawerToggle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setActionBarTitle(String title) {
|
public void setActionBarTitle(String title) {
|
||||||
|
@ -175,49 +189,6 @@ public class SettingsActivity extends BaseActivity implements ViewAnimator.ViewA
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createMenuList() {
|
|
||||||
|
|
||||||
SlideMenuItem menuItemClose = new SlideMenuItem(ContentSettingsFragment.type.CLOSE, R.drawable.ic_close);
|
|
||||||
SlideMenuItem menuItemTimeline = new SlideMenuItem(ContentSettingsFragment.type.TIMELINES, R.drawable.ic_timeline_menu_s);
|
|
||||||
SlideMenuItem menuItemNotification = new SlideMenuItem(ContentSettingsFragment.type.NOTIFICATIONS, R.drawable.ic_notifications_menu);
|
|
||||||
SlideMenuItem menuItemAdmin = new SlideMenuItem(ContentSettingsFragment.type.ADMIN, R.drawable.ic_security_admin_menu);
|
|
||||||
SlideMenuItem menuItemInterface = new SlideMenuItem(ContentSettingsFragment.type.INTERFACE, R.drawable.ic_tablet_menu);
|
|
||||||
SlideMenuItem menuItemEdit = new SlideMenuItem(ContentSettingsFragment.type.COMPOSE, R.drawable.ic_edit_black_menu);
|
|
||||||
SlideMenuItem menuLanguage = new SlideMenuItem(ContentSettingsFragment.type.LANGUAGE, R.drawable.ic_translate_menu);
|
|
||||||
SlideMenuItem menuMenu = new SlideMenuItem(ContentSettingsFragment.type.MENU, R.drawable.ic_menu_menu);
|
|
||||||
list.add(menuItemClose);
|
|
||||||
list.add(menuItemTimeline);
|
|
||||||
list.add(menuItemNotification);
|
|
||||||
list.add(menuItemInterface);
|
|
||||||
list.add(menuItemEdit);
|
|
||||||
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
|
|
||||||
list.add(menuMenu);
|
|
||||||
list.add(menuItemAdmin);
|
|
||||||
}
|
|
||||||
list.add(menuLanguage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostCreate(Bundle savedInstanceState) {
|
|
||||||
super.onPostCreate(savedInstanceState);
|
|
||||||
drawerToggle.syncState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onConfigurationChanged(Configuration newConfig) {
|
|
||||||
super.onConfigurationChanged(newConfig);
|
|
||||||
drawerToggle.onConfigurationChanged(newConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
if (item.getItemId() == android.R.id.home) {
|
|
||||||
finish();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -227,63 +198,4 @@ public class SettingsActivity extends BaseActivity implements ViewAnimator.ViewA
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private ScreenShotable replaceFragment(ScreenShotable screenShotable, ContentSettingsFragment.type type, int topPosition) {
|
|
||||||
this.res = this.res == R.drawable.ic_timeline_menu_s ? R.drawable.ic_notifications_menu : R.drawable.ic_timeline_menu_s;
|
|
||||||
if (type == ContentSettingsFragment.type.LANGUAGE) {
|
|
||||||
Intent intent = new Intent(getApplicationContext(), LanguageActivity.class);
|
|
||||||
startActivity(intent);
|
|
||||||
type = previous;
|
|
||||||
} else if (type == ContentSettingsFragment.type.MENU) {
|
|
||||||
Intent intent = new Intent(getApplicationContext(), HideItemActivity.class);
|
|
||||||
startActivity(intent);
|
|
||||||
type = previous;
|
|
||||||
}
|
|
||||||
View view = findViewById(R.id.content_frame);
|
|
||||||
int finalRadius = Math.max(view.getWidth(), view.getHeight());
|
|
||||||
Animator animator;
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
animator = ViewAnimationUtils.createCircularReveal(view, 0, topPosition, 0, finalRadius);
|
|
||||||
animator.setInterpolator(new AccelerateInterpolator());
|
|
||||||
animator.setDuration(ViewAnimator.CIRCULAR_REVEAL_ANIMATION_DURATION);
|
|
||||||
findViewById(R.id.content_overlay).setBackground(new BitmapDrawable(getResources(), screenShotable.getBitmap()));
|
|
||||||
animator.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ContentSettingsFragment contentSettingsFragment = ContentSettingsFragment.newInstance(this.res);
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putSerializable("type", type);
|
|
||||||
contentSettingsFragment.setArguments(bundle);
|
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, contentSettingsFragment).commit();
|
|
||||||
previous = type;
|
|
||||||
return contentSettingsFragment;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ScreenShotable onSwitch(Resourceble slideMenuItem, ScreenShotable screenShotable, int position) {
|
|
||||||
|
|
||||||
ContentSettingsFragment.type type = slideMenuItem.getType();
|
|
||||||
if (ContentSettingsFragment.type.CLOSE.equals(type)) {
|
|
||||||
finish();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return replaceFragment(screenShotable, type, position);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void disableHomeButton() {
|
|
||||||
Objects.requireNonNull(getSupportActionBar()).setHomeButtonEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enableHomeButton() {
|
|
||||||
Objects.requireNonNull(getSupportActionBar()).setHomeButtonEnabled(true);
|
|
||||||
drawerLayout.closeDrawers();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addViewToContainer(View view) {
|
|
||||||
linearLayout.addView(view);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
package app.fedilab.android.animatemenu.animation;
|
|
||||||
|
|
||||||
import android.graphics.Camera;
|
|
||||||
import android.graphics.Matrix;
|
|
||||||
import android.view.animation.Animation;
|
|
||||||
import android.view.animation.Transformation;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Konstantin on 22.12.2014.
|
|
||||||
*/
|
|
||||||
public class FlipAnimation extends Animation {
|
|
||||||
private final float mFromDegrees;
|
|
||||||
private final float mToDegrees;
|
|
||||||
private final float mCenterX;
|
|
||||||
private final float mCenterY;
|
|
||||||
private Camera mCamera;
|
|
||||||
|
|
||||||
public FlipAnimation(float fromDegrees, float toDegrees,
|
|
||||||
float centerX, float centerY) {
|
|
||||||
mFromDegrees = fromDegrees;
|
|
||||||
mToDegrees = toDegrees;
|
|
||||||
mCenterX = centerX;
|
|
||||||
mCenterY = centerY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initialize(int width, int height, int parentWidth, int parentHeight) {
|
|
||||||
super.initialize(width, height, parentWidth, parentHeight);
|
|
||||||
mCamera = new Camera();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
|
||||||
final float fromDegrees = mFromDegrees;
|
|
||||||
float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);
|
|
||||||
|
|
||||||
final float centerX = mCenterX;
|
|
||||||
final float centerY = mCenterY;
|
|
||||||
final Camera camera = mCamera;
|
|
||||||
|
|
||||||
final Matrix matrix = t.getMatrix();
|
|
||||||
|
|
||||||
camera.save();
|
|
||||||
|
|
||||||
camera.rotateY(degrees);
|
|
||||||
|
|
||||||
camera.getMatrix(matrix);
|
|
||||||
camera.restore();
|
|
||||||
|
|
||||||
matrix.preTranslate(-centerX, -centerY);
|
|
||||||
matrix.postTranslate(centerX, centerY);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package app.fedilab.android.animatemenu.interfaces;
|
|
||||||
|
|
||||||
import app.fedilab.android.fragments.ContentSettingsFragment;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Konstantin on 12.01.2015.
|
|
||||||
*/
|
|
||||||
public interface Resourceble {
|
|
||||||
public int getImageRes();
|
|
||||||
|
|
||||||
public ContentSettingsFragment.type getType();
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package app.fedilab.android.animatemenu.interfaces;
|
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Konstantin on 12.01.2015.
|
|
||||||
*/
|
|
||||||
public interface ScreenShotable {
|
|
||||||
public void takeScreenShot();
|
|
||||||
|
|
||||||
public Bitmap getBitmap();
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
package app.fedilab.android.animatemenu.model;
|
|
||||||
|
|
||||||
|
|
||||||
import app.fedilab.android.animatemenu.interfaces.Resourceble;
|
|
||||||
import app.fedilab.android.fragments.ContentSettingsFragment;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Konstantin on 23.12.2014.
|
|
||||||
*/
|
|
||||||
public class SlideMenuItem implements Resourceble {
|
|
||||||
|
|
||||||
private ContentSettingsFragment.type type;
|
|
||||||
private int imageRes;
|
|
||||||
|
|
||||||
public SlideMenuItem(ContentSettingsFragment.type type, int imageRes) {
|
|
||||||
this.type = type;
|
|
||||||
this.imageRes = imageRes;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int getImageRes() {
|
|
||||||
return imageRes;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ContentSettingsFragment.type getType() {
|
|
||||||
return this.type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setImageRes(int imageRes) {
|
|
||||||
this.imageRes = imageRes;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,222 +0,0 @@
|
||||||
package app.fedilab.android.animatemenu.util;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.animation.AccelerateInterpolator;
|
|
||||||
import android.view.animation.Animation;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
import androidx.drawerlayout.widget.DrawerLayout;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import app.fedilab.android.R;
|
|
||||||
import app.fedilab.android.activities.ManageAccountsInListActivity;
|
|
||||||
import app.fedilab.android.activities.SettingsActivity;
|
|
||||||
import app.fedilab.android.animatemenu.animation.FlipAnimation;
|
|
||||||
import app.fedilab.android.animatemenu.interfaces.Resourceble;
|
|
||||||
import app.fedilab.android.animatemenu.interfaces.ScreenShotable;
|
|
||||||
import app.fedilab.android.helper.Helper;
|
|
||||||
|
|
||||||
import static android.content.Context.MODE_PRIVATE;
|
|
||||||
import static app.fedilab.android.helper.Helper.changeDrawableColor;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Konstantin on 12.01.2015.
|
|
||||||
*/
|
|
||||||
public class ViewAnimator<T extends Resourceble> {
|
|
||||||
private final int ANIMATION_DURATION = 100;
|
|
||||||
public static final int CIRCULAR_REVEAL_ANIMATION_DURATION = 500;
|
|
||||||
|
|
||||||
private AppCompatActivity appCompatActivity;
|
|
||||||
|
|
||||||
private List<T> list;
|
|
||||||
|
|
||||||
private List<View> viewList = new ArrayList<>();
|
|
||||||
private ScreenShotable screenShotable;
|
|
||||||
private DrawerLayout drawerLayout;
|
|
||||||
private ViewAnimatorListener animatorListener;
|
|
||||||
|
|
||||||
|
|
||||||
public ViewAnimator(AppCompatActivity activity,
|
|
||||||
List<T> items,
|
|
||||||
ScreenShotable screenShotable,
|
|
||||||
final DrawerLayout drawerLayout,
|
|
||||||
ViewAnimatorListener animatorListener) {
|
|
||||||
this.appCompatActivity = activity;
|
|
||||||
|
|
||||||
this.list = items;
|
|
||||||
this.screenShotable = screenShotable;
|
|
||||||
this.drawerLayout = drawerLayout;
|
|
||||||
this.animatorListener = animatorListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void showMenuContent() {
|
|
||||||
setViewsClickable(false);
|
|
||||||
viewList.clear();
|
|
||||||
double size = list.size();
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
@SuppressLint("InflateParams") View viewMenu = appCompatActivity.getLayoutInflater().inflate(R.layout.menu_list_item, null);
|
|
||||||
|
|
||||||
if (i == SettingsActivity.position) {
|
|
||||||
viewMenu.setBackgroundColor(ContextCompat.getColor(appCompatActivity, R.color.mastodonC2));
|
|
||||||
} else {
|
|
||||||
SharedPreferences sharedpreferences = appCompatActivity.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
|
||||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
|
||||||
|
|
||||||
if (theme == Helper.THEME_DARK) {
|
|
||||||
viewMenu.setBackgroundResource(R.drawable.menu_item_selector);
|
|
||||||
} else if (theme == Helper.THEME_BLACK) {
|
|
||||||
viewMenu.setBackgroundResource(R.drawable.menu_item_selector_black);
|
|
||||||
} else {
|
|
||||||
viewMenu.setBackgroundResource(R.drawable.menu_item_selector_light);
|
|
||||||
ImageView imageView = viewMenu.findViewById(R.id.menu_item_image);
|
|
||||||
if (imageView != null) {
|
|
||||||
changeDrawableColor(appCompatActivity, imageView, R.color.black);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
final int finalI = i;
|
|
||||||
viewMenu.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
int[] location = {0, 0};
|
|
||||||
SettingsActivity.position = finalI;
|
|
||||||
v.getLocationOnScreen(location);
|
|
||||||
switchItem(list.get(finalI), location[1] + v.getHeight() / 2);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
((ImageView) viewMenu.findViewById(R.id.menu_item_image)).setImageResource(list.get(i).getImageRes());
|
|
||||||
viewMenu.setVisibility(View.GONE);
|
|
||||||
viewMenu.setEnabled(false);
|
|
||||||
viewList.add(viewMenu);
|
|
||||||
animatorListener.addViewToContainer(viewMenu);
|
|
||||||
final double position = i;
|
|
||||||
final double delay = 3 * ANIMATION_DURATION * (position / size);
|
|
||||||
if (screenShotable != null) {
|
|
||||||
new Handler().postDelayed(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
if (position < viewList.size()) {
|
|
||||||
animateView((int) position);
|
|
||||||
}
|
|
||||||
if (position == viewList.size() - 1) {
|
|
||||||
screenShotable.takeScreenShot();
|
|
||||||
setViewsClickable(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, (long) delay);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void hideMenuContent() {
|
|
||||||
setViewsClickable(false);
|
|
||||||
double size = list.size();
|
|
||||||
for (int i = list.size(); i >= 0; i--) {
|
|
||||||
final double position = i;
|
|
||||||
final double delay = 3 * ANIMATION_DURATION * (position / size);
|
|
||||||
new Handler().postDelayed(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
if (position < viewList.size()) {
|
|
||||||
animateHideView((int) position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, (long) delay);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setViewsClickable(boolean clickable) {
|
|
||||||
animatorListener.disableHomeButton();
|
|
||||||
for (View view : viewList) {
|
|
||||||
view.setEnabled(clickable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void animateView(int position) {
|
|
||||||
final View view = viewList.get(position);
|
|
||||||
view.setVisibility(View.VISIBLE);
|
|
||||||
FlipAnimation rotation =
|
|
||||||
new FlipAnimation(90, 0, 0.0f, view.getHeight() / 2.0f);
|
|
||||||
rotation.setDuration(ANIMATION_DURATION);
|
|
||||||
rotation.setFillAfter(true);
|
|
||||||
rotation.setInterpolator(new AccelerateInterpolator());
|
|
||||||
rotation.setAnimationListener(new Animation.AnimationListener() {
|
|
||||||
@Override
|
|
||||||
public void onAnimationStart(Animation animation) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAnimationEnd(Animation animation) {
|
|
||||||
view.clearAnimation();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAnimationRepeat(Animation animation) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
view.startAnimation(rotation);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void animateHideView(final int position) {
|
|
||||||
final View view = viewList.get(position);
|
|
||||||
FlipAnimation rotation =
|
|
||||||
new FlipAnimation(0, 90, 0.0f, view.getHeight() / 2.0f);
|
|
||||||
rotation.setDuration(ANIMATION_DURATION);
|
|
||||||
rotation.setFillAfter(true);
|
|
||||||
rotation.setInterpolator(new AccelerateInterpolator());
|
|
||||||
rotation.setAnimationListener(new Animation.AnimationListener() {
|
|
||||||
@Override
|
|
||||||
public void onAnimationStart(Animation animation) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAnimationEnd(Animation animation) {
|
|
||||||
view.clearAnimation();
|
|
||||||
view.setVisibility(View.INVISIBLE);
|
|
||||||
|
|
||||||
animatorListener.enableHomeButton();
|
|
||||||
drawerLayout.closeDrawers();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAnimationRepeat(Animation animation) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
view.startAnimation(rotation);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void switchItem(Resourceble slideMenuItem, int topPosition) {
|
|
||||||
this.screenShotable = animatorListener.onSwitch(slideMenuItem, screenShotable, topPosition);
|
|
||||||
hideMenuContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface ViewAnimatorListener {
|
|
||||||
|
|
||||||
ScreenShotable onSwitch(Resourceble slideMenuItem, ScreenShotable screenShotable, int position);
|
|
||||||
|
|
||||||
void disableHomeButton();
|
|
||||||
|
|
||||||
void enableHomeButton();
|
|
||||||
|
|
||||||
void addViewToContainer(View view);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -80,7 +80,6 @@ import app.fedilab.android.R;
|
||||||
import app.fedilab.android.activities.LanguageActivity;
|
import app.fedilab.android.activities.LanguageActivity;
|
||||||
import app.fedilab.android.activities.MainActivity;
|
import app.fedilab.android.activities.MainActivity;
|
||||||
import app.fedilab.android.activities.SettingsActivity;
|
import app.fedilab.android.activities.SettingsActivity;
|
||||||
import app.fedilab.android.animatemenu.interfaces.ScreenShotable;
|
|
||||||
import app.fedilab.android.asynctasks.DownloadTrackingDomainsAsyncTask;
|
import app.fedilab.android.asynctasks.DownloadTrackingDomainsAsyncTask;
|
||||||
import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
|
import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
|
||||||
import app.fedilab.android.client.Entities.Account;
|
import app.fedilab.android.client.Entities.Account;
|
||||||
|
@ -104,7 +103,7 @@ import static app.fedilab.android.fragments.ContentSettingsFragment.type.INTERFA
|
||||||
import static app.fedilab.android.fragments.ContentSettingsFragment.type.NOTIFICATIONS;
|
import static app.fedilab.android.fragments.ContentSettingsFragment.type.NOTIFICATIONS;
|
||||||
import static app.fedilab.android.fragments.ContentSettingsFragment.type.TIMELINES;
|
import static app.fedilab.android.fragments.ContentSettingsFragment.type.TIMELINES;
|
||||||
|
|
||||||
public class ContentSettingsFragment extends Fragment implements ScreenShotable {
|
public class ContentSettingsFragment extends Fragment {
|
||||||
|
|
||||||
|
|
||||||
private View containerView;
|
private View containerView;
|
||||||
|
@ -205,7 +204,7 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
|
||||||
|
|
||||||
Bundle bundle = this.getArguments();
|
Bundle bundle = this.getArguments();
|
||||||
if (bundle != null) {
|
if (bundle != null) {
|
||||||
type = (type) bundle.getSerializable("type");
|
type = (type) bundle.getSerializable("typeOfSettings");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -243,22 +242,15 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
|
||||||
String title = "";
|
String title = "";
|
||||||
if (type == null || type.equals(TIMELINES)) {
|
if (type == null || type.equals(TIMELINES)) {
|
||||||
settings_timeline.setVisibility(View.VISIBLE);
|
settings_timeline.setVisibility(View.VISIBLE);
|
||||||
title = context.getString(R.string.timelines);
|
|
||||||
} else if (type == NOTIFICATIONS) {
|
} else if (type == NOTIFICATIONS) {
|
||||||
settings_notifications.setVisibility(View.VISIBLE);
|
settings_notifications.setVisibility(View.VISIBLE);
|
||||||
title = context.getString(R.string.notifications);
|
|
||||||
} else if (type == ADMIN) {
|
} else if (type == ADMIN) {
|
||||||
settings_admin.setVisibility(View.VISIBLE);
|
settings_admin.setVisibility(View.VISIBLE);
|
||||||
title = context.getString(R.string.administration);
|
|
||||||
} else if (type == INTERFACE) {
|
} else if (type == INTERFACE) {
|
||||||
settings_interface.setVisibility(View.VISIBLE);
|
settings_interface.setVisibility(View.VISIBLE);
|
||||||
title = context.getString(R.string.u_interface);
|
|
||||||
} else if (type == COMPOSE) {
|
} else if (type == COMPOSE) {
|
||||||
settings_compose.setVisibility(View.VISIBLE);
|
settings_compose.setVisibility(View.VISIBLE);
|
||||||
title = context.getString(R.string.compose);
|
|
||||||
}
|
}
|
||||||
((SettingsActivity) context)
|
|
||||||
.setActionBarTitle(title);
|
|
||||||
|
|
||||||
|
|
||||||
boolean auto_store = sharedpreferences.getBoolean(Helper.SET_AUTO_STORE, true);
|
boolean auto_store = sharedpreferences.getBoolean(Helper.SET_AUTO_STORE, true);
|
||||||
|
@ -2214,30 +2206,9 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void takeScreenShot() {
|
|
||||||
Thread thread = new Thread() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(containerView.getWidth(),
|
|
||||||
containerView.getHeight(), Bitmap.Config.ARGB_8888);
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
|
||||||
containerView.draw(canvas);
|
|
||||||
ContentSettingsFragment.this.bitmap = bitmap;
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
thread.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Bitmap getBitmap() {
|
|
||||||
return bitmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//From: https://gist.github.com/asifmujteba/d89ba9074bc941de1eaa#file-asfurihelper
|
//From: https://gist.github.com/asifmujteba/d89ba9074bc941de1eaa#file-asfurihelper
|
||||||
|
|
|
@ -1,53 +1,25 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/drawer_layout"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_height="match_parent">
|
android:fitsSystemWindows="true"
|
||||||
|
tools:context="app.fedilab.android.activities.SettingsActivity"
|
||||||
<com.google.android.material.circularreveal.CircularRevealFrameLayout
|
android:layout_margin="@dimen/fab_margin"
|
||||||
android:id="@+id/container_frame"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/content_overlay"
|
|
||||||
android:layout_marginTop="?attr/actionBarSize"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical" />
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_marginTop="?attr/actionBarSize"
|
|
||||||
android:id="@+id/content_frame"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical" />
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.Toolbar
|
|
||||||
android:id="@+id/toolbar"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:minHeight="?attr/actionBarSize"
|
|
||||||
android:background="?attr/colorPrimary" />
|
|
||||||
|
|
||||||
</com.google.android.material.circularreveal.CircularRevealFrameLayout>
|
|
||||||
|
|
||||||
<ScrollView
|
|
||||||
android:id="@+id/scrollView"
|
|
||||||
android:scrollbarThumbVertical="@android:color/transparent"
|
|
||||||
android:layout_width="80dp"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_gravity="start|bottom">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/left_drawer"
|
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="80dp"
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<com.google.android.material.tabs.TabLayout
|
||||||
|
android:id="@+id/settings_tablayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:divider="@android:color/transparent"
|
app:tabSelectedTextColor="?attr/colorAccent"
|
||||||
android:dividerHeight="0dp"
|
app:tabTextColor="?attr/textColor"
|
||||||
android:background="@android:color/transparent">
|
app:tabMode="scrollable"
|
||||||
<!-- Layout of Drawer -->
|
app:tabGravity="fill" />
|
||||||
|
<androidx.viewpager.widget.ViewPager
|
||||||
|
android:id="@+id/settings_viewpager"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
|
||||||
</androidx.drawerlayout.widget.DrawerLayout>
|
|
Loading…
Reference in New Issue