• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 
17 package com.android.settings.deviceinfo;
18 
19 import android.content.Context;
20 import android.graphics.Color;
21 import android.util.MathUtils;
22 import android.view.View;
23 import android.widget.ProgressBar;
24 import android.widget.TextView;
25 
26 import androidx.preference.Preference;
27 import androidx.preference.PreferenceViewHolder;
28 
29 import com.android.settings.R;
30 
31 public class StorageSummaryPreference extends Preference {
32     private int mPercent = -1;
33 
StorageSummaryPreference(Context context)34     public StorageSummaryPreference(Context context) {
35         super(context);
36 
37         setLayoutResource(R.layout.storage_summary);
38         setEnabled(false);
39     }
40 
setPercent(long usedBytes, long totalBytes)41     public void setPercent(long usedBytes, long totalBytes) {
42         mPercent = MathUtils.constrain((int) ((usedBytes * 100) / totalBytes),
43                 (usedBytes > 0) ? 1 : 0, 100);
44     }
45 
46     @Override
onBindViewHolder(PreferenceViewHolder view)47     public void onBindViewHolder(PreferenceViewHolder view) {
48         final ProgressBar progress = (ProgressBar) view.findViewById(android.R.id.progress);
49         if (mPercent != -1) {
50             progress.setVisibility(View.VISIBLE);
51             progress.setProgress(mPercent);
52             progress.setScaleY(7f);
53         } else {
54             progress.setVisibility(View.GONE);
55         }
56 
57         final TextView summary = (TextView) view.findViewById(android.R.id.summary);
58         summary.setTextColor(Color.parseColor("#8a000000"));
59 
60         super.onBindViewHolder(view);
61     }
62 }
63