NetworkTraffic positioning: Adapt to new settings flags.

Partially based on:
1146bf83de

spezi77 edits:
-Clean up the code
-Refactorized to work with our new commit: c11cb77923

Change-Id: I5fc55ed94a1c9fabacde19e128baaa172a4b4a4c
Signed-off-by: spezi77 <spezi7713@gmx.net>
Signed-off-by: Arghya Chanda <arghyac35@gmail.com>
Signed-off-by: SagarMakhar <sagarmakhar@gmail.com>
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
spezi77
2019-11-29 14:26:47 +01:00
committed by Hưng Phan
parent 225e2cdeef
commit c8fff8b562
3 changed files with 31 additions and 28 deletions

View File

@@ -269,11 +269,12 @@
<!-- Statusbar net monitor -->
<string name="traffic_title">Traffic Indicators</string>
<string name="network_traffic_state_title">Network traffic</string>
<string name="network_traffic_location">Show net activity</string>
<string name="network_traffic">Network traffic</string>
<string name="network_traffic_state_title">Network traffic display</string>
<string name="network_traffic_location">Traffic indicator placement</string>
<string name="traffic_disabled">Disabled</string>
<string name="traffic_statusbar">Statusbar</string>
<string name="traffic_expanded_statusbar">Expanded Statusbar</string>
<string name="traffic_expanded_statusbar">Expanded header</string>
<string name="network_traffic_autohide_threshold_title">Net activity autohide threshold (KB/s)</string>
<string name="network_traffic_arrow">Show arrows</string>
<string name="network_traffic_arrow_summary">Show the network traffic indicator arrows</string>

View File

@@ -12,7 +12,7 @@
-->
<PreferenceScreen
android:title="@string/network_traffic_state_title"
android:title="@string/network_traffic"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">

View File

@@ -66,9 +66,7 @@ public class Traffic extends SettingsPreferenceFragment implements OnPreferenceC
mNetTrafficLocation = (ListPreference) findPreference("network_traffic_location");
int location = Settings.System.getIntForUser(resolver,
Settings.System.NETWORK_TRAFFIC_LOCATION, 0, UserHandle.USER_CURRENT);
mNetTrafficLocation.setValue(String.valueOf(location));
mNetTrafficLocation.setSummary(mNetTrafficLocation.getEntry());
Settings.System.NETWORK_TRAFFIC_VIEW_LOCATION, 0, UserHandle.USER_CURRENT);
mNetTrafficLocation.setOnPreferenceChangeListener(this);
int trafvalue = Settings.System.getIntForUser(resolver,
@@ -78,7 +76,16 @@ public class Traffic extends SettingsPreferenceFragment implements OnPreferenceC
mThreshold.setOnPreferenceChangeListener(this);
mShowArrows = (SystemSettingSwitchPreference) findPreference("network_traffic_arrow");
updateTrafficLocation(location);
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
@@ -96,10 +103,20 @@ public class Traffic extends SettingsPreferenceFragment implements OnPreferenceC
if (preference == mNetTrafficLocation) {
int location = Integer.valueOf((String) objValue);
int index = mNetTrafficLocation.findIndexOfValue((String) objValue);
Settings.System.putIntForUser(getActivity().getContentResolver(),
Settings.System.NETWORK_TRAFFIC_LOCATION, location, UserHandle.USER_CURRENT);
mNetTrafficLocation.setSummary(mNetTrafficLocation.getEntries()[index]);
updateTrafficLocation(location);
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(getActivity().getContentResolver(),
Settings.System.NETWORK_TRAFFIC_VIEW_LOCATION, location-1, UserHandle.USER_CURRENT);
// And also enable the net monitor
Settings.System.putIntForUser(getActivity().getContentResolver(),
Settings.System.NETWORK_TRAFFIC_STATE, 1, UserHandle.USER_CURRENT);
updateTrafficLocation(location+1);
} else { // Disable net monitor completely
Settings.System.putIntForUser(getActivity().getContentResolver(),
Settings.System.NETWORK_TRAFFIC_STATE, 0, UserHandle.USER_CURRENT);
updateTrafficLocation(location);
}
return true;
} else if (preference == mThreshold) {
int val = (Integer) objValue;
@@ -112,32 +129,17 @@ public class Traffic extends SettingsPreferenceFragment implements OnPreferenceC
}
public void updateTrafficLocation(int location) {
switch(location){
switch(location){
case 0:
mThreshold.setEnabled(false);
mShowArrows.setEnabled(false);
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.NETWORK_TRAFFIC_STATE, 0);
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.NETWORK_TRAFFIC_EXPANDED_STATUS_BAR_STATE, 0);
break;
case 1:
mThreshold.setEnabled(true);
mShowArrows.setEnabled(true);
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.NETWORK_TRAFFIC_STATE, 1);
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.NETWORK_TRAFFIC_EXPANDED_STATUS_BAR_STATE, 0);
break;
case 2:
mThreshold.setEnabled(true);
mShowArrows.setEnabled(true);
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.NETWORK_TRAFFIC_STATE, 0);
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.NETWORK_TRAFFIC_EXPANDED_STATUS_BAR_STATE, 1);
break;
default:
default:
break;
}
}