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

The following examples show how to use android.widget.RemoteViews#setImageViewBitmap() . 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: CustomNotificationBuilder.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Shows the work profile badge if it is needed.
 */
private void addWorkProfileBadge(RemoteViews view) {
    Resources resources = mContext.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    int size = dpToPx(WORK_PROFILE_BADGE_SIZE_DP, metrics);
    int[] colors = new int[size * size];

    // Create an immutable bitmap, so that it can not be reused for painting a badge into it.
    Bitmap bitmap = Bitmap.createBitmap(colors, size, size, Bitmap.Config.ARGB_8888);

    Drawable inputDrawable = new BitmapDrawable(resources, bitmap);
    Drawable outputDrawable = ApiCompatibilityUtils.getUserBadgedDrawableForDensity(
            mContext, inputDrawable, null /* badgeLocation */, metrics.densityDpi);

    // The input bitmap is immutable, so the output drawable will be a different instance from
    // the input drawable if the work profile badge was applied.
    if (inputDrawable != outputDrawable && outputDrawable instanceof BitmapDrawable) {
        view.setImageViewBitmap(
                R.id.work_profile_badge, ((BitmapDrawable) outputDrawable).getBitmap());
        view.setViewVisibility(R.id.work_profile_badge, View.VISIBLE);
    }
}
 
Example 2
Source File: WorldCupDownloadReceiver.java    From letv with Apache License 2.0 6 votes vote down vote up
private void setPushData(Context context) {
    if (!this.isPush) {
        Constants.debug("======Push Id:-10000");
        String pushText = PreferencesManager.getInstance().getPushText(context);
        Intent intent = new Intent(context, PushNotificationReceiver.class);
        intent.putExtra("msgId", DataManager.NOT_UPLOAD_INT);
        intent.putExtra("type", 1000);
        intent.addFlags(268435456);
        NotificationManager notificationManager = (NotificationManager) context.getSystemService("notification");
        Notification notification = new Notification();
        notification.icon = R.drawable.notify_icon;
        notification.tickerText = pushText;
        notification.flags = 16;
        notification.defaults |= 4;
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.push_layout);
        remoteViews.setImageViewBitmap(R.id.push_icon, BitmapFactory.decodeResource(context.getResources(), R.drawable.push_icon));
        remoteViews.setTextViewText(R.id.push_text, LetvUtil.ToDBC(pushText));
        notification.contentView = remoteViews;
        notification.contentIntent = PendingIntent.getBroadcast(context, DataManager.NOT_UPLOAD_INT, intent, 268435456);
        notificationManager.notify(DataManager.NOT_UPLOAD_INT, notification);
        this.isPush = true;
    }
}
 
Example 3
Source File: CustomNotificationBuilder.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Shows the work profile badge if it is needed.
 */
private void addWorkProfileBadge(RemoteViews view) {
    Resources resources = mContext.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    int size = dpToPx(WORK_PROFILE_BADGE_SIZE_DP, metrics);
    int[] colors = new int[size * size];

    // Create an immutable bitmap, so that it can not be reused for painting a badge into it.
    Bitmap bitmap = Bitmap.createBitmap(colors, size, size, Bitmap.Config.ARGB_8888);

    Drawable inputDrawable = new BitmapDrawable(resources, bitmap);
    Drawable outputDrawable = ApiCompatibilityUtils.getUserBadgedDrawableForDensity(
            mContext, inputDrawable, null /* badgeLocation */, metrics.densityDpi);

    // The input bitmap is immutable, so the output drawable will be a different instance from
    // the input drawable if the work profile badge was applied.
    if (inputDrawable != outputDrawable && outputDrawable instanceof BitmapDrawable) {
        view.setImageViewBitmap(
                R.id.work_profile_badge, ((BitmapDrawable) outputDrawable).getBitmap());
        view.setViewVisibility(R.id.work_profile_badge, View.VISIBLE);
    }
}
 
