Example usage for android.view View requestFocus

List of usage examples for android.view View requestFocus

Introduction

In this page you can find the example usage for android.view View requestFocus.

Prototype

public final boolean requestFocus() 

Source Link

Document

Call this to try to give focus to a specific view or to one of its descendants.

Usage

From source file:org.tomahawk.tomahawk_android.dialogs.RegisterConfigDialog.java

/**
 * Attempts to sign in or register the account specified by the login form. If there are form
 * errors (invalid email, missing fields, etc.), the errors are presented and no actual login
 * attempt is made.//ww  w  . j av a  2s.c om
 */
private void attemptRegister() {
    // Reset errors.
    mUsernameEditText.setError(null);
    mPasswordEditText.setError(null);
    mPasswordConfirmationEditText.setError(null);

    // Store values at the time of the login attempt.
    String username = mUsernameEditText.getText().toString();
    String password = mPasswordEditText.getText().toString();
    String passwordConfirmation = mPasswordConfirmationEditText.getText().toString();
    String email = null;
    if (!TextUtils.isEmpty(mMailEditText.getText().toString())) {
        email = mMailEditText.getText().toString();
    }

    boolean cancel = false;
    View focusView = null;

    // Check for a valid username
    if (TextUtils.isEmpty(username)) {
        mUsernameEditText.setError(getString(R.string.error_field_required));
        focusView = mUsernameEditText;
        cancel = true;
    }

    // Check for a valid password.
    if (TextUtils.isEmpty(password)) {
        mPasswordEditText.setError(getString(R.string.error_field_required));
        focusView = mPasswordEditText;
        cancel = true;
    }

    // Check for a valid password confirmation.
    if (TextUtils.isEmpty(passwordConfirmation)) {
        mPasswordConfirmationEditText.setError(getString(R.string.error_field_required));
        focusView = mPasswordConfirmationEditText;
        cancel = true;
    }
    if (!password.equals(passwordConfirmation)) {
        mPasswordConfirmationEditText.setError(getString(R.string.error_passwords_dont_match));
        focusView = mPasswordConfirmationEditText;
        cancel = true;
    }

    if (cancel) {
        // There was an error; don't attempt register and focus the first
        // form field with an error.
        focusView.requestFocus();
    } else {
        // Tell the service to register
        mAuthenticatorUtils.register(username, password, email);
        startLoadingAnimation();
    }
}

From source file:de.uni_koblenz_landau.apow.LoginActivity.java

/**
 * Checks input and logs in.// www.j  ava 2  s .com
 */
public void login(View view) {
    // Abort if task is already running.
    if (mLoginTask != null || mFirstRun) {
        return;
    }

    // Reset errors.
    mLoginPasswordView.setError(null);

    // Store UI values.
    mLoginPassword = mLoginPasswordView.getText().toString();

    boolean cancel = false;
    View focusView = null;

    // Check input.
    if (TextUtils.isEmpty(mLoginPassword)) {
        mLoginPasswordView.setError(getString(R.string.error_field_required));
        focusView = mLoginPasswordView;
        cancel = true;
    } else if (mLoginPassword.length() < 4) {
        mLoginPasswordView.setError(getString(R.string.error_invalid_password));
        focusView = mLoginPasswordView;
        cancel = true;
    }

    if (TextUtils.isEmpty(mNFCTag)) {
        mLoginNFCText.setError(getString(R.string.error_no_tag));
        focusView = mLoginNFCText;
        cancel = true;
    }

    // When there are no error start login task.
    if (cancel) {
        focusView.requestFocus();
    } else {
        mStatusMessageView.setText(R.string.login_login_progress);
        showProgress(true);
        mLoginTask = new LoginTask();
        TaskActivityReference.getInstance().addTask(LoginTask.TASK_ID, mLoginTask, this);
        mLoginTask.execute(Helper.hash(mNFCTag + mLoginPassword));
    }
}

From source file:org.hansel.myAlert.Registro.java

