NetworkTraffic: Show single traffic for statusbar & allow custom font size [2/2].

Based on commits by idoybh, SKULSHADY and SDB:
* https://github.com/pixeldust-project-caf/android_packages_apps_PixelDustSettings/commit/8f52988
* https://github.com/pixeldust-project-caf/android_packages_apps_PixelDustSettings/commit/0a5424b

Co-authored-by: Ido Ben-Hur <idoybh2@gmail.com>
Co-authored-by: SuperDroidBond <superdroidbond@yahoo.com>
Signed-off-by: spezi77 <spezi7713@gmx.net>
Change-Id: I26c826066569af2cb07c2a9e6c03f6c71f8a18f7
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
SKULSHADY
2022-02-03 20:48:33 +01:00
committed by Hưng Phan
parent a855197418
commit 3b1960c6ea
3 changed files with 27 additions and 1 deletions

View File

@@ -512,5 +512,6 @@
<string name="network_traffic_dynamic">Dynamic</string> <string name="network_traffic_dynamic">Dynamic</string>
<string name="network_traffic_download">Download</string> <string name="network_traffic_download">Download</string>
<string name="network_traffic_upload">Upload</string> <string name="network_traffic_upload">Upload</string>
<string name="network_traffic_font_size">Single net font size</string>
</resources> </resources>

View File

@@ -51,4 +51,12 @@
settings:units="sec" settings:units="sec"
android:defaultValue="1" /> android:defaultValue="1" />
</PreferenceScreen> <com.cherish.settings.preferences.CustomSeekBarPreference
android:key="network_traffic_font_size"
android:title="@string/network_traffic_font_size"
android:max="20"
android:min="12"
settings:defaultValue="18"
settings:units="dp" />
</PreferenceScreen>

View File

@@ -59,10 +59,12 @@ public class Traffic extends SettingsPreferenceFragment implements OnPreferenceC
private static final String NETWORK_TRAFFIC_AUTOHIDE_THRESHOLD = "network_traffic_autohide_threshold"; private static final String NETWORK_TRAFFIC_AUTOHIDE_THRESHOLD = "network_traffic_autohide_threshold";
private static final String NETWORK_TRAFFIC_LOCATION = "network_traffic_location"; private static final String NETWORK_TRAFFIC_LOCATION = "network_traffic_location";
private static final String NETWORK_TRAFFIC_REFRESH_INTERVAL = "network_traffic_refresh_interval"; private static final String NETWORK_TRAFFIC_REFRESH_INTERVAL = "network_traffic_refresh_interval";
private static final String NETWORK_TRAFFIC_FONT_SIZE = "network_traffic_font_size";
private CustomSeekBarPreference mThreshold; private CustomSeekBarPreference mThreshold;
private SystemSettingSeekBarPreference mInterval; private SystemSettingSeekBarPreference mInterval;
private ListPreference mNetTrafficLocation; private ListPreference mNetTrafficLocation;
private CustomSeekBarPreference mNetTrafficSize;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@@ -91,6 +93,12 @@ public class Traffic extends SettingsPreferenceFragment implements OnPreferenceC
mInterval.setValue(val); mInterval.setValue(val);
mInterval.setOnPreferenceChangeListener(this); mInterval.setOnPreferenceChangeListener(this);
int fontSize = Settings.System.getInt(resolver,
Settings.System.NETWORK_TRAFFIC_FONT_SIZE, 18);
mNetTrafficSize = (CustomSeekBarPreference) findPreference(NETWORK_TRAFFIC_FONT_SIZE);
mNetTrafficSize.setValue(fontSize / 1);
mNetTrafficSize.setOnPreferenceChangeListener(this);
int netMonitorEnabled = Settings.System.getIntForUser(resolver, int netMonitorEnabled = Settings.System.getIntForUser(resolver,
Settings.System.NETWORK_TRAFFIC_STATE, 0, UserHandle.USER_CURRENT); Settings.System.NETWORK_TRAFFIC_STATE, 0, UserHandle.USER_CURRENT);
if (netMonitorEnabled == 1) { if (netMonitorEnabled == 1) {
@@ -145,6 +153,11 @@ public class Traffic extends SettingsPreferenceFragment implements OnPreferenceC
Settings.System.NETWORK_TRAFFIC_REFRESH_INTERVAL, val, Settings.System.NETWORK_TRAFFIC_REFRESH_INTERVAL, val,
UserHandle.USER_CURRENT); UserHandle.USER_CURRENT);
return true; return true;
} else if (preference == mNetTrafficSize) {
int fontSize = ((Integer)objValue).intValue();
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.NETWORK_TRAFFIC_FONT_SIZE, fontSize);
return true;
} }
return false; return false;
} }
@@ -154,11 +167,15 @@ public class Traffic extends SettingsPreferenceFragment implements OnPreferenceC
case 0: case 0:
mThreshold.setEnabled(false); mThreshold.setEnabled(false);
mInterval.setEnabled(false); mInterval.setEnabled(false);
mNetTrafficSize.setEnabled(false);
break; break;
case 1: case 1:
mNetTrafficSize.setEnabled(true);
break;
case 2: case 2:
mThreshold.setEnabled(true); mThreshold.setEnabled(true);
mInterval.setEnabled(true); mInterval.setEnabled(true);
mNetTrafficSize.setEnabled(false);
break; break;
default: default:
break; break;