當前位置: 首頁>>代碼示例>>Java>>正文


Java View.requestFocus方法代碼示例

本文整理匯總了Java中android.view.View.requestFocus方法的典型用法代碼示例。如果您正苦於以下問題:Java View.requestFocus方法的具體用法?Java View.requestFocus怎麽用?Java View.requestFocus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.view.View的用法示例。


在下文中一共展示了View.requestFocus方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: scrollAndFocus

import android.view.View; //導入方法依賴的package包/類
private boolean scrollAndFocus(int direction, int top, int bottom) {
    boolean handled = true;
    int height = getHeight();
    int containerTop = getScrollY();
    int containerBottom = containerTop + height;
    boolean up = direction == 33;
    View newFocused = findFocusableViewInBounds(up, top, bottom);
    if (newFocused == null) {
        newFocused = this;
    }
    if (top < containerTop || bottom > containerBottom) {
        doScrollY(up ? top - containerTop : bottom - containerBottom);
    } else {
        handled = false;
    }
    if (newFocused != findFocus()) {
        newFocused.requestFocus(direction);
    }
    return handled;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:21,代碼來源:NestedScrollView.java

示例2: onClick

import android.view.View; //導入方法依賴的package包/類
@Override
public void onClick(final View v) {
	if (!v.isFocused()) {
		v.setFocusable(true);
		v.setFocusableInTouchMode(true);					
		v.requestFocus();
		GuiUtils.setKeypadVisibility(getActivity(), (EditText)v, View.VISIBLE);
		
		// 這裡會先delay再送出event,要不然softkeyboard不會出現				
		/*(new Handler()).postDelayed(new Runnable() {
            public void run() {			            	
            	v.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN , 0, 0, 0));
            	v.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP , 0, 0, 0));
            }
        }, 200);*/
	}
}
 
開發者ID:Welloculus,項目名稱:MobileAppForPatient,代碼行數:18,代碼來源:MeterPreferenceDialog.java

示例3: attemptLogin

import android.view.View; //導入方法依賴的package包/類
/**
 * Attempts to sign in with the login form.
 * If there are form errors, the errors are presented
 * and no actual login attempt is made.
 */
private void attemptLogin() {
    try {
        m_passwordView.setError(null);
        m_password = m_passwordView.getText().toString();
        boolean cancel = false;
        View focusView = null;

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

        String currentHash = LoginHashCreator.getLoginHash(m_context, m_password);
        String verificationHash = KeyValueDB.getVerificationPasswordHash(m_context);
        boolean correctPassword = (currentHash.equals(verificationHash));

        if(!correctPassword) {
            m_passwordView.setError(getString(R.string.error_login_wrong_password));
            focusView = m_passwordView;
            cancel = true;
        }

        if(cancel) {
            focusView.requestFocus();
            m_passwordView.setText(null);
        } else {
            Toast.makeText(getApplicationContext(), getString(R.string.success_login_general)
                    + ". " + getString(R.string.greeting_general) + ", " + KeyValueDB.getUsername(m_context)
                    + "!", Toast.LENGTH_SHORT).show();
            showProgress(true);
            startActivity(NOTES_ACTIVITY, true);
        }
    } catch (Exception e) {
        Toast.makeText(getApplicationContext(), getString(R.string.error_login_general) + ". " + getString(R.string.action_try_again) + ".", Toast.LENGTH_SHORT).show();
    }
}
 
開發者ID:YoeriNijs,項目名稱:NoteBuddy,代碼行數:43,代碼來源:LoginActivity.java

示例4: onRequestFocusInDescendants

import android.view.View; //導入方法依賴的package包/類
/**
 * We only want the current page that is being shown to be focusable.
 */
@Override
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
	int index;
	int increment;
	int end;
	int count = getChildCount();
	if ((direction & FOCUS_FORWARD) != 0) {
		index = 0;
		increment = 1;
		end = count;
	} else {
		index = count - 1;
		increment = -1;
		end = -1;
	}
	for (int i = index; i != end; i += increment) {
		View child = getChildAt(i);
		if (child.getVisibility() == VISIBLE) {
			ItemInfo ii = infoForChild(child);
			if (ii != null && ii.position == mCurItem) {
				if (child.requestFocus(direction, previouslyFocusedRect)) {
					return true;
				}
			}
		}
	}
	return false;
}
 