Example 4
Source File: UrlDeviceDiscoveryService.java    From physical-web with Apache License 2.0 6 votes vote down vote up
private void updateSummaryNotificationRemoteViewsSecondBeacon(PwPair pwPair,
                                                              RemoteViews remoteViews) {
  PwsResult pwsResult = pwPair.getPwsResult();
  remoteViews.setImageViewBitmap(
      R.id.icon_secondBeacon, Utils.getBitmapIcon(mPwCollection, pwsResult));
  remoteViews.setTextViewText(R.id.title_secondBeacon, pwsResult.getTitle());
  remoteViews.setTextViewText(R.id.url_secondBeacon, pwsResult.getSiteUrl());
  remoteViews.setTextViewText(R.id.description_secondBeacon, pwsResult.getDescription());
  // Recolor notifications to have light text for non-Lollipop devices
  if (!(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)) {
    remoteViews.setTextColor(R.id.title_secondBeacon, NON_LOLLIPOP_NOTIFICATION_TITLE_COLOR);
    remoteViews.setTextColor(R.id.url_secondBeacon, NON_LOLLIPOP_NOTIFICATION_URL_COLOR);
    remoteViews.setTextColor(R.id.description_secondBeacon,
                             NON_LOLLIPOP_NOTIFICATION_SNIPPET_COLOR);
  }

  // Create an intent that will open the browser to the beacon's url
  // if the user taps the notification
  remoteViews.setOnClickPendingIntent(R.id.second_beacon_main_layout,
      Utils.createNavigateToUrlPendingIntent(pwsResult, this));
  remoteViews.setViewVisibility(R.id.secondBeaconLayout, View.VISIBLE);
}
 
Example 5
Source File: SunLayout_1x1_2.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void themeViews(Context context, RemoteViews views, SuntimesTheme theme)
{
    super.themeViews(context, views, theme);

    int sunsetColor = theme.getSunsetTextColor();
    int suffixColor = theme.getTimeSuffixColor();
    views.setTextColor(R.id.text_time_set_suffix, suffixColor);
    views.setTextColor(R.id.text_time_set, sunsetColor);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
    {
        views.setTextViewTextSize(R.id.text_time_set, TypedValue.COMPLEX_UNIT_DIP, theme.getTimeSizeSp());
        views.setTextViewTextSize(R.id.text_time_set_suffix, TypedValue.COMPLEX_UNIT_DIP, theme.getTimeSuffixSizeSp());
    }

    Bitmap sunsetIcon = SuntimesUtils.layerDrawableToBitmap(context, R.drawable.ic_sunset_large0, theme.getSunsetIconColor(), theme.getSunsetIconStrokeColor(), theme.getSunsetIconStrokePixels(context));
    views.setImageViewBitmap(R.id.icon_time_sunset, sunsetIcon);
}
 
Example 6
Source File: RemoteViewsFactory.java    From android-vlc-remote with GNU General Public License v3.0 6 votes vote down vote up
private void setupCommonViews(RemoteViews remote, Status status, Bitmap art) {
    remote.setImageViewBitmap(R.id.art, art);
    if(server.getAuthority() == null) {
        setError(remote, context.getString(R.string.noserver));
        return;
    }
    remote.setViewVisibility(R.id.control_next, View.VISIBLE);
    remote.setOnClickPendingIntent(R.id.control_play, server.status().command.playback.pendingPause());
    remote.setOnClickPendingIntent(R.id.control_next, server.status().command.playback.pendingNext());
    remote.setOnClickPendingIntent(R.id.control_close, PendingIntent.getService(context, 0, Intents.service(context, Intents.ACTION_NOTIFICATION_CANCEL), 0));
    if(status == null) {
        remote.setTextViewText(R.id.title, context.getString(R.string.loading));
    } else {
        if(status.isStopped()) {
            remote.setTextViewText(R.id.title, context.getString(R.string.no_media));
            remote.setImageViewResource(R.id.control_play, R.drawable.ic_media_play);
        } else {
            remote.setImageViewResource(R.id.control_play, status.isPaused() ? R.drawable.ic_media_play : R.drawable.ic_media_pause);
        }
    }
}
 
Example 7
Source File: UrlDeviceDiscoveryService.java    From physical-web with Apache License 2.0 6 votes vote down vote up
private void updateSummaryNotificationRemoteViewsFirstBeacon(PwPair pwPair,
                                                             RemoteViews remoteViews) {
  PwsResult pwsResult = pwPair.getPwsResult();
  remoteViews.setImageViewBitmap(
      R.id.icon_firstBeacon, Utils.getBitmapIcon(mPwCollection, pwsResult));
  remoteViews.setTextViewText(R.id.title_firstBeacon, pwsResult.getTitle());
  remoteViews.setTextViewText(R.id.url_firstBeacon, pwsResult.getSiteUrl());
  remoteViews.setTextViewText(R.id.description_firstBeacon, pwsResult.getDescription());
  // Recolor notifications to have light text for non-Lollipop devices
  if (!(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)) {
    remoteViews.setTextColor(R.id.title_firstBeacon, NON_LOLLIPOP_NOTIFICATION_TITLE_COLOR);
    remoteViews.setTextColor(R.id.url_firstBeacon, NON_LOLLIPOP_NOTIFICATION_URL_COLOR);
    remoteViews.setTextColor(R.id.description_firstBeacon,
                             NON_LOLLIPOP_NOTIFICATION_SNIPPET_COLOR);
  }

  // Create an intent that will open the browser to the beacon's url
  // if the user taps the notification
  remoteViews.setOnClickPendingIntent(R.id.first_beacon_main_layout,
      Utils.createNavigateToUrlPendingIntent(pwsResult, this));
  remoteViews.setViewVisibility(R.id.firstBeaconLayout, View.VISIBLE);
}
 
