Example usage for android.view ViewGroup getClass

List of usage examples for android.view ViewGroup getClass

Introduction

In this page you can find the example usage for android.view ViewGroup 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 void checkRecyclerView(ViewGroup recyclerView) {
    checkRecyclerViewOnClassPath();//from  w  w  w . j  av  a 2  s  .  co m

    Class clazz = recyclerView.getClass();
    while (clazz != null) {
        if (clazz.getName().equals(RECYCLERVIEW_CLASS_NAME)) {
            return;
        }
        clazz = clazz.getSuperclass();
    }

    throw new IllegalArgumentException("ViewGroup " + recyclerView.getClass().getName() + " not supported");

}

From source file:Main.java

public static MarginLayoutParams newLayoutParam(ViewGroup placer, int width, int height) {
    if (placer instanceof FrameLayout) {
        return new FrameLayout.LayoutParams(width, height);
    } else if (placer instanceof RelativeLayout) {
        return new RelativeLayout.LayoutParams(width, height);
    } else if (placer == null) {
        throw new NullPointerException("placer is null");
    } else {//  w ww  .  j a v a 2s.c  o  m
        throw new IllegalArgumentException(
                "placer is neither FrameLayout nor RelativeLayout: " + placer.getClass().getName());
    }
}

From source file:com.nttec.everychan.ui.theme.CustomThemeHelper.java

private static void setLollipopMenuOverflowIconColor(final ViewGroup toolbar, final int color) {
    try {//from www  . ja  v a2  s  .c o  m
        //for API 23 (Android 6): at this point method Toolbar.setOverflowIcon(Drawable) has no effect
        toolbar.getClass().getMethod("getMenu").invoke(toolbar);
        AppearanceUtils.callWhenLoaded(toolbar, new Runnable() {
            @Override
            public void run() {
                try {
                    final ViewGroup actionMenuView = (ViewGroup) findViewByClassName(toolbar,
                            "android.widget.ActionMenuView");

                    Runnable setOverflowIcon = new Runnable() {
                        @Override
                        public void run() {
                            try {
                                Class<?> toolbarClass = toolbar.getClass();
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                                    Drawable overflowIcon = (Drawable) toolbarClass.getMethod("getOverflowIcon")
                                            .invoke(toolbar);
                                    setColorFilter(overflowIcon);
                                    toolbarClass.getMethod("setOverflowIcon", Drawable.class).invoke(toolbar,
                                            overflowIcon);
                                } else {
                                    ImageView overflowButton = (ImageView) findViewByClassName(actionMenuView,
                                            "android.widget.ActionMenuPresenter$OverflowMenuButton");
                                    if (overflowButton != null) {
                                        Drawable overflowIcon = overflowButton.getDrawable();
                                        setColorFilter(overflowIcon);
                                        overflowButton.setImageDrawable(overflowIcon);
                                    }
                                }
                            } catch (Exception e) {
                                Logger.e(TAG, e);
                            }
                        }

                        private void setColorFilter(Drawable overflowIcon) {
                            overflowIcon.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
                        }
                    };

                    if (actionMenuView.getChildCount() == 0) {
                        AppearanceUtils.callWhenLoaded(actionMenuView == null ? toolbar : actionMenuView,
                                setOverflowIcon);
                    } else {
                        setOverflowIcon.run();
                    }
                } catch (Exception e) {
                    Logger.e(TAG, e);
                }
            }

            private View findViewByClassName(ViewGroup group, String className) {
                for (int i = 0, size = group.getChildCount(); i < size; ++i) {
                    View child = group.getChildAt(i);
                    if (child.getClass().getName().equals(className)) {
                        return child;
                    }
                }
                return null;
            }
        });
    } catch (Exception e) {
        Logger.e(TAG, e);
    }
}

From source file:com.acbelter.directionalcarousel.page.PageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (container == null) {
        return null;
    }/* www . ja  v  a2 s .  c om*/

    if (container.getClass() != CarouselViewPager.class) {
        throw new IllegalArgumentException("PageFragment must be attached to " + "CarouselViewPager.");
    }

    int pageLayoutId = getArguments().getInt("page_layout_id");
    PageLayout pageLayout = (PageLayout) inflater.inflate(pageLayoutId, container, false);
    if (pageLayout == null) {
        throw new IllegalStateException("PageFragment root layout must have id " + "R.id.page.");
    }

    CarouselConfig config = CarouselConfig.getInstance();
    float scale;
    if (config.scrollScalingMode == CarouselConfig.SCROLL_MODE_BIG_CURRENT
            || config.scrollScalingMode == CarouselConfig.SCROLL_MODE_BIG_ALL) {
        scale = config.smallScale;
    } else {
        scale = config.bigScale;
    }
    pageLayout.setScaleBoth(scale);

    if (config.orientation == CarouselConfig.VERTICAL) {
        pageLayout.setRotation(-90);
    }

    T item = getArguments().getParcelable("item");
    View pageContent = setupPage(pageLayout, item);
    if (pageContent != null) {
        pageContent.setOnTouchListener((CarouselViewPager) container);
        pageContent.setTag(item);
    }
    return pageLayout;
}

