Search in sources :

Example 6 with TextAppearanceSpan

use of android.text.style.TextAppearanceSpan in project platform_frameworks_base by android.

the class SuggestionsPopupWindowTest method testTextAppearanceInSuggestionsPopup.

@SmallTest
public void testTextAppearanceInSuggestionsPopup() {
    final String text = "abc def ghi";
    final String[] singleWordCandidates = { "DEF", "Def" };
    final SuggestionSpan suggestionSpan = new SuggestionSpan(getActivity(), singleWordCandidates, SuggestionSpan.FLAG_MISSPELLED);
    final String[] multiWordCandidates = { "ABC DEF GHI", "Abc Def Ghi" };
    final SuggestionSpan multiWordSuggestionSpan = new SuggestionSpan(getActivity(), multiWordCandidates, SuggestionSpan.FLAG_MISSPELLED);
    final TypedArray array = getActivity().obtainStyledAttributes(com.android.internal.R.styleable.Theme);
    final int id = array.getResourceId(com.android.internal.R.styleable.Theme_textEditSuggestionHighlightStyle, 0);
    array.recycle();
    final TextAppearanceSpan expectedSpan = new TextAppearanceSpan(getActivity(), id);
    final TextPaint tmpTp = new TextPaint();
    expectedSpan.updateDrawState(tmpTp);
    final int expectedHighlightTextColor = tmpTp.getColor();
    final float expectedHighlightTextSize = tmpTp.getTextSize();
    final TextView textView = (TextView) getActivity().findViewById(R.id.textview);
    // *XX* means that XX is highlighted.
    for (int i = 0; i < 2; i++) {
        onView(withId(R.id.textview)).perform(click());
        onView(withId(R.id.textview)).perform(replaceText(text));
        setSuggestionSpan(suggestionSpan, text.indexOf('d'), text.indexOf('f') + 1);
        setSuggestionSpan(multiWordSuggestionSpan, 0, text.length());
        showSuggestionsPopup();
        assertSuggestionsPopupIsDisplayed();
        assertSuggestionsPopupContainsItem("abc DEF ghi");
        assertSuggestionsPopupContainsItem("abc Def ghi");
        assertSuggestionsPopupContainsItem("ABC DEF GHI");
        assertSuggestionsPopupContainsItem("Abc Def Ghi");
        assertSuggestionsPopupContainsItem(getActivity().getString(com.android.internal.R.string.delete));
        onSuggestionsPopup().check(new ViewAssertion() {

            @Override
            public void check(View view, NoMatchingViewException e) {
                final ListView listView = (ListView) view.findViewById(com.android.internal.R.id.suggestionContainer);
                assertNotNull(listView);
                final int childNum = listView.getChildCount();
                assertEquals(singleWordCandidates.length + multiWordCandidates.length, childNum);
                for (int j = 0; j < childNum; j++) {
                    final TextView suggestion = (TextView) listView.getChildAt(j);
                    assertNotNull(suggestion);
                    final Spanned spanned = (Spanned) suggestion.getText();
                    assertNotNull(spanned);
                    // Check that the suggestion item order is kept.
                    final String expectedText;
                    if (j < singleWordCandidates.length) {
                        expectedText = "abc " + singleWordCandidates[j] + " ghi";
                    } else {
                        expectedText = multiWordCandidates[j - singleWordCandidates.length];
                    }
                    assertEquals(expectedText, spanned.toString());
                    // Check that the text is highlighted with correct color and text size.
                    final TextAppearanceSpan[] taSpan = spanned.getSpans(text.indexOf('d'), text.indexOf('f') + 1, TextAppearanceSpan.class);
                    assertEquals(1, taSpan.length);
                    TextPaint tp = new TextPaint();
                    taSpan[0].updateDrawState(tp);
                    assertEquals(expectedHighlightTextColor, tp.getColor());
                    assertEquals(expectedHighlightTextSize, tp.getTextSize());
                    // Check the correct part of the text is highlighted.
                    final int expectedStart;
                    final int expectedEnd;
                    if (j < singleWordCandidates.length) {
                        expectedStart = text.indexOf('d');
                        expectedEnd = text.indexOf('f') + 1;
                    } else {
                        expectedStart = 0;
                        expectedEnd = text.length();
                    }
                    assertEquals(expectedStart, spanned.getSpanStart(taSpan[0]));
                    assertEquals(expectedEnd, spanned.getSpanEnd(taSpan[0]));
                }
            }
        });
        pressBack();
        onView(withId(R.id.textview)).inRoot(withDecorView(is(getActivity().getWindow().getDecorView()))).perform(clearText());
    }
}
Also used : TextAppearanceSpan(android.text.style.TextAppearanceSpan) NoMatchingViewException(android.support.test.espresso.NoMatchingViewException) View(android.view.View) Espresso.onView(android.support.test.espresso.Espresso.onView) RootMatchers.withDecorView(android.support.test.espresso.matcher.RootMatchers.withDecorView) DragHandleUtils.onHandleView(android.widget.espresso.DragHandleUtils.onHandleView) Spanned(android.text.Spanned) TextPaint(android.text.TextPaint) TextPaint(android.text.TextPaint) ViewAssertion(android.support.test.espresso.ViewAssertion) TypedArray(android.content.res.TypedArray) SuggestionSpan(android.text.style.SuggestionSpan) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 7 with TextAppearanceSpan

