List of usage examples for android.widget RemoteViews setTextColor
public void setTextColor(int viewId, @ColorInt ColorStateList colors)
From source file:com.ultrafunk.network_info.receiver.MobileDataStatusReceiver.java
private void setStateColor(Context context, RemoteViews remoteViews, int state) { int color = (state == STATE_ON) ? ContextCompat.getColor(context, android.R.color.white) : ContextCompat.getColor(context, R.color.medium_gray); remoteViews.setTextColor(R.id.mobileNameTextView, color); remoteViews.setInt(R.id.mobileHeaderSpacerTextView, "setBackgroundColor", color); remoteViews.setTextColor(R.id.mobileInfoTopTextView, color); remoteViews.setTextColor(R.id.mobileInfoBottomTextView, color); }
From source file:org.solovyev.android.calculator.widget.CalculatorWidget.java
private void updateDisplayState(@Nonnull Context context, @Nonnull RemoteViews views, @Nonnull DisplayState displayState, @Nonnull SimpleTheme theme) { final boolean error = !displayState.valid; if (!error) { views.setTextViewText(R.id.calculator_display, displayState.text); }/*from w w w. j a v a 2s. com*/ views.setTextColor(R.id.calculator_display, ContextCompat.getColor(context, theme.getDisplayTextColor(error))); }
From source file:com.freshplanet.nativeExtensions.C2DMBroadcastReceiver.java
/** * Get the parameters from the message and create a notification from it. * @param context//from w w w . ja va 2 s . co m * @param intent */ public void handleMessage(Context context, Intent intent) { try { registerResources(context); extractColors(context); FREContext ctxt = C2DMExtension.context; NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // icon is required for notification. // @see http://developer.android.com/guide/practices/ui_guidelines/icon_design_status_bar.html int icon = notificationIcon; long when = System.currentTimeMillis(); // json string String parameters = intent.getStringExtra("parameters"); String facebookId = null; JSONObject object = null; if (parameters != null) { try { object = (JSONObject) new JSONTokener(parameters).nextValue(); } catch (Exception e) { Log.d(TAG, "cannot parse the object"); } } if (object != null && object.has("facebookId")) { facebookId = object.getString("facebookId"); } CharSequence tickerText = intent.getStringExtra("tickerText"); CharSequence contentTitle = intent.getStringExtra("contentTitle"); CharSequence contentText = intent.getStringExtra("contentText"); Intent notificationIntent = new Intent(context, Class.forName(context.getPackageName() + ".AppEntry")); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); Notification notification = new Notification(icon, tickerText, when); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); RemoteViews contentView = new RemoteViews(context.getPackageName(), customLayout); contentView.setTextViewText(customLayoutTitle, contentTitle); contentView.setTextViewText(customLayoutDescription, contentText); contentView.setTextColor(customLayoutTitle, notification_text_color); contentView.setFloat(customLayoutTitle, "setTextSize", notification_title_size_factor * notification_text_size); contentView.setTextColor(customLayoutDescription, notification_text_color); contentView.setFloat(customLayoutDescription, "setTextSize", notification_description_size_factor * notification_text_size); if (facebookId != null) { Log.d(TAG, "bitmap not null"); CreateNotificationTask cNT = new CreateNotificationTask(); cNT.setParams(customLayoutImageContainer, NotifId, nm, notification, contentView); String src = "http://graph.facebook.com/" + facebookId + "/picture?type=normal"; URL url = new URL(src); cNT.execute(url); } else { Log.d(TAG, "bitmap null"); contentView.setImageViewResource(customLayoutImageContainer, customLayoutImage); notification.contentView = contentView; nm.notify(NotifId, notification); } NotifId++; if (ctxt != null) { parameters = parameters == null ? "" : parameters; ctxt.dispatchStatusEventAsync("COMING_FROM_NOTIFICATION", parameters); } } catch (Exception e) { Log.e(TAG, "Error activating application:", e); } }
From source file:com.abhijitvalluri.android.fitnotifications.widget.ServiceToggle.java
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { // Perform this loop procedure for each App Widget that belongs to this provider for (int appWidgetId : appWidgetIds) { // Get the layout for the App Widget and attach an on-click listener // to the button RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.service_toggle_widget); if (NLService.isEnabled()) { views.setImageViewResource(R.id.widgetToggleButton, R.drawable.ic_speaker_notes_white_48dp); views.setInt(R.id.widgetToggleButton, "setBackgroundResource", R.drawable.round_rectangle_green); views.setTextViewText(R.id.widgetToggleText, context.getString(R.string.widget_on_text)); views.setTextColor(R.id.widgetToggleText, ContextCompat.getColor(context, R.color.green)); } else {/*from ww w . j a v a 2 s .c o m*/ views.setImageViewResource(R.id.widgetToggleButton, R.drawable.ic_speaker_notes_off_white_48dp); views.setInt(R.id.widgetToggleButton, "setBackgroundResource", R.drawable.round_rectangle_red); views.setTextViewText(R.id.widgetToggleText, context.getString(R.string.widget_off_text)); views.setTextColor(R.id.widgetToggleText, ContextCompat.getColor(context, R.color.red)); } views.setOnClickPendingIntent(R.id.widgetToggleButton, getPendingSelfIntent(context, appWidgetId, TOGGLE_CLICKED)); // Tell the AppWidgetManager to perform an update on the current app widget appWidgetManager.updateAppWidget(appWidgetId, views); } }
From source file:org.gnucash.android.ui.widget.WidgetConfigurationActivity.java
/** * Updates the widget with id <code>appWidgetId</code> with information from the * account with record ID <code>accountId</code> * If the account has been deleted, then a notice is posted in the widget * @param appWidgetId ID of the widget to be updated * @param accountId Database ID of the account tied to the widget *///from w w w. j av a 2 s . c o m public static void updateWidget(Context context, int appWidgetId, long accountId) { Log.i("WidgetConfiguration", "Updating widget: " + appWidgetId); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); AccountsDbAdapter accountsDbAdapter = new AccountsDbAdapter(context); Account account = accountsDbAdapter.getAccount(accountId); if (account == null) { Log.i("WidgetConfiguration", "Account not found, resetting widget " + appWidgetId); //if account has been deleted, let the user know RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_4x1); views.setTextViewText(R.id.account_name, context.getString(R.string.toast_account_deleted)); views.setTextViewText(R.id.transactions_summary, ""); //set it to simply open the app PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, AccountsActivity.class), 0); views.setOnClickPendingIntent(R.id.widget_layout, pendingIntent); views.setOnClickPendingIntent(R.id.btn_new_transaction, pendingIntent); appWidgetManager.updateAppWidget(appWidgetId, views); Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit(); editor.remove(UxArgument.SELECTED_ACCOUNT_ID + appWidgetId); editor.commit(); return; } RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_4x1); views.setTextViewText(R.id.account_name, account.getName()); Money accountBalance = accountsDbAdapter.getAccountBalance(accountId); views.setTextViewText(R.id.transactions_summary, accountBalance.formattedString(Locale.getDefault())); int color = account.getBalance().isNegative() ? R.color.debit_red : R.color.credit_green; views.setTextColor(R.id.transactions_summary, context.getResources().getColor(color)); Intent accountViewIntent = new Intent(context, TransactionsActivity.class); accountViewIntent.setAction(Intent.ACTION_VIEW); accountViewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); accountViewIntent.putExtra(UxArgument.SELECTED_ACCOUNT_ID, accountId); PendingIntent accountPendingIntent = PendingIntent.getActivity(context, appWidgetId, accountViewIntent, 0); views.setOnClickPendingIntent(R.id.widget_layout, accountPendingIntent); Intent newTransactionIntent = new Intent(context, TransactionsActivity.class); newTransactionIntent.setAction(Intent.ACTION_INSERT_OR_EDIT); newTransactionIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); newTransactionIntent.putExtra(UxArgument.SELECTED_ACCOUNT_ID, accountId); PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, newTransactionIntent, 0); views.setOnClickPendingIntent(R.id.btn_new_transaction, pendingIntent); appWidgetManager.updateAppWidget(appWidgetId, views); }
From source file:com.abhijitvalluri.android.fitnotifications.widget.ServiceToggle.java
@Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); if (TOGGLE_CLICKED.equals(intent.getAction())) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.service_toggle_widget); if (NLService.isEnabled()) { NLService.setEnabled(false); views.setImageViewResource(R.id.widgetToggleButton, R.drawable.ic_speaker_notes_off_white_48dp); views.setInt(R.id.widgetToggleButton, "setBackgroundResource", R.drawable.round_rectangle_red); views.setTextViewText(R.id.widgetToggleText, context.getString(R.string.widget_off_text)); views.setTextColor(R.id.widgetToggleText, ContextCompat.getColor(context, R.color.red)); } else {/*from w w w . j a v a 2 s . c o m*/ NLService.setEnabled(true); views.setImageViewResource(R.id.widgetToggleButton, R.drawable.ic_speaker_notes_white_48dp); views.setInt(R.id.widgetToggleButton, "setBackgroundResource", R.drawable.round_rectangle_green); views.setTextViewText(R.id.widgetToggleText, context.getString(R.string.widget_on_text)); views.setTextColor(R.id.widgetToggleText, ContextCompat.getColor(context, R.color.green)); } views.setOnClickPendingIntent(R.id.widgetToggleButton, getPendingSelfIntent(context, 0, TOGGLE_CLICKED)); ComponentName componentName = new ComponentName(context, ServiceToggle.class); appWidgetManager.updateAppWidget(componentName, views); } }
From source file:net.naonedbus.appwidget.HoraireWidgetProvider.java
/** * Prparer le widget avec les lments fixes (nom, ligne, sens...) *//* w ww . j a v a 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:au.com.wallaceit.reddinator.Rservice.java
@Override public RemoteViews getLoadingView() { RemoteViews rowload = new RemoteViews(mContext.getPackageName(), R.layout.listrowload); if (themeColors == null) { getThemeColors(); // prevents null pointer }//from w w w. j a va2 s . c o m rowload.setTextColor(R.id.listloadtxt, themeColors[0]); return rowload; }
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);/*ww w .j av a2s . c om*/ 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++; }
From source file:com.metinkale.prayerapp.vakit.WidgetService.java
public static void updateOngoing() { extractColors();/* w w w .java2s .c o m*/ NotificationManager nm = (NotificationManager) App.getContext() .getSystemService(Context.NOTIFICATION_SERVICE); for (int i = mOngoing.size() - 1; i >= 0; i--) { long id = mOngoing.get(i); Times t = Times.getTimes(id); if ((t == null) || !t.isOngoingNotificationActive()) { nm.cancel(id + "", NotIds.ONGOING); mOngoing.remove(i); } } List<Long> ids = Times.getIds(); for (long id : ids) { Times t = Times.getTimes(id); if ((t != null) && t.isOngoingNotificationActive() && !mOngoing.contains(id)) { mOngoing.add(id); } } LocalDate cal = LocalDate.now(); String[] left_part = App.getContext().getResources().getStringArray(R.array.lefttext_part); for (long id : mOngoing) { Times t = Times.getTimes(id); String[] dt = { t.getTime(cal, 0), t.getTime(cal, 1), t.getTime(cal, 2), t.getTime(cal, 3), t.getTime(cal, 4), t.getTime(cal, 5) }; boolean icon = Prefs.showOngoingIcon(); boolean number = Prefs.showOngoingNumber(); Crashlytics.setBool("showIcon", icon); Crashlytics.setBool("showNumber", number); Notification noti; if (Prefs.getAlternativeOngoing()) { RemoteViews views = new RemoteViews(App.getContext().getPackageName(), R.layout.notification_layout); int[] timeIds = { R.id.time0, R.id.time1, R.id.time2, R.id.time3, R.id.time4, R.id.time5 }; int[] vakitIds = { R.id.imsak, R.id.gunes, R.id.ogle, R.id.ikindi, R.id.aksam, R.id.yatsi }; int next = t.getNext(); if (Prefs.getVakitIndicator().equals("next")) next++; for (int i = 0; i < dt.length; i++) { if ((next - 1) == i) { views.setTextViewText(timeIds[i], Html.fromHtml("<strong><em>" + Utils.fixTime(dt[i]) + "</em></strong>")); } else { views.setTextViewText(timeIds[i], Utils.fixTime(dt[i])); } } for (int i = 0; i < dt.length; i++) { if ((next - 1) == i) { views.setTextViewText(vakitIds[i], Html.fromHtml("<strong><em>" + Vakit.getByIndex(i).getString() + "</em></strong>")); } else { views.setTextViewText(vakitIds[i], Vakit.getByIndex(i).getString()); } } views.setTextViewText(R.id.time, t.getLeft(t.getNext(), false)); views.setTextViewText(R.id.city, t.getName()); views.setTextColor(R.id.imsak, COLOR_1ST); views.setTextColor(R.id.gunes, COLOR_1ST); views.setTextColor(R.id.ogle, COLOR_1ST); views.setTextColor(R.id.ikindi, COLOR_1ST); views.setTextColor(R.id.aksam, COLOR_1ST); views.setTextColor(R.id.yatsi, COLOR_1ST); views.setTextColor(R.id.time0, COLOR_1ST); views.setTextColor(R.id.time1, COLOR_1ST); views.setTextColor(R.id.time2, COLOR_1ST); views.setTextColor(R.id.time3, COLOR_1ST); views.setTextColor(R.id.time4, COLOR_1ST); views.setTextColor(R.id.time5, COLOR_1ST); views.setTextColor(R.id.time, COLOR_1ST); views.setTextColor(R.id.city, COLOR_1ST); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { long left = t.getLeftMinutes(t.getNext()); noti = new Notification.Builder(App.getContext()).setContent(views) .setContentIntent(Main.getPendingIntent(t)) .setSmallIcon(icon ? (number ? Icon.createWithBitmap(getIconFromMinutes(left)) : Icon.createWithResource(App.getContext(), R.drawable.ic_abicon)) : Icon.createWithResource(App.getContext(), R.drawable.ic_placeholder)) .setOngoing(true).build(); } else { noti = new NotificationCompat.Builder(App.getContext()).setContent(views) .setContentIntent(Main.getPendingIntent(t)) .setSmallIcon(icon ? R.drawable.ic_abicon : R.drawable.ic_placeholder).setOngoing(true) .build(); } } else { int n = t.getNext(); String sum = App.getContext().getString(R.string.leftText, Vakit.getByIndex(n - 1).getString(), left_part[n], t.getLeft().substring(0, 5)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { long left = t.getLeftMinutes(t.getNext()); noti = new Notification.InboxStyle( new Notification.Builder(App.getContext()) .setContentTitle(t.getName() + " (" + t.getSource() + ")").setContentText("") .setLargeIcon(mAbIcon) .setSmallIcon(icon ? (number ? Icon.createWithBitmap(getIconFromMinutes(left)) : Icon.createWithResource(App.getContext(), R.drawable.ic_abicon)) : Icon.createWithResource(App.getContext(), R.drawable.ic_placeholder)) .setContentInfo(sum).setContentIntent(Main.getPendingIntent(t)) .setOngoing(true)) .addLine(Vakit.getByIndex(0).getString() + ": " + Utils.fixTime(dt[0])) .addLine(Vakit.GUNES.getString() + ": " + Utils.fixTime(dt[1])) .addLine(Vakit.OGLE.getString() + ": " + Utils.fixTime(dt[2])) .addLine(Vakit.IKINDI.getString() + ": " + Utils.fixTime(dt[3])) .addLine(Vakit.AKSAM.getString() + ": " + Utils.fixTime(dt[4])) .addLine(Vakit.YATSI.getString() + ": " + Utils.fixTime(dt[5])) .setSummaryText("").build(); } else { noti = new NotificationCompat.InboxStyle(new NotificationCompat.Builder(App.getContext()) .setContentTitle(t.getName() + " (" + t.getSource() + ")").setContentText("") .setLargeIcon(mAbIcon) .setSmallIcon(icon ? R.drawable.ic_abicon : R.drawable.ic_placeholder) .setContentInfo(sum).setContentIntent(Main.getPendingIntent(t)).setOngoing(true)) .addLine(Vakit.getByIndex(0).getString() + ": " + Utils.fixTime(dt[0])) .addLine(Vakit.GUNES.getString() + ": " + Utils.fixTime(dt[1])) .addLine(Vakit.OGLE.getString() + ": " + Utils.fixTime(dt[2])) .addLine(Vakit.IKINDI.getString() + ": " + Utils.fixTime(dt[3])) .addLine(Vakit.AKSAM.getString() + ": " + Utils.fixTime(dt[4])) .addLine(Vakit.YATSI.getString() + ": " + Utils.fixTime(dt[5])) .setSummaryText("").build(); } } if (Build.VERSION.SDK_INT >= 16) { noti.priority = Notification.PRIORITY_LOW; } noti.when = icon ? System.currentTimeMillis() : 0; try { nm.notify(id + "", NotIds.ONGOING, noti); } catch (Exception e) { Crashlytics.logException(e); } } }