当前位置: 首页>>代码示例>>Java>>正文


Java AppWidgetManager类代码示例

本文整理汇总了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);
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:19,代码来源:MessageListWidgetProvider.java

示例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);
                        }
                    });
        }
    }
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:18,代码来源:AppWidgetsRestoredReceiver.java

示例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);
}
 
开发者ID:mgilangjanuar,项目名称:GoSCELE,代码行数:19,代码来源:ScheduleDailyWidget.java

示例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);
}
 
开发者ID:prshntpnwr,项目名称:Monolith,代码行数:26,代码来源:MonolithWidget.java

示例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;
}
 
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:19,代码来源:ScriptWidget.java

示例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);
}
 
开发者ID:quaap,项目名称:LaunchTime,代码行数:9,代码来源:Widget.java

示例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;
    }
 
开发者ID:quaap,项目名称:LaunchTime,代码行数:27,代码来源:Widget.java

示例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);
}
 
开发者ID:paulnunezm,项目名称:Boookito-Capstone-Project,代码行数:9,代码来源:FirebaseRepo.java

示例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;
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:29,代码来源:SearchWidgetProvider.java

示例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;
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:22,代码来源:WidgetHostViewLoader.java

示例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);
    }
}
 
开发者ID:EmmettWilson,项目名称:AppTerminator,代码行数:21,代码来源:TerminatorWidgetProvider.java

示例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();
}
 
开发者ID:personaljesusua,项目名称:DepressingThoughts,代码行数:19,代码来源:AppWidgetConfigureActivity.java

示例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);
		}
	}
}
 
开发者ID:ultrasonic,项目名称:ultrasonic,代码行数:18,代码来源:UltraSonicAppWidgetProvider.java

示例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);
}
 
开发者ID:djuelg,项目名称:Neuronizer,代码行数:9,代码来源:TodoListAppWidgetProvider.java

示例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);
}
 
开发者ID:changja88,项目名称:Udacity_Sunshine,代码行数:13,代码来源:TodayWidgetIntentService.java


注:本文中的android.appwidget.AppWidgetManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。