move the remaining Utils functions into extensions
This commit is contained in:
parent
802789d1da
commit
b04022d365
|
@ -1,34 +0,0 @@
|
|||
package com.simplemobiletools.gallery
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.util.TypedValue
|
||||
|
||||
class Utils {
|
||||
companion object {
|
||||
fun getActionBarHeight(context: Context, res: Resources): Int {
|
||||
val tv = TypedValue()
|
||||
var height = 0
|
||||
if (context.theme.resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
|
||||
height = TypedValue.complexToDimensionPixelSize(tv.data, res.displayMetrics)
|
||||
}
|
||||
return height
|
||||
}
|
||||
|
||||
fun getStatusBarHeight(res: Resources): Int {
|
||||
val id = res.getIdentifier("status_bar_height", "dimen", "android")
|
||||
return if (id > 0) {
|
||||
res.getDimensionPixelSize(id)
|
||||
} else
|
||||
0
|
||||
}
|
||||
|
||||
fun getNavBarHeight(res: Resources): Int {
|
||||
val id = res.getIdentifier("navigation_bar_height", "dimen", "android")
|
||||
return if (id > 0) {
|
||||
res.getDimensionPixelSize(id)
|
||||
} else
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,13 +16,14 @@ import com.simplemobiletools.filepicker.asynctasks.CopyMoveTask
|
|||
import com.simplemobiletools.filepicker.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.filepicker.extensions.*
|
||||
import com.simplemobiletools.fileproperties.dialogs.PropertiesDialog
|
||||
import com.simplemobiletools.gallery.*
|
||||
import com.simplemobiletools.gallery.MEDIUM
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.REQUEST_EDIT_IMAGE
|
||||
import com.simplemobiletools.gallery.REQUEST_SET_WALLPAPER
|
||||
import com.simplemobiletools.gallery.adapters.MyPagerAdapter
|
||||
import com.simplemobiletools.gallery.dialogs.CopyDialog
|
||||
import com.simplemobiletools.gallery.dialogs.RenameFileDialog
|
||||
import com.simplemobiletools.gallery.extensions.openWith
|
||||
import com.simplemobiletools.gallery.extensions.setAsWallpaper
|
||||
import com.simplemobiletools.gallery.extensions.shareMedium
|
||||
import com.simplemobiletools.gallery.extensions.*
|
||||
import com.simplemobiletools.gallery.fragments.ViewPagerFragment
|
||||
import com.simplemobiletools.gallery.models.Medium
|
||||
import kotlinx.android.synthetic.main.activity_medium.*
|
||||
|
@ -390,11 +391,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
private fun addUndoMargin() {
|
||||
val res = resources
|
||||
val params = undo_delete.layoutParams as RelativeLayout.LayoutParams
|
||||
val topMargin = Utils.getStatusBarHeight(res) + Utils.getActionBarHeight(applicationContext, res)
|
||||
val topMargin = res.getStatusBarHeight() + res.getActionBarHeight(applicationContext)
|
||||
var rightMargin = params.rightMargin
|
||||
|
||||
if (res.configuration.orientation != Configuration.ORIENTATION_PORTRAIT) {
|
||||
rightMargin += Utils.getNavBarHeight(res)
|
||||
rightMargin += res.getNavBarHeight()
|
||||
}
|
||||
|
||||
params.setMargins(params.leftMargin, topMargin, rightMargin, params.bottomMargin)
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package com.simplemobiletools.gallery.extensions
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.util.TypedValue
|
||||
|
||||
fun Resources.getActionBarHeight(context: Context): Int {
|
||||
val tv = TypedValue()
|
||||
var height = 0
|
||||
if (context.theme.resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
|
||||
height = TypedValue.complexToDimensionPixelSize(tv.data, displayMetrics)
|
||||
}
|
||||
return height
|
||||
}
|
||||
|
||||
fun Resources.getStatusBarHeight(): Int {
|
||||
val id = getIdentifier("status_bar_height", "dimen", "android")
|
||||
return if (id > 0) {
|
||||
getDimensionPixelSize(id)
|
||||
} else
|
||||
0
|
||||
}
|
||||
|
||||
fun Resources.getNavBarHeight(): Int {
|
||||
val id = getIdentifier("navigation_bar_height", "dimen", "android")
|
||||
return if (id > 0) {
|
||||
getDimensionPixelSize(id)
|
||||
} else
|
||||
0
|
||||
}
|
|
@ -16,7 +16,7 @@ import android.widget.TextView
|
|||
import com.simplemobiletools.gallery.Config
|
||||
import com.simplemobiletools.gallery.MEDIUM
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.Utils
|
||||
import com.simplemobiletools.gallery.extensions.getNavBarHeight
|
||||
import com.simplemobiletools.gallery.extensions.hasNavBar
|
||||
import com.simplemobiletools.gallery.models.Medium
|
||||
import kotlinx.android.synthetic.main.pager_video_item.view.*
|
||||
|
@ -107,7 +107,7 @@ class VideoFragment : ViewPagerFragment(), View.OnClickListener, SurfaceHolder.C
|
|||
private fun initTimeHolder() {
|
||||
mTimeHolder = mView.video_time_holder
|
||||
val res = resources
|
||||
val height = Utils.getNavBarHeight(res)
|
||||
val height = res.getNavBarHeight()
|
||||
val left = mTimeHolder!!.paddingLeft
|
||||
val top = mTimeHolder!!.paddingTop
|
||||
var right = res.getDimension(R.dimen.timer_padding).toInt()
|
||||
|
|
Loading…
Reference in New Issue