@Override
  public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);

    if (intent.getAction().equals(DATA_FETCHED)) {

      int appWidgetId =
          intent.getIntExtra(
              AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
      AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);

      RemoteViews remoteViews = updateWidgetListView(context, appWidgetId);

      // update and notify widget when data arrives

      appWidgetManager.updateAppWidget(appWidgetId, remoteViews);

      appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.stack_view);
    }

    if (intent.getAction().equals(TOAST_ACTION)) {
      // The click form the widget item is received here
      int appWidgetId =
          intent.getIntExtra(
              AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
      int viewIndex = intent.getIntExtra(EXTRA_ITEM, 0);
      context.startActivity(
          new Intent(context, ShowImagesActivity.class)
              .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
              .putExtra("click", "Clicked Movie is \n --- " + Constants.text[viewIndex]));
    }
  }
  @Override
  public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);
    Log.v(TAG, "onStart");

    // RemoteViews is used with widget. This can be displayed in another process.
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.main);
    // Prepare Intent which is sent when button is clicked
    Intent buttonIntent = new Intent();

    // If this Intent is issued when button is clicked
    if (BUTTON_CLICK_ACTION.equals(intent.getAction())) {
      buttonIntent.setAction(BUTTON_CLICK_ACTION2);
      remoteViews.setTextViewText(R.id.text, "Push Button");
    } else {
      buttonIntent.setAction(BUTTON_CLICK_ACTION);
      remoteViews.setTextViewText(R.id.text, "WidgetSample");
    }

    // Handle this Intent as PendingIntent
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, buttonIntent, 0);
    remoteViews.setOnClickPendingIntent(R.id.button, pendingIntent);
    Log.v(TAG, "set PendingIntent here");
    Toast.makeText(this, "set PendingIntent", Toast.LENGTH_SHORT).show();

    // Update AppWidget display
    ComponentName thisWidget = new ComponentName(this, WidgetSample.class);
    AppWidgetManager manager = AppWidgetManager.getInstance(this);
    manager.updateAppWidget(thisWidget, remoteViews);
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals("android.appwidget.action.notify")) {
      AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
      int appWidgetIds[] =
          appWidgetManager.getAppWidgetIds(new ComponentName(context, TimeTableProvider.class));

      for (int i = 0; i < appWidgetIds.length; i++) {
        Intent svcIntent = new Intent(context, TimeTableWidget.class);

        svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
        svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));

        RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.widget_layout);

        widget.setRemoteAdapter(appWidgetIds[i], R.id.words, svcIntent);

        Intent clickIntent = new Intent(context, MainActivity.class);
        PendingIntent clickPI =
            PendingIntent.getActivity(context, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        widget.setPendingIntentTemplate(R.id.words, clickPI);

        widget.setTextViewText(R.id.weekday, TimeTableControl.today());
        appWidgetManager.updateAppWidget(appWidgetIds[i], widget);
      }
      appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.words);
    }
    super.onReceive(context, intent);
  }
  private void handleIsOpen(final Context mContext, final OpeningStatus openingStatus) {
    final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext);
    final int[] appWidgetIds =
        appWidgetManager.getAppWidgetIds(new ComponentName(mContext, AnalogWidget.class));
    final RemoteViews views = new RemoteViews(mContext.getPackageName(), R.layout.analog_widget);
    views.setTextViewText(R.id.appwidget_text, mContext.getText(R.string.refreshing_analog));
    views.setTextColor(
        R.id.appwidget_text, ContextCompat.getColor(mContext, android.R.color.primary_text_dark));
    // Instruct the widget manager to update the widget
    for (int appWidgetId : appWidgetIds) {
      appWidgetManager.updateAppWidget(appWidgetId, views);
    }

    CharSequence widgetText;
    if (openingStatus.open) {
      widgetText = mContext.getString(R.string.widget_open_analog);
      views.setTextColor(R.id.appwidget_text, ContextCompat.getColor(mContext, R.color.openColor));
    } else {
      widgetText = mContext.getString(R.string.widget_closed_analog);
      views.setTextColor(
          R.id.appwidget_text, ContextCompat.getColor(mContext, R.color.closedColor));
    }

    views.setTextViewText(R.id.appwidget_text, widgetText);
    views.setOnClickPendingIntent(R.id.appwidget_text, getPendingSelfIntent(mContext));
    // Instruct the widget manager to update the widget
    for (int appWidgetId : appWidgetIds) {
      appWidgetManager.updateAppWidget(appWidgetId, views);
    }
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    Log.d(
        Constants.TAG,
        "[ColorThemeChangedReceiver onReceive]---intent.getAction()=" + intent.getAction());
    if (intent.getAction().equals("action.flyaudio.colortheme")) {
      Log.e("lixuanbright", "action.flyaudio.colortheme====");
      //			AppWidgetDao dao = new AppWidgetDao(context);
      //			List<Integer> appWidgetIds = dao.getAppWidgetIds();
      int[] appWidgetIds = AppWidgetDao.getAllAppWidgetId(context);
      appWidgetManager = AppWidgetManager.getInstance(context);
      for (int appWidgetId : appWidgetIds) {
        remoteViews = SwitchWidget.initRemoteViews(context, appWidgetId);
        //  restore shortcut had been set
        SwitchWidget.dataRestore(context, appWidgetId, remoteViews, false);

        appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
      }
      //			dao.close();
    }
    if (Intent.ACTION_LOCALE_CHANGED.equals(intent.getAction())) {
      Log.e("lixuanbright", "主题:Intent.ACTION_LOCALE_CHANGED===");
      /*			int[] appWidgetIds = AppWidgetDao.getAllAppWidgetId(context);
      appWidgetManager = AppWidgetManager.getInstance(context);
      for (int appWidgetId : appWidgetIds) {
       remoteViews =SwitchWidget.initRemoteViews(context, appWidgetId);
      	//  restore shortcut had been set
      	SwitchWidget.dataRestore(context, appWidgetId , remoteViews, false);

      	appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
      }*/
    }
  }
  @Override
  public void onHandleIntent(Intent intent) {
    ComponentName me = new ComponentName(this, AppWidget.class);
    RemoteViews updateViews = new RemoteViews("apt.tutorial", R.layout.widget);
    RestaurantHelper helper = new RestaurantHelper(this);
    AppWidgetManager mgr = AppWidgetManager.getInstance(this);

    try {
      Cursor c = helper.getReadableDatabase().rawQuery(SQL_QUERY_COUNT, null);
      c.moveToFirst();
      int count = c.getInt(0);
      c.close();
      if (count > 0) {
        int offset = (int) (count * Math.random());
        String args[] = {String.valueOf(offset)};
        c = helper.getReadableDatabase().rawQuery(SQL_QUERY_SELECT, args);
        c.moveToFirst();
        updateViews.setTextViewText(R.id.name, c.getString(1));
        Intent i = new Intent(this, DetailForm.class);
        i.putExtra(LunchList.ID_EXTRA, c.getString(0));
        PendingIntent pi = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
        updateViews.setOnClickPendingIntent(R.id.name, pi);
        c.close();
      } else {
        updateViews.setTextViewText(R.id.title, this.getString(R.string.empty));
      }
    } finally {
      helper.close();
    }

    Intent i = new Intent(this, WidgetService.class);
    PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
    updateViews.setOnClickPendingIntent(R.id.next, pi);
    mgr.updateAppWidget(me, updateViews);
  }
  /**
   * 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.
   */
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
  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)) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
          if ((info.widgetCategory & AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX) != 0) {
            return info;
          } else if (defaultWidgetForSearchPackage == null) {
            defaultWidgetForSearchPackage = info;
          }
        } else {
          return info;
        }
      }
    }
    return defaultWidgetForSearchPackage;
  }
 @Override
 public void onReceive(Context context, Intent intent) {
   // TODO Auto-generated method stub
   String action = intent.getAction();
   if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action) || action.equals(_myaction)) {
     int[] IDs = null;
     if (action.equals(_myaction)) {
       ComponentName provdier = new ComponentName(context, this.getClass());
       IDs = AppWidgetManager.getInstance(context).getAppWidgetIds(provdier);
     }
     Bundle extras = intent.getExtras();
     int[] appWidgetIds;
     if (extras != null || IDs != null) {
       if (extras != null) appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
       else appWidgetIds = IDs;
       if (appWidgetIds != null && appWidgetIds.length > 0) {
         if (appWidgetIds.length == 1) {
           this.onUpdate(context, AppWidgetManager.getInstance(context), appWidgetIds);
         } else if (appWidgetIds[0] < appWidgetIds[1]) {
           for (int i = 0; i < appWidgetIds.length; i++) {
             int[] tempappWidgetIds = {appWidgetIds[i]};
             this.onUpdate(context, AppWidgetManager.getInstance(context), tempappWidgetIds);
           }
         } else {
           for (int i = appWidgetIds.length - 1; i > -1; i--) {
             int[] tempappWidgetIds = {appWidgetIds[i]};
             this.onUpdate(context, AppWidgetManager.getInstance(context), tempappWidgetIds);
           }
         }
       }
     }
   } else {
     super.onReceive(context, intent);
   }
 }
  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

    // Get all ids
    ComponentName thisWidget = new ComponentName(context, MyWidgetProvider.class);
    int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
    for (int widgetId : allWidgetIds) {
      // Create some random data
      int number = (new Random().nextInt(100));

      RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
      Log.w("WidgetExample", String.valueOf(number));
      // Set the text
      remoteViews.setTextViewText(R.id.update, String.valueOf(number));

      // Register an onClickListener
      Intent intent = new Intent(context, MyWidgetProvider.class);

      intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
      intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);

      PendingIntent pendingIntent =
          PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
      remoteViews.setOnClickPendingIntent(R.id.update, pendingIntent);
      appWidgetManager.updateAppWidget(widgetId, remoteViews);
    }
  }
  public void onReceive(Context context, Intent intent) {

    Log.d("TimeSetReceiver", "onReceive");

    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.my_widget);

    ComponentName thisWidget; // 组件名
    AppWidgetManager manager; // AppWidget管理器

    thisWidget = new ComponentName(context, CalendarWidget.class);
    manager = AppWidgetManager.getInstance(context);

    Calendar calendar = Calendar.getInstance();

    int day = calendar.get(Calendar.DAY_OF_MONTH);
    int month = calendar.get(Calendar.MONTH) + 1;
    int week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
    Lunar lunar = new Lunar(calendar);

    Log.d("TimeSetReceiver", month + "," + day + lunar.toString());

    String month_week = month + "月" + "          周" + weekArray[week];
    views.setTextViewText(R.id.month_week, month_week);
    views.setTextViewText(R.id.nongli, lunar.toString());
    views.setTextViewText(R.id.day, Html.fromHtml("<B>" + String.valueOf(day) + "</B>"));

    manager.updateAppWidget(thisWidget, views);

    Log.d("TimeSetReceiver", "updateAppWidget finish");
  }
