Network traffic with center cutout [2/3]

A new setting NETWORK_TRAFFIC_POSITION decides, if the traffic display
is at the traditional center position or right or left.

Change-Id: I768259696be1186cb1dd4630c2b35540529a7f67
This commit is contained in:
Wolfram Liebchen
2023-01-24 20:15:34 +01:00
committed by Michael Bestas
parent 3ee210210d
commit 95e2d729c9
2 changed files with 32 additions and 2 deletions

View File

@@ -2972,6 +2972,19 @@ public final class LineageSettings {
public static final Validator NETWORK_TRAFFIC_MODE_VALIDATOR =
new InclusiveIntegerRangeValidator(0, 3);
/**
* Network traffic indicator position
* 0 = Start side
* 1 = Center
* 2 = End side
* @hide
*/
public static final String NETWORK_TRAFFIC_POSITION = "network_traffic_position";
/** @hide */
public static final Validator NETWORK_TRAFFIC_POSITION_VALIDATOR =
new InclusiveIntegerRangeValidator(0, 2);
/**
* Whether or not to hide the network traffic indicator when there is no activity
* @hide
@@ -3094,6 +3107,7 @@ public final class LineageSettings {
VALIDATORS.put(BERRY_BLACK_THEME, BERRY_BLACK_THEME_VALIDATOR);
VALIDATORS.put(GESTURE_BACK_EXCLUDE_TOP, GESTURE_BACK_EXCLUDE_TOP_VALIDATOR);
VALIDATORS.put(NETWORK_TRAFFIC_MODE, NETWORK_TRAFFIC_MODE_VALIDATOR);
VALIDATORS.put(NETWORK_TRAFFIC_POSITION, NETWORK_TRAFFIC_POSITION_VALIDATOR);
VALIDATORS.put(NETWORK_TRAFFIC_AUTOHIDE, NETWORK_TRAFFIC_AUTOHIDE_VALIDATOR);
VALIDATORS.put(NETWORK_TRAFFIC_UNITS, NETWORK_TRAFFIC_UNITS_VALIDATOR);
VALIDATORS.put(NETWORK_TRAFFIC_SHOW_UNITS, NETWORK_TRAFFIC_SHOW_UNITS_VALIDATOR);

View File

@@ -1,5 +1,5 @@
/**
* Copyright (C) 2017-2020 The LineageOS project
* Copyright (C) 2017-2023 The LineageOS project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,6 +58,10 @@ public class NetworkTraffic extends TextView {
private static final int MODE_DOWNSTREAM_ONLY = 2;
private static final int MODE_UPSTREAM_AND_DOWNSTREAM = 3;
private static final int POSITION_START = 0;
private static final int POSITION_CENTER = 1;
private static final int POSITION_END = 2;
private static final int MESSAGE_TYPE_PERIODIC_REFRESH = 0;
private static final int MESSAGE_TYPE_UPDATE_VIEW = 1;
private static final int MESSAGE_TYPE_ADD_NETWORK = 2;
@@ -82,6 +86,8 @@ public class NetworkTraffic extends TextView {
private final SettingsObserver mObserver;
private int mMode = MODE_DISABLED;
private int mPosition = POSITION_CENTER;
private int mViewPosition = -1;
private boolean mNetworkTrafficIsVisible;
private long mTxKbps;
private long mRxKbps;
@@ -185,7 +191,8 @@ public class NetworkTraffic extends TextView {
}
private void displayStatsAndReschedule() {
final boolean enabled = mMode != MODE_DISABLED && isConnectionAvailable();
final boolean enabled = mMode != MODE_DISABLED && mPosition == mViewPosition
&& isConnectionAvailable();
final boolean showUpstream =
mMode == MODE_UPSTREAM_ONLY || mMode == MODE_UPSTREAM_AND_DOWNSTREAM;
final boolean showDownstream =
@@ -311,6 +318,10 @@ public class NetworkTraffic extends TextView {
.registerDefaultNetworkCallback(defaultNetworkCallback);
}
public void setViewPosition(int vpos) {
mViewPosition = vpos;
}
private final LineageStatusBarItem.DarkReceiver mDarkReceiver =
new LineageStatusBarItem.DarkReceiver() {
public void onDarkChanged(ArrayList<Rect> areas, float darkIntensity, int tint) {
@@ -361,6 +372,9 @@ public class NetworkTraffic extends TextView {
resolver.registerContentObserver(LineageSettings.Secure.getUriFor(
LineageSettings.Secure.NETWORK_TRAFFIC_MODE),
false, this, UserHandle.USER_ALL);
resolver.registerContentObserver(LineageSettings.Secure.getUriFor(
LineageSettings.Secure.NETWORK_TRAFFIC_POSITION),
false, this, UserHandle.USER_ALL);
resolver.registerContentObserver(LineageSettings.Secure.getUriFor(
LineageSettings.Secure.NETWORK_TRAFFIC_AUTOHIDE),
false, this, UserHandle.USER_ALL);
@@ -392,6 +406,8 @@ public class NetworkTraffic extends TextView {
mMode = LineageSettings.Secure.getInt(resolver,
LineageSettings.Secure.NETWORK_TRAFFIC_MODE, 0);
mPosition = LineageSettings.Secure.getInt(resolver,
LineageSettings.Secure.NETWORK_TRAFFIC_POSITION, POSITION_CENTER);
mAutoHide = LineageSettings.Secure.getInt(resolver,
LineageSettings.Secure.NETWORK_TRAFFIC_AUTOHIDE, 0) == 1;
mUnits = LineageSettings.Secure.getInt(resolver,