Widget improvements

This commit is contained in:
M66B 2015-11-07 11:08:30 +01:00
parent d19a329fce
commit 17e1c16718
7 changed files with 13 additions and 6 deletions

View File

@ -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();
}

View File

@ -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