Example usage for android.graphics Outline setRect

List of usage examples for android.graphics Outline setRect

Introduction

In this page you can find the example usage for android.graphics Outline setRect.

Prototype

public void setRect(int left, int top, int right, int bottom) 

Source Link

Document

Sets the Outline to the rounded rect defined by the input rect, and corner radius.

Usage

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  . j  a  va  2  s .com
 */
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: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//from  w  ww.  j  a  va  2s  . c om
            public void getOutline(View view, Outline outline) {

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

From source file:com.android.messaging.ui.ViewPagerTabs.java

public ViewPagerTabs(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);/* w  ww.  j  av  a2 s  .  co m*/

    mSidePadding = (int) (getResources().getDisplayMetrics().density * TAB_SIDE_PADDING_IN_DPS);

    final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    mTextSize = a.getDimensionPixelSize(0, 0);
    mTextStyle = a.getInt(1, 0);
    mTextColor = a.getColorStateList(2);
    mTextAllCaps = a.getBoolean(3, false);

    mTabStrip = new ViewPagerTabStrip(context);
    addView(mTabStrip, new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
    a.recycle();

    // enable shadow casting from view bounds
    if (OsUtil.isAtLeastL()) {
        setOutlineProvider(new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setRect(0, 0, view.getWidth(), view.getHeight());
            }
        });
    }
}

From source file:com.frozendevs.periodictable.view.ViewPagerTabs.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ViewPagerTabs(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);/*from w w w . j av a 2 s  . c om*/

    mSidePadding = getResources().getDimensionPixelOffset(R.dimen.tab_side_padding);

    final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    mTextSize = a.getDimensionPixelSize(0, 0);
    mTextStyle = a.getInt(1, 0);
    mTextColor = a.getColorStateList(2);
    a.recycle();

    Resources.Theme theme = getContext().getTheme();
    TypedValue typedValue = new TypedValue();
    theme.resolveAttribute(R.attr.theme, typedValue, true);
    TypedArray typedArray = theme.obtainStyledAttributes(typedValue.resourceId,
            new int[] { R.attr.selectableItemBackground });
    mTextBackground = typedArray.getResourceId(0, 0);
    typedArray.recycle();

    mTabStrip = new ViewPagerTabStrip(context);
    addView(mTabStrip, new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // enable shadow casting from view bounds
        setOutlineProvider(new ViewOutlineProvider() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setRect(0, 0, view.getWidth(), view.getHeight());
            }
        });
    }
}

From source file:com.cyanogenmod.eleven.ui.fragments.AudioPlayerFragment.java

/**
 * Initializes the header bar/*from w  ww. ja  v a2  s . c om*/
 */
private void initHeaderBar() {
    View headerBar = mRootView.findViewById(R.id.audio_player_header);
    final int bottomActionBarHeight = getResources().getDimensionPixelSize(R.dimen.bottom_action_bar_height);

    headerBar.setOutlineProvider(new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            // since we only want the top and bottom shadows, pad the horizontal width
            // to hide the shadows. Can't seem to find a better way to do this
            int padWidth = (int) (0.2f * view.getWidth());
            outline.setRect(-padWidth, -bottomActionBarHeight, view.getWidth() + padWidth, view.getHeight());
        }
    });

    // Title text
    mSongTitle = (TextView) mRootView.findViewById(R.id.header_bar_song_title);
    mArtistName = (TextView) mRootView.findViewById(R.id.header_bar_artist_title);

    // Buttons
    // Search Button
    View v = mRootView.findViewById(R.id.header_bar_search_button);
    v.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            NavUtils.openSearch(getActivity(), "");
        }
    });

    // Add to Playlist Button
    // Setup the playlist button - add a click listener to show the context
    mAddToPlaylistButton = (ImageView) mRootView.findViewById(R.id.header_bar_add_button);

    // Create the context menu when requested
    mAddToPlaylistButton.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
        @Override
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
            MusicUtils.makePlaylistMenu(getActivity(), GROUP_ID, menu);
            menu.setHeaderTitle(R.string.add_to_playlist);
        }
    });

    // add a click listener to show the context
    mAddToPlaylistButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // save the current track id
            mSelectedId = MusicUtils.getCurrentAudioId();
            mAddToPlaylistButton.showContextMenu();
        }
    });

    // Add the menu button
    // menu button
    mMenuButton = (ImageView) mRootView.findViewById(R.id.header_bar_menu_button);
    mMenuButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showPopupMenu();
        }
    });
}