mirror of https://github.com/M66B/NetGuard.git
Widget improvements
This commit is contained in:
parent
d19a329fce
commit
17e1c16718
|
@ -75,9 +75,9 @@ public class SinkholeService extends VpnService {
|
|||
last_roaming = Util.isRoaming(SinkholeService.this);
|
||||
vpn = startVPN();
|
||||
startDebug(vpn);
|
||||
removeDisabledNotification();
|
||||
Widget.updateWidgets(SinkholeService.this);
|
||||
}
|
||||
removeDisabledNotification();
|
||||
Widget.updateWidgets(SinkholeService.this);
|
||||
break;
|
||||
|
||||
case reload:
|
||||
|
@ -95,8 +95,8 @@ public class SinkholeService extends VpnService {
|
|||
stopDebug();
|
||||
stopVPN(vpn);
|
||||
vpn = null;
|
||||
Widget.updateWidgets(SinkholeService.this);
|
||||
}
|
||||
Widget.updateWidgets(SinkholeService.this);
|
||||
stopSelf();
|
||||
break;
|
||||
}
|
||||
|
@ -159,6 +159,7 @@ public class SinkholeService extends VpnService {
|
|||
|
||||
// Feedback
|
||||
Util.toast(ex.toString(), Toast.LENGTH_LONG, this);
|
||||
Widget.updateWidgets(this);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -338,6 +339,7 @@ public class SinkholeService extends VpnService {
|
|||
|
||||
// Display warning
|
||||
showDisabledNotification();
|
||||
Widget.updateWidgets(this);
|
||||
|
||||
super.onRevoke();
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import android.content.ComponentName;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.VpnService;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
|
@ -63,13 +64,17 @@ public class Widget extends AppWidgetProvider {
|
|||
private static void update(int[] appWidgetIds, AppWidgetManager appWidgetManager, Context context) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean enabled = prefs.getBoolean("enabled", false);
|
||||
Intent intent = new Intent(enabled ? INTENT_OFF : INTENT_ON);
|
||||
PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
|
||||
PendingIntent pi;
|
||||
if (VpnService.prepare(context) == null)
|
||||
pi = PendingIntent.getBroadcast(context, 0, new Intent(enabled ? INTENT_OFF : INTENT_ON), PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
else
|
||||
pi = PendingIntent.getActivity(context, 0, new Intent(context, ActivityMain.class), PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
|
||||
for (int id : appWidgetIds) {
|
||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
|
||||
views.setOnClickPendingIntent(R.id.ivEnabled, pi);
|
||||
views.setImageViewResource(R.id.ivEnabled, enabled ? R.mipmap.ic_launcher : R.drawable.ic_security_white_24dp);
|
||||
views.setImageViewResource(R.id.ivEnabled, enabled ? R.mipmap.ic_launcher : R.drawable.ic_security_white_24dp_60);
|
||||
appWidgetManager.updateAppWidget(id, views);
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 895 B |
Binary file not shown.
After Width: | Height: | Size: 593 B |
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
Loading…
Reference in New Issue