List of usage examples for android.text.style StyleSpan StyleSpan
public StyleSpan(@NonNull Parcel src)
From source file:org.mozilla.gecko.DataReportingNotification.java
/** * Launch a notification of the data policy, and record notification time and version. *//* www .j av a 2 s .com*/ private static void notifyDataPolicy(Context context, SharedPreferences sharedPrefs) { boolean result = false; try { // Launch main App to launch Data choices when notification is clicked. Intent prefIntent = new Intent(GeckoApp.ACTION_LAUNCH_SETTINGS); prefIntent.setClassName(AppConstants.ANDROID_PACKAGE_NAME, AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS); GeckoPreferences.setResourceToOpen(prefIntent, "preferences_vendor"); prefIntent.putExtra(ALERT_NAME_DATAREPORTING_NOTIFICATION, true); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, prefIntent, PendingIntent.FLAG_UPDATE_CURRENT); final Resources resources = context.getResources(); // Create and send notification. String notificationTitle = resources.getString(R.string.datareporting_notification_title); String notificationSummary; if (Versions.preJB) { notificationSummary = resources.getString(R.string.datareporting_notification_action); } else { // Display partial version of Big Style notification for supporting devices. notificationSummary = resources.getString(R.string.datareporting_notification_summary); } String notificationAction = resources.getString(R.string.datareporting_notification_action); String notificationBigSummary = resources.getString(R.string.datareporting_notification_summary); // Make styled ticker text for display in notification bar. String tickerString = resources.getString(R.string.datareporting_notification_ticker_text); SpannableString tickerText = new SpannableString(tickerString); // Bold the notification title of the ticker text, which is the same string as notificationTitle. tickerText.setSpan(new StyleSpan(Typeface.BOLD), 0, notificationTitle.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); Notification notification = new NotificationCompat.Builder(context).setContentTitle(notificationTitle) .setContentText(notificationSummary).setSmallIcon(R.drawable.ic_status_logo).setAutoCancel(true) .setContentIntent(contentIntent) .setStyle(new NotificationCompat.BigTextStyle().bigText(notificationBigSummary)) .addAction(R.drawable.firefox_settings_alert, notificationAction, contentIntent) .setTicker(tickerText).build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); int notificationID = ALERT_NAME_DATAREPORTING_NOTIFICATION.hashCode(); notificationManager.notify(notificationID, notification); // Record version and notification time. SharedPreferences.Editor editor = sharedPrefs.edit(); long now = System.currentTimeMillis(); editor.putLong(PREFS_POLICY_NOTIFIED_TIME, now); editor.putInt(PREFS_POLICY_VERSION, DATA_REPORTING_VERSION); editor.apply(); result = true; } finally { // We want to track any errors, so record notification outcome. Telemetry.sendUIEvent(TelemetryContract.Event.POLICY_NOTIFICATION_SUCCESS, result); } }
From source file:com.oasisfeng.nevo.decorators.whatsapp.WhatsAppDecorator.java
@Override public void apply(final StatusBarNotificationEvo evolving) throws RemoteException { final INotification n = evolving.notification(); final IBundle extras = n.extras(); final CharSequence who, group, message; @SuppressWarnings("unchecked") final List<CharSequence> lines = extras.getCharSequenceArray(EXTRA_TEXT_LINES); final boolean has_lines = lines != null && !lines.isEmpty(); final CharSequence title = extras.getCharSequence(EXTRA_TITLE); final CharSequence last = has_lines ? lines.get(lines.size() - 1) : extras.getCharSequence(EXTRA_TEXT); final CharSequence[] last_parts = extract(title, last); who = last_parts[0];//from w w w.j a v a2 s .c o m group = last_parts[1]; message = last_parts[2]; if (group != null) evolving.setTag(".Group"); else if (who != null) evolving.setTag(".Direct"); else return; // Nothing to do for other messages. final CharSequence new_title = group != null ? group : who; evolving.setId(new_title.toString().hashCode()); if (n.getColor() == 0) n.setColor(DEFAULT_COLOR); // Fix the missing color in some notifications if (!has_lines) return; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) n.removeFlags(Notification.FLAG_GROUP_SUMMARY); else extras.remove("android.support.isGroupSummary"); extras.putCharSequence(EXTRA_TITLE, new_title); extras.putCharSequence(EXTRA_TITLE_BIG, new_title); extras.putCharSequence(EXTRA_TEXT, group != null ? who + ": " + message : message); final List<CharSequence> new_lines = new ArrayList<>(lines.size()); for (final CharSequence line : lines) { final CharSequence[] parts = extract(title, line); if (group != null) { // Group chat, keep messages within the same group. if (!group.equals(parts[1])) continue; final SpannableStringBuilder new_line = new SpannableStringBuilder(); new_line.append(parts[0]).setSpan(new StyleSpan(BOLD), 0, new_line.length(), SPAN_EXCLUSIVE_EXCLUSIVE); new_lines.add(new_line.append(": ").append(parts[2])); } else if (who.equals(parts[0]) && parts[1] == null) new_lines.add(parts[2]); // Direct chat, keep messages from the same person (excluding group chat) } extras.putCharSequenceArray(EXTRA_TEXT_LINES, new_lines); extras.remove(EXTRA_SUMMARY_TEXT); extras.putString(EXTRA_REBUILD_STYLE, STYLE_INBOX); if (new_lines.size() > 1) n.setNumber(new_lines.size()); }
From source file:de.ktran.anno1404warenrechner.views.PopulationNumberDialog.java
private void setAdvancementText(int value, PopulationType.Civilization civilization) { String advanceTextStart = getActivity().getString(R.string.advance_to); String advanceName = getPopulationTypeByProgress(value, civilization).getString(getContext()); if (advancementText != null) { advancementText.setText(advanceTextStart + " " + advanceName.toLowerCase(), TextView.BufferType.SPANNABLE); Spannable sp = (Spannable) advancementText.getText(); sp.setSpan(new StyleSpan(Typeface.BOLD), advanceTextStart.length(), 1 + advanceTextStart.length() + advanceName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); }//from w w w. j av a2s . c o m }
From source file:org.sirimangalo.meditationplus.AdapterChat.java
@Override public View getView(final int position, View convertView, ViewGroup parent) { View rowView;/*from w w w .j av a 2s .c o m*/ if (convertView == null) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); rowView = inflater.inflate(R.layout.list_item_chat, parent, false); } else { rowView = convertView; } JSONObject p = values.get(position); try { int then = Integer.parseInt(p.getString("time")); long nowL = System.currentTimeMillis() / 1000; int now = (int) nowL; int ela = now - then; int day = 60 * 60 * 24; ela = ela > day ? day : ela; int intColor = 255 - Math.round((float) ela * 255 / day); intColor = intColor > 100 ? intColor : 100; String hexTransparency = Integer.toHexString(intColor); hexTransparency = hexTransparency.length() > 1 ? hexTransparency : "0" + hexTransparency; String hexColor = "#" + hexTransparency + "000000"; int transparency = Color.parseColor(hexColor); TextView time = (TextView) rowView.findViewById(R.id.time); if (time != null) { String ts = null; ts = Utils.time2Ago(then); time.setText(ts); time.setTextColor(transparency); } TextView mess = (TextView) rowView.findViewById(R.id.message); if (mess != null) { final String username = p.getString("username"); String messageString = p.getString("message"); messageString = Html.fromHtml(messageString).toString(); SpannableString messageSpan = Utils.replaceSmilies(context, messageString, intColor); if (messageString.contains("@" + loggedUser)) { int index = messageString.indexOf("@" + loggedUser); messageSpan.setSpan(new StyleSpan(Typeface.BOLD), index, index + loggedUser.length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); messageSpan.setSpan(new ForegroundColorSpan(Color.parseColor("#" + hexTransparency + "990000")), index, index + loggedUser.length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } for (String user : users) { if (!user.equals(loggedUser) && messageString.contains("@" + user)) { int index = messageString.indexOf("@" + user); messageSpan = Utils.createProfileSpan(context, index, index + user.length() + 1, user, messageSpan); messageSpan.setSpan( new ForegroundColorSpan(Color.parseColor("#" + hexTransparency + "009900")), index, index + user.length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } Spannable userSpan = Utils.createProfileSpan(context, 0, username.length(), username, new SpannableString(username + ": ")); if (p.getString("me").equals("true")) userSpan.setSpan(new ForegroundColorSpan(Color.parseColor("#" + hexTransparency + "0000FF")), 0, userSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); else userSpan.setSpan(new ForegroundColorSpan(Color.parseColor("#" + hexTransparency + "000000")), 0, userSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); CharSequence full = TextUtils.concat(userSpan, messageSpan); mess.setTextColor(transparency); mess.setText(full); mess.setMovementMethod(LinkMovementMethod.getInstance()); Linkify.addLinks(mess, Linkify.ALL); mess.setTag(p.getString("cid")); } } catch (JSONException e) { e.printStackTrace(); } return rowView; }
From source file:io.relayr.tellmewhen.gcm.GcmIntentService.java
private void sendNotification(Bundle msg) { Storage.startRuleScreen(false);//from w w w .j a va2 s. c o m String ruleId = msg.getString("rule_id", "null"); if (ruleId == null) { sendNotification(getBaseContext().getString(R.string.please_open_app)); return; } TMWRule rule = new Select().from(TMWRule.class).where("dbId = ?", ruleId).executeSingle(); if (rule == null) { sendNotification(getBaseContext().getString(R.string.please_open_app)); return; } Float notificationValue = 0f; try { notificationValue = Float.parseFloat(msg.getString("val", "0")); } catch (NumberFormatException e) { Log.e(GcmIntentService.class.getSimpleName(), e.getMessage()); } pushedRules.put(new Pair<>(rule.getSensorType(), rule.name), notificationValue); String title = pushedRules.size() + " " + (pushedRules.size() > 1 ? getString(R.string.push_notification_title) : getString(R.string.push_notification_title_one_rule)); Spannable spanTitle = new SpannableString(title); spanTitle.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); Notification notification = new Builder(getApplicationContext()).setContentIntent(createContentIntent()) .setDeleteIntent(createDeleteIntent()).setSmallIcon(R.drawable.icon_notifications) .setContentTitle(spanTitle).setContentText(getString(R.string.push_notification_summary)) .setAutoCancel(true).setStyle(prepareBigNotificationDetails(spanTitle)).build(); showNotification(TMW_NOTIFICATION_ID, notification); playSound(); }
From source file:eu.power_switch.widget.provider.ReceiverWidgetProvider.java
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { Log.d("Updating Receiver Widgets..."); // Perform this loop procedure for each App Widget that belongs to this provider for (int i = 0; i < appWidgetIds.length; i++) { int appWidgetId = appWidgetIds[i]; RemoteViews remoteViews = new RemoteViews( context.getResources().getString(eu.power_switch.shared.R.string.PACKAGE_NAME), R.layout.widget_receiver); try {/* ww w . j ava2s. c o m*/ ReceiverWidget receiverWidget = DatabaseHandler.getReceiverWidget(appWidgetId); Room room = DatabaseHandler.getRoom(receiverWidget.getRoomId()); if (room != null) { Receiver receiver = DatabaseHandler.getReceiver(receiverWidget.getReceiverId()); if (receiver != null) { Apartment apartment = DatabaseHandler.getApartment(room.getApartmentId()); // update UI remoteViews.setTextViewText(R.id.textView_receiver_widget_name, apartment.getName() + ": " + room.getName() + ": " + receiver.getName()); LinkedList<Button> buttons = receiver.getButtons(); // remove all previous buttons remoteViews.removeAllViews(R.id.linearlayout_receiver_widget); // add buttons from database int buttonOffset = 0; for (Button button : buttons) { // set button action RemoteViews buttonView = new RemoteViews( context.getResources().getString(eu.power_switch.shared.R.string.PACKAGE_NAME), R.layout.widget_receiver_button_layout); SpannableString s = new SpannableString(button.getName()); s.setSpan(new StyleSpan(Typeface.BOLD), 0, button.getName().length(), 0); buttonView.setTextViewText(R.id.button_widget_universal, s); if (SmartphonePreferencesHandler.getHighlightLastActivatedButton() && receiver.getLastActivatedButtonId().equals(button.getId())) { buttonView.setTextColor(R.id.button_widget_universal, ContextCompat.getColor(context, R.color.color_light_blue_a700)); } PendingIntent intent = WidgetIntentReceiver.buildReceiverWidgetActionPendingIntent( context, apartment, room, receiver, button, appWidgetId * 15 + buttonOffset); buttonView.setOnClickPendingIntent(R.id.button_widget_universal, intent); remoteViews.addView(R.id.linearlayout_receiver_widget, buttonView); buttonOffset++; } remoteViews.setViewVisibility(R.id.linearlayout_receiver_widget, View.VISIBLE); } else { remoteViews.setTextViewText(R.id.textView_receiver_widget_name, context.getString(R.string.receiver_not_found)); remoteViews.removeAllViews(R.id.linearlayout_receiver_widget); remoteViews.setViewVisibility(R.id.linearlayout_receiver_widget, View.GONE); } } else { remoteViews.setTextViewText(R.id.textView_receiver_widget_name, context.getString(R.string.room_not_found)); remoteViews.removeAllViews(R.id.linearlayout_receiver_widget); remoteViews.setViewVisibility(R.id.linearlayout_receiver_widget, View.GONE); } } catch (Exception e) { Log.e(e); remoteViews.setTextViewText(R.id.textView_receiver_widget_name, context.getString(R.string.unknown_error)); remoteViews.removeAllViews(R.id.linearlayout_receiver_widget); remoteViews.setViewVisibility(R.id.linearlayout_receiver_widget, View.GONE); } appWidgetManager.updateAppWidget(appWidgetId, remoteViews); } super.onUpdate(context, appWidgetManager, appWidgetIds); }
From source file:org.anoopam.main.anoopamvideo.VideoListActivity.java
@Override public void manageAppBar(ActionBar actionBar, Toolbar toolbar, ActionBarDrawerToggle actionBarDrawerToggle) { actionBar.setDisplayHomeAsUpEnabled(true); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override//from w w w .ja v a2 s. com public void onClick(View v) { finish(); } }); toolbar.setTitle(getString(R.string.nav_video)); SpannableString spannableString = new SpannableString(currentAlbumName); spannableString.setSpan(new StyleSpan(Typeface.ITALIC), 0, spannableString.length(), 0); toolbar.setSubtitle(spannableString); }
From source file:io.github.marktony.espresso.mvp.companydetails.CompanyDetailFragment.java
@Override public void setCompanyName(String name) { String companyName = getString(R.string.company_name) + "\n" + name; Spannable spannable = new SpannableStringBuilder(companyName); spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, companyName.length() - name.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan(new StyleSpan(Typeface.NORMAL), companyName.length() - name.length(), companyName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); textViewCompanyName.setText(spannable); }
From source file:com.liferay.mobile.screens.viewsets.westeros.auth.signup.SignUpView.java
private void initClickableTermsAndConditions() { TextView textView = (TextView) findViewById(R.id.terms); textView.setMovementMethod(LinkMovementMethod.getInstance()); SpannableStringBuilder ssb = new SpannableStringBuilder("I accept the terms and conditions"); ssb.setSpan(new ClickableSpan() { @Override//ww w.j a v a 2 s .c o m public void onClick(View widget) { SignUpScreenlet signUpScreenlet = getSignUpScreenlet(); signUpScreenlet.performUserAction(SignUpScreenlet.TERMS_AND_CONDITIONS); } }, 13, ssb.length(), 0); ssb.setSpan(new StyleSpan(Typeface.BOLD), 13, ssb.length(), 0); ssb.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getContext(), android.R.color.white)), 13, ssb.length(), 0); textView.setText(ssb, TextView.BufferType.SPANNABLE); }
From source file:org.anoopam.main.anoopamvideo.VideoCatListActivity.java
@Override public void manageAppBar(ActionBar actionBar, Toolbar toolbar, ActionBarDrawerToggle actionBarDrawerToggle) { actionBar.setDisplayHomeAsUpEnabled(true); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override/*from ww w. ja v a 2s . c om*/ public void onClick(View v) { handleBackPress(); } }); toolbar.setTitle(getString(R.string.nav_video_title)); SpannableString spannableString = new SpannableString(albumName); spannableString.setSpan(new StyleSpan(Typeface.ITALIC), 0, spannableString.length(), 0); toolbar.setSubtitle(spannableString); }