OSDN Git Service

Merge "Fix search indexing for encryption_and_credential page" into oc-dr1-dev
[android-x86/packages-apps-Settings.git] / src / com / android / settings / datausage / DataPlanSummaryPreference.java
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
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
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
13  */
14
15 package com.android.settings.datausage;
16
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;
25
26 /**
27  * Provides a summary of data plans as preferences on settings page.
28  */
29 public final class DataPlanSummaryPreference extends Preference {
30     private String mName;
31     private String mDescription;
32     private double mPercentageUsage;
33     private int mUsageTextColor;
34     private int mMeterBackgroundColor;
35     private int mMeterConsumedColor;
36
37     public DataPlanSummaryPreference(Context context) {
38         super(context);
39         setLayoutResource(R.layout.settings_data_plan_summary_preference);
40     }
41
42     public DataPlanSummaryPreference(Context context, AttributeSet attrs) {
43         super(context, attrs);
44         setLayoutResource(R.layout.settings_data_plan_summary_preference);
45     }
46
47     public void setName(String planName) {
48         mName = planName;
49         notifyChanged();
50     }
51
52     public void setDescription(String planDescription) {
53         mDescription = planDescription;
54         notifyChanged();
55     }
56
57     public void setPercentageUsage(double percentageUsage) {
58         mPercentageUsage = percentageUsage;
59         notifyChanged();
60     }
61
62     public void setUsageTextColor(@ColorRes int planUsageTextColor) {
63         mUsageTextColor = planUsageTextColor;
64         notifyChanged();
65     }
66
67     public void setMeterBackgroundColor(@ColorRes int meterBackgroundColor) {
68         mMeterBackgroundColor = meterBackgroundColor;
69         notifyChanged();
70     }
71
72     public void setMeterConsumedColor(@ColorRes int meterConsumedColor) {
73         mMeterConsumedColor = meterConsumedColor;
74         notifyChanged();
75     }
76
77     @Override
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);
89     }
90 }