android.graphics.Outline Java Examples

The following examples show how to use android.graphics.Outline. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArcLayout.java    From Cinema-App-Concept with MIT License 6 votes vote down vote up
private void calculateLayout() {
    if (settings == null) {
        return;
    }
    height = getMeasuredHeight();
    width = getMeasuredWidth();
    if (width > 0 && height > 0) {

        clipPath = createClipPath();
        clipPath1 = createClipPath1();
        ViewCompat.setElevation(this, settings.getElevation());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !settings.isCropInside()) {
            ViewCompat.setElevation(this, settings.getElevation());
            setOutlineProvider(new ViewOutlineProvider() {
                @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
                @Override
                public void getOutline(View view, Outline outline) {
                    outline.setConvexPath(clipPath);
                    outline.setConvexPath(clipPath1);
                }
            });
        }
    }
}
 
Example #2
Source File: RecyclerView.java    From Carbon with Apache License 2.0 6 votes vote down vote up
private void updateCorners() {
    if (Carbon.IS_LOLLIPOP_OR_HIGHER) {
        setClipToOutline(true);
        setOutlineProvider(new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {
                if (Carbon.isShapeRect(shapeModel, boundsRect)) {
                    outline.setRect(0, 0, getWidth(), getHeight());
                } else {
                    shadowDrawable.setBounds(0, 0, getWidth(), getHeight());
                    shadowDrawable.setShadowCompatibilityMode(MaterialShapeDrawable.SHADOW_COMPAT_MODE_NEVER);
                    shadowDrawable.getOutline(outline);
                }
            }
        });
    }

    boundsRect.set(shadowDrawable.getBounds());
    shadowDrawable.getPathForSize(getWidth(), getHeight(), cornersMask);
}
 
Example #3
Source File: DrawerLayout.java    From Carbon with Apache License 2.0 6 votes vote down vote up
private void updateCorners() {
    if (Carbon.IS_LOLLIPOP_OR_HIGHER) {
        setClipToOutline(true);
        setOutlineProvider(new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {
                if (Carbon.isShapeRect(shapeModel, boundsRect)) {
                    outline.setRect(0, 0, getWidth(), getHeight());
                } else {
                    shadowDrawable.setBounds(0, 0, getWidth(), getHeight());
                    shadowDrawable.setShadowCompatibilityMode(MaterialShapeDrawable.SHADOW_COMPAT_MODE_NEVER);
                    shadowDrawable.getOutline(outline);
                }
            }
        });
    }

    boundsRect.set(shadowDrawable.getBounds());
    shadowDrawable.getPathForSize(getWidth(), getHeight(), cornersMask);
}
 
Example #4
Source File: DepthRelativeLayout.java    From Depth with MIT License 6 votes vote down vote up
private void initView(AttributeSet attrs) {

        setLayerType(LAYER_TYPE_HARDWARE, null);

        edgePaint.setColor(DEFAULT_EDGE_COLOR);
        edgePaint.setAntiAlias(true);
        if (attrs != null) {
            TypedArray arr = getContext().obtainStyledAttributes(attrs, R.styleable.DepthRelativeLayout);
            edgePaint.setColor(arr.getInt(R.styleable.DepthRelativeLayout_depth_edgeColor, DEFAULT_EDGE_COLOR));
            setIsCircle(arr.getBoolean(R.styleable.DepthRelativeLayout_depth_isCircle, false));
            depth = arr.getDimension(R.styleable.DepthRelativeLayout_depth_value, DEFAULT_THICKNESS * getResources().getDisplayMetrics().density);
            depthIndex = arr.getInteger(R.styleable.DepthRelativeLayout_depth_zIndex, depthIndex);
            animationDelay = arr.getInteger(R.styleable.DepthRelativeLayout_depth_animationDelay, animationDelay);
            customShadowElevation = arr.getDimension(R.styleable.DepthRelativeLayout_depth_elevation, 0);
        } else {
            edgePaint.setColor(DEFAULT_EDGE_COLOR);
            depth = DEFAULT_THICKNESS * getResources().getDisplayMetrics().density;
        }
        setOutlineProvider(new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {

            }
        });
    }
 
