Java Code Examples for android.widget.RemoteViews#setContentDescription()

The following examples show how to use android.widget.RemoteViews#setContentDescription() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SunPosLayout.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
protected void updateViewsAzimuthElevationText(Context context, @NonNull RemoteViews views, @Nullable SuntimesCalculator.SunPosition sunPosition, @Nullable SuntimesCalculator.SunPosition noonPosition)
{
    if (sunPosition != null)
    {
        SuntimesUtils.TimeDisplayText azimuthDisplay = utils.formatAsDirection2(sunPosition.azimuth, DECIMAL_PLACES, false);
        views.setTextViewText(R.id.info_sun_azimuth_current, styleAzimuthText(azimuthDisplay, highlightColor, suffixColor, boldTime));

        if (Build.VERSION.SDK_INT >= 15) {
            SuntimesUtils.TimeDisplayText azimuthDescription = utils.formatAsDirection2(sunPosition.azimuth, DECIMAL_PLACES, true);
            views.setContentDescription(R.id.info_sun_azimuth_current, utils.formatAsDirection(azimuthDescription.getValue(), azimuthDescription.getSuffix()));
        }

        int elevationColor = (sunPosition.elevation <= 0 ? highlightColor :
                (SuntimesRiseSetDataset.isRising(sunPosition, noonPosition) ? risingColor : settingColor));
        views.setTextViewText(R.id.info_sun_elevation_current, styleElevationText(sunPosition.elevation, elevationColor, suffixColor, boldTime));
    }
}
 
Example 2
Source File: ImageTransformation.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** @hide */
@TestApi
@Override
public void apply(@NonNull ValueFinder finder, @NonNull RemoteViews parentTemplate,
        int childViewId) throws Exception {
    final String value = finder.findByAutofillId(mId);
    if (value == null) {
        Log.w(TAG, "No view for id " + mId);
        return;
    }
    final int size = mOptions.size();
    if (sDebug) {
        Log.d(TAG, size + " multiple options on id " + childViewId + " to compare against");
    }

    for (int i = 0; i < size; i++) {
        final Option option = mOptions.get(i);
        try {
            if (option.pattern.matcher(value).matches()) {
                Log.d(TAG, "Found match at " + i + ": " + option);
                parentTemplate.setImageViewResource(childViewId, option.resId);
                if (option.contentDescription != null) {
                    parentTemplate.setContentDescription(childViewId,
                            option.contentDescription);
                }
                return;
            }
        } catch (Exception e) {
            // Do not log full exception to avoid PII leaking
            Log.w(TAG, "Error matching regex #" + i + "(" + option.pattern + ") on id "
                    + option.resId + ": " + e.getClass());
            throw e;

        }
    }
    if (sDebug) Log.d(TAG, "No match for " + value);
}
 
Example 3
Source File: AppWidget11.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
/**
 * Update all active widget instances by pushing changes
 */
public void performUpdate(ApolloService service, int[] appWidgetIds) {
    final RemoteViews views = new RemoteViews(service.getPackageName(),
            R.layout.music_onebyone_app_widget);

    // Set album art
    Bitmap bitmap = service.getAlbumBitmap();
    if (bitmap != null) {
        views.setViewVisibility(R.id.one_by_one_albumart, View.VISIBLE);
        views.setImageViewBitmap(R.id.one_by_one_albumart, bitmap);
    } else {
        views.setViewVisibility(R.id.one_by_one_albumart, View.INVISIBLE);
    }
    // Set correct contentDescription
    final boolean playing = service.isPlaying();
    if (playing) {
        views.setContentDescription(R.id.one_by_one_albumart,
            service.getResources().getString(R.string.nowplaying));
    } else {
        views.setContentDescription(R.id.one_by_one_albumart,
            service.getResources().getString(R.string.app_name));
    }

    // Link actions buttons to intents
    linkButtons(service, views, playing);

    pushUpdate(service, appWidgetIds, views);
}
 
Example 4
Source File: MoonLayout_1x1_5.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
protected void updateViewsAzimuthElevationText(Context context, RemoteViews views, SuntimesCalculator.MoonPosition moonPosition)
{
    SuntimesUtils.TimeDisplayText azimuthDisplay = utils.formatAsDirection2(moonPosition.azimuth, PositionLayout.DECIMAL_PLACES, false);
    views.setTextViewText(R.id.info_moon_azimuth_current, PositionLayout.styleAzimuthText(azimuthDisplay, highlightColor, suffixColor, boldTime));

    if (Build.VERSION.SDK_INT >= 15) {
        SuntimesUtils.TimeDisplayText azimuthDescription = utils.formatAsDirection2(moonPosition.azimuth, PositionLayout.DECIMAL_PLACES, true);
        views.setContentDescription(R.id.info_moon_azimuth_current, utils.formatAsDirection(azimuthDescription.getValue(), azimuthDescription.getSuffix()));
    }
    views.setTextViewText(R.id.info_moon_elevation_current, PositionLayout.styleElevationText(moonPosition.elevation, highlightColor, suffixColor, boldTime));
}
 