protected void AttempCreate() {
    if (mAuthTask != null) {
        return;/*from   w ww  .j  ava2s . co m*/
    }
    //obtenemos datos
    mUsuario = vUsuario.getText().toString().trim();
    mPassword = vPassword.getText().toString().trim();
    mEmail = vEmail.getText().toString().trim();
    //   mEmailContacto = vEmailContacto.getText().toString();
    boolean cancel = false;
    View focusView = null;
    // Check for a valid user.
    if (TextUtils.isEmpty(mUsuario)) {
        vUsuario.setError(getString(R.string.error_field_required));
        focusView = vUsuario;
        cancel = true;
    }
    if (TextUtils.isEmpty(mPassword)) {
        vPassword.setError(getString(R.string.error_field_required));
        focusView = vPassword;
        cancel = true;
    }
    if (TextUtils.isEmpty(mEmail)) {
        vEmail.setError(getString(R.string.error_field_required));
        focusView = vEmail;
        cancel = true;
    } else if (!mEmail.contains("@")) {
        vEmail.setError("Correo no vlido");
        focusView = vEmail;
        cancel = true;
    }
    /*if (TextUtils.isEmpty(mEmailContacto) ) {
       vEmail.setError(getString(R.string.error_field_required));
       focusView = vEmailContacto;
       cancel = true;
    }else */
    if (cancel) {
        // There was an error; don't attempt login and focus the first
        // form field with an error.
        focusView.requestFocus();
    } else {
        //escondemos teclado
        try {
            ((InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE))
                    .hideSoftInputFromWindow(vPassword.getWindowToken(), 0);
        } catch (Exception ex) {
            Log.v("Error al esconder teclado: " + ex.getMessage());
        }
        // Show a progress spinner, and kick off a background task to
        // perform the user login attempt.
        mLoginStatusMessageView.setText(R.string.login_progress_signing_in);

        mAuthTask = new UserCreateTask();
        mAuthTask.execute((Void) null);
    }

}

From source file:org.gege.caldavsyncadapter.authenticator.AuthenticatorActivity.java

/**
 * Attempts to sign in or register the account specified by the login form.
 * If there are form errors (invalid email, missing fields, etc.), the
 * errors are presented and no actual login attempt is made.
 *//*from  w w w.j ava2s  .  c o m*/
public void attemptLogin() {
    if (mAuthTask != null) {
        return;
    }

    // Reset errors.
    mUserView.setError(null);
    mPasswordView.setError(null);

    // Store values at the time of the login attempt.
    mUser = mUserView.getText().toString();
    mPassword = mPasswordView.getText().toString();
    mURL = mURLView.getText().toString();

    boolean cancel = false;
    View focusView = null;

    // Check for a valid password.
    if (TextUtils.isEmpty(mPassword)) {
        mPasswordView.setError(getString(R.string.error_field_required));
        focusView = mPasswordView;
        cancel = true;
    } else if (mPassword.length() < 4) {
        mPasswordView.setError(getString(R.string.error_invalid_password));
        focusView = mPasswordView;
        cancel = true;
    }

    // Check for a valid email address.
    if (TextUtils.isEmpty(mUser)) {
        mUserView.setError(getString(R.string.error_field_required));
        focusView = mUserView;
        cancel = true;
    }
    //else if (!mUser.contains("@")) {
    //   mUserView.setError(getString(R.string.error_invalid_email));
    //   focusView = mUserView;
    //   cancel = true;
    //}

    if (cancel) {
        // There was an error; don't attempt login and focus the first
        // form field with an error.
        focusView.requestFocus();
    } else {
        // Show a progress spinner, and kick off a background task to
        // perform the user login attempt.
        mLoginStatusMessageView.setText(R.string.login_progress_signing_in);
        showProgress(true);
        mAuthTask = new UserLoginTask();
        mAuthTask.execute((Void) null);
    }
}

From source file:android.car.ui.provider.CarDrawerLayout.java

/**
 * Close the specified drawer view by animating it into view.
 *///from w w w.j a  v a2s .c  o  m
public void closeDrawer() {
    ViewGroup drawerView = (ViewGroup) findDrawerView();
    if (!isDrawerView(drawerView)) {
        throw new IllegalArgumentException("View " + drawerView + " is not a sliding drawer");
    }
    mStartedOpen = true;

    // Don't trigger the close drawer animation if drawer is not open.
    if (hasWindowFocus() && isDrawerOpen()) {
        int left;
        LayoutParams drawerLp = (LayoutParams) drawerView.getLayoutParams();
        if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) {
            left = drawerLp.getMarginStart() - drawerView.getWidth();
        } else {
            left = drawerLp.getMarginStart() + getWidth();
        }
        mDragger.smoothSlideViewTo(drawerView, left, drawerView.getTop());
        dispatchOnDrawerClosing(drawerView);
    } else {
        final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
        lp.onScreen = 0.f;
        dispatchOnDrawerClosed(drawerView);
    }

    ViewGroup contentView = (ViewGroup) findContentView();
    drawerView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
    contentView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

    if (!isInTouchMode()) {
        List<View> focusables = contentView.getFocusables(FOCUS_DOWN);
        if (focusables.size() > 0) {
            View candidate = focusables.get(0);
            candidate.requestFocus();
        }
    }
    invalidate();
}

From source file:android.car.ui.provider.CarDrawerLayout.java

/**
 * Open the drawer view by animating it into view.
 *///from  www  .  ja v a  2  s .  co  m