Example #11
0
  private void updateWidgets() {
    RemoteViews widget = new RemoteViews(getPackageName(), R.layout.ticker_widget);
    widget.setOnClickPendingIntent(
        R.id.feed_ticker_tap_area,
        PendingIntent.getActivity(this, 0, new Intent(this, HomeActivity.class), 0));

    Cursor unread =
        getContentResolver()
            .query(
                FeedData.EntryColumns.CONTENT_URI,
                new String[] {FeedData.ALL_UNREAD_NUMBER},
                null,
                null,
                null);
    if (unread != null) {
      if (unread.moveToFirst()) {
        int unread_count = unread.getInt(0);
        if (unread_count > 0) {
          widget.setTextViewText(R.id.feed_ticker, String.valueOf(unread_count));
          widget.setViewVisibility(R.id.feed_ticker, View.VISIBLE);
          widget.setViewVisibility(R.id.feed_ticker_circle, View.VISIBLE);
        } else {
          widget.setViewVisibility(R.id.feed_ticker, View.INVISIBLE);
          widget.setViewVisibility(R.id.feed_ticker_circle, View.INVISIBLE);
        }
      }
      unread.close();
    }

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
    appWidgetManager.updateAppWidget(
        new ComponentName(getPackageName(), TickerWidgetProvider.class.getName()), widget);
  }
