Example usage for android.view ViewGroup FOCUS_BEFORE_DESCENDANTS

List of usage examples for android.view ViewGroup FOCUS_BEFORE_DESCENDANTS

Introduction

In this page you can find the example usage for android.view ViewGroup FOCUS_BEFORE_DESCENDANTS.

Prototype

int FOCUS_BEFORE_DESCENDANTS

To view the source code for android.view ViewGroup FOCUS_BEFORE_DESCENDANTS.

Click Source Link

Document

This view will get focus before any of its descendants.

Usage

From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.SurveyFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ImageButton infoButton = (ImageButton) view.findViewById(R.id.info);
    infoButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(final View view) {
            // Set info button not clickable when it was first clicked
            view.setClickable(false);//  ww  w .j  av a 2 s .c  o m
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    final Handler handler = new Handler();
                    handler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            view.setClickable(true);
                        }
                    }, 100);

                }
            });
            ApptentiveInternal.getInstance().showAboutInternal(getActivity(), false);
        }
    });
    scrollView = (ApptentiveNestedScrollView) view.findViewById(R.id.survey_scrollview);
    scrollView.setOnScrollChangeListener(this);

    /* Android's ScrollView (when scrolled or fling'd) by default always set the focus to an EditText when
     * it's one of it's children.
     * The following is needed to change this behavior such that touching outside EditText would take
     * away the focus
     */
    scrollView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
    scrollView.setFocusable(true);
    scrollView.setFocusableInTouchMode(true);
    scrollView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            v.requestFocusFromTouch();
            Util.hideSoftKeyboard(getContext(), v);
            return false;
        }
    });

    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

}

From source file:org.yammp.fragment.ArtistFragment.java

@Override
public void onNothingSelected(AdapterView<?> arg0) {
    if (!mListView.isFocused()) {
        mListView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
        mListView.requestFocus();/*from w ww. j  a v a2 s. co  m*/
    }
}

From source file:org.chromium.chrome.browser.autofill.CardUnmaskPrompt.java

/**
 * Updates the verification overlay and main contents such that the overlay has |visibility|.
 * @param visibility A View visibility enumeration value.
 *//*ww w . j  a v a  2s  . c  om*/