Example 8
Source File: MusicService.java    From DMusic with Apache License 2.0 5 votes vote down vote up
@android.support.annotation.NonNull
private RemoteViews getRemoteViews(Bitmap bitmap, String songName, String artistName, int status) {
    RemoteViews rv = new RemoteViews(getPackageName(), R.layout.module_play_notification);
    if (bitmap != null) {
        rv.setImageViewBitmap(R.id.image, bitmap);
    } else {
        rv.setImageViewResource(R.id.image, R.drawable.module_play_ic_notification);
    }
    if (status == Constants.PlayStatus.PLAY_STATUS_PLAYING) {
        rv.setImageViewResource(R.id.tv_play_pause, R.drawable.module_play_ic_notification_pause);
    } else if (status == Constants.PlayStatus.PLAY_STATUS_PAUSE) {
        rv.setImageViewResource(R.id.tv_play_pause, R.drawable.module_play_ic_notification_play);
    }
    rv.setTextViewText(R.id.title, songName);
    rv.setTextViewText(R.id.text, artistName);

    // 此处action不能是一样的 如果一样的 接受的flag参数只是第一个设置的值
    Intent pauseIntent = new Intent(Constants.PlayFlag.PLAYER_CONTROL_PLAY_PAUSE);
    pauseIntent.putExtra("flag", Constants.PlayFlag.PLAY_FLAG_PLAY_PAUSE);
    PendingIntent pausePIntent = PendingIntent.getBroadcast(this, 0, pauseIntent, 0);
    rv.setOnClickPendingIntent(R.id.play_pause, pausePIntent);

    Intent nextIntent = new Intent(Constants.PlayFlag.PLAYER_CONTROL_NEXT);
    nextIntent.putExtra("flag", Constants.PlayFlag.PLAY_FLAG_NEXT);
    PendingIntent nextPIntent = PendingIntent.getBroadcast(this, 0, nextIntent, 0);
    rv.setOnClickPendingIntent(R.id.next, nextPIntent);

    Intent preIntent = new Intent(Constants.PlayFlag.PLAYER_CONTROL_PREV);
    preIntent.putExtra("flag", Constants.PlayFlag.PLAY_FLAG_PRE);
    PendingIntent prePIntent = PendingIntent.getBroadcast(this, 0, preIntent, 0);
    rv.setOnClickPendingIntent(R.id.prev, prePIntent);

    Intent exitIntent = new Intent(Constants.PlayFlag.PLAYER_CONTROL_EXIT);
    exitIntent.putExtra("flag", Constants.PlayFlag.PLAY_FLAG_EXIT);
    PendingIntent exitPIntent = PendingIntent.getBroadcast(this, 0, exitIntent, 0);
    rv.setOnClickPendingIntent(R.id.exit, exitPIntent);
    return rv;
}
 
Example 9
Source File: AppWidgetBig.java    From Orin with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initialize given widgets to default state, where we launch Music on
 * default click and hide actions if service not running.
 */
private void defaultAppWidget(final Context context, final int[] appWidgetIds) {
    final RemoteViews appWidgetView = new RemoteViews(context.getPackageName(), R.layout.app_widget_big);

    appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
    appWidgetView.setViewVisibility(R.id.image, View.INVISIBLE);
    appWidgetView.setImageViewBitmap(R.id.button_next, createBitmap(Util.getTintedVectorDrawable(context, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getPrimaryTextColor(context, false)), 1f));
    appWidgetView.setImageViewBitmap(R.id.button_prev, createBitmap(Util.getTintedVectorDrawable(context, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getPrimaryTextColor(context, false)), 1f));
    appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, createBitmap(Util.getTintedVectorDrawable(context, R.drawable.ic_play_arrow_white_24dp, MaterialValueHelper.getPrimaryTextColor(context, false)), 1f));

    linkButtons(context, appWidgetView);
    pushUpdate(context, appWidgetIds, appWidgetView);
}
 
