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

public static String formatNumber(String phoneNumber, String defaultCountryIso) 

Source Link

Document

Format a phone number.

Usage

From source file:Main.java

private static String format(String number) {
    return PhoneNumberUtils.formatNumber(number, "uk");
}

From source file:Main.java

/**
 * Format a phone number based on the number's country code, falling
 * back to the format defined by the user's current locale. This is
 * to replace calling {@link PhoneNumberUtils#formatNumber(String)},
 * which was deprecated in the LOLLIPOP release.
 *
 * @see PhoneNumberUtils#formatNumber(String, String)
 * @param number The phone number to be formatted
 * @return The phone number, formatted based on the country code or
 * user's locale./*ww w.  j  a v  a  2 s. c  o  m*/
 */
public static String formatNumber(String number) {
    return PhoneNumberUtils.formatNumber(number, Locale.getDefault().getCountry());
}

From source file:com.hackensack.umc.activity.ViewProfileActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_profile);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    sharedPreferences = getSharedPreferences(Constant.SHAREPREF_TAG, MODE_PRIVATE);
    insuranceInfoTv = (TextView) findViewById(R.id.prof_insurance_tv);
    if (Util.isUserLogin(this) && Util.isPatientIdValid(this)) {

        try {//w  w w .j a va 2s  . co m
            mPatient = new LoginUserData(new JSONObject(Util.getPatientJSON(this)));
            ((TextView) findViewById(R.id.profile_fname)).setText(mPatient.getFirstName());
            ((TextView) findViewById(R.id.prof_lname)).setText(mPatient.getLastName());
            ((TextView) findViewById(R.id.prof_license)).setText(
                    TextUtils.isEmpty(mPatient.getDrivingLicense()) ? "-" : mPatient.getDrivingLicense());
            DateFormat formatterDate = new SimpleDateFormat("MM-dd-yyyy");

            Date d = null;
            try {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
                d = sdf.parse(mPatient.getBirthDate());
            } catch (Exception e) {
                Log.e("Date", " " + e);
            }

            //Bug is there : Null Pointer : Appointment Date
            ((TextView) findViewById(R.id.prof_date)).setText(formatterDate.format(d.getTime()));
            ((TextView) findViewById(R.id.prof_gender_tv)).setText(mPatient.getGender());
            //Code for getting and displaying phone numbers
            ArrayList<Telecom> telecom = mPatient.getTelephone();
            Log.v("Telecom", telecom.toString());
            String phonestr = null;
            for (int i = 0; i < telecom.size(); i++) {
                if (((Telecom) telecom.get(i)).getSystem().equalsIgnoreCase(Telecom.TELECOM_EMAIL)) {
                    ((TextView) findViewById(R.id.prof_email)).setText(((Telecom) telecom.get(i)).getValue());
                } else if (((Telecom) telecom.get(i)).getSystem().equalsIgnoreCase(Telecom.TELECOM_PHONE)) {
                    phonestr = telecom.get(i).getValue();
                    final Editable doctorPhoneNum = new SpannableStringBuilder(phonestr);
                    PhoneNumberUtils.formatNumber(doctorPhoneNum,
                            PhoneNumberUtils.getFormatTypeForLocale(Locale.US));
                    if (((Telecom) telecom.get(i)).getUse().equalsIgnoreCase(Telecom.TELECOM_MOBILE_PHONE)) {
                        findViewById(R.id.mobile_ll).setVisibility(View.VISIBLE);
                        ((TextView) findViewById(R.id.prof_mob_num)).setText(doctorPhoneNum);

                    } else if (((Telecom) telecom.get(i)).getUse()
                            .equalsIgnoreCase(Telecom.TELECOM_HOME_PHONE)) {
                        findViewById(R.id.home_ll).setVisibility(View.VISIBLE);
                        ((TextView) findViewById(R.id.prof_home_num)).setText(doctorPhoneNum);

                    } else if (((Telecom) telecom.get(i)).getUse()
                            .equalsIgnoreCase(Telecom.TELECOM_WORK_PHONE)) {
                        findViewById(R.id.work_ll).setVisibility(View.VISIBLE);
                        ((TextView) findViewById(R.id.prof_work_num)).setText(doctorPhoneNum);
                    }
                }
            }
            //Code to get and display address
            if (mPatient.getAddress() != null && mPatient.getAddress().size() > 0) {
                Address address = ((ArrayList<Address>) mPatient.getAddress()).get(0);
                ((TextView) findViewById(R.id.prof_addr_tv)).setText(address.getStreet1() + ","
                        + (TextUtils.isEmpty(address.getStreet2()) ? "" : address.getStreet2() + ",")
                        + address.getCity() + "," + address.getState() + "," + address.getZip() + ","
                        + address.getCountry());
            }

        } catch (Exception e) {
            Log.e("isUserLogin", "", e);

        }
        //Code to get and display insurance info

        new GetInsuranceInfo().execute(mPatient.getMRNId());
    }

    /* mProgressDialog = new ProgressDialog(this);
     mProgressDialog.setCancelable(false);*/
}

