From 2a9d5916a2acd0b468b9aa28977021fdd483e2aa Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 2 Jan 2018 23:38:51 -0500 Subject: Fix/searchview (#123) * Use workaround for kclick * Add text cleared callback * Add bundle scene transition functions * Add applier * Remove need for explicit context * Revert --- .../kotlin/ca/allanwang/kau/utils/BundleUtils.kt | 26 +++++++++++++++++++++- core/src/main/res-public/values/public.xml | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/BundleUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/BundleUtils.kt index 76c314a..82cd577 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/BundleUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/BundleUtils.kt @@ -6,6 +6,8 @@ import android.app.ActivityOptions import android.content.Context import android.os.Bundle import android.support.annotation.AnimRes +import android.util.Pair +import android.view.View import ca.allanwang.kau.R /** @@ -25,7 +27,29 @@ infix fun Bundle.with(bundle: Bundle?): Bundle { @SuppressLint("NewApi") fun Bundle.withSceneTransitionAnimation(context: Context) { if (context !is Activity || !buildIsLollipopAndUp) return - this with ActivityOptions.makeSceneTransitionAnimation(context).toBundle() + val options = ActivityOptions.makeSceneTransitionAnimation(context) + putAll(options.toBundle()) +} + +/** + * Given the parent view and map of view ids to tags, + * create a scene transition animation + */ +fun Bundle.withSceneTransitionAnimation(parent: View, data: Map) = + withSceneTransitionAnimation(parent.context, data.mapKeys { (id, _) -> + parent.findViewById(id) + }) + +/** + * Given a mapping of views to tags, + * create a scene transition animation + */ +@SuppressLint("NewApi") +fun Bundle.withSceneTransitionAnimation(context: Context, data: Map) { + if (context !is Activity || !buildIsLollipopAndUp) return + val options = ActivityOptions.makeSceneTransitionAnimation(context, + *data.map { (view, tag) -> Pair(view, tag) }.toTypedArray()) + putAll(options.toBundle()) } fun Bundle.withCustomAnimation(context: Context, diff --git a/core/src/main/res-public/values/public.xml b/core/src/main/res-public/values/public.xml index c309a70..f831c6d 100644 --- a/core/src/main/res-public/values/public.xml +++ b/core/src/main/res-public/values/public.xml @@ -1,5 +1,5 @@ - + -- cgit v1.2.3