Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/src/main/java/de/devmil/paperlaunch/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ package de.devmil.paperlaunch.config

interface IUserSettings {

val activationOffsetHeightDip: Int
val activationOffsetPositionDip: Int
val sensitivityDip: Int
val isOnRightSide: Boolean
val isShowBackground: Boolean
val isVibrateOnActivation: Boolean
val launcherGravity: LauncherGravity?
val showLogo: Boolean
val itemScalePercent: Int
val activationHeightPercent: Int
val activationOffsetPosition: Int
val isShowHint : Boolean

}
11 changes: 7 additions & 4 deletions app/src/main/java/de/devmil/paperlaunch/config/LaunchConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
27 changes: 17 additions & 10 deletions app/src/main/java/de/devmil/paperlaunch/config/UserSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
}

Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Rect>()
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
}
Comment on lines +669 to +674
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!!


wm.addView(result.activationView, params)

removeTouchReceiver(context, oldActivationView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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.support.design.widget.AppBarLayout
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_edit_folder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="de.devmil.paperlaunch.EditFolderActivity">

<android.support.design.widget.AppBarLayout
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_edit_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".locale.EditSettingActivity">

<android.support.design.widget.AppBarLayout
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
android:id="@+id/activity_main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">

<android.support.design.widget.AppBarLayout
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
android:id="@+id/activity_settings_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".SettingsActivity">

<android.support.design.widget.AppBarLayout
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_urlselectorview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<include
android:id="@+id/activity_urlselectorview_toolbar"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/common__intentselectorview.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_height="match_parent"
android:fitsSystemWindows="true" >

<include
android:id="@+id/common__intentSelector_toolbar"
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/values-v23/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.PaperLaunch" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="colorAccent">@color/theme_accent</item>
<item name="colorPrimary">@color/theme_primary</item>
<item name="colorPrimaryDark">@color/theme_primary_dark</item>
<!-- Status bar configuration for API 35+ -->
<item name="android:statusBarColor">@color/theme_primary_light</item>
<item name="android:windowLightStatusBar">true</item>
</style>
</resources>
Loading