From source file:com.example.android.oauthTesting_slidingTabBasic.SlidingTabsBasicFragment.java

/**
 * This is called after the {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)} has finished.
 * Here we can pick out the {@link View}s we need to configure from the content view.
 *
 * We set the {@link ViewPager}'s adapter to be an instance of {@link SamplePagerAdapter}. The
 * {@link SlidingTabLayout} is then given the {@link ViewPager} so that it can populate itself.
 *
 * @param view View created in {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}
 *//*  ww w. j  av a  2s. c  o m*/
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    // BEGIN_INCLUDE (setup_viewpager)
    // Get the ViewPager and set it's PagerAdapter so that it can display items
    mViewPager = (ViewPager) view.findViewById(R.id.viewpager);
    //mViewPager.setAdapter(new SimpleViewPagerAdapter(this.getChildFragmentManager()));
    mViewPager.setAdapter(new SimpleViewPagerAdapter(this.getChildFragmentManager()));
    // END_INCLUDE (setup_viewpager)

    // BEGIN_INCLUDE (setup_slidingtablayout)
    // Give the SlidingTabLayout the ViewPager, this must be done AFTER the ViewPager has had
    // it's PagerAdapter set.
    mSlidingTabLayout = (SlidingTabLayout) view.findViewById(R.id.sliding_tabs);
    mSlidingTabLayout.setViewPager(mViewPager);

    final EditText recipient_phone = (EditText) view.findViewById(R.id.recipient_phone);
    recipient_phone.addTextChangedListener(new PhoneNumberFormattingTextWatcher());

    final Button send_sms = (Button) view.findViewById(R.id.send_sms);
    send_sms.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String number = recipient_phone.getText().toString();
            String s = PhoneNumberUtils.stripSeparators(recipient_phone.getText().toString());

            String q = PhoneNumberUtils.formatNumber(s, "US");
            String r = q;

        }
        // END_INCLUDE (setup_slidingtablayout)
    });

    //----FACEBOOK OAUTH TRIAL STUFF----//
    callbackManager = CallbackManager.Factory.create();
    loginButton = (LoginButton) view.findViewById(R.id.login_button);

    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            int a = 5;
            int b = a;
        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError(FacebookException e) {

        }
    });
    // END_INCLUDE (fragment_onviewcreated)

    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail().build();

    mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
            .enableAutoManage(getActivity() /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();

    SignInButton signInButton = (SignInButton) view.findViewById(R.id.sign_in_button);
    signInButton.setOnClickListener(this);
}

From source file:android.pim.vcard.VCardBuilder.java

public VCardBuilder appendPhones(final List<ContentValues> contentValuesList) {
    boolean phoneLineExists = false;
    if (contentValuesList != null) {
        Set<String> phoneSet = new HashSet<String>();
        for (ContentValues contentValues : contentValuesList) {
            final Integer typeAsObject = contentValues.getAsInteger(Phone.TYPE);
            final String label = contentValues.getAsString(Phone.LABEL);
            final Integer isPrimaryAsInteger = contentValues.getAsInteger(Phone.IS_PRIMARY);
            final boolean isPrimary = (isPrimaryAsInteger != null ? (isPrimaryAsInteger > 0) : false);
            String phoneNumber = contentValues.getAsString(Phone.NUMBER);
            if (phoneNumber != null) {
                phoneNumber = phoneNumber.trim();
            }//from   w w  w . ja v a  2  s  .com
            if (TextUtils.isEmpty(phoneNumber)) {
                continue;
            }
            int type = (typeAsObject != null ? typeAsObject : DEFAULT_PHONE_TYPE);
            if (type == Phone.TYPE_PAGER) {
                phoneLineExists = true;
                if (!phoneSet.contains(phoneNumber)) {
                    phoneSet.add(phoneNumber);
                    appendTelLine(type, label, phoneNumber, isPrimary);
                }
            } else {
                // The entry "may" have several phone numbers when the contact entry is
                // corrupted because of its original source.
                //
                // e.g. I encountered the entry like the following.
                // "111-222-3333 (Miami)\n444-555-6666 (Broward; 305-653-6796 (Miami); ..."
                // This kind of entry is not able to be inserted via Android devices, but
                // possible if the source of the data is already corrupted.
                List<String> phoneNumberList = splitIfSeveralPhoneNumbersExist(phoneNumber);
                if (phoneNumberList.isEmpty()) {
                    continue;
                }
                phoneLineExists = true;
                for (String actualPhoneNumber : phoneNumberList) {
                    if (!phoneSet.contains(actualPhoneNumber)) {
                        final int format = VCardUtils.getPhoneNumberFormat(mVCardType);
                        final String formattedPhoneNumber = PhoneNumberUtils.formatNumber(actualPhoneNumber,
                                format);
                        phoneSet.add(actualPhoneNumber);
                        appendTelLine(type, label, formattedPhoneNumber, isPrimary);
                    }
                }
            }
        }
    }

    if (!phoneLineExists && mIsDoCoMo) {
        appendTelLine(Phone.TYPE_HOME, "", "", false);
    }

    return this;
}