Browse Source

Fixed layout bug, fixed bug slowing down recyclerview animations

master
Anthony Restaino 9 years ago
parent
commit
97a64401e8
  1. 13
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 7
      app/src/main/java/acr/browser/lightning/fragment/anim/HorizontalItemAnimator.java
  3. 7
      app/src/main/java/acr/browser/lightning/fragment/anim/VerticalItemAnimator.java

13
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -131,9 +131,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
private static final String INTENT_PANIC_TRIGGER = "info.guardianproject.panic.action.TRIGGER"; private static final String INTENT_PANIC_TRIGGER = "info.guardianproject.panic.action.TRIGGER";
// Static Layout // Static Layout
@Bind(R.id.main_layout)
View mRootLayout;
@Bind(R.id.drawer_layout) @Bind(R.id.drawer_layout)
DrawerLayout mDrawerLayout; DrawerLayout mDrawerLayout;
@ -1044,7 +1041,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
initializeTabHeight(); initializeTabHeight();
doOnLayout(mRootLayout, new Runnable() { doOnLayout(mUiLayout, new Runnable() {
@Override @Override
public void run() { public void run() {
int toolbarSize; int toolbarSize;
@ -1849,7 +1846,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
* first. * first.
*/ */
private void initializeTabHeight() { private void initializeTabHeight() {
doOnLayout(mRootLayout, new Runnable() { doOnLayout(mUiLayout, new Runnable() {
@Override @Override
public void run() { public void run() {
setTabHeight(); setTabHeight();
@ -1885,12 +1882,12 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
* laid out in order to set the correct height. * laid out in order to set the correct height.
*/ */
private void setTabHeight() { private void setTabHeight() {
if (mRootLayout.getHeight() == 0) { if (mUiLayout.getHeight() == 0) {
mRootLayout.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); mUiLayout.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
} }
if (mFullScreen) { if (mFullScreen) {
mBrowserFrame.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, mRootLayout.getHeight())); mBrowserFrame.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, mUiLayout.getHeight()));
} else { } else {
mBrowserFrame.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); mBrowserFrame.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
} }

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

@ -22,7 +22,6 @@ 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.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator; import android.view.animation.DecelerateInterpolator;
@ -262,13 +261,13 @@ public class HorizontalItemAnimator extends SimpleItemAnimator {
final View view = holder.itemView; final View view = holder.itemView;
fromX += ViewCompat.getTranslationX(holder.itemView); fromX += ViewCompat.getTranslationX(holder.itemView);
fromY += ViewCompat.getTranslationY(holder.itemView); fromY += ViewCompat.getTranslationY(holder.itemView);
resetAnimation(holder);
int deltaX = toX - fromX; int deltaX = toX - fromX;
int deltaY = toY - fromY; int deltaY = toY - fromY;
if (deltaX == 0 && deltaY == 0) { if (deltaX == 0 && deltaY == 0) {
dispatchMoveFinished(holder); dispatchMoveFinished(holder);
return false; return false;
} }
resetAnimation(holder);
if (deltaX != 0) { if (deltaX != 0) {
ViewCompat.setTranslationX(view, -deltaX); ViewCompat.setTranslationX(view, -deltaX);
} }
@ -337,6 +336,10 @@ public class HorizontalItemAnimator extends SimpleItemAnimator {
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.
if ((fromX - toX) == 0 && (fromY - toY) == 0) {
dispatchMoveFinished(oldHolder);
return false;
}
return animateMove(oldHolder, fromX, fromY, toX, toY); return animateMove(oldHolder, fromX, fromY, toX, toY);
} }
final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView); final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);

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

@ -22,7 +22,6 @@ 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.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator; import android.view.animation.DecelerateInterpolator;
@ -261,13 +260,13 @@ public class VerticalItemAnimator extends SimpleItemAnimator {
final View view = holder.itemView; final View view = holder.itemView;
fromX += ViewCompat.getTranslationX(holder.itemView); fromX += ViewCompat.getTranslationX(holder.itemView);
fromY += ViewCompat.getTranslationY(holder.itemView); fromY += ViewCompat.getTranslationY(holder.itemView);
resetAnimation(holder);
int deltaX = toX - fromX; int deltaX = toX - fromX;
int deltaY = toY - fromY; int deltaY = toY - fromY;
if (deltaX == 0 && deltaY == 0) { if (deltaX == 0 && deltaY == 0) {
dispatchMoveFinished(holder); dispatchMoveFinished(holder);
return false; return false;
} }
resetAnimation(holder);
if (deltaX != 0) { if (deltaX != 0) {
ViewCompat.setTranslationX(view, -deltaX); ViewCompat.setTranslationX(view, -deltaX);
} }
@ -336,6 +335,10 @@ public class VerticalItemAnimator extends SimpleItemAnimator {
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.
if ((fromX - toX) == 0 && (fromY - toY) == 0) {
dispatchMoveFinished(oldHolder);
return false;
}
return animateMove(oldHolder, fromX, fromY, toX, toY); return animateMove(oldHolder, fromX, fromY, toX, toY);
} }
final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView); final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);

Loading…
Cancel
Save