Java Code Examples for android.util.Patterns

The following are top voted examples for showing how to use android.util.Patterns. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: yyox   File: CustomClickSpan.java   View source code 6 votes vote down vote up
@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();
    }
}
 
Example 2
Project: PeSanKita-android   File: Recipients.java   View source code 6 votes vote down vote up
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;
}
 
Example 3
Project: cda-app   File: LoginActivity.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 4
Project: XERUNG   File: VerifyOTP.java   View source code 6 votes vote down vote up
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;

	}
 
Example 5
Project: XERUNG   File: VerifyOTP.java   View source code 6 votes vote down vote up
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;

	}
 
Example 6
Project: Auto.js   File: RegisterActivity.java   View source code 6 votes vote down vote up
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;
}
 
Example 7
Project: PingWidget   File: PingWidgetConfigureFragment.java   View source code 6 votes vote down vote up
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;
}
 
Example 8
Project: Remindy   File: EditLinkAttachmentDialogFragment.java   View source code 6 votes vote down vote up
@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;
    }
}
 
Example 9
Project: cleanarchitecture-unidirectional   File: EmailRegisterPresenter.java   View source code 6 votes vote down vote up
@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());
}
 
Example 10
Project: android-study   File: TextInputActivity.java   View source code 6 votes vote down vote up
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);
  }
}
 
Example 11
Project: AmenEye   File: LoginActivity.java   View source code 6 votes vote down vote up
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;
}
 
Example 12
Project: VideoDownloader-Android   File: iUtils.java   View source code 6 votes vote down vote up
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;
}
 
Example 13
Project: Tech-Jalsa   File: NotificationUtils.java   View source code 6 votes vote down vote up
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);
    }
}
 
Example 14
Project: FicsaveMiddleware   File: MainActivity.java   View source code 6 votes vote down vote up
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);
            }

        }
    }
}
 
Example 15
Project: Programmers   File: Presenter.java   View source code 6 votes vote down vote up
@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();
}
 
Example 16
Project: Programmers   File: Presenter.java   View source code 6 votes vote down vote up
@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);
}
 
Example 17
Project: Xndroid   File: UrlUtils.java   View source code 5 votes vote down vote up
/**
 * Attempts to determine whether user input is a URL or search
 * terms.  Anything with a space is passed to search if canBeSearch is true.
 * <p/>
 * Converts to lowercase any mistakenly uppercased schema (i.e.,
 * "Http://" converts to "http://"
 *
 * @param canBeSearch If true, will return a search url if it isn't a valid
 *                    URL. If false, invalid URLs will return null
 * @return Original or modified URL
 */
@NonNull
public static String smartUrlFilter(@NonNull String url, boolean canBeSearch, String searchUrl) {
    String inUrl = url.trim();
    boolean hasSpace = inUrl.indexOf(' ') != -1;
    Matcher matcher = ACCEPTED_URI_SCHEMA.matcher(inUrl);
    if (matcher.matches()) {
        // force scheme to lowercase
        String scheme = matcher.group(1);
        String lcScheme = scheme.toLowerCase();
        if (!lcScheme.equals(scheme)) {
            inUrl = lcScheme + matcher.group(2);
        }
        if (hasSpace && Patterns.WEB_URL.matcher(inUrl).matches()) {
            inUrl = inUrl.replace(" ", "%20");
        }
        return inUrl;
    }
    if (!hasSpace) {
        if (Patterns.WEB_URL.matcher(inUrl).matches()) {
            return URLUtil.guessUrl(inUrl);
        }
    }
    if (canBeSearch) {
        return URLUtil.composeSearchUrl(inUrl,
            searchUrl, QUERY_PLACE_HOLDER);
    }
    return "";
}
 
Example 18
Project: SimpleUILauncher   File: AutoInstallsLayout.java   View source code 5 votes vote down vote up
protected Intent parseIntent(XmlResourceParser parser) {
    final String url = getAttributeValue(parser, ATTR_URL);
    if (TextUtils.isEmpty(url) || !Patterns.WEB_URL.matcher(url).matches()) {
        if (LOGD) Log.d(TAG, "Ignoring shortcut, invalid url: " + url);
        return null;
    }
    return new Intent(Intent.ACTION_VIEW, null).setData(Uri.parse(url));
}
 
