Search in sources :

Example 76 with Spannable

use of android.text.Spannable in project android_frameworks_base by ResurrectionRemix.

the class SuggestionsPopupWindowTest method setSuggestionSpan.

private void setSuggestionSpan(SuggestionSpan span, int start, int end) {
    final TextView textView = (TextView) getActivity().findViewById(R.id.textview);
    textView.post(() -> {
        final Spannable text = (Spannable) textView.getText();
        text.setSpan(span, start, end, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        Selection.setSelection(text, (start + end) / 2);
    });
    getInstrumentation().waitForIdleSync();
}
Also used : Spannable(android.text.Spannable)

Example 77 with Spannable

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;
}
Also used : Spannable(android.text.Spannable) Point(android.graphics.Point)

Example 78 with Spannable

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);
        }
    }
}
Also used : InputConnection(android.view.inputmethod.InputConnection) Spannable(android.text.Spannable)

Example 79 with Spannable

use of android.text.Spannable in project wechat by motianhuo.

the class SmileUtils method getSmiledText.

public static Spannable getSmiledText(Context context, CharSequence text) {
    Spannable spannable = spannableFactory.newSpannable(text);
    addSmiles(context, spannable);
    return spannable;
}
Also used : Spannable(android.text.Spannable)

Example 80 with Spannable

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());
}
Also used : MonETSNotification(ca.etsmtl.applets.etsmobile.model.MonETSNotification) NotificationManager(android.app.NotificationManager) Gson(com.google.gson.Gson) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) SecurePreferences(ca.etsmtl.applets.etsmobile.util.SecurePreferences) SpannableString(android.text.SpannableString) SpannableString(android.text.SpannableString) Bitmap(android.graphics.Bitmap) TypeToken(com.google.gson.reflect.TypeToken) StyleSpan(android.text.style.StyleSpan) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) Spannable(android.text.Spannable)

Aggregations

Spannable (android.text.Spannable)333 Paint (android.graphics.Paint)122 TextPaint (android.text.TextPaint)97 SpannableString (android.text.SpannableString)72 Editable (android.text.Editable)42 InputMethodManager (android.view.inputmethod.InputMethodManager)34 Spanned (android.text.Spanned)32 SuggestionSpan (android.text.style.SuggestionSpan)29 View (android.view.View)28 SpannableStringBuilder (android.text.SpannableStringBuilder)24 ForegroundColorSpan (android.text.style.ForegroundColorSpan)21 TextView (android.widget.TextView)17 ClickableSpan (android.text.style.ClickableSpan)14 StyleSpan (android.text.style.StyleSpan)14 Intent (android.content.Intent)13 KeyEvent (android.view.KeyEvent)13 URLSpan (android.text.style.URLSpan)12 Layout (android.text.Layout)11 Parcelable (android.os.Parcelable)8 SpannedString (android.text.SpannedString)8