Move functions to get Android dimen to ThemeHelper
This commit is contained in:
parent
1cf746f721
commit
9c51fc3ade
|
@ -1,6 +1,5 @@
|
|||
package org.schabi.newpipe.player.gesture
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
|
@ -17,6 +16,7 @@ import org.schabi.newpipe.player.Player
|
|||
import org.schabi.newpipe.player.helper.AudioReactor
|
||||
import org.schabi.newpipe.player.helper.PlayerHelper
|
||||
import org.schabi.newpipe.player.ui.MainPlayerUi
|
||||
import org.schabi.newpipe.util.ThemeHelper.getAndroidDimenPx
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
@ -172,9 +172,13 @@ class MainPlayerGestureListener(
|
|||
return false
|
||||
}
|
||||
|
||||
val isTouchingStatusBar: Boolean = initialEvent.y < getStatusBarHeight(player.context)
|
||||
val isTouchingNavigationBar: Boolean =
|
||||
initialEvent.y > (binding.root.height - getNavigationBarHeight(player.context))
|
||||
// Calculate heights of status and navigation bars
|
||||
val statusBarHeight = getAndroidDimenPx(player.context, "status_bar_height")
|
||||
val navigationBarHeight = getAndroidDimenPx(player.context, "navigation_bar_height")
|
||||
|
||||
// Do not handle this event if initially it started from status or navigation bars
|
||||
val isTouchingStatusBar = initialEvent.y < statusBarHeight
|
||||
val isTouchingNavigationBar = initialEvent.y > (binding.root.height - navigationBarHeight)
|
||||
if (isTouchingStatusBar || isTouchingNavigationBar) {
|
||||
return false
|
||||
}
|
||||
|
@ -226,21 +230,5 @@ class MainPlayerGestureListener(
|
|||
private val TAG = MainPlayerGestureListener::class.java.simpleName
|
||||
private val DEBUG = MainActivity.DEBUG
|
||||
private const val MOVEMENT_THRESHOLD = 40
|
||||
|
||||
private fun getNavigationBarHeight(context: Context): Int {
|
||||
val resId = context.resources
|
||||
.getIdentifier("navigation_bar_height", "dimen", "android")
|
||||
return if (resId > 0) {
|
||||
context.resources.getDimensionPixelSize(resId)
|
||||
} else 0
|
||||
}
|
||||
|
||||
private fun getStatusBarHeight(context: Context): Int {
|
||||
val resId = context.resources
|
||||
.getIdentifier("status_bar_height", "dimen", "android")
|
||||
return if (resId > 0) {
|
||||
context.resources.getDimensionPixelSize(resId)
|
||||
} else 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -244,6 +244,22 @@ public final class ThemeHelper {
|
|||
return AppCompatResources.getDrawable(context, typedValue.resourceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a runtime dimen from the {@code android} package. Should be used for dimens for which
|
||||
* normal accessing with {@code R.dimen.} is not available.
|
||||
*
|
||||
* @param context context
|
||||
* @param name dimen resource name (e.g. navigation_bar_height)
|
||||
* @return the obtained dimension, in pixels, or 0 if the resource could not be resolved
|
||||
*/
|
||||
public static int getAndroidDimenPx(@NonNull final Context context, final String name) {
|
||||
final int resId = context.getResources().getIdentifier(name, "dimen", "android");
|
||||
if (resId <= 0) {
|
||||
return 0;
|
||||
}
|
||||
return context.getResources().getDimensionPixelSize(resId);
|
||||
}
|
||||
|
||||
private static String getSelectedThemeKey(final Context context) {
|
||||
final String themeKey = context.getString(R.string.theme_key);
|
||||
final String defaultTheme = context.getResources().getString(R.string.default_theme_value);
|
||||
|
|
Loading…
Reference in New Issue