'Free up space' uses CardPreference

For material next style.

Bug: 188599776
Test: make RunSettingsRoboTests ROBOTEST_FILTER=CardPreferenceTest
Change-Id: Ibaf4d11ab44017453498676db00cff1e49c83b9d
This commit is contained in:
Arc Wang
2021-06-08 20:21:05 +08:00
parent 603cd6c44c
commit 7b85f2af24
6 changed files with 70 additions and 6 deletions

View File

@@ -19,7 +19,9 @@ package com.android.settings.widget;
import android.content.Context;
import android.util.AttributeSet;
import androidx.annotation.ColorInt;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
@@ -29,6 +31,11 @@ import com.google.android.material.card.MaterialCardView;
* Preference that wrapped by {@link MaterialCardView}, only support to set icon, title and summary
*/
public class CardPreference extends Preference {
private static final @ColorInt int INVALID_COLOR = -1;
private @ColorInt int mCardBackgroundColor = INVALID_COLOR;
public CardPreference(Context context) {
this(context, null /* attrs */);
}
@@ -36,4 +43,23 @@ public class CardPreference extends Preference {
public CardPreference(Context context, AttributeSet attrs) {
super(context, attrs, R.attr.cardPreferenceStyle);
}
/** Set card background color of the MaterialCardView in CardPreference. */
public void setCardBackgroundColor(@ColorInt int color) {
if (mCardBackgroundColor == color) {
return;
}
mCardBackgroundColor = color;
notifyChanged();
}
@Override
public void onBindViewHolder(PreferenceViewHolder view) {
super.onBindViewHolder(view);
if (mCardBackgroundColor != INVALID_COLOR) {
final MaterialCardView cardView = (MaterialCardView) view.findViewById(R.id.container);
cardView.setCardBackgroundColor(mCardBackgroundColor);
}
}
}