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

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

      Bundle extras = intent.getExtras();

      if (extras != null) {

        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        ComponentName thisAppWidget =
            new ComponentName(context.getPackageName(), VerboseClockWidget.class.getName());
        int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget);

        onUpdate(context, appWidgetManager, appWidgetIds);
      }

    } else {
      Bundle extras = intent.getExtras();

      if (extras != null) {

        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        ComponentName thisAppWidget =
            new ComponentName(context.getPackageName(), VerboseClockWidget.class.getName());
        int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget);

        onUpdate(context, appWidgetManager, appWidgetIds);
      }
    }
  }
  @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    ComponentName thisWidget = new ComponentName(context, Widget4x4Provider.class);
    this.appWidgetIds = appWidgetIds;

    /*
    Set up the intent that starts the LargeWidgetService, which will
    provide the views for this collection.
    */
    Intent serviceIntent = new Intent(context, LargeWidgetService.class);

    // ---Add this app widget to the intent extras---
    serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, thisWidget);
    serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME)));

    /*
    This adapter connects to a RemoteViewsService through the specified intent.
    This is how you populate the data.
    */
    remoteView =
        new RemoteViews(
            context.getPackageName(), com.eazyigz.RussiaMediaSearch.R.layout.appwidget_4x4);
    //        remoteView.setRemoteAdapter(R.id.listViewWidget, serviceIntent);
    for (int i = 0; i < appWidgetManager.getAppWidgetIds(thisWidget).length; ++i) {
      remoteView.setRemoteAdapter(
          appWidgetManager.getAppWidgetIds(thisWidget)[i], R.id.listViewWidget, serviceIntent);
    }
    remoteView.setEmptyView(R.id.listViewWidget, R.id.row_empty_label_widget);

    final Intent onClickIntent = new Intent(context, Widget4x4Provider.class);
    onClickIntent.setAction(Widget4x4Provider._listClickAction);
    onClickIntent.setData(Uri.parse(onClickIntent.toUri(Intent.URI_INTENT_SCHEME)));
    final PendingIntent listClickPendingIntent =
        PendingIntent.getBroadcast(context, 0, onClickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
      remoteView.setPendingIntentTemplate(R.id.listViewWidget, listClickPendingIntent);

    setupLauncherShortcut(context, remoteView);
    setupRussianVoiceSearch(context, remoteView);
    setupEnglishVoiceSearch(context, remoteView);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
      appWidgetManager.notifyAppWidgetViewDataChanged(
          appWidgetManager.getAppWidgetIds(thisWidget), R.id.listViewWidget);
    appWidgetManager.updateAppWidget(thisWidget, remoteView);

    super.onUpdate(context, appWidgetManager, appWidgetManager.getAppWidgetIds(thisWidget));
  }
Exemplo n.º 3
0
  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);
    }
  }
Exemplo n.º 4
0
  @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);
    }
  }
  @Override
  public void onUpdate(
      final Context context, final AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    Log.d("TAG", "onUpdate");
    ComponentName thisWidget = new ComponentName(context, WeatherWidgetProvider.class);
    final int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
    WidgetManager widgetManager = new WidgetManager(context);
    widgetManager
        .fetchWeatherDataForWidget()
        .subscribeOn(Schedulers.newThread())
        .subscribe(
            new Subscriber<CityWeather>() {
              @Override
              public void onCompleted() {}

              @Override
              public void onError(Throwable e) {}

              @Override
              public void onNext(CityWeather cityWeather) {
                updateWeatherData(context, appWidgetManager, allWidgetIds, cityWeather);
              }
            });

    super.onUpdate(context, appWidgetManager, appWidgetIds);
  }
  @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);
  }
Exemplo n.º 7
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);
 }
Exemplo n.º 8
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)));
 }
 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);
 }
 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);
 }
 @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);
   }
 }
Exemplo n.º 12
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();
   }
 }
Exemplo n.º 13
0
  @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);
    }
  }
 @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);
   }
 }
