Merge changes I3ee2313c,Ibbf9eb2a
* changes: Remove divider line for battery card preference Add CardPreference in battery settings page
This commit is contained in:
30
res/layout/card_preference_layout.xml
Normal file
30
res/layout/card_preference_layout.xml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2019 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<com.google.android.material.card.MaterialCardView
|
||||||
|
android:id="@+id/container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="8dp"
|
||||||
|
style="@style/ContextualCardStyle">
|
||||||
|
<include layout="@layout/preference_material" />
|
||||||
|
</com.google.android.material.card.MaterialCardView>
|
||||||
|
</FrameLayout>
|
@@ -54,6 +54,8 @@
|
|||||||
|
|
||||||
<attr name="slicePreferenceStyle" format="reference" />
|
<attr name="slicePreferenceStyle" format="reference" />
|
||||||
|
|
||||||
|
<attr name="cardPreferenceStyle" format="reference" />
|
||||||
|
|
||||||
<attr name="footerPreferenceStyle" format="reference" />
|
<attr name="footerPreferenceStyle" format="reference" />
|
||||||
|
|
||||||
<declare-styleable name="FixedLineSummaryPreference">
|
<declare-styleable name="FixedLineSummaryPreference">
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
<style name="PreferenceTheme" parent="@style/PreferenceThemeOverlay.SettingsBase">
|
<style name="PreferenceTheme" parent="@style/PreferenceThemeOverlay.SettingsBase">
|
||||||
<item name="apnPreferenceStyle">@style/ApnPreference</item>
|
<item name="apnPreferenceStyle">@style/ApnPreference</item>
|
||||||
|
<item name="cardPreferenceStyle">@style/CardPreference</item>
|
||||||
<item name="slicePreferenceStyle">@style/SlicePreference</item>
|
<item name="slicePreferenceStyle">@style/SlicePreference</item>
|
||||||
<item name="seekBarPreferenceStyle">@style/SettingsSeekBarPreference</item>
|
<item name="seekBarPreferenceStyle">@style/SettingsSeekBarPreference</item>
|
||||||
<item name="twoStateButtonPreferenceStyle">@style/TwoStateButtonPreference</item>
|
<item name="twoStateButtonPreferenceStyle">@style/TwoStateButtonPreference</item>
|
||||||
@@ -35,6 +36,10 @@
|
|||||||
<item name="android:layout">@layout/apn_preference_layout</item>
|
<item name="android:layout">@layout/apn_preference_layout</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="CardPreference" parent="@style/Preference.Material">
|
||||||
|
<item name="android:layout">@layout/card_preference_layout</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
<style name="SlicePreference" parent="@style/Preference.Material">
|
<style name="SlicePreference" parent="@style/Preference.Material">
|
||||||
<item name="android:layout">@layout/slice_preference_layout</item>
|
<item name="android:layout">@layout/slice_preference_layout</item>
|
||||||
</style>
|
</style>
|
||||||
|
@@ -28,10 +28,9 @@
|
|||||||
android:layout="@layout/battery_header"
|
android:layout="@layout/battery_header"
|
||||||
settings:controller="com.android.settings.fuelgauge.BatteryHeaderPreferenceController" />
|
settings:controller="com.android.settings.fuelgauge.BatteryHeaderPreferenceController" />
|
||||||
|
|
||||||
<PreferenceCategory
|
<com.android.settings.widget.CardPreference
|
||||||
android:key="battery_tip"
|
android:key="battery_tip"
|
||||||
android:title="@string/summary_placeholder"
|
android:title="@string/summary_placeholder"
|
||||||
android:layout="@layout/preference_category_no_label"
|
|
||||||
settings:controller="com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController" />
|
settings:controller="com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController" />
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
@@ -39,8 +38,7 @@
|
|||||||
android:key="battery_saver_summary"
|
android:key="battery_saver_summary"
|
||||||
android:title="@string/battery_saver"
|
android:title="@string/battery_saver"
|
||||||
settings:controller="com.android.settings.fuelgauge.BatterySaverController"
|
settings:controller="com.android.settings.fuelgauge.BatterySaverController"
|
||||||
settings:platform_slice="true"
|
settings:platform_slice="true" />
|
||||||
settings:allowDividerAbove="true" />
|
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:fragment="com.android.settings.fuelgauge.SmartBatterySettings"
|
android:fragment="com.android.settings.fuelgauge.SmartBatterySettings"
|
||||||
|
@@ -21,7 +21,6 @@ import android.os.Bundle;
|
|||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceGroup;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
@@ -32,6 +31,7 @@ import com.android.settings.fuelgauge.batterytip.actions.BatteryTipAction;
|
|||||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||||
import com.android.settings.fuelgauge.batterytip.tips.SummaryTip;
|
import com.android.settings.fuelgauge.batterytip.tips.SummaryTip;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
import com.android.settings.widget.CardPreference;
|
||||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -56,7 +56,7 @@ public class BatteryTipPreferenceController extends BasePreferenceController {
|
|||||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
private boolean mNeedUpdate;
|
private boolean mNeedUpdate;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
PreferenceGroup mPreferenceGroup;
|
CardPreference mCardPreference;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
Context mPrefContext;
|
Context mPrefContext;
|
||||||
InstrumentedPreferenceFragment mFragment;
|
InstrumentedPreferenceFragment mFragment;
|
||||||
@@ -89,12 +89,12 @@ public class BatteryTipPreferenceController extends BasePreferenceController {
|
|||||||
public void displayPreference(PreferenceScreen screen) {
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
super.displayPreference(screen);
|
super.displayPreference(screen);
|
||||||
mPrefContext = screen.getContext();
|
mPrefContext = screen.getContext();
|
||||||
mPreferenceGroup = (PreferenceGroup) screen.findPreference(getPreferenceKey());
|
mCardPreference = screen.findPreference(getPreferenceKey());
|
||||||
|
|
||||||
// Add summary tip in advance to avoid UI flakiness
|
// Add summary tip in advance to avoid UI flakiness
|
||||||
final SummaryTip summaryTip = new SummaryTip(BatteryTip.StateType.NEW,
|
final SummaryTip summaryTip = new SummaryTip(BatteryTip.StateType.NEW,
|
||||||
Estimate.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN);
|
Estimate.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN);
|
||||||
mPreferenceGroup.addPreference(summaryTip.buildPreference(mPrefContext));
|
summaryTip.updatePreference(mCardPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateBatteryTips(List<BatteryTip> batteryTips) {
|
public void updateBatteryTips(List<BatteryTip> batteryTips) {
|
||||||
@@ -110,14 +110,12 @@ public class BatteryTipPreferenceController extends BasePreferenceController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mPreferenceGroup.removeAll();
|
|
||||||
for (int i = 0, size = batteryTips.size(); i < size; i++) {
|
for (int i = 0, size = batteryTips.size(); i < size; i++) {
|
||||||
final BatteryTip batteryTip = mBatteryTips.get(i);
|
final BatteryTip batteryTip = mBatteryTips.get(i);
|
||||||
batteryTip.sanityCheck(mContext);
|
batteryTip.sanityCheck(mContext);
|
||||||
if (batteryTip.getState() != BatteryTip.StateType.INVISIBLE) {
|
if (batteryTip.getState() != BatteryTip.StateType.INVISIBLE) {
|
||||||
final Preference preference = batteryTip.buildPreference(mPrefContext);
|
batteryTip.updatePreference(mCardPreference);
|
||||||
mBatteryTipMap.put(preference.getKey(), batteryTip);
|
mBatteryTipMap.put(mCardPreference.getKey(), batteryTip);
|
||||||
mPreferenceGroup.addPreference(preference);
|
|
||||||
batteryTip.log(mContext, mMetricsFeatureProvider);
|
batteryTip.log(mContext, mMetricsFeatureProvider);
|
||||||
mNeedUpdate = batteryTip.needUpdate();
|
mNeedUpdate = batteryTip.needUpdate();
|
||||||
break;
|
break;
|
||||||
|
@@ -26,6 +26,7 @@ import androidx.annotation.IntDef;
|
|||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.widget.CardPreference;
|
||||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
@@ -146,14 +147,11 @@ public abstract class BatteryTip implements Comparable<BatteryTip>, Parcelable {
|
|||||||
*/
|
*/
|
||||||
public abstract void log(Context context, MetricsFeatureProvider metricsFeatureProvider);
|
public abstract void log(Context context, MetricsFeatureProvider metricsFeatureProvider);
|
||||||
|
|
||||||
public Preference buildPreference(Context context) {
|
public void updatePreference(Preference preference) {
|
||||||
Preference preference = new Preference(context);
|
final Context context = preference.getContext();
|
||||||
|
|
||||||
preference.setKey(getKey());
|
|
||||||
preference.setTitle(getTitle(context));
|
preference.setTitle(getTitle(context));
|
||||||
preference.setSummary(getSummary(context));
|
preference.setSummary(getSummary(context));
|
||||||
preference.setIcon(getIconId());
|
preference.setIcon(getIconId());
|
||||||
return preference;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldShowDialog() {
|
public boolean shouldShowDialog() {
|
||||||
|
39
src/com/android/settings/widget/CardPreference.java
Normal file
39
src/com/android/settings/widget/CardPreference.java
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 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;
|
||||||
|
|
||||||
|
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 {
|
||||||
|
public CardPreference(Context context) {
|
||||||
|
this(context, null /* attrs */);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CardPreference(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs, R.attr.cardPreferenceStyle);
|
||||||
|
}
|
||||||
|
}
|
@@ -44,6 +44,7 @@ import com.android.settings.core.InstrumentedPreferenceFragment;
|
|||||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||||
import com.android.settings.fuelgauge.batterytip.tips.SummaryTip;
|
import com.android.settings.fuelgauge.batterytip.tips.SummaryTip;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
import com.android.settings.widget.CardPreference;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -72,17 +73,14 @@ public class BatteryTipPreferenceControllerTest {
|
|||||||
private BatteryTip mBatteryTip;
|
private BatteryTip mBatteryTip;
|
||||||
@Mock
|
@Mock
|
||||||
private SettingsActivity mSettingsActivity;
|
private SettingsActivity mSettingsActivity;
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
|
||||||
private PreferenceManager mPreferenceManager;
|
|
||||||
@Mock
|
@Mock
|
||||||
private InstrumentedPreferenceFragment mFragment;
|
private InstrumentedPreferenceFragment mFragment;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private PreferenceGroup mPreferenceGroup;
|
private CardPreference mCardPreference;
|
||||||
private BatteryTipPreferenceController mBatteryTipPreferenceController;
|
private BatteryTipPreferenceController mBatteryTipPreferenceController;
|
||||||
private List<BatteryTip> mOldBatteryTips;
|
private List<BatteryTip> mOldBatteryTips;
|
||||||
private List<BatteryTip> mNewBatteryTips;
|
private List<BatteryTip> mNewBatteryTips;
|
||||||
private Preference mPreference;
|
|
||||||
private FakeFeatureFactory mFeatureFactory;
|
private FakeFeatureFactory mFeatureFactory;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@@ -90,12 +88,9 @@ public class BatteryTipPreferenceControllerTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
|
|
||||||
mPreferenceGroup = spy(new PreferenceCategory(mContext));
|
mCardPreference = spy(new CardPreference(mContext));
|
||||||
when(mPreferenceScreen.getContext()).thenReturn(mContext);
|
when(mPreferenceScreen.getContext()).thenReturn(mContext);
|
||||||
when(mPreferenceGroup.getPreferenceManager()).thenReturn(mPreferenceManager);
|
doReturn(mCardPreference).when(mPreferenceScreen).findPreference(KEY_PREF);
|
||||||
doReturn(mPreferenceGroup).when(mPreferenceScreen).findPreference(KEY_PREF);
|
|
||||||
mPreference = new Preference(mContext);
|
|
||||||
mPreference.setKey(KEY_TIP);
|
|
||||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
|
|
||||||
mOldBatteryTips = new ArrayList<>();
|
mOldBatteryTips = new ArrayList<>();
|
||||||
@@ -104,7 +99,7 @@ public class BatteryTipPreferenceControllerTest {
|
|||||||
mNewBatteryTips.add(new SummaryTip(BatteryTip.StateType.INVISIBLE, AVERAGE_TIME_MS));
|
mNewBatteryTips.add(new SummaryTip(BatteryTip.StateType.INVISIBLE, AVERAGE_TIME_MS));
|
||||||
|
|
||||||
mBatteryTipPreferenceController = buildBatteryTipPreferenceController();
|
mBatteryTipPreferenceController = buildBatteryTipPreferenceController();
|
||||||
mBatteryTipPreferenceController.mPreferenceGroup = mPreferenceGroup;
|
mBatteryTipPreferenceController.mCardPreference = mCardPreference;
|
||||||
mBatteryTipPreferenceController.mPrefContext = mContext;
|
mBatteryTipPreferenceController.mPrefContext = mContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,18 +107,7 @@ public class BatteryTipPreferenceControllerTest {
|
|||||||
public void testDisplayPreference_addSummaryTip() {
|
public void testDisplayPreference_addSummaryTip() {
|
||||||
mBatteryTipPreferenceController.displayPreference(mPreferenceScreen);
|
mBatteryTipPreferenceController.displayPreference(mPreferenceScreen);
|
||||||
|
|
||||||
assertOnlyContainsSummaryTip(mPreferenceGroup);
|
assertOnlyContainsSummaryTip(mCardPreference);
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateBatteryTips_updateTwice_firstShowSummaryTipThenRemoveIt() {
|
|
||||||
// Display summary tip because its state is new
|
|
||||||
mBatteryTipPreferenceController.updateBatteryTips(mOldBatteryTips);
|
|
||||||
assertOnlyContainsSummaryTip(mPreferenceGroup);
|
|
||||||
|
|
||||||
// Remove summary tip because its new state is invisible
|
|
||||||
mBatteryTipPreferenceController.updateBatteryTips(mNewBatteryTips);
|
|
||||||
assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -142,11 +126,11 @@ public class BatteryTipPreferenceControllerTest {
|
|||||||
mBatteryTipPreferenceController.saveInstanceState(bundle);
|
mBatteryTipPreferenceController.saveInstanceState(bundle);
|
||||||
|
|
||||||
final BatteryTipPreferenceController controller = buildBatteryTipPreferenceController();
|
final BatteryTipPreferenceController controller = buildBatteryTipPreferenceController();
|
||||||
controller.mPreferenceGroup = mPreferenceGroup;
|
controller.mCardPreference = mCardPreference;
|
||||||
controller.mPrefContext = mContext;
|
controller.mPrefContext = mContext;
|
||||||
controller.restoreInstanceState(bundle);
|
controller.restoreInstanceState(bundle);
|
||||||
|
|
||||||
assertOnlyContainsSummaryTip(mPreferenceGroup);
|
assertOnlyContainsSummaryTip(mCardPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -166,12 +150,11 @@ public class BatteryTipPreferenceControllerTest {
|
|||||||
when(mBatteryTip.getType()).thenReturn(SMART_BATTERY_MANAGER);
|
when(mBatteryTip.getType()).thenReturn(SMART_BATTERY_MANAGER);
|
||||||
List<BatteryTip> batteryTips = new ArrayList<>();
|
List<BatteryTip> batteryTips = new ArrayList<>();
|
||||||
batteryTips.add(mBatteryTip);
|
batteryTips.add(mBatteryTip);
|
||||||
doReturn(mPreference).when(mBatteryTip).buildPreference(any());
|
|
||||||
doReturn(false).when(mBatteryTip).shouldShowDialog();
|
doReturn(false).when(mBatteryTip).shouldShowDialog();
|
||||||
doReturn(KEY_TIP).when(mBatteryTip).getKey();
|
doReturn(KEY_TIP).when(mBatteryTip).getKey();
|
||||||
mBatteryTipPreferenceController.updateBatteryTips(batteryTips);
|
mBatteryTipPreferenceController.updateBatteryTips(batteryTips);
|
||||||
|
|
||||||
mBatteryTipPreferenceController.handlePreferenceTreeClick(mPreference);
|
mBatteryTipPreferenceController.handlePreferenceTreeClick(mCardPreference);
|
||||||
|
|
||||||
verify(mBatteryTipListener).onBatteryTipHandled(mBatteryTip);
|
verify(mBatteryTipListener).onBatteryTipHandled(mBatteryTip);
|
||||||
}
|
}
|
||||||
@@ -182,10 +165,7 @@ public class BatteryTipPreferenceControllerTest {
|
|||||||
BasePreferenceController.AVAILABLE_UNSEARCHABLE);
|
BasePreferenceController.AVAILABLE_UNSEARCHABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertOnlyContainsSummaryTip(final PreferenceGroup preferenceGroup) {
|
private void assertOnlyContainsSummaryTip(CardPreference preference) {
|
||||||
assertThat(preferenceGroup.getPreferenceCount()).isEqualTo(1);
|
|
||||||
|
|
||||||
final Preference preference = preferenceGroup.getPreference(0);
|
|
||||||
assertThat(preference.getTitle()).isEqualTo(
|
assertThat(preference.getTitle()).isEqualTo(
|
||||||
mContext.getString(R.string.battery_tip_summary_title));
|
mContext.getString(R.string.battery_tip_summary_title));
|
||||||
assertThat(preference.getSummary()).isEqualTo(
|
assertThat(preference.getSummary()).isEqualTo(
|
||||||
|
@@ -56,7 +56,8 @@ public class BatteryTipTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildPreference() {
|
public void buildPreference() {
|
||||||
final Preference preference = mBatteryTip.buildPreference(mContext);
|
final Preference preference = new Preference(mContext);
|
||||||
|
mBatteryTip.updatePreference(preference);
|
||||||
|
|
||||||
assertThat(preference.getTitle()).isEqualTo(TITLE);
|
assertThat(preference.getTitle()).isEqualTo(TITLE);
|
||||||
assertThat(preference.getSummary()).isEqualTo(SUMMARY);
|
assertThat(preference.getSummary()).isEqualTo(SUMMARY);
|
||||||
|
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 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 static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class CardPreferenceTest {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private CardPreference mCardPreference;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
|
mContext.setTheme(R.style.PreferenceTheme);
|
||||||
|
mCardPreference = new CardPreference(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getLayoutResource() {
|
||||||
|
assertThat(mCardPreference.getLayoutResource()).isEqualTo(R.layout.card_preference_layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user