List of usage examples for android.util Patterns EMAIL_ADDRESS
Pattern EMAIL_ADDRESS
To view the source code for android.util Patterns EMAIL_ADDRESS.
Click Source Link
From source file:com.bcp.bcp.gcm.RegistrationIntentService.java
private String getMailId() { String email = ""; Pattern gmailPattern = Patterns.EMAIL_ADDRESS; Account[] accounts = AccountManager.get(this).getAccounts(); for (Account account : accounts) { if (gmailPattern.matcher(account.name).matches()) { email = account.name;// w ww . j a v a2s . co m } } return email; }
From source file:me.philio.ghost.ui.LoginFragment.java
@OnClick(R.id.btn_login) @Override/*from www . j av a 2 s .c o m*/ public void onClick(View v) { switch (v.getId()) { case R.id.btn_login: // Make sure email is lower case mEditEmail.setText(mEditEmail.getText().toString().trim().toLowerCase()); // Validate data before requesting an access token boolean valid = true; // Validate email address if (mEditEmail.getText().toString().isEmpty()) { mEditEmail.setError(getString(R.string.error_field_required)); valid = false; } else if (!Patterns.EMAIL_ADDRESS.matcher(mEditEmail.getText().toString()).matches()) { mEditEmail.setError(getString(R.string.error_invalid_email)); valid = false; } else if (AccountUtils.accountExists(getActivity(), mBlogUrl, mEditEmail.getText().toString())) { mEditEmail.setError(getString(R.string.error_email_exists)); valid = false; } else { mEditEmail.setError(null); } //Validate password if (mEditPassword.getText().toString().trim().isEmpty()) { mEditPassword.setError(getString(R.string.error_field_required)); valid = false; } else { mEditPassword.setError(null); } // If valid request access token if (valid) { // Disable button to avoid multiple clicks, show progress bar mBtnLogin.setEnabled(false); ((LoginActivity) getActivity()).setToolbarProgressBarVisibility(true); // Get credentials for later mEmail = mEditEmail.getText().toString(); mPassword = mEditPassword.getText().toString(); // Request access token Authentication authentication = mClient.createAuthentication(); authentication.getAccessToken(ApiConstants.GRANT_TYPE_PASSWORD, ApiConstants.CLIENT_ID, mEmail, mPassword, this); } break; } }
From source file:com.vinexs.tool.Utility.java
/** * <p>Get user gmail address.</p> * Required Permission <uses-permission android:name="android.permission.GET_ACCOUNTS"/> * * @param context Application context./*from www.j a va 2s .c o m*/ * @return Phone number in string. */ public static String getUserGmailAddress(Context context) { try { if (!hasPermission(context, Manifest.permission.GET_ACCOUNTS)) { throw new Exception("User did not grant permission."); } Pattern emailPattern = Patterns.EMAIL_ADDRESS; Account[] accounts = AccountManager.get(context).getAccounts(); for (Account account : accounts) { if (emailPattern.matcher(account.name).matches() && account.name.endsWith("gmail.com")) { return account.name; } } return null; } catch (Exception e) { Log.e("AccountManager", e.getMessage(), e); return null; } }
From source file:id.satusatudua.sigap.ui.fragment.TrustedsFragment.java
@OnClick(R.id.fab) public void addNewContact() { EditText editText = new EditText(getActivity()); editText.setHint("Email"); editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).setIcon(R.mipmap.ic_launcher) .setTitle("Masukan alamat email kontak").setView(editText) .setPositiveButton("Kirim", (dialog, which) -> { String email = editText.getText().toString(); if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) { showError("Mohon masukan alamat email yang valid!"); } else if (email.equalsIgnoreCase(CacheManager.pluck().getCurrentUser().getEmail())) { showError("Mohon masukan alamat email selain email anda sendiri!"); } else { trustedUserPresenter.searchUser(email); KeyboardUtil.hideKeyboard(getActivity(), editText); dialog.dismiss();/* www .jav a 2s. c o m*/ } }).setNegativeButton("Batal", (dialog, which1) -> { dialog.dismiss(); }).show(); alertDialog.getButton(DialogInterface.BUTTON_POSITIVE) .setTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary)); alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE) .setTextColor(ContextCompat.getColor(getActivity(), R.color.primary_text)); alertDialog.show(); }
From source file:com.netpace.expressit.fragment.MainGridFragment.java
private String getEmailId() { Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ Account[] accounts = AccountManager.get(getActivity().getApplicationContext()).getAccounts(); for (Account account : accounts) { if (emailPattern.matcher(account.name).matches()) { String possibleEmail = account.name; return possibleEmail; }/*from w w w . jav a 2 s .c om*/ } return null; }
From source file:com.denizensoft.appcompatlib.AppActivity.java
@Override public String appGetGoogleAccountString() { Pattern emailPattern = Patterns.EMAIL_ADDRESS; Account[] accounts = AccountManager.get(this).getAccounts(); for (int i = 0; i < accounts.length; ++i) { Account a1 = accounts[i];//from ww w . ja va2 s .co m if (emailPattern.matcher(a1.name).matches()) { String possibleEmail = a1.name, stType = a1.type; Log.d("Superhero", String.format("Found possible account %d: %s type: %s", i, possibleEmail, stType)); if (stType.equals("com.google")) { return possibleEmail; } } } return null; }
From source file:dtu.ds.warnme.app.dialog.RegisterDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_register, null); builder.setView(view);//from w w w.j a v a2 s. c o m builder.setTitle(R.string.register); builder.setPositiveButton(R.string.register, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int which) { // Nothing to do here... } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int which) { // Nothing to do here... } }); progressView = view.findViewById(R.id.dialog_register_progress); formView = view.findViewById(R.id.dialog_register_form); usernameEditText = (EditText) view.findViewById(R.id.dialog_register_edit_text_username); usernameEditText.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { // Nothing to do here... } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // Nothing to do here... } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { usernameEditText.setError(null); } }); passwordEditText = (EditText) view.findViewById(R.id.dialog_register_edit_text_password); passwordEditText.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { // Nothing to do here... } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // Nothing to do here... } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { passwordEditText.setError(null); } }); emailEditText = (EditText) view.findViewById(R.id.dialog_register_edit_text_email); emailEditText.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { // Nothing to do here... } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // Nothing to do here... } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { emailEditText.setError(null); } }); dialog = builder.create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { final Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE); positiveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String username = usernameEditText.getText().toString(); String password = passwordEditText.getText().toString(); String email = emailEditText.getText().toString(); boolean formOk = true; if (StringUtils.isBlank(username)) { usernameEditText.setError(getString(R.string.cannot_be_empty)); formOk = false; } if (StringUtils.isBlank(password)) { passwordEditText.setError(getString(R.string.cannot_be_empty)); formOk = false; } if (StringUtils.isBlank(email)) { emailEditText.setError(getString(R.string.cannot_be_empty)); formOk = false; } if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) { emailEditText.setError(getString(R.string.invalid_email)); formOk = false; } if (!formOk) { Log.d(TAG, "Form contains errors."); return; } password = SecurityUtils.hashSHA512Base64(password); User newUser = new User(); newUser.setUsername(username); newUser.setPassword(password); newUser.setEmail(email); tempRestClient = new RestClient(Prefs.getHost(), Prefs.getPort(), Prefs.getWsContextPath(), username, password, Prefs.getRealm()); tempRestClient.registerUser(dialog.getContext(), newUser, new GsonHttpResponseHandler<User>(new TypeToken<User>() { }.getType()) { @Override public void onFailure(int statusCode, Header[] headers, String responseBody, Throwable error) { Log.e(TAG, "Registration failed. [statusCode = " + statusCode + ", error=" + error + "]"); if (statusCode == 0) { Toast.makeText(dialog.getOwnerActivity(), R.string.check_connection, Toast.LENGTH_LONG).show(); ; return; } Toast.makeText(dialog.getContext(), R.string.pick_different_username, Toast.LENGTH_LONG).show(); listener.onRegisterFailure(); } @Override public void onFinish() { positiveButton.setEnabled(true); UiUtilities.fadeInFadeOut(formView, progressView); } @Override public void onStart() { positiveButton.setEnabled(false); UiUtilities.fadeInFadeOut(progressView, formView); } @Override public void onSuccess(int statusCode, Header[] headers, User object) { Log.i(TAG, "Registration succeeded. [statusCode = " + statusCode + "]"); dialog.dismiss(); listener.onRegisterSuccess(); } }); } }); final Button negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE); negativeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (tempRestClient != null) { tempRestClient.cancelRequests(dialog.getOwnerActivity(), true); } dialog.dismiss(); } }); } }); return dialog; }
From source file:com.honestme.animetasteex.login.LoginFragment.java
@Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.rb_login: mLoginButton.setText(R.string.login_login); mPhoneAutoComplete.setVisibility(View.GONE); break;//from w ww. j a v a 2 s .c o m case R.id.rb_create: mLoginButton.setText(R.string.login_register); mPhoneAutoComplete.setVisibility(View.VISIBLE); if (mPhoneAutoComplete.getAdapter() == null) { final Set<String> phoneSet = new HashSet<>(); for (Account account : AccountManager.get(getActivity()).getAccounts()) { if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) { phoneSet.add(account.name); } } List<String> emails = new ArrayList<>(phoneSet); mPhoneAutoComplete.setAdapter( new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item, emails)); } break; } }
From source file:app.philm.in.fragments.LoginFragment.java
@Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.rb_login: mLoginButton.setText(R.string.account_login); mEmailAutoComplete.setVisibility(View.GONE); break;//from ww w. j a va 2 s.co m case R.id.rb_create: mLoginButton.setText(R.string.account_register); mEmailAutoComplete.setVisibility(View.VISIBLE); if (mEmailAutoComplete.getAdapter() == null) { final Set<String> emailSet = new HashSet<>(); for (Account account : AccountManager.get(getActivity()).getAccounts()) { if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) { emailSet.add(account.name); } } List<String> emails = new ArrayList<>(emailSet); mEmailAutoComplete.setAdapter( new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item, emails)); } break; } }
From source file:com.imgtec.hobbyist.fragments.loginsignup.LogInFragment.java
private void initListeners() { new OnTextChangedListener(passwordField) { @Override// ww w . jav a2 s.c o m public void onTextChanged(CharSequence s) { if (isPasswordAndConnectionValid()) { logIn.setEnabled(true); } else { logIn.setEnabled(false); } } }; logIn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (validate()) { if (FlowHelper.isLicenseCorrect()) { showProgress(appContext.getString(R.string.logging_in)); flowLogin(); } else { ActivitiesAndFragmentsHelper.showToast(appContext, R.string.error_invalid_api_key, handler); } } } private boolean validate() { boolean result = true; if (!Patterns.EMAIL_ADDRESS.matcher(emailAddressField.getText().toString()).matches()) { emailAddressField.setError(appContext.getString(R.string.email_address_is_required)); result = false; } else { emailAddressField.setError(null); } final int passLength = passwordField.getText().toString().length(); if (passLength < 5 || passLength > Constants.DEFAULT_MAXIMUM_FIELD_CHARACTERS_COUNT) { passwordField.setError(appContext.getString(R.string.incorrect_password_character_count)); result = false; } else { passwordField.setError(null); } return result; } }); forgotPassword.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.FLOW_FORGOT_PASSWORD_URL))); } }); }