码迷,mamicode.com
首页 > 其他好文 > 详细

增加电量百分比功能

时间:2015-01-07 11:01:46      阅读:503      评论:0      收藏:0      [点我收藏+]

标签:电量百分比   sc7715   android4.4.2   

差分包:

--- a/idh.code/frameworks/base/core/java/android/provider/Settings.java
+++ b/idh.code/frameworks/base/core/java/android/provider/Settings.java
@@ -4519,6 +4519,10 @@ public final class Settings {
          */
         public static final String PAYMENT_SERVICE_SEARCH_URI = "payment_service_search_uri";
 
+        /*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> start*/
+       public static final String BATTERY_PERCENTAGE = "battery_percentage";
+        /*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> end*/
+               
         /**
          * This are the settings to be backed up.
          *
diff --git a/idh.code/frameworks/base/packages/SettingsProvider/res/values/defaults.xml b/idh.code/frameworks/base/packages/SettingsPro
index 506c0b1..b4c7d8b 100755
--- a/idh.code/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
+++ b/idh.code/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
@@ -190,4 +190,6 @@
     <integer name="def_sms_validity">255</integer>
     <!--tangjc add-->
     <string name="time_12_24" translatable="false">24</string>
+    <!--Yang Liu add-->
+    <bool name="def_battery_percentage">false</bool>
 </resources>
diff --git a/idh.code/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/idh.code/frame
index 22351dc..35b0554 100755
--- a/idh.code/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
+++ b/idh.code/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
@@ -2148,6 +2148,10 @@ public class DatabaseHelper extends SQLiteOpenHelper {
                                   R.string.config_default_input_method);
             }
             /* @} */
+/*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> start*/
+            loadBooleanSetting(stmt, Settings.Secure.BATTERY_PERCENTAGE,
+                    R.bool.def_battery_percentage);
+/*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> end*/            
         } finally {
             if (stmt != null) stmt.close();
         }
diff --git a/idh.code/frameworks/base/packages/SystemUI/res/layout/status_bar.xml b/idh.code/frameworks/base/packages/SystemUI/res/layo
old mode 100644
new mode 100755
index 1b67e8a..794a0c6
--- a/idh.code/frameworks/base/packages/SystemUI/res/layout/status_bar.xml
+++ b/idh.code/frameworks/base/packages/SystemUI/res/layout/status_bar.xml
@@ -95,6 +95,15 @@
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     />
+                 <TextView
+                       android:id="@+id/percentage"
+                       android:layout_height="wrap_content"
+                       android:layout_width="wrap_content"
+                       android:visibility = "gone"
+                       android:paddingLeft="4dip"
+                       android:textSize="16sp"
+                       android:textColor="@android:color/holo_blue_light"
+                />
                 <!-- battery must be padded below by 2px to match assets -->
                 <com.android.systemui.BatteryMeterView
                     android:id="@+id/battery"
diff --git a/idh.code/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/idh.code/framewo
old mode 100644
new mode 100755
index ba5c2a9..67ed407
--- a/idh.code/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/idh.code/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -548,6 +548,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode {
         // Other icons
         mLocationController = new LocationController(mContext); // will post a notification
         mBatteryController = new BatteryController(mContext);
+       /*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> start*/
+       mBatteryController.addLabelView((TextView) mStatusBarWindow.findViewById(R.id.percentage));
+       /*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> end*/
         mNetworkController = new NetworkController(mContext);
         mBluetoothController = new BluetoothController(mContext);
         mRotationLockController = new RotationLockController(mContext);
diff --git a/idh.code/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryController.java b/idh.code/fra
old mode 100644
new mode 100755
index d098d3d..1c59ad1
--- a/idh.code/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryController.java
+++ b/idh.code/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryController.java
@@ -25,13 +25,23 @@ import android.graphics.drawable.Drawable;
 import android.os.BatteryManager;
 import android.util.Log;
 import android.widget.ImageView;
-
+/*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> start*/
+import android.widget.TextView;
+import android.view.View;
+import android.provider.Settings;
+/*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> end*/
 import java.util.ArrayList;
 
 import com.android.systemui.R;
 
 public class BatteryController extends BroadcastReceiver {
     private static final String TAG = "StatusBar.BatteryController";
+    /*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> start*/
+    private boolean mShouldShowBatteryPercentage = false;
+    private String mBatteryPercentage = "100%";
+    private static final String ACTION_BATTERY_PERCENTAGE_SWITCH = "silence.intent.action.BATTERY_PERCENTAGE_SWITCH";
+    private ArrayList<TextView> mLabelViews = new ArrayList<TextView>();
+    /*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> end*/
     /* SPRD: Modify 20140319 of bug 290550,rm systemui animation {@ */
     /*Context mContext;
     private ArrayList<ImageView> mIconViews = new ArrayList<ImageView>();
@@ -63,8 +73,11 @@ public class BatteryController extends BroadcastReceiver {
 
     public BatteryController(Context context) {
         //mContext = context;
+        mShouldShowBatteryPercentage = (Settings.Secure.getInt(context.getContentResolver(), 
+                                               Settings.Secure.BATTERY_PERCENTAGE, 0) != 0);
         IntentFilter filter = new IntentFilter();
         filter.addAction(Intent.ACTION_BATTERY_CHANGED);
+       filter.addAction(ACTION_BATTERY_PERCENTAGE_SWITCH);
         context.registerReceiver(this, filter);
         /* SPRD: Modify 20140319 of bug 290550,rm systemui animation {@ */
         /*m_Anim_Charge_a = (AnimationDrawable) context.getResources().getDrawable(R.anim.stat_sys_battery_charge_anim_a);
@@ -76,7 +89,18 @@ public class BatteryController extends BroadcastReceiver {
         m_Anim_Charge_g = (AnimationDrawable) context.getResources().getDrawable(R.anim.stat_sys_battery_charge_anim_g);*/
         /* @} */
     }
-
+       
+     /*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> start*/
+     public void addLabelView(TextView v) {
+        mLabelViews.add(v);
+    }
+    private  String getBatteryPercentage(Intent batteryChangedIntent) {
+        int level = batteryChangedIntent.getIntExtra("level", 0);
+        int scale = batteryChangedIntent.getIntExtra("scale", 100);
+        return String.valueOf(level * 100 / scale) + "%";
+    }
+     /*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> end*/
+        
     public void addStateChangedCallback(BatteryStateChangeCallback cb) {
         mChangeCallbacks.add(cb);
     }
@@ -189,7 +213,34 @@ public class BatteryController extends BroadcastReceiver {
                 }
             }*/
             /* @} */