Example 10
Source File: AppWidgetSmall.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initialize given widgets to default state, where we launch Music on
 * default click and hide actions if service not running.
 */
protected void defaultAppWidget(final Context context, final int[] appWidgetIds) {
    final RemoteViews appWidgetView = new RemoteViews(context.getPackageName(), R.layout.app_widget_small);

    appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
    appWidgetView.setImageViewResource(R.id.image, R.drawable.default_album_art);
    appWidgetView.setImageViewBitmap(R.id.button_next, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))));
    appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))));
    appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_play_arrow_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))));

    linkButtons(context, appWidgetView);
    pushUpdate(context, appWidgetIds, appWidgetView);
}
 
Example 11
Source File: AppWidgetClassicDark.java    From Music-Player with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initialize given widgets to default state, where we launch Music on
 * default click and hide actions if service not running.
 */
protected void defaultAppWidget(final Context context, final int[] appWidgetIds) {
    final RemoteViews appWidgetView = new RemoteViews(context.getPackageName(), R.layout.app_widget_classic_dark);

    appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
    appWidgetView.setImageViewResource(R.id.image, R.drawable.default_album_art);
    appWidgetView.setImageViewBitmap(R.id.button_next, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, false))));
    appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, false))));
    appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_play_arrow_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, false))));

    linkButtons(context, appWidgetView);
    pushUpdate(context, appWidgetIds, appWidgetView);
}
 
Example 12
Source File: SquareWidget.java    From Jockey with Apache License 2.0 5 votes vote down vote up
private static RemoteViews setArtwork(RemoteViews views, @Nullable Bitmap artwork) {
    if (artwork == null) {
        views.setImageViewResource(R.id.widget_square_artwork, R.drawable.art_default_xl);
    } else {
        views.setImageViewBitmap(R.id.widget_square_artwork, artwork);
    }

    return views;
}
 
Example 13
Source File: BaseAppWidget.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initialize given widgets to default state, where we launch Music on
 * default click and hide actions if service not running.
 */
protected void defaultAppWidget(final Context context, final int[] appWidgetIds) {
    appWidgetView = new RemoteViews(context.getPackageName(), getLayout());

    setBackground();
    appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
    appWidgetView.setImageViewResource(R.id.image, R.drawable.default_album_art);
    appWidgetView.setImageViewBitmap(R.id.button_next, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))));
    appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))));
    appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_play_arrow_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))));

    linkButtons(context);
    pushUpdate(context, appWidgetIds);
}
 
