aboutsummaryrefslogtreecommitdiff
path: root/core-ui/src
diff options
context:
space:
mode:
Diffstat (limited to 'core-ui/src')
-rw-r--r--core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt81
-rw-r--r--core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/BoundedCardView.kt8
-rw-r--r--core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt6
-rw-r--r--core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/MeasuredImageView.kt23
-rw-r--r--core-ui/src/main/res/drawable/kau_selectable_white.xml6
-rw-r--r--core-ui/src/main/res/layout/kau_elastic_recycler_activity.xml51
-rw-r--r--core-ui/src/main/res/values/attr.xml58
-rw-r--r--core-ui/src/main/res/values/colors.xml4
-rw-r--r--core-ui/src/main/res/values/strings.xml4
-rw-r--r--core-ui/src/main/res/values/styles.xml16
10 files changed, 217 insertions, 40 deletions
diff --git a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt
new file mode 100644
index 0000000..1dcf14b
--- /dev/null
+++ b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt
@@ -0,0 +1,81 @@
+package ca.allanwang.kau.ui.activities
+
+import android.os.Bundle
+import android.support.design.widget.AppBarLayout
+import android.support.design.widget.CoordinatorLayout
+import android.support.design.widget.FloatingActionButton
+import android.support.v7.app.AppCompatActivity
+import android.support.v7.widget.RecyclerView
+import android.support.v7.widget.Toolbar
+import android.transition.TransitionInflater
+import ca.allanwang.kau.ui.R
+import ca.allanwang.kau.ui.widgets.ElasticDragDismissFrameLayout
+import ca.allanwang.kau.utils.bindView
+
+/**
+ * Created by Allan Wang on 2017-07-17.
+ *
+ * A generic activity comprised of an ElasticDragDismissFrameLayout, CoordinatorLayout, Toolbar, RecyclerView, and Fab
+ * [ca.allanwang.kau.ui.widgets.ElasticDragDismissFrameLayout]
+ * [android.support.v7.widget.RecyclerView]
+ *
+ * The recyclerview defaults to a linearlayoutmanager, and the adapter is automatically bounded
+ *
+ * The exit animation is set to slide out, but the entrance must be defined yourself
+ */
+abstract class ElasticRecyclerActivity() : AppCompatActivity() {
+
+ val appBar: AppBarLayout by bindView(R.id.kau_appbar)
+ val toolbar: Toolbar by bindView(R.id.kau_toolbar)
+ val coordinator: CoordinatorLayout by bindView(R.id.kau_coordinator)
+ val draggableFrame: ElasticDragDismissFrameLayout by bindView(R.id.kau_draggable)
+ val recycler: RecyclerView by bindView(R.id.kau_recycler)
+ val fab: FloatingActionButton by bindView(R.id.kau_fab)
+ val configs = Configs()
+
+ class Configs {
+ var exitTransitionBottom = R.transition.kau_exit_slide_bottom
+ var exitTransitionTop = R.transition.kau_exit_slide_top
+ }
+
+ override final fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.kau_elastic_recycler_activity)
+ setSupportActionBar(toolbar)
+ if (!onCreate(savedInstanceState, configs)) return
+ draggableFrame.addListener(object : ElasticDragDismissFrameLayout.SystemChromeFader(this) {
+ override fun onDragDismissed() {
+ window.returnTransition = TransitionInflater.from(this@ElasticRecyclerActivity)
+ .inflateTransition(if (draggableFrame.translationY > 0) configs.exitTransitionBottom else configs.exitTransitionTop)
+ recycler.stopScroll()
+ finishAfterTransition()
+ }
+ })
+ }
+
+ /**
+ * The replacement method for the original [onCreate]
+ * The configurations are passed and can be customized here
+ * Returns true (default) if we wish to continue with the remaining optional setup
+ * Return false if we wish to skip this (usually if we have more complez requirements)
+ */
+ abstract fun onCreate(savedInstanceState: Bundle?, configs: Configs): Boolean
+
+ /**
+ * Receive actions when the a click event is received outside of the coordinator
+ */
+ fun setOutsideTapListener(listener: () -> Unit) {
+ draggableFrame.setOnClickListener { listener() }
+ }
+
+ fun hideFabOnUpwardsScroll() {
+ recycler.addOnScrollListener(object :RecyclerView.OnScrollListener(){
+ override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) {
+ if (dy > 0 && fab.isShown) fab.hide()
+ else if (dy < 0 && !fab.isShown) fab.show()
+ }
+ })
+ }
+
+}
+
diff --git a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/BoundedCardView.kt b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/BoundedCardView.kt
index db002b9..5fc3e06 100644
--- a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/BoundedCardView.kt
+++ b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/BoundedCardView.kt
@@ -1,10 +1,11 @@
package ca.allanwang.kau.ui.views
import android.content.Context
+import android.graphics.Rect
import android.support.v7.widget.CardView
import android.util.AttributeSet
import ca.allanwang.kau.ui.R
-import ca.allanwang.kau.utils.parentVisibleHeight
+import ca.allanwang.kau.utils.parentViewGroup
/**
@@ -29,6 +30,8 @@ class BoundedCardView @JvmOverloads constructor(
*/
var maxHeightPercent: Float = -1.0f
+ private val parentFrame = Rect()
+
init {
if (attrs != null) {
val styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.BoundedCardView)
@@ -39,7 +42,8 @@ class BoundedCardView @JvmOverloads constructor(
}
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
- var maxMeasureHeight = if (maxHeight > 0) maxHeight else parentVisibleHeight
+ parentViewGroup.getWindowVisibleDisplayFrame(parentFrame)
+ var maxMeasureHeight = if (maxHeight > 0) maxHeight else parentFrame.height()
if (maxHeightPercent > 0f) maxMeasureHeight = (maxMeasureHeight * maxHeightPercent).toInt()
val trueHeightMeasureSpec = MeasureSpec.makeMeasureSpec(maxMeasureHeight, MeasureSpec.AT_MOST)
super.onMeasure(widthMeasureSpec, trueHeightMeasureSpec)
diff --git a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt
index 42f19b9..9e8ac11 100644
--- a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt
+++ b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt
@@ -27,7 +27,7 @@ import android.view.View
import ca.allanwang.kau.ui.R
import ca.allanwang.kau.utils.dimenPixelSize
import ca.allanwang.kau.utils.getFont
-import ca.allanwang.kau.utils.parentVisibleHeight
+import ca.allanwang.kau.utils.parentViewGroup
import ca.allanwang.kau.utils.toBitmap
/**
@@ -66,6 +66,7 @@ class CutoutView @JvmOverloads constructor(
private var heightPercentage: Float = 0f
private var minHeight: Float = 0f
private val maxTextSize: Float
+ private val parentFrame = Rect()
init {
if (attrs != null) {
@@ -121,7 +122,8 @@ class CutoutView @JvmOverloads constructor(
* If height percent is specified, ensure it is met
*/
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
- val minHeight = Math.max(minHeight, heightPercentage * parentVisibleHeight)
+ parentViewGroup.getWindowVisibleDisplayFrame(parentFrame)
+ val minHeight = Math.max(minHeight, heightPercentage * parentFrame.height())
val trueHeightMeasureSpec = if (minHeight > 0)
MeasureSpec.makeMeasureSpec(Math.max(minHeight.toInt(), measuredHeight), MeasureSpec.EXACTLY)
else heightMeasureSpec
diff --git a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/MeasuredImageView.kt b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/MeasuredImageView.kt
new file mode 100644
index 0000000..2627d13
--- /dev/null
+++ b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/MeasuredImageView.kt
@@ -0,0 +1,23 @@
+package ca.allanwang.kau.ui.views
+
+import android.content.Context
+import android.util.AttributeSet
+import android.widget.ImageView
+
+/**
+ * Created by Allan Wang on 2017-07-14.
+ */
+class MeasuredImageView @JvmOverloads constructor(
+ context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0
+) : ImageView(context, attrs, defStyleAttr, defStyleRes), MeasureSpecContract by MeasureSpecDelegate() {
+
+ init {
+ initAttrs(context, attrs)
+ }
+
+ override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
+ val result = onMeasure(this, widthMeasureSpec, heightMeasureSpec)
+ super.onMeasure(result.first, result.second)
+ }
+
+} \ No newline at end of file
diff --git a/core-ui/src/main/res/drawable/kau_selectable_white.xml b/core-ui/src/main/res/drawable/kau_selectable_white.xml
new file mode 100644
index 0000000..942f149
--- /dev/null
+++ b/core-ui/src/main/res/drawable/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-ui/src/main/res/layout/kau_elastic_recycler_activity.xml b/core-ui/src/main/res/layout/kau_elastic_recycler_activity.xml
new file mode 100644
index 0000000..055d61d
--- /dev/null
+++ b/core-ui/src/main/res/layout/kau_elastic_recycler_activity.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ca.allanwang.kau.ui.widgets.ElasticDragDismissFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:id="@+id/kau_draggable"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:dragDismissDistance="@dimen/kau_drag_dismiss_distance_large"
+ app:dragDismissScale="0.95">
+
+ <android.support.design.widget.CoordinatorLayout
+ android:id="@+id/kau_coordinator"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_marginTop="@dimen/kau_drag_dismiss_distance"
+ android:background="?android:colorBackground"
+ android:orientation="vertical">
+
+ <android.support.design.widget.AppBarLayout
+ android:id="@+id/kau_appbar"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <android.support.v7.widget.Toolbar
+ android:id="@+id/kau_toolbar"
+ android:layout_width="match_parent"
+ android:layout_height="?attr/actionBarSize"
+ app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
+
+ </android.support.design.widget.AppBarLayout>
+
+ <android.support.v7.widget.RecyclerView
+ android:id="@+id/kau_recycler"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:layoutManager="android.support.v7.widget.LinearLayoutManager"
+ app:layout_behavior="@string/appbar_scrolling_view_behavior" />
+
+ <android.support.design.widget.FloatingActionButton
+ android:id="@+id/kau_fab"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_margin="@dimen/kau_fab_margin"
+ android:clickable="true"
+ android:visibility="gone"
+ app:backgroundTint="?colorAccent"
+ app:layout_anchor="@id/kau_recycler"
+ app:layout_anchorGravity="bottom|right|end" />
+
+ </android.support.design.widget.CoordinatorLayout>
+
+</ca.allanwang.kau.ui.widgets.ElasticDragDismissFrameLayout> \ No newline at end of file
diff --git a/core-ui/src/main/res/values/attr.xml b/core-ui/src/main/res/values/attr.xml
index 49be8d9..271d132 100644
--- a/core-ui/src/main/res/values/attr.xml
+++ b/core-ui/src/main/res/values/attr.xml
@@ -1,41 +1,39 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
-
<declare-styleable name="BoundedCardView">
- <attr name="maxHeight" format="dimension" />
- <attr name="maxHeightPercent" format="float" />
+ <attr format="dimension" name="maxHeight"/>
+ <attr format="float" name="maxHeightPercent"/>
</declare-styleable>
- <declare-styleable name="TextSlider">
- <attr name="animation_type" format="enum">
- <enum name="none" value="1000" />
- <enum name="slide_horizontal" value="1001" />
- <enum name="slide_vertical" value="1002" />
- </attr>
- </declare-styleable>
-
- <declare-styleable name="InkPageIndicator">
- <attr name="dotDiameter" format="dimension" />
- <attr name="dotGap" format="dimension" />
- <attr name="animationDuration" format="integer" />
- <attr name="pageIndicatorColor" format="color" />
- <attr name="currentPageIndicatorColor" format="color" />
+ <declare-styleable name="CutoutView">
+ <attr format="color" name="foregroundColor"/>
+ <attr name="android:text"/>
+ <attr name="android:drawable"/>
+ <attr name="android:minHeight"/>
+ <attr format="float" name="heightPercentageToScreen"/>
+ <attr name="font"/>
</declare-styleable>
<declare-styleable name="ElasticDragDismissFrameLayout">
- <attr name="dragDismissDistance" format="dimension" />
- <attr name="dragDismissFraction" format="float" />
- <attr name="dragDismissScale" format="float" />
- <attr name="dragElasticity" format="float" />
+ <attr format="dimension" name="dragDismissDistance"/>
+ <attr format="float" name="dragDismissFraction"/>
+ <attr format="float" name="dragDismissScale"/>
+ <attr format="float" name="dragElasticity"/>
</declare-styleable>
- <declare-styleable name="CutoutView">
- <attr name="foregroundColor" format="color" />
- <attr name="android:text" />
- <attr name="android:drawable" />
- <attr name="android:minHeight" />
- <attr name="heightPercentageToScreen" format="float" />
- <attr name="font"/>
+ <declare-styleable name="InkPageIndicator">
+ <attr format="dimension" name="dotDiameter"/>
+ <attr format="dimension" name="dotGap"/>
+ <attr format="integer" name="animationDuration"/>
+ <attr format="color" name="pageIndicatorColor"/>
+ <attr format="color" name="currentPageIndicatorColor"/>
</declare-styleable>
-</resources> \ No newline at end of file
+ <declare-styleable name="TextSlider">
+ <attr format="enum" name="animation_type">
+ <enum name="none" value="1000"/>
+ <enum name="slide_horizontal" value="1001"/>
+ <enum name="slide_vertical" value="1002"/>
+ </attr>
+ </declare-styleable>
+</resources>
diff --git a/core-ui/src/main/res/values/colors.xml b/core-ui/src/main/res/values/colors.xml
index 6d51597..273d6f1 100644
--- a/core-ui/src/main/res/values/colors.xml
+++ b/core-ui/src/main/res/values/colors.xml
@@ -1,6 +1,6 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<resources>
- <color name="kau_shadow_overlay">#80000000</color>
-
<color name="kau_about_page_indicator_dark">#80ffffff</color>
<color name="kau_about_page_indicator_dark_selected">#fff</color>
+ <color name="kau_shadow_overlay">#80000000</color>
</resources>
diff --git a/core-ui/src/main/res/values/strings.xml b/core-ui/src/main/res/values/strings.xml
new file mode 100644
index 0000000..80e6233
--- /dev/null
+++ b/core-ui/src/main/res/values/strings.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="kau_blurrable_imageview">Blurrable ImageView</string>
+</resources> \ No newline at end of file
diff --git a/core-ui/src/main/res/values/styles.xml b/core-ui/src/main/res/values/styles.xml
index f9fd7d4..dfbb6d3 100644
--- a/core-ui/src/main/res/values/styles.xml
+++ b/core-ui/src/main/res/values/styles.xml
@@ -1,7 +1,6 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources>
-
- <style name="Kau" parent="Theme.AppCompat.NoActionBar" />
+ <style name="Kau" parent="Theme.AppCompat.NoActionBar"/>
<style name="Kau.Translucent">
<item name="android:windowBackground">@color/kau_shadow_overlay</item>
@@ -17,4 +16,13 @@
<item name="android:windowAnimationStyle">@null</item>
</style>
-</resources> \ No newline at end of file
+ <style name="Kau.Translucent.SlideBottom">
+ <item name="android:windowEnterTransition">@transition/kau_enter_slide_bottom</item>
+ <item name="android:windowReturnTransition">@transition/kau_exit_slide_bottom</item>
+ </style>
+
+ <style name="Kau.Translucent.SlideTop">
+ <item name="android:windowEnterTransition">@transition/kau_enter_slide_top</item>
+ <item name="android:windowReturnTransition">@transition/kau_exit_slide_top</item>
+ </style>
+</resources>