Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d610e516 authored by Sundeep Ghuman's avatar Sundeep Ghuman Committed by Android (Google) Code Review
Browse files

Merge "Fix the ProgressBar in DataUsageSummaryV2 page." into pi-dev

parents 0f6ff091 ea8d8663
Loading
Loading
Loading
Loading
+45 −0
Original line number Diff line number Diff line
<?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>
+5 −3
Original line number Diff line number Diff line
@@ -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"
+39 −2
Original line number Diff line number Diff line
@@ -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);

+1 −2
Original line number Diff line number Diff line
@@ -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);
+3 −0
Original line number Diff line number Diff line
@@ -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;
Loading