From 48213d0b427c478865c75fee912ff1ae8bbaffb5 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 31 Jul 2017 23:02:01 -0700 Subject: Major update to core and kotterknife; create mediapicker (#15) * Readme * Fix kau direction bits * Truly support transparent ripples * Update changelog * Test rect as base * Replace fab transition with generic fade scale transition * Add scalexy func * Add scaleXY * Add arguments to fadeScaleTransition * Clean up ink indicator * Create setOnSingleTapListener * Fix lint and add rndColor * Create kotterknife resettables * Add readme and missing object * Create lazy resettable registered * Update core docs * Opt for separate class for resettable registry * Clean up resettable registry * Rename functions * Add ripple callback listener * Adjust kprefactivity desc color * Add more transitions * Add delete keys option * Add instrumentation tests * switch id * Revert automatic instrumental tests * Generify imagepickercore and prepare video alternative * Create working video picker * Address possible null issue * Update searchview * Make layouts public * Add changelog test * Update logo link * Add custom color gif --- imagepicker/src/main/AndroidManifest.xml | 1 - .../allanwang/kau/imagepicker/BlurredImageView.kt | 161 ----------------- .../ca/allanwang/kau/imagepicker/ImageItem.kt | 69 ------- .../ca/allanwang/kau/imagepicker/ImageItemBasic.kt | 71 -------- .../ca/allanwang/kau/imagepicker/ImageModel.kt | 58 ------ .../kau/imagepicker/ImagePickerActivityBase.kt | 100 ----------- .../imagepicker/ImagePickerActivityOverlayBase.kt | 51 ------ .../allanwang/kau/imagepicker/ImagePickerBinder.kt | 34 ---- .../allanwang/kau/imagepicker/ImagePickerCore.kt | 200 --------------------- .../src/main/res-public/values-v21/styles.xml | 9 - imagepicker/src/main/res-public/values/colors.xml | 6 - imagepicker/src/main/res-public/values/dimens.xml | 6 - imagepicker/src/main/res-public/values/public.xml | 7 - imagepicker/src/main/res-public/values/styles.xml | 12 -- .../kau_activity_image_picker_overlay.xml | 17 -- .../main/res/layout/kau_activity_image_picker.xml | 55 ------ .../src/main/res/layout/kau_blurred_imageview.xml | 32 ---- .../src/main/res/layout/kau_iitem_image.xml | 9 - .../src/main/res/layout/kau_iitem_image_basic.xml | 10 -- .../main/res/transition-v21/kau_image_enter.xml | 16 -- .../res/transition-v21/kau_image_exit_bottom.xml | 16 -- .../main/res/transition-v21/kau_image_exit_top.xml | 16 -- imagepicker/src/main/res/values/strings.xml | 7 - 23 files changed, 963 deletions(-) delete mode 100644 imagepicker/src/main/AndroidManifest.xml delete mode 100644 imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/BlurredImageView.kt delete mode 100644 imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImageItem.kt delete mode 100644 imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImageItemBasic.kt delete mode 100644 imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImageModel.kt delete mode 100644 imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerActivityBase.kt delete mode 100644 imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerActivityOverlayBase.kt delete mode 100644 imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerBinder.kt delete mode 100644 imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerCore.kt delete mode 100644 imagepicker/src/main/res-public/values-v21/styles.xml delete mode 100644 imagepicker/src/main/res-public/values/colors.xml delete mode 100644 imagepicker/src/main/res-public/values/dimens.xml delete mode 100644 imagepicker/src/main/res-public/values/public.xml delete mode 100644 imagepicker/src/main/res-public/values/styles.xml delete mode 100644 imagepicker/src/main/res/layout-v21/kau_activity_image_picker_overlay.xml delete mode 100644 imagepicker/src/main/res/layout/kau_activity_image_picker.xml delete mode 100644 imagepicker/src/main/res/layout/kau_blurred_imageview.xml delete mode 100644 imagepicker/src/main/res/layout/kau_iitem_image.xml delete mode 100644 imagepicker/src/main/res/layout/kau_iitem_image_basic.xml delete mode 100644 imagepicker/src/main/res/transition-v21/kau_image_enter.xml delete mode 100644 imagepicker/src/main/res/transition-v21/kau_image_exit_bottom.xml delete mode 100644 imagepicker/src/main/res/transition-v21/kau_image_exit_top.xml delete mode 100644 imagepicker/src/main/res/values/strings.xml (limited to 'imagepicker/src/main') diff --git a/imagepicker/src/main/AndroidManifest.xml b/imagepicker/src/main/AndroidManifest.xml deleted file mode 100644 index 89dccc2..0000000 --- a/imagepicker/src/main/AndroidManifest.xml +++ /dev/null @@ -1 +0,0 @@ - diff --git a/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/BlurredImageView.kt b/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/BlurredImageView.kt deleted file mode 100644 index 2ce00ba..0000000 --- a/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/BlurredImageView.kt +++ /dev/null @@ -1,161 +0,0 @@ -package ca.allanwang.kau.imagepicker - -import android.content.Context -import android.graphics.Color -import android.support.annotation.StyleRes -import android.util.AttributeSet -import android.view.View -import android.widget.FrameLayout -import android.widget.ImageView -import ca.allanwang.kau.ui.views.MeasureSpecContract -import ca.allanwang.kau.ui.views.MeasureSpecDelegate -import ca.allanwang.kau.utils.* -import com.mikepenz.google_material_typeface_library.GoogleMaterial -import com.mikepenz.iconics.IconicsDrawable -import jp.wasabeef.blurry.internal.BlurFactor -import jp.wasabeef.blurry.internal.BlurTask - -/** - * Created by Allan Wang on 2017-07-14. - * - * ImageView that can be blurred and selected - * The frame is composed of three layers: the base, the blur, and the foreground - * Images should be placed in the base view, and the blur view should not be touched - * as the class will handle it - * The foreground by default contains a white checkmark, but can be customized or hidden depending on the situation - */ -class BlurredImageView @JvmOverloads constructor( - context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 -) : FrameLayout(context, attrs, defStyleAttr), MeasureSpecContract by MeasureSpecDelegate() { - - private var blurred = false - val imageBase: ImageView by bindView(R.id.image_base) - internal val imageBlur: ImageView by bindView(R.id.image_blur) - val imageForeground: ImageView by bindView(R.id.image_foreground) - - init { - inflate(R.layout.kau_blurred_imageview, true) - initAttrs(context, attrs) - imageForeground.setIcon(GoogleMaterial.Icon.gmd_check, 30) - } - - override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { - val result = onMeasure(this, widthMeasureSpec, heightMeasureSpec) - super.onMeasure(result.first, result.second) - } - - override fun clearAnimation() { - super.clearAnimation() - imageBase.clearAnimation() - imageBlur.clearAnimation() - imageForeground.clearAnimation() - } - - private fun View.scaleAnimate(scale: Float) = animate().scaleX(scale).scaleY(scale).setDuration(ANIMATION_DURATION) - private fun View.alphaAnimate(alpha: Float) = animate().alpha(alpha).setDuration(ANIMATION_DURATION) - - - fun isBlurred(): Boolean { - return blurred - } - - /** - * Applies a blur and fills the blur image asynchronously - * When ready, scales the image down and shows the blur & foreground - */ - fun blur() { - if (blurred) return - blurred = true - val factor = BlurFactor() - factor.width = width - factor.height = height - BlurTask(imageBase, factor) { - imageBlur.setImageDrawable(it) - scaleAnimate(ANIMATION_SCALE).start() - imageBlur.alphaAnimate(1f).start() - imageForeground.alphaAnimate(1f).start() - }.execute() - } - - /** - * Clears animations and blurs the image without further animations - * This method is relatively instantaneous, as retrieving the blurred image - * is still asynchronous and takes time - */ - fun blurInstantly() { - blurred = true - clearAnimation() - val factor = BlurFactor() - factor.width = width - factor.height = height - BlurTask(imageBase, factor) { drawable -> - imageBlur.setImageDrawable(drawable) - scaleX = ANIMATION_SCALE - scaleY = ANIMATION_SCALE - imageBlur.alpha = 1f - imageForeground.alpha = 1f - }.execute() - } - - /** - * Animate view back to original state and remove drawable when finished - */ - fun removeBlur() { - if (!blurred) return - blurred = false - scaleAnimate(1.0f).start() - imageBlur.alphaAnimate(0f).withEndAction { imageBlur.setImageDrawable(null) }.start() - imageForeground.alphaAnimate(0f).start() - } - - - /** - * Clear all animations and unblur the image - */ - fun removeBlurInstantly() { - blurred = false - clearAnimation() - scaleX = 1.0f - scaleX = 1.0f - imageBlur.alpha = 0f - imageBlur.setImageDrawable(null) - imageForeground.alpha = 0f - } - - /** - * Switch blur state and apply transition - * - * @return true if new state is blurred; false otherwise - */ - fun toggleBlur(): Boolean { - if (blurred) removeBlur() - else blur() - return blurred - } - - /** - * Clears all of the blur effects to restore the original states - * If views were modified in other ways, this method won't affect it - */ - fun reset() { - removeBlurInstantly() - imageBase.setImageDrawable(null) - } - - /** - * Reset most of possible changes to the view - */ - fun fullReset() { - reset() - fullAction({ it.visible().background = null }) - imageForeground.setBackgroundColorRes(R.color.kau_blurred_image_selection_overlay) - imageForeground.setIcon(GoogleMaterial.Icon.gmd_check, 30, Color.WHITE) - } - - private fun fullAction(action: (View) -> Unit) { - action(this) - action(imageBase) - action(imageBlur) - action(imageForeground) - } -} \ No newline at end of file diff --git a/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImageItem.kt b/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImageItem.kt deleted file mode 100644 index ffeb560..0000000 --- a/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImageItem.kt +++ /dev/null @@ -1,69 +0,0 @@ -package ca.allanwang.kau.imagepicker - -import android.graphics.drawable.Drawable -import android.support.v7.widget.RecyclerView -import android.view.View -import ca.allanwang.kau.iitems.KauIItem -import ca.allanwang.kau.utils.bindView -import com.bumptech.glide.Glide -import com.bumptech.glide.load.DataSource -import com.bumptech.glide.load.engine.GlideException -import com.bumptech.glide.request.RequestListener -import com.bumptech.glide.request.target.Target -import com.mikepenz.fastadapter.FastAdapter - -/** - * Created by Allan Wang on 2017-07-04. - */ -class ImageItem(val data: ImageModel) - : KauIItem(R.layout.kau_iitem_image, { ViewHolder(it) }) { - - private var failedToLoad = false - - companion object { - fun bindEvents(fastAdapter: FastAdapter) { - fastAdapter.withMultiSelect(true) - .withSelectable(true) - //adapter selector occurs before the on click event - .withOnClickListener { v, _, item, _ -> - val image = v as BlurredImageView - if (item.isSelected) image.blur() - else image.removeBlur() - true - } - } - } - - override fun isSelectable(): Boolean = !failedToLoad - - override fun bindView(holder: ViewHolder, payloads: List?) { - super.bindView(holder, payloads) - Glide.with(holder.itemView) - .load(data.data) - .listener(object : RequestListener { - override fun onLoadFailed(e: GlideException?, model: Any, target: Target, isFirstResource: Boolean): Boolean { - failedToLoad = true - holder.container.imageBase.setImageDrawable(ImagePickerCore.getErrorDrawable(holder.itemView.context)) - return true; - } - - override fun onResourceReady(resource: Drawable, model: Any, target: Target, dataSource: DataSource, isFirstResource: Boolean): Boolean { - holder.container.imageBase.setImageDrawable(resource) - if (isSelected) holder.container.blurInstantly() - return true; - } - }) - .into(holder.container.imageBase) - } - - override fun unbindView(holder: ViewHolder) { - super.unbindView(holder) - Glide.with(holder.itemView).clear(holder.container.imageBase) - holder.container.removeBlurInstantly() - failedToLoad = false - } - - class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { - val container: BlurredImageView by bindView(R.id.kau_image) - } -} \ No newline at end of file diff --git a/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImageItemBasic.kt b/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImageItemBasic.kt deleted file mode 100644 index bc2a4e1..0000000 --- a/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImageItemBasic.kt +++ /dev/null @@ -1,71 +0,0 @@ -package ca.allanwang.kau.imagepicker - -import android.annotation.SuppressLint -import android.app.Activity -import android.content.Intent -import android.graphics.drawable.Drawable -import android.support.v7.app.AppCompatActivity -import android.support.v7.widget.RecyclerView -import android.view.View -import ca.allanwang.kau.iitems.KauIItem -import ca.allanwang.kau.ui.views.MeasuredImageView -import ca.allanwang.kau.utils.bindView -import ca.allanwang.kau.utils.buildIsLollipopAndUp -import com.bumptech.glide.Glide -import com.bumptech.glide.load.DataSource -import com.bumptech.glide.load.engine.GlideException -import com.bumptech.glide.request.RequestListener -import com.bumptech.glide.request.target.Target -import com.mikepenz.fastadapter.FastAdapter - -/** - * Created by Allan Wang on 2017-07-04. - */ -class ImageItemBasic(val data: ImageModel) - : KauIItem(R.layout.kau_iitem_image_basic, { ViewHolder(it) }) { - - companion object { - @SuppressLint("NewApi") - fun bindEvents(activity: Activity, fastAdapter: FastAdapter) { - fastAdapter.withSelectable(false) - //add image data and return right away - .withOnClickListener { _, _, item, _ -> - val intent = Intent() - val data = arrayListOf(item.data) - intent.putParcelableArrayListExtra(IMAGE_PICKER_RESULT, data) - activity.setResult(AppCompatActivity.RESULT_OK, intent) - if (buildIsLollipopAndUp) activity.finishAfterTransition() - else activity.finish() - true - } - } - } - - override fun isSelectable(): Boolean = false - - override fun bindView(holder: ViewHolder, payloads: List?) { - super.bindView(holder, payloads) - Glide.with(holder.itemView) - .load(data.data) - .listener(object : RequestListener { - override fun onLoadFailed(e: GlideException?, model: Any, target: Target, isFirstResource: Boolean): Boolean { - holder.image.setImageDrawable(ImagePickerCore.getErrorDrawable(holder.itemView.context)) - return true; - } - - override fun onResourceReady(resource: Drawable, model: Any, target: Target, dataSource: DataSource, isFirstResource: Boolean): Boolean { - return false - } - }) - .into(holder.image) - } - - override fun unbindView(holder: ViewHolder) { - super.unbindView(holder) - Glide.with(holder.itemView).clear(holder.image) - } - - class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { - val image: MeasuredImageView by bindView(R.id.kau_image) - } -} \ No newline at end of file diff --git a/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImageModel.kt b/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImageModel.kt deleted file mode 100644 index 202805c..0000000 --- a/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImageModel.kt +++ /dev/null @@ -1,58 +0,0 @@ -package ca.allanwang.kau.imagepicker - -import android.database.Cursor -import android.net.Uri -import android.os.Parcel -import android.os.Parcelable -import android.provider.MediaStore -import android.support.annotation.NonNull -import java.io.File - - -/** - * Created by Allan Wang on 2017-07-14. - */ - -data class ImageModel(val size: Long, val dateModified: Long, val data: String, val displayName: String) : Parcelable { - - constructor(@NonNull cursor: Cursor) : this( - cursor.getLong(MediaStore.Images.Media.SIZE), - cursor.getLong(MediaStore.Images.Media.DATE_MODIFIED), - cursor.getString(MediaStore.Images.Media.DATA), - cursor.getString(MediaStore.Images.Media.DISPLAY_NAME) - ) - - constructor(parcel: Parcel) : this( - parcel.readLong(), - parcel.readLong(), - parcel.readString(), - parcel.readString()) - - - override fun writeToParcel(parcel: Parcel, flags: Int) { - parcel.writeLong(this.size) - parcel.writeLong(this.dateModified) - parcel.writeString(this.data) - parcel.writeString(this.displayName) - } - - val uri: Uri by lazy { Uri.fromFile(File(data)) } - - override fun describeContents(): Int { - return 0 - } - - companion object CREATOR : Parcelable.Creator { - override fun createFromParcel(parcel: Parcel): ImageModel { - return ImageModel(parcel) - } - - override fun newArray(size: Int): Array { - return arrayOfNulls(size) - } - } - -} - -private fun Cursor.getString(name: String) = getString(getColumnIndex(name)) -private fun Cursor.getLong(name: String) = getLong(getColumnIndex(name)) \ No newline at end of file diff --git a/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerActivityBase.kt b/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerActivityBase.kt deleted file mode 100644 index 3a9809c..0000000 --- a/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerActivityBase.kt +++ /dev/null @@ -1,100 +0,0 @@ -package ca.allanwang.kau.imagepicker - -import android.content.Intent -import android.database.Cursor -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.v4.content.Loader -import android.support.v7.widget.LinearLayoutManager -import android.support.v7.widget.RecyclerView -import android.support.v7.widget.Toolbar -import android.widget.TextView -import ca.allanwang.kau.utils.* -import com.mikepenz.google_material_typeface_library.GoogleMaterial - -/** - * Created by Allan Wang on 2017-07-04. - * - * Base activity for selecting images from storage - * Images are blurred when selected, and multiple images can be selected at a time. - * Having three layered images makes this slightly slower than [ImagePickerActivityOverlayBase] - */ -abstract class ImagePickerActivityBase : ImagePickerCore() { - - val coordinator: CoordinatorLayout by bindView(R.id.kau_coordinator) - val toolbar: Toolbar by bindView(R.id.kau_toolbar) - val selectionCount: TextView by bindView(R.id.kau_selection_count) - val recycler: RecyclerView by bindView(R.id.kau_recyclerview) - val fab: FloatingActionButton by bindView(R.id.kau_fab) - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - setContentView(R.layout.kau_activity_image_picker) - - selectionCount.setCompoundDrawables(null, null, GoogleMaterial.Icon.gmd_image.toDrawable(this, 18), null) - - setSupportActionBar(toolbar) - supportActionBar?.apply { - setDisplayHomeAsUpEnabled(true) - setDisplayShowHomeEnabled(true) - setHomeAsUpIndicator(GoogleMaterial.Icon.gmd_close.toDrawable(this@ImagePickerActivityBase, 18)) - } - toolbar.setNavigationOnClickListener { onBackPressed() } - - initializeRecycler(recycler) - - ImageItem.bindEvents(imageAdapter) - imageAdapter.withSelectionListener({ _, _ -> selectionCount.text = imageAdapter.selections.size.toString() }) - - fab.apply { - show() - setIcon(GoogleMaterial.Icon.gmd_send) - setOnClickListener { - val selection = imageAdapter.selectedItems - if (selection.isEmpty()) { - toast(R.string.kau_no_images_selected) - } else { - val intent = Intent() - val data = ArrayList(selection.map { it.data }) - intent.putParcelableArrayListExtra(IMAGE_PICKER_RESULT, data) - setResult(RESULT_OK, intent) - finish() - } - } - hideOnDownwardsScroll(recycler) - } - - loadImages() - } - - override fun converter(model: ImageModel): ImageItem = ImageItem(model) - - /** - * Decide whether the toolbar can hide itself - * We typically want this behaviour unless we don't have enough images - * to fill the entire screen. In that case we don't want the recyclerview to be scrollable - * which means the toolbar shouldn't scroll either - - * @param scrollable true if scroll flags are enabled, false otherwise - */ - private fun setToolbarScrollable(scrollable: Boolean) { - val params = toolbar.layoutParams as AppBarLayout.LayoutParams - if (scrollable) - params.scrollFlags = AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS or AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL - else - params.scrollFlags = 0 - } - - override fun onLoadFinished(loader: Loader?, data: Cursor?) { - super.onLoadFinished(loader, data) - setToolbarScrollable((recycler.layoutManager as LinearLayoutManager).findLastCompletelyVisibleItemPosition() < imageAdapter.getItemCount() - 1) - } - - override fun onStatusChange(loaded: Boolean) { - setToolbarScrollable(loaded) - } - -} \ No newline at end of file diff --git a/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerActivityOverlayBase.kt b/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerActivityOverlayBase.kt deleted file mode 100644 index ed8eee4..0000000 --- a/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerActivityOverlayBase.kt +++ /dev/null @@ -1,51 +0,0 @@ -package ca.allanwang.kau.imagepicker - -import android.os.Build -import android.os.Bundle -import android.support.annotation.RequiresApi -import android.support.v7.widget.RecyclerView -import ca.allanwang.kau.ui.widgets.ElasticDragDismissFrameLayout -import ca.allanwang.kau.utils.bindView -import ca.allanwang.kau.utils.toast - -/** - * Created by Allan Wang on 2017-07-23. - * - * Base activity for selecting images from storage - * This variant is an overlay and selects one image only before returning directly - * It is more efficient than [ImagePickerActivityBase], as all images are one layer deep - * as opposed to three layers deep - */ -@RequiresApi(Build.VERSION_CODES.LOLLIPOP) -abstract class ImagePickerActivityOverlayBase : ImagePickerCore() { - - val draggable: ElasticDragDismissFrameLayout by bindView(R.id.kau_draggable) - val recycler: RecyclerView by bindView(R.id.kau_recyclerview) - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.kau_activity_image_picker_overlay) - initializeRecycler(recycler) - ImageItemBasic.bindEvents(this, imageAdapter) - - draggable.addExitListener(this, R.transition.kau_image_exit_bottom, R.transition.kau_image_exit_top) - draggable.setOnClickListener { finishAfterTransition() } - - loadImages() - } - - override fun finishAfterTransition() { - recycler.stopScroll() - super.finishAfterTransition() - } - - override fun onStatusChange(loaded: Boolean) { - if (!loaded) toast(R.string.kau_no_images_loaded) - } - - override fun converter(model: ImageModel): ImageItemBasic = ImageItemBasic(model) - - override fun onBackPressed() { - finishAfterTransition() - } -} \ No newline at end of file diff --git a/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerBinder.kt b/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerBinder.kt deleted file mode 100644 index db8d113..0000000 --- a/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerBinder.kt +++ /dev/null @@ -1,34 +0,0 @@ -package ca.allanwang.kau.imagepicker - -import android.app.Activity -import android.content.Intent -import ca.allanwang.kau.utils.startActivityForResult - -/** - * Created by Allan Wang on 2017-07-21. - * - * Extension functions for interacting with the image picker - * as well as internal constants - */ - -/** - * Image picker launchers - */ -fun Activity.kauLaunchImagePicker(clazz: Class>, requestCode: Int) { -// startActivityForResult(clazz, requestCode, true) - startActivityForResult(clazz, requestCode, transition = ImagePickerActivityOverlayBase::class.java.isAssignableFrom(clazz)) -} - -/** - * Image picker result - * call under [Activity.onActivityResult] - * and make sure that the requestCode matches first - */ -fun Activity.kauOnImagePickerResult(resultCode: Int, data: Intent?) = ImagePickerCore.onImagePickerResult(resultCode, data) - -internal const val LOADER_ID = 42 -internal const val IMAGE_PICKER_RESULT = "image_picker_result" - -internal const val ANIMATION_DURATION = 200L -internal const val ANIMATION_SCALE = 0.95f - diff --git a/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerCore.kt b/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerCore.kt deleted file mode 100644 index f197a5e..0000000 --- a/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerCore.kt +++ /dev/null @@ -1,200 +0,0 @@ -package ca.allanwang.kau.imagepicker - -import android.Manifest -import android.app.Activity -import android.content.Context -import android.content.Intent -import android.database.Cursor -import android.graphics.Color -import android.graphics.drawable.Drawable -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 ca.allanwang.kau.animators.FadeScaleAnimatorAdd -import ca.allanwang.kau.animators.KauAnimator -import ca.allanwang.kau.permissions.kauRequestPermissions -import ca.allanwang.kau.utils.dimenPixelSize -import ca.allanwang.kau.utils.toast -import com.mikepenz.fastadapter.IItem -import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter -import com.mikepenz.google_material_typeface_library.GoogleMaterial -import com.mikepenz.iconics.IconicsDrawable - -/** - * Created by Allan Wang on 2017-07-23. - * - * Container for the main logic behind the image pickers - */ -abstract class ImagePickerCore> : AppCompatActivity(), LoaderManager.LoaderCallbacks { - - companion object { - /** - * Given the dimensions of our device and a minimum image size, - * Computer the optimal column count for our grid layout - * - * @return column count - */ - fun computeColumnCount(context: Context): Int { - val minImageSizePx = context.dimenPixelSize(R.dimen.kau_image_minimum_size) - val screenWidthPx = context.resources.displayMetrics.widthPixels - return screenWidthPx / minImageSizePx - } - - /** - * Compute our resulting image size - */ - fun computeViewSize(context: Context): Int { - val screenWidthPx = context.resources.displayMetrics.widthPixels - return screenWidthPx / computeColumnCount(context) - } - - /** - * Create error tile for a given item - */ - fun getErrorDrawable(context: Context): Drawable { - val sizePx = ImagePickerCore.computeViewSize(context) - return IconicsDrawable(context, GoogleMaterial.Icon.gmd_error) - .sizePx(sizePx) - .backgroundColor(accentColor) - .paddingPx(sizePx / 3) - .color(Color.WHITE) - } - - var accentColor: Int = 0xff666666.toInt() - - /** - * Helper method to retrieve the images from our iamge picker - * This is used for both single and multiple photo picks - */ - fun onImagePickerResult(resultCode: Int, data: Intent?): List { - if (resultCode != Activity.RESULT_OK || data == null || !data.hasExtra(IMAGE_PICKER_RESULT)) - return emptyList() - return data.getParcelableArrayListExtra(IMAGE_PICKER_RESULT) - } - - /** - * Number of loaded images we should cache - * This is arbitrary - */ - const val CACHE_SIZE = 80 - - /** - * We know that Glide takes a while to initially fetch the images - * My as well make it look pretty - */ - const val INITIAL_LOAD_DELAY = 600L - } - - val imageAdapter: FastItemAdapter = FastItemAdapter() - - /** - * Further improve preloading by extending the layout space - */ - val extraSpace: Int by lazy { resources.displayMetrics.heightPixels } - - fun initializeRecycler(recycler: RecyclerView) { - recycler.apply { - val manager = object : GridLayoutManager(context, computeColumnCount(context)) { - override fun getExtraLayoutSpace(state: RecyclerView.State?): Int { - return extraSpace - } - } - setItemViewCacheSize(CACHE_SIZE) - isDrawingCacheEnabled = true - layoutManager = manager - adapter = imageAdapter - setHasFixedSize(true) - itemAnimator = object : KauAnimator(FadeScaleAnimatorAdd(0.8f)) { - override fun startDelay(holder: RecyclerView.ViewHolder, duration: Long, factor: Float): Long { - return super.startDelay(holder, duration, factor) + INITIAL_LOAD_DELAY - } - } - } - } - - //Sort by descending date - var sortQuery = MediaStore.Images.Media.DATE_MODIFIED + " DESC" - - /** - * Request read permissions and load all external images - * The result will be filtered through {@link #onLoadFinished(Loader, Cursor)} - * Call this to make sure that we request permissions each time - * The adapter will be cleared on each successful call - */ - open fun loadImages() { - kauRequestPermissions(Manifest.permission.READ_EXTERNAL_STORAGE) { - granted, _ -> - if (granted) { - supportLoaderManager.initLoader(LOADER_ID, null, this) - onStatusChange(true) - } else { - toast(R.string.kau_permission_denied) - onStatusChange(false) - } - } - } - - override fun onCreateLoader(id: Int, args: Bundle?): Loader { - val columns = arrayOf( - MediaStore.Images.Media._ID, - MediaStore.Images.Media.TITLE, - MediaStore.Images.Media.DATA, - MediaStore.Images.Media.SIZE, - MediaStore.Images.Media.DISPLAY_NAME, - MediaStore.Images.Media.DATE_MODIFIED - ) - return CursorLoader(this, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null, null, sortQuery) - } - - override fun onLoadFinished(loader: Loader?, data: Cursor?) { - reset() - if (data == null || !data.moveToFirst()) { - toast(R.string.kau_no_images_found) - onStatusChange(false) - return - } - val items = mutableListOf() - do { - val model = ImageModel(data) - if (!shouldLoad(model)) continue - items.add(converter(model)) - } while (data.moveToNext()) - addItems(items) - } - - abstract fun converter(model: ImageModel): T - - override fun onLoaderReset(loader: Loader?) = reset() - - /** - * Called at the end of [onLoadFinished] - * when the adapter should add the items - */ - open fun addItems(items: List) { - imageAdapter.add(items) - } - - /** - * Clears the adapter to prepare for a new load - */ - open fun reset() { - imageAdapter.clear() - } - - /** - * Optional filter to decide which images get displayed - * Defaults to checking their sizes to filter out - * very small images such as lurking drawables/icons - * - * Returns true if model should be displayed, false otherwise - */ - open fun shouldLoad(model: ImageModel): Boolean = model.size > 10000L - - open fun onStatusChange(loaded: Boolean) {} - -} \ No newline at end of file diff --git a/imagepicker/src/main/res-public/values-v21/styles.xml b/imagepicker/src/main/res-public/values-v21/styles.xml deleted file mode 100644 index bae68da..0000000 --- a/imagepicker/src/main/res-public/values-v21/styles.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - diff --git a/imagepicker/src/main/res-public/values/colors.xml b/imagepicker/src/main/res-public/values/colors.xml deleted file mode 100644 index ebaa3f7..0000000 --- a/imagepicker/src/main/res-public/values/colors.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - #30000000 - - \ No newline at end of file diff --git a/imagepicker/src/main/res-public/values/dimens.xml b/imagepicker/src/main/res-public/values/dimens.xml deleted file mode 100644 index 3ff2dd7..0000000 --- a/imagepicker/src/main/res-public/values/dimens.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - 120dp - - \ No newline at end of file diff --git a/imagepicker/src/main/res-public/values/public.xml b/imagepicker/src/main/res-public/values/public.xml deleted file mode 100644 index a892651..0000000 --- a/imagepicker/src/main/res-public/values/public.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/imagepicker/src/main/res-public/values/styles.xml b/imagepicker/src/main/res-public/values/styles.xml deleted file mode 100644 index 99f294a..0000000 --- a/imagepicker/src/main/res-public/values/styles.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - diff --git a/imagepicker/src/main/res/layout-v21/kau_activity_image_picker_overlay.xml b/imagepicker/src/main/res/layout-v21/kau_activity_image_picker_overlay.xml deleted file mode 100644 index a0ce301..0000000 --- a/imagepicker/src/main/res/layout-v21/kau_activity_image_picker_overlay.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - \ 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 deleted file mode 100644 index 6d991b0..0000000 --- a/imagepicker/src/main/res/layout/kau_activity_image_picker.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/imagepicker/src/main/res/layout/kau_blurred_imageview.xml b/imagepicker/src/main/res/layout/kau_blurred_imageview.xml deleted file mode 100644 index e28cb9a..0000000 --- a/imagepicker/src/main/res/layout/kau_blurred_imageview.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - \ 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 deleted file mode 100644 index 9d51d77..0000000 --- a/imagepicker/src/main/res/layout/kau_iitem_image.xml +++ /dev/null @@ -1,9 +0,0 @@ - - \ No newline at end of file diff --git a/imagepicker/src/main/res/layout/kau_iitem_image_basic.xml b/imagepicker/src/main/res/layout/kau_iitem_image_basic.xml deleted file mode 100644 index b89e41d..0000000 --- a/imagepicker/src/main/res/layout/kau_iitem_image_basic.xml +++ /dev/null @@ -1,10 +0,0 @@ - - \ No newline at end of file diff --git a/imagepicker/src/main/res/transition-v21/kau_image_enter.xml b/imagepicker/src/main/res/transition-v21/kau_image_enter.xml deleted file mode 100644 index 447c0c9..0000000 --- a/imagepicker/src/main/res/transition-v21/kau_image_enter.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - diff --git a/imagepicker/src/main/res/transition-v21/kau_image_exit_bottom.xml b/imagepicker/src/main/res/transition-v21/kau_image_exit_bottom.xml deleted file mode 100644 index 447c0c9..0000000 --- a/imagepicker/src/main/res/transition-v21/kau_image_exit_bottom.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - diff --git a/imagepicker/src/main/res/transition-v21/kau_image_exit_top.xml b/imagepicker/src/main/res/transition-v21/kau_image_exit_top.xml deleted file mode 100644 index 8d64f48..0000000 --- a/imagepicker/src/main/res/transition-v21/kau_image_exit_top.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - diff --git a/imagepicker/src/main/res/values/strings.xml b/imagepicker/src/main/res/values/strings.xml deleted file mode 100644 index 17af1d8..0000000 --- a/imagepicker/src/main/res/values/strings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - No images found - No images have been selected - Blurrable ImageView - No images loaded - \ No newline at end of file -- cgit v1.2.3