Example usage for android.view View isFocusable

List of usage examples for android.view View isFocusable

Introduction

In this page you can find the example usage for android.view View isFocusable.

Prototype

@ViewDebug.ExportedProperty(category = "focus")
public final boolean isFocusable() 

Source Link

Document

Returns whether this View is currently able to take focus.

Usage

From source file:Main.java

public static void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {
    int childCount = viewGroup.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View view = viewGroup.getChildAt(i);
        if (view.isFocusable())
            view.setEnabled(enabled);/*from  w  w w.  jav  a2s.  c o m*/
        if (view instanceof ViewGroup) {
            enableDisableViewGroup((ViewGroup) view, enabled);
        } else if (view instanceof ListView) {
            if (view.isFocusable())
                view.setEnabled(enabled);
            ListView listView = (ListView) view;
            int listChildCount = listView.getChildCount();
            for (int j = 0; j < listChildCount; j++) {
                if (view.isFocusable())
                    listView.getChildAt(j).setEnabled(false);
            }
        }
    }
}

From source file:com.google.android.apps.common.testing.accessibility.framework.ViewAccessibilityUtils.java

/**
 * Determines if the supplied {@link View} is actionable for accessibility purposes.
 *
 * @param view The {@link View} to evaluate
 * @return {@code true} if {@code view} is considered actionable for accessibility
 *//*  w  w  w  . ja v  a  2s .  co m*/
public static boolean isActionableForAccessibility(View view) {
    if (view == null) {
        return false;
    }

    return (view.isClickable() || view.isLongClickable() || view.isFocusable());
}

From source file:com.lamcreations.scaffold.common.views.CollapsingToolbarTabLayout.java

private View getDummyView() {
    if (mDummyView == null) {
        Toolbar toolBar = (Toolbar) findViewById(R.id.scaffold_toolbar);
        int size = toolBar.getChildCount();
        for (int i = 0; i < size; ++i) {
            View view = toolBar.getChildAt(i);
            if (!view.isFocusable() && !view.isClickable()) {
                mDummyView = view;/*from   w w w  . j ava  2 s.c o m*/
            }
        }
    }
    return mDummyView;
}

From source file:com.esri.android.maps.app.MapAppRobotiumTests.java

/**
 * Sanity check presence of UI widgets that
 * should be present at startup//from   w ww.j a v a  2  s .com
 */
public void testWidgetsOnStartup() {
    // Map view
    View mapView = solo.getView(id.map);
    Assert.assertTrue(solo.waitForView(mapView));

    // FAB
    View fab = solo.getView(id.fab);
    Assert.assertTrue(fab.isClickable());

    // Drawer
    solo.clickOnImageButton(0);
    solo.takeScreenshot("drawer");
    Assert.assertTrue(solo.searchText(solo.getString(string.signin)));
    solo.searchText(solo.getString(string.switch_basemap));
    solo.setNavigationDrawer(Solo.CLOSED);

    // Dismiss the drawer
    solo.clickOnView(mapView, true);

    // Search view
    View searchView = solo.getView(id.searchView1);
    Assert.assertTrue(searchView.isFocusable());
}

From source file:android.support.car.app.CarFragmentActivity.java

private static String viewToString(View view) {
    StringBuilder out = new StringBuilder(128);
    out.append(view.getClass().getName());
    out.append('{');
    out.append(Integer.toHexString(System.identityHashCode(view)));
    out.append(' ');
    switch (view.getVisibility()) {
    case View.VISIBLE:
        out.append('V');
        break;//  w w w.j a v a  2s  .  co  m
    case View.INVISIBLE:
        out.append('I');
        break;
    case View.GONE:
        out.append('G');
        break;
    default:
        out.append('.');
        break;
    }
    out.append(view.isFocusable() ? 'F' : '.');
    out.append(view.isEnabled() ? 'E' : '.');
    out.append(view.willNotDraw() ? '.' : 'D');
    out.append(view.isHorizontalScrollBarEnabled() ? 'H' : '.');
    out.append(view.isVerticalScrollBarEnabled() ? 'V' : '.');
    out.append(view.isClickable() ? 'C' : '.');
    out.append(view.isLongClickable() ? 'L' : '.');
    out.append(' ');
    out.append(view.isFocused() ? 'F' : '.');
    out.append(view.isSelected() ? 'S' : '.');
    out.append(view.isPressed() ? 'P' : '.');
    out.append(' ');
    out.append(view.getLeft());
    out.append(',');
    out.append(view.getTop());
    out.append('-');
    out.append(view.getRight());
    out.append(',');
    out.append(view.getBottom());
    final int id = view.getId();
    if (id != View.NO_ID) {
        out.append(" #");
        out.append(Integer.toHexString(id));
        final Resources r = view.getResources();
        if (id != 0 && r != null) {
            try {
                String pkgname;
                switch (id & 0xff000000) {
                case 0x7f000000:
                    pkgname = "app";
                    break;
                case 0x01000000:
                    pkgname = "android";
                    break;
                default:
                    pkgname = r.getResourcePackageName(id);
                    break;
                }
                String typename = r.getResourceTypeName(id);
                String entryname = r.getResourceEntryName(id);
                out.append(" ");
                out.append(pkgname);
                out.append(":");
                out.append(typename);
                out.append("/");
                out.append(entryname);
            } catch (Resources.NotFoundException e) {
            }
        }
    }
    out.append("}");
    return out.toString();
}

