Data plans setting peference.

Change-Id: Ieb2aa67ab98140aa90501227345a15ad64cf124c
Note: These changes are required for Data balance UI.
Bug: 62349208
Test: make RunSettingsRoboTests -j40
This commit is contained in:
Rajeev Kumar
2017-07-11 15:44:46 -07:00
parent 6fab00e64b
commit c6f0b9d6f3
4 changed files with 297 additions and 8 deletions

View File

@@ -0,0 +1,90 @@
/*
* Copyright (C) 2017 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.datausage;
import android.content.Context;
import android.support.annotation.ColorRes;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder;
import android.util.AttributeSet;
import android.widget.TextView;
import com.android.settings.R;
import com.android.settings.widget.DonutView;
/**
* Provides a summary of data plans as preferences on settings page.
*/
public final class DataPlanSummaryPreference extends Preference {
private String mName;
private String mDescription;
private double mPercentageUsage;
private int mUsageTextColor;
private int mMeterBackgroundColor;
private int mMeterConsumedColor;
public DataPlanSummaryPreference(Context context) {
super(context);
setLayoutResource(R.layout.settings_data_plan_summary_preference);
}
public DataPlanSummaryPreference(Context context, AttributeSet attrs) {
super(context, attrs);
setLayoutResource(R.layout.settings_data_plan_summary_preference);
}
public void setName(String planName) {
mName = planName;
notifyChanged();
}
public void setDescription(String planDescription) {
mDescription = planDescription;
notifyChanged();
}
public void setPercentageUsage(double percentageUsage) {
mPercentageUsage = percentageUsage;
notifyChanged();
}
public void setUsageTextColor(@ColorRes int planUsageTextColor) {
mUsageTextColor = planUsageTextColor;
notifyChanged();
}
public void setMeterBackgroundColor(@ColorRes int meterBackgroundColor) {
mMeterBackgroundColor = meterBackgroundColor;
notifyChanged();
}
public void setMeterConsumedColor(@ColorRes int meterConsumedColor) {
mMeterConsumedColor = meterConsumedColor;
notifyChanged();
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
holder.setDividerAllowedAbove(false);
TextView titleView = (TextView) holder.findViewById(android.R.id.title);
titleView.setTextColor(mUsageTextColor);
((TextView) holder.findViewById(android.R.id.text1)).setText(mName);
((TextView) holder.findViewById(android.R.id.text2)).setText(mDescription);
DonutView donutView = (DonutView) holder.findViewById(R.id.donut);
donutView.setPercentage(mPercentageUsage);
donutView.setMeterBackgroundColor(mMeterBackgroundColor);
donutView.setMeterConsumedColor(mMeterConsumedColor);
}
}

View File

@@ -48,6 +48,8 @@ public class DonutView extends View {
private String mPercentString;
private String mFullString;
private boolean mShowPercentString = true;
private int mMeterBackgroundColor;
private int mMeterConsumedColor;
public DonutView(Context context) {
super(context);
@@ -55,18 +57,18 @@ public class DonutView extends View {
public DonutView(Context context, AttributeSet attrs) {
super(context, attrs);
int meterBackgroundColor = context.getColor(R.color.meter_background_color);
int meterConsumedColor = Utils.getDefaultColor(mContext, R.color.meter_consumed_color);
mMeterBackgroundColor = context.getColor(R.color.meter_background_color);
mMeterConsumedColor = Utils.getDefaultColor(mContext, R.color.meter_consumed_color);
boolean applyColorAccent = true;
Resources resources = context.getResources();
mStrokeWidth = resources.getDimension(R.dimen.storage_donut_thickness);
if (attrs != null) {
TypedArray styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.DonutView);
meterBackgroundColor = styledAttrs.getColor(R.styleable.DonutView_meterBackgroundColor,
meterBackgroundColor);
meterConsumedColor = styledAttrs.getColor(R.styleable.DonutView_meterConsumedColor,
meterConsumedColor);
mMeterBackgroundColor = styledAttrs.getColor(R.styleable.DonutView_meterBackgroundColor,
mMeterBackgroundColor);
mMeterConsumedColor = styledAttrs.getColor(R.styleable.DonutView_meterConsumedColor,
mMeterConsumedColor);
applyColorAccent = styledAttrs.getBoolean(R.styleable.DonutView_applyColorAccent,
true);
mShowPercentString = styledAttrs.getBoolean(R.styleable.DonutView_showPercentString,
@@ -81,14 +83,14 @@ public class DonutView extends View {
mBackgroundCircle.setStrokeCap(Paint.Cap.BUTT);
mBackgroundCircle.setStyle(Paint.Style.STROKE);
mBackgroundCircle.setStrokeWidth(mStrokeWidth);
mBackgroundCircle.setColor(meterBackgroundColor);
mBackgroundCircle.setColor(mMeterBackgroundColor);
mFilledArc = new Paint();
mFilledArc.setAntiAlias(true);
mFilledArc.setStrokeCap(Paint.Cap.BUTT);
mFilledArc.setStyle(Paint.Style.STROKE);
mFilledArc.setStrokeWidth(mStrokeWidth);
mFilledArc.setColor(meterConsumedColor);
mFilledArc.setColor(mMeterConsumedColor);
if (applyColorAccent) {
final ColorFilter mAccentColorFilter =
@@ -179,12 +181,24 @@ public class DonutView extends View {
invalidate();
}
@ColorRes
public int getMeterBackgroundColor() {
return mMeterBackgroundColor;
}
public void setMeterBackgroundColor(@ColorRes int meterBackgroundColor) {
mMeterBackgroundColor = meterBackgroundColor;
mBackgroundCircle.setColor(meterBackgroundColor);
invalidate();
}
@ColorRes
public int getMeterConsumedColor() {
return mMeterConsumedColor;
}
public void setMeterConsumedColor(@ColorRes int meterConsumedColor) {
mMeterConsumedColor = meterConsumedColor;
mFilledArc.setColor(meterConsumedColor);
invalidate();
}