Example usage for android.support.v4.text TextDirectionHeuristicsCompat LTR

List of usage examples for android.support.v4.text TextDirectionHeuristicsCompat LTR

Introduction

In this page you can find the example usage for android.support.v4.text TextDirectionHeuristicsCompat LTR.

Prototype

TextDirectionHeuristicCompat LTR

To view the source code for android.support.v4.text TextDirectionHeuristicsCompat LTR.

Click Source Link

Usage

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

public void bind(final ParticipantListItemData data) {
    mData = data;/*  w ww .jav a  2 s.  co 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();/* w w  w . jav  a  2 s .  co  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  2s.  c o  m*/
    getEditText().setInputType(InputType.TYPE_CLASS_PHONE);
}

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).
 *///from  w ww .  j av  a2 s.  c om
@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.android.messaging.ui.PersonItemView.java

/**
 * @return Display name, possibly comma-ellipsized.
 *//*from  w  ww  .  j  a v a  2 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.android.contacts.interactions.ImportDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final LayoutInflater dialogInflater = (LayoutInflater) getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    // Adapter that shows a list of string resources
    final ArrayAdapter<AdapterEntry> adapter = new ArrayAdapter<AdapterEntry>(getActivity(),
            R.layout.select_dialog_item) {

        @Override/*from  w  w  w .  j a va2s .c o  m*/
        public View getView(int position, View convertView, ViewGroup parent) {
            final View result = convertView != null ? convertView
                    : dialogInflater.inflate(R.layout.select_dialog_item, parent, false);
            final TextView primaryText = (TextView) result.findViewById(R.id.primary_text);
            final TextView secondaryText = (TextView) result.findViewById(R.id.secondary_text);
            final AdapterEntry entry = getItem(position);
            secondaryText.setVisibility(View.GONE);
            if (entry.mChoiceResourceId == R.string.import_from_sim) {
                final CharSequence secondary = getSimSecondaryText(entry.mSim);
                if (TextUtils.isEmpty(secondary)) {
                    secondaryText.setVisibility(View.GONE);
                } else {
                    secondaryText.setText(secondary);
                    secondaryText.setVisibility(View.VISIBLE);
                }
            }
            primaryText.setText(entry.mLabel);
            return result;
        }

        CharSequence getSimSecondaryText(SimCard sim) {
            int count = getSimContactCount(sim);

            CharSequence phone = sim.getFormattedPhone();
            if (phone == null) {
                phone = sim.getPhone();
            }
            if (phone != null) {
                phone = sBidiFormatter.unicodeWrap(PhoneNumberUtilsCompat.createTtsSpannable(phone),
                        TextDirectionHeuristicsCompat.LTR);
            }

            if (count != -1 && phone != null) {
                // We use a template instead of format string so that the TTS span is preserved
                final CharSequence template = getResources()
                        .getQuantityString(R.plurals.import_from_sim_secondary_template, count);
                return TextUtils.expandTemplate(template, String.valueOf(count), phone);
            } else if (phone != null) {
                return phone;
            } else if (count != -1) {
                // count != -1
                return getResources().getQuantityString(R.plurals.import_from_sim_secondary_contact_count_fmt,
                        count, count);
            } else {
                return null;
            }
        }
    };

    addItems(adapter);

    final DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            final int resId = adapter.getItem(which).mChoiceResourceId;
            if (resId == R.string.import_from_sim) {
                handleSimImportRequest(adapter.getItem(which).mSim);
            } else if (resId == R.string.import_from_vcf_file) {
                handleImportRequest(resId, SimCard.NO_SUBSCRIPTION_ID);
            } else {
                Log.e(TAG, "Unexpected resource: " + getActivity().getResources().getResourceEntryName(resId));
            }
            dialog.dismiss();
        }
    };

    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), getTheme())
            .setTitle(R.string.dialog_import).setNegativeButton(android.R.string.cancel, null);
    if (adapter.isEmpty()) {
        // Handle edge case; e.g. SIM card was removed.
        builder.setMessage(R.string.nothing_to_import_message);
    } else {
        builder.setSingleChoiceItems(adapter, -1, clickListener);
    }

    return builder.create();
}

From source file:com.android.messaging.ui.conversationlist.ConversationListItemView.java

