diff options
author | Justin Klaassen <justinklaassen@google.com> | 2018-04-15 00:41:15 -0400 |
---|---|---|
committer | Justin Klaassen <justinklaassen@google.com> | 2018-04-15 00:41:15 -0400 |
commit | b8042fc9b036db0a6692ca853428fc6ab1e60892 (patch) | |
tree | 82669ea5d75238758e22d379a42baeada526219e /android/widget | |
parent | 4d01eeaffaa720e4458a118baa137a11614f00f7 (diff) | |
download | android-28-b8042fc9b036db0a6692ca853428fc6ab1e60892.tar.gz |
Import Android SDK Platform P [4719250]HEADmastermainandroidx-work-releaseandroidx-webkit-releaseandroidx-viewpager2-releaseandroidx-versionedparcelable-releaseandroidx-vectordrawable-releaseandroidx-transition-releaseandroidx-sqlite-releaseandroidx-sharetarget-releaseandroidx-security-security-crypto-releaseandroidx-savedstate-releaseandroidx-room-releaseandroidx-recyclerview-releaseandroidx-recyclerview-recyclerview-selection-releaseandroidx-preference-releaseandroidx-paging-releaseandroidx-paging-legacy-releaseandroidx-navigation-releaseandroidx-mediarouter-releaseandroidx-media2-releaseandroidx-media2-media2-widget-releaseandroidx-media-releaseandroidx-master-releaseandroidx-localbroadcastmanager-releaseandroidx-loader-releaseandroidx-lifecycle-releaseandroidx-jetifier-releaseandroidx-g3-releaseandroidx-fragment-releaseandroidx-exifinterface-releaseandroidx-enterprise-releaseandroidx-core-releaseandroidx-core-core-role-releaseandroidx-coordinatorlayout-releaseandroidx-concurrent-releaseandroidx-compose-releaseandroidx-collection-releaseandroidx-camerax-releaseandroidx-browser-releaseandroidx-biometric-releaseandroidx-benchmark-releaseandroidx-autofill-releaseandroidx-arch-core-releaseandroidx-appcompat-releaseandroidx-annotation-releaseandroidx-annotation-annotation-experimental-releaseandroidx-activity-releaseandroid-arch-work-releaseandroid-arch-navigation-release
/google/data/ro/projects/android/fetch_artifact \
--bid 4719250 \
--target sdk_phone_armv7-win_sdk \
sdk-repo-linux-sources-4719250.zip
AndroidVersion.ApiLevel has been modified to appear as 28
Change-Id: I9ec0a12c9251b8449dba0d86b0cfdbcca16b0a7c
Diffstat (limited to 'android/widget')
-rw-r--r-- | android/widget/Editor.java | 63 | ||||
-rw-r--r-- | android/widget/ImageView.java | 2 | ||||
-rw-r--r-- | android/widget/LinearLayout.java | 26 | ||||
-rw-r--r-- | android/widget/Magnifier.java | 18 | ||||
-rw-r--r-- | android/widget/SelectionActionModeHelper.java | 28 | ||||
-rw-r--r-- | android/widget/TextClock.java | 9 | ||||
-rw-r--r-- | android/widget/TextView.java | 33 |
7 files changed, 105 insertions, 74 deletions
diff --git a/android/widget/Editor.java b/android/widget/Editor.java index 99467265..dac100a4 100644 --- a/android/widget/Editor.java +++ b/android/widget/Editor.java @@ -39,6 +39,7 @@ import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Path; +import android.graphics.Point; import android.graphics.PointF; import android.graphics.Rect; import android.graphics.RectF; @@ -4837,14 +4838,48 @@ public class Editor { return true; } - private boolean handleOverlapsMagnifier() { - final int handleY = mContainer.getDecorViewLayoutParams().y; - final int magnifierBottomWhenAtWindowTop = - mTextView.getRootWindowInsets().getSystemWindowInsetTop() - + mMagnifierAnimator.mMagnifier.getHeight(); - return handleY <= magnifierBottomWhenAtWindowTop; + private boolean handleOverlapsMagnifier(@NonNull final HandleView handle, + @NonNull final Rect magnifierRect) { + final PopupWindow window = handle.mContainer; + if (!window.hasDecorView()) { + return false; + } + final Rect handleRect = new Rect( + window.getDecorViewLayoutParams().x, + window.getDecorViewLayoutParams().y, + window.getDecorViewLayoutParams().x + window.getContentView().getWidth(), + window.getDecorViewLayoutParams().y + window.getContentView().getHeight()); + return Rect.intersects(handleRect, magnifierRect); + } + + private @Nullable HandleView getOtherSelectionHandle() { + final SelectionModifierCursorController controller = getSelectionController(); + if (controller == null || !controller.isActive()) { + return null; + } + return controller.mStartHandle != this + ? controller.mStartHandle + : controller.mEndHandle; } + private final Magnifier.Callback mHandlesVisibilityCallback = new Magnifier.Callback() { + @Override + public void onOperationComplete() { + final Point magnifierTopLeft = mMagnifierAnimator.mMagnifier.getWindowCoords(); + if (magnifierTopLeft == null) { + return; + } + final Rect magnifierRect = new Rect(magnifierTopLeft.x, magnifierTopLeft.y, + magnifierTopLeft.x + mMagnifierAnimator.mMagnifier.getWidth(), + magnifierTopLeft.y + mMagnifierAnimator.mMagnifier.getHeight()); + setVisible(!handleOverlapsMagnifier(HandleView.this, magnifierRect)); + final HandleView otherHandle = getOtherSelectionHandle(); + if (otherHandle != null) { + otherHandle.setVisible(!handleOverlapsMagnifier(otherHandle, magnifierRect)); + } + } + }; + protected final void updateMagnifier(@NonNull final MotionEvent event) { if (mMagnifierAnimator == null) { return; @@ -4858,12 +4893,8 @@ public class Editor { mRenderCursorRegardlessTiming = true; mTextView.invalidateCursorPath(); suspendBlink(); - // Hide handle if it overlaps the magnifier. - if (handleOverlapsMagnifier()) { - setVisible(false); - } else { - setVisible(true); - } + mMagnifierAnimator.mMagnifier + .setOnOperationCompleteCallback(mHandlesVisibilityCallback); mMagnifierAnimator.show(showPosInView.x, showPosInView.y); } else { @@ -4877,6 +4908,10 @@ public class Editor { mRenderCursorRegardlessTiming = false; resumeBlink(); setVisible(true); + final HandleView otherHandle = getOtherSelectionHandle(); + if (otherHandle != null) { + otherHandle.setVisible(true); + } } } @@ -6031,7 +6066,9 @@ public class Editor { mSwitchedLines = false; final int selectionStart = mTextView.getSelectionStart(); final int selectionEnd = mTextView.getSelectionEnd(); - if (selectionStart > selectionEnd) { + if (selectionStart < 0 || selectionEnd < 0) { + Selection.removeSelection((Spannable) mTextView.getText()); + } else if (selectionStart > selectionEnd) { Selection.setSelection((Spannable) mTextView.getText(), selectionEnd, selectionStart); } diff --git a/android/widget/ImageView.java b/android/widget/ImageView.java index 4b951fa1..13729874 100644 --- a/android/widget/ImageView.java +++ b/android/widget/ImageView.java @@ -817,8 +817,6 @@ public class ImageView extends View { if (mScaleType != scaleType) { mScaleType = scaleType; - setWillNotCacheDrawing(mScaleType == ScaleType.CENTER); - requestLayout(); invalidate(); } diff --git a/android/widget/LinearLayout.java b/android/widget/LinearLayout.java index d32e93c7..40f9652c 100644 --- a/android/widget/LinearLayout.java +++ b/android/widget/LinearLayout.java @@ -217,6 +217,17 @@ public class LinearLayout extends ViewGroup { private int mLayoutDirection = View.LAYOUT_DIRECTION_UNDEFINED; + /** + * Signals that compatibility booleans have been initialized according to + * target SDK versions. + */ + private static boolean sCompatibilityDone = false; + + /** + * Behavior change in P; always remeasure weighted children, regardless of excess space. + */ + private static boolean sRemeasureWeightedChildren = true; + public LinearLayout(Context context) { this(context, null); } @@ -232,6 +243,15 @@ public class LinearLayout extends ViewGroup { public LinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); + if (!sCompatibilityDone && context != null) { + final int targetSdkVersion = context.getApplicationInfo().targetSdkVersion; + + // Older apps only remeasure non-zero children + sRemeasureWeightedChildren = targetSdkVersion >= Build.VERSION_CODES.P; + + sCompatibilityDone = true; + } + final TypedArray a = context.obtainStyledAttributes( attrs, com.android.internal.R.styleable.LinearLayout, defStyleAttr, defStyleRes); @@ -917,7 +937,8 @@ public class LinearLayout extends ViewGroup { // measurement on any children, we need to measure them now. int remainingExcess = heightSize - mTotalLength + (mAllowInconsistentMeasurement ? 0 : consumedExcessSpace); - if (skippedMeasure || totalWeight > 0.0f) { + if (skippedMeasure + || ((sRemeasureWeightedChildren || remainingExcess != 0) && totalWeight > 0.0f)) { float remainingWeightSum = mWeightSum > 0.0f ? mWeightSum : totalWeight; mTotalLength = 0; @@ -1300,7 +1321,8 @@ public class LinearLayout extends ViewGroup { // measurement on any children, we need to measure them now. int remainingExcess = widthSize - mTotalLength + (mAllowInconsistentMeasurement ? 0 : usedExcessSpace); - if (skippedMeasure || totalWeight > 0.0f) { + if (skippedMeasure + || ((sRemeasureWeightedChildren || remainingExcess != 0) && totalWeight > 0.0f)) { float remainingWeightSum = mWeightSum > 0.0f ? mWeightSum : totalWeight; maxAscent[0] = maxAscent[1] = maxAscent[2] = maxAscent[3] = -1; diff --git a/android/widget/Magnifier.java b/android/widget/Magnifier.java index 5eb66999..cb362e65 100644 --- a/android/widget/Magnifier.java +++ b/android/widget/Magnifier.java @@ -233,6 +233,17 @@ public final class Magnifier { return mZoom; } + /** + * @hide + */ + @Nullable + public Point getWindowCoords() { + if (mWindow == null) { + return null; + } + return new Point(mWindow.mLastDrawContentPositionX, mWindow.mLastDrawContentPositionY); + } + @Nullable private Surface getValidViewSurface() { // TODO: deduplicate this against the first part of #performPixelCopy @@ -374,8 +385,11 @@ public final class Magnifier { private final Runnable mMagnifierUpdater; // The handler where the magnifier updater jobs will be post'd. private final Handler mHandler; - // The callback to be run after the next draw. Only used for testing. + // The callback to be run after the next draw. private Callback mCallback; + // The position of the magnifier content when the last draw was requested. + private int mLastDrawContentPositionX; + private int mLastDrawContentPositionY; // Members below describe the state of the magnifier. Reads/writes to them // have to be synchronized between the UI thread and the thread that handles @@ -598,6 +612,8 @@ public final class Magnifier { callback = null; } + mLastDrawContentPositionX = mWindowPositionX + mOffsetX; + mLastDrawContentPositionY = mWindowPositionY + mOffsetY; mFrameDrawScheduled = false; } diff --git a/android/widget/SelectionActionModeHelper.java b/android/widget/SelectionActionModeHelper.java index b3327a70..1f2b90a1 100644 --- a/android/widget/SelectionActionModeHelper.java +++ b/android/widget/SelectionActionModeHelper.java @@ -33,9 +33,9 @@ import android.text.Spannable; import android.text.TextUtils; import android.util.Log; import android.view.ActionMode; -import android.view.textclassifier.Logger; import android.view.textclassifier.SelectionEvent; import android.view.textclassifier.SelectionEvent.InvocationMethod; +import android.view.textclassifier.SelectionSessionLogger; import android.view.textclassifier.TextClassification; import android.view.textclassifier.TextClassificationConstants; import android.view.textclassifier.TextClassificationManager; @@ -663,7 +663,6 @@ public final class SelectionActionModeHelper { private static final String LOG_TAG = "SelectionMetricsLogger"; private static final Pattern PATTERN_WHITESPACE = Pattern.compile("\\s+"); - private final Logger mLogger; private final boolean mEditTextLogger; private final BreakIterator mTokenIterator; @@ -673,10 +672,8 @@ public final class SelectionActionModeHelper { SelectionMetricsLogger(TextView textView) { Preconditions.checkNotNull(textView); - mLogger = textView.getTextClassifier().getLogger( - new Logger.Config(textView.getContext(), getWidetType(textView), null)); mEditTextLogger = textView.isTextEditable(); - mTokenIterator = mLogger.getTokenIterator(textView.getTextLocale()); + mTokenIterator = SelectionSessionLogger.getTokenIterator(textView.getTextLocale()); } @TextClassifier.WidgetType @@ -702,8 +699,6 @@ public final class SelectionActionModeHelper { } mTokenIterator.setText(mText); mStartIndex = index; - mLogger.logSelectionStartedEvent(invocationMethod, 0); - // TODO: Remove the above legacy logging. mClassificationSession = classificationSession; mClassificationSession.onSelectionEvent( SelectionEvent.createSelectionStartedEvent(invocationMethod, 0)); @@ -720,27 +715,18 @@ public final class SelectionActionModeHelper { Preconditions.checkArgumentInRange(end, start, mText.length(), "end"); int[] wordIndices = getWordDelta(start, end); if (selection != null) { - mLogger.logSelectionModifiedEvent( - wordIndices[0], wordIndices[1], selection); - // TODO: Remove the above legacy logging. if (mClassificationSession != null) { mClassificationSession.onSelectionEvent( SelectionEvent.createSelectionModifiedEvent( wordIndices[0], wordIndices[1], selection)); } } else if (classification != null) { - mLogger.logSelectionModifiedEvent( - wordIndices[0], wordIndices[1], classification); - // TODO: Remove the above legacy logging. if (mClassificationSession != null) { mClassificationSession.onSelectionEvent( SelectionEvent.createSelectionModifiedEvent( wordIndices[0], wordIndices[1], classification)); } } else { - mLogger.logSelectionModifiedEvent( - wordIndices[0], wordIndices[1]); - // TODO: Remove the above legacy logging. if (mClassificationSession != null) { mClassificationSession.onSelectionEvent( SelectionEvent.createSelectionModifiedEvent( @@ -762,18 +748,12 @@ public final class SelectionActionModeHelper { Preconditions.checkArgumentInRange(end, start, mText.length(), "end"); int[] wordIndices = getWordDelta(start, end); if (classification != null) { - mLogger.logSelectionActionEvent( - wordIndices[0], wordIndices[1], action, classification); - // TODO: Remove the above legacy logging. if (mClassificationSession != null) { mClassificationSession.onSelectionEvent( SelectionEvent.createSelectionActionEvent( wordIndices[0], wordIndices[1], action, classification)); } } else { - mLogger.logSelectionActionEvent( - wordIndices[0], wordIndices[1], action); - // TODO: Remove the above legacy logging. if (mClassificationSession != null) { mClassificationSession.onSelectionEvent( SelectionEvent.createSelectionActionEvent( @@ -989,7 +969,7 @@ public final class SelectionActionModeHelper { mHot = true; trimText(); final TextSelection selection; - if (mContext.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.O_MR1) { + if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.P) { final TextSelection.Request request = new TextSelection.Request.Builder( mTrimmedText, mRelativeStart, mRelativeEnd) .setDefaultLocales(mDefaultLocales) @@ -1043,7 +1023,7 @@ public final class SelectionActionModeHelper { trimText(); final TextClassification classification; - if (mContext.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.O_MR1) { + if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.P) { final TextClassification.Request request = new TextClassification.Request.Builder( mTrimmedText, mRelativeStart, mRelativeEnd) diff --git a/android/widget/TextClock.java b/android/widget/TextClock.java index 53318c99..d8a9ccad 100644 --- a/android/widget/TextClock.java +++ b/android/widget/TextClock.java @@ -408,6 +408,15 @@ public class TextClock extends TextView { } /** + * Update the displayed time if necessary and invalidate the view. + * @hide + */ + public void refresh() { + onTimeChanged(); + invalidate(); + } + + /** * Indicates whether the system is currently using the 24-hour mode. * * When the system is in 24-hour mode, this view will use the pattern diff --git a/android/widget/TextView.java b/android/widget/TextView.java index 11db6b65..7b9ecca0 100644 --- a/android/widget/TextView.java +++ b/android/widget/TextView.java @@ -317,7 +317,6 @@ import java.util.function.Supplier; * @attr ref android.R.styleable#TextView_autoSizeMaxTextSize * @attr ref android.R.styleable#TextView_autoSizeStepGranularity * @attr ref android.R.styleable#TextView_autoSizePresetSizes - * @attr ref android.R.styleable#TextView_accessibilityHeading */ @RemoteView public class TextView extends View implements ViewTreeObserver.OnPreDrawListener { @@ -417,7 +416,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener private int mCurTextColor; private int mCurHintTextColor; private boolean mFreezesText; - private boolean mIsAccessibilityHeading; private Editable.Factory mEditableFactory = Editable.Factory.getInstance(); private Spannable.Factory mSpannableFactory = Spannable.Factory.getInstance(); @@ -1294,8 +1292,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener case com.android.internal.R.styleable.TextView_lineHeight: lineHeight = a.getDimensionPixelSize(attr, -1); break; - case com.android.internal.R.styleable.TextView_accessibilityHeading: - mIsAccessibilityHeading = a.getBoolean(attr, false); } } @@ -5213,32 +5209,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * Gets whether this view is a heading for accessibility purposes. - * - * @return {@code true} if the view is a heading, {@code false} otherwise. - * - * @attr ref android.R.styleable#TextView_accessibilityHeading - */ - public boolean isAccessibilityHeading() { - return mIsAccessibilityHeading; - } - - /** - * Set if view is a heading for a section of content for accessibility purposes. - * - * @param isHeading {@code true} if the view is a heading, {@code false} otherwise. - * - * @attr ref android.R.styleable#TextView_accessibilityHeading - */ - public void setAccessibilityHeading(boolean isHeading) { - if (isHeading != mIsAccessibilityHeading) { - mIsAccessibilityHeading = isHeading; - notifyViewAccessibilityStateChangedIfNeeded( - AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED); - } - } - - /** * Convenience method to append the specified text to the TextView's * display buffer, upgrading it to {@link android.widget.TextView.BufferType#EDITABLE} * if it was not already editable. @@ -9380,7 +9350,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener final int selectionStart = getSelectionStart(); final int selectionEnd = getSelectionEnd(); - return selectionStart >= 0 && selectionStart != selectionEnd; + return selectionStart >= 0 && selectionEnd > 0 && selectionStart != selectionEnd; } String getSelectedText() { @@ -10833,7 +10803,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener info.setText(getTextForAccessibility()); info.setHintText(mHint); info.setShowingHintText(isShowingHint()); - info.setHeading(mIsAccessibilityHeading); if (mBufferType == BufferType.EDITABLE) { info.setEditable(true); |