Example usage for android.view View isClickable

List of usage examples for android.view View isClickable

Introduction

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

Prototype

@ViewDebug.ExportedProperty
public boolean isClickable() 

Source Link

Document

Indicates whether this view reacts to click events or not.

Usage

From source file:Main.java

public static boolean isClickable(Object v) {
    if (!(v instanceof View)) {
        return true;
    }//from  ww w.jav a  2 s .  c  o m
    View view = (View) v;

    return view.isClickable();
}

From source file:Main.java

public static void lockForOneSec(final View view) {
    if (!view.isClickable())
        return;/*w  w w .  j a v a 2  s.c om*/
    view.setClickable(false);
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            if (view == null)
                return;
            view.setClickable(true);
        }
    }, 1000);
}

From source file:Main.java

public static void traverseAndRecolor(View root, int color, boolean withStates,
        boolean setClickableItemBackgrounds) {
    Context context = root.getContext();

    if (setClickableItemBackgrounds && root.isClickable()) {
        StateListDrawable selectableItemBackground = new StateListDrawable();
        selectableItemBackground.addState(new int[] { android.R.attr.state_pressed },
                new ColorDrawable((color & 0xffffff) | 0x33000000));
        selectableItemBackground.addState(new int[] { android.R.attr.state_focused },
                new ColorDrawable((color & 0xffffff) | 0x44000000));
        selectableItemBackground.addState(new int[] {}, null);
        root.setBackground(selectableItemBackground);
    }//ww w .j a va2s  .c o m

    if (root instanceof ViewGroup) {
        ViewGroup parent = (ViewGroup) root;
        for (int i = 0; i < parent.getChildCount(); i++) {
            traverseAndRecolor(parent.getChildAt(i), color, withStates, setClickableItemBackgrounds);
        }

    } else if (root instanceof ImageView) {
        ImageView imageView = (ImageView) root;
        Drawable sourceDrawable = imageView.getDrawable();
        if (withStates && sourceDrawable != null && sourceDrawable instanceof BitmapDrawable) {
            imageView.setImageDrawable(
                    makeRecoloredDrawable(context, (BitmapDrawable) sourceDrawable, color, true));
        } else {
            imageView.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
        }

    } else if (root instanceof TextView) {
        TextView textView = (TextView) root;
        if (withStates) {
            int sourceColor = textView.getCurrentTextColor();
            ColorStateList colorStateList = new ColorStateList(
                    new int[][] { new int[] { android.R.attr.state_pressed },
                            new int[] { android.R.attr.state_focused }, new int[] {} },
                    new int[] { sourceColor, sourceColor, color });
            textView.setTextColor(colorStateList);
        } else {
            textView.setTextColor(color);
        }

    } else if (root instanceof AnalogClock) {
        AnalogClock analogClock = (AnalogClock) root;
        try {
            Field hourHandField = AnalogClock.class.getDeclaredField("mHourHand");
            hourHandField.setAccessible(true);
            Field minuteHandField = AnalogClock.class.getDeclaredField("mMinuteHand");
            minuteHandField.setAccessible(true);
            Field dialField = AnalogClock.class.getDeclaredField("mDial");
            dialField.setAccessible(true);
            BitmapDrawable hourHand = (BitmapDrawable) hourHandField.get(analogClock);
            if (hourHand != null) {
                Drawable d = makeRecoloredDrawable(context, hourHand, color, withStates);
                d.setCallback(analogClock);
                hourHandField.set(analogClock, d);
            }
            BitmapDrawable minuteHand = (BitmapDrawable) minuteHandField.get(analogClock);
            if (minuteHand != null) {
                Drawable d = makeRecoloredDrawable(context, minuteHand, color, withStates);
                d.setCallback(analogClock);
                minuteHandField.set(analogClock, d);
            }
            BitmapDrawable dial = (BitmapDrawable) dialField.get(analogClock);
            if (dial != null) {
                Drawable d = makeRecoloredDrawable(context, dial, color, withStates);
                d.setCallback(analogClock);
                dialField.set(analogClock, d);
            }
        } catch (NoSuchFieldException ignored) {
        } catch (IllegalAccessException ignored) {
        } catch (ClassCastException ignored) {
        } // TODO: catch all exceptions?
    }
}

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
 *///from w w  w  .  ja va  2s  . c  o  m
public static boolean isActionableForAccessibility(View view) {
    if (view == null) {
        return false;
    }

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

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;//from www . java 2 s  .  c o 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:com.esri.android.maps.app.MapAppRobotiumTests.java

/**
 * Sanity check presence of UI widgets that
 * should be present at startup//from w w w. ja v  a  2s.c o m
 */
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: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   www  . j a  v a 2  s  . c om
            }
        }
    }
    return mDummyView;
}

From source file:io.github.meness.easyintro.EasyIntroFragment.java

@Override
@CallSuper/*from  w w w  . j av a  2 s .com*/
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    // set view clickable property true to prevent passing click event to its parent
    if (!view.isClickable()) {
        view.setClickable(true);
    }
}

From source file:com.xinkaishi.apple.xinweidian.CustomView.PinnedHeaderExpandableListView.java

private boolean isTouchPointInView(View view, int x, int y) {
    if (view.isClickable() && y >= view.getTop() && y <= view.getBottom() && x >= view.getLeft()
            && x <= view.getRight()) {
        return true;
    }//from   ww w. j ava  2  s . c om
    return false;
}

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;/*from  ww  w .ja  v  a  2  s  . c o  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();
}