Java 类android.appwidget.AppWidgetManager 实例源码

项目:LaunchEnr    文件:AppWidgetsRestoredReceiver.java   
@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);
                        }
                    });
        }
    }
}
项目:GoSCELE    文件:ScheduleDailyWidget.java   
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);
}
项目:Monolith    文件:MonolithWidget.java   
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);
}
项目:https-github.com-hyb1996-NoRootScriptDroid    文件:ScriptWidget.java   
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;
}
项目:q-mail    文件:MessageListWidgetProvider.java   
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);
}
项目:LaunchTime    文件:Widget.java   
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;
    }
项目:Boookito-Capstone-Project    文件:FirebaseRepo.java   
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);
}
项目:LaunchEnr    文件:SearchWidgetProvider.java   
/**
 * -     * 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;
}
项目:LaunchEnr    文件:WidgetHostViewLoader.java   
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;
}
项目:AppTerminator    文件:TerminatorWidgetProvider.java   
@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);
    }
}
项目:DepressingThoughts    文件:AppWidgetConfigureActivity.java   
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();
}
项目:ultrasonic    文件:UltraSonicAppWidgetProvider.java   
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);
        }
    }
}
项目:Neuronizer    文件:TodoListAppWidgetProvider.java   
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);
}
项目:Udacity_Sunshine    文件:TodayWidgetIntentService.java   
@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);
}
项目:GitJourney    文件:GitHubJourneyWidgetProvider.java   
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
                            int appWidgetId, Parcelable[] parcelables) {
    Log.v(TAG, "updateAppWidget parcelables = " + parcelables.length);
    // Construct the RemoteViews object
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.git_hub_journey_widget);

    Intent startActivityIntent = new Intent(context, GeneralActivity.class);
    PendingIntent startActivityPendingIntent = PendingIntent.getActivity(context, 0, startActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    views.setPendingIntentTemplate(R.id.widget_data_view, startActivityPendingIntent);

    Calendar calendar = Calendar.getInstance();
    DateFormat dateFormat = Utils.createDateFormatterWithTimeZone(context, context.getString(R.string.add_widget_date_format));
    views.setTextViewText(R.id.widget_date, dateFormat.format(calendar.getTime()));
    Intent intent = new Intent(context, StackWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    // When intents are compared, the extras are ignored, so we need to embed the extras
    // into the data so that the extras will not be ignored.
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    Bundle bundle = new Bundle();
    bundle.putParcelableArray("parcelables", parcelables);
    intent.putExtra("bundle", bundle);
    views.setRemoteAdapter(R.id.widget_data_view, intent);
    views.setEmptyView(R.id.widget_data_view, R.id.empty_view);
    // Instruct the widget manager to update the widget
    appWidgetManager.updateAppWidget(appWidgetId, views);
}
项目:puremadrid    文件:GetLastStatusAsync.java   
@Override
protected ApiMedicion doInBackground(Object... params) {
    ApiMedicion result = getLastStatusRequest(isFromBackgound);
    while (result == null && isFromBackgound && retries < MAX_RETRIES){
        retries++;
        result = getLastStatusRequest(isFromBackgound);
    }

    if (result != null) {
        // Update database in background thread
        PureMadridDbHelper.addMeasure(mContext, result);

        // Update Widget
        Intent intent = new Intent(mContext, PureMadridWidget.class);
        intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
        ComponentName thisWidget = new ComponentName(mContext, PureMadridWidget.class);
        int[] appWidgetIds = AppWidgetManager.getInstance(mContext).getAppWidgetIds(thisWidget);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
        mContext.sendBroadcast(intent);

    }
    return result;
}
项目:SimpleUILauncher    文件:QsbContainerView.java   
/**
 * 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 getSearchWidgetProvider(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;
}
项目:CSipSimple    文件:AccountWidgetConfigure.java   
@Override
public void onAccountClicked(long accountId, String d, String w) {

    if(appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
        SharedPreferences prefs = getSharedPreferences(WIDGET_PREFS, 0);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putLong(getPrefsKey(appWidgetId), accountId);
        edit.commit();


        Intent resultValue = new Intent();
        resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                        appWidgetId);
        setResult(RESULT_OK, resultValue);

        AccountWidgetProvider.updateWidget(this);

        finish();
    }else {
        Log.w(THIS_FILE, "Invalid widget ID here...");
    }
}
项目:FlickLauncher    文件:QsbContainerView.java   
/**
 * 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 getSearchWidgetProvider(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;
}
项目:AppTerminator    文件:TerminatorWidgetProvider.java   
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    PackageManager packageManager = context.getPackageManager();
    List<ApplicationInfo> installedApplications = packageManager.getInstalledApplications(0);
    debugApps = new ArrayList<>();
    for (ApplicationInfo applicationInfo : installedApplications) {
        boolean isDebuggable = (0 != (applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE));
        if (isDebuggable) {
            debugApps.add(applicationInfo);
        }
    }

    for(int widgetId : appWidgetIds){
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);

        setupRemoteViews(context, appWidgetManager, remoteViews, widgetId, 0);
    }
}
项目:https-github.com-hyb1996-NoRootScriptDroid    文件:ScriptWidgetSettingsActivity.java   
@Override
public void finish() {
    if (ScriptWidget.updateWidget(this, mAppWidgetId, mSelectedScriptFilePath)) {
        setResult(RESULT_OK, new Intent()
                .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId));

    } else {
        setResult(RESULT_CANCELED, new Intent()
                .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId));
    }
    super.finish();
}
项目:https-github.com-hyb1996-NoRootScriptDroid    文件:ScriptWidget.java   
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);
    Set<Integer> appWidgetIdSet = new HashSet<>();
    for (int appWidgetId : appWidgetIds) {
        updateWidget(context, appWidgetId, ScriptWidgets.getPathForAppWidgetId(appWidgetId));
        appWidgetIdSet.add(appWidgetId);
    }
    if (appWidgetIdSet.size() > 1)
        ScriptWidgets.removeAllNotIn(appWidgetIdSet);
}
项目:buildAPKsSamples    文件:StackWidgetProvider.java   
@Override
public void onReceive(Context context, Intent intent) {
    AppWidgetManager mgr = AppWidgetManager.getInstance(context);
    if (intent.getAction().equals(TOAST_ACTION)) {
        int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                AppWidgetManager.INVALID_APPWIDGET_ID);
        int viewIndex = intent.getIntExtra(EXTRA_ITEM, 0);
        Toast.makeText(context, "Touched view " + viewIndex, Toast.LENGTH_SHORT).show();
    }
    super.onReceive(context, intent);
}
项目:LaunchTime    文件:Widget.java   
private void addEmptyData(Intent pickIntent) {
    // This is needed work around some weird bug.
    // This will simply add some empty data to the intent.
    ArrayList<Parcelable> customInfo = new ArrayList<>();
    pickIntent.putParcelableArrayListExtra(AppWidgetManager.EXTRA_CUSTOM_INFO, customInfo);
    ArrayList<Parcelable> customExtras = new ArrayList<>();
    pickIntent.putParcelableArrayListExtra(AppWidgetManager.EXTRA_CUSTOM_EXTRAS, customExtras);
}
项目:ThunderMusic    文件:MediaAppWidgetProvider2x1.java   
private void pushUpdate(Context context, int[] appWidgetIds,
                        RemoteViews views) {
    // Update specific list of appWidgetIds if given, otherwise default to
    // all
    final AppWidgetManager gm = AppWidgetManager.getInstance(context);
    if (appWidgetIds != null) {
        gm.updateAppWidget(appWidgetIds, views);
    } else {
        gm.updateAppWidget(new ComponentName(context, this.getClass()),
                views);
    }
}
项目:financisto1-holo    文件:AccountWidget.java   
@Override
public void onReceive(Context context, Intent intent) {
    Log.d("FinancistoWidget", "onReceive intent "+intent);
    String action = intent.getAction();
    if (WIDGET_UPDATE_ACTION.equals(action)) {
        int widgetId = intent.getIntExtra(WIDGET_ID, INVALID_APPWIDGET_ID);
        if (widgetId != INVALID_APPWIDGET_ID) {
            AppWidgetManager manager = AppWidgetManager.getInstance(context);
            updateWidgets(context, manager, new int[]{widgetId}, true);
        }
    } else {
        super.onReceive(context, intent);
    }
}
项目:GarageDoor    文件:ConfigureGarageDoor.java   
public void onOk(View v) {
    final EditText userEdit = (EditText) findViewById(R.id.userEdit);
    final EditText passwordEdit = (EditText) findViewById(R.id.passwordEdit);

    mSharedPreferences.edit().putString(GarageDoorWidgetProvider.PREF_USERNAME,
            userEdit.getText().toString()).apply();
    mSharedPreferences.edit().putString(GarageDoorWidgetProvider.PREF_PASSWORD,
            passwordEdit.getText().toString()).apply();

    Intent resultValue = new Intent();
    resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
    setResult(RESULT_OK, resultValue);
    finish();
}
项目:orgzly-android    文件:FilterSelectDialogActivity.java   
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG, "onItemClick", id);

    /* notify Widget */
    Intent intent = new Intent(this, ListWidgetProvider.class);
    intent.setAction(AppIntent.ACTION_SET_FILTER_LIST_WIDGET);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, getIntent().getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID));
    intent.putExtra(AppIntent.EXTRA_SAVED_SEARCH_ID, id);
    sendBroadcast(intent);

    setResult(RESULT_OK);
    finish();
}
项目:q-mail    文件:MessageListWidgetProvider.java   
@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);

    String action = intent.getAction();
    if (action.equals(ACTION_UPDATE_MESSAGE_LIST)) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        int[] appWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
        appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.listView);
    }
}
项目:homescreenarcade    文件:UpDownWidget.java   
protected void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
                            int appWidgetId) {
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.up_down_widget);
    views.setOnClickPendingIntent(R.id.up_btn,
            PendingIntent.getBroadcast(context, 0, new Intent(ArcadeCommon.ACTION_UP), 0));
    views.setOnClickPendingIntent(R.id.down_btn,
            PendingIntent.getBroadcast(context, 0, new Intent(ArcadeCommon.ACTION_DOWN), 0));

    appWidgetManager.updateAppWidget(appWidgetId, views);
}
项目:homescreenarcade    文件:LeftRightWidget.java   
protected void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
                            int appWidgetId) {
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.left_right_widget);
    views.setOnClickPendingIntent(R.id.left_btn,
            PendingIntent.getBroadcast(context, 0, new Intent(ArcadeCommon.ACTION_LEFT), 0));
    views.setOnClickPendingIntent(R.id.right_btn,
            PendingIntent.getBroadcast(context, 0, new Intent(ArcadeCommon.ACTION_RIGHT), 0));

    appWidgetManager.updateAppWidget(appWidgetId, views);
}
项目:TaipeiTechRefined    文件:CourseWidgetProvider.java   
private void refreshCourseTable(Context context, RemoteViews views) {
    Intent clickIntent = new Intent(context, MainActivity.class);
    clickIntent.setAction(Intent.ACTION_MAIN);
    clickIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    clickIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
            R.id.course_widget_table);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
            clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    views.setOnClickPendingIntent(R.id.course_widget_table, pendingIntent);
    Model model = Model.getInstance();
    cleanTable(context, views);
    showCourse(context, views, model.getStudentCourse());
}
项目:LaunchTime    文件:Widget.java   
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);
}
项目:GitHub    文件:AppWidgetTarget.java   
/**
 * Updates the AppWidget after the ImageView has loaded the Bitmap.
 */
