当前位置: 首页>>代码示例>>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;未经允许,请勿转载。