use of android.text.style.StyleSpan in project WordPress-Android by wordpress-mobile.
the class NotificationsUtils method getSpannableContentForRanges.
/**
* Returns a spannable with formatted content based on WP.com note content 'range' data
* @param blockObject the JSON data
* @param textView the TextView that will display the spannnable
* @param onNoteBlockTextClickListener - click listener for ClickableSpans in the spannable
* @param isFooter - Set if spannable should apply special formatting
* @return Spannable string with formatted content
*/
public static Spannable getSpannableContentForRanges(JSONObject blockObject, TextView textView, final NoteBlock.OnNoteBlockTextClickListener onNoteBlockTextClickListener, boolean isFooter) {
if (blockObject == null) {
return new SpannableStringBuilder();
}
String text = blockObject.optString("text", "");
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
boolean shouldLink = onNoteBlockTextClickListener != null;
// Add ImageSpans for note media
addImageSpansForBlockMedia(textView, blockObject, spannableStringBuilder);
// Process Ranges to add links and text formatting
JSONArray rangesArray = blockObject.optJSONArray("ranges");
if (rangesArray != null) {
for (int i = 0; i < rangesArray.length(); i++) {
JSONObject rangeObject = rangesArray.optJSONObject(i);
if (rangeObject == null) {
continue;
}
NoteBlockClickableSpan clickableSpan = new NoteBlockClickableSpan(WordPress.getContext(), rangeObject, shouldLink, isFooter) {
@Override
public void onClick(View widget) {
if (onNoteBlockTextClickListener != null) {
onNoteBlockTextClickListener.onNoteBlockTextClicked(this);
}
}
};
int[] indices = clickableSpan.getIndices();
if (indices.length == 2 && indices[0] <= spannableStringBuilder.length() && indices[1] <= spannableStringBuilder.length()) {
spannableStringBuilder.setSpan(clickableSpan, indices[0], indices[1], Spanned.SPAN_INCLUSIVE_INCLUSIVE);
// Add additional styling if the range wants it
if (clickableSpan.getSpanStyle() != Typeface.NORMAL) {
StyleSpan styleSpan = new StyleSpan(clickableSpan.getSpanStyle());
spannableStringBuilder.setSpan(styleSpan, indices[0], indices[1], Spanned.SPAN_INCLUSIVE_INCLUSIVE);
}
}
}
}
return spannableStringBuilder;
}
use of android.text.style.StyleSpan in project WordPress-Android by wordpress-mobile.
the class DeleteSiteDialogFragment method confirmationPromptString.
private Spannable confirmationPromptString() {
String deletePrompt = String.format(getString(R.string.confirm_delete_site_prompt), mSiteDomain);
Spannable promptSpannable = new SpannableString(deletePrompt);
int beginning = deletePrompt.indexOf(mSiteDomain);
int end = beginning + mSiteDomain.length();
promptSpannable.setSpan(new StyleSpan(Typeface.BOLD), beginning, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return promptSpannable;
}
use of android.text.style.StyleSpan in project TapTargetView by KeepSafe.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.inflateMenu(R.menu.menu_main);
toolbar.setNavigationIcon(ContextCompat.getDrawable(this, R.drawable.ic_arrow_back_white_24dp));
// We load a drawable and create a location to show a tap target here
// We need the display to get the width and height at this point in time
final Display display = getWindowManager().getDefaultDisplay();
// Load our little droid guy
final Drawable droid = ContextCompat.getDrawable(this, R.drawable.ic_android_black_24dp);
// Tell our droid buddy where we want him to appear
final Rect droidTarget = new Rect(0, 0, droid.getIntrinsicWidth() * 2, droid.getIntrinsicHeight() * 2);
// Using deprecated methods makes you look way cool
droidTarget.offset(display.getWidth() / 2, display.getHeight() / 2);
final SpannableString sassyDesc = new SpannableString("It allows you to go back, sometimes");
sassyDesc.setSpan(new StyleSpan(Typeface.ITALIC), sassyDesc.length() - "somtimes".length(), sassyDesc.length(), 0);
// We have a sequence of targets, so lets build it!
final TapTargetSequence sequence = new TapTargetSequence(this).targets(// This tap target will target the back button, we just need to pass its containing toolbar
TapTarget.forToolbarNavigationIcon(toolbar, "This is the back button", sassyDesc).id(1), // Likewise, this tap target will target the search button
TapTarget.forToolbarMenuItem(toolbar, R.id.search, "This is a search icon", "As you can see, it has gotten pretty dark around here...").dimColor(android.R.color.black).outerCircleColor(R.color.colorAccent).targetCircleColor(android.R.color.black).transparentTarget(true).textColor(android.R.color.black).id(2), // You can also target the overflow button in your toolbar
TapTarget.forToolbarOverflow(toolbar, "This will show more options", "But they're not useful :(").id(3), // This tap target will target our droid buddy at the given target rect
TapTarget.forBounds(droidTarget, "Oh look!", "You can point to any part of the screen. You also can't cancel this one!").cancelable(false).icon(droid).id(4)).listener(new TapTargetSequence.Listener() {
// This listener will tell us when interesting(tm) events happen in regards
// to the sequence
@Override
public void onSequenceFinish() {
((TextView) findViewById(R.id.educated)).setText("Congratulations! You're educated now!");
}
@Override
public void onSequenceStep(TapTarget lastTarget, boolean targetClicked) {
Log.d("TapTargetView", "Clicked on " + lastTarget.id());
}
@Override
public void onSequenceCanceled(TapTarget lastTarget) {
final AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).setTitle("Uh oh").setMessage("You canceled the sequence").setPositiveButton("Oops", null).show();
TapTargetView.showFor(dialog, TapTarget.forView(dialog.getButton(DialogInterface.BUTTON_POSITIVE), "Uh oh!", "You canceled the sequence at step " + lastTarget.id()).cancelable(false).tintTarget(false), new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
dialog.dismiss();
}
});
}
});
// You don't always need a sequence, and for that there's a single time tap target
final SpannableString spannedDesc = new SpannableString("This is the sample app for TapTargetView");
spannedDesc.setSpan(new UnderlineSpan(), spannedDesc.length() - "TapTargetView".length(), spannedDesc.length(), 0);
TapTargetView.showFor(this, TapTarget.forView(findViewById(R.id.fab), "Hello, world!", spannedDesc).cancelable(false).drawShadow(true).tintTarget(false), new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
// .. which evidently starts the sequence we defined earlier
sequence.start();
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
Toast.makeText(view.getContext(), "You clicked the outer circle!", Toast.LENGTH_SHORT).show();
}
@Override
public void onTargetDismissed(TapTargetView view, boolean userInitiated) {
Log.d("TapTargetViewSample", "You dismissed me :(");
}
});
}
use of android.text.style.StyleSpan in project Conversations by siacs.
the class NotificationService method buildMultipleConversation.
private Builder buildMultipleConversation() {
final Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
style.setBigContentTitle(notifications.size() + " " + mXmppConnectionService.getString(R.string.unread_conversations));
final StringBuilder names = new StringBuilder();
Conversation conversation = null;
for (final ArrayList<Message> messages : notifications.values()) {
if (messages.size() > 0) {
conversation = messages.get(0).getConversation();
final String name = conversation.getName();
SpannableString styledString;
if (Config.HIDE_MESSAGE_TEXT_IN_NOTIFICATION) {
int count = messages.size();
styledString = new SpannableString(name + ": " + mXmppConnectionService.getResources().getQuantityString(R.plurals.x_messages, count, count));
styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0);
style.addLine(styledString);
} else {
styledString = new SpannableString(name + ": " + UIHelper.getMessagePreview(mXmppConnectionService, messages.get(0)).first);
styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0);
style.addLine(styledString);
}
names.append(name);
names.append(", ");
}
}
if (names.length() >= 2) {
names.delete(names.length() - 2, names.length());
}
mBuilder.setContentTitle(notifications.size() + " " + mXmppConnectionService.getString(R.string.unread_conversations));
mBuilder.setContentText(names.toString());
mBuilder.setStyle(style);
if (conversation != null) {
mBuilder.setContentIntent(createContentIntent(conversation));
}
mBuilder.setGroupSummary(true);
mBuilder.setGroup(CONVERSATIONS_GROUP);
mBuilder.setDeleteIntent(createDeleteIntent(null));
mBuilder.setSmallIcon(R.drawable.ic_notification);
return mBuilder;
}
use of android.text.style.StyleSpan in project android_frameworks_base by crdroidandroid.
the class ProgressDialog method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
LayoutInflater inflater = LayoutInflater.from(mContext);
TypedArray a = mContext.obtainStyledAttributes(null, com.android.internal.R.styleable.AlertDialog, com.android.internal.R.attr.alertDialogStyle, 0);
if (mProgressStyle == STYLE_HORIZONTAL) {
/* Use a separate handler to update the text views as they
* must be updated on the same thread that created them.
*/
mViewUpdateHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
/* Update the number and percent */
int progress = mProgress.getProgress();
int max = mProgress.getMax();
if (mProgressNumberFormat != null) {
String format = mProgressNumberFormat;
mProgressNumber.setText(String.format(format, progress, max));
} else {
mProgressNumber.setText("");
}
if (mProgressPercentFormat != null) {
double percent = (double) progress / (double) max;
SpannableString tmp = new SpannableString(mProgressPercentFormat.format(percent));
tmp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, tmp.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mProgressPercent.setText(tmp);
} else {
mProgressPercent.setText("");
}
}
};
View view = inflater.inflate(a.getResourceId(com.android.internal.R.styleable.AlertDialog_horizontalProgressLayout, R.layout.alert_dialog_progress), null);
mProgress = (ProgressBar) view.findViewById(R.id.progress);
mProgressNumber = (TextView) view.findViewById(R.id.progress_number);
mProgressPercent = (TextView) view.findViewById(R.id.progress_percent);
setView(view);
} else {
View view = inflater.inflate(a.getResourceId(com.android.internal.R.styleable.AlertDialog_progressLayout, R.layout.progress_dialog), null);
mProgress = (ProgressBar) view.findViewById(R.id.progress);
mMessageView = (TextView) view.findViewById(R.id.message);
setView(view);
}
a.recycle();
if (mMax > 0) {
setMax(mMax);
}
if (mProgressVal > 0) {
setProgress(mProgressVal);
}
if (mSecondaryProgressVal > 0) {
setSecondaryProgress(mSecondaryProgressVal);
}
if (mIncrementBy > 0) {
incrementProgressBy(mIncrementBy);
}
if (mIncrementSecondaryBy > 0) {
incrementSecondaryProgressBy(mIncrementSecondaryBy);
}
if (mProgressDrawable != null) {
setProgressDrawable(mProgressDrawable);
}
if (mIndeterminateDrawable != null) {
setIndeterminateDrawable(mIndeterminateDrawable);
}
if (mMessage != null) {
setMessage(mMessage);
}
setIndeterminate(mIndeterminate);
onProgressChanged();
super.onCreate(savedInstanceState);
}
Aggregations