Exemplo n.º 15
0
  public static void updateWidgets(Context context) {
    AppWidgetManager widgetManager = AppWidgetManager.getInstance(context);

    int[] widgetIds;

    widgetIds =
        widgetManager.getAppWidgetIds(new ComponentName(context, LargeWidgetProvider.class));
    if (widgetIds.length > 0) {
      AppWidgetProvider provider = (AppWidgetProvider) new LargeWidgetProvider();
      provider.onUpdate(context, widgetManager, widgetIds);
    }

    widgetIds =
        widgetManager.getAppWidgetIds(new ComponentName(context, SmallWidgetProvider.class));
    if (widgetIds.length > 0) {
      AppWidgetProvider provider = (AppWidgetProvider) new SmallWidgetProvider();
      provider.onUpdate(context, widgetManager, widgetIds);
    }
  }
 /**
  * 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]);
   }
 }
Exemplo n.º 17
0
  @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);
    }
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);

    if (intent.getAction().equals(ACTION_DATA_UPDATED)) {
      Log.d(TAG, "Received intent to update");
      AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
      int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, getClass()));
      appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.widget_list);
    }
  }
  private void update(Context context) {
    Log.d("component class", "name = " + this.getClass().getName());
    ComponentName widget = new ComponentName(context, this.getClass());
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(widget);

    for (int widgetId : appWidgetIds) {
      RemoteViews views = updateRemoteViews(context, widgetId);
      appWidgetManager.updateAppWidget(widgetId, views);
    }
  }
  @Override
  protected void onHandleIntent(Intent intent) {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
    int[] appWidgetIds =
        appWidgetManager.getAppWidgetIds(new ComponentName(this, ScoresWidgetProvider.class));

    getLatest(this);

    for (int appWidgetId : appWidgetIds) {
      updateWidget(this, appWidgetManager, appWidgetId);
    }
  }
Exemplo n.º 21
0
 @Override
 public void onReceive(Context context, Intent intent) { //
   super.onReceive(context, intent);
   if (intent.getAction().equals("startup.nsn.yamba.NEW_STATUS")) { //
     Log.d(TAG, "onReceived detected new status update");
     AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); //
     this.onUpdate(
         context,
         appWidgetManager,
         appWidgetManager.getAppWidgetIds(new ComponentName(context, YambaWidget.class))); //
   }
 }
Exemplo n.º 22
0
 private void handleError(Context mContext) {
   AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext);
   RemoteViews views = new RemoteViews(mContext.getPackageName(), R.layout.analog_widget);
   int[] appWidgetIds =
       appWidgetManager.getAppWidgetIds(new ComponentName(mContext, AnalogWidget.class));
   views.setTextViewText(R.id.appwidget_text, "Error");
   views.setOnClickPendingIntent(R.id.appwidget_text, getPendingSelfIntent(mContext));
   // Instruct the widget manager to update the widget
   for (int appWidgetId : appWidgetIds) {
     appWidgetManager.updateAppWidget(appWidgetId, views);
   }
 }
Exemplo n.º 23
0
  public static void notifyThemeChanged(Context context) {
    if (context != null) {
      AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
      int[] appWidgetIds =
          appWidgetManager.getAppWidgetIds(new ComponentName(context, WidgetProvider.class));

      for (int appWidgetId : appWidgetIds) {
        updateWidget(context, appWidgetId);
      }
    }

    notifyDatasetChanged(context);
  }
Exemplo n.º 24
0
  /**
   * Trigger update for all of our unread widgets.
   *
   * @param context The {@code Context} object to use for the broadcast intent.
   */
  public static void updateUnreadCount(Context context) {
    Context appContext = context.getApplicationContext();
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(appContext);

    ComponentName thisWidget = new ComponentName(appContext, UnreadWidgetProvider.class);
    int[] widgetIds = appWidgetManager.getAppWidgetIds(thisWidget);

    Intent intent = new Intent(context, UnreadWidgetProvider.class);
    intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds);

    context.sendBroadcast(intent);
  }
  private void refreshWidgets() {
    // Obtain all app widget IDs.
    Context context = getApplicationContext();
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    ComponentName cn = new ComponentName(context, CalendarWidgetProvider.class);
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(cn);

    if (appWidgetIds != null && appWidgetIds.length != 0) {
      // Broadcast update action to all running app widgets.
      Intent intent = new Intent(context, CalendarWidgetProvider.class);
      intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
      intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
      context.sendBroadcast(intent);
    }
  }
Exemplo n.º 26
0
  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

    Log.w(LOG, "onUpdate method called");
    // Get all ids
    ComponentName thisWidget = new ComponentName(context, MyWidgetProvider.class);
    int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);

    // Build the intent to call the service
    Intent intent = new Intent(context.getApplicationContext(), UpdateWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, allWidgetIds);

    // Update the widgets via the service
    context.startService(intent);
  }
