當前位置: 首頁>>代碼示例>>Java>>正文


Java PhoneFormat.stripExceptNumbers方法代碼示例

本文整理匯總了Java中org.telegram.PhoneFormat.PhoneFormat.stripExceptNumbers方法的典型用法代碼示例。如果您正苦於以下問題:Java PhoneFormat.stripExceptNumbers方法的具體用法?Java PhoneFormat.stripExceptNumbers怎麽用?Java PhoneFormat.stripExceptNumbers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.telegram.PhoneFormat.PhoneFormat的用法示例。


在下文中一共展示了PhoneFormat.stripExceptNumbers方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkPhonePattern

import org.telegram.PhoneFormat.PhoneFormat; //導入方法依賴的package包/類
public static boolean checkPhonePattern(String pattern, String phone) {
    if (TextUtils.isEmpty(pattern) || pattern.equals("*")) {
        return true;
    }
    String args[] = pattern.split("\\*");
    phone = PhoneFormat.stripExceptNumbers(phone);
    int checkStart = 0;
    int index;
    for (int a = 0; a < args.length; a++) {
        String arg = args[a];
        if (!TextUtils.isEmpty(arg)) {
            if ((index = phone.indexOf(arg, checkStart)) == -1) {
                return false;
            }
            checkStart = index + arg.length();
        }
    }
    return true;
}
 
開發者ID:DrKLO,項目名稱:Telegram,代碼行數:20,代碼來源:AndroidUtilities.java

示例2: fillNumber

import org.telegram.PhoneFormat.PhoneFormat; //導入方法依賴的package包/類
@SuppressLint("HardwareIds")
public void fillNumber(String number) {
    try {
        TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
        boolean allowCall = true;
        boolean allowSms = true;
        if (number != null || tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE) {
            if (Build.VERSION.SDK_INT >= 23) {
                allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
                allowSms = getParentActivity().checkSelfPermission(Manifest.permission.RECEIVE_SMS) == PackageManager.PERMISSION_GRANTED;
            }
            if (number != null || allowCall || allowSms) {
                if (number == null) {
                    number = PhoneFormat.stripExceptNumbers(tm.getLine1Number());
                }
                String textToSet = null;
                boolean ok = false;
                if (!TextUtils.isEmpty(number)) {
                    if (number.length() > 4) {
                        for (int a = 4; a >= 1; a--) {
                            String sub = number.substring(0, a);
                            String country = codesMap.get(sub);
                            if (country != null) {
                                ok = true;
                                textToSet = number.substring(a, number.length());
                                inputFields[FIELD_PHONECODE].setText(sub);
                                break;
                            }
                        }
                        if (!ok) {
                            textToSet = number.substring(1, number.length());
                            inputFields[FIELD_PHONECODE].setText(number.substring(0, 1));
                        }
                    }
                    if (textToSet != null) {
                        inputFields[FIELD_PHONE].setText(textToSet);
                        inputFields[FIELD_PHONE].setSelection(inputFields[FIELD_PHONE].length());
                    }
                }
            }
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
}
 
開發者ID:DrKLO,項目名稱:Telegram,代碼行數:46,代碼來源:PaymentFormActivity.java

示例3: fillNumber

import org.telegram.PhoneFormat.PhoneFormat; //導入方法依賴的package包/類
public void fillNumber() {
    try {
        TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
        if (tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE) {
            boolean allowCall = true;
            boolean allowSms = true;
            if (Build.VERSION.SDK_INT >= 23) {
                allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
                allowSms = getParentActivity().checkSelfPermission(Manifest.permission.RECEIVE_SMS) == PackageManager.PERMISSION_GRANTED;
                if (checkShowPermissions && !allowCall && !allowSms) {
                    permissionsShowItems.clear();
                    if (!allowCall) {
                        permissionsShowItems.add(Manifest.permission.READ_PHONE_STATE);
                    }
                    if (!allowSms) {
                        permissionsShowItems.add(Manifest.permission.RECEIVE_SMS);
                        if (Build.VERSION.SDK_INT >= 23) {
                            permissionsShowItems.add(Manifest.permission.READ_SMS);
                        }
                    }
                    if (!permissionsShowItems.isEmpty()) {
                        SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                        if (preferences.getBoolean("firstloginshow", true) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.READ_PHONE_STATE) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.RECEIVE_SMS)) {
                            preferences.edit().putBoolean("firstloginshow", false).commit();
                            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                            builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                            builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                            builder.setMessage(LocaleController.getString("AllowFillNumber", R.string.AllowFillNumber));
                            permissionsShowDialog = showDialog(builder.create());
                        } else {
                            getParentActivity().requestPermissions(permissionsShowItems.toArray(new String[permissionsShowItems.size()]), 7);
                        }
                    }
                    return;
                }
            }
            if (allowCall || allowSms) {
                String number = PhoneFormat.stripExceptNumbers(tm.getLine1Number());
                String textToSet = null;
                boolean ok = false;
                if (!TextUtils.isEmpty(number)) {
                    if (number.length() > 4) {
                        for (int a = 4; a >= 1; a--) {
                            String sub = number.substring(0, a);
                            String country = codesMap.get(sub);
                            if (country != null) {
                                ok = true;
                                textToSet = number.substring(a, number.length());
                                codeField.setText(sub);
                                break;
                            }
                        }
                        if (!ok) {
                            textToSet = number.substring(1, number.length());
                            codeField.setText(number.substring(0, 1));
                        }
                    }
                    if (textToSet != null) {
                        phoneField.requestFocus();
                        phoneField.setText(textToSet);
                        phoneField.setSelection(phoneField.length());
                    }
                }
            }
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
}
 
開發者ID:DrKLO,項目名稱:Telegram,代碼行數:70,代碼來源:LoginActivity.java


注:本文中的org.telegram.PhoneFormat.PhoneFormat.stripExceptNumbers方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。