List of usage examples for android.text SpannableString SpannableString
public SpannableString(CharSequence source)
From source file:com.popdeem.sdk.uikit.adapter.PDUIFeedRecyclerViewAdapter.java
@Deprecated private Spannable getRedemptionText(Context context, String firstName, String secondName, String reward, String brandName, boolean isCheckin) { String fullName = firstName + " " + secondName; String redemptionName;// w w w . j av a 2 s . c o m if (fullName.equalsIgnoreCase(mCurrentUserName)) { redemptionName = "You"; } else { redemptionName = fullName; } String redemptionAction; if (isCheckin) { redemptionAction = "checked in and redeemed"; } else { redemptionAction = "shared an image and redeemed"; } Spannable spannable = new SpannableString( redemptionName + " " + redemptionAction + " " + reward + " at " + brandName); spannable.setSpan( new ForegroundColorSpan(ContextCompat.getColor(context, R.color.pd_feed_item_name_text_color)), 0, redemptionName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan( new ForegroundColorSpan(ContextCompat.getColor(context, R.color.pd_feed_item_title_text_color)), (redemptionName + " " + redemptionAction).length(), (redemptionName + " " + redemptionAction + " ").length() + reward.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan( new ForegroundColorSpan(ContextCompat.getColor(context, R.color.pd_feed_item_title_text_color)), (redemptionName + " " + redemptionAction + " " + reward + " at").length(), (redemptionName + " " + redemptionAction + " " + reward + " at ").length() + brandName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannable; }
From source file:com.flowzr.activity.EntityListActivity.java
public void setMyTitle(String t) { SpannableString s = new SpannableString(t); s.setSpan(new TypefaceSpan("sans-serif"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); getSupportActionBar().setTitle(s);/*from www .j ava 2 s. co m*/ }
From source file:gov.wa.wsdot.android.wsdot.ui.tollrates.I405TollRatesFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_dynamic_toll_rates, null); mRecyclerView = root.findViewById(R.id.my_recycler_view); mRecyclerView.setHasFixedSize(true); mLayoutManager = new LinearLayoutManager(getActivity()); mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); mRecyclerView.setLayoutManager(mLayoutManager); mAdapter = new I405TollRatesItemAdapter(getActivity()); mRecyclerView.setAdapter(mAdapter);//from w w w . ja v a 2 s.com mRecyclerView.addItemDecoration(new SimpleDividerItemDecoration(getActivity())); mRecyclerView.setPadding(0, 0, 0, 120); addDisclaimerView(root); directionRadioGroup = root.findViewById(R.id.segment_control); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); radioGroupDirectionIndex = sharedPref.getInt(getString(R.string.toll_rates_405_travel_direction_key), 0); if (radioGroupDirectionIndex == 0) { RadioButton leftSegment = root.findViewById(R.id.radio_left); leftSegment.setChecked(true); } else { RadioButton rightSegment = root.findViewById(R.id.radio_right); rightSegment.setChecked(true); } directionRadioGroup.setOnCheckedChangeListener((group, checkedId) -> { RadioButton selectedDirection = directionRadioGroup.findViewById(checkedId); mAdapter.setData(filterTollsForDirection(String.valueOf(selectedDirection.getText().charAt(0)))); mLayoutManager.scrollToPositionWithOffset(0, 0); SharedPreferences sharedPref1 = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences.Editor editor = sharedPref1.edit(); radioGroupDirectionIndex = directionRadioGroup.indexOfChild(selectedDirection); TextView travelTimeView = root.findViewById(R.id.travel_time_text); travelTimeView.setText(getTravelTimeStringForDirection(radioGroupDirectionIndex == 0 ? "N" : "S")); editor.putInt(getString(R.string.toll_rates_405_travel_direction_key), radioGroupDirectionIndex); editor.apply(); }); // For some reason, if we omit this, NoSaveStateFrameLayout thinks we are // FILL_PARENT / WRAP_CONTENT, making the progress bar stick to the top of the activity. root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); swipeRefreshLayout = root.findViewById(R.id.swipe_container); swipeRefreshLayout.setOnRefreshListener(this); swipeRefreshLayout.setColorSchemeResources(R.color.holo_blue_bright, R.color.holo_green_light, R.color.holo_orange_light, R.color.holo_red_light); mEmptyView = root.findViewById(R.id.empty_list_view); TextView header_link = root.findViewById(R.id.header_text); // create spannable string for underline SpannableString content = new SpannableString( getActivity().getResources().getString(R.string.i405_info_link)); content.setSpan(new UnderlineSpan(), 0, content.length(), 0); header_link.setText(content); header_link.setTextColor(getResources().getColor(R.color.primary_default)); header_link.setOnClickListener(v -> { Intent intent = new Intent(); // GA tracker mTracker = ((WsdotApplication) getActivity().getApplication()).getDefaultTracker(); mTracker.setScreenName("/Toll Rates/Learn about I-405"); mTracker.send(new HitBuilders.ScreenViewBuilder().build()); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse("https://www.wsdot.wa.gov/Tolling/405/rates.htm")); startActivity(intent); }); viewModel = ViewModelProviders.of(this, viewModelFactory).get(TollRatesViewModel.class); viewModel.getResourceStatus().observe(this, resourceStatus -> { if (resourceStatus != null) { switch (resourceStatus.status) { case LOADING: swipeRefreshLayout.setRefreshing(true); break; case SUCCESS: swipeRefreshLayout.setRefreshing(false); break; case ERROR: swipeRefreshLayout.setRefreshing(false); Toast.makeText(this.getContext(), "connection error", Toast.LENGTH_LONG).show(); } } }); viewModel.getTravelTimesStatus().observe(this, resourceStatus -> { if (resourceStatus != null) { switch (resourceStatus.status) { case LOADING: break; case SUCCESS: root.findViewById(R.id.travel_time_text).setVisibility(View.VISIBLE); break; case ERROR: root.findViewById(R.id.travel_time_text).setVisibility(View.GONE); } } }); viewModel.getI405TollRateItems().observe(this, tollRateGroups -> { if (tollRateGroups != null) { mEmptyView.setVisibility(View.GONE); Collections.sort(tollRateGroups, new SortTollGroupByLocation()); Collections.sort(tollRateGroups, new SortTollGroupByDirection()); tollGroups = new ArrayList<>(tollRateGroups); directionRadioGroup.getCheckedRadioButtonId(); RadioButton selectedDirection = directionRadioGroup .findViewById(directionRadioGroup.getCheckedRadioButtonId()); mAdapter.setData(filterTollsForDirection(String.valueOf(selectedDirection.getText().charAt(0)))); } }); viewModel.getTravelTimesForETLFor("405").observe(this, travelTimes -> { TextView travelTimeView = root.findViewById(R.id.travel_time_text); if (travelTimes.size() > 0) { travelTimeView.setVisibility(View.VISIBLE); this.travelTimes = new ArrayList<>(travelTimes); travelTimeView.setText(getTravelTimeStringForDirection(radioGroupDirectionIndex == 0 ? "N" : "S")); } else { travelTimeView.setVisibility(View.GONE); } }); timer = new Timer(); timer.schedule(new RatesTimerTask(), 0, 60000); // Schedule rates to update every 60 seconds return root; }
From source file:com.eugene.fithealthmaingit.MainActivity.java
private void applyFontToMenuItem(MenuItem mi) { Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Regular.ttf"); SpannableString mNewTitle = new SpannableString(mi.getTitle()); mNewTitle.setSpan(new CustomTypefaceSpan("", font), 0, mNewTitle.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); mi.setTitle(mNewTitle);//from w ww . j a v a 2s . c o m }
From source file:se.anyro.tagtider.TransferActivity.java
private void setupTransferData(final Bundle extras) { TextView trainView = (TextView) findViewById(R.id.train); ViewGroup originGroup = (ViewGroup) findViewById(R.id.origin_group); TextView originView = (TextView) findViewById(R.id.origin); TextView arrivalView = (TextView) findViewById(R.id.arrival); TextView stationTrackView = (TextView) findViewById(R.id.station_track); ViewGroup destinationGroup = (ViewGroup) findViewById(R.id.destination_group); TextView destinationView = (TextView) findViewById(R.id.destination); TextView departureView = (TextView) findViewById(R.id.departure); TextView commentView = (TextView) findViewById(R.id.comment); mEmptyView = (TextView) findViewById(android.R.id.empty); trainView.setText("Tg " + extras.getString("train") + " (" + extras.getString("type") + ")"); String origin = extras.getString("origin"); if (origin != null && origin.length() > 0) { originView.setText("Frn " + origin); originGroup.setVisibility(View.VISIBLE); } else {/*from w w w . j ava2 s .co m*/ originGroup.setVisibility(View.GONE); } String track = extras.getString("track"); if (track == null || track.equalsIgnoreCase("x") || track.equalsIgnoreCase("null")) track = ""; String arrival = extras.getString("arrival"); if (arrival != null && !arrival.startsWith("0000")) { arrivalView.setText("Ankommer " + StringUtils.extractTime(arrival)); String newArrival = extras.getString("newArrival"); if (newArrival != null) { newArrival = StringUtils.extractTime(newArrival); SpannableString strike = new SpannableString(arrivalView.getText() + " " + newArrival); strike.setSpan(new StrikethroughSpan(), strike.length() - 11, strike.length() - 6, 0); arrivalView.setText(strike, TextView.BufferType.SPANNABLE); } if (track.length() == 0) { SpannableString strike = new SpannableString(arrivalView.getText()); strike.setSpan(new StrikethroughSpan(), strike.length() - 5, strike.length(), 0); arrivalView.setText(strike, TextView.BufferType.SPANNABLE); } } if (extras.getString("stationName") != null) { mStationName = extras.getString("stationName"); } if (track.length() > 0 && mStationName != null) stationTrackView.setText(mStationName + ", spr " + track); else if (mStationName != null) stationTrackView.setText(mStationName); else if (track.length() > 0) stationTrackView.setText("Spr " + track); else stationTrackView.setText(""); String destination = extras.getString("destination"); if (destination != null && destination.length() > 0) { destinationView.setText("Till " + destination); destinationGroup.setVisibility(View.VISIBLE); } else { destinationGroup.setVisibility(View.GONE); } String departure = extras.getString("departure"); if (departure != null && !departure.startsWith("0000")) { departureView.setText("Avgr " + StringUtils.extractTime(departure)); String newDeparture = extras.getString("newDeparture"); if (newDeparture != null) { newDeparture = StringUtils.extractTime(newDeparture); SpannableString strike = new SpannableString(departureView.getText() + " " + newDeparture); strike.setSpan(new StrikethroughSpan(), strike.length() - 11, strike.length() - 6, 0); departureView.setText(strike, TextView.BufferType.SPANNABLE); } if (track.length() == 0) { SpannableString strike = new SpannableString(departureView.getText()); strike.setSpan(new StrikethroughSpan(), strike.length() - 5, strike.length(), 0); departureView.setText(strike, TextView.BufferType.SPANNABLE); } } String comment = extras.getString("comment"); if ((comment == null || comment.length() == 0) && track.length() == 0) comment = "Instllt"; if (comment != null && comment.length() > 0) { commentView.setText(comment); commentView.setVisibility(View.VISIBLE); } else { commentView.setVisibility(View.GONE); } mTrain = extras.getString("train"); mStationId = extras.getString("stationId"); mTransferId = extras.getString("id"); }
From source file:com.tct.email.provider.EmailMessageCursor.java
public EmailMessageCursor(final Context c, final Cursor cursor, final String htmlColumn, final String textColumn) { super(cursor); mHtmlColumnIndex = cursor.getColumnIndex(htmlColumn); mTextColumnIndex = cursor.getColumnIndex(textColumn); final int cursorSize = cursor.getCount(); mHtmlParts = new SparseArray<String>(cursorSize); mTextParts = new SparseArray<String>(cursorSize); //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_S mHtmlLinkifyColumnIndex = cursor.getColumnIndex(UIProvider.MessageColumns.BODY_HTML_LINKIFY); mHtmlLinkifyParts = new SparseArray<String>(cursorSize); mTextLinkifyColumnIndex = cursor.getColumnIndex(UIProvider.MessageColumns.BODY_TEXT_LINKIFY); mTextLinkifyParts = new SparseArray<String>(cursorSize); //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_E final ContentResolver cr = c.getContentResolver(); while (cursor.moveToNext()) { final int position = cursor.getPosition(); final long messageId = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID)); // TS: chao.zhang 2015-09-14 EMAIL BUGFIX-1039046 MOD_S InputStream htmlIn = null; InputStream textIn = null; try {/* ww w.ja va 2 s . c o m*/ if (mHtmlColumnIndex != -1) { final Uri htmlUri = Body.getBodyHtmlUriForMessageWithId(messageId); //WARNING: Actually openInput will used 2 PIPE(FD) to connect,but if some exception happen during connect, //such as fileNotFoundException,maybe the connection will not be closed. just a try!!! htmlIn = cr.openInputStream(htmlUri); final String underlyingHtmlString; try { underlyingHtmlString = IOUtils.toString(htmlIn); } finally { htmlIn.close(); htmlIn = null; } //TS: zhaotianyong 2015-04-05 EMAIL BUGFIX_964325 MOD_S final String sanitizedHtml = HtmlSanitizer.sanitizeHtml(underlyingHtmlString); mHtmlParts.put(position, sanitizedHtml); //TS: zhaotianyong 2015-04-05 EMAIL BUGFIX_964325 MOD_E //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_S //NOTE: add links for sanitized html if (!TextUtils.isEmpty(sanitizedHtml)) { final String linkifyHtml = com.tct.mail.utils.Linkify.addLinks(sanitizedHtml); mHtmlLinkifyParts.put(position, linkifyHtml); } else { mHtmlLinkifyParts.put(position, ""); } //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_E } } catch (final IOException e) { LogUtils.v(LogUtils.TAG, e, "Did not find html body for message %d", messageId); } catch (final OutOfMemoryError oom) { LogUtils.v(LogUtils.TAG, oom, "Terrible,OOM happen durning query EmailMessageCursor in bodyHtml,current message %d", messageId); mHtmlLinkifyParts.put(position, ""); } try { if (mTextColumnIndex != -1) { final Uri textUri = Body.getBodyTextUriForMessageWithId(messageId); textIn = cr.openInputStream(textUri); final String underlyingTextString; try { underlyingTextString = IOUtils.toString(textIn); } finally { textIn.close(); textIn = null; } mTextParts.put(position, underlyingTextString); //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_S //NOTE: add links for underlying text string if (!TextUtils.isEmpty(underlyingTextString)) { final SpannableString spannable = new SpannableString(underlyingTextString); Linkify.addLinks(spannable, Linkify.EMAIL_ADDRESSES | Linkify.WEB_URLS | Linkify.PHONE_NUMBERS); final String linkifyText = Html.toHtml(spannable); mTextLinkifyParts.put(position, linkifyText); } else { mTextLinkifyParts.put(position, ""); } //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_E } } catch (final IOException e) { LogUtils.v(LogUtils.TAG, e, "Did not find text body for message %d", messageId); } catch (final OutOfMemoryError oom) { LogUtils.v(LogUtils.TAG, oom, "Terrible,OOM happen durning query EmailMessageCursor in bodyText,current message %d", messageId); mTextLinkifyParts.put(position, ""); } //NOTE:Remember that this just a protective code,for better release Not used Resources. if (htmlIn != null) { try { htmlIn.close(); } catch (IOException e1) { LogUtils.v(LogUtils.TAG, e1, "IOException happen while close the htmlInput connection "); } } if (textIn != null) { try { textIn.close(); } catch (IOException e2) { LogUtils.v(LogUtils.TAG, e2, "IOException happen while close the textInput connection "); } } // TS: chao.zhang 2015-09-14 EMAIL BUGFIX-1039046 MOD_E } cursor.moveToPosition(-1); }
From source file:org.sirimangalo.meditationplus.AdapterCommit.java
@Override public View getView(final int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate(R.layout.list_item_commit, parent, false); final View shell = rowView.findViewById(R.id.detail_shell); rowView.setOnClickListener(new View.OnClickListener() { @Override/*from w ww . j a v a2 s .com*/ public void onClick(View view) { boolean visible = shell.getVisibility() == View.VISIBLE; shell.setVisibility(visible ? View.GONE : View.VISIBLE); context.setCommitVisible(position, !visible); } }); final JSONObject p = values.get(position); TextView title = (TextView) rowView.findViewById(R.id.title); TextView descV = (TextView) rowView.findViewById(R.id.desc); TextView defV = (TextView) rowView.findViewById(R.id.def); TextView usersV = (TextView) rowView.findViewById(R.id.users); TextView youV = (TextView) rowView.findViewById(R.id.you); try { if (p.getBoolean("open")) shell.setVisibility(View.VISIBLE); title.setText(p.getString("title")); descV.setText(p.getString("description")); String length = p.getString("length"); String time = p.getString("time"); final String cid = p.getString("cid"); String def = ""; boolean repeat = false; if (length.indexOf(":") > 0) { repeat = true; String[] lengtha = length.split(":"); def += lengtha[0] + " minutes walking and " + lengtha[1] + " minutes sitting"; } else def += length + " minutes total meditation"; String period = p.getString("period"); String day = p.getString("day"); if (period.equals("daily")) { if (repeat) def += " every day"; else def += " per day"; } else if (period.equals("weekly")) { if (repeat) def += " every " + dow[Integer.parseInt(day)]; else def += " per week"; } else if (period.equals("monthly")) { if (repeat) def += " on the " + day + (day.substring(day.length() - 1).equals("1") ? "st" : (day.substring(day.length() - 1).equals("2") ? "nd" : (day.substring(day.length() - 1).equals("3") ? "rd" : "th"))) + " day of the month"; else def += " per month"; } else if (period.equals("yearly")) { if (repeat) def += " on the " + day + (day.substring(day.length() - 1).equals("1") ? "st" : (day.substring(day.length() - 1).equals("2") ? "nd" : (day.substring(day.length() - 1).equals("3") ? "rd" : "th"))) + " day of the year"; else def += " per year"; } if (!time.equals("any")) { Calendar utc = Calendar.getInstance(TimeZone.getTimeZone("UTC")); utc.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time.split(":")[0])); utc.set(Calendar.MINUTE, Integer.parseInt(time.split(":")[1])); Calendar here = Calendar.getInstance(); here.setTimeInMillis(utc.getTimeInMillis()); int hours = here.get(Calendar.HOUR_OF_DAY); int minutes = here.get(Calendar.MINUTE); def += " at " + (time.length() == 4 ? "0" : "") + time.replace(":", "") + "h UTC <i>(" + (hours > 12 ? hours - 12 : hours) + ":" + ((minutes < 10 ? "0" : "") + minutes) + " " + (hours > 11 && hours < 24 ? "PM" : "AM") + " your time)</i>"; } defV.setText(Html.fromHtml(def)); JSONObject usersJ = p.getJSONObject("users"); ArrayList<String> committedArray = new ArrayList<String>(); // collect into array for (int i = 0; i < usersJ.names().length(); i++) { try { String j = usersJ.names().getString(i); String k = j; // if(j.equals(p.getString("creator"))) // k = "["+j+"]"; committedArray.add(k); } catch (JSONException e) { e.printStackTrace(); } } String text = context.getString(R.string.committed) + " "; // add spans int committed = -1; int pos = text.length(); // start after "Committed: " text += TextUtils.join(", ", committedArray); Spannable span = new SpannableString(text); span.setSpan(new StyleSpan(Typeface.BOLD), 0, pos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // bold the "Online: " for (int i = 0; i < committedArray.size(); i++) { try { final String oneCom = committedArray.get(i); String userCom = usersJ.getString(oneCom); //String userCom = usersJ.getString(oneCom.replace("[", "").replace("]", "")); //if(oneCom.replace("[","").replace("]","").equals(loggedUser)) if (oneCom.equals(loggedUser)) committed = Integer.parseInt(userCom); int end = pos + oneCom.length(); ClickableSpan clickable = new ClickableSpan() { @Override public void onClick(View widget) { context.showProfile(oneCom); } }; span.setSpan(clickable, pos, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new UnderlineSpan() { public void updateDrawState(TextPaint tp) { tp.setUnderlineText(false); } }, pos, end, 0); String color = Utils.makeRedGreen(Integer.parseInt(userCom), true); span.setSpan(new ForegroundColorSpan(Color.parseColor("#FF" + color)), pos, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); pos += oneCom.length() + 2; } catch (JSONException e) { e.printStackTrace(); } } usersV.setText(span); usersV.setMovementMethod(new LinkMovementMethod()); if (loggedUser != null && loggedUser.length() > 0) { LinearLayout bl = (LinearLayout) rowView.findViewById(R.id.commit_buttons); if (!usersJ.has(loggedUser)) { Button commitB = new Button(context); commitB.setId(R.id.commit_button); commitB.setText(R.string.commit); commitB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>(); nvp.add(new BasicNameValuePair("full_update", "true")); context.doSubmit("commitform_" + cid, nvp, true); } }); bl.addView(commitB); } else { Button commitB = new Button(context); commitB.setId(R.id.uncommit_button); commitB.setText(R.string.uncommit); commitB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>(); nvp.add(new BasicNameValuePair("full_update", "true")); context.doSubmit("uncommitform_" + cid, nvp, true); } }); bl.addView(commitB); } if (loggedUser.equals(p.getString("creator")) || context.isAdmin) { Button commitB2 = new Button(context); commitB2.setId(R.id.edit_commit_button); commitB2.setText(R.string.edit); commitB2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent i = new Intent(context, ActivityCommit.class); i.putExtra("commitment", p.toString()); context.startActivity(i); } }); bl.addView(commitB2); Button commitB3 = new Button(context); commitB3.setId(R.id.uncommit_button); commitB3.setText(R.string.delete); commitB3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>(); nvp.add(new BasicNameValuePair("full_update", "true")); context.doSubmit("delcommitform_" + cid, nvp, true); } }); bl.addView(commitB3); } } if (committed > -1) { int color = Color.parseColor("#FF" + Utils.makeRedGreen(committed, false)); rowView.setBackgroundColor(color); } if (committed != -1) { youV.setText(String.format(context.getString(R.string.you_commit_x), committed)); youV.setVisibility(View.VISIBLE); } } catch (Exception e) { e.printStackTrace(); } return rowView; }
From source file:org.jraf.android.dcn.handheld.app.geofencing.GeofencingService.java
private void showEnteredNotification(AddressInfo addressInfo) { Log.d("addressInfo=" + addressInfo); String titleShort = getNotificationTitle(addressInfo, false); String titleLong = getNotificationTitle(addressInfo, true); String textShort = getNotificationText(addressInfo, false); String textLong = getNotificationText(addressInfo, true); NotificationCompat.Builder mainNotifBuilder = new NotificationCompat.Builder(this); // Small icon mainNotifBuilder.setSmallIcon(R.drawable.ic_stat_entered); // Make a bigger title SpannableString titleSpannable = new SpannableString(titleShort); Object span = new TextAppearanceSpan(this, R.style.NotificationContentTitleTextAppearance); titleSpannable.setSpan(span, 0, titleShort.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // Title//from w w w. jav a 2 s . c om mainNotifBuilder.setContentTitle(titleSpannable); // Ticker mainNotifBuilder.setTicker(titleShort); // Text (short) mainNotifBuilder.setContentText(textShort); // Text (long) mainNotifBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(textLong)); // Misc mainNotifBuilder.setPriority(NotificationCompat.PRIORITY_HIGH); // Time sensitive, try to appear on top mainNotifBuilder.setCategory(NotificationCompat.CATEGORY_STATUS); // Not sure if this category is really the most appropriate mainNotifBuilder.setLights(0, 0, 0); // No light mainNotifBuilder.setShowWhen(false); // No date mainNotifBuilder.addPerson(addressInfo.contactInfo.contentLookupUri.toString()); // Contact photo Bitmap contactPhoto = addressInfo.getContactPhoto(this); if (contactPhoto != null) mainNotifBuilder.setLargeIcon(contactPhoto); // Dismiss intent Intent dismissIntent = new Intent(ACTION_DISMISS_NOTIFICATION, null, this, getClass()); PendingIntent dismissPendingIntent = PendingIntent.getService(this, 0, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT); mainNotifBuilder.setDeleteIntent(dismissPendingIntent); // Main action (click on the notification itself) Intent mainIntent = new Intent(Intent.ACTION_VIEW); mainIntent.setData(addressInfo.contactInfo.contentLookupUri); PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT); mainNotifBuilder.setContentIntent(mainPendingIntent); String phoneNumber = addressInfo.getContactPhoneNumber(this); if (phoneNumber != null) { // Call action Intent callIntent = new Intent(Intent.ACTION_DIAL); callIntent.setData(Uri.parse("tel:" + phoneNumber)); PendingIntent callPendingIntent = PendingIntent.getActivity(this, 0, callIntent, PendingIntent.FLAG_UPDATE_CURRENT); String callText = getString(R.string.notification_action_call); mainNotifBuilder.addAction(R.drawable.ic_action_call, callText, callPendingIntent); // Sms action Intent smsIntent = new Intent(Intent.ACTION_VIEW); smsIntent.setData(Uri.parse("sms:" + phoneNumber)); smsIntent.putExtra("sms_body", getString(R.string.notification_action_sms_body)); PendingIntent smsPendingIntent = PendingIntent.getActivity(this, 0, smsIntent, PendingIntent.FLAG_UPDATE_CURRENT); String smsText = getString(R.string.notification_action_sms); mainNotifBuilder.addAction(R.drawable.ic_action_sms, smsText, smsPendingIntent); } // Since we have a specific Wear notification, show this one only on handheld mainNotifBuilder.setLocalOnly(true); // Show it Notification notification = mainNotifBuilder.build(); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, notification); // Show a Wear notification // Blocking mWearHelper.connect(this); mWearHelper.putNotification(titleLong, textShort, textLong, contactPhoto, addressInfo.contactInfo.contentLookupUri, phoneNumber); }
From source file:com.tasomaniac.openwith.settings.SettingsFragment.java
private static CharSequence coloredErrorString(Context context, CharSequence originalString) { SpannableString errorSpan = new SpannableString(originalString); ForegroundColorSpan colorSpan = new ForegroundColorSpan( ContextCompat.getColor(context, R.color.error_color)); errorSpan.setSpan(colorSpan, 0, originalString.length(), 0); return errorSpan; }
From source file:org.thoughtcrime.securesms.PassphrasePromptActivity.java
private void initializeResources() { ImageButton okButton = findViewById(R.id.ok_button); Toolbar toolbar = findViewById(R.id.toolbar); showButton = findViewById(R.id.passphrase_visibility); hideButton = findViewById(R.id.passphrase_visibility_off); visibilityToggle = findViewById(R.id.button_toggle); passphraseText = findViewById(R.id.passphrase_edit); passphraseAuthContainer = findViewById(R.id.password_auth_container); fingerprintPrompt = findViewById(R.id.fingerprint_auth_container); lockScreenButton = findViewById(R.id.lock_screen_auth_container); fingerprintManager = FingerprintManagerCompat.from(this); fingerprintCancellationSignal = new CancellationSignal(); fingerprintListener = new FingerprintListener(); setSupportActionBar(toolbar);/* ww w . j a v a2 s . c o m*/ getSupportActionBar().setTitle(""); SpannableString hint = new SpannableString( " " + getString(R.string.PassphrasePromptActivity_enter_passphrase)); hint.setSpan(new RelativeSizeSpan(0.9f), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); hint.setSpan(new TypefaceSpan("sans-serif"), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); passphraseText.setHint(hint); okButton.setOnClickListener(new OkButtonClickListener()); showButton.setOnClickListener(new ShowButtonOnClickListener()); hideButton.setOnClickListener(new HideButtonOnClickListener()); passphraseText.setOnEditorActionListener(new PassphraseActionListener()); passphraseText.setImeActionLabel(getString(R.string.prompt_passphrase_activity__unlock), EditorInfo.IME_ACTION_DONE); fingerprintPrompt.setImageResource(R.drawable.ic_fingerprint_white_48dp); fingerprintPrompt.getBackground().setColorFilter(getResources().getColor(R.color.signal_primary), PorterDuff.Mode.SRC_IN); lockScreenButton.setOnClickListener(v -> resumeScreenLock()); }