+
+           /*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> start*/
+           mBatteryPercentage = getBatteryPercentage(intent);
+            Log.d(TAG,"mBatteryPercentage is " + mBatteryPercentage + " mShouldShowBatteryPercentage is "
+                    + mShouldShowBatteryPercentage + " mLabelViews.size() " + mLabelViews.size());
+            TextView v = mLabelViews.get(0);
+            if (mShouldShowBatteryPercentage) {
+                v.setText(mBatteryPercentage);
+                v.setVisibility(View.VISIBLE);
+            } else {
+                v.setVisibility(View.GONE);
+            }
+           /*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> end*/
+        } 
+           /*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> start*/
+       else if (action.equals(ACTION_BATTERY_PERCENTAGE_SWITCH)) {
+            mShouldShowBatteryPercentage = (intent.getIntExtra("state",0) == 1);
+            Log.d(TAG, " OnReceive from mediatek.intent.ACTION_BATTERY_PERCENTAGE_SWITCH  mShouldShowBatteryPercentage" +
+                    " is " + mShouldShowBatteryPercentage);
+            TextView v = mLabelViews.get(0);
+            if (mShouldShowBatteryPercentage) {
+                v.setText(mBatteryPercentage);
+                v.setVisibility(View.VISIBLE);
+            } else {
+                v.setVisibility(View.GONE);
+            }
         }
+       /*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> end*/
     }
 
     // SPRD: Modify 20140319 of bug 290550,rm systemui animation
diff --git a/idh.code/packages/apps/Settings/res/values-id/strings.xml b/idh.code/packages/apps/Settings/res/values-id/strings.xml
old mode 100644
new mode 100755
index a7d5455..f024973
--- a/idh.code/packages/apps/Settings/res/values-id/strings.xml
+++ b/idh.code/packages/apps/Settings/res/values-id/strings.xml
@@ -1562,4 +1562,5 @@
   <string name="master_clear_level">"Kapasitas kurang dari 30%, apakah melanjutkan operasi ulang telepon?"</string>
   <string name="factory_dialog_title">"Minta"</string>
   <string name="wep_password_tip_text">Silakan masukan 5,13,29 karakter ASCII atau 10,26,58 karakter lain untuk otentikasi WEP.</strin
+  <string name="battery_percent">baterai Persentase</string>
 </resources>
\ No newline at end of file
diff --git a/idh.code/packages/apps/Settings/res/values-zh-rCN/strings_ex.xml b/idh.code/packages/apps/Settings/res/values-zh-rCN/strin
old mode 100644
new mode 100755
index 0de2451..deaae77
--- a/idh.code/packages/apps/Settings/res/values-zh-rCN/strings_ex.xml
+++ b/idh.code/packages/apps/Settings/res/values-zh-rCN/strings_ex.xml
@@ -60,4 +60,5 @@
   <string name="close">关闭</string>
 
     <string name="apn_settings_ex">SIM<xliff:g id="SIM">%s</xliff:g> 接入点名称</string>
+  <string name="battery_percent">电量百分比</string>
 </resources>
