--- /dev/null
+<?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>
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"
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;
/**
* 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. */
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);
}
}
+ public void setProgress(float progress) {
+ mProgress = progress;
+ notifyChanged();
+ }
+
public void setUsageInfo(long cycleEnd, long snapshotTime, CharSequence carrierName,
int numPlans, Intent launchIntent) {
mCycleEndTimeMs = cycleEnd;
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);
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);
import com.android.settings.Utils;
+/**
+ * @Deprecated Use {@link android.widget.ProgressBar} instead.
+ */
public class LinearColorBar extends LinearLayout {
static final int RIGHT_COLOR = 0xffced7db;
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;
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;
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);
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);
}
}
\ No newline at end of file