diff options
Diffstat (limited to 'core/src/main')
36 files changed, 357 insertions, 104 deletions
diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt index 7f4399d..1474c1a 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt @@ -1,5 +1,6 @@ package ca.allanwang.kau.swipe +import android.annotation.SuppressLint import android.app.Activity import android.content.Context import android.graphics.Canvas @@ -37,6 +38,7 @@ class SwipeBackLayout @JvmOverloads constructor(context: Context, attrs: Attribu } var activity: Activity? = null + @SuppressLint("NewApi") set(value) { field = value if (value != null) { @@ -81,6 +83,7 @@ class SwipeBackLayout @JvmOverloads constructor(context: Context, attrs: Attribu val chromeFadeListener: SwipeListener by lazy { object : SwipeListener { + @SuppressLint("NewApi") override fun onScroll(percent: Float, px: Int, edgeFlag: Int) { if (!transitionSystemBars) return activity?.apply { diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/SimpleRippleDrawable.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/SimpleRippleDrawable.kt index 30c8edd..b92b222 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/ui/SimpleRippleDrawable.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/ui/SimpleRippleDrawable.kt @@ -3,7 +3,9 @@ package ca.allanwang.kau.ui import android.content.res.ColorStateList import android.graphics.drawable.ColorDrawable import android.graphics.drawable.RippleDrawable +import android.os.Build import android.support.annotation.ColorInt +import android.support.annotation.RequiresApi import ca.allanwang.kau.utils.adjustAlpha /** @@ -11,6 +13,7 @@ import ca.allanwang.kau.utils.adjustAlpha * * Tries to mimic a standard ripple, given the foreground and background colors */ +@RequiresApi(Build.VERSION_CODES.LOLLIPOP) fun createSimpleRippleDrawable(@ColorInt foregroundColor: Int, @ColorInt backgroundColor: Int): RippleDrawable { val states = ColorStateList(arrayOf(intArrayOf()), intArrayOf(foregroundColor)) val content = ColorDrawable(backgroundColor) diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt index cd6e089..54aeaff 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt @@ -39,13 +39,17 @@ fun Activity.finishSlideOut() { } inline var Activity.navigationBarColor: Int + @SuppressLint("NewApi") get() = if (buildIsLollipopAndUp) window.navigationBarColor else Color.BLACK + @SuppressLint("NewApi") set(value) { if (buildIsLollipopAndUp) window.navigationBarColor = value } inline var Activity.statusBarColor: Int + @SuppressLint("NewApi") get() = if (buildIsLollipopAndUp) window.statusBarColor else Color.BLACK + @SuppressLint("NewApi") set(value) { if (buildIsLollipopAndUp) window.statusBarColor = value } diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/AnimHolder.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/AnimHolder.kt index 3db8b9c..2767f04 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/AnimHolder.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/AnimHolder.kt @@ -1,5 +1,7 @@ package ca.allanwang.kau.utils +import android.os.Build +import android.support.annotation.RequiresApi import ca.allanwang.kau.kotlin.lazyInterpolator /** @@ -9,6 +11,7 @@ import ca.allanwang.kau.kotlin.lazyInterpolator */ object AnimHolder { + @RequiresApi(Build.VERSION_CODES.LOLLIPOP) val fastOutSlowInInterpolator = lazyInterpolator(android.R.interpolator.fast_out_linear_in) val decelerateInterpolator = lazyInterpolator(android.R.interpolator.decelerate_cubic) diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt index bbde077..ed4b7bd 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt @@ -2,12 +2,12 @@ package ca.allanwang.kau.utils import android.animation.Animator import android.animation.AnimatorListenerAdapter +import android.annotation.SuppressLint import android.support.annotation.StringRes import android.view.View import android.view.ViewAnimationUtils import android.view.animation.Animation import android.view.animation.AnimationUtils -import android.view.animation.DecelerateInterpolator import android.widget.TextView /** @@ -15,33 +15,8 @@ import android.widget.TextView * * Animation extension functions for Views */ -@KauUtils fun View.rootCircularReveal(x: Int = 0, y: Int = 0, duration: Long = 500L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) { - this.addOnLayoutChangeListener(object : View.OnLayoutChangeListener { - override @KauUtils fun onLayoutChange(v: View, left: Int, top: Int, right: Int, bottom: Int, oldLeft: Int, oldTop: Int, - oldRight: Int, oldBottom: Int) { - v.removeOnLayoutChangeListener(this) - var x2 = x - var y2 = y - if (x2 > right) x2 = 0 - if (y2 > bottom) y2 = 0 - val radius = Math.hypot(Math.max(x2, right - x2).toDouble(), Math.max(y2, bottom - y2).toDouble()).toInt() - val reveal = ViewAnimationUtils.createCircularReveal(v, x2, y2, 0f, radius.toFloat()) - reveal.interpolator = DecelerateInterpolator(1f) - reveal.duration = duration - reveal.addListener(object : AnimatorListenerAdapter() { - override @KauUtils fun onAnimationStart(animation: Animator?) { - visible() - onStart?.invoke() - } - - override @KauUtils fun onAnimationEnd(animation: Animator?) = onFinish?.invoke() ?: Unit - override @KauUtils fun onAnimationCancel(animation: Animator?) = onFinish?.invoke() ?: Unit - }) - reveal.start() - } - }) -} +@SuppressLint("NewApi") @KauUtils fun View.circularReveal(x: Int = 0, y: Int = 0, offset: Long = 0L, radius: Float = -1.0f, duration: Long = 500L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) { if (!isAttachedToWindow) { onStart?.invoke() @@ -49,10 +24,11 @@ import android.widget.TextView onFinish?.invoke() return } - var r = radius - if (r < 0.0f) { - r = Math.max(Math.hypot(x.toDouble(), y.toDouble()), Math.hypot((width - x.toDouble()), (height - y.toDouble()))).toFloat() - } + if (!buildIsLollipopAndUp) return fadeIn(offset, duration, onStart, onFinish) + + val r = if (radius >= 0) radius + else Math.max(Math.hypot(x.toDouble(), y.toDouble()), Math.hypot((width - x.toDouble()), (height - y.toDouble()))).toFloat() + val anim = ViewAnimationUtils.createCircularReveal(this, x, y, 0f, r).setDuration(duration) anim.startDelay = offset anim.addListener(object : AnimatorListenerAdapter() { @@ -67,6 +43,7 @@ import android.widget.TextView anim.start() } +@SuppressLint("NewApi") @KauUtils fun View.circularHide(x: Int = 0, y: Int = 0, offset: Long = 0L, radius: Float = -1.0f, duration: Long = 500L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) { if (!isAttachedToWindow) { onStart?.invoke() @@ -74,10 +51,11 @@ import android.widget.TextView onFinish?.invoke() return } - var r = radius - if (r < 0.0f) { - r = Math.max(Math.hypot(x.toDouble(), y.toDouble()), Math.hypot((width - x.toDouble()), (height - y.toDouble()))).toFloat() - } + if (!buildIsLollipopAndUp) return fadeOut(offset, duration, onStart, onFinish) + + val r = if (radius >= 0) radius + else Math.max(Math.hypot(x.toDouble(), y.toDouble()), Math.hypot((width - x.toDouble()), (height - y.toDouble()))).toFloat() + val anim = ViewAnimationUtils.createCircularReveal(this, x, y, r, 0f).setDuration(duration) anim.startDelay = offset anim.addListener(object : AnimatorListenerAdapter() { @@ -100,20 +78,18 @@ import android.widget.TextView onFinish?.invoke() return } - if (isAttachedToWindow) { - val anim = AnimationUtils.loadAnimation(context, android.R.anim.fade_in) - anim.startOffset = offset - anim.duration = duration - anim.setAnimationListener(object : Animation.AnimationListener { - override @KauUtils fun onAnimationRepeat(animation: Animation?) {} - override @KauUtils fun onAnimationEnd(animation: Animation?) = onFinish?.invoke() ?: Unit - override @KauUtils fun onAnimationStart(animation: Animation?) { - visible() - onStart?.invoke() - } - }) - startAnimation(anim) - } + val anim = AnimationUtils.loadAnimation(context, android.R.anim.fade_in) + anim.startOffset = offset + anim.duration = duration + anim.setAnimationListener(object : Animation.AnimationListener { + override @KauUtils fun onAnimationRepeat(animation: Animation?) {} + override @KauUtils fun onAnimationEnd(animation: Animation?) = onFinish?.invoke() ?: Unit + override @KauUtils fun onAnimationStart(animation: Animation?) { + visible() + onStart?.invoke() + } + }) + startAnimation(anim) } @KauUtils fun View.fadeOut(offset: Long = 0L, duration: Long = 200L, onStart: (() -> Unit)? = null, onFinish: (() -> Unit)? = null) { diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/Const.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/Const.kt index 9fcc7e7..f267a60 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/Const.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/Const.kt @@ -8,4 +8,7 @@ const val ANDROID_NAMESPACE = "http://schemas.android.com/apk/res/android" const val KAU_LEFT = 1 const val KAU_TOP = 2 const val KAU_RIGHT = 4 -const val KAU_BOTTOM = 8
\ No newline at end of file +const val KAU_BOTTOM = 8 +const val KAU_HORIZONTAL = KAU_LEFT and KAU_RIGHT +const val KAU_VERTICAL = KAU_TOP and KAU_BOTTOM +const val KAU_ALL = KAU_HORIZONTAL and KAU_VERTICAL
\ No newline at end of file diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt index a8e0715..bf30a91 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt @@ -1,5 +1,6 @@ package ca.allanwang.kau.utils +import android.annotation.SuppressLint import android.app.Activity import android.app.ActivityOptions import android.content.ClipData @@ -25,6 +26,7 @@ import com.afollestad.materialdialogs.MaterialDialog /** * Created by Allan Wang on 2017-06-03. */ +@SuppressLint("NewApi") fun Context.startActivity( clazz: Class<out Activity>, clearStack: Boolean = false, @@ -34,7 +36,9 @@ fun Context.startActivity( val intent = (Intent(this, clazz)) if (clearStack) intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK) intent.intentBuilder() - val fullBundle = if (transition && this is Activity) ActivityOptions.makeSceneTransitionAnimation(this).toBundle() else Bundle() + val fullBundle = if (transition && this is Activity && buildIsLollipopAndUp) + ActivityOptions.makeSceneTransitionAnimation(this).toBundle() + else Bundle() if (transition && this !is Activity) KL.d("Cannot make scene transition when context is not an instance of an Activity") if (bundle != null) fullBundle.putAll(bundle) ContextCompat.startActivity(this, intent, if (fullBundle.isEmpty) null else fullBundle) @@ -97,7 +101,11 @@ inline fun Context.drawable(@DrawableRes id: Int): Drawable = ContextCompat.getD inline fun Context.drawable(@DrawableRes id: Int, fallback: Drawable?): Drawable? = if (id > 0) drawable(id) else fallback inline fun Context.interpolator(@InterpolatorRes id: Int) = AnimationUtils.loadInterpolator(this, id) inline fun Context.animation(@AnimRes id: Int) = AnimationUtils.loadAnimation(this, id) -inline fun Context.plural(@PluralsRes id: Int, quantity: Number) = resources.getQuantityString(id, quantity.toInt()) +/** + * Returns plural form of res. The quantity is also passed to the formatter as an int + */ +inline fun Context.plural(@PluralsRes id: Int, quantity: Number) + = resources.getQuantityString(id, quantity.toInt(), quantity.toInt()) //Attr retrievers fun Context.resolveColor(@AttrRes attr: Int, fallback: Int = 0): Int { diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt index 03a1605..4c71945 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt @@ -13,8 +13,7 @@ import com.mikepenz.iconics.typeface.IIcon */ @KauUtils fun IIcon.toDrawable(c: Context, sizeDp: Int = 24, @ColorInt color: Int = Color.WHITE, builder: IconicsDrawable.() -> Unit = {}): Drawable { val state = ColorStateList.valueOf(color) - val icon = IconicsDrawable(c).icon(this).sizeDp(sizeDp) - icon.setTintList(state) + val icon = IconicsDrawable(c).icon(this).sizeDp(sizeDp).color(state) icon.builder() return icon }
\ No newline at end of file diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt index 89d64e5..36bcc93 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt @@ -30,12 +30,14 @@ import android.os.Build } } -inline val buildIsLollipopAndUp: Boolean - get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP - inline val buildIsMarshmallowAndUp: Boolean + get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M +inline val buildIsLollipopAndUp: Boolean + @SuppressWarnings("NewApi") + get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP + inline val buildIsNougatAndUp: Boolean get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/TransitionUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/TransitionUtils.kt index 9e668d0..fa062f7 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/TransitionUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/TransitionUtils.kt @@ -1,11 +1,19 @@ package ca.allanwang.kau.utils -import android.support.transition.Transition -import android.support.transition.TransitionSet +import android.os.Build +import android.support.annotation.RequiresApi +import android.support.annotation.TransitionRes +import android.support.transition.AutoTransition +import android.support.transition.TransitionInflater +import android.support.transition.TransitionManager +import android.support.transition.Transition as SupportTransition +import android.transition.Transition +import android.view.ViewGroup /** * Created by Allan Wang on 2017-06-24. */ +@RequiresApi(Build.VERSION_CODES.LOLLIPOP) class TransitionEndListener(val onEnd: (transition: Transition) -> Unit) : Transition.TransitionListener { override fun onTransitionEnd(transition: Transition) = onEnd(transition) override fun onTransitionResume(transition: Transition) {} @@ -14,6 +22,35 @@ class TransitionEndListener(val onEnd: (transition: Transition) -> Unit) : Trans override fun onTransitionStart(transition: Transition) {} } -@KauUtils fun TransitionSet.addEndListener(onEnd: (transition: Transition) -> Unit) { +@RequiresApi(Build.VERSION_CODES.LOLLIPOP) +@KauUtils fun Transition.addEndListener(onEnd: (transition: Transition) -> Unit) { addListener(TransitionEndListener(onEnd)) +} + +@RequiresApi(Build.VERSION_CODES.LOLLIPOP) +class SupportTransitionEndListener(val onEnd: (transition: SupportTransition) -> Unit) : SupportTransition.TransitionListener { + override fun onTransitionEnd(transition: SupportTransition) = onEnd(transition) + override fun onTransitionResume(transition: SupportTransition) {} + override fun onTransitionPause(transition: SupportTransition) {} + override fun onTransitionCancel(transition: SupportTransition) {} + override fun onTransitionStart(transition: SupportTransition) {} +} + +@RequiresApi(Build.VERSION_CODES.LOLLIPOP) +@KauUtils fun SupportTransition.addEndListener(onEnd: (transition: SupportTransition) -> Unit) { + addListener(SupportTransitionEndListener(onEnd)) +} + +@KauUtils fun ViewGroup.transitionAuto(builder: AutoTransition.() -> Unit = {}) { + if (!buildIsLollipopAndUp) return + val transition = AutoTransition() + transition.builder() + TransitionManager.beginDelayedTransition(this, transition) +} + +@KauUtils fun ViewGroup.transitionDelayed(@TransitionRes id: Int, builder: android.support.transition.Transition.() -> Unit = {}) { + if (!buildIsLollipopAndUp) return + val transition = TransitionInflater.from(context).inflateTransition(id) + transition.builder() + TransitionManager.beginDelayedTransition(this, transition) }
\ No newline at end of file diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt index 59ae204..ead2cb7 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt @@ -5,10 +5,8 @@ package ca.allanwang.kau.utils import android.animation.ValueAnimator import android.content.Context import android.graphics.Color -import android.support.annotation.ColorInt -import android.support.annotation.ColorRes -import android.support.annotation.StringRes -import android.support.annotation.TransitionRes +import android.os.Build +import android.support.annotation.* import android.support.design.widget.FloatingActionButton import android.support.design.widget.Snackbar import android.support.design.widget.TextInputEditText @@ -93,30 +91,98 @@ fun FloatingActionButton.hideIf(hide: Boolean) = if (hide) hide() else show() /** * Set left margin to a value in px */ -@KauUtils fun View.updateLeftMargin(margin: Int) = updateMargins(margin, KAU_LEFT) +@KauUtils fun View.setMarginLeft(margin: Int) = setMargins(margin, KAU_LEFT) /** * Set top margin to a value in px */ -@KauUtils fun View.updateTopMargin(margin: Int) = updateMargins(margin, KAU_TOP) +@KauUtils fun View.setMarginTop(margin: Int) = setMargins(margin, KAU_TOP) /** * Set right margin to a value in px */ -@KauUtils fun View.updateRightMargin(margin: Int) = updateMargins(margin, KAU_RIGHT) +@KauUtils fun View.setMarginRight(margin: Int) = setMargins(margin, KAU_RIGHT) /** * Set bottom margin to a value in px */ -@KauUtils fun View.updateBottomMargin(margin: Int) = updateMargins(margin, KAU_BOTTOM) +@KauUtils fun View.setMarginBottom(margin: Int) = setMargins(margin, KAU_BOTTOM) -@KauUtils private fun View.updateMargins(margin: Int, flag: Int) { - val p = (layoutParams as? ViewGroup.MarginLayoutParams) ?: return +/** + * Set left and right margins to a value in px + */ +@KauUtils fun View.setMarginHorizontal(margin: Int) = setMargins(margin, KAU_HORIZONTAL) + +/** + * Set top and bottom margins to a value in px + */ +@KauUtils fun View.setMarginVertical(margin: Int) = setMargins(margin, KAU_VERTICAL) + +/** + * Set all margins to a value in px + */ +@KauUtils fun View.setMargin(margin: Int) = setMargins(margin, KAU_ALL) + +/** + * Base margin setter + * returns true if setting is successful, false otherwise + */ +@KauUtils private fun View.setMargins(margin: Int, flag: Int): Boolean { + val p = (layoutParams as? ViewGroup.MarginLayoutParams) ?: return false p.setMargins( - if (flag == KAU_LEFT) margin else p.leftMargin, - if (flag == KAU_TOP) margin else p.topMargin, - if (flag == KAU_RIGHT) margin else p.rightMargin, - if (flag == KAU_BOTTOM) margin else p.bottomMargin + if (flag and KAU_LEFT > 0) margin else p.leftMargin, + if (flag and KAU_TOP > 0) margin else p.topMargin, + if (flag and KAU_RIGHT > 0) margin else p.rightMargin, + if (flag and KAU_BOTTOM > 0) margin else p.bottomMargin + ) + requestLayout() + return true +} + +/** + * Set left padding to a value in px + */ +@KauUtils fun View.setPaddingLeft(padding: Int) = setPadding(padding, KAU_LEFT) + +/** + * Set top padding to a value in px + */ +@KauUtils fun View.setPaddingTop(padding: Int) = setPadding(padding, KAU_TOP) + +/** + * Set right padding to a value in px + */ +@KauUtils fun View.setPaddingRight(padding: Int) = setPadding(padding, KAU_RIGHT) + +/** + * Set bottom padding to a value in px + */ +@KauUtils fun View.setPaddingBottom(padding: Int) = setPadding(padding, KAU_BOTTOM) + +/** + * Set left and right padding to a value in px + */ +@KauUtils fun View.setPaddingHorizontal(padding: Int) = setPadding(padding, KAU_HORIZONTAL) + +/** + * Set top and bottom padding to a value in px + */ +@KauUtils fun View.setPaddingVertical(padding: Int) = setPadding(padding, KAU_VERTICAL) + +/** + * Set all padding to a value in px + */ +@KauUtils fun View.setPadding(padding: Int) = setPadding(padding, KAU_ALL) + +/** + * Base padding setter + */ +@KauUtils private fun View.setPadding(padding: Int, flag: Int) { + setPadding( + if (flag and KAU_LEFT > 0) padding else paddingLeft, + if (flag and KAU_TOP > 0) padding else paddingTop, + if (flag and KAU_RIGHT > 0) padding else paddingRight, + if (flag and KAU_BOTTOM > 0) padding else paddingBottom ) requestLayout() } @@ -131,18 +197,8 @@ fun FloatingActionButton.hideIf(hide: Boolean) = if (hide) hide() else show() (context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).showSoftInput(this, InputMethodManager.SHOW_IMPLICIT) } -@KauUtils fun ViewGroup.transitionAuto(builder: AutoTransition.() -> Unit = {}) { - val transition = AutoTransition() - transition.builder() - TransitionManager.beginDelayedTransition(this, transition) -} - -@KauUtils fun ViewGroup.transitionDelayed(@TransitionRes id: Int, builder: Transition.() -> Unit = {}) { - val transition = TransitionInflater.from(context).inflateTransition(id) - transition.builder() - TransitionManager.beginDelayedTransition(this, transition) -} +@RequiresApi(Build.VERSION_CODES.LOLLIPOP) @KauUtils fun View.setRippleBackground(@ColorInt foregroundColor: Int, @ColorInt backgroundColor: Int) { background = createSimpleRippleDrawable(foregroundColor, backgroundColor) } @@ -192,4 +248,22 @@ inline fun FloatingActionButton.transition(crossinline action: FloatingActionBut start() } } +} + +/** + * Attaches a listener to the recyclerview to hide the fab when it is scrolling downwards + * The fab will reappear when scrolling has stopped or if the user scrolls up + */ +fun FloatingActionButton.hideOnDownwardsScroll(recycler: RecyclerView) { + recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() { + + override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { + if (newState == android.support.v7.widget.RecyclerView.SCROLL_STATE_IDLE && !isShown) show(); + } + + override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { + if (dy > 0 && isShown) hide() + else if (dy < 0 && isHidden) show() + } + }) }
\ No newline at end of file diff --git a/core/src/main/res/anim/kau_fade_in.xml b/core/src/main/res-public/anim/kau_fade_in.xml index 03312a2..03312a2 100644 --- a/core/src/main/res/anim/kau_fade_in.xml +++ b/core/src/main/res-public/anim/kau_fade_in.xml diff --git a/core/src/main/res/anim/kau_fade_out.xml b/core/src/main/res-public/anim/kau_fade_out.xml index 322befc..322befc 100644 --- a/core/src/main/res/anim/kau_fade_out.xml +++ b/core/src/main/res-public/anim/kau_fade_out.xml diff --git a/core/src/main/res/anim/kau_slide_in_bottom.xml b/core/src/main/res-public/anim/kau_slide_in_bottom.xml index a07cba4..a07cba4 100644 --- a/core/src/main/res/anim/kau_slide_in_bottom.xml +++ b/core/src/main/res-public/anim/kau_slide_in_bottom.xml diff --git a/core/src/main/res/anim/kau_slide_in_left.xml b/core/src/main/res-public/anim/kau_slide_in_left.xml index 828bdae..828bdae 100644 --- a/core/src/main/res/anim/kau_slide_in_left.xml +++ b/core/src/main/res-public/anim/kau_slide_in_left.xml diff --git a/core/src/main/res/anim/kau_slide_in_right.xml b/core/src/main/res-public/anim/kau_slide_in_right.xml index 0f9fbce..0f9fbce 100644 --- a/core/src/main/res/anim/kau_slide_in_right.xml +++ b/core/src/main/res-public/anim/kau_slide_in_right.xml diff --git a/core/src/main/res/anim/kau_slide_in_top.xml b/core/src/main/res-public/anim/kau_slide_in_top.xml index 8caee9b..8caee9b 100644 --- a/core/src/main/res/anim/kau_slide_in_top.xml +++ b/core/src/main/res-public/anim/kau_slide_in_top.xml diff --git a/core/src/main/res/anim/kau_slide_out_bottom.xml b/core/src/main/res-public/anim/kau_slide_out_bottom.xml index 44e7e21..44e7e21 100644 --- a/core/src/main/res/anim/kau_slide_out_bottom.xml +++ b/core/src/main/res-public/anim/kau_slide_out_bottom.xml diff --git a/core/src/main/res/anim/kau_slide_out_left.xml b/core/src/main/res-public/anim/kau_slide_out_left.xml index 6fab33e..6fab33e 100644 --- a/core/src/main/res/anim/kau_slide_out_left.xml +++ b/core/src/main/res-public/anim/kau_slide_out_left.xml diff --git a/core/src/main/res/anim/kau_slide_out_right.xml b/core/src/main/res-public/anim/kau_slide_out_right.xml index 9322741..9322741 100644 --- a/core/src/main/res/anim/kau_slide_out_right.xml +++ b/core/src/main/res-public/anim/kau_slide_out_right.xml diff --git a/core/src/main/res/anim/kau_slide_out_right_top.xml b/core/src/main/res-public/anim/kau_slide_out_right_top.xml index 5b63474..5b63474 100644 --- a/core/src/main/res/anim/kau_slide_out_right_top.xml +++ b/core/src/main/res-public/anim/kau_slide_out_right_top.xml diff --git a/core/src/main/res/anim/kau_slide_out_top.xml b/core/src/main/res-public/anim/kau_slide_out_top.xml index 9f8e14c..9f8e14c 100644 --- a/core/src/main/res/anim/kau_slide_out_top.xml +++ b/core/src/main/res-public/anim/kau_slide_out_top.xml diff --git a/core/src/main/res-public/drawable-v21/kau_selectable_white.xml b/core/src/main/res-public/drawable-v21/kau_selectable_white.xml new file mode 100644 index 0000000..942f149 --- /dev/null +++ b/core/src/main/res-public/drawable-v21/kau_selectable_white.xml @@ -0,0 +1,6 @@ +<ripple xmlns:android="http://schemas.android.com/apk/res/android" + android:color="#40ffffff"> + <item android:id="@android:id/mask"> + <color android:color="@android:color/white" /> + </item> +</ripple>
\ No newline at end of file diff --git a/core/src/main/res-public/drawable/kau_selectable_white.xml b/core/src/main/res-public/drawable/kau_selectable_white.xml new file mode 100644 index 0000000..5738478 --- /dev/null +++ b/core/src/main/res-public/drawable/kau_selectable_white.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> + <item> + <selector> + <item android:state_activated="true"> + <color android:color="#40ffffff" /> + </item> + <item> + <color android:color="@android:color/transparent" /> + </item> + </selector> + </item> +</layer-list>
\ No newline at end of file diff --git a/core/src/main/res/drawable/kau_transparent.xml b/core/src/main/res-public/drawable/kau_transparent.xml index 399a46b..399a46b 100644 --- a/core/src/main/res/drawable/kau_transparent.xml +++ b/core/src/main/res-public/drawable/kau_transparent.xml diff --git a/core/src/main/res/transition/kau_enter_slide_bottom.xml b/core/src/main/res-public/transition-v21/kau_enter_slide_bottom.xml index 575e189..575e189 100644 --- a/core/src/main/res/transition/kau_enter_slide_bottom.xml +++ b/core/src/main/res-public/transition-v21/kau_enter_slide_bottom.xml diff --git a/core/src/main/res/transition/kau_enter_slide_top.xml b/core/src/main/res-public/transition-v21/kau_enter_slide_top.xml index 8cf613b..8cf613b 100644 --- a/core/src/main/res/transition/kau_enter_slide_top.xml +++ b/core/src/main/res-public/transition-v21/kau_enter_slide_top.xml diff --git a/core/src/main/res/transition/kau_exit_slide_bottom.xml b/core/src/main/res-public/transition-v21/kau_exit_slide_bottom.xml index e0967ec..e0967ec 100644 --- a/core/src/main/res/transition/kau_exit_slide_bottom.xml +++ b/core/src/main/res-public/transition-v21/kau_exit_slide_bottom.xml diff --git a/core/src/main/res/transition/kau_exit_slide_top.xml b/core/src/main/res-public/transition-v21/kau_exit_slide_top.xml index a9849c0..a9849c0 100644 --- a/core/src/main/res/transition/kau_exit_slide_top.xml +++ b/core/src/main/res-public/transition-v21/kau_exit_slide_top.xml diff --git a/core/src/main/res/values/dimens.xml b/core/src/main/res-public/values/dimens.xml index b7c237a..efc7598 100644 --- a/core/src/main/res/values/dimens.xml +++ b/core/src/main/res-public/values/dimens.xml @@ -20,14 +20,13 @@ <dimen name="kau_spacing_large">32dp</dimen> <dimen name="kau_spacing_xlarge">48dp</dimen> <dimen name="kau_spacing_huge">64dp</dimen> + <dimen name="kau_padding_small">8dp</dimen> <dimen name="kau_padding_normal">16dp</dimen> <dimen name="kau_padding_large">24dp</dimen> <dimen name="kau_fab_size">56dp</dimen> <dimen name="kau_fab_radius">28dp</dimen> <dimen name="kau_display_4_text_size">112sp</dimen> - <dimen name="kau_about_header_height">224dp</dimen> - <!-- avatar should be a 40dp asset in a 48dp touch target & optically aligned with standard padding --> <dimen name="kau_avatar_size">40dp</dimen> <dimen name="kau_avatar_bounds">48dp</dimen> diff --git a/core/src/main/res-public/values/public.xml b/core/src/main/res-public/values/public.xml new file mode 100644 index 0000000..7057f1f --- /dev/null +++ b/core/src/main/res-public/values/public.xml @@ -0,0 +1,111 @@ +<resources xmlns:tools='http://schemas.android.com/tools' tools:ignore='ResourceName'> +<!-- AUTO-GENERATED FILE. DO NOT MODIFY. public.xml is generated by the generatepublicxml gradle task --> + <public name='kau_fade_in' type='anim' /> + <public name='kau_fade_out' type='anim' /> + <public name='kau_slide_in_bottom' type='anim' /> + <public name='kau_slide_in_left' type='anim' /> + <public name='kau_slide_in_right' type='anim' /> + <public name='kau_slide_in_top' type='anim' /> + <public name='kau_slide_out_bottom' type='anim' /> + <public name='kau_slide_out_left' type='anim' /> + <public name='kau_slide_out_right' type='anim' /> + <public name='kau_slide_out_right_top' type='anim' /> + <public name='kau_slide_out_top' type='anim' /> + <public name='kau_selectable_white' type='drawable' /> + <public name='kau_transparent' type='drawable' /> + <public name='kau_enter_slide_bottom' type='transition' /> + <public name='kau_enter_slide_top' type='transition' /> + <public name='kau_exit_slide_bottom' type='transition' /> + <public name='kau_exit_slide_top' type='transition' /> + <public name='kau_activity_horizontal_margin' type='dimen' /> + <public name='kau_activity_vertical_margin' type='dimen' /> + <public name='kau_dialog_margin' type='dimen' /> + <public name='kau_dialog_margin_bottom' type='dimen' /> + <public name='kau_fab_margin' type='dimen' /> + <public name='kau_appbar_padding_top' type='dimen' /> + <public name='kau_splash_logo' type='dimen' /> + <public name='kau_progress_bar_height' type='dimen' /> + <public name='kau_account_image_size' type='dimen' /> + <public name='kau_status_bar_height' type='dimen' /> + <public name='kau_drag_dismiss_distance' type='dimen' /> + <public name='kau_drag_dismiss_distance_large' type='dimen' /> + <public name='kau_spacing_normal' type='dimen' /> + <public name='kau_spacing_micro' type='dimen' /> + <public name='kau_spacing_large' type='dimen' /> + <public name='kau_spacing_xlarge' type='dimen' /> + <public name='kau_spacing_huge' type='dimen' /> + <public name='kau_padding_small' type='dimen' /> + <public name='kau_padding_normal' type='dimen' /> + <public name='kau_padding_large' type='dimen' /> + <public name='kau_fab_size' type='dimen' /> + <public name='kau_fab_radius' type='dimen' /> + <public name='kau_display_4_text_size' type='dimen' /> + <public name='kau_avatar_size' type='dimen' /> + <public name='kau_avatar_bounds' type='dimen' /> + <public name='kau_avatar_padding' type='dimen' /> + <public name='kau_avatar_margin' type='dimen' /> + <public name='kau_avatar_ripple_radius' type='dimen' /> + <public name='kau_about_app' type='string' /> + <public name='kau_about_x' type='string' /> + <public name='kau_add_account' type='string' /> + <public name='kau_amoled' type='string' /> + <public name='kau_back' type='string' /> + <public name='kau_cancel' type='string' /> + <public name='kau_changelog' type='string' /> + <public name='kau_close' type='string' /> + <public name='kau_contact_us' type='string' /> + <public name='kau_copy' type='string' /> + <public name='kau_custom' type='string' /> + <public name='kau_dark' type='string' /> + <public name='kau_default' type='string' /> + <public name='kau_do_not_show_again' type='string' /> + <public name='kau_done' type='string' /> + <public name='kau_error' type='string' /> + <public name='kau_exit' type='string' /> + <public name='kau_exit_confirmation' type='string' /> + <public name='kau_exit_confirmation_x' type='string' /> + <public name='kau_glass' type='string' /> + <public name='kau_got_it' type='string' /> + <public name='kau_great' type='string' /> + <public name='kau_hide' type='string' /> + <public name='kau_light' type='string' /> + <public name='kau_login' type='string' /> + <public name='kau_logout' type='string' /> + <public name='kau_logout_confirm_as_x' type='string' /> + <public name='kau_lorem_ipsum' type='string' /> + <public name='kau_manage_account' type='string' /> + <public name='kau_maybe' type='string' /> + <public name='kau_menu' type='string' /> + <public name='kau_no' type='string' /> + <public name='kau_no_results_found' type='string' /> + <public name='kau_none' type='string' /> + <public name='kau_ok' type='string' /> + <public name='kau_play_store' type='string' /> + <public name='kau_rate' type='string' /> + <public name='kau_report_bug' type='string' /> + <public name='kau_search' type='string' /> + <public name='kau_send_feedback' type='string' /> + <public name='kau_send_via' type='string' /> + <public name='kau_settings' type='string' /> + <public name='kau_share' type='string' /> + <public name='kau_text_copied' type='string' /> + <public name='kau_thank_you' type='string' /> + <public name='kau_uh_oh' type='string' /> + <public name='kau_warning' type='string' /> + <public name='kau_x_days' type='plurals' /> + <public name='kau_x_hours' type='plurals' /> + <public name='kau_x_minutes' type='plurals' /> + <public name='kau_x_seconds' type='plurals' /> + <public name='kau_yes' type='string' /> + <public name='kau_permission_denied' type='string' /> + <public name='kau_0' type='string' /> + <public name='kau_bullet_point' type='string' /> + <public name='Kau' type='style' /> + <public name='KauFadeIn' type='style' /> + <public name='KauFadeInFadeOut' type='style' /> + <public name='KauSlideInRight' type='style' /> + <public name='KauSlideInBottom' type='style' /> + <public name='KauSlideInFadeOut' type='style' /> + <public name='KauSlideInSlideOutRight' type='style' /> + <public name='KauSlideInSlideOutBottom' type='style' /> +</resources>
\ No newline at end of file diff --git a/core/src/main/res/values/strings_commons.xml b/core/src/main/res-public/values/strings_commons.xml index 560a478..d236021 100644 --- a/core/src/main/res/values/strings_commons.xml +++ b/core/src/main/res-public/values/strings_commons.xml @@ -68,4 +68,7 @@ Most resources are verbatim and x represents a formatted item <item quantity="other">%d seconds</item> </plurals> <string name="kau_yes">Yes</string> + <string name="kau_permission_denied">Permission denied</string> + <string name="kau_0">0</string> + <string name="kau_bullet_point">•</string> </resources> diff --git a/core/src/main/res-public/values/styles.xml b/core/src/main/res-public/values/styles.xml new file mode 100644 index 0000000..f6f1929 --- /dev/null +++ b/core/src/main/res-public/values/styles.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8" standalone="no"?> +<resources> + <style name="Kau" parent="Theme.AppCompat.NoActionBar"/> +</resources> diff --git a/core/src/main/res/values/styles_animations.xml b/core/src/main/res-public/values/styles_animations.xml index fc872bd..b98add9 100644 --- a/core/src/main/res/values/styles_animations.xml +++ b/core/src/main/res-public/values/styles_animations.xml @@ -18,7 +18,7 @@ <item name="android:windowExitAnimation">@anim/kau_fade_out</item> </style> - <style name="KauSlideIn" parent="@android:style/Animation.Activity"> + <style name="KauSlideInRight" parent="@android:style/Animation.Activity"> <item name="android:activityOpenEnterAnimation">@anim/kau_slide_in_right</item> <item name="android:activityCloseEnterAnimation">@anim/kau_slide_in_right</item> <item name="android:taskOpenEnterAnimation">@anim/kau_slide_in_right</item> @@ -27,7 +27,16 @@ <item name="android:windowEnterAnimation">@anim/kau_slide_in_right</item> </style> - <style name="KauSlideInFadeOut" parent="@style/KauSlideIn"> + <style name="KauSlideInBottom" parent="@android:style/Animation.Activity"> + <item name="android:activityOpenEnterAnimation">@anim/kau_slide_in_bottom</item> + <item name="android:activityCloseEnterAnimation">@anim/kau_slide_in_bottom</item> + <item name="android:taskOpenEnterAnimation">@anim/kau_slide_in_bottom</item> + <item name="android:taskCloseEnterAnimation">@anim/kau_slide_in_bottom</item> + <item name="android:taskToFrontEnterAnimation">@anim/kau_slide_in_bottom</item> + <item name="android:windowEnterAnimation">@anim/kau_slide_in_bottom</item> + </style> + + <style name="KauSlideInFadeOut" parent="@style/KauSlideInRight"> <item name="android:activityOpenExitAnimation">@anim/kau_fade_out</item> <item name="android:activityCloseExitAnimation">@anim/kau_fade_out</item> <item name="android:taskOpenExitAnimation">@anim/kau_fade_out</item> @@ -36,7 +45,7 @@ <item name="android:windowExitAnimation">@anim/kau_fade_out</item> </style> - <style name="KauSlideInSlideOut" parent="@style/KauSlideIn"> + <style name="KauSlideInSlideOutRight" parent="@style/KauSlideInRight"> <item name="android:activityOpenExitAnimation">@anim/kau_slide_out_right</item> <item name="android:activityCloseExitAnimation">@anim/kau_slide_out_right</item> <item name="android:taskOpenExitAnimation">@anim/kau_slide_out_right</item> @@ -44,4 +53,13 @@ <item name="android:taskToFrontExitAnimation">@anim/kau_slide_out_right</item> <item name="android:windowExitAnimation">@anim/kau_slide_out_right</item> </style> + + <style name="KauSlideInSlideOutBottom" parent="@style/KauSlideInBottom"> + <item name="android:activityOpenExitAnimation">@anim/kau_slide_out_bottom</item> + <item name="android:activityCloseExitAnimation">@anim/kau_slide_out_bottom</item> + <item name="android:taskOpenExitAnimation">@anim/kau_slide_out_bottom</item> + <item name="android:taskCloseExitAnimation">@anim/kau_slide_out_bottom</item> + <item name="android:taskToFrontExitAnimation">@anim/kau_slide_out_bottom</item> + <item name="android:windowExitAnimation">@anim/kau_slide_out_bottom</item> + </style> </resources> diff --git a/core/src/main/res/layout/kau_changelog_content.xml b/core/src/main/res/layout/kau_changelog_content.xml index 92b87b9..5c463aa 100644 --- a/core/src/main/res/layout/kau_changelog_content.xml +++ b/core/src/main/res/layout/kau_changelog_content.xml @@ -15,7 +15,7 @@ android:layout_height="wrap_content" android:lineSpacingMultiplier="1.6" android:paddingRight="5dp" - android:text="@string/kau_u2022" + android:text="@string/kau_bullet_point" android:textAppearance="@style/TextAppearance.AppCompat.Small" /> <TextView diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml deleted file mode 100644 index 7ad6e38..0000000 --- a/core/src/main/res/values/strings.xml +++ /dev/null @@ -1,13 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<resources> - <string name="kau_about_libraries_intro">This app would not be possible without the following great libraries.</string> - <string name="kau_color_picker">Color Picker</string> - <string name="kau_dependencies_used">Dependencies Used</string> - <string name="kau_kpref_title_placeholder">Title Placeholder</string> - <string name="kau_md_color_palette">Color Palette</string> - <!--Color Picker--> - <string name="kau_md_custom">Custom</string> - <string name="kau_md_presets">Presets</string> - <string name="kau_pref_icon">Pref Icon</string> - <string name="kau_u2022">•</string> -</resources> |