Cherish: Improve Network traffic

Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
SKULSHADY
2021-04-27 00:05:36 +07:00
committed by Hưng Phan
parent 22a871caa2
commit f083d98042
4 changed files with 64 additions and 35 deletions

View File

@@ -410,6 +410,7 @@
<!-- Network traffic location -->
<string-array name="network_traffic_location_entries" translatable="false">
<item>@string/network_traffic_disabled</item>
<item>@string/network_traffic_statusbar</item>
<item>@string/network_traffic_qs_header</item>
</string-array>
@@ -417,6 +418,7 @@
<string-array name="network_traffic_location_values" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
<string-array name="network_traffic_mode_entries" translatable="false">

View File

@@ -502,9 +502,9 @@
<!-- Network Traffic -->
<string name="traffic_title">Traffic indicators</string>
<string name="traffic_summary">Customize the traffic indicators</string>
<string name="network_traffic_state_title">Show network traffic</string>
<string name="network_traffic_autohide_threshold_title">Auto-hide threshold</string>
<string name="network_traffic_location_title">Location</string>
<string name="network_traffic_disabled">Disabled</string>
<string name="network_traffic_statusbar">Status bar</string>
<string name="network_traffic_qs_header">QS header</string>
<string name="network_traffic_refresh_interval_title">Refresh interval</string>

View File

@@ -19,26 +19,14 @@
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
android:title="@string/traffic_title">
<com.cherish.settings.preferences.SystemSettingSwitchPreference
android:key="network_traffic_state"
android:title="@string/network_traffic_state_title"
android:defaultValue="false" />
<com.cherish.settings.preferences.SystemSettingListPreference
<ListPreference
android:key="network_traffic_location"
android:title="@string/network_traffic_location_title"
android:summary="%s"
android:entries="@array/network_traffic_location_entries"
android:entryValues="@array/network_traffic_location_values"
android:defaultValue="0"
android:dependency="network_traffic_state" />
<com.cherish.settings.preferences.SystemSettingListPreference
android:key="network_traffic_mode"
android:title="@string/network_traffic_mode_title"
android:entries="@array/network_traffic_mode_entries"
android:entryValues="@array/network_traffic_mode_values"
android:defaultValue="0"
android:dependency="network_traffic_state" />
android:persistent="false" />
<com.cherish.settings.preferences.CustomSeekBarPreference
android:key="network_traffic_autohide_threshold"
@@ -48,13 +36,19 @@
settings:units="KB/s"
android:defaultValue="0" />
<com.cherish.settings.preferences.SystemSettingListPreference
android:key="network_traffic_mode"
android:title="@string/network_traffic_mode_title"
android:entries="@array/network_traffic_mode_entries"
android:entryValues="@array/network_traffic_mode_values"
android:defaultValue="0" />
<com.cherish.settings.preferences.SystemSettingSeekBarPreference
android:key="network_traffic_refresh_interval"
android:title="@string/network_traffic_refresh_interval_title"
android:max="10"
settings:min="1"
settings:units="sec"
android:defaultValue="1"
android:dependency="network_traffic_state" />
android:defaultValue="1" />
</PreferenceScreen>
</PreferenceScreen>

View File

