类android.graphics.Outline源码实例Demo

下面列出了怎么用android.graphics.Outline的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Carbon   文件: RecyclerView.java
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);
}
 
源代码2 项目: fab   文件: ActionButton.java
/**
 * 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");
}
 
源代码3 项目: Carbon   文件: MotionLayout.java
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);
}
 
源代码4 项目: ArcLayout   文件: ShapeOfView.java
@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();
                    }
                }
            }

        }
    };
}
 
源代码5 项目: ShapeOfView   文件: ShapeOfView.java
@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();
                    }
                }
            }

        }
    };
}
 
源代码6 项目: Mysplash   文件: LongPressDragCardView.java
@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);
    }
}
 
源代码7 项目: Carbon   文件: LayerDrawable.java
/**
 * 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;
            }
        }
    }
}
 
源代码8 项目: Cinema-App-Concept   文件: ArcLayout.java
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);
                }
            });
        }
    }
}
 
源代码9 项目: Carbon   文件: RelativeLayout.java
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);
}
 
源代码10 项目: heads-up   文件: LLand.java
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);
            }
        });
    }
}
 
源代码11 项目: LaunchEnr   文件: HeaderElevationController.java
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);
}
 
源代码12 项目: RippleDrawable   文件: LayerDrawable.java
/**
 * 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;
        }
    }
}
 
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);
}
 
源代码14 项目: Depth   文件: DepthRelativeLayout.java
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) {

            }
        });
    }
 
源代码15 项目: ShareBox   文件: Label.java
@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;
}
 
源代码16 项目: FluxyAndroidTodo   文件: FloatingActionButton.java
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);
}
 
@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;
}
 
源代码18 项目: Android-Plugin-Framework   文件: DepthLayout.java
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) {

      }
    });
  }
 
源代码19 项目: DiagonalLayout   文件: ShapeOfView.java
@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();
                    }
                }
            }

        }
    };
}
 
源代码20 项目: Carbon   文件: DrawerLayout.java
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);
}
 
源代码21 项目: Blackbulb   文件: DiagonalLayout.java
@Override
public ViewOutlineProvider getOutlineProvider() {
	return new ViewOutlineProvider() {
		@Override
		public void getOutline(View view, Outline outline) {
			outline.setConvexPath(outlinePath);
		}
	};
}
 
源代码22 项目: scene   文件: ViewOtherAnimationBuilder.java
public T boundsRadiusBy(float deltaValue) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        Outline outline = new Outline();
        mView.getOutlineProvider().getOutline(mView, outline);
        float radius = outline.getRadius();
        return boundsRadius(radius, radius + deltaValue);
    }
    return (T) this;
}
 
源代码23 项目: android_9.0.0_r45   文件: ViewOutlineProvider.java
@Override
public void getOutline(View view, Outline outline) {
    Drawable background = view.getBackground();
    if (background != null) {
        background.getOutline(outline);
    } else {
        outline.setRect(0, 0, view.getWidth(), view.getHeight());
        outline.setAlpha(0.0f);
    }
}
 
源代码24 项目: android_9.0.0_r45   文件: ViewOutlineProvider.java
@Override
public void getOutline(View view, Outline outline) {
    outline.setRect(view.getPaddingLeft(),
            view.getPaddingTop(),
            view.getWidth() - view.getPaddingRight(),
            view.getHeight() - view.getPaddingBottom());
}
 
源代码25 项目: weex   文件: WXBackgroundDrawable.java
@Override
public void getOutline(@NonNull Outline outline) {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    super.getOutline(outline);
  } else {
    if ((!CSSConstants.isUndefined(mBorderRadius) && mBorderRadius > 0) || mBorderCornerRadii != null) {
      updatePath();

      outline.setConvexPath(mPathForBorderRadiusOutline);
    } else {
      outline.setRect(getBounds());
    }
  }

}
 
源代码26 项目: kolabnotes-android   文件: Utils.java
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);
        }
    }
 
源代码27 项目: Genius-Android   文件: TouchEffectDrawable.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void getOutline(Outline outline) {
    if (mState.mEffect != null) {
        mState.mEffect.getOutline(outline);
        outline.setAlpha(getAlpha() / 255.0f);
    }
}
 
源代码28 项目: ArcLayout   文件: ArcDrawable.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void getOutline(Outline outline) {
  if (arcPath == null || !arcPath.isConvex()) {
    super.getOutline(outline);
  } else {
    outline.setConvexPath(arcPath);
  }
}
 
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());
        }
    });
}
 
源代码30 项目: google-io-2014   文件: DetailActivity.java
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);
}
 
 类所在包
 同包方法