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:
Jason Chiu
2022-03-24 16:58:31 +08:00
parent c4c923d1eb
commit 680fce3acd
17 changed files with 441 additions and 98 deletions

View File

@@ -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();