Example usage for android.view View getClass

List of usage examples for android.view View getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:Main.java

public static String getViewLogTag(View v) {
    return v.getClass().getSimpleName() + "[" + v.getTag() + "]";
}

From source file:Main.java

/**
 * Gets the type.//ww w  .j  a  va 2  s  .c o  m
 *
 * @param view the view
 * @return the type
 */
public static String getType(View view) {
    return view.getClass().getName();
}

From source file:Main.java

public static <T extends View> T findParentOfClass(View view, Class<T> theClass) {
    if (theClass.isAssignableFrom(view.getClass()))
        return (T) view;
    else if (view.getParent() != null && view.getParent() instanceof View)
        return findParentOfClass((View) view.getParent(), theClass);
    else//w w w.  j a v a2s  . com
        return null;
}

From source file:Main.java

public static <T extends View> T findParentView(View view, Class<T> c) {
    if (view == null || c == null)
        return null;
    View parent = (View) view.getParent();
    while (parent != null && !parent.getClass().equals(c)) {
        parent = (View) parent.getParent();
    }// ww w  .  ja  v  a  2  s  .c  om
    return (T) parent;
}

From source file:Main.java

private static View getFirstChildByClassName(ViewGroup parent, String name) {
    View retView = null;/*from w w w . j a  v  a  2 s.  c  om*/
    int childCount = parent.getChildCount();

    for (int childIndex = 0; childIndex < childCount; childIndex++) {
        View child = parent.getChildAt(childIndex);

        if (child.getClass().getName().equals(name)) {
            return child;
        }

        if (child instanceof ViewGroup) {
            View v = getFirstChildByClassName((ViewGroup) child, name);

            if (v != null) {
                return v;
            }
        }
    }

    return retView;
}

From source file:Main.java

/**
 * Measures the height of the changeView based on the size 
 * of the the view that should be expand, and returns it.
 * /*www . j  a  v a 2 s  .  co m*/
 * The two parameters are often the same (e.g. in case of a TextView,
 * it's content changes, so it should be measured again, 
 * and it will be the one that will be applied the animation to as well.
 * 
 * TODO: Add listener support for applied animation!
 */
private static int measureViewHeight(final View viewToExpand, final View changedView) {
    try {
        final Method m = changedView.getClass().getDeclaredMethod("onMeasure", int.class, int.class);
        m.setAccessible(true);
        m.invoke(changedView, MeasureSpec.makeMeasureSpec(viewToExpand.getWidth(), MeasureSpec.AT_MOST),
                MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    } catch (Exception e) {
        return -1;
    }
    int measuredHeight = changedView.getMeasuredHeight();
    return measuredHeight;
}

From source file:Main.java

public static <X extends View> X getChild(ViewGroup row, Class<X> klass) {
    assert klass != null;
    for (int i = 0; i < row.getChildCount(); i++) {
        View child = row.getChildAt(i);
        if (klass.isAssignableFrom(child.getClass())) {
            return klass.cast(child);
        }/*from w  ww  . ja  v a  2 s . com*/

        if (child instanceof ViewGroup) {
            X kid = getChild((ViewGroup) child, klass);
            if (kid != null)
                return kid;
        }
    }
    // fail
    return null;
}

From source file:Main.java

public static void findAllViews(ViewGroup parent, List<View> views, Class type) {
    for (int i = 0; i < parent.getChildCount(); i++) {
        View child = parent.getChildAt(i);
        if (child instanceof ViewGroup && child.getClass() != type) {
            findAllViews((ViewGroup) child, views, type);
        } else if (child != null) {
            if (child.getClass() == type) {
                views.add(child);//  ww w .j a  v  a 2  s . com
            }
        }
    }
}

From source file:Main.java

static void getSubviewsTree(ViewGroup parentView, Class<?> classOfSubviews, ArrayList<View> result) {
    for (int i = 0; i < parentView.getChildCount(); i++) {
        View child = parentView.getChildAt(i);
        if (classOfSubviews.isAssignableFrom(child.getClass()))
            result.add(child);/*from  ww  w. jav  a 2s  . c  om*/
        if (child instanceof ViewGroup)
            getSubviewsTree((ViewGroup) child, classOfSubviews, result);
    }
}

From source file:Main.java

private static <T extends View> T getFirstChildByInstance(ViewGroup parent, Class<T> instance) {
    View retView = null;//from w  w w.  ja  v  a 2s . c o m
    int childCount = parent.getChildCount();

    for (int childIndex = 0; childIndex < childCount; childIndex++) {
        View child = parent.getChildAt(childIndex);

        if (instance.isAssignableFrom(child.getClass())) {
            return instance.cast(child);
        }

        if (child instanceof ViewGroup) {
            View v = getFirstChildByInstance((ViewGroup) child, instance);

            if (v != null) {
                return instance.cast(v);
            }
        }
    }

    return instance.cast(retView);
}