Show if internet connectivity (experimental)

This commit is contained in:
M66B 2017-02-10 20:38:39 +01:00
parent 4ff5d74173
commit ca65ab92a0
27 changed files with 87 additions and 2 deletions

View File

@ -138,7 +138,6 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/reports" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />

View File

@ -86,6 +86,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
private ImageView ivIcon;
private ImageView ivQueue;
private SwitchCompat swEnabled;
private ImageView ivActive;
private ImageView ivMetered;
private SwipeRefreshLayout swipeRefresh;
private AdapterRule adapter = null;
@ -151,6 +152,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
ivIcon = (ImageView) actionView.findViewById(R.id.ivIcon);
ivQueue = (ImageView) actionView.findViewById(R.id.ivQueue);
swEnabled = (SwitchCompat) actionView.findViewById(R.id.swEnabled);
ivActive = (ImageView) actionView.findViewById(R.id.ivActive);
ivMetered = (ImageView) actionView.findViewById(R.id.ivMetered);
// Icon
@ -239,6 +241,23 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
if (enabled)
checkDoze();
// Network is active
ivActive.setImageResource(Util.isActive(ActivityMain.this) ? R.drawable.ic_cloud_queue_white_24dp : R.drawable.ic_cloud_off_white_24dp);
ivActive.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
int location[] = new int[2];
actionView.getLocationOnScreen(location);
Toast toast = Toast.makeText(ActivityMain.this, Util.isActive(ActivityMain.this) ? R.string.msg_active : R.string.msg_inactive, Toast.LENGTH_LONG);
toast.setGravity(
Gravity.TOP | Gravity.LEFT,
location[0] + ivActive.getLeft(),
Math.round(location[1] + ivActive.getBottom() - toast.getView().getPaddingTop()));
toast.show();
return true;
}
});
// Network is metered
ivMetered.setOnLongClickListener(new View.OnLongClickListener() {
@Override
@ -608,7 +627,8 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
Log.i(TAG, "Received " + intent);
Util.logExtras(intent);
if (adapter != null)
if (adapter != null) {
ivActive.setImageResource(Util.isActive(ActivityMain.this) ? R.drawable.ic_cloud_queue_white_24dp : R.drawable.ic_cloud_off_white_24dp);
if (intent.hasExtra(EXTRA_CONNECTED) && intent.hasExtra(EXTRA_METERED)) {
if (intent.getBooleanExtra(EXTRA_CONNECTED, false)) {
if (intent.getBooleanExtra(EXTRA_METERED, false))
@ -622,6 +642,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
}
} else
updateApplicationList(null);
}
}
};

View File

@ -114,6 +114,11 @@ public class Util {
}
}
public static boolean isActive(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
return (cm == null ? false : cm.getActiveNetworkInfo() != null);
}
public static boolean isConnected(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = (cm == null ? null : cm.getActiveNetworkInfo());

Binary file not shown.

After

Width:  |  Height:  |  Size: 460 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 462 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 425 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 593 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 534 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 537 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 834 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 859 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 784 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 785 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -30,6 +30,14 @@
android:layout_marginStart="16dp"
android:saveEnabled="false" />
<ImageView
android:id="@+id/ivActive"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp" />
<ImageView
android:id="@+id/ivMetered"
android:layout_width="24dp"

View File

@ -65,6 +65,50 @@
android:textAppearance="@style/TextMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:layout_margin="4dp"
android:src="?attr/iconActive" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:text="@string/msg_active"
android:textAppearance="@style/TextMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:layout_margin="4dp"
android:src="?attr/iconInactive" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:text="@string/msg_inactive"
android:textAppearance="@style/TextMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -196,6 +196,8 @@ Your internet traffic is not being sent to a remote VPN server.</string>
<string name="msg_start_forward" formatted="false">Start forwarding from %1$s port %2$d to %3$s:%4$d of \'%5$s\'?</string>
<string name="msg_stop_forward">Stop forwarding of %1$s port %2$d?</string>
<string name="msg_metered">Network is metered</string>
<string name="msg_active">Network is active</string>
<string name="msg_inactive">Network is inactive</string>
<string name="msg_queue">NetGuard is busy</string>
<string name="msg_update">Update available, tap to download</string>
<string name="msg_usage">You can allow (greenish) or deny (reddish) Wi-Fi or mobile internet access to by tapping on the icons next to an application</string>

View File

@ -3,6 +3,8 @@
<attr name="colorOff" format="reference" />
<attr name="expander" format="reference" />
<attr name="iconQueue" format="reference" />
<attr name="iconActive" format="reference" />
<attr name="iconInactive" format="reference" />
<attr name="iconMetered" format="reference" />
<attr name="iconSettings" format="reference" />
<attr name="iconDatasaver" format="reference" />
@ -19,6 +21,8 @@
<style name="BaseThemeDark" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="expander">@drawable/expander_black</item>
<item name="iconQueue">@drawable/ic_hourglass_empty_black_24dp</item>
<item name="iconActive">@drawable/ic_cloud_queue_black_24dp</item>
<item name="iconInactive">@drawable/ic_cloud_off_black_24dp</item>
<item name="iconMetered">@drawable/ic_attach_money_black_24dp</item>
<item name="iconSettings">@drawable/ic_settings_black_24dp</item>
<item name="iconDatasaver">@drawable/ic_perm_data_setting_black_24dp</item>
@ -32,6 +36,8 @@
<style name="BaseThemeLight" parent="Theme.AppCompat">
<item name="expander">@drawable/expander_white</item>
<item name="iconQueue">@drawable/ic_hourglass_empty_white_24dp</item>
<item name="iconActive">@drawable/ic_cloud_queue_white_24dp</item>
<item name="iconInactive">@drawable/ic_cloud_off_white_24dp</item>
<item name="iconMetered">@drawable/ic_attach_money_white_24dp</item>
<item name="iconSettings">@drawable/ic_settings_white_24dp</item>
<item name="iconDatasaver">@drawable/ic_perm_data_setting_white_24dp</item>