summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbodunrinwa Toki <toki@google.com>2015-06-16 15:54:24 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-06-16 15:54:26 +0000
commit98f98dd19def468afc310bd879cb79cce9917ba2 (patch)
tree0a92465862817a1edc7c5dd74bd31d675232fe40
parent209fb43376989c9a68f947d12bae3ea87e4101d2 (diff)
parentf444b5c3ae46f8790c8f2a8481fb688b00a42d3b (diff)
downloadframeworks_base-98f98dd19def468afc310bd879cb79cce9917ba2.zip
frameworks_base-98f98dd19def468afc310bd879cb79cce9917ba2.tar.gz
frameworks_base-98f98dd19def468afc310bd879cb79cce9917ba2.tar.bz2
Merge "Fix floating toolbar flickers." into mnc-dev
-rw-r--r--core/java/android/widget/Editor.java14
-rw-r--r--core/java/com/android/internal/view/FloatingActionMode.java95
2 files changed, 58 insertions, 51 deletions
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index cf6a018..f89ee91 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -244,15 +244,6 @@ public class Editor {
final CursorAnchorInfoNotifier mCursorAnchorInfoNotifier = new CursorAnchorInfoNotifier();
- private final Runnable mHideFloatingToolbar = new Runnable() {
- @Override
- public void run() {
- if (mTextActionMode != null) {
- mTextActionMode.hide(ActionMode.DEFAULT_HIDE_DURATION);
- }
- }
- };
-
private final Runnable mShowFloatingToolbar = new Runnable() {
@Override
public void run() {
@@ -389,7 +380,6 @@ public class Editor {
mTextView.removeCallbacks(mInsertionActionModeRunnable);
}
- mTextView.removeCallbacks(mHideFloatingToolbar);
mTextView.removeCallbacks(mShowFloatingToolbar);
destroyDisplayListsData();
@@ -1248,14 +1238,12 @@ public class Editor {
private void hideFloatingToolbar() {
if (mTextActionMode != null) {
mTextView.removeCallbacks(mShowFloatingToolbar);
- // Delay the "hide" a little bit just in case a "show" will happen almost immediately.
- mTextView.postDelayed(mHideFloatingToolbar, 100);
+ mTextActionMode.hide(ActionMode.DEFAULT_HIDE_DURATION);
}
}
private void showFloatingToolbar() {
if (mTextActionMode != null) {
- mTextView.removeCallbacks(mHideFloatingToolbar);
// Delay "show" so it doesn't interfere with click confirmations
// or double-clicks that could "dismiss" the floating toolbar.
int delay = ViewConfiguration.getDoubleTapTimeout();
diff --git a/core/java/com/android/internal/view/FloatingActionMode.java b/core/java/com/android/internal/view/FloatingActionMode.java
index 661dce1..99c1277 100644
--- a/core/java/com/android/internal/view/FloatingActionMode.java
+++ b/core/java/com/android/internal/view/FloatingActionMode.java
@@ -48,12 +48,14 @@ public class FloatingActionMode extends ActionMode {
private final Runnable mMovingOff = new Runnable() {
public void run() {
mFloatingToolbarVisibilityHelper.setMoving(false);
+ mFloatingToolbarVisibilityHelper.updateToolbarVisibility();
}
};
private final Runnable mHideOff = new Runnable() {
public void run() {
mFloatingToolbarVisibilityHelper.setHideRequested(false);
+ mFloatingToolbarVisibilityHelper.updateToolbarVisibility();
}
};
@@ -87,6 +89,7 @@ public class FloatingActionMode extends ActionMode {
}
});
mFloatingToolbarVisibilityHelper = new FloatingToolbarVisibilityHelper(mFloatingToolbar);
+ mFloatingToolbarVisibilityHelper.activate();
}
@Override
@@ -108,8 +111,7 @@ public class FloatingActionMode extends ActionMode {
public void invalidate() {
checkToolbarInitialized();
mCallback.onPrepareActionMode(this, mMenu);
- mFloatingToolbar.updateLayout();
- invalidateContentRect();
+ invalidateContentRect(); // Will re-layout and show the toolbar if necessary.
}
@Override
@@ -131,44 +133,43 @@ public class FloatingActionMode extends ActionMode {
mContentRectOnWindow.set(mContentRect);
mContentRectOnWindow.offset(mViewPosition[0], mViewPosition[1]);
- // Make sure that content rect is not out of the view's visible bounds.
- mContentRectOnWindow.set(
- Math.max(mContentRectOnWindow.left, mViewRect.left),
- Math.max(mContentRectOnWindow.top, mViewRect.top),
- Math.min(mContentRectOnWindow.right, mViewRect.right),
- Math.min(mContentRectOnWindow.bottom, mViewRect.bottom));
-
- if (!mContentRectOnWindow.equals(mPreviousContentRectOnWindow)) {
- if (!mPreviousContentRectOnWindow.isEmpty()) {
- notifyContentRectMoving();
- }
- mFloatingToolbar.setContentRect(mContentRectOnWindow);
- mFloatingToolbar.updateLayout();
- }
- mPreviousContentRectOnWindow.set(mContentRectOnWindow);
if (isContentRectWithinBounds()) {
mFloatingToolbarVisibilityHelper.setOutOfBounds(false);
+ // Make sure that content rect is not out of the view's visible bounds.
+ mContentRectOnWindow.set(
+ Math.max(mContentRectOnWindow.left, mViewRect.left),
+ Math.max(mContentRectOnWindow.top, mViewRect.top),
+ Math.min(mContentRectOnWindow.right, mViewRect.right),
+ Math.min(mContentRectOnWindow.bottom, mViewRect.bottom));
+
+ if (!mContentRectOnWindow.equals(mPreviousContentRectOnWindow)) {
+ // Content rect is moving.
+ mOriginatingView.removeCallbacks(mMovingOff);
+ mFloatingToolbarVisibilityHelper.setMoving(true);
+ mOriginatingView.postDelayed(mMovingOff, MOVING_HIDE_DELAY);
+
+ mFloatingToolbar.setContentRect(mContentRectOnWindow);
+ mFloatingToolbar.updateLayout();
+ }
} else {
mFloatingToolbarVisibilityHelper.setOutOfBounds(true);
+ mContentRectOnWindow.setEmpty();
}
- }
+ mFloatingToolbarVisibilityHelper.updateToolbarVisibility();
- private boolean isContentRectWithinBounds() {
- mScreenRect.set(
- 0,
- 0,
- mContext.getResources().getDisplayMetrics().widthPixels,
- mContext.getResources().getDisplayMetrics().heightPixels);
-
- return Rect.intersects(mContentRectOnWindow, mScreenRect)
- && Rect.intersects(mContentRectOnWindow, mViewRect);
+ mPreviousContentRectOnWindow.set(mContentRectOnWindow);
}
- private void notifyContentRectMoving() {
- mOriginatingView.removeCallbacks(mMovingOff);
- mFloatingToolbarVisibilityHelper.setMoving(true);
- mOriginatingView.postDelayed(mMovingOff, MOVING_HIDE_DELAY);
+ private boolean isContentRectWithinBounds() {
+ mScreenRect.set(
+ 0,
+ 0,
+ mContext.getResources().getDisplayMetrics().widthPixels,
+ mContext.getResources().getDisplayMetrics().heightPixels);
+
+ return Rect.intersects(mContentRectOnWindow, mScreenRect)
+ && Rect.intersects(mContentRectOnWindow, mViewRect);
}
@Override
@@ -184,6 +185,7 @@ public class FloatingActionMode extends ActionMode {
mHideOff.run();
} else {
mFloatingToolbarVisibilityHelper.setHideRequested(true);
+ mFloatingToolbarVisibilityHelper.updateToolbarVisibility();
mOriginatingView.postDelayed(mHideOff, duration);
}
}
@@ -221,7 +223,7 @@ public class FloatingActionMode extends ActionMode {
}
/**
- * @throws IlllegalStateException
+ * @throws IllegalStateException
*/
private void checkToolbarInitialized() {
Preconditions.checkState(mFloatingToolbar != null);
@@ -229,13 +231,14 @@ public class FloatingActionMode extends ActionMode {
}
private void reset() {
+ mFloatingToolbarVisibilityHelper.deactivate();
mOriginatingView.removeCallbacks(mMovingOff);
mOriginatingView.removeCallbacks(mHideOff);
}
/**
- * A helper that shows/hides the floating toolbar depending on certain states.
+ * A helper for showing/hiding the floating toolbar depending on certain states.
*/
private static final class FloatingToolbarVisibilityHelper {
@@ -245,29 +248,45 @@ public class FloatingActionMode extends ActionMode {
private boolean mMoving;
private boolean mOutOfBounds;
+ private boolean mActive;
+
public FloatingToolbarVisibilityHelper(FloatingToolbar toolbar) {
mToolbar = Preconditions.checkNotNull(toolbar);
}
+ public void activate() {
+ mHideRequested = false;
+ mMoving = false;
+ mOutOfBounds = false;
+
+ mActive = true;
+ }
+
+ public void deactivate() {
+ mActive = false;
+ mToolbar.dismiss();
+ }
+
public void setHideRequested(boolean hide) {
mHideRequested = hide;
- updateToolbarVisibility();
}
public void setMoving(boolean moving) {
mMoving = moving;
- updateToolbarVisibility();
}
public void setOutOfBounds(boolean outOfBounds) {
mOutOfBounds = outOfBounds;
- updateToolbarVisibility();
}
- private void updateToolbarVisibility() {
+ public void updateToolbarVisibility() {
+ if (!mActive) {
+ return;
+ }
+
if (mHideRequested || mMoving || mOutOfBounds) {
mToolbar.hide();
- } else if (mToolbar.isHidden()) {
+ } else {
mToolbar.show();
}
}