Java 类android.appwidget.AppWidgetProvider 实例源码
项目:isu
文件:Tools.java
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);
}
项目:FullRobolectricTestSample
文件:ShadowAppWidgetManager.java
/**
* 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;
}
项目:Exo-Launcher
文件:MainActivity.java
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]);
}
}
项目:WorkflowyList
文件:AppWidgetUtils.java
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);
}
项目:WorkflowyList
文件:AppWidgetUtils.java
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);
}
项目:WorkflowyList
文件:AppWidgetUtils.java
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);
}
项目:CumulusTV
文件:ChannelShortcut.java
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);
}
项目:FullRobolectricTestSample
文件:ShadowAppWidgetManager.java
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);
}
项目:FullRobolectricTestSample
文件:ServiceTest.java
@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
}
项目:FullRobolectricTestSample
文件:ActivityTest.java
@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
}
项目:android-vlc-remote
文件:MediaAppWidgetProvider.java
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);
}
}
项目:android-vlc-remote
文件:SeekControlWidgetProvider.java
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);
}
}
项目:fb-android-dagger
文件:InjectingAppWidgetProvider.java
/**
* Provides the Context for the AppWidgetProvider associated with this graph.
*
* @return the AppWidgetProvider Context
*/
@Provides
@Singleton
@AppWidgetProvider
public Context provideAppWidgetProviderContext() {
return mContext;
}
项目:fb-android-dagger
文件:InjectingAppWidgetProvider.java
/**
* Provides the Injector for the AppWidgetProvider-scope graph
*
* @return the Injector
*/
@Provides
@Singleton
@AppWidgetProvider
public Injector provideAppWidgetProviderInjector() {
return mInjector;
}
项目:Android-NetPowerctrl
文件:WidgetUpdateService.java
@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);
}
}
项目:opencdk-appwidget
文件:NewsRemoteViews.java
private Class<? extends AppWidgetProvider> getAppWidgetProvider() {
return NewsAppWidgetProvider.class;
}
项目:FullRobolectricTestSample
文件:ShadowAppWidgetManager.java
private void createWidgetProvider(Class<? extends AppWidgetProvider> appWidgetProviderClass, int... newWidgetIds) {
AppWidgetProvider appWidgetProvider = newInstanceOf(appWidgetProviderClass);
appWidgetProvider.onUpdate(context, realAppWidgetManager, newWidgetIds);
}
项目:FullRobolectricTestSample
文件:ContextWrapperTest.java
@Test(expected = IllegalArgumentException.class)
public void unregisterReceiver_shouldThrowExceptionWhenReceiverIsNotRegistered() throws Exception {
contextWrapper.unregisterReceiver(new AppWidgetProvider());
}
项目:FullRobolectricTestSample
文件:ServiceTest.java
@Test(expected = IllegalStateException.class)
public void shouldComplainIfServiceIsDestroyedWithRegisteredBroadcastReceivers() throws Exception {
service.registerReceiver(new AppWidgetProvider(), new IntentFilter());
service.onDestroy();
}
项目:FullRobolectricTestSample
文件:ActivityTest.java
@Test(expected = IllegalStateException.class)
public void shouldComplainIfActivityIsDestroyedWithRegisteredBroadcastReceivers() throws Exception {
activity = create(DialogLifeCycleActivity.class);
activity.registerReceiver(new AppWidgetProvider(), new IntentFilter());
destroy(activity);
}
项目:nsuweather-android
文件:AppWidgetHelper.java
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;
}
项目:fb-android-dagger
文件:InjectingAppWidgetProvider.java
/**
* 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;
}
项目:fb-android-dagger
文件:InjectingAppWidgetProvider.java
/**
* Provides the AppWidgetProvider
*
* @return the AppWidgetProvider
*/
@Provides
@Singleton
public android.appwidget.AppWidgetProvider provideAppWidgetProvider() {
return mAppWidgetProvider;
}
项目:Android-NetPowerctrl
文件:WidgetUpdateService.java
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);
}
项目:FullRobolectricTestSample
文件:ShadowAppWidgetManager.java
/**
* 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];
}
项目:FullRobolectricTestSample
文件:ShadowAppWidgetManager.java
/**
* 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;
}