List of usage examples for android.widget RemoteViews RemoteViews
public RemoteViews(RemoteViews landscape, RemoteViews portrait)
From source file:com.mb.android.playbackmediator.notification.VideoCastNotificationService.java
private RemoteViews build(SessionInfoDto info, Bitmap bitmap, boolean isPlaying) throws CastException, TransientNetworkDisconnectionException, NoConnectionException { if (info.getNowPlayingItem() == null) { return null; }// w w w .jav a 2s. co m if (mIsLollipopOrAbove) { buildForLollipopAndAbove(info, bitmap, isPlaying); return null; } Bundle mediaWrapper = Utils.fromMediaInfo(mCastManager.getRemoteMediaInformation()); mTargetActivity = RemoteControlActivity.class; Intent contentIntent = new Intent(this, mTargetActivity); contentIntent.putExtra("LAUNCHED_BY_NOTIFICATION", true); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(mTargetActivity); stackBuilder.addNextIntent(contentIntent); if (stackBuilder.getIntentCount() > 1) { stackBuilder.editIntentAt(1).putExtra("media", mediaWrapper); } // Gets a PendingIntent containing the entire back stack PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(NOTIFICATION_ID, PendingIntent.FLAG_UPDATE_CURRENT); RemoteViews rv = new RemoteViews(getPackageName(), R.layout.custom_notification); if (mIsIcsOrAbove) { addPendingIntents(rv, isPlaying, info); } if (null != bitmap) { rv.setImageViewBitmap(R.id.iconView, bitmap); } rv.setTextViewText(R.id.titleView, info.getNowPlayingItem().getName()); String castingTo = getResources().getString(R.string.casting_to_device, mCastManager.getDeviceName()); rv.setTextViewText(R.id.subTitleView, castingTo); mNotification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_stat_action_notification) .setContentIntent(resultPendingIntent).setContent(rv).setAutoCancel(false).setOngoing(true).build(); // to get around a bug in GB version, we add the following line // see https://code.google.com/p/android/issues/detail?id=30495 mNotification.contentView = rv; return rv; }
From source file:name.gumartinm.weather.information.widget.WidgetIntentService.java
private RemoteViews makeView(final Current current, final WeatherLocation weatherLocation, final int appWidgetId) { // 1. Update units of measurement. UnitsConversor tempUnitsConversor;/*from w w w. jav a 2 s .c om*/ String keyPreference = this.getApplicationContext() .getString(R.string.widget_preferences_temperature_units_key); String realKeyPreference = keyPreference + "_" + appWidgetId; // What was saved to permanent storage (or default values if it is the first time) final int tempValue = this.getSharedPreferences(WIDGET_PREFERENCES_NAME, Context.MODE_PRIVATE) .getInt(realKeyPreference, 0); final String tempSymbol = this.getResources() .getStringArray(R.array.weather_preferences_temperature)[tempValue]; if (tempValue == 0) { tempUnitsConversor = new UnitsConversor() { @Override public double doConversion(final double value) { return value - 273.15; } }; } else if (tempValue == 1) { tempUnitsConversor = new UnitsConversor() { @Override public double doConversion(final double value) { return (value * 1.8) - 459.67; } }; } else { tempUnitsConversor = new UnitsConversor() { @Override public double doConversion(final double value) { return value; } }; } // 2. Update country. keyPreference = this.getApplicationContext().getString(R.string.widget_preferences_country_switch_key); realKeyPreference = keyPreference + "_" + appWidgetId; // What was saved to permanent storage (or default values if it is the first time) final boolean isCountry = this.getSharedPreferences(WIDGET_PREFERENCES_NAME, Context.MODE_PRIVATE) .getBoolean(realKeyPreference, false); // 3. Formatters final DecimalFormat tempFormatter = (DecimalFormat) NumberFormat.getNumberInstance(Locale.US); tempFormatter.applyPattern("###.##"); // 4. Prepare data for RemoteViews. String tempMax = ""; if (current.getMain().getTemp_max() != null) { double conversion = (Double) current.getMain().getTemp_max(); conversion = tempUnitsConversor.doConversion(conversion); tempMax = tempFormatter.format(conversion) + tempSymbol; } String tempMin = ""; if (current.getMain().getTemp_min() != null) { double conversion = (Double) current.getMain().getTemp_min(); conversion = tempUnitsConversor.doConversion(conversion); tempMin = tempFormatter.format(conversion) + tempSymbol; } Bitmap picture; if ((current.getWeather().size() > 0) && (current.getWeather().get(0).getIcon() != null) && (IconsList.getIcon(current.getWeather().get(0).getIcon()) != null)) { final String icon = current.getWeather().get(0).getIcon(); picture = BitmapFactory.decodeResource(this.getResources(), IconsList.getIcon(icon).getResourceDrawable()); } else { picture = BitmapFactory.decodeResource(this.getResources(), R.drawable.weather_severe_alert); } final String city = weatherLocation.getCity(); final String country = weatherLocation.getCountry(); // 5. Insert data in RemoteViews. final RemoteViews remoteView = new RemoteViews(this.getApplicationContext().getPackageName(), R.layout.appwidget); remoteView.setImageViewBitmap(R.id.weather_appwidget_image, picture); remoteView.setTextViewText(R.id.weather_appwidget_temperature_max, tempMax); remoteView.setTextViewText(R.id.weather_appwidget_temperature_min, tempMin); remoteView.setTextViewText(R.id.weather_appwidget_city, city); if (!isCountry) { remoteView.setViewVisibility(R.id.weather_appwidget_country, View.GONE); } else { // TODO: It is as if Android had a view cache. If I did not set VISIBLE value, // the country field would be gone forever... :/ remoteView.setViewVisibility(R.id.weather_appwidget_country, View.VISIBLE); remoteView.setTextViewText(R.id.weather_appwidget_country, country); } // 6. Activity launcher. final Intent resultIntent = new Intent(this.getApplicationContext(), WidgetConfigure.class); resultIntent.putExtra("actionFromUser", true); resultIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); // From: http://stackoverflow.com/questions/4011178/multiple-instances-of-widget-only-updating-last-widget final Uri data = Uri.withAppendedPath(Uri.parse("PAIN" + "://widget/id/"), String.valueOf(appWidgetId)); resultIntent.setData(data); final TaskStackBuilder stackBuilder = TaskStackBuilder.create(this.getApplicationContext()); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(WidgetConfigure.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); final PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); remoteView.setOnClickPendingIntent(R.id.weather_appwidget, resultPendingIntent); return remoteView; }
From source file:com.devbrackets.android.exomedia.EMNotification.java
/** * Creates the RemoteViews used for the expanded (big) notification * * @return The resulting RemoteViews//from ww w .j a v a2s. c om */ private RemoteViews getBigNotification() { if (bigContent == null) { bigContent = new RemoteViews(context.getPackageName(), R.layout.exomedia_big_notification_content); bigContent.setOnClickPendingIntent(R.id.exomedia_big_notification_close, createPendingIntent(EMRemoteActions.ACTION_STOP, mediaServiceClass)); bigContent.setOnClickPendingIntent(R.id.exomedia_big_notification_playpause, createPendingIntent(EMRemoteActions.ACTION_PLAY_PAUSE, mediaServiceClass)); bigContent.setOnClickPendingIntent(R.id.exomedia_big_notification_next, createPendingIntent(EMRemoteActions.ACTION_NEXT, mediaServiceClass)); bigContent.setOnClickPendingIntent(R.id.exomedia_big_notification_prev, createPendingIntent(EMRemoteActions.ACTION_PREVIOUS, mediaServiceClass)); } bigContent.setTextViewText(R.id.exomedia_big_notification_title, notificationInfo.getTitle()); bigContent.setTextViewText(R.id.exomedia_big_notification_album, notificationInfo.getAlbum()); bigContent.setTextViewText(R.id.exomedia_big_notification_artist, notificationInfo.getArtist()); bigContent.setBitmap(R.id.exomedia_big_notification_large_image, "setImageBitmap", notificationInfo.getLargeImage()); bigContent.setBitmap(R.id.exomedia_big_notification_secondary_image, "setImageBitmap", notificationInfo.getSecondaryImage()); //Makes sure the play/pause, next, and previous are displayed correctly if (notificationInfo.getMediaState() != null) { updateBigNotificationMediaState(bigContent); } return bigContent; }
From source file:org.alfresco.mobile.android.platform.AlfrescoNotificationManager.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) public int createNotification(int notificationId, Bundle params) { Notification notification;//w w w. j a va2s . com // Get the builder to create notification. NotificationCompat.Builder builder = new NotificationCompat.Builder(appContext.getApplicationContext()); builder.setContentTitle(params.getString(ARGUMENT_TITLE)); if (params.containsKey(ARGUMENT_DESCRIPTION)) { builder.setContentText(params.getString(ARGUMENT_DESCRIPTION)); } builder.setNumber(0); if (AndroidVersion.isLollipopOrAbove()) { builder.setSmallIcon(R.drawable.ic_notification); builder.setColor(appContext.getResources().getColor(R.color.alfresco_sky)); } else { builder.setSmallIcon(R.drawable.ic_notification); } if (params.containsKey(ARGUMENT_DESCRIPTION)) { builder.setContentText(params.getString(ARGUMENT_DESCRIPTION)); } if (params.containsKey(ARGUMENT_CONTENT_INFO)) { builder.setContentInfo(params.getString(ARGUMENT_CONTENT_INFO)); } if (params.containsKey(ARGUMENT_SMALL_ICON)) { builder.setSmallIcon(params.getInt(ARGUMENT_SMALL_ICON)); } Intent i; PendingIntent pIntent; switch (notificationId) { case CHANNEL_SYNC: i = new Intent(PrivateIntent.ACTION_SYNCHRO_DISPLAY); pIntent = PendingIntent.getActivity(appContext, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); break; default: i = new Intent(PrivateIntent.ACTION_DISPLAY_OPERATIONS); i.putExtra(PrivateIntent.EXTRA_OPERATIONS_TYPE, notificationId); if (SessionUtils.getAccount(appContext) != null) { i.putExtra(PrivateIntent.EXTRA_ACCOUNT_ID, SessionUtils.getAccount(appContext).getId()); } pIntent = PendingIntent.getActivity(appContext, 0, i, 0); break; } builder.setContentIntent(pIntent); if (AndroidVersion.isICSOrAbove()) { if (params.containsKey(ARGUMENT_PROGRESS_MAX) && params.containsKey(ARGUMENT_PROGRESS)) { long max = params.getLong(ARGUMENT_PROGRESS_MAX); long progress = params.getLong(ARGUMENT_PROGRESS); float value = (((float) progress / ((float) max)) * 100); int percentage = Math.round(value); builder.setProgress(100, percentage, false); } if (params.getBoolean(ARGUMENT_INDETERMINATE)) { builder.setProgress(0, 0, true); } } else { RemoteViews remote = new RemoteViews(appContext.getPackageName(), R.layout.app_notification); remote.setImageViewResource(R.id.status_icon, R.drawable.ic_application_logo); remote.setTextViewText(R.id.status_text, params.getString(ARGUMENT_TITLE)); remote.setProgressBar(R.id.status_progress, params.getInt(ARGUMENT_PROGRESS_MAX), 0, false); builder.setContent(remote); } if (AndroidVersion.isJBOrAbove()) { builder.setPriority(0); notification = builder.build(); } else { notification = builder.getNotification(); } notification.flags |= Notification.FLAG_AUTO_CANCEL; ((NotificationManager) appContext.getSystemService(Context.NOTIFICATION_SERVICE)).notify(notificationId, notification); return notificationId; }
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;//w w w . java 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:org.chromium.chrome.browser.media.ui.NotificationMediaPlaybackControls.java
private RemoteViews createContentView() { RemoteViews contentView = new RemoteViews(mContext.getPackageName(), R.layout.playback_notification_bar); // 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 (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { contentView.setViewVisibility(R.id.stop, View.VISIBLE); contentView.setOnClickPendingIntent(R.id.stop, mService.getPendingIntent(ListenerService.ACTION_STOP)); }//from ww w . j a v a 2 s . c om return contentView; }
From source file:com.gdpi.app.UpdateManager.java
/** * ??/*ww w . j a v a 2 s .c o m*/ */ @SuppressWarnings({ "deprecation", "unused" }) private void showNotify() { mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); int icon = R.drawable.icon; CharSequence tickerText = ""; long when = System.currentTimeMillis(); nitify = new Notification(icon, tickerText, when); // "?"? nitify.flags = Notification.FLAG_ONGOING_EVENT; RemoteViews contentView = new RemoteViews(mContext.getPackageName(), R.layout.view_custom_progress); contentView.setTextViewText(R.id.tv_custom_progress_title, name); // nitify.contentView = contentView; Intent intent = new Intent(mContext, MainFragment.class); PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0); // ? nitify.contentIntent = contentIntent; mNotificationManager.notify(notifyId, nitify); }
From source file:org.openbitcoinwidget.WidgetProvider.java
public static void updateAppWidgetWithWaitMessage(Context context, AppWidgetManager appWidgetManager, int appWidgetId) { appWidgetManager.updateAppWidget(appWidgetId, new RemoteViews(context.getPackageName(), R.layout.appwidget_loading)); }
From source file:com.example.accessibility.OverlayManager.java
private void triggerNotification() { //The idea is that this notification allows you to switch off the service. Now you can only access the application information and stop it there. NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notification = new Notification.Builder(this).setContentText("Hola hola") .setSmallIcon(R.drawable.images).setWhen(System.currentTimeMillis()).build(); RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification_layout); contentView.setImageViewResource(R.id.img_notification, R.drawable.images); contentView.setTextViewText(R.id.txt_notification, "Switch off TouchAccessibility."); notification.contentView = contentView; notificationManager.notify(NOTIFICATION_ID, notification); }
From source file:com.devbrackets.android.playlistcore.helper.NotificationHelper.java
/** * Creates the RemoteViews used for the expanded (big) notification * * @return The resulting RemoteViews// w w w. ja v a2 s. c o m */ @NonNull protected RemoteViews getBigNotification(Class<? extends Service> serviceClass) { RemoteViews bigContent = new RemoteViews(context.getPackageName(), R.layout.playlistcore_big_notification_content); bigContent.setOnClickPendingIntent(R.id.playlistcore_big_notification_close, createPendingIntent(RemoteActions.ACTION_STOP, serviceClass)); bigContent.setOnClickPendingIntent(R.id.playlistcore_big_notification_playpause, createPendingIntent(RemoteActions.ACTION_PLAY_PAUSE, serviceClass)); bigContent.setOnClickPendingIntent(R.id.playlistcore_big_notification_next, createPendingIntent(RemoteActions.ACTION_NEXT, serviceClass)); bigContent.setOnClickPendingIntent(R.id.playlistcore_big_notification_prev, createPendingIntent(RemoteActions.ACTION_PREVIOUS, serviceClass)); bigContent.setTextViewText(R.id.playlistcore_big_notification_title, notificationInfo.getTitle()); bigContent.setTextViewText(R.id.playlistcore_big_notification_album, notificationInfo.getAlbum()); bigContent.setTextViewText(R.id.playlistcore_big_notification_artist, notificationInfo.getArtist()); bigContent.setBitmap(R.id.playlistcore_big_notification_large_image, "setImageBitmap", notificationInfo.getLargeImage()); bigContent.setBitmap(R.id.playlistcore_big_notification_secondary_image, "setImageBitmap", notificationInfo.getSecondaryImage()); //Makes sure the play/pause, next, and previous are displayed correctly if (notificationInfo.getMediaState() != null) { updateBigNotificationMediaState(bigContent); } return bigContent; }