Example usage for android.util Patterns DOMAIN_NAME

List of usage examples for android.util Patterns DOMAIN_NAME

Introduction

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

Prototype

Pattern DOMAIN_NAME

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

Click Source Link

Usage

From source file:Main.java

public static boolean isValidWebAddress(CharSequence target) {
    return !TextUtils.isEmpty(target) && Patterns.DOMAIN_NAME.matcher(target).matches();
}

From source file:eu.operando.proxy.filters.domain.DomainFiltersActivity.java

@OnClick(R.id.add_filter)
public void addFilter() {

    if (viewSelected == 0) { //User Filter

        View dialogView = getLayoutInflater().inflate(R.layout.user_domain_filter_dialog, null);
        final EditText input = (EditText) dialogView.findViewById(R.id.filter_content);
        final CheckBox isWildcard = (CheckBox) dialogView.findViewById(R.id.is_wildcard);

        AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle("New DomainFilter")
                .setView(dialogView)/*from  w ww.java2s .  com*/
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        DomainFilter domainFilter = new DomainFilter();
                        domainFilter.setContent(input.getText().toString().toLowerCase());
                        domainFilter.setSource(null);
                        domainFilter.setIsWildcard(isWildcard.isChecked());
                        db.createDomainFilter(domainFilter);
                        updateFiltersList();
                        userDomainFiltersAdapter.notifyItemInserted(userFilters.size() - 1);
                        recyclerView.scrollToPosition(userFilters.size() - 1);
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Canceled.
                    }
                });

        final AlertDialog dialog = builder.create();

        input.addTextChangedListener(new TextWatcher() {
            @Override
            public void afterTextChanged(Editable s) {
                if (Patterns.DOMAIN_NAME.matcher(s).matches()) {
                    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
                } else
                    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }
        });

        dialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
            }
        });

        dialog.show();

    } else { //Imported filter list
        final EditText input = new EditText(this);
        input.setSingleLine(true);
        input.setHint("Enter URL");
        new AlertDialog.Builder(this).setTitle("Import filters from remote file (hosts file format)")
                .setView(input).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        final String importUrl = input.getText().toString();
                        importExternalFilters(importUrl);

                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Canceled.
                    }
                }).show();
    }
}

From source file:eu.operando.operandoapp.filters.domain.DomainFiltersActivity.java

@OnClick(R.id.add_filter)
public void addFilter() {

    if (viewSelected == 0) { //User Filter

        View dialogView = getLayoutInflater().inflate(R.layout.user_domain_filter_dialog, null);
        final EditText input = (EditText) dialogView.findViewById(R.id.filter_content);
        final CheckBox isWildcard = (CheckBox) dialogView.findViewById(R.id.is_wildcard);

        AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle("New DomainFilter")
                .setView(dialogView)/*  w ww .  j av a  2 s . c  om*/
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        DomainFilter domainFilter = new DomainFilter();
                        domainFilter.setContent(input.getText().toString().toLowerCase());
                        domainFilter.setSource(null);
                        domainFilter.setIsWildcard(isWildcard.isChecked());
                        db.createDomainFilter(domainFilter);
                        updateFiltersList();
                        userDomainFiltersAdapter.notifyItemInserted(userFilters.size() - 1);
                        recyclerView.scrollToPosition(userFilters.size() - 1);
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Canceled.
                    }
                });

        final AlertDialog dialog = builder.create();

        input.addTextChangedListener(new TextWatcher() {
            @Override
            public void afterTextChanged(Editable s) {
                if (Patterns.DOMAIN_NAME.matcher(s).matches()) {
                    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
                } else
                    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }
        });

        dialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
            }
        });

        dialog.show();

    } else { //Imported filter list
        final EditText input = new EditText(this);
        input.setSingleLine(true);
        //input.setHint("Enter URL");
        input.setText(DatabaseHelper.serverUrl + "/blocked_urls");
        new AlertDialog.Builder(this).setTitle("Import filters from remote file (hosts file format)")
                .setView(input).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        final String importUrl = input.getText().toString();
                        long start = System.currentTimeMillis();
                        importExternalFilters(importUrl);
                        long end = System.currentTimeMillis();
                        Toast.makeText(DomainFiltersActivity.this, (end - start) + "ms required",
                                Toast.LENGTH_LONG).show();

                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Canceled.
                    }
                }).show();
    }
}

From source file:com.wly.net.PortScannerActivity.java

private boolean validateUrl(final String url) {
    boolean result = Patterns.DOMAIN_NAME.matcher(url).matches();
    Log.i(TAG, " Validation of " + url + " returned " + String.valueOf(result));
    return result;
}

From source file:org.rm3l.ddwrt.mgmt.AbstractRouterMgmtDialogFragment.java

private boolean validateForm(@NotNull AlertDialog d) {
    @NotNull/*from   w w  w . ja v  a2  s . c  o  m*/
    final EditText ipAddrView = (EditText) d.findViewById(R.id.router_add_ip);

    final Editable ipAddrViewText = ipAddrView.getText();

    if (!(Patterns.IP_ADDRESS.matcher(ipAddrViewText).matches()
            || Patterns.DOMAIN_NAME.matcher(ipAddrViewText).matches())) {
        displayMessage(getString(R.string.router_add_dns_or_ip_invalid) + ":" + ipAddrViewText, ALERT);
        ipAddrView.requestFocus();
        openKeyboard(ipAddrView);
        return false;
    }

    boolean validPort;
    @NotNull
    final EditText portView = (EditText) d.findViewById(R.id.router_add_port);
    try {
        final String portStr = portView.getText().toString();
        validPort = (!isNullOrEmpty(portStr) && (Integer.parseInt(portStr) > 0));
    } catch (@NotNull final Exception e) {
        e.printStackTrace();
        validPort = false;
    }
    if (!validPort) {
        displayMessage(getString(R.string.router_add_port_invalid) + ":" + portView.getText(), ALERT);
        portView.requestFocus();
        openKeyboard(portView);
        return false;
    }

    @NotNull
    final EditText sshUsernameView = (EditText) d.findViewById(R.id.router_add_username);
    if (isNullOrEmpty(sshUsernameView.getText().toString())) {
        displayMessage(getString(R.string.router_add_username_invalid), ALERT);
        sshUsernameView.requestFocus();
        openKeyboard(sshUsernameView);
        return false;
    }

    final int checkedAuthMethodRadioButtonId = ((RadioGroup) d.findViewById(R.id.router_add_ssh_auth_method))
            .getCheckedRadioButtonId();
    if (checkedAuthMethodRadioButtonId == R.id.router_add_ssh_auth_method_password) {
        //Check password
        @NotNull
        final EditText sshPasswordView = (EditText) d.findViewById(R.id.router_add_password);
        if (isNullOrEmpty(sshPasswordView.getText().toString())) {
            displayMessage(getString(R.string.router_add_password_invalid), ALERT);
            sshPasswordView.requestFocus();
            openKeyboard(sshPasswordView);
            return false;
        }
    } else if (checkedAuthMethodRadioButtonId == R.id.router_add_ssh_auth_method_privkey) {
        //Check privkey
        @NotNull
        final TextView sshPrivKeyView = (TextView) d.findViewById(R.id.router_add_privkey_path);
        if (isNullOrEmpty(sshPrivKeyView.getText().toString())) {
            displayMessage(getString(R.string.router_add_privkey_invalid), ALERT);
            sshPrivKeyView.requestFocus();
            return false;
        }
    }

    return true;
}