Example #5
Source File: ActionButton.java    From fab with Apache License 2.0 6 votes vote down vote up
/**
 * Draws the elevation around the main circle
 * <p>
 * Stroke corrective is used due to ambiguity in drawing stroke in
 * combination with elevation enabled (for API 21 and higher only.
 * In such case there is no possibility to determine the accurate
 * <b>Action Button</b> size, so width and height must be corrected
 * <p>
 * This logic may be changed in future if the better solution is found
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected void drawElevation() {
	float halfSize = getSize() / 2;
	final int left = (int) (calculateCenterX() - halfSize);
	final int top = (int) (calculateCenterY() - halfSize);
	final int right = (int) (calculateCenterX() + halfSize);
	final int bottom = (int) (calculateCenterY() + halfSize);
	ViewOutlineProvider provider = new ViewOutlineProvider() {
		@Override
		public void getOutline(View view, Outline outline) {
			outline.setOval(left, top, right, bottom);
		}
	};
	setOutlineProvider(provider);
	LOGGER.trace("Drawn the Action Button elevation");
}
 
Example #6
Source File: FloatingActionButton.java    From FluxyAndroidTodo with MIT License 6 votes vote down vote up
public FloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr,
                            int defStyleRes) {
    super(context, attrs, defStyleAttr);

    setClickable(true);

    // Set the outline provider for this view. The provider is given the outline which it can
    // then modify as needed. In this case we set the outline to be an oval fitting the height
    // and width.
    setOutlineProvider(new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            outline.setOval(0, 0, getWidth(), getHeight());
        }
    });

    // Finally, enable clipping to the outline, using the provider we set above
    setClipToOutline(true);
}
 
Example #7
Source File: FloatingActionButton.java    From FloatingActionButton with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(new int[]{-android.R.attr.state_enabled}, createCircleDrawable(mColorDisabled));
    drawable.addState(new int[]{android.R.attr.state_pressed}, createCircleDrawable(mColorPressed));
    drawable.addState(new int[]{}, createCircleDrawable(mColorNormal));

    if (Util.hasLollipop()) {
        RippleDrawable ripple = new RippleDrawable(new ColorStateList(new int[][]{{}},
                new int[]{mColorRipple}), drawable, null);
        setOutlineProvider(new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, view.getWidth(), view.getHeight());
            }
        });
        setClipToOutline(true);
        mBackgroundDrawable = ripple;
        return ripple;
    }

    mBackgroundDrawable = drawable;
    return drawable;
}
 
Example #8
Source File: FloatingActionButton.java    From android-FloatingActionButtonBasic with Apache License 2.0 6 votes vote down vote up
public FloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr,
        int defStyleRes) {
    super(context, attrs, defStyleAttr);

    setClickable(true);

    // Set the outline provider for this view. The provider is given the outline which it can
    // then modify as needed. In this case we set the outline to be an oval fitting the height
    // and width.
    setOutlineProvider(new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            outline.setOval(0, 0, getWidth(), getHeight());
        }
    });

    // Finally, enable clipping to the outline, using the provider we set above
    setClipToOutline(true);
}
 
Example #9
Source File: LayerDrawable.java    From RippleDrawable with MIT License 6 votes vote down vote up
/**
 * Populates <code>outline</code> with the first available (non-empty) layer outline.
 *
 * @param outline Outline in which to place the first available layer outline
 */
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void getOutline(Outline outline) {
    if (!Android.isLollipop()) {
        return;
    }

    final LayerState state = mLayerState;
    final ChildDrawable[] children = state.mChildren;
    final int N = state.mNum;
    for (int i = 0; i < N; i++) {
        children[i].mDrawable.getOutline(outline);
        if (!outline.isEmpty()) {
            return;
        }
    }
}
 
