public static void updateAllWidgets(boolean SU_SEL, final Context context, final int layoutResourceId, final Class < ? extends AppWidgetProvider > appWidgetClass) { boolean su = SuBinary(); boolean selinux = isSELinuxActive(context); RemoteViews remoteViews = new RemoteViews(context.getPackageName(), layoutResourceId); remoteViews.setTextViewText(R.id.iSuMain, "SU" + "\n" + (su ? context.getString(R.string.activated) : context.getString(R.string.deactivated))); remoteViews.setInt(R.id.iSuMain, "setBackgroundResource", (su ? R.drawable.button : R.drawable.buttong)); if (SU_SEL) { remoteViews.setTextViewText(R.id.iSuMonitor, context.getString(R.string.selinux) + "\n" + (selinux ? context.getString(R.string.enforcing) : context.getString(R.string.permissive))); remoteViews.setInt(R.id.iSuMonitor, "setBackgroundResource", (selinux ? R.drawable.buttong : R.drawable.button)); } AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); final int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, appWidgetClass)); appWidgetManager.partiallyUpdateAppWidget(appWidgetIds, remoteViews); }
/** * Creates a bunch of widgets by inflating the same layout multiple times. * * @param appWidgetProviderClass the app widget provider class * @param widgetLayoutId id of the layout to inflate * @param howManyToCreate number of new widgets to create * @return the IDs of the new widgets */ public int[] createWidgets(Class<? extends AppWidgetProvider> appWidgetProviderClass, int widgetLayoutId, int howManyToCreate) { AppWidgetProvider appWidgetProvider = newInstanceOf(appWidgetProviderClass); int[] newWidgetIds = new int[howManyToCreate]; for (int i = 0; i < howManyToCreate; i++) { View widgetView = createWidgetView(widgetLayoutId); int myWidgetId = nextWidgetId++; widgetInfos.put(myWidgetId, new WidgetInfo(widgetView, widgetLayoutId, appWidgetProvider)); newWidgetIds[i] = myWidgetId; } appWidgetProvider.onUpdate(context, realAppWidgetManager, newWidgetIds); return newWidgetIds; }
public void getWidgetIDs(){ AppWidgetManager manager = AppWidgetManager.getInstance(this); ArrayList<Integer> widgets = new ArrayList<>(); int[] IDs; IDs = manager.getAppWidgetIds(new ComponentName(getApplicationContext(), AppWidgetProvider.class)); for(int i=0; i < IDs.length;i++){ //Toast.makeText(getBaseContext(),"IDS: " + IDs[i] ,Toast.LENGTH_LONG).show(); widgets.add(IDs[i]); } }
public static void addListener(Context context, RemoteViews rv, int appWidgetId, int componentId, String action, Class<? extends AppWidgetProvider> widgetClass) { Intent intent = new Intent(context, widgetClass) .setAction(action) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, appWidgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT); // use the appWidgetId as a unique identifier to avoid different instances overwriting each other rv.setOnClickPendingIntent(componentId, pendingIntent); }
public static void fireEvent(Context context, int appWidgetId, String action, Class<? extends AppWidgetProvider> widgetClass, Map<String, String> extraStrings, Map<String, Integer> extraInts) { Intent intent = new Intent(context, widgetClass) .setAction(action) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); fillIntent(intent, extraStrings, extraInts); context.sendBroadcast(intent); }
public static void addListListener(Context context, RemoteViews rv, int appWidgetId, int componentId, String action, Class<? extends AppWidgetProvider> widgetClass) { // Here we setup the a pending intent template. Individuals items of a collection // cannot setup their own pending intents, instead, the collection as a whole can // setup a pending intent template, and the individual items can set a fillInIntent // to create unique before on an item to item basis. Intent i = new Intent(context, widgetClass) .setAction(action) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); i.setData(Uri.parse(i.toUri(Intent.URI_INTENT_SCHEME))); PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); rv.setPendingIntentTemplate(componentId, pi); }
public static void updateWidgets(Context context, Class<? extends AppWidgetProvider> widgetType) { Intent intent = new Intent(context, widgetType); intent.setAction("android.appwidget.action.APPWIDGET_UPDATE"); int ids[] = AppWidgetManager.getInstance(context) .getAppWidgetIds(new ComponentName(context, widgetType)); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS,ids); context.sendBroadcast(intent); }
public WidgetInfo(View view, int layoutId, AppWidgetProvider appWidgetProvider) { this.view = view; this.layoutId = layoutId; this.appWidgetProvider = appWidgetProvider; String packageName = appWidgetProvider.getClass().getPackage().getName(); String className = appWidgetProvider.getClass().getName(); providerComponent = new ComponentName(packageName, className); }
@Test public void shouldNotComplainIfServiceIsDestroyedWhileAnotherServiceHasRegisteredBroadcastReceivers() throws Exception { MyService service1 = new MyService(); MyService service2 = new MyService(); service2.registerReceiver(new AppWidgetProvider(), new IntentFilter()); service1.onDestroy(); // should not throw exception }
@Test public void shouldNotComplainIfActivityIsDestroyedWhileAnotherActivityHasRegisteredBroadcastReceivers() throws Exception { activity = create(DialogLifeCycleActivity.class); DialogLifeCycleActivity activity2 = new DialogLifeCycleActivity(); activity2.registerReceiver(new AppWidgetProvider(), new IntentFilter()); destroy(activity); // should not throw exception }
private void pushUpdate(Context context, int[] appWidgetIds, RemoteViews views) { // Update specific list of appWidgetIds if given, // otherwise default to all AppWidgetManager manager = AppWidgetManager.getInstance(context); if (appWidgetIds != null) { manager.updateAppWidget(appWidgetIds, views); } else { Class<? extends AppWidgetProvider> cls = getClass(); ComponentName provider = new ComponentName(context, cls); manager.updateAppWidget(provider, views); } }
/** * Provides the Context for the AppWidgetProvider associated with this graph. * * @return the AppWidgetProvider Context */ @Provides @Singleton @AppWidgetProvider public Context provideAppWidgetProviderContext() { return mContext; }
/** * Provides the Injector for the AppWidgetProvider-scope graph * * @return the Injector */ @Provides @Singleton @AppWidgetProvider public Injector provideAppWidgetProviderInjector() { return mInjector; }
@SuppressWarnings("unused") static public void ForceUpdateAll(Context ctx, Class<? extends AppWidgetProvider> widgetProviderClass) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(ctx); ComponentName thisAppWidget = new ComponentName(ctx.getPackageName(), widgetProviderClass.getName()); @SuppressWarnings("ConstantConditions") int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget); assert appWidgetIds != null; for (int id : appWidgetIds) { ForceUpdate(ctx, id, widgetProviderClass); } }
private Class<? extends AppWidgetProvider> getAppWidgetProvider() { return NewsAppWidgetProvider.class; }
private void createWidgetProvider(Class<? extends AppWidgetProvider> appWidgetProviderClass, int... newWidgetIds) { AppWidgetProvider appWidgetProvider = newInstanceOf(appWidgetProviderClass); appWidgetProvider.onUpdate(context, realAppWidgetManager, newWidgetIds); }
@Test(expected = IllegalArgumentException.class) public void unregisterReceiver_shouldThrowExceptionWhenReceiverIsNotRegistered() throws Exception { contextWrapper.unregisterReceiver(new AppWidgetProvider()); }
@Test(expected = IllegalStateException.class) public void shouldComplainIfServiceIsDestroyedWithRegisteredBroadcastReceivers() throws Exception { service.registerReceiver(new AppWidgetProvider(), new IntentFilter()); service.onDestroy(); }
@Test(expected = IllegalStateException.class) public void shouldComplainIfActivityIsDestroyedWithRegisteredBroadcastReceivers() throws Exception { activity = create(DialogLifeCycleActivity.class); activity.registerReceiver(new AppWidgetProvider(), new IntentFilter()); destroy(activity); }
public static int[] getAppWidgetIds(final Context context, final AppWidgetManager appWidgetManager, final Class<? extends AppWidgetProvider> widgetProviderClass) { ComponentName thisAppWidget = new ComponentName(context.getPackageName(), widgetProviderClass.getName()); int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget); return appWidgetIds; }
/** * Class constructor. * * @param appWidgetProvider the InjectingAppWidgetProvider with which this module is associated. */ public InjectingAppWidgetProviderModule(Context context, android.appwidget.AppWidgetProvider appWidgetProvider, Injector injector) { mContext = context; mAppWidgetProvider = appWidgetProvider; mInjector = injector; }
/** * Provides the AppWidgetProvider * * @return the AppWidgetProvider */ @Provides @Singleton public android.appwidget.AppWidgetProvider provideAppWidgetProvider() { return mAppWidgetProvider; }
static public void ForceUpdate(Context ctx, int widgetId, Class<? extends AppWidgetProvider> widgetProviderClass) { Intent updateWidget = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null, ctx, widgetProviderClass); updateWidget.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[]{widgetId}); ctx.sendBroadcast(updateWidget); }
/** * Creates a widget by inflating its layout. * * @param appWidgetProviderClass the app widget provider class * @param widgetLayoutId id of the layout to inflate * @return the ID of the new widget */ public int createWidget(Class<? extends AppWidgetProvider> appWidgetProviderClass, int widgetLayoutId) { return createWidgets(appWidgetProviderClass, widgetLayoutId, 1)[0]; }
/** * Non-Android accessor. * * @param widgetId id of the widget whose provider is to be returned * @return the {@code AppWidgetProvider} associated with {@code widgetId} */ public AppWidgetProvider getAppWidgetProviderFor(int widgetId) { return widgetInfos.get(widgetId).appWidgetProvider; }