Example usage for android.view View setOutlineProvider

List of usage examples for android.view View setOutlineProvider

Introduction

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

Prototype

public void setOutlineProvider(ViewOutlineProvider provider) 

Source Link

Document

Sets the ViewOutlineProvider of the view, which generates the Outline that defines the shape of the shadow it casts, and enables outline clipping.

Usage

From source file:Main.java

static void setBoundsViewOutlineProvider(View view) {
    view.setOutlineProvider(ViewOutlineProvider.BOUNDS);
}

From source file:com.landenlabs.allperfimages.ui.Ui.java

public static void setRectOutline(View view) {
    final int width = view.getWidth();
    final int height = view.getHeight();

    if (Build.VERSION.SDK_INT >= 21) {
        view.setOutlineProvider(new ViewOutlineProvider() {
            @Override//  w  w w.  ja  v  a2  s.  co  m
            public void getOutline(View view, Outline outline) {

                if (Build.VERSION.SDK_INT >= 21) {
                    outline.setRect(0, 0, width, height);
                }
            }
        });
    }
}

From source file:net.kourlas.voipms_sms.Utils.java

/**
 * Applies a circular mask to a view.//from ww  w.ja va 2  s  . c o  m
 * <p/>
 * Note that this method only works on Lollipop and above; it will silently fail on older versions.
 *
 * @param view The view to apply the mask to.
 */
public static void applyCircularMask(View view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        view.setOutlineProvider(new ViewOutlineProvider() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, view.getWidth(), view.getHeight());
            }
        });
        view.setClipToOutline(true);
    }
}

From source file:net.kourlas.voipms_sms.Utils.java

/**
 * Applies a rectangular rounded corners mask to a view.
 * <p/>/*from  w  ww  .j  a v  a2s. co  m*/
 * Note that this method only works on Lollipop and above; it will silently fail on older versions.
 *
 * @param view The view to apply the mask to.
 */
public static void applyRoundedCornersMask(View view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        view.setOutlineProvider(new ViewOutlineProvider() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), 15);
            }
        });
        view.setClipToOutline(true);
    }
}

From source file:Main.java

/**
 * Adds a rectangular outline to a view. This can be useful when you want to add a shadow
 * to a transparent view. See b/16856049.
 * @param view view that the outline is added to
 * @param res The resources file.//from   w w w.  ja  va2s  .  c o m
 */
public static void addRectangularOutlineProvider(View view, Resources res) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ViewOutlineProvider rectOutlineProvider = new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    outline.setRect(0, 0, view.getWidth(), view.getHeight());
                }
            }
        };

        view.setOutlineProvider(rectOutlineProvider);
    }
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void makeCircle(final View view, final int dimenResId) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ViewOutlineProvider viewOutlineProvider = new ViewOutlineProvider() {
            @Override//  w ww.j a v a 2  s. co  m
            public void getOutline(View view, Outline outline) {
                Context context = view.getContext();
                int size = context.getResources().getDimensionPixelSize(dimenResId);
                outline.setOval(0, 0, size, size);
            }
        };

        view.setOutlineProvider(viewOutlineProvider);
    }
}

From source file:com.silentcircle.common.util.ViewUtil.java

/**
 * Adds a rectangular outline to a view. This can be useful when you want to add a shadow
 * to a transparent view. See b/16856049.
 * @param view view that the outline is added to
 * @param res The resources file./*from ww w . j  av a  2s. co m*/
 */
public static void addRectangularOutlineProvider(View view, Resources res) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        view.setOutlineProvider(RECT_OUTLINE_PROVIDER);
}

From source file:com.silentcircle.common.util.ViewUtil.java

/**
 * Configures the floating action button, clipping it to a circle and setting its translation z.
 * @param view The float action button's view.
 * @param res The resources file.//from   w  ww.  ja  v  a 2s .  c o m
 */
public static void setupFloatingActionButton(View view, Resources res) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        view.setOutlineProvider(OVAL_OUTLINE_PROVIDER);
        view.setTranslationZ(res.getDimensionPixelSize(R.dimen.floating_action_button_translation_z));
    }
}

From source file:mad.com.applicationproject.activity.DragFragment.java

private void addDragView(View view) {
    mDragViews.add(view);/*  w ww  . j a v a2  s  .c  om*/
    view.setOutlineProvider(mOutlineProviderCircle);
    view.setClipToOutline(true);
    mRootView.addDragView(view);
}

From source file:com.example.android.clippingbasic.ClippingBasicFragment.java

@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    /* Set the initial text for the TextView. */
    mTextView = (TextView) view.findViewById(R.id.text_view);
    changeText();/*  w ww .j av a 2s . co m*/

    final View clippedView = view.findViewById(R.id.frame);

    /* Sets the OutlineProvider for the View. */
    clippedView.setOutlineProvider(mOutlineProvider);

    /* When the button is clicked, the text is clipped or un-clipped. */
    view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View bt) {
            // Toggle whether the View is clipped to the outline
            if (clippedView.getClipToOutline()) {
                /* The Outline is set for the View, but disable clipping. */
                clippedView.setClipToOutline(false);

                Log.d(TAG, String.format("Clipping to outline is disabled"));
                ((Button) bt).setText(R.string.clip_button);
            } else {
                /* Enables clipping on the View. */
                clippedView.setClipToOutline(true);

                Log.d(TAG, String.format("Clipping to outline is enabled"));
                ((Button) bt).setText(R.string.unclip_button);
            }
        }
    });

    /* When the text is clicked, a new string is shown. */
    view.findViewById(R.id.text_view).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mClickCount++;

            // Update the text in the TextView
            changeText();

            // Invalidate the outline just in case the TextView changed size
            clippedView.invalidateOutline();
        }
    });
}