Example usage for android.view View getClipToOutline

List of usage examples for android.view View getClipToOutline

Introduction

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

Prototype

public final boolean getClipToOutline() 

Source Link

Document

Returns whether the Outline should be used to clip the contents of the View.

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.  ja va2  s . c o 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();
        }
    });
}