diff options
Diffstat (limited to 'imagepicker')
27 files changed, 0 insertions, 1020 deletions
diff --git a/imagepicker/.gitignore b/imagepicker/.gitignore deleted file mode 100644 index 796b96d..0000000 --- a/imagepicker/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/imagepicker/README.md b/imagepicker/README.md deleted file mode 100644 index f70de2b..0000000 --- a/imagepicker/README.md +++ /dev/null @@ -1,41 +0,0 @@ -# KAU :imagepicker - -ImagePicker is a beautiful gallery activity that allows you to pick images -from your storage. It is backed by FastAdapter and Glide, and stems from the ImagePickerCore model - -Currently, there are two options: - --------------------------------- - -## ImagePickerActivityBase - -A full screen multi image picker with beautiful animations. -Images are blurred when selected, and there is a counter on the top right. -There is a FAB to send back the response. - -`R.style.Kau.ImagePicker` is added for your convenience. - -## ImagePickerActivityOverlayBase - -This overlaying activity makes use of transitions and nested scrolling, and is only for Lollipop and up. -Only one image can be selected, so the overlay exists immediately upon the first selection. -Having this model also means that each item is only one simple image, as opposed to the blurrable image view above. -As a result, this activity has faster loading on scrolling. - -`R.style.Kau.ImagePicker.Overlay` is added for your convenience. - --------------------------------- - -Both activities work out of the box and can be extended without needing further modifications. -Their convenience styles default to a slide in slide out animation from the bottom edge. - -You may also easily launch either activity through the simple binder: -``` -Activity.kauLaunchImagePicker(YourClass::class.java, yourRequestCode) -``` - -Note that this launches the activity through a `startActivityForResult` call - -You may get the activity response by overriding your `onActivityResult` method -to first verify that the request code matches and then call `kauOnImagePickerResult`, -which will return the list of ImageModels.
\ No newline at end of file diff --git a/imagepicker/build.gradle b/imagepicker/build.gradle deleted file mode 100644 index 93f52ac..0000000 --- a/imagepicker/build.gradle +++ /dev/null @@ -1,14 +0,0 @@ -ext.kauSubModuleMinSdk = project.CORE_MIN_SDK - -apply from: '../android-lib.gradle' - -dependencies { - - compile project(':core-ui') - - compile "com.github.bumptech.glide:glide:${GLIDE}" - kapt "com.github.bumptech.glide:compiler:${GLIDE}" - compile "jp.wasabeef:blurry:${BLURRY}" -} - -apply from: '../artifacts.gradle' diff --git a/imagepicker/progress-proguard.txt b/imagepicker/progress-proguard.txt deleted file mode 100644 index 8b13789..0000000 --- a/imagepicker/progress-proguard.txt +++ /dev/null @@ -1 +0,0 @@ - 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 @@ -<manifest package="ca.allanwang.kau.imagepicker" /> 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<ImageItem, ImageItem.ViewHolder>(R.layout.kau_iitem_image, { ViewHolder(it) }) { - - private var failedToLoad = false - - companion object { - fun bindEvents(fastAdapter: FastAdapter<ImageItem>) { - 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<Any>?) { - super.bindView(holder, payloads) - Glide.with(holder.itemView) - .load(data.data) - .listener(object : RequestListener<Drawable> { - override fun onLoadFailed(e: GlideException?, model: Any, target: Target<Drawable>, 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<Drawable>, 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<ImageItem, ImageItemBasic.ViewHolder>(R.layout.kau_iitem_image_basic, { ViewHolder(it) }) { - - companion object { - @SuppressLint("NewApi") - fun bindEvents(activity: Activity, fastAdapter: FastAdapter<ImageItemBasic>) { - 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<Any>?) { - super.bindView(holder, payloads) - Glide.with(holder.itemView) - .load(data.data) - .listener(object : RequestListener<Drawable> { - override fun onLoadFailed(e: GlideException?, model: Any, target: Target<Drawable>, isFirstResource: Boolean): Boolean { - holder.image.setImageDrawable(ImagePickerCore.getErrorDrawable(holder.itemView.context)) - return true; - } - - override fun onResourceReady(resource: Drawable, model: Any, target: Target<Drawable>, 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<ImageModel> { - override fun createFromParcel(parcel: Parcel): ImageModel { - return ImageModel(parcel) - } - - override fun newArray(size: Int): Array<ImageModel?> { - 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<ImageItem>() { - - 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<Cursor>?, 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<ImageItemBasic>() { - - 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<out ImagePickerCore<*>>, 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<T : IItem<*, *>> : AppCompatActivity(), LoaderManager.LoaderCallbacks<Cursor> { - - 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<ImageModel> { - 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<T> = 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<Cursor> { - 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<Cursor>?, data: Cursor?) { - reset() - if (data == null || !data.moveToFirst()) { - toast(R.string.kau_no_images_found) - onStatusChange(false) - return - } - val items = mutableListOf<T>() - 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<Cursor>?) = reset() - - /** - * Called at the end of [onLoadFinished] - * when the adapter should add the items - */ - open fun addItems(items: List<T>) { - 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 @@ -<resources> - - <style name="Kau.ImagePicker.Overlay" parent="Kau.Translucent"> - <item name="android:statusBarColor">@android:color/transparent</item> - <item name="android:windowEnterTransition">@transition/kau_image_enter</item> - <item name="android:windowReturnTransition">@transition/kau_image_exit_bottom</item> - </style> - -</resources> 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 @@ -<?xml version="1.0" encoding="utf-8"?> -<resources> - - <color name="kau_blurred_image_selection_overlay">#30000000</color> - -</resources>
\ 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 @@ -<?xml version="1.0" encoding="utf-8"?> -<resources> - - <dimen name="kau_image_minimum_size">120dp</dimen> - -</resources>
\ 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 @@ -<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_blurred_image_selection_overlay' type='color' /> - <public name='kau_image_minimum_size' type='dimen' /> - <public name='Kau.ImagePicker' type='style' /> - <public name='Kau.ImagePicker.Overlay' type='style' /> -</resources>
\ 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 @@ -<resources> - - <style name="Kau.ImagePicker"> - <item name="android:windowAnimationStyle">@style/KauSlideInSlideOutBottom</item> - </style> - - <!--Just as a placeholder for public.xml--> - <style name="Kau.ImagePicker.Overlay" parent="Kau.Translucent"> - <item name="android:windowAnimationStyle">@null</item> - </style> - -</resources> 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 @@ -<?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.v7.widget.RecyclerView - android:id="@+id/kau_recyclerview" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:layout_marginTop="@dimen/kau_drag_dismiss_distance" - android:background="?android:colorBackground" /> - -</ca.allanwang.kau.ui.widgets.ElasticDragDismissFrameLayout>
\ 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 @@ -<?xml version="1.0" encoding="utf-8"?> -<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:app="http://schemas.android.com/apk/res-auto" - android:id="@+id/kau_coordinator" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:background="?android:colorBackground" - android:fitsSystemWindows="true"> - - <android.support.design.widget.AppBarLayout - android:id="@+id/kau_appbar" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> - - <android.support.v7.widget.Toolbar - android:id="@+id/kau_toolbar" - android:layout_width="match_parent" - android:layout_height="?attr/actionBarSize" - app:layout_scrollFlags="scroll|enterAlways" - app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> - - <TextView - android:id="@+id/kau_selection_count" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_gravity="end" - android:drawablePadding="@dimen/kau_padding_small" - android:gravity="center_vertical" - android:paddingEnd="@dimen/kau_padding_normal" - android:paddingStart="@dimen/kau_padding_normal" - android:text="@string/kau_0" /> - - </android.support.v7.widget.Toolbar> - - </android.support.design.widget.AppBarLayout> - - <android.support.v7.widget.RecyclerView - android:id="@+id/kau_recyclerview" - android:layout_width="match_parent" - android:layout_height="match_parent" - 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" - app:backgroundTint="?colorAccent" - app:layout_anchor="@id/kau_recyclerview" - app:layout_anchorGravity="bottom|right|end" /> - - -</android.support.design.widget.CoordinatorLayout>
\ 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 @@ -<?xml version="1.0" encoding="utf-8"?> -<merge 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/image_base" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:contentDescription="@string/kau_blurrable_imageview" - android:scaleType="centerCrop" /> - - <ImageView - android:id="@+id/image_blur" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:alpha="0" - android:contentDescription="@string/kau_blurrable_imageview" - android:scaleType="centerCrop" /> - - <ImageView - android:id="@+id/image_foreground" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:layout_gravity="center" - android:alpha="0" - android:background="@color/kau_blurred_image_selection_overlay" - android:contentDescription="@string/kau_blurrable_imageview" - android:scaleType="centerInside" /> - -</merge>
\ 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 @@ -<?xml version="1.0" encoding="utf-8"?> -<ca.allanwang.kau.imagepicker.BlurredImageView xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:app="http://schemas.android.com/apk/res-auto" - android:id="@+id/kau_image" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:layout_margin="2dp" - android:foreground="@drawable/kau_selectable_white" - app:relativeHeight="1" />
\ 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 @@ -<?xml version="1.0" encoding="utf-8"?> -<ca.allanwang.kau.ui.views.MeasuredImageView xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:app="http://schemas.android.com/apk/res-auto" - android:id="@+id/kau_image" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:layout_margin="2dp" - android:foreground="@drawable/kau_selectable_white" - android:scaleType="centerCrop" - app:relativeHeight="1" />
\ 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 @@ -<?xml version="1.0" encoding="utf-8"?> -<transitionSet xmlns:android="http://schemas.android.com/apk/res/android" - android:interpolator="@android:interpolator/fast_out_linear_in" - android:transitionOrdering="together"> - - <slide - android:duration="400" - android:slideEdge="bottom"> - <targets android:targetId="@id/kau_draggable" /> - </slide> - - <fade - android:duration="200" - android:startDelay="200" /> - -</transitionSet> 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 @@ -<?xml version="1.0" encoding="utf-8"?> -<transitionSet xmlns:android="http://schemas.android.com/apk/res/android" - android:interpolator="@android:interpolator/fast_out_linear_in" - android:transitionOrdering="together"> - - <slide - android:duration="400" - android:slideEdge="bottom"> - <targets android:targetId="@id/kau_draggable" /> - </slide> - - <fade - android:duration="200" - android:startDelay="200" /> - -</transitionSet> 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 @@ -<?xml version="1.0" encoding="utf-8"?> -<transitionSet xmlns:android="http://schemas.android.com/apk/res/android" - android:interpolator="@android:interpolator/fast_out_linear_in" - android:transitionOrdering="together"> - - <slide - android:duration="400" - android:slideEdge="top"> - <targets android:targetId="@id/kau_draggable" /> - </slide> - - <fade - android:duration="200" - android:startDelay="200" /> - -</transitionSet> 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 @@ -<?xml version="1.0" encoding="utf-8"?> -<resources> - <string name="kau_no_images_found">No images found</string> - <string name="kau_no_images_selected">No images have been selected</string> - <string name="kau_blurrable_imageview">Blurrable ImageView</string> - <string name="kau_no_images_loaded">No images loaded</string> -</resources>
\ No newline at end of file |