List of usage examples for android.widget RemoteViews setImageViewUri
public void setImageViewUri(int viewId, Uri uri)
From source file:ru.kaefik.isaifutdinov.an_weather_widget.AnWeatherWidget.java
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) throws JSONException { Log.i(TAG_SERVICE, "start updateAppWidget" + " appWidgetId = " + String.valueOf(appWidgetId)); String nameCity = ConfigActivity.loadStringParametersFromFile(context, String.valueOf(appWidgetId)); CityModel mCityModel = new CityModel(nameCity); // ? // w w w .j av a 2 s . com mCityModel = GetWeatherCityService.restoreCityInfoFromFile(context, mCityModel); Log.i(TAG_SERVICE, "updateAppWidget -> ?? " + mCityModel.getName() + " -> " + mCityModel.getTemp()); if (!nameCity.trim().equals("")) { Log.i(TAG_SERVICE, " updateAppWidget - >: " + nameCity + " appWidgetId = " + String.valueOf(appWidgetId)); // ? CLICK_WIDGET_BUTTON onReceive RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.an_weather_widget); // Intent ? Broadcast Intent active = new Intent(context, AnWeatherWidget.class); active.setAction(CLICK_WIDGET_BUTTON); //? ? PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0); //? ? remoteViews.setOnClickPendingIntent(R.id.refreshButton, actionPendingIntent); //? remoteViews.setTextViewText(R.id.cityNameText, mCityModel.getName()); remoteViews.setTextViewText(R.id.tempCityText, mCityModel.getTemp() + "C"); remoteViews.setTextViewText(R.id.windText, Utils.windGradus2Rumb(mCityModel.getWinddirection()) + " (" + Float.toString(mCityModel.getWindspeed()) + " /?)"); remoteViews.setTextViewText(R.id.timeRefreshText, mCityModel.getTimeRefresh()); remoteViews.setTextViewText(R.id.descriptionWeatherText, mCityModel.getWeather("description")); remoteViews.setImageViewUri(R.id.weatherImageView, Uri.parse("android.resource://ru.kaefik.isaifutdinov.an_weather_widget/mipmap/" + "weather" + mCityModel.getWeather("icon"))); appWidgetManager.updateAppWidget(appWidgetId, remoteViews); // END - ? CLICK_WIDGET_BUTTON onReceive startGetWeatherCityService(context, appWidgetId, mCityModel); } else { Log.i(TAG_SERVICE, " updateAppWidget - > ? " + " appWidgetId = " + String.valueOf(appWidgetId)); } }
From source file:com.lithiumli.fiction.PlaybackService.java
private void showNotification() { Intent launchPlaybackIntent = new Intent(getApplicationContext(), NowPlayingActivity.class); launchPlaybackIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, launchPlaybackIntent, PendingIntent.FLAG_UPDATE_CURRENT); String title = "(unknown title)"; String artist = "(unknown artist)"; String album = "(unknown album)"; Uri albumArt = Song.DEFAULT_ALBUM;//from ww w .j av a 2s . c om if (mQueue.getCount() != 0) { Song song = mQueue.getCurrent(); title = song.getTitle(); artist = song.getArtist(); album = song.getAlbum(); albumArt = song.getAlbumArt(); // TODO see ImageView.resolveUri for a working method // if (albumArt.getPath() == null) { // albumArt = Song.DEFAULT_ALBUM; // } } Notification.Builder builder = new Notification.Builder(getApplicationContext()); builder.setSmallIcon(R.drawable.ic_menu_play).setContentTitle("Playing" + title).setOngoing(true) .setContentIntent(pi); Notification notification = builder.build(); RemoteViews customView = new RemoteViews(getPackageName(), R.layout.notification); customView.setImageViewUri(R.id.notification_cover, albumArt); customView.setTextViewText(R.id.notification_title, title); customView.setTextViewText(R.id.notification_subtitle, artist); notification.contentView = customView; customView = new RemoteViews(getPackageName(), R.layout.notification_big); customView.setImageViewUri(R.id.notification_cover, albumArt); customView.setImageViewResource(R.id.notification_play_pause, mPaused ? R.drawable.ic_menu_play : R.drawable.ic_menu_pause); customView.setTextViewText(R.id.notification_title, title); customView.setTextViewText(R.id.notification_album, album); customView.setTextViewText(R.id.notification_artist, artist); customView.setOnClickPendingIntent(R.id.notification_previous, createAction(ACTION_PREV)); customView.setOnClickPendingIntent(R.id.notification_play_pause, createAction(ACTION_PLAY_PAUSE)); customView.setOnClickPendingIntent(R.id.notification_next, createAction(ACTION_NEXT)); notification.bigContentView = customView; startForeground(NOTIFICATION_PLAYING, notification); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_PLAYING, notification); }
From source file:ru.kaefik.isaifutdinov.an_weather_widget.AnWeatherWidget.java
@Override public void onReceive(Context context, Intent intent) { Log.i(TAG_SERVICE, " onReceive " + intent.getAction()); super.onReceive(context, intent); if (FORCE_WIDGET_UPDATE.equals(intent.getAction())) { String nameCity = intent.getStringExtra(PARAM_CITY); String tempCity = intent.getStringExtra(PARAM_TEMP); String windCity = intent.getStringExtra(PARAM_WIND); String timeRefreshCity = intent.getStringExtra(PARAM_TIMEREFRESH); String weatherImageCity = intent.getStringExtra(PARAM_WEATHERIMAGE); String descriptionWeather = intent.getStringExtra(PARAM_DESCWEATHER); int WidgetId = intent.getIntExtra(PARAM_WIDGETID, 0); //TODO: ? , ?. ? ? GetWeatherCityService Log.i(TAG_SERVICE, "onReceive " + nameCity + " -> " + tempCity); // /*from w ww .j a v a 2s.co m*/ AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); ComponentName thisWidget = new ComponentName(context, AnWeatherWidget.class); int[] appWidgetId = appWidgetManager.getAppWidgetIds(thisWidget); for (int i = 0; i < appWidgetId.length; i++) { Log.i(TAG_SERVICE, "onReceive -> appWidgetId = " + String.valueOf(appWidgetId[i])); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.an_weather_widget); if (WidgetId == appWidgetId[i]) { views.setTextViewText(R.id.cityNameText, nameCity); views.setTextViewText(R.id.tempCityText, tempCity); views.setTextViewText(R.id.windText, windCity); views.setTextViewText(R.id.timeRefreshText, timeRefreshCity); views.setTextViewText(R.id.descriptionWeatherText, descriptionWeather); views.setImageViewUri(R.id.weatherImageView, Uri.parse("android.resource://ru.kaefik.isaifutdinov.an_weather_widget/mipmap/" + "weather" + weatherImageCity)); // ? CLICK_WIDGET_BUTTON onReceive // Intent ? Broadcast Intent active = new Intent(context, AnWeatherWidget.class); active.setAction(CLICK_WIDGET_BUTTON); //? ? PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0); //? ? views.setOnClickPendingIntent(R.id.refreshButton, actionPendingIntent); //? // END - ? CLICK_WIDGET_BUTTON onReceive appWidgetManager.updateAppWidget(appWidgetId[i], views); break; } appWidgetManager.updateAppWidget(appWidgetId[i], views); } } if (CLICK_WIDGET_BUTTON.equals(intent.getAction())) { Log.i(TAG_SERVICE, " "); // AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); ComponentName thisWidget = new ComponentName(context, AnWeatherWidget.class); int[] appWidgetId = appWidgetManager.getAppWidgetIds(thisWidget); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.an_weather_widget); // ? for (int i = 0; i < appWidgetId.length; i++) { Log.i(TAG_SERVICE, "id -> " + String.valueOf(appWidgetId[i])); String nameCity = ConfigActivity.loadStringParametersFromFile(context, String.valueOf(appWidgetId[i])); startGetWeatherCityService(context, appWidgetId[i], new CityModel(nameCity)); } } }
From source file:com.namelessdev.mpdroid.NotificationService.java
/** * This method builds the base, otherwise known as the collapsed notification. The expanded * notification method builds upon this method. * * @param resultView The RemoteView to begin with, be it new or from the current notification. * @return The base, otherwise known as, collapsed notification resources for RemoteViews. *///from w w w . ja v a 2 s .co m private RemoteViews buildBaseNotification(final RemoteViews resultView) { final String title = mCurrentMusic.getTitle(); /** If in streaming, the notification should be persistent. */ if (app.getApplicationState().streamingMode && !StreamingService.isWoundDown()) { resultView.setViewVisibility(R.id.notificationClose, View.GONE); } else { resultView.setViewVisibility(R.id.notificationClose, View.VISIBLE); resultView.setOnClickPendingIntent(R.id.notificationClose, notificationClose); } if (MPDStatus.MPD_STATE_PLAYING.equals(getStatus().getState())) { resultView.setOnClickPendingIntent(R.id.notificationPlayPause, notificationPause); resultView.setImageViewResource(R.id.notificationPlayPause, R.drawable.ic_media_pause); } else { resultView.setOnClickPendingIntent(R.id.notificationPlayPause, notificationPlay); resultView.setImageViewResource(R.id.notificationPlayPause, R.drawable.ic_media_play); } /** When streaming, move things down (hopefully, very) temporarily. */ if (mediaPlayerServiceIsBuffering) { resultView.setTextViewText(R.id.notificationTitle, getString(R.string.buffering)); resultView.setTextViewText(R.id.notificationArtist, title); } else { resultView.setTextViewText(R.id.notificationTitle, title); resultView.setTextViewText(R.id.notificationArtist, mCurrentMusic.getArtist()); } resultView.setOnClickPendingIntent(R.id.notificationNext, notificationNext); if (mAlbumCover != null) { resultView.setImageViewUri(R.id.notificationIcon, Uri.parse(mAlbumCoverPath)); } return resultView; }