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:com.bcp.bcp.geofencing.GeofenceTransitionsIntentService.java

/**
 * Gets transition details and returns them as a formatted string.
 *
 * @param context               The app context.
 * @param geofenceTransition    The ID of the geofence transition.
 * @param triggeringGeofences   The geofence(s) triggered.
 * @return The transition details formatted as String.
 *///  w w w  . j a  va  2s .  c  o m
private String getGeofenceTransitionDetails(Context context, int geofenceTransition,
        List<Geofence> triggeringGeofences) {

    String geofenceTransitionString = getTransitionString(geofenceTransition);

    // Get the Ids of each geofence that was triggered.
    ArrayList triggeringGeofencesIdsList = new ArrayList();
    for (Geofence geofence : triggeringGeofences) {
        triggeringGeofencesIdsList.add(geofence.getRequestId());
    }
    String triggeringGeofencesIdsString = TextUtils.join(", ", triggeringGeofencesIdsList);
    Date curDate = new Date();
    SimpleDateFormat format = new SimpleDateFormat(Constants.TIME_FORMAT);
    gEntryDate = format.format(curDate);
    boolean isInserted;

    gaddress = triggeringGeofencesIdsList.toString();
    gstatus = geofenceTransitionString;
    String geoFenceDetailString = geofenceTransitionString + ": " + triggeringGeofencesIdsString;

    Pattern gmailPattern = Patterns.EMAIL_ADDRESS;
    Account[] accounts = AccountManager.get(this).getAccounts();

    for (Account account : accounts) {
        if (gmailPattern.matcher(account.name).matches()) {
            gemail = account.name;
        }
    }

    //insert into new fence breach fusion table for each entry exit //no conditions

    //When switch is ON  and we are breaching a fence (entering) we will write that data to FT When switch is ON and we are breaching fence(exiting) we will write that data to FT as well.

    //status:exit
    if (geofenceTransitionString.equalsIgnoreCase("Exited")) {
        if (mPref.getBoolean("SWITCH", false)) {
            //Switch : ON
            //if switch is ON
            String timeValue = mPref.getString("Time_Interval", "60000");
            long configurableTime = Long.parseLong(timeValue);
            mEditor.putLong("CONFIG TIME", configurableTime);
            mEditor.commit();
            Intent intent = new Intent(this, MyLocationService.class);
            startService(intent);
            if (!mPref.getBoolean(geoFenceDetailString, false)) {
                credentials.insertIntoGeoFusionTables(
                        this.saveGeoFile(gaddress, gstatus, gEntryDate, gemail, "geofile"));
            }

        } else {
        }

    } else if (geofenceTransitionString.equalsIgnoreCase("Entered")) {//status :Entry

        if (mPref.getBoolean("SWITCH", false)) {

            if (!mPref.getBoolean(geoFenceDetailString, false)) {
                credentials.insertIntoGeoFusionTables(
                        this.saveGeoFile(gaddress, gstatus, gEntryDate, gemail, "geofile"));
            }

        } else {//Switch : OFF

        }
    }

    if (!mPref.getBoolean(geoFenceDetailString, false)) {
        isInserted = databaseHandler.addFenceTiming(
                new FenceTiming(triggeringGeofencesIdsList.toString(), geofenceTransitionString, gEntryDate));
        if (isInserted) {
            Log.e("GeofenceonsIS : ", "inserted to db");
        }
    }

    return geoFenceDetailString;
}

From source file:com.example.feedback.ActivityFeedback.java

/**
 * Get Google accounts from Android to populate spinner dropdown list.
 * Replace with custom method if application uses non-Google accounts.
 */// w  ww.ja  va 2s. c  om
public void getAccounts() {
    emailPattern = Patterns.EMAIL_ADDRESS;
    accountArray = AccountManager.get(getApplicationContext()).getAccounts();
    accountList = new ArrayList<String>();
    accountList.add(getResources().getString(R.string.feedback_anonymous));

    for (Account accountItem : accountArray) {
        if (emailPattern.matcher(accountItem.name).matches() && accountItem.type.matches("com.google")) {
            accountList.add(accountItem.name);
        }
    }

    accountAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, accountList);
}

From source file:ansteph.com.beecabfordrivers.view.registration.RegistrationFragment.java

private boolean isEmailOk() {
    if (!txtEmail.getText().toString().isEmpty()) {
        return Patterns.EMAIL_ADDRESS.matcher(txtEmail.getText().toString().trim()).matches();
    } else {/*from ww  w. j  a  v  a2 s.  co m*/
        return false;
    }
}

From source file:com.example.android.animationsdemo.FacebookSdkActivity.java

