List of usage examples for android.text SpannableString setSpan
public void setSpan(Object what, int start, int end, int flags)
From source file:com.android.mail.utils.NotificationUtils.java
/** * Sets the bigtext for a notification for a single new conversation * * @param context//from w w w .j av a 2 s. c om * @param subject Subject of the new message that triggered the notification * @param message the {@link Message} to be displayed. * @return a {@link CharSequence} suitable for use in * {@link android.support.v4.app.NotificationCompat.BigTextStyle} */ private static CharSequence getSingleMessageBigText(Context context, String subject, final Message message) { final TextAppearanceSpan notificationSubjectSpan = new TextAppearanceSpan(context, R.style.NotificationPrimaryText); final String snippet = getMessageBodyWithoutElidedText(message); // Change multiple newlines (with potential white space between), into a single new line final String collapsedSnippet = !TextUtils.isEmpty(snippet) ? snippet.replaceAll("\\n\\s+", "\n") : ""; if (TextUtils.isEmpty(subject)) { // If the subject is empty, just use the snippet. return snippet; } else if (TextUtils.isEmpty(collapsedSnippet)) { // If the snippet is empty, just use the subject. final SpannableString spannableString = new SpannableString(subject); spannableString.setSpan(notificationSubjectSpan, 0, subject.length(), 0); return spannableString; } else { final String notificationBigTextFormat = context.getResources() .getString(R.string.single_new_message_notification_big_text); // Localizers may change the order of the parameters, look at how the format // string is structured. final boolean isSubjectFirst = notificationBigTextFormat.indexOf("%2$s") > notificationBigTextFormat .indexOf("%1$s"); final String bigText = String.format(notificationBigTextFormat, subject, collapsedSnippet); final SpannableString spannableString = new SpannableString(bigText); final int subjectOffset = (isSubjectFirst ? bigText.indexOf(subject) : bigText.lastIndexOf(subject)); spannableString.setSpan(notificationSubjectSpan, subjectOffset, subjectOffset + subject.length(), 0); return spannableString; } }
From source file:com.android.mail.utils.NotificationUtils.java
/** * Sets the bigtext for a notification for a single new conversation * * @param context/* w w w . ja v a 2s . c om*/ * @param senders Sender of the new message that triggered the notification. * @param subject Subject of the new message that triggered the notification * @param snippet Snippet of the new message that triggered the notification * @return a {@link CharSequence} suitable for use in * {@link android.support.v4.app.NotificationCompat.BigTextStyle} */ private static CharSequence getSingleMessageInboxLine(Context context, String senders, String subject, String snippet) { // TODO(cwren) finish this step toward commmon code with getSingleMessageBigText final String subjectSnippet = !TextUtils.isEmpty(subject) ? subject : snippet; final TextAppearanceSpan notificationPrimarySpan = new TextAppearanceSpan(context, R.style.NotificationPrimaryText); if (TextUtils.isEmpty(senders)) { // If the senders are empty, just use the subject/snippet. return subjectSnippet; } else if (TextUtils.isEmpty(subjectSnippet)) { // If the subject/snippet is empty, just use the senders. final SpannableString spannableString = new SpannableString(senders); spannableString.setSpan(notificationPrimarySpan, 0, senders.length(), 0); return spannableString; } else { final String formatString = context.getResources() .getString(R.string.multiple_new_message_notification_item); final TextAppearanceSpan notificationSecondarySpan = new TextAppearanceSpan(context, R.style.NotificationSecondaryText); // senders is already individually unicode wrapped so it does not need to be done here final String instantiatedString = String.format(formatString, senders, sBidiFormatter.unicodeWrap(subjectSnippet)); final SpannableString spannableString = new SpannableString(instantiatedString); final boolean isOrderReversed = formatString.indexOf("%2$s") < formatString.indexOf("%1$s"); final int primaryOffset = (isOrderReversed ? instantiatedString.lastIndexOf(senders) : instantiatedString.indexOf(senders)); final int secondaryOffset = (isOrderReversed ? instantiatedString.lastIndexOf(subjectSnippet) : instantiatedString.indexOf(subjectSnippet)); spannableString.setSpan(notificationPrimarySpan, primaryOffset, primaryOffset + senders.length(), 0); spannableString.setSpan(notificationSecondarySpan, secondaryOffset, secondaryOffset + subjectSnippet.length(), 0); return spannableString; } }
From source file:org.anoopam.main.anoopamaudio.AudioListActivity.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 2 s. co m public void onClick(View v) { handleBackPress(); } }); toolbar.setTitle(getString(R.string.nav_audio_title)); SpannableString spannableString = new SpannableString(currentAlbumName); spannableString.setSpan(new StyleSpan(Typeface.ITALIC), 0, spannableString.length(), 0); toolbar.setSubtitle(spannableString); }
From source file:com.github.guwenk.smuradio.SignInDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { builder = new AlertDialog.Builder(getActivity()); View signInDialogView = getActivity().getLayoutInflater().inflate(R.layout.dialog_sign_in, null); builder.setView(signInDialogView);/*from ww w . j a va 2 s.co m*/ builder.setMessage(R.string.upload_your_song); checkBox = (CheckBox) signInDialogView.findViewById(R.id.checkBox2); int currentOrientation = getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) { getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } else { getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } check1 = false; check2 = false; check3 = false; // Log.d(AuthTag, "onCreateDialog " + check1 + " " + check2 + " " + check3); this.mGoogleApiClient = OrderActivity.getmGoogleApiClient(); mAuth = FirebaseAuth.getInstance(); selectFileButton = (Button) signInDialogView.findViewById(R.id.selectFileButton); selectFileButton.setOnClickListener(new customButtonClickListener()); signInButton = (SignInButton) signInDialogView.findViewById(R.id.sign_in_button); signInButton.setStyle(SignInButton.SIZE_WIDE, SignInButton.COLOR_AUTO); signInButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { signIn(); } }); builder.setPositiveButton(getString(R.string.next), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO upload song } }); builder.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); SpannableString ss = new SpannableString(getString(R.string.you_accepting_license_agreement)); ClickableSpan clickableSpan = new ClickableSpan() { @Override public void onClick(View textView) { Log.d(AuthTag, "click"); LicenseDialog licenseDialog = new LicenseDialog(); licenseDialog.show(getFragmentManager(), "Sing in dialog"); } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(true); } }; ss.setSpan(clickableSpan, 14, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); TextView textView = (TextView) signInDialogView.findViewById(R.id.textView); textView.setText(ss); textView.setMovementMethod(LinkMovementMethod.getInstance()); textView.setHighlightColor(Color.TRANSPARENT); checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { check2 = isChecked; Log.d(AuthTag, "Checked: " + isChecked); buttonStatus(); } }); mStorageRef = FirebaseStorage.getInstance().getReference(); alert = builder.create(); return alert; }
From source file:io.plaidapp.designernews.ui.story.StoryActivity.java
private CharSequence getStoryPosterTimeText(String userDisplayName, String userJob, Date createdAt) { SpannableString poster = new SpannableString(userDisplayName.toLowerCase()); poster.setSpan(new TextAppearanceSpan(this, io.plaidapp.R.style.TextAppearance_CommentAuthor), 0, poster.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); CharSequence job = !TextUtils.isEmpty(userJob) ? "\n" + userJob.toLowerCase() : ""; CharSequence timeAgo = DateUtils.getRelativeTimeSpanString(createdAt.getTime(), System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS).toString().toLowerCase(); return TextUtils.concat(poster, job, "\n", timeAgo); }
From source file:com.aegiswallet.actions.MainActivity.java
@Override public void setTitle(CharSequence title) { SpannableString s = new SpannableString(title); s.setSpan(new CustomTypefaceSpan(this, "regular.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); //getActionBar().setTitle(s); mTitle = s;// w ww .j a v a2 s .c o m }
From source file:com.todoroo.astrid.actfm.ActFmLoginActivity.java
protected SpannableString getLinkStringWithCustomInterval(String base, String linkComponent, int start, int endOffset, final OnClickListener listener) { SpannableString link = new SpannableString(String.format("%s %s", //$NON-NLS-1$ base, linkComponent));//from w ww . j a va2 s . c om ClickableSpan linkSpan = new ClickableSpan() { @Override public void onClick(View widget) { listener.onClick(widget); } @Override public void updateDrawState(TextPaint ds) { ds.setUnderlineText(true); ds.setColor(Color.rgb(68, 68, 68)); } }; link.setSpan(linkSpan, start, link.length() + endOffset, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return link; }
From source file:com.air.mobilebrowser.BrowserActivity.java
/** Logs an onscreen message for debugging. */ public void logMessage(final TextView consoleView, String message, String value, int color) { if (mIsDebugEnabled && consoleView != null) { consoleView.setOnFocusChangeListener(new OnFocusChangeListener() { @Override/* w w w. j a v a 2 s. c om*/ public void onFocusChange(View v, boolean hasFocus) { ViewParent parent = consoleView.getParent(); final ScrollView scroll = (ScrollView) parent; new Handler().postDelayed(new Runnable() { @Override public void run() { scroll.smoothScrollTo(0, consoleView.getMeasuredHeight() + 10); } }, 0); } }); Editable editable = consoleView.getEditableText(); SpannableString str = null; if (editable == null) { editable = new SpannableStringBuilder(); str = new SpannableString(message + ": " + value); str.setSpan(new ForegroundColorSpan(color), message.length() + 2, message.length() + 2 + value.length(), 0); } else { str = new SpannableString("\n" + message + ": " + value); str.setSpan(new ForegroundColorSpan(color), message.length() + 2, message.length() + 3 + value.length(), 0); } editable.append(str); consoleView.setText(editable, TextView.BufferType.EDITABLE); ViewParent parent = consoleView.getParent(); if (parent instanceof ScrollView) { final ScrollView scroll = (ScrollView) parent; new Handler().postDelayed(new Runnable() { @Override public void run() { scroll.smoothScrollTo(0, consoleView.getMeasuredHeight() + 10); } }, 1000); } } }
From source file:info.guardianproject.otr.app.im.app.MessageView.java
private SpannableString formatTimeStamp(Date date, int messageType, DateFormat format, MessageView.DeliveryState delivery, EncryptionState encryptionState) { StringBuilder deliveryText = new StringBuilder(); deliveryText.append(format.format(date)); deliveryText.append(' '); if (delivery != null) { //this is for delivery if (delivery == DeliveryState.DELIVERED) { deliveryText.append(DELIVERED_SUCCESS); } else if (delivery == DeliveryState.UNDELIVERED) { deliveryText.append(DELIVERED_FAIL); }//w w w .j ava 2s. co m } if (messageType != Imps.MessageType.POSTPONED) deliveryText.append(DELIVERED_SUCCESS);//this is for sent, so we know show 2 checks like WhatsApp! SpannableString spanText = null; if (encryptionState == EncryptionState.ENCRYPTED) { deliveryText.append('X'); spanText = new SpannableString(deliveryText.toString()); int len = spanText.length(); spanText.setSpan(new ImageSpan(getContext(), R.drawable.lock16), len - 1, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } else if (encryptionState == EncryptionState.ENCRYPTED_AND_VERIFIED) { deliveryText.append('X'); spanText = new SpannableString(deliveryText.toString()); int len = spanText.length(); spanText.setSpan(new ImageSpan(getContext(), R.drawable.lock16), len - 1, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } else { spanText = new SpannableString(deliveryText.toString()); int len = spanText.length(); } // spanText.setSpan(new StyleSpan(Typeface.SANS_SERIF), 0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // spanText.setSpan(new RelativeSizeSpan(0.8f), 0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // spanText.setSpan(new ForegroundColorSpan(R.color.soft_grey), // 0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return spanText; }
From source file:com.timekeeping.app.activities.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Crashlytics.start(this); mSystemUiHelper = new SystemUiHelper(this, SystemUiHelper.LEVEL_IMMERSIVE, 0); mSystemUiHelper.hide();// w w w. j a v a2s .co m setContentView(LAYOUT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && Build.VERSION.SDK_INT < VERSION_CODES.LOLLIPOP) { View decorView = getWindow().getDecorView(); decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int visibility) { // Note that system bars will only be "visible" if none of the // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set. if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { // The system bars are visible. animToolActionBar(getStatusBarHeight()); } else { if (mFistTimeHide) { mFistTimeHide = false; return; } // The system bars are NOT visible. animToolActionBar(0); } } }); } mToolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(mToolbar); calcActionBarHeight(); initDrawer(); //Let all columns to equal. mGv = (GridView) findViewById(R.id.schedule_gv); int screenWidth = DeviceUtils.getScreenSize(this, 0).Width; if (Prefs.getInstance(getApplication()).isLastAListView()) { mGv.setColumnWidth(screenWidth / 2); } else { mGv.setColumnWidth(screenWidth / 3); } mGv.setOnScrollListener(this); //Init speech-framework. Intent checkIntent = new Intent(); checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); startActivityForResult(checkIntent, 0x1); //Add new item. mAddNewV = findViewById(R.id.add_new_time_btn); mAddNewV.setOnClickListener(this); //Adapter for grid and dummy data. mAdp = new ItemsGridViewListAdapter(); mGv.setAdapter(mAdp); refreshGrid(); mGv.setOnItemLongClickListener(this); //Customized the title of ActionBar with a right font. SpannableString s = new SpannableString(getString(R.string.application_name)); s.setSpan(new TypefaceSpan(this, Fonts.FONT_LIGHT), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // Update the action bar title with the TypefaceSpan instance ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setTitle(s); } }