List of usage examples for android.widget RemoteViews setImageViewResource
public void setImageViewResource(int viewId, int srcId)
From source file:org.gaeproxy.GAEProxyService.java
public void handleCommand(Intent intent) { if (intent == null) { stopSelf();/*w w w . ja va 2 s . c o m*/ return; } proxyType = settings.getString("proxyType", "GAE"); sitekey = settings.getString("sitekey", ""); try { port = Integer.valueOf(settings.getString("port", "1984")); } catch (NumberFormatException ex) { port = 1984; } isGlobalProxy = settings.getBoolean("isGlobalProxy", false); isGFWList = settings.getBoolean("isGFWList", false); isBypassApps = settings.getBoolean("isBypassApps", false); if (!parseProxyURL(settings.getString("proxy", "proxyofmax.appspot.com"))) { stopSelf(); return; } if (!"GAE".equals(proxyType) && !"PaaS".equals(proxyType)) { proxyType = "GAE"; } if ("fetch.py".equals(appPath)) appPath = "2"; Log.e(TAG, "Proxy: " + appId + " " + appPath); Log.e(TAG, "Local Port: " + port); new Thread(new Runnable() { @Override public void run() { handler.sendEmptyMessage(MSG_CONNECT_START); Log.d(TAG, "IPTABLES: " + Utils.getIptables()); // Test for Redirect Support hasRedirectSupport = Utils.getHasRedirectSupport(); if (handleConnection()) { // Connection and forward successful notifyAlert(getString(R.string.forward_success), getString(R.string.service_running)); handler.sendEmptyMessageDelayed(MSG_CONNECT_SUCCESS, 500); // for widget, maybe exception here try { RemoteViews views = new RemoteViews(getPackageName(), R.layout.gaeproxy_appwidget); views.setImageViewResource(R.id.serviceToggle, R.drawable.on); AppWidgetManager awm = AppWidgetManager.getInstance(GAEProxyService.this); awm.updateAppWidget( awm.getAppWidgetIds( new ComponentName(GAEProxyService.this, GAEProxyWidgetProvider.class)), views); } catch (Exception ignore) { // Nothing } } else { // Connection or forward unsuccessful notifyAlert(getString(R.string.forward_fail), getString(R.string.service_failed)); stopSelf(); handler.sendEmptyMessageDelayed(MSG_CONNECT_FAIL, 500); } handler.sendEmptyMessageDelayed(MSG_CONNECT_FINISH, 500); } }).start(); markServiceStarted(); }
From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java
private void refreshWifiStatus(Context context, RemoteViews widget) { mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); int wifiStatus = mWifiManager.getWifiState(); if (WifiManager.WIFI_STATE_ENABLED == wifiStatus || WifiManager.WIFI_STATE_ENABLING == wifiStatus) { widget.setImageViewResource(R.id.wifi, R.drawable.status_wifi_on); } else {//from ww w.jav a 2 s. c om widget.setImageViewResource(R.id.wifi, R.drawable.status_wifi_off); } }
From source file:org.openbitcoinwidget.WidgetProvider.java
private static void updateViews(RemoteViews views, TickerData prevData, TickerData newData, WidgetPreferences preferences) { String updated = "@ " + dateFormat.format(newData.getTimestamp()); String lastRounded = round(newData.getLast(), preferences); String lowRounded = round(newData.getLow(), preferences); String highRounded = round(newData.getHigh(), preferences); 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 {//from w w w. j av a 2 s . co m // 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); // Set Litecoin logo if that is the chosen currency. switch (preferences.getCurrencyConversion().digitalCurrency) { case LITECOIN: views.setImageViewResource(R.id.appwidget_logo, R.drawable.logo); break; // The Bitcoin logo is default in the layout. } }
From source file:air.com.snagfilms.cast.chromecast.notifications.VideoCastNotificationService.java
private void addPendingIntents(RemoteViews rv, boolean isPlaying, MediaInfo info) { Intent playbackIntent = new Intent(ACTION_TOGGLE_PLAYBACK); playbackIntent.setPackage(getPackageName()); PendingIntent playbackPendingIntent = PendingIntent.getBroadcast(this, 0, playbackIntent, 0); Intent stopIntent = new Intent(ACTION_STOP); stopIntent.setPackage(getPackageName()); PendingIntent stopPendingIntent = PendingIntent.getBroadcast(this, 0, stopIntent, 0); rv.setOnClickPendingIntent(R.id.playPauseView, playbackPendingIntent); rv.setOnClickPendingIntent(R.id.removeView, stopPendingIntent); if (isPlaying) { if (info.getStreamType() == MediaInfo.STREAM_TYPE_LIVE) { rv.setImageViewResource(R.id.playPauseView, R.drawable.ic_av_stop_sm_dark); } else {//from w w w .j ava 2 s. c o m rv.setImageViewResource(R.id.playPauseView, R.drawable.ic_av_pause_sm_dark); } } else { rv.setImageViewResource(R.id.playPauseView, R.drawable.ic_av_play_sm_dark); } }
From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java
private void refreshBtStatus(Context context, RemoteViews widget) { bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE); bluetoothApapter = bluetoothManager.getAdapter(); if (bluetoothApapter != null) { int btStatus = bluetoothApapter.getState(); if (BluetoothAdapter.STATE_ON == btStatus || BluetoothAdapter.STATE_TURNING_ON == btStatus) { widget.setImageViewResource(R.id.bt, R.drawable.status_bt_on); } else {// w w w .jav a 2s.c o m widget.setImageViewResource(R.id.bt, R.drawable.ic_qs_bluetooth_off_sprd); } } }
From source file:com.mb.android.playbackmediator.notification.VideoCastNotificationService.java
private void addPendingIntents(RemoteViews rv, boolean isPlaying, SessionInfoDto info) { Intent playbackIntent = new Intent(ACTION_TOGGLE_PLAYBACK); playbackIntent.setPackage(getPackageName()); PendingIntent playbackPendingIntent = PendingIntent.getBroadcast(this, 0, playbackIntent, 0); Intent stopIntent = new Intent(ACTION_STOP); stopIntent.setPackage(getPackageName()); PendingIntent stopPendingIntent = PendingIntent.getBroadcast(this, 0, stopIntent, 0); rv.setOnClickPendingIntent(R.id.playPauseView, playbackPendingIntent); rv.setOnClickPendingIntent(R.id.removeView, stopPendingIntent); if (isPlaying) { if (info.getNowPlayingItem().getRunTimeTicks() == null) { rv.setImageViewResource(R.id.playPauseView, R.drawable.ic_av_stop_sm_dark); } else {/* ww w.j ava 2s . co m*/ rv.setImageViewResource(R.id.playPauseView, R.drawable.ic_av_pause_sm_dark); } } else { rv.setImageViewResource(R.id.playPauseView, R.drawable.ic_av_play_sm_dark); } }
From source file:github.madmarty.madsonic.util.Util.java
private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean playing) { // 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 {/*from w w w .j a v a 2 s. c o m*/ int size = context.getResources().getDrawable(R.drawable.unknown_album).getIntrinsicHeight(); Bitmap bitmap = FileUtil.getAlbumArtBitmap(context, song, size); 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.warn("Failed to get notification cover art", x); rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } rv.setImageViewResource(R.id.control_starred, song.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off); // 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); Pair<Integer, Integer> colors = getNotificationTextColors(context); if (colors.getFirst() != null) { rv.setTextColor(R.id.notification_title, colors.getFirst()); } if (colors.getSecond() != null) { rv.setTextColor(R.id.notification_artist, colors.getSecond()); } if (!playing) { rv.setImageViewResource(R.id.control_pause, R.drawable.notification_play); rv.setImageViewResource(R.id.control_previous, R.drawable.notification_stop); } // Create actions for media buttons PendingIntent pendingIntent; if (playing) { Intent prevIntent = new Intent("KEYCODE_MEDIA_PREVIOUS"); prevIntent.setComponent(new ComponentName(context, DownloadServiceImpl.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(R.id.control_previous, pendingIntent); } else { Intent prevIntent = new Intent("KEYCODE_MEDIA_STOP"); prevIntent.setComponent(new ComponentName(context, DownloadServiceImpl.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(R.id.control_previous, pendingIntent); } Intent starredIntent = new Intent("KEYCODE_MEDIA_STARRED"); starredIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); starredIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_STAR)); pendingIntent = PendingIntent.getService(context, 0, starredIntent, 0); rv.setOnClickPendingIntent(R.id.control_starred, pendingIntent); Intent pauseIntent = new Intent("KEYCODE_MEDIA_PLAY_PAUSE"); pauseIntent.setComponent(new ComponentName(context, DownloadServiceImpl.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(R.id.control_pause, pendingIntent); Intent nextIntent = new Intent("KEYCODE_MEDIA_NEXT"); nextIntent.setComponent(new ComponentName(context, DownloadServiceImpl.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(R.id.control_next, pendingIntent); }
From source file:org.zywx.wbpalmstar.platform.push.PushRecieveMsgReceiver.java
private void buildPushNotification(Context context, Intent intent, PushDataInfo dataInfo) { String title = dataInfo.getTitle(); String body = dataInfo.getAlert(); String message = dataInfo.getPushDataString(); Builder builder = new Builder(context); builder.setAutoCancel(true);/*from w w w . jav a 2 s .com*/ builder.setContentTitle(title); // builder.setContentText(body); // builder.setTicker(body); // ?? String[] remindType = dataInfo.getRemindType(); if (remindType != null) { if (remindType.length == 3) { builder.setDefaults(Notification.DEFAULT_ALL); } else { int defaults = 0; for (int i = 0; i < remindType.length; i++) { if ("sound".equalsIgnoreCase(remindType[i])) { defaults = Notification.DEFAULT_SOUND; continue; } if ("shake".equalsIgnoreCase(remindType[i])) { defaults = defaults | Notification.DEFAULT_VIBRATE; continue; } if ("breathe".equalsIgnoreCase(remindType[i])) { defaults = defaults | Notification.DEFAULT_LIGHTS; continue; } } builder.setDefaults(defaults); } } Resources res = context.getResources(); int icon = res.getIdentifier("icon", "drawable", intent.getPackage()); builder.setSmallIcon(icon); builder.setWhen(System.currentTimeMillis()); // String iconUrl = dataInfo.getIconUrl(); boolean isDefaultIcon = !TextUtils.isEmpty(iconUrl) && "default".equalsIgnoreCase(iconUrl); Bitmap bitmap = null; if (!isDefaultIcon) { bitmap = getIconBitmap(context, iconUrl); } String fontColor = dataInfo.getFontColor(); RemoteViews remoteViews = null; if (!TextUtils.isEmpty(fontColor)) { int color = BUtility.parseColor(fontColor); int alphaColor = parseAlphaColor(fontColor); remoteViews = new RemoteViews(intent.getPackage(), EUExUtil.getResLayoutID("push_notification_view")); // Title remoteViews.setTextViewText(EUExUtil.getResIdID("notification_title"), title); remoteViews.setTextColor(EUExUtil.getResIdID("notification_title"), color); // Body remoteViews.setTextViewText(EUExUtil.getResIdID("notification_body"), body); remoteViews.setTextColor(EUExUtil.getResIdID("notification_body"), alphaColor); // LargeIcon if (bitmap != null) { remoteViews.setImageViewBitmap(EUExUtil.getResIdID("notification_largeIcon"), bitmap); } else { remoteViews.setImageViewResource(EUExUtil.getResIdID("notification_largeIcon"), EUExUtil.getResDrawableID("icon")); } // Time SimpleDateFormat format = new SimpleDateFormat("HH:mm"); remoteViews.setTextViewText(EUExUtil.getResIdID("notification_time"), format.format(System.currentTimeMillis())); remoteViews.setTextColor(EUExUtil.getResIdID("notification_time"), alphaColor); builder.setContent(remoteViews); } Intent notiIntent = new Intent(context, EBrowserActivity.class); notiIntent.putExtra("ntype", F_TYPE_PUSH); notiIntent.putExtra("data", body); notiIntent.putExtra("message", message); Bundle bundle = new Bundle(); bundle.putSerializable(PushReportConstants.PUSH_DATA_INFO_KEY, dataInfo); notiIntent.putExtras(bundle); PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationNB, notiIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = builder.build(); // Android v4bug2.3?Builder?NotificationRemoteView?? if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB && remoteViews != null) { notification.contentView = remoteViews; } manager.notify(notificationNB, notification); notificationNB++; }
From source file:net.sourceforge.servestream.service.AppWidgetOneProvider.java
/** * Update all active widget instances by pushing changes *///from w ww . j a v a 2 s . c om public void performUpdate(MediaPlaybackService service, int[] appWidgetIds, String what) { final Resources res = service.getResources(); final RemoteViews views = new RemoteViews(service.getPackageName(), R.layout.appwidget_one); if (what.equals(MediaPlaybackService.PLAYER_CLOSED)) { defaultAppWidget(service, appWidgetIds); } else { CharSequence trackName = service.getTrackName(); CharSequence artistName = service.getArtistName(); //CharSequence errorState = null; if (trackName == null || trackName.equals(Media.UNKNOWN_STRING)) { trackName = res.getText(R.string.widget_one_track_info_unavailable); } if (artistName == null || artistName.equals(Media.UNKNOWN_STRING)) { artistName = service.getMediaUri(); } // Show media info views.setViewVisibility(R.id.title, View.VISIBLE); views.setTextViewText(R.id.title, trackName); views.setViewVisibility(R.id.artist, View.VISIBLE); views.setTextViewText(R.id.artist, artistName); // Set correct drawable for pause state final boolean playing = service.isPlaying(); if (playing) { views.setImageViewResource(R.id.control_play, android.R.drawable.ic_media_pause); } else { views.setImageViewResource(R.id.control_play, android.R.drawable.ic_media_play); } BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap b = BitmapFactory.decodeStream( service.getResources().openRawResource(R.drawable.albumart_mp_unknown_widget), null, opts); views.setImageViewBitmap(R.id.coverart, b); if (service.getAudioId() >= 0) { views.setImageViewBitmap(R.id.coverart, service.getAlbumArt(true)); } // Link actions buttons to intents linkButtons(service, views, true); pushUpdate(service, appWidgetIds, views); } }
From source file:org.videolan.vlc.AudioService.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void showNotification() { try {/* ww w . j a va 2 s . co m*/ Bitmap cover = AudioUtil.getCover(this, mCurrentMedia, 64); String title = mCurrentMedia.getTitle(); String artist = mCurrentMedia.getArtist(); String album = mCurrentMedia.getAlbum(); Notification notification; // add notification to status bar NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_vlc).setTicker(title + " - " + artist).setAutoCancel(false) .setOngoing(true); Intent notificationIntent = new Intent(this, AudioPlayerActivity.class); notificationIntent.setAction(Intent.ACTION_MAIN); notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER); notificationIntent.putExtra(START_FROM_NOTIFICATION, true); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); if (Util.isJellyBeanOrLater()) { Intent iBackward = new Intent(ACTION_REMOTE_BACKWARD); Intent iPlay = new Intent(ACTION_REMOTE_PLAYPAUSE); Intent iForward = new Intent(ACTION_REMOTE_FORWARD); Intent iStop = new Intent(ACTION_REMOTE_STOP); PendingIntent piBackward = PendingIntent.getBroadcast(this, 0, iBackward, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piPlay = PendingIntent.getBroadcast(this, 0, iPlay, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piForward = PendingIntent.getBroadcast(this, 0, iForward, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piStop = PendingIntent.getBroadcast(this, 0, iStop, PendingIntent.FLAG_UPDATE_CURRENT); RemoteViews view = new RemoteViews(getPackageName(), R.layout.notification); if (cover != null) view.setImageViewBitmap(R.id.cover, cover); view.setTextViewText(R.id.songName, title); view.setTextViewText(R.id.artist, artist); view.setImageViewResource(R.id.play_pause, mLibVLC.isPlaying() ? R.drawable.ic_pause : R.drawable.ic_play); view.setOnClickPendingIntent(R.id.play_pause, piPlay); view.setOnClickPendingIntent(R.id.forward, piForward); view.setOnClickPendingIntent(R.id.stop, piStop); view.setOnClickPendingIntent(R.id.content, pendingIntent); RemoteViews view_expanded = new RemoteViews(getPackageName(), R.layout.notification_expanded); if (cover != null) view_expanded.setImageViewBitmap(R.id.cover, cover); view_expanded.setTextViewText(R.id.songName, title); view_expanded.setTextViewText(R.id.artist, artist); view_expanded.setTextViewText(R.id.album, album); view_expanded.setImageViewResource(R.id.play_pause, mLibVLC.isPlaying() ? R.drawable.ic_pause : R.drawable.ic_play); view_expanded.setOnClickPendingIntent(R.id.backward, piBackward); view_expanded.setOnClickPendingIntent(R.id.play_pause, piPlay); view_expanded.setOnClickPendingIntent(R.id.forward, piForward); view_expanded.setOnClickPendingIntent(R.id.stop, piStop); view_expanded.setOnClickPendingIntent(R.id.content, pendingIntent); notification = builder.build(); notification.contentView = view; notification.bigContentView = view_expanded; } else { builder.setLargeIcon(cover).setContentTitle(title) .setContentText(Util.isJellyBeanOrLater() ? artist : mCurrentMedia.getSubtitle()) .setContentInfo(album).setContentIntent(pendingIntent); notification = builder.build(); } startForeground(3, notification); } catch (NoSuchMethodError e) { // Compat library is wrong on 3.2 // http://code.google.com/p/android/issues/detail?id=36359 // http://code.google.com/p/android/issues/detail?id=36502 } }