Cherish:Network traffic location [2/2]

spezi77 edits:
-Adapted to our codebase
-Indicator arrows: Reverse logic of the toggle. Following a373316b1d

Change-Id: I6e7ebce7738c1dcc1b8b359b58f5d90aa8c07ecd
Signed-off-by: spezi77 <spezi7713@gmx.net>
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
Anushek Prasal
2018-12-27 02:54:40 +05:30
committed by Hưng Phan
parent 9886cd4864
commit c22803f129
4 changed files with 77 additions and 26 deletions

View File

@@ -238,4 +238,16 @@
<item>2</item>
<item>3</item>
</string-array>
<!-- Network traffic location -->
<string-array name="network_traffic_location_entries">
<item>@string/traffic_disabled</item>
<item>@string/traffic_statusbar</item>
<item>@string/traffic_expanded_statusbar</item>
</string-array>
<string-array name="network_traffic_location_values" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
</resources>

View File

@@ -349,8 +349,11 @@
<!-- 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_location">Show net activity</string>
<string name="traffic_disabled">Disabled</string>
<string name="traffic_statusbar">Statusbar</string>
<string name="traffic_expanded_statusbar">Expanded Statusbar</string>
<string name="network_traffic_autohide_threshold_title">Net activity autohide threshold (KB/s)</string>
<string name="network_traffic_hidearrow">Hide arrows</string>
<string name="network_traffic_hidearrow_summary">Hide the network traffic indicator arrows</string>
<string name="network_traffic_arrow">Show arrows</string>
<string name="network_traffic_arrow_summary">Show the network traffic indicator arrows</string>
</resources>

View File

@@ -16,10 +16,13 @@
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" />
<ListPreference
android:key="network_traffic_location"
android:title="@string/network_traffic_location"
android:summary="%s"
android:entries="@array/network_traffic_location_entries"
android:entryValues="@array/network_traffic_location_values"
android:persistent="false" />
<com.cherish.settings.preferences.CustomSeekBarPreference
android:key="network_traffic_autohide_threshold"
@@ -29,10 +32,9 @@
settings:units="" />
<com.cherish.settings.preferences.SystemSettingSwitchPreference
android:key="network_traffic_hidearrow"
android:title="@string/network_traffic_hidearrow"
android:summary="@string/network_traffic_hidearrow_summary"
android:dependency="network_traffic_state"
android:defaultValue="false" />
android:key="network_traffic_arrow"
android:title="@string/network_traffic_arrow"
android:summary="@string/network_traffic_arrow_summary"
android:defaultValue="true" />
</PreferenceScreen>

View File

@@ -51,9 +51,9 @@ import com.cherish.settings.preferences.SystemSettingSwitchPreference;
public class Traffic extends SettingsPreferenceFragment implements OnPreferenceChangeListener {
private ListPreference mNetTrafficLocation;
private CustomSeekBarPreference mThreshold;
private SystemSettingSwitchPreference mNetMonitor;
private SystemSettingSwitchPreference mShowArrows;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -64,18 +64,21 @@ 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, 1, UserHandle.USER_CURRENT) == 1;
mNetMonitor = (SystemSettingSwitchPreference) findPreference("network_traffic_state");
mNetMonitor.setChecked(isNetMonitorEnabled);
mNetMonitor.setOnPreferenceChangeListener(this);
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());
mNetTrafficLocation.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);
mShowArrows = (SystemSettingSwitchPreference) findPreference("network_traffic_arrow");
updateTrafficLocation(location);
}
@Override
@@ -90,13 +93,13 @@ public class Traffic extends SettingsPreferenceFragment implements OnPreferenceC
@Override
public boolean onPreferenceChange(Preference preference, Object objValue) {
if (preference == mNetMonitor) {
boolean value = (Boolean) objValue;
if (preference == mNetTrafficLocation) {
int location = Integer.valueOf((String) objValue);
int index = mNetTrafficLocation.findIndexOfValue((String) objValue);
Settings.System.putIntForUser(getActivity().getContentResolver(),
Settings.System.NETWORK_TRAFFIC_STATE, value ? 1 : 0,
UserHandle.USER_CURRENT);
mNetMonitor.setChecked(value);
mThreshold.setEnabled(value);
Settings.System.NETWORK_TRAFFIC_LOCATION, location, UserHandle.USER_CURRENT);
mNetTrafficLocation.setSummary(mNetTrafficLocation.getEntries()[index]);
updateTrafficLocation(location);
return true;
} else if (preference == mThreshold) {
int val = (Integer) objValue;
@@ -107,4 +110,35 @@ public class Traffic extends SettingsPreferenceFragment implements OnPreferenceC
}
return false;
}
public void updateTrafficLocation(int 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:
break;
}
}
}