Example #10
Source File: MotionLayout.java    From Carbon with Apache License 2.0 6 votes vote down vote up
private void updateCorners() {
    if (Carbon.IS_LOLLIPOP_OR_HIGHER) {
        setClipToOutline(true);
        setOutlineProvider(new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {
                if (Carbon.isShapeRect(shapeModel, boundsRect)) {
                    outline.setRect(0, 0, getWidth(), getHeight());
                } else {
                    shadowDrawable.setBounds(0, 0, getWidth(), getHeight());
                    shadowDrawable.setShadowCompatibilityMode(MaterialShapeDrawable.SHADOW_COMPAT_MODE_NEVER);
                    shadowDrawable.getOutline(outline);
                }
            }
        });
    }

    boundsRect.set(shadowDrawable.getBounds());
    shadowDrawable.getPathForSize(getWidth(), getHeight(), cornersMask);
}
 
Example #11
Source File: ShapeOfView.java    From ArcLayout with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public ViewOutlineProvider getOutlineProvider() {
    return new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            if (clipManager != null) {
                final Path shadowConvexPath = clipManager.getShadowConvexPath();
                if (shadowConvexPath != null) {
                    try {
                        outline.setConvexPath(shadowConvexPath);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }

        }
    };
}
 
Example #12
Source File: Label.java    From ShareBox with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(new int[]{android.R.attr.state_pressed}, createRectDrawable(mColorPressed));
    drawable.addState(new int[]{}, createRectDrawable(mColorNormal));

    if (Util.hasLollipop()) {
        RippleDrawable ripple = new RippleDrawable(new ColorStateList(new int[][]{{}},
                new int[]{mColorRipple}), drawable, null);
        setOutlineProvider(new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, view.getWidth(), view.getHeight());
            }
        });
        setClipToOutline(true);
        mBackgroundDrawable = ripple;
        return ripple;
    }

    mBackgroundDrawable = drawable;
    return drawable;
}
 
Example #13
Source File: RelativeLayout.java    From Carbon with Apache License 2.0 6 votes vote down vote up
private void updateCorners() {
    if (Carbon.IS_LOLLIPOP_OR_HIGHER) {
        setClipToOutline(true);
        setOutlineProvider(new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {
                if (Carbon.isShapeRect(shapeModel, boundsRect)) {
                    outline.setRect(0, 0, getWidth(), getHeight());
                } else {
                    shadowDrawable.setBounds(0, 0, getWidth(), getHeight());
                    shadowDrawable.setShadowCompatibilityMode(MaterialShapeDrawable.SHADOW_COMPAT_MODE_NEVER);
                    shadowDrawable.getOutline(outline);
                }
            }
        });
    }

    boundsRect.set(shadowDrawable.getBounds());
    shadowDrawable.getPathForSize(getWidth(), getHeight(), cornersMask);
}
 
Example #14
Source File: LayerDrawable.java    From Carbon with Apache License 2.0 6 votes vote down vote up
/**
 * Populates <code>outline</code> with the first available (non-empty) layer outline.
 *
 * @param outline Outline in which to place the first available layer outline
 */
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void getOutline(@NonNull Outline outline) {
    final ChildDrawable[] array = mLayerState.mChildren;
    final int N = mLayerState.mNum;
    for (int i = 0; i < N; i++) {
        final Drawable dr = array[i].mDrawable;
        if (dr != null) {
            dr.getOutline(outline);
            if (!outline.isEmpty()) {
                return;
            }
        }
    }
}
 
Example #15
Source File: LongPressDragCardView.java    From Mysplash with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void setRadius(float radius) {
    super.setRadius(radius);
    if (coverImage != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        coverImage.setOutlineProvider(new ViewOutlineProvider() {
            @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setRoundRect(
                        view.getPaddingLeft(),
                        view.getPaddingTop(),
                        view.getWidth() - view.getPaddingRight(),
                        view.getHeight() - view.getPaddingBottom(),
                        radius
                );
            }
        });
        coverImage.setClipToOutline(true);
    }
}
 