@@ -56,10 +56,10 @@ import com.cherish.settings.preferences.SystemSettingSwitchPreference;
public class Traffic extends SettingsPreferenceFragment implements OnPreferenceChangeListener {
private static final String NETWORK_TRAFFIC_AUTOHIDE_THRESHOLD = "network_traffic_autohide_threshold";
private static final String NETWORK_TRAFFIC_STATE = "network_traffic_state";
private static final String NETWORK_TRAFFIC_LOCATION = "network_traffic_location";
private SystemSettingSwitchPreference mNetMonitor;
private CustomSeekBarPreference mThreshold;
private ListPreference mNetTrafficLocation;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -70,18 +70,28 @@ public class Traffic extends SettingsPreferenceFragment implements OnPreferenceC
final ContentResolver resolver = getActivity().getContentResolver();
final PreferenceScreen prefSet = getPreferenceScreen();
boolean isNetMonitorEnabled = Settings.System.getIntForUser(resolver,
Settings.System.NETWORK_TRAFFIC_STATE, 0, UserHandle.USER_CURRENT) == 1;
mNetMonitor = (SystemSettingSwitchPreference) findPreference(NETWORK_TRAFFIC_STATE);
mNetMonitor.setChecked(isNetMonitorEnabled);
mNetMonitor.setOnPreferenceChangeListener(this);
// Network traffic location
mNetTrafficLocation = (ListPreference) findPreference(NETWORK_TRAFFIC_LOCATION);
int location = Settings.System.getIntForUser(resolver,
Settings.System.NETWORK_TRAFFIC_LOCATION, 0, UserHandle.USER_CURRENT);
mNetTrafficLocation.setOnPreferenceChangeListener(this);
int value = Settings.System.getIntForUser(resolver,
Settings.System.NETWORK_TRAFFIC_AUTOHIDE_THRESHOLD, 1, UserHandle.USER_CURRENT);
mThreshold = (CustomSeekBarPreference) findPreference(NETWORK_TRAFFIC_AUTOHIDE_THRESHOLD);
mThreshold.setValue(value);
mThreshold.setOnPreferenceChangeListener(this);
mThreshold.setEnabled(isNetMonitorEnabled);
int netMonitorEnabled = Settings.System.getIntForUser(resolver,
Settings.System.NETWORK_TRAFFIC_STATE, 0, UserHandle.USER_CURRENT);
if (netMonitorEnabled == 1) {
mNetTrafficLocation.setValue(String.valueOf(location+1));
updateTrafficLocation(location+1);
} else {
mNetTrafficLocation.setValue("0");
updateTrafficLocation(0);
}
mNetTrafficLocation.setSummary(mNetTrafficLocation.getEntry());
}
@Override
@@ -97,17 +107,26 @@ public class Traffic extends SettingsPreferenceFragment implements OnPreferenceC
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final ContentResolver resolver = getActivity().getContentResolver();
if (preference == mNetMonitor) {
boolean value = (Boolean) newValue;
Settings.System.putIntForUser(resolver,
Settings.System.NETWORK_TRAFFIC_STATE, value ? 1 : 0,
UserHandle.USER_CURRENT);
mNetMonitor.setChecked(value);
mThreshold.setEnabled(value);
if (preference == mNetTrafficLocation) {
int location = Integer.valueOf((String) newValue);
int index = mNetTrafficLocation.findIndexOfValue((String) newValue);
mNetTrafficLocation.setSummary(mNetTrafficLocation.getEntries()[index]);
if (location > 0) {
// Convert the selected location mode from our list {0,1,2} and store it to "view location" setting: 0=sb; 1=expanded sb
Settings.System.putIntForUser(resolver,
Settings.System.NETWORK_TRAFFIC_LOCATION, location-1, UserHandle.USER_CURRENT);
// And also enable the net monitor
Settings.System.putIntForUser(resolver,
Settings.System.NETWORK_TRAFFIC_STATE, 1, UserHandle.USER_CURRENT);
} else { // Disable net monitor completely
Settings.System.putIntForUser(resolver,
Settings.System.NETWORK_TRAFFIC_STATE, 0, UserHandle.USER_CURRENT);
}
updateTrafficLocation(location);
return true;
} else if (preference == mThreshold) {
int val = (Integer) newValue;
Settings.System.putIntForUser(getContentResolver(),
Settings.System.putIntForUser(resolver,
Settings.System.NETWORK_TRAFFIC_AUTOHIDE_THRESHOLD, val,
UserHandle.USER_CURRENT);
return true;
@@ -115,6 +134,20 @@ public class Traffic extends SettingsPreferenceFragment implements OnPreferenceC
return false;
}
public void updateTrafficLocation(int location) {
switch(location){
case 0:
mThreshold.setEnabled(false);
break;
case 1:
case 2:
mThreshold.setEnabled(true);
break;
default:
break;
}
}
/**
* For Search.
*/