mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-03-12 14:46:49 +01:00
Merge pull request #3517 from sigmabeta/android-animation-refactor
[Android] Refactor animations
This commit is contained in:
commit
ba8dc2cef3
@ -15,9 +15,6 @@ import android.view.MenuItem;
|
|||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewTreeObserver;
|
import android.view.ViewTreeObserver;
|
||||||
import android.view.animation.AccelerateInterpolator;
|
|
||||||
import android.view.animation.DecelerateInterpolator;
|
|
||||||
import android.view.animation.Interpolator;
|
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
@ -32,6 +29,7 @@ import org.dolphinemu.dolphinemu.fragments.LoadStateFragment;
|
|||||||
import org.dolphinemu.dolphinemu.fragments.MenuFragment;
|
import org.dolphinemu.dolphinemu.fragments.MenuFragment;
|
||||||
import org.dolphinemu.dolphinemu.fragments.SaveStateFragment;
|
import org.dolphinemu.dolphinemu.fragments.SaveStateFragment;
|
||||||
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
|
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
|
||||||
|
import org.dolphinemu.dolphinemu.utils.Animations;
|
||||||
import org.dolphinemu.dolphinemu.utils.Log;
|
import org.dolphinemu.dolphinemu.utils.Log;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -53,9 +51,6 @@ public final class EmulationActivity extends AppCompatActivity
|
|||||||
private boolean mSystemUiVisible;
|
private boolean mSystemUiVisible;
|
||||||
private boolean mMenuVisible;
|
private boolean mMenuVisible;
|
||||||
|
|
||||||
private static final Interpolator sDecelerator = new DecelerateInterpolator();
|
|
||||||
private static final Interpolator sAccelerator = new AccelerateInterpolator();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handlers are a way to pass a message to an Activity telling it to do something
|
* Handlers are a way to pass a message to an Activity telling it to do something
|
||||||
* on the UI thread. This Handler responds to any message, even blank ones, by
|
* on the UI thread. This Handler responds to any message, even blank ones, by
|
||||||
@ -160,11 +155,8 @@ public final class EmulationActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mImageView.animate()
|
Animations.fadeViewOut(mImageView)
|
||||||
.withLayer()
|
|
||||||
.setStartDelay(2000)
|
.setStartDelay(2000)
|
||||||
.setDuration(500)
|
|
||||||
.alpha(0.0f)
|
|
||||||
.withStartAction(new Runnable()
|
.withStartAction(new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -268,7 +260,7 @@ public final class EmulationActivity extends AppCompatActivity
|
|||||||
{
|
{
|
||||||
if (mSubmenuFragmentTag != null)
|
if (mSubmenuFragmentTag != null)
|
||||||
{
|
{
|
||||||
removeMenu();
|
removeSubMenu();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -287,12 +279,7 @@ public final class EmulationActivity extends AppCompatActivity
|
|||||||
{
|
{
|
||||||
mMenuVisible = false;
|
mMenuVisible = false;
|
||||||
|
|
||||||
mMenuLayout.animate()
|
Animations.fadeViewOutToLeft(mMenuLayout)
|
||||||
.withLayer()
|
|
||||||
.setDuration(200)
|
|
||||||
.setInterpolator(sAccelerator)
|
|
||||||
.alpha(0.0f)
|
|
||||||
.translationX(-400.0f)
|
|
||||||
.withEndAction(new Runnable()
|
.withEndAction(new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -308,17 +295,7 @@ public final class EmulationActivity extends AppCompatActivity
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
mMenuVisible = true;
|
mMenuVisible = true;
|
||||||
mMenuLayout.setVisibility(View.VISIBLE);
|
Animations.fadeViewInFromLeft(mMenuLayout);
|
||||||
|
|
||||||
// mMenuLayout.setTranslationX(-400.0f);
|
|
||||||
mMenuLayout.setAlpha(0.0f);
|
|
||||||
|
|
||||||
mMenuLayout.animate()
|
|
||||||
.withLayer()
|
|
||||||
.setDuration(300)
|
|
||||||
.setInterpolator(sDecelerator)
|
|
||||||
.alpha(1.0f)
|
|
||||||
.translationX(0.0f);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,11 +342,7 @@ public final class EmulationActivity extends AppCompatActivity
|
|||||||
|
|
||||||
private void showScreenshot()
|
private void showScreenshot()
|
||||||
{
|
{
|
||||||
mImageView.setVisibility(View.VISIBLE);
|
Animations.fadeViewIn(mImageView)
|
||||||
mImageView.animate()
|
|
||||||
.withLayer()
|
|
||||||
.setDuration(100)
|
|
||||||
.alpha(1.0f)
|
|
||||||
.withEndAction(afterShowingScreenshot);
|
.withEndAction(afterShowingScreenshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -623,7 +596,7 @@ public final class EmulationActivity extends AppCompatActivity
|
|||||||
.commit();
|
.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeMenu()
|
private void removeSubMenu()
|
||||||
{
|
{
|
||||||
if (mSubmenuFragmentTag != null)
|
if (mSubmenuFragmentTag != null)
|
||||||
{
|
{
|
||||||
@ -631,14 +604,9 @@ public final class EmulationActivity extends AppCompatActivity
|
|||||||
|
|
||||||
if (fragment != null)
|
if (fragment != null)
|
||||||
{
|
{
|
||||||
// When removing a fragment without replacement, its aniimation must be done
|
// When removing a fragment without replacement, its animation must be done
|
||||||
// manually beforehand.
|
// manually beforehand.
|
||||||
fragment.getView().animate()
|
Animations.fadeViewOutToRight(fragment.getView())
|
||||||
.withLayer()
|
|
||||||
.setDuration(200)
|
|
||||||
.setInterpolator(sAccelerator)
|
|
||||||
.alpha(0.0f)
|
|
||||||
.translationX(600.0f)
|
|
||||||
.withEndAction(new Runnable()
|
.withEndAction(new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,71 @@
|
|||||||
|
package org.dolphinemu.dolphinemu.utils;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewPropertyAnimator;
|
||||||
|
import android.view.animation.AccelerateInterpolator;
|
||||||
|
import android.view.animation.DecelerateInterpolator;
|
||||||
|
import android.view.animation.Interpolator;
|
||||||
|
|
||||||
|
public final class Animations
|
||||||
|
{
|
||||||
|
private static final Interpolator DECELERATOR = new DecelerateInterpolator();
|
||||||
|
private static final Interpolator ACCELERATOR = new AccelerateInterpolator();
|
||||||
|
|
||||||
|
private Animations()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ViewPropertyAnimator fadeViewOutToRight(View view)
|
||||||
|
{
|
||||||
|
return view.animate()
|
||||||
|
.withLayer()
|
||||||
|
.setDuration(200)
|
||||||
|
.setInterpolator(ACCELERATOR)
|
||||||
|
.alpha(0.0f)
|
||||||
|
.translationX(view.getWidth());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ViewPropertyAnimator fadeViewOutToLeft(View view)
|
||||||
|
{
|
||||||
|
return view.animate()
|
||||||
|
.withLayer()
|
||||||
|
.setDuration(200)
|
||||||
|
.setInterpolator(ACCELERATOR)
|
||||||
|
.alpha(0.0f)
|
||||||
|
.translationX(-view.getWidth());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ViewPropertyAnimator fadeViewInFromLeft(View view)
|
||||||
|
{
|
||||||
|
|
||||||
|
view.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
view.setTranslationX(-view.getWidth());
|
||||||
|
view.setAlpha(0.0f);
|
||||||
|
|
||||||
|
return view.animate()
|
||||||
|
.withLayer()
|
||||||
|
.setDuration(300)
|
||||||
|
.setInterpolator(DECELERATOR)
|
||||||
|
.alpha(1.0f)
|
||||||
|
.translationX(0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ViewPropertyAnimator fadeViewIn(View view)
|
||||||
|
{
|
||||||
|
view.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
return view.animate()
|
||||||
|
.withLayer()
|
||||||
|
.setDuration(100)
|
||||||
|
.alpha(1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ViewPropertyAnimator fadeViewOut(View view)
|
||||||
|
{
|
||||||
|
return view.animate()
|
||||||
|
.withLayer()
|
||||||
|
.setDuration(300)
|
||||||
|
.alpha(0.0f);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package org.dolphinemu.dolphinemu.utils;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
|
|
||||||
|
public final class Pixels
|
||||||
|
{
|
||||||
|
private Pixels()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float convertDpToPx(float original, Context context)
|
||||||
|
{
|
||||||
|
Resources resources = context.getResources();
|
||||||
|
DisplayMetrics metrics = resources.getDisplayMetrics();
|
||||||
|
|
||||||
|
return original * metrics.density;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float convertPxToDp(float original, Context context)
|
||||||
|
{
|
||||||
|
Resources resources = context.getResources();
|
||||||
|
DisplayMetrics metrics = resources.getDisplayMetrics();
|
||||||
|
|
||||||
|
return original / metrics.density;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user