[2/2] OmniGears: rework and cleanup network traffic

Change-Id: Ie7962d2cd58544c2ab956ade9db4cddaaed5b9eb
diff --git a/res/values/custom_arrays.xml b/res/values/custom_arrays.xml
index 64451ee..eff5300 100644
--- a/res/values/custom_arrays.xml
+++ b/res/values/custom_arrays.xml
@@ -149,14 +149,12 @@
 
     <!-- Network Traffic Display States -->
     <string-array name="show_network_traffic_state_entries" translatable="false">
-        <item>@string/show_network_traffic_disable</item>
         <item>@string/show_network_traffic_up</item>
         <item>@string/show_network_traffic_down</item>
         <item>@string/show_network_traffic_all</item>
     </string-array>
 
     <string-array name="show_network_traffic_state_values" translatable="false">
-        <item>0</item>
         <item>1</item>
         <item>2</item>
         <item>3</item>
diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml
index a0c5740..7cebd66 100644
--- a/res/values/custom_strings.xml
+++ b/res/values/custom_strings.xml
@@ -271,7 +271,8 @@
 
     <!-- Network traffic -->
     <string name="network_traffic_title">Network traffic</string>
-    <string name="show_network_traffic_state">Status bar traffic monitor</string>
+    <string name="network_traffic_summary">Status bar traffic monitor</string>
+    <string name="show_network_traffic_state">Display traffic type</string>
     <string name="show_network_traffic_unit">Display unit</string>
     <string name="show_network_traffic_frequency">Update interval</string>
     <string name="show_network_traffic_disable">Disabled</string>
@@ -287,6 +288,7 @@
     <string name="network_traffic_autohide_title">Auto hide</string>
     <string name="network_traffic_autohide_summary">Hide the traffic monitor when there is no activity</string>
     <string name="network_traffic_autohide_threshold">Inactivity threshold</string>
+    <string name="network_traffic_enable_title">Enable</string>
 
     <!-- statusbar brightness -->
     <string name="status_bar_brightness_control_title">Brightness control</string>
diff --git a/res/xml/bars_settings.xml b/res/xml/bars_settings.xml
index e813280..9f8d195 100644
--- a/res/xml/bars_settings.xml
+++ b/res/xml/bars_settings.xml
@@ -21,30 +21,31 @@
             android:key="category_statusbar"
             android:title="@string/statusbar_title">
 
-            <org.omnirom.omnigears.preference.SystemCheckBoxPreference
+            <org.omnirom.omnigears.preference.SystemSettingSwitchPreference
                 android:key="double_tap_sleep_gesture"
                 android:title="@string/double_tap_to_sleep_title"
                 android:summary="@string/double_tap_to_sleep_summary"
                 android:defaultValue="false" />
 
-            <org.omnirom.omnigears.preference.SystemCheckBoxPreference
+            <org.omnirom.omnigears.preference.SystemSettingSwitchPreference
                 android:key="status_bar_ime_notification"
                 android:title="@string/status_bar_ime_notification_title"
                 android:summary="@string/status_bar_ime_notification_summary"
                 android:defaultValue="true"/>
 
-        </PreferenceCategory>
-
-        <PreferenceScreen
+            <Preference
                 android:key="category_network_traffic"
                 android:title="@string/network_traffic_title"
+                android:summary="@string/network_traffic_summary"
                 android:fragment="org.omnirom.omnigears.interfacesettings.NetworkTraffic" />
 
+        </PreferenceCategory>
+
         <PreferenceCategory
             android:key="category_navigationbar"
             android:title="@string/navigationbar_title">
 
-            <org.omnirom.omnigears.preference.SystemCheckBoxPreference
+            <org.omnirom.omnigears.preference.SystemSettingSwitchPreference
                 android:key="navigation_bar_ime_button"
                 android:title="@string/navigation_bar_ime_button_title"
                 android:summary="@string/navigation_bar_ime_button_summary"
diff --git a/res/xml/network_traffic.xml b/res/xml/network_traffic.xml
index 6877985..6b73836 100644
--- a/res/xml/network_traffic.xml
+++ b/res/xml/network_traffic.xml
@@ -19,32 +19,42 @@
         android:key="category_network_traffic"
         android:title="@string/network_traffic_title">
 
+           <org.omnirom.omnigears.preference.SystemSettingSwitchPreference
+                android:key="network_traffic_enable"
+                android:title="@string/network_traffic_enable_title"
+                android:defaultValue="false"/>
+
             <ListPreference
                 android:key="network_traffic_state"
                 android:title="@string/show_network_traffic_state"
                 android:entries="@array/show_network_traffic_state_entries"
                 android:entryValues="@array/show_network_traffic_state_values"
