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.nutsuser.ridersdomain.activities.LiveforDream.java
private boolean validEmail(String email) { Pattern pattern = Patterns.EMAIL_ADDRESS; return pattern.matcher(email).matches(); }
From source file:io.plaidapp.ui.DesignerNewsLogin.java
@SuppressLint("NewApi") private void setupAccountAutocomplete() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS) == PackageManager.PERMISSION_GRANTED) { permissionPrimer.setVisibility(View.GONE); final Account[] accounts = AccountManager.get(this).getAccounts(); final Set<String> emailSet = new HashSet<>(); for (Account account : accounts) { if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) { emailSet.add(account.name); }// www .j ava2 s . c o m } username.setAdapter( new ArrayAdapter<>(this, R.layout.account_dropdown_item, new ArrayList<>(emailSet))); } else { if (shouldShowRequestPermissionRationale(Manifest.permission.GET_ACCOUNTS)) { setupPermissionPrimer(); } else { permissionPrimer.setVisibility(View.GONE); shouldPromptForPermission = true; } } }
From source file:io.plaidapp.ui.DesignerNewsLogin.java
private void setupAccountAutocomplete() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS) == PackageManager.PERMISSION_GRANTED) { permissionPrimer.setVisibility(View.GONE); final Account[] accounts = AccountManager.get(this).getAccounts(); final Set<String> emailSet = new HashSet<>(); for (Account account : accounts) { if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) { emailSet.add(account.name); }/*from www . ja v a2 s .c om*/ } username.setAdapter( new ArrayAdapter<>(this, R.layout.account_dropdown_item, new ArrayList<>(emailSet))); } else { if (shouldShowRequestPermissionRationale(Manifest.permission.GET_ACCOUNTS)) { setupPermissionPrimer(); } else { permissionPrimer.setVisibility(View.GONE); shouldPromptForPermission = true; } } }
From source file:org.linphone.purchase.InAppPurchaseHelper.java
private boolean isEmailCorrect(String email) { Pattern emailPattern = Patterns.EMAIL_ADDRESS; return emailPattern.matcher(email).matches(); }
From source file:dynamite.zafroshops.app.MainActivity.java
public String getEmail() { String email = ""; Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ Account[] accounts = AccountManager.get(this).getAccounts(); for (Account account : accounts) { if (emailPattern.matcher(account.name).matches()) { email = account.name;/* www .j a va 2s . c o m*/ } } return email; }
From source file:com.annanovas.bestprice.DashBoardEditActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dash_board_edit); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);// w w w. j av a 2s .co m ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setHomeButtonEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); } // chosenBrandList.add(new ArrayList<String>()); // chosenBrandList.add(new ArrayList<String>()); // chosenBrandList.add(new ArrayList<String>()); etAddress = (EditText) findViewById(R.id.et_address); etEmail = (EditText) findViewById(R.id.et_email); etShopName = (EditText) findViewById(R.id.et_shop_name); etDrivingLicense = (EditText) findViewById(R.id.et_driving_licence); etNid = (EditText) findViewById(R.id.et_nid); etExperience = (EditText) findViewById(R.id.et_experience); etFirstName = (EditText) findViewById(R.id.et_first_name); etMiddleName = (EditText) findViewById(R.id.et_middle_name); etLastName = (EditText) findViewById(R.id.et_last_name); etPhoneNumber = (EditText) findViewById(R.id.et_phone); tvAddress = (TextView) findViewById(R.id.tv_address); tvArea = (TextView) findViewById(R.id.tv_area); tvDealerShip = (LinearLayout) findViewById(R.id.tv_dealership); tvDealerShipWith = (TextView) findViewById(R.id.tv_dealership_content); tvSelectedProduct = (TextView) findViewById(R.id.tv_select_product_content); tvProduct = (LinearLayout) findViewById(R.id.tv_select_product); buttonSubmit = (Button) findViewById(R.id.button_submit); areaLayout = (LinearLayout) findViewById(R.id.layout_area); brandLayout = (LinearLayout) findViewById(R.id.layout_brand); productLayout = (LinearLayout) findViewById(R.id.layout_product); layoutCamera = (LinearLayout) findViewById(R.id.layout_camera); layoutGallery = (LinearLayout) findViewById(R.id.layout_gallery); userImage = (ImageView) findViewById(R.id.iv_user_image); areaRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_area); brandRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_brand); productRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_product); etProductSearch = (EditText) findViewById(R.id.et_product_name); etBrandSearch = (EditText) findViewById(R.id.et_brand_name); etAreaSearch = (EditText) findViewById(R.id.et_area_name); layoutSearchArea = (LinearLayout) findViewById(R.id.layout_search_area); layoutSearchProduct = (LinearLayout) findViewById(R.id.layout_search_product); layoutSearchBrand = (LinearLayout) findViewById(R.id.layout_search_brand); tvSelectedBrand = (TextView) findViewById(R.id.tv_selected_brand); tvSelectedArea = (TextView) findViewById(R.id.tv_setect_area); ivArrow1 = (ImageView) findViewById(R.id.iv_arrow1); ivArrow2 = (ImageView) findViewById(R.id.iv_arrow2); ivArrow3 = (ImageView) findViewById(R.id.iv_arrow3); ivArrow4 = (ImageView) findViewById(R.id.iv_arrow4); myDB = MyDatabaseManager.getInstance(getApplicationContext()); sharedPreferences = getSharedPreferences(AppGlobal.MY_PREFS_NAME, MODE_PRIVATE); userType = sharedPreferences.getInt("user_type", 1); int imageDimen = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.size_150dp), getResources().getDisplayMetrics()); myDB.open(); Cursor cursor = myDB.getUserInfo(userType, sharedPreferences.getString("user_phone_number", "")); if (userType == AppGlobal.CAR_OWNER) { userImage.setImageResource(R.drawable.ic_car_owner); tvAddress.setVisibility(View.VISIBLE); etAddress.setVisibility(View.VISIBLE); tvArea.setVisibility(View.VISIBLE); areaLayout.setVisibility(View.VISIBLE); if (!cursor.isLast()) { while (cursor.moveToNext()) { etFirstName.setText(cursor.getString(cursor.getColumnIndex("firstname"))); etMiddleName.setText(cursor.getString(cursor.getColumnIndex("middlename"))); etLastName.setText(cursor.getString(cursor.getColumnIndex("lastname"))); if (cursor.getString(cursor.getColumnIndex("address")) != null && !cursor.getString(cursor.getColumnIndex("address")).equals("null")) { etAddress.setText(cursor.getString(cursor.getColumnIndex("address"))); } etPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone"))); etEmail.setText(cursor.getString(cursor.getColumnIndex("email"))); etShopName.setText(cursor.getString(cursor.getColumnIndex("shopname"))); areaId = cursor.getInt(cursor.getColumnIndex("area_id")); if (areaId != 0) { tvSelectedArea.setText(myDB.getAreaName(areaId)); } else { tvSelectedArea.setText(getResources().getString(R.string.select_area)); } if (cursor.getString(cursor.getColumnIndex("image")) != null && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) { Glide.with(getApplicationContext()) .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image"))) .error(R.drawable.ic_supplier).dontAnimate().override(imageDimen, imageDimen) .into(userImage); } else { userImage.setImageResource(R.drawable.ic_car_owner); } } } cursor.close(); generateAreaRecyclerView(); } else if (userType == AppGlobal.SUPPLIER) { tvAddress.setVisibility(View.VISIBLE); etAddress.setVisibility(View.VISIBLE); tvDealerShip.setVisibility(View.VISIBLE); tvProduct.setVisibility(View.VISIBLE); tvArea.setVisibility(View.VISIBLE); brandLayout.setVisibility(View.VISIBLE); productLayout.setVisibility(View.VISIBLE); areaLayout.setVisibility(View.VISIBLE); etShopName.setVisibility(View.VISIBLE); if (!cursor.isLast()) { while (cursor.moveToNext()) { etFirstName.setText(cursor.getString(cursor.getColumnIndex("firstname"))); etMiddleName.setText(cursor.getString(cursor.getColumnIndex("middlename"))); etLastName.setText(cursor.getString(cursor.getColumnIndex("lastname"))); etPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone"))); etEmail.setText(cursor.getString(cursor.getColumnIndex("email"))); etShopName.setText(cursor.getString(cursor.getColumnIndex("shopname"))); etAddress.setText(cursor.getString(cursor.getColumnIndex("address"))); areaId = cursor.getInt(cursor.getColumnIndex("area_id")); if (areaId != 0) { tvSelectedArea.setText(myDB.getAreaName(areaId)); } else { tvSelectedArea.setText(getResources().getString(R.string.select_area)); } selectedProductIdList = myDB.getSelectedProductList(cursor.getInt(cursor.getColumnIndex("id"))); chosenBrandIdList = myDB.getSelectedBrandList(cursor.getInt(cursor.getColumnIndex("id"))); if (cursor.getString(cursor.getColumnIndex("image")) != null && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) { Glide.with(getApplicationContext()) .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image"))) .error(R.drawable.ic_supplier).dontAnimate().override(imageDimen, imageDimen) .into(userImage); } else { userImage.setImageResource(R.drawable.ic_supplier); } } } cursor.close(); generateAreaRecyclerView(); generateProductRecyclerView(); } else if (userType == AppGlobal.DRIVER) { etDrivingLicense.setVisibility(View.VISIBLE); etNid.setVisibility(View.VISIBLE); etExperience.setVisibility(View.VISIBLE); if (!cursor.isLast()) { while (cursor.moveToNext()) { etFirstName.setText(cursor.getString(cursor.getColumnIndex("firstname"))); etMiddleName.setText(cursor.getString(cursor.getColumnIndex("middlename"))); etLastName.setText(cursor.getString(cursor.getColumnIndex("lastname"))); etAddress.setText(cursor.getString(cursor.getColumnIndex("address"))); etPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone"))); etEmail.setText(cursor.getString(cursor.getColumnIndex("email"))); etDrivingLicense.setText(cursor.getString(cursor.getColumnIndex("drivinglicence"))); etNid.setText(cursor.getString(cursor.getColumnIndex("nid"))); etExperience.setText(cursor.getString(cursor.getColumnIndex("yearofexperience"))); if (cursor.getString(cursor.getColumnIndex("image")) != null && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) { Glide.with(getApplicationContext()) .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image"))) .error(R.drawable.ic_supplier).dontAnimate().override(imageDimen, imageDimen) .into(userImage); } else { userImage.setImageResource(R.drawable.ic_car_owner); } } } cursor.close(); } else if (userType == AppGlobal.SHOP_WORKER) { etShopName.setVisibility(View.VISIBLE); etNid.setVisibility(View.VISIBLE); if (!cursor.isLast()) { while (cursor.moveToNext()) { etFirstName.setText(cursor.getString(cursor.getColumnIndex("firstname"))); etMiddleName.setText(cursor.getString(cursor.getColumnIndex("middlename"))); etLastName.setText(cursor.getString(cursor.getColumnIndex("lastname"))); etAddress.setText(cursor.getString(cursor.getColumnIndex("address"))); etPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone"))); etEmail.setText(cursor.getString(cursor.getColumnIndex("email"))); etShopName.setText(cursor.getString(cursor.getColumnIndex("shopname"))); etNid.setText(cursor.getString(cursor.getColumnIndex("nid"))); if (cursor.getString(cursor.getColumnIndex("image")) != null && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) { Glide.with(getApplicationContext()) .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image"))) .error(R.drawable.ic_supplier).dontAnimate().override(imageDimen, imageDimen) .into(userImage); } else { userImage.setImageResource(R.drawable.ic_car_owner); } } } cursor.close(); } myDB.close(); areaLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (layoutSearchArea.getVisibility() == View.GONE) { layoutSearchArea.setVisibility(View.VISIBLE); areaRecyclerView.setVisibility(View.VISIBLE); ivArrow2.setImageDrawable( ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_up_arrow)); } else { layoutSearchArea.setVisibility(View.GONE); areaRecyclerView.setVisibility(View.GONE); ivArrow2.setImageDrawable( ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_down_arrow)); } } }); brandLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (selectedProductIdList.size() == 0) { Toast.makeText(getApplicationContext(), R.string.add_product, Toast.LENGTH_SHORT).show(); return; } if (layoutSearchBrand.getVisibility() == View.GONE) { layoutSearchBrand.setVisibility(View.VISIBLE); brandRecyclerView.setVisibility(View.VISIBLE); ivArrow3.setImageDrawable( ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_up_arrow)); } else { layoutSearchBrand.setVisibility(View.GONE); brandRecyclerView.setVisibility(View.GONE); ivArrow3.setImageDrawable( ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_down_arrow)); } } }); productLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (layoutSearchProduct.getVisibility() == View.GONE) { layoutSearchProduct.setVisibility(View.VISIBLE); productRecyclerView.setVisibility(View.VISIBLE); ivArrow1.setImageDrawable( ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_up_arrow)); } else { layoutSearchProduct.setVisibility(View.GONE); productRecyclerView.setVisibility(View.GONE); ivArrow1.setImageDrawable( ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_down_arrow)); } } }); layoutCamera.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File file = createImageFile(); imageUri = String.valueOf(file); // showLog(imageUri); Uri photoURI = FileProvider.getUriForFile(getApplicationContext(), BuildConfig.APPLICATION_ID + ".provider", file); intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); startActivityForResult(intent, REQUEST_CAMERA); } catch (IOException e) { e.printStackTrace(); } } }); layoutGallery.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); intent.setType("image/*"); startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE); } }); buttonSubmit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { progressDialog = new ProgressDialog(DashBoardEditActivity.this); progressDialog.setMessage(getResources().getString(R.string.please_wait)); progressDialog.setCancelable(false); progressDialog.show(); UpdateUserInfo updateUserInfo = new UpdateUserInfo(getApplicationContext()); updateUserInfo.signUpListener = DashBoardEditActivity.this; //viewEnable(false); if (userType == AppGlobal.CAR_OWNER) { boolean hasError = false; boolean hasPhoneNoError = false; if (etFirstName.getText().length() == 0) { etFirstName.setError(getResources().getString(R.string.enter_first_name)); hasError = true; } if (etLastName.getText().length() == 0) { etLastName.setError(getResources().getString(R.string.enter_last_name)); hasError = true; } if (etPhoneNumber.getText().length() == 0) { etPhoneNumber.setError(getResources().getString(R.string.enter_phone_no)); hasError = true; hasPhoneNoError = true; } if (!hasPhoneNoError && etPhoneNumber.getText().length() != 11) { etPhoneNumber.setError(getResources().getString(R.string.enter_valid_phone_no)); hasError = true; } if (etEmail.getText().length() != 0 && !Patterns.EMAIL_ADDRESS.matcher(etEmail.getText().toString()).matches()) { etEmail.setError(getResources().getString(R.string.enter_valid_email)); hasError = true; } if (etAddress.getText().length() == 0) { etAddress.setError(getResources().getString(R.string.enter_address)); hasError = true; } if (hasError) { if (progressDialog.isShowing()) progressDialog.dismiss(); return; } HashMap<String, String> params = new HashMap<>(); params.put("authentication", AppGlobal.authentication); params.put("api_token", sharedPreferences.getString("api_token", "")); params.put("phone", etPhoneNumber.getText().toString()); params.put("firstname", etFirstName.getText().toString()); if (!etMiddleName.getText().toString().equals("")) { params.put("middlename", etMiddleName.getText().toString()); } params.put("lastname", etLastName.getText().toString()); params.put("district_id", "1"); params.put("area_id", String.valueOf(areaId)); params.put("address", etAddress.getText().toString()); if (!etEmail.getText().toString().equals("")) { params.put("email", etEmail.getText().toString()); } if (!image.equals("")) { params.put("image", image); } updateUserInfo.parseData(params, "updateCarOwnerInfo"); } else if (userType == AppGlobal.SUPPLIER) { boolean hasError = false; boolean hasPhoneNoError = false; if (etFirstName.getText().length() == 0) { etFirstName.setError(getResources().getString(R.string.enter_first_name)); hasError = true; } if (etLastName.getText().length() == 0) { etLastName.setError(getResources().getString(R.string.enter_last_name)); hasError = true; } if (etPhoneNumber.getText().length() == 0) { etPhoneNumber.setError(getResources().getString(R.string.enter_phone_no)); hasError = true; hasPhoneNoError = true; } if (!hasPhoneNoError && etPhoneNumber.getText().length() != 11) { etPhoneNumber.setError(getResources().getString(R.string.enter_valid_phone_no)); hasError = true; } if (etEmail.getText().length() != 0 && !Patterns.EMAIL_ADDRESS.matcher(etEmail.getText().toString()).matches()) { etEmail.setError(getResources().getString(R.string.enter_valid_email)); hasError = true; } if (etShopName.getText().length() == 0) { etShopName.setError(getResources().getString(R.string.enter_shop_name)); hasError = true; } if (etAddress.getText().length() == 0) { etAddress.setError(getResources().getString(R.string.enter_address)); hasError = true; } if (hasError) { if (progressDialog.isShowing()) progressDialog.dismiss(); return; } HashMap<String, String> params = new HashMap<>(); params.put("authentication", AppGlobal.authentication); params.put("api_token", sharedPreferences.getString("api_token", "")); params.put("phone", etPhoneNumber.getText().toString()); params.put("firstname", etFirstName.getText().toString()); if (!etMiddleName.getText().toString().equals("")) { params.put("middlename", etMiddleName.getText().toString()); } params.put("lastname", etLastName.getText().toString()); params.put("district_id", "1"); params.put("area_id", String.valueOf(areaId)); if (!etEmail.getText().toString().equals("")) { params.put("email", etEmail.getText().toString()); } if (!image.equals("")) { params.put("image", image); } params.put("shopname", etShopName.getText().toString()); params.put("address", etAddress.getText().toString()); for (int i = 0; i < selectedProductIdList.size(); i++) { params.put("products[" + i + "]", selectedProductIdList.get(i)); } for (int i = 0; i < chosenBrandIdList.size(); i++) { params.put("brands[" + i + "]", chosenBrandIdList.get(i)); } updateUserInfo.parseData(params, "updateSupplierInfo"); } else if (userType == AppGlobal.DRIVER) { boolean hasError = false; boolean hasPhoneNoError = false; boolean hasDrivingLicenseNoError = false; boolean hasNidNoError = false; if (etFirstName.getText().length() == 0) { etFirstName.setError(getResources().getString(R.string.enter_first_name)); hasError = true; } if (etLastName.getText().length() == 0) { etLastName.setError(getResources().getString(R.string.enter_last_name)); hasError = true; } if (etPhoneNumber.getText().length() == 0) { etPhoneNumber.setError(getResources().getString(R.string.enter_phone_no)); hasError = true; hasPhoneNoError = true; } if (!hasPhoneNoError && etPhoneNumber.getText().length() != 11) { etPhoneNumber.setError(getResources().getString(R.string.enter_valid_phone_no)); hasError = true; } if (etEmail.getText().length() != 0 && !Patterns.EMAIL_ADDRESS.matcher(etEmail.getText().toString()).matches()) { etEmail.setError(getResources().getString(R.string.enter_valid_email)); hasError = true; } if (etDrivingLicense.getText().length() == 0) { etDrivingLicense.setError(getResources().getString(R.string.enter_driving_licence)); hasError = true; hasDrivingLicenseNoError = true; } if (!hasDrivingLicenseNoError && etDrivingLicense.getText().length() != 15) { etDrivingLicense.setError(getResources().getString(R.string.enter_valid_driving_licence)); hasError = true; } if (etNid.getText().length() == 0) { etNid.setError(getResources().getString(R.string.enter_nid_no)); hasError = true; hasNidNoError = true; } if (!hasNidNoError && etNid.getText().length() != 17) { etNid.setError(getResources().getString(R.string.enter_valid_nid)); hasError = true; } if (etExperience.getText().length() == 0) { etExperience.setError(getResources().getString(R.string.enter_year_of_experience)); hasError = true; } if (hasError) { if (progressDialog.isShowing()) progressDialog.dismiss(); return; } HashMap<String, String> params = new HashMap<>(); params.put("authentication", AppGlobal.authentication); params.put("api_token", sharedPreferences.getString("api_token", "")); params.put("phone", etPhoneNumber.getText().toString()); params.put("firstname", etFirstName.getText().toString()); if (!etMiddleName.getText().toString().equals("")) { params.put("middlename", etMiddleName.getText().toString()); } params.put("lastname", etLastName.getText().toString()); params.put("drivinglicence", etDrivingLicense.getText().toString()); params.put("nid", etNid.getText().toString()); params.put("yearofexperience", etExperience.getText().toString()); if (!etEmail.getText().toString().equals("")) { params.put("email", etEmail.getText().toString()); } if (!image.equals("")) { params.put("image", image); } updateUserInfo.parseData(params, "updateDriverInfo"); } else if (userType == AppGlobal.SHOP_WORKER) { boolean hasError = false; boolean hasPhoneNoError = false; if (etFirstName.getText().length() == 0) { etFirstName.setError(getResources().getString(R.string.enter_first_name)); hasError = true; } if (etLastName.getText().length() == 0) { etLastName.setError(getResources().getString(R.string.enter_last_name)); hasError = true; } if (etPhoneNumber.getText().length() == 0) { etPhoneNumber.setError(getResources().getString(R.string.enter_phone_no)); hasError = true; hasPhoneNoError = true; } if (!hasPhoneNoError && etPhoneNumber.getText().length() != 11) { etPhoneNumber.setError(getResources().getString(R.string.enter_valid_phone_no)); hasError = true; } if (etEmail.getText().length() != 0 && !Patterns.EMAIL_ADDRESS.matcher(etEmail.getText().toString()).matches()) { etEmail.setError(getResources().getString(R.string.enter_valid_email)); hasError = true; } if (etNid.getText().length() == 0) { etNid.setError(getResources().getString(R.string.enter_nid_no)); hasError = true; } if (etShopName.getText().length() == 0) { etShopName.setError(getResources().getString(R.string.enter_shop_name)); hasError = true; } if (hasError) { if (progressDialog.isShowing()) progressDialog.dismiss(); return; } HashMap<String, String> params = new HashMap<>(); params.put("authentication", AppGlobal.authentication); params.put("api_token", sharedPreferences.getString("api_token", "")); params.put("phone", etPhoneNumber.getText().toString()); params.put("firstname", etFirstName.getText().toString()); if (!etMiddleName.getText().toString().equals("")) { params.put("middlename", etMiddleName.getText().toString()); } params.put("lastname", etLastName.getText().toString()); params.put("nid", etNid.getText().toString()); params.put("shopname", etShopName.getText().toString()); if (!etEmail.getText().toString().equals("")) { params.put("email", etEmail.getText().toString()); } if (!image.equals("")) { params.put("image", image); } updateUserInfo.parseData(params, "updateWorkerInfo"); } } }); }
From source file:com.pdftron.pdf.tools.Tool.java
protected void setAuthor(Markup annot) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(mPDFView.getContext()); boolean authorNameHasBeenAsked = pref.getBoolean("pref_author_name_has_been_asked", false); String authorName = pref.getString("pref_author_name", ""); if (!authorNameHasBeenAsked && authorName.isEmpty()) { // Show dialog to get the author name. boolean askAuthor = false; if (mPDFView.getToolManager() instanceof ToolManager) { if (((ToolManager) mPDFView.getToolManager()).isShowAuthorDialog()) { askAuthor = true;//from w ww . j a va2 s . c o m } } mMarkupToAuthor = annot; String possibleName = ""; // If the author name in the preferences is empty, we try to get // the name of the current user in the device. int res = mPDFView.getContext().checkCallingOrSelfPermission("android.permission.GET_ACCOUNTS"); if (res == PackageManager.PERMISSION_GRANTED) { Pattern emailPattern = Patterns.EMAIL_ADDRESS; //Account[] accounts = AccountManager.get(mPDFView.getContext()).getAccounts(); // for (Account account : accounts) { // if (emailPattern.matcher(account.name).matches()) { // possibleName = account.name; // break; // } // } } final SharedPreferences.Editor editor = pref.edit(); editor.putBoolean("pref_author_name_has_been_asked", true); editor.commit(); if (askAuthor) { LayoutInflater inflater = (LayoutInflater) mPDFView.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View authorNameDialog = inflater.inflate(R.layout.tools_dialog_author_name, null); final EditText authorNameEditText = (EditText) authorNameDialog .findViewById(R.id.tools_dialog_author_name_edittext); authorNameEditText.setText(possibleName); authorNameEditText.selectAll(); AlertDialog.Builder builder = new AlertDialog.Builder(mPDFView.getContext()); final AlertDialog authorDialog = builder.setView(authorNameDialog) .setTitle(R.string.tools_dialog_author_name_title) .setPositiveButton(R.string.tools_misc_ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String author = authorNameEditText.getText().toString().trim(); // Set author information on the markup setAuthor(mMarkupToAuthor, author); // Update preferences with the new name //SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(mPDFView.getContext()).edit(); editor.putString("pref_author_name", author); editor.commit(); } }).setNegativeButton(R.string.tools_misc_skip, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).create(); authorDialog.show(); if (authorNameEditText.getText().length() == 0) { // empty, don't allow OK authorDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false); } else { authorDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true); } authorNameEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (authorDialog != null) { if (s.length() == 0) { // empty, don't allow OK authorDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false); } else { authorDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true); } } } }); } else { // Set author information on the markup setAuthor(mMarkupToAuthor, possibleName); // Update preferences with the new name //SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(mPDFView.getContext()).edit(); editor.putString("pref_author_name", possibleName); editor.commit(); } } else { // Use author name in the preferences String author = pref.getString("pref_author_name", ""); setAuthor(annot, author); } }
From source file:org.thoughtland.xlocation.ActivityShare.java
@SuppressLint("InflateParams") public static boolean registerDevice(final ActivityBase context) { int userId = Util.getUserId(Process.myUid()); if (Util.hasProLicense(context) == null && !PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingRegistered, false)) { // Get accounts String email = null;//from ww w. j a v a 2 s . c o m for (Account account : AccountManager.get(context).getAccounts()) if ("com.google".equals(account.type)) { email = account.name; break; } LayoutInflater LayoutInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = LayoutInflater.inflate(R.layout.register, null); final EditText input = (EditText) view.findViewById(R.id.etEmail); if (email != null) input.setText(email); // Build dialog AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); alertDialogBuilder.setTitle(R.string.msg_register); alertDialogBuilder.setIcon(context.getThemed(R.attr.icon_launcher)); alertDialogBuilder.setView(view); alertDialogBuilder.setPositiveButton(context.getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String email = input.getText().toString(); if (Patterns.EMAIL_ADDRESS.matcher(email).matches()) new RegisterTask(context).executeOnExecutor(mExecutor, email); } }); alertDialogBuilder.setNegativeButton(context.getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Do nothing } }); // Show dialog AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); return false; } return true; }