diff options
-rw-r--r-- | gradle.properties | 2 | ||||
-rw-r--r-- | library/build.gradle | 4 | ||||
-rw-r--r-- | library/progress-proguard.txt | 6 | ||||
-rw-r--r-- | library/src/main/kotlin/ca/allanwang/kau/about/AboutActivity.kt | 33 | ||||
-rw-r--r-- | library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt | 53 | ||||
-rw-r--r-- | library/src/main/kotlin/ca/allanwang/kau/views/TextSlider.kt | 112 | ||||
-rw-r--r-- | library/src/main/kotlin/ca/allanwang/kau/views/TextSwitcherThemed.kt | 27 | ||||
-rw-r--r-- | library/src/main/res/anim/kau_slide_in_bottom.xml | 7 | ||||
-rw-r--r-- | library/src/main/res/anim/kau_slide_in_top.xml | 7 | ||||
-rw-r--r-- | library/src/main/res/anim/kau_slide_out_bottom.xml | 7 | ||||
-rw-r--r-- | library/src/main/res/anim/kau_slide_out_top.xml | 7 | ||||
-rw-r--r-- | library/src/main/res/layout/kau_activity_about.xml | 34 | ||||
-rw-r--r-- | library/src/main/res/layout/kau_activity_kpref.xml | 2 | ||||
-rw-r--r-- | library/src/main/res/values/strings_about.xml | 19 | ||||
-rw-r--r-- | library/src/main/res/values/strings_commons.xml | 2 |
15 files changed, 248 insertions, 74 deletions
diff --git a/gradle.properties b/gradle.properties index 3f64bcf..873d527 100644 --- a/gradle.properties +++ b/gradle.properties @@ -35,4 +35,4 @@ ANKO=0.10.1 RX_JAVA=2.1.0 RX_ANDROID=2.0.1 RX_BINDING=2.0.0 - +ABOUT_LIBRARIES=5.9.6 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$* { + <fields>; +} 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<Int> = 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<CharSequence?> = 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<set xmlns:android="http://schemas.android.com/apk/res/android"> + <translate + android:duration="@android:integer/config_shortAnimTime" + android:fromYDelta="100%p" + android:toYDelta="0" /> +</set>
\ 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<set xmlns:android="http://schemas.android.com/apk/res/android"> + <translate + android:duration="@android:integer/config_shortAnimTime" + android:fromYDelta="-100%p" + android:toYDelta="0" /> +</set>
\ 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<set xmlns:android="http://schemas.android.com/apk/res/android"> + <translate + android:duration="@android:integer/config_shortAnimTime" + android:fromYDelta="0" + android:toYDelta="100%p" /> +</set>
\ 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<set xmlns:android="http://schemas.android.com/apk/res/android"> + <translate + android:duration="@android:integer/config_shortAnimTime" + android:fromYDelta="0" + android:toYDelta="-100%p" /> +</set>
\ 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:id="@+id/kau_container" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <android.support.v7.widget.Toolbar + android:id="@id/kau_toolbar" + android:layout_width="0dp" + android:layout_height="?attr/actionBarSize" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + + <ca.allanwang.kau.views.TextSlider + android:id="@+id/kau_toolbar_text" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:gravity="center" + android:textAppearance="@style/TextAppearance.AppCompat.Title" /> + + </android.support.v7.widget.Toolbar> + + <android.support.v7.widget.RecyclerView + android:id="@+id/kau_recycler" + android:layout_width="0dp" + android:layout_height="0dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/kau_toolbar" /> + +</android.support.constraint.ConstraintLayout> 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"> - <ca.allanwang.kau.views.TextSwitcherThemed + <ca.allanwang.kau.views.TextSlider android:id="@+id/kau_toolbar_text" android:layout_width="wrap_content" android:layout_height="wrap_content" diff --git a/library/src/main/res/values/strings_about.xml b/library/src/main/res/values/strings_about.xml new file mode 100644 index 0000000..2c3f9a1 --- /dev/null +++ b/library/src/main/res/values/strings_about.xml @@ -0,0 +1,19 @@ +<resources xmlns:tools="http://schemas.android.com/tools"> + <string name="define_int_kau" tools:ignore="ResourceName" /> + <!-- Author section --> + <string name="library_kau_author" tools:ignore="ResourceName">Allan Wang</string> + <string name="library_kau_authorWebsite" tools:ignore="ResourceName">https://www.allanwang.ca/dev/</string> + <!-- Library section --> + <string name="library_kau_libraryName" tools:ignore="ResourceName">KAU</string> + <string name="library_kau_libraryDescription" tools:ignore="ResourceName">An extensive collection of Kotlin Android Utilities.</string> + <string name="library_kau_libraryWebsite" tools:ignore="ResourceName">https://github.com/AllanWang/KAU</string> + <string name="library_kau_libraryVersion" tools:ignore="ResourceName">1.3</string> + <!-- OpenSource section --> + <string name="library_kau_isOpenSource" tools:ignore="ResourceName">true</string> + <string name="library_kau_repositoryLink" tools:ignore="ResourceName">https://github.com/AllanWang/KAU</string> + <!-- ClassPath for autoDetect section --> + <string name="library_kau_classPath" tools:ignore="ResourceName">ca.allanwang.kau</string> + <!-- License section --> + <string name="library_kau_licenseId" tools:ignore="ResourceName">apache_2_0</string> + <!-- Custom variables section --> +</resources>
\ 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 <string name="kau_yes">Yes</string> <string name="kau_search">Search</string> <string name="kau_no_results_found">No Results Found</string> + <string name="kau_about_app">About App</string> + <string name="kau_about_x">About %s</string> </resources> |