Problem: I'm showing a Dialog that I want in full screen but the status bar and navigation bar are limiting so how do I make it full screen how to hide all the bar and make it full screen
Problem: I'm showing a Dialog that I want in full screen but the status bar and navigation bar are limiting so how do I make it full screen
how to hide all the bar and make it full screen
@SuppressLint("ClickableViewAccessibility") class WindowUtil(context: Context) : View.OnTouchListener {
private var context: Context? = null
private var mView: View? = null
private var mParams: WindowManager.LayoutParams? = null
private var mWindowManager: WindowManager? = null
private var layoutInflater: LayoutInflater? = null
private var initialX = 0
private var initialY = 0
private var initialTouchX = 0f
private var initialTouchY = 0f
init {
this.context = context
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// set the layout parameters of the window
mParams = WindowManager.LayoutParams( // Shrink the window to wrap the content rather
// than filling the screen
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT, // Display it on top of other application windows
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, // Don't let it grab the input focus
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, // Make the underlying application window visible
// through any transparent parts
PixelFormat.TRANSLUCENT
)
}
// getting a LayoutInflater
layoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
// inflating the view with the custom layout we created
mView = layoutInflater!!.inflate(R.layout.tapp_popup_lay,null)
// set onClickListener on the remove button, which removes
// the view from the window
mView?.findViewById<AppCompatImageView>(R.id.tappIcon)
?.setOnTouchListener(this)
mView?.findViewById<AppCompatImageView>(R.id.tappIcon)!!.animate().alpha(0.5f).setDuration(10000).start()
// Define the position of the
// window within the screen
mParams!!.gravity = Gravity.CENTER
mWindowManager = context.getSystemService(WINDOW_SERVICE) as WindowManager
}
fun open() {
try {
// check if the view is already
// inflated or present in the window
if (mView?.windowToken == null) {
if (mView?.parent == null) {
mWindowManager!!.addView(mView, mParams)
}
}
} catch (e: Exception) {
Log.d("Error1", e.toString())
}
}
fun close() {
try {
// remove the view from the window
(context?.getSystemService(WINDOW_SERVICE) as WindowManager).removeView(mView)
// invalidate the view
mView?.invalidate()
// remove all views
(mView?.parent as ViewGroup).removeAllViews()
Log.d("***********", "onCreate: stop ")
// the above steps are necessary when you are adding and removing
// the view simultaneously, it might give some exceptions
} catch (e: Exception) {
Log.d("Error2", e.toString())
}
}
override fun onTouch(v: View?, event: MotionEvent?): Boolean {
Log.d("AD", "Action E$event")
when (event?.action) {
MotionEvent.ACTION_DOWN -> {
Log.d("AD", "Action Down")
mView?.findViewById<AppCompatImageView>(R.id.tappIcon)!!.animate().alpha(1f)
.setDuration(0).start()
initialX = mParams!!.x
initialY = mParams!!.y
initialTouchX = event.rawX
initialTouchY = event.rawY
return true
}
MotionEvent.ACTION_UP -> {
Log.d("AD", "Action Up")
mView?.findViewById<AppCompatImageView>(R.id.tappIcon)!!.animate().alpha(0.5f)
.setDuration(5000).start()
val Xdiff = (event.rawX - initialTouchX).toInt()
val Ydiff = (event.rawY - initialTouchY).toInt()
if (Xdiff < 10 && Ydiff < 10) {
v?.performClick()
Log.d("AD", "Action Clicked *************")
//user clicked
}
return true
}
MotionEvent.ACTION_MOVE -> {
Log.d("AD", "Action Move")
mParams?.x = initialX + (event.rawX - initialTouchX).toInt()
mParams?.y = initialY + (event.rawY - initialTouchY).toInt()
mView?.findViewById<AppCompatImageView>(R.id.tappIcon)!!.animate().setDuration(0)
.start()
mWindowManager!!.updateViewLayout(mView, mParams)
return true
}
}
return false
}
}