提交 e281b27e 编写于 作者: C chaychan

重新整理expandableTextView的依赖

上级 fac89a1d
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 3
versionName "2.3.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
version = "2.3.0"
def siteUrl = 'https://github.com/androiddevelop/AlignTextView'
def gitUrl = 'https://github.com/androiddevelop/AlignTextView.git'
group = "me.codeboy.android"
archivesBaseName = "align-text-view"
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives javadocJar
archives sourcesJar
}
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<lint>
<issue id="RtlHardcoded">
<ignore path="src/main/java/cn/androiddevelop/aligntextview/lib/Align.java" />
</issue>
</lint>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<manifest package="me.codeboy.android.aligntextview">
</manifest>
\ No newline at end of file
apply plugin: 'com.android.library'
ext{
PUBLISH_GROUP_ID = 'com.jaydenxiao'
PUBLISH_ARTIFACT_ID = 'ExpandableTextView'
PUBLISH_VERSION = '1.0.0'
}
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
//打包不检查
lintOptions {
checkReleaseBuilds false
abortOnError false
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile project(':AliagnTextView')
}
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in H:\android-22\sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
package jaydenxiao.com.expandabletextview;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
\ No newline at end of file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="jaydenxiao.com.expandabletextview">
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true">
</application>
</manifest>
package jaydenxiao.com.expandabletextview;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.WindowManager;
import android.widget.LinearLayout;
/**
* des:屏幕相关辅助类
* Created by xsf
* on 2016.08.24
*/
public class UIUtil {
private UIUtil() {
/* cannot be instantiated */
throw new UnsupportedOperationException("cannot be instantiated");
}
/**
* 将px值转换为dip或dp值,保证尺寸大小不变
*
* @param pxValue
* (DisplayMetrics类中属性density)
* @return
*/
public static int px2dip(Context context,float pxValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (pxValue / scale + 0.5f);
}
/**
* 将dip或dp值转换为px值,保证尺寸大小不变
*
* @param dipValue
* @return
*/
public static int dip2px( Context context ,float dipValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dipValue * scale + 0.5f);
}
/**
* 将px值转换为sp值,保证文字大小不变
*
* @param pxValue
* @return
*/
public static int px2sp(Context context,float pxValue) {
final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
return (int) (pxValue / fontScale + 0.5f);
}
/**
* 将sp值转换为px值,保证文字大小不变
*
* @param spValue
* @return
*/
public static int sp2px(Context context,float spValue) {
final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
return (int) (spValue * fontScale + 0.5f);
}
/**
* 直接获取控件的宽、高
* @param view
* @return int[]
*/
public static int[] getWidgetWH(final View view){
ViewTreeObserver vto2 = view.getViewTreeObserver();
vto2.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});
return new int[]{view.getWidth(),view.getHeight()};
}
/**
* 直接获取控件的宽、高
* @param view
* @return int[]
*/
public static int getViewHeight(final View view){
ViewTreeObserver vto2 = view.getViewTreeObserver();
vto2.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});
return view.getHeight();
}
/**
* 直接获取控件的宽、高
* @param view
* @return int[]
*/
public static int getViewWidth(final View view){
ViewTreeObserver vto2 = view.getViewTreeObserver();
vto2.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});
return view.getWidth();
}
/**
* 获得屏幕宽度
*
* @param context
* @return
*/
public static int getScreenWidth(Context context) {
WindowManager wm = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(outMetrics);
return outMetrics.widthPixels;
}
/**
* 获得屏幕高度
*
* @param context
* @return
*/
public static int getScreenHeight(Context context) {
WindowManager wm = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(outMetrics);
return outMetrics.heightPixels;
}
/**
* 获取控件的宽
* @param view
* @return
*/
public static int getWidgetWidth(View view){
int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
view.measure(w, h);//先度量
int width = view.getMeasuredWidth();
return width;
}
/**
* 获取控件的高
* @param view
* @return
*/
public static int getWidgetHeight(View view){
int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
view.measure(w, h);//先度量
int height = view.getMeasuredHeight();
return height;
}
/**
* 设置控件宽
* @param view
* @param width
*/
public static void setWidgetWidth(View view, int width){
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams();
params.width = width;
view.setLayoutParams(params);
}
/**
* 设置控件高
* @param view
* @param height
*/
public static void setWidgetHeight(View view, int height){
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams();
params.height = height;
view.setLayoutParams(params);
}
//获得状态栏的高度
public static int getStatusBarHeight(Context context) {
int result = 0;
int resId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resId > 0) {
result = context.getResources().getDimensionPixelOffset(resId);
}
return result;
}
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--收起展开textview-->
<declare-styleable name="ExpandableTextView">
<attr name="maxCollapsedLines" format="integer"/>
<attr name="animDuration" format="integer"/>
<attr name="expandDrawable" format="reference"/>
<attr name="collapseDrawable" format="reference"/>
<attr name="contentTextColor" format="color" />
<attr name="collapseExpandTextColor" format="color" />
<attr name="contentTextSize" format="dimension" />
<attr name="collapseExpandTextSize" format="dimension" />
<attr name="textCollapse" format="string" />
<attr name="textExpand" format="string" />
<attr name="collapseExpandGrarity" >
<flag name="left" value="3"/>
<flag name="right" value="5"/>
</attr>
<attr name="drawableGrarity" >
<flag name="left" value="3"/>
<flag name="right" value="5"/>
</attr>
</declare-styleable>
</resources>
\ No newline at end of file
<resources>
<string name="app_name">ExpandableTextView</string>
<string name="expand">展开</string>
<string name="collapse">收起</string>
<string name="test_content">The story of a Chinese couple at Oxford University who first met each other as deskmate in middle school and recently married each other has gone viral, southcn.com reported.
Zhou Si, the groom, and Chen Mengge, the bride, married each other on Aug 18 and will together go to Oxford University to pursue their doctoral degrees later this year.
They were deskmate in middle school and then both were admitted by same high school but not in same class.</string>
</resources>
package jaydenxiao.com.expandabletextview;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* To work on unit tests, switch the Test Artifact in the Build Variants view.
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
......@@ -9,8 +9,8 @@ import android.widget.Toast;
import com.chaychan.viewlib.ExpandableLinearLayout;
import com.chaychan.viewlib.PowerfulEditText;
import com.chaychan.viewlib.expandabletextview.ExpandableTextView;
import jaydenxiao.com.expandabletextview.ExpandableTextView;
public class MainActivity extends AppCompatActivity {
......@@ -31,7 +31,7 @@ public class MainActivity extends AppCompatActivity {
});
ExpandableTextView etv = (ExpandableTextView) findViewById(R.id.tv_intro);
etv.setText("啊哈可接受的看哈市的哈数据库和的看就好撒看就好将卡上的空间哈看就好啊数据库和的空间哈市科空间哈市科技很多借口撒谎的健康哈数据库空间哈市科技很多借口撒谎的健康哈数据库空间哈市科技很多借口撒谎的健康哈数据库空间哈市科技很多借口撒谎的健康哈数据库技很多借口撒谎的健康哈数据库将撒谎的健康哈啊市科技哈看就好啊数据库的哈看将撒谎空间的哈市科技哈看将");
etv.setText("啊哈可接受的看哈市的哈数据库和的看就好撒看就,好将卡上的空间哈看就,好啊数据库和的空间哈市科空间哈市科技很多借口撒谎的健康哈数据库空间哈市科技很多借口撒谎的健康哈数据库空间哈市科技很多借口撒谎的健康哈数据库空间哈市科技很多借口撒谎的健康哈数据库技很多借口撒谎的健康哈数据库将撒谎的健康哈啊市科技哈看就好啊数据库的哈看将撒谎空间的哈市科技哈看将");
View view1 = View.inflate(this, R.layout.item_expandable_linear_layout, null);
View view2 = View.inflate(this, R.layout.item_expandable_linear_layout, null);
......
......@@ -28,7 +28,7 @@
app:hideText="查看更多"
/>
<jaydenxiao.com.expandabletextview.ExpandableTextView
<com.chaychan.viewlib.expandabletextview.ExpandableTextView
android:id="@+id/tv_intro"
android:layout_width="match_parent"
android:layout_height="wrap_content"
......@@ -37,15 +37,14 @@
android:ellipsize="end"
android:textColor="#666"
app:animDuration="200"
app:collapseDrawable="@drawable/icon_green_arrow_down"
app:collapseDrawable="@mipmap/icon_green_arrow_down"
app:collapseExpandGrarity="right"
app:collapseExpandTextColor="@color/main_color"
app:contentTextSize="12sp"
app:expandDrawable="@drawable/icon_green_arrow_up"
app:expandDrawable="@mipmap/icon_green_arrow_up"
app:maxCollapsedLines="3"
app:textCollapse="@string/collapse"
app:textExpand="@string/expand"/>
</LinearLayout>
include ':app', ':viewlib', ':ExpandableTextView', ':AliagnTextView'
include ':app', ':viewlib'
......@@ -23,5 +23,5 @@ dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.nineoldandroids:library:2.4.0'
compile project(':ExpandableTextView')
compile 'com.android.support:support-v4:24.2.0'
}
package me.codeboy.android.aligntextview;
package com.chaychan.viewlib.expandabletextview;
import android.content.Context;
import android.content.res.TypedArray;
......@@ -9,6 +9,8 @@ import android.util.AttributeSet;
import android.util.TypedValue;
import android.widget.TextView;
import com.chaychan.viewlib.R;
import java.util.ArrayList;
import java.util.List;
......
package me.codeboy.android.aligntextview;
package com.chaychan.viewlib.expandabletextview;
import android.content.ClipboardManager;
import android.content.Context;
......@@ -10,12 +10,12 @@ import android.util.AttributeSet;
import android.view.ViewTreeObserver;
import android.widget.TextView;
import com.chaychan.viewlib.R;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import me.codeboy.android.aligntextview.util.CBAlignTextViewUtil;
/**
* 对齐的TextView
* <p>
......
package jaydenxiao.com.expandabletextview;
package com.chaychan.viewlib.expandabletextview;
import android.animation.Animator;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
......@@ -19,7 +20,8 @@ import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import me.codeboy.android.aligntextview.AlignTextView;
import com.chaychan.viewlib.R;
import com.chaychan.viewlib.UIUtils;
/**
* des:可伸展textview
......@@ -131,10 +133,10 @@ public class ExpandableTextView extends LinearLayout implements View.OnClickList
textExpand = typedArray.getString(R.styleable.ExpandableTextView_textExpand);
if (mExpandDrawable == null) {
mExpandDrawable = ContextCompat.getDrawable(getContext(),R.drawable.icon_green_arrow_up);
mExpandDrawable = ContextCompat.getDrawable(getContext(),R.mipmap.icon_green_arrow_up);
}
if (mCollapseDrawable == null) {
mCollapseDrawable = ContextCompat.getDrawable(getContext(), R.drawable.icon_green_arrow_down);
mCollapseDrawable = ContextCompat.getDrawable(getContext(), R.mipmap.icon_green_arrow_down);
}
if (TextUtils.isEmpty(textCollapse)) {
......@@ -144,10 +146,10 @@ public class ExpandableTextView extends LinearLayout implements View.OnClickList
textExpand = getContext().getString(R.string.expand);
}
contentTextColor = typedArray.getColor(R.styleable.ExpandableTextView_contentTextColor, ContextCompat.getColor(getContext(), R.color.gray));
contentTextSize = typedArray.getDimension(R.styleable.ExpandableTextView_contentTextSize, UIUtil.sp2px(getContext(),14));
contentTextSize = typedArray.getDimension(R.styleable.ExpandableTextView_contentTextSize, UIUtils.sp2px(getContext(),14));
collapseExpandTextColor = typedArray.getColor(R.styleable.ExpandableTextView_collapseExpandTextColor, ContextCompat.getColor(getContext(), R.color.main_color));
collapseExpandTextSize = typedArray.getDimension(R.styleable.ExpandableTextView_collapseExpandTextSize, UIUtil.sp2px(getContext(),14));
collapseExpandTextSize = typedArray.getDimension(R.styleable.ExpandableTextView_collapseExpandTextSize, UIUtils.sp2px(getContext(),14));
grarity = typedArray.getInt(R.styleable.ExpandableTextView_collapseExpandGrarity, Gravity.LEFT);
drawableGrarity=typedArray.getInt(R.styleable.ExpandableTextView_drawableGrarity, Gravity.RIGHT);
......@@ -164,6 +166,7 @@ public class ExpandableTextView extends LinearLayout implements View.OnClickList
*/
@Override
protected void onFinishInflate() {
super.onFinishInflate();
findViews();
}
......
......@@ -4,7 +4,8 @@
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<me.codeboy.android.aligntextview.AlignTextView
<com.chaychan.viewlib.expandabletextview.AlignTextView
android:id="@+id/expandable_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
......@@ -13,6 +14,7 @@
tools:text="@string/test_content"
android:ellipsize="end"
android:textSize="15sp" />
<TextView
android:id="@+id/expand_collapse"
android:layout_width="wrap_content"
......@@ -25,6 +27,7 @@
android:gravity="center"
android:textColor="@color/main_color"
android:drawablePadding="3dp"
tools:drawableRight="@drawable/icon_green_arrow_up"
tools:drawableRight="@mipmap/icon_green_arrow_up"
android:layout_marginTop="5dp" />
</LinearLayout>
\ No newline at end of file
......@@ -39,5 +39,27 @@
<attr name="dividerString" format="string" />
</declare-styleable>
<!--收起展开textview-->
<declare-styleable name="ExpandableTextView">
<attr name="maxCollapsedLines" format="integer"/>
<attr name="animDuration" format="integer"/>
<attr name="expandDrawable" format="reference"/>
<attr name="collapseDrawable" format="reference"/>
<attr name="contentTextColor" format="color" />
<attr name="collapseExpandTextColor" format="color" />
<attr name="contentTextSize" format="dimension" />
<attr name="collapseExpandTextSize" format="dimension" />
<attr name="textCollapse" format="string" />
<attr name="textExpand" format="string" />
<attr name="collapseExpandGrarity" >
<flag name="left" value="3"/>
<flag name="right" value="5"/>