Example 19
Project: LaunchEnr   File: AutoInstallsLayout.java   View source code 5 votes vote down vote up
protected Intent parseIntent(XmlResourceParser parser) {
    final String url = getAttributeValue(parser, ATTR_URL);
    if (TextUtils.isEmpty(url) || !Patterns.WEB_URL.matcher(url).matches()) {
        return null;
    }
    return new Intent(Intent.ACTION_VIEW, null).setData(Uri.parse(url));
}
 
Example 20
Project: RippleValidatorEditText   File: RVEValidatorFactory.java   View source code 5 votes vote down vote up
private static RVEValidator PhoneNumberChecker(String error){
  return new RVEValidator(error) {
    @Override public boolean isValid(@NonNull CharSequence text) {
      Boolean isNumber= Patterns.PHONE.matcher(text).matches();
      if(!isNumber) {
        return false;
      }
      return true;
    }
  };
}
 
Example 21
Project: Tusky   File: StringUtils.java   View source code 5 votes vote down vote up
static List<String> extractUrl(String text) {
    List<String> links = new ArrayList<>();
    Matcher m = Patterns.WEB_URL.matcher(text);
    while (m.find()) {
        String url = m.group();
        links.add(url);
    }
    return links;
}
 
Example 22
Project: Rx_java2_soussidev   File: RxTextInputLayout.java   View source code 5 votes vote down vote up
/**
 * @author Soussi
 *
 * @param email
 * Function Checks for validity Email and return true or false
 */

private static boolean validateEmail(String email) {
    Pattern patternEmail = Patterns.EMAIL_ADDRESS;
    if (TextUtils.isEmpty(email))
        return false;

    matcher = patternEmail.matcher(email);
    return matcher.matches();
}
 
Example 23
Project: Rx_java2_soussidev   File: RxTextInputLayout.java   View source code 5 votes vote down vote up
/**
 * @author Soussi
 *
 * @param phone
 * Function Checks for validity Phone and return true or false
 */
private static boolean validatePhone(String phone) {
    Pattern patternEmail = Patterns.PHONE;
    if (TextUtils.isEmpty(phone))
        return false;

    matcher = patternEmail.matcher(phone);
    return matcher.matches();
}
 
Example 24
Project: Rx_java2_soussidev   File: RxTextInputLayout.java   View source code 5 votes vote down vote up
/**
 * @author Soussi
 *
 * @param url
 * Function Checks for validity Url Web and return true or false
 */

private static boolean validateWeb(String url) {
    Pattern patternEmail = Patterns.WEB_URL;
    if (TextUtils.isEmpty(url))
        return false;

    matcher = patternEmail.matcher(url);
    return matcher.matches();
}
 
Example 25
Project: Rx_java2_soussidev   File: RxTextInputLayout.java   View source code 5 votes vote down vote up
/**
 * @author Soussi
 *
 * @param ip
 * Function Checks for validity IP Adresse and return true or false
 */

private static boolean validateIP(String ip) {
    Pattern patternEmail = Patterns.IP_ADDRESS;
    if (TextUtils.isEmpty(ip))
        return false;

    matcher = patternEmail.matcher(ip);
    return matcher.matches();
}
 
Example 26
Project: QRCodeScanner   File: BarcodeScanActivity.java   View source code 5 votes vote down vote up
private void handleDecodeResult(int type, Result result) {
    if (Patterns.WEB_URL.matcher(result.getText().trim()).matches()) {
        loadUrl(result);
    } else {
        Intent intent = new Intent(this, TextScanResultActivity.class);
        intent.putExtra(TextScanResultActivity.KEY_TEXT, result.getText());
        startActivityForResult(intent, TEXT_REQUESTCODE);
    }
}
 
