Example usage for android.telephony PhoneNumberUtils formatNumber

List of usage examples for android.telephony PhoneNumberUtils formatNumber

Introduction

In this page you can find the example usage for android.telephony PhoneNumberUtils formatNumber.

Prototype

@Deprecated
public static String formatNumber(String source) 

Source Link

Document

Breaks the given number down and formats it according to the rules for the country the number is from.

Usage

From source file:com.andrewshu.android.reddit.comments.CommentsListActivity.java

/**
 * Helper function to add links from mVoteTargetThing to the button
 * @param linkButton Button that should open list of links
 *//*from   w ww  .  j  av  a 2s.  c om*/
private void linkToEmbeddedURLs(Button linkButton) {
    final ArrayList<String> urls = new ArrayList<String>();
    final ArrayList<MarkdownURL> vtUrls = mVoteTargetThing.getUrls();
    int urlsCount = vtUrls.size();
    for (int i = 0; i < urlsCount; i++) {
        urls.add(vtUrls.get(i).url);
    }
    if (urlsCount == 0) {
        linkButton.setEnabled(false);
    } else {
        linkButton.setEnabled(true);
        linkButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                removeDialog(Constants.DIALOG_COMMENT_CLICK);

                ArrayAdapter<MarkdownURL> adapter = new ArrayAdapter<MarkdownURL>(CommentsListActivity.this,
                        android.R.layout.select_dialog_item, vtUrls) {
                    public View getView(int position, View convertView, ViewGroup parent) {
                        TextView tv;
                        if (convertView == null) {
                            tv = (TextView) ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE))
                                    .inflate(android.R.layout.select_dialog_item, null);
                        } else {
                            tv = (TextView) convertView;
                        }

                        String url = getItem(position).url;
                        String anchorText = getItem(position).anchorText;
                        if (Constants.LOGGING)
                            Log.d(TAG, "links url=" + url + " anchorText=" + anchorText);

                        Drawable d = null;
                        try {
                            d = getPackageManager()
                                    .getActivityIcon(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                        } catch (NameNotFoundException ignore) {
                        }
                        if (d != null) {
                            d.setBounds(0, 0, d.getIntrinsicHeight(), d.getIntrinsicHeight());
                            tv.setCompoundDrawablePadding(10);
                            tv.setCompoundDrawables(d, null, null, null);
                        }

                        final String telPrefix = "tel:";
                        if (url.startsWith(telPrefix)) {
                            url = PhoneNumberUtils.formatNumber(url.substring(telPrefix.length()));
                        }

                        if (anchorText != null)
                            tv.setText(Html.fromHtml(
                                    "<span>" + anchorText + "</span><br /><small>" + url + "</small>"));
                        else
                            tv.setText(Html.fromHtml(url));

                        return tv;
                    }
                };

                AlertDialog.Builder b = new AlertDialog.Builder(
                        new ContextThemeWrapper(CommentsListActivity.this, mSettings.getDialogTheme()));

                DialogInterface.OnClickListener click = new DialogInterface.OnClickListener() {
                    public final void onClick(DialogInterface dialog, int which) {
                        if (which >= 0) {
                            Common.launchBrowser(CommentsListActivity.this, urls.get(which),
                                    Util.createThreadUri(getOpThingInfo()).toString(), false, false,
                                    mSettings.isUseExternalBrowser(), mSettings.isSaveHistory());
                        }
                    }
                };

                b.setTitle(R.string.select_link_title);
                b.setCancelable(true);
                b.setAdapter(adapter, click);

                b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public final void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });

                b.show();
            }
        });
    }
}