use of android.text.Spannable in project android_frameworks_base by ResurrectionRemix.
the class FindActionModeCallback method setText.
/*
* Place text in the text field so it can be searched for. Need to press
* the find next or find previous button to find all of the matches.
*/
public void setText(String text) {
mEditText.setText(text);
Spannable span = (Spannable) mEditText.getText();
int length = span.length();
// Ideally, we would like to set the selection to the whole field,
// but this brings up the Text selection CAB, which dismisses this
// one.
Selection.setSelection(span, length, length);
// Necessary each time we set the text, so that this will watch
// changes to it.
span.setSpan(this, 0, length, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
mMatchesFound = false;
}
use of android.text.Spannable in project android_frameworks_base by ResurrectionRemix.
the class InputMethodService method onExtractedSetSpan.
/**
* @hide
*/
public void onExtractedSetSpan(Object span, int start, int end, int flags) {
InputConnection conn = getCurrentInputConnection();
if (conn != null) {
if (!conn.setSelection(start, end))
return;
CharSequence text = conn.getSelectedText(InputConnection.GET_TEXT_WITH_STYLES);
if (text instanceof Spannable) {
((Spannable) text).setSpan(span, 0, text.length(), flags);
conn.setComposingRegion(start, end);
conn.commitText(text, 1);
}
}
}
use of android.text.Spannable in project ETSMobile-Android2 by ApplETS.
the class ETSGcmListenerService method sendNotification.
/**
* Create and show a simple notification containing the received GCM message.
*
* @param data GCM message received.
*/
private void sendNotification(Bundle data) {
SecurePreferences securePreferences = new SecurePreferences(this);
Gson gson = new Gson();
String receivedNotifString = securePreferences.getString(Constants.RECEIVED_NOTIF, "");
ArrayList<MonETSNotification> receivedNotif = gson.fromJson(receivedNotifString, new TypeToken<ArrayList<MonETSNotification>>() {
}.getType());
if (receivedNotif == null) {
receivedNotif = new ArrayList<>();
}
MonETSNotification nouvelleNotification = getMonETSNotificationFromBundle(data);
receivedNotif.add(nouvelleNotification);
int numberOfNotifications = receivedNotif.size();
Intent intent = new Intent(this, NotificationActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_ets);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.school_48).setColor(getResources().getColor(R.color.red)).setContentTitle(getString(R.string.ets)).setContentText(getString(R.string.new_notifications)).setContentIntent(pendingIntent).setLargeIcon(icon).setAutoCancel(true).setNumber(numberOfNotifications);
NotificationCompat.InboxStyle inBoxStyle = new NotificationCompat.InboxStyle();
// Sets a title for the Inbox in expanded layout
String bigContentTitle = getString(R.string.notification_content_title, numberOfNotifications + "", (numberOfNotifications == 1 ? "" : "s"), (numberOfNotifications == 1 ? "" : "s"));
inBoxStyle.setBigContentTitle(bigContentTitle);
String username = ApplicationManager.userCredentials.getUsername();
Spannable sb = new SpannableString(username);
sb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
inBoxStyle.setSummaryText(sb);
securePreferences.edit().putString(Constants.RECEIVED_NOTIF, gson.toJson(receivedNotif)).commit();
int minimumIndex = receivedNotif.size() - NUMBER_OF_NOTIF_TO_DISPLAY;
minimumIndex = minimumIndex < 0 ? 0 : minimumIndex;
for (int i = receivedNotif.size() - 1; i >= minimumIndex; i--) {
inBoxStyle.addLine(receivedNotif.get(i).getNotificationTexte());
}
if (numberOfNotifications > NUMBER_OF_NOTIF_TO_DISPLAY) {
int plusOthers = (numberOfNotifications - NUMBER_OF_NOTIF_TO_DISPLAY);
String plusOthersString = getString(R.string.others_notifications, plusOthers + "", (plusOthers == 1 ? "" : "s"));
Spannable others = new SpannableString(plusOthersString);
others.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, others.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
inBoxStyle.addLine(others);
}
mBuilder.setStyle(inBoxStyle);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
use of android.text.Spannable in project zxing by zxing.
the class SupplementalInfoRetriever method append.
final void append(String itemID, String source, String[] newTexts, String linkURL) {
StringBuilder newTextCombined = new StringBuilder();
if (source != null) {
newTextCombined.append(source).append(' ');
}
int linkStart = newTextCombined.length();
boolean first = true;
for (String newText : newTexts) {
if (first) {
newTextCombined.append(newText);
first = false;
} else {
newTextCombined.append(" [");
newTextCombined.append(newText);
newTextCombined.append(']');
}
}
int linkEnd = newTextCombined.length();
String newText = newTextCombined.toString();
Spannable content = new SpannableString(newText + "\n\n");
if (linkURL != null) {
// Lower-case these as it should always be OK to lower-case these schemes.
if (linkURL.startsWith("HTTP://")) {
linkURL = "http" + linkURL.substring(4);
} else if (linkURL.startsWith("HTTPS://")) {
linkURL = "https" + linkURL.substring(5);
}
content.setSpan(new URLSpan(linkURL), linkStart, linkEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
newContents.add(content);
newHistories.add(new String[] { itemID, newText });
}
use of android.text.Spannable in project AntennaPod by AntennaPod.
the class ChaptersListAdapter method getView.
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
Holder holder;
Chapter sc = getItem(position);
// Inflate Layout
if (convertView == null) {
holder = new Holder();
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.simplechapter_item, parent, false);
holder.view = convertView;
holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
defaultTextColor = holder.title.getTextColors().getDefaultColor();
holder.start = (TextView) convertView.findViewById(R.id.txtvStart);
holder.link = (TextView) convertView.findViewById(R.id.txtvLink);
holder.butPlayChapter = (ImageButton) convertView.findViewById(R.id.butPlayChapter);
convertView.setTag(holder);
} else {
holder = (Holder) convertView.getTag();
}
holder.title.setText(sc.getTitle());
holder.start.setText(Converter.getDurationStringLong((int) sc.getStart()));
if (sc.getLink() != null) {
holder.link.setVisibility(View.VISIBLE);
holder.link.setText(sc.getLink());
Linkify.addLinks(holder.link, Linkify.WEB_URLS);
} else {
holder.link.setVisibility(View.GONE);
}
holder.link.setMovementMethod(null);
holder.link.setOnTouchListener((v, event) -> {
// from
// http://stackoverflow.com/questions/7236840/android-textview-linkify-intercepts-with-parent-view-gestures
TextView widget = (TextView) v;
Object text = widget.getText();
if (text instanceof Spanned) {
Spannable buffer = (Spannable) text;
int action = event.getAction();
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();
x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();
x += widget.getScrollX();
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
if (link.length != 0) {
if (action == MotionEvent.ACTION_UP) {
link[0].onClick(widget);
} else if (action == MotionEvent.ACTION_DOWN) {
Selection.setSelection(buffer, buffer.getSpanStart(link[0]), buffer.getSpanEnd(link[0]));
}
return true;
}
}
}
return false;
});
holder.butPlayChapter.setOnClickListener(v -> {
if (callback != null) {
callback.onPlayChapterButtonClicked(position);
}
});
Chapter current = ChapterUtils.getCurrentChapter(media);
if (current != null) {
if (current == sc) {
int playingBackGroundColor;
if (UserPreferences.getTheme() == R.style.Theme_AntennaPod_Dark) {
playingBackGroundColor = ContextCompat.getColor(getContext(), R.color.highlight_dark);
} else {
playingBackGroundColor = ContextCompat.getColor(getContext(), R.color.highlight_light);
}
holder.view.setBackgroundColor(playingBackGroundColor);
} else {
holder.view.setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent));
holder.title.setTextColor(defaultTextColor);
holder.start.setTextColor(defaultTextColor);
}
} else {
Log.w(TAG, "Could not find out what the current chapter is.");
}
return convertView;
}
Aggregations