diff --git a/app/src/main/java/de/devmil/paperlaunch/SettingsActivity.kt b/app/src/main/java/de/devmil/paperlaunch/SettingsActivity.kt index 11420c4..9e8df06 100644 --- a/app/src/main/java/de/devmil/paperlaunch/SettingsActivity.kt +++ b/app/src/main/java/de/devmil/paperlaunch/SettingsActivity.kt @@ -64,8 +64,8 @@ class SettingsActivity : Activity() { activationIndicatorView, this, ViewUtils.getPxFromDip(this, us.sensitivityDip.toFloat()).toInt(), - ViewUtils.getPxFromDip(this, us.activationOffsetPositionDip.toFloat()).toInt(), - ViewUtils.getPxFromDip(this, us.activationOffsetHeightDip.toFloat()).toInt(), + us.activationOffsetPosition, + us.activationHeightPercent, us.isOnRightSide, ContextCompat.getColor(this, R.color.theme_accent) ) diff --git a/app/src/main/java/de/devmil/paperlaunch/config/IUserSettings.kt b/app/src/main/java/de/devmil/paperlaunch/config/IUserSettings.kt index 239cdca..67f5341 100644 --- a/app/src/main/java/de/devmil/paperlaunch/config/IUserSettings.kt +++ b/app/src/main/java/de/devmil/paperlaunch/config/IUserSettings.kt @@ -17,8 +17,6 @@ package de.devmil.paperlaunch.config interface IUserSettings { - val activationOffsetHeightDip: Int - val activationOffsetPositionDip: Int val sensitivityDip: Int val isOnRightSide: Boolean val isShowBackground: Boolean @@ -26,4 +24,8 @@ interface IUserSettings { val launcherGravity: LauncherGravity? val showLogo: Boolean val itemScalePercent: Int + val activationHeightPercent: Int + val activationOffsetPosition: Int + val isShowHint : Boolean + } diff --git a/app/src/main/java/de/devmil/paperlaunch/config/LaunchConfig.kt b/app/src/main/java/de/devmil/paperlaunch/config/LaunchConfig.kt index c431354..aee1e77 100644 --- a/app/src/main/java/de/devmil/paperlaunch/config/LaunchConfig.kt +++ b/app/src/main/java/de/devmil/paperlaunch/config/LaunchConfig.kt @@ -46,15 +46,17 @@ class LaunchConfig(userSettings: IUserSettings) : ILaunchEntryConfig, ILaunchLan val launcherBackgroundAlpha = 0.3f val launcherBackgroundAnimationDurationMS = 250 val maxFolderDepth = 9 + val launcherHintAlpha = 0.28f //UserSettings @Suppress("JoinDeclarationAndAssignment") val launcherSensitivityDip: Int override val isOnRightSide: Boolean - val launcherOffsetPositionDip: Int - val launcherOffsetHeightDip: Int val showLauncherBackground: Boolean val isVibrateOnActivation: Boolean + val launcherOffsetPosition: Int + val launcherHeightPercent: Int + val showLauncherHint : Boolean override val launcherGravity: LauncherGravity? override val imageWidthDip: Float override val showLogo: Boolean @@ -68,12 +70,13 @@ class LaunchConfig(userSettings: IUserSettings) : ILaunchEntryConfig, ILaunchLan init { launcherSensitivityDip = userSettings.sensitivityDip isOnRightSide = userSettings.isOnRightSide - launcherOffsetPositionDip = userSettings.activationOffsetPositionDip - launcherOffsetHeightDip = userSettings.activationOffsetHeightDip showLauncherBackground = userSettings.isShowBackground isVibrateOnActivation = userSettings.isVibrateOnActivation launcherGravity = userSettings.launcherGravity imageWidthDip = (BASE_IMAGE_WIDTH_DIP * userSettings.itemScalePercent) / 100f showLogo = userSettings.showLogo + showLauncherHint = userSettings.isShowHint + launcherOffsetPosition = userSettings.activationOffsetPosition + launcherHeightPercent = userSettings.activationHeightPercent } } diff --git a/app/src/main/java/de/devmil/paperlaunch/config/UserSettings.kt b/app/src/main/java/de/devmil/paperlaunch/config/UserSettings.kt index c2ff8af..071deb6 100644 --- a/app/src/main/java/de/devmil/paperlaunch/config/UserSettings.kt +++ b/app/src/main/java/de/devmil/paperlaunch/config/UserSettings.kt @@ -21,14 +21,16 @@ class UserSettings(context: Context) : IUserSettings { override var sensitivityDip: Int = 0 - override var activationOffsetPositionDip: Int = 0 - override var activationOffsetHeightDip: Int = 0 override var isShowBackground: Boolean = false override var isVibrateOnActivation: Boolean = false override var isOnRightSide: Boolean = false override var launcherGravity: LauncherGravity = LauncherGravity.Center override var showLogo: Boolean = true override var itemScalePercent: Int = 100 + override var activationOffsetPosition: Int = 0 + override var activationHeightPercent: Int = 0 + override var isShowHint: Boolean = false + init { load(context) @@ -37,28 +39,30 @@ class UserSettings(context: Context) : IUserSettings { fun load(context: Context) { val prefs = context.getSharedPreferences(SHARED_PREFS_NAME, Context.MODE_PRIVATE) sensitivityDip = prefs.getInt(KEY_SENSITIVITY_DIP, DEFAULT_SENSITIVITY_DIP) - activationOffsetPositionDip = prefs.getInt(KEY_ACTIVATION_OFFSET_POSITION_DIP, DEFAULT_ACTIVATION_OFFSET_POSITION_DIP) - activationOffsetHeightDip = prefs.getInt(KEY_ACTIVATION_OFFSET_HEIGHT_DIP, DEFAULT_ACTIVATION_OFFSET_HEIGHT_DIP) isShowBackground = prefs.getBoolean(KEY_SHOW_BACKGROUND, DEFAULT_SHOW_BACKGROUND) isVibrateOnActivation = prefs.getBoolean(KEY_VIBRATE_ON_ACTIVATION, DEFAULT_VIBRATE_ON_ACTIVATION) isOnRightSide = prefs.getBoolean(KEY_IS_ON_RIGHT_SIDE, DEFAULT_IS_ON_RIGHT_SIDE) launcherGravity = LauncherGravity.fromValue(prefs.getInt(KEY_LAUNCHER_GRAVITY, DEFAULT_LAUNCHER_GRAVITY.value)) showLogo = prefs.getBoolean(KEY_SHOW_LOGO, DEFAULT_SHOW_LOGO) itemScalePercent = prefs.getInt(KEY_ITEM_SCALE_PERCENT, DEFAULT_ITEM_SCALE_PERCENT) + activationOffsetPosition = prefs.getInt(KEY_ACTIVATION_OFFSET_POSITION, DEFAULT_ACTIVATION_OFFSET_POSITION) + activationHeightPercent = prefs.getInt(KEY_ACTIVATION_HEIGHT_PERCENT, DEFAULT_ACTIVATION_HEIGHT_PERCENT) + isShowHint = prefs.getBoolean(KEY_IS_SHOW_HINT, DEFAULT_SHOW_HINT) } fun save(context: Context) { val prefs = context.getSharedPreferences(SHARED_PREFS_NAME, Context.MODE_PRIVATE) prefs.edit() .putInt(KEY_SENSITIVITY_DIP, sensitivityDip) - .putInt(KEY_ACTIVATION_OFFSET_POSITION_DIP, activationOffsetPositionDip) - .putInt(KEY_ACTIVATION_OFFSET_HEIGHT_DIP, activationOffsetHeightDip) .putBoolean(KEY_SHOW_BACKGROUND, isShowBackground) .putBoolean(KEY_VIBRATE_ON_ACTIVATION, isVibrateOnActivation) .putBoolean(KEY_IS_ON_RIGHT_SIDE, isOnRightSide) .putInt(KEY_LAUNCHER_GRAVITY, launcherGravity.value) .putBoolean(KEY_SHOW_LOGO, showLogo) .putInt(KEY_ITEM_SCALE_PERCENT, itemScalePercent) + .putBoolean(KEY_IS_SHOW_HINT, isShowHint) + .putInt(KEY_ACTIVATION_OFFSET_POSITION, activationOffsetPosition) + .putInt(KEY_ACTIVATION_HEIGHT_PERCENT, activationHeightPercent) .apply() } @@ -67,23 +71,26 @@ class UserSettings(context: Context) : IUserSettings { internal val SHARED_PREFS_NAME = "paperLaunch" internal val KEY_SENSITIVITY_DIP = "sensitivityDip" - internal val KEY_ACTIVATION_OFFSET_POSITION_DIP = "activationOffsetPositionDip" - internal val KEY_ACTIVATION_OFFSET_HEIGHT_DIP = "activationOffsetHeightDip" internal val KEY_SHOW_BACKGROUND = "showBackground" internal val KEY_VIBRATE_ON_ACTIVATION = "vibrateOnActivation" internal val KEY_IS_ON_RIGHT_SIDE = "isOnRightSide" internal val KEY_LAUNCHER_GRAVITY = "launcherGravity" internal val KEY_SHOW_LOGO = "showLogo" internal val KEY_ITEM_SCALE_PERCENT = "itemScalePercent" + internal val KEY_ACTIVATION_OFFSET_POSITION = "activationOffsetPosition" + internal val KEY_ACTIVATION_HEIGHT_PERCENT = "activationHeightPercent" + internal val KEY_IS_SHOW_HINT = "isShowHint" + private val DEFAULT_SENSITIVITY_DIP = 10 - private val DEFAULT_ACTIVATION_OFFSET_POSITION_DIP = 0 - private val DEFAULT_ACTIVATION_OFFSET_HEIGHT_DIP = 0 private val DEFAULT_SHOW_BACKGROUND = false private val DEFAULT_VIBRATE_ON_ACTIVATION = false private val DEFAULT_IS_ON_RIGHT_SIDE = true private val DEFAULT_LAUNCHER_GRAVITY = LauncherGravity.Center private val DEFAULT_SHOW_LOGO = true private val DEFAULT_ITEM_SCALE_PERCENT = 100 + private val DEFAULT_SHOW_HINT = false + private val DEFAULT_ACTIVATION_OFFSET_POSITION = 0 + private val DEFAULT_ACTIVATION_HEIGHT_PERCENT = 25 } } diff --git a/app/src/main/java/de/devmil/paperlaunch/service/LauncherOverlayService.kt b/app/src/main/java/de/devmil/paperlaunch/service/LauncherOverlayService.kt index a679b94..c75c198 100644 --- a/app/src/main/java/de/devmil/paperlaunch/service/LauncherOverlayService.kt +++ b/app/src/main/java/de/devmil/paperlaunch/service/LauncherOverlayService.kt @@ -23,12 +23,15 @@ import android.content.IntentFilter import android.graphics.Color import android.graphics.PixelFormat import android.graphics.Rect +import android.graphics.drawable.ShapeDrawable +import android.graphics.drawable.shapes.RoundRectShape import android.os.Build import android.os.IBinder import android.os.VibrationEffect import android.os.Vibrator import android.support.annotation.RequiresApi import android.support.v4.app.NotificationCompat +import android.support.v4.content.ContextCompat import android.util.DisplayMetrics import android.util.Log import android.view.Gravity @@ -376,14 +379,25 @@ class LauncherOverlayService : Service() { @Synchronized private fun reloadTouchReceiver() { + val showLauncherHint = currentConfig!!.showLauncherHint + val colorAccent = ContextCompat.getColor(this, R.color.theme_accent) + val backgroundColor = if(showLauncherHint) + Color.argb( + (currentConfig!!.launcherHintAlpha * 0xff).toInt(), + Color.red(colorAccent), + Color.green(colorAccent), + Color.blue(colorAccent) ) + else Color.TRANSPARENT + val avr = addActivationViewToWindow( touchReceiverView, this, ViewUtils.getPxFromDip(this, currentConfig!!.launcherSensitivityDip.toFloat()).toInt(), - ViewUtils.getPxFromDip(this, currentConfig!!.launcherOffsetPositionDip.toFloat()).toInt(), - ViewUtils.getPxFromDip(this, currentConfig!!.launcherOffsetHeightDip.toFloat()).toInt(), + currentConfig!!.launcherOffsetPosition, + currentConfig!!.launcherHeightPercent, currentConfig!!.isOnRightSide, - Color.TRANSPARENT) + backgroundColor + ) if(!avr.success) { return @@ -630,14 +644,35 @@ class LauncherOverlayService : Service() { @Suppress("RtlHardcoded") params.gravity = Gravity.LEFT or Gravity.TOP + val cornerRadius = 20.0f + val radiusRect = if(isOnRightSide) + RoundRectShape( + floatArrayOf(cornerRadius,cornerRadius,.0f,.0f,.0f,.0f,cornerRadius,cornerRadius), null, null) + else + RoundRectShape( + floatArrayOf(.0f,.0f,cornerRadius,cornerRadius,cornerRadius,cornerRadius,.0f,.0f), null, null) + + val activationBg = ShapeDrawable().apply { + shape = radiusRect + paint.color = backgroundColor + } + result.activationView = LinearLayout(context) - result.activationView!!.setBackgroundColor(backgroundColor) + result.activationView!!.background = activationBg val touchReceiverParams = LinearLayout.LayoutParams( activationRect.width(), activationRect.height()) touchReceiverParams.setMargins(0, activationRect.top, 0, windowRect.height() - activationRect.bottom) + // Prevent conflicting with system's back gesture starting Android 10 + val exclusionRects = mutableListOf() + val exclusionRect = Rect(0, 0,activationRect.width(), activationRect.height()) + exclusionRects.add(exclusionRect) + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){ // Android 10 and up + result.activationView!!.systemGestureExclusionRects = exclusionRects + } + wm.addView(result.activationView, params) removeTouchReceiver(context, oldActivationView) diff --git a/app/src/main/java/de/devmil/paperlaunch/utils/ActivationIndicatorHelper.kt b/app/src/main/java/de/devmil/paperlaunch/utils/ActivationIndicatorHelper.kt index 5088a77..97f75d7 100644 --- a/app/src/main/java/de/devmil/paperlaunch/utils/ActivationIndicatorHelper.kt +++ b/app/src/main/java/de/devmil/paperlaunch/utils/ActivationIndicatorHelper.kt @@ -37,16 +37,15 @@ object ActivationIndicatorHelper { right = left + sensitivity } - val height = availableRect.height() - offsetSize - top += offsetPosition + offsetSize / 2 + val height = (availableRect.height() * (offsetSize/100.0f)).toInt() + + // top += (center Y of the window) - (half the view height) + ( (position range) * position percentage) + top += ((availableRect.height()/2) - (height / 2) + ( (availableRect.height()-height) * offsetPosition/100.0f) ).toInt() + bottom = top + height val result = Rect(left, top, right, bottom) - if (!result.intersect(availableRect)) { - return availableRect - } - return result } } diff --git a/app/src/main/java/de/devmil/paperlaunch/view/fragments/SettingsFragment.kt b/app/src/main/java/de/devmil/paperlaunch/view/fragments/SettingsFragment.kt index 14f1774..3c9b898 100644 --- a/app/src/main/java/de/devmil/paperlaunch/view/fragments/SettingsFragment.kt +++ b/app/src/main/java/de/devmil/paperlaunch/view/fragments/SettingsFragment.kt @@ -89,34 +89,29 @@ class SettingsFragment : PreferenceFragment() { val metrics = DisplayMetrics() activity.windowManager.defaultDisplay.getMetrics(metrics) - val heightDpi = metrics.heightPixels / metrics.density - - val offsetHeightPreference = SeekBarPreference(context, 0, heightDpi.toInt()) + val offsetHeightPreference = SeekBarPreference(context, 0, 100) activationCategory.addPreference(offsetHeightPreference) - offsetHeightPreference.setValue(heightDpi.toInt() - userSettings!!.activationOffsetHeightDip) + offsetHeightPreference.setValue(userSettings!!.activationHeightPercent) offsetHeightPreference.setTitle(R.string.fragment_settings_activation_offset_height_title) offsetHeightPreference.isPersistent = false offsetHeightPreference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> userSettings!!.load(activity) - userSettings!!.activationOffsetHeightDip = heightDpi.toInt() - newValue as Int + userSettings!!.activationHeightPercent = newValue as Int userSettings!!.save(activity) fireActivationParametersChanged() true } - val offsetMin = -(heightDpi / 2).toInt() - val offsetMax = (heightDpi / 2).toInt() - - val offsetPositionPreference = SeekBarPreference(context, offsetMin, offsetMax) + val offsetPositionPreference = SeekBarPreference(context, -50,50) // 0 is center of the window's height activationCategory.addPreference(offsetPositionPreference) - offsetPositionPreference.setValue(userSettings!!.activationOffsetPositionDip) + offsetPositionPreference.setValue(userSettings!!.activationOffsetPosition) offsetPositionPreference.setTitle(R.string.fragment_settings_activation_offset_position_title) offsetPositionPreference.isPersistent = false offsetPositionPreference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> userSettings!!.load(activity) - userSettings!!.activationOffsetPositionDip = newValue as Int + userSettings!!.activationOffsetPosition = newValue as Int userSettings!!.save(activity) fireActivationParametersChanged() true @@ -137,6 +132,26 @@ class SettingsFragment : PreferenceFragment() { LauncherOverlayService.notifyConfigChanged(activity) true } + + val showActivationHintPreference = CheckBoxPreference(context) + activationCategory.addPreference(showActivationHintPreference) + + val isShowHint = userSettings!!.isShowHint + showActivationHintPreference.isChecked = isShowHint + + showActivationHintPreference.setTitle(R.string.fragment_settings_activation_show_hint_title) + showActivationHintPreference.setSummaryOn(R.string.fragment_settings_activation_show_hint_summary_on) + showActivationHintPreference.setSummaryOff(R.string.fragment_settings_activation_show_hint_summary_off) + showActivationHintPreference.isPersistent = false + showActivationHintPreference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener{ _, newValue -> + userSettings!!.load(activity) + userSettings!!.isShowHint = newValue as Boolean + userSettings!!.save(activity) + LauncherOverlayService.notifyConfigChanged(activity) + + true + } + } private fun addAppearanceSettings(context: Context, screen: PreferenceScreen) { diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml index ba3b4b0..0bdbe11 100644 --- a/app/src/main/res/layout/activity_about.xml +++ b/app/src/main/res/layout/activity_about.xml @@ -5,6 +5,7 @@ android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:orientation="vertical" + android:fitsSystemWindows="true" tools:context="de.devmil.paperlaunch.AboutActivity"> + android:layout_height="match_parent" + android:fitsSystemWindows="true"> + android:layout_height="match_parent" + android:fitsSystemWindows="true" > + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3496e7b..731c38b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -90,4 +90,7 @@ Activate Pause New PaperLaunch state: + Show activation hint + Activation hint is shown + Activation hint is not shown diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index fee5977..e1924bd 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -5,5 +5,7 @@ @color/theme_accent @color/theme_primary @color/theme_primary_dark + + @color/theme_primary_light diff --git a/app/src/test/java/de/devmil/paperlaunch/config/UserSettingsTest.kt b/app/src/test/java/de/devmil/paperlaunch/config/UserSettingsTest.kt index e8d3b8d..21a8d48 100644 --- a/app/src/test/java/de/devmil/paperlaunch/config/UserSettingsTest.kt +++ b/app/src/test/java/de/devmil/paperlaunch/config/UserSettingsTest.kt @@ -22,8 +22,8 @@ class UserSettingsTest { private fun createUUT( sensitivityDip: Int, - activationOffsetPositionDip: Int, - activationOffsetHeightDip: Int, + activationOffsetPosition: Int, + activationOffsetHeightPercent: Int, isShowBackground: Boolean, isVibrateOnActivation: Boolean, isOnRightSide: Boolean, @@ -37,10 +37,10 @@ class UserSettingsTest { `when`(mockSharedPreferences.getInt(eq(UserSettings.KEY_SENSITIVITY_DIP), anyInt())) .thenReturn(sensitivityDip) - `when`(mockSharedPreferences.getInt(eq(UserSettings.KEY_ACTIVATION_OFFSET_POSITION_DIP), anyInt())) - .thenReturn(activationOffsetPositionDip) - `when`(mockSharedPreferences.getInt(eq(UserSettings.KEY_ACTIVATION_OFFSET_HEIGHT_DIP), anyInt())) - .thenReturn(activationOffsetHeightDip) + `when`(mockSharedPreferences.getInt(eq(UserSettings.KEY_ACTIVATION_OFFSET_POSITION), anyInt())) + .thenReturn(activationOffsetPosition) + `when`(mockSharedPreferences.getInt(eq(UserSettings.KEY_ACTIVATION_HEIGHT_PERCENT), anyInt())) + .thenReturn(activationOffsetHeightPercent) `when`(mockSharedPreferences.getBoolean(eq(UserSettings.KEY_SHOW_BACKGROUND), anyBoolean())) .thenReturn(isShowBackground) `when`(mockSharedPreferences.getBoolean(eq(UserSettings.KEY_VIBRATE_ON_ACTIVATION), anyBoolean()))