android7.1修改待机时间(添加存储容量显示和已开机时间选项)

vendor/mediatek/proprietary/packages/apps/MtkSettings/res/values-zh-rCN/strings.xml <string name="storage_info">存储容量</string> <string name="storage_total">总共容量: </string> <string name="storage_free">剩余空间: </string> ,今天小编就来聊一聊关于android7.1修改待机时间?接下来我们就一起去研究一下吧!

android7.1修改待机时间(添加存储容量显示和已开机时间选项)

android7.1修改待机时间

vendor/mediatek/proprietary/packages/apps/MtkSettings/res/values-zh-rCN/strings.xml

<string name="storage_info">存储容量</string> <string name="storage_total">总共容量: </string> <string name="storage_free">剩余空间: </string>

vendor/mediatek/proprietary/packages/apps/MtkSettings/res/xml/my_device_info.xml

<!-- add storage --> <Preference android:key="storage_info" android:order="53" android:title="@string/storage_info" android:summary="@string/summary_placeholder"/> <!-- add uptime --> <Preference android:enabled="false" android:key="up_time" android:order="54" android:persistent="false" android:shouldDisableView="false" android:summary="@string/summary_placeholder" android:title="@string/status_up_time" />

vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java

import com.android.settings.deviceinfo.imei.ImeiInfoPreferenceController; import com.android.settings.deviceinfo.simstatus.SimStatusPreferenceController; import com.android.settings.deviceinfo.StorageInfoPreferenceController;// add storage import com.android.settings.deviceinfo.UpdateTimePreferenceController;// add uptime import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.widget.EntityHeaderController; import com.android.settingslib.core.AbstractPreferenceController; @@ -68,6 70,7 @@ public class MyDeviceInfoFragment extends DashboardFragment private static final String KEY_MY_DEVICE_INFO_HEADER = "my_device_info_header"; private static final String KEY_LEGAL_CONTAINER = "legal_container"; private static UpdateTimePreferenceController mUpdateTimePreferenceController;//add uptime @Override public int getMetricsCategory() { @@ -82,9 85,18 @@ public class MyDeviceInfoFragment extends DashboardFragment @Override public void onResume() { super.onResume(); mUpdateTimePreferenceController.onResume();/ add uptime initHeader(); } // add uptime @Override public void onPause() { super.onPause(); mUpdateTimePreferenceController.onPause(); } // end uptime @Override protected String getLogTag() { return LOG_TAG; @@ -109,6 121,9 @@ public class MyDeviceInfoFragment extends DashboardFragment final List<AbstractPreferenceController> controllers = new ArrayList<>(); controllers.add(new EmergencyInfoPreferenceController(context)); /// M: Revise for updating phone number. mUpdateTimePreferenceController = new UpdateTimePreferenceController(context);// add uptime controllers.add(mUpdateTimePreferenceController);// add uptime controllers.add(new StorageInfoPreferenceController(context));//add storage controllers.add(new PhoneNumberPreferenceController(context, lifecycle)); controllers.add(new BrandedAccountPreferenceController(context));

添加vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/deviceinfo/StorageInfoPreferenceController.java

/* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this File except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.deviceinfo; import java.text.NumberFormat; import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settings.R; import android.content.Context; import android.content.res.Resources; import android.os.storage.StorageManager; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceScreen; import android.text.format.Formatter; import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider; import com.android.settingslib.deviceinfo.PrivateStorageInfo; public class StorageInfoPreferenceController extends AbstractPreferenceController implements PreferenceControllerMixin { private static final String KEY_STORAGE_INFO = "storage_info"; private StorageManagerVolumeProvider mStorageManagerVolumeProvider; private Context mContext; public StorageInfoPreferenceController(Context context) { super(context); mContext = context; } @Override public boolean isAvailable() { return true; } @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); final Preference pref = screen.findPreference(KEY_STORAGE_INFO); if (pref != null) { pref.setSummary(getStorageInfo()); } } @Override public String getPreferenceKey() { return KEY_STORAGE_INFO; } @Override public boolean handlePreferenceTreeClick(Preference preference) { return false; } private String getStorageInfo() { StorageManager storageManager = mContext.getSystemService(StorageManager.class); mStorageManagerVolumeProvider = new StorageManagerVolumeProvider(storageManager); NumberFormat percentageFormat = NumberFormat.getPercentInstance(); PrivateStorageInfo info = PrivateStorageInfo.getPrivateStorageInfo(mStorageManagerVolumeProvider); double privateUsedBytes = info.totalBytes - info.freeBytes; StringBuilder builder = new StringBuilder(); Resources res = mContext.getResources(); builder.append(res.getString(R.string.storage_total)) .append(Formatter.formatFileSize(mContext, info.totalBytes)).append(" ") .append(res.getString(R.string.storage_free)) .append(Formatter.formatFileSize(mContext, info.freeBytes)); return builder.toString(); } }

添加vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/deviceinfo/UpdateTimePreferenceController.java

/* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.deviceinfo; import java.lang.ref.WeakReference; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import com.android.internal.R; import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.core.AbstractPreferenceController; import android.app.ActivityManager; import android.app.Fragment; import android.content.Context; import android.os.Build; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.SystemClock; import android.os.storage.StorageManager; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceScreen; import android.text.format.DateFormat; public class UpdateTimePreferenceController extends AbstractPreferenceController implements PreferenceControllerMixin { private static final String KEY_UPDATE_TIME = "up_time"; private static final int EVENT_UPDATE_STATS = 500; private Context mContext; private Preference mPref; private MyHandler mMyHandler; public UpdateTimePreferenceController(Context context) { super(context); mContext = context; mMyHandler = new MyHandler(this); } @Override public boolean isAvailable() { return true; } @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); mPref = screen.findPreference(KEY_UPDATE_TIME); } @Override public String getPreferenceKey() { return KEY_UPDATE_TIME; } @Override public boolean handlePreferenceTreeClick(Preference preference) { return false; } public void onResume() { mMyHandler.sendEmptyMessage(EVENT_UPDATE_STATS); } public void onPause() { mMyHandler.removeMessages(EVENT_UPDATE_STATS); } private void updateTime() { long at = SystemClock.uptimeMillis() / 1000; long ut = SystemClock.elapsedRealtime() / 1000; if (ut == 0) { ut = 1; } if (mPref != null) { mPref.setSummary(convert(ut)); } } private String pad(int n) { if (n >= 10) { return String.valueOf(n); } else { return "0" String.valueOf(n); } } private String convert(long t) { int s = (int) (t % 60); int m = (int) ((t / 60) % 60); int h = (int) ((t / 3600)); return h ":" pad(m) ":" pad(s); } private static class MyHandler extends Handler { UpdateTimePreferenceController controller; public MyHandler(UpdateTimePreferenceController controller) { super(Looper.getMainLooper()); this.controller = controller; } @Override public void handleMessage(Message msg) { switch (msg.what) { case EVENT_UPDATE_STATS: controller.updateTime(); sendEmptyMessageDelayed(EVENT_UPDATE_STATS, 1000); break; } } } }

,

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页