|
@@ -2,8 +2,16 @@ package im.angry.openeuicc.util
|
|
|
|
|
|
|
|
import android.content.res.Resources
|
|
import android.content.res.Resources
|
|
|
import android.graphics.Rect
|
|
import android.graphics.Rect
|
|
|
|
|
+import android.view.View
|
|
|
import android.view.ViewGroup
|
|
import android.view.ViewGroup
|
|
|
|
|
+import androidx.appcompat.app.AppCompatActivity
|
|
|
|
|
+import androidx.appcompat.widget.Toolbar
|
|
|
|
|
+import androidx.core.view.ViewCompat
|
|
|
|
|
+import androidx.core.view.WindowInsetsCompat
|
|
|
|
|
+import androidx.core.view.updateLayoutParams
|
|
|
|
|
+import androidx.core.view.updatePadding
|
|
|
import androidx.fragment.app.DialogFragment
|
|
import androidx.fragment.app.DialogFragment
|
|
|
|
|
+import im.angry.openeuicc.common.R
|
|
|
|
|
|
|
|
// Source: <https://stackoverflow.com/questions/12478520/how-to-set-dialogfragments-width-and-height>
|
|
// Source: <https://stackoverflow.com/questions/12478520/how-to-set-dialogfragments-width-and-height>
|
|
|
/**
|
|
/**
|
|
@@ -26,3 +34,25 @@ fun DialogFragment.setWidthPercent(percentage: Int) {
|
|
|
fun DialogFragment.setFullScreen() {
|
|
fun DialogFragment.setFullScreen() {
|
|
|
dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
|
dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+fun AppCompatActivity.setupToolbarInsets() {
|
|
|
|
|
+ val spacer = requireViewById<View>(R.id.toolbar_spacer)
|
|
|
|
|
+ ViewCompat.setOnApplyWindowInsetsListener(requireViewById(R.id.toolbar)) { v, insets ->
|
|
|
|
|
+ val bars = insets.getInsets(
|
|
|
|
|
+ WindowInsetsCompat.Type.systemBars()
|
|
|
|
|
+ or WindowInsetsCompat.Type.displayCutout()
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ v.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
|
|
|
|
+ topMargin = bars.top
|
|
|
|
|
+ }
|
|
|
|
|
+ v.updatePadding(bars.left, v.paddingTop, bars.right, v.paddingBottom)
|
|
|
|
|
+
|
|
|
|
|
+ spacer.updateLayoutParams {
|
|
|
|
|
+ height = v.top
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ android.util.Log.d("aaa", "${(v as Toolbar).minimumHeight}")
|
|
|
|
|
+ WindowInsetsCompat.CONSUMED
|
|
|
|
|
+ }
|
|
|
|
|
+}
|