-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhangjin
committed
May 14, 2021
0 parents
commit 83a37b4
Showing
45 changed files
with
1,880 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/build | ||
/src/test | ||
/src/androidTest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'com.github.dcendents.android-maven' | ||
|
||
android { | ||
compileSdkVersion 30 | ||
buildToolsVersion "30.0.3" | ||
|
||
defaultConfig { | ||
minSdkVersion 16 | ||
targetSdkVersion 30 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles "consumer-rules.pro" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: "libs", include: ["*.jar"]) | ||
implementation 'androidx.appcompat:appcompat:1.2.0' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.2' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | ||
|
||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.zjview.library"> | ||
</manifest> |
34 changes: 34 additions & 0 deletions
34
ZJlibrary/src/main/java/com/zjview/library/ZJCenterTextView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.zjview.library; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.view.Gravity; | ||
import android.widget.TextView; | ||
|
||
|
||
@SuppressLint("AppCompatCustomView") | ||
public class ZJCenterTextView extends TextView implements ZJView { | ||
|
||
|
||
private ZJCenterTextViewRenderProxy mSharpViewRenderProxy; | ||
|
||
public ZJCenterTextView(Context context) { | ||
this(context, null); | ||
} | ||
|
||
public ZJCenterTextView(Context context, AttributeSet attrs) { | ||
this(context, attrs, -1); | ||
} | ||
|
||
public ZJCenterTextView(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
this.mSharpViewRenderProxy = new ZJCenterTextViewRenderProxy(this, context, attrs, defStyleAttr); | ||
setGravity(Gravity.CENTER); | ||
} | ||
|
||
|
||
public ZJCenterTextViewRenderProxy getmSharpViewRenderProxy() { | ||
return mSharpViewRenderProxy; | ||
} | ||
} |
247 changes: 247 additions & 0 deletions
247
ZJlibrary/src/main/java/com/zjview/library/ZJCenterTextViewRenderProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,247 @@ | ||
package com.zjview.library; | ||
|
||
import android.content.Context; | ||
import android.content.res.TypedArray; | ||
import android.graphics.drawable.GradientDrawable; | ||
import android.os.Build; | ||
import android.util.AttributeSet; | ||
import android.view.Gravity; | ||
import android.view.View; | ||
|
||
|
||
public class ZJCenterTextViewRenderProxy { | ||
public static final int TOP_BOTTOM = 0; | ||
public static final int TR_BL = 1; | ||
public static final int RIGHT_LEFT = 2; | ||
public static final int BR_TL = 3; | ||
public static final int BOTTOM_TOP = 4; | ||
public static final int BL_TR = 5; | ||
public static final int LEFT_RIGHT = 6; | ||
public static final int TL_BR = 7; | ||
private View mView; | ||
private int textGravity; | ||
private ZJCenterTextView textView; | ||
|
||
public int getGradientOrientation() { | ||
return gradientOrientation; | ||
} | ||
|
||
public void setGradientOrientation(int gradientOrientation) { | ||
this.gradientOrientation = gradientOrientation; | ||
} | ||
|
||
private int gradientOrientation; | ||
|
||
|
||
public float getRadius() { | ||
return mRadius; | ||
} | ||
|
||
public int getBackgroundColor() { | ||
return mBackgroundColor; | ||
} | ||
|
||
public float getRelativePosition() { | ||
return mRelativePosition; | ||
} | ||
|
||
public float getSharpSize() { | ||
return mSharpSize; | ||
} | ||
|
||
public float getBorder() { | ||
return mBorder; | ||
} | ||
|
||
public int getBorderColor() { | ||
return mBorderColor; | ||
} | ||
|
||
public int[] getBgColors() { | ||
return mBgColors; | ||
} | ||
|
||
public float[] getCornerRadii() { | ||
return mCornerRadii; | ||
} | ||
|
||
public ZJView.ArrowDirection getArrowDirection() { | ||
return mArrowDirection; | ||
} | ||
|
||
private float mRadius; | ||
|
||
private int mBackgroundColor; | ||
|
||
private float mRelativePosition; | ||
|
||
private float mSharpSize; | ||
|
||
private float mBorder; | ||
|
||
private int mBorderColor; | ||
|
||
public void setBgColor(int[] bgColor) { | ||
mBgColors = bgColor; | ||
refreshView(); | ||
} | ||
|
||
private int[] mBgColors; | ||
|
||
public void setCornerRadii(float leftTop, float rightTop, float rightBottom, float leftBottom) { | ||
mCornerRadii[0] = leftTop; | ||
mCornerRadii[1] = leftTop; | ||
mCornerRadii[2] = rightTop; | ||
mCornerRadii[3] = rightTop; | ||
mCornerRadii[4] = rightBottom; | ||
mCornerRadii[5] = rightBottom; | ||
mCornerRadii[6] = leftBottom; | ||
mCornerRadii[7] = leftBottom; | ||
|
||
} | ||
|
||
private float[] mCornerRadii = new float[8]; | ||
|
||
private ZJView.ArrowDirection mArrowDirection = ZJView.ArrowDirection.LEFT; | ||
|
||
public void setBorder(float border) { | ||
mBorder = border; | ||
refreshView(); | ||
} | ||
|
||
public void setBorderColor(int borderColor) { | ||
mBorderColor = borderColor; | ||
refreshView(); | ||
} | ||
|
||
ZJCenterTextViewRenderProxy(View view, Context context, AttributeSet attrs, int defStyleAttr) { | ||
mView = view; | ||
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ZJCenterTextView, defStyleAttr, 0); | ||
mRadius = typedArray.getDimension(R.styleable.ZJCenterTextView_radius, 0); | ||
mCornerRadii[0] = mCornerRadii[1] = typedArray.getDimension(R.styleable.ZJCenterTextView_left_top_radius, 0); | ||
mCornerRadii[2] = mCornerRadii[3] = typedArray.getDimension(R.styleable.ZJCenterTextView_right_top_radius, 0); | ||
mCornerRadii[4] = mCornerRadii[5] = typedArray.getDimension(R.styleable.ZJCenterTextView_right_bottom_radius, 0); | ||
mCornerRadii[6] = mCornerRadii[7] = typedArray.getDimension(R.styleable.ZJCenterTextView_left_bottom_radius, 0); | ||
mBorder = typedArray.getDimension(R.styleable.ZJCenterTextView_border, 0); | ||
mBackgroundColor = typedArray.getColor(R.styleable.ZJCenterTextView_backgroundColor, 0); | ||
mBorderColor = typedArray.getColor(R.styleable.ZJCenterTextView_borderColor, 0); | ||
int direction = typedArray.getInt(R.styleable.ZJCenterTextView_arrowDirection, 3); | ||
mRelativePosition = typedArray.getFraction(R.styleable.ZJCenterTextView_relativePosition, 1, 1, 0.5f); | ||
mSharpSize = typedArray.getDimension(R.styleable.ZJCenterTextView_sharpSize, 0); | ||
textGravity = typedArray.getInt(R.styleable.ZJCenterTextView_android_gravity, Gravity.CENTER); | ||
|
||
gradientOrientation = typedArray.getInt(R.styleable.ZJCenterTextView_gradient_orientation, 6); | ||
switch (direction) { | ||
case 1: | ||
mArrowDirection = ZJView.ArrowDirection.LEFT; | ||
break; | ||
case 2: | ||
mArrowDirection = ZJView.ArrowDirection.TOP; | ||
break; | ||
case 3: | ||
mArrowDirection = ZJView.ArrowDirection.RIGHT; | ||
break; | ||
case 4: | ||
mArrowDirection = ZJView.ArrowDirection.BOTTOM; | ||
break; | ||
} | ||
int start = typedArray.getColor(R.styleable.ZJCenterTextView_startBgColor, -1); | ||
int middle = typedArray.getColor(R.styleable.ZJCenterTextView_middleBgColor, -1); | ||
int end = typedArray.getColor(R.styleable.ZJCenterTextView_endBgColor, -1); | ||
if (start != -1 && end != -1) { | ||
if (middle != -1) { | ||
mBgColors = new int[]{start, middle, end}; | ||
} else { | ||
mBgColors = new int[]{start, end}; | ||
} | ||
} | ||
typedArray.recycle(); | ||
refreshView(); | ||
} | ||
|
||
ZJDrawable mSharpDrawable; | ||
|
||
private void refreshView() { | ||
ZJDrawable bd = new ZJDrawable(GradientDrawable.Orientation.LEFT_RIGHT, null); | ||
mSharpDrawable = bd; | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { | ||
bd.setColors(mBgColors); | ||
switch (gradientOrientation) { | ||
case TOP_BOTTOM: | ||
bd.setOrientation(GradientDrawable.Orientation.TOP_BOTTOM); | ||
break; | ||
case TR_BL: | ||
bd.setOrientation(GradientDrawable.Orientation.TR_BL); | ||
break; | ||
case RIGHT_LEFT: | ||
bd.setOrientation(GradientDrawable.Orientation.RIGHT_LEFT); | ||
break; | ||
case BR_TL: | ||
bd.setOrientation(GradientDrawable.Orientation.BR_TL); | ||
break; | ||
case BOTTOM_TOP: | ||
bd.setOrientation(GradientDrawable.Orientation.BOTTOM_TOP); | ||
break; | ||
case BL_TR: | ||
bd.setOrientation(GradientDrawable.Orientation.BL_TR); | ||
break; | ||
case LEFT_RIGHT: | ||
bd.setOrientation(GradientDrawable.Orientation.LEFT_RIGHT); | ||
break; | ||
case TL_BR: | ||
bd.setOrientation(GradientDrawable.Orientation.TL_BR); | ||
break; | ||
} | ||
} else { | ||
bd.setColor(mBgColors[0]); | ||
} | ||
|
||
if (mBgColors != null) { | ||
bd.setColors(mBgColors); | ||
} else { | ||
bd.setBgColor(mBackgroundColor); | ||
} | ||
bd.setSharpSize(mSharpSize); | ||
bd.setArrowDirection(mArrowDirection); | ||
bd.setCornerRadius(mRadius); | ||
bd.setBorder(mBorder); | ||
bd.setBorderColor(mBorderColor); | ||
bd.setRelativePosition(mRelativePosition); | ||
if (mRadius == 0) { | ||
bd.setCornerRadii(mCornerRadii); | ||
} | ||
|
||
mView.setBackground(bd); | ||
textView = (ZJCenterTextView) mView; | ||
textView.setGravity(textGravity); | ||
} | ||
|
||
public void setRadius(float radius) { | ||
mRadius = radius; | ||
refreshView(); | ||
} | ||
|
||
public void setBackgroundColor(int backgroundColor) { | ||
mBackgroundColor = backgroundColor; | ||
mBgColors = null; | ||
refreshView(); | ||
} | ||
|
||
public void setRelativePosition(float relativePosition) { | ||
mRelativePosition = relativePosition; | ||
refreshView(); | ||
} | ||
|
||
public void setSharpSize(float sharpSize) { | ||
mSharpSize = sharpSize; | ||
refreshView(); | ||
} | ||
|
||
public void setArrowDirection(ZJView.ArrowDirection arrowDirection) { | ||
mArrowDirection = arrowDirection; | ||
refreshView(); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.