Exemplo n.º 27
0
        @Override
        public void handleMessage(Message msg) {
          Editor ed = settings.edit();
          switch (msg.what) {
            case MSG_CONNECT_START:
              ed.putBoolean("isConnecting", true);
              break;
            case MSG_CONNECT_FINISH:
              ed.putBoolean("isConnecting", false);
              ed.putBoolean("isSwitching", false);
              break;
            case MSG_CONNECT_SUCCESS:
              ed.putBoolean("isRunning", true);
              // stateChanged = new ConnectivityBroadcastReceiver();
              // registerReceiver(stateChanged, new IntentFilter(
              // ConnectivityManager.CONNECTIVITY_ACTION));
              break;
            case MSG_CONNECT_FAIL:
              ed.putBoolean("isRunning", false);
              break;
            case MSG_DISCONNECT_FINISH:
              ed.putBoolean("isRunning", false);
              ed.putBoolean("isSwitching", false);

              try {
                notificationManager.cancel(0);
                notificationManager.cancel(1);
              } catch (Exception ignore) {
                // Nothing
              }

              // for widget, maybe exception here
              try {
                RemoteViews views = new RemoteViews(getPackageName(), R.layout.sshtunnel_appwidget);
                views.setImageViewResource(R.id.serviceToggle, R.drawable.off);
                AppWidgetManager awm = AppWidgetManager.getInstance(SSHTunnelService.this);
                awm.updateAppWidget(
                    awm.getAppWidgetIds(
                        new ComponentName(SSHTunnelService.this, SSHTunnelWidgetProvider.class)),
                    views);
              } catch (Exception ignore) {
                // Nothing
              }
              break;
          }
          ed.commit();
          super.handleMessage(msg);
        }
  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    ComponentName thisWidget = new ComponentName(context, ToggleLocationWidgetProvider.class);
    int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);

    Intent changeLocationProvidersServiceIntent =
        new Intent(context.getApplicationContext(), ChangeLocationProvidersStateService.class);
    changeLocationProvidersServiceIntent.putExtra(
        AppWidgetManager.EXTRA_APPWIDGET_IDS, allWidgetIds);
    changeLocationProvidersServiceIntent.putExtra(
        AppWidgetManager.EXTRA_CUSTOM_EXTRAS, isFirstOnUpdateCall);

    context.startService(changeLocationProvidersServiceIntent);

    isFirstOnUpdateCall = false;
  }
Exemplo n.º 29
0
  @Override
  protected void onHandleIntent(Intent intent) {
    Log.i(LOG, "Called");
    AppWidgetManager mgr = AppWidgetManager.getInstance(getApplicationContext());
    int[] widgetIds =
        mgr.getAppWidgetIds(new ComponentName(getApplicationContext(), CamWidgetProvider.class));

    for (int widgetId : widgetIds) {
      Log.i(LOG, "Updating widget id " + widgetId);
      refreshText(mgr, widgetId);

      SharedPreferences prefs =
          getApplicationContext()
              .getSharedPreferences(CamWidgetConfigure.PREFS_NAME, Context.MODE_PRIVATE);

      List<String> cameraSet =
          split(prefs.getString(CamWidgetConfigure.CAMERA_SET + "_" + widgetId, ""));
      List<String> temps = new ArrayList<String>();
      for (String camId : cameraSet) {
        int retries = 3;
        String temp = null;
        for (int i = 0; i < retries && temp == null; i++) {
          temp = tempFromCamera(Integer.valueOf(camId));
        }
        temps.add(temp);
      }
      StringBuilder result = new StringBuilder();
      for (String temp : temps) {
        if (temp == null) {
          result.append("?");
        } else {
          result.append(temp);
        }
        result.append("\n");
      }
      if (result.length() > 0) {
        result.delete(result.length() - 1, result.length());
      }
      RemoteViews remoteViews =
          new RemoteViews(getApplicationContext().getPackageName(), R.layout.appwidget);
      remoteViews.setTextViewText(R.id.text, result.toString());
      remoteViews.setViewVisibility(R.id.text, View.VISIBLE);
      remoteViews.setViewVisibility(R.id.progress, View.INVISIBLE);
      mgr.updateAppWidget(widgetId, remoteViews);
    }
  }
  @Override
  public void onReceive(android.content.Context context, Intent intent) {
    super.onReceive(context, intent);

    String action = intent.getAction();
    if (TaskProvider.cUpdateIntent.equals(action)
        || ProjectProvider.cUpdateIntent.equals(action)
        || ContextProvider.cUpdateIntent.equals(action)) {
      AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
      // Retrieve the identifiers for each instance of your chosen widget.
      ComponentName thisWidget = new ComponentName(context, WidgetProvider.class);
      int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
      if (appWidgetIds != null && appWidgetIds.length > 0) {
        this.onUpdate(context, appWidgetManager, appWidgetIds);
      }
    }
  }