Example 5
Source File: SunPosLayout.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
protected void updateViewsAzimuthElevationText(Context context, @NonNull RemoteViews views, @Nullable SuntimesCalculator.SunPosition sunPosition, @Nullable SuntimesCalculator.SunPosition risingPosition, @Nullable SuntimesCalculator.SunPosition noonPosition, @Nullable SuntimesCalculator.SunPosition settingPosition)
{
    if (risingPosition != null)
    {
        SuntimesUtils.TimeDisplayText azimuthRising = utils.formatAsDirection2(risingPosition.azimuth, DECIMAL_PLACES, false);
        views.setTextViewText(R.id.info_sun_azimuth_rising, styleAzimuthText(azimuthRising, risingColor, suffixColor, boldTime));

        if (Build.VERSION.SDK_INT >= 15) {
            SuntimesUtils.TimeDisplayText azimuthRisingDesc = utils.formatAsDirection2(risingPosition.azimuth, DECIMAL_PLACES, true);
            views.setContentDescription(R.id.info_sun_azimuth_rising, utils.formatAsDirection(azimuthRisingDesc.getValue(), azimuthRisingDesc.getSuffix()));
        }
    }

    if (noonPosition != null) {
        views.setTextViewText(R.id.info_sun_elevation_atnoon, styleElevationText(noonPosition.elevation, settingColor, suffixColor, boldTime));
    }

    if (settingPosition != null)
    {
        SuntimesUtils.TimeDisplayText azimuthSetting = utils.formatAsDirection2(settingPosition.azimuth, DECIMAL_PLACES, false);
        views.setTextViewText(R.id.info_sun_azimuth_setting, styleAzimuthText(azimuthSetting, settingColor, suffixColor, boldTime));

        if (Build.VERSION.SDK_INT >= 15) {
            SuntimesUtils.TimeDisplayText azimuthSettingDesc = utils.formatAsDirection2(settingPosition.azimuth, DECIMAL_PLACES, true);
            views.setContentDescription(R.id.info_sun_azimuth_setting, utils.formatAsDirection(azimuthSettingDesc.getValue(), azimuthSettingDesc.getSuffix()));
        }
    }
}
 
Example 6
Source File: SunPosLayout_3X1_0.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updateViews(Context context, int appWidgetId, RemoteViews views, SuntimesRiseSetDataset dataset)
{
    super.updateViews(context, appWidgetId, views, dataset);
    Calendar now = dataset.now();
    SuntimesCalculator calculator = dataset.calculator();
    SuntimesCalculator.SunPosition sunPosition = (calculator != null ? calculator.getSunPosition(now) : null);

    SuntimesRiseSetData riseSetData = dataset.dataActual;
    Calendar riseTime = (riseSetData != null ? riseSetData.sunriseCalendarToday() : null);
    SuntimesCalculator.SunPosition risingPosition = (riseTime != null && calculator != null ? calculator.getSunPosition(riseTime) : null);

    SuntimesRiseSetData noonData = dataset.dataNoon;
    Calendar noonTime = (noonData != null ? noonData.sunriseCalendarToday() : null);
    SuntimesCalculator.SunPosition noonPosition = (noonTime != null && calculator != null ? calculator.getSunPosition(noonTime) : null);

    Calendar setTime = (riseSetData != null ? riseSetData.sunsetCalendarToday() : null);
    SuntimesCalculator.SunPosition settingPosition = (setTime != null && calculator != null ? calculator.getSunPosition(setTime) : null);

    updateViewsAzimuthElevationText(context, views, sunPosition, noonPosition);
    updateViewsAzimuthElevationText(context, views, sunPosition, risingPosition, noonPosition, settingPosition);

    boolean showLabels = WidgetSettings.loadShowLabelsPref(context, appWidgetId);
    int visibility = (showLabels ? View.VISIBLE : View.GONE);
    views.setViewVisibility(R.id.info_time_lightmap_labels, visibility);

    LightMapView.LightMapTask drawTask = new LightMapView.LightMapTask();
    Bitmap bitmap = drawTask.makeBitmap(dataset, SuntimesUtils.dpToPixels(context, dpWidth), SuntimesUtils.dpToPixels(context, dpHeight), colors);
    views.setImageViewBitmap(R.id.info_time_lightmap, bitmap);

    if (Build.VERSION.SDK_INT >= 15) {
        views.setContentDescription(R.id.info_time_lightmap, buildContentDescription(context, now, sunPosition));
    }
}
 
