本文整理汇总了Java中android.appwidget.AppWidgetProvider类的典型用法代码示例。如果您正苦于以下问题:Java AppWidgetProvider类的具体用法?Java AppWidgetProvider怎么用?Java AppWidgetProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AppWidgetProvider类属于android.appwidget包,在下文中一共展示了AppWidgetProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateAllWidgets
import android.appwidget.AppWidgetProvider; //导入依赖的package包/类
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);
}
示例2: createWidgets
import android.appwidget.AppWidgetProvider; //导入依赖的package包/类
/**
* 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;
}
示例3: getWidgetIDs
import android.appwidget.AppWidgetProvider; //导入依赖的package包/类
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]);
}
}
示例4: addListener
import android.appwidget.AppWidgetProvider; //导入依赖的package包/类
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);
}
示例5: fireEvent
import android.appwidget.AppWidgetProvider; //导入依赖的package包/类
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);
}
示例6: addListListener
import android.appwidget.AppWidgetProvider; //导入依赖的package包/类
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);
}
示例7: updateWidgets
import android.appwidget.AppWidgetProvider; //导入依赖的package包/类
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);
}
示例8: WidgetInfo
import android.appwidget.AppWidgetProvider; //导入依赖的package包/类
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);
}
示例9: shouldNotComplainIfServiceIsDestroyedWhileAnotherServiceHasRegisteredBroadcastReceivers
import android.appwidget.AppWidgetProvider; //导入依赖的package包/类
@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
}
示例10: shouldNotComplainIfActivityIsDestroyedWhileAnotherActivityHasRegisteredBroadcastReceivers
import android.appwidget.AppWidgetProvider; //导入依赖的package包/类
@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
}
示例11: pushUpdate
import android.appwidget.AppWidgetProvider; //导入依赖的package包/类
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);
}
}
示例12: provideAppWidgetProviderContext
import android.appwidget.AppWidgetProvider; //导入依赖的package包/类
/**
* Provides the Context for the AppWidgetProvider associated with this graph.
*
* @return the AppWidgetProvider Context
*/
@Provides
@Singleton
@AppWidgetProvider
public Context provideAppWidgetProviderContext() {
return mContext;
}
示例13: provideAppWidgetProviderInjector
import android.appwidget.AppWidgetProvider; //导入依赖的package包/类
/**
* Provides the Injector for the AppWidgetProvider-scope graph
*
* @return the Injector
*/
@Provides
@Singleton
@AppWidgetProvider
public Injector provideAppWidgetProviderInjector() {
return mInjector;
}
示例14: ForceUpdateAll
import android.appwidget.AppWidgetProvider; //导入依赖的package包/类
@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);
}
}
示例15: getAppWidgetProvider
import android.appwidget.AppWidgetProvider; //导入依赖的package包/类
private Class<? extends AppWidgetProvider> getAppWidgetProvider() {
return NewsAppWidgetProvider.class;
}