From 2fe301db7555bccf53e465436d4cb7442c803df3 Mon Sep 17 00:00:00 2001 From: Adam Powell Date: Mon, 15 Aug 2016 16:34:37 -0700 Subject: [PATCH] Focus behavior for scroll containers in watch mode Change default scrolling containers not to request a reveal (parent scroll) on focus, and to be focusable in touch mode. This helps watch devices with other input mechanisms that rely on view focus. Since there's no attribute for the reveal on focus hint, set that in code. Set focusable in touch mode on the default styles for ScrollView/HorizontalScrollView. AbsListView already sets this historically anyway. Change-Id: I74760f6d523874127da6f6134f0461cc59ce189a --- core/java/android/widget/AbsListView.java | 5 +++++ .../android/widget/HorizontalScrollView.java | 17 ++++++++++++----- core/java/android/widget/ScrollView.java | 17 ++++++++++++----- core/res/res/values-watch/config.xml | 5 +++++ core/res/res/values/config.xml | 5 +++++ core/res/res/values/styles.xml | 2 ++ 6 files changed, 41 insertions(+), 10 deletions(-) diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java index 7b45d8cb05b09..3ca928235b2b5 100644 --- a/core/java/android/widget/AbsListView.java +++ b/core/java/android/widget/AbsListView.java @@ -21,6 +21,7 @@ import android.annotation.DrawableRes; import android.annotation.NonNull; import android.content.Context; import android.content.Intent; +import android.content.res.Configuration; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Rect; @@ -857,6 +858,10 @@ public abstract class AbsListView extends AdapterView implements Te R.styleable.AbsListView_fastScrollAlwaysVisible, false)); a.recycle(); + + if (context.getResources().getConfiguration().uiMode == Configuration.UI_MODE_TYPE_WATCH) { + setRevealOnFocusHint(false); + } } private void initAbsListView() { diff --git a/core/java/android/widget/HorizontalScrollView.java b/core/java/android/widget/HorizontalScrollView.java index 00f368e3abe31..5eea7a4f922c8 100644 --- a/core/java/android/widget/HorizontalScrollView.java +++ b/core/java/android/widget/HorizontalScrollView.java @@ -18,6 +18,7 @@ package android.widget; import android.annotation.NonNull; import android.content.Context; +import android.content.res.Configuration; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Rect; @@ -165,6 +166,10 @@ public class HorizontalScrollView extends FrameLayout { setFillViewport(a.getBoolean(android.R.styleable.HorizontalScrollView_fillViewport, false)); a.recycle(); + + if (context.getResources().getConfiguration().uiMode == Configuration.UI_MODE_TYPE_WATCH) { + setRevealOnFocusHint(false); + } } @Override @@ -1430,11 +1435,13 @@ public class HorizontalScrollView extends FrameLayout { @Override public void requestChildFocus(View child, View focused) { - if (!mIsLayoutDirty) { - scrollToChild(focused); - } else { - // The child may not be laid out yet, we can't compute the scroll yet - mChildToScrollTo = focused; + if (focused.getRevealOnFocusHint()) { + if (!mIsLayoutDirty) { + scrollToChild(focused); + } else { + // The child may not be laid out yet, we can't compute the scroll yet + mChildToScrollTo = focused; + } } super.requestChildFocus(child, focused); } diff --git a/core/java/android/widget/ScrollView.java b/core/java/android/widget/ScrollView.java index 0555cd403b005..493b28c688f9a 100644 --- a/core/java/android/widget/ScrollView.java +++ b/core/java/android/widget/ScrollView.java @@ -17,6 +17,7 @@ package android.widget; import android.annotation.NonNull; +import android.content.res.Configuration; import android.os.Build; import android.os.Build.VERSION_CODES; import android.os.Parcel; @@ -186,6 +187,10 @@ public class ScrollView extends FrameLayout { setFillViewport(a.getBoolean(R.styleable.ScrollView_fillViewport, false)); a.recycle(); + + if (context.getResources().getConfiguration().uiMode == Configuration.UI_MODE_TYPE_WATCH) { + setRevealOnFocusHint(false); + } } @Override @@ -1455,11 +1460,13 @@ public class ScrollView extends FrameLayout { @Override public void requestChildFocus(View child, View focused) { - if (!mIsLayoutDirty) { - scrollToChild(focused); - } else { - // The child may not be laid out yet, we can't compute the scroll yet - mChildToScrollTo = focused; + if (focused.getRevealOnFocusHint()) { + if (!mIsLayoutDirty) { + scrollToChild(focused); + } else { + // The child may not be laid out yet, we can't compute the scroll yet + mChildToScrollTo = focused; + } } super.requestChildFocus(child, focused); } diff --git a/core/res/res/values-watch/config.xml b/core/res/res/values-watch/config.xml index 919519e5832ae..7c05b7a8e3627 100644 --- a/core/res/res/values-watch/config.xml +++ b/core/res/res/values-watch/config.xml @@ -57,4 +57,9 @@ true + + + true diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 662fc83c1499b..1b66e303700be 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -2567,6 +2567,11 @@ + + false + com.android.systemui/com.android.systemui.net.NetworkOverLimitActivity com.android.settings/com.android.settings.Settings$DataUsageSummaryActivity diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml index 762cf31abd55f..937428b12c60b 100644 --- a/core/res/res/values/styles.xml +++ b/core/res/res/values/styles.xml @@ -649,11 +649,13 @@ please see styles_device_defaults.xml.