Create BottomSheetDialog and related stuff
This commit is contained in:
parent
fb4b8fe169
commit
27d1bfec7b
5 changed files with 120 additions and 0 deletions
11
OsmAnd-telegram/res/anim/slide_in_bottom.xml
Normal file
11
OsmAnd-telegram/res/anim/slide_in_bottom.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<translate
|
||||
android:duration="@android:integer/config_mediumAnimTime"
|
||||
android:fromYDelta="100%p"
|
||||
android:toYDelta="0"/>
|
||||
<alpha
|
||||
android:duration="@android:integer/config_mediumAnimTime"
|
||||
android:fromAlpha="0.0"
|
||||
android:toAlpha="1.0"/>
|
||||
</set>
|
11
OsmAnd-telegram/res/anim/slide_out_bottom.xml
Normal file
11
OsmAnd-telegram/res/anim/slide_out_bottom.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<translate
|
||||
android:duration="@android:integer/config_mediumAnimTime"
|
||||
android:fromYDelta="0"
|
||||
android:toYDelta="100%p"/>
|
||||
<alpha
|
||||
android:duration="@android:integer/config_mediumAnimTime"
|
||||
android:fromAlpha="1.0"
|
||||
android:toAlpha="0.0"/>
|
||||
</set>
|
19
OsmAnd-telegram/res/layout/bottom_sheet_dialog.xml
Normal file
19
OsmAnd-telegram/res/layout/bottom_sheet_dialog.xml
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<View
|
||||
android:id="@+id/touch_outside"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/content_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal|bottom"/>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
|
@ -73,4 +73,13 @@
|
|||
<item name="android:background">@drawable/btn_round</item>
|
||||
</style>
|
||||
|
||||
<style name="Animations"/>
|
||||
|
||||
<style name="Animations.PopUpMenu"/>
|
||||
|
||||
<style name="Animations.PopUpMenu.Bottom">
|
||||
<item name="android:windowEnterAnimation">@anim/slide_in_bottom</item>
|
||||
<item name="android:windowExitAnimation">@anim/slide_out_bottom</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
package net.osmand.telegram.ui.views
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.Window
|
||||
import android.view.WindowManager
|
||||
import net.osmand.telegram.R
|
||||
|
||||
class BottomSheetDialog(ctx: Context, themeId: Int) : Dialog(ctx, themeId) {
|
||||
|
||||
init {
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
window?.apply {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
|
||||
addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
|
||||
}
|
||||
setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
|
||||
attributes?.windowAnimations = R.style.Animations_PopUpMenu_Bottom
|
||||
}
|
||||
}
|
||||
|
||||
override fun setContentView(layoutResID: Int) {
|
||||
super.setContentView(wrapInContainer(layoutResID, null, null))
|
||||
}
|
||||
|
||||
override fun setContentView(view: View?) {
|
||||
super.setContentView(wrapInContainer(0, view, null))
|
||||
}
|
||||
|
||||
override fun setContentView(view: View?, params: ViewGroup.LayoutParams?) {
|
||||
super.setContentView(wrapInContainer(0, view, params))
|
||||
}
|
||||
|
||||
private fun wrapInContainer(
|
||||
layoutResId: Int,
|
||||
view: View?,
|
||||
params: ViewGroup.LayoutParams?
|
||||
): View {
|
||||
val res = View.inflate(context, R.layout.bottom_sheet_dialog, null)
|
||||
val container = res.findViewById<ViewGroup>(R.id.content_container)
|
||||
var v = view
|
||||
|
||||
if (layoutResId != 0 && v == null) {
|
||||
v = layoutInflater.inflate(layoutResId, container, false)
|
||||
}
|
||||
if (params == null) {
|
||||
container.addView(v)
|
||||
} else {
|
||||
container.addView(v, params)
|
||||
}
|
||||
|
||||
res.findViewById<View>(R.id.touch_outside).setOnClickListener {
|
||||
cancel()
|
||||
}
|
||||
|
||||
// Consume the event and prevent it from falling through
|
||||
container.setOnTouchListener { _, _ -> return@setOnTouchListener true }
|
||||
|
||||
return res
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue