Browse Source

Fixing some animation bugs

master
Anthony Restaino 9 years ago
parent
commit
3833fdb449
  1. 27
      app/src/main/java/acr/browser/lightning/activity/TabsManager.java
  2. 5
      app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java
  3. 24
      app/src/main/java/acr/browser/lightning/fragment/anim/HorizontalItemAnimator.java
  4. 23
      app/src/main/java/acr/browser/lightning/fragment/anim/VerticalItemAnimator.java

27
app/src/main/java/acr/browser/lightning/activity/TabsManager.java

@ -24,11 +24,11 @@ import acr.browser.lightning.R;
import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.react.Action; import acr.browser.lightning.react.Action;
import acr.browser.lightning.react.Observable;
import acr.browser.lightning.react.OnSubscribe; import acr.browser.lightning.react.OnSubscribe;
import acr.browser.lightning.react.Subscriber;
import acr.browser.lightning.react.Schedulers; import acr.browser.lightning.react.Schedulers;
import acr.browser.lightning.react.Subscriber;
import acr.browser.lightning.utils.FileUtils; import acr.browser.lightning.utils.FileUtils;
import acr.browser.lightning.react.Observable;
import acr.browser.lightning.view.LightningView; import acr.browser.lightning.view.LightningView;
/** /**
@ -308,6 +308,8 @@ public class TabsManager {
* will switch the current tab to a new valid tab. * will switch the current tab to a new valid tab.
* *
* @param position the position of the tab to delete. * @param position the position of the tab to delete.
* @return returns true if the current tab
* was deleted, false otherwise.
*/ */
public synchronized boolean deleteTab(int position) { public synchronized boolean deleteTab(int position) {
Log.d(TAG, "Delete tab: " + position); Log.d(TAG, "Delete tab: " + position);
@ -319,22 +321,17 @@ public class TabsManager {
mCurrentTab = null; mCurrentTab = null;
} else if (current < size() - 1) { } else if (current < size() - 1) {
// There is another tab after this one // There is another tab after this one
mCurrentTab = getTabAtPosition(current + 1); switchToTab(current + 1);
} else { } else {
mCurrentTab = getTabAtPosition(current - 1); switchToTab(current - 1);
}
removeTab(current);
if (mTabNumberListener != null) {
mTabNumberListener.tabNumberChanged(size());
} }
return true;
} else {
removeTab(position);
if (mTabNumberListener != null) {
mTabNumberListener.tabNumberChanged(size());
}
return false;
} }
removeTab(position);
if (mTabNumberListener != null) {
mTabNumberListener.tabNumberChanged(size());
}
return current == position;
} }
/** /**

5
app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java

@ -99,7 +99,10 @@ public class BrowserPresenter {
mView.setForwardButtonEnabled(newTab.canGoForward()); mView.setForwardButtonEnabled(newTab.canGoForward());
mView.updateUrl(newTab.getUrl(), true); mView.updateUrl(newTab.getUrl(), true);
mView.setTabView(newTab.getWebView()); mView.setTabView(newTab.getWebView());
mView.notifyTabViewChanged(mTabsModel.indexOfTab(newTab)); int index = mTabsModel.indexOfTab(newTab);
if (index >= 0) {
mView.notifyTabViewChanged(mTabsModel.indexOfTab(newTab));
}
} }
} }

24
app/src/main/java/acr/browser/lightning/fragment/anim/HorizontalItemAnimator.java

@ -22,7 +22,10 @@ import android.support.v4.view.ViewPropertyAnimatorListener;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder; import android.support.v7.widget.RecyclerView.ViewHolder;
import android.support.v7.widget.SimpleItemAnimator; import android.support.v7.widget.SimpleItemAnimator;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -197,7 +200,8 @@ public class HorizontalItemAnimator extends SimpleItemAnimator {
final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
mRemoveAnimations.add(holder); mRemoveAnimations.add(holder);
animation.setDuration(getRemoveDuration()) animation.setDuration(getRemoveDuration())
.alpha(0).translationY(holder.itemView.getHeight()).setListener(new VpaListenerAdapter() { .alpha(0).translationY(holder.itemView.getHeight())
.setInterpolator(new AccelerateInterpolator()).setListener(new VpaListenerAdapter() {
@Override @Override
public void onAnimationStart(View view) { public void onAnimationStart(View view) {
dispatchRemoveStarting(holder); dispatchRemoveStarting(holder);
@ -207,6 +211,7 @@ public class HorizontalItemAnimator extends SimpleItemAnimator {
public void onAnimationEnd(View view) { public void onAnimationEnd(View view) {
animation.setListener(null); animation.setListener(null);
ViewCompat.setAlpha(view, 1); ViewCompat.setAlpha(view, 1);
ViewCompat.setTranslationY(view, 0);
dispatchRemoveFinished(holder); dispatchRemoveFinished(holder);
mRemoveAnimations.remove(holder); mRemoveAnimations.remove(holder);
dispatchFinishedWhenDone(); dispatchFinishedWhenDone();
@ -227,8 +232,9 @@ public class HorizontalItemAnimator extends SimpleItemAnimator {
final View view = holder.itemView; final View view = holder.itemView;
final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
mAddAnimations.add(holder); mAddAnimations.add(holder);
animation.alpha(1).translationY(0).setDuration(getAddDuration()). animation.alpha(1).translationY(0)
setListener(new VpaListenerAdapter() { .setInterpolator(new DecelerateInterpolator()).setDuration(getAddDuration())
.setListener(new VpaListenerAdapter() {
@Override @Override
public void onAnimationStart(View view) { public void onAnimationStart(View view) {
dispatchAddStarting(holder); dispatchAddStarting(holder);
@ -236,6 +242,7 @@ public class HorizontalItemAnimator extends SimpleItemAnimator {
@Override @Override
public void onAnimationCancel(View view) { public void onAnimationCancel(View view) {
ViewCompat.setTranslationY(view, 0);
ViewCompat.setAlpha(view, 1); ViewCompat.setAlpha(view, 1);
} }
@ -316,6 +323,17 @@ public class HorizontalItemAnimator extends SimpleItemAnimator {
@Override @Override
public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder, public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder,
int fromX, int fromY, int toX, int toY) { int fromX, int fromY, int toX, int toY) {
// if (oldHolder != newHolder) {
// if (oldHolder != null) {
// dispatchChangeFinished(oldHolder, true);
// }
// if (newHolder != null) {
// dispatchChangeFinished(newHolder, false);
// }
// } else if (oldHolder != null) {
// dispatchChangeFinished(oldHolder, true);
// }
// return false;
if (oldHolder == newHolder) { if (oldHolder == newHolder) {
// Don't know how to run change animations when the same view holder is re-used. // Don't know how to run change animations when the same view holder is re-used.
// run a move animation to handle position changes. // run a move animation to handle position changes.

23
app/src/main/java/acr/browser/lightning/fragment/anim/VerticalItemAnimator.java

@ -22,7 +22,10 @@ import android.support.v4.view.ViewPropertyAnimatorListener;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder; import android.support.v7.widget.RecyclerView.ViewHolder;
import android.support.v7.widget.SimpleItemAnimator; import android.support.v7.widget.SimpleItemAnimator;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -197,7 +200,8 @@ public class VerticalItemAnimator extends SimpleItemAnimator {
final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
mRemoveAnimations.add(holder); mRemoveAnimations.add(holder);
animation.setDuration(getRemoveDuration()) animation.setDuration(getRemoveDuration())
.alpha(0).translationX(-holder.itemView.getWidth() / 2).setListener(new VpaListenerAdapter() { .alpha(0).translationX(-holder.itemView.getWidth() / 2)
.setInterpolator(new AccelerateInterpolator()).setListener(new VpaListenerAdapter() {
@Override @Override
public void onAnimationStart(View view) { public void onAnimationStart(View view) {
dispatchRemoveStarting(holder); dispatchRemoveStarting(holder);
@ -207,6 +211,7 @@ public class VerticalItemAnimator extends SimpleItemAnimator {
public void onAnimationEnd(View view) { public void onAnimationEnd(View view) {
animation.setListener(null); animation.setListener(null);
ViewCompat.setAlpha(view, 1); ViewCompat.setAlpha(view, 1);
ViewCompat.setTranslationX(view, 0);
dispatchRemoveFinished(holder); dispatchRemoveFinished(holder);
mRemoveAnimations.remove(holder); mRemoveAnimations.remove(holder);
dispatchFinishedWhenDone(); dispatchFinishedWhenDone();
@ -227,8 +232,8 @@ public class VerticalItemAnimator extends SimpleItemAnimator {
final View view = holder.itemView; final View view = holder.itemView;
final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
mAddAnimations.add(holder); mAddAnimations.add(holder);
animation.alpha(1).translationX(0).setDuration(getAddDuration()). animation.alpha(1).translationX(0).setDuration(getAddDuration())
setListener(new VpaListenerAdapter() { .setInterpolator(new DecelerateInterpolator()).setListener(new VpaListenerAdapter() {
@Override @Override
public void onAnimationStart(View view) { public void onAnimationStart(View view) {
dispatchAddStarting(holder); dispatchAddStarting(holder);
@ -237,6 +242,7 @@ public class VerticalItemAnimator extends SimpleItemAnimator {
@Override @Override
public void onAnimationCancel(View view) { public void onAnimationCancel(View view) {
ViewCompat.setAlpha(view, 1); ViewCompat.setAlpha(view, 1);
ViewCompat.setTranslationX(view, 0);
} }
@Override @Override
@ -316,6 +322,17 @@ public class VerticalItemAnimator extends SimpleItemAnimator {
@Override @Override
public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder, public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder,
int fromX, int fromY, int toX, int toY) { int fromX, int fromY, int toX, int toY) {
// if (oldHolder != newHolder) {
// if (oldHolder != null) {
// dispatchChangeFinished(oldHolder, true);
// }
// if (newHolder != null) {
// dispatchChangeFinished(newHolder, false);
// }
// } else if (oldHolder != null) {
// dispatchChangeFinished(oldHolder, true);
// }
// return false;
if (oldHolder == newHolder) { if (oldHolder == newHolder) {
// Don't know how to run change animations when the same view holder is re-used. // Don't know how to run change animations when the same view holder is re-used.
// run a move animation to handle position changes. // run a move animation to handle position changes.

Loading…
Cancel
Save