Example #16
Source File: DepthLayout.java    From Android-Plugin-Framework with MIT License 6 votes vote down vote up
private void initView(AttributeSet attrs) {

    edgePaint.setColor(DEFAULT_EDGE_COLOR);
    edgePaint.setAntiAlias(true);
    if (attrs != null) {
      TypedArray arr = getContext().obtainStyledAttributes(attrs, STYLEABLE);
      edgePaint.setColor(arr.getInt(1, DEFAULT_EDGE_COLOR));
      setIsCircle(arr.getBoolean(0, false));
      depth = arr.getDimension(2, DEFAULT_THICKNESS * getResources().getDisplayMetrics().density);
      customShadowElevation = arr.getDimension(3, 0);
      arr.recycle();
    } else {
      edgePaint.setColor(DEFAULT_EDGE_COLOR);
      depth = DEFAULT_THICKNESS * getResources().getDisplayMetrics().density;
    }
    setOutlineProvider(new ViewOutlineProvider() {
      @Override public void getOutline(View view, Outline outline) {

      }
    });
  }
 
Example #17
Source File: LLand.java    From heads-up with GNU General Public License v3.0 6 votes vote down vote up
public Player(Context context) {
    super(context);

    setBackgroundResource(R.drawable.android);
    if (Build.VERSION.SDK_INT >= 21) {
        getBackground().setTintMode(PorterDuff.Mode.SRC_ATOP);
        getBackground().setTint(sColors[0]);
        setOutlineProvider(new ViewOutlineProvider() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void getOutline(View view, Outline outline) {
                final int w = view.getWidth();
                final int h = view.getHeight();
                final int ix = (int) (w * 0.3f);
                final int iy = (int) (h * 0.2f);
                outline.setRect(ix, iy, w - ix, h - iy);
            }
        });
    }
}
 
Example #18
Source File: ShapeOfView.java    From ShapeOfView with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public ViewOutlineProvider getOutlineProvider() {
    return new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            if (clipManager != null && !isInEditMode()) {
                final Path shadowConvexPath = clipManager.getShadowConvexPath();
                if (shadowConvexPath != null) {
                    try {
                        outline.setConvexPath(shadowConvexPath);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }

        }
    };
}
 
Example #19
Source File: HeaderElevationController.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
HeaderElevationController(View header) {
    mHeader = header;
    final Resources res = mHeader.getContext().getResources();
    mMaxElevation = res.getDimension(R.dimen.all_apps_header_max_elevation);
    mScrollToElevation = res.getDimension(R.dimen.all_apps_header_scroll_to_elevation);

    // We need to provide a custom outline so the shadow only appears on the bottom edge.
    // The top, left and right edges are all extended out, and the shadow is clipped
    // by the parent.
    final ViewOutlineProvider vop = new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            final View parent = (View) mHeader.getParent();

            final int left = parent.getLeft(); // Use the parent to account for offsets
            final int top = view.getTop();
            final int right = left + view.getWidth();
            final int bottom = view.getBottom();

            final int offset = Utilities.pxFromDp(mMaxElevation, res.getDisplayMetrics());
            outline.setRect(left - offset, top - offset, right + offset, bottom);
        }
    };
    mHeader.setOutlineProvider(vop);
}
 
Example #20
Source File: ShapeOfView.java    From DiagonalLayout with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public ViewOutlineProvider getOutlineProvider() {
    return new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            if (clipManager != null) {
                final Path shadowConvexPath = clipManager.getShadowConvexPath();
                if (shadowConvexPath != null) {
                    try {
                        outline.setConvexPath(shadowConvexPath);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }

        }
    };
}
 
Example #21
Source File: SeekBarCompatDontCrash.java    From PLDroidShortVideo with Apache License 2.0 5 votes vote down vote up
public static void setOutlineProvider(View marker, final MarkerDrawable markerDrawable) {
    marker.setOutlineProvider(new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            outline.setConvexPath(markerDrawable.getPath());
        }
    });
}
 
Example #22
Source File: CircleImageView.java    From CircleImageView with Apache License 2.0 5 votes vote down vote up
@Override
public void getOutline(View view, Outline outline) {
    if (mDisableCircularTransformation) {
        ViewOutlineProvider.BACKGROUND.getOutline(view, outline);
    } else {
        Rect bounds = new Rect();
        mBorderRect.roundOut(bounds);
        outline.setRoundRect(bounds, bounds.width() / 2.0f);
    }
}
 