private void setOverlayVisibility(int visibility) {
    mVerificationOverlay.setVisibility(visibility);
    mControlsContainer.setAlpha(1f);
    boolean contentsShowing = visibility == View.GONE;
    if (!contentsShowing) {
        int durationMs = 250;
        mVerificationOverlay.setAlpha(0f);
        mVerificationOverlay.animate().alpha(1f).setDuration(durationMs);
        mControlsContainer.animate().alpha(0f).setDuration(durationMs);
    }
    ViewCompat.setImportantForAccessibility(mControlsContainer,
            contentsShowing ? View.IMPORTANT_FOR_ACCESSIBILITY_AUTO
                    : View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
    mControlsContainer.setDescendantFocusability(
            contentsShowing ? ViewGroup.FOCUS_BEFORE_DESCENDANTS : ViewGroup.FOCUS_BLOCK_DESCENDANTS);
}

From source file:android.support.v17.leanback.widget.GuidedActionsStylist.java

/**
 * Binds a {@link ViewHolder} to a particular {@link GuidedAction}.
 * @param vh The view holder to be associated with the given action.
 * @param action The guided action to be displayed by the view holder's view.
 * @return The view to be added to the caller's view hierarchy.
 *//* w  ww.  j a v  a  2s  .  co  m*/
public void onBindViewHolder(ViewHolder vh, GuidedAction action) {

    vh.mAction = action;
    if (vh.mTitleView != null) {
        vh.mTitleView.setText(action.getTitle());
        vh.mTitleView.setAlpha(action.isEnabled() ? mEnabledTextAlpha : mDisabledTextAlpha);
        vh.mTitleView.setFocusable(false);
        vh.mTitleView.setClickable(false);
        vh.mTitleView.setLongClickable(false);
    }
    if (vh.mDescriptionView != null) {
        vh.mDescriptionView.setText(action.getDescription());
        vh.mDescriptionView
                .setVisibility(TextUtils.isEmpty(action.getDescription()) ? View.GONE : View.VISIBLE);
        vh.mDescriptionView.setAlpha(action.isEnabled() ? mEnabledDescriptionAlpha : mDisabledDescriptionAlpha);
        vh.mDescriptionView.setFocusable(false);
        vh.mDescriptionView.setClickable(false);
        vh.mDescriptionView.setLongClickable(false);
    }
    // Clients might want the check mark view to be gone entirely, in which case, ignore it.
    if (vh.mCheckmarkView != null) {
        onBindCheckMarkView(vh, action);
    }
    setIcon(vh.mIconView, action);

    if (action.hasMultilineDescription()) {
        if (vh.mTitleView != null) {
            setMaxLines(vh.mTitleView, mTitleMaxLines);
            if (vh.mDescriptionView != null) {
                vh.mDescriptionView
                        .setMaxHeight(getDescriptionMaxHeight(vh.itemView.getContext(), vh.mTitleView));
            }
        }
    } else {
        if (vh.mTitleView != null) {
            setMaxLines(vh.mTitleView, mTitleMinLines);
        }
        if (vh.mDescriptionView != null) {
            setMaxLines(vh.mDescriptionView, mDescriptionMinLines);
        }
    }
    if (vh.mActivatorView != null) {
        onBindActivatorView(vh, action);
    }
    setEditingMode(vh, action, false);
    if (action.isFocusable()) {
        vh.itemView.setFocusable(true);
        ((ViewGroup) vh.itemView).setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
    } else {
        vh.itemView.setFocusable(false);
        ((ViewGroup) vh.itemView).setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
    }
    setupImeOptions(vh, action);

    updateChevronAndVisibility(vh);
}

From source file:com.apptentive.android.sdk.view.ApptentiveNestedScrollView.java

/**
 * Handle scrolling in response to an up or down arrow click.
 *
 * @param direction The direction corresponding to the arrow key that was
 *                  pressed//from  w  ww  .  j a v  a 2s. c  o  m
 * @return True if we consumed the event, false otherwise
 */
public boolean arrowScroll(int direction) {

    View currentFocused = findFocus();
    if (currentFocused == this)
        currentFocused = null;

    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);

    final int maxJump = getMaxScrollAmount();

    if (nextFocused != null && isWithinDeltaOfScreen(nextFocused, maxJump, getHeight())) {
        nextFocused.getDrawingRect(mTempRect);
        offsetDescendantRectToMyCoords(nextFocused, mTempRect);
        int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
        doScrollY(scrollDelta);
        nextFocused.requestFocus(direction);
    } else {
        // no new focus
        int scrollDelta = maxJump;

        if (direction == View.FOCUS_UP && getScrollY() < scrollDelta) {
            scrollDelta = getScrollY();
        } else if (direction == View.FOCUS_DOWN) {
            if (getChildCount() > 0) {
                int daBottom = getChildAt(0).getBottom();
                int screenBottom = getScrollY() + getHeight() - getPaddingBottom();
                if (daBottom - screenBottom < maxJump) {
                    scrollDelta = daBottom - screenBottom;
                }
            }
        }
        if (scrollDelta == 0) {
            return false;
        }
        doScrollY(direction == View.FOCUS_DOWN ? scrollDelta : -scrollDelta);
    }

    if (currentFocused != null && currentFocused.isFocused() && isOffScreen(currentFocused)) {
        // previously focused item still has focus and is off screen, give
        // it up (take it back to ourselves)
        // (also, need to temporarily force FOCUS_BEFORE_DESCENDANTS so we are
        // sure to
        // get it)
        final int descendantFocusability = getDescendantFocusability(); // save
        setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
        requestFocus();
        setDescendantFocusability(descendantFocusability); // restore
    }
    return true;
}

From source file:com.peerless2012.twowaynestedscrollview.TwoWayNestedScrollView.java

/**
 * Handle scrolling in response to an up or down arrow click.
 *
 * @param direction//from  w w  w.  j  av  a2 s  .co m
 *            The direction corresponding to the arrow key that was pressed
 * @return True if we consumed the event, false otherwise
 */
public boolean arrowScroll(int direction) {

    View currentFocused = findFocus();
    if (currentFocused == this)
        currentFocused = null;

    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);

    final int maxJump = getMaxScrollYAmount();

    if (nextFocused != null && isWithinDeltaOfScreen(nextFocused, maxJump, getHeight())) {
        nextFocused.getDrawingRect(mTempRect);
        offsetDescendantRectToMyCoords(nextFocused, mTempRect);
        int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
        doScrollY(scrollDelta);
        nextFocused.requestFocus(direction);
    } else {
        // no new focus
        int scrollDelta = maxJump;

        if (direction == View.FOCUS_UP && getScrollY() < scrollDelta) {
            scrollDelta = getScrollY();
        } else if (direction == View.FOCUS_DOWN) {
            if (getChildCount() > 0) {
                int daBottom = getChildAt(0).getBottom();
                int screenBottom = getScrollY() + getHeight() - getPaddingBottom();
                if (daBottom - screenBottom < maxJump) {
                    scrollDelta = daBottom - screenBottom;
                }
            }
        }
        if (scrollDelta == 0) {
            return false;
        }
        doScrollY(direction == View.FOCUS_DOWN ? scrollDelta : -scrollDelta);
    }

    if (currentFocused != null && currentFocused.isFocused() && isOffScreen(currentFocused)) {
        // previously focused item still has focus and is off screen, give
        // it up (take it back to ourselves)
        // (also, need to temporarily force FOCUS_BEFORE_DESCENDANTS so we
        // are
        // sure to
        // get it)
        final int descendantFocusability = getDescendantFocusability(); // save
        setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
        requestFocus();
        setDescendantFocusability(descendantFocusability); // restore
    }
    return true;
}