Example 27
Project: Trackr   File: LoginActivity.java   View source code 5 votes vote down vote up
public boolean validate() {
    //fetch data into corresponding strings to validate
    phone= editText_phone.getText().toString();
    psw= editText_psw.getText().toString();

    boolean valid= true;

    //validate phone
    if(phone.isEmpty()|| !Patterns.PHONE.matcher(phone).matches()|| phone.length()< 10) {
        editText_phone.setError("enter a valid phone number");
        valid= false;
    }
    else {
        editText_phone.setError(null);
    }

    //validate psw
    if(psw.isEmpty()|| psw.length()< 4) {
        editText_psw.setError("at least 6 alphanumeric characters");
        valid= false;
    }
    else {
        editText_psw.setError(null);
    }

    return valid;
}
 
Example 28
Project: My-Android-Base-Code   File: DeviceUtils.java   View source code 5 votes vote down vote up
public static String getDeviceEmailAddress(Activity activity) {
    Pattern emailPattern = Patterns.EMAIL_ADDRESS;
    if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) {
        return "";
    }
    Account[] accounts = AccountManager.get(activity).getAccounts();
    for (Account account : accounts) {
        if (emailPattern.matcher(account.name).matches()) {
            return account.name;
        }
    }
    return "";
}
 
Example 29
Project: social-text-view   File: SocialTextView.java   View source code 5 votes vote down vote up
/**
 * Checks which flags are enable so that the appropriate link items can be
 * collected from each respective mode.
 *
 * @param text Text
 * @return Set of {@link LinkItem}
 */
private Set<LinkItem> collectLinkItemsFromText(String text) {
    final Set<LinkItem> items = new HashSet<>();

    // Check for hashtag links, if possible
    if ((flags&HASHTAG) == HASHTAG) {
        collectLinkItems(HASHTAG, items, getHashtagPattern().matcher(text));
    }

    // Check for mention links, if possible
    if ((flags&MENTION) == MENTION) {
        collectLinkItems(MENTION, items, getMentionPattern().matcher(text));
    }

    // Check for phone links, if possible
    if ((flags&PHONE) == PHONE) {
        collectLinkItems(PHONE, items, Patterns.PHONE.matcher(text));
    }

    // Check for email links, if possible
    if ((flags&EMAIL) == EMAIL) {
        collectLinkItems(EMAIL, items, Patterns.EMAIL_ADDRESS.matcher(text));
    }

    // Check for url links, if possible
    if ((flags&URL) == URL) {
        collectLinkItems(URL, items, Patterns.WEB_URL.matcher(text));
    }

    return items;
}
 
Example 30
Project: MVP-Android   File: DeviceUtils.java   View source code 5 votes vote down vote up
public static String getDeviceEmailAddress(Activity activity) {
    Pattern emailPattern = Patterns.EMAIL_ADDRESS;
    if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) {
        return "";
    }
    Account[] accounts = AccountManager.get(activity).getAccounts();
    for (Account account : accounts) {
        if (emailPattern.matcher(account.name).matches()) {
            return account.name;
        }
    }
    return "";
}
 
Example 31
Project: OSTMiniProject   File: NotificationUtils.java   View source code 5 votes vote down vote up
public void showNotificationMessage(final String title, final String message, final String timeStamp, Intent intent, String imageUrl) {

        // check for empty msg
        if(TextUtils.isEmpty(message)) {
            return;
        }

        // notification icon
        final int icon = R.mipmap.iconcp;

        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        final PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

        final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

        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, builder, icon, title, message, timeStamp, resultPendingIntent);
                } else {
                    showSmallNotification(builder, icon, title, message, timeStamp, resultPendingIntent);
                }
            } else {
                showSmallNotification(builder, icon, title, message, timeStamp, resultPendingIntent);
            }
        }
    }
 
