Example usage for android.widget RemoteViews setContentDescription

List of usage examples for android.widget RemoteViews setContentDescription

Introduction

In this page you can find the example usage for android.widget RemoteViews setContentDescription.

Prototype

public void setContentDescription(int viewId, CharSequence contentDescription) 

Source Link

Document

Equivalent to calling View.setContentDescription(CharSequence).

Usage

From source file:Main.java

/**
 * @see android.widget.RemoteViews#setContentDescription(int, CharSequence)
 */// w  w  w.  j  av  a 2 s.co  m
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.
    }
}

From source file:barqsoft.footballscores.utils.Utility.java

/**
 * Set the content description on a remote view
 *
 * @param views       RemoteViews//from  www  .jav a  2 s  .c  o  m
 * @param viewId      int
 * @param description String
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
public static void setImageContentDescription(RemoteViews views, int viewId, String description) {
    views.setContentDescription(viewId, description);
}

From source file:android.support.v7.app.NotificationCompatImplBase.java

private static RemoteViews generateMediaActionButton(Context context, NotificationCompatBase.Action action) {
    final boolean tombstone = (action.getActionIntent() == null);
    RemoteViews button = new RemoteViews(context.getPackageName(), R.layout.notification_media_action);
    button.setImageViewResource(R.id.action0, action.getIcon());
    if (!tombstone) {
        button.setOnClickPendingIntent(R.id.action0, action.getActionIntent());
    }//  w w w.  ja va2s.  c o  m
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
        button.setContentDescription(R.id.action0, action.getTitle());
    }
    return button;
}

From source file:org.opensilk.fuzzyclock.FuzzyWidgetService.java

/**
 * Updates single appwidget, will schedule next update based on current logic
 * @param id//from   w  w w  .  j  ava2s .  c o  m
 */
@DebugLog
private void updateWidget(int id) {
    FuzzyPrefs settings = sWidgetSettings.get((Integer) id);
    if (settings == null) {
        return; // Once setup is done we will be called again.
    }
    if (LOGV)
        Log.v(TAG, "Updating widget id=" + id + " " + settings.toString());
    mFuzzyClock.loadPreferences(settings);
    mFuzzyClock.setDateFormat();
    mFuzzyClock.updateTime();
    Bitmap bitmap = mFuzzyClock.createBitmap();
    if (bitmap == null) {
        return;
    }
    // build onClick intent
    Intent intent = new Intent(mContext, FuzzyWidgetSettings.class);
    intent.setAction(String.format(Locale.US, "dummy_%d", id));
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
    PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    // send bitmap to remote view
    RemoteViews views = new RemoteViews(mContext.getPackageName(), R.layout.fuzzy_widget);
    views.setImageViewBitmap(R.id.fuzzy_clock_image, bitmap);
    views.setContentDescription(R.id.fuzzy_clock_image, mFuzzyClock.getContentDescription());
    views.setOnClickPendingIntent(R.id.fuzzy_clock_image, pi);
    mWidgetManager.updateAppWidget(id, views);
    scheduleUpdate(mFuzzyClock.getLogic().getCalendar().getTimeInMillis(),
            mFuzzyClock.getLogic().getNextIntervalMilli(), id);
}

From source file:org.chromium.chrome.browser.media.ui.NotificationMediaPlaybackControls.java