Example #12
0
 @TargetApi(Build.VERSION_CODES.HONEYCOMB)
 public static void updateScrollableWidgets(Context context, int[] widgetIds) {
   AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
   if (widgetIds == null) {
     widgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, TasksWidget.class));
   }
   appWidgetManager.notifyAppWidgetViewDataChanged(widgetIds, R.id.list_view);
 }
 public static void updateAllWidgets(Context context) {
   AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
   ComponentName compName = new ComponentName(context, EventAppWidgetProvider.class);
   Intent intent = new Intent(context, EventAppWidgetProvider.class);
   intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
   intent.putExtra(
       AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetManager.getAppWidgetIds(compName));
   context.sendBroadcast(intent);
 }
Example #14
0
 @Override
 public void onReceive(Context context, Intent intent) {
   super.onReceive(context, intent);
   AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
   this.onUpdate(
       context,
       appWidgetManager,
       appWidgetManager.getAppWidgetIds(new ComponentName(context, YambaWidget.class)));
 }
 /*
  * Refresh widget
  */
 private void updateWidget(Context ctx) {
   RemoteViews rview = new RemoteViews(ctx.getPackageName(), R.layout.widget);
   ComponentName cname = new ComponentName(ctx, BlurApnSwitch.class);
   AppWidgetManager amgr = AppWidgetManager.getInstance(ctx);
   rview.setImageViewResource(
       R.id.Unknown, getApnStatus(ctx) ? R.drawable.apn_on : R.drawable.apn_off);
   makeClickable(ctx, rview);
   amgr.updateAppWidget(cname, rview);
 }
 private void pushUpdate(
     final Context context, final int[] appWidgetIds, final RemoteViews views) {
   final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
   if (appWidgetIds != null) {
     appWidgetManager.updateAppWidget(appWidgetIds, views);
   } else {
     appWidgetManager.updateAppWidget(new ComponentName(context, getClass()), views);
   }
 }
 private RemoteViews getRemoteViews(
     Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
   if (mRemoteViews == null) {
     int minWidth = appWidgetManager.getAppWidgetInfo(appWidgetId).minResizeWidth;
     int minHeight = appWidgetManager.getAppWidgetInfo(appWidgetId).minResizeHeight;
     mRemoteViews = getRemoteViews(context, minWidth, minHeight);
   }
   return mRemoteViews;
 }
 public static void updateNote(Context context) {
   AppWidgetManager manager = AppWidgetManager.getInstance(context);
   int[] ids = manager.getAppWidgetIds(new ComponentName(context, TimetableWidgetProvider.class));
   Intent intent = new Intent(context, TimetableWidgetProvider.class);
   intent.setAction(ACTION_UPDATE_NOTE);
   intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
   intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
   context.sendBroadcast(intent);
 }
 private void setRemotes(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
   for (int id : appWidgetIds) {
     RemoteViews remoteViews = getRemoteViews(context, id, TimetableUtils.todayDate());
     if (remoteViews != null) {
       appWidgetManager.updateAppWidget(id, remoteViews);
     }
   }
   appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.list_widget);
 }
