diff --git a/build.gradle b/build.gradle index 200395b..5a9d158 100644 --- a/build.gradle +++ b/build.gradle @@ -3,9 +3,10 @@ buildscript { repositories { jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.3' + classpath 'com.android.tools.build:gradle:3.2.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -14,6 +15,7 @@ buildscript { allprojects { repositories { + google() jcenter() } } @@ -24,11 +26,11 @@ task clean(type: Delete) { ext { // sdk and tools - minSdkVersion = 9 - targetSdkVersion = 25 - compileSdkVersion = 25 - buildToolsVersion = '25.0.2' + minSdkVersion = 14 + targetSdkVersion = 26 + compileSdkVersion = 26 + buildToolsVersion = '27.0.3' // dependencies versions - supportVersion = '25.3.0' + supportVersion = '27.1.1' } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 1d3591c..fe4fbde 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,4 +15,6 @@ # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true \ No newline at end of file +# org.gradle.parallel=true + +#org.gradle.jvmargs=-DsocksProxyHost=127.0.0.1 -DsocksProxyPort=1086 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1d0368e..7c4cfa3 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Jun 20 19:22:06 CEST 2017 +#Thu Jan 03 11:12:45 CST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip diff --git a/library/build.gradle b/library/build.gradle index 1a4a45a..b995cb5 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -8,7 +8,6 @@ ext { android { compileSdkVersion rootProject.compileSdkVersion - buildToolsVersion rootProject.buildToolsVersion defaultConfig { minSdkVersion rootProject.minSdkVersion @@ -25,7 +24,7 @@ android { } dependencies { - compile "com.android.support:appcompat-v7:$rootProject.supportVersion" + api "com.android.support:appcompat-v7:$rootProject.supportVersion" } // to generate release build use './gradlew clean build generateRelease' diff --git a/library/src/main/java/com/tolstykh/textviewrichdrawable/ButtonRichDrawable.java b/library/src/main/java/com/tolstykh/textviewrichdrawable/ButtonRichDrawable.java index e8cc52a..14ea9c3 100644 --- a/library/src/main/java/com/tolstykh/textviewrichdrawable/ButtonRichDrawable.java +++ b/library/src/main/java/com/tolstykh/textviewrichdrawable/ButtonRichDrawable.java @@ -1,7 +1,9 @@ package com.tolstykh.textviewrichdrawable; import android.content.Context; +import android.graphics.drawable.Drawable; import android.support.annotation.DrawableRes; +import android.support.annotation.Nullable; import android.support.v7.widget.AppCompatButton; import android.util.AttributeSet; @@ -70,4 +72,31 @@ public void setDrawableBottomVectorId(@DrawableRes int id) { mRichDrawableHelper.setDrawableBottomVectorId(id); mRichDrawableHelper.apply(this); } + + + public void setDrawables(@Nullable Drawable left, @Nullable Drawable top, @Nullable Drawable right, @Nullable Drawable bottom) { + super.setCompoundDrawables(left, top, right, bottom); + mRichDrawableHelper.apply(this); + } + + public void setLeftDrawable(@Nullable Drawable left) { + Drawable[] compoundDrawables = getCompoundDrawables(); + setDrawables(left, compoundDrawables[1], compoundDrawables[2], compoundDrawables[3]); + } + + public void setRightDrawable(@Nullable Drawable right) { + Drawable[] compoundDrawables = getCompoundDrawables(); + setDrawables(compoundDrawables[0], compoundDrawables[1], right, compoundDrawables[3]); + } + + public void setTopDrawable(@Nullable Drawable top) { + Drawable[] compoundDrawables = getCompoundDrawables(); + setDrawables(compoundDrawables[0], top, compoundDrawables[2], compoundDrawables[3]); + } + + public void setBottomDrawable(@Nullable Drawable bottom) { + Drawable[] compoundDrawables = getCompoundDrawables(); + setDrawables(compoundDrawables[0], compoundDrawables[1], compoundDrawables[2], bottom); + } + } diff --git a/library/src/main/java/com/tolstykh/textviewrichdrawable/CheckBoxRichDrawable.java b/library/src/main/java/com/tolstykh/textviewrichdrawable/CheckBoxRichDrawable.java index 3d3b4e3..f14ed2d 100644 --- a/library/src/main/java/com/tolstykh/textviewrichdrawable/CheckBoxRichDrawable.java +++ b/library/src/main/java/com/tolstykh/textviewrichdrawable/CheckBoxRichDrawable.java @@ -1,7 +1,9 @@ package com.tolstykh.textviewrichdrawable; import android.content.Context; +import android.graphics.drawable.Drawable; import android.support.annotation.DrawableRes; +import android.support.annotation.Nullable; import android.support.v7.widget.AppCompatCheckBox; import android.util.AttributeSet; @@ -70,4 +72,31 @@ public void setDrawableBottomVectorId(@DrawableRes int id) { mRichDrawableHelper.setDrawableTopVectorId(id); mRichDrawableHelper.apply(this); } + + + public void setDrawables(@Nullable Drawable left, @Nullable Drawable top, @Nullable Drawable right, @Nullable Drawable bottom) { + super.setCompoundDrawables(left, top, right, bottom); + mRichDrawableHelper.apply(this); + } + + public void setLeftDrawable(@Nullable Drawable left) { + Drawable[] compoundDrawables = getCompoundDrawables(); + setDrawables(left, compoundDrawables[1], compoundDrawables[2], compoundDrawables[3]); + } + + public void setRightDrawable(@Nullable Drawable right) { + Drawable[] compoundDrawables = getCompoundDrawables(); + setDrawables(compoundDrawables[0], compoundDrawables[1], right, compoundDrawables[3]); + } + + public void setTopDrawable(@Nullable Drawable top) { + Drawable[] compoundDrawables = getCompoundDrawables(); + setDrawables(compoundDrawables[0], top, compoundDrawables[2], compoundDrawables[3]); + } + + public void setBottomDrawable(@Nullable Drawable bottom) { + Drawable[] compoundDrawables = getCompoundDrawables(); + setDrawables(compoundDrawables[0], compoundDrawables[1], compoundDrawables[2], bottom); + } + } diff --git a/library/src/main/java/com/tolstykh/textviewrichdrawable/EditTextRichDrawable.java b/library/src/main/java/com/tolstykh/textviewrichdrawable/EditTextRichDrawable.java index 6189bbe..ce4ba22 100644 --- a/library/src/main/java/com/tolstykh/textviewrichdrawable/EditTextRichDrawable.java +++ b/library/src/main/java/com/tolstykh/textviewrichdrawable/EditTextRichDrawable.java @@ -1,7 +1,9 @@ package com.tolstykh.textviewrichdrawable; import android.content.Context; +import android.graphics.drawable.Drawable; import android.support.annotation.DrawableRes; +import android.support.annotation.Nullable; import android.support.v7.widget.AppCompatEditText; import android.util.AttributeSet; @@ -70,4 +72,31 @@ public void setDrawableBottomVectorId(@DrawableRes int id) { mRichDrawableHelper.setDrawableBottomVectorId(id); mRichDrawableHelper.apply(this); } + + + public void setDrawables(@Nullable Drawable left, @Nullable Drawable top, @Nullable Drawable right, @Nullable Drawable bottom) { + super.setCompoundDrawables(left, top, right, bottom); + mRichDrawableHelper.apply(this); + } + + public void setLeftDrawable(@Nullable Drawable left) { + Drawable[] compoundDrawables = getCompoundDrawables(); + setDrawables(left, compoundDrawables[1], compoundDrawables[2], compoundDrawables[3]); + } + + public void setRightDrawable(@Nullable Drawable right) { + Drawable[] compoundDrawables = getCompoundDrawables(); + setDrawables(compoundDrawables[0], compoundDrawables[1], right, compoundDrawables[3]); + } + + public void setTopDrawable(@Nullable Drawable top) { + Drawable[] compoundDrawables = getCompoundDrawables(); + setDrawables(compoundDrawables[0], top, compoundDrawables[2], compoundDrawables[3]); + } + + public void setBottomDrawable(@Nullable Drawable bottom) { + Drawable[] compoundDrawables = getCompoundDrawables(); + setDrawables(compoundDrawables[0], compoundDrawables[1], compoundDrawables[2], bottom); + } + } diff --git a/library/src/main/java/com/tolstykh/textviewrichdrawable/RadioButtonRichDrawable.java b/library/src/main/java/com/tolstykh/textviewrichdrawable/RadioButtonRichDrawable.java index 521c7f0..446ed5b 100644 --- a/library/src/main/java/com/tolstykh/textviewrichdrawable/RadioButtonRichDrawable.java +++ b/library/src/main/java/com/tolstykh/textviewrichdrawable/RadioButtonRichDrawable.java @@ -1,7 +1,9 @@ package com.tolstykh.textviewrichdrawable; import android.content.Context; +import android.graphics.drawable.Drawable; import android.support.annotation.DrawableRes; +import android.support.annotation.Nullable; import android.support.v7.widget.AppCompatRadioButton; import android.util.AttributeSet; @@ -70,4 +72,32 @@ public void setDrawableBottomVectorId(@DrawableRes int id) { mRichDrawableHelper.setDrawableBottomVectorId(id); mRichDrawableHelper.apply(this); } + + + + public void setDrawables(@Nullable Drawable left, @Nullable Drawable top, @Nullable Drawable right, @Nullable Drawable bottom) { + super.setCompoundDrawables(left, top, right, bottom); + mRichDrawableHelper.apply(this); + } + + public void setLeftDrawable(@Nullable Drawable left) { + Drawable[] compoundDrawables = getCompoundDrawables(); + setDrawables(left, compoundDrawables[1], compoundDrawables[2], compoundDrawables[3]); + } + + public void setRightDrawable(@Nullable Drawable right) { + Drawable[] compoundDrawables = getCompoundDrawables(); + setDrawables(compoundDrawables[0], compoundDrawables[1], right, compoundDrawables[3]); + } + + public void setTopDrawable(@Nullable Drawable top) { + Drawable[] compoundDrawables = getCompoundDrawables(); + setDrawables(compoundDrawables[0], top, compoundDrawables[2], compoundDrawables[3]); + } + + public void setBottomDrawable(@Nullable Drawable bottom) { + Drawable[] compoundDrawables = getCompoundDrawables(); + setDrawables(compoundDrawables[0], compoundDrawables[1], compoundDrawables[2], bottom); + } + } diff --git a/library/src/main/java/com/tolstykh/textviewrichdrawable/TextViewRichDrawable.java b/library/src/main/java/com/tolstykh/textviewrichdrawable/TextViewRichDrawable.java index 0c4810a..7dfa742 100644 --- a/library/src/main/java/com/tolstykh/textviewrichdrawable/TextViewRichDrawable.java +++ b/library/src/main/java/com/tolstykh/textviewrichdrawable/TextViewRichDrawable.java @@ -1,7 +1,9 @@ package com.tolstykh.textviewrichdrawable; import android.content.Context; +import android.graphics.drawable.Drawable; import android.support.annotation.DrawableRes; +import android.support.annotation.Nullable; import android.support.v7.widget.AppCompatTextView; import android.util.AttributeSet; @@ -70,4 +72,30 @@ public void setDrawableBottomVectorId(@DrawableRes int id) { mRichDrawableHelper.setDrawableBottomVectorId(id); mRichDrawableHelper.apply(this); } + + + public void setDrawables(@Nullable Drawable left, @Nullable Drawable top, @Nullable Drawable right, @Nullable Drawable bottom) { + super.setCompoundDrawables(left, top, right, bottom); + mRichDrawableHelper.apply(this); + } + + public void setLeftDrawable(@Nullable Drawable left) { + Drawable[] compoundDrawables = getCompoundDrawables(); + setDrawables(left, compoundDrawables[1], compoundDrawables[2], compoundDrawables[3]); + } + + public void setRightDrawable(@Nullable Drawable right) { + Drawable[] compoundDrawables = getCompoundDrawables(); + setDrawables(compoundDrawables[0], compoundDrawables[1], right, compoundDrawables[3]); + } + + public void setTopDrawable(@Nullable Drawable top) { + Drawable[] compoundDrawables = getCompoundDrawables(); + setDrawables(compoundDrawables[0], top, compoundDrawables[2], compoundDrawables[3]); + } + + public void setBottomDrawable(@Nullable Drawable bottom) { + Drawable[] compoundDrawables = getCompoundDrawables(); + setDrawables(compoundDrawables[0], compoundDrawables[1], compoundDrawables[2], bottom); + } } diff --git a/sample/build.gradle b/sample/build.gradle index c8c48f6..a04472f 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -6,7 +6,6 @@ apply plugin: 'com.android.application' android { compileSdkVersion rootProject.compileSdkVersion - buildToolsVersion rootProject.buildToolsVersion defaultConfig { applicationId "com.tolstykh.textviewrichdrawable" @@ -26,7 +25,8 @@ android { } dependencies { - compile "com.android.support:appcompat-v7:$rootProject.supportVersion" - compile "com.android.support:design:$rootProject.supportVersion" - compile 'com.tolstykh.textviewrichdrawable:textview-rich-drawable:0.3.2' + implementation "com.android.support:appcompat-v7:$rootProject.supportVersion" + implementation "com.android.support:design:$rootProject.supportVersion" +// implementation 'com.tolstykh.textviewrichdrawable:textview-rich-drawable:0.3.2' + implementation project(path: ':library') } diff --git a/sample/src/main/java/com/tolstykh/textviewrichdrawable/example/ChangeRuntimeFragment.java b/sample/src/main/java/com/tolstykh/textviewrichdrawable/example/ChangeRuntimeFragment.java new file mode 100644 index 0000000..832e26e --- /dev/null +++ b/sample/src/main/java/com/tolstykh/textviewrichdrawable/example/ChangeRuntimeFragment.java @@ -0,0 +1,60 @@ +package com.tolstykh.textviewrichdrawable.example; + +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.support.v4.content.ContextCompat; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.tolstykh.textviewrichdrawable.R; +import com.tolstykh.textviewrichdrawable.TextViewRichDrawable; + +/** + * * Created by rqg on 2019/1/3. + */ +public class ChangeRuntimeFragment extends Fragment { + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + return inflater.inflate(R.layout.f_runtime_change, container, false); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + final TextViewRichDrawable tvrd = view.findViewById(R.id.tv_demo); + + view.findViewById(R.id.set_top).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + tvrd.setTopDrawable(ContextCompat.getDrawable(getContext(), R.drawable.icon_shz_skrz)); + } + }); + + view.findViewById(R.id.set_bottom).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + tvrd.setBottomDrawable(ContextCompat.getDrawable(getContext(), R.drawable.icon_shz_skrz)); + } + }); + + view.findViewById(R.id.set_left).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + tvrd.setLeftDrawable(ContextCompat.getDrawable(getContext(), R.drawable.icon_shz_skrz)); + } + }); + + view.findViewById(R.id.set_right).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + tvrd.setRightDrawable(ContextCompat.getDrawable(getContext(), R.drawable.icon_shz_skrz)); + } + }); + + } +} diff --git a/sample/src/main/java/com/tolstykh/textviewrichdrawable/example/DemoPage.java b/sample/src/main/java/com/tolstykh/textviewrichdrawable/example/DemoPage.java index a2be64e..dccbc98 100644 --- a/sample/src/main/java/com/tolstykh/textviewrichdrawable/example/DemoPage.java +++ b/sample/src/main/java/com/tolstykh/textviewrichdrawable/example/DemoPage.java @@ -17,6 +17,12 @@ Fragment instantiateFragment() { Fragment instantiateFragment() { return SimpleFragment.newInstance(R.layout.f_controls_all); } + }, + RUNTIME_CHANGE(R.string.title_runtime_change) { + @Override + Fragment instantiateFragment() { + return new ChangeRuntimeFragment(); + } }; @StringRes diff --git a/sample/src/main/res/drawable-xxhdpi/icon_shz_skrz.png b/sample/src/main/res/drawable-xxhdpi/icon_shz_skrz.png new file mode 100644 index 0000000..6b4224d Binary files /dev/null and b/sample/src/main/res/drawable-xxhdpi/icon_shz_skrz.png differ diff --git a/sample/src/main/res/drawable/bg_stroke_black.xml b/sample/src/main/res/drawable/bg_stroke_black.xml new file mode 100644 index 0000000..348801c --- /dev/null +++ b/sample/src/main/res/drawable/bg_stroke_black.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/sample/src/main/res/layout/f_runtime_change.xml b/sample/src/main/res/layout/f_runtime_change.xml new file mode 100644 index 0000000..a57dbd6 --- /dev/null +++ b/sample/src/main/res/layout/f_runtime_change.xml @@ -0,0 +1,49 @@ + + + + + + +