List of usage examples for android.widget RemoteViews setTextViewText
public void setTextViewText(int viewId, CharSequence text)
From source file:org.zoumbox.mh_dla_notifier.Receiver.java
protected void checkForWidgetsUpdate(Context context, Troll troll) { try {/* w w w . j a v a 2 s.c o m*/ AppWidgetManager widgetManager = AppWidgetManager.getInstance(context); ComponentName componentName = new ComponentName(context, HomeScreenWidget.class); int[] appWidgetIds = widgetManager.getAppWidgetIds(componentName); if (appWidgetIds != null && appWidgetIds.length > 0) { // FIXME AThimel 14/02/14 Remove ASAP StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); String dlaText = Trolls.getWidgetDlaTextFunction(context).apply(troll); Bitmap blason = MhDlaNotifierUtils.loadBlasonForWidget(troll.getBlason(), context.getCacheDir()); for (int appWidgetId : appWidgetIds) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.home_screen_widget); views.setTextViewText(R.id.widgetDla, dlaText); if (blason == null) { views.setImageViewResource(R.id.widgetImage, R.drawable.trarnoll_square_transparent_128); } else { views.setImageViewBitmap(R.id.widgetImage, blason); } // Tell the AppWidgetManager to perform an update on the current app widget widgetManager.updateAppWidget(appWidgetId, views); } } } catch (Exception eee) { Log.e(TAG, "Unable to update widget(s)", eee); } }
From source file:name.gumartinm.weather.information.widget.WidgetIntentService.java
private RemoteViews makeView(final Current current, final WeatherLocation weatherLocation, final int appWidgetId) { // 1. Update units of measurement. UnitsConversor tempUnitsConversor;//from w w w . java2s .co m String keyPreference = this.getApplicationContext() .getString(R.string.widget_preferences_temperature_units_key); String realKeyPreference = keyPreference + "_" + appWidgetId; // What was saved to permanent storage (or default values if it is the first time) final int tempValue = this.getSharedPreferences(WIDGET_PREFERENCES_NAME, Context.MODE_PRIVATE) .getInt(realKeyPreference, 0); final String tempSymbol = this.getResources() .getStringArray(R.array.weather_preferences_temperature)[tempValue]; if (tempValue == 0) { tempUnitsConversor = new UnitsConversor() { @Override public double doConversion(final double value) { return value - 273.15; } }; } else if (tempValue == 1) { tempUnitsConversor = new UnitsConversor() { @Override public double doConversion(final double value) { return (value * 1.8) - 459.67; } }; } else { tempUnitsConversor = new UnitsConversor() { @Override public double doConversion(final double value) { return value; } }; } // 2. Update country. keyPreference = this.getApplicationContext().getString(R.string.widget_preferences_country_switch_key); realKeyPreference = keyPreference + "_" + appWidgetId; // What was saved to permanent storage (or default values if it is the first time) final boolean isCountry = this.getSharedPreferences(WIDGET_PREFERENCES_NAME, Context.MODE_PRIVATE) .getBoolean(realKeyPreference, false); // 3. Formatters final DecimalFormat tempFormatter = (DecimalFormat) NumberFormat.getNumberInstance(Locale.US); tempFormatter.applyPattern("###.##"); // 4. 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) + tempSymbol; } String tempMin = ""; if (current.getMain().getTemp_min() != null) { double conversion = (Double) current.getMain().getTemp_min(); conversion = tempUnitsConversor.doConversion(conversion); tempMin = tempFormatter.format(conversion) + tempSymbol; } 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(); // 5. Insert data in RemoteViews. final RemoteViews remoteView = new RemoteViews(this.getApplicationContext().getPackageName(), R.layout.appwidget); remoteView.setImageViewBitmap(R.id.weather_appwidget_image, picture); remoteView.setTextViewText(R.id.weather_appwidget_temperature_max, tempMax); remoteView.setTextViewText(R.id.weather_appwidget_temperature_min, tempMin); remoteView.setTextViewText(R.id.weather_appwidget_city, city); if (!isCountry) { remoteView.setViewVisibility(R.id.weather_appwidget_country, View.GONE); } else { // TODO: It is as if Android had a view cache. If I did not set VISIBLE value, // the country field would be gone forever... :/ remoteView.setViewVisibility(R.id.weather_appwidget_country, View.VISIBLE); remoteView.setTextViewText(R.id.weather_appwidget_country, country); } // 6. Activity launcher. final Intent resultIntent = new Intent(this.getApplicationContext(), WidgetConfigure.class); resultIntent.putExtra("actionFromUser", true); resultIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); // From: http://stackoverflow.com/questions/4011178/multiple-instances-of-widget-only-updating-last-widget final Uri data = Uri.withAppendedPath(Uri.parse("PAIN" + "://widget/id/"), String.valueOf(appWidgetId)); resultIntent.setData(data); final TaskStackBuilder stackBuilder = TaskStackBuilder.create(this.getApplicationContext()); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(WidgetConfigure.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); remoteView.setOnClickPendingIntent(R.id.weather_appwidget, resultPendingIntent); return remoteView; }
From source file:com.gsoc.ijosa.liquidgalaxycontroller.PW.UrlDeviceDiscoveryService.java
private void updateSummaryNotificationRemoteViewsFirstBeacon(PwPair pwPair, RemoteViews remoteViews) { PwsResult pwsResult = pwPair.getPwsResult(); remoteViews.setImageViewBitmap(R.id.icon_firstBeacon, Utils.getBitmapIcon(mPwCollection, pwsResult)); remoteViews.setTextViewText(R.id.title_firstBeacon, pwsResult.getTitle()); remoteViews.setTextViewText(R.id.url_firstBeacon, pwsResult.getSiteUrl()); remoteViews.setTextViewText(R.id.description_firstBeacon, pwsResult.getDescription()); // 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); }// ww w . j a v a 2s.c om // Create an intent that will open the browser to the beacon's url // if the user taps the notification remoteViews.setOnClickPendingIntent(R.id.first_beacon_main_layout, Utils.createNavigateToUrlPendingIntent(pwsResult, this)); remoteViews.setViewVisibility(R.id.firstBeaconLayout, View.VISIBLE); }
From source file:com.gsoc.ijosa.liquidgalaxycontroller.PW.UrlDeviceDiscoveryService.java
private void updateSummaryNotificationRemoteViewsSecondBeacon(PwPair pwPair, RemoteViews remoteViews) { PwsResult pwsResult = pwPair.getPwsResult(); remoteViews.setImageViewBitmap(R.id.icon_secondBeacon, Utils.getBitmapIcon(mPwCollection, pwsResult)); remoteViews.setTextViewText(R.id.title_secondBeacon, pwsResult.getTitle()); remoteViews.setTextViewText(R.id.url_secondBeacon, pwsResult.getSiteUrl()); remoteViews.setTextViewText(R.id.description_secondBeacon, pwsResult.getDescription()); // 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 a v a 2s .c om*/ // Create an intent that will open the browser to the beacon's url // if the user taps the notification remoteViews.setOnClickPendingIntent(R.id.second_beacon_main_layout, Utils.createNavigateToUrlPendingIntent(pwsResult, this)); remoteViews.setViewVisibility(R.id.secondBeaconLayout, View.VISIBLE); }
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); }//from w w w . j av a 2 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.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); }//ww w. j av a 2 s. c o m // 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.tct.mail.widget.WidgetService.java
/** * Modifies the remoteView for the given account and folder. */// w ww. jav a 2s. c o m public static void configureValidAccountWidget(Context context, RemoteViews remoteViews, int appWidgetId, Account account, final int folderType, final int folderCapabilities, final Uri folderUri, final Uri folderConversationListUri, String folderDisplayName, Class<?> widgetService) { remoteViews.setViewVisibility(R.id.widget_folder, View.VISIBLE); // If the folder or account name are empty, we don't want to overwrite the valid data that // had been saved previously. Since the launcher will save the state of the remote views // we should rely on the fact that valid data has been saved. But we should still log this, // as it shouldn't happen if (TextUtils.isEmpty(folderDisplayName) || TextUtils.isEmpty(account.getDisplayName())) { LogUtils.e(LOG_TAG, new Error(), "Empty folder or account name. account: %s, folder: %s", account.getEmailAddress(), folderDisplayName); } if (!TextUtils.isEmpty(folderDisplayName)) { remoteViews.setTextViewText(R.id.widget_folder, folderDisplayName); } //TS: junwei-xu 2014-12-23 EMAIL BUGFIX_850975 ADD_S remoteViews.setViewVisibility(R.id.widget_account_noflip, View.VISIBLE); if (!TextUtils.isEmpty(account.getEmailAddress())) { remoteViews.setTextViewText(R.id.widget_account_noflip, account.getEmailAddress()); remoteViews.setTextViewText(R.id.widget_account, account.getEmailAddress()); } remoteViews.setViewVisibility(R.id.widget_account_unread_flipper, View.GONE); //TS: junwei-xu 2014-12-23 EMAIL BUGFIX_850975 ADD_E remoteViews.setViewVisibility(R.id.widget_compose, View.VISIBLE); remoteViews.setViewVisibility(R.id.conversation_list, View.VISIBLE); remoteViews.setViewVisibility(R.id.empty_conversation_list, View.GONE); //TS: zheng.zou 2015-08-11 EMAIL BUGFIX_1044483 MOD remoteViews.setViewVisibility(R.id.widget_folder_not_synced, View.GONE); remoteViews.setViewVisibility(R.id.widget_configuration, View.GONE); // remoteViews.setEmptyView(R.id.conversation_list, R.id.empty_conversation_list); //TS: zheng.zou 2015-08-11 EMAIL BUGFIX_1044483 DEL WidgetService.configureValidWidgetIntents(context, remoteViews, appWidgetId, account, folderType, folderCapabilities, folderUri, folderConversationListUri, folderDisplayName, widgetService); }
From source file:com.firefly.sample.castcompanionlibrary.notification.VideoCastNotificationService.java
private RemoteViews build(MediaInfo info, Bitmap bitmap, boolean isPlaying, Class<?> targetActivity) throws CastException, TransientNetworkDisconnectionException, NoConnectionException { Bundle mediaWrapper = Utils.fromMediaInfo(mCastManager.getRemoteMediaInformation()); Intent contentIntent = null;/*from w ww .j av a 2 s .c o m*/ if (null == mTargetActivity) { mTargetActivity = VideoCastControllerActivity.class; } contentIntent = new Intent(this, mTargetActivity); contentIntent.putExtra("media", mediaWrapper); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(mTargetActivity); stackBuilder.addNextIntent(contentIntent); if (stackBuilder.getIntentCount() > 1) { stackBuilder.editIntentAt(1).putExtra("media", mediaWrapper); } // Gets a PendingIntent containing the entire back stack PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(NOTIFICATION_ID, PendingIntent.FLAG_UPDATE_CURRENT); MediaMetadata mm = info.getMetadata(); RemoteViews rv = new RemoteViews(getPackageName(), R.layout.custom_notification); if (mIsIcsOrAbove) { addPendingIntents(rv, isPlaying, info); } if (null != bitmap) { rv.setImageViewBitmap(R.id.iconView, bitmap); } rv.setTextViewText(R.id.titleView, mm.getString(MediaMetadata.KEY_TITLE)); String castingTo = getResources().getString(R.string.casting_to_device, mCastManager.getDeviceName()); rv.setTextViewText(R.id.subTitleView, castingTo); mNotification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_stat_action_notification) .setContentIntent(resultPendingIntent).setContent(rv).setAutoCancel(false).setOngoing(true).build(); // to get around a bug in GB version, we add the following line // see https://code.google.com/p/android/issues/detail?id=30495 mNotification.contentView = rv; return rv; }
From source file:air.com.snagfilms.cast.chromecast.notifications.VideoCastNotificationService.java
private RemoteViews build(MediaInfo info, Bitmap bitmap, boolean isPlaying, Class<?> targetActivity) throws CastException, TransientNetworkDisconnectionException, NoConnectionException { Bundle mediaWrapper = Utils.fromMediaInfo(mCastManager.getRemoteMediaInformation()); Intent contentIntent = null;// w ww.j av a 2s . c o m if (null == mTargetActivity) { mTargetActivity = VideoPlayerActivity.class; } contentIntent = new Intent(this, mTargetActivity); contentIntent.putExtra("media", mediaWrapper); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(mTargetActivity); stackBuilder.addNextIntent(contentIntent); if (stackBuilder.getIntentCount() > 1) { stackBuilder.editIntentAt(1).putExtra("media", mediaWrapper); } // Gets a PendingIntent containing the entire back stack PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(NOTIFICATION_ID, PendingIntent.FLAG_UPDATE_CURRENT); MediaMetadata mm = info.getMetadata(); RemoteViews rv = new RemoteViews(getPackageName(), R.layout.custom_notification); if (mIsIcsOrAbove) { addPendingIntents(rv, isPlaying, info); } if (null != bitmap) { rv.setImageViewBitmap(R.id.iconView, bitmap); } rv.setTextViewText(R.id.titleView, mm.getString(MediaMetadata.KEY_TITLE)); String castingTo = getResources().getString(R.string.casting_to_device, mCastManager.getDeviceName()); rv.setTextViewText(R.id.subTitleView, castingTo); mNotification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_stat_action_notification) .setContentIntent(resultPendingIntent).setContent(rv).setAutoCancel(false).setOngoing(true).build(); // to get around a bug in GB version, we add the following line // see https://code.google.com/p/android/issues/detail?id=30495 mNotification.contentView = rv; return rv; }
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 . ja v a 2 s .c o m*/ 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++; }