List of usage examples for android.widget RemoteViews setTextViewText
public void setTextViewText(int viewId, CharSequence text)
From source file:com.androidinspain.deskclock.data.TimerNotificationBuilder.java
@TargetApi(Build.VERSION_CODES.N) private RemoteViews buildChronometer(String pname, long base, boolean running, CharSequence stateText) { final RemoteViews content = new RemoteViews(pname, com.androidinspain.deskclock.R.layout.chronometer_notif_content); content.setChronometerCountDown(com.androidinspain.deskclock.R.id.chronometer, true); content.setChronometer(com.androidinspain.deskclock.R.id.chronometer, base, null, running); content.setTextViewText(com.androidinspain.deskclock.R.id.state, stateText); return content; }
From source file:com.QuarkLabs.BTCeClient.UpdateWidgetsTask.java
@Override protected void onPostExecute(JSONObject jsonObject) { if (jsonObject != null) { try {// w w w.j ava 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:cat.mvmike.minimalcalendarwidget.service.DayService.java
private static void setInstanceNumber(final Context context, final RemoteViews cellRv, final String dayOfMonth, final boolean isToday, final int found) { Symbol symbols = ConfigurationService.getInstancesSymbols(context); Character[] symbolArray = symbols.getArray(); int max = symbolArray.length - 1; String symbol = String.valueOf(found > max ? symbolArray[max] : symbolArray[found]); String dayOfMonthSpSt = PADDING + (dayOfMonth.length() == 1 ? dayOfMonth + DOUBLE_PADDING : dayOfMonth) + PADDING + symbol;//from w w w . j av a2 s . c om SpannableString daySpSt = new SpannableString(dayOfMonthSpSt); daySpSt.setSpan(new StyleSpan(Typeface.BOLD), dayOfMonthSpSt.length() - 1, dayOfMonthSpSt.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); int color; if (isToday) { color = ContextCompat.getColor(context, R.color.instances_today); daySpSt.setSpan(new StyleSpan(Typeface.BOLD), 0, dayOfMonthSpSt.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } else { color = ContextCompat.getColor(context, ConfigurationService.getInstancesSymbolsColours(context).getHexValue()); } daySpSt.setSpan(new ForegroundColorSpan(color), dayOfMonthSpSt.length() - 1, dayOfMonthSpSt.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); daySpSt.setSpan(new RelativeSizeSpan(symbols.getRelativeSize()), dayOfMonthSpSt.length() - 1, dayOfMonthSpSt.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); cellRv.setTextViewText(android.R.id.text1, daySpSt); }
From source file:net.tac42.subtails.util.Util.java
public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler, MusicDirectory.Entry song) { // Use the same text for the ticker and the expanded notification String title = song.getTitle(); String text = song.getArtist(); // Set the icon, scrolling text and timestamp final Notification notification = new Notification(R.drawable.stat_notify_playing, title, System.currentTimeMillis()); notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification); // Set the album art. try {//from ww w . j av a 2 s . c om int size = context.getResources().getDrawable(R.drawable.unknown_album).getIntrinsicHeight(); Bitmap bitmap = FileUtil.getAlbumArtBitmap(context, song, size); if (bitmap == null) { // set default album art contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } else { contentView.setImageViewBitmap(R.id.notification_image, bitmap); } } catch (Exception x) { Log.w(TAG, "Failed to get notification cover art", x); contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } // set the text for the notifications contentView.setTextViewText(R.id.notification_title, title); contentView.setTextViewText(R.id.notification_artist, text); Pair<Integer, Integer> colors = getNotificationTextColors(context); if (colors.getFirst() != null) { contentView.setTextColor(R.id.notification_title, colors.getFirst()); } if (colors.getSecond() != null) { contentView.setTextColor(R.id.notification_artist, colors.getSecond()); } notification.contentView = contentView; Intent notificationIntent = new Intent(context, DownloadActivity.class); notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); // Send the notification and put the service in the foreground. handler.post(new Runnable() { @Override public void run() { startForeground(downloadService, Constants.NOTIFICATION_ID_PLAYING, notification); } }); // Update widget SubtailsAppWidgetProvider.getInstance().notifyChange(context, downloadService, true); }
From source file:au.com.wallaceit.reddinator.Rservice.java
@Override public RemoteViews getViewAt(int position) { RemoteViews row;/*from w w w. jav a2 s . c o m*/ if (position > data.length()) { return null; // prevent errornous views } // check if its the last view and return loading view instead of normal row if (position == data.length()) { // build load more item //System.out.println("load more getViewAt("+position+") firing"); RemoteViews loadmorerow = new RemoteViews(mContext.getPackageName(), R.layout.listrowloadmore); if (endOfFeed) { loadmorerow.setTextViewText(R.id.loadmoretxt, "There's nothing more here"); } else { loadmorerow.setTextViewText(R.id.loadmoretxt, "Load more..."); } loadmorerow.setTextColor(R.id.loadmoretxt, themeColors[0]); Intent i = new Intent(); Bundle extras = new Bundle(); extras.putString(WidgetProvider.ITEM_ID, "0"); // zero will be an indicator in the onreceive function of widget provider if its not present it forces a reload i.putExtras(extras); loadmorerow.setOnClickFillInIntent(R.id.listrowloadmore, i); return loadmorerow; } else { // build normal item String title = ""; String url = ""; String permalink = ""; String thumbnail = ""; String domain = ""; String id = ""; int score = 0; int numcomments = 0; boolean nsfw = false; try { JSONObject tempobj = data.getJSONObject(position).getJSONObject("data"); title = tempobj.getString("title"); //userlikes = tempobj.getString("likes"); domain = tempobj.getString("domain"); id = tempobj.getString("name"); url = tempobj.getString("url"); permalink = tempobj.getString("permalink"); thumbnail = (String) tempobj.get("thumbnail"); // we have to call get and cast cause its not in quotes score = tempobj.getInt("score"); numcomments = tempobj.getInt("num_comments"); nsfw = tempobj.getBoolean("over_18"); } catch (JSONException e) { e.printStackTrace(); // return null; // The view is invalid; } // create remote view from specified layout if (bigThumbs) { row = new RemoteViews(mContext.getPackageName(), R.layout.listrowbigthumb); } else { row = new RemoteViews(mContext.getPackageName(), R.layout.listrow); } // build view row.setTextViewText(R.id.listheading, Html.fromHtml(title).toString()); row.setFloat(R.id.listheading, "setTextSize", Integer.valueOf(titleFontSize)); // use for compatibility setTextViewTextSize only introduced in API 16 row.setTextColor(R.id.listheading, themeColors[0]); row.setTextViewText(R.id.sourcetxt, domain); row.setTextColor(R.id.sourcetxt, themeColors[3]); row.setTextColor(R.id.votestxt, themeColors[4]); row.setTextColor(R.id.commentstxt, themeColors[4]); row.setTextViewText(R.id.votestxt, String.valueOf(score)); row.setTextViewText(R.id.commentstxt, String.valueOf(numcomments)); row.setInt(R.id.listdivider, "setBackgroundColor", themeColors[2]); row.setViewVisibility(R.id.nsfwflag, nsfw ? TextView.VISIBLE : TextView.GONE); // add extras and set click intent Intent i = new Intent(); Bundle extras = new Bundle(); extras.putString(WidgetProvider.ITEM_ID, id); extras.putInt("itemposition", position); extras.putString(WidgetProvider.ITEM_URL, url); extras.putString(WidgetProvider.ITEM_PERMALINK, permalink); i.putExtras(extras); row.setOnClickFillInIntent(R.id.listrow, i); // load thumbnail if they are enabled for this widget if (loadThumbnails) { // load big image if preference is set if (!thumbnail.equals("")) { // check for thumbnail; self is used to display the thinking logo on the reddit site, we'll just show nothing for now if (thumbnail.equals("nsfw") || thumbnail.equals("self") || thumbnail.equals("default")) { int resource = 0; switch (thumbnail) { case "nsfw": resource = R.drawable.nsfw; break; case "default": case "self": resource = R.drawable.self_default; break; } row.setImageViewResource(R.id.thumbnail, resource); row.setViewVisibility(R.id.thumbnail, View.VISIBLE); //System.out.println("Loading default image: "+thumbnail); } else { Bitmap bitmap; String fileurl = mContext.getCacheDir() + "/thumbcache-" + appWidgetId + "/" + id + ".png"; // check if the image is in cache if (new File(fileurl).exists()) { bitmap = BitmapFactory.decodeFile(fileurl); saveImageToStorage(bitmap, id); } else { // download the image bitmap = loadImage(thumbnail); } if (bitmap != null) { row.setImageViewBitmap(R.id.thumbnail, bitmap); row.setViewVisibility(R.id.thumbnail, View.VISIBLE); } else { // row.setImageViewResource(R.id.thumbnail, android.R.drawable.stat_notify_error); for later row.setViewVisibility(R.id.thumbnail, View.GONE); } } } else { row.setViewVisibility(R.id.thumbnail, View.GONE); } } else { row.setViewVisibility(R.id.thumbnail, View.GONE); } // hide info bar if options set if (hideInf) { row.setViewVisibility(R.id.infbox, View.GONE); } else { row.setViewVisibility(R.id.infbox, View.VISIBLE); } } //System.out.println("getViewAt("+position+");"); return row; }
From source file:com.elekso.potfix.MainActivity.java
private void createNotification() { // BEGIN_INCLUDE(notificationCompat) NotificationCompat.Builder builder = new NotificationCompat.Builder(this); // END_INCLUDE(notificationCompat) // BEGIN_INCLUDE(intent) //Create Intent to launch this Activity again if the notification is clicked. Intent i = new Intent(this, MainActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(intent);//from w ww . j av a2 s.com // END_INCLUDE(intent) // BEGIN_INCLUDE(ticker) // Sets the ticker text builder.setTicker(getResources().getString(R.string.custom_notification)); // Sets the small icon for the ticker builder.setSmallIcon(R.drawable.icon4_1); // END_INCLUDE(ticker) // BEGIN_INCLUDE(buildNotification) // Cancel the notification when clicked builder.setAutoCancel(true); // Build the notification Notification notification = builder.build(); // END_INCLUDE(buildNotification) // BEGIN_INCLUDE(customLayout) // Inflate the notification layout as RemoteViews RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification); // Set text on a TextView in the RemoteViews programmatically. final String time = DateFormat.getTimeInstance().format(new Date()).toString(); final String text = getResources().getString(R.string.collapsed, time); contentView.setTextViewText(R.id.textView, text); /* Workaround: Need to set the content view here directly on the notification. * NotificationCompatBuilder contains a bug that prevents this from working on platform * versions HoneyComb. * See https://code.google.com/p/android/issues/detail?id=30495 */ notification.contentView = contentView; // Add a big content view to the notification if supported. // Support for expanded notifications was added in API level 16. // (The normal contentView is shown when the notification is collapsed, when expanded the // big content view set here is displayed.) if (Build.VERSION.SDK_INT >= 16) { // Inflate and set the layout for the expanded notification view RemoteViews expandedView = new RemoteViews(getPackageName(), R.layout.notification_expanded); notification.bigContentView = expandedView; } // END_INCLUDE(customLayout) // START_INCLUDE(notify) // Use the NotificationManager to show the notification NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); nm.notify(0, notification); // END_INCLUDE(notify) }
From source file:com.perm.DoomPlay.PlayingService.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private Notification createJellyBeanNotif() { RemoteViews views = getNotifViews(R.layout.notif_jelly); Notification notification = createNotification(); views.setTextViewText(R.id.textNotifCount, String.valueOf(indexCurrentTrack + 1) + "/" + String.valueOf(audios.size())); notification.bigContentView = views; notification.priority = Notification.PRIORITY_MAX; return notification; }
From source file:com.mb.android.playbackmediator.notification.VideoCastNotificationService.java
private RemoteViews build(SessionInfoDto info, Bitmap bitmap, boolean isPlaying) throws CastException, TransientNetworkDisconnectionException, NoConnectionException { if (info.getNowPlayingItem() == null) { return null; }//from ww w. ja v a2 s .c om if (mIsLollipopOrAbove) { buildForLollipopAndAbove(info, bitmap, isPlaying); return null; } Bundle mediaWrapper = Utils.fromMediaInfo(mCastManager.getRemoteMediaInformation()); mTargetActivity = RemoteControlActivity.class; Intent contentIntent = new Intent(this, mTargetActivity); contentIntent.putExtra("LAUNCHED_BY_NOTIFICATION", true); 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); 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, info.getNowPlayingItem().getName()); 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:com.battlelancer.seriesguide.appwidget.ListWidgetProvider.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public static RemoteViews buildRemoteViews(Context context, AppWidgetManager appWidgetManager, int appWidgetId) { // setup intent pointing to RemoteViewsService providing the views for the collection Intent intent = new Intent(context, ListWidgetService.class); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); // When intents are compared, the extras are ignored, so we need to // embed the extras into the data so that the extras will not be // ignored.//w ww . ja v a2 s.co m intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); // determine layout (current size) and theme (user pref) final boolean isCompactLayout = isCompactLayout(appWidgetManager, appWidgetId); final boolean isLightTheme = WidgetSettings.isLightTheme(context, appWidgetId); int layoutResId; if (isLightTheme) { layoutResId = isCompactLayout ? R.layout.appwidget_v11_light_compact : R.layout.appwidget_v11_light; } else { layoutResId = isCompactLayout ? R.layout.appwidget_v11_compact : R.layout.appwidget_v11; } // build widget views RemoteViews rv = new RemoteViews(context.getPackageName(), layoutResId); rv.setRemoteAdapter(R.id.list_view, intent); // The empty view is displayed when the collection has no items. It // should be a sibling of the collection view. rv.setEmptyView(R.id.list_view, R.id.empty_view); // set the background color int bgColor = WidgetSettings.getWidgetBackgroundColor(context, appWidgetId, isLightTheme); rv.setInt(R.id.container, "setBackgroundColor", bgColor); // determine type specific values final int widgetType = WidgetSettings.getWidgetListType(context, appWidgetId); int showsTabIndex; int titleResId; int emptyResId; if (widgetType == WidgetSettings.Type.UPCOMING) { // upcoming showsTabIndex = ShowsActivity.InitBundle.INDEX_TAB_UPCOMING; titleResId = R.string.upcoming; emptyResId = R.string.noupcoming; } else if (widgetType == WidgetSettings.Type.RECENT) { // recent showsTabIndex = ShowsActivity.InitBundle.INDEX_TAB_RECENT; titleResId = R.string.recent; emptyResId = R.string.norecent; } else { // favorites showsTabIndex = ShowsActivity.InitBundle.INDEX_TAB_SHOWS; titleResId = R.string.action_shows_filter_favorites; emptyResId = R.string.no_nextepisode; } // change title and empty view based on type rv.setTextViewText(R.id.empty_view, context.getString(emptyResId)); if (!isCompactLayout) { // only regular layout has text title rv.setTextViewText(R.id.widgetTitle, context.getString(titleResId)); } // app launch button final Intent appLaunchIntent = new Intent(context, ShowsActivity.class) .putExtra(ShowsActivity.InitBundle.SELECTED_TAB, showsTabIndex); PendingIntent pendingIntent = TaskStackBuilder.create(context).addNextIntent(appLaunchIntent) .getPendingIntent(appWidgetId, PendingIntent.FLAG_UPDATE_CURRENT); rv.setOnClickPendingIntent(R.id.widget_title, pendingIntent); // item intent template, launches episode detail view TaskStackBuilder builder = TaskStackBuilder.create(context); builder.addNextIntent(appLaunchIntent); builder.addNextIntent(new Intent(context, EpisodesActivity.class)); rv.setPendingIntentTemplate(R.id.list_view, builder.getPendingIntent(1, PendingIntent.FLAG_UPDATE_CURRENT)); // settings button Intent settingsIntent = new Intent(context, ListWidgetConfigure.class) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); rv.setOnClickPendingIntent(R.id.widget_settings, PendingIntent.getActivity(context, appWidgetId, settingsIntent, PendingIntent.FLAG_UPDATE_CURRENT)); return rv; }
From source file:com.perm.DoomPlay.PlayingService.java
private RemoteViews getNotifViews(int layoutId) { RemoteViews views = new RemoteViews(getPackageName(), layoutId); Audio audio = audios.get(indexCurrentTrack); views.setTextViewText(R.id.notifTitle, audio.getTitle()); views.setTextViewText(R.id.notifArtist, audio.getArtist()); Bitmap cover = AlbumArtGetter.getBitmapFromStore(audio.getAid(), this); if (cover == null) { Bitmap tempBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.fallback_cover); views.setImageViewBitmap(R.id.notifAlbum, tempBitmap); tempBitmap.recycle();/*from w w w. j a v a2s. c o m*/ } else { //TODO: java.lang.IllegalArgumentException: RemoteViews for widget update exceeds // maximum bitmap memory usage (used: 3240000, max: 2304000) // The total memory cannot exceed that required to fill the device's screen once try { views.setImageViewBitmap(R.id.notifAlbum, cover); } catch (IllegalArgumentException e) { Bitmap tempBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.fallback_cover); views.setImageViewBitmap(R.id.notifAlbum, tempBitmap); tempBitmap.recycle(); } finally { cover.recycle(); } } views.setImageViewResource(R.id.notifPlay, isPlaying ? R.drawable.widget_pause : R.drawable.widget_play); ComponentName componentName = new ComponentName(this, PlayingService.class); Intent intentPlay = new Intent(actionPlay); intentPlay.setComponent(componentName); views.setOnClickPendingIntent(R.id.notifPlay, PendingIntent.getService(this, 0, intentPlay, 0)); Intent intentNext = new Intent(actionNext); intentNext.setComponent(componentName); views.setOnClickPendingIntent(R.id.notifNext, PendingIntent.getService(this, 0, intentNext, 0)); Intent intentPrevious = new Intent(actionPrevious); intentPrevious.setComponent(componentName); views.setOnClickPendingIntent(R.id.notifPrevious, PendingIntent.getService(this, 0, intentPrevious, 0)); Intent intentClose = new Intent(actionClose); intentClose.setComponent(componentName); views.setOnClickPendingIntent(R.id.notifClose, PendingIntent.getService(this, 0, intentClose, 0)); return views; }