private void update() {
  AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this.context);
  if (this.componentName != null) {
    appWidgetManager.updateAppWidget(this.componentName, this.remoteViews);
  } else {
    appWidgetManager.updateAppWidget(this.widgetIds, this.remoteViews);
  }
}
项目:PingWidget    文件:PingWidgetUpdateService.java   
@Override
public void onConfigurationChanged(Configuration newConfig) {
    Log.d(TAG, "onConfigurationChanged() " + newConfig.toString());

    //Called when screen is rotated, phone charging state changes
    //The widget gets reset, so we need to reconfigure some things

    //Get AppWidgetManager
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getApplicationContext());

    // Get all widget ids
    int[] allWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(getApplication(), PingWidgetProvider.class));

    for (int widgetId : allWidgetIds) {

        //Get widget data
        PingWidgetData data = SharedPreferencesHelper.readPingWidgetData(getApplicationContext(), widgetId);
        if(data != null) {

            //Get RemoteViews
            RemoteViews views = RemoteViewsUtil.getRemoteViews(getApplicationContext(), data.getWidgetLayoutType());

            //Update widget views
            RemoteViewsUtil.initWidgetViews(getApplicationContext(), views, data);

            //Register an Intent so that onClicks on the widget are received by PingWidgetProvider.onReceive()
            //Create an Intent, set PING_WIDGET_TOGGLE action to it, put EXTRA_APPWIDGET_ID as extra
            Util.registerWidgetStartPauseOnClickListener(getApplication(), widgetId, views);
            Util.registerWidgetReconfigureClickListener(getApplication(), widgetId, views);

            //Update the widget
            appWidgetManager.updateAppWidget(widgetId, views);
        }

    }
    super.onConfigurationChanged(newConfig);
}
项目:Boookito-Capstone-Project    文件:BooksWidgetProvider.java   
@Override
  public void onReceive(Context context, Intent intent) {
    AppWidgetManager mgr = AppWidgetManager.getInstance(context);
//    Toast.makeText(context, "Touched view -> onReceive", Toast.LENGTH_SHORT).show();


    if (intent.getAction().equals(CLICKED_ITEM_ACTION)) {
      String bookId = intent.getStringExtra(CLICKED_ITEM_BOOK_ID);

      final FirebaseRepo firebaseRepo = FirebaseRepo.getInstance();
      firebaseRepo.setContext(context);
      firebaseRepo.setFirebaseAnalytics(FirebaseAnalytics.getInstance(context));

      // First we get the book from the corresponding id.
      FirebaseRepo.GetBookFromListListener listener = new FirebaseRepo.GetBookFromListListener() {
        @Override
        public void onReceivedBook(Book book) {
          // then we send it to "my books" list.
          firebaseRepo.moveBook(FirebaseNodes.WISHLIST, FirebaseNodes.MY_BOOKS, book);
          firebaseRepo.logEvent("moved_book", "from_widget");
        }

        @Override
        public void onError() {
          Log.d(TAG, "onError: Database error");
        }
      };

      firebaseRepo.getBookFromIdInList(FirebaseNodes.WISHLIST, bookId, listener);
    }

    super.onReceive(context, intent);
  }