public void openDrawer() {
    ViewGroup drawerView = (ViewGroup) findDrawerView();
    mStartedOpen = false;

    if (hasWindowFocus()) {
        int left;
        LayoutParams drawerLp = (LayoutParams) drawerView.getLayoutParams();
        if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) {
            left = drawerLp.getMarginStart();
        } else {
            left = drawerLp.getMarginStart() + getWidth() - drawerView.getWidth();
        }
        mDragger.smoothSlideViewTo(drawerView, left, drawerView.getTop());
        dispatchOnDrawerOpening(drawerView);
    } else {
        final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
        lp.onScreen = 1.f;
        dispatchOnDrawerOpened(drawerView);
    }

    ViewGroup contentView = (ViewGroup) findContentView();
    contentView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
    drawerView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

    View focusable = drawerView.getChildAt(0);
    if (focusable != null) {
        focusable.requestFocus();
    }
    invalidate();
}

From source file:in.andres.kandroid.ui.LoginActivity.java

/**
 * Attempts to sign in or register the account specified by the login form.
 * If there are form errors (invalid email, missing fields, etc.), the
 * errors are presented and no actual login attempt is made.
 *///w ww  . j a va  2s.c o m
private void attemptLogin() {
    if (kanboardAPI != null) {
        return;
    }

    // Reset errors.
    mUsernameView.setError(null);
    mPasswordView.setError(null);

    // Store values at the time of the login attempt.
    final String serverurl = mServerURLView.getText().toString();
    //        String apikey = mAPIKeyView.getText().toString();
    final String username = mUsernameView.getText().toString();
    final String password = mPasswordView.getText().toString();

    boolean cancel = false;
    View focusView = null;

    // Check for a valid password, if the user entered one.
    if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
        mPasswordView.setError(getString(R.string.error_invalid_password));
        focusView = mPasswordView;
        cancel = true;
    }

    // Check for a valid email address.
    if (TextUtils.isEmpty(username)) {
        mUsernameView.setError(getString(R.string.error_field_required));
        focusView = mUsernameView;
        cancel = true;
    }

    //        if (TextUtils.isEmpty(apikey)) {
    //            mAPIKeyView.setError(getString(R.string.error_field_required));
    //            focusView = mAPIKeyView;
    //            cancel = true;
    //        }

    if (TextUtils.isEmpty(serverurl)) {
        mServerURLView.setError(getString(R.string.error_field_required));
        focusView = mServerURLView;
        cancel = true;
    }

    if (cancel) {
        // There was an error; don't attempt login and focus the first
        // form field with an error.
        focusView.requestFocus();
    } else {
        // Show a progress spinner, and kick off a background task to
        // perform the user login attempt.
        try {
            kanboardAPI = new KanboardAPI(serverurl, username, password);
            kanboardAPI.addErrorListener(new OnErrorListener() {
                @Override
                public void onError(KanboardError error) {
                    showProgress(false);
                    Log.e(Constants.TAG,
                            String.format("%s (%d; %d)", error.Message, error.Code, error.HTTPReturnCode));
                    if (error.Code == -10) {
                        mServerURLView.setError(getString(R.string.error_host_unknown));
                        mServerURLView.requestFocus();
                    } else if (error.Code == -30) {
                        mServerURLView.setError(getString(R.string.error_server_url));
                        mServerURLView.requestFocus();
                    } else if (error.HTTPReturnCode == 401 || error.HTTPReturnCode == 403
                            || error.Code == -20) {
                        mUsernameView.setError(getString(R.string.error_incorrect_username));
                        mPasswordView.setError(getString(R.string.error_incorrect_password));
                        mPasswordView.requestFocus();
                    }
                    kanboardAPI = null;
                }
            });
            kanboardAPI.addOnGetVersionListener(new OnGetVersionListener() {
                @Override
                public void onGetVersion(boolean success, int[] version, String tag) {
                    showProgress(false);
                    if (version[0] >= Constants.minKanboardVersion[0]
                            && version[1] >= Constants.minKanboardVersion[1]
                            && version[2] >= Constants.minKanboardVersion[2]) {
                        SharedPreferences preferences = PreferenceManager
                                .getDefaultSharedPreferences(getApplicationContext());
                        SharedPreferences.Editor editor = preferences.edit();
                        editor.putString("serverurl", serverurl.trim());
                        editor.putString("username", username);
                        editor.putString("password", password);
                        editor.apply();
                        finish();
                    } else {
                        mServerURLView.setError(getString(R.string.error_wrong_kanboard_version,
                                Constants.minKanboardVersion[0], Constants.minKanboardVersion[1],
                                Constants.minKanboardVersion[2]));
                        mServerURLView.requestFocus();
                    }
                    kanboardAPI = null;
                }
            });
            kanboardAPI.getVersion();
            showProgress(true);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:fr.cobaltians.cobalt.fragments.CobaltFragment.java

protected void setWebViewSettings(Object javascriptInterface) {
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
        mWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD)
        mWebView.setOverScrollMode(View.OVER_SCROLL_IF_CONTENT_SCROLLS);
    mWebView.setScrollListener(this);
    mWebView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);

    // Enables JS
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);

    // Enables and setups JS local storage
    webSettings.setDomStorageEnabled(true);
    webSettings.setDatabaseEnabled(true);
    //@deprecated since API 19. But calling this method have simply no effect for API 19+
    webSettings.setDatabasePath(mContext.getFilesDir().getParentFile().getPath() + "/databases/");

    // Enables cross-domain calls for Ajax
    allowAjax();// ww w  .jav a2s .  com

    // Fix some focus issues on old devices like HTC Wildfire
    // keyboard was not properly showed on input touch.
    mWebView.requestFocus(View.FOCUS_DOWN);
    mWebView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_UP:
                if (!view.hasFocus()) {
                    view.requestFocus();
                }
                break;
            default:
                break;
            }

            return false;
        }
    });

    // Add JavaScript interface so JavaScript can call native functions.
    mWebView.addJavascriptInterface(javascriptInterface, "Android");
    mWebView.addJavascriptInterface(new LocalStorageJavaScriptInterface(mContext), "LocalStorage");

    WebViewClient webViewClient = new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            executeWaitingCalls();
        }
    };

    mWebView.setWebViewClient(webViewClient);
}

