Merge changes from topic 'highlight_fixed' into oc-dev
* changes: Check default focus highlight for ImageView. Check state_focus in foreground.
This commit is contained in:
committed by
Android (Google) Code Review
commit
759669988b
@@ -45743,6 +45743,7 @@ package android.view {
|
||||
method public boolean isAttachedToWindow();
|
||||
method public boolean isClickable();
|
||||
method public boolean isContextClickable();
|
||||
method public boolean isDefaultFocusHighlightNeeded(android.graphics.drawable.Drawable, android.graphics.drawable.Drawable);
|
||||
method public boolean isDirty();
|
||||
method public boolean isDrawingCacheEnabled();
|
||||
method public boolean isDuplicateParentStateEnabled();
|
||||
|
||||
@@ -19809,18 +19809,23 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
* Check whether we need to draw a default focus highlight when this view gets focused,
|
||||
* which requires:
|
||||
* <ul>
|
||||
* <li>In the background, {@link android.R.attr#state_focused} is not defined.</li>
|
||||
* <li>In both background and foreground, {@link android.R.attr#state_focused}
|
||||
* is not defined.</li>
|
||||
* <li>This view is not in touch mode.</li>
|
||||
* <li>This view doesn't opt out for a default focus highlight, via
|
||||
* {@link #setDefaultFocusHighlightEnabled(boolean)}.</li>
|
||||
* <li>This view is attached to window.</li>
|
||||
* </ul>
|
||||
* @return {@code true} if a default focus highlight is needed.
|
||||
* @hide
|
||||
*/
|
||||
private boolean isDefaultFocusHighlightNeeded(Drawable background) {
|
||||
final boolean hasFocusStateSpecified = background == null || !background.isStateful()
|
||||
|| !background.hasFocusStateSpecified();
|
||||
return !isInTouchMode() && getDefaultFocusHighlightEnabled() && hasFocusStateSpecified
|
||||
@TestApi
|
||||
public boolean isDefaultFocusHighlightNeeded(Drawable background, Drawable foreground) {
|
||||
final boolean lackFocusState = (background == null || !background.isStateful()
|
||||
|| !background.hasFocusStateSpecified())
|
||||
&& (foreground == null || !foreground.isStateful()
|
||||
|| !foreground.hasFocusStateSpecified());
|
||||
return !isInTouchMode() && getDefaultFocusHighlightEnabled() && lackFocusState
|
||||
&& isAttachedToWindow() && sUseDefaultFocusHighlight;
|
||||
}
|
||||
|
||||
@@ -19832,7 +19837,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
*/
|
||||
private void switchDefaultFocusHighlight() {
|
||||
if (isFocused()) {
|
||||
final boolean needed = isDefaultFocusHighlightNeeded(mBackground);
|
||||
final boolean needed = isDefaultFocusHighlightNeeded(mBackground,
|
||||
mForegroundInfo == null ? null : mForegroundInfo.mDrawable);
|
||||
final boolean active = mDefaultFocusHighlight != null;
|
||||
if (needed && !active) {
|
||||
setDefaultFocusHighlight(getDefaultFocusHighlightDrawable());
|
||||
|
||||
@@ -19,6 +19,7 @@ package android.widget;
|
||||
import android.annotation.DrawableRes;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.TestApi;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
@@ -1640,4 +1641,13 @@ public class ImageView extends View {
|
||||
super.encodeProperties(stream);
|
||||
stream.addProperty("layout:baseline", getBaseline());
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
@Override
|
||||
@TestApi
|
||||
public boolean isDefaultFocusHighlightNeeded(Drawable background, Drawable foreground) {
|
||||
final boolean lackFocusState = mDrawable == null || !mDrawable.isStateful()
|
||||
|| !mDrawable.hasFocusStateSpecified();
|
||||
return super.isDefaultFocusHighlightNeeded(background, foreground) && lackFocusState;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user