Use level list for network state

This commit is contained in:
M66B 2015-11-04 13:14:44 +01:00
parent 9c2cda867d
commit 4ecd024df0
3 changed files with 23 additions and 32 deletions

View File

@ -89,9 +89,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
private boolean running = false;
private View actionView;
private ImageView ivInteractive;
private ImageView ivWifi;
private ImageView ivOther;
private ImageView ivRoaming;
private ImageView ivNetwork;
private SwipeRefreshLayout swipeRefresh;
private RuleAdapter adapter = null;
private MenuItem menuSearch = null;
@ -129,9 +127,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
actionView = getLayoutInflater().inflate(R.layout.action, null);
SwitchCompat swEnabled = (SwitchCompat) actionView.findViewById(R.id.swEnabled);
ivInteractive = (ImageView) actionView.findViewById(R.id.ivInteractive);
ivWifi = (ImageView) actionView.findViewById(R.id.ivWifi);
ivOther = (ImageView) actionView.findViewById(R.id.ivOther);
ivRoaming = (ImageView) actionView.findViewById(R.id.ivRoaming);
ivNetwork = (ImageView) actionView.findViewById(R.id.ivNetwork);
getSupportActionBar().setDisplayShowCustomEnabled(true);
getSupportActionBar().setCustomView(actionView);
@ -322,17 +318,15 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
Log.i(TAG, "Received " + intent);
Util.logExtras(TAG, intent);
ivWifi.setVisibility(View.GONE);
ivOther.setVisibility(View.GONE);
ivRoaming.setVisibility(View.GONE);
ivNetwork.setVisibility(View.VISIBLE);
if (Util.isMetered(context)) {
if (Util.isRoaming(context))
ivRoaming.setVisibility(View.VISIBLE);
ivNetwork.setImageLevel(3);
else
ivOther.setVisibility(View.VISIBLE);
ivNetwork.setImageLevel(2);
} else
ivWifi.setVisibility(View.VISIBLE);
ivNetwork.setImageLevel(1);
actionView.postInvalidate();
}

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/ic_network_wifi_white_24dp"
android:maxLevel="1"
android:minLevel="1" />
<item
android:drawable="@drawable/ic_network_cell_white_24dp"
android:maxLevel="2"
android:minLevel="2" />
<item
android:drawable="@drawable/ic_network_cell_white_24px_roaming"
android:maxLevel="3"
android:minLevel="3" />
</level-list>

View File

@ -21,29 +21,11 @@
android:visibility="invisible" />
<ImageView
android:id="@+id/ivWifi"
android:id="@+id/ivNetwork"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="4dp"
android:src="@drawable/ic_network_wifi_white_24dp"
android:visibility="gone" />
<ImageView
android:id="@+id/ivOther"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="4dp"
android:src="@drawable/ic_network_cell_white_24dp"
android:visibility="gone" />
<ImageView
android:id="@+id/ivRoaming"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="4dp"
android:src="@drawable/ic_network_cell_white_24px_roaming"
android:src="@drawable/network"
android:visibility="gone" />
</LinearLayout>