Example 14
Source File: SunLayout_2x1_0.java    From SuntimesWidget with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void themeViews(Context context, RemoteViews views, SuntimesTheme theme)
{
    super.themeViews(context, views, theme);

    int sunriseColor = theme.getSunriseTextColor();
    int sunsetColor = theme.getSunsetTextColor();
    int noonColor = theme.getNoonTextColor();
    int suffixColor = theme.getTimeSuffixColor();
    int timeColor = theme.getTimeColor();
    int textColor = theme.getTextColor();
    boldTime = theme.getTimeBold();

    // theme sunrise text
    views.setTextColor(R.id.text_time_rise_suffix, suffixColor);
    views.setTextColor(R.id.text_time_rise, sunriseColor);

    // theme sunset text
    views.setTextColor(R.id.text_time_set_suffix, suffixColor);
    views.setTextColor(R.id.text_time_set, sunsetColor);

    // theme note
    views.setTextColor(R.id.text_delta_day_prefix, textColor);
    views.setTextColor(R.id.text_delta_day_value, timeColor);
    views.setTextColor(R.id.text_delta_day_units, textColor);
    views.setTextColor(R.id.text_delta_day_suffix, textColor);

    // theme noon
    views.setTextColor(R.id.text_time_noon_suffix, suffixColor);
    views.setTextColor(R.id.text_time_noon, noonColor);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
    {
        float textSize = theme.getTextSizeSp();
        float timeSize = theme.getTimeSizeSp();
        float suffSize = theme.getTimeSuffixSizeSp();

        views.setTextViewTextSize(R.id.text_time_rise_suffix, TypedValue.COMPLEX_UNIT_DIP, suffSize);
        views.setTextViewTextSize(R.id.text_time_rise, TypedValue.COMPLEX_UNIT_DIP, timeSize);

        views.setTextViewTextSize(R.id.text_time_noon, TypedValue.COMPLEX_UNIT_DIP, timeSize);
        views.setTextViewTextSize(R.id.text_time_noon_suffix, TypedValue.COMPLEX_UNIT_DIP, suffSize);

        views.setTextViewTextSize(R.id.text_time_set, TypedValue.COMPLEX_UNIT_DIP, timeSize);
        views.setTextViewTextSize(R.id.text_time_set_suffix, TypedValue.COMPLEX_UNIT_DIP, suffSize);

        views.setTextViewTextSize(R.id.text_delta_day_prefix, TypedValue.COMPLEX_UNIT_DIP, textSize);
        views.setTextViewTextSize(R.id.text_delta_day_value, TypedValue.COMPLEX_UNIT_DIP, textSize);
        views.setTextViewTextSize(R.id.text_delta_day_units, TypedValue.COMPLEX_UNIT_DIP, textSize);
        views.setTextViewTextSize(R.id.text_delta_day_suffix, TypedValue.COMPLEX_UNIT_DIP, textSize);
    }

    Bitmap sunriseIcon = SuntimesUtils.layerDrawableToBitmap(context, R.drawable.ic_sunrise0, theme.getSunriseIconColor(), theme.getSunriseIconStrokeColor(), theme.getSunriseIconStrokePixels(context));
    views.setImageViewBitmap(R.id.icon_time_sunrise, sunriseIcon);

    Bitmap noonIcon = SuntimesUtils.gradientDrawableToBitmap(context, R.drawable.ic_noon_large0, theme.getNoonIconColor(), theme.getNoonIconStrokeColor(), theme.getNoonIconStrokePixels(context));
    views.setImageViewBitmap(R.id.icon_time_noon, noonIcon);

    Bitmap sunsetIcon = SuntimesUtils.layerDrawableToBitmap(context, R.drawable.ic_sunset0, theme.getSunsetIconColor(), theme.getSunsetIconStrokeColor(), theme.getSunsetIconStrokePixels(context));
    views.setImageViewBitmap(R.id.icon_time_sunset, sunsetIcon);
}
 
Example 15
Source File: MoreWidgetProvider.java    From good-weather with GNU General Public License v3.0 4 votes vote down vote up
private void preLoadWeather(Context context, RemoteViews remoteViews) {
    SharedPreferences weatherPref = context.getSharedPreferences(Constants.PREF_WEATHER_NAME,
                                                                 Context.MODE_PRIVATE);
    String temperatureScale = Utils.getTemperatureScale(context);
    String speedScale = Utils.getSpeedScale(context);
    String percentSign = context.getString(R.string.percent_sign);
    String pressureMeasurement = context.getString(R.string.pressure_measurement);

    String temperature = String.format(Locale.getDefault(), "%.0f", weatherPref
            .getFloat(Constants.WEATHER_DATA_TEMPERATURE, 0));
    String description = weatherPref.getString(Constants.WEATHER_DATA_DESCRIPTION, "clear sky");
    String wind = context.getString(R.string.wind_label,
                                    String.format(Locale.getDefault(), "%.0f", weatherPref
                                            .getFloat(Constants.WEATHER_DATA_WIND_SPEED, 0)),
                                    speedScale);
    String humidity =
            context.getString(R.string.humidity_label,
                              String.valueOf(
                                      weatherPref.getInt(Constants.WEATHER_DATA_HUMIDITY, 0)),
                              percentSign);
    String pressure =
            context.getString(R.string.pressure_label,
                              String.format(Locale.getDefault(),
                                            "%.1f",
                                            weatherPref
                                                    .getFloat(Constants.WEATHER_DATA_PRESSURE,
                                                              0)),
                              pressureMeasurement);
    String cloudiness =
            context.getString(R.string.cloudiness_label,
                              String.valueOf(
                                      weatherPref.getInt(Constants.WEATHER_DATA_CLOUDS, 0)),
                              percentSign);
    String iconId = weatherPref.getString(Constants.WEATHER_DATA_ICON, "01d");
    String weatherIcon = Utils.getStrIcon(context, iconId);
    String lastUpdate = Utils.setLastUpdateTime(context,
                                                AppPreference.getLastUpdateTimeMillis(context));

    remoteViews.setTextViewText(R.id.widget_city, Utils.getCityAndCountry(context));
    remoteViews.setTextViewText(R.id.widget_temperature, temperature + temperatureScale);
    if(!AppPreference.hideDescription(context))
        remoteViews.setTextViewText(R.id.widget_description, description);
    else remoteViews.setTextViewText(R.id.widget_description, " ");
    remoteViews.setTextViewText(R.id.widget_wind, wind);
    remoteViews.setTextViewText(R.id.widget_humidity, humidity);
    remoteViews.setTextViewText(R.id.widget_pressure, pressure);
    remoteViews.setTextViewText(R.id.widget_clouds, cloudiness);
    remoteViews.setImageViewBitmap(R.id.widget_icon,
                                   Utils.createWeatherIcon(context, weatherIcon));
    remoteViews.setTextViewText(R.id.widget_last_update, lastUpdate);
}
 
