Example usage for android.support.v4.text BidiFormatter getInstance

List of usage examples for android.support.v4.text BidiFormatter getInstance

Introduction

In this page you can find the example usage for android.support.v4.text BidiFormatter getInstance.

Prototype

public static BidiFormatter getInstance() 

Source Link

Usage

From source file:com.android.messaging.ui.BlockedParticipantListItemView.java

public void bind(final ParticipantListItemData data) {
    mData = data;/*  w w  w . j a v a  2  s  .  c o m*/
    final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
    mNameTextView.setText(bidiFormatter.unicodeWrap(data.getDisplayName(), TextDirectionHeuristicsCompat.LTR));
    mContactIconView.setImageResourceUri(data.getAvatarUri(), data.getContactId(), data.getLookupKey(),
            data.getNormalizedDestination());
    mNameTextView.setText(data.getDisplayName());
}

From source file:com.android.messaging.ui.appsettings.PhoneNumberPreference.java

@Override
protected void onBindView(final View view) {
    // Show the preference value if it's set, or the default number if not.
    // If we don't have a default, fall back to a static string (e.g. Unknown).
    String value = getText();/*from www  .  j ava2  s. c  o m*/
    if (TextUtils.isEmpty(value)) {
        value = mDefaultPhoneNumber;
    }
    final String displayValue = (!TextUtils.isEmpty(value)) ? PhoneUtils.get(mSubId).formatForDisplay(value)
            : getContext().getString(R.string.unknown_phone_number_pref_display_value);
    final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
    final String phoneNumber = bidiFormatter.unicodeWrap(displayValue, TextDirectionHeuristicsCompat.LTR);
    // Set the value as the summary and let the superclass populate the views
    setSummary(phoneNumber);
    super.onBindView(view);
}

From source file:com.android.messaging.ui.appsettings.PhoneNumberPreference.java

@Override
protected void onBindDialogView(final View view) {
    super.onBindDialogView(view);

    final String value = getText();

    // If the preference is empty, populate the EditText with the default number instead.
    if (TextUtils.isEmpty(value) && !TextUtils.isEmpty(mDefaultPhoneNumber)) {
        final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
        final String phoneNumber = bidiFormatter.unicodeWrap(
                PhoneUtils.get(mSubId).getCanonicalBySystemLocale(mDefaultPhoneNumber),
                TextDirectionHeuristicsCompat.LTR);
        getEditText().setText(phoneNumber);
    }/*  w w  w. j  a  v  a 2 s  .co  m*/
    getEditText().setInputType(InputType.TYPE_CLASS_PHONE);
}

From source file:com.keylesspalace.tusky.adapter.NotificationsAdapter.java

public NotificationsAdapter(StatusActionListener statusListener,
        NotificationActionListener notificationActionListener) {
    super();/*from   ww w.  j av  a2  s.c o m*/
    notifications = new ArrayList<>();
    this.statusListener = statusListener;
    this.notificationActionListener = notificationActionListener;
    footerState = FooterViewHolder.State.END;
    mediaPreviewEnabled = true;
    bidiFormatter = BidiFormatter.getInstance();
}

From source file:com.android.messaging.ui.contact.ContactDropdownLayouter.java

/**
 * Bind a drop down view to a RecipientEntry. We'd like regular dropdown items (BASE_RECIPIENT)
 * to behave the same as regular ContactListItemViews, while using the chips library's
 * item styling for alternates dropdown items (happens when you click on a chip).
 *//*  www  .ja  v a2 s  .com*/
