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 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 97626ba..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 66e2f6f..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 5d19981..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 64b0a1a..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/CommonTextView_Readme.md b/CommonTextView_Readme.md index f589e79..bf7fd59 100644 --- a/CommonTextView_Readme.md +++ b/CommonTextView_Readme.md @@ -2,13 +2,14 @@ 是SuperTextView的精简版,但同样是一个功能强大的TextView,可以满足日常大部分布局方式,开发者可已自行组合属性配置出属于自己风格的样式!如果觉得对你有用的话,点一下右上的星星赞一下吧! -#效果图 +# 效果图
-效果图
+效果图 -#基本使用 -###1.添加Gradle依赖 +# 基本使用 + +### 1.添加Gradle依赖 先在项目根目录的 build.gradle 的 repositories 添加: allprojects { @@ -25,7 +26,7 @@ compile 'com.github.lygttpod:SuperTextView:1.1.2' } -###2.布局中如何使用(列出所有属性使用方法) +### 2.布局中如何使用(列出所有属性使用方法) diff --git a/README.md b/README.md index 8c1b684..266ae18 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,29 @@ -## 目录 -* 1、功能描述 -* 2、效果图 -* 3、如何使用 - - 3.1、 Android Studio导入方法 - - 3.2、 项目中如何使用 - - 3.2.1、布局中使用 - - 3.2.2、在代码中使用 - - 3.2.3、属性介绍 -* 4、 实现原理 - - 4.1、需求分析 - - 4.2、代码封装 - - 4.3、总结 -* 5、更新日志 +# SuperTextView + +[![](https://jitpack.io/v/lygttpod/SuperTextView.svg)](https://jitpack.io/#lygttpod/SuperTextView) +[![API](https://img.shields.io/badge/API-14%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=14) +[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-SuperTextView-green.svg?style=true)](https://github.com/lygttpod) +[![](https://img.shields.io/github/stars/lygttpod/SuperTextView.svg)](https://github.com/lygttpod/SuperTextView/stargazers) +[![](https://img.shields.io/github/forks/lygttpod/SuperTextView.svg)](https://github.com/lygttpod/SuperTextView/network) + + +### 重磅推出SuperTextView2.x版本,属性参数相比1.x有些变化,1.x的用户升级2.x的时候请注意 + ## 1、功能描述 -> [**SuperTextView**](https://github.com/lygttpod/SuperTextView)是一个功能强大的View,可以满足日常大部分布局样式,开发者可已自行组合属性配置出属于自己风格的样式!可能描述起来没有概念,还是直接看效果图吧! +> [**SuperTextView**](https://github.com/lygttpod/SuperTextView)是一个功能强大的View,可以满足日常大部分布局样式,开发者可已自行组合属性配置出属于自己风格的样式!可能描述起来没有概念,还是直接看效果图吧! -> 简化版 [**CommonTextView**](https://github.com/lygttpod/SuperTextView/blob/master/CommonTextView_Readme.md)只是逻辑简化,其实功能并不差少哦,有兴趣的可以看看 +> [**SuperButton**](https://github.com/lygttpod/SuperTextView/blob/master/SuperButton_Readme.md)拥有shape文件的大部分属性,从此写shape属性变得非常简单 -> 如果觉得对你有用的话,点一下右上的星星赞一下吧! +> [**CommonTextView**](https://github.com/lygttpod/SuperTextView/blob/master/CommonTextView_Readme.md)只是SuperTextView的逻辑简化,其实功能并不差少哦,有兴趣的可以看看 -## 2、 效果图 +> 如果觉得对你有用的话,点一下右上的星星赞一下吧! -
-效果图
-
-效果图 -效果图 -效果图 -效果图 -效果图 -效果图 -
+## 2、 效果 [**Demo下载地址**]( https://fir.im/eft1) +

+ +

