1 /* 2 * Copyright (C) 2013 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.applications; 18 19 import android.content.Context; 20 import android.graphics.drawable.ColorDrawable; 21 import android.graphics.drawable.Drawable; 22 import android.preference.Preference; 23 import android.text.format.Formatter; 24 import android.view.View; 25 import android.widget.ProgressBar; 26 import android.widget.TextView; 27 import com.android.settings.R; 28 29 public class ProcessStatsPreference extends Preference { 30 private final ProcStatsEntry mEntry; 31 private int mProgress; 32 private CharSequence mProgressText; 33 ProcessStatsPreference(Context context, Drawable icon, ProcStatsEntry entry)34 public ProcessStatsPreference(Context context, Drawable icon, ProcStatsEntry entry) { 35 super(context); 36 mEntry = entry; 37 setLayoutResource(R.layout.app_percentage_item); 38 setIcon(icon != null ? icon : new ColorDrawable(0)); 39 } 40 getEntry()41 public ProcStatsEntry getEntry() { 42 return mEntry; 43 } 44 setPercent(double percentOfWeight, double percentOfTime)45 public void setPercent(double percentOfWeight, double percentOfTime) { 46 mProgress = (int) Math.ceil(percentOfWeight); 47 mProgressText = getContext().getResources().getString( 48 R.string.percentage, (int) Math.round(percentOfTime)); 49 notifyChanged(); 50 } 51 52 @Override onBindView(View view)53 protected void onBindView(View view) { 54 super.onBindView(view); 55 56 final ProgressBar progress = (ProgressBar) view.findViewById(android.R.id.progress); 57 progress.setProgress(mProgress); 58 59 final TextView text1 = (TextView) view.findViewById(android.R.id.text1); 60 text1.setText(mProgressText); 61 } 62 } 63