Example usage for android.telephony PhoneNumberUtils stripSeparators

List of usage examples for android.telephony PhoneNumberUtils stripSeparators

Introduction

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

Prototype

public static String stripSeparators(String phoneNumber) 

Source Link

Document

Strips separators from a phone number string.

Usage

From source file:com.csipsimple.ui.dialpad.DialerFragment.java

private void placeCallWithOption(Bundle b) {
    if (service == null) {
        return;//from  ww  w.j  av  a2  s.  c  o  m
    }
    String toCall = "";
    Long accountToUse = SipProfile.INVALID_ID;
    // Find account to use
    SipProfile acc = accountChooserButton.getSelectedAccount();
    if (acc == null) {
        return;
    }

    accountToUse = acc.id;
    // Find number to dial
    toCall = digits.getText().toString();
    if (isDigit) {
        toCall = PhoneNumberUtils.stripSeparators(toCall);
    }

    if (accountChooserFilterItem != null && accountChooserFilterItem.isChecked()) {
        toCall = rewriteNumber(toCall);
    }

    if (TextUtils.isEmpty(toCall)) {
        return;
    }

    // Well we have now the fields, clear theses fields
    digits.getText().clear();

    // -- MAKE THE CALL --//
    if (accountToUse >= 0) {
        // It is a SIP account, try to call service for that
        try {
            service.makeCallWithOptions(toCall, accountToUse.intValue(), b);
        } catch (RemoteException e) {
            Log.e(THIS_FILE, "Service can't be called to make the call");
        }
    } else if (accountToUse != SipProfile.INVALID_ID) {
        // It's an external account, find correct external account
        CallHandlerPlugin ch = new CallHandlerPlugin(getActivity());
        ch.loadFrom(accountToUse, toCall, new OnLoadListener() {
            @Override
            public void onLoad(CallHandlerPlugin ch) {
                placePluginCall(ch);
            }
        });
    }
}

From source file:com.sonetel.ui.dialpad.ContactFragment.java

private void placeCallWithOption(Bundle b) {
    if (service == null) {
        return;//from   w  w w .  j  a  v a2s  . c  om
    }
    String toCall = "";
    Long accountToUse = SipProfile.INVALID_ID;
    // Find account to use
    SipProfile acc = accountChooserButton.getSelectedAccount();
    if (acc != null) {
        accountToUse = acc.id;
    }
    // Find number to dial
    if (isDigit) {
        toCall = PhoneNumberUtils.stripSeparators(digits.getText().toString());
    } else {
        toCall = digits.getText().toString();
    }

    if (TextUtils.isEmpty(toCall)) {
        return;
    }

    // Well we have now the fields, clear theses fields
    digits.getText().clear();

    // -- MAKE THE CALL --//
    if (accountToUse >= 0) {
        // It is a SIP account, try to call service for that
        try {
            service.makeCallWithOptions(toCall, accountToUse.intValue(), b);
        } catch (RemoteException e) {
            Log.e(THIS_FILE, "Service can't be called to make the call");
        }
    } else if (accountToUse != SipProfile.INVALID_ID) {
        // It's an external account, find correct external account
        // CallHandlerPlugin ch = new CallHandlerPlugin(getActivity());
        // String actualCall = toCall;
        if (accountToUse == -2) {
            if (!isRoaming()) {
                CallHandlerPlugin ch = new CallHandlerPlugin(getActivity());
                if (actualCall != null) {
                    if (!actualCall.equalsIgnoreCase("")) {
                        pDialog = new ProgressDialog(getActivity());
                        pDialog.setTitle("Sonetel call thru");
                        pDialog.setMessage("Authenticating...");
                        pDialog.setIndeterminate(true);
                        pDialog.show();

                        ch.loadFrom(accountToUse, actualCall, toCall, new OnLoadListener() {
                            @Override
                            public void onLoad(CallHandlerPlugin ch) {
                                // placePluginCall(ch);
                            }
                        });
                    } else {
                        Location_Finder LocFinder = new Location_Finder(getActivity());
                        if (LocFinder.getContryName().startsWith("your"))
                            Toast.makeText(getActivity(),
                                    "Country of your current location unknown. Call thru not available.",
                                    Toast.LENGTH_LONG).show();
                        else
                            Toast.makeText(getActivity(),
                                    "No Call thru access number available in " + LocFinder.getContryName(),
                                    Toast.LENGTH_LONG).show();
                        //Toast.makeText(context, "No Call thru access number available in ", Toast.LENGTH_LONG).show();
                    }
                } else {
                    Location_Finder LocFinder = new Location_Finder(getActivity());
                    if (LocFinder.getContryName().startsWith("your"))
                        Toast.makeText(getActivity(),
                                "Country of your current location unknown. Call thru not available.",
                                Toast.LENGTH_LONG).show();
                    else
                        Toast.makeText(getActivity(),
                                "No Call thru access number available in " + LocFinder.getContryName(),
                                Toast.LENGTH_LONG).show();
                    //Toast.makeText(context, "No Call thru access number available in ", Toast.LENGTH_LONG).show();
                }

            } else
                Toast.makeText(getActivity(),
                        "Call thru is not available when roaming. Please buy a local SIM card if you want to use Call thru in this country.",
                        Toast.LENGTH_LONG).show();
        } else if (accountToUse == -3) {
            CallHandlerPlugin ch = new CallHandlerPlugin(getActivity());

            pDialog = new ProgressDialog(getActivity());
            pDialog.setTitle("Sonetel call back");
            pDialog.setMessage("Please wait. You will receive a call in a moment.");
            pDialog.setIndeterminate(true);
            pDialog.show();

            ch.loadFrom(accountToUse, actualCall, toCall, new OnLoadListener() {
                @Override
                public void onLoad(CallHandlerPlugin ch) {
                    // placePluginCall(ch);
                }
            });

        }
        /*  else
          {
           ch.loadFrom(accountToUse, toCall, actualCall, new OnLoadListener() {
        @Override
        public void onLoad(CallHandlerPlugin ch) {
            placePluginCall(ch);
        }
           });
        }*/
    }
}