@Override
public View bindView(final View convertView, final ViewGroup parent, final RecipientEntry entry,
        final int position, AdapterType type, final String substring, final StateListDrawable deleteDrawable) {
    if (type != AdapterType.BASE_RECIPIENT) {
        if (type == AdapterType.SINGLE_RECIPIENT) {
            // Treat single recipients the same way as alternates. The base implementation of
            // single recipients would try to simplify the destination by tokenizing. We'd
            // like to always show the full destination address per design request.
            type = AdapterType.RECIPIENT_ALTERNATES;
        }
        return super.bindView(convertView, parent, entry, position, type, substring, deleteDrawable);
    }

    // Default to show all the information
    // RTL : To format contact name and detail if they happen to be phone numbers.
    final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
    final String displayName = bidiFormatter.unicodeWrap(
            ContactRecipientEntryUtils.getDisplayNameForContactList(entry), TextDirectionHeuristicsCompat.LTR);
    final String destination = bidiFormatter.unicodeWrap(ContactRecipientEntryUtils.formatDestination(entry),
            TextDirectionHeuristicsCompat.LTR);
    final View itemView = reuseOrInflateView(convertView, parent, type);

    // Bold the string that is matched.
    final CharSequence[] styledResults = getStyledResults(substring, displayName, destination);

    Assert.isTrue(itemView instanceof ContactListItemView);
    final ContactListItemView contactListItemView = (ContactListItemView) itemView;
    contactListItemView.setImageClickHandlerDisabled(true);
    boolean isWorkContact = ContactUtil.isEnterpriseContactId(entry.getContactId());
    contactListItemView.bind(entry, styledResults[0], styledResults[1], mClivHostInterface,
            (type == AdapterType.SINGLE_RECIPIENT), isWorkContact);
    return itemView;
}

From source file:com.keylesspalace.tusky.util.NotificationHelper.java

/**
 * Takes a given Mastodon notification and either creates a new Android notification or updates
 * the state of the existing notification to reflect the new interaction.
 *
 * @param context to access application preferences and services
 * @param body    a new Mastodon notification
 * @param account the account for which the notification should be shown
 *///from  ww w  . j a  va  2s. c  o  m

public static void make(final Context context, Notification body, AccountEntity account,
        boolean isFirstOfBatch) {

    if (!filterNotification(account, body, context)) {
        return;
    }

    String rawCurrentNotifications = account.getActiveNotifications();
    JSONArray currentNotifications;
    BidiFormatter bidiFormatter = BidiFormatter.getInstance();

    try {
        currentNotifications = new JSONArray(rawCurrentNotifications);
    } catch (JSONException e) {
        currentNotifications = new JSONArray();
    }

    for (int i = 0; i < currentNotifications.length(); i++) {
        try {
            if (currentNotifications.getString(i).equals(body.getAccount().getName())) {
                currentNotifications.remove(i);
                break;
            }
        } catch (JSONException e) {
            Log.d(TAG, Log.getStackTraceString(e));
        }
    }

    currentNotifications.put(body.getAccount().getName());

    account.setActiveNotifications(currentNotifications.toString());

    // Notification group member
    // =========================
    final NotificationCompat.Builder builder = newNotification(context, body, account, false);

    notificationId++;

    builder.setContentTitle(titleForType(context, body, bidiFormatter)).setContentText(bodyForType(body));

    if (body.getType() == Notification.Type.MENTION) {
        builder.setStyle(new NotificationCompat.BigTextStyle().bigText(bodyForType(body)));
    }

    //load the avatar synchronously
    Bitmap accountAvatar;
    try {
        accountAvatar = Picasso.with(context).load(body.getAccount().getAvatar())
                .transform(new RoundedTransformation(20)).get();
    } catch (IOException e) {
        Log.d(TAG, "error loading account avatar", e);
        accountAvatar = BitmapFactory.decodeResource(context.getResources(), R.drawable.avatar_default);
    }

    builder.setLargeIcon(accountAvatar);

    // Reply to mention action; RemoteInput is available from KitKat Watch, but buttons are available from Nougat
    if (body.getType() == Notification.Type.MENTION
            && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        RemoteInput replyRemoteInput = new RemoteInput.Builder(KEY_REPLY)
                .setLabel(context.getString(R.string.label_quick_reply)).build();

        PendingIntent quickReplyPendingIntent = getStatusReplyIntent(REPLY_ACTION, context, body, account);

        NotificationCompat.Action quickReplyAction = new NotificationCompat.Action.Builder(
                R.drawable.ic_reply_24dp, context.getString(R.string.action_quick_reply),
                quickReplyPendingIntent).addRemoteInput(replyRemoteInput).build();

        builder.addAction(quickReplyAction);

        PendingIntent composePendingIntent = getStatusReplyIntent(COMPOSE_ACTION, context, body, account);

        NotificationCompat.Action composeAction = new NotificationCompat.Action.Builder(
                R.drawable.ic_reply_24dp, context.getString(R.string.action_compose_shortcut),
                composePendingIntent).build();

        builder.addAction(composeAction);
    }

    builder.setSubText(account.getFullName());
    builder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE);
    builder.setCategory(NotificationCompat.CATEGORY_SOCIAL);
    builder.setOnlyAlertOnce(true);

    // only alert for the first notification of a batch to avoid multiple alerts at once
    if (!isFirstOfBatch) {
        builder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY);
    }

    // Summary
    // =======
    final NotificationCompat.Builder summaryBuilder = newNotification(context, body, account, true);

    if (currentNotifications.length() != 1) {
        try {
            String title = context.getString(R.string.notification_title_summary,
                    currentNotifications.length());
            String text = joinNames(context, currentNotifications, bidiFormatter);
            summaryBuilder.setContentTitle(title).setContentText(text);
        } catch (JSONException e) {
            Log.d(TAG, Log.getStackTraceString(e));
        }
    }

    summaryBuilder.setSubText(account.getFullName());
    summaryBuilder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE);
    summaryBuilder.setCategory(NotificationCompat.CATEGORY_SOCIAL);
    summaryBuilder.setOnlyAlertOnce(true);
    summaryBuilder.setGroupSummary(true);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

    //noinspection ConstantConditions
    notificationManager.notify(notificationId, builder.build());
    if (currentNotifications.length() == 1) {
        notificationManager.notify((int) account.getId(), builder.setGroupSummary(true).build());
    } else {
        notificationManager.notify((int) account.getId(), summaryBuilder.build());
    }
}

