move system UI toggling into extensions

This commit is contained in:
tibbi 2016-11-12 23:27:10 +01:00
parent 493ba31c5f
commit 8ccb0385ca
5 changed files with 38 additions and 48 deletions

View file

@ -8,10 +8,11 @@ import android.database.Cursor
import android.net.Uri
import android.os.Build
import android.provider.MediaStore
import android.support.v7.app.ActionBar
import android.util.DisplayMetrics
import android.util.TypedValue
import android.view.*
import android.view.KeyCharacterMap
import android.view.KeyEvent
import android.view.ViewConfiguration
import android.webkit.MimeTypeMap
import com.simplemobiletools.filepicker.extensions.*
import com.simplemobiletools.gallery.models.Medium
@ -96,25 +97,6 @@ class Utils {
activity.startActivity(Intent.createChooser(intent, shareTitle))
}
fun showSystemUI(actionbar: ActionBar?, window: Window) {
actionbar?.show()
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
}
fun hideSystemUI(actionbar: ActionBar?, window: Window) {
actionbar?.hide()
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
View.SYSTEM_UI_FLAG_LOW_PROFILE or
View.SYSTEM_UI_FLAG_FULLSCREEN or
View.SYSTEM_UI_FLAG_IMMERSIVE
}
fun getRealPathFromURI(context: Context, uri: Uri): String? {
var cursor: Cursor? = null
try {

View file

@ -5,13 +5,11 @@ import android.content.res.Configuration
import android.net.Uri
import android.os.Bundle
import android.provider.MediaStore
import android.support.v7.app.ActionBar
import android.view.Menu
import android.view.MenuItem
import com.simplemobiletools.filepicker.extensions.getFilenameFromPath
import com.simplemobiletools.gallery.Constants
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.Utils
import com.simplemobiletools.gallery.fragments.PhotoFragment
import com.simplemobiletools.gallery.fragments.VideoFragment
import com.simplemobiletools.gallery.fragments.ViewPagerFragment
@ -20,10 +18,8 @@ import java.io.File
open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentClickListener {
companion object {
private var mActionbar: ActionBar? = null
private var mUri: Uri? = null
private var mFragment: ViewPagerFragment? = null
private var mIsFullScreen = false
var mIsVideo = false
}
@ -34,9 +30,7 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentClic
mUri = intent.data ?: return
mActionbar = supportActionBar
mIsFullScreen = true
hideSystemUI()
val bundle = Bundle()
val file = File(mUri!!.toString())
@ -49,7 +43,7 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentClic
mFragment!!.arguments = bundle
supportFragmentManager.beginTransaction().replace(R.id.fragment_holder, mFragment).commit()
}
hideSystemUI()
hideUI()
if (mUri!!.scheme == "content") {
val proj = arrayOf(MediaStore.Images.Media.TITLE)
@ -98,17 +92,9 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentClic
override fun fragmentClicked() {
mIsFullScreen = !mIsFullScreen
if (mIsFullScreen) {
hideSystemUI()
hideUI()
} else {
showSystemUI()
showUI()
}
}
private fun hideSystemUI() {
Utils.hideSystemUI(mActionbar, window)
}
private fun showSystemUI() {
Utils.showSystemUI(mActionbar, window)
}
}

View file

@ -11,6 +11,8 @@ import com.simplemobiletools.filepicker.extensions.isShowingWritePermissions
import com.simplemobiletools.gallery.Config
import com.simplemobiletools.gallery.Constants
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.extensions.hideSystemUI
import com.simplemobiletools.gallery.extensions.showSystemUI
import java.io.File
open class SimpleActivity : AppCompatActivity() {
@ -53,4 +55,8 @@ open class SimpleActivity : AppCompatActivity() {
}
fun isShowingPermDialog(file: File) = isShowingWritePermissions(file, mConfig.treeUri, Constants.OPEN_DOCUMENT_TREE)
fun hideUI() = hideSystemUI(supportActionBar, window)
fun showUI() = showSystemUI(supportActionBar, window)
}

View file

@ -8,7 +8,6 @@ import android.net.Uri
import android.os.Bundle
import android.provider.MediaStore
import android.support.v4.view.ViewPager
import android.support.v7.app.ActionBar
import android.view.Menu
import android.view.MenuItem
import android.view.View
@ -30,7 +29,6 @@ import java.util.*
import java.util.regex.Pattern
class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View.OnSystemUiVisibilityChangeListener, ViewPagerFragment.FragmentClickListener {
private var mActionbar: ActionBar? = null
private var mMedia: MutableList<Medium>? = null
private var mPath = ""
private var mDirectory = ""
@ -81,10 +79,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
mPos = 0
mIsFullScreen = true
mActionbar = supportActionBar
mToBeDeleted = ""
mBeingDeleted = ""
hideSystemUI()
hideUI()
scanPath(mPath) {}
addUndoMargin()
@ -393,16 +390,12 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
deleteFile()
mIsFullScreen = !mIsFullScreen
if (mIsFullScreen) {
hideSystemUI()
hideUI()
} else {
showSystemUI()
showUI()
}
}
private fun hideSystemUI() = Utils.hideSystemUI(mActionbar, window)
private fun showSystemUI() = Utils.showSystemUI(mActionbar, window)
private fun updateActionbarTitle() {
title = mMedia!![view_pager.currentItem].path.getFilenameFromPath()
}

View file

@ -0,0 +1,23 @@
package com.simplemobiletools.gallery.extensions
import android.app.Activity
import android.support.v7.app.ActionBar
import android.view.View
import android.view.Window
fun Activity.showSystemUI(actionbar: ActionBar?, window: Window) {
actionbar?.show()
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
}
fun Activity.hideSystemUI(actionbar: ActionBar?, window: Window) {
actionbar?.hide()
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
View.SYSTEM_UI_FLAG_LOW_PROFILE or
View.SYSTEM_UI_FLAG_FULLSCREEN or
View.SYSTEM_UI_FLAG_IMMERSIVE
}