From source file:com.newcell.calltext.ui.dialpad.DialerFragment.java

private void placeCallWithOption(Bundle b) {
    if (service == null) {
        return;/*from w w  w .  j  a va 2s . com*/
    }
    String toCall = "";
    Long accountToUse = SipProfile.INVALID_ID;
    // Find account to use
    SipProfile acc = accountChooserButton.getSelectedAccount();
    if (acc == null) {
        return;
    }

    accountToUse = acc.id;
    // Find number to dial
    toCall = digits.getText().toString();
    if (isDigit) {
        toCall = PhoneNumberUtils.stripSeparators(toCall);
    }

    /*
     * Check for special phone numbers ie. *228
     * If found, call using gsm
     */
    if (toCall.equals("*228")) {
        Intent intent = new Intent(Intent.ACTION_CALL);
        intent.setData(Uri.parse("tel:" + toCall));
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        return;
    }

    if (accountChooserFilterItem != null && accountChooserFilterItem.isChecked()) {
        toCall = rewriteNumber(toCall);
    }

    if (TextUtils.isEmpty(toCall)) {
        return;
    }

    // Well we have now the fields, clear theses fields
    digits.getText().clear();

    // -- MAKE THE CALL --//
    if (accountToUse >= 0) {
        // It is a SIP account, try to call service for that
        try {
            service.makeCallWithOptions(toCall, accountToUse.intValue(), b);
        } catch (RemoteException e) {
            Log.e(THIS_FILE, "Service can't be called to make the call");
        }
    } else if (accountToUse != SipProfile.INVALID_ID) {
        // It's an external account, find correct external account
        CallHandlerPlugin ch = new CallHandlerPlugin(getActivity());
        ch.loadFrom(accountToUse, toCall, new OnLoadListener() {
            @Override
            public void onLoad(CallHandlerPlugin ch) {
                placePluginCall(ch);
            }
        });
    }
}

From source file:com.fututel.ui.dialpad.DialerFragment.java

private void placeCallWithOption(Bundle b) {
    if (service == null) {
        return;/*from  w  w w . j  a  v a  2  s  .  c  o m*/
    }
    String toCall = "";
    Long accountToUse = SipProfile.INVALID_ID;
    // Find account to use
    SipProfile acc = accountChooserButton.getSelectedAccount();
    if (acc != null) {
        accountToUse = acc.id;
    }
    // Find number to dial
    if (isDigit) {
        toCall = PhoneNumberUtils.stripSeparators(digits.getText().toString());
    } else {
        toCall = digits.getText().toString();
    }
    toCall = toCall.replace("+", ""); //rangdong

    if (TextUtils.isEmpty(toCall)) {
        return;
    }

    // Well we have now the fields, clear theses fields
    digits.getText().clear();

    // -- MAKE THE CALL --//
    if (accountToUse >= 0) {
        // It is a SIP account, try to call service for that
        try {
            service.makeCallWithOptions(toCall, accountToUse.intValue(), b);
        } catch (RemoteException e) {
            Log.e(THIS_FILE, "Service can't be called to make the call");
        }
    } else if (accountToUse != SipProfile.INVALID_ID) {
        // It's an external account, find correct external account
        CallHandlerPlugin ch = new CallHandlerPlugin(getActivity());
        ch.loadFrom(accountToUse, toCall, new OnLoadListener() {
            @Override
            public void onLoad(CallHandlerPlugin ch) {
                placePluginCall(ch);
            }
        });
    }
}

