diff --git a/packages/SettingsLib/Android.bp b/packages/SettingsLib/Android.bp
index 042808a07f8f514199beda0097af4be1b1e91e27..2321790fa960f10b6ce8b3f79f576669c6039333 100644
--- a/packages/SettingsLib/Android.bp
+++ b/packages/SettingsLib/Android.bp
@@ -19,6 +19,7 @@ android_library {
"SettingsLibLayoutPreference",
"SettingsLibActionButtonsPreference",
"SettingsLibEntityHeaderWidgets",
+ "SettingsLibBarChartPreference"
],
// ANDROIDMK TRANSLATION ERROR: unsupported assignment to LOCAL_SHARED_JAVA_LIBRARIES
diff --git a/packages/SettingsLib/BarChartPreference/Android.bp b/packages/SettingsLib/BarChartPreference/Android.bp
new file mode 100644
index 0000000000000000000000000000000000000000..477e8979b03b822c6a9d038438790a61bab820a0
--- /dev/null
+++ b/packages/SettingsLib/BarChartPreference/Android.bp
@@ -0,0 +1,13 @@
+android_library {
+ name: "SettingsLibBarChartPreference",
+
+ srcs: ["src/**/*.java"],
+ resource_dirs: ["res"],
+
+ static_libs: [
+ "androidx.preference_preference",
+ ],
+
+ sdk_version: "system_current",
+ min_sdk_version: "21",
+}
diff --git a/packages/SettingsLib/BarChartPreference/AndroidManifest.xml b/packages/SettingsLib/BarChartPreference/AndroidManifest.xml
new file mode 100644
index 0000000000000000000000000000000000000000..4b9f1ab8d6cc81723bcc63da77681f3f82ddb978
--- /dev/null
+++ b/packages/SettingsLib/BarChartPreference/AndroidManifest.xml
@@ -0,0 +1,23 @@
+
+
+
+
The following code sample shows a typical use, with an XML layout and code to initialize the + * contents of the BarChartPreference: + * + *
+ * <com.android.settingslib.widget.BarChartPreference + * android:key="bar_chart"/> + *+ * + *
This code sample demonstrates how to initialize the contents of the BarChartPreference defined + * in the previous XML layout: + * + *
+ * BarViewInfo[] viewsInfo = new BarViewInfo [] { + * new BarViewInfo(icon, 18, res of summary), + * new BarViewInfo(icon, 25, res of summary), + * new BarViewInfo(icon, 10, res of summary), + * new BarViewInfo(icon, 3, res of summary), + * }; + *+ * + *
+ * BarChartPreference preference = ((BarChartPreference) findPreference("bar_chart")); + * + * preference.setBarChartTitleRes(R.string.title_res); + * preference.setBarChartDetailsRes(R.string.details_res); + * preference.setBarChartDetailsClickListener(v -> doSomething()); + * preference.setAllBarViewsData(viewsInfo); + *+ */ +public class BarChartPreference extends Preference { + + private static final String TAG = "BarChartPreference"; + private static final int MAXIMUM_BAR_VIEWS = 4; + private static final int[] BAR_VIEWS = { + R.id.bar_view1, + R.id.bar_view2, + R.id.bar_view3, + R.id.bar_view4 + }; + + private int mMaxBarHeight; + private @StringRes int mTitleId; + private @StringRes int mDetailsId; + private BarViewInfo[] mBarViewsInfo; + private View.OnClickListener mDetailsOnClickListener; + + /** + * Constructs a new BarChartPreference with the given context's theme. + * It sets a layout with settings bar chart style + * + * @param context The Context the view is running in, through which it can + * access the current theme, resources, etc. + */ + public BarChartPreference(Context context) { + super(context); + init(); + } + + /** + * Constructs a new BarChartPreference with the given context's theme and the supplied + * attribute set. + * It sets a layout with settings bar chart style + * + * @param context the Context the view is running in + * @param attrs the attributes of the XML tag that is inflating the view. + */ + public BarChartPreference(Context context, AttributeSet attrs) { + super(context, attrs); + init(); + } + + /** + * Constructs a new BarChartPreference with the given context's theme, the supplied + * attribute set, and default style attribute. + * It sets a layout with settings bar chart style + * + * @param context The Context the view is running in, through which it can + * access the current theme, resources, etc. + * @param attrs The attributes of the XML tag that is inflating the view. + * @param defStyleAttr An attribute in the current theme that contains a + * reference to a style resource that supplies default + * values for the view. Can be 0 to not look for + * defaults. + */ + public BarChartPreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(); + } + + /** + * Constructs a new BarChartPreference with the given context's theme, the supplied + * attribute set, and default styles. + * It sets a layout with settings bar chart style + * + * @param context The Context the view is running in, through which it can + * access the current theme, resources, etc. + * @param attrs The attributes of the XML tag that is inflating the view. + * @param defStyleAttr An attribute in the current theme that contains a + * reference to a style resource that supplies default + * values for the view. Can be 0 to not look for + * defaults. + * @param defStyleRes A resource identifier of a style resource that + * supplies default values for the view, used only if + * defStyleAttr is 0 or can not be found in the theme. + * Can be 0 to not look for defaults. + */ + public BarChartPreference(Context context, AttributeSet attrs, int defStyleAttr, + int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + init(); + } + + /** + * Set the text resource for bar chart title. + */ + public void setBarChartTitle(@StringRes int resId) { + mTitleId = resId; + notifyChanged(); + } + + /** + * Set the text resource for bar chart details. + */ + public void setBarChartDetails(@StringRes int resId) { + mDetailsId = resId; + notifyChanged(); + } + + /** + * Register a callback to be invoked when bar chart details view is clicked. + */ + public void setBarChartDetailsClickListener(@Nullable View.OnClickListener clickListener) { + mDetailsOnClickListener = clickListener; + notifyChanged(); + } + + /** + * Set all bar view information which you'd like to show in preference. + * + *
This method helps you do a sort by {@linkBarViewInfo#mBarNumber} in descending order.
+ *
+ * @param barViewsInfo the barViewsInfo contain at least one {@link BarViewInfo}.
+ */
+ public void setAllBarViewsInfo(@NonNull BarViewInfo[] barViewsInfo) {
+ mBarViewsInfo = barViewsInfo;
+ // Do a sort in descending order, the first element would have max {@link
+ // BarViewInfo#mBarNumber}
+ Arrays.sort(mBarViewsInfo);
+ caculateAllBarViewsHeight();
+ notifyChanged();
+ }
+
+ @Override
+ public void onBindViewHolder(PreferenceViewHolder holder) {
+ super.onBindViewHolder(holder);
+ holder.setDividerAllowedAbove(true);
+ holder.setDividerAllowedBelow(true);
+
+ bindChartTitleView(holder);
+ bindChartDetailsView(holder);
+ updateBarChart(holder);
+ }
+
+ private void init() {
+ setSelectable(false);
+ setLayoutResource(R.layout.settings_bar_chart);
+ mMaxBarHeight = getContext().getResources().getDimensionPixelSize(
+ R.dimen.settings_bar_view_max_height);
+ }
+
+ private void bindChartTitleView(PreferenceViewHolder holder) {
+ final TextView titleView = (TextView) holder.findViewById(R.id.bar_chart_title);
+ titleView.setText(mTitleId);
+ }
+
+ private void bindChartDetailsView(PreferenceViewHolder holder) {
+ final Button detailsView = (Button) holder.findViewById(R.id.bar_chart_details);
+ detailsView.setText(mDetailsId);
+ detailsView.setOnClickListener(mDetailsOnClickListener);
+ }
+
+ private void updateBarChart(PreferenceViewHolder holder) {
+ for (int index = 0; index < MAXIMUM_BAR_VIEWS; index++) {
+ final BarView barView = (BarView) holder.findViewById(BAR_VIEWS[index]);
+
+ // If there is no bar views data can be shown.
+ if (mBarViewsInfo == null || index >= mBarViewsInfo.length) {
+ barView.setVisibility(View.GONE);
+ continue;
+ }
+ barView.setVisibility(View.VISIBLE);
+ barView.updateBarViewUI(mBarViewsInfo[index]);
+ }
+ }
+
+ private void caculateAllBarViewsHeight() {
+ // Since we sorted this array in advance, the first element must have the max {@link
+ // BarViewInfo#mBarNumber}.
+ final int maxBarViewNumber = mBarViewsInfo[0].getBarNumber();
+ // If the max number of bar view is zero, then we don't caculate the unit for bar height.
+ final int unit = maxBarViewNumber == 0 ? 0 : mMaxBarHeight / maxBarViewNumber;
+
+ for (BarViewInfo barView : mBarViewsInfo) {
+ barView.setBarHeight(barView.getBarNumber() * unit);
+ }
+ }
+}
diff --git a/packages/SettingsLib/BarChartPreference/src/com/android/settingslib/widget/BarView.java b/packages/SettingsLib/BarChartPreference/src/com/android/settingslib/widget/BarView.java
new file mode 100644
index 0000000000000000000000000000000000000000..6243a2de387ab15d91486a5832899bc5f56cc62f
--- /dev/null
+++ b/packages/SettingsLib/BarChartPreference/src/com/android/settingslib/widget/BarView.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2018 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.settingslib.widget;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.util.AttributeSet;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.annotation.ColorInt;
+import androidx.annotation.VisibleForTesting;
+
+/**
+ * A extension view for bar chart.
+ */
+public class BarView extends LinearLayout {
+
+ private static final String TAG = "BarView";
+
+ private View mBarView;
+ private ImageView mIcon;
+ private TextView mBarTitle;
+ private TextView mBarSummary;
+
+ /**
+ * Constructs a new BarView with the given context's theme.
+ *
+ * @param context The Context the view is running in, through which it can
+ * access the current theme, resources, etc.
+ */
+ public BarView(Context context) {
+ super(context);
+ init();
+ }
+
+ /**
+ * Constructs a new BarView with the given context's theme and the supplied
+ * attribute set.
+ *
+ * @param context the Context the view is running in
+ * @param attrs the attributes of the XML tag that is inflating the view.
+ */
+ public BarView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init();
+
+ // Get accent color
+ TypedArray a = context.obtainStyledAttributes(new int[]{android.R.attr.colorAccent});
+ @ColorInt final int colorAccent = a.getColor(0, 0);
+
+ // Get bar color from layout XML
+ a = context.obtainStyledAttributes(attrs, R.styleable.SettingsBarView);
+ @ColorInt final int barColor = a.getColor(R.styleable.SettingsBarView_barColor,
+ colorAccent);
+ a.recycle();
+
+ mBarView.setBackgroundColor(barColor);
+ }
+
+ /**
+ * This helps update the bar view UI with a {@link BarViewInfo}.
+ *
+ * @param barViewInfo A {@link BarViewInfo} saves bar view status.
+ */
+ public void updateBarViewUI(BarViewInfo barViewInfo) {
+ //Set height of bar view
+ mBarView.getLayoutParams().height = barViewInfo.getBarHeight();
+ mIcon.setImageDrawable(barViewInfo.getIcon());
+ // For now, we use the bar number as title.
+ mBarTitle.setText(Integer.toString(barViewInfo.getBarNumber()));
+ mBarSummary.setText(barViewInfo.getSummaryRes());
+ }
+
+ @VisibleForTesting
+ CharSequence getTitle() {
+ return mBarTitle.getText();
+ }
+
+ @VisibleForTesting
+ CharSequence getSummary() {
+ return mBarSummary.getText();
+ }
+
+ private void init() {
+ LayoutInflater.from(getContext()).inflate(R.layout.settings_bar_view, this);
+ setOrientation(LinearLayout.VERTICAL);
+ setGravity(Gravity.CENTER);
+
+ mBarView = findViewById(R.id.bar_view);
+ mIcon = (ImageView) findViewById(R.id.icon_view);
+ mBarTitle = (TextView) findViewById(R.id.bar_title);
+ mBarSummary = (TextView) findViewById(R.id.bar_summary);
+ }
+
+ private void setOnClickListner(View.OnClickListener listener) {
+ mBarView.setOnClickListener(listener);
+ }
+}
diff --git a/packages/SettingsLib/BarChartPreference/src/com/android/settingslib/widget/BarViewInfo.java b/packages/SettingsLib/BarChartPreference/src/com/android/settingslib/widget/BarViewInfo.java
new file mode 100644
index 0000000000000000000000000000000000000000..aa83ce99d20068cda6ef010d656db255ffb57f0e
--- /dev/null
+++ b/packages/SettingsLib/BarChartPreference/src/com/android/settingslib/widget/BarViewInfo.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2018 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.settingslib.widget;
+
+import android.graphics.drawable.Drawable;
+import android.view.View;
+
+import androidx.annotation.IntRange;
+import androidx.annotation.Nullable;
+import androidx.annotation.StringRes;
+
+import java.util.Comparator;
+
+/**
+ * A class responsible for saving bar view information.
+ */
+public class BarViewInfo implements Comparable This method should not be called by outside. It usually should be called by
+ * {@link BarChartPreference#caculateAllBarViewsHeight}
+ *
+ * @param barHeight the real bar height for bar view.
+ */
+ void setBarHeight(@IntRange(from = 0) int barHeight) {
+ mBarHeight = barHeight;
+ }
+}
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/BarChartPreferenceTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/BarChartPreferenceTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..371c3d46dfb46333fc4dcc46adb9dedd37faa714
--- /dev/null
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/BarChartPreferenceTest.java
@@ -0,0 +1,211 @@
+/*
+ * Copyright (C) 2018 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.settingslib.widget;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.view.View;
+import android.widget.TextView;
+
+import androidx.preference.PreferenceViewHolder;
+
+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 BarChartPreferenceTest {
+
+ private Context mContext;
+ private View mBarChartView;
+ private Drawable mIcon;
+ private BarView mBarView1;
+ private BarView mBarView2;
+ private BarView mBarView3;
+ private BarView mBarView4;
+ private PreferenceViewHolder mHolder;
+ private BarChartPreference mPreference;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ mBarChartView = View.inflate(mContext, R.layout.settings_bar_chart, null /* parent */);
+ mHolder = PreferenceViewHolder.createInstanceForTests(mBarChartView);
+ mPreference = new BarChartPreference(mContext, null /* attrs */);
+ mPreference.setBarChartTitle(R.string.debug_app);
+ mPreference.setBarChartDetails(R.string.debug_app);
+
+
+ mIcon = mContext.getDrawable(R.drawable.ic_menu);
+ mBarView1 = (BarView) mBarChartView.findViewById(R.id.bar_view1);
+ mBarView2 = (BarView) mBarChartView.findViewById(R.id.bar_view2);
+ mBarView3 = (BarView) mBarChartView.findViewById(R.id.bar_view3);
+ mBarView4 = (BarView) mBarChartView.findViewById(R.id.bar_view4);
+ }
+
+ @Test
+ public void setBarChartTitleRes_setTitleRes_showInBarChartTitle() {
+ final TextView titleView = (TextView) mBarChartView.findViewById(R.id.bar_chart_title);
+
+ mPreference.setBarChartTitle(R.string.debug_app);
+ mPreference.onBindViewHolder(mHolder);
+
+ assertThat(titleView.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(titleView.getText()).isEqualTo(mContext.getText(R.string.debug_app));
+ }
+
+ @Test
+ public void setBarChartDetailsRes_setDetailsRes_showInBarChartDetails() {
+ final TextView detailsView = (TextView) mBarChartView.findViewById(R.id.bar_chart_details);
+
+ mPreference.setBarChartDetails(R.string.debug_app);
+ mPreference.onBindViewHolder(mHolder);
+
+ assertThat(detailsView.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(detailsView.getText()).isEqualTo(mContext.getText(R.string.debug_app));
+ }
+
+ @Test
+ public void setBarChartDetailsClickListener_setClickListener_detailsViewAttachClickListener() {
+ final TextView detailsView = (TextView) mBarChartView.findViewById(R.id.bar_chart_details);
+
+ mPreference.setBarChartDetailsClickListener(v -> {
+ });
+ mPreference.onBindViewHolder(mHolder);
+
+ assertThat(detailsView.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(detailsView.hasOnClickListeners()).isTrue();
+ }
+
+ @Test
+ public void setAllBarViewsInfo_setOneBarViewInfo_showOneBarView() {
+ final BarViewInfo[] barViewsInfo = new BarViewInfo[]{
+ new BarViewInfo(mIcon, 10 /* barNumber */, R.string.debug_app)
+ };
+
+ mPreference.setAllBarViewsInfo(barViewsInfo);
+ mPreference.onBindViewHolder(mHolder);
+
+ assertThat(mBarView1.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(mBarView1.getTitle()).isEqualTo("10");
+
+ assertThat(mBarView2.getVisibility()).isEqualTo(View.GONE);
+ assertThat(mBarView3.getVisibility()).isEqualTo(View.GONE);
+ assertThat(mBarView4.getVisibility()).isEqualTo(View.GONE);
+ }
+
+ @Test
+ public void setAllBarViewsInfo_setTwoBarViewsInfo_showTwoBarViews() {
+ final BarViewInfo[] barViewsInfo = new BarViewInfo[]{
+ new BarViewInfo(mIcon, 20 /* barNumber */, R.string.debug_app),
+ new BarViewInfo(mIcon, 10 /* barNumber */, R.string.debug_app)
+ };
+
+ mPreference.setAllBarViewsInfo(barViewsInfo);
+ mPreference.onBindViewHolder(mHolder);
+
+ assertThat(mBarView1.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(mBarView1.getTitle()).isEqualTo("20");
+ assertThat(mBarView2.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(mBarView2.getTitle()).isEqualTo("10");
+
+ assertThat(mBarView3.getVisibility()).isEqualTo(View.GONE);
+ assertThat(mBarView4.getVisibility()).isEqualTo(View.GONE);
+ }
+
+ @Test
+ public void setAllBarViewsInfo_setThreeBarViewsInfo_showThreeBarViews() {
+ final BarViewInfo[] barViewsInfo = new BarViewInfo[]{
+ new BarViewInfo(mIcon, 20 /* barNumber */, R.string.debug_app),
+ new BarViewInfo(mIcon, 10 /* barNumber */, R.string.debug_app),
+ new BarViewInfo(mIcon, 5 /* barNumber */, R.string.debug_app)
+ };
+
+ mPreference.setAllBarViewsInfo(barViewsInfo);
+ mPreference.onBindViewHolder(mHolder);
+
+ assertThat(mBarView1.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(mBarView1.getTitle()).isEqualTo("20");
+ assertThat(mBarView2.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(mBarView2.getTitle()).isEqualTo("10");
+ assertThat(mBarView3.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(mBarView3.getTitle()).isEqualTo("5");
+
+ assertThat(mBarView4.getVisibility()).isEqualTo(View.GONE);
+ }
+
+ @Test
+ public void setAllBarViewsInfo_setFourBarViewsInfo_showFourBarViews() {
+ final BarViewInfo[] barViewsInfo = new BarViewInfo[]{
+ new BarViewInfo(mIcon, 20 /* barNumber */, R.string.debug_app),
+ new BarViewInfo(mIcon, 10 /* barNumber */, R.string.debug_app),
+ new BarViewInfo(mIcon, 5 /* barNumber */, R.string.debug_app),
+ new BarViewInfo(mIcon, 2 /* barNumber */, R.string.debug_app),
+ };
+
+ mPreference.setAllBarViewsInfo(barViewsInfo);
+ mPreference.onBindViewHolder(mHolder);
+
+ assertThat(mBarView1.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(mBarView1.getTitle()).isEqualTo("20");
+ assertThat(mBarView2.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(mBarView2.getTitle()).isEqualTo("10");
+ assertThat(mBarView3.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(mBarView3.getTitle()).isEqualTo("5");
+ assertThat(mBarView4.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(mBarView4.getTitle()).isEqualTo("2");
+ }
+
+ @Test
+ public void setAllBarViewsInfo_setFourBarViewsInfo_barViewWasSortedInDescending() {
+ final BarViewInfo[] barViewsInfo = new BarViewInfo[]{
+ new BarViewInfo(mIcon, 30 /* barNumber */, R.string.debug_app),
+ new BarViewInfo(mIcon, 50 /* barNumber */, R.string.debug_app),
+ new BarViewInfo(mIcon, 5 /* barNumber */, R.string.debug_app),
+ new BarViewInfo(mIcon, 10 /* barNumber */, R.string.debug_app),
+ };
+
+ mPreference.setAllBarViewsInfo(barViewsInfo);
+ mPreference.onBindViewHolder(mHolder);
+
+ assertThat(mBarView1.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(mBarView1.getTitle()).isEqualTo("50");
+ assertThat(mBarView2.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(mBarView2.getTitle()).isEqualTo("30");
+ assertThat(mBarView3.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(mBarView3.getTitle()).isEqualTo("10");
+ assertThat(mBarView4.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(mBarView4.getTitle()).isEqualTo("5");
+ }
+
+ @Test
+ public void setAllBarViewsInfo_setValidSummaryRes_barViewShouldShowSummary() {
+ final BarViewInfo[] barViewsInfo = new BarViewInfo[]{
+ new BarViewInfo(mIcon, 10 /* barNumber */, R.string.debug_app),
+ };
+
+ mPreference.setAllBarViewsInfo(barViewsInfo);
+ mPreference.onBindViewHolder(mHolder);
+
+ assertThat(mBarView1.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(mBarView1.getSummary()).isEqualTo(mContext.getText(R.string.debug_app));
+ }
+}