## 3、如何使用 ### 3.1、Android Studio导入方法,添加Gradle依赖 @@ -50,407 +41,356 @@ ``` dependencies { ... - compile 'com.github.lygttpod:SuperTextView:1.1.2' +        compile 'com.github.lygttpod:SuperTextView:VERSION_CODE' } ``` +> ## 温馨提示:项目中部分代码使用kotlin写的,所以你的项目需要支持kotlin + +> ### 注意:VERSION_CODE为[![](https://jitpack.io/v/lygttpod/SuperTextView.svg)](https://jitpack.io/#lygttpod/SuperTextView)后面的数字,即最新的[release](https://github.com/lygttpod/SuperTextView/releases)版本号 + ### 3.2、项目中如何使用 -##### 3.2.1、布局中如何使用(示例中只列出部分属性,开发者可根据具体需求使用其他属性) -``` -         +#### 3.2.1、布局中如何使用(示例中只列出部分属性,开发者可根据具体需求使用其他属性) +``` +         注意: -                1、上下的线可以通过   sLineShow 设置  有四种显示方式 none,top,bottom,both +                1、上下的线可以通过   sDividerLineType 设置  有四种显示方式 none,top,bottom,both                 2、通过设置 sUseRipple=true 开启水波效果 ``` -##### 3.2.2、代码中如何使用 +#### 3.2.2、代码中如何使用 ```        /**      * 可以通过链式设置大部分常用的属性值      */ -        superTextView.setLeftIcon(drawable) -                .setLeftString("") -                .setLeftTVColor(0) -                .setLeftTopString("") -                .setLeftTopTVColor(0) -                .setLeftBottomString("") -                .setLeftBottomTVColor(0) -                .setLeftBottomString2("") -                .setLeftBottomTVColor2(0) -                .setRightString("") -                .setRightTVColor(0) -                .setCbChecked(true) -                .setCbBackground(drawable) -                .setRightIcon(drawable) -                .setRightString("") -                .setRightTVColor(0) -                .setLeftString("") -``` -###### 点击事件(可根据需求选择实现单个或者多个点击事件,需要配合xml添加是否允许点击的属性,详情见属性参数的意义) -``` -        superTextView.setOnSuperTextViewClickListener(new SuperTextView.OnSuperTextViewClickListener() { -                    @Override -                    public void onSuperTextViewClick() { -                        super.onSuperTextViewClick(); -                        //do something -                    } - -                    @Override -                    public void onLeftTopClick() { -                        super.onLeftTopClick(); -                        //do something -                    } - -                    @Override -                    public void onLeftBottomClick() { -                        super.onLeftBottomClick(); -                        //do something -                    } - -                    @Override -                    public void onLeftBottomClick2() { -                        super.onLeftBottomClick2(); -                        //do something -                    } -                }); - - 注意:点击事件需要配合属性值使用 - sLeftTopViewIsClickable= true - sLeftBottomViewIsClickable= true - sLeftBottomView2IsClickable= true -``` -###### 使用第三方库(Picasso或者Glide)加载网络图片 -``` - Picasso.with(this) - .load(url) - .placeholder(R.drawable.head_default) - .into((ImageView) superTextView.getView(SuperTextView.leftImageViewId)); + superTextView.setLeftTopString("") + .setLeftString("") + .setLeftBottomString("") + .setCenterTopString("") + .setCenterString("") + .setCenterBottomString("") + .setRightTopString("") + .setRightString("") + .setRightBottomString("") + .setLeftIcon(0) + .setRightIcon(0) + .setCbChecked(true) + .setCbBackground(null) + .setLeftTvDrawableLeft(null) + .setLeftTvDrawableRight(null) + .setCenterTvDrawableLeft(null) + .setCenterTvDrawableRight(null) + .setRightTvDrawableLeft(null) + .setRightTvDrawableRight(null); + + superTextView.setShapeCornersRadius(20) + .setShapeCornersTopLeftRadius(20) + .setShapeCornersBottomLeftRadius(20) + .setShapeCornersTopRightRadius(20) + .setShapeCornersBottomRightRadius(20) + .setShapeStrokeColor(getResources().getColor(R.color.colorPrimary)) + .setShapeStrokeWidth(1) + .setShapeSrokeDashWidth(1) + .setShapeStrokeDashGap(5) + .setShapeSolidColor(getResources().getColor(R.color.white)) + .setShapeSelectorNormalColor(getResources().getColor(R.color.red_btn)) + .setShapeSelectorPressedColor(getResources().getColor(R.color.gray)) + .useShape();//设置完各个参数之后这句调用才生效 +``` +#### 3.2.3点击事件(可根据需求选择实现单个或者多个点击事件) +``` + /** + * 根据实际需求对需要的View设置点击事件 + */ + /** + * 根据实际需求对需要的View设置点击事件 + */ + superTextView.setOnSuperTextViewClickListener(new SuperTextView.OnSuperTextViewClickListener() { + @Override + public void onClickListener(SuperTextView superTextView) { + string = "整个item的点击事件"; + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setLeftTopTvClickListener(new SuperTextView.OnLeftTopTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getLeftTopString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setLeftTvClickListener(new SuperTextView.OnLeftTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getLeftString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setLeftBottomTvClickListener(new SuperTextView.OnLeftBottomTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getLeftBottomString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setCenterTopTvClickListener(new SuperTextView.OnCenterTopTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getCenterTopString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setCenterTvClickListener(new SuperTextView.OnCenterTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getCenterString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setCenterBottomTvClickListener(new SuperTextView.OnCenterBottomTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getCenterBottomString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setRightTopTvClickListener(new SuperTextView.OnRightTopTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getRightTopString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setRightTvClickListener(new SuperTextView.OnRightTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getRightString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setRightBottomTvClickListener(new SuperTextView.OnRightBottomTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getRightBottomString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setLeftImageViewClickListener(new SuperTextView.OnLeftImageViewClickListener() { + @Override + public void onClickListener(ImageView imageView) { + Toast.makeText(ClickActivity.this, "左边图片", Toast.LENGTH_SHORT).show(); + } + }).setRightImageViewClickListener(new SuperTextView.OnRightImageViewClickListener() { + @Override + public void onClickListener(ImageView imageView) { + Toast.makeText(ClickActivity.this, "右边图片", Toast.LENGTH_SHORT).show(); + } + }); + + superTextView_cb.setOnSuperTextViewClickListener(new SuperTextView.OnSuperTextViewClickListener() { + @Override + public void onClickListener(SuperTextView superTextView) { + superTextView.setCbChecked(!superTextView.getCbisChecked()); + } + }).setCheckBoxCheckedChangeListener(new SuperTextView.OnCheckBoxCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + Toast.makeText(ClickActivity.this, "" + isChecked, Toast.LENGTH_SHORT).show(); + } + }); + + superTextView_switch.setOnSuperTextViewClickListener(new SuperTextView.OnSuperTextViewClickListener() { + @Override + public void onClickListener(SuperTextView superTextView) { + superTextView.setSwitchIsChecked(!superTextView.getSwitchIsChecked()); + } + }).setSwitchCheckedChangeListener(new SuperTextView.OnSwitchCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + Toast.makeText(ClickActivity.this, "" + isChecked, Toast.LENGTH_SHORT).show(); + } + }); +``` +#### 3.2.4使用第三方库(Picasso或者Glide)加载网络图片 +``` + 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"; + + 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()); + + Glide.with(this) + .load(url3) + .placeholder(R.drawable.head_default) + .into(new SimpleTarget() { + @Override + public void onResourceReady(GlideDrawable resource, GlideAnimation glideAnimation) { + superTextView3.setRightTvDrawableRight(resource); + } + }); ``` -##### 3.2.3、属性说明(以下属性全部可以通过xml文件配置和代码进行设置) - -属性名 | 字段 | 描述 -----|------|---- -sLeftIconRes | reference | 左边图标资源 -sRightIconRes | reference | 右边图标资源 -sLeftIconWidth | dimension | 左边图标的宽度 -sLeftIconHeight | dimension | 左边图标的高度 -sRightIconWidth | dimension | 右边图标的高度 -sRightIconHeight | dimension | 右边图标的高度 -sRightCheckBoxRes | reference | 右边CheckBox图标资源 +#### 3.2.5、属性说明(以下属性全部可以通过xml文件配置和代码进行设置) + +属性名 | 字段 | 描述 | 默认值 +----|------|----| ---- sLeftTextString | string | 左边文字字符串 sLeftTopTextString | string | 左上文字字符串 sLeftBottomTextString | string | 左下文字字符串 -sLeftBottomTextString2 | string | 左下第二个文字字符串 sCenterTextString | string | 中间文字字符串 +sCenterTopTextString | string | 中上文字字符串 +sCenterBottomTextString | string | 中下文字字符串 sRightTextString | string | 右边文字字符串 -sTopLineMargin| dimension | 顶部横线的Margin -sTopLineMarginLeft | dimension | 顶部横线的MarginLeft -sTopLineMarginRight | dimension | 顶部横线的MarginRight -sBottomLineMargin | dimension | 底部横线的Margin -sBottomLineMarginLeft | dimension | 底部横线的MarginLeft -sBottomLineMarginRight | dimension | 底部横线的MarginRight -sBothLineMargin | dimension | 上下两条横线的Margin -sBothLineMarginLeft | dimension | 上下两条横线的MarginLeft -sBothLineMarginRight | dimension | 上下两条横线的MarginRight -sCenterSpaceHeight | dimension | top和bottom文字间的高度 -sLeftIconMarginLeft | dimension | 左边图标MarginLeft -sLeftTextMarginLeft | dimension | 左边文字MarginLeft -sLeftTopTextMarginLeft | dimension | 左上文字MarginLeft -sLeftBottomTextMarginLeft | dimension | 左下文字MarginLeft -sLeftBottomTextMarginLeft2 | dimension | 左下第二个文字MarginLeft -sRightTextStringRightIconRes | reference | 右边文字的右边图标资源 -sRightTextStringRightIconResPadding | dimension | 右边文字的右边图标的Padding -sRightIconMarginRight |dimension | 右边icon的MarginRight -sRightTextMarginRight | dimension| 右边文字的MarginRight -sRightCheckBoxMarginRight | dimension| 右边CheckBox的MarginRight -sRightCheckBoxShow | boolean | 右边的CheckBox是否显示 -sIsChecked | boolean | 是否选中 -sUseRipple | boolean | 是否使用点击出现波纹效果 - sLeftTextSize | dimension | 左边文字的字体大小 - sLeftTopTextSize | dimension | 左上文字的字体大小 - sLeftBottomTextSize | dimension | 左下文字的字体大小 - sLeftBottomTextSize2 | dimension | 左下第二个文字的字体大小 - sRightTextSize | dimension | 右边文字的字体大小 - sCenterTextSize | dimension | 中间文字的字体大小 - sBackgroundColor | color | 背景颜色 - sLeftTextColor | color | 左边文字颜色 - sLeftTopTextColor | color | 左上文字颜色 - sLeftBottomTextColor | color | 左下文字颜色 - sLeftBottomTextColor2 | color | 左下第二个文字颜色 - sRightTextColor | color | 右边文字颜色 - sCenterTextColor | color | 中间文字颜色 - sIsSingLines | boolean | 是否单行显示 - sMaxLines | integer | 允许的最大行数 - sMaxEms | integer | 允许的最多字数 - sLineShow | enum | 分割线的显示方式none、top、bottom、both - sBothLineWidth | dimension | 两条分割线的宽度 - sTopLineWidth | dimension | 上边分割线的宽度 - sBottomLineWidth | dimension | 下边分割线的宽度 - sLineColor | color | 分割线的颜色 - sLeftTopViewIsClickable | boolean | 左上view是否可点击 - sLeftBottomViewIsClickable | boolean | 左下view是否可点击 - sLeftBottomView2IsClickable | boolean | 左下第二个view是否可点击 - sBackgroundDrawableRes | reference | 背景资源 - -### 4、实现原理 -##### 4.1、需求分析 -> 黑格尔曾说过:存在即合理。SuperTextView的出现应该就是某种需求下的产物。 - -在开发项目的过程中你会发现有很多页面的布局都是类似的,就比如说常见的设置页面,基本上都是图标+文字+图标的格式,而且出现的频率都很高,如果不做处理势必会写很多无用的代码降低开发效率,正因为如此我们为什么不把这一类view统一封装起来呐(其实就是程序猿的懒惰,哈哈),有了这个想法就开始调研市场上主流应用的显示样式,经过调研总结出一套显示方案涵盖了市面上90%以上的布局样式,目的是在以后的使用中快速高效的开发。 - -##### 4.2、代码封装 -> 在介绍封装之前先说一句题外话,其实任何功能的封装并不难,还是看你愿不愿意花时间去做,及时是简单的功能真正实现起来的时候还是会或多或少的遇到一些问题,发现问题解决问题的过程其实就是进步的过程。好了,废话不多说,下边看代码。 - -首先SuperTextView 是继承自 RelativeLayout实现,里边所有布局的添加都是通过Java代码实现的,事先定义好需要的参数名及类型 +sRightTopTextString | string | 右上文字字符串 +sRightBottomTextString | string | 右下文字字符串 +sLeftTextColor | color | 左边文字颜色 | 默认0xFF373737 +sLeftTopTextColor | color | 左上文字颜色 | 默认0xFF373737 +sLeftBottomTextColor | color | 左下文字颜色 | 默认0xFF373737 +sCenterTextColor | color | 中间文字颜色 | 默认0xFF373737 +sCenterTopTextColor | color | 中上文字颜色 | 默认0xFF373737 +sCenterBottomTextColor | color | 中下文字颜色 | 默认0xFF373737 +sRightTextColor | color | 左边文字颜色 | 默认0xFF373737 +sRightTopTextColor | color | 右上文字颜色 | 默认0xFF373737 +sRightBottomTextColor | color | 右下文字颜色 | 默认0xFF373737 +sLeftTextSize | dimension | 左边字体大小 | 默认15sp +sLeftTopTextSize | dimension | 左上字体大小 | 默认15sp +sLeftBottomTextSize | dimension | 左下字体大小 | 默认15sp +sCenterTextSize | dimension | 中间字体大小 | 默认15sp +sCenterTopTextSize | dimension | 中上字体大小 | 默认15sp +sCenterBottomTextSize | dimension | 中下字体大小 | 默认15sp +sRightTextSize | dimension | 右边字体大小 | 默认15sp +sRightTopTextSize | dimension | 右上字体大小 | 默认15sp +sRightBottomTextSize | dimension | 右下字体大小 | 默认15sp +sLeftLines | integer | 左边文字显示行数 | 默认不设置 +sLeftTopLines | integer | 左上文字显示行数 | 默认不设置 +sLeftBottomLines | integer | 左下文字显示行数 | 默认不设置 +sCenterLines | integer | 中间文字显示行数 | 默认不设置 +sCenterTopLines | integer | 中上文字显示行数 | 默认不设置 +sCenterBottomLines | integer | 中下文字显示行数 | 默认不设置 +sRightLines | integer | 右边文字显示行数 | 默认不设置 +sRightTopLines | integer | 右上文字显示行数 | 默认不设置 +sRightBottomLines | integer | 右下文字显示行数 | 默认不设置 +sLeftMaxEms | integer | 左边文字显示个数 | 默认不设置 +sLeftTopMaxEms | integer | 左上文字显示个数 | 默认不设置 +sLeftBottomMaxEms | integer | 左下文字显示个数 | 默认不设置 +sCenterMaxEms | integer | 中间文字显示个数 | 默认不设置 +sCenterTopMaxEms | integer | 中上文字显示个数 | 默认不设置 +sCenterBottomMaxEms | integer | 中下文字显示个数 | 默认不设置 +sRightMaxEms | integer | 右边文字显示个数 | 默认不设置 +sRightTopMaxEms | integer | 右上文字显示个数 | 默认不设置 +sRightBottomMaxEms | integer | 右下文字显示个数 | 默认不设置 +sLeftViewGravity | enum | 左边文字对齐方式
left_center(左对齐)
center(居中)
right_center(右对齐) | 默认center +sCenterViewGravity | enum | 中间文字对齐方式
left_center(左对齐)
center(居中)
right_center(右对齐) | 默认center +sRightViewGravity | enum | 右边文字对齐方式
left_center(左对齐)
center(居中)
right_center(右对齐) | 默认center +sLeftTvDrawableLeft | reference | 左边TextView左侧的drawable +sLeftTvDrawableRight | reference | 左边TextView右侧的drawable +sCenterTvDrawableLeft | reference | 中间TextView左侧的drawable +sCenterTvDrawableRight | reference | 中间TextView右侧的drawable +sRightTvDrawableLeft | reference | 右边TextView左侧的drawable +sRightTvDrawableRight | reference | 右边TextView右侧的drawable +sLeftTvDrawableWidth | dimension | 左边TextView的drawable的宽度 +sLeftTvDrawableHeight | dimension | 左边TextView的drawable的高度 +sCenterTvDrawableWidth | dimension | 中间TextView的drawable的宽度 +sCenterTvDrawableHeight | dimension | 中间TextView的drawable的高度 +sRightTvDrawableWidth | dimension | 右边TextView的drawable的宽度 +sRightTvDrawableHeight | dimension | 右边TextView的drawable的高度 +sTextViewDrawablePadding | dimension | TextView的drawable对应的Padding | 默认10dp +sLeftViewWidth | dimension | 左边textView的宽度 为了中间文字左对齐的时候使用 +sTopDividerLineMarginLR | dimension | 上边分割线的MarginLeft和MarginRight | 默认0dp +sTopDividerLineMarginLeft | dimension | 上边分割线的MarginLeft | 默认0dp +sTopDividerLineMarginRight | dimension | 上边分割线的MarginRight | 默认0dp +sBottomDividerLineMarginLR | dimension | 下边分割线的MarginLeft和MarginRigh | 默认0dp +sBottomDividerLineMarginLeft | dimension | 下边分割线的MarginLeft | 默认0dp +sBottomDividerLineMarginRight | dimension | 下边分割线的MarginRight | 默认0dp +sDividerLineColor | color | 分割线的颜色 | 默认0xFFE8E8E8 +sDividerLineHeight | dimension | 分割线的高度 | 默认0.5dp +sDividerLineType | enum | 分割线显示方式
none(不显示分割线)
top(显示上边的分割线)
bottom(显示下边的分割线)
both(显示上下两条分割线) | 默认bottom +sLeftViewMarginLeft | dimension | 左边view的MarginLeft | 默认10dp +sLeftViewMarginRight | dimension | 左边view的MarginRight | 默认10dp +sCenterViewMarginLeft | dimension | 中间view的MarginLeft | 默认10dp +sCenterViewMarginRight | dimension | 中间view的MarginRight | 默认10dp +sRightViewMarginLeft | dimension | 右边view的MarginLeft | 默认10dp +sRightViewMarginRight | dimension | 右边view的MarginRight | 默认10dp +sLeftTextIsBold(移除) | boolean | 左边文字是否加粗 | 默认false(暂时去除此属性改为代码动态配置) +sLeftTopTextIsBold(移除) | boolean | 左上文字是否加粗 | 默认false(暂时去除此属性改为代码动态配置) +sLeftBottomTextIsBold(移除) | boolean | 左下文字是否加粗 | 默认false(暂时去除此属性改为代码动态配置) +sCenterTextIsBold(移除) | boolean | 中间文字是否加粗 | 默认false(暂时去除此属性改为代码动态配置) +sCenterTopTextIsBold(移除) | boolean | 中上文字是否加粗 | 默认false(暂时去除此属性改为代码动态配置) +sCenterBottomTextIsBold(移除) | boolean | 中下文字是否加粗 | 默认false(暂时去除此属性改为代码动态配置) +sRightTextIsBold(移除) | boolean | 右边文字是否加粗 | 默认false(暂时去除此属性改为代码动态配置) +sRightTopTextIsBold(移除) | boolean | 右上文字是否加粗 | 默认false(暂时去除此属性改为代码动态配置) +sRightBottomTextIsBold(移除) | boolean | 右下文字是否加粗 | 默认false(暂时去除此属性改为代码动态配置) +sLeftIconRes | reference | 左边图片资源 可以用来显示网络图片或者本地 +sRightIconRes | reference | 右边图片资源 可以用来显示网络图片或者本地 +sLeftIconWidth | dimension | 左边图片资源的宽度 用于固定图片大小的时候使用 +sLeftIconHeight | dimension | 左边图片资源的高度 用于固定图片大小的时候使用 +sRightIconWidth | dimension | 右边图片资源的宽度 用于固定图片大小的时候使用 +sRightIconHeight | dimension | 右边图片资源的高度 用于固定图片大小的时候使用 +sLeftIconMarginLeft | dimension | 左边图片资源的MarginLeft | 默认10dp +sRightIconMarginRight | dimension | 右边图片资源的MarginLeft | 默认10dp +sCenterSpaceHeight | dimension | 上中下三行文字的间距 | 默认5dp +sRightCheckBoxRes | reference | 右边CheckBox的资源 +sRightCheckBoxMarginRight | dimension | 右边CheckBox的MarginRight | 默认10dp +sIsChecked | boolean | 右边CheckBox是否选中 | 默认 false +sUseRipple | boolean | 是否开启点击出现水波效果 | 默认 true +sBackgroundDrawableRes | reference | SuperTextView的背景资源 +sRightViewType | enum | 右边显示的特殊View
checkbox
switchBtn | 默认都不显示 +sRightSwitchMarginRight | dimension | 右边SwitchBtn的MarginRight | 默认10dp +sSwitchIsChecked | boolean | 右边SwitchBtn是否选中 | 默认 false +sTextOff | string | TextOff | 默认"" +sTextOn | string | TextOn | 默认"" +sSwitchMinWidth | dimension | SwitchMinWidth | 系统默认 +sSwitchPadding | dimension | SwitchPadding | 系统默认 +sThumbTextPadding | dimension | ThumbTextPadding | 系统默认 +sThumbResource | reference | 右边SwitchBtn自定义选中资源 | 系统默认 +sTrackResource | reference | 右边SwitchBtn自定义未选中资源 | 系统默认 +sUseShape | boolean | 是否使用shape设置圆角及触摸反馈
设为true之后才能使用一下属性 | 默认false +sShapeSolidColor | color | 填充色 | 默认false +sShapeSelectorPressedColor | color | 按下时候的颜色 | 默认0xffffffff +sShapeSelectorNormalColor | color | 正常显示的颜色 | 默认0xffffffff +sShapeCornersRadius | dimension | 四个角的圆角半径 | 默认0dp +sShapeCornersTopLeftRadius | dimension | 左上角的圆角半径 | 默认0dp +sShapeCornersTopRightRadius | dimension | 右上角的圆角半径 | 默认0dp +sShapeCornersBottomLeftRadius | dimension | 左下角的圆角半径 | 默认0dp +sShapeCornersBottomRightRadius | dimension | 右下角的圆角半径 | 默认0dp +sShapeStrokeWidth | dimension | 边框宽度 | 默认0dp +sShapeStrokeDashWidth | dimension | 虚线宽度 | 默认0dp +sShapeStrokeDashGap | dimension | 虚线间隙宽度 | 默认0dp +sShapeStrokeColor | color | 边框颜色 | 默认0dp +sLeftTextBackground | reference | 左边textView的背景 +sCenterTextBackground | reference | 中间textView的背景 +sRightTextBackground | reference | 右边textView的背景 +sLeftTextGravity | enum | 左边TextView内文字对齐方式
left(左对齐)
center(居中)
right(右对齐) | 默认left +sCenterTextGravity | enum | 中间TextView内文字对齐方式
left(左对齐)
center(居中)
right(右对齐) | 默认left +sRightTextGravity | enum | 右边TextView内文字对齐方式
left(左对齐)
center(居中)
right(右对齐) | 默认left +sLeftIconShowCircle | boolean | 左边ImageView是否显示为圆形 | 默认false +sRightIconShowCircle | boolean | 右边ImageView是否显示为圆形 | 默认false -下边只列出部分参数 -``` - 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 SuperTextView(Context context, AttributeSet attrs) { - super(context, attrs); - mContext = context; - getAttr(attrs); - initLayout(); - } -``` -我们知道系统控件可以从XML中拿到定义好的属性值,那么我们其实也是可以的,首先在attr中定义好相关属性名及字段类型然后通过AttributeSet去拿到相关属性值在进行设置 -``` -private void getAttr(AttributeSet attrs) { - //获取我们在attr中定义的SuperTextView相关属性 - TypedArray typedArray = mContext.obtainStyledAttributes(attrs, R.styleable.SuperTextView); - - //下边展示的各个类型参数的获取方法,drawable、string、boolean、int、px - leftIconRes = typedArray.getDrawable(R.styleable.SuperTextView_sLeftIconRes); - leftTextString = typedArray.getString(R.styleable.SuperTextView_sLeftTextString); - showCheckBox = typedArray.getBoolean(R.styleable.SuperTextView_sRightCheckBoxShow, false); - lineType = typedArray.getInt(R.styleable.SuperTextView_sLineShow, DEFAULT); - topLineMargin = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sTopLineMargin, defaultLinePadding); - - //获取完之后记得recycle()释放掉资源 - typedArray.recycle(); - } -``` -接下来就拿一个view为例进行说明如何动态添加view及设置相关属性 -``` -/** - * 初始化左边文字 - */ - 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); - //设置Params的方法抽离出来便于以后统一调用 - setTextViewParams(leftTV, isSingLines, maxLines, maxEms); - //设置字体颜色的方法抽离出来便于以后统一调用 - setTextColor(leftTV, leftTVColor); - //设置字体大小的方法抽离出来便于以后统一调用 - setTextSize(leftTV, leftTVSize); - //调用addView方法把我们动态创建的view添加到布局中 - addView(leftTV); - } -``` -初始化完view之后就是要暴露一些方法供外部人员使用了(部分代码示例) -在这里我们返回SuperTextView对象是为了实现链式调用 -``` - /** - * 获取checkbox状态 - * - * @return 返回选择框当前选中状态 - */ - public boolean getCbisChecked() { - boolean isChecked = false; - if (rightCheckBox != null) { - isChecked = rightCheckBox.isChecked(); - } - return isChecked; - } - - /** - * 设置左边文字的颜色 - * - * @param textColor 文字颜色值 - * @return 返回对象 - */ - public SuperTextView setLeftTVColor(int textColor) { - leftTVColor = textColor; - if (leftTV == null) { - initLeftText(); - } else { - leftTV.setTextColor(textColor); - } - return this; - } -``` -最后就是一些回调方法的使用,以点击事件为例 -``` -/** - * 点击事件接口 - * 这里没有使用interface是因为有些方法我们不是一定要实现的 - * 用到哪个方法再去重写方法就可以了 - */ - public static class OnSuperTextViewClickListener { - public void onSuperTextViewClick() { - } - - public void onLeftTopClick() { - } - - public void onLeftBottomClick() { - } - - public void onLeftBottomClick2() { - } - - } -``` -相关的set方法拿到OnSuperTextViewClickListener对象 -``` - public SuperTextView setOnSuperTextViewClickListener(OnSuperTextViewClickListener listener) { - onSuperTextViewClickListener = listener; - return this; - } -``` - -初始化view的时候在各个view的点击事件中添加相应的回调方法就行了 -``` - if (mLeftTopViewIsClickable) { - leftTopTV.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - if (onSuperTextViewClickListener != null) { - onSuperTextViewClickListener.onLeftTopClick(); - } - } - }); - } -``` -> 以上只是源码中的部分方法拿出来供分析使用,看了之后是不是感觉实现其实很简单,赶紧自己着手实现一个吧! - -##### 4.3、总结 -想必看到这里的小伙伴已经对这个库的源码实现方式了解了,这里只是把实现的流程给大家介绍了一下,我又对这个库做了一个简化版的处理,有兴趣的小伙伴可以去读读源码哦,发现哪里写的不妥的地方还请指正。 - -## 5、更新日志 - -### V1.1.2 -* 上下分割线添加单独设置左右边距的参数 -``` - 1、SuperTextVIew配置方法如下:下列两种方式都是单独使用 - - //方法一 - stv:sTopLineMarginLeft="10dp" - stv:sTopLineMarginRight="0dp" - - stv:sBottomLineMarginLeft="10dp" - stv:sBottomLineMarginRight="0dp" - - //方法二 - stv:sBothLineMarginLeft="10dp" - stv:sBothLineMarginRight="0dp" - - 2、CommonTextView配置方法如下:下列两种方式都是单独使用 - - //方法一 - ctv:cTopDividerLineMarginLeft="10dp" - ctv:cTopDividerLineMarginRight="0dp" - - ctv:cBottomDividerLineMarginLeft="10dp" - ctv:cBottomDividerLineMarginRight="0dp" - - //方法二 - ctv:cBothDividerLineMarginLeft="10dp" - ctv:cBothDividerLineMarginRight="0dp" -``` - -### V1.1.1 -* 1、SuperTextview和CommonTextview新增点击时候自定义选中和默认背景效果 -``` - sBackgroundDrawableRes="@drawable/selector_red" - - cBackgroundDrawableRes="@drawable/selector_red" -``` - -* 2、CommonTextview新增中间布局左对齐属性 -``` - 两个属性配合使用 - ctv:cIsCenterAlignLeft="true" - ctv:cCenterViewMarginLeft="200dp" - -``` - -### V1.1 -* 修复SuperTextView和CommonTextView点击事件被子View消耗掉的bug(具体使用请参考文档) - -### V1.0.9 -* SuperTextView新增左右图标可自定义大小的功能 -``` - stv:sRightIconWidth="30dp" - stv:sRightIconHeight="30dp" - stv:sLeftIconWidth="30dp" - stv:slefticonHeight="30dp" - ``` -### V1.0.8 -* 修复CommonTextView点击事件无效的bug +> 黑格尔曾说过:存在即合理。SuperTextView的出现应该就是某种需求下的产物。 -### V1.0.7 -* CommonTextView新增支持加载网络图片 -### V1.0.6 -* 新增设置分割线颜色和宽度的方法 -* 新增简化版CommonTextView +# 4、[更新日志](https://github.com/lygttpod/SuperTextView/releases) -### V1.0.3 -* 新增左右两边图片支持常用三方库加载网络图片 +# 意见反馈 -### V1.0.2 -* 修复文字内容过多,超过1行的处理,导致两边的文字会引起重叠的bug +STV&RxHttp交流群 -### 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文件了,想怎么玩就怎么玩! + +# 效果图 +
+效果图
+ + +### SuperButton所有属性均提供代码动态设置 +``` + /** + * 所有属性均可用代码动态实现 + * 以下只是展示部分方法 可根据需求选择不同的方法 + */ + superButton.setShapeType(SuperButton.RECTANGLE) + .setShapeCornersRadius(20) + .setShapeSolidColor(getResources().getColor(R.color.colorAccent)) + .setShapeStrokeColor(getResources().getColor(R.color.colorPrimary)) + .setShapeStrokeWidth(1) + .setShapeSrokeDashWidth(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 才能对设置的参数生效 + +``` +### 布局中如何使用(只是列出部分属性) +``` + +``` + +### 属性说明(以下属性全部可以通过xml文件配置) + +``` + + + + + + + + +``` + +> ### 以上shape对应下边的SuperButton属性 + +属性名 | 字段 | 描述 | 默认值 +----|------|----| ---- +sGravity | enum | 设置文字对其方式
center
left
right
top
bottom | 默认center +sShapeType | enum | 设置Shape的类型
rectangle
oval
right
line
ring | 默认rectangle +sSolidColor | color | 填充颜色 | 默认 +sSelectorPressedColor | color | 按下时颜色 | 默认0x20000000 +sSelectorDisableColor | color | 不可点击颜色 | 默认0x20000000 +sSelectorNormalColor | color | 正常显示的颜色 | 默认0x20000000 +sCornersRadius | dimension | shape的四个圆角半径 | 默认0dp +sCornersTopLeftRadius | dimension | shape的左上圆角半径 | 默认0dp +sCornersTopRightRadius | dimension | shape的右上圆角半径 | 默认0dp +sCornersBottomLeftRadius | dimension | shape的左下圆角半径 | 默认0dp +sCornersBottomRightRadius | dimension | shape的右下圆角半径 | 默认0dp +sStrokeDashWidth | dimension | shape的虚线宽度 | 默认0dp +sStrokeDashGap | dimension | shape的虚线间隙 | 默认0dp +sStrokeWidth | dimension | shape的边框宽度 | 默认0dp +sStrokeColor | color | shape的边框颜色 | 默认0x20000000 +sSizeWidth | dimension | shape的SizeWidth | 默认0dp +sSizeHeight | dimension | shape的SizeHeight | 默认0dp +sGradientOrientation | enum | 设置渐变类型
TOP_BOTTOM
TR_BL
RIGHT_LEFT
BR_TL
BOTTOM_TOP
BL_TR
LEFT_RIGHT
TL_BR | 默认rectangle +sGradientType | enum | 设置渐变类型
linear
radial
sweep | 默认rectangle +sGradientCenterX | float | shape的CenterX | 默认0f +sGradientCenterY | float | shape的CenterY | 默认0f +sGradientGradientRadius | dimension | shape的GradientRadius | 默认0dp +sGradientStartColor | color | shape的StartColor | +sGradientCenterColor | color | shape的CenterColor | +sGradientEndColor | color | shape的EndColor | +sGradientUseLevel | boolean | shape的UseLevel | 默认flase +sUseSelector | boolean | 是否使用selector | 默认false + diff --git a/app/build.gradle b/app/build.gradle index 8a93cd5..8c1660a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,15 +1,16 @@ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { - compileSdkVersion 24 - buildToolsVersion "24.0.1" + compileSdkVersion 28 defaultConfig { applicationId "com.allen.supertextview" - minSdkVersion 11 - targetSdkVersion 24 + minSdkVersion 14 + targetSdkVersion 28 versionCode 1 versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' } buildTypes { release { @@ -17,17 +18,26 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + productFlavors { + } } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' + androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', { exclude group: 'com.android.support', module: 'support-annotations' }) - compile 'com.android.support:appcompat-v7:24.2.1' - testCompile 'junit:junit:4.12' - compile project(':library') - compile 'com.squareup.picasso:picasso:2.5.2' - compile 'com.zhy:base-rvadapter:3.0.3' - compile 'com.github.bumptech.glide:glide:3.7.0' + implementation project(':library') + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.2.1' + implementation 'com.squareup.picasso:picasso:2.5.2' + implementation 'com.github.bumptech.glide:glide:3.8.0' + implementation 'com.zhy:base-rvadapter:3.0.3' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + testImplementation 'junit:junit:4.13.1' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" +} +repositories { + mavenCentral() } diff --git a/app/src/androidTest/java/com/allen/supertextview/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/allen/supertextview/ExampleInstrumentedTest.java index 8189050..5f3aec6 100644 --- a/app/src/androidTest/java/com/allen/supertextview/ExampleInstrumentedTest.java +++ b/app/src/androidTest/java/com/allen/supertextview/ExampleInstrumentedTest.java @@ -1,8 +1,8 @@ package com.allen.supertextview; import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cab142b..b0365e1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,7 +2,8 @@ - + + - - - + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/allen/supertextview/ClickActivity.java b/app/src/main/java/com/allen/supertextview/ClickActivity.java new file mode 100644 index 0000000..f61dcdd --- /dev/null +++ b/app/src/main/java/com/allen/supertextview/ClickActivity.java @@ -0,0 +1,139 @@ +package com.allen.supertextview; + +import androidx.appcompat.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.CompoundButton; +import android.widget.ImageView; +import android.widget.Toast; + +import com.allen.library.SuperTextView; + +public class ClickActivity extends AppCompatActivity { + + private SuperTextView superTextView, superTextView_cb, superTextView_switch; + + private String string; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_click); + + superTextView = (SuperTextView) findViewById(R.id.super_tv); + superTextView_cb = (SuperTextView) findViewById(R.id.super_cb_tv); + superTextView_switch = (SuperTextView) findViewById(R.id.super_switch_tv); + + /** + * 根据实际需求对需要的View设置点击事件 + */ + superTextView.setOnSuperTextViewClickListener(new SuperTextView.OnSuperTextViewClickListener() { + @Override + public void onClickListener(SuperTextView superTextView) { + string = "整个item的点击事件"; + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setLeftTopTvClickListener(new SuperTextView.OnLeftTopTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getLeftTopString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setLeftTvClickListener(new SuperTextView.OnLeftTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getLeftString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setLeftBottomTvClickListener(new SuperTextView.OnLeftBottomTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getLeftBottomString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setCenterTopTvClickListener(new SuperTextView.OnCenterTopTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getCenterTopString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setCenterTvClickListener(new SuperTextView.OnCenterTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getCenterString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setCenterBottomTvClickListener(new SuperTextView.OnCenterBottomTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getCenterBottomString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setRightTopTvClickListener(new SuperTextView.OnRightTopTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getRightTopString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setRightTvClickListener(new SuperTextView.OnRightTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getRightString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setRightBottomTvClickListener(new SuperTextView.OnRightBottomTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getRightBottomString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setLeftImageViewClickListener(new SuperTextView.OnLeftImageViewClickListener() { + @Override + public void onClickListener(ImageView imageView) { + } + }).setRightImageViewClickListener(new SuperTextView.OnRightImageViewClickListener() { + @Override + public void onClickListener(ImageView imageView) { + } + }).setLeftTextGroupClickListener(new SuperTextView.OnLeftTextGroupClickListener() { + @Override + public void onClickListener(View view) { + Toast.makeText(ClickActivity.this, "点击左边text区域", Toast.LENGTH_SHORT).show(); + } + }).setCenterTextGroupClickListener(new SuperTextView.OnCenterTextGroupClickListener() { + @Override + public void onClickListener(View view) { + Toast.makeText(ClickActivity.this, "点击中间text区域", Toast.LENGTH_SHORT).show(); + } + }).setRightTextGroupClickListener(new SuperTextView.OnRightTextGroupClickListener() { + @Override + public void onClickListener(View view) { + Toast.makeText(ClickActivity.this, "点击右边text区域", Toast.LENGTH_SHORT).show(); + } + }); + + superTextView_cb.setOnSuperTextViewClickListener(new SuperTextView.OnSuperTextViewClickListener() { + @Override + public void onClickListener(SuperTextView superTextView) { + superTextView.setCbChecked(!superTextView.getCbisChecked()); + } + }).setCheckBoxCheckedChangeListener(new SuperTextView.OnCheckBoxCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + Toast.makeText(ClickActivity.this, "" + isChecked, Toast.LENGTH_SHORT).show(); + } + }); + + superTextView_switch.setOnSuperTextViewClickListener(new SuperTextView.OnSuperTextViewClickListener() { + @Override + public void onClickListener(SuperTextView superTextView) { + superTextView.setSwitchIsChecked(!superTextView.getSwitchIsChecked()); + } + }).setSwitchCheckedChangeListener(new SuperTextView.OnSwitchCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + Toast.makeText(ClickActivity.this, "" + isChecked, Toast.LENGTH_SHORT).show(); + } + }); + } +} diff --git a/app/src/main/java/com/allen/supertextview/CommonTextViewActivity.java b/app/src/main/java/com/allen/supertextview/CommonTextViewActivity.java index 9faa400..a53bad3 100644 --- a/app/src/main/java/com/allen/supertextview/CommonTextViewActivity.java +++ b/app/src/main/java/com/allen/supertextview/CommonTextViewActivity.java @@ -1,8 +1,8 @@ package com.allen.supertextview; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v7.app.AppCompatActivity; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; import android.widget.Toast; import com.allen.library.CommonTextView; diff --git a/app/src/main/java/com/allen/supertextview/ListActivity.java b/app/src/main/java/com/allen/supertextview/ListActivity.java index ab50434..5febc2d 100644 --- a/app/src/main/java/com/allen/supertextview/ListActivity.java +++ b/app/src/main/java/com/allen/supertextview/ListActivity.java @@ -1,23 +1,29 @@ package com.allen.supertextview; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.Nullable; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import android.view.View; +import android.widget.Toast; import com.allen.supertextview.adapter.NewsAdapter; import com.allen.supertextview.bean.NewsBean; +import com.zhy.adapter.recyclerview.MultiItemTypeAdapter; import java.util.ArrayList; import java.util.List; /** * Created by allen on 2016/10/31. + * 列表中使用 */ -public class ListActivity extends AppCompatActivity { +public class ListActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener { private RecyclerView recyclerView; + private SwipeRefreshLayout swipeRefreshLayout; private NewsAdapter adapter; private List newsBeanList = new ArrayList<>(); @@ -32,6 +38,16 @@ public class ListActivity extends AppCompatActivity { "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=3244336274,3651700434&fm=80&w=179&h=119&img.JPEG", "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=219781665,3032880226&fm=80&w=179&h=119&img.JPEG", "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=831306574,2792494868&fm=80&w=179&h=119&img.GIF", + "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=1580482776,3214289843&fm=80&w=179&h=119&img.JPEG", + "https://ss2.baidu.com/-vo3dSag_xI4khGko9WTAnF6hhy/vip/whcrop%3D176%2C106/sign=cffe5aed6363f6241c086f41e834d6c9/f3d3572c11dfa9ecb7f287c36ad0f703908fc102.jpg", + "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=1383170885,2038374031&fm=80&w=179&h=119&img.JPEG", + "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=2218526845,522933158&fm=80&w=179&h=119&img.JPEG", + "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=775731846,1370921386&fm=80", + "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3860616424,1789830124&fm=80&w=179&h=119&img.PNG", + "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=4096069947,473932952&fm=80&w=179&h=119&img.JPEG", + "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=3244336274,3651700434&fm=80&w=179&h=119&img.JPEG", + "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=219781665,3032880226&fm=80&w=179&h=119&img.JPEG", + "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=831306574,2792494868&fm=80&w=179&h=119&img.GIF", }; @@ -39,22 +55,61 @@ public class ListActivity extends AppCompatActivity { protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list); + swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout); recyclerView = (RecyclerView) findViewById(R.id.recycler_view); - adapter = new NewsAdapter(this,getData()); + adapter = new NewsAdapter(this, getData()); + adapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() { + @Override + public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) { + Toast.makeText(ListActivity.this, position + "", Toast.LENGTH_SHORT).show(); + } + + @Override + public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) { + return false; + } + }); LinearLayoutManager layoutManager = new LinearLayoutManager(this); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); recyclerView.setLayoutManager(layoutManager); recyclerView.setAdapter(adapter); + + swipeRefreshLayout.setOnRefreshListener(this); } private List getData() { + for (int i = 0; i < url.length; i++) { + NewsBean newsBean = new NewsBean(); + newsBean.setImgUrl(url[i]); + newsBean.setTitle("新闻标题" + i); + newsBean.setTime("在列表中使用的demo在列表中使用的demo在列表中使用的demo" + i); + newsBeanList.add(newsBean); + } + return newsBeanList; + } + + private List getRefreshData() { + newsBeanList.clear(); for (int i = 0; i < 10; i++) { NewsBean newsBean = new NewsBean(); newsBean.setImgUrl(url[i]); - newsBean.setTitle("新闻标题----"+i); - newsBean.setTime("2016.10.31----"+i); + newsBean.setTitle("新标" + i); + newsBean.setTime("在列表中使用的demo" + i); newsBeanList.add(newsBean); } return newsBeanList; } + + @Override + public void onRefresh() { + getRefreshData(); + adapter.notifyDataSetChanged(); + + swipeRefreshLayout.post(new Runnable() { + @Override + public void run() { + swipeRefreshLayout.setRefreshing(false); + } + }); + } } diff --git a/app/src/main/java/com/allen/supertextview/MainActivity.java b/app/src/main/java/com/allen/supertextview/MainActivity.java index 9889fd8..37836d0 100644 --- a/app/src/main/java/com/allen/supertextview/MainActivity.java +++ b/app/src/main/java/com/allen/supertextview/MainActivity.java @@ -1,21 +1,17 @@ package com.allen.supertextview; import android.content.Intent; -import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatActivity; import android.view.View; import android.widget.Button; -import com.allen.library.SuperTextView; - public class MainActivity extends AppCompatActivity implements View.OnClickListener { - private SuperTextView superTextView; - private Drawable drawable; + private Button button0, button1, button2, button3, + button4, button5, button6, button7, button8, list_button, click_button, super_button, super_shape, super_shadow; - private Button button0,button1,button2,button3,button4,button5,button6,button7; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -29,6 +25,12 @@ protected void onCreate(Bundle savedInstanceState) { button5 = (Button) findViewById(R.id.button5); button6 = (Button) findViewById(R.id.button6); button7 = (Button) findViewById(R.id.button7); + button8 = (Button) findViewById(R.id.button8); + list_button = (Button) findViewById(R.id.list_button); + click_button = (Button) findViewById(R.id.click_button); + super_button = (Button) findViewById(R.id.super_button); + super_shape = (Button) findViewById(R.id.super_shape); + super_shadow = (Button) findViewById(R.id.super_shadow); button0.setOnClickListener(this); button1.setOnClickListener(this); @@ -38,102 +40,84 @@ protected void onCreate(Bundle savedInstanceState) { button5.setOnClickListener(this); button6.setOnClickListener(this); button7.setOnClickListener(this); + button8.setOnClickListener(this); + list_button.setOnClickListener(this); + click_button.setOnClickListener(this); + super_button.setOnClickListener(this); + super_shape.setOnClickListener(this); + super_shadow.setOnClickListener(this); } @Override public void onClick(View v) { Intent intent = new Intent(); - switch (v.getId()){ + switch (v.getId()) { case R.id.button0: - intent.setClass(this,TypeActivity.class); - intent.putExtra("type",0); + intent.setClass(this, TypeActivity.class); + intent.putExtra("type", 0); startActivity(intent); break; case R.id.button1: - intent.setClass(this,TypeActivity.class); - intent.putExtra("type",1); + intent.setClass(this, TypeActivity.class); + intent.putExtra("type", 1); startActivity(intent); break; case R.id.button2: - intent.setClass(this,TypeActivity.class); - intent.putExtra("type",2); + intent.setClass(this, TypeActivity.class); + intent.putExtra("type", 2); startActivity(intent); break; case R.id.button3: - intent.setClass(this,TypeActivity.class); - intent.putExtra("type",3); + intent.setClass(this, TypeActivity.class); + intent.putExtra("type", 3); startActivity(intent); break; case R.id.button4: - intent.setClass(this,TypeActivity.class); - intent.putExtra("type",4); + intent.setClass(this, TypeActivity.class); + intent.putExtra("type", 4); startActivity(intent); break; case R.id.button5: - intent.setClass(this,TypeActivity.class); - intent.putExtra("type",5); + intent.setClass(this, TypeActivity.class); + intent.putExtra("type", 5); startActivity(intent); break; case R.id.button6: -// intent.setClass(this, ListActivity.class); - intent.setClass(this,TypeActivity.class); + intent.setClass(this, TypeActivity.class); intent.putExtra("type", 6); startActivity(intent); break; case R.id.button7: -// intent.setClass(this, ListActivity.class); - intent.setClass(this, CommonTextViewActivity.class); - intent.putExtra("type", 6); + intent.setClass(this, TypeActivity.class); + intent.putExtra("type", 7); + startActivity(intent); + break; + case R.id.button8: + intent.setClass(this, TypeActivity.class); + intent.putExtra("type", 8); + startActivity(intent); + break; + case R.id.list_button: + intent.setClass(this, ListActivity.class); + startActivity(intent); + break; + case R.id.click_button: + intent.setClass(this, ClickActivity.class); + startActivity(intent); + break; + case R.id.super_button: + intent.setClass(this, SuperButtonActivity.class); + startActivity(intent); + break; + case R.id.super_shape: + intent.setClass(this, ShapeActivity.class); + startActivity(intent); + break; + case R.id.super_shadow: + intent.setClass(this, ShadowActivity.class); startActivity(intent); break; } } - /** - * 可以通过链式设置大部分常用的属性值 - */ -// private void setSuperTextView() { -// superTextView.setLeftIcon(drawable) -// .setLeftString("") -// .setLeftTVColor(0) -// .setLeftTopString("") -// .setLeftTopTVColor(0) -// .setLeftBottomString("") -// .setLeftBottomTVColor(0) -// .setLeftBottomString2("") -// .setLeftBottomTVColor2(0) -// .setRightString("") -// .setRightTVColor(0) -// .setCbChecked(true) -// .setCbBackground(drawable) -// .setRightIcon(drawable) -// .setRightString("") -// .setRightTVColor(0) -// .setLeftString("") -// .setOnSuperTextViewClickListener(new SuperTextView.OnSuperTextViewClickListener() { -// @Override -// public void onSuperTextViewClick() { -// super.onSuperTextViewClick(); -// //do something -// } -// -// @Override -// public void onLeftTopClick() { -// super.onLeftTopClick(); -// //do something -// } -// -// @Override -// public void onLeftBottomClick() { -// super.onLeftBottomClick(); -// //do something -// } -// -// @Override -// public void onLeftBottomClick2() { -// super.onLeftBottomClick2(); -// //do something -// } -// }); -// } } diff --git a/app/src/main/java/com/allen/supertextview/ShadowActivity.kt b/app/src/main/java/com/allen/supertextview/ShadowActivity.kt new file mode 100644 index 0000000..cddae2e --- /dev/null +++ b/app/src/main/java/com/allen/supertextview/ShadowActivity.kt @@ -0,0 +1,115 @@ +package com.allen.supertextview + +import android.graphics.Color +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import android.widget.SeekBar +import kotlinx.android.synthetic.main.activity_shadow.* +import java.lang.Exception + +/** + *
+ *      @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() { + @Override + public void onResourceReady(GlideDrawable resource, GlideAnimation glideAnimation) { + superTextView3.setRightTvDrawableRight(resource); + } + }); + Glide.with(this) + .load(url4) + .into(new SimpleTarget() { + @Override + public void onResourceReady(GlideDrawable resource, GlideAnimation glideAnimation) { + alipayStv.setLeftTvDrawableRight(resource); + } + }); } diff --git a/app/src/main/java/com/allen/supertextview/adapter/NewsAdapter.java b/app/src/main/java/com/allen/supertextview/adapter/NewsAdapter.java index b9fd99c..4ad5521 100644 --- a/app/src/main/java/com/allen/supertextview/adapter/NewsAdapter.java +++ b/app/src/main/java/com/allen/supertextview/adapter/NewsAdapter.java @@ -2,9 +2,10 @@ import android.content.Context; +import com.allen.library.SuperTextView; import com.allen.supertextview.R; import com.allen.supertextview.bean.NewsBean; -import com.allen.library.SuperTextView; +import com.squareup.picasso.Picasso; import com.zhy.adapter.recyclerview.CommonAdapter; import com.zhy.adapter.recyclerview.base.ViewHolder; @@ -16,7 +17,7 @@ public class NewsAdapter extends CommonAdapter { private Context mContext; - private SuperTextView superTextView; + public NewsAdapter(Context context, List datas) { super(context, R.layout.item, datas); mContext = context; @@ -24,11 +25,10 @@ public NewsAdapter(Context context, List datas) { @Override protected void convert(ViewHolder holder, NewsBean newsBean, int position) { -// if (superTextView ==null){ -// superTextView = holder.getView(R.id.super_tv); -// } -// holder.setText(superTextView.getViewId(SuperTextView.leftTopTextViewId),newsBean.getTitle()); -// holder.setText(superTextView.getViewId(SuperTextView.leftBottomTextViewId),newsBean.getTime()); -// Picasso.with(mContext).load(newsBean.getImgUrl()).into((ImageView) SuperTextView.getView(SuperTextView.leftImageViewId)); + + ((SuperTextView) holder.getView(R.id.super_tv)).setLeftTopString(newsBean.getTitle()).setLeftBottomString(newsBean.getTime()); + Picasso.with(mContext).load(newsBean.getImgUrl()).placeholder(R.drawable.head_default + ).into(((SuperTextView) holder.getView(R.id.super_tv)) + .getLeftIconIV()); } } diff --git a/app/src/main/java/com/allen/supertextview/utils/DisplayUtils.java b/app/src/main/java/com/allen/supertextview/utils/DisplayUtils.java new file mode 100644 index 0000000..c2c2525 --- /dev/null +++ b/app/src/main/java/com/allen/supertextview/utils/DisplayUtils.java @@ -0,0 +1,65 @@ +package com.allen.supertextview.utils; + +import android.content.Context; +import android.util.DisplayMetrics; +import android.view.WindowManager; + +/** + *
+ *      @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 @@ + + + + + diff --git a/app/src/main/res/drawable-xhdpi/alipay_icon.png b/app/src/main/res/drawable-xhdpi/alipay_icon.png new file mode 100644 index 0000000..ef95fd1 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/alipay_icon.png differ diff --git a/app/src/main/res/drawable-xhdpi/name_icon.png b/app/src/main/res/drawable-xhdpi/name_icon.png new file mode 100644 index 0000000..c85bce8 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/name_icon.png differ diff --git a/app/src/main/res/drawable-xxhdpi/app_back_icon_3x.png b/app/src/main/res/drawable-xxhdpi/app_back_icon_3x.png new file mode 100644 index 0000000..822935c Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/app_back_icon_3x.png differ diff --git a/app/src/main/res/drawable-xxhdpi/icon_iv_bg.png b/app/src/main/res/drawable-xxhdpi/icon_iv_bg.png new file mode 100644 index 0000000..e606417 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/icon_iv_bg.png differ diff --git a/app/src/main/res/drawable-xxhdpi/original_label.png b/app/src/main/res/drawable-xxhdpi/original_label.png new file mode 100644 index 0000000..05cced7 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/original_label.png differ diff --git a/app/src/main/res/drawable-xxhdpi/shape_cycle.xml b/app/src/main/res/drawable-xxhdpi/shape_cycle.xml new file mode 100644 index 0000000..649a700 --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/shape_cycle.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable-xxhdpi/shape_cycle_rectangle.xml b/app/src/main/res/drawable-xxhdpi/shape_cycle_rectangle.xml new file mode 100644 index 0000000..cffd260 --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/shape_cycle_rectangle.xml @@ -0,0 +1,14 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable-xxhdpi/shape_cycle_rectangle_download.xml b/app/src/main/res/drawable-xxhdpi/shape_cycle_rectangle_download.xml new file mode 100644 index 0000000..3fe8439 --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/shape_cycle_rectangle_download.xml @@ -0,0 +1,17 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable-xxhdpi/shape_cycle_small.xml b/app/src/main/res/drawable-xxhdpi/shape_cycle_small.xml new file mode 100644 index 0000000..92dd529 --- /dev/null +++ b/app/src/main/res/drawable-xxhdpi/shape_cycle_small.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable-xxhdpi/success_blue13.png b/app/src/main/res/drawable-xxhdpi/success_blue13.png new file mode 100644 index 0000000..1a2501a Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/success_blue13.png differ diff --git a/app/src/main/res/drawable/edit_cursor.xml b/app/src/main/res/drawable/edit_cursor.xml new file mode 100644 index 0000000..c530802 --- /dev/null +++ b/app/src/main/res/drawable/edit_cursor.xml @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/gray_thumb.xml b/app/src/main/res/drawable/gray_thumb.xml new file mode 100644 index 0000000..be9a719 --- /dev/null +++ b/app/src/main/res/drawable/gray_thumb.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/gray_track.xml b/app/src/main/res/drawable/gray_track.xml new file mode 100644 index 0000000..322984a --- /dev/null +++ b/app/src/main/res/drawable/gray_track.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/green_thumb.xml b/app/src/main/res/drawable/green_thumb.xml new file mode 100644 index 0000000..972c6e3 --- /dev/null +++ b/app/src/main/res/drawable/green_thumb.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/green_track.xml b/app/src/main/res/drawable/green_track.xml new file mode 100644 index 0000000..1be155a --- /dev/null +++ b/app/src/main/res/drawable/green_track.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/shape_test.xml b/app/src/main/res/drawable/shape_test.xml new file mode 100644 index 0000000..2c8d006 --- /dev/null +++ b/app/src/main/res/drawable/shape_test.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/thumb.xml b/app/src/main/res/drawable/thumb.xml new file mode 100644 index 0000000..4355018 --- /dev/null +++ b/app/src/main/res/drawable/thumb.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/track.xml b/app/src/main/res/drawable/track.xml new file mode 100644 index 0000000..da1b10f --- /dev/null +++ b/app/src/main/res/drawable/track.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_click.xml b/app/src/main/res/layout/activity_click.xml new file mode 100644 index 0000000..476d5b3 --- /dev/null +++ b/app/src/main/res/layout/activity_click.xml @@ -0,0 +1,51 @@ + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 37dae11..c7cb7fd 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,6 +1,5 @@ - -