From source file:com.android.messaging.ui.PersonItemView.java

/**
 * @return Display name, possibly comma-ellipsized.
 *//*w w w  .  ja v a2  s. c  o m*/
private String getDisplayName() {
    final int width = mNameTextView.getMeasuredWidth();
    final String displayName = mBinding.getData().getDisplayName();
    if (width == 0 || TextUtils.isEmpty(displayName) || !displayName.contains(",")) {
        return displayName;
    }
    final String plusOneString = getContext().getString(R.string.plus_one);
    final String plusNString = getContext().getString(R.string.plus_n);
    return BidiFormatter.getInstance()
            .unicodeWrap(UiUtils
                    .commaEllipsize(displayName, mNameTextView.getPaint(), width, plusOneString, plusNString)
                    .toString(), TextDirectionHeuristicsCompat.LTR);
}

From source file:com.chen.mail.browse.SendersView.java

private static synchronized void getSenderResources(Context context, final boolean resourceCachingRequired) {
    if (sConfigurationChangedReceiver == null && resourceCachingRequired) {
        sConfigurationChangedReceiver = new BroadcastReceiver() {
            @Override//ww w . j  a  v a 2  s  . c  o  m
            public void onReceive(Context context, Intent intent) {
                sDraftSingularString = null;
                getSenderResources(context, true);
            }
        };
        context.registerReceiver(sConfigurationChangedReceiver,
                new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED));
    }
    if (sDraftSingularString == null) {
        Resources res = context.getResources();
        sSendersSplitToken = res.getString(R.string.senders_split_token);
        sElidedString = res.getString(R.string.senders_elided);
        sDraftSingularString = res.getQuantityText(R.plurals.draft, 1);
        sDraftPluralString = res.getQuantityText(R.plurals.draft, 2);
        sDraftCountFormatString = res.getString(R.string.draft_count_format);
        sMessageInfoUnreadStyleSpan = new TextAppearanceSpan(context, R.style.MessageInfoUnreadTextAppearance);
        sMessageInfoReadStyleSpan = new TextAppearanceSpan(context, R.style.MessageInfoReadTextAppearance);
        sDraftsStyleSpan = new TextAppearanceSpan(context, R.style.DraftTextAppearance);
        sUnreadStyleSpan = new TextAppearanceSpan(context, R.style.SendersUnreadTextAppearance);
        sSendingStyleSpan = new TextAppearanceSpan(context, R.style.SendingTextAppearance);
        sReadStyleSpan = new TextAppearanceSpan(context, R.style.SendersReadTextAppearance);
        sMessageCountSpacerString = res.getString(R.string.message_count_spacer);
        sSendingString = res.getString(R.string.sending);
        sBidiFormatter = BidiFormatter.getInstance();
    }
}

