@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);
    }
  }
  @SuppressLint("NewApi")
  private void updateWidget(int appWidgetId) {
    NoteWidget noteWidget = getNoteWidgetForId(appWidgetId);
    if (noteWidget.width == 0 || noteWidget.height == 0) {
      updateNoteWidgetSize(appWidgetId);
    }

    LayoutParams lp = noteWidget.view.getLayoutParams();
    lp.width = noteWidget.width;
    lp.height = noteWidget.height;
    noteWidget.view.setLayoutParams(lp);

    String text = NoteStorage.getNote(this, appWidgetId);
    applyNoteViewAttrs(this, noteWidget.view, text);
    noteWidget.view.setTextColor(Color.WHITE);

    RemoteViews views = new RemoteViews(getPackageName(), R.layout.appwidget_note);
    Bitmap viewImage = getViewImage(noteWidget.view);
    views.setImageViewBitmap(R.id.appwidget_note, viewImage);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
      views.setContentDescription(R.id.appwidget_note, text);
    }

    Intent configIntent =
        new Intent(this, ConfigActivity.class)
            .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    views.setOnClickPendingIntent(
        R.id.appwidget_note, PendingIntent.getActivity(this, appWidgetId, configIntent, 0));

    getAppWidgetManager().updateAppWidget(appWidgetId, views);

    viewImage.recycle();
  }
 /** @see android.widget.RemoteViews#setContentDescription(int, CharSequence) */
 public static void setContentDescriptionForRemoteView(
     RemoteViews remoteViews, int viewId, CharSequence contentDescription) {
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
     remoteViews.setContentDescription(viewId, contentDescription);
   } else {
     // setContentDescription() is unavailable in earlier versions.
   }
 }
 @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
 private void setRemoteContentDescription(RemoteViews views, String description) {
   views.setContentDescription(R.id.widget, description);
 }
Example #5
0
 @Override
 public void setViewContentDescription(int viewId, String contentDescription) {
   mRemoteViews.setContentDescription(viewId, contentDescription);
 }
 private void setRemoteContentDescription(RemoteViews views, String description) {
   views.setContentDescription(R.id.widget_icon, description);
 }
  /** Update all active widget instances by pushing changes */
  public void performUpdate(final MusicPlaybackService service, final int[] appWidgetIds) {
    final RemoteViews appWidgetView =
        new RemoteViews(service.getPackageName(), R.layout.app_widget_large_alternate);

    final CharSequence trackName = service.getTrackName();
    final CharSequence artistName = service.getArtistName();
    final CharSequence albumName = service.getAlbumName();
    final Bitmap bitmap = service.getAlbumArt();

    // Set the titles and artwork
    appWidgetView.setTextViewText(R.id.app_widget_large_alternate_line_one, trackName);
    appWidgetView.setTextViewText(R.id.app_widget_large_alternate_line_two, artistName);
    appWidgetView.setTextViewText(R.id.app_widget_large_alternate_line_three, albumName);
    appWidgetView.setImageViewBitmap(R.id.app_widget_large_alternate_image, bitmap);

    // Set correct drawable for pause state
    final boolean isPlaying = service.isPlaying();
    if (isPlaying) {
      appWidgetView.setImageViewResource(
          R.id.app_widget_large_alternate_play, R.drawable.btn_playback_pause);
      if (ApolloUtils.hasJellyBean()) {
        appWidgetView.setContentDescription(
            R.id.app_widget_large_alternate_play, service.getString(R.string.accessibility_pause));
      }
    } else {
      appWidgetView.setImageViewResource(
          R.id.app_widget_large_alternate_play, R.drawable.btn_playback_play);
      if (ApolloUtils.hasJellyBean()) {
        appWidgetView.setContentDescription(
            R.id.app_widget_large_alternate_play, service.getString(R.string.accessibility_play));
      }
    }

    // Set the correct drawable for the repeat state
    switch (service.getRepeatMode()) {
      case MusicPlaybackService.REPEAT_ALL:
        appWidgetView.setImageViewResource(
            R.id.app_widget_large_alternate_repeat, R.drawable.btn_playback_repeat_all);
        break;
      case MusicPlaybackService.REPEAT_CURRENT:
        appWidgetView.setImageViewResource(
            R.id.app_widget_large_alternate_repeat, R.drawable.btn_playback_repeat_one);
        break;
      default:
        appWidgetView.setImageViewResource(
            R.id.app_widget_large_alternate_repeat, R.drawable.btn_playback_repeat);
        break;
    }

    // Set the correct drawable for the shuffle state
    switch (service.getShuffleMode()) {
      case MusicPlaybackService.SHUFFLE_NONE:
        appWidgetView.setImageViewResource(
            R.id.app_widget_large_alternate_shuffle, R.drawable.btn_playback_shuffle);
        break;
      case MusicPlaybackService.SHUFFLE_AUTO:
        appWidgetView.setImageViewResource(
            R.id.app_widget_large_alternate_shuffle, R.drawable.btn_playback_shuffle_all);
        break;
      default:
        appWidgetView.setImageViewResource(
            R.id.app_widget_large_alternate_shuffle, R.drawable.btn_playback_shuffle_all);
        break;
    }

    // Link actions buttons to intents
    linkButtons(service, appWidgetView, isPlaying);

    // Update the app-widget
    pushUpdate(service, appWidgetIds, appWidgetView);

    // Build the notification
    if (ApolloUtils.isApplicationSentToBackground(service)) {
      service.mBuildNotification = true;
    }
  }