List of usage examples for android.widget RemoteViews setImageViewResource
public void setImageViewResource(int viewId, int srcId)
From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java
private void refreshAirplaneStatus(Context context, RemoteViews widget, boolean isAirplaneEnabled) { if (isAirplaneEnabled) { widget.setImageViewResource(R.id.airplane, R.drawable.status_airplane_on); } else {//from w w w. ja v a 2s.c om widget.setImageViewResource(R.id.airplane, R.drawable.status_airplane_off); } }
From source file:com.audiokernel.euphonyrmt.service.NotificationHandler.java
/** * This method constructs the notification 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. *///from w w w.ja v a 2 s . c o m private void buildBaseNotification(final RemoteViews resultView) { final PendingIntent closeAction = buildPendingIntent(MPDroidService.ACTION_STOP); final PendingIntent nextAction = buildPendingIntent(MPDControl.ACTION_NEXT); resultView.setViewVisibility(R.id.notificationClose, View.VISIBLE); resultView.setOnClickPendingIntent(R.id.notificationClose, closeAction); updateStatePaused(resultView); resultView.setOnClickPendingIntent(R.id.notificationNext, nextAction); resultView.setImageViewResource(R.id.notificationIcon, AlbumCoverDownloadListener.getNoCoverResource()); }
From source file:leoisasmendi.android.com.suricatepodcast.services.MediaPlayerService.java
private void updateWidgets(PlaybackStatus playbackStatus) { final RemoteViews view = new RemoteViews(getPackageName(), R.layout.podcast_widget_player); if (playbackStatus == PlaybackStatus.PLAYING) { view.setImageViewResource(R.id.widget_play, R.drawable.media_player_pause_24x24); } else if (playbackStatus == PlaybackStatus.PAUSED) { view.setImageViewResource(R.id.widget_play, R.drawable.media_player_play_24x24); }//from ww w . ja v a2s . c o m view.setTextViewText(R.id.widget_title, activeAudio.getTitle()); view.setTextViewText(R.id.widget_length, activeAudio.getDuration()); Picasso.with(getBaseContext()).setLoggingEnabled(true); Target target = new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { view.setImageViewBitmap(R.id.widget_thumbail, bitmap); } @Override public void onBitmapFailed(Drawable errorDrawable) { view.setImageViewResource(R.id.widget_thumbail, R.drawable.picture); } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { view.setImageViewResource(R.id.widget_thumbail, R.drawable.picture); } }; Picasso.with(getBaseContext()).load(activeAudio.getPoster()).into(target); // Push update for this widget to the home screen ComponentName thisWidget = new ComponentName(this, PodcastWidgetProvider.class); AppWidgetManager manager = AppWidgetManager.getInstance(this); manager.updateAppWidget(thisWidget, view); }
From source file:free.yhc.netmbuddy.model.NotiManager.java
private Notification buildNotificationICS(NotiType ntype, CharSequence videoTitle) { RemoteViews rv = new RemoteViews(Utils.getAppContext().getPackageName(), R.layout.player_notification); NotificationCompat.Builder nbldr = new NotificationCompat.Builder(Utils.getAppContext()); rv.setTextViewText(R.id.title, videoTitle); Intent intent = new Intent(Utils.getAppContext(), NotiManager.NotiIntentReceiver.class); intent.setAction(NOTI_INTENT_ACTION); intent.putExtra("type", ntype.name()); PendingIntent pi = PendingIntent.getBroadcast(Utils.getAppContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); rv.setImageViewResource(R.id.action, ntype.getIcon()); rv.setOnClickPendingIntent(R.id.action, pi); intent = new Intent(Utils.getAppContext(), NotiManager.NotiIntentReceiver.class); intent.setAction(NOTI_INTENT_STOP_PLAYER); pi = PendingIntent.getBroadcast(Utils.getAppContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); rv.setImageViewResource(R.id.stop, R.drawable.ic_media_stop); rv.setOnClickPendingIntent(R.id.stop, pi); intent = new Intent(Utils.getAppContext(), NotiManager.NotiIntentReceiver.class); intent.setAction(NOTI_INTENT_DELETE); PendingIntent piDelete = PendingIntent.getBroadcast(Utils.getAppContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); intent = new Intent(Utils.getAppContext(), YTMPActivity.class); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); PendingIntent piContent = PendingIntent.getActivity(Utils.getAppContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); nbldr.setContent(rv).setContentIntent(piContent).setDeleteIntent(piDelete).setAutoCancel(true) .setSmallIcon(ntype.getIcon()).setTicker(null); return nbldr.build(); }
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.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 w w w .j a va 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:st.brothas.mtgoxwidget.MtGoxWidgetProvider.java
private static void updateViews(RemoteViews views, MtGoxTickerData prevData, MtGoxTickerData newData, WidgetPreferences preferences) { String updated = "@ " + dateFormat.format(newData.getTimestamp()); String lastRounded = round(newData.getLast()); String lowRounded = round(newData.getLow()); String highRounded = round(newData.getHigh()); views.setTextViewText(R.id.appwidget_last, preferences.getCurrencyConversion().symbol + lastRounded); views.setTextColor(R.id.appwidget_updated, getColor(preferences.getColorMode(), WidgetColor.Normal)); if (newData.getTimestamp().before(getDateMinutesAgo(DATA_IS_CONSIDERED_OLD_AFTER_MINUTES))) { // Data is old, show it by "old" and "warning" colors views.setTextColor(R.id.appwidget_last, Color.GRAY); views.setTextColor(R.id.appwidget_updated, getColor(preferences.getColorMode(), WidgetColor.Warning)); } else if (prevData != null) { // We have previous data, compare to get the color views.setTextColor(R.id.appwidget_last, getColorFromValueChange(prevData.getLast(), newData.getLast(), preferences.getColorMode())); } else {/* ww w . j av a 2 s. c om*/ // No previous data, set standard color views.setTextColor(R.id.appwidget_last, getColor(preferences.getColorMode(), WidgetColor.StartValue)); } views.setTextViewText(R.id.appwidget_high, highRounded); views.setTextViewText(R.id.appwidget_low, lowRounded); views.setTextViewText(R.id.appwidget_updated, updated); //aws if (preferences.getCurrencyConversion().toString().contains("LTC_")) { views.setImageViewResource(R.id.appwidget_logo, R.drawable.lc_logo_32); } //else default which is bitcoin logo }
From source file:com.teclib.service.BootService.java
public void CustomNotification(int status) { if (status == 1) { //enrolement ok } else {/* w ww .j a v a 2s . c om*/ RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_enrolment); String strTitle = getString(R.string.app_name); String strText = getString(R.string.enrolement_string); Intent intent = new Intent(this, MainActivity.class); intent.putExtra("title", strTitle); intent.putExtra("text", strText); PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_white_stork).setTicker(getString(R.string.enrolement_string)) .setOngoing(true).setContentIntent(pIntent).setContent(remoteViews); remoteViews.setImageViewResource(R.id.imagenotileft, R.mipmap.ic_notification_enrolment); remoteViews.setTextViewText(R.id.title, getString(R.string.app_name)); remoteViews.setTextViewText(R.id.text, getString(R.string.enrolement_string)); NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationmanager.notify(1, builder.build()); } }
From source file:org.gaeproxy.GAEProxyService.java
/** Called when the activity is closed. */ @Override/*w ww. j av a 2s . c o m*/ public void onDestroy() { EasyTracker.getTracker().trackEvent("service", "stop", getVersionName(), 0L); if (mShutdownReceiver != null) { unregisterReceiver(mShutdownReceiver); mShutdownReceiver = null; } statusLock = true; stopForegroundCompat(1); notifyAlert(getString(R.string.forward_stop), getString(R.string.service_stopped), Notification.FLAG_AUTO_CANCEL); try { if (dnsServer != null) dnsServer.close(); } catch (Exception e) { Log.e(TAG, "DNS Server close unexpected"); } new Thread() { @Override public void run() { // Make sure the connection is closed, important here onDisconnect(); } }.start(); // for widget, maybe exception here try { RemoteViews views = new RemoteViews(getPackageName(), R.layout.gaeproxy_appwidget); views.setImageViewResource(R.id.serviceToggle, R.drawable.off); AppWidgetManager awm = AppWidgetManager.getInstance(this); awm.updateAppWidget(awm.getAppWidgetIds(new ComponentName(this, GAEProxyWidgetProvider.class)), views); } catch (Exception ignore) { // Nothing } Editor ed = settings.edit(); ed.putBoolean("isRunning", false); ed.putBoolean("isConnecting", false); ed.commit(); try { notificationManager.cancel(0); } catch (Exception ignore) { // Nothing } try { ProxySettings.resetProxy(this); } catch (Exception ignore) { // Nothing } super.onDestroy(); statusLock = false; markServiceStopped(); }
From source file:com.google.android.vending.expansion.downloader.impl.V4CustomNotificationBuilder.java
@Override public Notification build() { if (android.os.Build.VERSION.SDK_INT > 10) { // only matters for Honeycomb setOnlyAlertOnce(true);/*w w w. j a v a2s . com*/ } // Build the RemoteView object RemoteViews expandedView = new RemoteViews(mContext.getPackageName(), R.layout.status_bar_ongoing_event_progress_bar); expandedView.setTextViewText(R.id.title, mContentTitle); // look at strings expandedView.setViewVisibility(R.id.description, View.VISIBLE); expandedView.setTextViewText(R.id.description, Helpers.getDownloadProgressString(this.mCurrentBytes, mTotalBytes)); expandedView.setViewVisibility(R.id.progress_bar_frame, View.VISIBLE); expandedView.setProgressBar(R.id.progress_bar, (int) (mTotalBytes >> 8), (int) (mCurrentBytes >> 8), mTotalBytes <= 0); expandedView.setViewVisibility(R.id.time_remaining, View.VISIBLE); expandedView.setTextViewText(R.id.time_remaining, mContentInfo); expandedView.setTextViewText(R.id.progress_text, Helpers.getDownloadProgressPercent(mCurrentBytes, mTotalBytes)); expandedView.setImageViewResource(R.id.appIcon, mIcon); Notification n = super.build(); n.contentView = expandedView; return n; }