Tweak UI of CardPreference and ContextualCard
- CardPreference uses settingslib_preference layout to fix title/summary alignment issue. - Remove stroke for CardPreference and ContextualCard. - Set colorSurface as default card background color. Bug: 188599776 Test: manual visual Change-Id: Id0ee40be60de1f7605849490ee43eae4b9420abb
This commit is contained in:
@@ -1117,22 +1117,6 @@
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
message="Avoid using hardcoded color"
|
||||
category="Correctness"
|
||||
priority="4"
|
||||
summary="Using hardcoded color"
|
||||
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||
errorLine1=" <color name="contextual_card_stroke_color">#1f000000</color>"
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/values/colors.xml"
|
||||
line="106"
|
||||
column="5"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
@@ -4285,22 +4269,6 @@
|
||||
column="44"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
message="Avoid using hardcoded color"
|
||||
category="Correctness"
|
||||
priority="4"
|
||||
summary="Using hardcoded color"
|
||||
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||
errorLine1=" <item name="strokeColor">@color/contextual_card_stroke_color</item>"
|
||||
errorLine2=" ^">
|
||||
<location
|
||||
file="res/values/styles.xml"
|
||||
line="475"
|
||||
column="34"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
|
@@ -29,6 +29,6 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="-8dp"
|
||||
layout="@layout/preference_material" />
|
||||
layout="@layout/settingslib_preference" />
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
</FrameLayout>
|
||||
|
@@ -103,9 +103,7 @@
|
||||
<color name="homepage_wallpaper_background">#E51AD1</color>
|
||||
<color name="homepage_notification_background">#DD4C9D</color>
|
||||
|
||||
<color name="contextual_card_stroke_color">#1f000000</color>
|
||||
<color name="contextual_card_dismissal_background">@*android:color/material_grey_100</color>
|
||||
<color name="contextual_card_background">@*android:color/background_device_default_light</color>
|
||||
<!-- End of dashboard/homepage icon background colors -->
|
||||
|
||||
<color name="switchbar_background_color">@*android:color/material_grey_600</color>
|
||||
|
@@ -13,7 +13,8 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<resources
|
||||
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
|
||||
|
||||
<style name="Widget.ActionBar.Base"
|
||||
parent="@android:style/Widget.DeviceDefault.Light.ActionBar.Solid"/>
|
||||
@@ -470,11 +471,9 @@
|
||||
<item name="android:layout_marginBottom">@dimen/contextual_card_vertical_margin</item>
|
||||
<item name="android:layout_marginStart">@dimen/contextual_card_side_margin</item>
|
||||
<item name="android:layout_marginEnd">@dimen/contextual_card_side_margin</item>
|
||||
<item name="cardBackgroundColor">@color/contextual_card_background</item>
|
||||
<item name="cardBackgroundColor">?androidprv:attr/colorSurface</item>
|
||||
<item name="cardCornerRadius">@dimen/contextual_card_corner_radius</item>
|
||||
<item name="cardElevation">0dp</item>
|
||||
<item name="strokeColor">@color/contextual_card_stroke_color</item>
|
||||
<item name="strokeWidth">1dp</item>
|
||||
<item name="rippleColor">?android:attr/colorControlHighlight</item>
|
||||
</style>
|
||||
|
||||
|
@@ -44,7 +44,6 @@ import com.android.settings.deviceinfo.storage.StorageItemPreferenceController;
|
||||
import com.android.settings.deviceinfo.storage.UserIconLoader;
|
||||
import com.android.settings.deviceinfo.storage.VolumeSizesLoader;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.CardPreference;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
import com.android.settingslib.applications.StorageStatsSource;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
@@ -91,7 +90,7 @@ public class StorageCategoryFragment extends DashboardFragment
|
||||
private List<AbstractPreferenceController> mSecondaryUsers;
|
||||
private boolean mIsWorkProfile;
|
||||
private int mUserId;
|
||||
private CardPreference mFreeUpSpacePreference;
|
||||
private Preference mFreeUpSpacePreference;
|
||||
|
||||
/**
|
||||
* Refresh UI for specified storageEntry.
|
||||
@@ -146,11 +145,8 @@ public class StorageCategoryFragment extends DashboardFragment
|
||||
}
|
||||
|
||||
private void initializePreference() {
|
||||
mFreeUpSpacePreference = (CardPreference) getPreferenceScreen()
|
||||
.findPreference(FREE_UP_SPACE_PREF_KEY);
|
||||
mFreeUpSpacePreference = getPreferenceScreen().findPreference(FREE_UP_SPACE_PREF_KEY);
|
||||
mFreeUpSpacePreference.setOnPreferenceClickListener(this);
|
||||
mFreeUpSpacePreference.setCardBackgroundColor(Utils.getColorAttrDefaultColor(getContext(),
|
||||
com.android.internal.R.attr.colorSurface));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -56,7 +56,6 @@ import com.android.settings.deviceinfo.storage.UserIconLoader;
|
||||
import com.android.settings.deviceinfo.storage.VolumeSizesLoader;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.widget.CardPreference;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
import com.android.settingslib.applications.StorageStatsSource;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
@@ -110,7 +109,7 @@ public class StorageDashboardFragment extends DashboardFragment
|
||||
private List<AbstractPreferenceController> mSecondaryUsers;
|
||||
private boolean mIsWorkProfile;
|
||||
private int mUserId;
|
||||
private CardPreference mFreeUpSpacePreference;
|
||||
private Preference mFreeUpSpacePreference;
|
||||
|
||||
private final StorageEventListener mStorageEventListener = new StorageEventListener() {
|
||||
@Override
|
||||
@@ -282,11 +281,8 @@ public class StorageDashboardFragment extends DashboardFragment
|
||||
}
|
||||
|
||||
private void initializePreference() {
|
||||
mFreeUpSpacePreference = (CardPreference) getPreferenceScreen()
|
||||
.findPreference(FREE_UP_SPACE_PREF_KEY);
|
||||
mFreeUpSpacePreference = getPreferenceScreen().findPreference(FREE_UP_SPACE_PREF_KEY);
|
||||
mFreeUpSpacePreference.setOnPreferenceClickListener(this);
|
||||
mFreeUpSpacePreference.setCardBackgroundColor(Utils.getColorAttrDefaultColor(getContext(),
|
||||
com.android.internal.R.attr.colorSurface));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -19,9 +19,7 @@ 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;
|
||||
|
||||
@@ -32,10 +30,6 @@ import com.google.android.material.card.MaterialCardView;
|
||||
*/
|
||||
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 */);
|
||||
}
|
||||
@@ -43,23 +37,4 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -18,26 +18,13 @@ package com.android.settings.widget;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import com.google.android.material.card.MaterialCardView;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@@ -46,34 +33,16 @@ public class CardPreferenceTest {
|
||||
|
||||
private Context mContext;
|
||||
private CardPreference mCardPreference;
|
||||
@Mock
|
||||
private PreferenceViewHolder mPreferenceViewHolder;
|
||||
@Mock
|
||||
private MaterialCardView mCardView;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mContext.setTheme(R.style.SettingsPreferenceTheme);
|
||||
mCardPreference = new CardPreference(mContext);
|
||||
mPreferenceViewHolder = spy(PreferenceViewHolder.createInstanceForTests(mock(View.class)));
|
||||
doReturn(mCardView).when(mPreferenceViewHolder).findViewById(R.id.container);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLayoutResource() {
|
||||
assertThat(mCardPreference.getLayoutResource()).isEqualTo(R.layout.card_preference_layout);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCardBackgroundColor_shouldUseCorrectColor() {
|
||||
final @ColorInt int testColor = 0xABCDEF;
|
||||
|
||||
mCardPreference.setCardBackgroundColor(testColor);
|
||||
mCardPreference.onBindViewHolder(mPreferenceViewHolder);
|
||||
|
||||
verify(mCardView).setCardBackgroundColor(testColor);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user