aboutsummaryrefslogtreecommitdiff
path: root/imagepicker
diff options
context:
space:
mode:
Diffstat (limited to 'imagepicker')
-rw-r--r--imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerActivityBase.kt72
-rw-r--r--imagepicker/src/main/res/layout/kau_activity_image_picker.xml29
-rw-r--r--imagepicker/src/main/res/layout/kau_iitem_image.xml16
-rw-r--r--imagepicker/src/main/res/values/styles.xml8
4 files changed, 93 insertions, 32 deletions
diff --git a/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerActivityBase.kt b/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerActivityBase.kt
index 216939f..d5562aa 100644
--- a/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerActivityBase.kt
+++ b/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerActivityBase.kt
@@ -1,39 +1,77 @@
package ca.allanwang.kau.imagepicker
-import android.graphics.drawable.Drawable
+import android.database.Cursor
import android.os.Bundle
+import android.provider.MediaStore
+import android.support.v4.app.LoaderManager
+import android.support.v4.content.CursorLoader
+import android.support.v4.content.Loader
import android.support.v7.app.AppCompatActivity
+import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.RecyclerView
import android.support.v7.widget.Toolbar
import android.transition.TransitionInflater
-import android.view.LayoutInflater
-import android.view.View
-import android.view.ViewGroup
-import ca.allanwang.kau.R
-import ca.allanwang.kau.adapters.FastItemThemedAdapter
-import ca.allanwang.kau.adapters.ThemableIItemColors
-import ca.allanwang.kau.adapters.ThemableIItemColorsDelegate
-import ca.allanwang.kau.iitems.LibraryIItem
+import ca.allanwang.kau.logging.KL
import ca.allanwang.kau.utils.bindView
-import ca.allanwang.kau.utils.string
import ca.allanwang.kau.widgets.ElasticDragDismissFrameLayout
-import com.mikepenz.aboutlibraries.Libs
-import com.mikepenz.aboutlibraries.entity.Library
import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter
-import java.security.InvalidParameterException
+
/**
* Created by Allan Wang on 2017-07-04.
*
*/
-abstract class ImagePickerActivityBase : AppCompatActivity() {
+abstract class ImagePickerActivityBase : AppCompatActivity(), LoaderManager.LoaderCallbacks<Cursor> {
- val toolbar:Toolbar by bindView(R.id.kau_toolbar)
- val recycler:RecyclerView by bindView(R.id.kau_recycler)
- val adapter = FastItemAdapter<ImageItem>()
+ val toolbar: Toolbar by bindView(R.id.kau_toolbar)
+ val draggableFrame: ElasticDragDismissFrameLayout by bindView(R.id.kau_draggable)
+ val recycler: RecyclerView by bindView(R.id.kau_recycler)
+ val imageAdapter = FastItemAdapter<ImageItem>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.kau_activity_image_picker)
+ with(recycler) {
+ layoutManager = GridLayoutManager(this@ImagePickerActivityBase, 3)
+ adapter = this@ImagePickerActivityBase.imageAdapter
+ }
+ imageAdapter.add(arrayOf("a", "b", "c").map { ImageItem(it) })
+ draggableFrame.addListener(object : ElasticDragDismissFrameLayout.SystemChromeFader(this) {
+ override fun onDragDismissed() {
+ if (draggableFrame.translationY < 0) {
+ window.returnTransition = TransitionInflater.from(this@ImagePickerActivityBase)
+ .inflateTransition(R.transition.kau_about_return_upwards)
+ }
+ finishAfterTransition()
+ }
+ })
+ }
+
+ override fun onCreateLoader(id: Int, args: Bundle?): Loader<Cursor> {
+ val columns = arrayOf(
+ MediaStore.Images.Media._ID,
+ MediaStore.Images.Media.DATA,
+ MediaStore.Images.Media.DISPLAY_NAME,
+ MediaStore.Images.Media.DATE_MODIFIED)
+
+ return CursorLoader(this, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null, null, null)
+ }
+
+ override fun onLoadFinished(loader: Loader<Cursor>, data: Cursor) {
+ val dataIndex = data.getColumnIndex(MediaStore.Images.Media.DATA)
+ val alstPhotos = mutableListOf<String>()
+
+ data.moveToLast()
+ while (!data.isBeforeFirst) {
+ val photoPath = data.getString(dataIndex)
+ KL.d(photoPath)
+ alstPhotos.add(photoPath)
+ data.moveToPrevious()
+ }
+ imageAdapter.add(alstPhotos.map { ImageItem(it) })
+ }
+
+ override fun onLoaderReset(loader: Loader<Cursor>) {
+ imageAdapter.clear()
}
} \ No newline at end of file
diff --git a/imagepicker/src/main/res/layout/kau_activity_image_picker.xml b/imagepicker/src/main/res/layout/kau_activity_image_picker.xml
index d3739dd..3c12a84 100644
--- a/imagepicker/src/main/res/layout/kau_activity_image_picker.xml
+++ b/imagepicker/src/main/res/layout/kau_activity_image_picker.xml
@@ -1,18 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<ca.allanwang.kau.widgets.ElasticDragDismissFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:layout_marginTop="@dimen/kau_drag_dismiss_distance">
+ android:id="@+id/kau_draggable"
+ app:dragDismissDistance="@dimen/kau_drag_dismiss_distance"
+ app:dragDismissScale="0.95">
- <android.support.v7.widget.Toolbar
- android:id="@+id/kau_toolbar"
- android:layout_width="match_parent"
- android:layout_height="?attr/actionBarSize" />
-
- <android.support.v7.widget.RecyclerView
- android:id="@+id/kau_recycler"
+ <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:layout_marginTop="?attr/actionBarSize" />
+ android:layout_marginTop="@dimen/kau_drag_dismiss_distance"
+ android:orientation="vertical">
+
+ <android.support.v7.widget.Toolbar
+ android:id="@+id/kau_toolbar"
+ android:layout_width="match_parent"
+ android:layout_height="?attr/actionBarSize" />
+
+ <android.support.v7.widget.RecyclerView
+ android:id="@+id/kau_recycler"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="?android:colorBackground" />
+
+ </LinearLayout>
</ca.allanwang.kau.widgets.ElasticDragDismissFrameLayout> \ No newline at end of file
diff --git a/imagepicker/src/main/res/layout/kau_iitem_image.xml b/imagepicker/src/main/res/layout/kau_iitem_image.xml
index 824ae7b..22cc998 100644
--- a/imagepicker/src/main/res/layout/kau_iitem_image.xml
+++ b/imagepicker/src/main/res/layout/kau_iitem_image.xml
@@ -1,11 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="80dp"
- android:layout_height="80dp">
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
<ImageView
android:id="@+id/kau_image"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
+ android:layout_width="0dp"
+ android:layout_height="0dp"
+ android:scaleType="centerCrop"
+ android:background="#f0f"
+ app:layout_constraintDimensionRatio="1:1" />
-</FrameLayout> \ No newline at end of file
+</android.support.constraint.ConstraintLayout> \ No newline at end of file
diff --git a/imagepicker/src/main/res/values/styles.xml b/imagepicker/src/main/res/values/styles.xml
new file mode 100644
index 0000000..1dc5149
--- /dev/null
+++ b/imagepicker/src/main/res/values/styles.xml
@@ -0,0 +1,8 @@
+<resources>
+
+ <style name="Kau.Translucent.ImagePicker">
+ <item name="android:windowEnterTransition">@transition/kau_enter_slide_bottom</item>
+ <item name="android:windowReturnTransition">@transition/kau_about_return_downward</item>
+ </style>
+
+</resources>