diff options
Diffstat (limited to 'sample/src/main/kotlin')
-rw-r--r-- | sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt | 5 | ||||
-rw-r--r-- | sample/src/main/kotlin/ca/allanwang/kau/sample/SwipeActivity.kt | 75 |
2 files changed, 78 insertions, 2 deletions
diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt index 62ca8a3..51b8530 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt @@ -14,6 +14,7 @@ import ca.allanwang.kau.mediapicker.kauOnMediaPickerResult import ca.allanwang.kau.searchview.SearchItem import ca.allanwang.kau.searchview.SearchView import ca.allanwang.kau.searchview.bindSearchView +import ca.allanwang.kau.swipe.SWIPE_EDGE_LEFT import ca.allanwang.kau.ui.views.RippleCanvas import ca.allanwang.kau.utils.materialDialog import ca.allanwang.kau.utils.navigationBarColor @@ -164,8 +165,8 @@ class MainActivity : KPrefActivity() { descRes = R.string.sub_item_desc } - plainText(R.string.image_showcase) { - onClick = { _, _, _ -> kauLaunchMediaPicker(ImagePickerActivity::class.java, REQUEST_MEDIA); false } + plainText(R.string.swipe_showcase) { + onClick = { _, _, _ -> startActivityWithEdge(SWIPE_EDGE_LEFT); false } } plainText(R.string.video_overlay_showcase) { diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/SwipeActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/SwipeActivity.kt new file mode 100644 index 0000000..cba9ccd --- /dev/null +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/SwipeActivity.kt @@ -0,0 +1,75 @@ +package ca.allanwang.kau.sample + +import android.app.Activity +import android.os.Bundle +import android.support.v7.widget.Toolbar +import android.view.ViewGroup +import android.widget.Button +import ca.allanwang.kau.internal.KauBaseActivity +import ca.allanwang.kau.swipe.* +import ca.allanwang.kau.utils.* + +/** + * Created by Allan Wang on 2017-08-05. + */ +private const val SWIPE_EDGE = "swipe_edge" + +fun Activity.startActivityWithEdge(flag: Int) { + startActivity(SwipeActivity::class.java) { + putExtra(SWIPE_EDGE, flag) + } +} + +class SwipeActivity : KauBaseActivity() { + + val toolbar: Toolbar by bindView(R.id.swipe_toolbar) + val container: ViewGroup by bindView(R.id.swipe_container) + val directions: List<Button> by bindViews(R.id.swipe_from_left, R.id.swipe_from_right, R.id.swipe_from_top, R.id.swipe_from_bottom) + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_swipe) + directions.forEach { + val swipeEdge = when (it.id) { + R.id.swipe_from_left -> SWIPE_EDGE_LEFT + R.id.swipe_from_right -> SWIPE_EDGE_RIGHT + R.id.swipe_from_top -> SWIPE_EDGE_TOP + R.id.swipe_from_bottom -> SWIPE_EDGE_BOTTOM + else -> -1 + } + it.setOnClickListener { startActivityWithEdge(swipeEdge) } + } + val flag = intent.getIntExtra(SWIPE_EDGE, -1) + kauSwipeOnCreate { + edgeFlag = flag + } + toolbar.title = when (flag) { + SWIPE_EDGE_LEFT -> "Left Edge Swipe" + SWIPE_EDGE_RIGHT -> "Right Edge Swipe" + SWIPE_EDGE_TOP -> "Top Edge Swipe" + SWIPE_EDGE_BOTTOM -> "Bottom Edge Swipe" + else -> "Invalid Edge Swipe" + } + setSupportActionBar(toolbar) + val headerColor = rndColor.darken(0.6f) + toolbar.setBackgroundColor(headerColor) + statusBarColor = headerColor + val bg = headerColor.darken(0.2f) + container.setBackgroundColor(bg) + navigationBarColor = bg + } + + override fun onPostCreate(savedInstanceState: Bundle?) { + super.onPostCreate(savedInstanceState) + kauSwipeOnPostCreate() + } + + override fun onDestroy() { + super.onDestroy() + kauSwipeOnDestroy() + } + + override fun onBackPressed() { + kauSwipeFinish() + } +}
\ No newline at end of file |