Example 7
Source File: MediaNotificationManager.java    From delion with Apache License 2.0 4 votes vote down vote up
private RemoteViews createContentView() {
    RemoteViews contentView =
            new RemoteViews(mContext.getPackageName(), R.layout.playback_notification_bar);

    // By default, play/pause button is the only one.
    int playPauseButtonId = R.id.button1;
    // On Android pre-L, dismissing the notification when the service is no longer in foreground
    // doesn't work. Instead, a STOP button is shown.
    if (mMediaNotificationInfo.supportsSwipeAway()
                    && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP
            || mMediaNotificationInfo.supportsStop()) {
        contentView.setOnClickPendingIntent(
                R.id.button1, createPendingIntent(ListenerService.ACTION_STOP));
        contentView.setContentDescription(R.id.button1, mStopDescription);

        // If the play/pause needs to be shown, it moves over to the second button from the end.
        playPauseButtonId = R.id.button2;
    }

    contentView.setTextViewText(R.id.title, mMediaNotificationInfo.metadata.getTitle());
    contentView.setTextViewText(R.id.status, mMediaNotificationInfo.origin);

    // 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, mMediaNotificationInfo.icon);
        mNotificationIcon = drawableToBitmap(notificationIconDrawable);
    }

    if (mNotificationIcon != null) {
        contentView.setImageViewBitmap(R.id.icon, mNotificationIcon);
    } else {
        contentView.setImageViewResource(R.id.icon, mMediaNotificationInfo.icon);
    }

    if (mMediaNotificationInfo.supportsPlayPause()) {
        if (mMediaNotificationInfo.isPaused) {
            contentView.setImageViewResource(playPauseButtonId, R.drawable.ic_vidcontrol_play);
            contentView.setContentDescription(playPauseButtonId, mPlayDescription);
            contentView.setOnClickPendingIntent(
                    playPauseButtonId, createPendingIntent(ListenerService.ACTION_PLAY));
        } else {
            // If we're here, the notification supports play/pause button and is playing.
            contentView.setImageViewResource(playPauseButtonId, R.drawable.ic_vidcontrol_pause);
            contentView.setContentDescription(playPauseButtonId, mPauseDescription);
            contentView.setOnClickPendingIntent(
                    playPauseButtonId, createPendingIntent(ListenerService.ACTION_PAUSE));
        }

        contentView.setViewVisibility(playPauseButtonId, View.VISIBLE);
    } else {
        contentView.setViewVisibility(playPauseButtonId, View.GONE);
    }

    return contentView;
}
 
Example 8
Source File: AppWidget42.java    From mobile-manager-tool with MIT License 4 votes vote down vote up
/**
 * Update all active widget instances by pushing changes
 */
