本文整理汇总了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;
}
示例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);*/
}
}
示例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();
}
}
示例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;
}
示例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);
}
}
示例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;
}
}
示例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;
}
示例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
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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();
}
}
示例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);
}
}