2 * Copyright (C) 2017 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
15 package com.android.settings.datausage;
17 import android.content.Context;
18 import android.support.annotation.ColorRes;
19 import android.support.v7.preference.Preference;
20 import android.support.v7.preference.PreferenceViewHolder;
21 import android.util.AttributeSet;
22 import android.widget.TextView;
23 import com.android.settings.R;
24 import com.android.settings.widget.DonutView;
27 * Provides a summary of data plans as preferences on settings page.
29 public final class DataPlanSummaryPreference extends Preference {
31 private String mDescription;
32 private double mPercentageUsage;
33 private int mUsageTextColor;
34 private int mMeterBackgroundColor;
35 private int mMeterConsumedColor;
37 public DataPlanSummaryPreference(Context context) {
39 setLayoutResource(R.layout.settings_data_plan_summary_preference);
42 public DataPlanSummaryPreference(Context context, AttributeSet attrs) {
43 super(context, attrs);
44 setLayoutResource(R.layout.settings_data_plan_summary_preference);
47 public void setName(String planName) {
52 public void setDescription(String planDescription) {
53 mDescription = planDescription;
57 public void setPercentageUsage(double percentageUsage) {
58 mPercentageUsage = percentageUsage;
62 public void setUsageTextColor(@ColorRes int planUsageTextColor) {
63 mUsageTextColor = planUsageTextColor;
67 public void setMeterBackgroundColor(@ColorRes int meterBackgroundColor) {
68 mMeterBackgroundColor = meterBackgroundColor;
72 public void setMeterConsumedColor(@ColorRes int meterConsumedColor) {
73 mMeterConsumedColor = meterConsumedColor;
78 public void onBindViewHolder(PreferenceViewHolder holder) {
79 super.onBindViewHolder(holder);
80 holder.setDividerAllowedAbove(false);
81 TextView titleView = (TextView) holder.findViewById(android.R.id.title);
82 titleView.setTextColor(mUsageTextColor);
83 ((TextView) holder.findViewById(android.R.id.text1)).setText(mName);
84 ((TextView) holder.findViewById(android.R.id.text2)).setText(mDescription);
85 DonutView donutView = (DonutView) holder.findViewById(R.id.donut);
86 donutView.setPercentage(mPercentageUsage);
87 donutView.setMeterBackgroundColor(mMeterBackgroundColor);
88 donutView.setMeterConsumedColor(mMeterConsumedColor);