/** * Choose the right builder stick according to layout params type * * @param layoutParamsType say {@link android.widget.LinearLayout.LayoutParams} * @param useExistingLayoutParams if true, no LayoutParams will be instantiated * @param width if not useExistingLayoutParams, new LayoutParams will use this as its width * @param height if not useExistingLayoutParams, new LayoutParams will use this as its height * @param <LP> the LayoutParam generic type * @return the corresponding builder stick */ private <LP extends ViewGroup.LayoutParams> Chopstick isInLayout(Class<LP> layoutParamsType, boolean useExistingLayoutParams, int width, int height){ LP lp = useExistingLayoutParams ? useExistingLayoutParams(layoutParamsType) : useNewLayoutParams(layoutParamsType, width, height); if (RelativeLayout.LayoutParams.class.equals(layoutParamsType)) { return new RelativeLayoutStick((RelativeLayout.LayoutParams) lp, mView); } else if(LinearLayout.LayoutParams.class.equals(layoutParamsType)){ return new LinearLayoutStick((LinearLayout.LayoutParams)lp, mView); } throw new UnsupportedOperationException("This Layout is not currently supported. A PR is welcome!"); }