Example 16
Source File: AppWidgetBig.java    From Phonograph with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Update all active widget instances by pushing changes
 */
public void performUpdate(final MusicService service, final int[] appWidgetIds) {
    final RemoteViews appWidgetView = new RemoteViews(service.getPackageName(), R.layout.app_widget_big);

    final boolean isPlaying = service.isPlaying();
    final Song song = service.getCurrentSong();

    // Set the titles and artwork
    if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
        appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
    } else {
        appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE);
        appWidgetView.setTextViewText(R.id.title, song.title);
        appWidgetView.setTextViewText(R.id.text, getSongArtistAndAlbum(song));
    }

    // Set correct drawable for pause state
    int playPauseRes = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
    appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, playPauseRes, MaterialValueHelper.getPrimaryTextColor(service, false))));

    // Set prev/next button drawables
    appWidgetView.setImageViewBitmap(R.id.button_next, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getPrimaryTextColor(service, false))));
    appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getPrimaryTextColor(service, false))));

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

    // Load the album cover async and push the update on completion
    Point p = Util.getScreenSize(service);
    final int widgetImageSize = Math.min(p.x, p.y);
    final Context appContext = service.getApplicationContext();
    service.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (target != null) {
                Glide.clear(target);
            }
            target = SongGlideRequest.Builder.from(Glide.with(appContext), song)
                    .checkIgnoreMediaStore(appContext)
                    .asBitmap().build()
                    .into(new SimpleTarget<Bitmap>(widgetImageSize, widgetImageSize) {
                        @Override
                        public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                            update(resource);
                        }

                        @Override
                        public void onLoadFailed(Exception e, Drawable errorDrawable) {
                            super.onLoadFailed(e, errorDrawable);
                            update(null);
                        }

                        private void update(@Nullable Bitmap bitmap) {
                            if (bitmap == null) {
                                appWidgetView.setImageViewResource(R.id.image, R.drawable.default_album_art);
                            } else {
                                appWidgetView.setImageViewBitmap(R.id.image, bitmap);
                            }
                            pushUpdate(appContext, appWidgetIds, appWidgetView);
                        }
                    });
        }
    });
}
 