From source file:com.example.devesh.Coride.DriverRegistration.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_driver_registration);
    context = getApplicationContext();/* w  ww.  j  a  va2s . c  o  m*/

    // Set up the login form.
    mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
    //populateAutoComplete();

    mPasswordView = (EditText) findViewById(R.id.password);

    /**
     * Attempts to sign in or register the account specified by the login form.
     * If there are form errors (invalid email, missing fields, etc.), the
     * errors are presented and no actual login attempt is made.
     */

    // Reset errors.
    mEmailView.setError(null);
    mPasswordView.setError(null);

    // Store values at the time of the login attempt.
    String email = mEmailView.getText().toString();
    String password = mPasswordView.getText().toString();

    boolean cancel = false;
    View focusView = null;

    // Check for a valid password, if the user entered one.
    if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
        mPasswordView.setError(getString(R.string.error_invalid_password));
        focusView = mPasswordView;
        cancel = true;
    }

    // Check for a valid email address.
    if (TextUtils.isEmpty(email)) {
        mEmailView.setError(getString(R.string.error_field_required));
        focusView = mEmailView;
        cancel = true;
    } else if (!isEmailValid(email)) {
        mEmailView.setError(getString(R.string.error_invalid_email));
        focusView = mEmailView;
        cancel = true;
    }

    if (cancel) {
        // There was an error; don't attempt login and focus the first
        // form field with an error.
        focusView.requestFocus();
    } else {
        // Show a progress spinner, and kick off a background task to
        // perform the user login attempt.
        showProgress(true);
        mAuthTask = new UserLoginTask(email, password);
        mAuthTask.execute((Void) null);
    }
}

From source file:org.alfresco.mobile.android.application.fragments.signin.AccountCredentialsFragment.java

/**
 * Attempts to sign in or register the account specified by the login form.
 * If there are form errors (invalid email, missing fields, etc.), the
 * errors are presented and no actual login attempt is made.
 *//*from   w w w. j  a  va 2 s  .com*/
public void attemptLogin() {
    // Reset errors.
    usernameField.setError(null);
    passwordField.setError(null);
    alfrescoField.setError(null);

    // Store values at the time of the login attempt.
    username = usernameField.getText().toString();
    password = passwordField.getText().toString();
    alfrescoUrlValue = alfrescoField.getText().toString();

    boolean cancel = false;
    View focusView = null;

    // Check for a valid password, if the task entered one.
    if (TextUtils.isEmpty(password)) {
        passwordField.setError(getString(R.string.error_field_required));
        focusView = passwordField;
        cancel = true;
    }

    // Check for a valid email address.
    if (TextUtils.isEmpty(username)) {
        usernameField.setError(getString(R.string.error_field_required));
        focusView = usernameField;
        cancel = true;
    }

    // Check for a valid hostname.
    if (TextUtils.isEmpty(alfrescoUrlValue)) {
        alfrescoField.setError(getString(R.string.error_field_required));
        focusView = alfrescoField;
        cancel = true;
    }

    // Check URL
    if (TextUtils.isEmpty(alfrescoUrlValue)) {
        alfrescoField.setError(getString(R.string.error_invalid_url));
        focusView = alfrescoField;
        cancel = true;
    } else {
        endpoint = Uri.parse(alfrescoUrlValue);
    }

    if (cancel) {
        // There was an error; don't attempt login and focus the first
        // form field with an error.
        focusView.requestFocus();
    } else {
        showProgress(true);
        connect();
    }
}