From source file:de.dreier.mytargets.views.MaterialTapTargetPrompt.java

/**
 * Displays the prompt.//from  w w  w  .j a  va2 s.c o  m
 */
public void show() {
    final ViewGroup parent = getParentView();
    // If the content view is a drawer layout then that is the parent so
    // that the prompt can be added behind the navigation drawer
    if (parent.getClass().getName().equals("android.support.v4.widget.DrawerLayout")) {
        parent.addView(mView, 1);
    } else {
        parent.addView(mView);
    }

    addGlobalLayoutListener();

    updateFocalCentrePosition();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        startRevealAnimation();
    } else {
        mView.mBackgroundRadius = mBaseBackgroundRadius;
        mView.mFocalRadius = mBaseFocalRadius;
        mView.mPaintFocal.setAlpha(255);
        mView.mPaintBackground.setAlpha(244);
        mPaintSecondaryText.setAlpha(mSecondaryTextColourAlpha);
        mPaintPrimaryText.setAlpha(mPrimaryTextColourAlpha);
    }
}

From source file:de.dreier.mytargets.views.MaterialTapTargetPrompt.java

/**
 * Returns {@link #mParentView}.// www  .j  av  a 2 s. co m
 * <p>
 * If the {@link #mParentView} is {@link null} it determines what view it should be.
 *
 * @return The view to add the prompt view to.
 */
private ViewGroup getParentView() {
    if (mParentView == null) {
        final ViewGroup decorView = (ViewGroup) mActivity.getWindow().getDecorView();
        final ViewGroup contentView = (ViewGroup) ((ViewGroup) decorView.findViewById(android.R.id.content))
                .getChildAt(0);
        // If the content view is a drawer layout then that is the parent so
        // that the prompt can be added behind the navigation drawer
        if (contentView.getClass().getName().equals("android.support.v4.widget.DrawerLayout")) {
            mParentView = contentView;
            mParentViewIsDecor = false;
        } else {
            mParentView = decorView;
            mParentViewIsDecor = true;
        }
        mView.mClipBounds = mParentViewIsDecor;
    }

    return mParentView;
}

From source file:uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.java

/**
 * Returns {@link #mParentView}.//w ww  . j a v  a 2  s  . c  o  m
 *
 * If the {@link #mParentView} is {@link null} it determines what view it should be.
 *
 * @return The view to add the prompt view to.
 */
ViewGroup getParentView() {
    if (mParentView == null) {
        final ViewGroup decorView = (ViewGroup) mActivity.getWindow().getDecorView();
        final ViewGroup contentView = (ViewGroup) ((ViewGroup) decorView.findViewById(android.R.id.content))
                .getChildAt(0);
        // If the content view is a drawer layout then that is the parent so
        // that the prompt can be added behind the navigation drawer
        if (contentView.getClass().getName().equals("android.support.v4.widget.DrawerLayout")) {
            mParentView = contentView;
            mParentViewIsDecor = false;
        } else {
            mParentView = decorView;
            mParentViewIsDecor = true;
        }
        mView.mClipBounds = mParentViewIsDecor;
    }

    return mParentView;
}

From source file:com.juick.android.MainActivity.java

private static void restyleViewGroup(ViewGroup view, ColorsTheme.ColorTheme colorTheme, boolean pressed,
        boolean selected, boolean dontBackground) {
    ViewGroup parent = view;//from w  w  w . j av  a 2 s  . c om
    if (parent.getId() == R.id.navigation_panel)
        return;
    int childCount = parent.getChildCount();
    int background = colorTheme.getBackground(pressed);
    int foreground = colorTheme.getForeground(pressed);
    if (selected) {
        background = calculatePressedBackground(background, foreground);
    }
    if (!dontBackground) {
        boolean skipDraw = false;
        if ((view instanceof LinearLayout || view instanceof FrameLayout || view instanceof RelativeLayout)) {
            Context context = view.getContext();
            if (context instanceof MainActivity || context instanceof MessagesActivity
                    || context instanceof ThreadActivity) {
                // no unneeded background in given scrolling activities
                skipDraw = true;
                if (view.getBackground() != null) {
                    // but enable for layouts that with color
                    skipDraw = false;
                }
                if (!skipDraw && view.getClass().getName().toLowerCase().contains("decorview")) {
                    // given activities manage themselves
                    skipDraw = true;
                }
            }
        }
        if (!skipDraw)
            parent.setBackgroundColor(background);
    }
    if (view instanceof ListView)
        dontBackground = true;
    for (int i = 0; i < childCount; i++) {
        View child = parent.getChildAt(i);
        restyleChildrenOrWidget(child, dontBackground);
    }
}