List of usage examples for android.widget RemoteViews RemoteViews
public RemoteViews(RemoteViews landscape, RemoteViews portrait)
From source file:org.tomahawk.tomahawk_android.services.PlaybackService.java
/** * Create or update an ongoing notification *///from w ww . j a v a 2s . com public void updateNotification() { if (mShowingNotification) { Log.d(TAG, "updateNotification"); String albumName = ""; String artistName = ""; if (getCurrentQuery().getAlbum() != null) { albumName = getCurrentQuery().getAlbum().getName(); } if (getCurrentQuery().getArtist() != null) { artistName = getCurrentQuery().getArtist().getName(); } Intent intent = new Intent(ACTION_PREVIOUS, null, PlaybackService.this, PlaybackService.class); PendingIntent previousPendingIntent = PendingIntent.getService(PlaybackService.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); intent = new Intent(ACTION_PLAYPAUSE, null, PlaybackService.this, PlaybackService.class); PendingIntent playPausePendingIntent = PendingIntent.getService(PlaybackService.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); intent = new Intent(ACTION_NEXT, null, PlaybackService.this, PlaybackService.class); PendingIntent nextPendingIntent = PendingIntent.getService(PlaybackService.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); intent = new Intent(ACTION_FAVORITE, null, PlaybackService.this, PlaybackService.class); PendingIntent favoritePendingIntent = PendingIntent.getService(PlaybackService.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); intent = new Intent(ACTION_EXIT, null, PlaybackService.this, PlaybackService.class); PendingIntent exitPendingIntent = PendingIntent.getService(PlaybackService.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { mSmallNotificationView = new RemoteViews(getPackageName(), R.layout.notification_small); } else { mSmallNotificationView = new RemoteViews(getPackageName(), R.layout.notification_small_compat); } mSmallNotificationView.setTextViewText(R.id.notification_small_textview, getCurrentQuery().getName()); if (TextUtils.isEmpty(albumName)) { mSmallNotificationView.setTextViewText(R.id.notification_small_textview2, artistName); } else { mSmallNotificationView.setTextViewText(R.id.notification_small_textview2, artistName + " - " + albumName); } if (isPlaying()) { mSmallNotificationView.setImageViewResource(R.id.notification_small_imageview_playpause, R.drawable.ic_player_pause_light); } else { mSmallNotificationView.setImageViewResource(R.id.notification_small_imageview_playpause, R.drawable.ic_player_play_light); } mSmallNotificationView.setOnClickPendingIntent(R.id.notification_small_imageview_playpause, playPausePendingIntent); mSmallNotificationView.setOnClickPendingIntent(R.id.notification_small_imageview_next, nextPendingIntent); mSmallNotificationView.setOnClickPendingIntent(R.id.notification_small_imageview_exit, exitPendingIntent); NotificationCompat.Builder builder = new NotificationCompat.Builder(PlaybackService.this) .setSmallIcon(R.drawable.ic_notification).setContentTitle(artistName) .setContentText(getCurrentQuery().getName()).setOngoing(true) .setPriority(NotificationCompat.PRIORITY_MAX).setContent(mSmallNotificationView); Intent notificationIntent = new Intent(PlaybackService.this, TomahawkMainActivity.class); intent.setAction(TomahawkMainActivity.SHOW_PLAYBACKFRAGMENT_ON_STARTUP); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent resultPendingIntent = PendingIntent.getActivity(PlaybackService.this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(resultPendingIntent); mNotification = builder.build(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { mLargeNotificationView = new RemoteViews(getPackageName(), R.layout.notification_large); mLargeNotificationView.setTextViewText(R.id.notification_large_textview, getCurrentQuery().getName()); mLargeNotificationView.setTextViewText(R.id.notification_large_textview2, artistName); mLargeNotificationView.setTextViewText(R.id.notification_large_textview3, albumName); if (isPlaying()) { mLargeNotificationView.setImageViewResource(R.id.notification_large_imageview_playpause, R.drawable.ic_player_pause_light); } else { mLargeNotificationView.setImageViewResource(R.id.notification_large_imageview_playpause, R.drawable.ic_player_play_light); } if (DatabaseHelper.get().isItemLoved(getCurrentQuery())) { mLargeNotificationView.setImageViewResource(R.id.notification_large_imageview_favorite, R.drawable.ic_action_favorites_underlined); } else { mLargeNotificationView.setImageViewResource(R.id.notification_large_imageview_favorite, R.drawable.ic_action_favorites); } mLargeNotificationView.setOnClickPendingIntent(R.id.notification_large_imageview_previous, previousPendingIntent); mLargeNotificationView.setOnClickPendingIntent(R.id.notification_large_imageview_playpause, playPausePendingIntent); mLargeNotificationView.setOnClickPendingIntent(R.id.notification_large_imageview_next, nextPendingIntent); mLargeNotificationView.setOnClickPendingIntent(R.id.notification_large_imageview_favorite, favoritePendingIntent); mLargeNotificationView.setOnClickPendingIntent(R.id.notification_large_imageview_exit, exitPendingIntent); mNotification.bigContentView = mLargeNotificationView; new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { ImageUtils.loadImageIntoNotification(TomahawkApp.getContext(), getCurrentQuery().getImage(), mSmallNotificationView, R.id.notification_small_imageview_albumart, PLAYBACKSERVICE_NOTIFICATION_ID, mNotification, Image.getSmallImageSize(), getCurrentQuery().hasArtistImage()); ImageUtils.loadImageIntoNotification(TomahawkApp.getContext(), getCurrentQuery().getImage(), mLargeNotificationView, R.id.notification_large_imageview_albumart, PLAYBACKSERVICE_NOTIFICATION_ID, mNotification, Image.getSmallImageSize(), getCurrentQuery().hasArtistImage()); } }); } startForeground(PLAYBACKSERVICE_NOTIFICATION_ID, mNotification); } }
From source file:br.com.viniciuscr.notification2android.mediaPlayer.MediaPlaybackService.java
private void updateNotification() { RemoteViews views = new RemoteViews(getPackageName(), R.layout.statusbar); views.setImageViewResource(R.id.icon, R.drawable.stat_notify_musicplayer); if (getAudioId() < 0) { // streaming views.setTextViewText(R.id.trackname, getPath()); views.setTextViewText(R.id.artistalbum, null); } else {/*from www .j a va 2s.c om*/ String artist = getArtistName(); views.setTextViewText(R.id.trackname, getTrackName()); if (artist == null || artist.equals(MediaStore.UNKNOWN_STRING)) { artist = getString(R.string.unknown_artist_name); } String album = getAlbumName(); if (album == null || album.equals(MediaStore.UNKNOWN_STRING)) { album = getString(R.string.unknown_album_name); } views.setTextViewText(R.id.artistalbum, getString(R.string.notification_artist_album, artist, album)); } Notification status = new Notification(); status.contentView = views; status.flags |= Notification.FLAG_ONGOING_EVENT; status.icon = R.drawable.stat_notify_musicplayer; status.contentIntent = PendingIntent.getActivity(this, 0, new Intent("com.android.music.PLAYBACK_VIEWER").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0); startForeground(PLAYBACKSERVICE_STATUS, status); }
From source file:com.zertinteractive.wallpaper.MainActivity.java
@SuppressLint("NewApi") public void setNotification() { String ns = Context.NOTIFICATION_SERVICE; NotificationManager notificationManager = (NotificationManager) getSystemService(ns); @SuppressWarnings("deprecation") Notification notification = new Notification(R.drawable.ic_launcher, "Ticker Text", System.currentTimeMillis()); RemoteViews notificationView = new RemoteViews(getPackageName(), R.layout.romantic_wallpaper); //the intent that is started when the notification is clicked (works) Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.contentView = notificationView; notification.contentIntent = pendingNotificationIntent; // notification.flags |= Notification.FLAG_NO_CLEAR; notification.flags = Notification.FLAG_LOCAL_ONLY; //this is the intent that is supposed to be called when the button is clicked Intent switchIntent = new Intent(this, MainActivity.class); PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(this, 0, switchIntent, 0); ////from w w w . j a v a 2 s . c o m notificationView.setOnClickPendingIntent(R.id.download_notification, pendingSwitchIntent); notificationManager.notify(1, notification); }
From source file:com.xperia64.timidityae.MusicService.java
public void updateNotification(String title, boolean paused) { //System.out.println("Updating notification"); remoteViews = new RemoteViews(getPackageName(), R.layout.music_notification); remoteViews.setTextViewText(R.id.titley, currTitle); remoteViews.setImageViewResource(R.id.notPause, (paused) ? R.drawable.ic_media_play : R.drawable.ic_media_pause); // Previous/*from ww w. java 2s . c o m*/ Intent new_intent = new Intent(); //new_intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); new_intent.setAction(getResources().getString(R.string.msrv_rec)); new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 4); PendingIntent pendingNotificationIntent = PendingIntent.getBroadcast(this, 1, new_intent, 0); remoteViews.setOnClickPendingIntent(R.id.notPrev, pendingNotificationIntent); // Play/Pause new_intent = new Intent(); //new_intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); new_intent.setAction(getResources().getString(R.string.msrv_rec)); new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 2); pendingNotificationIntent = PendingIntent.getBroadcast(this, 2, new_intent, 0); remoteViews.setOnClickPendingIntent(R.id.notPause, pendingNotificationIntent); // Next new_intent = new Intent(); //new_intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); new_intent.setAction(getResources().getString(R.string.msrv_rec)); new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 3); pendingNotificationIntent = PendingIntent.getBroadcast(this, 3, new_intent, 0); remoteViews.setOnClickPendingIntent(R.id.notNext, pendingNotificationIntent); // Stop new_intent = new Intent(); //new_intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); new_intent.setAction(getResources().getString(R.string.msrv_rec)); new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 5); pendingNotificationIntent = PendingIntent.getBroadcast(this, 4, new_intent, 0); remoteViews.setOnClickPendingIntent(R.id.notStop, pendingNotificationIntent); final Intent emptyIntent = new Intent(this, TimidityActivity.class); //emptyIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); PendingIntent pendingIntent = PendingIntent.getActivity(this, 5, emptyIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setContentTitle(getResources().getString(R.string.app_name)).setContentText(currTitle) .setContentIntent(pendingIntent).setContent(remoteViews); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) mBuilder.setSmallIcon(R.drawable.ic_lol); else mBuilder.setSmallIcon(R.drawable.ic_launcher); n = mBuilder.build(); n.flags |= Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_ONGOING_EVENT; if (!foreground) { foreground = true; startForeground(13901858, n); if (!wl.isHeld()) wl.acquire(); TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); if (mgr != null) { mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); } } else { if (!wl.isHeld()) wl.acquire(); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(13901858, n); } if (shouldDoWidget) { Intent intent = new Intent(this, TimidityAEWidgetProvider.class); //Intent intent = new Intent("Ilikepotatoes"); intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); // Use an array and EXTRA_APPWIDGET_IDS instead of AppWidgetManager.EXTRA_APPWIDGET_ID, // since it seems the onUpdate() is only fired on that: //intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids); intent.putExtra("com.xperia64.timidityae.timidityaewidgetprovider.paused", paused); intent.putExtra("com.xperia64.timidityae.timidityaewidgetprovider.title", currTitle); intent.putExtra("com.xperia64.timidityae.timidityaewidgetprovider.onlyart", true); sendBroadcast(intent); } }
From source file:com.andrew.apolloMod.service.ApolloService.java
public RemoteViews getNotificationViewApi8() { RemoteViews views = new RemoteViews(getPackageName(), R.layout.status_bar_old); Bitmap b = getAlbumBitmap();/* w w w . j ava 2 s . c o m*/ if (b != null) { views.setViewVisibility(R.id.icon, View.VISIBLE); views.setImageViewBitmap(R.id.icon, b); } else { views.setViewVisibility(R.id.icon, View.GONE); } if (getAudioId() < 0) { // streaming views.setTextViewText(R.id.trackname, getPath()); views.setTextViewText(R.id.artistalbum, null); } else { String artist = getArtistName(); String album = getAlbumName(); views.setTextViewText(R.id.trackname, getTrackName()); views.setTextViewText(R.id.artistalbum, artist + " - " + album); } return views; }
From source file:com.andrew.apolloMod.service.ApolloService.java
/** Return notification remote views * // ww w . j a v a 2 s . co m * @return [views, bigViews] */ public RemoteViews[] getNotificationViews() { Bitmap b = getAlbumBitmap(); RemoteViews bigViews = new RemoteViews(getPackageName(), R.layout.status_bar_expanded); RemoteViews views = new RemoteViews(getPackageName(), R.layout.status_bar); if (b != null) { bigViews.setImageViewBitmap(R.id.status_bar_album_art, b); views.setViewVisibility(R.id.status_bar_icon, View.GONE); views.setViewVisibility(R.id.status_bar_album_art, View.VISIBLE); views.setImageViewBitmap(R.id.status_bar_album_art, b); } else { views.setViewVisibility(R.id.status_bar_icon, View.VISIBLE); views.setViewVisibility(R.id.status_bar_album_art, View.GONE); } ComponentName rec = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.putExtra(CMDNOTIF, 1); mediaButtonIntent.setComponent(rec); KeyEvent mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE); mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey); PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 1, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.status_bar_play, mediaPendingIntent); bigViews.setOnClickPendingIntent(R.id.status_bar_play, mediaPendingIntent); mediaButtonIntent.putExtra(CMDNOTIF, 2); mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT); mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey); mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 2, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.status_bar_next, mediaPendingIntent); bigViews.setOnClickPendingIntent(R.id.status_bar_next, mediaPendingIntent); mediaButtonIntent.putExtra(CMDNOTIF, 4); mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS); mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey); mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 4, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT); bigViews.setOnClickPendingIntent(R.id.status_bar_prev, mediaPendingIntent); mediaButtonIntent.putExtra(CMDNOTIF, 3); mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_STOP); mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey); mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 3, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.status_bar_collapse, mediaPendingIntent); bigViews.setOnClickPendingIntent(R.id.status_bar_collapse, mediaPendingIntent); views.setImageViewResource(R.id.status_bar_play, R.drawable.apollo_holo_dark_pause); bigViews.setImageViewResource(R.id.status_bar_play, R.drawable.apollo_holo_dark_pause); views.setTextViewText(R.id.status_bar_track_name, getTrackName()); bigViews.setTextViewText(R.id.status_bar_track_name, getTrackName()); views.setTextViewText(R.id.status_bar_artist_name, getArtistName()); bigViews.setTextViewText(R.id.status_bar_artist_name, getArtistName()); bigViews.setTextViewText(R.id.status_bar_album_name, getAlbumName()); return new RemoteViews[] { views, bigViews }; }
From source file:com.wm.remusic.service.MediaService.java
private Notification getNotification() { RemoteViews remoteViews;//ww w. j ava 2s. c o m final int PAUSE_FLAG = 0x1; final int NEXT_FLAG = 0x2; final int STOP_FLAG = 0x3; final String albumName = getAlbumName(); final String artistName = getArtistName(); final boolean isPlaying = isPlaying(); remoteViews = new RemoteViews(this.getPackageName(), R.layout.notification); String text = TextUtils.isEmpty(albumName) ? artistName : artistName + " - " + albumName; remoteViews.setTextViewText(R.id.title, getTrackName()); remoteViews.setTextViewText(R.id.text, text); //action? ?flag?? Intent pauseIntent = new Intent(TOGGLEPAUSE_ACTION); pauseIntent.putExtra("FLAG", PAUSE_FLAG); PendingIntent pausePIntent = PendingIntent.getBroadcast(this, 0, pauseIntent, 0); remoteViews.setImageViewResource(R.id.iv_pause, isPlaying ? R.drawable.note_btn_pause : R.drawable.note_btn_play); remoteViews.setOnClickPendingIntent(R.id.iv_pause, pausePIntent); Intent nextIntent = new Intent(NEXT_ACTION); nextIntent.putExtra("FLAG", NEXT_FLAG); PendingIntent nextPIntent = PendingIntent.getBroadcast(this, 0, nextIntent, 0); remoteViews.setOnClickPendingIntent(R.id.iv_next, nextPIntent); Intent preIntent = new Intent(STOP_ACTION); preIntent.putExtra("FLAG", STOP_FLAG); PendingIntent prePIntent = PendingIntent.getBroadcast(this, 0, preIntent, 0); remoteViews.setOnClickPendingIntent(R.id.iv_stop, prePIntent); // PendingIntent pendingIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, // new Intent(this.getApplicationContext(), PlayingActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); final Intent nowPlayingIntent = new Intent(); //nowPlayingIntent.setAction("com.wm.remusic.LAUNCH_NOW_PLAYING_ACTION"); nowPlayingIntent .setComponent(new ComponentName("com.wm.remusic", "com.wm.remusic.activity.PlayingActivity")); nowPlayingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent clickIntent = PendingIntent.getBroadcast(this, 0, nowPlayingIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent click = PendingIntent.getActivity(this, 0, nowPlayingIntent, PendingIntent.FLAG_UPDATE_CURRENT); final Bitmap bitmap = ImageUtils.getArtworkQuick(this, getAlbumId(), 160, 160); if (bitmap != null) { remoteViews.setImageViewBitmap(R.id.image, bitmap); // remoteViews.setImageViewUri(R.id.image, MusicUtils.getAlbumUri(this, getAudioId())); mNoBit = null; } else if (!isTrackLocal()) { if (mNoBit != null) { remoteViews.setImageViewBitmap(R.id.image, mNoBit); mNoBit = null; } else { Uri uri = null; if (getAlbumPath() != null) { try { uri = Uri.parse(getAlbumPath()); } catch (Exception e) { e.printStackTrace(); } } if (getAlbumPath() == null || uri == null) { mNoBit = BitmapFactory.decodeResource(getResources(), R.drawable.placeholder_disk_210); updateNotification(); } else { ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(uri) .setProgressiveRenderingEnabled(true).build(); ImagePipeline imagePipeline = Fresco.getImagePipeline(); DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline .fetchDecodedImage(imageRequest, MediaService.this); dataSource.subscribe(new BaseBitmapDataSubscriber() { @Override public void onNewResultImpl(@Nullable Bitmap bitmap) { // You can use the bitmap in only limited ways // No need to do any cleanup. if (bitmap != null) { mNoBit = bitmap; } updateNotification(); } @Override public void onFailureImpl(DataSource dataSource) { // No cleanup required here. mNoBit = BitmapFactory.decodeResource(getResources(), R.drawable.placeholder_disk_210); updateNotification(); } }, CallerThreadExecutor.getInstance()); } } } else { remoteViews.setImageViewResource(R.id.image, R.drawable.placeholder_disk_210); } if (mNotificationPostTime == 0) { mNotificationPostTime = System.currentTimeMillis(); } if (mNotification == null) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContent(remoteViews) .setSmallIcon(R.drawable.ic_notification).setContentIntent(click) .setWhen(mNotificationPostTime); if (CommonUtils.isJellyBeanMR1()) { builder.setShowWhen(false); } mNotification = builder.build(); } else { mNotification.contentView = remoteViews; } return mNotification; }
From source file:com.av.remusic.service.MediaService.java
private Notification getNotification() { RemoteViews remoteViews;/*from w w w . j av a2 s.co m*/ final int PAUSE_FLAG = 0x1; final int NEXT_FLAG = 0x2; final int STOP_FLAG = 0x3; final String albumName = getAlbumName(); final String artistName = getArtistName(); final boolean isPlaying = isPlaying(); remoteViews = new RemoteViews(this.getPackageName(), R.layout.notification); String text = TextUtils.isEmpty(albumName) ? artistName : artistName + " - " + albumName; remoteViews.setTextViewText(R.id.title, getTrackName()); remoteViews.setTextViewText(R.id.text, text); //action? ?flag?? Intent pauseIntent = new Intent(TOGGLEPAUSE_ACTION); pauseIntent.putExtra("FLAG", PAUSE_FLAG); PendingIntent pausePIntent = PendingIntent.getBroadcast(this, 0, pauseIntent, 0); remoteViews.setImageViewResource(R.id.iv_pause, isPlaying ? R.drawable.note_btn_pause : R.drawable.note_btn_play); remoteViews.setOnClickPendingIntent(R.id.iv_pause, pausePIntent); Intent nextIntent = new Intent(NEXT_ACTION); nextIntent.putExtra("FLAG", NEXT_FLAG); PendingIntent nextPIntent = PendingIntent.getBroadcast(this, 0, nextIntent, 0); remoteViews.setOnClickPendingIntent(R.id.iv_next, nextPIntent); Intent preIntent = new Intent(STOP_ACTION); preIntent.putExtra("FLAG", STOP_FLAG); PendingIntent prePIntent = PendingIntent.getBroadcast(this, 0, preIntent, 0); remoteViews.setOnClickPendingIntent(R.id.iv_stop, prePIntent); // PendingIntent pendingIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, // new Intent(this.getApplicationContext(), PlayingActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); final Intent nowPlayingIntent = new Intent(); //nowPlayingIntent.setAction("com.av.remusic.LAUNCH_NOW_PLAYING_ACTION"); nowPlayingIntent .setComponent(new ComponentName("com.av.remusic", "com.av.remusic.activity.PlayingActivity")); nowPlayingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent clickIntent = PendingIntent.getBroadcast(this, 0, nowPlayingIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent click = PendingIntent.getActivity(this, 0, nowPlayingIntent, PendingIntent.FLAG_UPDATE_CURRENT); final Bitmap bitmap = ImageUtils.getArtworkQuick(this, getAlbumId(), 160, 160); if (bitmap != null) { remoteViews.setImageViewBitmap(R.id.image, bitmap); // remoteViews.setImageViewUri(R.id.image, MusicUtils.getAlbumUri(this, getAudioId())); mNoBit = null; } else if (!isTrackLocal()) { if (mNoBit != null) { remoteViews.setImageViewBitmap(R.id.image, mNoBit); mNoBit = null; } else { Uri uri = null; if (getAlbumPath() != null) { try { uri = Uri.parse(getAlbumPath()); } catch (Exception e) { e.printStackTrace(); } } if (getAlbumPath() == null || uri == null) { mNoBit = BitmapFactory.decodeResource(getResources(), R.drawable.placeholder_disk_210); updateNotification(); } else { ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(uri) .setProgressiveRenderingEnabled(true).build(); ImagePipeline imagePipeline = Fresco.getImagePipeline(); DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline .fetchDecodedImage(imageRequest, MediaService.this); dataSource.subscribe(new BaseBitmapDataSubscriber() { @Override public void onNewResultImpl(@Nullable Bitmap bitmap) { // You can use the bitmap in only limited ways // No need to do any cleanup. if (bitmap != null) { mNoBit = bitmap; } updateNotification(); } @Override public void onFailureImpl(DataSource dataSource) { // No cleanup required here. mNoBit = BitmapFactory.decodeResource(getResources(), R.drawable.placeholder_disk_210); updateNotification(); } }, CallerThreadExecutor.getInstance()); } } } else { remoteViews.setImageViewResource(R.id.image, R.drawable.placeholder_disk_210); } if (mNotificationPostTime == 0) { mNotificationPostTime = System.currentTimeMillis(); } if (mNotification == null) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContent(remoteViews) .setSmallIcon(R.drawable.ic_notification).setContentIntent(click) .setWhen(mNotificationPostTime); if (CommonUtils.isJellyBeanMR1()) { builder.setShowWhen(false); } mNotification = builder.build(); } else { mNotification.contentView = remoteViews; } return mNotification; }
From source file:com.cloud9.netmusic.service.MediaService.java
private Notification getNotification() { RemoteViews remoteViews;/*w ww . j a v a 2 s . co m*/ final int PAUSE_FLAG = 0x1; final int NEXT_FLAG = 0x2; final int STOP_FLAG = 0x3; final String albumName = getAlbumName(); final String artistName = getArtistName(); final boolean isPlaying = isPlaying(); remoteViews = new RemoteViews(this.getPackageName(), R.layout.notification); String text = TextUtils.isEmpty(albumName) ? artistName : artistName + " - " + albumName; remoteViews.setTextViewText(R.id.title, getTrackName()); remoteViews.setTextViewText(R.id.text, text); //action? ?flag?? Intent pauseIntent = new Intent(TOGGLEPAUSE_ACTION); pauseIntent.putExtra("FLAG", PAUSE_FLAG); PendingIntent pausePIntent = PendingIntent.getBroadcast(this, 0, pauseIntent, 0); remoteViews.setImageViewResource(R.id.iv_pause, isPlaying ? R.drawable.note_btn_pause : R.drawable.note_btn_play); remoteViews.setOnClickPendingIntent(R.id.iv_pause, pausePIntent); Intent nextIntent = new Intent(NEXT_ACTION); nextIntent.putExtra("FLAG", NEXT_FLAG); PendingIntent nextPIntent = PendingIntent.getBroadcast(this, 0, nextIntent, 0); remoteViews.setOnClickPendingIntent(R.id.iv_next, nextPIntent); Intent preIntent = new Intent(STOP_ACTION); preIntent.putExtra("FLAG", STOP_FLAG); PendingIntent prePIntent = PendingIntent.getBroadcast(this, 0, preIntent, 0); remoteViews.setOnClickPendingIntent(R.id.iv_stop, prePIntent); // PendingIntent pendingIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, // new Intent(this.getApplicationContext(), PlayingActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); final Intent nowPlayingIntent = new Intent(); //nowPlayingIntent.setAction("com.cloud9.netmusic.LAUNCH_NOW_PLAYING_ACTION"); nowPlayingIntent.setComponent(new ComponentName("com.wm.remusic", "PlayingActivity")); nowPlayingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent clickIntent = PendingIntent.getBroadcast(this, 0, nowPlayingIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent click = PendingIntent.getActivity(this, 0, nowPlayingIntent, PendingIntent.FLAG_UPDATE_CURRENT); final Bitmap bitmap = ImageUtils.getArtworkQuick(this, getAlbumId(), 160, 160); if (bitmap != null) { remoteViews.setImageViewBitmap(R.id.image, bitmap); // remoteViews.setImageViewUri(R.id.image, MusicUtils.getAlbumUri(this, getAudioId())); mNoBit = null; } else if (!isTrackLocal()) { if (mNoBit != null) { remoteViews.setImageViewBitmap(R.id.image, mNoBit); mNoBit = null; } else { Uri uri = null; if (getAlbumPath() != null) { try { uri = Uri.parse(getAlbumPath()); } catch (Exception e) { e.printStackTrace(); } } if (getAlbumPath() == null || uri == null) { mNoBit = BitmapFactory.decodeResource(getResources(), R.drawable.placeholder_disk_210); updateNotification(); } else { ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(uri) .setProgressiveRenderingEnabled(true).build(); ImagePipeline imagePipeline = Fresco.getImagePipeline(); DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline .fetchDecodedImage(imageRequest, MediaService.this); dataSource.subscribe(new BaseBitmapDataSubscriber() { @Override public void onNewResultImpl(@Nullable Bitmap bitmap) { // You can use the bitmap in only limited ways // No need to do any cleanup. if (bitmap != null) { mNoBit = bitmap; } updateNotification(); } @Override public void onFailureImpl(DataSource dataSource) { // No cleanup required here. mNoBit = BitmapFactory.decodeResource(getResources(), R.drawable.placeholder_disk_210); updateNotification(); } }, CallerThreadExecutor.getInstance()); } } } else { remoteViews.setImageViewResource(R.id.image, R.drawable.placeholder_disk_210); } if (mNotificationPostTime == 0) { mNotificationPostTime = System.currentTimeMillis(); } if (mNotification == null) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContent(remoteViews) .setSmallIcon(R.drawable.ic_notification).setContentIntent(click) .setWhen(mNotificationPostTime); if (CommonUtils.isJellyBeanMR1()) { builder.setShowWhen(false); } mNotification = builder.build(); } else { mNotification.contentView = remoteViews; } return mNotification; }
From source file:org.moire.ultrasonic.service.DownloadServiceImpl.java
@SuppressWarnings("IconColors") private Notification buildForegroundNotification() { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_stat_ultrasonic); builder.setAutoCancel(false);/*from ww w . ja v a2 s. co m*/ builder.setOngoing(true); builder.setWhen(System.currentTimeMillis()); RemoteViews contentView = new RemoteViews(this.getPackageName(), R.layout.notification); Util.linkButtons(this, contentView, false); RemoteViews bigView = new RemoteViews(this.getPackageName(), R.layout.notification_large); Util.linkButtons(this, bigView, false); builder.setContent(contentView); Intent notificationIntent = new Intent(this, DownloadActivity.class); builder.setContentIntent(PendingIntent.getActivity(this, 0, notificationIntent, 0)); if (playerState == PlayerState.PAUSED || playerState == PlayerState.IDLE) { contentView.setImageViewResource(R.id.control_play, R.drawable.media_start_normal_dark); bigView.setImageViewResource(R.id.control_play, R.drawable.media_start_normal_dark); } else if (playerState == PlayerState.STARTED) { contentView.setImageViewResource(R.id.control_play, R.drawable.media_pause_normal_dark); bigView.setImageViewResource(R.id.control_play, R.drawable.media_pause_normal_dark); } final Entry song = currentPlaying.getSong(); final String title = song.getTitle(); final String text = song.getArtist(); final String album = song.getAlbum(); final int imageSize = Util.getNotificationImageSize(this); try { final Bitmap nowPlayingImage = FileUtil.getAlbumArtBitmap(this, currentPlaying.getSong(), imageSize, true); if (nowPlayingImage == null) { contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); bigView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } else { contentView.setImageViewBitmap(R.id.notification_image, nowPlayingImage); bigView.setImageViewBitmap(R.id.notification_image, nowPlayingImage); } } catch (Exception x) { Log.w(TAG, "Failed to get notification cover art", x); contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); bigView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } contentView.setTextViewText(R.id.trackname, title); bigView.setTextViewText(R.id.trackname, title); contentView.setTextViewText(R.id.artist, text); bigView.setTextViewText(R.id.artist, text); contentView.setTextViewText(R.id.album, album); bigView.setTextViewText(R.id.album, album); Notification notification = builder.build(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { notification.bigContentView = bigView; } return notification; }