Example usage for android.util Patterns EMAIL_ADDRESS

List of usage examples for android.util Patterns EMAIL_ADDRESS

Introduction

In this page you can find the example usage for android.util Patterns EMAIL_ADDRESS.

Prototype

Pattern EMAIL_ADDRESS

To view the source code for android.util Patterns EMAIL_ADDRESS.

Click Source Link

Usage

From source file:dam.isi.frsf.utn.edu.ar.lab01c2016.MainActivity.java

private boolean validarEmail(String s) {
    return !TextUtils.isEmpty(s) && Patterns.EMAIL_ADDRESS.matcher(s).matches();
}

From source file:org.sufficientlysecure.keychain.util.ContactHelper.java

public List<String> getPossibleUserEmails() {
    Set<String> accountMails = getAccountEmails();
    accountMails.addAll(getMainProfileContactEmails());

    // remove items that are not an email
    Iterator<String> it = accountMails.iterator();
    while (it.hasNext()) {
        String email = it.next();
        Matcher emailMatcher = Patterns.EMAIL_ADDRESS.matcher(email);
        if (!emailMatcher.matches()) {
            it.remove();//from  w w  w.ja  va 2 s .c o  m
        }
    }

    // now return the Set (without duplicates) as a List
    return new ArrayList<>(accountMails);
}

From source file:es.hol.ecotiffins.view.LoginActivity.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.btnNext:
        //Validating user to fill the required field & entered number should be in four digits
        //If user satisfies the conditions, we will register the license number
        //Otherwise set error to TextInputLayout
        if (Patterns.EMAIL_ADDRESS.matcher(editEmail.getText().toString().trim()).matches()) {
            //Setting up animation to view flipper and moving to the next state
            viewFlipper.setInAnimation(LoginActivity.this, R.anim.slide_in_from_right);
            viewFlipper.setOutAnimation(LoginActivity.this, R.anim.slide_out_to_left);
            viewFlipper.showNext();/*from  w  w w  .j  a  va 2  s.com*/
            ((TextView) findViewById(R.id.txtEmailAddress)).setText(editEmail.getText().toString());
        } else {
            setValidationError(findViewById(R.id.txtInputLayoutEmail),
                    getResources().getString(R.string.error_email));
        }
        break;

    case R.id.btnLogin:
        if (editPassword.getText().toString().trim().equals("")) {
            setValidationError(findViewById(R.id.txtInputLayoutPassword),
                    getResources().getString(R.string.error_password));
        } else if (editPassword.getText().toString().trim().length() < 6) {
            setValidationError(findViewById(R.id.txtInputLayoutPassword),
                    getResources().getString(R.string.error_password_min_lenth));
        } else {
            loginUser();
        }
        break;
    case R.id.imgBack:
        //Setting up animation to view flipper
        viewFlipper.setInAnimation(LoginActivity.this, R.anim.slide_in_from_left);
        viewFlipper.setOutAnimation(LoginActivity.this, R.anim.slide_out_to_right);
        viewFlipper.showPrevious();
        break;

    case R.id.txtRegister:
        startActivity(new Intent(this, RegisterActivity.class));
        break;
    case R.id.txtForget:
        Intent intent = new Intent(LoginActivity.this, ForgetPasswordActivity.class);
        intent.putExtra("EMAIL", editEmail.getText().toString());
        startActivity(intent);
        break;
    }
}

From source file:com.fizz.StickyFragment.java

private void getNameNumber() {
    TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
    number = tm.getLine1Number();

    Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
    Account[] accounts = AccountManager.get(getActivity()).getAccounts();
    for (Account account : accounts) {
        if (emailPattern.matcher(account.name).matches()) {
            name = account.name;// w  w  w  .j  av  a 2  s  .  c om
        }
    }
}

From source file:org.sufficientlysecure.keychain.util.ContactHelper.java

public List<String> getPossibleUserNames() {
    Set<String> accountMails = getAccountEmails();
    Set<String> names = getContactNamesFromEmails(accountMails);
    names.addAll(getMainProfileContactName());

    // remove items that are an email
    Iterator<String> it = names.iterator();
    while (it.hasNext()) {
        String email = it.next();
        Matcher emailMatcher = Patterns.EMAIL_ADDRESS.matcher(email);
        if (emailMatcher.matches()) {
            it.remove();//from   www. ja  v a  2 s .c  om
        }
    }

    return new ArrayList<>(names);
}