public void performUpdate(ApolloService service, int[] appWidgetIds) {
	
	Context mContext = service.getApplicationContext();
	SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
	String widget_type = sp.getString( WIDGET_STYLE, mContext.getResources().getString(R.string.widget_style_light) );

	final RemoteViews views = new RemoteViews(mContext.getPackageName(),
            (widget_type.equals(mContext.getResources().getString(R.string.widget_style_light))?R.layout.music_fourbytwo_app_widget :R.layout.music_fourbytwo_app_widget_dark));
    
    CharSequence artistName = service.getArtistName();
    CharSequence albumName = service.getAlbumName();
    CharSequence trackName = service.getTrackName();
    views.setTextViewText(R.id.four_by_two_artistname, artistName);
    views.setTextViewText(R.id.four_by_two_albumname, albumName);
    views.setTextViewText(R.id.four_by_two_trackname, trackName);

    // Set album art
    Bitmap bitmap = service.getAlbumBitmap();
    if (bitmap != null) {
        views.setViewVisibility(R.id.four_by_two_albumart, View.VISIBLE);
        views.setImageViewBitmap(R.id.four_by_two_albumart, bitmap);
    } else {
        views.setViewVisibility(R.id.four_by_two_albumart, View.GONE);
    }

    // Set correct drawable and contentDescription for pause state
    final boolean playing = service.isPlaying();
    if (playing) {
        views.setImageViewResource(R.id.four_by_two_control_play,
        		 (widget_type.equals(mContext.getResources().getString(R.string.widget_style_light))?R.drawable.apollo_holo_light_pause:R.drawable.apollo_holo_dark_pause));
        views.setContentDescription(R.id.four_by_two_albumart,
            service.getResources().getString(R.string.nowplaying));
    } else {
        views.setImageViewResource(R.id.four_by_two_control_play,
        		(widget_type.equals(mContext.getResources().getString(R.string.widget_style_light))?R.drawable.apollo_holo_light_play:R.drawable.apollo_holo_dark_play));
        views.setContentDescription(R.id.four_by_two_albumart,
            service.getResources().getString(R.string.app_name));
    }

    // Set correct drawable for repeat state
    switch (service.getRepeatMode()) {
        case ApolloService.REPEAT_ALL:
            views.setImageViewResource(R.id.four_by_two_control_repeat,
                    R.drawable.apollo_holo_light_repeat_all);
            break;
        case ApolloService.REPEAT_CURRENT:
            views.setImageViewResource(R.id.four_by_two_control_repeat,
                    R.drawable.apollo_holo_light_repeat_one);
            break;
        default:
            views.setImageViewResource(R.id.four_by_two_control_repeat,
            		(widget_type.equals(mContext.getResources().getString(R.string.widget_style_light))?R.drawable.apollo_holo_light_repeat_normal:R.drawable.apollo_holo_dark_repeat_normal));
            break;
    }

    // Set correct drawable for shuffle state
    switch (service.getShuffleMode()) {
        case ApolloService.SHUFFLE_NONE:
            views.setImageViewResource(R.id.four_by_two_control_shuffle,
            		(widget_type.equals(mContext.getResources().getString(R.string.widget_style_light))?R.drawable.apollo_holo_light_shuffle_normal:R.drawable.apollo_holo_dark_shuffle_normal));
            break;
        case ApolloService.SHUFFLE_AUTO:
            views.setImageViewResource(R.id.four_by_two_control_shuffle,
                    R.drawable.apollo_holo_light_shuffle_on);
            break;
        default:
            views.setImageViewResource(R.id.four_by_two_control_shuffle,
                    R.drawable.apollo_holo_light_shuffle_on);
            break;
    }
    // Link actions buttons to intents
    linkButtons(service, views, playing);

    pushUpdate(service, appWidgetIds, views);

}
 
Example 9
Source File: AppWidget41.java    From mobile-manager-tool with MIT License 4 votes vote down vote up
/**
 * Update all active widget instances by pushing changes
 */
public void performUpdate(ApolloService service, int[] appWidgetIds) {

	Context mContext = service.getApplicationContext();
	SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
	String widget_type = sp.getString( WIDGET_STYLE, mContext.getResources().getString(R.string.widget_style_light) );

	final RemoteViews views = new RemoteViews(mContext.getPackageName(),
            (widget_type.equals(mContext.getResources().getString(R.string.widget_style_light))?R.layout.music_fourbyone_app_widget :R.layout.music_fourbyone_app_widget_dark));
    

    CharSequence titleName = service.getTrackName();
    CharSequence artistName = service.getArtistName();

    views.setTextViewText(R.id.four_by_one_title, titleName);
    views.setTextViewText(R.id.four_by_one_artist, artistName);
    // Set album art
    Bitmap bitmap = service.getAlbumBitmap();
    if (bitmap != null) {
        views.setViewVisibility(R.id.four_by_one_albumart, View.VISIBLE);
        views.setViewVisibility(R.id.four_by_one_control_prev, View.GONE);
        views.setImageViewBitmap(R.id.four_by_one_albumart, bitmap);
    } else {
        views.setViewVisibility(R.id.four_by_one_control_prev, View.VISIBLE);
        views.setViewVisibility(R.id.four_by_one_albumart, View.GONE);
    }

    // Set correct drawable and contentDescription for pause state
    final boolean playing = service.isPlaying();
    if (playing) {
        views.setImageViewResource(R.id.four_by_one_control_play,
        		(widget_type.equals(mContext.getResources().getString(R.string.widget_style_light))?R.drawable.apollo_holo_light_pause:R.drawable.apollo_holo_dark_pause));
        views.setContentDescription(R.id.four_by_one_albumart,
            service.getResources().getString(R.string.nowplaying));
    } else {
        views.setImageViewResource(R.id.four_by_one_control_play,
        		(widget_type.equals(mContext.getResources().getString(R.string.widget_style_light))?R.drawable.apollo_holo_light_play:R.drawable.apollo_holo_dark_play));
        views.setContentDescription(R.id.four_by_one_albumart,
            service.getResources().getString(R.string.app_name));
    }

    // Link actions buttons to intents
    linkButtons(service, views, playing);

    pushUpdate(service, appWidgetIds, views);
}
 
Example 10
Source File: TodayWidgetIntentService.java    From Advanced_Android_Development with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
private void setRemoteContentDescription(RemoteViews views, String description) {
    views.setContentDescription(R.id.widget_icon, description);
}