Example 17
Source File: PlacesWidgetRemoteViewsService.java    From protrip with MIT License 4 votes vote down vote up
public RemoteViews getViewAt(int position) {

        String place_id = "";
        String place_name = "";
        String place_poster_url = "";
        String place_rating = "";
        String place_address = "";

        if (mPlaceCursor.moveToPosition(position)) {

            place_id = mPlaceCursor.getString(mPlaceCursor.getColumnIndex(PlacesSQLiteHelper.ID));
            place_name = mPlaceCursor.getString(mPlaceCursor.getColumnIndex(PlacesSQLiteHelper.TITLE));
            place_poster_url = mPlaceCursor.getString(mPlaceCursor.getColumnIndex(PlacesSQLiteHelper.POSTERPATH_WIDE));
            place_rating = mPlaceCursor.getString(mPlaceCursor.getColumnIndex(PlacesSQLiteHelper.RATING_AVG));
            place_address = mPlaceCursor.getString(mPlaceCursor.getColumnIndex(PlacesSQLiteHelper.ADDRESS_FULL));

        }

        RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.widget_collection_item);
        //RemoteViews rootView = new RemoteViews(mContext.getPackageName(), R.layout.widget_collection);
        //Intent intent = new Intent(mContext, PlaceDetailActivity.class);
        //intent.putExtra("place_id", place_id);
        //PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0);

        //rv.setViewVisibility(R.id.widget_nofavs_badge, View.INVISIBLE);

        rv.setTextViewText(R.id.place_id, place_id);
        rv.setTextViewText(R.id.place_name, place_name);
        rv.setTextViewText(R.id.place_Address, place_address);
        place_rating = (place_rating == null) ? "0" : place_rating;
        rv.setTextViewText(R.id.rating, place_rating);
        //rv.setOnClickPendingIntent(R.id.root_view, pendingIntent);

        try {
            if (!place_poster_url.isEmpty()) {
                Bitmap b = Picasso.with(mContext).load(place_poster_url).get();
                rv.setImageViewBitmap(R.id.place_pic, b);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
        return rv;
    }
 
Example 18
Source File: DailyTrendWidgetIMP.java    From GeometricWeather with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressLint("WrongThread")
@WorkerThread
private static RemoteViews getRemoteViews(Context context, @Nullable View drawableView,
                                         Location location, int width,
                                          boolean darkCard, int cardAlpha) {
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_remote);
    if (drawableView == null) {
        return views;
    }

    WidgetItemView[] items = new WidgetItemView[] {
            drawableView.findViewById(R.id.widget_trend_daily_item_1),
            drawableView.findViewById(R.id.widget_trend_daily_item_2),
            drawableView.findViewById(R.id.widget_trend_daily_item_3),
            drawableView.findViewById(R.id.widget_trend_daily_item_4),
            drawableView.findViewById(R.id.widget_trend_daily_item_5),
    };
    for (WidgetItemView i : items) {
        i.setSize(width / 5f);
    }
    drawableView.measure(
            View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
    );
    drawableView.layout(
            0,
            0,
            drawableView.getMeasuredWidth(),
            drawableView.getMeasuredHeight()
    );

    Bitmap cache = Bitmap.createBitmap(
            drawableView.getMeasuredWidth(),
            drawableView.getMeasuredHeight(),
            Bitmap.Config.ARGB_8888
    );
    Canvas canvas = new Canvas(cache);
    drawableView.draw(canvas);

    views.setImageViewBitmap(R.id.widget_remote_drawable, cache);
    views.setViewVisibility(R.id.widget_remote_progress, View.GONE);

    views.setImageViewResource(
            R.id.widget_remote_card,
            getCardBackgroundId(context, darkCard, cardAlpha)
    );

    setOnClickPendingIntent(
            context,
            views,
            location,
            SettingsOptionManager.getInstance(context).isWidgetClickToRefreshEnabled()
    );

    return views;
}
 
Example 19
Source File: CustomNotificationBuilder.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * If there are actions, shows the button related views, and adds a button for each action.
 */
private void addActionButtons(RemoteViews bigView) {
    // Remove the existing buttons in case an existing notification is being updated.
    bigView.removeAllViews(R.id.buttons);

    // Always set the visibility of the views associated with the action buttons. The current
    // visibility state is not known as perhaps an existing notification is being updated.
    int visibility = mActions.isEmpty() ? View.GONE : View.VISIBLE;
    bigView.setViewVisibility(R.id.button_divider, visibility);
    bigView.setViewVisibility(R.id.buttons, visibility);

    Resources resources = mContext.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    for (Action action : mActions) {
        RemoteViews view =
                new RemoteViews(mContext.getPackageName(), R.layout.web_notification_button);

        // If there is an icon then set it and add some padding.
        if (action.iconBitmap != null || action.iconId != 0) {
            if (useMaterial()) {
                view.setInt(R.id.button_icon, "setColorFilter", BUTTON_ICON_COLOR_MATERIAL);
            }

            int iconWidth = 0;
            if (action.iconBitmap != null) {
                view.setImageViewBitmap(R.id.button_icon, action.iconBitmap);
                iconWidth = action.iconBitmap.getWidth();
            } else if (action.iconId != 0) {
                view.setImageViewResource(R.id.button_icon, action.iconId);
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inJustDecodeBounds = true;
                BitmapFactory.decodeResource(resources, action.iconId, options);
                iconWidth = options.outWidth;
            }
            iconWidth = dpToPx(
                    Math.min(pxToDp(iconWidth, metrics), MAX_ACTION_ICON_WIDTH_DP), metrics);

            // Set the padding of the button so the text does not overlap with the icon. Flip
            // between left and right manually as RemoteViews does not expose a method that sets
            // padding in a writing-direction independent way.
            int buttonPadding =
                    dpToPx(BUTTON_PADDING_START_DP + BUTTON_ICON_PADDING_DP, metrics)
                    + iconWidth;
            int buttonPaddingLeft = LocalizationUtils.isLayoutRtl() ? 0 : buttonPadding;
            int buttonPaddingRight = LocalizationUtils.isLayoutRtl() ? buttonPadding : 0;
            view.setViewPadding(R.id.button, buttonPaddingLeft, 0, buttonPaddingRight, 0);
        }

        view.setTextViewText(R.id.button, action.title);
        view.setOnClickPendingIntent(R.id.button, action.intent);
        bigView.addView(R.id.buttons, view);
    }
}
 
