Java Code Examples for org.telegram.PhoneFormat.PhoneFormat#stripExceptNumbers()
The following examples show how to use
org.telegram.PhoneFormat.PhoneFormat#stripExceptNumbers() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AndroidUtilities.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
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; }
Example 2
Source File: AndroidUtilities.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
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; }
Example 3
Source File: AndroidUtilities.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
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; }
Example 4
Source File: AndroidUtilities.java From Telegram with GNU General Public License v2.0 | 6 votes |
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; }
Example 5
Source File: PaymentFormActivity.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
@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); } }
Example 6
Source File: LoginActivity.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
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 = MessagesController.getGlobalMainSettings(); 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 (!newAccount && (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); } }
Example 7
Source File: PaymentFormActivity.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
@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); } }
Example 8
Source File: LoginActivity.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
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 = MessagesController.getGlobalMainSettings(); 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 (!newAccount && (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); } }
Example 9
Source File: PaymentFormActivity.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
@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; } if (number != null || allowCall) { 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); inputFields[FIELD_PHONECODE].setText(sub); break; } } if (!ok) { textToSet = number.substring(1); 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); } }
Example 10
Source File: PaymentFormActivity.java From Telegram with GNU General Public License v2.0 | 4 votes |
@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; } if (number != null || allowCall) { 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); inputFields[FIELD_PHONECODE].setText(sub); break; } } if (!ok) { textToSet = number.substring(1); 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); } }