Refine layouts for large screen
- Support dynamic paddings depending on app's screen width - Add round corners to homepage ripple effect to improve the transition of being highlighted - Add an interface to support dynamic split layout for suggestion cards Bug: 223300824 Test: robotest, manual Change-Id: Iaca6b4fd3f7369179416ef084a800d7eb2ee4640
This commit is contained in:
@@ -21,7 +21,6 @@ import android.graphics.drawable.Drawable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
@@ -46,6 +45,10 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
|
||||
private static final String TAG = "HighlightableTopLevelAdapter";
|
||||
|
||||
static final long DELAY_HIGHLIGHT_DURATION_MILLIS = 100L;
|
||||
private static final int RES_NORMAL_BACKGROUND =
|
||||
R.drawable.homepage_selectable_item_background;
|
||||
private static final int RES_HIGHLIGHTED_BACKGROUND =
|
||||
R.drawable.homepage_highlighted_item_background;
|
||||
|
||||
private final int mTitleColorNormal;
|
||||
private final int mTitleColorHighlight;
|
||||
@@ -54,11 +57,8 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
|
||||
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 int mHighlightPosition = RecyclerView.NO_POSITION;
|
||||
private int mScrollPosition = RecyclerView.NO_POSITION;
|
||||
@@ -74,23 +74,18 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
|
||||
mHighlightKey = key;
|
||||
mScrolled = !scrollNeeded;
|
||||
mViewHolders = new SparseArray<>();
|
||||
mContext = preferenceGroup.getContext();
|
||||
mHomepageActivity = homepageActivity;
|
||||
final TypedValue outValue = new TypedValue();
|
||||
mContext.getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
|
||||
outValue, true /* resolveRefs */);
|
||||
mNormalBackgroundRes = outValue.resourceId;
|
||||
mHighlightBackgroundRes = R.drawable.homepage_highlighted_item_background;
|
||||
mTitleColorNormal = Utils.getColorAttrDefaultColor(mContext,
|
||||
Context context = preferenceGroup.getContext();
|
||||
mTitleColorNormal = Utils.getColorAttrDefaultColor(context,
|
||||
android.R.attr.textColorPrimary);
|
||||
mTitleColorHighlight = Utils.getColorAttrDefaultColor(mContext,
|
||||
mTitleColorHighlight = Utils.getColorAttrDefaultColor(context,
|
||||
android.R.attr.textColorPrimaryInverse);
|
||||
mSummaryColorNormal = Utils.getColorAttrDefaultColor(mContext,
|
||||
mSummaryColorNormal = Utils.getColorAttrDefaultColor(context,
|
||||
android.R.attr.textColorSecondary);
|
||||
mSummaryColorHighlight = Utils.getColorAttrDefaultColor(mContext,
|
||||
mSummaryColorHighlight = Utils.getColorAttrDefaultColor(context,
|
||||
android.R.attr.textColorSecondaryInverse);
|
||||
mIconColorNormal = Utils.getHomepageIconColor(mContext);
|
||||
mIconColorHighlight = Utils.getHomepageIconColorHighlight(mContext);
|
||||
mIconColorNormal = Utils.getHomepageIconColor(context);
|
||||
mIconColorHighlight = Utils.getHomepageIconColorHighlight(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -236,7 +231,7 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
|
||||
|
||||
private void addHighlightBackground(PreferenceViewHolder holder) {
|
||||
final View v = holder.itemView;
|
||||
v.setBackgroundResource(mHighlightBackgroundRes);
|
||||
v.setBackgroundResource(RES_HIGHLIGHTED_BACKGROUND);
|
||||
((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();
|
||||
@@ -247,7 +242,7 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
|
||||
|
||||
private void removeHighlightBackground(PreferenceViewHolder holder) {
|
||||
final View v = holder.itemView;
|
||||
v.setBackgroundResource(mNormalBackgroundRes);
|
||||
v.setBackgroundResource(RES_NORMAL_BACKGROUND);
|
||||
((TextView) v.findViewById(android.R.id.title)).setTextColor(mTitleColorNormal);
|
||||
((TextView) v.findViewById(android.R.id.summary)).setTextColor(mSummaryColorNormal);
|
||||
final Drawable drawable = ((ImageView) v.findViewById(android.R.id.icon)).getDrawable();
|
||||
|
@@ -20,29 +20,43 @@ import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
/** A customized layout for homepage preference. */
|
||||
public class HomepagePreference extends Preference {
|
||||
public class HomepagePreference extends Preference implements
|
||||
HomepagePreferenceLayoutHelper.HomepagePreferenceLayout {
|
||||
|
||||
private final HomepagePreferenceLayoutHelper mHelper;
|
||||
|
||||
public HomepagePreference(Context context, AttributeSet attrs, int defStyleAttr,
|
||||
int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
setLayoutResource(R.layout.homepage_preference);
|
||||
mHelper = new HomepagePreferenceLayoutHelper(this);
|
||||
}
|
||||
|
||||
public HomepagePreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
setLayoutResource(R.layout.homepage_preference);
|
||||
mHelper = new HomepagePreferenceLayoutHelper(this);
|
||||
}
|
||||
|
||||
public HomepagePreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setLayoutResource(R.layout.homepage_preference);
|
||||
mHelper = new HomepagePreferenceLayoutHelper(this);
|
||||
}
|
||||
|
||||
public HomepagePreference(Context context) {
|
||||
super(context);
|
||||
setLayoutResource(R.layout.homepage_preference);
|
||||
mHelper = new HomepagePreferenceLayoutHelper(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
mHelper.onBindViewHolder(holder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HomepagePreferenceLayoutHelper getHelper() {
|
||||
return mHelper;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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.view.View;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
/** Helper for homepage preference to manage layout. */
|
||||
public class HomepagePreferenceLayoutHelper {
|
||||
|
||||
private View mIcon;
|
||||
private View mText;
|
||||
private boolean mIconVisible = true;
|
||||
private int mIconPaddingStart = -1;
|
||||
private int mTextPaddingStart = -1;
|
||||
|
||||
/** The interface for managing preference layouts on homepage */
|
||||
public interface HomepagePreferenceLayout {
|
||||
/** Returns a {@link HomepagePreferenceLayoutHelper} */
|
||||
HomepagePreferenceLayoutHelper getHelper();
|
||||
}
|
||||
|
||||
public HomepagePreferenceLayoutHelper(Preference preference) {
|
||||
preference.setLayoutResource(R.layout.homepage_preference);
|
||||
}
|
||||
|
||||
/** Sets whether the icon should be visible */
|
||||
public void setIconVisible(boolean visible) {
|
||||
mIconVisible = visible;
|
||||
if (mIcon != null) {
|
||||
mIcon.setVisibility(visible ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the icon padding start */
|
||||
public void setIconPaddingStart(int paddingStart) {
|
||||
mIconPaddingStart = paddingStart;
|
||||
if (mIcon != null && paddingStart >= 0) {
|
||||
mIcon.setPaddingRelative(paddingStart, mIcon.getPaddingTop(), mIcon.getPaddingEnd(),
|
||||
mIcon.getPaddingBottom());
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the text padding start */
|
||||
public void setTextPaddingStart(int paddingStart) {
|
||||
mTextPaddingStart = paddingStart;
|
||||
if (mText != null && paddingStart >= 0) {
|
||||
mText.setPaddingRelative(paddingStart, mText.getPaddingTop(), mText.getPaddingEnd(),
|
||||
mText.getPaddingBottom());
|
||||
}
|
||||
}
|
||||
|
||||
void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
mIcon = holder.findViewById(R.id.icon_frame);
|
||||
mText = holder.findViewById(R.id.text_frame);
|
||||
setIconVisible(mIconVisible);
|
||||
setIconPaddingStart(mIconPaddingStart);
|
||||
setTextPaddingStart(mTextPaddingStart);
|
||||
}
|
||||
}
|
@@ -19,29 +19,45 @@ package com.android.settings.widget;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.android.settings.R;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
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 class RestrictedHomepagePreference extends RestrictedTopLevelPreference implements
|
||||
HomepagePreferenceLayoutHelper.HomepagePreferenceLayout {
|
||||
|
||||
private final HomepagePreferenceLayoutHelper mHelper;
|
||||
|
||||
public RestrictedHomepagePreference(Context context, AttributeSet attrs, int defStyleAttr,
|
||||
int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
setLayoutResource(R.layout.homepage_preference);
|
||||
mHelper = new HomepagePreferenceLayoutHelper(this);
|
||||
}
|
||||
|
||||
public RestrictedHomepagePreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
setLayoutResource(R.layout.homepage_preference);
|
||||
mHelper = new HomepagePreferenceLayoutHelper(this);
|
||||
}
|
||||
|
||||
public RestrictedHomepagePreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setLayoutResource(R.layout.homepage_preference);
|
||||
mHelper = new HomepagePreferenceLayoutHelper(this);
|
||||
}
|
||||
|
||||
public RestrictedHomepagePreference(Context context) {
|
||||
super(context);
|
||||
setLayoutResource(R.layout.homepage_preference);
|
||||
mHelper = new HomepagePreferenceLayoutHelper(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
mHelper.onBindViewHolder(holder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HomepagePreferenceLayoutHelper getHelper() {
|
||||
return mHelper;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user