diff --git a/widget/src/main/java/com/pichs/common/widget/cardview/XCardTextView.java b/widget/src/main/java/com/pichs/common/widget/cardview/XCardTextView.java new file mode 100644 index 0000000..dbdb787 --- /dev/null +++ b/widget/src/main/java/com/pichs/common/widget/cardview/XCardTextView.java @@ -0,0 +1,330 @@ +/* + * Tencent is pleased to support the open source community by making QMUI_Android available. + * + * Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the MIT License (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.pichs.common.widget.cardview; + +import android.content.Context; +import android.graphics.Canvas; +import android.util.AttributeSet; + +import androidx.annotation.ColorInt; + +import com.pichs.common.widget.utils.XLayoutHelper; +import com.pichs.common.widget.view.XButton; +import com.pichs.common.widget.view.XTextView; + +/** + * @author pichs + */ +public class XCardTextView extends XTextView implements XILayout { + private XLayoutHelper mLayoutHelper; + + public XCardTextView(Context context) { + this(context, null); + } + + public XCardTextView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public XCardTextView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(context, attrs, defStyleAttr); + } + + private void init(Context context, AttributeSet attrs, int defStyleAttr) { + mLayoutHelper = new XLayoutHelper(context, attrs, defStyleAttr, this); + } + + @Override + public void updateTopDivider(int topInsetLeft, int topInsetRight, int topDividerHeight, int topDividerColor) { + mLayoutHelper.updateTopDivider(topInsetLeft, topInsetRight, topDividerHeight, topDividerColor); + invalidate(); + } + + @Override + public void updateBottomDivider(int bottomInsetLeft, int bottomInsetRight, int bottomDividerHeight, int bottomDividerColor) { + mLayoutHelper.updateBottomDivider(bottomInsetLeft, bottomInsetRight, bottomDividerHeight, bottomDividerColor); + invalidate(); + } + + @Override + public void updateLeftDivider(int leftInsetTop, int leftInsetBottom, int leftDividerWidth, int leftDividerColor) { + mLayoutHelper.updateLeftDivider(leftInsetTop, leftInsetBottom, leftDividerWidth, leftDividerColor); + invalidate(); + } + + public void updateRightDivider(int rightInsetTop, int rightInsetBottom, int rightDividerWidth, int rightDividerColor) { + mLayoutHelper.updateRightDivider(rightInsetTop, rightInsetBottom, rightDividerWidth, rightDividerColor); + invalidate(); + } + + @Override + public void onlyShowTopDivider(int topInsetLeft, int topInsetRight, + int topDividerHeight, int topDividerColor) { + mLayoutHelper.onlyShowTopDivider(topInsetLeft, topInsetRight, topDividerHeight, topDividerColor); + invalidate(); + } + + @Override + public void onlyShowBottomDivider(int bottomInsetLeft, int bottomInsetRight, + int bottomDividerHeight, int bottomDividerColor) { + mLayoutHelper.onlyShowBottomDivider(bottomInsetLeft, bottomInsetRight, bottomDividerHeight, bottomDividerColor); + invalidate(); + } + + @Override + public void onlyShowLeftDivider(int leftInsetTop, int leftInsetBottom, int leftDividerWidth, int leftDividerColor) { + mLayoutHelper.onlyShowLeftDivider(leftInsetTop, leftInsetBottom, leftDividerWidth, leftDividerColor); + invalidate(); + } + + @Override + public void onlyShowRightDivider(int rightInsetTop, int rightInsetBottom, int rightDividerWidth, int rightDividerColor) { + mLayoutHelper.onlyShowRightDivider(rightInsetTop, rightInsetBottom, rightDividerWidth, rightDividerColor); + invalidate(); + } + + @Override + public void setTopDividerAlpha(int dividerAlpha) { + mLayoutHelper.setTopDividerAlpha(dividerAlpha); + invalidate(); + } + + @Override + public void setBottomDividerAlpha(int dividerAlpha) { + mLayoutHelper.setBottomDividerAlpha(dividerAlpha); + invalidate(); + } + + @Override + public void setLeftDividerAlpha(int dividerAlpha) { + mLayoutHelper.setLeftDividerAlpha(dividerAlpha); + invalidate(); + } + + @Override + public void setRightDividerAlpha(int dividerAlpha) { + mLayoutHelper.setRightDividerAlpha(dividerAlpha); + invalidate(); + } + + @Override + public void setHideRadiusSide(int hideRadiusSide) { + mLayoutHelper.setHideRadiusSide(hideRadiusSide); + invalidate(); + } + + @Override + public int getHideRadiusSide() { + return mLayoutHelper.getHideRadiusSide(); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + widthMeasureSpec = mLayoutHelper.getMeasuredWidthSpec(widthMeasureSpec); + heightMeasureSpec = mLayoutHelper.getMeasuredHeightSpec(heightMeasureSpec); + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + int minW = mLayoutHelper.handleMiniWidth(widthMeasureSpec, getMeasuredWidth()); + int minH = mLayoutHelper.handleMiniHeight(heightMeasureSpec, getMeasuredHeight()); + if (widthMeasureSpec != minW || heightMeasureSpec != minH) { + super.onMeasure(minW, minH); + } + } + + @Override + public void setRadiusAndShadow(int radius, int shadowElevation, final float shadowAlpha) { + mLayoutHelper.setRadiusAndShadow(radius, shadowElevation, shadowAlpha); + } + + @Override + public void setRadiusAndShadow(int radius, @HideRadiusSide int hideRadiusSide, int shadowElevation, final float shadowAlpha) { + mLayoutHelper.setRadiusAndShadow(radius, hideRadiusSide, shadowElevation, shadowAlpha); + } + + @Override + public void setRadiusAndShadow(int radius, int hideRadiusSide, int shadowElevation, int shadowColor, float shadowAlpha) { + mLayoutHelper.setRadiusAndShadow(radius, hideRadiusSide, shadowElevation, shadowColor, shadowAlpha); + } + + @Override + public void setRadius(int radius) { + mLayoutHelper.setRadius(radius); + } + + @Override + public void setRadius(int radius, @HideRadiusSide int hideRadiusSide) { + mLayoutHelper.setRadius(radius, hideRadiusSide); + } + + @Override + public int getRadius() { + return mLayoutHelper.getRadius(); + } + + @Override + public void setOutlineInset(int left, int top, int right, int bottom) { + mLayoutHelper.setOutlineInset(left, top, right, bottom); + } + + @Override + public void setBorderColor(@ColorInt int borderColor) { + mLayoutHelper.setBorderColor(borderColor); + invalidate(); + } + + @Override + public void setBorderWidth(int borderWidth) { + mLayoutHelper.setBorderWidth(borderWidth); + invalidate(); + } + + @Override + public void setShowBorderOnlyBeforeL(boolean showBorderOnlyBeforeL) { + mLayoutHelper.setShowBorderOnlyBeforeL(showBorderOnlyBeforeL); + invalidate(); + } + + @Override + public boolean setWidthLimit(int widthLimit) { + if (mLayoutHelper.setWidthLimit(widthLimit)) { + requestLayout(); + invalidate(); + } + return true; + } + + @Override + public boolean setHeightLimit(int heightLimit) { + if (mLayoutHelper.setHeightLimit(heightLimit)) { + requestLayout(); + invalidate(); + } + return true; + } + + @Override + public void setOutlineExcludePadding(boolean outlineExcludePadding) { + mLayoutHelper.setOutlineExcludePadding(outlineExcludePadding); + } + + @Override + public void setShadowElevation(int elevation) { + mLayoutHelper.setShadowElevation(elevation); + } + + @Override + public int getShadowElevation() { + return mLayoutHelper.getShadowElevation(); + } + + @Override + public void setShadowAlpha(float shadowAlpha) { + mLayoutHelper.setShadowAlpha(shadowAlpha); + } + + @Override + public float getShadowAlpha() { + return mLayoutHelper.getShadowAlpha(); + } + + @Override + public void setShadowColor(int shadowColor) { + mLayoutHelper.setShadowColor(shadowColor); + } + + @Override + public int getShadowColor() { + return mLayoutHelper.getShadowColor(); + } + + @Override + public void setOuterNormalColor(int color) { + mLayoutHelper.setOuterNormalColor(color); + } + + @Override + public void updateBottomSeparatorColor(int color) { + mLayoutHelper.updateBottomSeparatorColor(color); + } + + @Override + public void updateLeftSeparatorColor(int color) { + mLayoutHelper.updateLeftSeparatorColor(color); + } + + @Override + public void updateRightSeparatorColor(int color) { + mLayoutHelper.updateRightSeparatorColor(color); + } + + @Override + public void updateTopSeparatorColor(int color) { + mLayoutHelper.updateTopSeparatorColor(color); + } + + @Override + protected void dispatchDraw(Canvas canvas) { + super.dispatchDraw(canvas); + mLayoutHelper.drawDividers(canvas, getWidth(), getHeight()); + mLayoutHelper.dispatchRoundBorderDraw(canvas); + } + + @Override + public boolean hasBorder() { + return mLayoutHelper.hasBorder(); + } + + @Override + public boolean hasLeftSeparator() { + return mLayoutHelper.hasLeftSeparator(); + } + + @Override + public boolean hasTopSeparator() { + return mLayoutHelper.hasTopSeparator(); + } + + @Override + public boolean hasRightSeparator() { + return mLayoutHelper.hasRightSeparator(); + } + + @Override + public boolean hasBottomSeparator() { + return mLayoutHelper.hasBottomSeparator(); + } + + @Override + public void setBorderGradientStartColor(int borderGradientStartColor) { + mLayoutHelper.setBorderGradientStartColor(borderGradientStartColor); + } + + @Override + public void setBorderGradientEndColor(int borderGradientEndColor) { + mLayoutHelper.setBorderGradientEndColor(borderGradientEndColor); + } + + @Override + public void setBorderGradientOrientation(@GradientOrientation int orientation) { + mLayoutHelper.setBorderGradientOrientation(orientation); + } + + @Override + public void setBorderGradientOrientation(int borderGradientStartColor, int borderGradientEndColor, @GradientOrientation int orientation) { + mLayoutHelper.setBorderGradientOrientation(borderGradientStartColor, borderGradientEndColor, orientation); + } +} diff --git a/widget/src/main/res/values/attrs.xml b/widget/src/main/res/values/attrs.xml index f80a73c..535fcbc 100644 --- a/widget/src/main/res/values/attrs.xml +++ b/widget/src/main/res/values/attrs.xml @@ -689,6 +689,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +