Fix the ProgressBar in DataUsageSummaryV2 page.

Bug: 70950124
Test: make RunSettingsRoboTests ROBOTEST_FILTER=DataUsageSummaryPreferenceTest
Change-Id: I83f268c0824d9e3520899725fa572753e1de0814
This commit is contained in:
Sundeep Ghuman
2018-03-12 22:25:23 -07:00
parent de08983dd2
commit ea8d866337
6 changed files with 143 additions and 7 deletions

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape android:shape="rectangle"
android:tint="?android:attr/colorControlActivated">
<corners android:radius="5dp" />
<size android:height="10dp" />
<solid android:color="@color/white_disabled" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<scale android:scaleWidth="100%">
<shape android:shape="rectangle"
android:tint="?android:attr/colorControlActivated">
<corners android:radius="5dp" />
<size android:height="10dp" />
<solid android:color="@color/white_disabled" />
</shape>
</scale>
</item>
<item android:id="@android:id/progress">
<scale android:scaleWidth="100%">
<shape android:shape="rectangle"
android:tint="?android:attr/colorControlActivated">
<corners android:radius="5dp" />
<size android:height="10dp" />
<solid android:color="@android:color/black" />
</shape>
</scale>
</item>
</layer-list>

View File

@@ -45,10 +45,12 @@
android:textColor="?android:attr/colorAccent"
android:textAppearance="@android:style/TextAppearance.Material.Large" />
<com.android.settings.widget.LinearColorBar
android:id="@+id/color_bar"
<android.widget.ProgressBar
android:id="@+id/determinateBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="28dp" />
android:layout_height="10dp"
android:progressDrawable="@drawable/data_usage_progress"/>
<LinearLayout
android:id="@+id/label_bar"

View File

@@ -18,14 +18,16 @@ package com.android.settings.datausage;
import android.content.Context;
import android.content.Intent;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.android.settings.R;
import com.android.settings.SummaryPreference;
import com.android.settingslib.utils.StringUtil;
import java.util.Objects;
@@ -33,7 +35,11 @@ import java.util.Objects;
/**
* Provides a summary of data usage.
*/
public class DataUsageSummaryPreference extends SummaryPreference {
public class DataUsageSummaryPreference extends Preference {
private boolean mChartEnabled = true;
private String mStartLabel;
private String mEndLabel;
private int mNumPlans;
/** The ending time of the billing cycle in milliseconds since epoch. */
@@ -45,6 +51,9 @@ public class DataUsageSummaryPreference extends SummaryPreference {
private String mLimitInfoText;
private Intent mLaunchIntent;
/** Progress to display on ProgressBar */
private float mProgress;
public DataUsageSummaryPreference(Context context, AttributeSet attrs) {
super(context, attrs);
setLayoutResource(R.layout.data_usage_summary_preference);
@@ -57,6 +66,11 @@ public class DataUsageSummaryPreference extends SummaryPreference {
}
}
public void setProgress(float progress) {
mProgress = progress;
notifyChanged();
}
public void setUsageInfo(long cycleEnd, long snapshotTime, CharSequence carrierName,
int numPlans, Intent launchIntent) {
mCycleEndTimeMs = cycleEnd;
@@ -67,10 +81,33 @@ public class DataUsageSummaryPreference extends SummaryPreference {
notifyChanged();
}
public void setChartEnabled(boolean enabled) {
if (mChartEnabled != enabled) {
mChartEnabled = enabled;
notifyChanged();
}
}
public void setLabels(String start, String end) {
mStartLabel = start;
mEndLabel = end;
notifyChanged();
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
if (mChartEnabled && (!TextUtils.isEmpty(mStartLabel) || !TextUtils.isEmpty(mEndLabel))) {
holder.findViewById(R.id.label_bar).setVisibility(View.VISIBLE);
ProgressBar bar = (ProgressBar) holder.findViewById(R.id.determinateBar);
bar.setProgress((int) (mProgress * 100));
((TextView) holder.findViewById(android.R.id.text1)).setText(mStartLabel);
((TextView) holder.findViewById(android.R.id.text2)).setText(mEndLabel);
} else {
holder.findViewById(R.id.label_bar).setVisibility(View.GONE);
}
TextView usageTitle = (TextView) holder.findViewById(R.id.usage_title);
usageTitle.setVisibility(mNumPlans > 1 ? View.VISIBLE : View.GONE);

View File

@@ -194,8 +194,7 @@ public class DataUsageSummaryPreferenceController extends BasePreferenceControll
summaryPreference.setChartEnabled(true);
summaryPreference.setLabels(Formatter.formatFileSize(mContext, 0 /* sizeBytes */),
Formatter.formatFileSize(mContext, mDataplanSize));
summaryPreference.setRatios(mDataplanUse / (float) mDataplanSize, 0 /* middle */,
(mDataplanSize - mDataplanUse) / (float) mDataplanSize);
summaryPreference.setProgress(mDataplanUse / (float) mDataplanSize);
}
summaryPreference.setUsageInfo(mCycleEnd, mSnapshotTime, mCarrierName,
mDataplanCount, mManageSubscriptionIntent);

View File

@@ -26,6 +26,9 @@ import android.widget.LinearLayout;
import com.android.settings.Utils;
/**
* @Deprecated Use {@link android.widget.ProgressBar} instead.
*/
public class LinearColorBar extends LinearLayout {
static final int RIGHT_COLOR = 0xffced7db;

View File

@@ -24,6 +24,8 @@ import android.support.v7.preference.PreferenceViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.android.settings.R;
@@ -54,6 +56,10 @@ public class DataUsageSummaryPreferenceTest {
private TextView mCarrierInfo;
private TextView mDataLimits;
private Button mLaunchButton;
private LinearLayout mLabelBar;
private TextView mLabel1;
private TextView mLabel2;
private ProgressBar mProgressBar;
private long mCycleEnd;
private long mUpdateTime;
@@ -159,6 +165,46 @@ public class DataUsageSummaryPreferenceTest {
assertThat(mDataLimits.getVisibility()).isEqualTo(View.GONE);
}
@Test
public void testSetChartEnabledFalse_hidesLabelBar() {
setValidLabels();
mSummaryPreference.setChartEnabled(false);
bindViewHolder();
assertThat(mLabelBar.getVisibility()).isEqualTo(View.GONE);
}
@Test
public void testSetEmptyLabels_hidesLabelBar() {
mSummaryPreference.setLabels("", "");
bindViewHolder();
assertThat(mLabelBar.getVisibility()).isEqualTo(View.GONE);
}
@Test
public void testLabelBar_isVisible_whenLabelsSet() {
setValidLabels();
//mChartEnabled defaults to true
bindViewHolder();
assertThat(mLabelBar.getVisibility()).isEqualTo(View.VISIBLE);
}
@Test
public void testSetProgress_updatesProgressBar() {
setValidLabels();
mSummaryPreference.setProgress(.5f);
bindViewHolder();
assertThat(mProgressBar.getProgress()).isEqualTo(50);
}
private void setValidLabels() {
mSummaryPreference.setLabels("0.0 GB", "5.0 GB");
}
private void bindViewHolder() {
mSummaryPreference.onBindViewHolder(mHolder);
mUsageTitle = (TextView) mHolder.findViewById(R.id.usage_title);
@@ -166,5 +212,9 @@ public class DataUsageSummaryPreferenceTest {
mCarrierInfo = (TextView) mHolder.findViewById(R.id.carrier_and_update);
mDataLimits = (TextView) mHolder.findViewById(R.id.data_limits);
mLaunchButton = (Button) mHolder.findViewById(R.id.launch_mdp_app_button);
mLabelBar = (LinearLayout) mHolder.findViewById(R.id.label_bar);
mLabel1 = (TextView) mHolder.findViewById(R.id.text1);
mLabel2 = (TextView) mHolder.findViewById(R.id.text2);
mProgressBar = (ProgressBar) mHolder.findViewById(R.id.determinateBar);
}
}