andrid5.0添加开关默认控制电量百分比显示


     "Yes"
+
+ Percentage of Charge
 
     
     "No"
diff --git a/packages/apps/Settings/res/xml/power_usage_summary.xml b/packages/apps/Settings/res/xml/power_usage_summary.xml
old mode 100644
new mode 100755
index 0622513..a4b1e17
--- a/packages/apps/Settings/res/xml/power_usage_summary.xml
+++ b/packages/apps/Settings/res/xml/power_usage_summary.xml
@@ -19,4 +19,9 @@
         android:title="@string/power_usage_summary_title"
         settings:keywords="@string/keywords_battery"
         android:key="app_list">
+ +        android:key="battery_percentage_on"
+ android:title="@string/battery_percentage"
+ android:persistent="true"/>
+
 
diff --git a/packages/apps/Settings/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/packages/apps/Settings/src/com/android/settings/fuelgauge/PowerUsageSummary.java
old mode 100644
new mode 100755
index 5ee4fa0..adf96cd
--- a/packages/apps/Settings/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/packages/apps/Settings/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -37,16 +37,17 @@ import android.text.TextUtils;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
-
 import com.android.internal.os.BatterySipper;
 import com.android.internal.os.BatteryStatsHelper;
 import com.android.internal.os.PowerProfile;
 import com.android.settings.HelpUtils;
 import com.android.settings.R;
 import com.android.settings.SettingsActivity;
-
+import android.preference.CheckBoxPreference;
+import android.util.Log;
 import java.util.List;
-
+import com.android.settings.R;
+import android.provider.Settings;
 /**
  * Displays a list of apps and subsystems that consume power, ordered by how much power was
  * consumed since the last time it was unplugged.
@@ -65,14 +66,14 @@ public class PowerUsageSummary extends PreferenceFragment {
     private static final int MENU_STATS_REFRESH = Menu.FIRST + 1;
     private static final int MENU_BATTERY_SAVER = Menu.FIRST + 2;
     private static final int MENU_HELP = Menu.FIRST + 3;
-
+    private static final String KEY_BATTERY_Percentage = "battery_percentage_on";
     private UserManager mUm;
-
+   
     private BatteryHistoryPreference mHistPref;
     private PreferenceGroup mAppListGroup;
     private String mBatteryLevel;
     private String mBatteryStatus;
-
+    private CheckBoxPreference mBatteryPercentagePref;
     private int mStatsType = BatteryStats.STATS_SINCE_CHARGED;
 
     private static final int MIN_POWER_THRESHOLD_MILLI_AMP = 5;
@@ -110,6 +111,16 @@ public class PowerUsageSummary extends PreferenceFragment {
 
         addPreferencesFromResource(R.xml.power_usage_summary);
         mAppListGroup = (PreferenceGroup) findPreference(KEY_APP_LIST);
+ mBatteryPercentagePref = (CheckBoxPreference) 
+                mAppListGroup.findPreference(KEY_BATTERY_Percentage); 
+       // mBatteryPercentagePref.setChecked(Settings.System.getInt(getActivity().getContentResolver(),
+              //  "battery_percentage_enabled", 0) == 1);
+      int battery=Settings.Global.getInt(getActivity().getContentResolver(),"battery_percentage", 1);
+  if(battery==1){
+           mBatteryPercentagePref.setChecked(true);
+       }else{
+           mBatteryPercentagePref.setChecked(false);
+       }
         setHasOptionsMenu(true);
     }
 
@@ -157,6 +168,15 @@ public class PowerUsageSummary extends PreferenceFragment {
 
     @Override
     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+   /*if(mBatteryPercentagePref == preference){
+ Settings.System.putInt(getActivity().getContentResolver(),
+ "battery_percentage_enabled",mBatteryPercentagePref.isChecked() ? 1 : 0);
+ Intent levelShowChanged = new Intent("com.sprd.battery.percentage");
+ getActivity().sendBroadcast(levelShowChanged);
+ return true;
+        }*/
+  
+
         if (preference instanceof BatteryHistoryPreference) {
             mStatsHelper.storeStatsHistoryInFile(BATTERY_HISTORY_FILE);
             Bundle args = new Bundle();
@@ -168,6 +188,24 @@ public class PowerUsageSummary extends PreferenceFragment {
                     R.string.history_details_title, null, null, 0);
             return super.onPreferenceTreeClick(preferenceScreen, preference);
         }
+ if (mBatteryPercentagePref == preference) {
+                     
+            if(mBatteryPercentagePref.isChecked()){
+                               Intent intent = new Intent("xiaoyao_battery_show");      
+                               intent.putExtra("flag", true);
+                               getActivity().sendBroadcast(intent);
+                              
+                       Settings.Global.putInt(getActivity().getContentResolver(),"battery_percentage",1);
+                       }else{
+                               Intent intent = new Intent("xiaoyao_battery_gone");      
+                               intent.putExtra("flag", false);
+                               getActivity().sendBroadcast(intent);
+                              
+                      Settings.Global.putInt(getActivity().getContentResolver(),"battery_percentage",0);
+                       }
+                   
+            return true;
+       }
         if (!(preference instanceof PowerGaugePreference)) {
             return false;
         }
@@ -251,6 +289,10 @@ public class PowerUsageSummary extends PreferenceFragment {
     private void refreshStats() {
         mAppListGroup.removeAll();
         mAppListGroup.setOrderingAsAdded(false);
+ mBatteryPercentagePref.setOrder(-3);
+        mAppListGroup.addPreference(mBatteryPercentagePref);
+        
+
         mHistPref = new BatteryHistoryPreference(getActivity(), mStatsHelper.getStats(),
                 mStatsHelper.getBatteryBroadcast());
         mHistPref.setOrder(-1);

你可能感兴趣的:(andrid5.0添加开关默认控制电量百分比显示)