List of usage examples for android.widget RemoteViews setTextViewText
public void setTextViewText(int viewId, CharSequence text)
From source file:org.chromium.chrome.browser.media.ui.NotificationMediaPlaybackControls.java
private void updateNotification() { if (mService == null) return;//from w ww . j a 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.google.android.apps.mytracks.widgets.TrackWidgetProvider.java
/** * Updates total distance./* w ww.ja v a 2 s . c o m*/ * * @param context the context * @param remoteViews the remote views * @param tripStatistics the trip statistics * @param metricUnits true to use metric units */ private void updateTotalDistance(Context context, RemoteViews remoteViews, TripStatistics tripStatistics, boolean metricUnits) { String totalDistanceValue = tripStatistics == null ? context.getString(R.string.value_unknown) : StringUtils.formatDistanceNoM(context, tripStatistics.getTotalDistance(), metricUnits); remoteViews.setTextViewText(R.id.track_widget_total_distance_value, totalDistanceValue); }
From source file:org.appd.login.V_Connection.java
/** * Action Initial Synchronization/*w ww .j a v a 2 s .c o m*/ * @author Yamel Senih 24/04/2012, 00:14:42 * Carlos Parada 17/05/2012 Se Coloco la carga inicial automatica desde adempiere * @return void */ private void synchronize() { m_load = new InitialLoad(this) { @Override protected void onPostExecute(Object result) { super.onPostExecute(result); // Load Context loadContext(); } }; m_load.LoadSoapFromContext(getActivity()); if (!Env.isEnvLoad(getActivity())) { RemoteViews contentView = new RemoteViews(getActivity().getPackageName(), R.layout.v_progressdialog); contentView.setImageViewResource(R.id.iV_Synchronizing, R.drawable.syncserver_m); contentView.setTextViewText(R.id.tV_CurrentSinchronizing, getResources().getString(R.string.msg_CallingWebService)); contentView.setTextViewText(R.id.tV_Percentaje, "0%"); NotificationManager notify = Msg.notificationMsg(getActivity(), R.drawable.syncserver_h, "", 0, getActivity().getIntent(), contentView); m_load.setContentView(contentView); m_load.setM_NotificationManager(notify); m_load.execute(); } else { loadContext(); } }
From source file:com.chen.mail.widget.WidgetService.java
/** * Modifies the remoteView for the given account and folder. *///from w ww.j av a2 s . c o m public static void configureValidAccountWidget(Context context, RemoteViews remoteViews, int appWidgetId, Account account, final int folderType, final Uri folderUri, final Uri folderConversationListUri, String folderDisplayName, Class<?> widgetService) { remoteViews.setViewVisibility(R.id.widget_folder, View.VISIBLE); // If the folder or account name are empty, we don't want to overwrite the valid data that // had been saved previously. Since the launcher will save the state of the remote views // we should rely on the fact that valid data has been saved. But we should still log this, // as it shouldn't happen if (TextUtils.isEmpty(folderDisplayName) || TextUtils.isEmpty(account.name)) { LogUtils.e(LOG_TAG, new Error(), "Empty folder or account name. account: %s, folder: %s", account.name, folderDisplayName); } if (!TextUtils.isEmpty(folderDisplayName)) { remoteViews.setTextViewText(R.id.widget_folder, folderDisplayName); } remoteViews.setViewVisibility(R.id.widget_account_noflip, View.VISIBLE); if (!TextUtils.isEmpty(account.name)) { remoteViews.setTextViewText(R.id.widget_account_noflip, account.name); remoteViews.setTextViewText(R.id.widget_account, account.name); } remoteViews.setViewVisibility(R.id.widget_account_unread_flipper, View.GONE); remoteViews.setViewVisibility(R.id.widget_compose, View.VISIBLE); remoteViews.setViewVisibility(R.id.conversation_list, View.VISIBLE); remoteViews.setViewVisibility(R.id.empty_conversation_list, View.VISIBLE); remoteViews.setViewVisibility(R.id.widget_folder_not_synced, View.GONE); remoteViews.setViewVisibility(R.id.widget_configuration, View.GONE); remoteViews.setEmptyView(R.id.conversation_list, R.id.empty_conversation_list); WidgetService.configureValidWidgetIntents(context, remoteViews, appWidgetId, account, folderType, folderUri, folderConversationListUri, folderDisplayName, widgetService); }
From source file:com.abhijitvalluri.android.fitnotifications.setup.AppIntroActivity.java
private void addDemoSlide() { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); final boolean dismissPlaceholderNotif = preferences .getBoolean(getString(R.string.dismiss_placeholder_notif_key), false); final int placeholderNotifDismissDelayMillis = preferences .getInt(getString(R.string.placeholder_dismiss_delay_key), Constants.DEFAULT_DELAY_SECONDS) * 1000; final Handler handler = new Handler(); // Demo/*from www . j av a 2 s . c om*/ addSlide(new SimpleSlide.Builder().layout(R.layout.fragment_intro).title(R.string.intro_done_title) .description(R.string.intro_done_desc).image(R.drawable.intro_done).background(R.color.colorAccent) .backgroundDark(R.color.colorAccentDark).buttonCtaLabel(R.string.test_notification) .buttonCtaClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bundle newExtra = new Bundle(); NotificationCompat.Builder builder = new NotificationCompat.Builder(AppIntroActivity.this); String notificationText = "Sample notification subject"; String notificationBigText = "Sample notification body. This is where the details of the notification will be shown."; StringBuilder sb = new StringBuilder(); sb.append("[").append("example").append("] "); sb.append(notificationText); if (notificationBigText.length() > 0) { sb.append(" -- ").append(notificationBigText); } RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification); contentView.setTextViewText(R.id.customNotificationText, getString(R.string.placeholder_notification_text)); builder.setSmallIcon(R.drawable.ic_sms_white_24dp).setContentText(sb.toString()) .setExtras(newExtra).setContentTitle("Sample Notification Title") .setContent(contentView); // Creates an explicit intent for the SettingsActivity in the app Intent settingsIntent = new Intent(AppIntroActivity.this, SettingsActivity.class); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // the application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(AppIntroActivity.this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(SettingsActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(settingsIntent); PendingIntent settingsPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(settingsPendingIntent).setAutoCancel(true); ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID, builder.build()); Toast.makeText(AppIntroActivity.this, getString(R.string.test_notification_sent), Toast.LENGTH_LONG).show(); if (dismissPlaceholderNotif) { handler.postDelayed(new Runnable() { @Override public void run() { ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)) .cancel(NOTIFICATION_ID); } }, placeholderNotifDismissDelayMillis); } } }).build()); }
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;// ww w . jav a 2s.c o m 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:com.customprogrammingsolutions.MediaStreamer.MediaStreamerService.java
private void startNotification() { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout); contentView.setImageViewResource(R.id.notification_icon, R.drawable.notification_icon); contentView.setTextViewText(R.id.notification_title, getString(R.string.notification_title)); contentView.setTextViewText(R.id.notification_text, urlToStream); if (isPreparing) { contentView.setImageViewResource(R.id.media_state_indicator_icon, R.drawable.notification_playback_loading); contentView.setOnClickPendingIntent(R.id.media_state_indicator_icon, PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0)); } else if (isStreamError) { contentView.setImageViewResource(R.id.media_state_indicator_icon, R.drawable.notification_playback_error); contentView.setOnClickPendingIntent(R.id.media_state_indicator_icon, PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0)); } else if (isPlaying) { contentView.setImageViewResource(R.id.media_state_indicator_icon, R.drawable.stop_button); PendingIntent stopIntentPending = PendingIntent.getService(this, 0, new Intent(MainActivity.STOP_INTENT), PendingIntent.FLAG_CANCEL_CURRENT); contentView.setOnClickPendingIntent(R.id.media_state_indicator_icon, stopIntentPending); } else {//from w ww .j a v a 2 s . c o m contentView.setImageViewResource(R.id.media_state_indicator_icon, R.drawable.play_button); Intent playIntent = new Intent(MainActivity.PLAY_INTENT); playIntent.putExtra(MainActivity.URL_EXTRA, urlToStream); PendingIntent playIntentPending = PendingIntent.getService(this, 0, playIntent, PendingIntent.FLAG_CANCEL_CURRENT); contentView.setOnClickPendingIntent(R.id.media_state_indicator_icon, playIntentPending); } PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); contentView.setOnClickPendingIntent(R.id.notification_layout, contentIntent); PendingIntent killIntentPending = PendingIntent.getService(this, 0, new Intent(MainActivity.KILL_SERVICE_INTENT), 0); contentView.setOnClickPendingIntent(R.id.close_notification_icon, killIntentPending); builder.setContent(contentView); builder.setSmallIcon(R.drawable.notification_icon); builder.setAutoCancel(false); startForeground(NOTIFICATION_ID, builder.build()); }
From source file:com.maass.android.imgur_uploader.ImgurUpload.java
/** * Method to generate the remote view for the progress notification * //from ww w . j av a2 s .c o m * */ private RemoteViews generateProgressNotificationView(final int progress, final int total) { final RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification_layout_upload); contentView.setProgressBar(R.id.UploadProgress, total, progress, false); contentView.setTextViewText(R.id.text, "Uploaded " + progress + " of " + total + " bytes"); return contentView; }
From source file:com.android.mail.widget.WidgetService.java
/** * Modifies the remoteView for the given account and folder. */// w ww . j av a2 s . c o m public static void configureValidAccountWidget(Context context, RemoteViews remoteViews, int appWidgetId, Account account, final int folderType, final int folderCapabilities, final Uri folderUri, final Uri folderConversationListUri, String folderDisplayName, Class<?> widgetService) { remoteViews.setViewVisibility(R.id.widget_folder, View.VISIBLE); // If the folder or account name are empty, we don't want to overwrite the valid data that // had been saved previously. Since the launcher will save the state of the remote views // we should rely on the fact that valid data has been saved. But we should still log this, // as it shouldn't happen if (TextUtils.isEmpty(folderDisplayName) || TextUtils.isEmpty(account.getDisplayName())) { LogUtils.e(LOG_TAG, new Error(), "Empty folder or account name. account: %s, folder: %s", account.getEmailAddress(), folderDisplayName); } if (!TextUtils.isEmpty(folderDisplayName)) { remoteViews.setTextViewText(R.id.widget_folder, folderDisplayName); } remoteViews.setViewVisibility(R.id.widget_compose, View.VISIBLE); remoteViews.setViewVisibility(R.id.conversation_list, View.VISIBLE); remoteViews.setViewVisibility(R.id.empty_conversation_list, View.VISIBLE); remoteViews.setViewVisibility(R.id.widget_folder_not_synced, View.GONE); remoteViews.setViewVisibility(R.id.widget_configuration, View.GONE); remoteViews.setEmptyView(R.id.conversation_list, R.id.empty_conversation_list); WidgetService.configureValidWidgetIntents(context, remoteViews, appWidgetId, account, folderType, folderCapabilities, folderUri, folderConversationListUri, folderDisplayName, widgetService); }
From source file:github.daneren2005.dsub.util.Notifications.java
private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean expanded, boolean playing, boolean remote) { // Use the same text for the ticker and the expanded notification String title = song.getTitle(); String arist = song.getArtist(); String album = song.getAlbum(); // Set the album art. try {// www . ja v a 2 s.c om ImageLoader imageLoader = SubsonicActivity.getStaticImageLoader(context); Bitmap bitmap = null; if (imageLoader != null) { bitmap = imageLoader.getCachedImage(context, song, false); } if (bitmap == null) { // set default album art rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } else { rv.setImageViewBitmap(R.id.notification_image, bitmap); } } catch (Exception x) { Log.w(TAG, "Failed to get notification cover art", x); rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } // set the text for the notifications rv.setTextViewText(R.id.notification_title, title); rv.setTextViewText(R.id.notification_artist, arist); rv.setTextViewText(R.id.notification_album, album); boolean persistent = Util.getPreferences(context) .getBoolean(Constants.PREFERENCES_KEY_PERSISTENT_NOTIFICATION, false); if (persistent) { if (expanded) { rv.setImageViewResource(R.id.control_pause, playing ? R.drawable.notification_pause : R.drawable.notification_start); } else { rv.setImageViewResource(R.id.control_previous, playing ? R.drawable.notification_pause : R.drawable.notification_start); rv.setImageViewResource(R.id.control_pause, R.drawable.notification_forward); rv.setImageViewResource(R.id.control_next, R.drawable.notification_close); } } // Create actions for media buttons PendingIntent pendingIntent; int previous = 0, pause = 0, next = 0, close = 0; if (persistent && !expanded) { pause = R.id.control_previous; next = R.id.control_pause; close = R.id.control_next; } else { previous = R.id.control_previous; pause = R.id.control_pause; next = R.id.control_next; } if ((remote || persistent) && close == 0 && expanded) { close = R.id.notification_close; rv.setViewVisibility(close, View.VISIBLE); } if (previous > 0) { Intent prevIntent = new Intent("KEYCODE_MEDIA_PREVIOUS"); prevIntent.setComponent(new ComponentName(context, DownloadService.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(previous, pendingIntent); } if (pause > 0) { if (playing) { Intent pauseIntent = new Intent("KEYCODE_MEDIA_PLAY_PAUSE"); pauseIntent.setComponent(new ComponentName(context, DownloadService.class)); pauseIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)); pendingIntent = PendingIntent.getService(context, 0, pauseIntent, 0); rv.setOnClickPendingIntent(pause, pendingIntent); } else { Intent prevIntent = new Intent("KEYCODE_MEDIA_START"); prevIntent.setComponent(new ComponentName(context, DownloadService.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(pause, pendingIntent); } } if (next > 0) { Intent nextIntent = new Intent("KEYCODE_MEDIA_NEXT"); nextIntent.setComponent(new ComponentName(context, DownloadService.class)); nextIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT)); pendingIntent = PendingIntent.getService(context, 0, nextIntent, 0); rv.setOnClickPendingIntent(next, pendingIntent); } if (close > 0) { Intent prevIntent = new Intent("KEYCODE_MEDIA_STOP"); prevIntent.setComponent(new ComponentName(context, DownloadService.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_STOP)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(close, pendingIntent); } }