use of android.text.style.StyleSpan in project Signal-Android by WhisperSystems.
the class Util method getBoldedString.
public static CharSequence getBoldedString(String value) {
SpannableString spanned = new SpannableString(value);
spanned.setSpan(new StyleSpan(Typeface.BOLD), 0, spanned.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return spanned;
}
use of android.text.style.StyleSpan in project actor-platform by actorapp.
the class AndroidMarkdown method writeText.
private static void writeText(MDText[] texts, SpannableStringBuilder builder) {
for (MDText text : texts) {
if (text instanceof MDRawText) {
builder.append(((MDRawText) text).getRawText());
} else if (text instanceof MDSpan) {
MDSpan span = (MDSpan) text;
int start = builder.length();
writeText(span.getChild(), builder);
Object spanObj;
if (span.getSpanType() == MDSpan.TYPE_BOLD) {
spanObj = new StyleSpan(Typeface.BOLD);
} else {
spanObj = new StyleSpan(Typeface.ITALIC);
}
builder.setSpan(spanObj, start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (text instanceof MDUrl) {
final MDUrl url = (MDUrl) text;
int start = builder.length();
builder.append(url.getUrlTitle());
builder.setSpan(new ClickableSpan() {
@Override
public void onClick(View view) {
Context ctx = view.getContext();
if (url.getUrl().startsWith("send:") && view.getTag(R.id.peer) != null && view.getTag(R.id.peer) instanceof Peer) {
ActorSDK.sharedActor().getMessenger().sendMessage((Peer) view.getTag(R.id.peer), url.getUrl().replaceFirst("send:", ""));
} else {
Intent intent = buildChromeIntent().intent;
intent.setData(Uri.parse(url.getUrl()));
if (intent.resolveActivity(ctx.getPackageManager()) != null) {
ctx.startActivity(intent);
} else {
intent.setData(Uri.parse("http://" + url.getUrl()));
if (intent.resolveActivity(ctx.getPackageManager()) != null) {
ctx.startActivity(intent);
} else {
Toast.makeText(view.getContext(), "Unknown URL type", Toast.LENGTH_SHORT).show();
}
}
}
}
}, start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
throw new RuntimeException("Unknown text type: " + text);
}
}
}
use of android.text.style.StyleSpan in project Signal-Android by WhisperSystems.
the class MessageRecord method emphasisAdded.
protected SpannableString emphasisAdded(String sequence) {
SpannableString spannable = new SpannableString(sequence);
spannable.setSpan(new RelativeSizeSpan(0.9f), 0, sequence.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, sequence.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return spannable;
}
use of android.text.style.StyleSpan in project Signal-Android by WhisperSystems.
the class ThreadRecord method emphasisAdded.
private SpannableString emphasisAdded(String sequence, int start, int end) {
SpannableString spannable = new SpannableString(sequence);
spannable.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return spannable;
}
use of android.text.style.StyleSpan in project platform_frameworks_base by android.
the class MediaProjectionPermissionActivity method onCreate.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
mPackageName = getCallingPackage();
IBinder b = ServiceManager.getService(MEDIA_PROJECTION_SERVICE);
mService = IMediaProjectionManager.Stub.asInterface(b);
if (mPackageName == null) {
finish();
return;
}
PackageManager packageManager = getPackageManager();
ApplicationInfo aInfo;
try {
aInfo = packageManager.getApplicationInfo(mPackageName, 0);
mUid = aInfo.uid;
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "unable to look up package name", e);
finish();
return;
}
try {
if (mService.hasProjectionPermission(mUid, mPackageName)) {
setResult(RESULT_OK, getMediaProjectionIntent(mUid, mPackageName, false));
finish();
return;
}
} catch (RemoteException e) {
Log.e(TAG, "Error checking projection permissions", e);
finish();
return;
}
TextPaint paint = new TextPaint();
paint.setTextSize(42);
String label = aInfo.loadLabel(packageManager).toString();
// If the label contains new line characters it may push the security
// message below the fold of the dialog. Labels shouldn't have new line
// characters anyways, so just truncate the message the first time one
// is seen.
final int labelLength = label.length();
int offset = 0;
while (offset < labelLength) {
final int codePoint = label.codePointAt(offset);
final int type = Character.getType(codePoint);
if (type == Character.LINE_SEPARATOR || type == Character.CONTROL || type == Character.PARAGRAPH_SEPARATOR) {
label = label.substring(0, offset) + ELLIPSIS;
break;
}
offset += Character.charCount(codePoint);
}
if (label.isEmpty()) {
label = mPackageName;
}
String unsanitizedAppName = TextUtils.ellipsize(label, paint, MAX_APP_NAME_SIZE_PX, TextUtils.TruncateAt.END).toString();
String appName = BidiFormatter.getInstance().unicodeWrap(unsanitizedAppName);
String actionText = getString(R.string.media_projection_dialog_text, appName);
SpannableString message = new SpannableString(actionText);
int appNameIndex = actionText.indexOf(appName);
if (appNameIndex >= 0) {
message.setSpan(new StyleSpan(Typeface.BOLD), appNameIndex, appNameIndex + appName.length(), 0);
}
mDialog = new AlertDialog.Builder(this).setIcon(aInfo.loadIcon(packageManager)).setMessage(message).setPositiveButton(R.string.media_projection_action_text, this).setNegativeButton(android.R.string.cancel, this).setView(R.layout.remember_permission_checkbox).setOnCancelListener(this).create();
mDialog.create();
mDialog.getButton(DialogInterface.BUTTON_POSITIVE).setFilterTouchesWhenObscured(true);
((CheckBox) mDialog.findViewById(R.id.remember)).setOnCheckedChangeListener(this);
mDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
mDialog.show();
}
Aggregations