From source file:com.facebook.litho.MountItem.java

void init(Component<?> component, ComponentHost host, Object content, NodeInfo nodeInfo,
        ViewNodeInfo viewNodeInfo, DisplayListDrawable displayListDrawable, int flags,
        int importantForAccessibility) {
    mComponent = component;/*  w ww  .j a v  a  2 s.co  m*/
    mContent = content;
    mHost = host;
    mFlags = flags;
    mImportantForAccessibility = importantForAccessibility;
    mDisplayListDrawable = displayListDrawable;

    if (mNodeInfo != null) {
        mNodeInfo.release();
        mNodeInfo = null;
    }

    if (nodeInfo != null) {
        mNodeInfo = nodeInfo.acquireRef();
    }

    if (mViewNodeInfo != null) {
        mViewNodeInfo.release();
        mViewNodeInfo = null;
    }

    if (viewNodeInfo != null) {
        mViewNodeInfo = viewNodeInfo.acquireRef();
    }

    if (mContent instanceof View) {
        final View view = (View) mContent;

        if (view.isClickable()) {
            mFlags |= FLAG_VIEW_CLICKABLE;
        }

        if (view.isLongClickable()) {
            mFlags |= FLAG_VIEW_LONG_CLICKABLE;
        }

        if (view.isFocusable()) {
            mFlags |= FLAG_VIEW_FOCUSABLE;
        }
    }
}

From source file:de.lmu.ifi.medien.probui.system.ProbUIManager.java

public void manageHelper(MotionEvent ev) throws WrongObservationDelegationException {

    this.currentTouchObservations.clear();

    int action = MotionEventCompat.getActionMasked(ev);
    int index = MotionEventCompat.getActionIndex(ev);
    int pointerID = ev.getPointerId(index);

    int type = -1;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_POINTER_DOWN:
        type = ProbObservationTouch.TYPE_TOUCH_DOWN;
        break;//from   ww  w . java 2 s.  c o m
    case MotionEvent.ACTION_MOVE:
        type = ProbObservationTouch.TYPE_TOUCH_MOVE;
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
        type = ProbObservationTouch.TYPE_TOUCH_UP;
        break;
    default:
        type = -1;
        break;
    }

    long timestamp = ev.getEventTime();

    ProbObservationTouch observation = ProbObservationFactory.createTouchObservation(ev.getX(index),
            ev.getY(index), ev.getX(index) * 1.0 / container.getWidth(),
            ev.getY(index) * 1.0 / container.getHeight(), ev.getOrientation(index),
            ev.getTouchMinor(index) * 1.0 / container.getWidth(),
            ev.getTouchMajor(index) * 1.0 / container.getHeight(), ev.getPressure(index), type, pointerID,
            timestamp);
    this.currentTouchObservations.add(observation);

    // Since move is always associated with the first pointer,
    // we need to manually duplicate it for the second one
    // (TODO: and for further pointers, if we change it to more than 2):
    if (ev.getPointerCount() == 2 && type == ProbObservationTouch.TYPE_TOUCH_MOVE) {
        ProbObservationTouch observation2 = ProbObservationFactory.createTouchObservation(ev.getX(index),
                ev.getY(index), ev.getX(1) * 1.0 / container.getWidth(),
                ev.getY(1) * 1.0 / container.getHeight(), ev.getOrientation(1),
                ev.getToolMinor(1) * 1.0 / container.getWidth(),
                ev.getToolMajor(1) * 1.0 / container.getHeight(), ev.getPressure(1), type, ev.getPointerId(1),
                timestamp);
        this.currentTouchObservations.add(observation2);
    }

    //Log.d("MULTITOUCH", "type: " + type + ", index: " + pointerID + ", size: " + ev.getTouchMajor(index) * 1.0 / container.getHeight());

    // Distribute touch observation to the cores of all probInteractors
    // (for reasoning by these interactor cores!, not for visual feedback etc. - that comes below: interactor.onTouchDown etc.)
    boolean passedOn = false;
    for (ProbInteractor interactor : this.probInteractors) {

        for (int i = 0; i < this.currentTouchObservations.size(); i++) {
            ProbObservationTouch obs = this.currentTouchObservations.get(i);
            if (obs == null)
                continue;
            if (obs.getNominalFeatures()[0] != ProbObservationTouch.TYPE_TOUCH_MOVE
                    || this.currentTouchObservations.size() != this.previousTouchObservations.size()) {
                interactor.getCore().onTouchObservation(obs);
                passedOn = true;
            } else { // This code filters out move events that moved very little (potentially improves performance):
                double[] obsXY = this.currentTouchObservations.get(i).getRealFeatures();
                double[] obsPrevXY = this.previousTouchObservations.get(i).getRealFeatures();
                double dx = obsXY[0] - obsPrevXY[0];
                double dy = obsXY[1] - obsPrevXY[1];
                double dist = Math.sqrt(dx * dx + dy * dy);
                if (dist > 0.0125) { // TODO: movement threshold currently hardcoded: 0.0125
                    interactor.getCore().onTouchObservation(obs);
                    passedOn = true;
                } else {
                }
            }
        }

    }

    if (passedOn) {
        this.previousTouchObservations.clear();
        this.previousTouchObservations.addAll(this.currentTouchObservations);
    }

    // Forward the touch observation for probInteractors
    // to react (e.g. visual feedback, triggering actions, nothing to do with the mediation):
    for (ProbInteractor interactor : this.probInteractors) {
        for (ProbObservationTouch obs : this.currentTouchObservations) {
            if (obs != null) {
                switch (obs.getNominalFeatures()[0]) {

                case ProbObservationTouch.TYPE_TOUCH_DOWN:
                    interactor.onTouchDown(obs);
                    break;

                case ProbObservationTouch.TYPE_TOUCH_MOVE:
                    interactor.onTouchMove(obs);
                    break;

                case ProbObservationTouch.TYPE_TOUCH_UP:
                    interactor.onTouchUp(obs, ev.getPointerCount() - 1);
                    break;
                default:
                    break;
                }
            }
        }
    }

    // If no element is determined yet (i.e. no decision yet), update the reasoning process.
    if (!isOneDetermined() && passedOn) {
        this.mediator.mediate(false);
    }

    // Post mediation: Forward the touch observation again
    // to the post-mediation versions of the onTouch... methods
    for (ProbInteractor interactor : this.probInteractors) {
        for (ProbObservationTouch obs : this.currentTouchObservations) {
            if (obs != null) {
                switch (obs.getNominalFeatures()[0]) {

                case ProbObservationTouch.TYPE_TOUCH_DOWN:
                    interactor.onTouchDownPost(obs);
                    break;

                case ProbObservationTouch.TYPE_TOUCH_MOVE:
                    interactor.onTouchMovePost(obs);
                    break;

                case ProbObservationTouch.TYPE_TOUCH_UP:
                    interactor.onTouchUpPost(obs, ev.getPointerCount() - 1);
                    break;
                default:
                    break;
                }
            }
        }
    }

    // Pass on to other GUI elements:
    if (!isOneDetermined()) {
        for (View view : this.nonProbInteractors) {
            if (view.isFocusable() && view.isEnabled())
                view.onTouchEvent(ev);
        }
    }
}