项目:musicwidget    文件:StandardWidget.java   
@Override
public void onReceive(Context context, Intent intent) {

    super.onReceive(context, intent);
       ComponentName thisAppWidget = new ComponentName(context.getPackageName(), getClass().getName());
       AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
       int ids[] = appWidgetManager.getAppWidgetIds(thisAppWidget);
       for (int appWidgetID: ids) {
           updateAppWidget(context, appWidgetManager, appWidgetID);
       }
}
项目:chromium-for-android-56-debug-video    文件:BookmarkWidgetProvider.java   
/**
 *  Checks for any states that may have not received onDeleted.
 */
private void removeOrphanedStates(Context context) {
    AppWidgetManager wm = AppWidgetManager.getInstance(context);
    int[] ids = wm.getAppWidgetIds(getComponentName(context));
    for (int id : ids) {
        BookmarkWidgetService.deleteWidgetState(context, id);
    }
}
项目:Udacity_Sunshine    文件:TodayWidgetIntentService.java   
private int getWidgetWidth(AppWidgetManager appWidgetManager, int appWidgetId) {
    // Prior to Jelly Bean, widgets were always their default size
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        return getResources().getDimensionPixelSize(R.dimen.widget_today_default_width);
    }
    // For Jelly Bean and higher devices, widgets can be resized - the current size can be
    // retrieved from the newly added App Widget Options
    return getWidgetWidthFromOptions(appWidgetManager, appWidgetId);
}
项目:Udacity_Sunshine    文件:DetailWidgetProvider.java   
@Override
public void onReceive(@NonNull Context context, @NonNull Intent intent) {
    super.onReceive(context, intent);
    if (SunshineSyncAdapter.ACTION_DATA_UPDATED.equals(intent.getAction())) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        int[] appWidgetIds = appWidgetManager.getAppWidgetIds(
                new ComponentName(context, getClass()));
        appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.widget_list);
    }
}