List of usage examples for android.widget RemoteViews RemoteViews
public RemoteViews(RemoteViews landscape, RemoteViews portrait)
From source file:name.gumartinm.weather.information.notification.NotificationIntentService.java
private void showNotification(final Current current, final WeatherLocation weatherLocation) { // 1. Update units of measurement. final UnitsConversor tempUnitsConversor = new TempUnitsConversor(this.getApplicationContext()); // 2. Formatters final DecimalFormat tempFormatter = (DecimalFormat) NumberFormat.getNumberInstance(Locale.US); tempFormatter.applyPattern("###.##"); // 3. 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) + tempUnitsConversor.getSymbol(); }/*from w ww.ja v a2s . com*/ String tempMin = ""; if (current.getMain().getTemp_min() != null) { double conversion = (Double) current.getMain().getTemp_min(); conversion = tempUnitsConversor.doConversion(conversion); tempMin = tempFormatter.format(conversion) + tempUnitsConversor.getSymbol(); } 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(); // 4. Insert data in RemoteViews. final RemoteViews remoteView = new RemoteViews(this.getApplicationContext().getPackageName(), R.layout.weather_notification); remoteView.setImageViewBitmap(R.id.weather_notification_image, picture); remoteView.setTextViewText(R.id.weather_notification_temperature_max, tempMax); remoteView.setTextViewText(R.id.weather_notification_temperature_min, tempMin); remoteView.setTextViewText(R.id.weather_notification_city, city); remoteView.setTextViewText(R.id.weather_notification_country, country); // 5. Activity launcher. final Intent resultIntent = new Intent(this.getApplicationContext(), MainTabsActivity.class); // The PendingIntent to launch our activity if the user selects this notification. // 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 // your application to the Home screen. final TaskStackBuilder stackBuilder = TaskStackBuilder.create(this.getApplicationContext()); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(MainTabsActivity.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); final NotificationManagerCompat notificationManager = NotificationManagerCompat .from(this.getApplicationContext()); // 6. Create notification. final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder( this.getApplicationContext()).setContent(remoteView).setSmallIcon(R.drawable.ic_launcher) .setAutoCancel(true).setLocalOnly(true).setWhen(System.currentTimeMillis()) .setContentIntent(resultPendingIntent).setPriority(NotificationCompat.PRIORITY_DEFAULT); final Notification notification = notificationBuilder.build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; // Send the notification. // Sets an ID for the notification, so it can be updated (just in case) int notifyID = 1; notificationManager.notify(notifyID, notification); }
From source file:br.com.bioscada.apps.biotracks.widgets.TrackWidgetProvider.java
/** * Gets the remote views.//from www. j a v a 2s .co m * * @param context the context * @param trackId the track id * @param heightSize the layout height size */ private static RemoteViews getRemoteViews(Context context, long trackId, int heightSize) { int layout; switch (heightSize) { case 4: layout = R.layout.track_widget_4x4; break; case 3: layout = R.layout.track_widget_4x3; break; case 2: layout = R.layout.track_widget_4x2; break; case 1: layout = R.layout.track_widget_4x1; break; default: layout = R.layout.track_widget_4x2; break; } RemoteViews remoteViews = new RemoteViews(context.getPackageName(), layout); // Get the preferences long recordingTrackId = PreferencesUtils.getLong(context, R.string.recording_track_id_key); boolean isRecording = recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT; boolean isPaused = PreferencesUtils.getBoolean(context, R.string.recording_track_paused_key, PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT); boolean metricUnits = PreferencesUtils.isMetricUnits(context); boolean reportSpeed = PreferencesUtils.isReportSpeed(context); int item1 = PreferencesUtils.getInt(context, R.string.track_widget_item1, PreferencesUtils.TRACK_WIDGET_ITEM1_DEFAULT); int item2 = PreferencesUtils.getInt(context, R.string.track_widget_item2, PreferencesUtils.TRACK_WIDGET_ITEM2_DEFAULT); // Get track and trip statistics MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context); if (trackId == -1L) { trackId = recordingTrackId; } Track track = trackId != -1L ? myTracksProviderUtils.getTrack(trackId) : myTracksProviderUtils.getLastTrack(); TripStatistics tripStatistics = track == null ? null : track.getTripStatistics(); updateStatisticsContainer(context, remoteViews, track); setItem(context, remoteViews, ITEM1_IDS, item1, tripStatistics, isRecording, isPaused, metricUnits, reportSpeed); setItem(context, remoteViews, ITEM2_IDS, item2, tripStatistics, isRecording, isPaused, metricUnits, reportSpeed); updateRecordButton(context, remoteViews, isRecording, isPaused); updateStopButton(context, remoteViews, isRecording); if (heightSize > 1) { int item3 = PreferencesUtils.getInt(context, R.string.track_widget_item3, PreferencesUtils.TRACK_WIDGET_ITEM3_DEFAULT); int item4 = PreferencesUtils.getInt(context, R.string.track_widget_item4, PreferencesUtils.TRACK_WIDGET_ITEM4_DEFAULT); setItem(context, remoteViews, ITEM3_IDS, item3, tripStatistics, isRecording, isPaused, metricUnits, reportSpeed); setItem(context, remoteViews, ITEM4_IDS, item4, tripStatistics, isRecording, isPaused, metricUnits, reportSpeed); updateRecordStatus(context, remoteViews, isRecording, isPaused); } return remoteViews; }
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.shanet.relayremote.Main.java
private void setRelayStates(ArrayList<BasicNameValuePair> states) { if (states == null) return;/*from www . ja v a 2 s . c om*/ // The server these states correspond to is the first entry String server = states.get(0).getValue(); Relay relay; ArrayList<Bundle> widgets = database.selectAllWidgets(); relay_loop: for (int i = 0; i < relays.size(); i++) { relay = relays.get(i); // If the current relay belongs to the server the states belong to, find it's state by matching pins if (relay.getServer().equals(server)) { for (int j = 1; j < states.size(); j++) { if (relay.getPin() == Integer.valueOf(states.get(j).getName())) { if (states.get(j).getValue().charAt(0) == Constants.CMD_ON) { relay.turnOn(); } else { relay.turnOff(); } // Check if any widgets are assigned to this relay, and if so, update them for (Bundle widget : widgets) { if (widget.getInt("type") == Constants.WIDGET_RELAY && widget.getInt("id") == relay.getRid()) { // Update the indicator image RemoteViews views = new RemoteViews(this.getPackageName(), R.layout.widget); views.setImageViewResource(R.id.widgetIndicator, (states.get(i).getValue().charAt(0) == Constants.CMD_ON) ? R.drawable.widget_on : R.drawable.widget_off); AppWidgetManager.getInstance(this).updateAppWidget(widget.getInt("wid"), views); // Set the state of the widget in the widget class Widget.setState(widget.getInt("wid"), (states.get(i).getValue().charAt(0) == Constants.CMD_ON) ? Widget.STATE_ON : Widget.STATE_OFF); } } // Done with this relay; move to the next one continue relay_loop; } } } } }
From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java
@Override public void onReceive(Context context, Intent intent) { mComtext = context;//from w w w.j av a 2 s . c o m String action = intent.getAction(); Log.i("sai", "onReceive: " + action); super.onReceive(context, intent); if (ACTION_ON_QUARTER_HOUR.equals(action) || Intent.ACTION_DATE_CHANGED.equals(action) || Intent.ACTION_TIMEZONE_CHANGED.equals(action) || Intent.ACTION_TIME_CHANGED.equals(action) || Intent.ACTION_LOCALE_CHANGED.equals(action)) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); if (appWidgetManager != null) { int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context)); for (int appWidgetId : appWidgetIds) { RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget); float ratio = WidgetUtils.getScaleRatio(context, null, appWidgetId); // SPRD for bug421127 add am/pm for widget WidgetUtils.setTimeFormat(widget, (int) context.getResources().getDimension(R.dimen.widget_label_font_size), R.id.the_clock); WidgetUtils.setClockSize(context, widget, ratio); //refreshAlarm(context, widget); appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget); } } if (!ACTION_ON_QUARTER_HOUR.equals(action)) { cancelAlarmOnQuarterHour(context); } startAlarmOnQuarterHour(context); } // cg sai.pan begin else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); if (appWidgetManager != null) { int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context)); for (int appWidgetId : appWidgetIds) { RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget); refreshBtStatus(context, widget); appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget); } } } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) { int wifiStatus = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0); Log.e("sai", "wifiStatus" + wifiStatus); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); if (appWidgetManager != null) { int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context)); for (int appWidgetId : appWidgetIds) { RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget); if (WifiManager.WIFI_STATE_ENABLED == wifiStatus || WifiManager.WIFI_STATE_ENABLING == wifiStatus) { widget.setImageViewResource(R.id.wifi, R.drawable.status_wifi_on); } else { widget.setImageViewResource(R.id.wifi, R.drawable.status_wifi_off); } appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget); } } } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); if (appWidgetManager != null) { int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context)); for (int appWidgetId : appWidgetIds) { RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget); refreshWifiStatus(context, widget); } } } else if ("android.net.conn.CONNECTIVITY_CHANGE".equals(action)) { if (isNetworkConnected(context)) { Log.e("sai", "isNetworkConnected true"); requestLocation(context); } else { Log.e("sai", "isNetworkConnected false"); } } }
From source file:com.audiokernel.euphonyrmt.service.NotificationHandler.java
/** * This method builds upon the base notification resources to create * the resources necessary for the expanded notification RemoteViews. *//*from w ww .j a v a2 s . c o m*/ @TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void buildExpandedNotification() { final PendingIntent previousAction = buildPendingIntent(MPDControl.ACTION_PREVIOUS); final RemoteViews resultView = new RemoteViews(mServiceContext.getPackageName(), R.layout.notification_big); buildBaseNotification(resultView); resultView.setOnClickPendingIntent(R.id.notificationPrev, previousAction); mNotification.bigContentView = resultView; }
From source file:ar.com.martinrevert.argenteam.GcmIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from ww w. j ava 2s . c om*/ private void generarNotification(Context context, String message, String urlimagen, String urlarticulo, String tipo, String fecha) { SharedPreferences preferencias = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); boolean vib = preferencias.getBoolean("vibraoff", false); boolean movieoff = preferencias.getBoolean("movieoff", false); boolean tvoff = preferencias.getBoolean("tvoff", false); String ringmovie = preferencias.getString("prefRingtonemovie", ""); String ringtv = preferencias.getString("prefRingtonetv", ""); //Todo traducir ticker String ticker = "Nuevo subttulo " + tipo + " en aRGENTeaM"; Random randomGenerator = new Random(); int randomInt = randomGenerator.nextInt(100); Bitmap bitmap = getRemoteImage(urlimagen, tipo); Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); int dash = 500; int short_gap = 200; long[] pattern = { 0, // Start immediately dash, short_gap, dash, short_gap, dash }; Intent notificationIntent; String ringtone; int ledlight; if (tipo.equalsIgnoreCase("Movie")) { ringtone = ringmovie; notificationIntent = new Intent(context, Peli.class); ledlight = preferencias.getInt("ledMovie", 0); } else { notificationIntent = new Intent(context, Tv.class); ringtone = ringtv; ledlight = preferencias.getInt("ledTV", 0); System.out.println(ledlight); } notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); notificationIntent.putExtra("passed", urlarticulo); PendingIntent pendingIntent; pendingIntent = PendingIntent.getActivity(context, randomInt, notificationIntent, 0); Notification myNotification; myNotification = new NotificationCompat.Builder(context).setPriority(1).setContentTitle(message) .setTicker(ticker).setLights(ledlight, 300, 300).setWhen(System.currentTimeMillis()) .setContentIntent(pendingIntent).setSound(Uri.parse(ringtone)).setAutoCancel(true) .setSmallIcon(R.drawable.ic_stat_ic_argenteam_gcm).build(); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { RemoteViews views; views = new RemoteViews(getPackageName(), R.layout.custom_notification); views.setImageViewBitmap(R.id.big_picture, bitmap); views.setImageViewBitmap(R.id.big_icon, BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_ic_argenteam_gcm)); views.setTextViewText(R.id.title, message); myNotification.bigContentView = views; } NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (movieoff && tipo.equalsIgnoreCase("Movie")) { if (vib) { v.vibrate(pattern, -1); } notificationManager.notify(randomInt, myNotification); } if (tvoff && tipo.equalsIgnoreCase("Serie TV")) { if (vib) { v.vibrate(pattern, -1); } notificationManager.notify(randomInt, myNotification); } }
From source file:cm.aptoide.pt.DownloadQueueService.java
private void setFinishedNotification(int apkidHash, String localPath) { String apkid = notifications.get(apkidHash).get("apkid"); int size = Integer.parseInt(notifications.get(apkidHash).get("intSize")); String version = notifications.get(apkidHash).get("version"); RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.download_notification); contentView.setImageViewResource(R.id.download_notification_icon, R.drawable.ic_notification); contentView.setTextViewText(R.id.download_notification_name, getString(R.string.finished_download_message) + " " + apkid + " v." + version); contentView.setProgressBar(R.id.download_notification_progress_bar, size * KBYTES_TO_BYTES, size * KBYTES_TO_BYTES, false); Intent onClick = new Intent("pt.caixamagica.aptoide.INSTALL_APK", Uri.parse("apk:" + apkid)); onClick.setClassName("cm.aptoide.pt", "cm.aptoide.pt.RemoteInTab"); onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); onClick.putExtra("localPath", localPath); onClick.putExtra("apkid", apkid); onClick.putExtra("apkidHash", apkidHash); onClick.putExtra("isUpdate", Boolean.parseBoolean(notifications.get(apkid.hashCode()).get("isUpdate"))); /*Changed by Rafael Campos*/ onClick.putExtra("version", notifications.get(apkid.hashCode()).get("version")); Log.d("Aptoide-DownloadQueuService", "finished notification apkidHash: " + apkidHash + " localPath: " + localPath); // The PendingIntent to launch our activity if the user selects this notification PendingIntent onClickAction = PendingIntent.getActivity(context, 0, onClick, 0); Notification notification = new Notification(R.drawable.ic_notification, getString(R.string.finished_download_alrt) + " " + apkid, System.currentTimeMillis()); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.contentView = contentView; // Set the info for the notification panel. notification.contentIntent = onClickAction; // notification.setLatestEventInfo(this, getText(R.string.app_name), getText(R.string.add_repo_text), contentIntent); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Send the notification. // We use the position because it is a unique number. We use it later to cancel. notificationManager.notify(apkidHash, notification); // Log.d("Aptoide-DownloadQueueService", "Notification Set"); }
From source file:com.kiandastream.musicplayer.MusicService.java
/** * Configures service as a foreground service. A foreground service is a service that's doing * something the user is actively aware of (such as playing music), and must appear to the * user as a notification. That's why we create the notification here. *///from w w w. ja v a 2 s . co m public boolean setNotification(String songname) { nBuilder = new NotificationCompat.Builder(this).setContentTitle("KiandaStream") .setSmallIcon(R.drawable.headphone).setOngoing(true); remoteView = new RemoteViews(getPackageName(), R.layout.notificationview); //set the button listeners setListeners(remoteView, songname); nBuilder.setContent(remoteView); Notification notification; nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notification = nBuilder.build(); /*nManager.notify(NOTIFICATION_ID, nBuilder.build());*/ startForeground(NOTIFICATION_ID, notification); return true; }
From source file:com.ohnemax.android.glass.doseview.CSDataSort.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (mLiveCard == null) { // Get an instance of a live card mLiveCard = new LiveCard(this, LIVE_CARD_TAG); // Inflate a layout into a remote view mLiveCardView = new RemoteViews(getPackageName(), R.layout.service_doserate); // Set up the live card's action with a pending intent // to show a menu when tapped Intent menuIntent = new Intent(this, MenuActivity.class); menuIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0)); // Publish the live card mLiveCard.publish(PublishMode.REVEAL); // Queue the update text runnable mHandler.post(mUpdateLiveCardRunnable); }/*w w w .j a v a 2s. c om*/ return START_STICKY; }