From source file:com.android.mail.browse.ConversationViewAdapter.java

public boolean focusFirstMessageHeader() {
    if (mItems.size() > 1) {
        final View v = mItems.get(1).getFocusableView();
        if (v != null && v.isShown() && v.isFocusable()) {
            v.requestFocus();/*from w w w  .  j a v  a 2  s.co m*/
            return true;
        }
    }
    return false;
}

From source file:com.android.mail.browse.ConversationViewAdapter.java

/**
 * Find the next view that should grab focus with respect to the current position.
 *///from   ww w  .  jav  a  2s  .co m
public View getNextOverlayView(View curr, boolean isDown, Set<View> scraps) {
    // First find the root view of the overlay item
    while (curr.getTag() != OVERLAY_ITEM_ROOT_TAG) {
        final ViewParent parent = curr.getParent();
        if (parent != null && parent instanceof View) {
            curr = (View) parent;
        } else {
            return null;
        }
    }

    // Find the position of the root view
    for (int i = 0; i < mItems.size(); i++) {
        if (mItems.get(i).mRootView == curr) {
            // Found view, now find the next applicable view
            if (isDown && i >= 0) {
                while (++i < mItems.size()) {
                    final ConversationOverlayItem item = mItems.get(i);
                    final View next = item.getFocusableView();
                    if (item.mRootView != null && !scraps.contains(item.mRootView) && next != null
                            && next.isFocusable()) {
                        return next;
                    }
                }
            } else {
                while (--i >= 0) {
                    final ConversationOverlayItem item = mItems.get(i);
                    final View next = item.getFocusableView();
                    if (item.mRootView != null && !scraps.contains(item.mRootView) && next != null
                            && next.isFocusable()) {
                        return next;
                    }
                }
            }
            return null;
        }
    }
    return null;
}

From source file:com.tct.mail.browse.ConversationViewAdapter.java

/**
 * Find the next view that should grab focus with respect to the current position.
 *//*from w w  w.  j  a v  a  2s. c  o m*/
public View getNextOverlayView(int position, boolean isDown) {
    if (isDown && position >= 0) {
        while (++position < mItems.size()) {
            final View v = mItems.get(position).getFocusableView();
            if (v != null && v.isFocusable()) {
                return v;
            }
        }
    } else {
        while (--position >= 0) {
            final View v = mItems.get(position).getFocusableView();
            if (v != null && v.isFocusable()) {
                return v;
            }
        }
    }
    // Special case two end points
    if ((position == 0 && !isDown) || (position == mItems.size() - 1 && isDown)) {

    }
    return null;
}