From source file:com.hippo.widget.BothScrollView.java

/**
 * Handle scrolling in response to a left or right arrow click.
 *
 * @param direction The direction corresponding to the arrow key that was
 *                  pressed/*from   ww  w .  jav  a2 s.  c  o m*/
 * @return True if we consumed the event, false otherwise
 */
public boolean arrowScrollHorizontally(int direction) {

    View currentFocused = findFocus();
    if (currentFocused == this)
        currentFocused = null;

    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);

    final int maxJump = getHorizontalMaxScrollAmount();

    if (nextFocused != null && isWithinDeltaOfScreen(nextFocused, maxJump, getWidth(), getHeight())) {
        nextFocused.getDrawingRect(mTempRect);
        offsetDescendantRectToMyCoords(nextFocused, mTempRect);
        int scrollDelta = computeScrollXDeltaToGetChildRectOnScreen(mTempRect);
        doScrollX(scrollDelta);
        nextFocused.requestFocus(direction);
    } else {
        // no new focus
        int scrollDelta = maxJump;

        if (direction == View.FOCUS_LEFT && getScrollX() < scrollDelta) {
            scrollDelta = getScrollX();
        } else if (direction == View.FOCUS_RIGHT && getChildCount() > 0) {

            int daRight = getChildAt(0).getRight();

            int screenRight = getScrollX() + getWidth() - getPaddingRight();

            if (daRight - screenRight < maxJump) {
                scrollDelta = daRight - screenRight;
            }
        }
        if (scrollDelta == 0) {
            return false;
        }
        doScrollX(direction == View.FOCUS_RIGHT ? scrollDelta : -scrollDelta);
    }

    if (currentFocused != null && currentFocused.isFocused() && isOffScreen(currentFocused)) {
        // previously focused item still has focus and is off screen, give
        // it up (take it back to ourselves)
        // (also, need to temporarily force FOCUS_BEFORE_DESCENDANTS so we are
        // sure to
        // get it)
        final int descendantFocusability = getDescendantFocusability(); // save
        setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
        requestFocus();
        setDescendantFocusability(descendantFocusability); // restore
    }
    return true;
}

From source file:com.hippo.widget.BothScrollView.java

/**
 * Handle scrolling in response to an up or down arrow click.
 *
 * @param direction The direction corresponding to the arrow key that was
 *                  pressed/*from   w w  w  . j  a v a 2  s .  c om*/
 * @return True if we consumed the event, false otherwise
 */
public boolean arrowScrollVertically(int direction) {

    View currentFocused = findFocus();
    if (currentFocused == this)
        currentFocused = null;

    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);

    final int maxJump = getVerticalMaxScrollAmount();

    if (nextFocused != null && isWithinDeltaOfScreen(nextFocused, maxJump, getWidth(), getHeight())) {
        nextFocused.getDrawingRect(mTempRect);
        offsetDescendantRectToMyCoords(nextFocused, mTempRect);
        int scrollDelta = computeScrollYDeltaToGetChildRectOnScreen(mTempRect);
        doScrollY(scrollDelta);
        nextFocused.requestFocus(direction);
    } else {
        // no new focus
        int scrollDelta = maxJump;

        if (direction == View.FOCUS_UP && getScrollY() < scrollDelta) {
            scrollDelta = getScrollY();
        } else if (direction == View.FOCUS_DOWN) {
            if (getChildCount() > 0) {
                int daBottom = getChildAt(0).getBottom();
                int screenBottom = getScrollY() + getHeight() - getPaddingBottom();
                if (daBottom - screenBottom < maxJump) {
                    scrollDelta = daBottom - screenBottom;
                }
            }
        }
        if (scrollDelta == 0) {
            return false;
        }
        doScrollY(direction == View.FOCUS_DOWN ? scrollDelta : -scrollDelta);
    }

    if (currentFocused != null && currentFocused.isFocused() && isOffScreen(currentFocused)) {
        // previously focused item still has focus and is off screen, give
        // it up (take it back to ourselves)
        // (also, need to temporarily force FOCUS_BEFORE_DESCENDANTS so we are
        // sure to
        // get it)
        final int descendantFocusability = getDescendantFocusability(); // save
        setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
        requestFocus();
        setDescendantFocusability(descendantFocusability); // restore
    }
    return true;
}