Example 32
Project: YZxing   File: ShowResultActivity.java   View source code 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_activity_show_result);
    webView = (WebView) findViewById(R.id.web_content);
    tv = (TextView) findViewById(R.id.tv);
    pb = (ProgressBar) findViewById(R.id.progress);

    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);
    webView.setWebChromeClient(webChromeClient);
    webView.setWebViewClient(webViewClient);

    Intent intent = getIntent();
    if (intent != null) {
        resultText = intent.getStringExtra(Constant.EXTRA_RESULT_TEXT_FROM_PIC);
        if (Patterns.WEB_URL.matcher(resultText).matches()) {
            //是一个web url
            tv.setVisibility(View.GONE);
            webView.setVisibility(View.VISIBLE);
            webView.loadUrl(resultText);
        } else {
            //不是web url
            tv.setVisibility(View.VISIBLE);
            webView.setVisibility(View.GONE);
            pb.setVisibility(View.GONE);
            tv.setText(resultText);
        }
    }
}
 
Example 33
Project: CXJPadProject   File: UpdateUtils.java   View source code 5 votes vote down vote up
private static void checkDownload(Context context, String title, String downloadUrl) {
    if (Patterns.WEB_URL.matcher(downloadUrl).matches()) {
        long downloadId = downloadApk( context, downloadUrl, title);
        if(downloadId==0)
            return;
    }
}
 
Example 34
Project: FlickLauncher   File: AutoInstallsLayout.java   View source code 5 votes vote down vote up
protected Intent parseIntent(XmlResourceParser parser) {
    final String url = getAttributeValue(parser, ATTR_URL);
    if (TextUtils.isEmpty(url) || !Patterns.WEB_URL.matcher(url).matches()) {
        if (LOGD) Log.d(TAG, "Ignoring shortcut, invalid url: " + url);
        return null;
    }
    return new Intent(Intent.ACTION_VIEW, null).setData(Uri.parse(url));
}
 
Example 35
Project: cleanarchitecture-unidirectional   File: ForgotPwPresenter.java   View source code 5 votes vote down vote up
@Override
protected ObservableTransformer<Action, Result> actionsToResults() {
    return upstream -> upstream.ofType(ForgotPwActions.ForgotPwSubmit.class)
            .flatMap(action -> {
                if (!Patterns.EMAIL_ADDRESS.matcher(action.getEmail()).matches()) {
                    return Observable.just(Result.<Boolean, ForgotPwActions.ForgotPwSubmit>error(action, new FormValidationException("Must enter a valid email address!")));
                }

                return useCase.performAction(action)
                        .onErrorReturn(throwable -> Result.error(action, throwable))
                        .startWith(Result.<Boolean, ForgotPwActions.ForgotPwSubmit>loading(action));
            })
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io());
}
 
Example 36
Project: SimpleDialogFragments   File: MainActivity.java   View source code 5 votes vote down vote up
public void showEmailInput(View view){

        // email suggestion from registered accounts
        ArrayList<String> emails = new ArrayList<>(0);
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && view != null) {
                requestPermissions(new String[]{Manifest.permission.GET_ACCOUNTS}, REQUEST_ACCOUNTS_PERMISSION);
                return;
            }
        } else {
            Account[] accounts = AccountManager.get(this).getAccounts();
            for (Account account : accounts) {
                if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) {
                    emails.add(account.name);
                }
            }
        }

        SimpleFormDialog.build()
                .fields(Input.email(EMAIL)
                        .required()
                        .suggest(emails)
                        .text(emails.size() > 0 ? emails.get(0) : null)
                )
                .show(this, EMAIL_DIALOG);

        /** Results: {@link MainActivity#onResult} **/

    }
 
Example 37
Project: OpenYOLO-Android   File: CredentialView.java   View source code 5 votes vote down vote up
@OnTextChanged(R.id.profile_picture_field)
void loadProfilePicture() {
    String profilePictureUri = mProfilePictureField.getText().toString();

    if (profilePictureUri.trim().isEmpty()
            || !Patterns.WEB_URL.matcher(profilePictureUri).matches()) {
        mProfilePictureView.setImageDrawable(null);
    } else {
        GlideApp.with(getContext())
                .load(Uri.parse(profilePictureUri))
                .fitCenter()
                .into(mProfilePictureView);
    }
}
 