From source file:com.android.mail.browse.SendersView.java

private static synchronized void getSenderResources(Context context, final boolean resourceCachingRequired) {
    if (sConfigurationChangedReceiver == null && resourceCachingRequired) {
        sConfigurationChangedReceiver = new BroadcastReceiver() {
            @Override//from  w  w w .j  a v a  2  s . co  m
            public void onReceive(Context context, Intent intent) {
                sDraftSingularString = null;
                getSenderResources(context, true);
            }
        };
        context.registerReceiver(sConfigurationChangedReceiver,
                new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED));
    }
    if (sDraftSingularString == null) {
        Resources res = context.getResources();
        sSendersSplitToken = res.getString(R.string.senders_split_token);
        sElidedString = res.getString(R.string.senders_elided);
        sDraftSingularString = res.getQuantityText(R.plurals.draft, 1);
        sDraftPluralString = res.getQuantityText(R.plurals.draft, 2);
        sDraftCountFormatString = res.getString(R.string.draft_count_format);
        sMeSubjectString = res.getString(R.string.me_subject_pronoun);
        sMeObjectString = res.getString(R.string.me_object_pronoun);
        sToHeaderString = res.getString(R.string.to_heading);
        sMessageInfoUnreadStyleSpan = new TextAppearanceSpan(context, R.style.MessageInfoUnreadTextAppearance);
        sMessageInfoReadStyleSpan = new TextAppearanceSpan(context, R.style.MessageInfoReadTextAppearance);
        sDraftsStyleSpan = new TextAppearanceSpan(context, R.style.DraftTextAppearance);
        sUnreadStyleSpan = new TextAppearanceSpan(context, R.style.SendersAppearanceUnreadStyle);
        sSendingStyleSpan = new TextAppearanceSpan(context, R.style.SendingTextAppearance);
        sRetryingStyleSpan = new TextAppearanceSpan(context, R.style.RetryingTextAppearance);
        sFailedStyleSpan = new TextAppearanceSpan(context, R.style.FailedTextAppearance);
        sReadStyleSpan = new TextAppearanceSpan(context, R.style.SendersAppearanceReadStyle);
        sMessageCountSpacerString = res.getString(R.string.message_count_spacer);
        sSendingString = res.getString(R.string.sending);
        sRetryingString = res.getString(R.string.message_retrying);
        sFailedString = res.getString(R.string.message_failed);
        sBidiFormatter = BidiFormatter.getInstance();
    }
}

From source file:com.android.mail.browse.SubjectAndFolderView.java

private BidiFormatter getBidiFormatter() {
    if (mBidiFormatter == null) {
        final ConversationViewAdapter adapter = mHeaderItem != null ? mHeaderItem.getAdapter() : null;
        if (adapter == null) {
            mBidiFormatter = BidiFormatter.getInstance();
        } else {/*  w  w  w . j  a  va2 s  .c om*/
            mBidiFormatter = adapter.getBidiFormatter();
        }
    }
    return mBidiFormatter;
}