android.view.View#isFocused ( )源码实例Demo

下面列出了android.view.View#isFocused ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Carbon   文件: InputLayout.java
private void updateHint(View child) {
    if (labelTextView == null)
        return;
    if (child == null) {
        labelTextView.setVisibility(GONE);
        return;
    }
    if (labelMode == LabelMode.Persistent || labelMode == LabelMode.Floating && child.isFocused() ||
            labelMode == LabelMode.IfNotEmpty && (child.isFocused() || child instanceof android.widget.TextView && ((android.widget.TextView) child).getText().length() > 0)) {
        labelTextView.animateVisibility(VISIBLE);
        if (child instanceof EditText)
            ((EditText) child).setHint(null);
    } else if (labelMode != LabelMode.Hint) {
        labelTextView.animateVisibility(INVISIBLE);
        if (child instanceof EditText)
            ((EditText) child).setHint(label + (((EditText) child).isRequired() ? " *" : ""));
    } else {
        labelTextView.setVisibility(GONE);
    }
}
 
源代码2 项目: android-tv-launcher   文件: MainActivity.java
/**
 * 顶部焦点获取
 *
 * @param keyCode
 * @param event
 * @return
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean focusFlag = false;
    for (View v : mViews) {
        if (v.isFocused()) {
            focusFlag = true;
        }
    }
    Log.d(TAG, "code:" + keyCode + " flag:" + focusFlag);
    if (focusFlag) {
        if (KeyEvent.KEYCODE_DPAD_LEFT == keyCode) {
            if (mCurrentIndex > 0) {
                mViews[--mCurrentIndex].requestFocus();
            }
            return true;
        } else if (KeyEvent.KEYCODE_DPAD_RIGHT == keyCode) {
            if (mCurrentIndex < 2) {
                mViews[++mCurrentIndex].requestFocus();
            }
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}
 
源代码3 项目: DevUtils   文件: ViewUtils.java
/**
 * 获取是否当前 View 就是焦点 View
 * @param view {@link View}
 * @return {@code true} yes, {@code false} no
 */
public static boolean isFocused(final View view) {
    if (view != null) {
        return view.isFocused();
    }
    return false;
}
 
源代码4 项目: ViewPrinter   文件: DocumentView.java
@Override
public void onLayoutChange(View view, int left, int top, int right, int bottom,
                           int oldLeft, int oldTop, int oldRight, int oldBottom) {
    if (view.isFocused() && view instanceof TextView) {
        // A focused view changed its bounds. Follow it?
        int height = bottom - top;
        int oldHeight = oldBottom - oldTop;
        if (oldHeight != height) {
            zoomToView(view, false);
        }
    } else {
        view.removeOnLayoutChangeListener(this);
    }
}
 
源代码5 项目: revolution-irc   文件: LabelLayout.java
private static boolean hasFocusedChild(View view) {
    if (view.isFocused())
        return true;
    if (view instanceof ViewGroup) {
        ViewGroup group = (ViewGroup) view;
        for (int i = 0; i < group.getChildCount(); i++) {
            if (hasFocusedChild(group.getChildAt(i)))
                return true;
        }
    }
    return false;
}
 
源代码6 项目: HgLauncher   文件: ActivityServiceUtils.java
/**
 * Show the software keyboard and request focus to a certain input field.
 *
 * @param activity The activity hosting the view to be in focus.
 * @param view     The view requesting focus.
 */
public static void showSoftKeyboard(Activity activity, View view) {
    InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(
            Activity.INPUT_METHOD_SERVICE);
    
    if (!view.isFocused()) {
        view.requestFocus();
    }

    if (inputMethodManager != null) {
        inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
    }
}
 
源代码7 项目: HgLauncher   文件: ActivityServiceUtils.java
/**
 * Show the software keyboard and request focus to a certain input field.
 *
 * @param activity The activity hosting the view to be in focus.
 * @param view     The view requesting focus.
 */
public static void showSoftKeyboard(Activity activity, View view) {
    InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(
            Activity.INPUT_METHOD_SERVICE);
    
    if (!view.isFocused()) {
        view.requestFocus();
    }

    if (inputMethodManager != null) {
        inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
    }
}
 
源代码8 项目: kripton   文件: RecyclerView.java
private int getDeepestFocusedViewWithId(View view) {
    int lastKnownId = view.getId();
    while (!view.isFocused() && view instanceof ViewGroup && view.hasFocus()) {
        view = ((ViewGroup) view).getFocusedChild();
        final int id = view.getId();
        if (id != View.NO_ID) {
            lastKnownId = view.getId();
        }
    }
    return lastKnownId;
}
 
源代码9 项目: aedict   文件: AndroidTester.java
/**
 * Sets focus on given view.
 * 
 * @param view
 *            the view to focus.
 */
public void focus(final View view) {
	if (view.isFocused()) {
		return;
	}
	if (!view.isFocusable()) {
		throw new AssertionError("The view " + view.getId() + " is not focusable");
	}
	if (!view.requestFocus()) {
		throw new AssertionError("The view " + view.getId() + " did not took the focus");
	}
}
 
源代码10 项目: letv   文件: NestedScrollView.java
public boolean arrowScroll(int direction) {
    View currentFocused = findFocus();
    if (currentFocused == this) {
        currentFocused = null;
    }
    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);
    int maxJump = getMaxScrollAmount();
    if (nextFocused == null || !isWithinDeltaOfScreen(nextFocused, maxJump, getHeight())) {
        int scrollDelta = maxJump;
        if (direction == 33 && getScrollY() < scrollDelta) {
            scrollDelta = getScrollY();
        } else if (direction == 130 && getChildCount() > 0) {
            int daBottom = getChildAt(0).getBottom();
            int screenBottom = (getScrollY() + getHeight()) - getPaddingBottom();
            if (daBottom - screenBottom < maxJump) {
                scrollDelta = daBottom - screenBottom;
            }
        }
        if (scrollDelta == 0) {
            return false;
        }
        int i;
        if (direction == 130) {
            i = scrollDelta;
        } else {
            i = -scrollDelta;
        }
        doScrollY(i);
    } else {
        nextFocused.getDrawingRect(this.mTempRect);
        offsetDescendantRectToMyCoords(nextFocused, this.mTempRect);
        doScrollY(computeScrollDeltaToGetChildRectOnScreen(this.mTempRect));
        nextFocused.requestFocus(direction);
    }
    if (currentFocused != null && currentFocused.isFocused() && isOffScreen(currentFocused)) {
        int descendantFocusability = getDescendantFocusability();
        setDescendantFocusability(131072);
        requestFocus();
        setDescendantFocusability(descendantFocusability);
    }
    return true;
}
 
源代码11 项目: android-test   文件: ViewMatchers.java
@Override
public boolean matchesSafely(View view) {
  return view.isFocused() == isFocused;
}
 
 方法所在类
 同类方法