Example 38
Project: Movie-Notifier-Android   File: WatcherActivity.java   View source code 5 votes vote down vote up
private void setupSharedInfo() {
    if((getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_SEND))
            || (getIntent().getAction() != null && getIntent().getAction().equals(NfcAdapter.ACTION_NDEF_DISCOVERED)
            || (getIntent().getType() != null && getIntent().getType().equals("text/plain")))
            || getIntent().getDataString() != null) {
        String data;

        if(getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_SEND)) {
            data = getIntent().getStringExtra(Intent.EXTRA_TEXT);
        } else {
            data = getIntent().getDataString();
        }

        if(Patterns.WEB_URL.matcher(data).matches()) {
            Uri received = Uri.parse(data);
            Uri instance = Uri.parse(BuildConfig.SERVER_BASE_URL);

            if(received.getHost().equals(instance.getHost())) {
                if(received.getPathSegments().size() == 2 && received.getPathSegments().get(1) != null && !received.getPathSegments().get(1).equals("")) {
                    id = received.getPathSegments().get(1);
                }
            } else if(received.getHost().equals("www.pathe.nl")) {
                if(received.getPathSegments().size() >= 2
                        && received.getPathSegments().get(0) != null && received.getPathSegments().get(0).equals("film")
                        && received.getPathSegments().get(1) != null && !received.getPathSegments().get(1).equals("")) {
                    sharedMovieID = Integer.parseInt(received.getPathSegments().get(1));

                    if(received.getPathSegments().size() >= 3 && received.getPathSegments().get(2) != null
                            && !received.getPathSegments().get(2).equals("")) {
                        sharedTitle = WordUtils.capitalizeFully(received.getPathSegments().get(2).replace("-", " "));
                    }
                }
            }
        }
    }
}
 
Example 39
Project: ValidationUtil-Android   File: ValidationUtilJava.java   View source code 5 votes vote down vote up
public static boolean isValidEmail(Context context, String email) {
    if (isNullOrEmpty(email)) {
        showToast(context, "Please enter Email first.");
    } else if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
        showToast(context, "Please enter a valid Email address.");
    } else {
        return true;
    }
    return false;
}
 
Example 40
Project: Kids-Portal-Android   File: helper_webView.java   View source code 5 votes vote down vote up
public static void openURL (Activity activity, WebView mWebView, EditText editText) {

        mWebView.setVisibility(View.GONE);
        mWebView.getSettings().setLoadsImagesAutomatically(false);
        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(activity);
        String text = editText.getText().toString();
        String searchEngine = sharedPref.getString("searchEngine", "http://www.kiddle.co/s.php?q=");
        String wikiLang = sharedPref.getString("wikiLang", "en");

        if(text.contains("//setting")){
           Intent intent = new Intent(activity, Login.class);
            activity.startActivity(intent);
            activity.finish();
        } else if(text.contains("google.com")) {
            mWebView.loadUrl("http://www.google.com/webhp?complete=0");
        }else if(text.startsWith("http")) {
            mWebView.loadUrl(text);
        } else if (text.startsWith("www.")) {
            mWebView.loadUrl("https://" + text);
        } else if (Patterns.WEB_URL.matcher(text).matches()) {
            mWebView.loadUrl("https://" + text);
        } else {
           String subStr=text.substring(3);

            if (text.startsWith(".Y ")) {
                mWebView.loadUrl("https://www.youtube.com/results?search_query=" + subStr);
            }else if (text.startsWith(".G ")) {
                mWebView.loadUrl("https://www.google.com/search?complete=0&q=" + subStr);
            }else if (text.startsWith(".K ")) {
                mWebView.loadUrl("http://www.kiddle.co/s.php?q=" + subStr);
            }else if (text.startsWith(".R ")) {
                mWebView.loadUrl("http://www.kidrex.org/results/?q=" + subStr);
            }else{
                mWebView.loadUrl(searchEngine + text);
            }

        }

    }