List of usage examples for android.widget RemoteViews setOnClickPendingIntent
public void setOnClickPendingIntent(int viewId, PendingIntent pendingIntent)
From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java
private void updateClock(Context context, AppWidgetManager appWidgetManager, int appWidgetId, float ratio) { RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget); // Launch setinngs when clicking on the time in the widget only if not a lock screen widget Bundle newOptions = appWidgetManager.getAppWidgetOptions(appWidgetId); if (newOptions != null && newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, -1) != AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD) { Intent mIntent = new Intent(Intent.ACTION_MAIN); mIntent.addCategory(Intent.CATEGORY_LAUNCHER); ComponentName component = new ComponentName("com.android.settings", "com.android.settings.Settings"); mIntent.setComponent(component); widget.setOnClickPendingIntent(R.id.digital_appwidget, PendingIntent.getActivity(context, 0, mIntent, 0)); }/* w w w.ja va 2 s . c om*/ //cg sai.pan begin refreshWifiStatus(context, widget); refreshBtStatus(context, widget); refreshAirplaneStatus(context, widget, Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0); mLocationManager = (LocationManager) context.getSystemService(context.LOCATION_SERVICE); refreshGpsStatus(context, widget, mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)); //refreshDataStatus(context, widget, Settings.Global.getInt(context.getContentResolver(), Settings.Global.MOBILE_DATA, 0) != 0); requestLocation(context); //cg sai.pan end // 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); // Set today's date format CharSequence dateFormat = DateFormat.getBestDateTimePattern(Locale.getDefault(), context.getString(R.string.abbrev_wday_month_day_no_year)); widget.setCharSequence(R.id.date, "setFormat12Hour", dateFormat); widget.setCharSequence(R.id.date, "setFormat24Hour", dateFormat); appWidgetManager.updateAppWidget(appWidgetId, widget); }
From source file:org.videolan.vlc.AudioService.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void showNotification() { try {/*w w w. jav a 2 s.c o 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 } }
From source file:com.karma.konnect.PwoDiscoveryService.java
private void updateSummaryNotificationRemoteViewsFirstBeacon(PwoMetadata pwoMetadata, RemoteViews remoteViews) { UrlMetadata urlMetadata = pwoMetadata.urlMetadata; remoteViews.setImageViewBitmap(R.id.icon_firstBeacon, urlMetadata.icon); remoteViews.setTextViewText(R.id.title_firstBeacon, urlMetadata.title); remoteViews.setTextViewText(R.id.url_firstBeacon, urlMetadata.displayUrl); remoteViews.setTextViewText(R.id.description_firstBeacon, urlMetadata.description); // Recolor notifications to have light text for non-Lollipop devices if (!(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)) { remoteViews.setTextColor(R.id.title_firstBeacon, NON_LOLLIPOP_NOTIFICATION_TITLE_COLOR); remoteViews.setTextColor(R.id.url_firstBeacon, NON_LOLLIPOP_NOTIFICATION_URL_COLOR); remoteViews.setTextColor(R.id.description_firstBeacon, NON_LOLLIPOP_NOTIFICATION_SNIPPET_COLOR); }/*w w w . j a va2 s.com*/ // Create an intent that will open the browser to the beacon's url // if the user taps the notification PendingIntent pendingIntent = pwoMetadata.createNavigateToUrlPendingIntent(this); remoteViews.setOnClickPendingIntent(R.id.first_beacon_main_layout, pendingIntent); remoteViews.setViewVisibility(R.id.firstBeaconLayout, View.VISIBLE); }
From source file:com.karma.konnect.PwoDiscoveryService.java
private void updateSummaryNotificationRemoteViewsSecondBeacon(PwoMetadata pwoMetadata, RemoteViews remoteViews) { UrlMetadata urlMetadata = pwoMetadata.urlMetadata; remoteViews.setImageViewBitmap(R.id.icon_secondBeacon, urlMetadata.icon); remoteViews.setTextViewText(R.id.title_secondBeacon, urlMetadata.title); remoteViews.setTextViewText(R.id.url_secondBeacon, urlMetadata.displayUrl); remoteViews.setTextViewText(R.id.description_secondBeacon, urlMetadata.description); // Recolor notifications to have light text for non-Lollipop devices if (!(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)) { remoteViews.setTextColor(R.id.title_secondBeacon, NON_LOLLIPOP_NOTIFICATION_TITLE_COLOR); remoteViews.setTextColor(R.id.url_secondBeacon, NON_LOLLIPOP_NOTIFICATION_URL_COLOR); remoteViews.setTextColor(R.id.description_secondBeacon, NON_LOLLIPOP_NOTIFICATION_SNIPPET_COLOR); }/*from w w w . j ava2 s .c om*/ // Create an intent that will open the browser to the beacon's url // if the user taps the notification PendingIntent pendingIntent = pwoMetadata.createNavigateToUrlPendingIntent(this); remoteViews.setOnClickPendingIntent(R.id.second_beacon_main_layout, pendingIntent); remoteViews.setViewVisibility(R.id.secondBeaconLayout, View.VISIBLE); }
From source file:com.massivcode.androidmusicplayer.services.MusicService.java
private void showNotificationUnderLollipop() { Notification.Builder builder = new Notification.Builder(this); RemoteViews remoteViews = new RemoteViews(this.getPackageName(), R.layout.notification); // ? ? ? /*from ww w. ja v a 2 s.c o m*/ // ========================================================================================= Intent musicPreviousIntent = new Intent(getApplicationContext(), MusicService.class); musicPreviousIntent.setAction(ACTION_PLAY_PREVIOUS); musicPreviousIntent.putExtra("position", getPositionAtPreviousOrNext(ACTION_PLAY_PREVIOUS)); PendingIntent musicPreviousPendingIntent = PendingIntent.getService(getApplicationContext(), 0, musicPreviousIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.noti_previous_ib, musicPreviousPendingIntent); // ========================================================================================= // ? ? ? // ========================================================================================= Intent musicStopIntent = new Intent(getApplicationContext(), MusicService.class); musicStopIntent.setAction(ACTION_PAUSE); PendingIntent musicStopPendingIntent = PendingIntent.getService(getApplicationContext(), 1, musicStopIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.noti_play_ib, musicStopPendingIntent); // ========================================================================================= // ? ? ? // ========================================================================================= Intent musicNextIntent = new Intent(getApplicationContext(), MusicService.class); musicNextIntent.setAction(ACTION_PLAY_NEXT); musicNextIntent.putExtra("position", getPositionAtPreviousOrNext(ACTION_PLAY_NEXT)); PendingIntent musicNextPendingIntent = PendingIntent.getService(getApplicationContext(), 2, musicNextIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.noti_next_ib, musicNextPendingIntent); // ========================================================================================= // ? ? // ========================================================================================= Intent closeIntent = new Intent(getApplicationContext(), MusicService.class); closeIntent.setAction(ACTION_FINISH); PendingIntent closePendingIntent = PendingIntent.getService(getApplicationContext(), 3, closeIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.noti_close_ib, closePendingIntent); // ========================================================================================= // Notification ? PendingIntent // ========================================================================================= Intent activityStartIntent = new Intent(MainActivity.ACTION_NAME); activityStartIntent.putExtra("restore", getCurrentInfo()); PendingIntent activityStartPendingIntent = PendingIntent.getActivity(getApplicationContext(), 1, activityStartIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(activityStartPendingIntent); // ========================================================================================= Bitmap bitmap = null; if (mCurrentMusicInfo != null) { if (mCurrentMusicInfo.getUri() != null) { bitmap = MusicInfoLoadUtil.getBitmap(getApplicationContext(), mCurrentMusicInfo.getUri(), 4); } } if (bitmap == null) { bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_no_image); } remoteViews.setImageViewBitmap(R.id.noti_album_art_iv, bitmap); if (mCurrentMusicInfo != null) { remoteViews.setTextViewText(R.id.noti_artist_tv, mCurrentMusicInfo.getArtist()); remoteViews.setTextViewText(R.id.noti_title_tv, mCurrentMusicInfo.getTitle()); } builder.setContent(remoteViews); builder.setLargeIcon(bitmap); builder.setSmallIcon(R.mipmap.ic_no_image); if (mMediaPlayer.isPlaying()) { remoteViews.setImageViewResource(R.id.noti_play_ib, android.R.drawable.ic_media_pause); } else { remoteViews.setImageViewResource(R.id.noti_play_ib, android.R.drawable.ic_media_play); } builder.setAutoCancel(false); Notification notification = builder.build(); startForeground(1, notification); }
From source file:ru.kaefik.isaifutdinov.an_weather_widget.AnWeatherWidget.java
@Override public void onReceive(Context context, Intent intent) { Log.i(TAG_SERVICE, " onReceive " + intent.getAction()); super.onReceive(context, intent); if (FORCE_WIDGET_UPDATE.equals(intent.getAction())) { String nameCity = intent.getStringExtra(PARAM_CITY); String tempCity = intent.getStringExtra(PARAM_TEMP); String windCity = intent.getStringExtra(PARAM_WIND); String timeRefreshCity = intent.getStringExtra(PARAM_TIMEREFRESH); String weatherImageCity = intent.getStringExtra(PARAM_WEATHERIMAGE); String descriptionWeather = intent.getStringExtra(PARAM_DESCWEATHER); int WidgetId = intent.getIntExtra(PARAM_WIDGETID, 0); //TODO: ? , ?. ? ? GetWeatherCityService Log.i(TAG_SERVICE, "onReceive " + nameCity + " -> " + tempCity); // /*w w w . jav a 2 s . c o m*/ AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); ComponentName thisWidget = new ComponentName(context, AnWeatherWidget.class); int[] appWidgetId = appWidgetManager.getAppWidgetIds(thisWidget); for (int i = 0; i < appWidgetId.length; i++) { Log.i(TAG_SERVICE, "onReceive -> appWidgetId = " + String.valueOf(appWidgetId[i])); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.an_weather_widget); if (WidgetId == appWidgetId[i]) { views.setTextViewText(R.id.cityNameText, nameCity); views.setTextViewText(R.id.tempCityText, tempCity); views.setTextViewText(R.id.windText, windCity); views.setTextViewText(R.id.timeRefreshText, timeRefreshCity); views.setTextViewText(R.id.descriptionWeatherText, descriptionWeather); views.setImageViewUri(R.id.weatherImageView, Uri.parse("android.resource://ru.kaefik.isaifutdinov.an_weather_widget/mipmap/" + "weather" + weatherImageCity)); // ? CLICK_WIDGET_BUTTON onReceive // Intent ? Broadcast Intent active = new Intent(context, AnWeatherWidget.class); active.setAction(CLICK_WIDGET_BUTTON); //? ? PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0); //? ? views.setOnClickPendingIntent(R.id.refreshButton, actionPendingIntent); //? // END - ? CLICK_WIDGET_BUTTON onReceive appWidgetManager.updateAppWidget(appWidgetId[i], views); break; } appWidgetManager.updateAppWidget(appWidgetId[i], views); } } if (CLICK_WIDGET_BUTTON.equals(intent.getAction())) { Log.i(TAG_SERVICE, " "); // AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); ComponentName thisWidget = new ComponentName(context, AnWeatherWidget.class); int[] appWidgetId = appWidgetManager.getAppWidgetIds(thisWidget); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.an_weather_widget); // ? for (int i = 0; i < appWidgetId.length; i++) { Log.i(TAG_SERVICE, "id -> " + String.valueOf(appWidgetId[i])); String nameCity = ConfigActivity.loadStringParametersFromFile(context, String.valueOf(appWidgetId[i])); startGetWeatherCityService(context, appWidgetId[i], new CityModel(nameCity)); } } }
From source file:org.videolan.vlc.MediaService.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void showNotification() { try {// w w w . ja v a 2s. c o 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, mIsVout ? MediaPlayerActivity.class : 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 } }
From source file:com.QuarkLabs.BTCeClient.UpdateWidgetsTask.java
@Override protected void onPostExecute(JSONObject jsonObject) { if (jsonObject != null) { try {/*from w w w .jav a 2s . c om*/ Context context = mContext.get(); if (context == null) { return; } AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); for (int x : mMap.keySet()) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_layout); double price = jsonObject.getJSONObject(mMap.get(x).replace("/", "_").toLowerCase(Locale.US)) .getDouble("last"); String priceString; if (price > 1) { priceString = (new DecimalFormat("#.##")).format(price); } else { priceString = String.valueOf(price); } views.setTextViewText(R.id.widgetCurrencyValue, priceString); views.setTextViewText(R.id.widgetPair, mMap.get(x)); String color = jsonObject.getJSONObject(mMap.get(x).replace("/", "_").toLowerCase(Locale.US)) .getString("color"); int colorValue = color.equals("green") ? Color.GREEN : Color.RED; views.setTextColor(R.id.widgetCurrencyValue, colorValue); Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE); Bundle bundle = new Bundle(); bundle.putIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetManager.getAppWidgetIds(new ComponentName(context, WidgetProvider.class))); intent.putExtras(bundle); PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.widgetContainer, pi); SimpleDateFormat df = new SimpleDateFormat("EEE HH:mm", Locale.US); Calendar calendar = Calendar.getInstance(); views.setTextViewText(R.id.widgetDate, df.format(calendar.getTime())); appWidgetManager.updateAppWidget(x, views); } } catch (JSONException e) { e.printStackTrace(); } } }
From source file:com.fbartnitzek.tasteemall.widget.StatsWidgetIntentService.java
@Override protected void onHandleIntent(Intent intent) { // Log.v(LOG_TAG, "onHandleIntent, hashCode=" + this.hashCode() + ", " + "intent = [" + intent + "]"); // get all widget ids AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this); int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(this, StatsWidgetProvider.class)); // query all entities int numLocations = queryAndGetCount(DatabaseContract.LocationEntry.CONTENT_URI, QueryColumns.Widget.LocationQuery.COLUMNS); int numProducers = queryAndGetCount(DatabaseContract.ProducerEntry.CONTENT_URI, QueryColumns.Widget.ProviderQuery.COLUMNS); int numDrinks = queryAndGetCount(DatabaseContract.DrinkEntry.CONTENT_URI, QueryColumns.Widget.DrinkQuery.COLUMNS); int numUsers = queryAndGetCount(DatabaseContract.UserEntry.CONTENT_URI, QueryColumns.Widget.UserQuery.COLUMNS); int numReviews = queryAndGetCount(DatabaseContract.ReviewEntry.CONTENT_URI, QueryColumns.Widget.ReviewQuery.COLUMNS); // TODO: results are getting "cached" or something like that ... // maybe that helps: http://stackoverflow.com/questions/9497270/widget-with-content-provider-impossible-to-use-readpermission Log.v(LOG_TAG,//from w ww . ja va 2 s .co m "onHandleIntent, producer=" + numProducers + ", drinks=" + numDrinks + ", reviews=" + numReviews); for (int appWidgetId : appWidgetIds) { // dynamically adapt widget width ... later RemoteViews views = new RemoteViews(getPackageName(), R.layout.info_widget); // fill stats views.setTextViewText(R.id.stats_locations, getString(R.string.widget_statistics_locations, numLocations)); views.setTextViewText(R.id.stats_producers, getString(R.string.widget_statistics_producers, numProducers)); views.setTextViewText(R.id.stats_drinks, getString(R.string.widget_statistics_drinks, numDrinks)); views.setTextViewText(R.id.stats_users, getString(R.string.widget_statistics_users, numUsers)); views.setTextViewText(R.id.stats_reviews, getString(R.string.widget_statistics_reviews, numReviews)); // seems to be impossible to get contentDescription for whole widget... // views.setContentDescription(R.id.widget_layout, // getString(R.string.a11y_widget_statistics_all, numProducers, numDrinks, numReviews)); views.setContentDescription(R.id.stats_reviews, getString(R.string.a11y_widget_statistics_all, numProducers, numDrinks, numReviews)); // set on click listener for add and search on every update (kind of useless...) // add button - create backStack for add Intent addIntent = new Intent(this, AddReviewActivity.class); PendingIntent addPendingIntent = TaskStackBuilder.create(this).addNextIntentWithParentStack(addIntent) .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.widget_add_button, addPendingIntent); // search button PendingIntent searchPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); views.setOnClickPendingIntent(R.id.widget_search_button, searchPendingIntent); // update each StatsWidget appWidgetManager.updateAppWidget(appWidgetId, views); } }
From source file:eu.operando.operandoapp.util.NotificationUtil.java
public void displayExfiltratedNotification(Context context, String applicationInfo, Set<RequestFilterUtil.FilterType> exfiltrated, int mainNotificationId) { try {/*from w ww. ja va 2 s.c om*/ StringBuilder sb = new StringBuilder(); for (RequestFilterUtil.FilterType f : exfiltrated) { sb.append(f + ", "); } sb.delete(sb.length() - 2, sb.length() - 1); RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.proxy_notification_small); smallContentView.setImageViewResource(R.id.image, R.drawable.logo_bevel); smallContentView.setTextViewText(R.id.titleTxtView, "Personal Information"); smallContentView.setTextViewText(R.id.subtitleTxtView, "Expand for more info"); RemoteViews bigContentView = new RemoteViews(context.getPackageName(), R.layout.proxy_notification_large); bigContentView.setImageViewResource(R.id.image, R.drawable.logo_bevel); bigContentView.setTextViewText(R.id.titleTxtView, "Personal Information"); bigContentView.setTextViewText(R.id.subtitleTxtView, applicationInfo.replaceAll("\\s\\(.*?\\)", "") + " requires access to " + sb); bigContentView.setTextViewText(R.id.allowBtn, "Allow"); bigContentView.setTextViewText(R.id.blockBtn, "Block"); //get exfiltrated info to string array String[] exfiltrated_array = new String[exfiltrated.size()]; int i = 0; for (RequestFilterUtil.FilterType filter_type : exfiltrated) { exfiltrated_array[i] = filter_type.name(); i++; } //set listeners for notification buttons Intent allowIntent = new Intent(context, NotificationActivityReceiver.class); allowIntent.setAction("allow"); Bundle allowBundle = new Bundle(); allowBundle.putString("appInfo", applicationInfo); allowBundle.putInt("notificationId", mainNotificationId); allowBundle.putStringArray("exfiltrated", exfiltrated_array); allowIntent.putExtras(allowBundle); PendingIntent pendingAllowIntent = PendingIntent.getBroadcast(context, mainNotificationId + 1, allowIntent, PendingIntent.FLAG_UPDATE_CURRENT); bigContentView.setOnClickPendingIntent(R.id.allowBtn, pendingAllowIntent); Intent blockIntent = new Intent(context, NotificationActivityReceiver.class); blockIntent.setAction("block"); Bundle blockBundle = new Bundle(); blockBundle.putString("appInfo", applicationInfo); blockBundle.putInt("notificationId", mainNotificationId); blockBundle.putStringArray("exfiltrated", exfiltrated_array); blockIntent.putExtras(blockBundle); PendingIntent pendingBlockIntent = PendingIntent.getBroadcast(context, mainNotificationId + 2, blockIntent, PendingIntent.FLAG_UPDATE_CURRENT); bigContentView.setOnClickPendingIntent(R.id.blockBtn, pendingBlockIntent); Notification.Builder mBuilder = new Notification.Builder(context).setSmallIcon(R.drawable.logo_bevel) .setContent(smallContentView); Notification proxyNotification = mBuilder.build(); proxyNotification.defaults |= Notification.DEFAULT_ALL; proxyNotification.bigContentView = bigContentView; NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(mainNotificationId, proxyNotification); DatabaseHelper db = new DatabaseHelper(context); db.addPendingNotification(new PendingNotification(applicationInfo, TextUtils.join(", ", exfiltrated_array), mainNotificationId)); } catch (Exception e) { Log.d("ERROR", e.getMessage()); } }