Example #20
0
 void buildUpdate(Intent intent) {
   SharedPreferences sp =
       this.getSharedPreferences(ConfigActivity.WIDGET_PREF, Context.MODE_PRIVATE);
   AppWidgetManager widgetManager = AppWidgetManager.getInstance(this);
   int[] widgetIds = widgetManager.getAppWidgetIds(new ComponentName(this, MyWidget.class));
   for (int id : widgetIds) {
     new HTMLpageGetter(this, widgetManager, sp, id).execute();
   }
 }
 @Override
 public void onReceive(@NonNull Context context, @NonNull Intent intent) {
   super.onReceive(context, intent);
   if (MyFetchService.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);
   }
 }
  @Override
  protected void onHandleIntent(Intent intent) {

    // Retrieve all of the Today widget ids: these are the widgets we need to update
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
    int[] appWidgetIds =
        appWidgetManager.getAppWidgetIds(
            new ComponentName(this, FootbalScoresWidgetProvider.class));

    for (int appWidgetId : appWidgetIds) {
      RemoteViews views = new RemoteViews(this.getPackageName(), R.layout.widget_layout);

      Intent mainIntent = new Intent(this, MainActivity.class);
      PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, mainIntent, 0);
      views.setOnClickPendingIntent(R.id.widget, pendingIntent);

      Uri u = DatabaseContract.scores_table.buildScoreWithDate();
      Date today = new Date();
      SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
      String sToday = fmt.format(today);

      // sToday = "2015-11-08";
      // fmt = new SimpleDateFormat("dd");
      // sToday = fmt.format(today);
      // int nToday = Integer.parseInt(sToday) - 7;
      // sToday = "2015-11-07";

      Cursor c = this.getContentResolver().query(u, INFO, null, new String[] {sToday}, null);
      if (c.moveToFirst()) {
        hometeam = c.getString(c.getColumnIndex(DatabaseContract.scores_table.HOME_COL));
        awayTeam = c.getString(c.getColumnIndex(DatabaseContract.scores_table.AWAY_COL));
        homeGoals = c.getString(c.getColumnIndex(DatabaseContract.scores_table.HOME_GOALS_COL));
        awayGoals = c.getString(c.getColumnIndex(DatabaseContract.scores_table.AWAY_GOALS_COL));
        matchTime = c.getString(c.getColumnIndex(DatabaseContract.scores_table.TIME_COL));
        fmt = new SimpleDateFormat("EEE, MMM d");
        gameDetail = fmt.format(today);
        if (!homeGoals.equals("-1")) {
          gameDetail += this.getResources().getString(R.string.full_time);
          views.setTextViewText(R.id.home_side_score, homeGoals);
          views.setTextViewText(R.id.away_side_score, awayGoals);
        } else {
          gameDetail += " " + this.getResources().getString(R.string.at) + " " + matchTime;
        }

        views.setTextViewText(R.id.home_side, hometeam);
        views.setTextViewText(R.id.away_side, awayTeam);
        views.setTextViewText(R.id.match_time, gameDetail);

      } else {
        views.setTextViewText(R.id.home_side, this.getResources().getString(R.string.no_games));
      }
      c.close();

      appWidgetManager.updateAppWidget(appWidgetId, views);
    }
  }
 /**
  * Update all running widgets.
  *
  * @param context {@link Context}
  */
 public static void updateWidgets(final Context context) {
   Log.d(TAG, "updateWidgets()");
   final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
   final int[] appWidgetIds =
       appWidgetManager.getAppWidgetIds(new ComponentName(context, StatsAppWidgetProvider.class));
   final int count = appWidgetIds.length;
   for (int i = 0; i < count; i++) {
     updateWidget(context, appWidgetManager, appWidgetIds[i]);
   }
 }
 private void handleRefreshAction(Context context, Intent intent) {
   Bundle extras = intent.getExtras();
   if (extras != null) {
     int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
     if (appWidgetId != 1) {
       AppWidgetManager manager = AppWidgetManager.getInstance(context);
       manager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.listItems);
     }
   }
 }
  @Override
  protected void onHandleIntent(Intent intent) {
    if (intent != null && intent.getBooleanExtra(ACTION_DO_TOGGLE, false)) {
      RingerHelper.performToggle(audioManager);
    }

    AppWidgetManager mgr = AppWidgetManager.getInstance(this);
    ComponentName name = new ComponentName(this, AppWidget.class);
    mgr.updateAppWidget(name, updateUi());
  }
 private void updateAllSummaries(boolean working) {
   // Tell the AppWidgetManager to perform an update on the current app widget
   AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
   ComponentName thisWidget = new ComponentName(context, getClass());
   int[] ids = AppWidgetManager.getInstance(context).getAppWidgetIds(thisWidget);
   for (int id : ids) {
     RemoteViews views = getViewsForId(id, working);
     appWidgetManager.updateAppWidget(id, views);
   }
 }
    @Override
    public void onStart(Intent intent, int startId) {
      Log.i(AnkiDroidApp.TAG, "SmallWidget: OnStart");

      RemoteViews updateViews = buildUpdate(this, true);

      ComponentName thisWidget = new ComponentName(this, AnkiDroidWidgetSmall.class);
      AppWidgetManager manager = AppWidgetManager.getInstance(this);
      manager.updateAppWidget(thisWidget, updateViews);
    }
 @TargetApi(Build.VERSION_CODES.HONEYCOMB)
 private void updateWidgets() {
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
     AppWidgetManager widgetManager = AppWidgetManager.getInstance(mParent);
     widgetManager.notifyAppWidgetViewDataChanged(
         widgetManager.getAppWidgetIds(
             new ComponentName(mParent, TransactionsAppWidgetProvider.class)),
         R.id.widget_list);
   }
 }
