Skip to content

Commit

Permalink
XCardTextView
Browse files Browse the repository at this point in the history
  • Loading branch information
pichsy committed Jan 8, 2021
1 parent 46208e4 commit eb06070
Show file tree
Hide file tree
Showing 2 changed files with 374 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
44 changes: 44 additions & 0 deletions widget/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,50 @@
<attr name="xp_borderGradientStartColor" />
</declare-styleable>

<declare-styleable name="XCardTextView">
<attr name="android:maxWidth" />
<attr name="android:maxHeight" />
<attr name="android:minWidth" />
<attr name="android:minHeight" />
<attr name="xp_bottomDividerHeight" />
<attr name="xp_bottomDividerColor" />
<attr name="xp_bottomDividerInsetLeft" />
<attr name="xp_bottomDividerInsetRight" />
<attr name="xp_topDividerHeight" />
<attr name="xp_topDividerColor" />
<attr name="xp_topDividerInsetLeft" />
<attr name="xp_topDividerInsetRight" />
<attr name="xp_leftDividerWidth" />
<attr name="xp_leftDividerColor" />
<attr name="xp_leftDividerInsetTop" />
<attr name="xp_leftDividerInsetBottom" />
<attr name="xp_rightDividerWidth" />
<attr name="xp_rightDividerColor" />
<attr name="xp_rightDividerInsetTop" />
<attr name="xp_rightDividerInsetBottom" />
<attr name="xp_radius" />
<attr name="xp_isRadiusAdjustBounds" />
<attr name="xp_borderColor" />
<attr name="xp_borderWidth" />
<attr name="xp_outerNormalColor" />
<attr name="xp_hideRadiusSide" />
<attr name="xp_shadowElevation" />
<attr name="xp_shadowAlpha" />
<attr name="xp_shadowColor" />
<attr name="xp_showBorderOnlyBeforeL" />
<attr name="xp_outlineInsetTop" />
<attr name="xp_outlineInsetLeft" />
<attr name="xp_outlineInsetRight" />
<attr name="xp_outlineInsetBottom" />
<attr name="xp_outlineExcludePadding" />
<attr name="xp_backgroundGradientStartColor" />
<attr name="xp_backgroundGradientEndColor" />
<attr name="xp_backgroundGradientOrientation" />
<attr name="xp_borderGradientOrientation" />
<attr name="xp_borderGradientEndColor" />
<attr name="xp_borderGradientStartColor" />
</declare-styleable>

<declare-styleable name="XCardConstraintLayout">
<attr name="android:maxWidth" />
<attr name="android:maxHeight" />
Expand Down

0 comments on commit eb06070

Please sign in to comment.