開發者ID:fengshihao,項目名稱:WebPager,代碼行數:32,代碼來源:CustomViewPager.java

示例5: attemptRecover

import android.view.View; //導入方法依賴的package包/類
/**
 * Attempts to recover 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.
 */
public void attemptRecover() {
    // Store values at the time of the login attempt.
    String email = edit_email.getText().toString();

    boolean cancel = false;
    View focusView = null;

    ValidateUserInfo validate = new ValidateUserInfo();

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

    if (cancel) {
        // There was an error; don't attempt login and focus the first
        // form field with an error.
        focusView.requestFocus();
    } else {
        //TODO Recover account logic
        // Show a progress spinner, and kick off a background task to
        // perform the user recover info attempt.
        mForgotTask = new ForgotPassTask(email);
        mForgotTask.execute((Void) null);
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:38,代碼來源:ForgotPassActivity.java

示例6: onClick

import android.view.View; //導入方法依賴的package包/類
@Override
public void onClick(View v) {
	switch (v.getId()) {
	case R.id.bu_setTime:
		v.requestFocus();
		v.requestFocusFromTouch();
		setPushTime();
		break;
	}
}
 
開發者ID:LuoLuo0101,項目名稱:JPush,代碼行數:11,代碼來源:SettingActivity.java

示例7: onRequestFocusInDescendants

import android.view.View; //導入方法依賴的package包/類
/**
 * We only want the current page that is being shown to be focusable.
 */
@Override
protected boolean onRequestFocusInDescendants(int direction,
                                              Rect previouslyFocusedRect) {
    int index;
    int increment;
    int end;
    int count = getChildCount();
    if ((direction & FOCUS_FORWARD) != 0) {
        index = 0;
        increment = 1;
        end = count;
    } else {
        index = count - 1;
        increment = -1;
        end = -1;
    }
    for (int i = index; i != end; i += increment) {
        View child = getChildAt(i);
        if (child.getVisibility() == VISIBLE) {
            ItemInfo ii = infoForChild(child);
            if (ii != null && ii.position == mCurItem && child.requestFocus(direction, previouslyFocusedRect)) {
                return true;
            }
        }
    }
    return false;
}
 
開發者ID:ynztlxdeai,項目名稱:TextReader,代碼行數:31,代碼來源:DirectionalViewpager.java

示例8: checkRegistrationPassword

import android.view.View; //導入方法依賴的package包/類
/**
 * Try to register a new account.
 */
public void checkRegistrationPassword(EditText passwordTextView) {

    if (mRegisterTask != null) {
        return;
    }

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

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

    boolean cancel = false;
    View focusView = null;

    // Check for valid password
    try {
        if (!CryptoUtils.isPasswordValid(password)) {
            focusView = passwordTextView;
            cancel = true;
        }
    } catch (InvalidPasswordException e) {
        passwordTextView.setError(e.getMessage());
    }

    if (cancel) {
        // There was an error; don't attempt login and focus the first
        // form field with an error.
        focusView.requestFocus();
    } else {
        temp_password = password;
        //TODO store password in a secure way
    }
}
 
開發者ID:ProjektMedInf,項目名稱:WiFiSDCryptoLocker,代碼行數:38,代碼來源:SetupActivity.java

示例9: attemptLogin

import android.view.View; //導入方法依賴的package包/類
/**
 * Attempts to sign in the account specified by the login form.
 * If there are form errors (missing fields), the
 * errors are presented and no actual login attempt is made.
 */
private void attemptLogin() {
    if (mAuthTask != null) {
        return;
    }

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

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

    boolean cancel = false;
    View focusView = null;

    // Check for empty password
    if (TextUtils.isEmpty(password)) {
        mPasswordView.setError(getString(R.string.error_field_required));
        focusView = mPasswordView;
        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(USER_NAME, password);
        mAuthTask.execute((Void) null);
    }
}
 
開發者ID:ProjektMedInf,項目名稱:WiFiSDCryptoLocker,代碼行數:39,代碼來源:LoginActivity.java

示例10: onRequestFocusInDescendants

import android.view.View; //導入方法依賴的package包/類
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
    if (direction == 2) {
        direction = 130;
    } else if (direction == 1) {
        direction = 33;
    }
    View nextFocus = previouslyFocusedRect == null ? FocusFinder.getInstance().findNextFocus(this, null, direction) : FocusFinder.getInstance().findNextFocusFromRect(this, previouslyFocusedRect, direction);
    if (nextFocus == null || isOffScreen(nextFocus)) {
        return false;
    }
    return nextFocus.requestFocus(direction, previouslyFocusedRect);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:13,代碼來源:NestedScrollView.java

示例11: showKeyboard

import android.view.View; //導入方法依賴的package包/類
public static void showKeyboard(final View view) {
    view.requestFocus();
    InputMethodManager inputManager =
            (InputMethodManager) view.getContext().getSystemService(
                    Context.INPUT_METHOD_SERVICE);
    inputManager.showSoftInput(view, 0);
}
 
開發者ID:qiujuer,項目名稱:AirPanel,代碼行數:8,代碼來源:Util.java

示例12: attemptLogin

import android.view.View; //導入方法依賴的package包/類
private void attemptLogin() {
    // Reset errors.
    txtAccount.setError(null);
    txtPassword.setError(null);
    // Store values at the time of the login attempt.
    String account = txtAccount.getText().toString();
    String password = txtPassword.getText().toString();

    boolean cancel = false;
    View focusView = null;

    // Check for a valid password, if the user entered one.
    if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
        txtPassword.setError(getString(R.string.error_invalid_password));
        focusView = txtPassword;
        cancel = true;
    }
    // Check for a valid email address.
    if (TextUtils.isEmpty(account)) {
        txtAccount.setError(getString(R.string.error_field_required));
        focusView = txtAccount;
        cancel = true;
    }
    if (cancel) {
        focusView.requestFocus();
    } else {
        showLoading();
        hashMap.put("loginName", account);
        hashMap.put("pwd", StringUtil.MD5(password));
        new LoginPresenter(LoginActivity.this);
        presenter.getData(hashMap);
    }
}
 
開發者ID:liuyongfeng90,項目名稱:JKCloud,代碼行數:34,代碼來源:LoginActivity.java

示例13: showSoftKeyboard

import android.view.View; //導入方法依賴的package包/類
public static void showSoftKeyboard(View view) {
    if (view == null) return;
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    if (!view.isFocused()) view.requestFocus();

    InputMethodManager inputMethodManager = (InputMethodManager) view.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.showSoftInput(view, 0);
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:11,代碼來源:TDevice.java

示例14: setViewFocus

import android.view.View; //導入方法依賴的package包/類
public void setViewFocus(View view) {
    if (view != null) {
        view.setFocusable(true);
        view.setFocusableInTouchMode(true);
        view.requestFocus();
        view.requestFocusFromTouch();
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:9,代碼來源:BasicActivity.java

示例15: attemptLogin

import android.view.View; //導入方法依賴的package包/類
/**
 * 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.
 */
private void attemptLogin() {
    if (mAuthTask != null) {
        return;
    }

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


    // Store values at the time of the login attempt.
    String username = mUsernameView.getText().toString();
    String password = mPasswordView.getText().toString();
    String url = mUrl.getText().toString();

    boolean cancel = false;
    View focusView = null;

    if(Validator.absoluteUrlIsValid(url) == false){
        mUrl.setError(getString(R.string.error_invalid_url));
        focusView = mUrl;
        cancel = true;
    }else if (TextUtils.isEmpty(password)) {
        mPasswordView.setError(getString(R.string.error_invalid_password));
        focusView = mPasswordView;
        cancel = true;
    }else if (TextUtils.isEmpty(username)) {
        mUsernameView.setError(getString(R.string.error_field_required));
        focusView = mUsernameView;
        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(mLoginFormView, username, password, url);
        mAuthTask.execute((Void) null);
    }
}
 
開發者ID:alextselegidis,項目名稱:easyappointments-android-client,代碼行數:51,代碼來源:LoginActivity.java


注:本文中的android.view.View.requestFocus方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。