\ No newline at end of file
diff --git a/idh.code/packages/apps/Settings/res/values-zh-rTW/strings_ex.xml b/idh.code/packages/apps/Settings/res/values-zh-rTW/strin
old mode 100644
new mode 100755
index fc853f9..60e43c5
--- a/idh.code/packages/apps/Settings/res/values-zh-rTW/strings_ex.xml
+++ b/idh.code/packages/apps/Settings/res/values-zh-rTW/strings_ex.xml
@@ -60,4 +60,5 @@
   <string name="close">關閉</string>
 
     <string name="apn_settings_ex">SIM<xliff:g id="SIM">%s</xliff:g> 存取點名稱</string>
+  <string name="battery_percent">電量百分比</string>
 </resources>
diff --git a/idh.code/packages/apps/Settings/res/values/strings.xml b/idh.code/packages/apps/Settings/res/values/strings.xml
old mode 100644
new mode 100755
index b2cf46f..7f6af10
--- a/idh.code/packages/apps/Settings/res/values/strings.xml
+++ b/idh.code/packages/apps/Settings/res/values/strings.xml
@@ -5206,4 +5206,7 @@
     <!-- SPRD: Bug #313604 UMS Settings modify sprd USB storage@{ -->
     <string name="move_app_to_internal_sdcard" product="default" msgid="1143379049903056407">"Move to internal SD card"</string>
     <!-- @} -->
+    <!-- SPRD: battery percentage yang liu@{ -->
+    <string name="battery_percent">Battery Percentage</string>
+     <!-- @} -->
 </resources>
diff --git a/idh.code/packages/apps/Settings/res/xml/power_usage_summary.xml b/idh.code/packages/apps/Settings/res/xml/power_usage_summ
old mode 100644
new mode 100755
diff --git a/idh.code/packages/apps/Settings/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/idh.code/packages/apps/Setting
old mode 100644
new mode 100755
index fc65a8c..c362b3a
--- a/idh.code/packages/apps/Settings/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/idh.code/packages/apps/Settings/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -43,12 +43,20 @@ import com.android.settings.R;
 
 import java.util.List;
 import com.android.internal.os.PowerProfile;
+
+import android.preference.CheckBoxPreference;
+/*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> start*/
+import android.provider.Settings;
+import android.util.Log;
+/*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> end*/
 /**
  * Displays a list of apps and subsystems that consume power, ordered by how much power was
  * consumed since the last time it was unplugged.
  */
 public class PowerUsageSummary extends PreferenceFragment {
-
+/*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> start*/
+    private static final String ACTION_BATTERY_PERCENTAGE_SWITCH = "silence.intent.action.BATTERY_PERCENTAGE_SWITCH";
+/*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> end*/
     private static final boolean DEBUG = false;
 
     private static final String TAG = "PowerUsageSummary";
@@ -133,7 +141,21 @@ public class PowerUsageSummary extends PreferenceFragment {
 
     @Override
     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
-        if (preference instanceof BatteryHistoryPreference) {
+/*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> start*/
+       if (preference instanceof CheckBoxPreference) {
+            Log.d(TAG, "click battery percentage checkbox");
+            CheckBoxPreference prf = (CheckBoxPreference) preference;
+            int state = prf.isChecked() ? 1 : 0;
+            Log.d(TAG, "state: " + state);
+            Settings.Secure.putInt(getActivity().getContentResolver(), Settings.Secure.BATTERY_PERCENTAGE, state);
+            Intent intent = new Intent(ACTION_BATTERY_PERCENTAGE_SWITCH);
+            intent.putExtra("state", state);
+            Log.d(TAG, "sendBroadcast battery percentage switch");
+            getActivity().sendBroadcast(intent);
+            return super.onPreferenceTreeClick(preferenceScreen, preference);
+        }
+/*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> end*/
+       if (preference instanceof BatteryHistoryPreference) {
             Parcel hist = Parcel.obtain();
             mStatsHelper.getStats().writeToParcelWithoutUids(hist, 0);
             byte[] histData = hist.marshall();
@@ -202,7 +224,19 @@ public class PowerUsageSummary extends PreferenceFragment {
     private void refreshStats() {
         mAppListGroup.removeAll();
         mAppListGroup.setOrderingAsAdded(false);
-
+               
+        /*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> start*/
+        CheckBoxPreference batterrPercentPrf = new CheckBoxPreference(getActivity());
+        batterrPercentPrf.setTitle(getString(R.string.battery_percent));
+        batterrPercentPrf.setOrder(-3);
+       
+        final boolean enable = Settings.Secure.getInt(getActivity().getContentResolver(),
+                Settings.Secure.BATTERY_PERCENTAGE, 0) != 0;
+        
+        batterrPercentPrf.setChecked(enable);        
+        mAppListGroup.addPreference(batterrPercentPrf);
+       /*Yang Liu for <B5><E7><C1><BF><B0>???<A6><C4><DC> end*/
+       
         mBatteryStatusPref.setOrder(-2);
         mAppListGroup.addPreference(mBatteryStatusPref);
         BatteryHistoryPreference hist = new BatteryHistoryPreference(


增加电量百分比功能

标签:电量百分比   sc7715   android4.4.2   

原文地址:http://blog.csdn.net/silence_cdsn/article/details/42487831

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!