Example usage for android.view View invalidateOutline

List of usage examples for android.view View invalidateOutline

Introduction

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

Prototype

public void invalidateOutline() 

Source Link

Document

Called to rebuild this View's Outline from its ViewOutlineProvider outline provider

Usage

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  w  w  . j  a v  a2 s  .com*/

    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();
        }
    });
}