From source file:org.sufficientlysecure.keychain.ui.CreateKeyInputFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.create_key_input_fragment, container, false);

    mNameEdit = (AutoCompleteTextView) view.findViewById(R.id.create_key_name);
    mEmailEdit = (AutoCompleteTextView) view.findViewById(R.id.create_key_email);
    mPassphraseEdit = (EditText) view.findViewById(R.id.create_key_passphrase);
    mPassphraseEditAgain = (EditText) view.findViewById(R.id.create_key_passphrase_again);
    mCreateButton = view.findViewById(R.id.create_key_button);

    // initial values
    String name = getArguments().getString(ARG_NAME);
    String email = getArguments().getString(ARG_EMAIL);
    mNameEdit.setText(name);// w w  w . j a va  2 s .  c om
    mEmailEdit.setText(email);

    // focus non-empty edit fields
    if (name != null && email != null) {
        mPassphraseEdit.requestFocus();
    } else if (name != null) {
        mEmailEdit.requestFocus();
    }

    mEmailEdit.setThreshold(1); // Start working from first character
    mEmailEdit.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item,
            ContactHelper.getPossibleUserEmails(getActivity())));
    mEmailEdit.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            String email = editable.toString();
            if (email.length() > 0) {
                Matcher emailMatcher = Patterns.EMAIL_ADDRESS.matcher(email);
                if (emailMatcher.matches()) {
                    mEmailEdit.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.uid_mail_ok, 0);
                } else {
                    mEmailEdit.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.uid_mail_bad, 0);
                }
            } else {
                // remove drawable if email is empty
                mEmailEdit.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
            }
        }
    });

    mNameEdit.setThreshold(1); // Start working from first character
    mNameEdit.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item,
            ContactHelper.getPossibleUserNames(getActivity())));

    mCreateButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            createKeyCheck();
        }
    });

    return view;
}

From source file:de.tu_berlin.snet.commstat.EmailFragment.java

private void loadAccounts() {
    String accounts = prefs.getString("accounts", null);

    if (accounts != null) {
        list = new ArrayList<String>(Arrays.asList(accounts.split(";")));
    } else {/*from  w w  w .j a  v  a 2  s  .  c  om*/
        Set<String> set = new HashSet<String>();

        for (Account acc : AccountManager.get(getActivity()).getAccounts()) {
            if (Patterns.EMAIL_ADDRESS.matcher(acc.name).matches())
                set.add(acc.name);
        }
        list = new ArrayList<String>(set);
        saveAccounts();
    }
}

From source file:id.satusatudua.sigap.ui.AddTrustedUserActivity.java

@OnClick(R.id.button_add_contact)
public void addTrustedUser() {
    String email = this.email.getText().toString();

    if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
        this.email.setError("Mohon masukan alamat email yang valid!");
    } else if (email.equalsIgnoreCase(CacheManager.pluck().getCurrentUser().getEmail())) {
        this.email.setError("Mohon masukan alamat email selain email anda sendiri!");
    } else {// ww w  . j a v  a2 s.com
        presenter.searchUser(email);
        KeyboardUtil.hideKeyboard(this, this.email);
        this.email.setText("");
    }
}

From source file:com.battlelancer.seriesguide.ui.ConnectTraktCredentialsFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    setupViews();/*  w  ww  .  j av  a  2 s  .co  m*/

    // unfinished task around?
    if (mTask != null && mTask.getStatus() != AsyncTask.Status.FINISHED) {
        // disable buttons, show status message
        setButtonStates(false, false);
        setStatus(true, true, R.string.waitplease);
    }

    // enable e-mail completion via device accounts
    final Account[] accounts = AccountManager.get(getActivity()).getAccounts();
    final Set<String> emailSet = new HashSet<>();
    for (Account account : accounts) {
        if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) {
            emailSet.add(account.name);
        }
    }
    List<String> emails = new ArrayList<>(emailSet);
    mEmailAutoCompleteView.setAdapter(
            new ArrayAdapter<String>(getActivity(), android.R.layout.simple_dropdown_item_1line, emails));

    // connect button
    mButtonConnect.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // disable buttons, show status message
            setButtonStates(false, false);
            setStatus(true, true, R.string.waitplease);

            // get username and password
            Editable editableUsername = mEditTextUsername.getText();
            String username = editableUsername != null ? editableUsername.toString().trim() : null;
            Editable editablePassword = mEditTextPassword.getText();
            String password = editablePassword != null ? editablePassword.toString().trim() : null;

            // get email
            String email = null;
            if (mCheckBoxNewAccount.isChecked()) {
                Editable editableEmail = mEmailAutoCompleteView.getText();
                email = editableEmail != null ? editableEmail.toString().trim() : null;
            }

            mTask = new ConnectTraktTask(getActivity().getApplicationContext(),
                    ConnectTraktCredentialsFragment.this);
            mTask.execute(username, password, email);
        }
    });

    // disconnect button
    mButtonDisconnect.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO do this async
            TraktCredentials.get(getActivity()).removeCredentials();
            setupViews();
        }
    });
}

From source file:com.android.shell.BugreportReceiver.java

/**
 * Find the best matching {@link Account} based on build properties.
 *///from  w ww.j a va 2  s . c o  m
private static Account findSendToAccount(Context context) {
    final AccountManager am = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);

    String preferredDomain = SystemProperties.get("sendbug.preferred.domain");
    if (!preferredDomain.startsWith("@")) {
        preferredDomain = "@" + preferredDomain;
    }

    final Account[] accounts = am.getAccounts();
    Account foundAccount = null;
    for (Account account : accounts) {
        if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) {
            if (!preferredDomain.isEmpty()) {
                // if we have a preferred domain and it matches, return; otherwise keep
                // looking
                if (account.name.endsWith(preferredDomain)) {
                    return account;
                } else {
                    foundAccount = account;
                }
                // if we don't have a preferred domain, just return since it looks like
                // an email address
            } else {
                return account;
            }
        }
    }
    return foundAccount;
}