Cherish:Status network traffic [2/2]
Change-Id: I914065e7f44e2b7a0299c2f219ec519e07b16b68 Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
@@ -345,4 +345,10 @@
|
||||
<string name="status_bar_battery_text_position_right">Right of the icon</string>
|
||||
<string name="status_bar_battery_text_charging_title">Battery percentage when charging</string>
|
||||
<string name="status_bar_battery_text_charging_summary">Always display battery percentage when charging</string>
|
||||
|
||||
<!-- Statusbar net monitor -->
|
||||
<string name="traffic_title">Traffic indicators</string>
|
||||
<string name="network_traffic_state_title">Network traffic</string>
|
||||
<string name="network_traffic_state_summary">Show net activity in statusbar</string>
|
||||
<string name="network_traffic_autohide_threshold_title">Net activity autohide threshold (KB/s)</string>
|
||||
</resources>
|
||||
|
||||
@@ -19,6 +19,12 @@
|
||||
android:key="status_bar_icons"
|
||||
android:title="@string/status_bar_system_icons_title">
|
||||
|
||||
<Preference
|
||||
android:key="traffic"
|
||||
android:icon="@drawable/ic_network_traffic"
|
||||
android:fragment="com.cherish.settings.fragments.Traffic"
|
||||
android:title="@string/traffic_title" />
|
||||
|
||||
<Preference
|
||||
android:title="@string/statusbar_items_title"
|
||||
android:icon="@drawable/ic_shortcuts">
|
||||
|
||||
31
res/xml/traffic.xml
Normal file
31
res/xml/traffic.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Copyright (C) 2014-2016 AospExtended ROM 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.
|
||||
-->
|
||||
|
||||
<PreferenceScreen
|
||||
android:title="@string/network_traffic_state_title"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="network_traffic_state"
|
||||
android:title="@string/network_traffic_state_title"
|
||||
android:defaultValue="false" />
|
||||
|
||||
<com.cherish.settings.preferences.CustomSeekBarPreference
|
||||
android:key="network_traffic_autohide_threshold"
|
||||
android:title="@string/network_traffic_autohide_threshold_title"
|
||||
android:max="10"
|
||||
settings:min="0"
|
||||
settings:units="" />
|
||||
|
||||
</PreferenceScreen>
|
||||
110
src/com/cherish/settings/fragments/Traffic.java
Normal file
110
src/com/cherish/settings/fragments/Traffic.java
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (C) 2017 AospExtended ROM 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.cherish.settings.fragments;
|
||||
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.content.Context;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.WindowManagerGlobal;
|
||||
import android.view.IWindowManager;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import java.util.Locale;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.Utils;
|
||||
|
||||
import com.cherish.settings.preferences.CustomSeekBarPreference;
|
||||
import com.cherish.settings.preferences.SystemSettingSwitchPreference;
|
||||
|
||||
public class Traffic extends SettingsPreferenceFragment implements OnPreferenceChangeListener {
|
||||
|
||||
|
||||
private CustomSeekBarPreference mThreshold;
|
||||
private SystemSettingSwitchPreference mNetMonitor;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
addPreferencesFromResource(R.xml.traffic);
|
||||
|
||||
final ContentResolver resolver = getActivity().getContentResolver();
|
||||
final PreferenceScreen prefSet = getPreferenceScreen();
|
||||
|
||||
boolean isNetMonitorEnabled = Settings.System.getIntForUser(resolver,
|
||||
Settings.System.NETWORK_TRAFFIC_STATE, 1, UserHandle.USER_CURRENT) == 1;
|
||||
mNetMonitor = (SystemSettingSwitchPreference) findPreference("network_traffic_state");
|
||||
mNetMonitor.setChecked(isNetMonitorEnabled);
|
||||
mNetMonitor.setOnPreferenceChangeListener(this);
|
||||
|
||||
int trafvalue = Settings.System.getIntForUser(resolver,
|
||||
Settings.System.NETWORK_TRAFFIC_AUTOHIDE_THRESHOLD, 1, UserHandle.USER_CURRENT);
|
||||
mThreshold = (CustomSeekBarPreference) findPreference("network_traffic_autohide_threshold");
|
||||
mThreshold.setValue(trafvalue);
|
||||
mThreshold.setOnPreferenceChangeListener(this);
|
||||
mThreshold.setEnabled(isNetMonitorEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object objValue) {
|
||||
if (preference == mNetMonitor) {
|
||||
boolean value = (Boolean) objValue;
|
||||
Settings.System.putIntForUser(getActivity().getContentResolver(),
|
||||
Settings.System.NETWORK_TRAFFIC_STATE, value ? 1 : 0,
|
||||
UserHandle.USER_CURRENT);
|
||||
mNetMonitor.setChecked(value);
|
||||
mThreshold.setEnabled(value);
|
||||
return true;
|
||||
} else if (preference == mThreshold) {
|
||||
int val = (Integer) objValue;
|
||||
Settings.System.putIntForUser(getContentResolver(),
|
||||
Settings.System.NETWORK_TRAFFIC_AUTOHIDE_THRESHOLD, val,
|
||||
UserHandle.USER_CURRENT);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user