Example 20
Source File: xDripWidget.java    From xDrip-Experimental with GNU General Public License v3.0 4 votes vote down vote up
private static void displayCurrentInfo(AppWidgetManager appWidgetManager, int appWidgetId, Context context, RemoteViews views) {
    BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(context);
    BgReading lastBgreading = BgReading.lastNoSenssor();

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    boolean showLines = settings.getBoolean("widget_range_lines", false);

    if (lastBgreading != null) {
        double estimate = 0;
        int height = appWidgetManager.getAppWidgetOptions(appWidgetId).getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT);
        int width = appWidgetManager.getAppWidgetOptions(appWidgetId).getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH);
        views.setImageViewBitmap(R.id.widgetGraph, new BgSparklineBuilder(context)
                .setBgGraphBuilder(bgGraphBuilder)
                .setHeight(height).setWidth(width).showHighLine(showLines).showLowLine(showLines).build());

        if ((new Date().getTime()) - (60000 * 11) - lastBgreading.timestamp > 0) {
            estimate = lastBgreading.calculated_value;
            Log.d(TAG, "old value, estimate " + estimate);
            views.setTextViewText(R.id.widgetBg, bgGraphBuilder.unitized_string(estimate));
            views.setTextViewText(R.id.widgetArrow, "--");
            views.setInt(R.id.widgetBg, "setPaintFlags", Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
        } else {
            estimate = lastBgreading.calculated_value;
            String stringEstimate = bgGraphBuilder.unitized_string(estimate);
            String slope_arrow = lastBgreading.slopeArrow();
            if (lastBgreading.hide_slope) {
                slope_arrow = "--";
            }
            Log.d(TAG, "newish value, estimate " + stringEstimate + slope_arrow);
            views.setTextViewText(R.id.widgetBg, stringEstimate);
            views.setTextViewText(R.id.widgetArrow, slope_arrow);
            views.setInt(R.id.widgetBg, "setPaintFlags", 0);
        }
        List<BgReading> bgReadingList =  BgReading.latest(2);
        if(bgReadingList != null && bgReadingList.size() == 2) {

            views.setTextViewText(R.id.widgetDelta, bgGraphBuilder.unitizedDeltaString(true, true));
        } else {
            views.setTextViewText(R.id.widgetDelta, "--");
        }
        int timeAgo =(int) Math.floor((new Date().getTime() - lastBgreading.timestamp)/(1000*60));
        if (timeAgo == 1) {
            views.setTextViewText(R.id.readingAge, timeAgo + " Minute ago");
        } else {
            views.setTextViewText(R.id.readingAge, timeAgo + " Minutes ago");
        }
        if (timeAgo > 15) {
            views.setTextColor(R.id.readingAge, Color.parseColor("#FFBB33"));
        } else {
            views.setTextColor(R.id.readingAge, Color.WHITE);
        }

        if(settings.getBoolean("extra_status_line", false) && settings.getBoolean("widget_status_line", false)) {
            views.setTextViewText(R.id.widgetStatusLine, Home.extraStatusLine(settings));
            views.setViewVisibility(R.id.widgetStatusLine, View.VISIBLE);
        } else {
            views.setTextViewText(R.id.widgetStatusLine, "");
            views.setViewVisibility(R.id.widgetStatusLine, View.GONE);
        }

        if (bgGraphBuilder.unitized(estimate) <= bgGraphBuilder.lowMark) {
            views.setTextColor(R.id.widgetBg, Color.parseColor("#C30909"));
            views.setTextColor(R.id.widgetDelta, Color.parseColor("#C30909"));
            views.setTextColor(R.id.widgetArrow, Color.parseColor("#C30909"));
        } else if (bgGraphBuilder.unitized(estimate) >= bgGraphBuilder.highMark) {
            views.setTextColor(R.id.widgetBg, Color.parseColor("#FFBB33"));
            views.setTextColor(R.id.widgetDelta, Color.parseColor("#FFBB33"));
            views.setTextColor(R.id.widgetArrow, Color.parseColor("#FFBB33"));
        } else {
            views.setTextColor(R.id.widgetBg, Color.WHITE);
            views.setTextColor(R.id.widgetDelta, Color.WHITE);
            views.setTextColor(R.id.widgetArrow, Color.WHITE);
        }
    }
}