diff --git a/demo/build.gradle b/demo/build.gradle index f7064a2..b4717e9 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -22,15 +22,15 @@ android { } dependencies { - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - testCompile 'junit:junit:4.12' - compile project(':expandable-textview') - compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlinVersion" - compile "org.jetbrains.anko:anko:$ankoVersion" - compile "com.android.support:appcompat-v7:$supportLibraryVersion" - compile "com.android.support:cardview-v7:$supportLibraryVersion" + testImplementation 'junit:junit:4.12' + implementation project(':expandable-textview') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlinVersion" + implementation "org.jetbrains.anko:anko:$ankoVersion" + implementation "com.android.support:appcompat-v7:$supportLibraryVersion" + implementation "com.android.support:cardview-v7:$supportLibraryVersion" } kotlin { diff --git a/demo/src/main/AndroidManifest.xml b/demo/src/main/AndroidManifest.xml index a4f3022..47d6032 100644 --- a/demo/src/main/AndroidManifest.xml +++ b/demo/src/main/AndroidManifest.xml @@ -5,12 +5,10 @@ - diff --git a/demo/src/main/java/tm/charlie/expandabletextview/demo/JavaActivity.java b/demo/src/main/java/tm/charlie/expandabletextview/demo/JavaActivity.java index dcba930..975e317 100644 --- a/demo/src/main/java/tm/charlie/expandabletextview/demo/JavaActivity.java +++ b/demo/src/main/java/tm/charlie/expandabletextview/demo/JavaActivity.java @@ -7,8 +7,7 @@ import tm.charlie.expandabletextview.ExpandableTextView; -import static tm.charlie.expandabletextview.demo.ExtensionsKt.makeClickable; -// Generated by Kotlin +import static tm.charlie.expandabletextview.demo.ExtensionsKt.makeClickable; // Generated by Kotlin public class JavaActivity extends AppCompatActivity{ @Override @@ -16,8 +15,8 @@ protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.java_activity_main); - final ExpandableTextView expandableText = (ExpandableTextView) findViewById(R.id.expandable_textview); - final ToggleButton toggleButton = (ToggleButton) findViewById(R.id.toggle_expand); + final ExpandableTextView expandableText = findViewById(R.id.expandable_textview); + final ToggleButton toggleButton = findViewById(R.id.toggle_expand); makeClickable(expandableText, false); expandableText.setOnClickListener(new View.OnClickListener(){ diff --git a/demo/src/main/java/tm/charlie/expandabletextview/demo/KotlinActivity.kt b/demo/src/main/java/tm/charlie/expandabletextview/demo/KotlinActivity.kt index 80ef4b0..98fc2a6 100644 --- a/demo/src/main/java/tm/charlie/expandabletextview/demo/KotlinActivity.kt +++ b/demo/src/main/java/tm/charlie/expandabletextview/demo/KotlinActivity.kt @@ -2,6 +2,7 @@ package tm.charlie.expandabletextview.demo import android.graphics.Color import android.os.Bundle +import android.support.v4.content.res.ResourcesCompat import android.support.v7.app.AppCompatActivity import android.text.TextUtils.TruncateAt import android.widget.ToggleButton @@ -34,6 +35,7 @@ class KotlinActivity: AppCompatActivity() { ellipsize = TruncateAt.START textSize = 17f textColor = Color.BLACK + typeface = ResourcesCompat.getFont(context, R.font.lato_black) animationDuration = 300 makeClickable() diff --git a/demo/src/main/res/font/lato_black.ttf b/demo/src/main/res/font/lato_black.ttf new file mode 100644 index 0000000..6848db0 Binary files /dev/null and b/demo/src/main/res/font/lato_black.ttf differ diff --git a/demo/src/main/res/layout/java_activity_main.xml b/demo/src/main/res/layout/java_activity_main.xml index 412edd4..8860f65 100644 --- a/demo/src/main/res/layout/java_activity_main.xml +++ b/demo/src/main/res/layout/java_activity_main.xml @@ -21,6 +21,7 @@ android:layout_height="wrap_content" android:layout_margin="8dp" android:ellipsize="end" + android:fontFamily="@font/lato_black" android:maxLines="3" android:text="@string/lipsum_long" android:textColor="@android:color/black" diff --git a/demo/src/main/res/mipmap-hdpi/ic_launcher.png b/demo/src/main/res/mipmap-hdpi/ic_launcher.png index cde69bc..4032139 100644 Binary files a/demo/src/main/res/mipmap-hdpi/ic_launcher.png and b/demo/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/demo/src/main/res/mipmap-hdpi/ic_launcher_round.png b/demo/src/main/res/mipmap-hdpi/ic_launcher_round.png deleted file mode 100644 index 9a078e3..0000000 Binary files a/demo/src/main/res/mipmap-hdpi/ic_launcher_round.png and /dev/null differ diff --git a/demo/src/main/res/mipmap-mdpi/ic_launcher.png b/demo/src/main/res/mipmap-mdpi/ic_launcher.png index c133a0c..84923ea 100644 Binary files a/demo/src/main/res/mipmap-mdpi/ic_launcher.png and b/demo/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/demo/src/main/res/mipmap-mdpi/ic_launcher_round.png b/demo/src/main/res/mipmap-mdpi/ic_launcher_round.png deleted file mode 100644 index efc028a..0000000 Binary files a/demo/src/main/res/mipmap-mdpi/ic_launcher_round.png and /dev/null differ diff --git a/demo/src/main/res/mipmap-xhdpi/ic_launcher.png b/demo/src/main/res/mipmap-xhdpi/ic_launcher.png index bfa42f0..b027d70 100644 Binary files a/demo/src/main/res/mipmap-xhdpi/ic_launcher.png and b/demo/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/demo/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/demo/src/main/res/mipmap-xhdpi/ic_launcher_round.png deleted file mode 100644 index 3af2608..0000000 Binary files a/demo/src/main/res/mipmap-xhdpi/ic_launcher_round.png and /dev/null differ diff --git a/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png b/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png index 324e72c..f8fa70b 100644 Binary files a/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png and b/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/demo/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/demo/src/main/res/mipmap-xxhdpi/ic_launcher_round.png deleted file mode 100644 index 9bec2e6..0000000 Binary files a/demo/src/main/res/mipmap-xxhdpi/ic_launcher_round.png and /dev/null differ diff --git a/demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png index aee44e1..95d4980 100644 Binary files a/demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png and b/demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/demo/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/demo/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png deleted file mode 100644 index 34947cd..0000000 Binary files a/demo/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png and /dev/null differ diff --git a/expandable-textview/build.gradle b/expandable-textview/build.gradle index 9279d54..64c8f3a 100644 --- a/expandable-textview/build.gradle +++ b/expandable-textview/build.gradle @@ -22,8 +22,9 @@ android { } dependencies { - compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlinVersion" - compile "org.jetbrains.anko:anko:$ankoVersion" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlinVersion" + implementation "org.jetbrains.anko:anko:$ankoVersion" + implementation "com.android.support:appcompat-v7:$supportLibraryVersion" } // Configs for publishing diff --git a/expandable-textview/src/main/java/tm/charlie/expandabletextview/ExpandableTextView.kt b/expandable-textview/src/main/java/tm/charlie/expandabletextview/ExpandableTextView.kt index ee27d8b..856c717 100644 --- a/expandable-textview/src/main/java/tm/charlie/expandabletextview/ExpandableTextView.kt +++ b/expandable-textview/src/main/java/tm/charlie/expandabletextview/ExpandableTextView.kt @@ -6,13 +6,13 @@ import android.animation.ValueAnimator import android.content.Context import android.os.Parcel import android.os.Parcelable +import android.support.v7.widget.AppCompatTextView import android.util.AttributeSet import android.view.View.MeasureSpec.makeMeasureSpec import android.view.animation.AccelerateDecelerateInterpolator -import android.widget.TextView import org.jetbrains.anko.wrapContent -open class ExpandableTextView: TextView { +open class ExpandableTextView: AppCompatTextView { constructor(context: Context): super(context) { initAttrs() } @@ -26,11 +26,6 @@ open class ExpandableTextView: TextView { initAttrs(attrs, defStyleAttr) } - constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) - : super(context, attrs, defStyleAttr, defStyleRes) { - initAttrs(attrs, defStyleAttr, defStyleRes) - } - // private properties private var collapsedHeight: Int = 0 private var expandedHeight: Int = 0 diff --git a/expandable-textview/src/main/java/tm/charlie/expandabletextview/Extensions.kt b/expandable-textview/src/main/java/tm/charlie/expandabletextview/Extensions.kt index 3049c44..4977bb9 100644 --- a/expandable-textview/src/main/java/tm/charlie/expandabletextview/Extensions.kt +++ b/expandable-textview/src/main/java/tm/charlie/expandabletextview/Extensions.kt @@ -1,13 +1,19 @@ package tm.charlie.expandabletextview +import android.support.v7.widget.AppCompatTextView import android.view.ViewManager import android.widget.TextView import org.jetbrains.anko.AnkoViewDslMarker import org.jetbrains.anko.custom.ankoView -inline fun ViewManager.expandableTextView(init: (@AnkoViewDslMarker ExpandableTextView).() -> Unit) = expandableTextView("", init) +// Public extensions +inline fun ViewManager.expandableTextView(init: (@AnkoViewDslMarker ExpandableTextView).() -> Unit) = expandableTextView("", init) inline fun ViewManager.expandableTextView(text: String = "", init: (@AnkoViewDslMarker ExpandableTextView).() -> Unit) = ankoView(::ExpandableTextView, 0) { setText(text); init() } -inline val TextView.isEllipsized get() = layout.getEllipsisCount(lineCount - 1) > 0 \ No newline at end of file +// Internal extensions +internal inline fun ViewManager.textViewCompat(text: CharSequence?, init: (@AnkoViewDslMarker AppCompatTextView).() -> Unit) + = ankoView(::AppCompatTextView, 0, { setText(text); init() }) + +internal inline val TextView.isEllipsized get() = layout.getEllipsisCount(lineCount - 1) > 0 \ No newline at end of file