diff options
author | Justin Klaassen <justinklaassen@google.com> | 2018-01-03 13:39:41 -0500 |
---|---|---|
committer | Justin Klaassen <justinklaassen@google.com> | 2018-01-03 13:39:41 -0500 |
commit | 98fe7819c6d14f4f464a5cac047f9e82dee5da58 (patch) | |
tree | a6b8b93eb21e205b27590ab5e2a1fb9efe27f892 /android/widget | |
parent | 4217cf85c20565a3446a662a7f07f26137b26b7f (diff) | |
download | android-28-98fe7819c6d14f4f464a5cac047f9e82dee5da58.tar.gz |
Import Android SDK Platform P [4524038]
/google/data/ro/projects/android/fetch_artifact \
--bid 4524038 \
--target sdk_phone_armv7-win_sdk \
sdk-repo-linux-sources-4524038.zip
AndroidVersion.ApiLevel has been modified to appear as 28
Change-Id: Ic193bf1cf0cae78d4f2bfb4fbddfe42025c5c3c2
Diffstat (limited to 'android/widget')
-rw-r--r-- | android/widget/DatePicker.java | 5 | ||||
-rw-r--r-- | android/widget/EditText.java | 5 | ||||
-rw-r--r-- | android/widget/Editor.java | 123 | ||||
-rw-r--r-- | android/widget/GridLayout.java | 10 | ||||
-rw-r--r-- | android/widget/GridView.java | 7 | ||||
-rw-r--r-- | android/widget/LinearLayout.java | 13 | ||||
-rw-r--r-- | android/widget/Magnifier.java | 2 | ||||
-rw-r--r-- | android/widget/NumberPicker.java | 13 | ||||
-rw-r--r-- | android/widget/SelectionActionModeHelper.java | 70 | ||||
-rw-r--r-- | android/widget/TextClock.java | 24 | ||||
-rw-r--r-- | android/widget/TextView.java | 39 | ||||
-rw-r--r-- | android/widget/TextViewMetrics.java | 25 | ||||
-rw-r--r-- | android/widget/TimePicker.java | 5 | ||||
-rw-r--r-- | android/widget/Toast.java | 8 |
14 files changed, 232 insertions, 117 deletions
diff --git a/android/widget/DatePicker.java b/android/widget/DatePicker.java index dfb36423..b2b93faf 100644 --- a/android/widget/DatePicker.java +++ b/android/widget/DatePicker.java @@ -107,7 +107,10 @@ public class DatePicker extends FrameLayout { public static final int MODE_CALENDAR = 2; /** @hide */ - @IntDef({MODE_SPINNER, MODE_CALENDAR}) + @IntDef(prefix = { "MODE_" }, value = { + MODE_SPINNER, + MODE_CALENDAR + }) @Retention(RetentionPolicy.SOURCE) public @interface DatePickerMode {} diff --git a/android/widget/EditText.java b/android/widget/EditText.java index 56c3e4a5..336c20cd 100644 --- a/android/widget/EditText.java +++ b/android/widget/EditText.java @@ -105,6 +105,11 @@ public class EditText extends TextView { @Override public Editable getText() { + CharSequence text = super.getText(); + if (text instanceof Editable) { + return (Editable) super.getText(); + } + super.setText(text, BufferType.EDITABLE); return (Editable) super.getText(); } diff --git a/android/widget/Editor.java b/android/widget/Editor.java index 05cba1e5..05d18d18 100644 --- a/android/widget/Editor.java +++ b/android/widget/Editor.java @@ -41,7 +41,6 @@ import android.graphics.Rect; import android.graphics.RectF; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; -import android.metrics.LogMaker; import android.os.Bundle; import android.os.LocaleList; import android.os.Parcel; @@ -108,6 +107,7 @@ import android.view.inputmethod.ExtractedTextRequest; import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputMethodManager; import android.view.textclassifier.TextClassification; +import android.view.textclassifier.TextLinks; import android.widget.AdapterView.OnItemClickListener; import android.widget.TextView.Drawables; import android.widget.TextView.OnEditorActionListener; @@ -175,6 +175,13 @@ public class Editor { int SELECTION_END = 2; } + @IntDef({TextActionMode.SELECTION, TextActionMode.INSERTION, TextActionMode.TEXT_LINK}) + @interface TextActionMode { + int SELECTION = 0; + int INSERTION = 1; + int TEXT_LINK = 2; + } + // Each Editor manages its own undo stack. private final UndoManager mUndoManager = new UndoManager(); private UndoOwner mUndoOwner = mUndoManager.getOwner(UNDO_OWNER_TAG, this); @@ -545,7 +552,8 @@ public class Editor { chooseSize(mErrorPopup, mError, tv); tv.setText(mError); - mErrorPopup.showAsDropDown(mTextView, getErrorX(), getErrorY()); + mErrorPopup.showAsDropDown(mTextView, getErrorX(), getErrorY(), + Gravity.TOP | Gravity.LEFT); mErrorPopup.fixDirection(mErrorPopup.isAboveAnchor()); } @@ -2053,7 +2061,7 @@ public class Editor { stopTextActionMode(); ActionMode.Callback actionModeCallback = - new TextActionModeCallback(false /* hasSelection */); + new TextActionModeCallback(TextActionMode.INSERTION); mTextActionMode = mTextView.startActionMode( actionModeCallback, ActionMode.TYPE_FLOATING); if (mTextActionMode != null && getInsertionController() != null) { @@ -2079,7 +2087,23 @@ public class Editor { * Asynchronously starts a selection action mode using the TextClassifier. */ void startSelectionActionModeAsync(boolean adjustSelection) { - getSelectionActionModeHelper().startActionModeAsync(adjustSelection); + getSelectionActionModeHelper().startSelectionActionModeAsync(adjustSelection); + } + + void startLinkActionModeAsync(TextLinks.TextLink link) { + Preconditions.checkNotNull(link); + if (!(mTextView.getText() instanceof Spannable)) { + return; + } + Spannable text = (Spannable) mTextView.getText(); + stopTextActionMode(); + if (mTextView.isTextSelectable()) { + Selection.setSelection((Spannable) text, link.getStart(), link.getEnd()); + } else { + //TODO: Nonselectable text + } + + getSelectionActionModeHelper().startLinkActionModeAsync(link); } /** @@ -2145,7 +2169,7 @@ public class Editor { return true; } - boolean startSelectionActionModeInternal() { + boolean startActionModeInternal(@TextActionMode int actionMode) { if (extractedTextModeWillBeStarted()) { return false; } @@ -2159,8 +2183,7 @@ public class Editor { return false; } - ActionMode.Callback actionModeCallback = - new TextActionModeCallback(true /* hasSelection */); + ActionMode.Callback actionModeCallback = new TextActionModeCallback(actionMode); mTextActionMode = mTextView.startActionMode(actionModeCallback, ActionMode.TYPE_FLOATING); final boolean selectionStarted = mTextActionMode != null; @@ -3828,8 +3851,9 @@ public class Editor { private final int mHandleHeight; private final Map<MenuItem, OnClickListener> mAssistClickHandlers = new HashMap<>(); - public TextActionModeCallback(boolean hasSelection) { - mHasSelection = hasSelection; + TextActionModeCallback(@TextActionMode int mode) { + mHasSelection = mode == TextActionMode.SELECTION + || (mTextIsSelectable && mode == TextActionMode.TEXT_LINK); if (mHasSelection) { SelectionModifierCursorController selectionController = getSelectionController(); if (selectionController.mStartHandle == null) { @@ -3982,31 +4006,39 @@ public class Editor { } final TextClassification textClassification = getSelectionActionModeHelper().getTextClassification(); - final int count = textClassification != null ? textClassification.getActionCount() : 0; + if (textClassification == null) { + return; + } + if (isValidAssistMenuItem( + textClassification.getIcon(), + textClassification.getLabel(), + textClassification.getOnClickListener(), + textClassification.getIntent())) { + final MenuItem item = menu.add( + TextView.ID_ASSIST, TextView.ID_ASSIST, MENU_ITEM_ORDER_ASSIST, + textClassification.getLabel()) + .setIcon(textClassification.getIcon()) + .setIntent(textClassification.getIntent()); + item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); + mAssistClickHandlers.put(item, textClassification.getOnClickListener()); + } + final int count = textClassification.getSecondaryActionsCount(); for (int i = 0; i < count; i++) { - if (!isValidAssistMenuItem(i)) { + if (!isValidAssistMenuItem( + textClassification.getSecondaryIcon(i), + textClassification.getSecondaryLabel(i), + textClassification.getSecondaryOnClickListener(i), + textClassification.getSecondaryIntent(i))) { continue; } - final int groupId = TextView.ID_ASSIST; - final int order = (i == 0) - ? MENU_ITEM_ORDER_ASSIST - : MENU_ITEM_ORDER_SECONDARY_ASSIST_ACTIONS_START + i; - final int id = (i == 0) ? TextView.ID_ASSIST : Menu.NONE; - final int showAsFlag = (i == 0) - ? MenuItem.SHOW_AS_ACTION_ALWAYS - : MenuItem.SHOW_AS_ACTION_NEVER; + final int order = MENU_ITEM_ORDER_SECONDARY_ASSIST_ACTIONS_START + i; final MenuItem item = menu.add( - groupId, id, order, textClassification.getLabel(i)) - .setIcon(textClassification.getIcon(i)) - .setIntent(textClassification.getIntent(i)); - item.setShowAsAction(showAsFlag); - mAssistClickHandlers.put(item, textClassification.getOnClickListener(i)); - if (id == TextView.ID_ASSIST) { - mMetricsLogger.write( - new LogMaker(MetricsEvent.TEXT_SELECTION_MENU_ITEM_ASSIST) - .setType(MetricsEvent.TYPE_OPEN) - .setSubtype(textClassification.getLogType())); - } + TextView.ID_ASSIST, Menu.NONE, order, + textClassification.getSecondaryLabel(i)) + .setIcon(textClassification.getSecondaryIcon(i)) + .setIntent(textClassification.getSecondaryIntent(i)); + item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); + mAssistClickHandlers.put(item, textClassification.getSecondaryOnClickListener(i)); } } @@ -4022,18 +4054,9 @@ public class Editor { } } - private boolean isValidAssistMenuItem(int index) { - final TextClassification textClassification = - getSelectionActionModeHelper().getTextClassification(); - if (!mTextView.isDeviceProvisioned() || textClassification == null - || index < 0 || index >= textClassification.getActionCount()) { - return false; - } - final Drawable icon = textClassification.getIcon(index); - final CharSequence label = textClassification.getLabel(index); + private boolean isValidAssistMenuItem( + Drawable icon, CharSequence label, OnClickListener onClick, Intent intent) { final boolean hasUi = icon != null || !TextUtils.isEmpty(label); - final OnClickListener onClick = textClassification.getOnClickListener(index); - final Intent intent = textClassification.getIntent(index); final boolean hasAction = onClick != null || isSupportedIntent(intent); return hasUi && hasAction; } @@ -4079,11 +4102,6 @@ public class Editor { if (onClickListener != null) { onClickListener.onClick(mTextView); stopTextActionMode(); - if (assistMenuItem.getItemId() == TextView.ID_ASSIST) { - mMetricsLogger.action( - MetricsEvent.ACTION_TEXT_SELECTION_MENU_ITEM_ASSIST, - textClassification.getLogType()); - } } // We tried our best. return true; @@ -4930,7 +4948,10 @@ public class Editor { } @Retention(RetentionPolicy.SOURCE) - @IntDef({HANDLE_TYPE_SELECTION_START, HANDLE_TYPE_SELECTION_END}) + @IntDef(prefix = { "HANDLE_TYPE_" }, value = { + HANDLE_TYPE_SELECTION_START, + HANDLE_TYPE_SELECTION_END + }) public @interface HandleType {} public static final int HANDLE_TYPE_SELECTION_START = 0; public static final int HANDLE_TYPE_SELECTION_END = 1; @@ -6135,7 +6156,11 @@ public class Editor { } @Retention(RetentionPolicy.SOURCE) - @IntDef({MERGE_EDIT_MODE_FORCE_MERGE, MERGE_EDIT_MODE_NEVER_MERGE, MERGE_EDIT_MODE_NORMAL}) + @IntDef(prefix = { "MERGE_EDIT_MODE_" }, value = { + MERGE_EDIT_MODE_FORCE_MERGE, + MERGE_EDIT_MODE_NEVER_MERGE, + MERGE_EDIT_MODE_NORMAL + }) private @interface MergeMode {} private static final int MERGE_EDIT_MODE_FORCE_MERGE = 0; private static final int MERGE_EDIT_MODE_NEVER_MERGE = 1; @@ -6594,7 +6619,7 @@ public class Editor { Editor.MENU_ITEM_ORDER_PROCESS_TEXT_INTENT_ACTIONS_START + i, getLabel(resolveInfo)) .setIntent(createProcessTextIntentForResolveInfo(resolveInfo)) - .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); + .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); } } diff --git a/android/widget/GridLayout.java b/android/widget/GridLayout.java index cbd1e0ad..012b918f 100644 --- a/android/widget/GridLayout.java +++ b/android/widget/GridLayout.java @@ -172,7 +172,10 @@ public class GridLayout extends ViewGroup { // Public constants /** @hide */ - @IntDef({HORIZONTAL, VERTICAL}) + @IntDef(prefix = { "HORIZONTAL", "VERTICAL" }, value = { + HORIZONTAL, + VERTICAL + }) @Retention(RetentionPolicy.SOURCE) public @interface Orientation {} @@ -198,7 +201,10 @@ public class GridLayout extends ViewGroup { public static final int UNDEFINED = Integer.MIN_VALUE; /** @hide */ - @IntDef({ALIGN_BOUNDS, ALIGN_MARGINS}) + @IntDef(prefix = { "ALIGN_" }, value = { + ALIGN_BOUNDS, + ALIGN_MARGINS + }) @Retention(RetentionPolicy.SOURCE) public @interface AlignmentMode {} diff --git a/android/widget/GridView.java b/android/widget/GridView.java index fcb44af6..1ec9b2f0 100644 --- a/android/widget/GridView.java +++ b/android/widget/GridView.java @@ -65,7 +65,12 @@ import java.lang.annotation.RetentionPolicy; @RemoteView public class GridView extends AbsListView { /** @hide */ - @IntDef({NO_STRETCH, STRETCH_SPACING, STRETCH_COLUMN_WIDTH, STRETCH_SPACING_UNIFORM}) + @IntDef(prefix = { "NO_STRETCH", "STRETCH_" }, value = { + NO_STRETCH, + STRETCH_SPACING, + STRETCH_COLUMN_WIDTH, + STRETCH_SPACING_UNIFORM + }) @Retention(RetentionPolicy.SOURCE) public @interface StretchMode {} diff --git a/android/widget/LinearLayout.java b/android/widget/LinearLayout.java index 380bf7ad..7ea1f1ed 100644 --- a/android/widget/LinearLayout.java +++ b/android/widget/LinearLayout.java @@ -95,13 +95,12 @@ public class LinearLayout extends ViewGroup { public static final int VERTICAL = 1; /** @hide */ - @IntDef(flag = true, - value = { - SHOW_DIVIDER_NONE, - SHOW_DIVIDER_BEGINNING, - SHOW_DIVIDER_MIDDLE, - SHOW_DIVIDER_END - }) + @IntDef(flag = true, prefix = { "SHOW_DIVIDER_" }, value = { + SHOW_DIVIDER_NONE, + SHOW_DIVIDER_BEGINNING, + SHOW_DIVIDER_MIDDLE, + SHOW_DIVIDER_END + }) @Retention(RetentionPolicy.SOURCE) public @interface DividerMode {} diff --git a/android/widget/Magnifier.java b/android/widget/Magnifier.java index bd48f455..26dfcc2d 100644 --- a/android/widget/Magnifier.java +++ b/android/widget/Magnifier.java @@ -125,7 +125,7 @@ public final class Magnifier { mView.getWidth() - mBitmap.getWidth())); final int startY = mCenterZoomCoords.y - mBitmap.getHeight() / 2; - if (startX != mPrevStartCoordsInSurface.x || startY != mPrevStartCoordsInSurface.y) { + if (xPosInView != mPrevPosInView.x || yPosInView != mPrevPosInView.y) { performPixelCopy(startX, startY); mPrevPosInView.x = xPosInView; diff --git a/android/widget/NumberPicker.java b/android/widget/NumberPicker.java index b3792806..d98b865d 100644 --- a/android/widget/NumberPicker.java +++ b/android/widget/NumberPicker.java @@ -510,7 +510,11 @@ public class NumberPicker extends LinearLayout { */ public interface OnScrollListener { /** @hide */ - @IntDef({SCROLL_STATE_IDLE, SCROLL_STATE_TOUCH_SCROLL, SCROLL_STATE_FLING}) + @IntDef(prefix = { "SCROLL_STATE_" }, value = { + SCROLL_STATE_IDLE, + SCROLL_STATE_TOUCH_SCROLL, + SCROLL_STATE_FLING + }) @Retention(RetentionPolicy.SOURCE) public @interface ScrollState {} @@ -1952,8 +1956,7 @@ public class NumberPicker extends LinearLayout { CharSequence beforeText = mInputText.getText(); if (!text.equals(beforeText.toString())) { mInputText.setText(text); - if (AccessibilityManager.getInstance(mContext).isObservedEventType( - AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED)) { + if (AccessibilityManager.getInstance(mContext).isEnabled()) { AccessibilityEvent event = AccessibilityEvent.obtain( AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED); mInputText.onInitializeAccessibilityEvent(event); @@ -2613,7 +2616,7 @@ public class NumberPicker extends LinearLayout { } private void sendAccessibilityEventForVirtualText(int eventType) { - if (AccessibilityManager.getInstance(mContext).isObservedEventType(eventType)) { + if (AccessibilityManager.getInstance(mContext).isEnabled()) { AccessibilityEvent event = AccessibilityEvent.obtain(eventType); mInputText.onInitializeAccessibilityEvent(event); mInputText.onPopulateAccessibilityEvent(event); @@ -2624,7 +2627,7 @@ public class NumberPicker extends LinearLayout { private void sendAccessibilityEventForVirtualButton(int virtualViewId, int eventType, String text) { - if (AccessibilityManager.getInstance(mContext).isObservedEventType(eventType)) { + if (AccessibilityManager.getInstance(mContext).isEnabled()) { AccessibilityEvent event = AccessibilityEvent.obtain(eventType); event.setClassName(Button.class.getName()); event.setPackageName(mContext.getPackageName()); diff --git a/android/widget/SelectionActionModeHelper.java b/android/widget/SelectionActionModeHelper.java index d0ad27af..2c6466cd 100644 --- a/android/widget/SelectionActionModeHelper.java +++ b/android/widget/SelectionActionModeHelper.java @@ -35,6 +35,7 @@ import android.util.Log; import android.view.ActionMode; import android.view.textclassifier.TextClassification; import android.view.textclassifier.TextClassifier; +import android.view.textclassifier.TextLinks; import android.view.textclassifier.TextSelection; import android.view.textclassifier.logging.SmartSelectionEventTracker; import android.view.textclassifier.logging.SmartSelectionEventTracker.SelectionEvent; @@ -97,7 +98,10 @@ public final class SelectionActionModeHelper { } } - public void startActionModeAsync(boolean adjustSelection) { + /** + * Starts Selection ActionMode. + */ + public void startSelectionActionModeAsync(boolean adjustSelection) { // Check if the smart selection should run for editable text. adjustSelection &= !mTextView.isTextEditable() || mTextView.getTextClassifier().getSettings() @@ -109,7 +113,7 @@ public final class SelectionActionModeHelper { mTextView.getSelectionEnd()); cancelAsyncTask(); if (skipTextClassification()) { - startActionMode(null); + startSelectionActionMode(null); } else { resetTextClassificationHelper(); mTextClassificationAsyncTask = new TextClassificationAsyncTask( @@ -119,8 +123,27 @@ public final class SelectionActionModeHelper { ? mTextClassificationHelper::suggestSelection : mTextClassificationHelper::classifyText, mSmartSelectSprite != null - ? this::startActionModeWithSmartSelectAnimation - : this::startActionMode) + ? this::startSelectionActionModeWithSmartSelectAnimation + : this::startSelectionActionMode) + .execute(); + } + } + + /** + * Starts Link ActionMode. + */ + public void startLinkActionModeAsync(TextLinks.TextLink textLink) { + //TODO: tracking/logging + cancelAsyncTask(); + if (skipTextClassification()) { + startLinkActionMode(null); + } else { + resetTextClassificationHelper(textLink.getStart(), textLink.getEnd()); + mTextClassificationAsyncTask = new TextClassificationAsyncTask( + mTextView, + mTextClassificationHelper.getTimeoutDuration(), + mTextClassificationHelper::classifyText, + this::startLinkActionMode) .execute(); } } @@ -200,9 +223,19 @@ public final class SelectionActionModeHelper { return noOpTextClassifier || noSelection || password; } - private void startActionMode(@Nullable SelectionResult result) { + private void startLinkActionMode(@Nullable SelectionResult result) { + startActionMode(Editor.TextActionMode.TEXT_LINK, result); + } + + private void startSelectionActionMode(@Nullable SelectionResult result) { + startActionMode(Editor.TextActionMode.SELECTION, result); + } + + private void startActionMode( + @Editor.TextActionMode int actionMode, @Nullable SelectionResult result) { final CharSequence text = getText(mTextView); - if (result != null && text instanceof Spannable) { + if (result != null && text instanceof Spannable + && (mTextView.isTextSelectable() || mTextView.isTextEditable())) { // Do not change the selection if TextClassifier should be dark launched. if (!mTextView.getTextClassifier().getSettings().isDarkLaunch()) { Selection.setSelection((Spannable) text, result.mStart, result.mEnd); @@ -211,12 +244,13 @@ public final class SelectionActionModeHelper { } else { mTextClassification = null; } - if (mEditor.startSelectionActionModeInternal()) { + if (mEditor.startActionModeInternal(actionMode)) { final SelectionModifierCursorController controller = mEditor.getSelectionController(); - if (controller != null) { + if (controller != null + && (mTextView.isTextSelectable() || mTextView.isTextEditable())) { controller.show(); } - if (result != null) { + if (result != null && actionMode == Editor.TextActionMode.SELECTION) { mSelectionTracker.onSmartSelection(result); } } @@ -224,10 +258,11 @@ public final class SelectionActionModeHelper { mTextClassificationAsyncTask = null; } - private void startActionModeWithSmartSelectAnimation(@Nullable SelectionResult result) { + private void startSelectionActionModeWithSmartSelectAnimation( + @Nullable SelectionResult result) { final Layout layout = mTextView.getLayout(); - final Runnable onAnimationEndCallback = () -> startActionMode(result); + final Runnable onAnimationEndCallback = () -> startSelectionActionMode(result); // TODO do not trigger the animation if the change included only non-printable characters final boolean didSelectionChange = result != null && (mTextView.getSelectionStart() != result.mStart @@ -386,15 +421,24 @@ public final class SelectionActionModeHelper { mTextClassificationAsyncTask = null; } - private void resetTextClassificationHelper() { + private void resetTextClassificationHelper(int selectionStart, int selectionEnd) { + if (selectionStart < 0 || selectionEnd < 0) { + // Use selection indices + selectionStart = mTextView.getSelectionStart(); + selectionEnd = mTextView.getSelectionEnd(); + } mTextClassificationHelper.init( mTextView.getContext(), mTextView.getTextClassifier(), getText(mTextView), - mTextView.getSelectionStart(), mTextView.getSelectionEnd(), + selectionStart, selectionEnd, mTextView.getTextLocales()); } + private void resetTextClassificationHelper() { + resetTextClassificationHelper(-1, -1); + } + private void cancelSmartSelectAnimation() { if (mSmartSelectSprite != null) { mSmartSelectSprite.cancelAnimation(); diff --git a/android/widget/TextClock.java b/android/widget/TextClock.java index 12790403..53318c99 100644 --- a/android/widget/TextClock.java +++ b/android/widget/TextClock.java @@ -20,6 +20,7 @@ import static android.view.ViewDebug.ExportedProperty; import static android.widget.RemoteViews.RemoteView; import android.annotation.NonNull; +import android.annotation.TestApi; import android.app.ActivityManager; import android.content.BroadcastReceiver; import android.content.ContentResolver; @@ -141,6 +142,9 @@ public class TextClock extends TextView { private boolean mShowCurrentUserTime; private ContentObserver mFormatChangeObserver; + // Used by tests to stop time change events from triggering the text update + private boolean mStopTicking; + private class FormatChangeObserver extends ContentObserver { public FormatChangeObserver(Handler handler) { @@ -163,6 +167,9 @@ public class TextClock extends TextView { private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { + if (mStopTicking) { + return; // Test disabled the clock ticks + } if (mTimeZone == null && Intent.ACTION_TIMEZONE_CHANGED.equals(intent.getAction())) { final String timeZone = intent.getStringExtra("time-zone"); createTime(timeZone); @@ -173,6 +180,9 @@ public class TextClock extends TextView { private final Runnable mTicker = new Runnable() { public void run() { + if (mStopTicking) { + return; // Test disabled the clock ticks + } onTimeChanged(); long now = SystemClock.uptimeMillis(); @@ -546,6 +556,15 @@ public class TextClock extends TextView { } } + /** + * Used by tests to stop the clock tick from updating the text. + * @hide + */ + @TestApi + public void disableClockTick() { + mStopTicking = true; + } + private void registerReceiver() { final IntentFilter filter = new IntentFilter(); @@ -570,11 +589,12 @@ public class TextClock extends TextView { mFormatChangeObserver = new FormatChangeObserver(getHandler()); } final ContentResolver resolver = getContext().getContentResolver(); + Uri uri = Settings.System.getUriFor(Settings.System.TIME_12_24); if (mShowCurrentUserTime) { - resolver.registerContentObserver(Settings.System.CONTENT_URI, true, + resolver.registerContentObserver(uri, true, mFormatChangeObserver, UserHandle.USER_ALL); } else { - resolver.registerContentObserver(Settings.System.CONTENT_URI, true, + resolver.registerContentObserver(uri, true, mFormatChangeObserver); } } diff --git a/android/widget/TextView.java b/android/widget/TextView.java index 71532a72..1e17f34a 100644 --- a/android/widget/TextView.java +++ b/android/widget/TextView.java @@ -77,6 +77,7 @@ import android.text.InputFilter; import android.text.InputType; import android.text.Layout; import android.text.ParcelableSpan; +import android.text.PremeasuredText; import android.text.Selection; import android.text.SpanWatcher; import android.text.Spannable; @@ -159,6 +160,7 @@ import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputMethodManager; import android.view.textclassifier.TextClassificationManager; import android.view.textclassifier.TextClassifier; +import android.view.textclassifier.TextLinks; import android.view.textservice.SpellCheckerSubtype; import android.view.textservice.TextServicesManager; import android.widget.RemoteViews.RemoteView; @@ -167,6 +169,7 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.util.FastMath; +import com.android.internal.util.Preconditions; import com.android.internal.widget.EditableInputConnection; import libcore.util.EmptyArray; @@ -750,7 +753,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener public static final int AUTO_SIZE_TEXT_TYPE_UNIFORM = 1; /** @hide */ - @IntDef({AUTO_SIZE_TEXT_TYPE_NONE, AUTO_SIZE_TEXT_TYPE_UNIFORM}) + @IntDef(prefix = { "AUTO_SIZE_TEXT_TYPE_" }, value = { + AUTO_SIZE_TEXT_TYPE_NONE, + AUTO_SIZE_TEXT_TYPE_UNIFORM + }) @Retention(RetentionPolicy.SOURCE) public @interface AutoSizeTextType {} // Default minimum size for auto-sizing text in scaled pixels. @@ -4861,6 +4867,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener * Sets line spacing for this TextView. Each line other than the last line will have its height * multiplied by {@code mult} and have {@code add} added to it. * + * @param add The value in pixels that should be added to each line other than the last line. + * This will be applied after the multiplier + * @param mult The value by which each line height other than the last line will be multiplied + * by * * @attr ref android.R.styleable#TextView_lineSpacingExtra * @attr ref android.R.styleable#TextView_lineSpacingMultiplier @@ -5326,7 +5336,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (imm != null) imm.restartInput(this); } else if (type == BufferType.SPANNABLE || mMovement != null) { text = mSpannableFactory.newSpannable(text); - } else if (!(text instanceof CharWrapper)) { + } else if (!(text instanceof PremeasuredText || text instanceof CharWrapper)) { text = TextUtils.stringOrSpannedString(text); } @@ -5610,10 +5620,15 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener spannable = (Spannable) text; } else { spannable = mSpannableFactory.newSpannable(text); - text = spannable; } SuggestionSpan[] spans = spannable.getSpans(0, text.length(), SuggestionSpan.class); + if (spans.length == 0) { + return text; + } else { + text = spannable; + } + for (int i = 0; i < spans.length; i++) { spannable.removeSpan(spans[i]); } @@ -10836,10 +10851,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener void sendAccessibilityEventTypeViewTextChanged(CharSequence beforeText, int fromIndex, int removedCount, int addedCount) { - if (!AccessibilityManager.getInstance(mContext).isObservedEventType( - AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED)) { - return; - } AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED); event.setFromIndex(fromIndex); @@ -11146,6 +11157,20 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** + * Starts an ActionMode for the specified TextLink. + * + * @return Whether or not we're attempting to start the action mode. + * @hide + */ + public boolean requestActionMode(@NonNull TextLinks.TextLink link) { + Preconditions.checkNotNull(link); + if (mEditor != null) { + mEditor.startLinkActionModeAsync(link); + return true; + } + return false; + } + /** * @hide */ protected void stopTextActionMode() { diff --git a/android/widget/TextViewMetrics.java b/android/widget/TextViewMetrics.java index 96d17943..738a5742 100644 --- a/android/widget/TextViewMetrics.java +++ b/android/widget/TextViewMetrics.java @@ -37,29 +37,4 @@ public final class TextViewMetrics { * Long press on TextView - drag and drop started. */ public static final int SUBTYPE_LONG_PRESS_DRAG_AND_DROP = 2; - - /** - * Assist menu item (shown or clicked) - classification: other. - */ - public static final int SUBTYPE_ASSIST_MENU_ITEM_OTHER = 0; - - /** - * Assist menu item (shown or clicked) - classification: email. - */ - public static final int SUBTYPE_ASSIST_MENU_ITEM_EMAIL = 1; - - /** - * Assist menu item (shown or clicked) - classification: phone. - */ - public static final int SUBTYPE_ASSIST_MENU_ITEM_PHONE = 2; - - /** - * Assist menu item (shown or clicked) - classification: address. - */ - public static final int SUBTYPE_ASSIST_MENU_ITEM_ADDRESS = 3; - - /** - * Assist menu item (shown or clicked) - classification: url. - */ - public static final int SUBTYPE_ASSIST_MENU_ITEM_URL = 4; } diff --git a/android/widget/TimePicker.java b/android/widget/TimePicker.java index ae6881e4..cfec3f2f 100644 --- a/android/widget/TimePicker.java +++ b/android/widget/TimePicker.java @@ -77,7 +77,10 @@ public class TimePicker extends FrameLayout { public static final int MODE_CLOCK = 2; /** @hide */ - @IntDef({MODE_SPINNER, MODE_CLOCK}) + @IntDef(prefix = { "MODE_" }, value = { + MODE_SPINNER, + MODE_CLOCK + }) @Retention(RetentionPolicy.SOURCE) public @interface TimePickerMode {} diff --git a/android/widget/Toast.java b/android/widget/Toast.java index bfde6ac3..edcf209b 100644 --- a/android/widget/Toast.java +++ b/android/widget/Toast.java @@ -71,7 +71,10 @@ public class Toast { static final boolean localLOGV = false; /** @hide */ - @IntDef({LENGTH_SHORT, LENGTH_LONG}) + @IntDef(prefix = { "LENGTH_" }, value = { + LENGTH_SHORT, + LENGTH_LONG + }) @Retention(RetentionPolicy.SOURCE) public @interface Duration {} @@ -504,8 +507,7 @@ public class Toast { private void trySendAccessibilityEvent() { AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(mView.getContext()); - if (!accessibilityManager.isObservedEventType( - AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED)) { + if (!accessibilityManager.isEnabled()) { return; } // treat toasts as notifications since they are used to |