private void updateNotification() {
    if (mService == null)
        return;/*from  w w w .  ja v a  2 s .  co  m*/

    if (mMediaNotificationInfo == null) {
        // Notification was hidden before we could update it.
        assert mNotificationBuilder == null;
        return;
    }

    // Android doesn't badge the icons for RemoteViews automatically when
    // running the app under the Work profile.
    if (mNotificationIcon == null) {
        Drawable notificationIconDrawable = ApiCompatibilityUtils.getUserBadgedIcon(mContext,
                R.drawable.audio_playing);
        mNotificationIcon = drawableToBitmap(notificationIconDrawable);
    }

    if (mNotificationBuilder == null) {
        mNotificationBuilder = new NotificationCompat.Builder(mContext).setSmallIcon(R.drawable.audio_playing)
                .setAutoCancel(false).setLocalOnly(true)
                .setDeleteIntent(mService.getPendingIntent(ListenerService.ACTION_STOP));
    }
    mNotificationBuilder.setOngoing(!mMediaNotificationInfo.isPaused);
    mNotificationBuilder.setContentIntent(createContentIntent());

    RemoteViews contentView = createContentView();

    contentView.setTextViewText(R.id.title, mMediaNotificationInfo.title);
    contentView.setTextViewText(R.id.status, getStatus());
    if (mNotificationIcon != null) {
        contentView.setImageViewBitmap(R.id.icon, mNotificationIcon);
    } else {
        contentView.setImageViewResource(R.id.icon, R.drawable.audio_playing);
    }

    if (mMediaNotificationInfo.isPaused) {
        contentView.setImageViewResource(R.id.playpause, R.drawable.ic_vidcontrol_play);
        contentView.setContentDescription(R.id.playpause, mPlayDescription);
        contentView.setOnClickPendingIntent(R.id.playpause,
                mService.getPendingIntent(ListenerService.ACTION_PLAY));
    } else {
        contentView.setImageViewResource(R.id.playpause, R.drawable.ic_vidcontrol_pause);
        contentView.setContentDescription(R.id.playpause, mPauseDescription);
        contentView.setOnClickPendingIntent(R.id.playpause,
                mService.getPendingIntent(ListenerService.ACTION_PAUSE));
    }

    mNotificationBuilder.setContent(contentView);
    mNotificationBuilder.setVisibility(mMediaNotificationInfo.isPrivate ? NotificationCompat.VISIBILITY_PRIVATE
            : NotificationCompat.VISIBILITY_PUBLIC);

    if (mMediaSession == null) {
        mMediaSession = new MediaSessionCompat(mContext, mContext.getString(R.string.app_name),
                new ComponentName(mContext.getPackageName(), MediaButtonReceiver.class.getName()), null);
        mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
                | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
        mMediaSession.setCallback(mMediaSessionCallback);
        mMediaSession.setActive(true);
    }

    mMediaSession.setMetadata(createMetadata());

    PlaybackStateCompat.Builder playbackStateBuilder = new PlaybackStateCompat.Builder()
            .setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE);
    if (mMediaNotificationInfo.isPaused) {
        playbackStateBuilder.setState(PlaybackStateCompat.STATE_PAUSED,
                PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f);
    } else {
        playbackStateBuilder.setState(PlaybackStateCompat.STATE_PLAYING,
                PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f);
    }
    mMediaSession.setPlaybackState(playbackStateBuilder.build());

    Notification notification = mNotificationBuilder.build();

    // We keep the service as a foreground service while the media is playing. When it is not,
    // the service isn't stopped but is no longer in foreground, thus at a lower priority.
    // While the service is in foreground, the associated notification can't be swipped away.
    // Moving it back to background allows the user to remove the notification.
    if (mMediaNotificationInfo.isPaused) {
        mService.stopForeground(false /* removeNotification */);

        NotificationManagerCompat manager = NotificationManagerCompat.from(mContext);
        manager.notify(R.id.media_playback_notification, notification);
    } else {
        mService.startForeground(R.id.media_playback_notification, notification);
    }
}

From source file:com.fbartnitzek.tasteemall.widget.StatsWidgetIntentService.java

@Override
protected void onHandleIntent(Intent intent) {

    //        Log.v(LOG_TAG, "onHandleIntent, hashCode=" + this.hashCode() + ", " + "intent = [" + intent + "]");

    // get all widget ids
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(this, StatsWidgetProvider.class));

    // query all entities
    int numLocations = queryAndGetCount(DatabaseContract.LocationEntry.CONTENT_URI,
            QueryColumns.Widget.LocationQuery.COLUMNS);
    int numProducers = queryAndGetCount(DatabaseContract.ProducerEntry.CONTENT_URI,
            QueryColumns.Widget.ProviderQuery.COLUMNS);
    int numDrinks = queryAndGetCount(DatabaseContract.DrinkEntry.CONTENT_URI,
            QueryColumns.Widget.DrinkQuery.COLUMNS);
    int numUsers = queryAndGetCount(DatabaseContract.UserEntry.CONTENT_URI,
            QueryColumns.Widget.UserQuery.COLUMNS);
    int numReviews = queryAndGetCount(DatabaseContract.ReviewEntry.CONTENT_URI,
            QueryColumns.Widget.ReviewQuery.COLUMNS);

    // TODO: results are getting "cached" or something like that ...
    // maybe that helps: http://stackoverflow.com/questions/9497270/widget-with-content-provider-impossible-to-use-readpermission
    Log.v(LOG_TAG,//from  w  ww .ja  v  a 2  s.  co  m
            "onHandleIntent, producer=" + numProducers + ", drinks=" + numDrinks + ", reviews=" + numReviews);

    for (int appWidgetId : appWidgetIds) {
        // dynamically adapt widget width ... later

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

        // fill stats
        views.setTextViewText(R.id.stats_locations,
                getString(R.string.widget_statistics_locations, numLocations));

        views.setTextViewText(R.id.stats_producers,
                getString(R.string.widget_statistics_producers, numProducers));

        views.setTextViewText(R.id.stats_drinks, getString(R.string.widget_statistics_drinks, numDrinks));

        views.setTextViewText(R.id.stats_users, getString(R.string.widget_statistics_users, numUsers));

        views.setTextViewText(R.id.stats_reviews, getString(R.string.widget_statistics_reviews, numReviews));

        // seems to be impossible to get contentDescription for whole widget...
        //            views.setContentDescription(R.id.widget_layout,
        //                    getString(R.string.a11y_widget_statistics_all, numProducers, numDrinks, numReviews));

        views.setContentDescription(R.id.stats_reviews,
                getString(R.string.a11y_widget_statistics_all, numProducers, numDrinks, numReviews));

        // set on click listener for add and search on every update (kind of useless...)

        // add button - create backStack for add
        Intent addIntent = new Intent(this, AddReviewActivity.class);
        PendingIntent addPendingIntent = TaskStackBuilder.create(this).addNextIntentWithParentStack(addIntent)
                .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        views.setOnClickPendingIntent(R.id.widget_add_button, addPendingIntent);

        // search button
        PendingIntent searchPendingIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, MainActivity.class), 0);
        views.setOnClickPendingIntent(R.id.widget_search_button, searchPendingIntent);

        // update each StatsWidget
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}