List of usage examples for android.text SpannableString SpannableString
public SpannableString(CharSequence source)
From source file:io.relayr.tellmewhen.gcm.GcmIntentService.java
private void sendNotification(Bundle msg) { Storage.startRuleScreen(false);//from w ww . ja v a2 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:com.thatkawaiiguy.meleehandbook.adapter.SearchAdapter.java
private void highlightAndCut(String search, String originalText, TextView textView) { int startPos = originalText.toLowerCase().indexOf(search); int endPos = startPos + search.length(); int wholeStart = originalText.toLowerCase().indexOf(" ", startPos - 100); if (wholeStart == -1) wholeStart = 0;//from w w w. j a v a2s . c o m if (originalText.substring(wholeStart, wholeStart + 1).equals(",")) wholeStart += 1; int wholeEnd = originalText.toLowerCase().indexOf(" ", endPos + 100 < originalText.length() - 1 ? endPos + 100 : endPos - search.length() - 1); if (wholeEnd == -1) wholeEnd = endPos; originalText = originalText.substring(wholeStart, wholeEnd).trim() + " (Click for more)"; startPos = originalText.toLowerCase().indexOf(search); endPos = startPos + search.length(); // This should always be true, just a sanity check if (startPos != -1) { Spannable spannable = new SpannableString(originalText); ColorStateList yellowColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { ContextCompat.getColor(mContext, R.color.overscroll_color) }); TextAppearanceSpan highlightSpan = new TextAppearanceSpan(null, Typeface.BOLD, -1, yellowColor, null); spannable.setSpan(highlightSpan, startPos, endPos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText(spannable); } else textView.setText(originalText); }
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 {// w w w.j a va 2 s .c om 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:com.maxleapmobile.gitmaster.ui.fragment.RecommendFragment.java
private void initUI(View view) { actionArea = (LinearLayout) view.findViewById(R.id.recommend_action_area); starProgressBar = (ProgressBar) view.findViewById(R.id.recommend_star_progressbar); starText = (TextView) view.findViewById(R.id.recommend_star); starText.setOnClickListener(this); view.findViewById(R.id.recommend_fork).setOnClickListener(this); skipBtn = view.findViewById(R.id.recommend_skip); skipBtn.setOnClickListener(this); mProgressBar = (ProgressBar) view.findViewById(R.id.repo_progressbar); TextView notice2 = (TextView) view.findViewById(R.id.recommend_notice2); SpannableString notice2SS = new SpannableString(mContext.getString(R.string.recommend_notice2_part1) + " " + mContext.getString(R.string.recommend_notice2_part2)); notice2SS.setSpan(new CustomClickableSpan(), 0, mContext.getString(R.string.recommend_notice2_part1).length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); notice2.setText(notice2SS);/*from w w w . j av a 2 s.co m*/ notice2.setOnClickListener(this); notice3 = (TextView) view.findViewById(R.id.recommend_notice3); final SpannableString notice3SS = new SpannableString(mContext.getString(R.string.recommend_notice3_part1) + " " + mContext.getString(R.string.recommend_notice3_part2)); notice3SS.setSpan(new CustomClickableSpan(), mContext.getString(R.string.recommend_notice3_part1).length(), notice3SS.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); notice3.setText(notice3SS); notice3.setOnClickListener(this); mWebView = (ProgressWebView) view.findViewById(R.id.recommend_webview); mWebView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); mProgressBar.setVisibility(View.GONE); } }); mEmptyView = (LinearLayout) view.findViewById(R.id.recommend_empty); mEmptyView.setVisibility(View.GONE); if (mParmasMap == null) { mParmasMap = new HashMap(); mParmasMap.put("userid", username); mParmasMap.put("page", page); mParmasMap.put("per_page", PER_PAGE); } }
From source file:org.thoughtcrime.securesms.components.webrtc.WebRtcCallScreen.java
public void setUntrustedIdentity(Recipient personInfo, IdentityKey untrustedIdentity) { String name = recipient.toShortString(); String introduction = String.format(getContext().getString(R.string.WebRtcCallScreen_new_safety_numbers), name, name);/*from www.j a va 2 s . c o m*/ SpannableString spannableString = new SpannableString(introduction + " " + getContext().getString(R.string.WebRtcCallScreen_you_may_wish_to_verify_this_contact)); spannableString.setSpan(new VerifySpan(getContext(), personInfo.getRecipientId(), untrustedIdentity), introduction.length() + 1, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); setPersonInfo(personInfo); this.incomingCallOverlay.setActiveCall(); this.status.setText(R.string.WebRtcCallScreen_new_safety_numbers_title); this.untrustedIdentityContainer.setVisibility(View.VISIBLE); this.untrustedIdentityExplanation.setText(spannableString); this.untrustedIdentityExplanation.setMovementMethod(LinkMovementMethod.getInstance()); this.endCallButton.setVisibility(View.INVISIBLE); }
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. java 2 s.c om*/ 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:nz.al4.airclock.AirClockFragment.java
private View setupDate() { // add digital date textDate = new TextClock(getContext()); textDate.setId(textDateId);/* w ww . ja v a 2s .c o m*/ RelativeLayout.LayoutParams textDateParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); textDateParams.addRule(RelativeLayout.BELOW, textClockId); textDate.setLayoutParams(textDateParams); textDate.setTypeface(textDate.getTypeface(), Typeface.BOLD); textDate.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); textDate.setGravity(Gravity.CENTER_HORIZONTAL); SpannableString dateSpan = new SpannableString("yyyy/MM/dd"); textDate.setFormat24Hour(dateSpan); textDate.setFormat12Hour(dateSpan); return textDate; }
From source file:org.floens.chan.ui.controller.ThemeSettingsController.java
@Override public void onCreate() { super.onCreate(); navigationItem.setTitle(R.string.settings_screen_theme); navigationItem.swipeable = false;/*w ww .j a v a 2 s . c o m*/ view = inflateRes(R.layout.controller_theme); themeHelper = ThemeHelper.getInstance(); themes = themeHelper.getThemes(); pager = (ViewPager) view.findViewById(R.id.pager); done = (FloatingActionButton) view.findViewById(R.id.add); done.setOnClickListener(this); textView = (TextView) view.findViewById(R.id.text); SpannableString changeAccentColor = new SpannableString(getString(R.string.setting_theme_accent)); changeAccentColor.setSpan(new ClickableSpan() { @Override public void onClick(View widget) { showAccentColorPicker(); } }, 0, changeAccentColor.length(), 0); textView.setText(TextUtils.concat(getString(R.string.setting_theme_explanation), changeAccentColor)); textView.setMovementMethod(LinkMovementMethod.getInstance()); adapter = new Adapter(); pager.setAdapter(adapter); ChanSettings.ThemeColor currentSettingsTheme = ChanSettings.getThemeAndColor(); for (int i = 0; i < themeHelper.getThemes().size(); i++) { Theme theme = themeHelper.getThemes().get(i); ThemeHelper.PrimaryColor primaryColor = theme.primaryColor; if (theme.name.equals(currentSettingsTheme.theme)) { // Current theme pager.setCurrentItem(i, false); } selectedPrimaryColors.add(primaryColor); } selectedAccentColor = themeHelper.getTheme().accentColor; done.setBackgroundTintList(ColorStateList.valueOf(selectedAccentColor.color)); }
From source file:io.vit.vitio.HomeActivity.java
public void setToolbarFormat(int pos, String t) { theme.refreshTheme();/* w ww.ja v a 2 s . c o m*/ if (!getSupportActionBar().isShowing()) { getSupportActionBar().show(); } String title = t; TypedArray colorres = theme.getToolbarColorTypedArray(); Log.d("setTooltheme", PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", "null")); getSupportActionBar() .setBackgroundDrawable(new ColorDrawable(getResources().getColor(colorres.getResourceId(pos, -1)))); SpannableString s = new SpannableString(title); s.setSpan(theme.getMyThemeTypeFaceSpan(), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); getSupportActionBar().setTitle(s); }
From source file:com.kawakawaplanning.rssreader.Main.MainActivity.java
private SpannableString createSpannableString(String message, Map<String, String> map) { SpannableString ss = new SpannableString(message); for (final Map.Entry<String, String> entry : map.entrySet()) { int start = 0; int end = 0; // ?? start, end ? Pattern pattern = Pattern.compile(entry.getKey()); Matcher matcher = pattern.matcher(message); while (matcher.find()) { start = matcher.start();//from w w w .ja v a 2 s.c om end = matcher.end(); break; } // SpannableString ??? ss.setSpan(new ClickableSpan() { @Override public void onClick(View textView) { Intent intent = new Intent(getApplicationContext(), OpenSourceLicenseActivity.class); startActivity(intent); } }, start, end, Spanned.SPAN_INCLUSIVE_INCLUSIVE); } return ss; }