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: Jayant-Deshmukh <jayantdeshmuk008@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 c22803f129
commit 9051fbfa02
3 changed files with 26 additions and 24 deletions

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;
@@ -116,26 +133,11 @@ public class Traffic extends SettingsPreferenceFragment implements OnPreferenceC
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:
break;