当前位置: 首页>>代码示例>>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;未经允许,请勿转载。