Example #29
0
 @Override
 public void onHandleIntent(Intent intent) {
   ComponentName componentName = new ComponentName(this, AlarmWidget.class);
   AppWidgetManager alarmWidget = AppWidgetManager.getInstance(this);
   try {
     buildUpdate();
   } catch (NameNotFoundException e) {
   }
   alarmWidget.updateAppWidget(componentName, remoteViews);
 }
  @Override
  protected void onHandleIntent(Intent intent) {
    Intent service_start = new Intent(getApplicationContext(), myFetchService.class);
    getApplicationContext().startService(service_start);

    Cursor scores =
        getApplicationContext()
            .getContentResolver()
            .query(DatabaseContract.scores_table.buildScores(), null, null, null, null);

    scores.moveToFirst();
    String lastestHome = scores.getString(scoresAdapter.COL_HOME);
    String lastestAway = scores.getString(scoresAdapter.COL_AWAY);
    Integer lastestScoreHome = scores.getInt(scoresAdapter.COL_HOME_GOALS);
    Integer lastestScoreAway = scores.getInt(scoresAdapter.COL_AWAY_GOALS);
    String lastestMatchTime = scores.getString(scoresAdapter.COL_MATCHTIME);

    // Retrieve all of the Today widget ids: these are the widgets we need to update
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
    int[] appWidgetIds =
        appWidgetManager.getAppWidgetIds(new ComponentName(this, ScoreWidgetProvider.class));

    for (int appWidgetId : appWidgetIds) {
      int layoutId = R.layout.widget_score_small;
      RemoteViews views = new RemoteViews(getPackageName(), layoutId);

      // views.widget_home_name.setText(cursor.getString(COL_HOME));
      views.setTextViewText(R.id.widget_home_name, lastestHome);
      views.setTextViewText(R.id.widget_away_name, lastestAway);
      views.setTextViewText(R.id.widget_date_textview, lastestMatchTime);
      views.setTextViewText(
          R.id.widget_score_textview, Utilies.getScores(lastestScoreHome, lastestScoreAway));
      views.setImageViewResource(
          R.id.widget_home_crest, Utilies.getTeamCrestByTeamName(lastestHome));
      views.setImageViewResource(
          R.id.widget_away_crest, Utilies.getTeamCrestByTeamName(lastestAway));

      // Add the data to the RemoteViews
      // Content Descriptions for RemoteViews were only added in ICS MR1
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
        views.setContentDescription(
            R.id.widget_score_textview,
            "Score " + Utilies.getScores(lastestScoreHome, lastestScoreAway));
        views.setContentDescription(R.id.widget_date_textview, "Time " + lastestMatchTime);
      }

      // Create an Intent to launch MainActivity
      Intent launchIntent = new Intent(this, MainActivity.class);
      PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, launchIntent, 0);
      views.setOnClickPendingIntent(R.id.widget, pendingIntent);

      // Tell the AppWidgetManager to perform an update on the current app widget
      appWidgetManager.updateAppWidget(appWidgetId, views);
    }
  }