From 1e5b600a5f6bbffa4dc8efa2991e4b833a8e4c15 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 27 Jun 2017 00:29:57 -0700 Subject: Update text slider and begin about libraries --- library/build.gradle | 4 + library/progress-proguard.txt | 6 +- .../kotlin/ca/allanwang/kau/about/AboutActivity.kt | 33 ++++++ .../kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt | 53 ++-------- .../kotlin/ca/allanwang/kau/views/TextSlider.kt | 112 +++++++++++++++++++++ .../ca/allanwang/kau/views/TextSwitcherThemed.kt | 27 ----- library/src/main/res/anim/kau_slide_in_bottom.xml | 7 ++ library/src/main/res/anim/kau_slide_in_top.xml | 7 ++ library/src/main/res/anim/kau_slide_out_bottom.xml | 7 ++ library/src/main/res/anim/kau_slide_out_top.xml | 7 ++ library/src/main/res/layout/kau_activity_about.xml | 34 +++++++ library/src/main/res/layout/kau_activity_kpref.xml | 2 +- library/src/main/res/values/strings_about.xml | 19 ++++ library/src/main/res/values/strings_commons.xml | 2 + 14 files changed, 247 insertions(+), 73 deletions(-) create mode 100644 library/src/main/kotlin/ca/allanwang/kau/about/AboutActivity.kt create mode 100644 library/src/main/kotlin/ca/allanwang/kau/views/TextSlider.kt delete mode 100644 library/src/main/kotlin/ca/allanwang/kau/views/TextSwitcherThemed.kt create mode 100644 library/src/main/res/anim/kau_slide_in_bottom.xml create mode 100644 library/src/main/res/anim/kau_slide_in_top.xml create mode 100644 library/src/main/res/anim/kau_slide_out_bottom.xml create mode 100644 library/src/main/res/anim/kau_slide_out_top.xml create mode 100644 library/src/main/res/layout/kau_activity_about.xml create mode 100644 library/src/main/res/values/strings_about.xml (limited to 'library') diff --git a/library/build.gradle b/library/build.gradle index 6984490..d4d7821 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -69,6 +69,10 @@ dependencies { compile "io.reactivex.rxjava2:rxandroid:${RX_ANDROID}" compile "com.jakewharton.rxbinding2:rxbinding-kotlin:${RX_BINDING}" compile "com.jakewharton.rxbinding2:rxbinding-appcompat-v7-kotlin:${RX_BINDING}" + + compile("com.mikepenz:aboutlibraries:${ABOUT_LIBRARIES}@aar") { + transitive = true + } } // build a jar with source files diff --git a/library/progress-proguard.txt b/library/progress-proguard.txt index 8b13789..a68e6b0 100644 --- a/library/progress-proguard.txt +++ b/library/progress-proguard.txt @@ -1 +1,5 @@ - +# About library +-keep class .R +-keep class **.R$* { + ; +} diff --git a/library/src/main/kotlin/ca/allanwang/kau/about/AboutActivity.kt b/library/src/main/kotlin/ca/allanwang/kau/about/AboutActivity.kt new file mode 100644 index 0000000..ce81c29 --- /dev/null +++ b/library/src/main/kotlin/ca/allanwang/kau/about/AboutActivity.kt @@ -0,0 +1,33 @@ +package ca.allanwang.kau.about + +import android.os.Bundle +import android.support.v7.app.AppCompatActivity +import android.support.v7.widget.RecyclerView +import android.support.v7.widget.Toolbar +import android.view.animation.Animation +import android.view.animation.AnimationUtils +import ca.allanwang.kau.R +import ca.allanwang.kau.utils.bindView +import ca.allanwang.kau.views.TextSlider + +/** + * Created by Allan Wang on 2017-06-26. + */ +open class AboutActivity : AppCompatActivity() { + + val toolbar: Toolbar by bindView(R.id.kau_toolbar) + val toolbarText: TextSlider by bindView(R.id.kau_toolbar_text) + val recycler: RecyclerView by bindView(R.id.kau_recycler) + + protected val SLIDE_IN_UP: Animation by lazy { AnimationUtils.loadAnimation(this, R.anim.kau_slide_in_top) } + protected val SLIDE_IN_DOWN: Animation by lazy { AnimationUtils.loadAnimation(this, R.anim.kau_slide_in_bottom) } + + protected val SLIDE_OUT_UP: Animation by lazy { AnimationUtils.loadAnimation(this, R.anim.kau_slide_out_top) } + protected val SLIDE_OUT_DOWN: Animation by lazy { AnimationUtils.loadAnimation(this, R.anim.kau_slide_out_bottom) } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.kau_activity_about) + + } +} \ No newline at end of file diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt index 6103e50..96b1237 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt @@ -3,17 +3,13 @@ package ca.allanwang.kau.kpref import android.os.Bundle import android.support.annotation.StringRes import android.support.constraint.ConstraintLayout -import android.support.v4.widget.TextViewCompat import android.support.v7.app.AppCompatActivity import android.support.v7.widget.RecyclerView import android.support.v7.widget.Toolbar -import android.text.TextUtils -import android.view.Gravity import android.view.View import android.view.animation.Animation import android.view.animation.AnimationUtils import android.widget.FrameLayout -import android.widget.TextView import android.widget.ViewAnimator import ca.allanwang.kau.R import ca.allanwang.kau.kpref.items.KPrefItemCore @@ -23,9 +19,8 @@ import ca.allanwang.kau.utils.resolveColor import ca.allanwang.kau.utils.statusBarColor import ca.allanwang.kau.utils.string import ca.allanwang.kau.views.RippleCanvas -import ca.allanwang.kau.views.TextSwitcherThemed +import ca.allanwang.kau.views.TextSlider import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter -import java.util.* abstract class KPrefActivity : AppCompatActivity(), KPrefActivityContract { @@ -38,19 +33,14 @@ abstract class KPrefActivity : AppCompatActivity(), KPrefActivityContract { val bgCanvas: RippleCanvas by bindView(R.id.kau_ripple) val toolbarCanvas: RippleCanvas by bindView(R.id.kau_toolbar_ripple) val toolbar: Toolbar by bindView(R.id.kau_toolbar) - val toolbarTitle: TextSwitcherThemed by bindView(R.id.kau_toolbar_text) + val toolbarTitle: TextSlider by bindView(R.id.kau_toolbar_text) val prefHolder: ViewAnimator by bindView(R.id.kau_holder) private lateinit var globalOptions: GlobalOptions - private val titleStack: Stack = Stack() var animate: Boolean = true - val isRootPref: Boolean - get() = titleStack.size == 1 - - //we can't use the same animations for both views; otherwise the durations will sync - private val SLIDE_IN_LEFT_TITLE: Animation by lazy { AnimationUtils.loadAnimation(this, R.anim.kau_slide_in_left) } - private val SLIDE_IN_RIGHT_TITLE: Animation by lazy { AnimationUtils.loadAnimation(this, R.anim.kau_slide_in_right) } - private val SLIDE_OUT_LEFT_TITLE: Animation by lazy { AnimationUtils.loadAnimation(this, R.anim.kau_slide_out_left) } - private val SLIDE_OUT_RIGHT_TITLE: Animation by lazy { AnimationUtils.loadAnimation(this, R.anim.kau_slide_out_right) } + set(value) { + field = value + toolbarTitle.animate = value + } private val SLIDE_IN_LEFT_ITEMS: Animation by lazy { AnimationUtils.loadAnimation(this, R.anim.kau_slide_in_left) } private val SLIDE_IN_RIGHT_ITEMS: Animation by lazy { AnimationUtils.loadAnimation(this, R.anim.kau_slide_in_right) } @@ -85,17 +75,6 @@ abstract class KPrefActivity : AppCompatActivity(), KPrefActivityContract { val builder = kPrefCoreAttributes() core.builder() globalOptions = GlobalOptions(core, this) - with(toolbarTitle) { - setFactory { - TextView(this@KPrefActivity).apply { - //replica of toolbar title - gravity = Gravity.START - setSingleLine() - ellipsize = TextUtils.TruncateAt.END - TextViewCompat.setTextAppearance(this, R.style.TextAppearance_AppCompat_Title) - } - } - } showNextPrefs(R.string.kau_settings, onCreateKPrefs(savedInstanceState)) } @@ -106,7 +85,6 @@ abstract class KPrefActivity : AppCompatActivity(), KPrefActivityContract { override fun showNextPrefs(@StringRes toolbarTitleRes: Int, builder: KPrefAdapterBuilder.() -> Unit) { val rv = RecyclerView(this).apply { layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT) - titleStack.push(toolbarTitleRes) setKPrefAdapter(globalOptions, builder) } with(prefHolder) { @@ -115,18 +93,10 @@ abstract class KPrefActivity : AppCompatActivity(), KPrefActivityContract { addView(rv) showNext() } - with(toolbarTitle) { - inAnimation = if (animate) SLIDE_IN_RIGHT_TITLE else null - outAnimation = if (animate) SLIDE_OUT_LEFT_TITLE else null - setText(string(titleStack.peek())) - } + toolbarTitle.setNextText(string(toolbarTitleRes)) } override fun showPrevPrefs() { - if (titleStack.size <= 1) { - KL.e("Cannot go back in KPrefActivity; already at index ${titleStack.size - 1}") - return - } val current = prefHolder.currentView with(prefHolder) { inAnimation = if (animate) SLIDE_IN_LEFT_ITEMS else null @@ -135,12 +105,7 @@ abstract class KPrefActivity : AppCompatActivity(), KPrefActivityContract { removeView(current) adapter.notifyAdapterDataSetChanged() } - titleStack.pop() - with(toolbarTitle) { - inAnimation = if (animate) SLIDE_IN_LEFT_TITLE else null - outAnimation = if (animate) SLIDE_OUT_RIGHT_TITLE else null - setText(string(titleStack.peek())) - } + toolbarTitle.setPrevText() } fun reload(vararg index: Int) { @@ -163,7 +128,7 @@ abstract class KPrefActivity : AppCompatActivity(), KPrefActivityContract { } fun backPress(): Boolean { - if (!isRootPref) { + if (!toolbarTitle.isRoot) { showPrevPrefs() return true } diff --git a/library/src/main/kotlin/ca/allanwang/kau/views/TextSlider.kt b/library/src/main/kotlin/ca/allanwang/kau/views/TextSlider.kt new file mode 100644 index 0000000..50b1848 --- /dev/null +++ b/library/src/main/kotlin/ca/allanwang/kau/views/TextSlider.kt @@ -0,0 +1,112 @@ +package ca.allanwang.kau.views + +import android.content.Context +import android.graphics.Color +import android.support.v4.widget.TextViewCompat +import android.text.TextUtils +import android.util.AttributeSet +import android.view.Gravity +import android.view.animation.Animation +import android.view.animation.AnimationUtils +import android.widget.TextSwitcher +import android.widget.TextView +import ca.allanwang.kau.R +import java.util.* + +/** + * Created by Allan Wang on 2017-06-21. + * + * Text switcher with global text color and embedded sliding animations + * Also has a stack to keep track of title changes + */ +class TextSlider @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null +) : TextSwitcher(context, attrs) { + + val titleStack: Stack = Stack() + + private val SLIDE_IN_LEFT: Animation by lazy { AnimationUtils.loadAnimation(context, R.anim.kau_slide_in_left) } + private val SLIDE_IN_RIGHT: Animation by lazy { AnimationUtils.loadAnimation(context, R.anim.kau_slide_in_right) } + private val SLIDE_IN_TOP: Animation by lazy { AnimationUtils.loadAnimation(context, R.anim.kau_slide_in_top) } + private val SLIDE_IN_BOTTOM: Animation by lazy { AnimationUtils.loadAnimation(context, R.anim.kau_slide_in_bottom) } + + private val SLIDE_OUT_LEFT: Animation by lazy { AnimationUtils.loadAnimation(context, R.anim.kau_slide_out_left) } + private val SLIDE_OUT_RIGHT: Animation by lazy { AnimationUtils.loadAnimation(context, R.anim.kau_slide_out_right) } + private val SLIDE_OUT_TOP: Animation by lazy { AnimationUtils.loadAnimation(context, R.anim.kau_slide_out_top) } + private val SLIDE_OUT_BOTTOM: Animation by lazy { AnimationUtils.loadAnimation(context, R.anim.kau_slide_out_bottom) } + + var animate: Boolean = true + var horizontal: Boolean = true + + var textColor: Int = Color.WHITE + get() = field + set(value) { + field = value + (getChildAt(0) as TextView).setTextColor(value) + (getChildAt(1) as TextView).setTextColor(value) + } + val isRoot: Boolean + get() = titleStack.size <= 1 + + override fun setText(text: CharSequence?) { + if ((currentView as TextView).text == text) return + super.setText(text) + } + + fun setTextSlideUp(text: CharSequence?) { + inAnimation = if (animate) SLIDE_IN_BOTTOM else null + outAnimation = if (animate) SLIDE_OUT_TOP else null + setText(text) + } + + fun setTextSlideDown(text: CharSequence?) { + inAnimation = if (animate) SLIDE_IN_TOP else null + outAnimation = if (animate) SLIDE_OUT_BOTTOM else null + setText(text) + } + + fun setTextSlideLeft(text: CharSequence?) { + inAnimation = if (animate) SLIDE_IN_RIGHT else null + outAnimation = if (animate) SLIDE_OUT_LEFT else null + setText(text) + } + + fun setTextSlideRight(text: CharSequence?) { + inAnimation = if (animate) SLIDE_IN_LEFT else null + outAnimation = if (animate) SLIDE_OUT_RIGHT else null + setText(text) + } + + override fun setCurrentText(text: CharSequence?) { + if (titleStack.isNotEmpty()) titleStack.pop() + titleStack.push(text) + super.setCurrentText(text) + } + + fun setNextText(text: CharSequence?) { + titleStack.push(text) + if (horizontal) setTextSlideLeft(text) else setTextSlideUp(text) + } + + /** + * Sets the text as the previous title + * No further checks are done, so be sure to verify with [isRoot] + */ + @Throws(EmptyStackException::class) + fun setPrevText() { + titleStack.pop() + val text = titleStack.peek() + if (horizontal) setTextSlideRight(text) else setTextSlideDown(text) + } + + init { + setFactory { + TextView(context).apply { + //replica of toolbar title + gravity = Gravity.START + setSingleLine() + ellipsize = TextUtils.TruncateAt.END + TextViewCompat.setTextAppearance(this, R.style.TextAppearance_AppCompat) + } + } + } +} \ No newline at end of file diff --git a/library/src/main/kotlin/ca/allanwang/kau/views/TextSwitcherThemed.kt b/library/src/main/kotlin/ca/allanwang/kau/views/TextSwitcherThemed.kt deleted file mode 100644 index bef661e..0000000 --- a/library/src/main/kotlin/ca/allanwang/kau/views/TextSwitcherThemed.kt +++ /dev/null @@ -1,27 +0,0 @@ -package ca.allanwang.kau.views - -import android.content.Context -import android.graphics.Color -import android.util.AttributeSet -import android.widget.TextSwitcher -import android.widget.TextView - -/** - * Created by Allan Wang on 2017-06-21. - */ -class TextSwitcherThemed @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null -) : TextSwitcher(context, attrs) { - - var textColor: Int = Color.WHITE - get() = field - set(value) { - field = value - (getChildAt(0) as TextView).setTextColor(value) - (getChildAt(1) as TextView).setTextColor(value) - } - - override fun setText(text: CharSequence?) { - if ((currentView as TextView).text == text) return - super.setText(text) - } -} \ No newline at end of file diff --git a/library/src/main/res/anim/kau_slide_in_bottom.xml b/library/src/main/res/anim/kau_slide_in_bottom.xml new file mode 100644 index 0000000..a07cba4 --- /dev/null +++ b/library/src/main/res/anim/kau_slide_in_bottom.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/library/src/main/res/anim/kau_slide_in_top.xml b/library/src/main/res/anim/kau_slide_in_top.xml new file mode 100644 index 0000000..8caee9b --- /dev/null +++ b/library/src/main/res/anim/kau_slide_in_top.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/library/src/main/res/anim/kau_slide_out_bottom.xml b/library/src/main/res/anim/kau_slide_out_bottom.xml new file mode 100644 index 0000000..44e7e21 --- /dev/null +++ b/library/src/main/res/anim/kau_slide_out_bottom.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/library/src/main/res/anim/kau_slide_out_top.xml b/library/src/main/res/anim/kau_slide_out_top.xml new file mode 100644 index 0000000..9f8e14c --- /dev/null +++ b/library/src/main/res/anim/kau_slide_out_top.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/library/src/main/res/layout/kau_activity_about.xml b/library/src/main/res/layout/kau_activity_about.xml new file mode 100644 index 0000000..1be7c17 --- /dev/null +++ b/library/src/main/res/layout/kau_activity_about.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + diff --git a/library/src/main/res/layout/kau_activity_kpref.xml b/library/src/main/res/layout/kau_activity_kpref.xml index 856f168..e4e7b97 100644 --- a/library/src/main/res/layout/kau_activity_kpref.xml +++ b/library/src/main/res/layout/kau_activity_kpref.xml @@ -24,7 +24,7 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> - + + + Allan Wang + https://www.allanwang.ca/dev/ + + KAU + An extensive collection of Kotlin Android Utilities. + https://github.com/AllanWang/KAU + 1.3 + + true + https://github.com/AllanWang/KAU + + ca.allanwang.kau + + apache_2_0 + + \ No newline at end of file diff --git a/library/src/main/res/values/strings_commons.xml b/library/src/main/res/values/strings_commons.xml index c678ba1..89d697e 100644 --- a/library/src/main/res/values/strings_commons.xml +++ b/library/src/main/res/values/strings_commons.xml @@ -51,4 +51,6 @@ Most resources are verbatim and x represents a formatted item Yes Search No Results Found + About App + About %s -- cgit v1.2.3