• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.settings.widget;
17 
18 import android.content.Context;
19 import android.support.v7.preference.Preference;
20 import android.support.v7.preference.PreferenceViewHolder;
21 import android.text.TextUtils;
22 import android.util.AttributeSet;
23 import android.view.View;
24 import android.widget.ProgressBar;
25 
26 import com.android.settings.R;
27 
28 public class AppPreference extends Preference {
29 
30     private int mProgress;
31     private boolean mProgressVisible;
32 
AppPreference(Context context)33     public AppPreference(Context context) {
34         super(context);
35         setLayoutResource(R.layout.preference_app);
36     }
37 
AppPreference(Context context, AttributeSet attrs)38     public AppPreference(Context context, AttributeSet attrs) {
39         super(context, attrs);
40         setLayoutResource(R.layout.preference_app);
41     }
42 
setProgress(int amount)43     public void setProgress(int amount) {
44         mProgress = amount;
45         mProgressVisible = true;
46         notifyChanged();
47     }
48 
49     @Override
onBindViewHolder(PreferenceViewHolder view)50     public void onBindViewHolder(PreferenceViewHolder view) {
51         super.onBindViewHolder(view);
52 
53         view.findViewById(R.id.summary_container)
54                 .setVisibility(TextUtils.isEmpty(getSummary()) ? View.GONE : View.VISIBLE);
55         final ProgressBar progress = (ProgressBar) view.findViewById(android.R.id.progress);
56         if (mProgressVisible) {
57             progress.setProgress(mProgress);
58             progress.setVisibility(View.VISIBLE);
59         } else {
60             progress.setVisibility(View.GONE);
61         }
62     }
63 }
64