Example #23
Source File: RoundedRectHelperApi21.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
@Override
public void getOutline(View view, Outline outline) {
    if (sCornerRadius == 0) {
        sCornerRadius = view.getResources().getDimensionPixelSize(
                R.dimen.lb_rounded_rect_corner_radius);
    }
    outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), sCornerRadius);
    outline.setAlpha(1f);
}
 
Example #24
Source File: Utils.java    From LollipopShowcase with Apache License 2.0 5 votes vote down vote up
public static void configureFab(View fabButton) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            fabButton.setOutlineProvider(new ViewOutlineProvider() {
                @TargetApi(Build.VERSION_CODES.LOLLIPOP)
                @Override
                public void getOutline(View view, Outline outline) {
                    int fabSize = view.getContext().getResources().getDimensionPixelSize(R.dimen.fab_size);
                    outline.setOval(0, 0, fabSize, fabSize);
                }
            });
        } else {
            ((ImageButton) fabButton).setScaleType(ImageView.ScaleType.FIT_CENTER);
        }
    }
 
Example #25
Source File: ViewOutlineProviderCompatUtilsLXX.java    From simple-keyboard with Apache License 2.0 5 votes vote down vote up
@Override
public void getOutline(final View view, final Outline outline) {
    if (mLastVisibleTopInsets == NO_DATA) {
        // Call default implementation.
        ViewOutlineProvider.BACKGROUND.getOutline(view, outline);
        return;
    }
    // TODO: Revisit this when floating/resize keyboard is supported.
    outline.setRect(
            view.getLeft(), mLastVisibleTopInsets, view.getRight(), view.getBottom());
}
 
Example #26
Source File: DiagonalLayout.java    From Blackbulb with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ViewOutlineProvider getOutlineProvider() {
	return new ViewOutlineProvider() {
		@Override
		public void getOutline(View view, Outline outline) {
			outline.setConvexPath(outlinePath);
		}
	};
}
 
Example #27
Source File: ZomServicesRecyclerViewAdapter.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
    Context context = holder.itemView.getContext();

    if (mValues.get(position) instanceof BotEntry) {
        final BotEntry e = (BotEntry)mValues.get(position);

        ViewHolderBot viewHolder = (ViewHolderBot) holder;
        viewHolder.image.setImageResource(e.resIdImage);
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            ViewOutlineProvider viewOutlineProvider = new ViewOutlineProvider() {
                @Override
                public void getOutline(View view, Outline outline) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        int rounding = view.getContext().getResources().getDimensionPixelSize(R.dimen.bot_image_rounding);
                        outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), rounding);
                    }
                }
            };
            viewHolder.image.setOutlineProvider(viewOutlineProvider);
            viewHolder.image.setClipToOutline(true);
        }
        viewHolder.name.setText(e.resIdName);
        viewHolder.description.setText(e.resIdDescription);
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBotClicked(e.jid,e.nickname);
            }
        });
    }
}
 
Example #28
Source File: DetailActivityL.java    From google-io-2014-compat with Apache License 2.0 5 votes vote down vote up
private void setOutlines(int star, int info) {
    final int size = getResources().getDimensionPixelSize(R.dimen.floating_button_size);

    final ViewOutlineProvider vop = new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            outline.setOval(0, 0, size, size);
        }
    };

    findViewById(star).setOutlineProvider(vop);
    findViewById(info).setOutlineProvider(vop);
}
 
Example #29
Source File: SeekBarCompatDontCrash.java    From Musicoco with Apache License 2.0 5 votes vote down vote up
public static void setOutlineProvider(View marker, final MarkerDrawable markerDrawable) {
    marker.setOutlineProvider(new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            outline.setConvexPath(markerDrawable.getPath());
        }
    });
}
 
Example #30
Source File: ViewOutlineProviderCompatUtilsLXX.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
@Override
public void getOutline(final View view, final Outline outline) {
    if (mLastVisibleTopInsets == NO_DATA) {
        // Call default implementation.
        ViewOutlineProvider.BACKGROUND.getOutline(view, outline);
        return;
    }
    // TODO: Revisit this when floating/resize keyboard is supported.
    outline.setRect(
            view.getLeft(), mLastVisibleTopInsets, view.getRight(), view.getBottom());
}