From source file:com.csipsimple.ui.dialpad.DialerFragment.java

private void applyRewritingInfo() {
    // Rewrite information textView update
    String newText = digits.getText().toString();
    if (accountChooserFilterItem != null && accountChooserFilterItem.isChecked()) {
        if (isDigit) {
            newText = PhoneNumberUtils.stripSeparators(newText);
        }//  www  .  j  a  v a 2 s .co m
        rewriteTextInfo.setText(rewriteNumber(newText));
    } else {
        rewriteTextInfo.setText("");
    }
}

From source file:com.sonetel.ui.dialpad.DialerFragment.java

private void placeCallWithOption(Bundle b) {
    if (service == null) {
        return;//from   w  w  w . j a  v  a2  s. co m
    }
    String toCall = "";
    Long accountToUse = SipProfile.INVALID_ID;
    // Find account to use
    SipProfile acc = accountChooserButton.getSelectedAccount();
    if (acc != null) {
        accountToUse = acc.id;
    }
    // Find number to dial
    if (isDigit) {
        toCall = PhoneNumberUtils.stripSeparators(digits.getText().toString());
    } else {
        toCall = digits.getText().toString();
    }

    if (TextUtils.isEmpty(toCall)) {
        return;
    }

    // Well we have now the fields, clear theses fields
    digits.getText().clear();

    // -- MAKE THE CALL --//
    if (accountToUse >= 0) {
        // It is a SIP account, try to call service for that
        try {
            service.makeCallWithOptions(toCall, accountToUse.intValue(), b);
        } catch (RemoteException e) {
            Log.e(THIS_FILE, "Service can't be called to make the call");
        }
    } else if (accountToUse != SipProfile.INVALID_ID) {
        // It's an external account, find correct external account

        // String actualCall = toCall;
        if (accountToUse == -2) {
            if (!isRoaming()) {

                if (actualCall != null) {
                    if (!actualCall.equalsIgnoreCase("")) {
                        pDialog = new ProgressDialog(getActivity());
                        pDialog.setTitle("Sonetel call thru");
                        pDialog.setMessage("Authenticating...");
                        pDialog.setIndeterminate(true);
                        pDialog.show();

                        CallHandlerPlugin ch = new CallHandlerPlugin(getActivity());
                        ch.loadFrom(accountToUse, actualCall, toCall, new OnLoadListener() {
                            @Override
                            public void onLoad(CallHandlerPlugin ch) {
                                // placePluginCall(ch);
                            }
                        });
                    } else {
                        Location_Finder LocFinder = new Location_Finder(getActivity());
                        if (LocFinder.getContryName().startsWith("your"))
                            Toast.makeText(getActivity(),
                                    "Country of your current location unknown. Call thru not available.",
                                    Toast.LENGTH_LONG).show();
                        else
                            Toast.makeText(getActivity(),
                                    "No Call thru access number available in " + LocFinder.getContryName(),
                                    Toast.LENGTH_LONG).show();
                        return;
                    }

                }

                else {
                    Location_Finder LocFinder = new Location_Finder(getActivity());
                    if (LocFinder.getContryName().startsWith("your"))
                        Toast.makeText(getActivity(),
                                "Country of your current location unknown. Call thru not available.",
                                Toast.LENGTH_LONG).show();
                    else
                        Toast.makeText(getActivity(),
                                "No Call thru access number available in " + LocFinder.getContryName(),
                                Toast.LENGTH_LONG).show();
                    return;
                }

            } else
                Toast.makeText(getActivity(),
                        "Call thru is not available when roaming. Please buy a local SIM card if you want to use Call thru in this country.",
                        Toast.LENGTH_LONG).show();
        } else if (accountToUse == -3) {
            CallHandlerPlugin ch = new CallHandlerPlugin(getActivity());

            pDialog = new ProgressDialog(getActivity());
            pDialog.setTitle("Sonetel call back");
            pDialog.setMessage("Please wait. You will receive a call in a moment.");
            pDialog.setIndeterminate(true);
            pDialog.show();

            ch.loadFrom(accountToUse, actualCall, toCall, new OnLoadListener() {
                @Override
                public void onLoad(CallHandlerPlugin ch) {
                    // placePluginCall(ch);
                }
            });

        }
    }
}