Home | History | Annotate | Download | only in fuelgauge
      1 /*
      2  * Copyright (C) 2009 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.fuelgauge;
     18 
     19 import android.content.Context;
     20 import android.graphics.drawable.Drawable;
     21 import android.preference.Preference;
     22 import android.view.View;
     23 import android.widget.ProgressBar;
     24 import android.widget.TextView;
     25 
     26 import com.android.settings.R;
     27 
     28 /**
     29  * Custom preference for displaying power consumption as a bar and an icon on
     30  * the left for the subsystem/app type.
     31  */
     32 public class PowerGaugePreference extends Preference {
     33     private BatterySipper mInfo;
     34     private int mProgress;
     35     private CharSequence mProgressText;
     36 
     37     public PowerGaugePreference(Context context, Drawable icon, BatterySipper info) {
     38         super(context);
     39         setLayoutResource(R.layout.app_percentage_item);
     40         setIcon(icon);
     41         mInfo = info;
     42     }
     43 
     44     public void setPercent(double percentOfMax, double percentOfTotal) {
     45         mProgress = (int) Math.ceil(percentOfMax);
     46         mProgressText = getContext().getResources().getString(
     47                 R.string.percentage, (int) Math.ceil(percentOfTotal));
     48         notifyChanged();
     49     }
     50 
     51     BatterySipper getInfo() {
     52         return mInfo;
     53     }
     54 
     55     @Override
     56     protected void onBindView(View view) {
     57         super.onBindView(view);
     58 
     59         final ProgressBar progress = (ProgressBar) view.findViewById(android.R.id.progress);
     60         progress.setProgress(mProgress);
     61 
     62         final TextView text1 = (TextView) view.findViewById(android.R.id.text1);
     63         text1.setText(mProgressText);
     64     }
     65 }
     66