diff --git a/res/drawable/homepage_highlighted_item_background.xml b/res/drawable/homepage_highlighted_item_background.xml new file mode 100644 index 00000000000..d45e489c7d3 --- /dev/null +++ b/res/drawable/homepage_highlighted_item_background.xml @@ -0,0 +1,27 @@ + + + + + + + + \ No newline at end of file diff --git a/res/layout/homepage_preference.xml b/res/layout/homepage_preference.xml new file mode 100644 index 00000000000..62f6457d27f --- /dev/null +++ b/res/layout/homepage_preference.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 9eadf897af6..2468db62bd1 100755 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -141,6 +141,10 @@ 8dp 24dp + + 16dp + 28dp + 16dp 16dp diff --git a/res/xml/top_level_settings.xml b/res/xml/top_level_settings.xml index e2cb1736fcf..042ce43999a 100644 --- a/res/xml/top_level_settings.xml +++ b/res/xml/top_level_settings.xml @@ -20,7 +20,7 @@ xmlns:settings="http://schemas.android.com/apk/res-auto" android:key="top_level_settings"> - - - - - - - - - - - - - - - - - - { + if (event.getAction() == MotionEvent.ACTION_DOWN) { + v.getParent().requestDisallowInterceptTouchEvent(true); + } + return false; + }); updateStage(Stage.NeedToUnlock); if (savedInstanceState == null) { diff --git a/src/com/android/settings/widget/HighlightableTopLevelPreferenceAdapter.java b/src/com/android/settings/widget/HighlightableTopLevelPreferenceAdapter.java index 4002500e3d2..b7f30158a1d 100644 --- a/src/com/android/settings/widget/HighlightableTopLevelPreferenceAdapter.java +++ b/src/com/android/settings/widget/HighlightableTopLevelPreferenceAdapter.java @@ -31,6 +31,7 @@ import androidx.preference.PreferenceGroupAdapter; import androidx.preference.PreferenceViewHolder; import androidx.recyclerview.widget.RecyclerView; +import com.android.settings.R; import com.android.settings.Utils; import com.android.settings.activityembedding.ActivityEmbeddingUtils; import com.android.settings.homepage.SettingsHomepageActivity; @@ -45,19 +46,18 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt static final long DELAY_HIGHLIGHT_DURATION_MILLIS = 100L; - @VisibleForTesting - final int mHighlightColor; - final int mTitleColorNormal; - final int mTitleColorHighlight; - final int mSummaryColorNormal; - final int mSummaryColorHighlight; - final int mIconColorNormal; - final int mIconColorHighlight; + private final int mTitleColorNormal; + private final int mTitleColorHighlight; + private final int mSummaryColorNormal; + private final int mSummaryColorHighlight; + private final int mIconColorNormal; + private final int mIconColorHighlight; private final Context mContext; private final SettingsHomepageActivity mHomepageActivity; private final RecyclerView mRecyclerView; private final int mNormalBackgroundRes; + private final int mHighlightBackgroundRes; private String mHighlightKey; private String mPreviousHighlightKey; private int mHighlightPosition = RecyclerView.NO_POSITION; @@ -76,8 +76,7 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt mContext.getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true /* resolveRefs */); mNormalBackgroundRes = outValue.resourceId; - mHighlightColor = Utils.getColorAttrDefaultColor(mContext, - com.android.internal.R.attr.colorAccentSecondaryVariant); + mHighlightBackgroundRes = R.drawable.homepage_highlighted_item_background; mTitleColorNormal = Utils.getColorAttrDefaultColor(mContext, android.R.attr.textColorPrimary); mTitleColorHighlight = Utils.getColorAttrDefaultColor(mContext, @@ -227,7 +226,7 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt private void addHighlightBackground(PreferenceViewHolder holder) { final View v = holder.itemView; - v.setBackgroundColor(mHighlightColor); + v.setBackgroundResource(mHighlightBackgroundRes); ((TextView) v.findViewById(android.R.id.title)).setTextColor(mTitleColorHighlight); ((TextView) v.findViewById(android.R.id.summary)).setTextColor(mSummaryColorHighlight); final Drawable drawable = ((ImageView) v.findViewById(android.R.id.icon)).getDrawable(); diff --git a/src/com/android/settings/widget/HomepagePreference.java b/src/com/android/settings/widget/HomepagePreference.java new file mode 100644 index 00000000000..ff4055ee226 --- /dev/null +++ b/src/com/android/settings/widget/HomepagePreference.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.widget; + +import android.content.Context; +import android.util.AttributeSet; + +import androidx.preference.Preference; + +import com.android.settings.R; + +/** A customized layout for homepage preference. */ +public class HomepagePreference extends Preference { + public HomepagePreference(Context context, AttributeSet attrs, int defStyleAttr, + int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + setLayoutResource(R.layout.homepage_preference); + } + + public HomepagePreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + setLayoutResource(R.layout.homepage_preference); + } + + public HomepagePreference(Context context, AttributeSet attrs) { + super(context, attrs); + setLayoutResource(R.layout.homepage_preference); + } + + public HomepagePreference(Context context) { + super(context); + setLayoutResource(R.layout.homepage_preference); + } +} diff --git a/src/com/android/settings/widget/RestrictedHomepagePreference.java b/src/com/android/settings/widget/RestrictedHomepagePreference.java new file mode 100644 index 00000000000..4667e2ce314 --- /dev/null +++ b/src/com/android/settings/widget/RestrictedHomepagePreference.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.widget; + +import android.content.Context; +import android.util.AttributeSet; + +import com.android.settings.R; +import com.android.settingslib.RestrictedTopLevelPreference; + +/** Homepage preference that can be disabled by a device admin using a user restriction. */ +public class RestrictedHomepagePreference extends RestrictedTopLevelPreference { + public RestrictedHomepagePreference(Context context, AttributeSet attrs, int defStyleAttr, + int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + setLayoutResource(R.layout.homepage_preference); + } + + public RestrictedHomepagePreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + setLayoutResource(R.layout.homepage_preference); + } + + public RestrictedHomepagePreference(Context context, AttributeSet attrs) { + super(context, attrs); + setLayoutResource(R.layout.homepage_preference); + } + + public RestrictedHomepagePreference(Context context) { + super(context); + setLayoutResource(R.layout.homepage_preference); + } +}