本文整理汇总了Java中android.util.Patterns类的典型用法代码示例。如果您正苦于以下问题:Java Patterns类的具体用法?Java Patterns怎么用?Java Patterns使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Patterns类属于android.util包,在下文中一共展示了Patterns类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onClick
import android.util.Patterns; //导入依赖的package包/类
@Override
public void onClick(View widget) {
try {
Intent intent = new Intent();
Uri uri;
if (Patterns.WEB_URL.matcher(clickUrl).find()) {
uri = Uri.parse(CustomTextView.makeWebUrl(clickUrl));
} else {
uri = Uri.parse(clickUrl);
}
intent.setAction(Intent.ACTION_VIEW);
intent.setData(uri);
if (Utils.isIntentAvailable(mContext, intent))
mContext.startActivity(intent);
else
Toast.makeText(mContext, mContext.getString(R.string.kf5_no_file_found_hint), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: toNumberStringArray
import android.util.Patterns; //导入依赖的package包/类
public @NonNull String[] toNumberStringArray(boolean scrub) {
String[] recipientsArray = new String[recipients.size()];
Iterator<Recipient> iterator = recipients.iterator();
int i = 0;
while (iterator.hasNext()) {
String number = iterator.next().getNumber();
if (scrub && number != null &&
!Patterns.EMAIL_ADDRESS.matcher(number).matches() &&
!GroupUtil.isEncodedGroup(number))
{
number = number.replaceAll("[^0-9+]", "");
}
recipientsArray[i++] = number;
}
return recipientsArray;
}
示例3: validLoginFields
import android.util.Patterns; //导入依赖的package包/类
/**
* Check if the email and password are valid before login in
* @return a boolean indicating if the login/password are in valid state
*/
private boolean validLoginFields() {
String email = mEmailAutoComplete.getText().toString();
String password = mPasswordEditText.getText().toString();
Boolean validFields = true;
if (TextUtils.isEmpty(email) ||
!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
validFields = false;
mEmailAutoComplete.setError(getString(R.string.invalid_email_error));
}
if (TextUtils.isEmpty(password)) {
validFields = false;
mPasswordEditText.setError(getString(R.string.empty_password_error));
}
return validFields;
}
示例4: getUserEmail
import android.util.Patterns; //导入依赖的package包/类
private ArrayList<String> getUserEmail(){
ArrayList<String> email = new ArrayList<String>();
Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
Account[] accounts = AccountManager.get(VerifyOTP.this).getAccounts();
for (Account account : accounts) {
if (emailPattern.matcher(account.name).matches()) {
String possibleEmail = account.name;
if(possibleEmail != null)
if(possibleEmail.length() !=0 ){
email.add(possibleEmail);
}
}
}
return email;
}
示例5: validateInput
import android.util.Patterns; //导入依赖的package包/类
private boolean validateInput(String email, String userName, String password) {
if (email.isEmpty()) {
mEmail.setError(getString(R.string.text_email_cannot_be_empty));
return false;
}
if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
mEmail.setError(getString(R.string.text_email_format_error));
return false;
}
if (userName.isEmpty()) {
mUserName.setError(getString(R.string.text_username_cannot_be_empty));
return false;
}
if (password.isEmpty()) {
mUserName.setError(getString(R.string.text_password_cannot_be_empty));
return false;
}
if (password.length() < 6) {
mPassword.setError(getString(R.string.nodebb_error_change_password_error_length));
return false;
}
return true;
}
示例6: checkValues
import android.util.Patterns; //导入依赖的package包/类
private boolean checkValues() {
if(mAddress.getText() == null || !Patterns.WEB_URL.matcher(mAddress.getText()).matches()) {
Toast.makeText(getActivity(), getResources().getString(R.string.fragment_widget_configure_err_address), Toast.LENGTH_SHORT).show();
return false;
}
if(mInterval.getValue() == null) {
Toast.makeText(getActivity(), getResources().getString(R.string.fragment_widget_configure_err_interval), Toast.LENGTH_SHORT).show();
return false;
}
if(mMaxPings.getValue() == null) {
Toast.makeText(getActivity(), getResources().getString(R.string.fragment_widget_configure_err_max_pings), Toast.LENGTH_SHORT).show();
return false;
}
return true;
}
示例7: onClick
import android.util.Patterns; //导入依赖的package包/类
@Override
public void onClick(View v) {
int id = v.getId();
switch(id) {
case R.id.dialog_edit_link_attachment_cancel:
//Hide keyboard
((InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(mLink.getWindowToken(), 0);
dismiss();
break;
case R.id.dialog_edit_link_attachment_ok:
String link = mLink.getText().toString().trim();
if(!link.isEmpty() && Patterns.WEB_URL.matcher(link).matches()) {
mListener.onFinishEditLinkAttachmentDialog(mLink.getText().toString());
//Hide keyboard
((InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(mLink.getWindowToken(), 0);
dismiss();
} else {
Toast.makeText(getActivity(), getResources().getString(R.string.dialog_edit_link_error_empty_text), Toast.LENGTH_SHORT).show();
}
break;
}
}
示例8: actionsToResults
import android.util.Patterns; //导入依赖的package包/类
@Override
protected ObservableTransformer<Action, Result> actionsToResults() {
return upstream -> upstream.ofType(EmailRegisterActions.EmailRegister.class)
.flatMap(action -> {
if (!Patterns.EMAIL_ADDRESS.matcher(action.getEmail()).matches()) {
return Observable.just(Result.<Boolean, EmailRegisterActions.EmailRegister>error(action, new FormValidationException("Must enter a valid email address!")));
}
if (!Pattern.compile("[0-9a-zA-Z]{6,}").matcher(action.getPassword()).matches()) {
return Observable.just(Result.<Boolean, EmailRegisterActions.EmailRegister>error(action, new FormValidationException("Password must be at least 6 characters long!")));
}
if (!TextUtils.equals(action.getPassword(), action.getPasswordConfirm())) {
return Observable.just(Result.<Boolean, EmailRegisterActions.EmailRegister>error(action, new FormValidationException("Passwords don't match!")));
}
return useCase.performAction(action)
.onErrorReturn(throwable -> Result.error(action, throwable))
.startWith(Result.<Boolean, EmailRegisterActions.EmailRegister>loading(action));
})
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io());
}
示例9: validate
import android.util.Patterns; //导入依赖的package包/类
private void validate() {
mUserName = mInputName.getText().toString().trim();
mEmali = mInputEmali.getText().toString().trim();
mPwd = mInputPwd.getText().toString().trim();
if (TextUtils.isEmpty(mUserName) || mUserName.length() < 3) {
mNameLayout.setError("至少3个字符");
} else {
mNameLayout.setError(null);
}
if (TextUtils.isEmpty(mEmali) || !Patterns.EMAIL_ADDRESS.matcher(mEmali).matches()) {
mEmailLayout.setError("请输入合法的电子邮箱");
} else {
mEmailLayout.setError(null);
}
if (TextUtils.isEmpty(mPwd) || mPwd.length() < 6 || mPwd.length() > 10) {
mPwdLayout.setError("密码长度在6到10位之间");
} else {
mPwdLayout.setError(null);
}
}
示例10: validate
import android.util.Patterns; //导入依赖的package包/类
private boolean validate() {
KLog.d("Login....");
boolean valid = true;
String email = _emailText.getText().toString();
String password = _passwordText.getText().toString();
//这是一个正则表达式
if (email.isEmpty() || !Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
_emailText.setError("enter a valid email address");
valid = false;
} else {
_emailText.setError(null);
}
if (password.isEmpty() || password.length() < 6) {
_passwordText.setError("the password length must be greater than six");
valid = false;
} else {
_passwordText.setError(null);
}
return valid;
}
示例11: checkURL
import android.util.Patterns; //导入依赖的package包/类
public static boolean checkURL(CharSequence input) {
if (TextUtils.isEmpty(input)) {
return false;
}
Pattern URL_PATTERN = Patterns.WEB_URL;
boolean isURL = URL_PATTERN.matcher(input).matches();
if (!isURL) {
String urlString = input + "";
if (URLUtil.isNetworkUrl(urlString)) {
try {
new URL(urlString);
isURL = true;
} catch (Exception e) {
}
}
}
return isURL;
}
示例12: showNotificationMessage
import android.util.Patterns; //导入依赖的package包/类
public void showNotificationMessage(final String title, final String message, final String timeStamp, Intent intent, String imageUrl) {
if (TextUtils.isEmpty(message))
return;
final int icon = R.drawable.logo;
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
final PendingIntent resultPendingIntent = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext);
if (!TextUtils.isEmpty(imageUrl)) {
if (imageUrl != null && imageUrl.length() > 4 && Patterns.WEB_URL.matcher(imageUrl).matches()) {
Bitmap bitmap = getBitmapFromURL(imageUrl);
if (bitmap != null) {
showBigNotification(bitmap, mBuilder, icon, title, message, timeStamp, resultPendingIntent);
} else {
showSmallNotification(mBuilder, icon, title, message, timeStamp, resultPendingIntent);
}
}
} else {
showSmallNotification(mBuilder, icon, title, message, timeStamp, resultPendingIntent);
}
}
示例13: setIntentFicUrl
import android.util.Patterns; //导入依赖的package包/类
private void setIntentFicUrl() {
ficUrl = "";
Intent intent = getIntent();
if (intent != null) {
String intentType = intent.getType();
String intentAction = intent.getAction();
Log.d("ficsaveM/intentReceived", intentAction + " " + intent.toString());
if (Intent.ACTION_SEND.equals(intentAction) && intentType != null && "text/plain".equals(intentType)) {
Matcher m = Patterns.WEB_URL.matcher(intent.getStringExtra(Intent.EXTRA_TEXT));
while (m.find()) {
String url = m.group();
ficUrl = url;
Log.d("ficsaveM/setIntFicUrl", "URL extracted: " + url);
mGTracker.send(new HitBuilders.EventBuilder()
.setCategory(MAIN_PAGE_CATEGORY)
.setAction("Fic Url Set")
.setLabel(URL_LABEL + ficUrl)
.setValue(1)
.build());
Bundle bundle = new Bundle();
bundle.putString("Url", ficUrl);
mFTracker.logEvent("FicUrlSet", bundle);
}
}
}
}
示例14: sendVerificationClicked
import android.util.Patterns; //导入依赖的package包/类
@Override
public void sendVerificationClicked() {
showLog("CLICKED");
String email = view.getEmail();
if(email.isEmpty()){
view.setEmailError();
return;
}
if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
view.clearCurrentEmailText();
view.setEmailError();
return;
}
// show a progress dialog
view.showProgress();
Worker.sendEmailVerification(this, email);
view.clearCurrentEmailText();
}
示例15: loginClicked
import android.util.Patterns; //导入依赖的package包/类
@Override
public void loginClicked() {
String email = view.getEmail();
String password = view.getPassword();
if (TextUtils.isEmpty(email)) {
view.setEmailError(R.string.empty_email);
return;
}
if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
view.setEmailError(R.string.incorrect_email);
return;
}
if (TextUtils.isEmpty(password)) {
view.setPasswordError(R.string.empty_password);
return;
}
view.showProgressDialog();
usersRepository.login(email, password, this);
}