blob: 593b6f5b35f40f160c3acdbbebf76723792e47e8 [file] [log] [blame]
Fan Zhang5b8116d2018-09-24 11:55:12 -07001/*
2 * Copyright (C) 2018 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
17package com.android.settingslib.widget.apppreference;
18
19import android.content.Context;
20import android.text.TextUtils;
21import android.util.AttributeSet;
22import android.view.View;
23import android.widget.ProgressBar;
24
25import androidx.preference.Preference;
26import androidx.preference.PreferenceViewHolder;
27
28public class AppPreference extends Preference {
29
30 private int mProgress;
31 private boolean mProgressVisible;
32
33 public AppPreference(Context context) {
34 super(context);
35 setLayoutResource(R.layout.preference_app);
36 }
37
38 public AppPreference(Context context, AttributeSet attrs) {
39 super(context, attrs);
40 setLayoutResource(R.layout.preference_app);
41 }
42
43 public void setProgress(int amount) {
44 mProgress = amount;
45 mProgressVisible = true;
46 notifyChanged();
47 }
48
49 @Override
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}