List of usage examples for android.widget RemoteViews setViewVisibility
public void setViewVisibility(int viewId, int visibility)
From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java
public void onBackPressed() { if (widgetFirstTimeSetup) { finishWidgetSetup();//ww w . j a v a 2 s . c om return; } // check if sort has changed if (needsFeedUpdate || needsFeedViewUpdate || needsThemeUpdate) { if (mAppWidgetId != 0) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(SubredditSelectActivity.this); RemoteViews views = new RemoteViews(getPackageName(), R.layout.widget); views.setViewVisibility(R.id.srloader, View.VISIBLE); views.setViewVisibility(R.id.erroricon, View.INVISIBLE); // bypass the cached entrys only if the sorting preference has changed if (needsFeedUpdate) { global.setBypassCache(true); } else { global.setRefreshView(); } if (needsThemeUpdate) { WidgetProvider.updateAppWidgets(SubredditSelectActivity.this, appWidgetManager, new int[] { mAppWidgetId }, false); } else { appWidgetManager.partiallyUpdateAppWidget(mAppWidgetId, views); } appWidgetManager.notifyAppWidgetViewDataChanged(mAppWidgetId, R.id.listview); } else { Intent intent = new Intent(); intent.putExtra("themeupdate", needsThemeUpdate); if (needsFeedUpdate) { setResult(2, intent); // reload feed and prefs } else { setResult(1, intent); // tells main activity to update feed prefs } if (needsThemeUpdate) { global.setRefreshView(); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(SubredditSelectActivity.this); int[] widgetIds = appWidgetManager .getAppWidgetIds(new ComponentName(SubredditSelectActivity.this, WidgetProvider.class)); WidgetProvider.updateAppWidgets(SubredditSelectActivity.this, appWidgetManager, widgetIds, false); appWidgetManager.notifyAppWidgetViewDataChanged(widgetIds, R.id.listview); } } } else { setResult(0); } finish(); }
From source file:eu.trentorise.smartcampus.widget.shortcuts.StackWidgetService.java
@Override public RemoteViews getViewAt(int position) { // position will always range from 0 to getCount() - 1. // We construct a remote views item based on our widget item xml // file, and set the // text based on the position. RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.widget_item); ShapeDrawable sd1 = new ShapeDrawable(new RectShape()); sd1.getPaint().setColor(0xFFFFFFFF); sd1.getPaint().setStyle(Style.STROKE); sd1.getPaint().setStrokeWidth(1);/* ww w . ja v a2 s .com*/ Canvas c = new Canvas(); sd1.draw(c); Bitmap b = Bitmap.createBitmap(120, 120, Bitmap.Config.ARGB_8888); c.drawBitmap(b, 0, 0, sd1.getPaint()); // Next, we set a fill-intent which will be used to fill-in the // pending intent template // which is set on the collection view in StackWidgetProvider. if (ALLPREFERENCES != null && ALLPREFERENCES[position] != null) { //ALLPREFERENCES dimensionato come le preferenze selezionate BookmarkDescriptor myDescriptor = ALLPREFERENCES[position]; // set the widgetbutton if (WidgetHelper.PARAM_TYPE.equals(myDescriptor.params.get(0).name)) { //controllare con gli input da config activity? String type = myDescriptor.params.get(0).value; if (WidgetHelper.TYPE_DT.equals(type)) { // dt -> put icons and hide text rv.setViewVisibility(R.id.text_widget_item, View.GONE); rv.setImageViewResource(R.id.image_widget_item, Integer.parseInt(myDescriptor.params.get(2).value)); rv.setInt(R.id.image_widget_item, "setBackgroundResource", R.drawable.rounded_border_dt); } else if (WidgetHelper.TYPE_JP.equals(type)) { // jp -> put text and hide icon rv.setViewVisibility(R.id.image_widget_item, View.GONE); // rv.setImageViewBitmap(R.id.text_widget_item, // getBackground(Color.parseColor("#6EB046"))); if (!("0".equals(myDescriptor.params.get(2).value))) { //bus rv.setTextViewTextSize(R.id.text_widget_item, TypedValue.COMPLEX_UNIT_DIP, 80); rv.setTextViewText(R.id.text_widget_item, RoutesHelper.getShortNameByRouteIdAndAgencyID( myDescriptor.params.get(4).value, myDescriptor.params.get(3).value)); //4,3 rv.setTextColor(R.id.text_widget_item, Integer.parseInt(myDescriptor.params.get(2).value));//rv.setInt(R.id.text_widget_item, "setBackgroundColor", //Integer.parseInt(myDescriptor.params.get(2).value)); rv.setInt(R.id.text_widget_item, "setBackgroundResource", R.drawable.rounded_border_jp); } else { //train rv.setTextViewTextSize(R.id.text_widget_item, TypedValue.COMPLEX_UNIT_DIP, 12); //controllo contesto getRouteDescriptor i vari parametri rv.setTextViewText(R.id.text_widget_item, mContext.getString( RoutesHelper.getRouteDescriptorByRouteId(myDescriptor.params.get(3).value, myDescriptor.params.get(4).value).getNameResource())); rv.setTextColor(R.id.text_widget_item, Color.BLACK);//Int(R.id.text_widget_item, "setBackgroundColor",Color.BLACK); rv.setInt(R.id.text_widget_item, "setBackgroundResource", R.drawable.rounded_border_jp); } } else if (WidgetHelper.TYPE_JP_PARKINGS.equals(type)) { // jp parcheggio -> put text and hide icon rv.setViewVisibility(R.id.text_widget_item, View.GONE); rv.setImageViewResource(R.id.image_widget_item, Integer.parseInt(myDescriptor.params.get(2).value)); rv.setInt(R.id.image_widget_item, "setBackgroundResource", R.drawable.rounded_border_jp); } BookmarkDescriptor bookmark = myDescriptor; Bundle extras = new Bundle(); extras.putString(StackWidgetProvider.EXTRA_INTENT, bookmark.getIntent()); if (bookmark.getParams() != null) { for (Param param : bookmark.getParams()) { extras.putString(param.name, param.value); } } Intent fillInIntent = new Intent(bookmark.getIntent()); fillInIntent.putExtras(extras); rv.setOnClickFillInIntent(R.id.layout, fillInIntent); } } // Return the remote views object. // AppWidgetManager manager = AppWidgetManager.getInstance(mContext); // manager.updateAppWidget(thisWidget, rv); return rv; }
From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java
private void updateFeedAndFinish() { if (widgetFirstTimeSetup) { finishWidgetSetup();//from w w w . j a v a2s .c om return; } if (mAppWidgetId != 0) { // refresh widget and close activity (NOTE: put in function) AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(SubredditSelectActivity.this); RemoteViews views = new RemoteViews(getPackageName(), R.layout.widget); views.setTextViewText(R.id.subreddittxt, global.getSubredditManager().getCurrentFeedName(mAppWidgetId)); views.setViewVisibility(R.id.srloader, View.VISIBLE); views.setViewVisibility(R.id.erroricon, View.INVISIBLE); // bypass cache if service not loaded global.setBypassCache(true); appWidgetManager.partiallyUpdateAppWidget(mAppWidgetId, views); appWidgetManager.notifyAppWidgetViewDataChanged(mAppWidgetId, R.id.listview); } else { Intent intent = new Intent(); intent.putExtra("themeupdate", needsThemeUpdate); setResult(2, intent); // update feed prefs + reload feed } finish(); }
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); }/*from w w w . j a v a 2 s .co m*/ // 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); }/* w w w . j a va 2 s. co m*/ // 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.irccloud.android.Notifications.java
@SuppressLint("NewApi") private android.app.Notification buildNotification(String ticker, int bid, long[] eids, String title, String text, Spanned big_text, int count, Intent replyIntent, Spanned wear_text, String network, String auto_messages[]) { SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext()); NotificationCompat.Builder builder = new NotificationCompat.Builder( IRCCloudApplication.getInstance().getApplicationContext()) .setContentTitle(title + ((network != null) ? (" (" + network + ")") : "")) .setContentText(Html.fromHtml(text)).setAutoCancel(true).setTicker(ticker) .setWhen(eids[0] / 1000).setSmallIcon(R.drawable.ic_stat_notify) .setColor(IRCCloudApplication.getInstance().getApplicationContext().getResources() .getColor(R.color.dark_blue)) .setVisibility(NotificationCompat.VISIBILITY_PRIVATE) .setCategory(NotificationCompat.CATEGORY_MESSAGE) .setPriority(NotificationCompat.PRIORITY_HIGH).setOnlyAlertOnce(false); if (ticker != null && (System.currentTimeMillis() - prefs.getLong("lastNotificationTime", 0)) > 10000) { if (prefs.getBoolean("notify_vibrate", true)) builder.setDefaults(android.app.Notification.DEFAULT_VIBRATE); String ringtone = prefs.getString("notify_ringtone", "content://settings/system/notification_sound"); if (ringtone != null && ringtone.length() > 0) builder.setSound(Uri.parse(ringtone)); }/*from w w w . j av a 2 s. com*/ int led_color = Integer.parseInt(prefs.getString("notify_led_color", "1")); if (led_color == 1) { if (prefs.getBoolean("notify_vibrate", true)) builder.setDefaults( android.app.Notification.DEFAULT_LIGHTS | android.app.Notification.DEFAULT_VIBRATE); else builder.setDefaults(android.app.Notification.DEFAULT_LIGHTS); } else if (led_color == 2) { builder.setLights(0xFF0000FF, 500, 500); } SharedPreferences.Editor editor = prefs.edit(); editor.putLong("lastNotificationTime", System.currentTimeMillis()); editor.commit(); Intent i = new Intent(); i.setComponent(new ComponentName(IRCCloudApplication.getInstance().getApplicationContext().getPackageName(), "com.irccloud.android.MainActivity")); i.putExtra("bid", bid); i.setData(Uri.parse("bid://" + bid)); Intent dismiss = new Intent(IRCCloudApplication.getInstance().getApplicationContext().getResources() .getString(R.string.DISMISS_NOTIFICATION)); dismiss.setData(Uri.parse("irccloud-dismiss://" + bid)); dismiss.putExtra("bid", bid); dismiss.putExtra("eids", eids); PendingIntent dismissPendingIntent = PendingIntent.getBroadcast( IRCCloudApplication.getInstance().getApplicationContext(), 0, dismiss, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent( PendingIntent.getActivity(IRCCloudApplication.getInstance().getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT)); builder.setDeleteIntent(dismissPendingIntent); if (replyIntent != null) { WearableExtender extender = new WearableExtender(); PendingIntent replyPendingIntent = PendingIntent.getService( IRCCloudApplication.getInstance().getApplicationContext(), bid + 1, replyIntent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT); extender.addAction( new NotificationCompat.Action.Builder(R.drawable.ic_reply, "Reply", replyPendingIntent) .addRemoteInput( new RemoteInput.Builder("extra_reply").setLabel("Reply to " + title).build()) .build()); if (count > 1 && wear_text != null) extender.addPage( new NotificationCompat.Builder(IRCCloudApplication.getInstance().getApplicationContext()) .setContentText(wear_text).extend(new WearableExtender().setStartScrollBottom(true)) .build()); NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder( title + ((network != null) ? (" (" + network + ")") : "")) .setReadPendingIntent(dismissPendingIntent).setReplyAction(replyPendingIntent, new RemoteInput.Builder("extra_reply").setLabel("Reply to " + title).build()); if (auto_messages != null) { for (String m : auto_messages) { if (m != null && m.length() > 0) { unreadConvBuilder.addMessage(m); } } } else { unreadConvBuilder.addMessage(text); } unreadConvBuilder.setLatestTimestamp(eids[count - 1] / 1000); builder.extend(extender) .extend(new NotificationCompat.CarExtender().setUnreadConversation(unreadConvBuilder.build())); } if (replyIntent != null && prefs.getBoolean("notify_quickreply", true)) { i = new Intent(IRCCloudApplication.getInstance().getApplicationContext(), QuickReplyActivity.class); i.setData(Uri.parse("irccloud-bid://" + bid)); i.putExtras(replyIntent); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent quickReplyIntent = PendingIntent.getActivity( IRCCloudApplication.getInstance().getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(R.drawable.ic_action_reply, "Quick Reply", quickReplyIntent); } android.app.Notification notification = builder.build(); RemoteViews contentView = new RemoteViews( IRCCloudApplication.getInstance().getApplicationContext().getPackageName(), R.layout.notification); contentView.setTextViewText(R.id.title, title + " (" + network + ")"); contentView.setTextViewText(R.id.text, (count == 1) ? Html.fromHtml(text) : (count + " unread highlights.")); contentView.setLong(R.id.time, "setTime", eids[0] / 1000); notification.contentView = contentView; if (Build.VERSION.SDK_INT >= 16 && big_text != null) { RemoteViews bigContentView = new RemoteViews( IRCCloudApplication.getInstance().getApplicationContext().getPackageName(), R.layout.notification_expanded); bigContentView.setTextViewText(R.id.title, title + (!title.equals(network) ? (" (" + network + ")") : "")); bigContentView.setTextViewText(R.id.text, big_text); bigContentView.setLong(R.id.time, "setTime", eids[0] / 1000); if (count > 3) { bigContentView.setViewVisibility(R.id.more, View.VISIBLE); bigContentView.setTextViewText(R.id.more, "+" + (count - 3) + " more"); } else { bigContentView.setViewVisibility(R.id.more, View.GONE); } if (replyIntent != null && prefs.getBoolean("notify_quickreply", true)) { bigContentView.setViewVisibility(R.id.actions, View.VISIBLE); bigContentView.setViewVisibility(R.id.action_divider, View.VISIBLE); i = new Intent(IRCCloudApplication.getInstance().getApplicationContext(), QuickReplyActivity.class); i.setData(Uri.parse("irccloud-bid://" + bid)); i.putExtras(replyIntent); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent quickReplyIntent = PendingIntent.getActivity( IRCCloudApplication.getInstance().getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT); bigContentView.setOnClickPendingIntent(R.id.action_reply, quickReplyIntent); } notification.bigContentView = bigContentView; } return notification; }
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 a v a2 s . co 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.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 ww w . java 2s . 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:net.naonedbus.appwidget.HoraireWidgetProvider.java
/** * Prparer le widget avec les lments fixes (nom, ligne, sens...) *///from w ww . j ava 2 s. c o m protected void prepareWidgetViewInit(final Context context, final RemoteViews views, final Favori favori) { views.setTextViewText(R.id.itemSymbole, favori.getLettre()); // Uniquement pour 2.2 et sup if (Build.VERSION.SDK_INT > 7) { views.setTextColor(R.id.itemSymbole, favori.getCouleurTexte()); views.setTextColor(R.id.itemTitle, favori.getCouleurTexte()); views.setTextColor(R.id.itemDescription, favori.getCouleurTexte()); final GradientDrawable gradientDrawable = ColorUtils.getGradiant(favori.getCouleurBackground()); final Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); gradientDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); gradientDrawable.draw(canvas); views.setImageViewBitmap(R.id.widgetHeaderBackground, bitmap); } if (favori.getNomFavori() == null) { views.setTextViewText(R.id.itemTitle, favori.getNomArret()); views.setTextViewText(R.id.itemDescription, FormatUtils.formatSens(favori.getNomSens())); } else { views.setTextViewText(R.id.itemTitle, favori.getNomArret()); views.setTextViewText(R.id.itemDescription, FormatUtils.formatSens(favori.getNomArret(), favori.getNomSens())); } views.setViewVisibility(R.id.widgetLoading, View.GONE); }
From source file:com.irccloud.android.data.collection.NotificationsList.java
@SuppressLint("NewApi") private android.app.Notification buildNotification(String ticker, int cid, int bid, long[] eids, String title, String text, int count, Intent replyIntent, String network, ArrayList<Notification> messages, NotificationCompat.Action otherAction, Bitmap largeIcon, Bitmap wearBackground) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel c = new NotificationChannel(String.valueOf(bid), title, NotificationManager.IMPORTANCE_HIGH); c.setGroup(String.valueOf(cid)); ((NotificationManager) IRCCloudApplication.getInstance().getApplicationContext() .getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(c); }/*from w w w .java 2 s .c om*/ SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext()); int defaults = 0; NotificationCompat.Builder builder = new NotificationCompat.Builder( IRCCloudApplication.getInstance().getApplicationContext(), String.valueOf(bid)) .setContentTitle( title + ((network != null && !network.equals(title)) ? (" (" + network + ")") : "")) .setContentText(Html.fromHtml(text)).setAutoCancel(true).setTicker(ticker) .setWhen(eids[0] / 1000).setSmallIcon(R.drawable.ic_stat_notify).setLargeIcon(largeIcon) .setColor(IRCCloudApplication.getInstance().getApplicationContext().getResources() .getColor(R.color.ic_background)) .setVisibility(NotificationCompat.VISIBILITY_PRIVATE) .setCategory(NotificationCompat.CATEGORY_MESSAGE) .setPriority(hasTouchWiz() ? NotificationCompat.PRIORITY_DEFAULT : NotificationCompat.PRIORITY_HIGH) .setOnlyAlertOnce(false); if (ticker != null && (System.currentTimeMillis() - prefs.getLong("lastNotificationTime", 0)) > 2000) { String ringtone = prefs.getString("notify_ringtone", "android.resource://" + IRCCloudApplication.getInstance().getApplicationContext().getPackageName() + "/" + R.raw.digit); if (ringtone.length() > 0) builder.setSound(Uri.parse(ringtone)); } int led_color = Integer.parseInt(prefs.getString("notify_led_color", "1")); if (led_color == 1) { defaults = android.app.Notification.DEFAULT_LIGHTS; } else if (led_color == 2) { builder.setLights(0xFF0000FF, 500, 500); } if (prefs.getBoolean("notify_vibrate", true) && ticker != null && (System.currentTimeMillis() - prefs.getLong("lastNotificationTime", 0)) > 2000) defaults |= android.app.Notification.DEFAULT_VIBRATE; else builder.setVibrate(new long[] { 0L }); builder.setDefaults(defaults); SharedPreferences.Editor editor = prefs.edit(); editor.putLong("lastNotificationTime", System.currentTimeMillis()); editor.commit(); Intent i = new Intent(); i.setComponent(new ComponentName(IRCCloudApplication.getInstance().getApplicationContext().getPackageName(), "com.irccloud.android.MainActivity")); i.putExtra("bid", bid); i.setData(Uri.parse("bid://" + bid)); Intent dismiss = new Intent(IRCCloudApplication.getInstance().getApplicationContext().getResources() .getString(R.string.DISMISS_NOTIFICATION)); dismiss.setData(Uri.parse("irccloud-dismiss://" + bid)); dismiss.putExtra("bid", bid); dismiss.putExtra("eids", eids); PendingIntent dismissPendingIntent = PendingIntent.getBroadcast( IRCCloudApplication.getInstance().getApplicationContext(), 0, dismiss, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent( PendingIntent.getActivity(IRCCloudApplication.getInstance().getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT)); builder.setDeleteIntent(dismissPendingIntent); WearableExtender wearableExtender = new WearableExtender(); wearableExtender.setBackground(wearBackground); if (messages != null && messages.size() > 0) { StringBuilder weartext = new StringBuilder(); String servernick = getServerNick(messages.get(0).cid); NotificationCompat.MessagingStyle style = new NotificationCompat.MessagingStyle(servernick); style.setConversationTitle(title + ((network != null) ? (" (" + network + ")") : "")); for (Notification n : messages) { if (n != null && n.message != null && n.message.length() > 0) { if (weartext.length() > 0) weartext.append("<br/>"); if (n.message_type.equals("buffer_me_msg")) { style.addMessage(Html.fromHtml(n.message).toString(), n.eid / 1000, " " + ((n.nick == null) ? servernick : n.nick)); weartext.append("<b> ").append((n.nick == null) ? servernick : n.nick).append("</b> ") .append(n.message); } else { style.addMessage(Html.fromHtml(n.message).toString(), n.eid / 1000, n.nick); weartext.append("<b><").append((n.nick == null) ? servernick : n.nick) .append("></b> ").append(n.message); } } } ArrayList<String> history = new ArrayList<>(messages.size()); for (int j = messages.size() - 1; j >= 0; j--) { Notification n = messages.get(j); if (n != null) { if (n.nick == null) history.add(Html.fromHtml(n.message).toString()); else break; } } builder.setRemoteInputHistory(history.toArray(new String[history.size()])); builder.setStyle(style); if (messages.size() > 1) { wearableExtender.addPage( new NotificationCompat.Builder(IRCCloudApplication.getInstance().getApplicationContext()) .setContentText(Html.fromHtml(weartext.toString())) .extend(new WearableExtender().setStartScrollBottom(true)).build()); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { weartext.setLength(0); int j = 0; for (Notification n : messages) { if (messages.size() - ++j < 3) { if (n != null && n.message != null && n.message.length() > 0) { if (weartext.length() > 0) weartext.append("<br/>"); if (n.message_type.equals("buffer_me_msg")) { weartext.append("<b> ").append((n.nick == null) ? servernick : n.nick) .append("</b> ").append(n.message); } else { weartext.append("<b><").append((n.nick == null) ? servernick : n.nick) .append("></b> ").append(n.message); } } } } RemoteViews bigContentView = new RemoteViews( IRCCloudApplication.getInstance().getApplicationContext().getPackageName(), R.layout.notification_expanded); bigContentView.setTextViewText(R.id.title, title + (!title.equals(network) ? (" (" + network + ")") : "")); bigContentView.setTextViewText(R.id.text, Html.fromHtml(weartext.toString())); bigContentView.setImageViewBitmap(R.id.image, largeIcon); bigContentView.setLong(R.id.time, "setTime", eids[0] / 1000); if (count > 3) { bigContentView.setViewVisibility(R.id.more, View.VISIBLE); bigContentView.setTextViewText(R.id.more, "+" + (count - 3) + " more"); } else { bigContentView.setViewVisibility(R.id.more, View.GONE); } if (replyIntent != null && prefs.getBoolean("notify_quickreply", true)) { bigContentView.setViewVisibility(R.id.actions, View.VISIBLE); bigContentView.setViewVisibility(R.id.action_divider, View.VISIBLE); i = new Intent(IRCCloudApplication.getInstance().getApplicationContext(), QuickReplyActivity.class); i.setData(Uri.parse("irccloud-bid://" + bid)); i.putExtras(replyIntent); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent quickReplyIntent = PendingIntent.getActivity( IRCCloudApplication.getInstance().getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT); bigContentView.setOnClickPendingIntent(R.id.action_reply, quickReplyIntent); } builder.setCustomBigContentView(bigContentView); } } if (replyIntent != null) { PendingIntent replyPendingIntent = PendingIntent.getService( IRCCloudApplication.getInstance().getApplicationContext(), bid + 1, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { builder.addAction(new NotificationCompat.Action.Builder(0, "Reply", replyPendingIntent) .setAllowGeneratedReplies(true) .addRemoteInput( new RemoteInput.Builder("extra_reply").setLabel("Reply to " + title).build()) .build()); } NotificationCompat.Action.Builder actionBuilder = new NotificationCompat.Action.Builder( R.drawable.ic_wearable_reply, "Reply", replyPendingIntent).setAllowGeneratedReplies(true) .addRemoteInput( new RemoteInput.Builder("extra_reply").setLabel("Reply to " + title).build()); NotificationCompat.Action.WearableExtender actionExtender = new NotificationCompat.Action.WearableExtender() .setHintLaunchesActivity(true).setHintDisplayActionInline(true); wearableExtender.addAction(actionBuilder.extend(actionExtender).build()); NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder( title + ((network != null) ? (" (" + network + ")") : "")) .setReadPendingIntent(dismissPendingIntent).setReplyAction(replyPendingIntent, new RemoteInput.Builder("extra_reply").setLabel("Reply to " + title).build()); if (messages != null) { for (Notification n : messages) { if (n != null && n.nick != null && n.message != null && n.message.length() > 0) { if (n.buffer_type.equals("conversation")) { if (n.message_type.equals("buffer_me_msg")) unreadConvBuilder .addMessage(" " + n.nick + " " + Html.fromHtml(n.message).toString()); else unreadConvBuilder.addMessage(Html.fromHtml(n.message).toString()); } else { if (n.message_type.equals("buffer_me_msg")) unreadConvBuilder .addMessage(" " + n.nick + " " + Html.fromHtml(n.message).toString()); else unreadConvBuilder .addMessage(n.nick + " said: " + Html.fromHtml(n.message).toString()); } } } } else { unreadConvBuilder.addMessage(text); } unreadConvBuilder.setLatestTimestamp(eids[count - 1] / 1000); builder.extend(new NotificationCompat.CarExtender().setUnreadConversation(unreadConvBuilder.build())); } if (replyIntent != null && prefs.getBoolean("notify_quickreply", true) && Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { i = new Intent(IRCCloudApplication.getInstance().getApplicationContext(), QuickReplyActivity.class); i.setData(Uri.parse("irccloud-bid://" + bid)); i.putExtras(replyIntent); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent quickReplyIntent = PendingIntent.getActivity( IRCCloudApplication.getInstance().getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(R.drawable.ic_action_reply, "Quick Reply", quickReplyIntent); } if (otherAction != null) { int drawable = 0; if (otherAction.getIcon() == R.drawable.ic_wearable_add) drawable = R.drawable.ic_action_add; else if (otherAction.getIcon() == R.drawable.ic_wearable_reply) drawable = R.drawable.ic_action_reply; builder.addAction( new NotificationCompat.Action(drawable, otherAction.getTitle(), otherAction.getActionIntent())); wearableExtender.addAction(otherAction); } builder.extend(wearableExtender); return builder.build(); }