private void setConversationName() {
    if (mData.getIsRead() || mData.getShowDraft()) {
        mConversationNameView.setTextColor(mListItemReadColor);
        mConversationNameView.setTypeface(mListItemReadTypeface);
    } else {//from w  w  w  .j  av  a 2s  .  c o m
        mConversationNameView.setTextColor(mListItemUnreadColor);
        mConversationNameView.setTypeface(mListItemUnreadTypeface);
    }

    final String conversationName = mData.getName();

    // For group conversations, ellipsize the group members that do not fit
    final CharSequence ellipsizedName = UiUtils.commaEllipsize(conversationName,
            mConversationNameView.getPaint(), mConversationNameView.getMeasuredWidth(), getPlusOneString(),
            getPlusNString());
    // RTL : To format conversation name if it happens to be phone number.
    final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
    final String bidiFormattedName = bidiFormatter.unicodeWrap(ellipsizedName.toString(),
            TextDirectionHeuristicsCompat.LTR);

    mConversationNameView.setText(bidiFormattedName);
}

From source file:com.bitflake.counter.HorizontalPicker.java

private TextDirectionHeuristicCompat getTextDirectionHeuristic() {

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {

        return TextDirectionHeuristicsCompat.FIRSTSTRONG_LTR;

    } else {//from  w ww  .java 2  s .  c  om

        // Always need to resolve layout direction first
        final boolean defaultIsRtl = (getLayoutDirection() == LAYOUT_DIRECTION_RTL);

        switch (getTextDirection()) {
        default:
        case TEXT_DIRECTION_FIRST_STRONG:
            return (defaultIsRtl ? TextDirectionHeuristicsCompat.FIRSTSTRONG_RTL
                    : TextDirectionHeuristicsCompat.FIRSTSTRONG_LTR);
        case TEXT_DIRECTION_ANY_RTL:
            return TextDirectionHeuristicsCompat.ANYRTL_LTR;
        case TEXT_DIRECTION_LTR:
            return TextDirectionHeuristicsCompat.LTR;
        case TEXT_DIRECTION_RTL:
            return TextDirectionHeuristicsCompat.RTL;
        case TEXT_DIRECTION_LOCALE:
            return TextDirectionHeuristicsCompat.LOCALE;
        }
    }
}

From source file:com.android.messaging.ui.conversation.ConversationFragment.java

public void updateActionBar(final ActionBar actionBar) {
    if (mComposeMessageView == null || !mComposeMessageView.updateActionBar(actionBar)) {
        updateActionAndStatusBarColor(actionBar);
        // We update this regardless of whether or not the action bar is showing so that we
        // don't get a race when it reappears.
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
        actionBar.setDisplayHomeAsUpEnabled(true);
        // Reset the back arrow to its default
        actionBar.setHomeAsUpIndicator(0);
        View customView = actionBar.getCustomView();
        if (customView == null || customView.getId() != R.id.conversation_title_container) {
            final LayoutInflater inflator = (LayoutInflater) getActivity()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            customView = inflator.inflate(R.layout.action_bar_conversation_name, null);
            customView.setOnClickListener(new View.OnClickListener() {
                @Override/* w  w  w  .  ja  v a2 s  .c o m*/
                public void onClick(final View v) {
                    onBackPressed();
                }
            });
            actionBar.setCustomView(customView);
        }

        final TextView conversationNameView = (TextView) customView.findViewById(R.id.conversation_title);
        final String conversationName = getConversationName();
        if (!TextUtils.isEmpty(conversationName)) {
            // RTL : To format conversation title if it happens to be phone numbers.
            final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
            final String formattedName = bidiFormatter.unicodeWrap(UiUtils.commaEllipsize(conversationName,
                    conversationNameView.getPaint(), conversationNameView.getWidth(),
                    getString(R.string.plus_one), getString(R.string.plus_n)).toString(),
                    TextDirectionHeuristicsCompat.LTR);
            conversationNameView.setText(formattedName);
            // In case phone numbers are mixed in the conversation name, we need to vocalize it.
            final String vocalizedConversationName = AccessibilityUtil.getVocalizedPhoneNumber(getResources(),
                    conversationName);
            conversationNameView.setContentDescription(vocalizedConversationName);
            getActivity().setTitle(conversationName);
        } else {
            final String appName = getString(R.string.app_name);
            conversationNameView.setText(appName);
            getActivity().setTitle(appName);
        }

        // When conversation is showing and media picker is not showing, then hide the action
        // bar only when we are in landscape mode, with IME open.
        if (mHost.isImeOpen() && UiUtils.isLandscapeMode()) {
            actionBar.hide();
        } else {
            actionBar.show();
        }
    }
}