本文整理匯總了Java中android.appwidget.AppWidgetManager類的典型用法代碼示例。如果您正苦於以下問題:Java AppWidgetManager類的具體用法?Java AppWidgetManager怎麽用?Java AppWidgetManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AppWidgetManager類屬於android.appwidget包,在下文中一共展示了AppWidgetManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateAppWidget
import android.appwidget.AppWidgetManager; //導入依賴的package包/類
private void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.message_list_widget_layout);
views.setTextViewText(R.id.folder, context.getString(R.string.integrated_inbox_title));
Intent intent = new Intent(context, MessageListWidgetService.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
views.setRemoteAdapter(R.id.listView, intent);
PendingIntent viewAction = viewActionTemplatePendingIntent(context);
views.setPendingIntentTemplate(R.id.listView, viewAction);
PendingIntent composeAction = composeActionPendingIntent(context);
views.setOnClickPendingIntent(R.id.new_message, composeAction);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
示例2: onReceive
import android.appwidget.AppWidgetManager; //導入依賴的package包/類
@Override
public void onReceive(final Context context, Intent intent) {
if (AppWidgetManager.ACTION_APPWIDGET_HOST_RESTORED.equals(intent.getAction())) {
final int[] oldIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_OLD_IDS);
final int[] newIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
if (oldIds.length == newIds.length) {
final PendingResult asyncResult = goAsync();
new Handler(LauncherModel.getWorkerLooper())
.postAtFrontOfQueue(new Runnable() {
@Override
public void run() {
restoreAppWidgetIds(context, asyncResult, oldIds, newIds);
}
});
}
}
}
示例3: updateAppWidget
import android.appwidget.AppWidgetManager; //導入依賴的package包/類
private static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.schedule_daily_widget);
Intent intent = new Intent(context, ScheduleDailyService.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
views.setRemoteAdapter(appWidgetId, R.id.list_item, intent);
views.setViewVisibility(R.id.sync_instruction, IS_NOT_READY_YET ? TextView.VISIBLE : TextView.GONE);
Intent launchMain = new Intent(context, MainActivity.class);
PendingIntent pendingMainIntent = PendingIntent.getActivity(context, 0, launchMain, 0);
views.setOnClickPendingIntent(R.id.widget_daily, pendingMainIntent);
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.list_item);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
示例4: updateAppWidget
import android.appwidget.AppWidgetManager; //導入依賴的package包/類
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId) {
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.monolith_widget);
// Intent to launch MainActivity
final Intent onItemClick = new Intent(context, MonolithWidget.class);
onItemClick.setAction(ACTION_WIDGET_CLICK);
if (intent != null) {
onItemClick.setData(intent.getData());
Log.e("Content not null", "updateAppWidget: " + intent.getData());
}
PendingIntent onClickPendingIntent = PendingIntent
.getBroadcast(context, 0, onItemClick,
PendingIntent.FLAG_UPDATE_CURRENT);
views.setPendingIntentTemplate(R.id.widget_list,
onClickPendingIntent);
views.setRemoteAdapter(R.id.widget_list,
new Intent(context, WidgetService.class));
views.setEmptyView(R.id.widget_list, R.id.widget_empty);
// Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, views);
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.widget_list);
}
示例5: updateWidget
import android.appwidget.AppWidgetManager; //導入依賴的package包/類
static boolean updateWidget(Context context, int widgetId, String path) {
if (TextUtils.isEmpty(path) || widgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
return false;
}
String name = PFile.getNameWithoutExtension(path);
int requestCode = ScriptWidgets.getRequestCodeForAppWidgetId(widgetId);
Log.d(LOG_TAG, "updateWidget: id = " + widgetId + ", requestCode = " + requestCode + ", path = " + path);
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_script_shortcut);
views.setOnClickPendingIntent(R.id.widget, PendingIntent.getActivity(context, requestCode,
new Intent(context, RunIntentActivity.class)
.putExtra(CommonUtils.EXTRA_KEY_PATH, path)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), PendingIntent.FLAG_UPDATE_CURRENT));
views.setTextViewText(R.id.name, name);
appWidgetManager.updateAppWidget(widgetId, views);
ScriptWidgets.setPathForAppWidgetId(widgetId, path);
return true;
}
示例6: popupSelectWidget
import android.appwidget.AppWidgetManager; //導入依賴的package包/類
public void popupSelectWidget() {
// Allocate widget id and start widget selection activity
int appWidgetId = this.mAppWidgetHost.allocateAppWidgetId();
Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
addEmptyData(pickIntent); // This is needed work around some weird bug.
mParent.startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
}
示例7: onActivityResult
import android.appwidget.AppWidgetManager; //導入依賴的package包/類
public AppWidgetHostView onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d("LaunchWidgeth", "onActivityResult: requestCode=" + requestCode + " resultCode=" + resultCode);
// listen for widget manager response
if (resultCode == Activity.RESULT_OK) {
if (requestCode == REQUEST_PICK_APPWIDGET) {
Log.d("LaunchWidgeth", "configureWidget");
return configureWidget(data);
} else if (requestCode == REQUEST_CREATE_APPWIDGET || requestCode == REQUEST_BIND_APPWIDGET) {
Log.d("LaunchWidgeth", "createWidget");
return createWidget(data);
} else {
Log.d("LaunchWidgeth", "unknown RESULT_OK");
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Log.d("LaunchWidgeth", "RESULT_CANCELED");
if (data!=null) {
int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
if (appWidgetId != -1) {
mAppWidgetHost.deleteAppWidgetId(appWidgetId);
}
}
}
return null;
}
示例8: updateWidget
import android.appwidget.AppWidgetManager; //導入依賴的package包/類
private static void updateWidget(Context context) {
ComponentName name = new ComponentName(context, BooksWidgetProvider.class);
int[] ids = AppWidgetManager.getInstance(context).getAppWidgetIds(name);
Intent intent = new Intent(context, BooksWidgetProvider.class);
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
context.sendBroadcast(intent);
}
示例9: get
import android.appwidget.AppWidgetManager; //導入依賴的package包/類
/**
* - * Returns a widget with category {@link AppWidgetProviderInfo#WIDGET_CATEGORY_SEARCHBOX}
* - * provided by the same package which is set to be global search activity.
* - * If widgetCategory is not supported, or no such widget is found, returns the first widget
* - * provided by the package.
* -
*/
public static AppWidgetProviderInfo get(Context context) {
SearchManager searchManager =
(SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
ComponentName searchComponent = searchManager.getGlobalSearchActivity();
if (searchComponent == null) return null;
String providerPkg = searchComponent.getPackageName();
AppWidgetProviderInfo defaultWidgetForSearchPackage = null;
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
for (AppWidgetProviderInfo info : appWidgetManager.getInstalledProviders()) {
if (info.provider.getPackageName().equals(providerPkg) && info.configure == null) {
if ((info.widgetCategory & AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX) != 0) {
return info;
} else if (defaultWidgetForSearchPackage == null) {
defaultWidgetForSearchPackage = info;
}
}
}
return defaultWidgetForSearchPackage;
}
示例10: getDefaultOptionsForWidget
import android.appwidget.AppWidgetManager; //導入依賴的package包/類
public static Bundle getDefaultOptionsForWidget(Context context, PendingAddWidgetInfo info) {
Rect rect = new Rect();
AppWidgetResizeFrame.getWidgetSizeRanges(context, info.spanX, info.spanY, rect);
Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context,
info.componentName, null);
float density = context.getResources().getDisplayMetrics().density;
int xPaddingDips = (int) ((padding.left + padding.right) / density);
int yPaddingDips = (int) ((padding.top + padding.bottom) / density);
Bundle options = new Bundle();
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH,
rect.left - xPaddingDips);
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT,
rect.top - yPaddingDips);
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH,
rect.right - xPaddingDips);
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT,
rect.bottom - yPaddingDips);
return options;
}
示例11: onReceive
import android.appwidget.AppWidgetManager; //導入依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
int widgetId = intent.getIntExtra(WIDGET_ID, 0);
int appIndex = intent.getIntExtra(APPLICATION_INDEX, 0);
if (KILL_CLICKED.equals(intent.getAction())) {
ApplicationInfo applicationInfo = debugApps.get(appIndex);
ActivityManager systemService = (ActivityManager) context.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
systemService.killBackgroundProcesses(applicationInfo.packageName);
Toast.makeText(context, context.getString(R.string.kill_process, applicationInfo.packageName), Toast.LENGTH_SHORT).show();
} else if (IMAGE_CLICKED.equals(intent.getAction())) {
appIndex = ++appIndex < debugApps.size() - 1 ? appIndex : 0;
setupRemoteViews(context, appWidgetManager, remoteViews, widgetId, appIndex);
}
}
示例12: onClick
import android.appwidget.AppWidgetManager; //導入依賴的package包/類
public void onClick(View v) {
final Context context = AppWidgetConfigureActivity.this;
// When the button is clicked, store the color locally
saveBackgroundColorPref(context, mAppWidgetId, backgroundColor);
saveButtonColorPref(context, mAppWidgetId, buttonColor);
saveTextColorPref(context, mAppWidgetId, textColor);
// It is the responsibility of the configuration activity to update the app widget
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
AppWidget.updateAppWidget(context, appWidgetManager, mAppWidgetId);
// Make sure we pass back the original appWidgetId
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
finish();
}
示例13: pushUpdate
import android.appwidget.AppWidgetManager; //導入依賴的package包/類
private void pushUpdate(Context context, int[] appWidgetIds, RemoteViews views)
{
// Update specific list of appWidgetIds if given, otherwise default to all
final AppWidgetManager manager = AppWidgetManager.getInstance(context);
if (manager != null)
{
if (appWidgetIds != null)
{
manager.updateAppWidget(appWidgetIds, views);
}
else
{
manager.updateAppWidget(new ComponentName(context, this.getClass()), views);
}
}
}
示例14: sendRefreshBroadcast
import android.appwidget.AppWidgetManager; //導入依賴的package包/類
public static void sendRefreshBroadcast(Context context) {
Intent intent = new Intent(context, TodoListAppWidgetProvider.class);
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
AppWidgetManager manager = AppWidgetManager.getInstance(context);
ComponentName component = new ComponentName(context, TodoListAppWidgetProvider.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, manager.getAppWidgetIds(component));
context.sendBroadcast(intent);
}
示例15: getWidgetWidthFromOptions
import android.appwidget.AppWidgetManager; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private int getWidgetWidthFromOptions(AppWidgetManager appWidgetManager, int appWidgetId) {
Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);
if (options.containsKey(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH)) {
int minWidthDp = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH);
// The width returned is in dp, but we'll convert it to pixels to match the other widths
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, minWidthDp,
displayMetrics);
}
return getResources().getDimensionPixelSize(R.dimen.widget_today_default_width);
}