-                android:persistent="false" />
+                android:persistent="false"
+                android:defaultValue="1"
+                android:dependency="network_traffic_enable" />
 
             <ListPreference
                 android:key="network_traffic_unit"
                 android:title="@string/show_network_traffic_unit"
                 android:entries="@array/show_network_traffic_unit_entries"
                 android:entryValues="@array/show_network_traffic_unit_values"
-                android:persistent="false" />
+                android:persistent="false"
+                android:dependency="network_traffic_enable" />
 
             <ListPreference
                 android:key="network_traffic_period"
                 android:title="@string/show_network_traffic_frequency"
                 android:entries="@array/show_network_traffic_frequency_entries"
                 android:entryValues="@array/show_network_traffic_frequency_values"
-                android:persistent="false" />
+                android:persistent="false"
+                android:dependency="network_traffic_enable" />
 
-            <org.omnirom.omnigears.preference.SystemCheckBoxPreference
+            <org.omnirom.omnigears.preference.SystemSettingSwitchPreference
                 android:key="network_traffic_autohide"
                 android:title="@string/network_traffic_autohide_title"
                 android:summary="@string/network_traffic_autohide_summary"
-                android:defaultValue="false"/>
+                android:defaultValue="false"
+                android:dependency="network_traffic_enable" />
 
             <org.omnirom.omnigears.preference.SeekBarPreference
                 android:key="network_traffic_autohide_threshold"
diff --git a/src/org/omnirom/omnigears/interfacesettings/NetworkTraffic.java b/src/org/omnirom/omnigears/interfacesettings/NetworkTraffic.java
index 6f983f9..d69d06c 100644
--- a/src/org/omnirom/omnigears/interfacesettings/NetworkTraffic.java
+++ b/src/org/omnirom/omnigears/interfacesettings/NetworkTraffic.java
@@ -47,7 +47,6 @@
 import java.util.ArrayList;
 
 import org.omnirom.omnigears.preference.SeekBarPreference;
-import org.omnirom.omnigears.preference.SystemCheckBoxPreference;
 
 public class NetworkTraffic extends SettingsPreferenceFragment implements
         Preference.OnPreferenceChangeListener, Indexable {
@@ -62,7 +61,6 @@
     private ListPreference mNetTrafficState;
     private ListPreference mNetTrafficUnit;
     private ListPreference mNetTrafficPeriod;
-    private SystemCheckBoxPreference mNetTrafficAutohide;
     private SeekBarPreference mNetTrafficAutohideThreshold;
 
     private int mNetTrafficVal;
@@ -89,7 +87,6 @@
         mNetTrafficState = (ListPreference) prefScreen.findPreference(NETWORK_TRAFFIC_STATE);
         mNetTrafficUnit = (ListPreference) prefScreen.findPreference(NETWORK_TRAFFIC_UNIT);
         mNetTrafficPeriod = (ListPreference) prefScreen.findPreference(NETWORK_TRAFFIC_PERIOD);
-        mNetTrafficAutohide = (SystemCheckBoxPreference) prefScreen.findPreference(NETWORK_TRAFFIC_AUTOHIDE);
         mNetTrafficAutohideThreshold = (SeekBarPreference) prefScreen.findPreference(NETWORK_TRAFFIC_AUTOHIDE_THRESHOLD);
 
         // TrafficStats will return UNSUPPORTED if the device does not support it.
@@ -117,11 +114,6 @@
                     Settings.System.NETWORK_TRAFFIC_AUTOHIDE_THRESHOLD, 10);
             mNetTrafficAutohideThreshold.setValue(netTrafficAutohideThreshold / 1);
             mNetTrafficAutohideThreshold.setOnPreferenceChangeListener(this);
-
-            mNetTrafficUnit.setEnabled(intIndex != 0);
-            mNetTrafficPeriod.setEnabled(intIndex != 0);
-            mNetTrafficAutohide.setEnabled(intIndex != 0);
-            mNetTrafficAutohideThreshold.setEnabled(intIndex != 0);
         }
     }
 
@@ -135,10 +127,6 @@
             Settings.System.putInt(resolver, Settings.System.NETWORK_TRAFFIC_STATE, mNetTrafficVal);
             int index = mNetTrafficState.findIndexOfValue((String) newValue);
             mNetTrafficState.setSummary(mNetTrafficState.getEntries()[index]);
-            mNetTrafficUnit.setEnabled(intState != 0);
-            mNetTrafficPeriod.setEnabled(intState != 0);
-            mNetTrafficAutohide.setEnabled(intState != 0);
-            mNetTrafficAutohideThreshold.setEnabled(intState != 0);
         } else if (preference == mNetTrafficUnit) {
             // 1 = Display as Byte/s; default is bit/s
             mNetTrafficVal = setBit(mNetTrafficVal, MASK_UNIT, ((String)newValue).equals("1"));