From 04974835d657d8e10440bf002fa2dd26fbdeb851 Mon Sep 17 00:00:00 2001 From: sigmabeta Date: Sat, 23 Jan 2016 17:00:06 -0500 Subject: [PATCH] Add fragment transition animations to the Settings UI screen --- .../ui/settings/SettingsActivity.java | 28 ++++++++-- .../settings/SettingsActivityPresenter.java | 20 +++++++ .../ui/settings/SettingsActivityView.java | 10 ++++ .../ui/settings/SettingsFragment.java | 2 +- .../ui/settings/SettingsFrameLayout.java | 56 +++++++++++++++++++ .../src/main/res/animator/settings_enter.xml | 27 +++++++++ .../src/main/res/animator/settings_exit.xml | 27 +++++++++ .../main/res/animator/settings_pop_enter.xml | 27 +++++++++ .../main/res/animator/setttings_pop_exit.xml | 26 +++++++++ .../src/main/res/layout/fragment_settings.xml | 8 ++- 10 files changed, 224 insertions(+), 7 deletions(-) create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFrameLayout.java create mode 100644 Source/Android/app/src/main/res/animator/settings_enter.xml create mode 100644 Source/Android/app/src/main/res/animator/settings_exit.xml create mode 100644 Source/Android/app/src/main/res/animator/settings_pop_enter.xml create mode 100644 Source/Android/app/src/main/res/animator/setttings_pop_exit.xml diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivity.java index 7cd744aff2..9af89ae48a 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivity.java @@ -1,10 +1,10 @@ package org.dolphinemu.dolphinemu.ui.settings; +import android.app.FragmentTransaction; import android.content.Context; import android.content.Intent; import android.os.Bundle; -import android.support.v4.app.FragmentTransaction; import android.support.v7.app.AppCompatActivity; import android.widget.Toast; @@ -45,16 +45,30 @@ public final class SettingsActivity extends AppCompatActivity implements Setting mPresenter.onStop(isFinishing()); } + @Override + public void onBackPressed() + { + mPresenter.onBackPressed(); + } + + @Override public void showSettingsFragment(String menuTag, boolean addToStack) { - FragmentTransaction transaction = getSupportFragmentManager().beginTransaction() - .replace(R.id.frame_content, SettingsFragment.newInstance(menuTag), SettingsFragment.FRAGMENT_TAG); + FragmentTransaction transaction = getFragmentManager().beginTransaction(); if (addToStack) { + transaction.setCustomAnimations( + R.animator.settings_enter, + R.animator.settings_exit, + R.animator.settings_pop_enter, + R.animator.setttings_pop_exit); + transaction.addToBackStack(null); + mPresenter.addToStack(); } + transaction.replace(R.id.frame_content, SettingsFragment.newInstance(menuTag), SettingsFragment.FRAGMENT_TAG); transaction.commit(); } @@ -88,9 +102,15 @@ public final class SettingsActivity extends AppCompatActivity implements Setting Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); } + @Override + public void popBackStack() + { + getFragmentManager().popBackStackImmediate(); + } + private SettingsFragment getFragment() { - return (SettingsFragment) getSupportFragmentManager().findFragmentByTag(SettingsFragment.FRAGMENT_TAG); + return (SettingsFragment) getFragmentManager().findFragmentByTag(SettingsFragment.FRAGMENT_TAG); } public static final String ARGUMENT_FILE_NAME = BuildConfig.APPLICATION_ID + ".file_name"; diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivityPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivityPresenter.java index aac7e8e2ed..46d95e47f6 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivityPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivityPresenter.java @@ -20,6 +20,8 @@ public final class SettingsActivityPresenter private String mFileName; private HashMap mSettingsBySection; + private int mStackCount; + public SettingsActivityPresenter(SettingsActivityView view) { mView = view; @@ -94,4 +96,22 @@ public final class SettingsActivityPresenter }); } } + + public void addToStack() + { + mStackCount++; + } + + public void onBackPressed() + { + if (mStackCount > 0) + { + mView.popBackStack(); + mStackCount--; + } + else + { + mView.finish(); + } + } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivityView.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivityView.java index 2409ed1221..84221b0220 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivityView.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsActivityView.java @@ -48,4 +48,14 @@ public interface SettingsActivityView * @param message The contents of the onscreen message. */ void showToastMessage(String message); + + /** + * Show the previous fragment. + */ + void popBackStack(); + + /** + * End the activity. + */ + void finish(); } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragment.java index 89e5edb056..0f83d4b591 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFragment.java @@ -1,9 +1,9 @@ package org.dolphinemu.dolphinemu.ui.settings; +import android.app.Fragment; import android.content.Context; import android.os.Bundle; import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFrameLayout.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFrameLayout.java new file mode 100644 index 0000000000..fc3d46e01d --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsFrameLayout.java @@ -0,0 +1,56 @@ +package org.dolphinemu.dolphinemu.ui.settings; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.FrameLayout; + +/** + * FrameLayout subclass with few Properties added to simplify animations. + */ +public final class SettingsFrameLayout extends FrameLayout +{ + private float mVisibleness = 1.0f; + + public SettingsFrameLayout(Context context) + { + super(context); + } + + public SettingsFrameLayout(Context context, AttributeSet attrs) + { + super(context, attrs); + } + + public SettingsFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) + { + super(context, attrs, defStyleAttr); + } + + public SettingsFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) + { + super(context, attrs, defStyleAttr, defStyleRes); + } + + public float getYFraction() + { + return getY() / getHeight(); + } + + public void setYFraction(float yFraction) + { + final int height = getHeight(); + setY((height > 0) ? (yFraction * height) : -9999); + } + + public float getVisibleness() + { + return mVisibleness; + } + + public void setVisibleness(float visibleness) + { + setScaleX(visibleness); + setScaleY(visibleness); + setAlpha(visibleness); + } +} diff --git a/Source/Android/app/src/main/res/animator/settings_enter.xml b/Source/Android/app/src/main/res/animator/settings_enter.xml new file mode 100644 index 0000000000..1e180ca6bc --- /dev/null +++ b/Source/Android/app/src/main/res/animator/settings_enter.xml @@ -0,0 +1,27 @@ + + + + + + + + + \ No newline at end of file diff --git a/Source/Android/app/src/main/res/animator/settings_exit.xml b/Source/Android/app/src/main/res/animator/settings_exit.xml new file mode 100644 index 0000000000..f5480541a9 --- /dev/null +++ b/Source/Android/app/src/main/res/animator/settings_exit.xml @@ -0,0 +1,27 @@ + + + + + + + + + \ No newline at end of file diff --git a/Source/Android/app/src/main/res/animator/settings_pop_enter.xml b/Source/Android/app/src/main/res/animator/settings_pop_enter.xml new file mode 100644 index 0000000000..f61efac611 --- /dev/null +++ b/Source/Android/app/src/main/res/animator/settings_pop_enter.xml @@ -0,0 +1,27 @@ + + + + + + + + + \ No newline at end of file diff --git a/Source/Android/app/src/main/res/animator/setttings_pop_exit.xml b/Source/Android/app/src/main/res/animator/setttings_pop_exit.xml new file mode 100644 index 0000000000..13a0ce1ff3 --- /dev/null +++ b/Source/Android/app/src/main/res/animator/setttings_pop_exit.xml @@ -0,0 +1,26 @@ + + + + + + + + + \ No newline at end of file diff --git a/Source/Android/app/src/main/res/layout/fragment_settings.xml b/Source/Android/app/src/main/res/layout/fragment_settings.xml index 3823d50d12..7af8c7c268 100644 --- a/Source/Android/app/src/main/res/layout/fragment_settings.xml +++ b/Source/Android/app/src/main/res/layout/fragment_settings.xml @@ -1,11 +1,15 @@ - - \ No newline at end of file + \ No newline at end of file