am e46094c4: am 84005b40: Merge "Use hint text to position handle / floating tool bar popups" into mnc-dev

* commit 'e46094c4388412f996292af73acb0b9fda99ffcd':
  Use hint text to position handle / floating tool bar popups
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index 7c4ff18..96e033a 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -1683,8 +1683,7 @@
             return;
         }
 
-        Layout layout = mTextView.getLayout();
-        Layout hintLayout = mTextView.getHintLayout();
+        Layout layout = getActiveLayout();
         final int offset = mTextView.getSelectionStart();
         final int line = layout.getLineForOffset(offset);
         final int top = layout.getLineTop(line);
@@ -1699,8 +1698,7 @@
         }
 
         boolean clamped = layout.shouldClampCursor(line);
-        updateCursorPosition(0, top, middle,
-                getPrimaryHorizontal(layout, hintLayout, offset, clamped));
+        updateCursorPosition(0, top, middle, layout.getPrimaryHorizontal(offset, clamped));
 
         if (mCursorCount == 2) {
             updateCursorPosition(1, middle, bottom,
@@ -1708,17 +1706,6 @@
         }
     }
 
-    private float getPrimaryHorizontal(Layout layout, Layout hintLayout, int offset,
-            boolean clamped) {
-        if (TextUtils.isEmpty(layout.getText()) &&
-                hintLayout != null &&
-                !TextUtils.isEmpty(hintLayout.getText())) {
-            return hintLayout.getPrimaryHorizontal(offset, clamped);
-        } else {
-            return layout.getPrimaryHorizontal(offset, clamped);
-        }
-    }
-
     /**
      * Start an Insertion action mode.
      */
@@ -3311,14 +3298,15 @@
                                 + mHandleHeight);
             } else {
                 // We have a single cursor.
-                int line = mTextView.getLayout().getLineForOffset(mTextView.getSelectionStart());
+                Layout layout = getActiveLayout();
+                int line = layout.getLineForOffset(mTextView.getSelectionStart());
                 float primaryHorizontal =
-                        mTextView.getLayout().getPrimaryHorizontal(mTextView.getSelectionStart());
+                        layout.getPrimaryHorizontal(mTextView.getSelectionStart());
                 mSelectionBounds.set(
                         primaryHorizontal,
-                        mTextView.getLayout().getLineTop(line),
+                        layout.getLineTop(line),
                         primaryHorizontal + 1,
-                        mTextView.getLayout().getLineTop(line + 1) + mHandleHeight);
+                        layout.getLineTop(line + 1) + mHandleHeight);
             }
             // Take TextView's padding and scroll into account.
             int textHorizontalOffset = mTextView.viewportToContentHorizontalOffset();
@@ -3684,6 +3672,7 @@
                 prepareCursorControllers();
                 return;
             }
+            layout = getActiveLayout();
 
             boolean offsetChanged = offset != mPreviousOffset;
             if (offsetChanged || parentScrolled) {
@@ -3863,6 +3852,19 @@
         public void onDetached() {}
     }
 
+    /**
+     * Returns the active layout (hint or text layout). Note that the text layout can be null.
+     */
+    private Layout getActiveLayout() {
+        Layout layout = mTextView.getLayout();
+        Layout hintLayout = mTextView.getHintLayout();
+        if (TextUtils.isEmpty(layout.getText()) && hintLayout != null &&
+                !TextUtils.isEmpty(hintLayout.getText())) {
+            layout = hintLayout;
+        }
+        return layout;
+    }
+
     private class InsertionHandleView extends HandleView {
         private static final int DELAY_BEFORE_HANDLE_FADES_OUT = 4000;
         private static final int RECENT_CUT_COPY_DURATION = 15 * 1000; // seconds