@@ -3925,6 +3925,9 @@ private void scrollLayerTo(int x, int y) {
39253925 mSelectCursorExtent .offset (dx , dy );
39263926 mSelectCursorExtentTextQuad .offset (dx , dy );
39273927 }
3928+ } else if (mHandleAlpha .getAlpha () > 0 ) {
3929+ // stop fading as we're not going to move with the layer.
3930+ mHandleAlphaAnimator .end ();
39283931 }
39293932 if (mAutoCompletePopup != null &&
39303933 mCurrentScrollingLayerId == mEditTextLayerId ) {
@@ -4418,9 +4421,7 @@ && nativeEvaluateLayersAnimations(mNativeClass)) {
44184421 }
44194422
44204423 canvas .restoreToCount (saveCount );
4421- if (mSelectingText ) {
4422- drawTextSelectionHandles (canvas );
4423- }
4424+ drawTextSelectionHandles (canvas );
44244425
44254426 if (extras == DRAW_EXTRAS_CURSOR_RING ) {
44264427 if (mTouchMode == TOUCH_SHORTPRESS_START_MODE ) {
@@ -4658,6 +4659,9 @@ int getBaseLayer() {
46584659 }
46594660
46604661 private void onZoomAnimationStart () {
4662+ if (!mSelectingText && mHandleAlpha .getAlpha () > 0 ) {
4663+ mHandleAlphaAnimator .end ();
4664+ }
46614665 }
46624666
46634667 private void onZoomAnimationEnd () {
@@ -4688,6 +4692,36 @@ void onFixedLengthZoomAnimationEnd() {
46884692 private final DrawFilter mScrollFilter =
46894693 new PaintFlagsDrawFilter (SCROLL_BITS , 0 );
46904694
4695+ private class SelectionHandleAlpha {
4696+ private int mAlpha = 0 ;
4697+ public void setAlpha (int alpha ) {
4698+ mAlpha = alpha ;
4699+ if (mSelectHandleCenter != null ) {
4700+ mSelectHandleCenter .setAlpha (alpha );
4701+ mSelectHandleLeft .setAlpha (alpha );
4702+ mSelectHandleRight .setAlpha (alpha );
4703+ // TODO: Use partial invalidate
4704+ invalidate ();
4705+ }
4706+ }
4707+
4708+ public int getAlpha () {
4709+ return mAlpha ;
4710+ }
4711+
4712+ }
4713+
4714+ private void startSelectingText () {
4715+ mSelectingText = true ;
4716+ mHandleAlphaAnimator .setIntValues (255 );
4717+ mHandleAlphaAnimator .start ();
4718+ }
4719+ private void endSelectingText () {
4720+ mSelectingText = false ;
4721+ mHandleAlphaAnimator .setIntValues (0 );
4722+ mHandleAlphaAnimator .start ();
4723+ }
4724+
46914725 private void ensureSelectionHandles () {
46924726 if (mSelectHandleCenter == null ) {
46934727 mSelectHandleCenter = mContext .getResources ().getDrawable (
@@ -4696,6 +4730,7 @@ private void ensureSelectionHandles() {
46964730 com .android .internal .R .drawable .text_select_handle_left );
46974731 mSelectHandleRight = mContext .getResources ().getDrawable (
46984732 com .android .internal .R .drawable .text_select_handle_right );
4733+ mHandleAlpha .setAlpha (mHandleAlpha .getAlpha ());
46994734 mSelectHandleCenterOffset = new Point (0 ,
47004735 -mSelectHandleCenter .getIntrinsicHeight ());
47014736 mSelectHandleLeftOffset = new Point (0 ,
@@ -4707,31 +4742,40 @@ private void ensureSelectionHandles() {
47074742 }
47084743
47094744 private void drawTextSelectionHandles (Canvas canvas ) {
4745+ if (mHandleAlpha .getAlpha () == 0 ) {
4746+ return ;
4747+ }
47104748 ensureSelectionHandles ();
4711- int [] handles = new int [4 ];
4712- getSelectionHandles (handles );
4713- int start_x = contentToViewDimension (handles [0 ]);
4714- int start_y = contentToViewDimension (handles [1 ]);
4715- int end_x = contentToViewDimension (handles [2 ]);
4716- int end_y = contentToViewDimension (handles [3 ]);
4749+ if (mSelectingText ) {
4750+ int [] handles = new int [4 ];
4751+ getSelectionHandles (handles );
4752+ int start_x = contentToViewDimension (handles [0 ]);
4753+ int start_y = contentToViewDimension (handles [1 ]);
4754+ int end_x = contentToViewDimension (handles [2 ]);
4755+ int end_y = contentToViewDimension (handles [3 ]);
4756+
4757+ if (mIsCaretSelection ) {
4758+ // Caret handle is centered
4759+ start_x -= (mSelectHandleCenter .getIntrinsicWidth () / 2 );
4760+ mSelectHandleCenter .setBounds (start_x , start_y ,
4761+ start_x + mSelectHandleCenter .getIntrinsicWidth (),
4762+ start_y + mSelectHandleCenter .getIntrinsicHeight ());
4763+ } else {
4764+ // Magic formula copied from TextView
4765+ start_x -= (mSelectHandleLeft .getIntrinsicWidth () * 3 ) / 4 ;
4766+ mSelectHandleLeft .setBounds (start_x , start_y ,
4767+ start_x + mSelectHandleLeft .getIntrinsicWidth (),
4768+ start_y + mSelectHandleLeft .getIntrinsicHeight ());
4769+ end_x -= mSelectHandleRight .getIntrinsicWidth () / 4 ;
4770+ mSelectHandleRight .setBounds (end_x , end_y ,
4771+ end_x + mSelectHandleRight .getIntrinsicWidth (),
4772+ end_y + mSelectHandleRight .getIntrinsicHeight ());
4773+ }
4774+ }
47174775
47184776 if (mIsCaretSelection ) {
4719- // Caret handle is centered
4720- start_x -= (mSelectHandleCenter .getIntrinsicWidth () / 2 );
4721- mSelectHandleCenter .setBounds (start_x , start_y ,
4722- start_x + mSelectHandleCenter .getIntrinsicWidth (),
4723- start_y + mSelectHandleCenter .getIntrinsicHeight ());
47244777 mSelectHandleCenter .draw (canvas );
47254778 } else {
4726- // Magic formula copied from TextView
4727- start_x -= (mSelectHandleLeft .getIntrinsicWidth () * 3 ) / 4 ;
4728- mSelectHandleLeft .setBounds (start_x , start_y ,
4729- start_x + mSelectHandleLeft .getIntrinsicWidth (),
4730- start_y + mSelectHandleLeft .getIntrinsicHeight ());
4731- end_x -= mSelectHandleRight .getIntrinsicWidth () / 4 ;
4732- mSelectHandleRight .setBounds (end_x , end_y ,
4733- end_x + mSelectHandleRight .getIntrinsicWidth (),
4734- end_y + mSelectHandleRight .getIntrinsicHeight ());
47354779 mSelectHandleLeft .draw (canvas );
47364780 mSelectHandleRight .draw (canvas );
47374781 }
@@ -5385,7 +5429,7 @@ private boolean setupWebkitSelect() {
53855429 selectionDone ();
53865430 return false ;
53875431 }
5388- mSelectingText = true ;
5432+ startSelectingText () ;
53895433 mTouchMode = TOUCH_DRAG_MODE ;
53905434 return true ;
53915435 }
@@ -5439,7 +5483,7 @@ public void selectAll() {
54395483 void selectionDone () {
54405484 if (mSelectingText ) {
54415485 hidePasteButton ();
5442- mSelectingText = false ;
5486+ endSelectingText () ;
54435487 // finish is idempotent, so this is fine even if selectionDone was
54445488 // called by mSelectCallback.onDestroyActionMode
54455489 if (mSelectCallback != null ) {
@@ -6571,6 +6615,9 @@ public boolean onGenericMotionEvent(MotionEvent event) {
65716615 private long mTrackballUpTime = 0 ;
65726616 private long mLastCursorTime = 0 ;
65736617 private Rect mLastCursorBounds ;
6618+ private SelectionHandleAlpha mHandleAlpha = new SelectionHandleAlpha ();
6619+ private ObjectAnimator mHandleAlphaAnimator =
6620+ ObjectAnimator .ofInt (mHandleAlpha , "alpha" , 0 );
65746621
65756622 // Set by default; BrowserActivity clears to interpret trackball data
65766623 // directly for movement. Currently, the framework only passes
0 commit comments