diff --git a/.idea/compiler.xml b/.idea/compiler.xml
deleted file mode 100644
index 96cc43e..0000000
--- a/.idea/compiler.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
-

-#基本使用
-###1.添加Gradle依赖
+# 基本使用
+
+### 1.添加Gradle依赖
先在项目根目录的 build.gradle 的 repositories 添加:
allprojects {
@@ -25,7 +26,7 @@
compile 'com.github.lygttpod:SuperTextView:1.1.2'
}
-###2.布局中如何使用(列出所有属性使用方法)
+### 2.布局中如何使用(列出所有属性使用方法)

-
-
-
-
-
-
+
+
-### V1.0.1
-* 修复编译版本不同导致无法正常使用的bug
+或者手动加QQ群:688433795
-### V1.0.0
-* 功能强大的TextView
+如果遇到问题或者好的建议,请反馈到:[issue](https://github.com/lygttpod/RxHttpUtils/issues)、[lygttpod@163.com](mailto:lygttpod@163.com) 或者[lygttpod@gmail.com](mailto:lygttpod@gmail.com)
-# 意见反馈
+如果觉得对你有用的话,点一下右上的星星赞一下吧!
-如果遇到问题或者好的建议,请反馈到我的邮箱:[lygttpod@163.com](mailto:lygttpod@163.com) 或者[lygttpod@gmail.com](mailto:lygttpod@gmail.com)
+## 代码是最好的老师,更多详细用法请查看 [demo](https://github.com/lygttpod/SuperTextView/tree/master/app):feet:
-如果觉得对你有用的话,点一下右上的星星赞一下吧!
# License
```
diff --git a/SuperButton_Readme.md b/SuperButton_Readme.md
new file mode 100644
index 0000000..98009ed
--- /dev/null
+++ b/SuperButton_Readme.md
@@ -0,0 +1,111 @@
+# SuperButton
+
+> ## SuperButton可以实现shape大部分属性设置,从此实现边框之类的UI宝宝再也不用写很多shape文件了,想怎么玩就怎么玩!
+
+# 效果图
+
+ * @author : Allen + * e-mail : lygttpod@163.com + * date : 2019/09/21 + * desc : + *+ */ +class ShadowActivity : AppCompatActivity(), SeekBar.OnSeekBarChangeListener { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_shadow) + setShadowColor() + + shadow_color_alpha_sb.setOnSeekBarChangeListener(this) + + shadow_padding_left_sb.setOnSeekBarChangeListener(this) + shadow_padding_top_sb.setOnSeekBarChangeListener(this) + shadow_padding_right_sb.setOnSeekBarChangeListener(this) + shadow_padding_bottom_sb.setOnSeekBarChangeListener(this) + + shadow_left_top_radius_sb.setOnSeekBarChangeListener(this) + shadow_left_bottom_radius_sb.setOnSeekBarChangeListener(this) + shadow_right_top_radius_sb.setOnSeekBarChangeListener(this) + shadow_right_bottom_radius_sb.setOnSeekBarChangeListener(this) + + shadow_all_radius_sb.setOnSeekBarChangeListener(this) + + shape_view.shadowHelper?.let { + it.setShadowAllRadius(10f) + .setShadowLeftWidth(20f) + .setShadowTopWidth(10f) + .setShadowBottomWidth(20f) + .setShadowRightWidth(10f) + .applyToView() + } + + } + + private fun setShadowColor() { + change_shadow_color_btn.setOnClickListener { + val colorString = shadow_color_et.text.toString() + if (colorString.length == 6 || colorString.length == 8) { + try { + val color = Color.parseColor("#$colorString") + shape_view.shadowHelper?.setShadowColor(color)?.applyToView() + } catch (e: Exception) { + } + } + } + } + + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { + + val size = progress.toFloat() + when (seekBar.id) { + R.id.shadow_color_alpha_sb -> { + shape_view.shadowHelper?.setShadowColorAlpha(size / 100) + } + R.id.shadow_padding_left_sb -> { + shape_view.shadowHelper?.setShadowLeftWidth(size) + } + R.id.shadow_padding_top_sb -> { + shape_view.shadowHelper?.setShadowTopWidth(size) + } + R.id.shadow_padding_right_sb -> { + shape_view.shadowHelper?.setShadowRightWidth(size) + } + R.id.shadow_padding_bottom_sb -> { + shape_view.shadowHelper?.setShadowBottomWidth(size) + } + R.id.shadow_left_top_radius_sb -> { + shadow_all_radius_sb.progress = 0 + shape_view.shadowHelper?.setShadowLeftTopRadius(size) + } + R.id.shadow_left_bottom_radius_sb -> { + shadow_all_radius_sb.progress = 0 + shape_view.shadowHelper?.setShadowLeftBottomRadius(size) + } + R.id.shadow_right_top_radius_sb -> { + shadow_all_radius_sb.progress = 0 + shape_view.shadowHelper?.setShadowRightTopRadius(size) + } + R.id.shadow_right_bottom_radius_sb -> { + shadow_all_radius_sb.progress = 0 + shape_view.shadowHelper?.setShadowRightBottomRadius(size) + } + R.id.shadow_all_radius_sb -> { + shadow_left_top_radius_sb.progress = 0 + shadow_left_bottom_radius_sb.progress = 0 + shadow_right_top_radius_sb.progress = 0 + shadow_right_bottom_radius_sb.progress = 0 + shape_view.shadowHelper?.setShadowAllRadius(size) + } + } + shape_view.shadowHelper?.applyToView() + + } + + override fun onStartTrackingTouch(seekBar: SeekBar?) { + } + + override fun onStopTrackingTouch(seekBar: SeekBar?) { + } +} \ No newline at end of file diff --git a/app/src/main/java/com/allen/supertextview/ShapeActivity.kt b/app/src/main/java/com/allen/supertextview/ShapeActivity.kt new file mode 100644 index 0000000..c3614fe --- /dev/null +++ b/app/src/main/java/com/allen/supertextview/ShapeActivity.kt @@ -0,0 +1,49 @@ +package com.allen.supertextview + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import com.allen.library.helper.ShapeBuilder +import com.allen.library.helper.ShapeType +import kotlinx.android.synthetic.main.activiy_shape.* + +/** + *
+ * @author : Allen + * e-mail : lygttpod@163.com + * date : 2019/05/31 + * desc : +* + */ +class ShapeActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activiy_shape) + + shape_text_view.setOnClickListener { + shape_text_view.shapeBuilder?.let { + it.setShapeType(ShapeType.RECTANGLE) + .setShapeSolidColor(resources.getColor(R.color.colorAccent)) + .setShapeStrokeColor(resources.getColor(R.color.colorPrimary)) + .setShapeStrokeWidth(2) + .setShapeCornersRadius(30f) + .into(shape_text_view) + } + } + + } + + /** + * 如果ShapeXXXView无法满足你的布局需求可以,使用ShapeBuilder对任何view设置shape属性 + * 用法如下: + * normalShape.into("你的任意View") + */ + private val normalShape: ShapeBuilder + get() = ShapeBuilder() + .setShapeType(ShapeType.RECTANGLE) + .setShapeSolidColor(resources.getColor(R.color.colorAccent)) + .setShapeStrokeColor(resources.getColor(R.color.colorPrimary)) + .setShapeStrokeWidth(2) + .setShapeCornersRadius(30f) + +} diff --git a/app/src/main/java/com/allen/supertextview/SuperButtonActivity.java b/app/src/main/java/com/allen/supertextview/SuperButtonActivity.java new file mode 100644 index 0000000..f41328a --- /dev/null +++ b/app/src/main/java/com/allen/supertextview/SuperButtonActivity.java @@ -0,0 +1,42 @@ +package com.allen.supertextview; + +import android.os.Bundle; +import androidx.appcompat.app.AppCompatActivity; + +import com.allen.library.SuperButton; + +/** + * Created by allen on 2017/7/10. + */ +public class SuperButtonActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.super_button_layout); + + + SuperButton superButton = new SuperButton(this); + + /** + * 所有属性均可用代码动态实现 + * 以下只是展示部分方法 可根据需求选择不同的方法 + */ + superButton.setShapeType(SuperButton.RECTANGLE) + .setShapeCornersRadius(20) + .setShapeSolidColor(getResources().getColor(R.color.colorAccent)) + .setShapeStrokeColor(getResources().getColor(R.color.colorPrimary)) + .setShapeStrokeWidth(1) + .setShapeStrokeDashWidth(2) + .setShapeStrokeDashGap(5) + .setTextGravity(SuperButton.TEXT_GRAVITY_RIGHT) + .setShapeUseSelector(true) + .setShapeSelectorPressedColor(getResources().getColor(R.color.gray)) + .setShapeSelectorNormalColor(getResources().getColor(R.color.red_btn)) + .setShapeSelectorDisableColor(getResources().getColor(R.color.colorPrimary)) + .setUseShape(); + // TODO: 2017/8/12 动态设置切记需要在最后调用 setUseShape 才能对设置的参数生效 + + } + +} diff --git a/app/src/main/java/com/allen/supertextview/TypeActivity.java b/app/src/main/java/com/allen/supertextview/TypeActivity.java index a7d68bf..d3f854b 100644 --- a/app/src/main/java/com/allen/supertextview/TypeActivity.java +++ b/app/src/main/java/com/allen/supertextview/TypeActivity.java @@ -1,10 +1,21 @@ package com.allen.supertextview; +import android.graphics.Color; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.widget.ImageView; +import androidx.appcompat.app.AppCompatActivity; +import android.view.Gravity; import com.allen.library.SuperTextView; +import com.allen.library.helper.ShapeGradientAngle; +import com.allen.library.helper.ShapeBuilder; +import com.allen.library.helper.ShapeGradientType; +import com.allen.library.helper.ShapeType; +import com.allen.library.shape.ShapeLinearLayout; +import com.allen.supertextview.utils.DisplayUtils; +import com.bumptech.glide.Glide; +import com.bumptech.glide.load.resource.drawable.GlideDrawable; +import com.bumptech.glide.request.animation.GlideAnimation; +import com.bumptech.glide.request.target.SimpleTarget; import com.squareup.picasso.Picasso; /** @@ -13,15 +24,22 @@ public class TypeActivity extends AppCompatActivity { private int type; - private SuperTextView superTextView,superTextView2,superTextView3; + private SuperTextView superTextView, superTextView2, superTextView3, alipayStv, superTextView4; @Override - protected void onCreate( Bundle savedInstanceState) { + protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); type = getIntent().getIntExtra("type", 0); switch (type) { case 0: setContentView(R.layout.main); + SuperTextView superTextView = findViewById(R.id.setDiv_stv); + SuperTextView superTextView2 = findViewById(R.id.setShape_stv); + SuperTextView superTextView3 = findViewById(R.id.setShape_stv2); + superTextView.setTopDividerLineColor(getResources().getColor(R.color.colorAccent)) + .setBottomDividerLineColor(getResources().getColor(R.color.colorPrimary)); + setShape1(superTextView2); + setShape2(superTextView3); break; case 1: setContentView(R.layout.layout1); @@ -41,26 +59,85 @@ protected void onCreate( Bundle savedInstanceState) { break; case 6: setContentView(R.layout.layout6); + superTextView4 = (SuperTextView) findViewById(R.id.super_tv4); + superTextView4.setCenterTextGravity(Gravity.LEFT); + + break; + case 7: + setContentView(R.layout.layout7); break; + case 8: + setContentView(R.layout.layout8); + break; + } + } + + private void setShape1(SuperTextView stv) { + stv + .getShapeBuilder() + .setShapeGradientAngle(ShapeGradientAngle.TL_BR) + .setShapeGradientStartColor(getResources().getColor(R.color.colorPrimary)) + .setShapeGradientEndColor(getResources().getColor(R.color.colorAccent)) + .into(stv); + } + private void setShape2(SuperTextView stv) { + ShapeBuilder shapeBuilder = new ShapeBuilder(); + shapeBuilder + .setShapeType(ShapeType.RECTANGLE) + .setShapeCornersRadius(DisplayUtils.dip2px(this,25f)) + .setShapeStrokeWidth(DisplayUtils.dip2px(this,2f)) + .setShapeStrokeColor(Color.YELLOW) + .setShapeStrokeDashWidth(DisplayUtils.dip2px(this,5f)) + .setShapeStrokeDashGap(DisplayUtils.dip2px(this,2f)) + .setShapeGradientAngle(ShapeGradientAngle.TR_BL) + .setShapeGradientStartColor(getResources().getColor(R.color.colorPrimary)) + .setShapeGradientEndColor(getResources().getColor(R.color.colorAccent)) + .into(stv); } private void setData() { superTextView = (SuperTextView) findViewById(R.id.super_tv1); superTextView2 = (SuperTextView) findViewById(R.id.super_tv2); + superTextView3 = (SuperTextView) findViewById(R.id.super_tv3); + alipayStv = (SuperTextView) findViewById(R.id.alipay_stv); - superTextView.setLeftTopString("姓名").setLeftBottomString("188********"); - superTextView2.setLeftTopString("姓名").setLeftBottomString("181********"); + String url1 = "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3860616424,1789830124&fm=80&w=179&h=119&img.PNG"; + String url2 = "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=219781665,3032880226&fm=80&w=179&h=119&img.JPEG"; + String url3 = "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3860616424,1789830124&fm=80&w=179&h=119&img.PNG"; + String url4 = "http://osnoex6vf.bkt.clouddn.com/original_label.png"; + Picasso.with(this) + .load(url1) + .placeholder(R.drawable.head_default) + .into(superTextView.getLeftIconIV()); + Glide.with(this) + .load(url2) + .placeholder(R.drawable.head_default) + .fitCenter() + .into(superTextView2.getRightIconIV()); - Picasso.with(this).load("https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3860616424,1789830124&fm=80&w=179&h=119&img.PNG") - .placeholder(R.drawable.head_default).into((ImageView) superTextView.getView(SuperTextView.leftImageViewId)); - Picasso.with(this).load("https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=219781665,3032880226&fm=80&w=179&h=119&img.JPEG") - .placeholder(R.drawable.head_default).into((ImageView) superTextView2.getView(SuperTextView.rightImageViewId)); + Glide.with(this) + .load(url3) + .placeholder(R.drawable.head_default) + .into(new SimpleTarget
+ * @author : Allen + * e-mail : lygttpod@163.com + * date : 2019/06/04 + * desc : + *+ */ +public class DisplayUtils { + /** + * 获取屏幕分辨率 + * + * @param context + * @return + */ + public static int[] getScreenDispaly(Context context) { + WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); + int width = windowManager.getDefaultDisplay().getWidth();// 手机屏幕的宽度 + int height = windowManager.getDefaultDisplay().getHeight();// 手机屏幕的高度 + int result[] = {width, height}; + return result; + } + + /** + * 获取屏幕宽度 + */ + public static int getDisplayWidth(Context context) { + if (context != null) { + DisplayMetrics dm = context.getResources().getDisplayMetrics(); + int w_screen = dm.widthPixels; + // int h_screen = dm.heightPixels; + return w_screen; + } + return 720; + } + + /** + * 获取屏幕高度 + */ + public static int getDisplayHight(Context context) { + if (context != null) { + DisplayMetrics dm = context.getResources().getDisplayMetrics(); + // int w_screen = dm.widthPixels; + int h_screen = dm.heightPixels; + return h_screen; + } + return 1280; + } + + public static int dip2px(Context context, float dipValue) { + final float scale = context.getResources().getDisplayMetrics().density; + return (int) (dipValue * scale + 0.5f); + } + + public static int px2dip(Context context, float pxValue) { + final float scale = context.getResources().getDisplayMetrics().density; + return (int) (pxValue / scale + 0.5f); + } +} diff --git a/app/src/main/res/color/selector_stv_text_color.xml b/app/src/main/res/color/selector_stv_text_color.xml new file mode 100644 index 0000000..cbeef4c --- /dev/null +++ b/app/src/main/res/color/selector_stv_text_color.xml @@ -0,0 +1,5 @@ + +
+ * 基础TextView + */ + +public class BaseTextView extends LinearLayout { + + private Context mContext; + + private AppCompatTextView topTextView, centerTextView, bottomTextView; + + private LinearLayout.LayoutParams topTVParams, centerTVParams, bottomTVParams; + + public BaseTextView(Context context) { + this(context, null); + } + + public BaseTextView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public BaseTextView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + + this.setOrientation(VERTICAL); + + mContext = context; + + initView(); + } + + private void initView() { + initTopView(); + initCenterView(); + initBottomView(); + } + + private void initTopView() { + if (topTVParams == null) { + topTVParams = getParams(topTVParams); + } + if (topTextView == null) { + topTextView = initTextView(topTVParams, topTextView); + } + } + + private void initCenterView() { + if (centerTVParams == null) { + centerTVParams = getParams(centerTVParams); + } + if (centerTextView == null) { + centerTextView = initTextView(centerTVParams, centerTextView); + } + } + + private void initBottomView() { + if (bottomTVParams == null) { + bottomTVParams = getParams(bottomTVParams); + } + if (bottomTextView == null) { + bottomTextView = initTextView(bottomTVParams, bottomTextView); + } + } + + + private AppCompatTextView initTextView(LinearLayout.LayoutParams params, AppCompatTextView textView) { + + textView = getTextView(textView, params); +// textView.setGravity(Gravity.CENTER); + addView(textView); + return textView; + } + + + /** + * 初始化textView + * + * @param textView 对象 + * @param layoutParams 对象 + * @return 返回 + */ + public AppCompatTextView getTextView(AppCompatTextView textView, LinearLayout.LayoutParams layoutParams) { + if (textView == null) { + textView = new AppCompatTextView(mContext); + textView.setLayoutParams(layoutParams); + textView.setVisibility(GONE); + } + return textView; + } + + /** + * 初始化Params + * + * @param params 对象 + * @return 返回 + */ + public LayoutParams getParams(LayoutParams params) { + if (params == null) { + // TODO: 2017/7/21 问题记录 :之前设置 MATCH_PARENT导致每次重新设置string的时候,textView的宽度都已第一次为准,在列表中使用的时候服用出现混乱,特此记录一下,以后处理好布局之间套用时候设置WRAP_CONTENT和MATCH_PARENT出现问题 + params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + } + return params; + } + + + private void setTextString(AppCompatTextView textView, CharSequence textString) { + textView.setText(textString); + if (!TextUtils.isEmpty(textString)) { + textView.setVisibility(VISIBLE); + } + } + + public void setTopTextString(CharSequence s) { + setTextString(topTextView, s); + } + + + public void setCenterTextString(CharSequence s) { + setTextString(centerTextView, s); + } + + public void setBottomTextString(CharSequence s) { + setTextString(bottomTextView, s); + } + + public AppCompatTextView getTopTextView() { + return topTextView; + } + + public AppCompatTextView getCenterTextView() { + return centerTextView; + } + + public AppCompatTextView getBottomTextView() { + return bottomTextView; + } + + public void setMaxEms(int topMaxEms, int centerMaxEms, int bottomMaxEms) { + + if (topMaxEms != 0) { + topTextView.setEllipsize(TextUtils.TruncateAt.END); + topTextView.setFilters(new InputFilter[]{new InputFilter.LengthFilter(topMaxEms)}); + } + if (centerMaxEms != 0) { + centerTextView.setEllipsize(TextUtils.TruncateAt.END); + centerTextView.setFilters(new InputFilter[]{new InputFilter.LengthFilter(centerMaxEms)}); + } + if (bottomMaxEms != 0) { + bottomTextView.setEllipsize(TextUtils.TruncateAt.END); + bottomTextView.setFilters(new InputFilter[]{new InputFilter.LengthFilter(bottomMaxEms)}); + } + + } + + public void setFakeBoldText(TextView textView, boolean isBold) { + if (textView != null) { + textView.getPaint().setFakeBoldText(isBold); + //在点击事件里边设置setFakeBoldText是无效的,必须调用invalidate刷新一下view + textView.invalidate(); + } + } + + public void setCenterSpaceHeight(int centerSpaceHeight) { + topTVParams.setMargins(0, 0, 0, centerSpaceHeight); + centerTVParams.setMargins(0, 0, 0, 0); + bottomTVParams.setMargins(0, centerSpaceHeight, 0, 0); + } + +} diff --git a/library/src/main/java/com/allen/library/CircleImageView.java b/library/src/main/java/com/allen/library/CircleImageView.java new file mode 100644 index 0000000..b0500a5 --- /dev/null +++ b/library/src/main/java/com/allen/library/CircleImageView.java @@ -0,0 +1,480 @@ +package com.allen.library; + +/* + * Copyright 2014 - 2017 Henning Dodenhof + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Bitmap; +import android.graphics.BitmapShader; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.ColorFilter; +import android.graphics.Matrix; +import android.graphics.Outline; +import android.graphics.Paint; +import android.graphics.Rect; +import android.graphics.RectF; +import android.graphics.Shader; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.ColorDrawable; +import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.os.Build; +import androidx.annotation.ColorInt; +import androidx.annotation.ColorRes; +import androidx.annotation.DrawableRes; +import androidx.annotation.RequiresApi; +import androidx.appcompat.widget.AppCompatImageView; + +import android.util.AttributeSet; +import android.view.View; +import android.view.ViewOutlineProvider; +import android.widget.ImageView; + +public class CircleImageView extends AppCompatImageView { + + private static final ScaleType SCALE_TYPE = ScaleType.CENTER_CROP; + + private static final Bitmap.Config BITMAP_CONFIG = Bitmap.Config.ARGB_8888; + private static final int COLORDRAWABLE_DIMENSION = 2; + + private static final int DEFAULT_BORDER_WIDTH = 0; + private static final int DEFAULT_BORDER_COLOR = Color.BLACK; + private static final int DEFAULT_CIRCLE_BACKGROUND_COLOR = Color.TRANSPARENT; + private static final boolean DEFAULT_BORDER_OVERLAY = false; + + private final RectF mDrawableRect = new RectF(); + private final RectF mBorderRect = new RectF(); + + private final Matrix mShaderMatrix = new Matrix(); + private final Paint mBitmapPaint = new Paint(); + private final Paint mBorderPaint = new Paint(); + private final Paint mCircleBackgroundPaint = new Paint(); + + private int mBorderColor = DEFAULT_BORDER_COLOR; + private int mBorderWidth = DEFAULT_BORDER_WIDTH; + private int mCircleBackgroundColor = DEFAULT_CIRCLE_BACKGROUND_COLOR; + + private Bitmap mBitmap; + private BitmapShader mBitmapShader; + private int mBitmapWidth; + private int mBitmapHeight; + + private float mDrawableRadius; + private float mBorderRadius; + + private ColorFilter mColorFilter; + + private boolean mReady; + private boolean mSetupPending; + private boolean mBorderOverlay; + private boolean mDisableCircularTransformation; + + public CircleImageView(Context context) { + super(context); + + init(); + } + + public CircleImageView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public CircleImageView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleImageView, defStyle, 0); + + mBorderWidth = a.getDimensionPixelSize(R.styleable.CircleImageView_civ_border_width, DEFAULT_BORDER_WIDTH); + mBorderColor = a.getColor(R.styleable.CircleImageView_civ_border_color, DEFAULT_BORDER_COLOR); + mBorderOverlay = a.getBoolean(R.styleable.CircleImageView_civ_border_overlay, DEFAULT_BORDER_OVERLAY); + + // Look for deprecated civ_fill_color if civ_circle_background_color is not set + if (a.hasValue(R.styleable.CircleImageView_civ_circle_background_color)) { + mCircleBackgroundColor = a.getColor(R.styleable.CircleImageView_civ_circle_background_color, + DEFAULT_CIRCLE_BACKGROUND_COLOR); + } else if (a.hasValue(R.styleable.CircleImageView_civ_fill_color)) { + mCircleBackgroundColor = a.getColor(R.styleable.CircleImageView_civ_fill_color, + DEFAULT_CIRCLE_BACKGROUND_COLOR); + } + + a.recycle(); + + init(); + } + + private void init() { + super.setScaleType(SCALE_TYPE); + mReady = true; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + setOutlineProvider(new OutlineProvider()); + } + + if (mSetupPending) { + setup(); + mSetupPending = false; + } + } + + @Override + public ScaleType getScaleType() { + return SCALE_TYPE; + } + + @Override + public void setScaleType(ScaleType scaleType) { + if (scaleType != SCALE_TYPE) { + throw new IllegalArgumentException(String.format("ScaleType %s not supported.", scaleType)); + } + } + + @Override + public void setAdjustViewBounds(boolean adjustViewBounds) { + if (adjustViewBounds) { + throw new IllegalArgumentException("adjustViewBounds not supported."); + } + } + + @Override + protected void onDraw(Canvas canvas) { + if (mDisableCircularTransformation) { + super.onDraw(canvas); + return; + } + + if (mBitmap == null) { + return; + } + + if (mCircleBackgroundColor != Color.TRANSPARENT) { + canvas.drawCircle(mDrawableRect.centerX(), mDrawableRect.centerY(), mDrawableRadius, mCircleBackgroundPaint); + } + canvas.drawCircle(mDrawableRect.centerX(), mDrawableRect.centerY(), mDrawableRadius, mBitmapPaint); + if (mBorderWidth > 0) { + canvas.drawCircle(mBorderRect.centerX(), mBorderRect.centerY(), mBorderRadius, mBorderPaint); + } + } + + @Override + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w, h, oldw, oldh); + setup(); + } + + @Override + public void setPadding(int left, int top, int right, int bottom) { + super.setPadding(left, top, right, bottom); + setup(); + } + + @Override + public void setPaddingRelative(int start, int top, int end, int bottom) { + super.setPaddingRelative(start, top, end, bottom); + setup(); + } + + public int getBorderColor() { + return mBorderColor; + } + + public void setBorderColor(@ColorInt int borderColor) { + if (borderColor == mBorderColor) { + return; + } + + mBorderColor = borderColor; + mBorderPaint.setColor(mBorderColor); + invalidate(); + } + + /** + * @deprecated Use {@link #setBorderColor(int)} instead + */ + @Deprecated + public void setBorderColorResource(@ColorRes int borderColorRes) { + setBorderColor(getContext().getResources().getColor(borderColorRes)); + } + + public int getCircleBackgroundColor() { + return mCircleBackgroundColor; + } + + public void setCircleBackgroundColor(@ColorInt int circleBackgroundColor) { + if (circleBackgroundColor == mCircleBackgroundColor) { + return; + } + + mCircleBackgroundColor = circleBackgroundColor; + mCircleBackgroundPaint.setColor(circleBackgroundColor); + invalidate(); + } + + public void setCircleBackgroundColorResource(@ColorRes int circleBackgroundRes) { + setCircleBackgroundColor(getContext().getResources().getColor(circleBackgroundRes)); + } + + /** + * Return the color drawn behind the circle-shaped drawable. + * + * @return The color drawn behind the drawable + * @deprecated Use {@link #getCircleBackgroundColor()} instead. + */ + @Deprecated + public int getFillColor() { + return getCircleBackgroundColor(); + } + + /** + * Set a color to be drawn behind the circle-shaped drawable. Note that + * this has no effect if the drawable is opaque or no drawable is set. + * + * @param fillColor The color to be drawn behind the drawable + * @deprecated Use {@link #setCircleBackgroundColor(int)} instead. + */ + @Deprecated + public void setFillColor(@ColorInt int fillColor) { + setCircleBackgroundColor(fillColor); + } + + /** + * Set a color to be drawn behind the circle-shaped drawable. Note that + * this has no effect if the drawable is opaque or no drawable is set. + * + * @param fillColorRes The color resource to be resolved to a color and + * drawn behind the drawable + * @deprecated Use {@link #setCircleBackgroundColorResource(int)} instead. + */ + @Deprecated + public void setFillColorResource(@ColorRes int fillColorRes) { + setCircleBackgroundColorResource(fillColorRes); + } + + public int getBorderWidth() { + return mBorderWidth; + } + + public void setBorderWidth(int borderWidth) { + if (borderWidth == mBorderWidth) { + return; + } + + mBorderWidth = borderWidth; + setup(); + } + + public boolean isBorderOverlay() { + return mBorderOverlay; + } + + public void setBorderOverlay(boolean borderOverlay) { + if (borderOverlay == mBorderOverlay) { + return; + } + + mBorderOverlay = borderOverlay; + setup(); + } + + public boolean isDisableCircularTransformation() { + return mDisableCircularTransformation; + } + + public void setDisableCircularTransformation(boolean disableCircularTransformation) { + if (mDisableCircularTransformation == disableCircularTransformation) { + return; + } + + mDisableCircularTransformation = disableCircularTransformation; + initializeBitmap(); + } + + @Override + public void setImageBitmap(Bitmap bm) { + super.setImageBitmap(bm); + initializeBitmap(); + } + + @Override + public void setImageDrawable(Drawable drawable) { + super.setImageDrawable(drawable); + initializeBitmap(); + } + + @Override + public void setImageResource(@DrawableRes int resId) { + super.setImageResource(resId); + initializeBitmap(); + } + + @Override + public void setImageURI(Uri uri) { + super.setImageURI(uri); + initializeBitmap(); + } + + @Override + public void setColorFilter(ColorFilter cf) { + if (cf == mColorFilter) { + return; + } + + mColorFilter = cf; + applyColorFilter(); + invalidate(); + } + + @Override + public ColorFilter getColorFilter() { + return mColorFilter; + } + + private void applyColorFilter() { + if (mBitmapPaint != null) { + mBitmapPaint.setColorFilter(mColorFilter); + } + } + + private Bitmap getBitmapFromDrawable(Drawable drawable) { + if (drawable == null) { + return null; + } + + if (drawable instanceof BitmapDrawable) { + return ((BitmapDrawable) drawable).getBitmap(); + } + + try { + Bitmap bitmap; + + if (drawable instanceof ColorDrawable) { + bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG); + } else { + bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG); + } + + Canvas canvas = new Canvas(bitmap); + drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); + drawable.draw(canvas); + return bitmap; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + private void initializeBitmap() { + if (mDisableCircularTransformation) { + mBitmap = null; + } else { + mBitmap = getBitmapFromDrawable(getDrawable()); + } + setup(); + } + + private void setup() { + if (!mReady) { + mSetupPending = true; + return; + } + + if (getWidth() == 0 && getHeight() == 0) { + return; + } + + if (mBitmap == null) { + invalidate(); + return; + } + + mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); + + mBitmapPaint.setAntiAlias(true); + mBitmapPaint.setShader(mBitmapShader); + + mBorderPaint.setStyle(Paint.Style.STROKE); + mBorderPaint.setAntiAlias(true); + mBorderPaint.setColor(mBorderColor); + mBorderPaint.setStrokeWidth(mBorderWidth); + + mCircleBackgroundPaint.setStyle(Paint.Style.FILL); + mCircleBackgroundPaint.setAntiAlias(true); + mCircleBackgroundPaint.setColor(mCircleBackgroundColor); + + mBitmapHeight = mBitmap.getHeight(); + mBitmapWidth = mBitmap.getWidth(); + + mBorderRect.set(calculateBounds()); + mBorderRadius = Math.min((mBorderRect.height() - mBorderWidth) / 2.0f, (mBorderRect.width() - mBorderWidth) / 2.0f); + + mDrawableRect.set(mBorderRect); + if (!mBorderOverlay && mBorderWidth > 0) { + mDrawableRect.inset(mBorderWidth - 1.0f, mBorderWidth - 1.0f); + } + mDrawableRadius = Math.min(mDrawableRect.height() / 2.0f, mDrawableRect.width() / 2.0f); + + applyColorFilter(); + updateShaderMatrix(); + invalidate(); + } + + private RectF calculateBounds() { + int availableWidth = getWidth() - getPaddingLeft() - getPaddingRight(); + int availableHeight = getHeight() - getPaddingTop() - getPaddingBottom(); + + int sideLength = Math.min(availableWidth, availableHeight); + + float left = getPaddingLeft() + (availableWidth - sideLength) / 2f; + float top = getPaddingTop() + (availableHeight - sideLength) / 2f; + + return new RectF(left, top, left + sideLength, top + sideLength); + } + + private void updateShaderMatrix() { + float scale; + float dx = 0; + float dy = 0; + + mShaderMatrix.set(null); + + if (mBitmapWidth * mDrawableRect.height() > mDrawableRect.width() * mBitmapHeight) { + scale = mDrawableRect.height() / (float) mBitmapHeight; + dx = (mDrawableRect.width() - mBitmapWidth * scale) * 0.5f; + } else { + scale = mDrawableRect.width() / (float) mBitmapWidth; + dy = (mDrawableRect.height() - mBitmapHeight * scale) * 0.5f; + } + + mShaderMatrix.setScale(scale, scale); + mShaderMatrix.postTranslate((int) (dx + 0.5f) + mDrawableRect.left, (int) (dy + 0.5f) + mDrawableRect.top); + + mBitmapShader.setLocalMatrix(mShaderMatrix); + } + + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + private class OutlineProvider extends ViewOutlineProvider { + + @Override + public void getOutline(View view, Outline outline) { + Rect bounds = new Rect(); + mBorderRect.roundOut(bounds); + outline.setRoundRect(bounds, bounds.width() / 2.0f); + } + + } + +} \ No newline at end of file diff --git a/library/src/main/java/com/allen/library/CommonTextView.java b/library/src/main/java/com/allen/library/CommonTextView.java index e59879d..a6249bb 100644 --- a/library/src/main/java/com/allen/library/CommonTextView.java +++ b/library/src/main/java/com/allen/library/CommonTextView.java @@ -3,6 +3,7 @@ import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; +import android.text.InputFilter; import android.text.TextUtils; import android.util.AttributeSet; import android.util.TypedValue; @@ -802,8 +803,9 @@ public TextView initText(TextView textView, LayoutParams layoutParams, int id, i // textView.setGravity(Gravity.CENTER); textView.setLines(mSetLines); textView.setSingleLine(mSetSingleLine); - textView.setMaxEms(mSetMaxEms); - textView.setEllipsize(TextUtils.TruncateAt.END); +// textView.setMaxEms(mSetMaxEms); +// textView.setEllipsize(TextUtils.TruncateAt.END); + textView.setFilters(new InputFilter[]{new InputFilter.LengthFilter(mSetMaxEms) }); addView(textView); } return textView; diff --git a/library/src/main/java/com/allen/library/SuperButton.java b/library/src/main/java/com/allen/library/SuperButton.java new file mode 100644 index 0000000..bf1166a --- /dev/null +++ b/library/src/main/java/com/allen/library/SuperButton.java @@ -0,0 +1,546 @@ +package com.allen.library; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.drawable.GradientDrawable; +import androidx.appcompat.widget.AppCompatButton; +import android.util.AttributeSet; +import android.view.Gravity; + +import com.allen.library.helper.ShapeGradientAngle; +import com.allen.library.helper.ShapeBuilder; +import com.allen.library.helper.ShapeGradientType; +import com.allen.library.helper.ShapeType; + +/** + * Created by Allen on 2017/7/6. + *
+ * 超级按钮 实现shape所有的属性 + * + * @deprecated Use {ShapeButton} instead. + * + */ + +@Deprecated +public class SuperButton extends AppCompatButton { + + private Context mContext; + + private int defaultColor = 0x20000000; + private int defaultSelectorColor = 0x20000000; + + private int solidColor; + private int selectorPressedColor; + private int selectorDisableColor; + private int selectorNormalColor; + + private float cornersRadius; + private float cornersTopLeftRadius; + private float cornersTopRightRadius; + private float cornersBottomLeftRadius; + private float cornersBottomRightRadius; + + private int strokeWidth; + private int strokeColor; + + private float strokeDashWidth; + private float strokeDashGap; + + private int sizeWidth; + private int sizeHeight; + + private int gradientAngle; + private float gradientCenterX; + private float gradientCenterY; + private int gradientGradientRadius; + + private int gradientStartColor; + private int gradientCenterColor; + private int gradientEndColor; + + private int gradientType; + + //"linear" 线形渐变。这也是默认的模式 + private static final int linear = 0; + //"radial" 辐射渐变。startColor即辐射中心的颜色 + private static final int radial = 1; + //"sweep" 扫描线渐变。 + private static final int sweep = 2; + + private boolean gradientUseLevel; + + private boolean useSelector; + + + //shape的样式 + public static final int RECTANGLE = 0; + public static final int OVAL = 1; + public static final int LINE = 2; + public static final int RING = 3; + + + //渐变色的显示方式 + 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; + + //文字显示的位置方式 + public static final int TEXT_GRAVITY_CENTER = 0; + public static final int TEXT_GRAVITY_LEFT = 1; + public static final int TEXT_GRAVITY_RIGHT = 2; + public static final int TEXT_GRAVITY_TOP = 3; + public static final int TEXT_GRAVITY_BOTTOM = 4; + + + private int shapeType; + + private int gravity; + + private GradientDrawable gradientDrawable; + + private ShapeBuilder shapeBuilder; + + public SuperButton(Context context) { + this(context, null); + } + + public SuperButton(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public SuperButton(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + mContext = context; + getAttr(attrs); + init(); + } + + private void getAttr(AttributeSet attrs) { + TypedArray typedArray = mContext.obtainStyledAttributes(attrs, R.styleable.SuperButton); + + gravity = typedArray.getInt(R.styleable.SuperButton_sGravity, 0); + + shapeType = typedArray.getInt(R.styleable.SuperButton_sShapeType, GradientDrawable.RECTANGLE); + + solidColor = typedArray.getColor(R.styleable.SuperButton_sSolidColor, defaultColor); + + selectorPressedColor = typedArray.getColor(R.styleable.SuperButton_sSelectorPressedColor, defaultSelectorColor); + selectorDisableColor = typedArray.getColor(R.styleable.SuperButton_sSelectorDisableColor, defaultSelectorColor); + selectorNormalColor = typedArray.getColor(R.styleable.SuperButton_sSelectorNormalColor, defaultSelectorColor); + + cornersRadius = typedArray.getDimensionPixelSize(R.styleable.SuperButton_sCornersRadius, 0); + cornersTopLeftRadius = typedArray.getDimensionPixelSize(R.styleable.SuperButton_sCornersTopLeftRadius, 0); + cornersTopRightRadius = typedArray.getDimensionPixelSize(R.styleable.SuperButton_sCornersTopRightRadius, 0); + cornersBottomLeftRadius = typedArray.getDimensionPixelSize(R.styleable.SuperButton_sCornersBottomLeftRadius, 0); + cornersBottomRightRadius = typedArray.getDimensionPixelSize(R.styleable.SuperButton_sCornersBottomRightRadius, 0); + + strokeWidth = typedArray.getDimensionPixelSize(R.styleable.SuperButton_sStrokeWidth, 0); + strokeDashWidth = typedArray.getDimensionPixelSize(R.styleable.SuperButton_sStrokeDashWidth, 0); + strokeDashGap = typedArray.getDimensionPixelSize(R.styleable.SuperButton_sStrokeDashGap, 0); + + strokeColor = typedArray.getColor(R.styleable.SuperButton_sStrokeColor, defaultColor); + + sizeWidth = typedArray.getDimensionPixelSize(R.styleable.SuperButton_sSizeWidth, 0); + sizeHeight = typedArray.getDimensionPixelSize(R.styleable.SuperButton_sSizeHeight, dip2px(mContext, 48)); + + gradientAngle = (int) typedArray.getFloat(R.styleable.SuperButton_sGradientAngle, -1); + gradientCenterX = typedArray.getFloat(R.styleable.SuperButton_sGradientCenterX, 0f); + gradientCenterY = typedArray.getFloat(R.styleable.SuperButton_sGradientCenterY, 0f); + gradientGradientRadius = typedArray.getDimensionPixelSize(R.styleable.SuperButton_sGradientGradientRadius, 0); + + gradientStartColor = typedArray.getColor(R.styleable.SuperButton_sGradientStartColor, -1); + gradientCenterColor = typedArray.getColor(R.styleable.SuperButton_sGradientCenterColor, -1); + gradientEndColor = typedArray.getColor(R.styleable.SuperButton_sGradientEndColor, -1); + + gradientType = typedArray.getInt(R.styleable.SuperButton_sGradientType, linear); + gradientUseLevel = typedArray.getBoolean(R.styleable.SuperButton_sGradientUseLevel, false); + + useSelector = typedArray.getBoolean(R.styleable.SuperButton_sUseSelector, false); + + typedArray.recycle(); + } + + private void init() { + setClickable(true); + shapeBuilder = new ShapeBuilder(); + shapeBuilder + .setShapeType(ShapeType.fromValue(shapeType)) + .setShapeCornersRadius(cornersRadius) + .setShapeCornersTopLeftRadius(cornersTopLeftRadius) + .setShapeCornersTopRightRadius(cornersTopRightRadius) + .setShapeCornersBottomRightRadius(cornersBottomRightRadius) + .setShapeCornersBottomLeftRadius(cornersBottomLeftRadius) + .setShapeSolidColor(solidColor) + .setShapeStrokeColor(strokeColor) + .setShapeStrokeWidth(strokeWidth) + .setShapeStrokeDashWidth(strokeDashWidth) + .setShapeStrokeDashGap(strokeDashGap) + .setShapeUseSelector(useSelector) + .setShapeSelectorNormalColor(selectorNormalColor) + .setShapeSelectorPressedColor(selectorPressedColor) + .setShapeSelectorDisableColor(selectorDisableColor) + .setShapeSizeWidth(sizeWidth) + .setShapeSizeHeight(sizeHeight) + .setShapeGradientType(ShapeGradientType.fromValue(gradientType)) + .setShapeGradientAngle(ShapeGradientAngle.fromValue(gradientAngle)) + .setShapeGradientUseLevel(gradientUseLevel) + .setShapeGradientCenterX(gradientCenterX) + .setShapeGradientCenterY(gradientCenterY) + .setShapeGradientStartColor(gradientStartColor) + .setShapeGradientCenterColor(gradientCenterColor) + .setShapeGradientEndColor(gradientEndColor) + .into(this); + setSGravity(); + } + + + /** + * 设置文字对其方式 + */ + private void setSGravity() { + switch (gravity) { + case 0: + setGravity(Gravity.CENTER); + break; + case 1: + setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); + break; + case 2: + setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL); + break; + case 3: + setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL); + break; + case 4: + setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL); + break; + } + } + + + /////////////////对外暴露的方法////////////// + + /** + * 设置Shape类型 + * + * @param type 类型 + * @return 对象 + */ + public SuperButton setShapeType(int type) { + this.shapeType = type; + return this; + } + + /** + * 设置文字对其方式 + * + * @param gravity 对齐方式 + * @return 对象 + */ + public SuperButton setTextGravity(int gravity) { + this.gravity = gravity; + return this; + } + + /** + * 设置按下的颜色 + * + * @param color 颜色 + * @return 对象 + */ + public SuperButton setShapeSelectorPressedColor(int color) { + this.shapeBuilder.setShapeSelectorPressedColor(color); + return this; + } + + /** + * 设置正常的颜色 + * + * @param color 颜色 + * @return 对象 + */ + public SuperButton setShapeSelectorNormalColor(int color) { + this.shapeBuilder.setShapeSelectorNormalColor(color); + return this; + } + + /** + * 设置不可点击的颜色 + * + * @param color 颜色 + * @return 对象 + */ + public SuperButton setShapeSelectorDisableColor(int color) { + this.shapeBuilder.setShapeSelectorDisableColor(color); + return this; + } + + /** + * 设置填充的颜色 + * + * @param color 颜色 + * @return 对象 + */ + public SuperButton setShapeSolidColor(int color) { + this.shapeBuilder.setShapeSolidColor(color); + return this; + } + + /** + * 设置边框宽度 + * + * @param strokeWidth 边框宽度值 + * @return 对象 + */ + public SuperButton setShapeStrokeWidth(int strokeWidth) { + this.shapeBuilder.setShapeStrokeWidth(dip2px(mContext, strokeWidth)); + return this; + } + + /** + * 设置边框颜色 + * + * @param strokeColor 边框颜色 + * @return 对象 + */ + public SuperButton setShapeStrokeColor(int strokeColor) { + this.shapeBuilder.setShapeStrokeColor(strokeColor); + return this; + } + + /** + * 设置边框虚线宽度 + * + * @param strokeDashWidth 边框虚线宽度 + * @return 对象 + */ + public SuperButton setShapeStrokeDashWidth(float strokeDashWidth) { + this.shapeBuilder.setShapeStrokeDashWidth(dip2px(mContext, strokeDashWidth)); + return this; + } + + /** + * 设置边框虚线间隙 + * + * @param strokeDashGap 边框虚线间隙值 + * @return 对象 + */ + public SuperButton setShapeStrokeDashGap(float strokeDashGap) { + this.shapeBuilder.setShapeStrokeDashGap(dip2px(mContext, strokeDashGap)); + return this; + } + + /** + * 设置圆角半径 + * + * @param radius 半径 + * @return 对象 + */ + public SuperButton setShapeCornersRadius(float radius) { + this.shapeBuilder.setShapeCornersRadius(dip2px(mContext, radius)); + return this; + } + + /** + * 设置左上圆角半径 + * + * @param radius 半径 + * @return 对象 + */ + public SuperButton setShapeCornersTopLeftRadius(float radius) { + this.shapeBuilder.setShapeCornersTopLeftRadius(dip2px(mContext, radius)); + return this; + } + + /** + * 设置右上圆角半径 + * + * @param radius 半径 + * @return 对象 + */ + public SuperButton setShapeCornersTopRightRadius(float radius) { + this.shapeBuilder.setShapeCornersTopRightRadius(dip2px(mContext, radius)); + return this; + } + + /** + * 设置左下圆角半径 + * + * @param radius 半径 + * @return 对象 + */ + public SuperButton setShapeCornersBottomLeftRadius(float radius) { + this.shapeBuilder.setShapeCornersBottomLeftRadius(dip2px(mContext, radius)); + return this; + } + + /** + * 设置右下圆角半径 + * + * @param radius 半径 + * @return 对象 + */ + public SuperButton setShapeCornersBottomRightRadius(float radius) { + this.shapeBuilder.setShapeCornersBottomRightRadius(dip2px(mContext, radius)); + return this; + } + + /** + * 设置shape的宽度 + * + * @param sizeWidth 宽 + * @return 对象 + */ + public SuperButton setShapeSizeWidth(int sizeWidth) { + this.shapeBuilder.setShapeSizeWidth(dip2px(mContext, sizeWidth)); + return this; + } + + /** + * 设置shape的高度 + * + * @param sizeHeight 高 + * @return 对象 + */ + public SuperButton setShapeSizeHeight(int sizeHeight) { + this.shapeBuilder.setShapeSizeHeight(dip2px(mContext, sizeHeight)); + return this; + } + + /** + * 设置背景渐变方式 + * + * @param gradientAngle 渐变类型 + * @return 对象 + */ + public SuperButton setShapeGradientAngle(int gradientAngle) { + this.shapeBuilder.setShapeGradientAngle(ShapeGradientAngle.fromValue(gradientAngle)); + return this; + } + + /** + * 设置渐变中心X + * + * @param gradientCenterX 中心x + * @return 对象 + */ + public SuperButton setShapeGradientCenterX(float gradientCenterX) { + this.shapeBuilder.setShapeGradientCenterX(gradientCenterX); + return this; + } + + /** + * 设置渐变中心Y + * + * @param gradientCenterY 中心y + * @return 对象 + */ + public SuperButton setShapeGradientCenterY(float gradientCenterY) { + this.shapeBuilder.setShapeGradientCenterY(gradientCenterY); + return this; + } + + /** + * 设置渐变半径 + * + * @param gradientGradientRadius 渐变半径 + * @return 对象 + */ + public SuperButton setShapeGradientGradientRadius(int gradientGradientRadius) { + this.shapeBuilder.setShapeGradientGradientRadius(gradientGradientRadius); + return this; + } + + /** + * 设置渐变开始的颜色 + * + * @param gradientStartColor 开始颜色 + * @return 对象 + */ + public SuperButton setShapeGradientStartColor(int gradientStartColor) { + this.shapeBuilder.setShapeGradientStartColor(gradientStartColor); + return this; + } + + /** + * 设置渐变中间的颜色 + * + * @param gradientCenterColor 中间颜色 + * @return 对象 + */ + public SuperButton setShapeGradientCenterColor(int gradientCenterColor) { + this.shapeBuilder.setShapeGradientCenterColor(gradientCenterColor); + return this; + } + + /** + * 设置渐变结束的颜色 + * + * @param gradientEndColor 结束颜色 + * @return 对象 + */ + public SuperButton setShapeGradientEndColor(int gradientEndColor) { + this.shapeBuilder.setShapeGradientEndColor(gradientEndColor); + return this; + } + + /** + * 设置渐变类型 + * + * @param gradientType 类型 + * @return 对象 + */ + public SuperButton setShapeGradientType(ShapeGradientType gradientType) { + this.shapeBuilder.setShapeGradientType(gradientType); + return this; + } + + /** + * 设置是否使用UseLevel + * + * @param gradientUseLevel true or false + * @return 对象 + */ + public SuperButton setShapeGradientUseLevel(boolean gradientUseLevel) { + this.shapeBuilder.setShapeGradientUseLevel(gradientUseLevel); + return this; + } + + /** + * 是否使用selector + * + * @param useSelector true or false + * @return 对象 + */ + public SuperButton setShapeUseSelector(boolean useSelector) { + this.shapeBuilder.setShapeUseSelector(useSelector); + return this; + } + + /** + * 使用shape + * 所有与shape相关的属性设置之后调用此方法才生效 + */ + public void setUseShape() { + this.shapeBuilder.into(this); + } + + + /** + * 单位转换工具类 + * + * @param context 上下文对象 + * @param dipValue 值 + * @return 返回值 + */ + private int dip2px(Context context, float dipValue) { + final float scale = context.getResources().getDisplayMetrics().density; + return (int) (dipValue * scale + 0.5f); + } + +} diff --git a/library/src/main/java/com/allen/library/SuperTextView.java b/library/src/main/java/com/allen/library/SuperTextView.java index 0e96e46..16f707b 100644 --- a/library/src/main/java/com/allen/library/SuperTextView.java +++ b/library/src/main/java/com/allen/library/SuperTextView.java @@ -1,666 +1,2241 @@ package com.allen.library; import android.content.Context; +import android.content.res.ColorStateList; import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.graphics.Paint; import android.graphics.drawable.Drawable; +import android.graphics.drawable.GradientDrawable; +import android.os.Build; +import android.text.Editable; import android.text.TextUtils; +import android.text.TextWatcher; import android.util.AttributeSet; import android.util.TypedValue; import android.view.Gravity; import android.view.View; +import android.view.inputmethod.EditorInfo; import android.widget.CheckBox; +import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.RelativeLayout; -import android.widget.TextView; + +import androidx.annotation.DrawableRes; +import androidx.appcompat.widget.AppCompatCheckBox; +import androidx.appcompat.widget.AppCompatEditText; +import androidx.appcompat.widget.AppCompatTextView; +import androidx.appcompat.widget.SwitchCompat; + +import com.allen.library.helper.EditTextHelper; +import com.allen.library.helper.ShapeBuilder; +import com.allen.library.helper.ShapeType; /** - * 万能的textView - * Created by allen on 2016/10/14. + * Created by Allen on 2017/7/1. + *
+ * 打造万能的布局满足市面常见的样式 */ public class SuperTextView extends RelativeLayout { private Context mContext; - private int defaultBgColor = 0xFFFFFFFF;//默认背景颜色 - private int defaultLineColor = 0xFFE8E8E8;//线的默认颜色 - //private int defaultLineColor = 0xFF535353;//文字默认颜色 - private int defaultLinePadding = 0;//线的左右边距 - - private ImageView leftIconIV;//左边图标 - private ImageView rightIconIV;//右边图标 - private CheckBox rightCheckBox;//右边checkbox - private Drawable rightCheckBoxBg;//checkBox的背景 - private TextView leftTV;//左边textView - private TextView centerTV;//中间textView - private TextView rightTV;//右边textView + private BaseTextView leftView, centerView, rightView; + private LayoutParams leftBaseViewParams, centerBaseViewParams, rightBaseViewParams; + + private CircleImageView leftIconIV, rightIconIV; + private LayoutParams leftImgParams, rightImgParams; + private int leftIconWidth;//左边图标的宽 + private int leftIconHeight;//左边图标的高 - private TextView leftTopTV;//左上的textView - private TextView leftBottomTV;//左下的textView - private TextView leftBottomTV2;//左下第二个textView + private int rightIconWidth;//右边图标的宽 + private int rightIconHeight;//右边图标的高 + private int leftIconMarginLeft;//左边图标的左边距 + private int rightIconMarginRight;//右边图标的右边距 private Drawable leftIconRes;//左边图标资源 private Drawable rightIconRes;//右边图标资源 - private String leftTextString;//左边显示的文字 - private String centerTextString;//中间显示的文字 - private String rightTextString;//右边显示的文字 - private String leftTopTextString;//左上显示的文字 - private String leftBottomTextString;//左下显示的文字 - private String leftBottomTextString2;//左下第二个显示的文字 - private int defaultPadding = 0;//默认边距 + private int defaultColor = 0xFF373737;//文字默认颜色 + private int defaultSize = 15;//默认字体大小 + private int defaultMaxEms = 0; + private int defaultMaxLines = 0; - private int centerSpaceHeight;//中间空间的高度 - private int bothLineWidth; - private int topLineWidth; - private int bottomLineWidth; - private int lineColor = 0xFFE8E8E8;//线的默认颜色 + private String mLeftTextString; + private String mLeftTopTextString; + private String mLeftBottomTextString; - private int topLineMargin;//上边线的左右边距 - private int topLineMarginLeft;//上边线的左边距 - private int topLineMarginRight;//上边线的右边距 + private String mRightTextString; + private String mRightTopTextString; + private String mRightBottomTextString; - private int bottomLineMargin;//下边线的左右边距 - private int bottomLineMarginLeft;//下边线的左边距 - private int bottomLineMarginRight;//下边线的右边距 + private String mCenterTextString; + private String mCenterTopTextString; + private String mCenterBottomTextString; - private int bothLineMargin;//两条线的左右边距 - private int bothLineMarginLeft;//两条线的左边距 - private int bothLineMarginRight;//两条线的右边距 - private int leftIconMarginLeft;//左边图标的左边距 + private ColorStateList mLeftTextColor; + private ColorStateList mLeftTopTextColor; + private ColorStateList mLeftBottomTextColor; - private int leftTVMarginLeft;//左边文字的左边距 + private ColorStateList mCenterTextColor; + private ColorStateList mCenterTopTextColor; + private ColorStateList mCenterBottomTextColor; - private int leftIconWidth;//左边图标的宽 - private int leftIconHeight;//左边图标的高 + private ColorStateList mRightTextColor; + private ColorStateList mRightTopTextColor; + private ColorStateList mRightBottomTextColor; - private int rightIconWidth;//右边图标的宽 - private int rightIconHeight;//右边图标的高 + private ColorStateList mRightEditHintTextColor; + private ColorStateList mRightEditTextColor; - private int leftTopMarginLeft;//左上文字的左边距 - private int leftBottomMarginLeft;//左下文字的左边距 - private int leftBottomMarginLeft2;//左下第二个文字的左边距 - private int rightTVMarginRight;//右边文字的右边距 - private int rightIconMarginRight;//右边图标的右边距 + private int mLeftTextSize; + private int mLeftTopTextSize; + private int mLeftBottomTextSize; + + private int mRightTextSize; + private int mRightTopTextSize; + private int mRightBottomTextSize; + + private int mCenterTextSize; + private int mCenterTopTextSize; + private int mCenterBottomTextSize; + + private int mLeftTopLines; + private int mLeftLines; + private int mLeftBottomLines; + + private int mCenterTopLines; + private int mCenterLines; + private int mCenterBottomLines; + + private int mRightTopLines; + private int mRightLines; + private int mRightBottomLines; + + private int mLeftTopMaxEms; + private int mLeftMaxEms; + private int mLeftBottomMaxEms; + + private int mCenterTopMaxEms; + private int mCenterMaxEms; + private int mCenterBottomMaxEms; + + private int mRightTopMaxEms; + private int mRightMaxEms; + private int mRightBottomMaxEms; + +// private boolean mLeftTopTextBold; +// private boolean mLeftTextBold; +// private boolean mLeftBottomTextBold; +// +// private boolean mCenterTopTextBold; +// private boolean mCenterTextBold; +// private boolean mCenterBottomTextBold; +// +// private boolean mRightTopTextBold; +// private boolean mRightTextBold; +// private boolean mRightBottomTextBold; + + private Drawable mLeftTextBackground; + private Drawable mCenterTextBackground; + private Drawable mRightTextBackground; + + private Drawable mLeftTvDrawableLeft; + private Drawable mLeftTvDrawableRight; + + private Drawable mCenterTvDrawableLeft; + private Drawable mCenterTvDrawableRight; + + private Drawable mRightTvDrawableLeft; + private Drawable mRightTvDrawableRight; + + private int mLeftTvDrawableWidth; + private int mLeftTvDrawableHeight; + + private int mCenterTvDrawableWidth; + private int mCenterTvDrawableHeight; + + private int mRightTvDrawableWidth; + private int mRightTvDrawableHeight; + + private int mTextViewDrawablePadding; + + private static final int gravity_Left_Center = 0; + private static final int gravity_Center = 1; + private static final int gravity_Right_Center = 2; + + private static final int default_Gravity = 1; + + private int mLeftGravity; + private int mCenterGravity; + private int mRightGravity; + + private int mLeftTextGravity; + private int mCenterTextGravity; + private int mRightTextGravity; + + private static final int text_gravity_Left = 0; + private static final int text_gravity_center = 1; + private static final int text_gravity_right = 2; + + private static final int default_text_gravity = -1; + + private int mLeftViewWidth; + + + private int mTopDividerLineMarginLR; + private int mTopDividerLineMarginLeft; + private int mTopDividerLineMarginRight; + + private int mBottomDividerLineMarginLR; + private int mBottomDividerLineMarginLeft; + private int mBottomDividerLineMarginRight; + + private int mDividerLineType; + private int mDividerLineColor; + private int mDividerLineHeight; + + private int mDefaultDividerLineColor = 0xFFE8E8E8;//分割线默认颜色 + + /** + * 分割线的类型 + */ + public static final int NONE = 0; + public static final int TOP = 1; + public static final int BOTTOM = 2; + public static final int BOTH = 3; + private static final int default_Divider = BOTTOM; + + private int default_Margin = 10; + + private int mLeftViewMarginLeft; + private int mLeftViewMarginRight; + + private int mCenterViewMarginLeft; + private int mCenterViewMarginRight; + + private int mRightViewMarginLeft; + private int mRightViewMarginRight; + + private boolean useRipple; + private Drawable mBackground_drawable; + + private OnSuperTextViewClickListener superTextViewClickListener; + + private OnLeftTopTvClickListener leftTopTvClickListener; + private OnLeftTvClickListener leftTvClickListener; + private OnLeftBottomTvClickListener leftBottomTvClickListener; + + private OnCenterTopTvClickListener centerTopTvClickListener; + private OnCenterTvClickListener centerTvClickListener; + private OnCenterBottomTvClickListener centerBottomTvClickListener; + + private OnRightTopTvClickListener rightTopTvClickListener; + private OnRightTvClickListener rightTvClickListener; + private OnRightBottomTvClickListener rightBottomTvClickListener; + + private OnSwitchCheckedChangeListener switchCheckedChangeListener; + private OnCheckBoxCheckedChangeListener checkBoxCheckedChangeListener; + private OnEditTextChangeListener editTextChangeListener; + + private OnLeftImageViewClickListener leftImageViewClickListener; + private OnRightImageViewClickListener rightImageViewClickListener; + + private static final int TYPE_CHECKBOX = 0; + private static final int TYPE_SWITCH = 1; + private static final int TYPE_EDIT = 2; + + private static int mRightViewType; + + private AppCompatCheckBox rightCheckBox;//右边checkbox + private LayoutParams rightCheckBoxParams;//右边checkbox + private Drawable rightCheckBoxBg;//checkBox的背景 private int rightCheckBoxMarginRight;//右边checkBox的右边距 - private boolean showCheckBox;//是否显示右边选择框 private boolean isChecked;//是否默认选中 - private int defaultSize = 0;//默认字体大小 - private int leftTVSize;//左边文字字体大小 - private int leftTopTVSize;//左上文字字体大小 - private int leftBottomTVSize;//左下文字字体大小 - private int leftBottomTVSize2;//左下第二个文字字体大小 - private int rightTVSize;//右边文字字体大小 - private int centerTVSize;//中间文字字体大小 + private int centerSpaceHeight;//中间空间的高度 + + private SwitchCompat mSwitch; + private LayoutParams mSwitchParams;//右边switch + private int rightSwitchMarginRight; + private boolean switchIsChecked = true; - private int defaultColor = 0xFF373737;//文字默认颜色 + private AppCompatEditText mEditText; + private LayoutParams mEditParams; + private int mEditMinWidth; + private int mEditImeOption; + private int mEditInputType; + private int rightEditMarginRight; + private int editActiveLineColor = -1; + private int mEditTextSize; + private int mEditCusorDrawableRes; + private boolean mEditCusorVisible; - private int backgroundColor;//背景颜色 - private int leftTVColor;//左边文字颜色 - private int leftTopTVColor;//左上文字颜色 - private int leftBottomTVColor;//左下文字颜色 - private int leftBottomTVColor2;//左下第二个文字颜色 - private int rightTVColor;//右边文字颜色 - private int centerTVColor;//中间文字颜色 - - private boolean isSingLines = true;//是否单行显示 默认单行 - private int maxLines = 1;//最多几行 默认显示一行 - private int maxEms = 10;//最多几个字 默认显示10个汉子 - - private static final int NONE = 0; - private static final int TOP = 1; - private static final int BOTTOM = 2; - private static final int BOTH = 3; - private static final int DEFAULT = BOTTOM; - - public static final int leftTextViewId = 0; - public static final int leftTopTextViewId = 1; - public static final int leftBottomTextViewId = 2; - public static final int leftBottomTextViewId2 = 3; - public static final int rightTextViewId = 4; - public static final int centerTextViewId = 5; - public static final int leftImageViewId = 6; - public static final int rightImageViewId = 7; + private String mEditHintText; + private String mTextOff; + private String mTextOn; - private boolean useRipple; - private int lineType; - private LayoutParams centerBaseLineParams, topLineParams, bottomLineParams, leftImgParams, leftTextParams, centerTextParams, leftTopTextParams, leftBottomParams, - leftBottomParams2, rightTextParams, rightImgParams, rightCheckBoxParams; + private int mSwitchMinWidth; + private int mSwitchPadding; - private OnSuperTextViewClickListener onSuperTextViewClickListener; - private Drawable rightTextStringRightIconRes; - private int rightTextStringRightIconPadding; + private int mThumbTextPadding; - private boolean mLeftTopViewIsClickable = false; - private boolean mLeftBottomViewIsClickable = false; - private boolean mLeftBottomView2IsClickable = false; + private Drawable mThumbResource; + private Drawable mTrackResource; - private Drawable mBackground_drawable; + /////////////////////一下是shape相关属性 + private int defaultShapeColor = 0xffffffff; + + private int selectorPressedColor; + private int selectorNormalColor; + + private int solidColor; + + private float cornersRadius; + private float cornersTopLeftRadius; + private float cornersTopRightRadius; + private float cornersBottomLeftRadius; + private float cornersBottomRightRadius; + + private int strokeWidth; + private int strokeColor; + + private float strokeDashWidth; + private float strokeDashGap; + + private boolean useShape; + + private boolean mLeftIconShowCircle; + private boolean mRightIconShowCircle; + + private GradientDrawable gradientDrawable; + + private Paint mTopDividerPaint; + private Paint mBottomDividerPaint; + + private boolean mIsShowTopDivider; + private boolean mIsShowBottomDivider; + + private ShapeBuilder shapeBuilder; public SuperTextView(Context context) { - super(context); + this(context, null); } public SuperTextView(Context context, AttributeSet attrs) { - super(context, attrs); - mContext = context; -// defaultLinePadding = dip2px(context, 16); - defaultPadding = dip2px(context, 16); - defaultSize = sp2px(context, 14); - centerSpaceHeight = dip2px(context, 10); - getAttr(attrs); + this(context, attrs, 0); + } - initLayout(); + public SuperTextView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + + mContext = context; + defaultSize = sp2px(context, defaultSize); + default_Margin = dip2px(context, default_Margin); + shapeBuilder = new ShapeBuilder(); + getAttr(attrs); + initPaint(); + initView(); } - /** - * 获取自定义属性值 - * - * @param attrs - */ private void getAttr(AttributeSet attrs) { TypedArray typedArray = mContext.obtainStyledAttributes(attrs, R.styleable.SuperTextView); - ////////设置文字或者图片资源//////// - leftIconRes = typedArray.getDrawable(R.styleable.SuperTextView_sLeftIconRes); - rightIconRes = typedArray.getDrawable(R.styleable.SuperTextView_sRightIconRes); - rightCheckBoxBg = typedArray.getDrawable(R.styleable.SuperTextView_sRightCheckBoxRes); - - leftTextString = typedArray.getString(R.styleable.SuperTextView_sLeftTextString); - centerTextString = typedArray.getString(R.styleable.SuperTextView_sCenterTextString); - rightTextString = typedArray.getString(R.styleable.SuperTextView_sRightTextString); - - rightTextStringRightIconRes = typedArray.getDrawable(R.styleable.SuperTextView_sRightTextStringRightIconRes); - rightTextStringRightIconPadding = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightTextStringRightIconResPadding, dip2px(mContext, 5)); - - leftTopTextString = typedArray.getString(R.styleable.SuperTextView_sLeftTopTextString); - leftBottomTextString = typedArray.getString(R.styleable.SuperTextView_sLeftBottomTextString); - leftBottomTextString2 = typedArray.getString(R.styleable.SuperTextView_sLeftBottomTextString2); - - showCheckBox = typedArray.getBoolean(R.styleable.SuperTextView_sRightCheckBoxShow, false); - isChecked = typedArray.getBoolean(R.styleable.SuperTextView_sIsChecked, false); - useRipple = typedArray.getBoolean(R.styleable.SuperTextView_sUseRipple, false); - - lineType = typedArray.getInt(R.styleable.SuperTextView_sLineShow, DEFAULT); - - /////////设置view的边距//////// - centerSpaceHeight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sCenterSpaceHeight, centerSpaceHeight); - - bothLineWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sBothLineWidth, dip2px(mContext, 0.5f)); - topLineWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sTopLineWidth, dip2px(mContext, 0.5f)); - bottomLineWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sBottomLineWidth, dip2px(mContext, 0.5f)); - - lineColor = typedArray.getColor(R.styleable.SuperTextView_sLineColor, lineColor); - - topLineMargin = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sTopLineMargin, defaultLinePadding); - topLineMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sTopLineMarginLeft, defaultLinePadding); - topLineMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sTopLineMarginRight, defaultLinePadding); - - bottomLineMargin = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sBottomLineMargin, defaultLinePadding); - bottomLineMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sBottomLineMarginLeft, defaultLinePadding); - bottomLineMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sBottomLineMarginRight, defaultLinePadding); - - bothLineMargin = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sBothLineMargin, defaultLinePadding); - bothLineMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sBothLineMarginLeft, defaultLinePadding); - bothLineMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sBothLineMarginRight, defaultLinePadding); - - leftIconMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftIconMarginLeft, defaultPadding); - leftTVMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftTextMarginLeft, defaultPadding); - - leftTopMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftTopTextMarginLeft, defaultPadding); - leftBottomMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftBottomTextMarginLeft, defaultPadding); - leftBottomMarginLeft2 = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftBottomTextMarginLeft2, defaultPadding); - rightTVMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightTextMarginRight, defaultPadding); - rightIconMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightIconMarginRight, defaultPadding); - rightCheckBoxMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightCheckBoxMarginRight, defaultPadding); - //////设置字体颜色//////// - backgroundColor = typedArray.getColor(R.styleable.SuperTextView_sBackgroundColor, defaultBgColor); - leftTVColor = typedArray.getColor(R.styleable.SuperTextView_sLeftTextColor, defaultColor); - leftTopTVColor = typedArray.getColor(R.styleable.SuperTextView_sLeftTopTextColor, defaultColor); - leftBottomTVColor = typedArray.getColor(R.styleable.SuperTextView_sLeftBottomTextColor, defaultColor); - leftBottomTVColor2 = typedArray.getColor(R.styleable.SuperTextView_sLeftBottomTextColor2, defaultColor); - rightTVColor = typedArray.getColor(R.styleable.SuperTextView_sRightTextColor, defaultColor); - centerTVColor = typedArray.getColor(R.styleable.SuperTextView_sCenterTextColor, defaultColor); - //////设置字体大小//////// - leftTVSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftTextSize, defaultSize); - leftTopTVSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftTopTextSize, defaultSize); - leftBottomTVSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftBottomTextSize, defaultSize); - leftBottomTVSize2 = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftBottomTextSize2, defaultSize); - rightTVSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightTextSize, defaultSize); - centerTVSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sCenterTextSize, defaultSize); - - ///////设置textView的属性///////////SuperTextViewxEms - isSingLines = typedArray.getBoolean(R.styleable.SuperTextView_sIsSingLines, isSingLines); - maxLines = typedArray.getInt(R.styleable.SuperTextView_sMaxLines, maxLines); - maxEms = typedArray.getInt(R.styleable.SuperTextView_sMaxEms, maxEms); + ///////////////////////////////////////////////// + mLeftTextString = typedArray.getString(R.styleable.SuperTextView_sLeftTextString); + mLeftTopTextString = typedArray.getString(R.styleable.SuperTextView_sLeftTopTextString); + mLeftBottomTextString = typedArray.getString(R.styleable.SuperTextView_sLeftBottomTextString); + + mCenterTextString = typedArray.getString(R.styleable.SuperTextView_sCenterTextString); + mCenterTopTextString = typedArray.getString(R.styleable.SuperTextView_sCenterTopTextString); + mCenterBottomTextString = typedArray.getString(R.styleable.SuperTextView_sCenterBottomTextString); + + mRightTextString = typedArray.getString(R.styleable.SuperTextView_sRightTextString); + mRightTopTextString = typedArray.getString(R.styleable.SuperTextView_sRightTopTextString); + mRightBottomTextString = typedArray.getString(R.styleable.SuperTextView_sRightBottomTextString); + ////////////////////////////////////////////////// + + mLeftTextColor = typedArray.getColorStateList(R.styleable.SuperTextView_sLeftTextColor); + mLeftTopTextColor = typedArray.getColorStateList(R.styleable.SuperTextView_sLeftTopTextColor); + mLeftBottomTextColor = typedArray.getColorStateList(R.styleable.SuperTextView_sLeftBottomTextColor); + + mCenterTextColor = typedArray.getColorStateList(R.styleable.SuperTextView_sCenterTextColor); + mCenterTopTextColor = typedArray.getColorStateList(R.styleable.SuperTextView_sCenterTopTextColor); + mCenterBottomTextColor = typedArray.getColorStateList(R.styleable.SuperTextView_sCenterBottomTextColor); + + mRightTextColor = typedArray.getColorStateList(R.styleable.SuperTextView_sRightTextColor); + mRightTopTextColor = typedArray.getColorStateList(R.styleable.SuperTextView_sRightTopTextColor); + mRightBottomTextColor = typedArray.getColorStateList(R.styleable.SuperTextView_sRightBottomTextColor); + + ////////////////////////////////////////////////// + + + mLeftTextSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftTextSize, defaultSize); + mLeftTopTextSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftTopTextSize, defaultSize); + mLeftBottomTextSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftBottomTextSize, defaultSize); + + mCenterTextSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sCenterTextSize, defaultSize); + mCenterTopTextSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sCenterTopTextSize, defaultSize); + mCenterBottomTextSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sCenterBottomTextSize, defaultSize); + + mRightTextSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightTextSize, defaultSize); + mRightTopTextSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightTopTextSize, defaultSize); + mRightBottomTextSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightBottomTextSize, defaultSize); + + ////////////////////////////////////////////////// + mLeftTopLines = typedArray.getInt(R.styleable.SuperTextView_sLeftTopLines, defaultMaxLines); + mLeftLines = typedArray.getInt(R.styleable.SuperTextView_sLeftLines, defaultMaxLines); + mLeftBottomLines = typedArray.getInt(R.styleable.SuperTextView_sLeftBottomLines, defaultMaxLines); + + mCenterTopLines = typedArray.getInt(R.styleable.SuperTextView_sCenterTopLines, defaultMaxLines); + mCenterLines = typedArray.getInt(R.styleable.SuperTextView_sCenterLines, defaultMaxLines); + mCenterBottomLines = typedArray.getInt(R.styleable.SuperTextView_sCenterBottomLines, defaultMaxLines); + + mRightTopLines = typedArray.getInt(R.styleable.SuperTextView_sRightTopLines, defaultMaxLines); + mRightLines = typedArray.getInt(R.styleable.SuperTextView_sRightLines, defaultMaxLines); + mRightBottomLines = typedArray.getInt(R.styleable.SuperTextView_sRightBottomLines, defaultMaxLines); + + ////////////////////////////////////////////////// + + mLeftTopMaxEms = typedArray.getInt(R.styleable.SuperTextView_sLeftTopMaxEms, defaultMaxEms); + mLeftMaxEms = typedArray.getInt(R.styleable.SuperTextView_sLeftMaxEms, defaultMaxEms); + mLeftBottomMaxEms = typedArray.getInt(R.styleable.SuperTextView_sLeftBottomMaxEms, defaultMaxEms); + + mCenterTopMaxEms = typedArray.getInt(R.styleable.SuperTextView_sCenterTopMaxEms, defaultMaxEms); + mCenterMaxEms = typedArray.getInt(R.styleable.SuperTextView_sCenterMaxEms, defaultMaxEms); + mCenterBottomMaxEms = typedArray.getInt(R.styleable.SuperTextView_sCenterBottomMaxEms, defaultMaxEms); + + mRightTopMaxEms = typedArray.getInt(R.styleable.SuperTextView_sRightTopMaxEms, defaultMaxEms); + mRightMaxEms = typedArray.getInt(R.styleable.SuperTextView_sRightMaxEms, defaultMaxEms); + mRightBottomMaxEms = typedArray.getInt(R.styleable.SuperTextView_sRightBottomMaxEms, defaultMaxEms); + + //////////////////////////////////////////////// + + mLeftGravity = typedArray.getInt(R.styleable.SuperTextView_sLeftViewGravity, default_Gravity); + mCenterGravity = typedArray.getInt(R.styleable.SuperTextView_sCenterViewGravity, default_Gravity); + mRightGravity = typedArray.getInt(R.styleable.SuperTextView_sRightViewGravity, default_Gravity); + + mLeftTextGravity = typedArray.getInt(R.styleable.SuperTextView_sLeftTextGravity, default_text_gravity); + mCenterTextGravity = typedArray.getInt(R.styleable.SuperTextView_sCenterTextGravity, default_text_gravity); + mRightTextGravity = typedArray.getInt(R.styleable.SuperTextView_sRightTextGravity, default_text_gravity); + //////////////////////////////////////////////// + + mLeftTvDrawableLeft = typedArray.getDrawable(R.styleable.SuperTextView_sLeftTvDrawableLeft); + mLeftTvDrawableRight = typedArray.getDrawable(R.styleable.SuperTextView_sLeftTvDrawableRight); + mCenterTvDrawableLeft = typedArray.getDrawable(R.styleable.SuperTextView_sCenterTvDrawableLeft); + mCenterTvDrawableRight = typedArray.getDrawable(R.styleable.SuperTextView_sCenterTvDrawableRight); + mRightTvDrawableLeft = typedArray.getDrawable(R.styleable.SuperTextView_sRightTvDrawableLeft); + mRightTvDrawableRight = typedArray.getDrawable(R.styleable.SuperTextView_sRightTvDrawableRight); + + mTextViewDrawablePadding = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sTextViewDrawablePadding, default_Margin); + //////////////////////////////////////////////// + + mLeftTvDrawableWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftTvDrawableWidth, -1); + mLeftTvDrawableHeight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftTvDrawableHeight, -1); + + mCenterTvDrawableWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sCenterTvDrawableWidth, -1); + mCenterTvDrawableHeight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sCenterTvDrawableHeight, -1); + + mRightTvDrawableWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightTvDrawableWidth, -1); + mRightTvDrawableHeight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightTvDrawableHeight, -1); + + mLeftViewWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftViewWidth, 0); + /////////////////////////////////////////////// + mTopDividerLineMarginLR = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sTopDividerLineMarginLR, 0); + mTopDividerLineMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sTopDividerLineMarginLeft, 0); + mTopDividerLineMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sTopDividerLineMarginRight, 0); + + mBottomDividerLineMarginLR = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sBottomDividerLineMarginLR, 0); + mBottomDividerLineMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sBottomDividerLineMarginLeft, 0); + mBottomDividerLineMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sBottomDividerLineMarginRight, 0); + /////////////////////////////////////////////// + mDividerLineType = typedArray.getInt(R.styleable.SuperTextView_sDividerLineType, default_Divider); + mDividerLineColor = typedArray.getColor(R.styleable.SuperTextView_sDividerLineColor, mDefaultDividerLineColor); + + mDividerLineHeight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sDividerLineHeight, dip2px(mContext, 0.5f)); + //////////////////////////////////////////////// + mLeftViewMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftViewMarginLeft, default_Margin); + mLeftViewMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftViewMarginRight, default_Margin); + mCenterViewMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sCenterViewMarginLeft, 0); + mCenterViewMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sCenterViewMarginRight, 0); + mRightViewMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightViewMarginLeft, default_Margin); + mRightViewMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightViewMarginRight, default_Margin); + /////////////////////////////////////////////// leftIconWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftIconWidth, 0); leftIconHeight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftIconHeight, 0); rightIconWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightIconWidth, 0); rightIconHeight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightIconHeight, 0); - mLeftTopViewIsClickable = typedArray.getBoolean(R.styleable.SuperTextView_sLeftTopViewIsClickable, false); - mLeftBottomViewIsClickable = typedArray.getBoolean(R.styleable.SuperTextView_sLeftBottomViewIsClickable, false); - mLeftBottomView2IsClickable = typedArray.getBoolean(R.styleable.SuperTextView_sLeftBottomView2IsClickable, false); + leftIconMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftIconMarginLeft, default_Margin); + rightIconMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightIconMarginRight, default_Margin); + leftIconRes = typedArray.getDrawable(R.styleable.SuperTextView_sLeftIconRes); + rightIconRes = typedArray.getDrawable(R.styleable.SuperTextView_sRightIconRes); + ////////////////////////由于自定义方法数达到最大限度128个,暂时关闭不常用属性改为代码控制////////////////////// +// mLeftTopTextBold = typedArray.getBoolean(R.styleable.SuperTextView_sLeftTopTextIsBold, false); +// mLeftTextBold = typedArray.getBoolean(R.styleable.SuperTextView_sLeftTextIsBold, false); +// mLeftBottomTextBold = typedArray.getBoolean(R.styleable.SuperTextView_sLeftBottomTextIsBold, false); +// +// mCenterTopTextBold = typedArray.getBoolean(R.styleable.SuperTextView_sCenterTopTextIsBold, false); +// mCenterTextBold = typedArray.getBoolean(R.styleable.SuperTextView_sCenterTextIsBold, false); +// mCenterBottomTextBold = typedArray.getBoolean(R.styleable.SuperTextView_sCenterBottomTextIsBold, false); +// +// mRightTopTextBold = typedArray.getBoolean(R.styleable.SuperTextView_sRightTopTextIsBold, false); +// mRightTextBold = typedArray.getBoolean(R.styleable.SuperTextView_sRightTextIsBold, false); +// mRightBottomTextBold = typedArray.getBoolean(R.styleable.SuperTextView_sRightBottomTextIsBold, false); + + mLeftTextBackground = typedArray.getDrawable(R.styleable.SuperTextView_sLeftTextBackground); + mCenterTextBackground = typedArray.getDrawable(R.styleable.SuperTextView_sCenterTextBackground); + mRightTextBackground = typedArray.getDrawable(R.styleable.SuperTextView_sRightTextBackground); + + ////////////////////////////////////////////// + useRipple = typedArray.getBoolean(R.styleable.SuperTextView_sUseRipple, true); mBackground_drawable = typedArray.getDrawable(R.styleable.SuperTextView_sBackgroundDrawableRes); + /////////////////////////////////////////////// + mRightViewType = typedArray.getInt(R.styleable.SuperTextView_sRightViewType, -1); + //////////////////////////////////////////////// + switch (mRightViewType){ + case TYPE_CHECKBOX:{ + isChecked = typedArray.getBoolean(R.styleable.SuperTextView_sIsChecked, false); + rightCheckBoxMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightCheckBoxMarginRight, default_Margin); + rightCheckBoxBg = typedArray.getDrawable(R.styleable.SuperTextView_sRightCheckBoxRes); + }break; + case TYPE_SWITCH:{ + rightSwitchMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightSwitchMarginRight, default_Margin); + switchIsChecked = typedArray.getBoolean(R.styleable.SuperTextView_sSwitchIsChecked, false); + mTextOff = typedArray.getString(R.styleable.SuperTextView_sTextOff); + mTextOn = typedArray.getString(R.styleable.SuperTextView_sTextOn); + + mSwitchMinWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sSwitchMinWidth, 0); + mSwitchPadding = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sSwitchPadding, 0); + mThumbTextPadding = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sThumbTextPadding, 0); + + mThumbResource = typedArray.getDrawable(R.styleable.SuperTextView_sThumbResource); + mTrackResource = typedArray.getDrawable(R.styleable.SuperTextView_sTrackResource); + }break; + case TYPE_EDIT:{ + rightEditMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sEditMarginRight, 0); + mEditMinWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sEditMinWidth, 0); + mEditImeOption = typedArray.getInt(R.styleable.SuperTextView_android_imeOptions, EditorInfo.IME_NULL); + mEditInputType = typedArray.getInt(R.styleable.SuperTextView_android_inputType, EditorInfo.TYPE_NULL); + mRightEditTextColor = typedArray.getColorStateList(R.styleable.SuperTextView_sEditTextColor); + mRightEditHintTextColor = typedArray.getColorStateList(R.styleable.SuperTextView_sEditHintTextColor); + mEditHintText = typedArray.getString(R.styleable.SuperTextView_sEditHint); + editActiveLineColor = typedArray.getColor(R.styleable.SuperTextView_sEditActiveLineColor, editActiveLineColor); + mEditTextSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sEditTextSize, defaultSize); + mEditCusorDrawableRes = typedArray.getResourceId(R.styleable.SuperTextView_sEditCursorDrawable,0); + mEditCusorVisible = typedArray.getBoolean(R.styleable.SuperTextView_sEditCursorVisible,true); + }break; + } + + centerSpaceHeight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sCenterSpaceHeight, dip2px(mContext, 5)); + //////////////////////////////////////////////////// + selectorPressedColor = typedArray.getColor(R.styleable.SuperTextView_sShapeSelectorPressedColor, -1); + selectorNormalColor = typedArray.getColor(R.styleable.SuperTextView_sShapeSelectorNormalColor, -1); + + solidColor = typedArray.getColor(R.styleable.SuperTextView_sShapeSolidColor, defaultShapeColor); + + cornersRadius = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sShapeCornersRadius, 0); + cornersTopLeftRadius = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sShapeCornersTopLeftRadius, 0); + cornersTopRightRadius = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sShapeCornersTopRightRadius, 0); + cornersBottomLeftRadius = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sShapeCornersBottomLeftRadius, 0); + cornersBottomRightRadius = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sShapeCornersBottomRightRadius, 0); + + strokeWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sShapeStrokeWidth, 0); + strokeDashWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sShapeStrokeDashWidth, 0); + strokeDashGap = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sShapeStrokeDashGap, 0); + + strokeColor = typedArray.getColor(R.styleable.SuperTextView_sShapeStrokeColor, defaultShapeColor); + + useShape = typedArray.getBoolean(R.styleable.SuperTextView_sUseShape, false); + mLeftIconShowCircle = typedArray.getBoolean(R.styleable.SuperTextView_sLeftIconShowCircle, false); + mRightIconShowCircle = typedArray.getBoolean(R.styleable.SuperTextView_sRightIconShowCircle, false); + typedArray.recycle(); } /** - * 初始化布局 + * 初始化Params + * + * @param params params + * @return params + */ + private LayoutParams getParams(LayoutParams params) { + if (params == null) { + params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + } + return params; + } + + /** + * 初始化View */ - private void initLayout() { + private void initView() { initSuperTextView(); - initCenterBaseLine(); - if (leftIconRes != null) { - initLeftIcon(); - } - if (leftTopTextString != null) { - initLeftTopText(); - } - if (leftBottomTextString != null) { - initLeftBottomText(); - } - if (leftBottomTextString2 != null) { - initLeftBottomText2(); - } - if (leftTextString != null) { - initLeftText(); - } - if (centerTextString != null) { - initCenterText(); - } - if (rightIconRes != null) { - initRightIcon(); - } - if (rightTextString != null || rightTextStringRightIconRes != null) { - initRightText(); - } - if (showCheckBox) { - initRightCheckBox(); - } + initShape(); + initLeftIcon(); - switch (lineType) { - case NONE: - break; - case TOP: - setTopLineMargin(); + switch (mRightViewType) { + case TYPE_CHECKBOX: + initRightCheckBox(); break; - case BOTTOM: - setBottomLineMargin(); - break; - case BOTH: - setTopLineMargin(); - setBottomLineMargin(); + case TYPE_SWITCH: + initRightSwitch(); break; } + + initRightIcon(); + + if(mRightViewType == TYPE_EDIT){ + initRightEditText(); + } + + initLeftTextView(); + initCenterTextView(); + initRightTextView(); + } - /** - * 设置顶部分割线的左右边距 - */ - private void setTopLineMargin() { - if (topLineMargin != 0) { - initTopLine(topLineMargin, topLineMargin, topLineWidth); - } else if (bothLineMarginLeft != 0 | bothLineMarginRight != 0) { - initTopLine(bothLineMarginLeft, bothLineMarginRight, topLineWidth); - } else { - initTopLine(topLineMarginLeft, topLineMarginRight, topLineWidth); + + private void initShape() { + if (useShape) { + shapeBuilder + .setShapeType(ShapeType.RECTANGLE) + .setShapeCornersRadius(cornersRadius) + .setShapeCornersTopLeftRadius(cornersTopLeftRadius) + .setShapeCornersTopRightRadius(cornersTopRightRadius) + .setShapeCornersBottomRightRadius(cornersBottomRightRadius) + .setShapeCornersBottomLeftRadius(cornersBottomLeftRadius) + .setShapeSolidColor(solidColor) + .setShapeStrokeColor(strokeColor) + .setShapeStrokeWidth(strokeWidth) + .setShapeStrokeDashWidth(strokeDashWidth) + .setShapeStrokeDashGap(strokeDashGap) + .setShapeUseSelector(selectorNormalColor != -1 || selectorPressedColor != -1) + .setShapeSelectorNormalColor(selectorNormalColor) + .setShapeSelectorPressedColor(selectorPressedColor) + .into(this); } } + private void initPaint() { + mTopDividerPaint = new Paint(); + mTopDividerPaint.setColor(mDividerLineColor); + mTopDividerPaint.setAntiAlias(true); + mTopDividerPaint.setStrokeWidth(mDividerLineHeight); + + + mBottomDividerPaint = new Paint(); + mBottomDividerPaint.setColor(mDividerLineColor); + mBottomDividerPaint.setAntiAlias(true); + mBottomDividerPaint.setStrokeWidth(mDividerLineHeight); + + } + + /** - * 设置底部分割线的左右边距 + * onDraw和dispatchDraw的区别请自行google + * + * @param canvas 画笔 */ - private void setBottomLineMargin() { - if (bottomLineMargin != 0) { - initBottomLine(bottomLineMargin, bottomLineMargin, bottomLineWidth); - } else if (bothLineMarginLeft != 0 | bothLineMarginRight != 0) { - initBottomLine(bothLineMarginLeft, bothLineMarginRight, topLineWidth); - } else { - initBottomLine(bottomLineMarginLeft, bottomLineMarginRight, topLineWidth); + @Override + protected void dispatchDraw(Canvas canvas) { + super.dispatchDraw(canvas); + if (!useShape) { + mIsShowTopDivider = (TOP == mDividerLineType || BOTH == mDividerLineType); + mIsShowBottomDivider = (BOTTOM == mDividerLineType || BOTH == mDividerLineType); + if (mIsShowTopDivider) { + drawTopDivider(canvas); + } + if (mIsShowBottomDivider) { + drawBottomDivider(canvas); + } } } /** - * 初始化上边的线 + * 绘制上边的分割线 + * + * @param canvas canvas */ - private void initTopLine(int lineMarginLeft, int lineMarginRight, int lineWidth) { - View topLine = new View(mContext); - topLineParams = new LayoutParams(LayoutParams.MATCH_PARENT, lineWidth); - topLineParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, TRUE); - topLineParams.setMargins(lineMarginLeft, 0, lineMarginRight, 0); - topLine.setLayoutParams(topLineParams); - topLine.setBackgroundColor(lineColor); - addView(topLine); + private void drawTopDivider(Canvas canvas) { + drawDivider(canvas, true, mTopDividerLineMarginLR, mTopDividerLineMarginLeft, mTopDividerLineMarginRight, mTopDividerPaint); } /** - * 初始化下边的线 + * 绘制底部的分割线 + * + * @param canvas canvas */ - private void initBottomLine(int lineMarginLeft, int lineMarginRight, int lineWidth) { - View bottomLine = new View(mContext); - bottomLineParams = new LayoutParams(LayoutParams.MATCH_PARENT, lineWidth); - bottomLineParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, TRUE); - bottomLineParams.setMargins(lineMarginLeft, 0, lineMarginRight, 0); - bottomLine.setLayoutParams(bottomLineParams); - bottomLine.setBackgroundColor(lineColor); - addView(bottomLine); + private void drawBottomDivider(Canvas canvas) { + drawDivider(canvas, false, mBottomDividerLineMarginLR, mBottomDividerLineMarginLeft, mBottomDividerLineMarginRight, mBottomDividerPaint); } /** - * 初始化SuperTextView + * 绘制分割线 + * + * @param canvas canvas + * @param marginLR 左右间距 + * @param marginLeft 左间距 + * @param marginRight 右间距 + * @param paint 画笔 */ - private void initSuperTextView() { + private void drawDivider(Canvas canvas, boolean isTopDivider, int marginLR, int marginLeft, int marginRight, Paint paint) { - this.setBackgroundColor(backgroundColor); - this.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - if (onSuperTextViewClickListener != null) { - onSuperTextViewClickListener.onSuperTextViewClick(); - } - } - }); + if (marginLR != 0) { + marginLeft = marginRight = marginLR; + } + canvas.drawLine(marginLeft, isTopDivider ? 0 : getHeight(), this.getWidth() - marginRight, isTopDivider ? 0 : getHeight(), paint); + } + + private void initSuperTextView() { if (useRipple) { this.setBackgroundResource(R.drawable.selector_white); + this.setClickable(true); } + if (mBackground_drawable != null) { this.setBackgroundDrawable(mBackground_drawable); } } - - /** - * 为了设置上下两排文字居中对齐显示而需要设置的基准线 - */ - private void initCenterBaseLine() { - View view = new View(mContext); - centerBaseLineParams = new LayoutParams(LayoutParams.MATCH_PARENT, centerSpaceHeight); - centerBaseLineParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE); - view.setId(R.id.sCenterBaseLineId); - view.setLayoutParams(centerBaseLineParams); - addView(view); - } - - /** * 初始化左边图标 */ private void initLeftIcon() { - leftIconIV = new ImageView(mContext); + if (leftIconIV == null) { + leftIconIV = new CircleImageView(mContext); + } leftImgParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - leftImgParams.addRule(ALIGN_PARENT_LEFT, TRUE); + leftImgParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, TRUE); leftImgParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE); if (leftIconHeight != 0 && leftIconWidth != 0) { leftImgParams.width = leftIconWidth; leftImgParams.height = leftIconHeight; } - setMargin(leftImgParams, leftIconMarginLeft, 0, 0, 0); - leftIconIV.setScaleType(ImageView.ScaleType.FIT_CENTER); - leftIconIV.setId(R.id.sLeftIconId); +// leftIconIV.setScaleType(ImageView.ScaleType.FIT_CENTER); + leftIconIV.setId(R.id.sLeftImgId); leftIconIV.setLayoutParams(leftImgParams); if (leftIconRes != null) { + leftImgParams.setMargins(leftIconMarginLeft, 0, 0, 0); leftIconIV.setImageDrawable(leftIconRes); } + setCircleImage(leftIconIV, mLeftIconShowCircle); addView(leftIconIV); } /** - * 初始化左边文字 + * 初始化右边图标 */ - private void initLeftText() { - leftTV = new TextView(mContext); - leftTextParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - leftTextParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE); - leftTextParams.addRule(RelativeLayout.RIGHT_OF, R.id.sLeftIconId); - setMargin(leftTextParams, leftTVMarginLeft, 0, dip2px(mContext, 10), 0); - leftTV.setId(R.id.sLeftTextId); - leftTV.setLayoutParams(leftTextParams); - leftTV.setText(leftTextString); + private void initRightIcon() { + if (rightIconIV == null) { + rightIconIV = new CircleImageView(mContext); + } + rightImgParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + rightImgParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE); - setTextViewParams(leftTV, isSingLines, maxLines, maxEms); + switch (mRightViewType) { + case TYPE_CHECKBOX: + rightImgParams.addRule(RelativeLayout.LEFT_OF, R.id.sRightCheckBoxId); + break; + case TYPE_SWITCH: + rightImgParams.addRule(RelativeLayout.LEFT_OF, R.id.sRightSwitchId); + break; + default: + rightImgParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, TRUE); - setTextColor(leftTV, leftTVColor); - setTextSize(leftTV, leftTVSize); - addView(leftTV); - } + } - /** - * 设置通用的textView显示效果属性 - * - * @param textView view - * @param isSingLines 是否单行显示 - * @param maxLines 显示最大行 - * @param maxEms 最多显示多少个字 - */ - private void setTextViewParams(TextView textView, boolean isSingLines, int maxLines, int maxEms) { - textView.setSingleLine(isSingLines); - textView.setMaxLines(maxLines); - textView.setMaxEms(maxEms); - textView.setEllipsize(TextUtils.TruncateAt.END); - } + if (rightIconHeight != 0 && rightIconWidth != 0) { + rightImgParams.width = rightIconWidth; + rightImgParams.height = rightIconHeight; + } - /** - * 初始化左上文字 - */ - private void initLeftTopText() { - leftTopTV = new TextView(mContext); - leftTopTextParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - leftTopTextParams.addRule(RelativeLayout.ABOVE, R.id.sCenterBaseLineId); - leftTopTextParams.addRule(RelativeLayout.RIGHT_OF, R.id.sLeftIconId); - setMargin(leftTopTextParams, leftTopMarginLeft, 0, 0, 0); - leftTopTV.setId(R.id.sLeftTopTextId); - leftTopTV.setLayoutParams(leftTopTextParams); - leftTopTV.setText(leftTopTextString); - setTextColor(leftTopTV, leftTopTVColor); - setTextSize(leftTopTV, leftTopTVSize); - if (mLeftTopViewIsClickable) { - leftTopTV.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - if (onSuperTextViewClickListener != null) { - onSuperTextViewClickListener.onLeftTopClick(); - } - } - }); +// rightIconIV.setScaleType(ImageView.ScaleType.FIT_CENTER); + rightIconIV.setId(R.id.sRightImgId); + rightIconIV.setLayoutParams(rightImgParams); + if (rightIconRes != null) { + rightImgParams.setMargins(0, 0, rightIconMarginRight, 0); + rightIconIV.setImageDrawable(rightIconRes); } - setTextViewParams(leftTopTV, isSingLines, maxLines, maxEms); - addView(leftTopTV); + setCircleImage(rightIconIV, mRightIconShowCircle); + addView(rightIconIV); } /** - * 初始化左下文字 + * 初始化LeftTextView */ - private void initLeftBottomText() { - leftBottomTV = new TextView(mContext); - leftBottomParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - leftBottomParams.addRule(RelativeLayout.BELOW, R.id.sCenterBaseLineId); - leftBottomParams.addRule(RelativeLayout.RIGHT_OF, R.id.sLeftIconId); - setMargin(leftBottomParams, leftBottomMarginLeft, 0, 0, 0); - leftBottomTV.setId(R.id.sLeftBottomTextId); - leftBottomTV.setLayoutParams(leftBottomParams); - leftBottomTV.setText(leftBottomTextString); - setTextColor(leftBottomTV, leftBottomTVColor); - setTextSize(leftBottomTV, leftBottomTVSize); - if (mLeftBottomViewIsClickable) { - leftBottomTV.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - if (onSuperTextViewClickListener != null) { - onSuperTextViewClickListener.onLeftBottomClick(); - } - } - }); + private void initLeftTextView() { + if (leftView == null) { + leftView = initBaseView(R.id.sLeftViewId); + } + leftBaseViewParams = getParams(leftBaseViewParams); + leftBaseViewParams.addRule(RelativeLayout.RIGHT_OF, R.id.sLeftImgId); + leftBaseViewParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE); + if (mLeftViewWidth != 0) { + leftBaseViewParams.width = mLeftViewWidth; } - setTextViewParams(leftBottomTV, isSingLines, maxLines, maxEms); - addView(leftBottomTV); + leftBaseViewParams.setMargins(mLeftViewMarginLeft, 0, mLeftViewMarginRight, 0); + + leftView.setLayoutParams(leftBaseViewParams); + + leftView.setCenterSpaceHeight(centerSpaceHeight); + setDefaultColor(leftView, mLeftTopTextColor, mLeftTextColor, mLeftBottomTextColor); + setDefaultSize(leftView, mLeftTopTextSize, mLeftTextSize, mLeftBottomTextSize); + setDefaultLines(leftView, mLeftTopLines, mLeftLines, mLeftBottomLines); + setDefaultMaxEms(leftView, mLeftTopMaxEms, mLeftMaxEms, mLeftBottomMaxEms); +// setDefaultTextIsBold(leftView, mLeftTopTextBold, mLeftTextBold, mLeftBottomTextBold); + setDefaultGravity(leftView, mLeftGravity); + setDefaultTextGravity(leftView, mLeftTextGravity); + setDefaultDrawable(leftView.getCenterTextView(), mLeftTvDrawableLeft, mLeftTvDrawableRight, mTextViewDrawablePadding, mLeftTvDrawableWidth, mLeftTvDrawableHeight); + setDefaultBackground(leftView.getCenterTextView(), mLeftTextBackground); + setDefaultString(leftView, mLeftTopTextString, mLeftTextString, mLeftBottomTextString); + + addView(leftView); } + /** - * 初始化左下第二个文字 + * 初始化CenterTextView */ - private void initLeftBottomText2() { - leftBottomTV2 = new TextView(mContext); - leftBottomParams2 = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - leftBottomParams2.addRule(RelativeLayout.BELOW, R.id.sCenterBaseLineId); - leftBottomParams2.addRule(RelativeLayout.RIGHT_OF, R.id.sLeftBottomTextId); - setMargin(leftBottomParams2, leftBottomMarginLeft2, 0, 0, 0); - leftBottomTV2.setId(R.id.sLeftBottomTextId2); - leftBottomTV2.setLayoutParams(leftBottomParams2); - leftBottomTV2.setText(leftBottomTextString2); - setTextColor(leftBottomTV2, leftBottomTVColor2); - setTextSize(leftBottomTV2, leftBottomTVSize2); - if (mLeftBottomView2IsClickable) { - leftBottomTV2.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - if (onSuperTextViewClickListener != null) { - onSuperTextViewClickListener.onLeftBottomClick2(); - } - } - }); + private void initCenterTextView() { + if (centerView == null) { + centerView = initBaseView(R.id.sCenterViewId); + } + centerBaseViewParams = getParams(centerBaseViewParams); + centerBaseViewParams.addRule(RelativeLayout.CENTER_IN_PARENT, TRUE); + centerBaseViewParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE); + + //默认情况下 中间的View整体剧中显示,设置左对齐或者右对齐的话使用下边属性 + if (mCenterGravity != default_Gravity) { + centerBaseViewParams.addRule(RIGHT_OF, R.id.sLeftViewId); + centerBaseViewParams.addRule(LEFT_OF, R.id.sRightViewId); } - setTextViewParams(leftBottomTV2, isSingLines, maxLines, maxEms); - addView(leftBottomTV2); + + centerBaseViewParams.setMargins(mCenterViewMarginLeft, 0, mCenterViewMarginRight, 0); + + centerView.setLayoutParams(centerBaseViewParams); + centerView.setCenterSpaceHeight(centerSpaceHeight); + + setDefaultColor(centerView, mCenterTopTextColor, mCenterTextColor, mCenterBottomTextColor); + setDefaultSize(centerView, mCenterTopTextSize, mCenterTextSize, mCenterBottomTextSize); + setDefaultLines(centerView, mCenterTopLines, mCenterLines, mCenterBottomLines); + setDefaultMaxEms(centerView, mCenterTopMaxEms, mCenterMaxEms, mCenterBottomMaxEms); +// setDefaultTextIsBold(centerView, mCenterTopTextBold, mCenterTextBold, mCenterBottomTextBold); + setDefaultGravity(centerView, mCenterGravity); + setDefaultTextGravity(centerView, mCenterTextGravity); + setDefaultDrawable(centerView.getCenterTextView(), mCenterTvDrawableLeft, mCenterTvDrawableRight, mTextViewDrawablePadding, mCenterTvDrawableWidth, mCenterTvDrawableHeight); + setDefaultBackground(centerView.getCenterTextView(), mCenterTextBackground); + setDefaultString(centerView, mCenterTopTextString, mCenterTextString, mCenterBottomTextString); + + addView(centerView); } /** - * 初始化中间文字 + * 初始化RightTextView */ - private void initCenterText() { - centerTV = new TextView(mContext); - centerTextParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - centerTextParams.addRule(RelativeLayout.CENTER_IN_PARENT, TRUE); - centerTV.setId(R.id.sCenterTextId); - centerTV.setLayoutParams(centerTextParams); - centerTV.setText(centerTextString); - setTextColor(centerTV, centerTVColor); - setTextSize(centerTV, centerTVSize); - setTextViewParams(centerTV, isSingLines, maxLines, maxEms); - addView(centerTV); + private void initRightTextView() { + if (rightView == null) { + rightView = initBaseView(R.id.sRightViewId); + } + rightBaseViewParams = getParams(rightBaseViewParams); + rightBaseViewParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE); + + rightBaseViewParams.addRule(RelativeLayout.LEFT_OF, R.id.sRightImgId); + rightBaseViewParams.setMargins(mRightViewMarginLeft, 0, mRightViewMarginRight, 0); + + rightView.setLayoutParams(rightBaseViewParams); + rightView.setCenterSpaceHeight(centerSpaceHeight); + + setDefaultColor(rightView, mRightTopTextColor, mRightTextColor, mRightBottomTextColor); + setDefaultSize(rightView, mRightTopTextSize, mRightTextSize, mRightBottomTextSize); + setDefaultLines(rightView, mRightTopLines, mRightLines, mRightBottomLines); + setDefaultMaxEms(rightView, mRightTopMaxEms, mRightMaxEms, mRightBottomMaxEms); +// setDefaultTextIsBold(rightView, mRightTopTextBold, mRightTextBold, mRightBottomTextBold); + setDefaultGravity(rightView, mRightGravity); + setDefaultTextGravity(rightView, mRightTextGravity); + setDefaultDrawable(rightView.getCenterTextView(), mRightTvDrawableLeft, mRightTvDrawableRight, mTextViewDrawablePadding, mRightTvDrawableWidth, mRightTvDrawableHeight); + setDefaultBackground(rightView.getCenterTextView(), mRightTextBackground); + setDefaultString(rightView, mRightTopTextString, mRightTextString, mRightBottomTextString); + + addView(rightView); } + /** - * 初始化右边文字 + * 初始化RightCheckBox */ - private void initRightText() { - rightTV = new TextView(mContext); - rightTextParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - rightTextParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE); - rightTextParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, TRUE); - rightTextParams.addRule(RelativeLayout.RIGHT_OF, R.id.sLeftTextId); - rightTextParams.addRule(RelativeLayout.LEFT_OF, R.id.sRightIconId); - setMargin(rightTextParams, 0, 0, rightTVMarginRight, 0); - rightTV.setId(R.id.sRightTextId); - rightTV.setLayoutParams(rightTextParams); - rightTV.setText(rightTextString); - setTextColor(rightTV, rightTVColor); - setTextSize(rightTV, rightTVSize); - setTextViewRightDrawble(rightTV, rightTextStringRightIconRes, rightTextStringRightIconPadding); - rightTV.setGravity(Gravity.RIGHT); - setTextViewParams(rightTV, isSingLines, maxLines, maxEms); - addView(rightTV); + private void initRightCheckBox() { + if (rightCheckBox == null) { + rightCheckBox = new AppCompatCheckBox(mContext); + } + rightCheckBoxParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + + rightCheckBoxParams.addRule(ALIGN_PARENT_RIGHT, TRUE); + rightCheckBoxParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE); + rightCheckBoxParams.setMargins(0, 0, rightCheckBoxMarginRight, 0); + rightCheckBox.setId(R.id.sRightCheckBoxId); + rightCheckBox.setLayoutParams(rightCheckBoxParams); + if (rightCheckBoxBg != null) { + rightCheckBox.setGravity(CENTER_IN_PARENT); + rightCheckBox.setButtonDrawable(rightCheckBoxBg); + } + rightCheckBox.setChecked(isChecked); + rightCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (checkBoxCheckedChangeListener != null) { + checkBoxCheckedChangeListener.onCheckedChanged(buttonView, isChecked); + } + } + }); + addView(rightCheckBox); } /** - * 初始化右边图标 + * 初始化RightSwitch */ - private void initRightIcon() { - rightIconIV = new ImageView(mContext); - rightImgParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - rightImgParams.addRule(ALIGN_PARENT_RIGHT, TRUE); - rightImgParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE); - if (rightIconHeight != 0 && rightIconWidth != 0) { - rightImgParams.width = rightIconWidth; - rightImgParams.height = rightIconHeight; + private void initRightSwitch() { + if (mSwitch == null) { + mSwitch = new SwitchCompat(mContext); + } + mSwitchParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + + mSwitchParams.addRule(ALIGN_PARENT_RIGHT, TRUE); + mSwitchParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE); + mSwitchParams.setMargins(0, 0, rightSwitchMarginRight, 0); + mSwitch.setId(R.id.sRightSwitchId); + mSwitch.setLayoutParams(mSwitchParams); + + mSwitch.setChecked(switchIsChecked); + if (!TextUtils.isEmpty(mTextOff)) { + mSwitch.setTextOff(mTextOff); + mSwitch.setShowText(true); + } + if (!TextUtils.isEmpty(mTextOn)) { + mSwitch.setTextOn(mTextOn); + mSwitch.setShowText(true); + } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + if (mSwitchMinWidth != 0) { + mSwitch.setSwitchMinWidth(mSwitchMinWidth); + } + if (mSwitchPadding != 0) { + mSwitch.setSwitchPadding(mSwitchPadding); + } + if (mThumbResource != null) { + mSwitch.setThumbDrawable(mThumbResource); + } + if (mThumbResource != null) { + mSwitch.setTrackDrawable(mTrackResource); + } + if (mThumbTextPadding != 0) { + mSwitch.setThumbTextPadding(mThumbTextPadding); + } + + } + mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (switchCheckedChangeListener != null) { + switchCheckedChangeListener.onCheckedChanged(buttonView, isChecked); + } + } + }); + + addView(mSwitch); + } + + + private void initRightEditText() { + + if (mEditText == null) { + mEditText = new AppCompatEditText(mContext); + mEditText.setSingleLine(true); + mEditText.setGravity(Gravity.END); + mEditText.setImeOptions(mEditImeOption); + mEditText.setInputType(mEditInputType); + mEditText.setBackgroundDrawable(null); + mEditText.setTextSize(TypedValue.COMPLEX_UNIT_PX,mEditTextSize); + mEditText.setCursorVisible(mEditCusorVisible); + //setFocusable(true); + //setFocusableInTouchMode(true); + EditTextHelper.INSTANCE.setCursorDrawable(mEditText,mEditCusorDrawableRes); + } + + if(mRightEditHintTextColor!=null){ + mEditText.setHintTextColor(mRightEditHintTextColor); + } + if(mRightEditTextColor!=null){ + mEditText.setTextColor(mRightEditTextColor); + } + if(mEditHintText!=null){ + mEditText.setHint(mEditHintText); + } + + if(mEditMinWidth==0){ + mEditParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); + }else{ + mEditText.setMinWidth(mEditMinWidth); + mEditParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + } + + + mEditParams.addRule(RelativeLayout.LEFT_OF, R.id.sRightImgId); + mEditParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE); + mEditParams.setMargins(0, 0, rightEditMarginRight, 0); + mEditText.setId(R.id.sRightEditTextId); + mEditText.setLayoutParams(mEditParams); + + addView(mEditText); + //setFocusable(false); + //setFocusableInTouchMode(false); + + mEditText.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + if (editTextChangeListener != null) { + editTextChangeListener.beforeTextChanged(s,start,count,after); + } + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + if (editTextChangeListener != null) { + editTextChangeListener.onTextChanged(s,start,before,count); + } + } + + @Override + public void afterTextChanged(Editable s) { + if (editTextChangeListener != null) { + editTextChangeListener.afterTextChanged(s); + } + } + }); + + + + if(editActiveLineColor!=-1){ + mEditText.setOnFocusChangeListener(new OnFocusChangeListener() { + @Override + public void onFocusChange(View v, boolean hasFocus) { + if(hasFocus){ + setBottomDividerLineColor(editActiveLineColor); + }else{ + setBottomDividerLineColor(mDividerLineColor); + } + } + }); + } + + + + } + + /////////////////////////////////////默认属性设置----begin///////////////////////////////// + + /** + * 设置圆形ImageView属性 + * + * @param circleImageView view + * @param disableCircularTransformation 是否允许圆形转换 默认true + */ + private void setCircleImage(CircleImageView circleImageView, boolean disableCircularTransformation) { + circleImageView.setDisableCircularTransformation(!disableCircularTransformation); + } + + /** + * 初始化BaseTextView + * + * @param id id + * @return baseTextView + */ + private BaseTextView initBaseView(int id) { + BaseTextView baseTextView = new BaseTextView(mContext); + baseTextView.setId(id); + return baseTextView; + } + + /** + * 设置默认值 + * + * @param baseTextView baseTextView + * @param topTextString topTextString + * @param leftTextString leftTextString + * @param bottomTextString bottomTextString + */ + private void setDefaultString(BaseTextView baseTextView, String topTextString, String leftTextString, String bottomTextString) { + if (baseTextView != null) { + baseTextView.setTopTextString(topTextString); + baseTextView.setCenterTextString(leftTextString); + baseTextView.setBottomTextString(bottomTextString); + } + } + + /** + * 设置默认 + * + * @param baseTextView baseTextView + * @param topTextColor topTextColor + * @param textColor textColor + * @param bottomTextColor bottomTextColor + */ + private void setDefaultColor(BaseTextView baseTextView, ColorStateList topTextColor, ColorStateList textColor, ColorStateList bottomTextColor) { + if (baseTextView != null) { + if (topTextColor == null) { + topTextColor = ColorStateList.valueOf(defaultColor); + } + if (textColor == null) { + textColor = ColorStateList.valueOf(defaultColor); + } + if (bottomTextColor == null) { + bottomTextColor = ColorStateList.valueOf(defaultColor); + } + baseTextView.getTopTextView().setTextColor(topTextColor); + baseTextView.getCenterTextView().setTextColor(textColor); + baseTextView.getBottomTextView().setTextColor(bottomTextColor); + } + } + + /** + * 设置默认字体大小 + * + * @param baseTextView baseTextView + * @param leftTextSize leftTextSize + * @param topTextSize topTextSize + * @param bottomTextSize bottomTextSize + */ + private void setDefaultSize(BaseTextView baseTextView, int topTextSize, int leftTextSize, int bottomTextSize) { + if (baseTextView != null) { + baseTextView.getTopTextView().setTextSize(TypedValue.COMPLEX_UNIT_PX, topTextSize); + baseTextView.getCenterTextView().setTextSize(TypedValue.COMPLEX_UNIT_PX, leftTextSize); + baseTextView.getBottomTextView().setTextSize(TypedValue.COMPLEX_UNIT_PX, bottomTextSize); + } + } + + /** + * 设置默认maxEms + * + * @param baseTextView baseTextView + * @param topMaxEms topMaxEms + * @param centerMaxEms centerMaxEms + * @param bottomMaxEms bottomMaxEms + */ + private void setDefaultMaxEms(BaseTextView baseTextView, int topMaxEms, int centerMaxEms, int bottomMaxEms) { + if (baseTextView != null) { + baseTextView.setMaxEms(topMaxEms, centerMaxEms, bottomMaxEms); + } + + } + + /** + * 设置默认lines + * + * @param baseTextView baseTextView + * @param leftTopLines leftTopLines + * @param leftLines leftLines + * @param bottomLines bottomLines + */ + private void setDefaultLines(BaseTextView baseTextView, int leftTopLines, int leftLines, int bottomLines) { + if (baseTextView != null) { + if (leftTopLines != 0) { + baseTextView.getTopTextView().setMaxLines(leftTopLines); + } + if (leftLines != 0) { + baseTextView.getCenterTextView().setMaxLines(leftLines); + } + if (bottomLines != 0) { + baseTextView.getBottomTextView().setMaxLines(bottomLines); + } + } + + } + + /** + * 设置文字对其方式 + * + * @param baseTextView baseTextView + * @param gravity 对其方式 + */ + private void setDefaultGravity(BaseTextView baseTextView, int gravity) { + if (baseTextView != null) { + setGravity(baseTextView, gravity); + } + } + + /** + * 文字对其方式 + * + * @param baseTextView textView + * @param gravity 对其方式 + */ + private void setGravity(BaseTextView baseTextView, int gravity) { + switch (gravity) { + case gravity_Left_Center: + baseTextView.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); + break; + case gravity_Center: + baseTextView.setGravity(Gravity.CENTER); + break; + case gravity_Right_Center: + baseTextView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL); + break; + } + } + + /** + * 设置文字对其方式 + * + * @param baseTextView baseTextView + * @param gravity 对其方式 + */ + private void setDefaultTextGravity(BaseTextView baseTextView, int gravity) { + if (baseTextView != null) { + switch (gravity) { + case text_gravity_Left: + setTextGravity(baseTextView, Gravity.LEFT); + break; + case text_gravity_center: + setTextGravity(baseTextView, Gravity.CENTER); + break; + case text_gravity_right: + setTextGravity(baseTextView, Gravity.RIGHT); + break; + } + } + } + + + /** + * 设置textView的drawable + * + * @param textView 对象 + * @param drawableLeft 左边图标 + * @param drawableRight 右边图标 + * @param drawablePadding 图标距离文字的间距 + */ + public void setDefaultDrawable(AppCompatTextView textView, Drawable drawableLeft, Drawable drawableRight, int drawablePadding, int drawableWidth, int drawableHeight) { + if (drawableLeft != null || drawableRight != null) { + textView.setVisibility(VISIBLE); + } + //可以指定drawable的宽高 + if (drawableWidth != -1 && drawableHeight != -1) { + if (drawableLeft != null) { + drawableLeft.setBounds(0, 0, drawableWidth, drawableHeight); + } + if (drawableRight != null) { + drawableRight.setBounds(0, 0, drawableWidth, drawableHeight); + } + textView.setCompoundDrawables(drawableLeft, null, drawableRight, null); + } else { + textView.setCompoundDrawablesWithIntrinsicBounds(drawableLeft, null, drawableRight, null); + } + textView.setCompoundDrawablePadding(drawablePadding); + } + + /** + * 设置textView的背景,用户传入drawable实现圆角之类的样式 + * + * @param textView + * @param background + */ + private void setDefaultBackground(AppCompatTextView textView, Drawable background) { + if (background != null) { + textView.setVisibility(VISIBLE); + if (Build.VERSION.SDK_INT < 16) { + textView.setBackgroundDrawable(background); + } else { + textView.setBackground(background); + } + } + } + + + /** + * 左边点击事件 + * + * @param baseTextView baseTextView + */ + private void setDefaultLeftViewClickListener(BaseTextView baseTextView) { + if (baseTextView != null) { + if (leftTopTvClickListener != null) { + baseTextView.getTopTextView().setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + leftTopTvClickListener.onClickListener(); + } + }); + } + + if (leftTvClickListener != null) { + baseTextView.getCenterTextView().setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + leftTvClickListener.onClickListener(); + } + }); + } + if (leftBottomTvClickListener != null) { + baseTextView.getBottomTextView().setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + leftBottomTvClickListener.onClickListener(); + } + }); + } + } + + } + + /** + * 中间点击事件 + * + * @param baseTextView baseTextView + */ + private void setDefaultCenterViewClickListener(BaseTextView baseTextView) { + if (baseTextView != null) { + if (centerTopTvClickListener != null) { + baseTextView.getTopTextView().setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + centerTopTvClickListener.onClickListener(); + } + }); + } + + if (centerTvClickListener != null) { + baseTextView.getCenterTextView().setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + centerTvClickListener.onClickListener(); + } + }); + } + if (centerBottomTvClickListener != null) { + baseTextView.getBottomTextView().setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + centerBottomTvClickListener.onClickListener(); + } + }); + } + } + + } + + + /** + * 右边点击事件 + * + * @param baseTextView baseTextView + */ + private void setDefaultRightViewClickListener(BaseTextView baseTextView) { + if (baseTextView != null) { + if (rightTopTvClickListener != null) { + baseTextView.getTopTextView().setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + rightTopTvClickListener.onClickListener(); + } + }); + } + + if (rightTvClickListener != null) { + baseTextView.getCenterTextView().setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + rightTvClickListener.onClickListener(); + } + }); + } + if (rightBottomTvClickListener != null) { + baseTextView.getBottomTextView().setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + rightBottomTvClickListener.onClickListener(); + } + }); + } + } + + } + + + /** + * 字体是否加粗 + * + * @param baseTextView baseTextView + * @param topTextBold 上边字体加粗 + * @param centerTextBold 中间字体加粗 + * @param bottomTextBold 下边字体加粗 + */ + private void setDefaultTextIsBold(BaseTextView baseTextView, boolean topTextBold, boolean centerTextBold, boolean bottomTextBold) { + if (baseTextView != null) { + baseTextView.getTopTextView().getPaint().setFakeBoldText(topTextBold); + baseTextView.getCenterTextView().getPaint().setFakeBoldText(centerTextBold); + baseTextView.getBottomTextView().getPaint().setFakeBoldText(bottomTextBold); + } + } + + + /////////////////////////////////////默认属性设置----end///////////////////////////////// + + + /////////////////////////////////////对外暴露的方法---begin///////////////////////////////// + + /** + * 设置左上字符串 + * + * @param string 字符串 + * @return 方便链式调用 + */ + public SuperTextView setLeftTopString(CharSequence string) { + if (leftView != null) { + leftView.setTopTextString(string); + } + return this; + } + + /** + * 设置左中字符串 + * + * @param string 字符串 + * @return 方便链式调用 + */ + public SuperTextView setLeftString(CharSequence string) { + if (leftView != null) { + leftView.setCenterTextString(string); + } + return this; + } + + /** + * 设置左下字符串 + * + * @param string 字符串 + * @return 方便链式调用 + */ + public SuperTextView setLeftBottomString(CharSequence string) { + if (leftView != null) { + leftView.setBottomTextString(string); + } + return this; + } + + + /** + * 设置中上字符串 + * + * @param string 字符串 + * @return 方便链式调用 + */ + public SuperTextView setCenterTopString(CharSequence string) { + if (centerView != null) { + centerView.setTopTextString(string); + } + return this; + } + + /** + * 设置中间字符串 + * + * @param string 字符串 + * @return 方便链式调用 + */ + public SuperTextView setCenterString(CharSequence string) { + if (centerView != null) { + centerView.setCenterTextString(string); + } + return this; + } + + /** + * 设置中下字符串 + * + * @param string 字符串 + * @return 方便链式调用 + */ + public SuperTextView setCenterBottomString(CharSequence string) { + if (centerView != null) { + centerView.setBottomTextString(string); + } + return this; + } + + /** + * 设置右上字符串 + * + * @param string 字符串 + * @return 方便链式调用 + */ + public SuperTextView setRightTopString(CharSequence string) { + if (rightView != null) { + rightView.setTopTextString(string); + } + return this; + } + + /** + * 设置右中字符串 + * + * @param string 字符串 + * @return 方便链式调用 + */ + public SuperTextView setRightString(CharSequence string) { + if (rightView != null) { + rightView.setCenterTextString(string); + } + return this; + } + + /** + * 设置右下字符串 + * + * @param string 字符串 + * @return 方便链式调用 + */ + public SuperTextView setRightBottomString(CharSequence string) { + if (rightView != null) { + rightView.setBottomTextString(string); + } + return this; + } + + /** + * 设置左上文字颜色 + * + * @param color 颜色值 + * @return SuperTextView + */ + public SuperTextView setLeftTopTextColor(int color) { + ColorStateList colorStateList = ColorStateList.valueOf(color); + setLeftTopTextColor(colorStateList); + return this; + } + + /** + * 设置左上文字颜色 + * + * @param color 颜色值 + * @return SuperTextView + */ + public SuperTextView setLeftTopTextColor(ColorStateList color) { + if (leftView != null) { + if (color == null) { + throw new NullPointerException(); + } + leftView.getTopTextView().setTextColor(color); + } + return this; + } + + /** + * 设置左中文字颜色 + * + * @param color 颜色值 + * @return SuperTextView + */ + public SuperTextView setLeftTextColor(int color) { + ColorStateList colorStateList = ColorStateList.valueOf(color); + setLeftTextColor(colorStateList); + return this; + } + + /** + * 设置左中文字颜色 + * + * @param color 颜色值 + * @return SuperTextView + */ + public SuperTextView setLeftTextColor(ColorStateList color) { + if (leftView != null) { + if (color == null) { + throw new NullPointerException(); + } + leftView.getCenterTextView().setTextColor(color); + } + return this; + } + + + /** + * 设置左下文字颜色 + * + * @param color 颜色值 + * @return SuperTextView + */ + public SuperTextView setLeftBottomTextColor(int color) { + ColorStateList colorStateList = ColorStateList.valueOf(color); + setLeftBottomTextColor(colorStateList); + return this; + } + + /** + * 设置左下文字颜色 + * + * @param color 颜色值 + * @return SuperTextView + */ + public SuperTextView setLeftBottomTextColor(ColorStateList color) { + if (leftView != null) { + if (color == null) { + throw new NullPointerException(); + } + leftView.getBottomTextView().setTextColor(color); + } + return this; + } + + /** + * 设置中上文字颜色 + * + * @param color 颜色值 + * @return SuperTextView + */ + public SuperTextView setCenterTopTextColor(int color) { + ColorStateList colorStateList = ColorStateList.valueOf(color); + setCenterTopTextColor(colorStateList); + return this; + } + + /** + * 设置中上文字颜色 + * + * @param color 颜色值 + * @return SuperTextView + */ + public SuperTextView setCenterTopTextColor(ColorStateList color) { + if (centerView != null) { + if (color == null) { + throw new NullPointerException(); + } + centerView.getTopTextView().setTextColor(color); + } + return this; + } + + /** + * 设置中间文字颜色 + * + * @param color 颜色值 + * @return SuperTextView + */ + public SuperTextView setCenterTextColor(int color) { + ColorStateList colorStateList = ColorStateList.valueOf(color); + setCenterTextColor(colorStateList); + return this; + } + + /** + * 设置中间文字颜色 + * + * @param color 颜色值 + * @return SuperTextView + */ + public SuperTextView setCenterTextColor(ColorStateList color) { + if (centerView != null) { + if (color == null) { + throw new NullPointerException(); + } + centerView.getCenterTextView().setTextColor(color); + } + return this; + } + + /** + * 设置中下文字颜色 + * + * @param color 颜色值 + * @return SuperTextView + */ + public SuperTextView setCenterBottomTextColor(int color) { + ColorStateList colorStateList = ColorStateList.valueOf(color); + setCenterBottomTextColor(colorStateList); + return this; + } + + /** + * 设置中下文字颜色 + * + * @param color 颜色值 + * @return SuperTextView + */ + public SuperTextView setCenterBottomTextColor(ColorStateList color) { + if (centerView != null) { + if (color == null) { + throw new NullPointerException(); + } + centerView.getBottomTextView().setTextColor(color); + } + return this; + } + + /** + * 设置右上文字颜色 + * + * @param color 颜色值 + * @return SuperTextView + */ + public SuperTextView setRightTopTextColor(int color) { + ColorStateList colorStateList = ColorStateList.valueOf(color); + setRightTopTextColor(colorStateList); + return this; + } + + /** + * 设置右上文字颜色 + * + * @param color 颜色值 + * @return SuperTextView + */ + public SuperTextView setRightTopTextColor(ColorStateList color) { + if (rightView != null) { + if (color == null) { + throw new NullPointerException(); + } + rightView.getTopTextView().setTextColor(color); + } + return this; + } + + /** + * 设置右中文字颜色 + * + * @param color 颜色值 + * @return SuperTextView + */ + public SuperTextView setRightTextColor(int color) { + ColorStateList colorStateList = ColorStateList.valueOf(color); + setRightTextColor(colorStateList); + return this; + } + + /** + * 设置右中文字颜色 + * + * @param color 颜色值 + * @return SuperTextView + */ + public SuperTextView setRightTextColor(ColorStateList color) { + if (rightView != null) { + if (color == null) { + throw new NullPointerException(); + } + rightView.getCenterTextView().setTextColor(color); + } + return this; + } + + /** + * 设置右下文字颜色 + * + * @param color 颜色值 + * @return SuperTextView + */ + public SuperTextView setRightBottomTextColor(int color) { + ColorStateList colorStateList = ColorStateList.valueOf(color); + setRightBottomTextColor(colorStateList); + return this; + } + + /** + * 设置右下文字颜色 + * + * @param color 颜色值 + * @return SuperTextView + */ + public SuperTextView setRightBottomTextColor(ColorStateList color) { + if (rightView != null) { + if (color == null) { + throw new NullPointerException(); + } + rightView.getBottomTextView().setTextColor(color); + } + return this; + } + + /** + * 设置左上文字字体为粗体 + * + * @return SuperTextView + */ + public SuperTextView setLeftTopTextIsBold(boolean isBold) { + if (leftView != null) { + leftView.setFakeBoldText(leftView.getTopTextView(), isBold); } - setMargin(rightImgParams, 0, 0, rightIconMarginRight, 0); - rightIconIV.setScaleType(ImageView.ScaleType.FIT_CENTER); - rightIconIV.setId(R.id.sRightIconId); - rightIconIV.setLayoutParams(rightImgParams); - if (rightIconRes != null) { - rightIconIV.setImageDrawable(rightIconRes); + return this; + } + + /** + * 设置左中文字字体为粗体 + * + * @return SuperTextView + */ + public SuperTextView setLeftTextIsBold(boolean isBold) { + if (leftView != null) { + leftView.setFakeBoldText(leftView.getCenterTextView(), isBold); } - addView(rightIconIV); + return this; + } + + /** + * 设置左下文字字体为粗体 + * + * @return SuperTextView + */ + public SuperTextView setLeftBottomTextIsBold(boolean isBold) { + if (leftView != null) { + leftView.setFakeBoldText(leftView.getBottomTextView(), isBold); + } + return this; + } + + /** + * 设置中上文字字体为粗体 + * + * @return SuperTextView + */ + public SuperTextView setCenterTopTextIsBold(boolean isBold) { + if (centerView != null) { + centerView.setFakeBoldText(centerView.getTopTextView(), isBold); + } + return this; + } + + /** + * 设置中中文字字体为粗体 + * + * @return SuperTextView + */ + public SuperTextView setCenterTextIsBold(boolean isBold) { + if (centerView != null) { + centerView.setFakeBoldText(centerView.getCenterTextView(), isBold); + } + return this; + } + + /** + * 设置中下文字字体为粗体 + * + * @return SuperTextView + */ + public SuperTextView setCenterBottomTextIsBold(boolean isBold) { + if (centerView != null) { + centerView.setFakeBoldText(centerView.getBottomTextView(), isBold); + } + return this; + } + + /** + * 设置右上文字字体为粗体 + * + * @return SuperTextView + */ + public SuperTextView setRightTopTextIsBold(boolean isBold) { + if (rightView != null) { + rightView.setFakeBoldText(rightView.getTopTextView(), isBold); + } + return this; + } + + /** + * 设置右中文字字体为粗体 + * + * @return SuperTextView + */ + public SuperTextView setRightTextIsBold(boolean isBold) { + if (rightView != null) { + rightView.setFakeBoldText(rightView.getCenterTextView(), isBold); + } + return this; + } + + /** + * 设置右下文字字体为粗体 + * + * @return SuperTextView + */ + public SuperTextView setRightBottomTextIsBold(boolean isBold) { + if (rightView != null) { + rightView.setFakeBoldText(rightView.getBottomTextView(), isBold); + } + return this; + } + + /** + * 获取左上字符串 + * + * @return 返回字符串 + */ + public String getLeftTopString() { + return leftView != null ? leftView.getTopTextView().getText().toString().trim() : ""; + } + + /** + * 获取左中字符串 + * + * @return 返回字符串 + */ + public String getLeftString() { + return leftView != null ? leftView.getCenterTextView().getText().toString().trim() : ""; + } + + /** + * 获取左下字符串 + * + * @return 返回字符串 + */ + public String getLeftBottomString() { + return leftView != null ? leftView.getBottomTextView().getText().toString().trim() : ""; + } + + //////////////////////////////////////////// + + /** + * 获取中上字符串 + * + * @return 返回字符串 + */ + public String getCenterTopString() { + return centerView != null ? centerView.getTopTextView().getText().toString().trim() : ""; + } + + /** + * 获取中间字符串 + * + * @return 返回字符串 + */ + + public String getCenterString() { + return centerView != null ? centerView.getCenterTextView().getText().toString().trim() : ""; + } + + /** + * 获取中下字符串 + * + * @return 返回字符串 + */ + public String getCenterBottomString() { + return centerView != null ? centerView.getBottomTextView().getText().toString().trim() : ""; + } + + /** + * 获取右上字符串 + * + * @return 返回字符串 + */ + public String getRightTopString() { + return rightView != null ? rightView.getTopTextView().getText().toString().trim() : ""; + } + + /** + * 获取右中字符串 + * + * @return 返回字符串 + */ + public String getRightString() { + return rightView != null ? rightView.getCenterTextView().getText().toString().trim() : ""; + } + + /** + * 获取右下字符串 + * + * @return 返回字符串 + */ + public String getRightBottomString() { + return rightView != null ? rightView.getBottomTextView().getText().toString().trim() : ""; + } + + /** + * 获取左边ImageView + * + * @return ImageView + */ + public ImageView getLeftIconIV() { + leftImgParams.setMargins(leftIconMarginLeft, 0, 0, 0); + return leftIconIV; + } + + /** + * 获取右边ImageView + * + * @return ImageView + */ + public ImageView getRightIconIV() { + rightImgParams.setMargins(0, 0, rightIconMarginRight, 0); + return rightIconIV; + } + + + /** + * 获取rightCheckBox + * + * @return rightCheckBox + */ + public CheckBox getCheckBox() { + return rightCheckBox; + } + + /** + * @param checked 是否选中 + * @return 返回值 + */ + public SuperTextView setCbChecked(boolean checked) { + isChecked = checked; + if (rightCheckBox != null) { + rightCheckBox.setChecked(checked); + } + return this; + } + + /** + * @param clickable 是否允许点击 + * @return 返回值 + */ + public SuperTextView setCbClickable(boolean clickable) { + if (rightCheckBox != null) { + rightCheckBox.setClickable(clickable); + } + return this; + } + + + /** + * 设置checkbox的背景图 + * + * @param drawable drawable对象 + * @return 返回对象 + */ + public SuperTextView setCbBackground(Drawable drawable) { + rightCheckBoxBg = drawable; + if (rightCheckBox != null) { + rightCheckBox.setBackgroundDrawable(drawable); + } + return this; + } + + /** + * 获取checkbox状态 + * + * @return 返回选择框当前选中状态 + */ + public boolean getCbisChecked() { + boolean isChecked = false; + if (rightCheckBox != null) { + isChecked = rightCheckBox.isChecked(); + } + return isChecked; + } + + /** + * @param checked Switch是否选中 + * @return 返回值 + */ + public SuperTextView setSwitchIsChecked(boolean checked) { + switchIsChecked = checked; + if (mSwitch != null) { + mSwitch.setChecked(checked); + } + return this; + } + + /** + * @param clickable Switch是否允许点击 + * @return 返回值 + */ + public SuperTextView setSwitchClickable(boolean clickable) { + if (mSwitch != null) { + mSwitch.setClickable(clickable); + } + return this; + } + + /** + * 获取switch状态 + * + * @return 返回switch当前选中状态 + */ + public boolean getSwitchIsChecked() { + boolean isChecked = false; + if (mSwitch != null) { + isChecked = mSwitch.isChecked(); + } + return isChecked; + } + + /** + * 获取switchView + * + * @return Switch + */ + public SwitchCompat getSwitch() { + return mSwitch; + } + + /** + * 获取Edittext View + * + * @return AppCompatEditText + */ + public AppCompatEditText getEditText(){ + return mEditText; + } + + public SuperTextView setEditImeOptions(int option){ + if (mEditText != null) { + mEditText.setImeOptions(option); + } + return this; + } + + public SuperTextView setEditInputType(int inputType){ + if (mEditText != null) { + mEditText.setInputType(inputType); + } + return this; + } + + public SuperTextView setEditHintText(String hintText){ + if (mEditText != null) { + mEditText.setHint(hintText); + } + return this; + } + + + public SuperTextView setEditHintTextColor(int color){ + if (mEditText != null) { + setEditHintTextColor(ColorStateList.valueOf(color)); + } + return this; + } + + public SuperTextView setEditHintTextColor(ColorStateList color){ + if (mEditText != null) { + if (color == null) { + throw new NullPointerException(); + } + mEditText.setHintTextColor(color); + } + return this; + } + + + public SuperTextView setEditTextColor(int color){ + if (mEditText != null) { + setEditTextColor(ColorStateList.valueOf(color)); + } + return this; + } + + public SuperTextView setEditTextColor(ColorStateList color){ + if (mEditText != null) { + if (color == null) { + throw new NullPointerException(); + } + mEditText.setTextColor(color); + } + return this; + } + + public SuperTextView setEditCursorVisible(boolean visible){ + if (mEditText != null) { + mEditText.setCursorVisible(visible); + } + return this; + } + + + public SuperTextView setEditCursorDrawableRes(@DrawableRes int drawableRes){ + if (mEditText != null) { + EditTextHelper.INSTANCE.setCursorDrawable(mEditText,drawableRes); + } + return this; + } + + + /** + * 设置左边tv的左侧图片 + * + * @param drawableLeft 左边图片资源 + */ + public SuperTextView setLeftTvDrawableLeft(Drawable drawableLeft) { + setDefaultDrawable(leftView.getCenterTextView(), drawableLeft, null, mTextViewDrawablePadding, mLeftTvDrawableWidth, mLeftTvDrawableHeight); + return this; } /** - * 初始化右边选择框 + * 设置左边tv的右侧图片 + * + * @param drawableRight 右边图片资源 */ - private void initRightCheckBox() { - rightCheckBox = new CheckBox(mContext); + public SuperTextView setLeftTvDrawableRight(Drawable drawableRight) { + setDefaultDrawable(leftView.getCenterTextView(), null, drawableRight, mTextViewDrawablePadding, mLeftTvDrawableWidth, mLeftTvDrawableHeight); + return this; + } - rightCheckBoxParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - rightCheckBoxParams.addRule(ALIGN_PARENT_RIGHT, TRUE); - rightCheckBoxParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE); - setMargin(rightCheckBoxParams, 0, 0, rightCheckBoxMarginRight, 0); - rightCheckBox.setLayoutParams(rightCheckBoxParams); - if (rightCheckBoxBg != null) { - rightCheckBox.setGravity(CENTER_IN_PARENT); - rightCheckBox.setButtonDrawable(rightCheckBoxBg); - } - rightCheckBox.setChecked(isChecked); - addView(rightCheckBox); + /** + * 设置中间tv的左侧图片 + * + * @param drawableLeft 左边图片资源 + */ + public SuperTextView setCenterTvDrawableLeft(Drawable drawableLeft) { + setDefaultDrawable(centerView.getCenterTextView(), drawableLeft, null, mTextViewDrawablePadding, mCenterTvDrawableWidth, mCenterTvDrawableHeight); + return this; } - private void setMargin(LayoutParams params, int left, int top, int right, int bottom) { - params.setMargins(left, top, right, bottom); - } /** - * 设置view的边距 + * 设置中间tv的右侧图片 * - * @param view view对象 - * @param left 左边边距 - * @param top 上边边距 - * @param right 右边边距 - * @param bottom 下边边距 + * @param drawableRight 右边图片资源 */ - private void setPadding(View view, int left, int top, int right, int bottom) { - view.setPadding(left, top, right, bottom); + public SuperTextView setCenterTvDrawableRight(Drawable drawableRight) { + setDefaultDrawable(centerView.getCenterTextView(), null, drawableRight, mTextViewDrawablePadding, mCenterTvDrawableWidth, mCenterTvDrawableHeight); + return this; } + /** - * 设置文字的字体大小 + * 设置右边tv的左侧图片 * - * @param textView textView对象 - * @param size 文字大小 + * @param drawableLeft 左边图片资源 */ - private void setTextSize(TextView textView, int size) { - textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); + public SuperTextView setRightTvDrawableLeft(Drawable drawableLeft) { + setDefaultDrawable(rightView.getCenterTextView(), drawableLeft, null, mTextViewDrawablePadding, mRightTvDrawableWidth, mRightTvDrawableHeight); + return this; } /** - * 设置文字的颜色 + * 设置右边tv的右侧图片 * - * @param textView textView对象 - * @param color 文字颜色 + * @param drawableRight 右边图片资源 */ - private void setTextColor(TextView textView, int color) { - textView.setTextColor(color); + public SuperTextView setRightTvDrawableRight(Drawable drawableRight) { + setDefaultDrawable(rightView.getCenterTextView(), null, drawableRight, mTextViewDrawablePadding, mRightTvDrawableWidth, mRightTvDrawableHeight); + return this; } - //////////对外公布的方法/////////////// - /** * 设置左边图标 * @@ -668,15 +2243,27 @@ private void setTextColor(TextView textView, int color) { * @return 返回对象 */ public SuperTextView setLeftIcon(Drawable leftIcon) { - leftIconRes = leftIcon; - if (leftIconIV == null) { - initLeftIcon(); - } else { + if (leftIconIV != null) { + leftImgParams.setMargins(leftIconMarginLeft, 0, 0, 0); leftIconIV.setImageDrawable(leftIcon); } return this; } + /** + * 设置左边图标 + * + * @param resId 左边图标资源id + * @return 返回对象 + */ + public SuperTextView setLeftIcon(int resId) { + if (leftIconIV != null) { + leftImgParams.setMargins(leftIconMarginLeft, 0, 0, 0); + leftIconIV.setImageResource(resId); + } + return this; + } + /** * 设置右边图标 * @@ -684,461 +2271,483 @@ public SuperTextView setLeftIcon(Drawable leftIcon) { * @return 返回对象 */ public SuperTextView setRightIcon(Drawable rightIcon) { - rightIconRes = rightIcon; - if (rightIconIV == null) { - initRightIcon(); - } else { + if (rightIconIV != null) { + rightImgParams.setMargins(0, 0, rightIconMarginRight, 0); rightIconIV.setImageDrawable(rightIcon); } return this; } /** - * 设置左边显示文字 + * 设置右边图标资源Id * - * @param leftString 左边文字 + * @param resId 右边图标 * @return 返回对象 */ - public SuperTextView setLeftString(String leftString) { - leftTextString = leftString; - if (leftTV == null) { - initLeftText(); - } else { - leftTV.setText(leftString); + public SuperTextView setRightIcon(int resId) { + if (rightIconIV != null) { + rightImgParams.setMargins(0, 0, rightIconMarginRight, 0); + rightIconIV.setImageResource(resId); } return this; } /** - * 设置左上显示的文字 + * 设置背景 * - * @param leftTopString 左上文字 - * @return 返回对象 + * @param drawable 背景资源 + * @return 对象 */ - public SuperTextView setLeftTopString(String leftTopString) { - leftTopTextString = leftTopString; - if (leftTopTV == null) { - initLeftTopText(); - } else { - leftTopTV.setText(leftTopString); + public SuperTextView setSBackground(Drawable drawable) { + if (drawable != null) { + this.setBackgroundDrawable(drawable); } return this; } /** - * 设置左下显示的文字 + * 获取左上的TextView * - * @param leftBottomString 左下第一个文字 - * @return 返回对象 + * @return textView */ - public SuperTextView setLeftBottomString(String leftBottomString) { - leftBottomTextString = leftBottomString; - if (leftBottomTV == null) { - initLeftBottomText(); - } else { - leftBottomTV.setText(leftBottomString); + public AppCompatTextView getLeftTopTextView() { + if (leftView == null) { + initLeftTextView(); } - return this; + return leftView.getTopTextView(); } /** - * 设置左下第二个显示的文字 + * 获取左中的TextView * - * @param leftBottomString2 左下第二个文字 - * @return 返回对象 + * @return textView */ - public SuperTextView setLeftBottomString2(String leftBottomString2) { - leftBottomTextString2 = leftBottomString2; - if (leftBottomTV2 == null) { - initLeftBottomText2(); - } else { - leftBottomTV2.setText(leftBottomString2); + public AppCompatTextView getLeftTextView() { + if (leftView == null) { + initLeftTextView(); } - return this; + return leftView.getCenterTextView(); } /** - * 设置右边显示的文字 + * 获取左下的TextView * - * @param rightString 右边文字 - * @return 返回对象 + * @return textView */ - public SuperTextView setRightString(String rightString) { - rightTextString = rightString; - if (rightTV == null) { - initRightText(); - } else { - rightTV.setText(rightString); + public AppCompatTextView getLeftBottomTextView() { + if (leftView == null) { + initLeftTextView(); } - return this; + return leftView.getBottomTextView(); } /** - * 设置右边显示的文字和图片 + * 获取中上的TextView * - * @param rightString 右边文字 - * @param drawable drawable - * @param drawablePadding drawablePadding - * @return + * @return textView */ - public SuperTextView setRightString(String rightString, Drawable drawable, int drawablePadding) { - rightTextString = rightString; - rightTextStringRightIconRes = drawable; - rightTextStringRightIconPadding = drawablePadding; - if (rightTV == null) { - initRightText(); - } else { - rightTV.setText(rightString); + public AppCompatTextView getCenterTopTextView() { + if (centerView == null) { + initCenterTextView(); } - return this; + return centerView.getTopTextView(); } - /** - * 设备中间文字 + * 获取中中的TextView * - * @param centerString 中间文字 - * @return 返回对象 + * @return textView */ - public SuperTextView setCenterString(String centerString) { - centerTextString = centerString; - if (centerTV == null) { - initCenterText(); - } else { - centerTV.setText(centerString); + public AppCompatTextView getCenterTextView() { + if (centerView == null) { + initCenterTextView(); } - return this; + return centerView.getCenterTextView(); } /** - * @param checked 是否选中 - * @return 返回值 + * 获取中下的TextView + * + * @return textView */ - public SuperTextView setCbChecked(boolean checked) { - isChecked = checked; - if (rightCheckBox == null) { - initRightCheckBox(); - } else { - rightCheckBox.setChecked(checked); + public AppCompatTextView getCenterBottomTextView() { + if (centerView == null) { + initCenterTextView(); } - return this; + return centerView.getBottomTextView(); } /** - * 设置checkbox的背景图 + * 获取右上的TextView * - * @param drawable drawable对象 - * @return 返回对象 + * @return textView */ - public SuperTextView setCbBackground(Drawable drawable) { - rightCheckBoxBg = drawable; - if (rightCheckBox == null) { - initRightCheckBox(); - } else { - rightCheckBox.setBackgroundDrawable(drawable); + public AppCompatTextView getRightTopTextView() { + if (rightView == null) { + initRightTextView(); } - return this; + return rightView.getTopTextView(); } /** - * 获取checkbox状态 + * 获取右中的TextView * - * @return 返回选择框当前选中状态 + * @return textView */ - public boolean getCbisChecked() { - boolean isChecked = false; - if (rightCheckBox != null) { - isChecked = rightCheckBox.isChecked(); + public AppCompatTextView getRightTextView() { + if (rightView == null) { + initRightTextView(); } - return isChecked; + return rightView.getCenterTextView(); } /** - * 设置左边文字的颜色 + * 获取右下的TextView * - * @param textColor 文字颜色值 - * @return 返回对象 + * @return textView */ - public SuperTextView setLeftTVColor(int textColor) { - leftTVColor = textColor; - if (leftTV == null) { - initLeftText(); - } else { - leftTV.setTextColor(textColor); + public AppCompatTextView getRightBottomTextView() { + if (rightView == null) { + initRightTextView(); } - return this; + return rightView.getBottomTextView(); } /** - * 设置右边文字的颜色 + * 设置左边textView文字对齐方式 * - * @param textColor 文字颜色值 - * @return 返回对象 + * @param gravity 对齐方式 + * @return SuperTextView */ - public SuperTextView setRightTVColor(int textColor) { - rightTVColor = textColor; - if (rightTV == null) { - initRightText(); - } else { - rightTV.setTextColor(textColor); - } + public SuperTextView setLeftTextGravity(int gravity) { + setTextGravity(leftView, gravity); return this; } /** - * 设置左上边文字的颜色 + * 设置中间textView文字对齐方式 * - * @param textColor 文字颜色值 - * @return 返回对象 + * @param gravity 对齐方式 + * @return SuperTextView */ - public SuperTextView setLeftTopTVColor(int textColor) { - leftTopTVColor = textColor; - if (leftTopTV == null) { - initLeftTopText(); - } else { - leftTopTV.setTextColor(textColor); - } + public SuperTextView setCenterTextGravity(int gravity) { + setTextGravity(centerView, gravity); return this; } /** - * 设置左下边文字的颜色 + * 设置右边textView文字对齐方式 * - * @param textColor 文字颜色值 - * @return 返回对象 + * @param gravity 对齐方式 + * @return SuperTextView */ - public SuperTextView setLeftBottomTVColor(int textColor) { - leftBottomTVColor = textColor; - if (leftBottomTV == null) { - initLeftBottomText(); - } else { - leftBottomTV.setTextColor(textColor); - } + public SuperTextView setRightTextGravity(int gravity) { + setTextGravity(rightView, gravity); return this; } /** - * 设置左下第二个文字的颜色 + * 文字对齐方式 * - * @param textColor 文字颜色值 - * @return 返回对象 + * @param baseTextView view + * @param gravity 对齐方式 */ - public SuperTextView setLeftBottomTVColor2(int textColor) { - leftBottomTVColor2 = textColor; - if (leftBottomTV2 == null) { - initLeftBottomText2(); - } else { - leftBottomTV2.setTextColor(textColor); + private void setTextGravity(BaseTextView baseTextView, int gravity) { + if (baseTextView != null) { + baseTextView.getTopTextView().setGravity(gravity); + baseTextView.getCenterTextView().setGravity(gravity); + baseTextView.getBottomTextView().setGravity(gravity); } - return this; } - //////////设置View的点击事件///////////////// - /** - * 点击事件 + * 代码动态设置分割线显示类型 * - * @param listener listener对象 - * @return 返回对象 + * @param dividerType TOP、BOTTOM、BOTH、NONE + * @return this */ - public SuperTextView setOnSuperTextViewClickListener(OnSuperTextViewClickListener listener) { - onSuperTextViewClickListener = listener; + public SuperTextView setDividerLineType(int dividerType) { + mDividerLineType = dividerType; + invalidate(); + return this; + } + + public SuperTextView setTopDividerLineColor(int lineColor) { + mTopDividerPaint.setColor(lineColor); + invalidate(); + return this; + } + + public SuperTextView setBottomDividerLineColor(int lineColor) { + mBottomDividerPaint.setColor(lineColor); + invalidate(); return this; } + /////////////////////////////////////对外暴露的方法---end///////////////////////////////// + /** - * 点击事件接口 + * 点击事件 + * + * @param onSuperTextViewClickListener ClickListener + * @return SuperTextView */ - public static class OnSuperTextViewClickListener { - public void onSuperTextViewClick() { + public SuperTextView setOnSuperTextViewClickListener(OnSuperTextViewClickListener onSuperTextViewClickListener) { + this.superTextViewClickListener = onSuperTextViewClickListener; + if (superTextViewClickListener != null) { + this.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + superTextViewClickListener.onClickListener(SuperTextView.this); + } + }); } + return this; + } - public void onLeftTopClick() { - } + public SuperTextView setLeftTopTvClickListener(OnLeftTopTvClickListener leftTopTvClickListener) { + this.leftTopTvClickListener = leftTopTvClickListener; + setDefaultLeftViewClickListener(leftView); + return this; + } - public void onLeftBottomClick() { - } + public SuperTextView setLeftTvClickListener(OnLeftTvClickListener leftTvClickListener) { + this.leftTvClickListener = leftTvClickListener; + setDefaultLeftViewClickListener(leftView); + return this; + } - public void onLeftBottomClick2() { - } + public SuperTextView setLeftBottomTvClickListener(OnLeftBottomTvClickListener leftBottomTvClickListener) { + this.leftBottomTvClickListener = leftBottomTvClickListener; + setDefaultLeftViewClickListener(leftView); + return this; + } + public SuperTextView setCenterTopTvClickListener(OnCenterTopTvClickListener centerTopTvClickListener) { + this.centerTopTvClickListener = centerTopTvClickListener; + setDefaultCenterViewClickListener(centerView); + return this; } - /** - * 获取控件ID便于根据ID设置值 - * - * @param viewName 需要的textViewName - * @return 返回ID - */ - public int getViewId(int viewName) { - int viewId = 0; - switch (viewName) { - case leftTextViewId: - if (leftTV == null) { - initLeftText(); - } - viewId = R.id.sLeftTextId; - break; - case leftTopTextViewId: - if (leftTopTV == null) { - initLeftTopText(); - } - viewId = R.id.sLeftTopTextId; - break; - case leftBottomTextViewId: - if (leftBottomTV == null) { - initLeftBottomText(); - } - viewId = R.id.sLeftBottomTextId; - break; - case leftBottomTextViewId2: - if (leftBottomTV2 == null) { - initLeftBottomText2(); - } - viewId = R.id.sLeftBottomTextId2; - break; - case centerTextViewId: - if (centerTV == null) { - initCenterText(); - } - viewId = R.id.sCenterTextId; - break; - case rightTextViewId: - if (rightTV == null) { - initRightText(); - } - viewId = R.id.sRightTextId; - break; - case leftImageViewId: - if (leftIconIV == null) { - initLeftIcon(); + public SuperTextView setCenterTvClickListener(OnCenterTvClickListener centerTvClickListener) { + this.centerTvClickListener = centerTvClickListener; + setDefaultCenterViewClickListener(centerView); + return this; + } + + public SuperTextView setCenterBottomTvClickListener(OnCenterBottomTvClickListener centerBottomTvClickListener) { + this.centerBottomTvClickListener = centerBottomTvClickListener; + setDefaultCenterViewClickListener(centerView); + return this; + } + + public SuperTextView setRightTopTvClickListener(OnRightTopTvClickListener rightTopTvClickListener) { + this.rightTopTvClickListener = rightTopTvClickListener; + setDefaultRightViewClickListener(rightView); + return this; + } + + public SuperTextView setRightTvClickListener(OnRightTvClickListener rightTvClickListener) { + this.rightTvClickListener = rightTvClickListener; + setDefaultRightViewClickListener(rightView); + return this; + } + + public SuperTextView setRightBottomTvClickListener(OnRightBottomTvClickListener rightBottomTvClickListener) { + this.rightBottomTvClickListener = rightBottomTvClickListener; + setDefaultRightViewClickListener(rightView); + return this; + } + + public SuperTextView setLeftImageViewClickListener(OnLeftImageViewClickListener listener) { + this.leftImageViewClickListener = listener; + + if (leftIconIV != null) { + leftIconIV.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + leftImageViewClickListener.onClickListener(leftIconIV); } - viewId = R.id.sLeftIconId; - break; - case rightImageViewId: - if (rightIconIV == null) { - initRightIcon(); + }); + } + return this; + } + + public SuperTextView setRightImageViewClickListener(final OnRightImageViewClickListener listener) { + this.rightImageViewClickListener = listener; + if (rightIconIV != null) { + rightIconIV.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + rightImageViewClickListener.onClickListener(rightIconIV); } - viewId = R.id.sRightIconId; - break; + }); } - return viewId; + return this; } - /** - * 获取view对象 - * - * @param viewName 传入viewName - * @return 返回view - */ - public View getView(int viewName) { - View view = null; - switch (viewName) { + public SuperTextView setSwitchCheckedChangeListener(OnSwitchCheckedChangeListener switchCheckedChangeListener) { + this.switchCheckedChangeListener = switchCheckedChangeListener; + return this; + } + + public SuperTextView setCheckBoxCheckedChangeListener(OnCheckBoxCheckedChangeListener checkBoxCheckedChangeListener) { + this.checkBoxCheckedChangeListener = checkBoxCheckedChangeListener; + return this; + } + + public SuperTextView setEditTextChangeListener(OnEditTextChangeListener editTextChangeListener) { + this.editTextChangeListener = editTextChangeListener; + return this; + } + + public SuperTextView setLeftTextGroupClickListener(final OnLeftTextGroupClickListener leftTextGroupClickListener) { + if (leftTextGroupClickListener != null) { + leftView.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + leftTextGroupClickListener.onClickListener(v); + } + }); + } + return this; + } - case leftImageViewId: - if (leftIconIV == null) { - initLeftIcon(); + public SuperTextView setCenterTextGroupClickListener(final OnCenterTextGroupClickListener centerTextGroupClickListener) { + if (centerTextGroupClickListener != null) { + centerView.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + centerTextGroupClickListener.onClickListener(v); } - view = leftIconIV; - break; - case rightImageViewId: - if (rightIconIV == null) { - initRightIcon(); + }); + } + return this; + } + + public SuperTextView setRightTextGroupClickListener(final OnRightTextGroupClickListener rightTextGroupClickListener) { + if (rightTextGroupClickListener != null) { + rightView.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + rightTextGroupClickListener.onClickListener(v); } - view = rightIconIV; - break; + }); } - return view; + return this; } + //////////////////////////////////////////////////////////////////////////////////// + public interface OnSuperTextViewClickListener { + void onClickListener(SuperTextView superTextView); + } - public int dip2px(Context context, float dipValue) { - final float scale = context.getResources().getDisplayMetrics().density; - return (int) (dipValue * scale + 0.5f); + public interface OnLeftTopTvClickListener { + void onClickListener(); } - public int px2dip(Context context, float pxValue) { - final float scale = context.getResources().getDisplayMetrics().density; - return (int) (pxValue / scale + 0.5f); + public interface OnLeftTvClickListener { + void onClickListener(); } - public int sp2px(Context context, float spValue) { - final float scale = context.getResources().getDisplayMetrics().scaledDensity; - return (int) (spValue * scale + 0.5f); + public interface OnLeftBottomTvClickListener { + void onClickListener(); } - public static void setTextViewRightDrawble(TextView textView, Drawable drawable, int drawablePadding) { - if (drawable != null && textView != null) { - drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); - textView.setCompoundDrawables(null, null, drawable, null); - textView.setCompoundDrawablePadding(drawablePadding); - } + public interface OnCenterTopTvClickListener { + void onClickListener(); + } + + public interface OnCenterTvClickListener { + void onClickListener(); + } + + public interface OnCenterBottomTvClickListener { + void onClickListener(); + } + + public interface OnRightTopTvClickListener { + void onClickListener(); + } + + public interface OnRightTvClickListener { + void onClickListener(); + } + + public interface OnRightBottomTvClickListener { + void onClickListener(); + } + + public interface OnLeftImageViewClickListener { + void onClickListener(ImageView imageView); + } + + public interface OnRightImageViewClickListener { + void onClickListener(ImageView imageView); + } + + public interface OnSwitchCheckedChangeListener { + void onCheckedChanged(CompoundButton buttonView, boolean isChecked); + } + + public interface OnCheckBoxCheckedChangeListener { + void onCheckedChanged(CompoundButton buttonView, boolean isChecked); + } + + public interface OnEditTextChangeListener{ + + void beforeTextChanged(CharSequence s, int start, int count, int after); + + void onTextChanged(CharSequence s, int start, int before, int count); + + void afterTextChanged(Editable s); + } + + public interface OnLeftTextGroupClickListener { + void onClickListener(View view); + } + + public interface OnCenterTextGroupClickListener { + void onClickListener(View view); + } + + public interface OnRightTextGroupClickListener { + void onClickListener(View view); } + + // TODO: 2019/6/4 以下是获取shapeBuilder进行相关shape属性的配置 + /** - * 设置左上view可点击 + * 获取shapeBuilder进行配置 * - * @param isClickable boolean类型 - * @return 返回 + * @return ShapeBuilder */ - public SuperTextView setLeftTopViewIsClickable(boolean isClickable) { - if (isClickable) { - if (leftTopTV != null) { - leftTopTV.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - if (onSuperTextViewClickListener != null) { - onSuperTextViewClickListener.onLeftTopClick(); - } - } - }); - } - } - - return this; + public ShapeBuilder getShapeBuilder() { + return shapeBuilder; } /** - * 设置左下第一个view可点击 + * 单位转换工具类 * - * @param isClickable boolean类型 - * @return 返回 + * @param context 上下文对象 + * @param spValue 值 + * @return 返回值 */ - public SuperTextView setLeftBottomViewIsClickable(boolean isClickable) { - if (isClickable) { - if (leftBottomTV != null) { - leftBottomTV.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - if (onSuperTextViewClickListener != null) { - onSuperTextViewClickListener.onLeftBottomClick(); - } - } - }); - } - } - return this; + private int sp2px(Context context, float spValue) { + final float scale = context.getResources().getDisplayMetrics().scaledDensity; + return (int) (spValue * scale + 0.5f); } /** - * 设置左下第二个view可点击 + * 单位转换工具类 * - * @param isClickable boolean类型 - * @return 返回 + * @param context 上下文对象 + * @param dipValue 值 + * @return 返回值 */ - public SuperTextView setLeftBottomView2IsClickable(boolean isClickable) { - if (isClickable) { - if (leftBottomTV2 != null) { - leftBottomTV2.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - if (onSuperTextViewClickListener != null) { - onSuperTextViewClickListener.onLeftBottomClick2(); - } - } - }); - } - } - return this; + private int dip2px(Context context, float dipValue) { + final float scale = context.getResources().getDisplayMetrics().density; + return (int) (dipValue * scale + 0.5f); } -} +} \ No newline at end of file diff --git a/library/src/main/java/com/allen/library/data/AttributeSetData.kt b/library/src/main/java/com/allen/library/data/AttributeSetData.kt new file mode 100644 index 0000000..21dbcbe --- /dev/null +++ b/library/src/main/java/com/allen/library/data/AttributeSetData.kt @@ -0,0 +1,61 @@ +package com.allen.library.data + +import android.graphics.Color + +/** + *
+ * @author : Allen + * e-mail : lygttpod@163.com + * date : 2019/09/22 + * desc : + *+ */ +class AttributeSetData { + var shapeType = -1 + var solidColor = -1 + + var strokeWidth = -1 + var strokeColor = -1 + var strokeDashWidth = 0.0f + var strokeDashGap = 0.0f + + var cornersRadius = 0.0f + var cornersTopLeftRadius = 0.0f + var cornersTopRightRadius = 0.0f + var cornersBottomLeftRadius = 0.0f + var cornersBottomRightRadius = 0.0f + + var gradientAngle = -1 + var gradientCenterX: Float = 0f + var gradientCenterY: Float = 0f + var gradientGradientRadius: Int = 0 + var gradientStartColor = -1 + var gradientCenterColor = -1 + var gradientEndColor = -1 + var gradientType: Int = 0 + var gradientUseLevel: Boolean = false + + var sizeWidth = -1 + var sizeHeight = -1 + + var selectorPressedColor: Int = 0 + var selectorDisableColor: Int = 0 + var selectorNormalColor: Int = 0 + + var useSelector: Boolean = false + + //////////阴影相关//////// + var showShadow: Boolean = false + var shadowColor: Int = Color.GRAY + var shadowColorAlpha: Float = 0.2f + var shadowLeftWidth: Float = 0f + var shadowTopWidth: Float = 0f + var shadowRightWidth: Float = 0f + var shadowBottomWidth: Float = 0f + + var shadowCornersRadius: Float = 0f + var shadowCornersTopLeftRadius: Float = 0f + var shadowCornersTopRightRadius: Float = 0f + var shadowCornersBottomLeftRadius: Float = 0f + var shadowCornersBottomRightRadius: Float = 0f +} \ No newline at end of file diff --git a/library/src/main/java/com/allen/library/helper/AttributeSetHelper.kt b/library/src/main/java/com/allen/library/helper/AttributeSetHelper.kt new file mode 100644 index 0000000..9130b90 --- /dev/null +++ b/library/src/main/java/com/allen/library/helper/AttributeSetHelper.kt @@ -0,0 +1,98 @@ +package com.allen.library.helper + +import android.content.Context +import android.graphics.Color +import android.graphics.drawable.GradientDrawable +import android.util.AttributeSet +import com.allen.library.R +import com.allen.library.data.AttributeSetData + +/** + *
+ * @author : Allen + * e-mail : lygttpod@163.com + * date : 2019/09/09 + * desc : + *+ */ +class AttributeSetHelper { + + private val defaultColor = 0xffffff + private val defaultSelectorColor = 0x20000000 + + fun loadFromAttributeSet(context: Context, attrs: AttributeSet?): AttributeSetData { + val attributeSetData = AttributeSetData() + + if (attrs == null) return attributeSetData + + val typedArray = context.obtainStyledAttributes(attrs, R.styleable.ShapeView) + + attributeSetData.shapeType = typedArray.getInt(R.styleable.ShapeView_shapeType, GradientDrawable.RECTANGLE) + + attributeSetData.solidColor = typedArray.getColor(R.styleable.ShapeView_shapeSolidColor, defaultColor) + + attributeSetData.selectorPressedColor = typedArray.getColor(R.styleable.ShapeView_shapeSelectorPressedColor, defaultSelectorColor) + attributeSetData.selectorDisableColor = typedArray.getColor(R.styleable.ShapeView_shapeSelectorDisableColor, defaultSelectorColor) + attributeSetData.selectorNormalColor = typedArray.getColor(R.styleable.ShapeView_shapeSelectorNormalColor, defaultSelectorColor) + + attributeSetData.cornersRadius = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shapeCornersRadius, 0).toFloat() + attributeSetData.cornersTopLeftRadius = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shapeCornersTopLeftRadius, 0).toFloat() + attributeSetData.cornersTopRightRadius = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shapeCornersTopRightRadius, 0).toFloat() + attributeSetData.cornersBottomLeftRadius = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shapeCornersBottomLeftRadius, 0).toFloat() + attributeSetData.cornersBottomRightRadius = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shapeCornersBottomRightRadius, 0).toFloat() + + attributeSetData.strokeWidth = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shapeStrokeWidth, 0) + attributeSetData.strokeDashWidth = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shapeStrokeDashWidth, 0).toFloat() + attributeSetData.strokeDashGap = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shapeStrokeDashGap, 0).toFloat() + + attributeSetData.strokeColor = typedArray.getColor(R.styleable.ShapeView_shapeStrokeColor, defaultColor) + + attributeSetData.sizeWidth = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shapeSizeWidth, 0) + attributeSetData.sizeHeight = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shapeSizeHeight, dip2px(context, 48f)) + + attributeSetData.gradientAngle = typedArray.getFloat(R.styleable.ShapeView_shapeGradientAngle, -1f).toInt() + attributeSetData.gradientCenterX = typedArray.getFloat(R.styleable.ShapeView_shapeGradientCenterX, 0f) + attributeSetData.gradientCenterY = typedArray.getFloat(R.styleable.ShapeView_shapeGradientCenterY, 0f) + attributeSetData.gradientGradientRadius = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shapeGradientGradientRadius, 0) + + attributeSetData.gradientStartColor = typedArray.getColor(R.styleable.ShapeView_shapeGradientStartColor, -1) + attributeSetData.gradientCenterColor = typedArray.getColor(R.styleable.ShapeView_shapeGradientCenterColor, -1) + attributeSetData.gradientEndColor = typedArray.getColor(R.styleable.ShapeView_shapeGradientEndColor, -1) + + attributeSetData.gradientType = typedArray.getInt(R.styleable.ShapeView_shapeGradientType, 0) + attributeSetData.gradientUseLevel = typedArray.getBoolean(R.styleable.ShapeView_shapeGradientUseLevel, false) + + attributeSetData.useSelector = typedArray.getBoolean(R.styleable.ShapeView_shapeUseSelector, false) + + + attributeSetData.showShadow = typedArray.getBoolean(R.styleable.ShapeView_showShadow, false) + attributeSetData.shadowColor = typedArray.getColor(R.styleable.ShapeView_shadowColor, Color.GRAY) + attributeSetData.shadowColorAlpha = typedArray.getFloat(R.styleable.ShapeView_shadowColorAlpha, 0.2f) + attributeSetData.shadowLeftWidth = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shadowLeftWidth, 0).toFloat() + attributeSetData.shadowTopWidth = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shadowTopWidth, 0).toFloat() + attributeSetData.shadowRightWidth = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shadowRightWidth, 0).toFloat() + attributeSetData.shadowBottomWidth = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shadowBottomWidth, 0).toFloat() + attributeSetData.shadowCornersRadius = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shadowCornersRadius, 0).toFloat() + attributeSetData.shadowCornersTopLeftRadius = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shadowCornersTopLeftRadius, 0).toFloat() + attributeSetData.shadowCornersTopRightRadius = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shadowCornersTopRightRadius, 0).toFloat() + attributeSetData.shadowCornersBottomLeftRadius = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shadowCornersBottomLeftRadius, 0).toFloat() + attributeSetData.shadowCornersBottomRightRadius = typedArray.getDimensionPixelSize(R.styleable.ShapeView_shadowCornersBottomRightRadius, 0).toFloat() + + typedArray.recycle() + + return attributeSetData + } + + + /** + * 单位转换工具类 + * + * @param context 上下文对象 + * @param dipValue 值 + * @return 返回值 + */ + private fun dip2px(context: Context, dipValue: Float): Int { + val scale = context.resources.displayMetrics.density + return (dipValue * scale + 0.5f).toInt() + } +} \ No newline at end of file diff --git a/library/src/main/java/com/allen/library/helper/EditTextHelper.kt b/library/src/main/java/com/allen/library/helper/EditTextHelper.kt new file mode 100644 index 0000000..9cb5c39 --- /dev/null +++ b/library/src/main/java/com/allen/library/helper/EditTextHelper.kt @@ -0,0 +1,32 @@ +package com.allen.library.helper + +import android.R +import android.annotation.TargetApi +import android.os.Build +import android.widget.EditText +import android.widget.TextView +import androidx.annotation.DrawableRes +import java.lang.reflect.Field + + +/** + * @name SuperTextView + * @author Realmo + * @email momo.weiye@gmail.com + * @version 1.0.0 + * @time 2020/12/14 10:27 + * @describe + */ +object EditTextHelper { + + @TargetApi(Build.VERSION_CODES.O) + fun setCursorDrawable(editText:EditText,@DrawableRes drawableRes:Int){ + try { //修改光标的颜色(反射) + val f: Field = TextView::class.java.getDeclaredField("mCursorDrawableRes") + f.setAccessible(true) + f.set(editText, drawableRes) + } catch (e: Exception) { + e.printStackTrace() + } + } +} \ No newline at end of file diff --git a/library/src/main/java/com/allen/library/helper/ShadowHelper.kt b/library/src/main/java/com/allen/library/helper/ShadowHelper.kt new file mode 100644 index 0000000..1717e24 --- /dev/null +++ b/library/src/main/java/com/allen/library/helper/ShadowHelper.kt @@ -0,0 +1,347 @@ +package com.allen.library.helper + +import android.graphics.* +import android.view.View +import com.allen.library.data.AttributeSetData +import kotlin.math.min + +/** + *
+ * @author : Allen + * e-mail : lygttpod@163.com + * date : 2019/09/22 + * desc : + *+ */ +class ShadowHelper { + + private var targetView: View? = null + + var attributeSetData: AttributeSetData = AttributeSetData() + + private var width: Int = 0 + private var height: Int = 0 + + private var cornersPathList: MutableList
+ * @author : Allen + * e-mail : lygttpod@163.com + * date : 2019/05/27 + * desc : shape构造器 +* + */ + +enum class ShapeType(val value: Int) { + RECTANGLE(0), + OVAL(1), + LINE(2), + RING(3); + + companion object { + @JvmStatic + fun fromValue(value: Int): ShapeType { + return values().find { it.value == value } ?: RECTANGLE + } + } +} + +enum class ShapeGradientAngle(val value: Int) { + LEFT_RIGHT(0), + BL_TR(45), + BOTTOM_TOP(90), + BR_TL(135), + RIGHT_LEFT(180), + TR_BL(225), + TOP_BOTTOM(270), + TL_BR(315); + + companion object { + @JvmStatic + fun fromValue(value: Int): ShapeGradientAngle { + return values().find { it.value == value } ?: LEFT_RIGHT + } + } +} + +enum class ShapeGradientType(val value: Int) { + LINEAR(0), + RADIAL(1), + SWEEP(2); + + companion object { + @JvmStatic + fun fromValue(value: Int): ShapeGradientType { + return values().find { it.value == value } ?: LINEAR + } + } +} + +class ShapeBuilder { + + /** + * android:shape=["rectangle" | "oval" | "line" | "ring"] + */ + private var shapeType: ShapeType = ShapeType.RECTANGLE + + /** + *
+ * @author : Allen + * e-mail : lygttpod@163.com + * date : 2019/09/09 + * desc : + *+ */ +class ShapeButton @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : AppCompatButton(context, attrs, defStyleAttr) { + var shapeBuilder: ShapeBuilder? = null + var attributeSetData: AttributeSetData = AttributeSetData() + + init { + attributeSetData = AttributeSetHelper().loadFromAttributeSet(context, attrs) + shapeBuilder = ShapeBuilder() + shapeBuilder?.init(this, attributeSetData) + } +} \ No newline at end of file diff --git a/library/src/main/java/com/allen/library/shape/ShapeCardView.kt b/library/src/main/java/com/allen/library/shape/ShapeCardView.kt new file mode 100644 index 0000000..4840911 --- /dev/null +++ b/library/src/main/java/com/allen/library/shape/ShapeCardView.kt @@ -0,0 +1,27 @@ +package com.allen.library.shape + +import android.content.Context +import androidx.cardview.widget.CardView +import android.util.AttributeSet +import com.allen.library.data.AttributeSetData +import com.allen.library.helper.AttributeSetHelper +import com.allen.library.helper.ShapeBuilder + +/** + *
+ * @author : Allen + * e-mail : lygttpod@163.com + * date : 2019/09/09 + * desc : + *+ */ +class ShapeCardView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : androidx.cardview.widget.CardView(context, attrs, defStyleAttr) { + var shapeBuilder: ShapeBuilder? = null + var attributeSetData: AttributeSetData = AttributeSetData() + + init { + attributeSetData = AttributeSetHelper().loadFromAttributeSet(context, attrs) + shapeBuilder = ShapeBuilder() + shapeBuilder?.init(this, attributeSetData) + } +} \ No newline at end of file diff --git a/library/src/main/java/com/allen/library/shape/ShapeConstraintLayout.kt b/library/src/main/java/com/allen/library/shape/ShapeConstraintLayout.kt new file mode 100644 index 0000000..cd87b94 --- /dev/null +++ b/library/src/main/java/com/allen/library/shape/ShapeConstraintLayout.kt @@ -0,0 +1,47 @@ +package com.allen.library.shape + +import android.content.Context +import android.graphics.Canvas +import androidx.constraintlayout.widget.ConstraintLayout +import android.util.AttributeSet +import com.allen.library.data.AttributeSetData +import com.allen.library.helper.AttributeSetHelper +import com.allen.library.helper.ShadowHelper +import com.allen.library.helper.ShapeBuilder + +/** + *
+ * @author : Allen + * e-mail : lygttpod@163.com + * date : 2019/09/09 + * desc : + *+ */ +class ShapeConstraintLayout @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : ConstraintLayout(context, attrs, defStyleAttr) { + var shapeBuilder: ShapeBuilder? = null + var shadowHelper: ShadowHelper? = null + + var attributeSetData: AttributeSetData = AttributeSetData() + + init { + attributeSetData = AttributeSetHelper().loadFromAttributeSet(context, attrs) + if (attributeSetData.showShadow) { + shadowHelper = ShadowHelper() + shadowHelper?.init(this, attributeSetData) + } else { + shapeBuilder = ShapeBuilder() + shapeBuilder?.init(this, attributeSetData) + } + } + + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { + super.onSizeChanged(w, h, oldw, oldh) + shadowHelper?.onSizeChanged(w, h) + } + + override fun dispatchDraw(canvas: Canvas) { + shadowHelper?.drawBefore(canvas) + super.dispatchDraw(canvas) + shadowHelper?.drawOver(canvas) + } +} \ No newline at end of file diff --git a/library/src/main/java/com/allen/library/shape/ShapeFrameLayout.kt b/library/src/main/java/com/allen/library/shape/ShapeFrameLayout.kt new file mode 100644 index 0000000..9d6b061 --- /dev/null +++ b/library/src/main/java/com/allen/library/shape/ShapeFrameLayout.kt @@ -0,0 +1,47 @@ +package com.allen.library.shape + +import android.content.Context +import android.graphics.Canvas +import android.util.AttributeSet +import android.widget.FrameLayout +import com.allen.library.data.AttributeSetData +import com.allen.library.helper.AttributeSetHelper +import com.allen.library.helper.ShadowHelper +import com.allen.library.helper.ShapeBuilder + +/** + *
+ * @author : Allen + * e-mail : lygttpod@163.com + * date : 2019/09/09 + * desc : + *+ */ +class ShapeFrameLayout @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : FrameLayout(context, attrs, defStyleAttr) { + var shapeBuilder: ShapeBuilder? = null + var shadowHelper: ShadowHelper? = null + + var attributeSetData: AttributeSetData = AttributeSetData() + + init { + attributeSetData = AttributeSetHelper().loadFromAttributeSet(context, attrs) + if (attributeSetData.showShadow) { + shadowHelper = ShadowHelper() + shadowHelper?.init(this, attributeSetData) + } else { + shapeBuilder = ShapeBuilder() + shapeBuilder?.init(this, attributeSetData) + } + } + + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { + super.onSizeChanged(w, h, oldw, oldh) + shadowHelper?.onSizeChanged(w, h) + } + + override fun dispatchDraw(canvas: Canvas) { + shadowHelper?.drawBefore(canvas) + super.dispatchDraw(canvas) + shadowHelper?.drawOver(canvas) + } +} \ No newline at end of file diff --git a/library/src/main/java/com/allen/library/shape/ShapeLinearLayout.kt b/library/src/main/java/com/allen/library/shape/ShapeLinearLayout.kt new file mode 100644 index 0000000..17c369e --- /dev/null +++ b/library/src/main/java/com/allen/library/shape/ShapeLinearLayout.kt @@ -0,0 +1,47 @@ +package com.allen.library.shape + +import android.content.Context +import android.graphics.Canvas +import android.util.AttributeSet +import android.widget.LinearLayout +import com.allen.library.data.AttributeSetData +import com.allen.library.helper.AttributeSetHelper +import com.allen.library.helper.ShadowHelper +import com.allen.library.helper.ShapeBuilder + +/** + *
+ * @author : Allen + * e-mail : lygttpod@163.com + * date : 2019/09/09 + * desc : + *+ */ +class ShapeLinearLayout @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : LinearLayout(context, attrs, defStyleAttr) { + var shapeBuilder: ShapeBuilder? = null + var shadowHelper: ShadowHelper? = null + + var attributeSetData: AttributeSetData = AttributeSetData() + + init { + attributeSetData = AttributeSetHelper().loadFromAttributeSet(context, attrs) + if (attributeSetData.showShadow) { + shadowHelper = ShadowHelper() + shadowHelper?.init(this, attributeSetData) + } else { + shapeBuilder = ShapeBuilder() + shapeBuilder?.init(this, attributeSetData) + } + } + + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { + super.onSizeChanged(w, h, oldw, oldh) + shadowHelper?.onSizeChanged(w, h) + } + + override fun dispatchDraw(canvas: Canvas) { + shadowHelper?.drawBefore(canvas) + super.dispatchDraw(canvas) + shadowHelper?.drawOver(canvas) + } +} \ No newline at end of file diff --git a/library/src/main/java/com/allen/library/shape/ShapeRelativeLayout.kt b/library/src/main/java/com/allen/library/shape/ShapeRelativeLayout.kt new file mode 100644 index 0000000..06fe4e5 --- /dev/null +++ b/library/src/main/java/com/allen/library/shape/ShapeRelativeLayout.kt @@ -0,0 +1,47 @@ +package com.allen.library.shape + +import android.content.Context +import android.graphics.Canvas +import android.util.AttributeSet +import android.widget.RelativeLayout +import com.allen.library.data.AttributeSetData +import com.allen.library.helper.AttributeSetHelper +import com.allen.library.helper.ShadowHelper +import com.allen.library.helper.ShapeBuilder + +/** + *
+ * @author : Allen + * e-mail : lygttpod@163.com + * date : 2019/09/09 + * desc : + *+ */ +class ShapeRelativeLayout @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : RelativeLayout(context, attrs, defStyleAttr) { + var shapeBuilder: ShapeBuilder? = null + var shadowHelper: ShadowHelper? = null + + var attributeSetData: AttributeSetData = AttributeSetData() + + init { + attributeSetData = AttributeSetHelper().loadFromAttributeSet(context, attrs) + if (attributeSetData.showShadow) { + shadowHelper = ShadowHelper() + shadowHelper?.init(this, attributeSetData) + } else { + shapeBuilder = ShapeBuilder() + shapeBuilder?.init(this, attributeSetData) + } + } + + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { + super.onSizeChanged(w, h, oldw, oldh) + shadowHelper?.onSizeChanged(w, h) + } + + override fun dispatchDraw(canvas: Canvas) { + shadowHelper?.drawBefore(canvas) + super.dispatchDraw(canvas) + shadowHelper?.drawOver(canvas) + } +} \ No newline at end of file diff --git a/library/src/main/java/com/allen/library/shape/ShapeTextView.kt b/library/src/main/java/com/allen/library/shape/ShapeTextView.kt new file mode 100644 index 0000000..eb1b7d3 --- /dev/null +++ b/library/src/main/java/com/allen/library/shape/ShapeTextView.kt @@ -0,0 +1,27 @@ +package com.allen.library.shape + +import android.content.Context +import androidx.appcompat.widget.AppCompatTextView +import android.util.AttributeSet +import com.allen.library.data.AttributeSetData +import com.allen.library.helper.AttributeSetHelper +import com.allen.library.helper.ShapeBuilder + +/** + *
+ * @author : Allen + * e-mail : lygttpod@163.com + * date : 2019/09/09 + * desc : + *+ */ +class ShapeTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : AppCompatTextView(context, attrs, defStyleAttr) { + var shapeBuilder: ShapeBuilder? = null + var attributeSetData: AttributeSetData = AttributeSetData() + + init { + attributeSetData = AttributeSetHelper().loadFromAttributeSet(context, attrs) + shapeBuilder = ShapeBuilder() + shapeBuilder?.init(this, attributeSetData) + } +} \ No newline at end of file diff --git a/library/src/main/res/drawable-v21/selector_white.xml b/library/src/main/res/drawable-v21/selector_white.xml index 0b8c32a..c45dc1c 100644 --- a/library/src/main/res/drawable-v21/selector_white.xml +++ b/library/src/main/res/drawable-v21/selector_white.xml @@ -1,5 +1,9 @@

-
-
-
-
-
-