@Override
public void onClick(View view) {
    switch (view.getId()) {
    case R.id.share_button:
        DKLog.d(TAG, Trace.getCurrentMethod() + mAccessToken);
        genAppLink();//ww w  .  j a v a 2s.c  o  m
        break;
    case R.id.checkbutton:
        if (Patterns.EMAIL_ADDRESS.matcher(mEmail.getText()).matches()) {
            Toast.makeText(this, "OK", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(this, "GG", Toast.LENGTH_SHORT).show();
        }
        break;
    case R.id.fb_custom_login:
        String email = "derekchang@gamania.com";
        SharedPrefsData.saveEmail(this, email);
        DKLog.d(TAG, Trace.getCurrentMethod() + Patterns.EMAIL_ADDRESS.matcher(email).matches());
        LoginManager.getInstance().logInWithReadPermissions(this,
                Arrays.asList("public_profile", "user_friends", "user_location", "user_birthday", "user_likes",
                        "publish_actions", "user_photos"));
        LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

            @Override
            public void onSuccess(LoginResult loginResult) {

                mAccessToken = loginResult.getAccessToken();
                DKLog.d(TAG, Trace.getCurrentMethod() + mAccessToken.getPermissions().toString());
                //send request and call graph api
                GraphRequest request = GraphRequest.newMeRequest(mAccessToken,
                        new GraphRequest.GraphJSONObjectCallback() {
                            @Override
                            public void onCompleted(JSONObject object, GraphResponse response) {
                                Log.d(TAG, "name:" + object.optString("name"));
                                Log.d(TAG, "link:" + object.optString("link"));
                                Log.d(TAG, "id:" + object.optString("id"));
                                Log.d(TAG, "Email:" + object.optString("email"));
                                Log.d(TAG, "about:" + object.optString("about"));
                                Log.d(TAG, "birthday:" + object.optString("birthday"));
                            }
                        });

                Bundle parameters = new Bundle();
                parameters.putString("fields", "id, name, email, link, about, birthday");
                request.setParameters(parameters);
                request.executeAsync();
            }

            @Override
            public void onCancel() {
                // App code
                DKLog.e(TAG, Trace.getCurrentMethod() + "CustomLoginButton");
            }

            @Override
            public void onError(FacebookException exception) {
                // App code
                DKLog.e(TAG, Trace.getCurrentMethod() + exception.toString());
            }
        });
        break;
    }
}

From source file:at.software2014.trackme.MainActivity.java

public String getEmailAddress() {
    String emailAddress = "";

    Pattern emailPattern = Patterns.EMAIL_ADDRESS;
    Account[] accounts = AccountManager.get(getBaseContext()).getAccounts();

    for (Account account : accounts) {
        if (emailPattern.matcher(account.name).matches() && account.name.endsWith("gmail.com")) {
            emailAddress = account.name;
            break;
        }/*from w  ww .jav  a 2s  . c om*/
    }

    return emailAddress;
}

From source file:com.jungle.base.utils.MiscUtils.java

public static boolean isEmailAddress(String str) {
    if (TextUtils.isEmpty(str)) {
        return false;
    }//  w ww .  j a v  a 2 s  .  co m

    Matcher matcher = Patterns.EMAIL_ADDRESS.matcher(str);
    return matcher.matches();
}

From source file:it.imwatch.nfclottery.dialogs.InsertContactDialog.java

/**
 * Validates a string as an email address.
 *
 * @param email The email address to validate
 *
 * @return Returns true if the string is a valid email address,
 * false otherwise/*from  w w w .jav  a2s .  c  o  m*/
 */
private static boolean isValidEmailAddress(CharSequence email) {
    return email != null && Patterns.EMAIL_ADDRESS.matcher(email.toString()).matches();
}

From source file:au.com.domain.AccountsAutoCompleteTextView.java

private List<String> getGoogleAccountEmails(Context context) {
    List<String> emails = new ArrayList<>();
    if (isPermissionGranted()) {
        //noinspection MissingPermission isPermission() is doing the check required by lint
        Account[] accounts = AccountManager.get(context).getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
        for (Account account : accounts) {
            if (android.util.Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) {
                emails.add(account.name);
            }/* w w w.  j a  va2 s  .com*/
        }
        Collections.sort(emails, String.CASE_INSENSITIVE_ORDER);
    }
    return emails;
}

From source file:de.da_sense.moses.client.LoginActivity.java

/**
 * This method validates the email provided by the user. It shows the user proper messages,
 * if the entered email is not well formated or missing.
 * @return true if the entered email is well formated.
 *///from  w w w  .j  a  va  2s.c  o  m
private boolean validateEmail() {
    String email = editTextEmail.getText().toString().trim();
    if (email.isEmpty() || !Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
        editTextEmail.setError(getString(R.string.login_hint_bad_email));
        return false;
    }
    return true;
}

From source file:au.com.domain.AccountsAutoCompleteTextView.java

public boolean isEmailValid() {
    final String input = mAccountsAutocomplete.getText().toString();
    return !TextUtils.isEmpty(input) && Patterns.EMAIL_ADDRESS.matcher(input).matches();
}