@@ -3909,6 +3909,9 @@ private void scrollLayerTo(int x, int y) {
39093909 mSelectCursorExtent .offset (dx , dy );
39103910 mSelectCursorExtentTextQuad .offset (dx , dy );
39113911 }
3912+ } else if (mHandleAlpha .getAlpha () > 0 ) {
3913+ // stop fading as we're not going to move with the layer.
3914+ mHandleAlphaAnimator .end ();
39123915 }
39133916 if (mAutoCompletePopup != null &&
39143917 mCurrentScrollingLayerId == mEditTextLayerId ) {
@@ -4490,9 +4493,7 @@ && nativeEvaluateLayersAnimations(mNativeClass)) {
44904493 }
44914494
44924495 canvas .restoreToCount (saveCount );
4493- if (mSelectingText ) {
4494- drawTextSelectionHandles (canvas );
4495- }
4496+ drawTextSelectionHandles (canvas );
44964497
44974498 if (extras == DRAW_EXTRAS_CURSOR_RING ) {
44984499 if (mTouchMode == TOUCH_SHORTPRESS_START_MODE ) {
@@ -4730,6 +4731,9 @@ int getBaseLayer() {
47304731 }
47314732
47324733 private void onZoomAnimationStart () {
4734+ if (!mSelectingText && mHandleAlpha .getAlpha () > 0 ) {
4735+ mHandleAlphaAnimator .end ();
4736+ }
47334737 }
47344738
47354739 private void onZoomAnimationEnd () {
@@ -4760,6 +4764,36 @@ void onFixedLengthZoomAnimationEnd() {
47604764 private final DrawFilter mScrollFilter =
47614765 new PaintFlagsDrawFilter (SCROLL_BITS , 0 );
47624766
4767+ private class SelectionHandleAlpha {
4768+ private int mAlpha = 0 ;
4769+ public void setAlpha (int alpha ) {
4770+ mAlpha = alpha ;
4771+ if (mSelectHandleCenter != null ) {
4772+ mSelectHandleCenter .setAlpha (alpha );
4773+ mSelectHandleLeft .setAlpha (alpha );
4774+ mSelectHandleRight .setAlpha (alpha );
4775+ // TODO: Use partial invalidate
4776+ invalidate ();
4777+ }
4778+ }
4779+
4780+ public int getAlpha () {
4781+ return mAlpha ;
4782+ }
4783+
4784+ }
4785+
4786+ private void startSelectingText () {
4787+ mSelectingText = true ;
4788+ mHandleAlphaAnimator .setIntValues (255 );
4789+ mHandleAlphaAnimator .start ();
4790+ }
4791+ private void endSelectingText () {
4792+ mSelectingText = false ;
4793+ mHandleAlphaAnimator .setIntValues (0 );
4794+ mHandleAlphaAnimator .start ();
4795+ }
4796+
47634797 private void ensureSelectionHandles () {
47644798 if (mSelectHandleCenter == null ) {
47654799 mSelectHandleCenter = mContext .getResources ().getDrawable (
@@ -4768,6 +4802,7 @@ private void ensureSelectionHandles() {
47684802 com .android .internal .R .drawable .text_select_handle_left );
47694803 mSelectHandleRight = mContext .getResources ().getDrawable (
47704804 com .android .internal .R .drawable .text_select_handle_right );
4805+ mHandleAlpha .setAlpha (mHandleAlpha .getAlpha ());
47714806 mSelectHandleCenterOffset = new Point (0 ,
47724807 -mSelectHandleCenter .getIntrinsicHeight ());
47734808 mSelectHandleLeftOffset = new Point (0 ,
@@ -4779,31 +4814,40 @@ private void ensureSelectionHandles() {
47794814 }
47804815
47814816 private void drawTextSelectionHandles (Canvas canvas ) {
4817+ if (mHandleAlpha .getAlpha () == 0 ) {
4818+ return ;
4819+ }
47824820 ensureSelectionHandles ();
4783- int [] handles = new int [4 ];
4784- getSelectionHandles (handles );
4785- int start_x = contentToViewDimension (handles [0 ]);
4786- int start_y = contentToViewDimension (handles [1 ]);
4787- int end_x = contentToViewDimension (handles [2 ]);
4788- int end_y = contentToViewDimension (handles [3 ]);
4821+ if (mSelectingText ) {
4822+ int [] handles = new int [4 ];
4823+ getSelectionHandles (handles );
4824+ int start_x = contentToViewDimension (handles [0 ]);
4825+ int start_y = contentToViewDimension (handles [1 ]);
4826+ int end_x = contentToViewDimension (handles [2 ]);
4827+ int end_y = contentToViewDimension (handles [3 ]);
4828+
4829+ if (mIsCaretSelection ) {
4830+ // Caret handle is centered
4831+ start_x -= (mSelectHandleCenter .getIntrinsicWidth () / 2 );
4832+ mSelectHandleCenter .setBounds (start_x , start_y ,
4833+ start_x + mSelectHandleCenter .getIntrinsicWidth (),
4834+ start_y + mSelectHandleCenter .getIntrinsicHeight ());
4835+ } else {
4836+ // Magic formula copied from TextView
4837+ start_x -= (mSelectHandleLeft .getIntrinsicWidth () * 3 ) / 4 ;
4838+ mSelectHandleLeft .setBounds (start_x , start_y ,
4839+ start_x + mSelectHandleLeft .getIntrinsicWidth (),
4840+ start_y + mSelectHandleLeft .getIntrinsicHeight ());
4841+ end_x -= mSelectHandleRight .getIntrinsicWidth () / 4 ;
4842+ mSelectHandleRight .setBounds (end_x , end_y ,
4843+ end_x + mSelectHandleRight .getIntrinsicWidth (),
4844+ end_y + mSelectHandleRight .getIntrinsicHeight ());
4845+ }
4846+ }
47894847
47904848 if (mIsCaretSelection ) {
4791- // Caret handle is centered
4792- start_x -= (mSelectHandleCenter .getIntrinsicWidth () / 2 );
4793- mSelectHandleCenter .setBounds (start_x , start_y ,
4794- start_x + mSelectHandleCenter .getIntrinsicWidth (),
4795- start_y + mSelectHandleCenter .getIntrinsicHeight ());
47964849 mSelectHandleCenter .draw (canvas );
47974850 } else {
4798- // Magic formula copied from TextView
4799- start_x -= (mSelectHandleLeft .getIntrinsicWidth () * 3 ) / 4 ;
4800- mSelectHandleLeft .setBounds (start_x , start_y ,
4801- start_x + mSelectHandleLeft .getIntrinsicWidth (),
4802- start_y + mSelectHandleLeft .getIntrinsicHeight ());
4803- end_x -= mSelectHandleRight .getIntrinsicWidth () / 4 ;
4804- mSelectHandleRight .setBounds (end_x , end_y ,
4805- end_x + mSelectHandleRight .getIntrinsicWidth (),
4806- end_y + mSelectHandleRight .getIntrinsicHeight ());
48074851 mSelectHandleLeft .draw (canvas );
48084852 mSelectHandleRight .draw (canvas );
48094853 }
@@ -5457,7 +5501,7 @@ private boolean setupWebkitSelect() {
54575501 selectionDone ();
54585502 return false ;
54595503 }
5460- mSelectingText = true ;
5504+ startSelectingText () ;
54615505 mTouchMode = TOUCH_DRAG_MODE ;
54625506 return true ;
54635507 }
@@ -5511,7 +5555,7 @@ public void selectAll() {
55115555 void selectionDone () {
55125556 if (mSelectingText ) {
55135557 hidePasteButton ();
5514- mSelectingText = false ;
5558+ endSelectingText () ;
55155559 // finish is idempotent, so this is fine even if selectionDone was
55165560 // called by mSelectCallback.onDestroyActionMode
55175561 if (mSelectCallback != null ) {
@@ -6643,6 +6687,9 @@ public boolean onGenericMotionEvent(MotionEvent event) {
66436687 private long mTrackballUpTime = 0 ;
66446688 private long mLastCursorTime = 0 ;
66456689 private Rect mLastCursorBounds ;
6690+ private SelectionHandleAlpha mHandleAlpha = new SelectionHandleAlpha ();
6691+ private ObjectAnimator mHandleAlphaAnimator =
6692+ ObjectAnimator .ofInt (mHandleAlpha , "alpha" , 0 );
66466693
66476694 // Set by default; BrowserActivity clears to interpret trackball data
66486695 // directly for movement. Currently, the framework only passes
0 commit comments