use of android.text.style.TextAppearanceSpan in project ShowcaseView by amlcurran.

the class TextDrawer method setTitleStyling.

public void setTitleStyling(int styleId) {
    titleSpan = new TextAppearanceSpan(this.context, styleId);
    setContentTitle(titleString);
}
Also used : TextAppearanceSpan(android.text.style.TextAppearanceSpan)

Example 8 with TextAppearanceSpan

use of android.text.style.TextAppearanceSpan in project ShowcaseView by amlcurran.

the class TextDrawer method setDetailStyling.

public void setDetailStyling(int styleId) {
    textSpan = new TextAppearanceSpan(this.context, styleId);
    setContentText(textString);
}
Also used : TextAppearanceSpan(android.text.style.TextAppearanceSpan)

Example 9 with TextAppearanceSpan

use of android.text.style.TextAppearanceSpan in project WordPress-Android by wordpress-mobile.

the class HtmlToSpannedConverter method endFont.

private static void endFont(SpannableStringBuilder text) {
    int len = text.length();
    Object obj = getLast(text, Font.class);
    int where = text.getSpanStart(obj);
    text.removeSpan(obj);
    if (where != len) {
        Font f = (Font) obj;
        if (!TextUtils.isEmpty(f.mColor)) {
            if (f.mColor.startsWith("@")) {
                Resources res = Resources.getSystem();
                String name = f.mColor.substring(1);
                int colorRes = res.getIdentifier(name, "color", "android");
                if (colorRes != 0) {
                    ColorStateList colors = res.getColorStateList(colorRes);
                    text.setSpan(new TextAppearanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            } else {
                int c = getHtmlColor(f.mColor);
                if (c != -1) {
                    text.setSpan(new ForegroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            }
        }
        if (f.mFace != null) {
            text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}
Also used : TextAppearanceSpan(android.text.style.TextAppearanceSpan) ForegroundColorSpan(android.text.style.ForegroundColorSpan) ColorStateList(android.content.res.ColorStateList) Resources(android.content.res.Resources) TypefaceSpan(android.text.style.TypefaceSpan)

Example 10 with TextAppearanceSpan

use of android.text.style.TextAppearanceSpan in project Etar-Calendar by Etar-Group.

the class AlertReceiver method makeDigestNotification.

/**
     * Creates an expanding digest notification for expired events.
     */
public static NotificationWrapper makeDigestNotification(Context context, ArrayList<AlertService.NotificationInfo> notificationInfos, String digestTitle, boolean expandable) {
    if (notificationInfos == null || notificationInfos.size() < 1) {
        return null;
    }
    Resources res = context.getResources();
    int numEvents = notificationInfos.size();
    long[] eventIds = new long[notificationInfos.size()];
    long[] startMillis = new long[notificationInfos.size()];
    for (int i = 0; i < notificationInfos.size(); i++) {
        eventIds[i] = notificationInfos.get(i).eventId;
        startMillis[i] = notificationInfos.get(i).startMillis;
    }
    // Create an intent triggered by clicking on the status icon that shows the alerts list.
    PendingIntent pendingClickIntent = createAlertActivityIntent(context);
    // Create an intent triggered by dismissing the digest notification that clears all
    // expired events.
    Intent deleteIntent = new Intent();
    deleteIntent.setClass(context, DismissAlarmsService.class);
    deleteIntent.setAction(DELETE_ALL_ACTION);
    deleteIntent.putExtra(AlertUtils.EVENT_IDS_KEY, eventIds);
    deleteIntent.putExtra(AlertUtils.EVENT_STARTS_KEY, startMillis);
    PendingIntent pendingDeleteIntent = PendingIntent.getService(context, 0, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    if (digestTitle == null || digestTitle.length() == 0) {
        digestTitle = res.getString(R.string.no_title_label);
    }
    Notification.Builder notificationBuilder = new Notification.Builder(context);
    notificationBuilder.setContentText(digestTitle);
    notificationBuilder.setSmallIcon(R.drawable.stat_notify_calendar_multiple);
    notificationBuilder.setContentIntent(pendingClickIntent);
    notificationBuilder.setDeleteIntent(pendingDeleteIntent);
    String nEventsStr = res.getQuantityString(R.plurals.Nevents, numEvents, numEvents);
    notificationBuilder.setContentTitle(nEventsStr);
    Notification n;
    if (Utils.isJellybeanOrLater()) {
        // New-style notification...
        // Set to min priority to encourage the notification manager to collapse it.
        notificationBuilder.setPriority(Notification.PRIORITY_MIN);
        if (expandable) {
            // Multiple reminders.  Combine into an expanded digest notification.
            Notification.InboxStyle expandedBuilder = new Notification.InboxStyle(notificationBuilder);
            int i = 0;
            for (AlertService.NotificationInfo info : notificationInfos) {
                if (i < NOTIFICATION_DIGEST_MAX_LENGTH) {
                    String name = info.eventName;
                    if (TextUtils.isEmpty(name)) {
                        name = context.getResources().getString(R.string.no_title_label);
                    }
                    String timeLocation = AlertUtils.formatTimeLocation(context, info.startMillis, info.allDay, info.location);
                    TextAppearanceSpan primaryTextSpan = new TextAppearanceSpan(context, R.style.NotificationPrimaryText);
                    TextAppearanceSpan secondaryTextSpan = new TextAppearanceSpan(context, R.style.NotificationSecondaryText);
                    // Event title in bold.
                    SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
                    stringBuilder.append(name);
                    stringBuilder.setSpan(primaryTextSpan, 0, stringBuilder.length(), 0);
                    stringBuilder.append("  ");
                    // Followed by time and location.
                    int secondaryIndex = stringBuilder.length();
                    stringBuilder.append(timeLocation);
                    stringBuilder.setSpan(secondaryTextSpan, secondaryIndex, stringBuilder.length(), 0);
                    expandedBuilder.addLine(stringBuilder);
                    i++;
                } else {
                    break;
                }
            }
            // If there are too many to display, add "+X missed events" for the last line.
            int remaining = numEvents - i;
            if (remaining > 0) {
                String nMoreEventsStr = res.getQuantityString(R.plurals.N_remaining_events, remaining, remaining);
                // TODO: Add highlighting and icon to this last entry once framework allows it.
                expandedBuilder.setSummaryText(nMoreEventsStr);
            }
            // Remove the title in the expanded form (redundant with the listed items).
            expandedBuilder.setBigContentTitle("");
            n = expandedBuilder.build();
        } else {
            n = notificationBuilder.build();
        }
    } else {
        // Old-style notification (pre-JB).  We only need a standard notification (no
        // buttons) but use a custom view so it is consistent with the others.
        n = notificationBuilder.getNotification();
        // Use custom view with buttons to provide JB-like functionality (snooze/email).
        RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification);
        contentView.setImageViewResource(R.id.image, R.drawable.stat_notify_calendar_multiple);
        contentView.setTextViewText(R.id.title, nEventsStr);
        contentView.setTextViewText(R.id.text, digestTitle);
        contentView.setViewVisibility(R.id.time, View.VISIBLE);
        contentView.setViewVisibility(R.id.map_button, View.GONE);
        contentView.setViewVisibility(R.id.call_button, View.GONE);
        contentView.setViewVisibility(R.id.email_button, View.GONE);
        contentView.setViewVisibility(R.id.snooze_button, View.GONE);
        contentView.setViewVisibility(R.id.end_padding, View.VISIBLE);
        n.contentView = contentView;
        // Use timestamp to force expired digest notification to the bottom (there is no
        // priority setting before JB release).  This is hidden by the custom view.
        n.when = 1;
    }
    NotificationWrapper nw = new NotificationWrapper(n);
    if (AlertService.DEBUG) {
        for (AlertService.NotificationInfo info : notificationInfos) {
            nw.add(new NotificationWrapper(null, 0, info.eventId, info.startMillis, info.endMillis, false));
        }
    }
    return nw;
}
Also used : TextAppearanceSpan(android.text.style.TextAppearanceSpan) SpannableStringBuilder(android.text.SpannableStringBuilder) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification) RemoteViews(android.widget.RemoteViews) Resources(android.content.res.Resources) PendingIntent(android.app.PendingIntent) SpannableStringBuilder(android.text.SpannableStringBuilder) NotificationWrapper(com.android.calendar.alerts.AlertService.NotificationWrapper)

Aggregations

TextAppearanceSpan (android.text.style.TextAppearanceSpan)52 SpannableString (android.text.SpannableString)21 SpannableStringBuilder (android.text.SpannableStringBuilder)15 Spanned (android.text.Spanned)15 TypedValue (android.util.TypedValue)15 View (android.view.View)10 ColorStateList (android.content.res.ColorStateList)9 SmallTest (android.test.suitebuilder.annotation.SmallTest)6 Intent (android.content.Intent)5 TypedArray (android.content.res.TypedArray)5 Espresso.onView (android.support.test.espresso.Espresso.onView)5 NoMatchingViewException (android.support.test.espresso.NoMatchingViewException)5 ViewAssertion (android.support.test.espresso.ViewAssertion)5 RootMatchers.withDecorView (android.support.test.espresso.matcher.RootMatchers.withDecorView)5 TextPaint (android.text.TextPaint)5 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)5 CharacterStyle (android.text.style.CharacterStyle)5 RelativeSizeSpan (android.text.style.RelativeSizeSpan)5 SuggestionSpan (android.text.style.SuggestionSpan)5 ImageView (android.widget.ImageView)5