Merge "Make text cursor drawable public"

This commit is contained in:
Mihai Popa
2018-12-06 13:49:29 +00:00
committed by Android (Google) Code Review
3 changed files with 68 additions and 7 deletions

View File

@@ -55960,6 +55960,7 @@ package android.widget {
method public java.lang.CharSequence getText();
method public android.view.textclassifier.TextClassifier getTextClassifier();
method public final android.content.res.ColorStateList getTextColors();
method public android.graphics.drawable.Drawable getTextCursorDrawable();
method public android.text.TextDirectionHeuristic getTextDirectionHeuristic();
method public java.util.Locale getTextLocale();
method public android.os.LocaleList getTextLocales();
@@ -56090,6 +56091,8 @@ package android.widget {
method public void setTextClassifier(android.view.textclassifier.TextClassifier);
method public void setTextColor(int);
method public void setTextColor(android.content.res.ColorStateList);
method public void setTextCursorDrawable(android.graphics.drawable.Drawable);
method public void setTextCursorDrawable(int);
method public void setTextIsSelectable(boolean);
method public final void setTextKeepState(java.lang.CharSequence);
method public final void setTextKeepState(java.lang.CharSequence, android.widget.TextView.BufferType);

View File

@@ -2051,8 +2051,8 @@ public class Editor {
}
void updateCursorPosition() {
if (mTextView.mCursorDrawableRes == 0) {
mDrawableForCursor = null;
loadCursorDrawable();
if (mDrawableForCursor == null) {
return;
}
@@ -2462,10 +2462,7 @@ public class Editor {
}
private void updateCursorPosition(int top, int bottom, float horizontal) {
if (mDrawableForCursor == null) {
mDrawableForCursor = mTextView.getContext().getDrawable(
mTextView.mCursorDrawableRes);
}
loadCursorDrawable();
final int left = clampHorizontalPosition(mDrawableForCursor, horizontal);
final int width = mDrawableForCursor.getIntrinsicWidth();
mDrawableForCursor.setBounds(left, top - mTempRect.top, left + width,
@@ -5698,6 +5695,12 @@ public class Editor {
public boolean isActive();
}
void loadCursorDrawable() {
if (mDrawableForCursor == null) {
mDrawableForCursor = mTextView.getTextCursorDrawable();
}
}
private class InsertionPointCursorController implements CursorController {
private InsertionHandleView mHandle;

View File

@@ -799,8 +799,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
// Although these fields are specific to editable text, they are not added to Editor because
// they are defined by the TextView's style and are theme-dependent.
@UnsupportedAppUsage
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
int mCursorDrawableRes;
private Drawable mCursorDrawable;
// Note: this might be stale if setTextSelectHandleLeft is used. We could simplify the code
// by removing it, but we would break apps targeting <= P that use it by reflection.
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
@@ -3640,6 +3641,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
/**
* Returns the Drawable corresponding to the right handle used
* for selecting text.
* Note that any change applied to the handle Drawable will not be visible
* until the handle is hidden and then drawn again.
*
* @return the right text selection handle drawable
*
@@ -3654,6 +3657,58 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
return mTextSelectHandleRight;
}
/**
* Sets the Drawable corresponding to the text cursor. The Drawable defaults to the
* value of the textCursorDrawable attribute.
* Note that any change applied to the cursor Drawable will not be visible
* until the cursor is hidden and then drawn again.
*
* @see #setTextCursorDrawable(int)
* @attr ref android.R.styleable#TextView_textCursorDrawable
*/
public void setTextCursorDrawable(@NonNull Drawable textCursorDrawable) {
Preconditions.checkNotNull(textCursorDrawable,
"The cursor drawable should not be null.");
mCursorDrawable = textCursorDrawable;
mCursorDrawableRes = 0;
if (mEditor != null) {
mEditor.loadCursorDrawable();
}
}
/**
* Sets the Drawable corresponding to the text cursor. The Drawable defaults to the
* value of the textCursorDrawable attribute.
* Note that any change applied to the cursor Drawable will not be visible
* until the cursor is hidden and then drawn again.
*
* @see #setTextCursorDrawable(Drawable)
* @attr ref android.R.styleable#TextView_textCursorDrawable
*/
public void setTextCursorDrawable(@DrawableRes int textCursorDrawable) {
Preconditions.checkArgumentPositive(textCursorDrawable,
"The cursor drawable should be a valid drawable resource id.");
setTextCursorDrawable(mContext.getDrawable(textCursorDrawable));
}
/**
* Returns the Drawable corresponding to the text cursor.
* Note that any change applied to the cursor Drawable will not be visible
* until the cursor is hidden and then drawn again.
*
* @return the text cursor drawable
*
* @see #setTextCursorDrawable(Drawable)
* @see #setTextCursorDrawable(int)
* @attr ref android.R.styleable#TextView_textCursorDrawable
*/
@Nullable public Drawable getTextCursorDrawable() {
if (mCursorDrawable == null && mCursorDrawableRes != 0) {
mCursorDrawable = mContext.getDrawable(mCursorDrawableRes);
}
return mCursorDrawable;
}
/**
* Sets the text appearance from the specified style resource.
* <p>