Skip to content

Commit

Permalink
1,新增功能
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyJingFish committed Apr 3, 2023
1 parent 5229fa9 commit 9c91cfa
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 70 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
<img src="https://github.com/FlyJingFish/GradientTextView/blob/master/screenshot/Screenshot_20221012_141234.jpg" width="405px" height="842px" alt="show" />

## 特色功能

## 新增继承 [PerfectTextView](https://github.com/FlyJingFish/PerfectTextView)

**继承[PerfectTextView](https://github.com/FlyJingFish/PerfectTextView) 可使用其所有功能,您可前往查看如何使用[点这里查看](https://github.com/FlyJingFish/PerfectTextView)**

1,支持前景字体渐变色,支持设置渐变方向

2,支持设置字体背景粗边,粗边支持渐变色
Expand All @@ -32,7 +37,7 @@

```gradle
dependencies {
implementation 'com.github.FlyJingFish:GradientTextView:1.0.7'
implementation 'com.github.FlyJingFish:GradientTextView:1.0.8'
}
```
## 第三步,使用说明
Expand Down
1 change: 1 addition & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ android {

dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
api 'com.github.FlyJingFish:PerfectTextView:1.1.8'
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Shader;
import android.graphics.drawable.Drawable;
import android.text.Layout;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.util.LayoutDirection;
Expand All @@ -19,9 +19,11 @@
import androidx.appcompat.widget.AppCompatTextView;
import androidx.core.text.TextUtilsCompat;

import com.flyjingfish.perfecttextviewlib.PerfectTextView;

import java.util.Locale;

public class GradientTextView extends AppCompatTextView {
public class GradientTextView extends PerfectTextView {

private final TextView backGroundText;
private int strokeWidth;
Expand Down Expand Up @@ -161,9 +163,9 @@ protected void onDraw(Canvas canvas) {
}

protected float[] getAngleXY(float currentAngle){
int[] paddings = getCompoundDrawablesPaddings();
int height = getHeight() - paddings[3] - paddings[1];
int width = getWidth() - paddings[2] - paddings[0];
Layout layout = getLayout();
int height = layout.getHeight();
int width = layout.getWidth();

float angle = currentAngle % 360;
if (angle < 0) {
Expand Down Expand Up @@ -389,67 +391,4 @@ private void initCompoundDrawables(){
backGroundText.setCompoundDrawables(drawableLeft,drawableTop,drawableRight,drawableBottom);
}

private int[] getCompoundDrawablesPaddings(){
Drawable[] drawablesRelative = getCompoundDrawablesRelative();

Drawable[] drawables = getCompoundDrawables();

Drawable drawableLeft;
Drawable drawableRight;
Drawable drawableTop = null;
Drawable drawableBottom = null;
if (isRtl){
if (drawablesRelative[0] != null || drawablesRelative[2] != null){
drawableLeft = drawablesRelative[2];
drawableRight = drawablesRelative[0];
}else {
drawableLeft = drawables[0];
drawableRight = drawables[2];
}

}else {
if (drawablesRelative[0] != null || drawablesRelative[2] != null){
drawableLeft = drawablesRelative[0];
drawableRight = drawablesRelative[2];
}else {
drawableLeft = drawables[0];
drawableRight = drawables[2];
}

}

if (drawablesRelative[1] != null){
drawableTop = drawablesRelative[1];
}else if (drawables[1] != null){
drawableTop = drawables[1];
}

if (drawablesRelative[3] != null){
drawableBottom = drawablesRelative[3];
}else if (drawables[3] != null){
drawableBottom = drawables[3];
}

int[] paddings = new int[4];
paddings[0] = ViewUtils.getViewPaddingLeft(this);
paddings[1] = getPaddingTop();
paddings[2] = ViewUtils.getViewPaddingRight(this);
paddings[3] = getPaddingBottom();
int drawablePadding = getCompoundDrawablePadding();
if (drawableLeft != null){
paddings[0] = drawableLeft.getMinimumWidth()+paddings[0]+drawablePadding;
}
if (drawableTop != null){
paddings[1] = drawableTop.getMinimumWidth()+paddings[1]+drawablePadding;
}
if (drawableRight != null){
paddings[2] = drawableRight.getMinimumWidth()+paddings[2]+drawablePadding;
}

if (drawableBottom != null){
paddings[3] = drawableBottom.getMinimumWidth()+paddings[3]+drawablePadding;
}

return paddings;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import java.util.Locale;

public class ViewUtils {
class ViewUtils {

public static int getViewPaddingLeft(View view){
boolean isRtl = false;
Expand Down

0 comments on commit 9c91cfa

Please sign in to comment.