refactored code related to gestures

This commit is contained in:
Josia Pietsch 2024-07-07 05:14:25 +02:00
parent 431f7b58ee
commit 3c6a883f39
Signed by: jrpie
GPG key ID: E70B571D66986A2D
20 changed files with 342 additions and 399 deletions

View file

@ -19,7 +19,6 @@ import android.os.Bundle
import android.os.SystemClock import android.os.SystemClock
import android.provider.Settings import android.provider.Settings
import android.util.DisplayMetrics import android.util.DisplayMetrics
import android.util.Log
import android.view.KeyEvent import android.view.KeyEvent
import android.view.View import android.view.View
import android.view.Window import android.view.Window
@ -40,37 +39,8 @@ import de.jrpie.android.launcher.settings.intendedSettingsPause
import de.jrpie.android.launcher.tutorial.TutorialActivity import de.jrpie.android.launcher.tutorial.TutorialActivity
/* Preferences (global, initialised when app is started) */
lateinit var launcherPreferences: SharedPreferences
/* Preference Key Constants */ /* Preference Key Constants */
const val ACTION_UP = "action_upApp"
const val ACTION_DOUBLE_UP = "action_doubleUpApp"
const val ACTION_DOWN = "action_downApp"
const val ACTION_DOUBLE_DOWN = "action_doubleDownApp"
const val ACTION_RIGHT = "action_rightApp"
const val ACTION_DOUBLE_RIGHT = "action_doubleRightApp"
const val ACTION_LEFT = "action_leftApp"
const val ACTION_DOUBLE_LEFT = "action_doubleLeftApp"
const val ACTION_VOL_UP = "action_volumeUpApp"
const val ACTION_VOL_DOWN = "action_volumeDownApp"
const val ACTION_DOUBLE_CLICK = "action_doubleClickApp"
const val ACTION_LONG_CLICK = "action_longClickApp"
const val ACTION_DATE = "action_dateApp"
const val ACTION_TIME = "action_timeApp"
val ACTIONS = listOf(
ACTION_UP, ACTION_DOUBLE_UP,
ACTION_DOWN, ACTION_DOUBLE_DOWN,
ACTION_RIGHT, ACTION_LEFT,
ACTION_VOL_UP, ACTION_VOL_DOWN,
ACTION_DOUBLE_CLICK, ACTION_LONG_CLICK,
ACTION_DATE, ACTION_TIME
)
const val PREF_DOMINANT = "custom_dominant" const val PREF_DOMINANT = "custom_dominant"
const val PREF_VIBRANT = "custom_vibrant" const val PREF_VIBRANT = "custom_vibrant"
const val PREF_THEME = "theme" const val PREF_THEME = "theme"
@ -96,24 +66,6 @@ val appsList: MutableList<AppInfo> = ArrayList()
/* Variables containing settings */ /* Variables containing settings */
val displayMetrics = DisplayMetrics() val displayMetrics = DisplayMetrics()
var upApp = ""
var doubleUpApp = ""
var downApp = ""
var doubleDownApp = ""
var rightApp = ""
var doubleRightApp = ""
var leftApp = ""
var doubleLeftApp = ""
var volumeUpApp = ""
var volumeDownApp = ""
var doubleClickApp = ""
var longClickApp = ""
var timeApp = ""
var dateApp = ""
var dominantColor = 0 var dominantColor = 0
var vibrantColor = 0 var vibrantColor = 0
@ -141,6 +93,13 @@ fun View.blink(
}) })
} }
fun getPreferences(context: Context): SharedPreferences{
return context.getSharedPreferences(
context.getString(R.string.preference_file_key),
Context.MODE_PRIVATE
)
}
/* Activity related */ /* Activity related */
fun isInstalled(uri: String, context: Context): Boolean { fun isInstalled(uri: String, context: Context): Boolean {
@ -269,12 +228,12 @@ fun openNewTabWindow(urls: String, context: Context) {
/* Settings related functions */ /* Settings related functions */
fun getSavedTheme() : String { fun getSavedTheme(context: Context) : String {
return launcherPreferences.getString(PREF_THEME, "finn").toString() return getPreferences(context).getString(PREF_THEME, "finn").toString()
} }
fun saveTheme(themeName: String) : String { fun saveTheme(context: Context, themeName: String) : String {
launcherPreferences.edit() getPreferences(context).edit()
.putString(PREF_THEME, themeName) .putString(PREF_THEME, themeName)
.apply() .apply()
@ -285,13 +244,13 @@ fun resetToDefaultTheme(activity: Activity) {
dominantColor = activity.resources.getColor(R.color.finnmglasTheme_background_color) dominantColor = activity.resources.getColor(R.color.finnmglasTheme_background_color)
vibrantColor = activity.resources.getColor(R.color.finnmglasTheme_accent_color) vibrantColor = activity.resources.getColor(R.color.finnmglasTheme_accent_color)
launcherPreferences.edit() getPreferences(activity).edit()
.putInt(PREF_DOMINANT, dominantColor) .putInt(PREF_DOMINANT, dominantColor)
.putInt(PREF_VIBRANT, vibrantColor) .putInt(PREF_VIBRANT, vibrantColor)
.apply() .apply()
saveTheme("finn") saveTheme(activity,"finn")
loadSettings() loadSettings(activity)
intendedSettingsPause = true intendedSettingsPause = true
activity.recreate() activity.recreate()
@ -301,12 +260,12 @@ fun resetToDarkTheme(activity: Activity) {
dominantColor = activity.resources.getColor(R.color.darkTheme_background_color) dominantColor = activity.resources.getColor(R.color.darkTheme_background_color)
vibrantColor = activity.resources.getColor(R.color.darkTheme_accent_color) vibrantColor = activity.resources.getColor(R.color.darkTheme_accent_color)
launcherPreferences.edit() getPreferences(activity).edit()
.putInt(PREF_DOMINANT, dominantColor) .putInt(PREF_DOMINANT, dominantColor)
.putInt(PREF_VIBRANT, vibrantColor) .putInt(PREF_VIBRANT, vibrantColor)
.apply() .apply()
saveTheme("dark") saveTheme(activity,"dark")
intendedSettingsPause = true intendedSettingsPause = true
activity.recreate() activity.recreate()
@ -329,9 +288,8 @@ fun openTutorial(activity: Activity){
fun openAppsList(activity: Activity){ fun openAppsList(activity: Activity){
val intent = Intent(activity, ListActivity::class.java) val intent = Intent(activity, ListActivity::class.java)
intent.putExtra("intention", "view") intent.putExtra("intention", ListActivity.ListActivityIntention.VIEW.toString())
intendedSettingsPause = true intendedSettingsPause = true
Log.i("de.jrpie", "openAppsList")
activity.startActivity(intent) activity.startActivity(intent)
} }
@ -358,31 +316,15 @@ fun loadApps(packageManager: PackageManager) {
appsList.addAll(loadList) appsList.addAll(loadList)
} }
fun loadSettings() { fun loadSettings(context: Context) {
upApp = launcherPreferences.getString(ACTION_UP, "")!! val preferences = getPreferences(context)
doubleUpApp = launcherPreferences.getString(ACTION_DOUBLE_UP, "")!! dominantColor = preferences.getInt(PREF_DOMINANT, 0)
downApp = launcherPreferences.getString(ACTION_DOWN, "")!! vibrantColor = preferences.getInt(PREF_VIBRANT, 0)
doubleDownApp = launcherPreferences.getString(ACTION_DOUBLE_DOWN, "")!!
rightApp = launcherPreferences.getString(ACTION_RIGHT, "")!!
doubleRightApp = launcherPreferences.getString(ACTION_DOUBLE_RIGHT, "")!!
leftApp = launcherPreferences.getString(ACTION_LEFT, "")!!
doubleLeftApp = launcherPreferences.getString(ACTION_DOUBLE_LEFT, "")!!
volumeUpApp = launcherPreferences.getString(ACTION_VOL_UP, "")!!
volumeDownApp = launcherPreferences.getString(ACTION_VOL_DOWN, "")!!
doubleClickApp = launcherPreferences.getString(ACTION_DOUBLE_CLICK, "")!!
longClickApp = launcherPreferences.getString(ACTION_LONG_CLICK, "")!!
dateApp = launcherPreferences.getString(ACTION_DATE, "")!!
timeApp = launcherPreferences.getString(ACTION_TIME, "")!!
dominantColor = launcherPreferences.getInt(PREF_DOMINANT, 0)
vibrantColor = launcherPreferences.getInt(PREF_VIBRANT, 0)
} }
fun resetSettings(context: Context) { fun resetSettings(context: Context) {
val editor = launcherPreferences.edit() val editor = getPreferences(context).edit()
// set default theme // set default theme
dominantColor = context.resources.getColor(R.color.finnmglasTheme_background_color) dominantColor = context.resources.getColor(R.color.finnmglasTheme_background_color)
@ -399,9 +341,7 @@ fun resetSettings(context: Context) {
.putBoolean(PREF_DOUBLE_ACTIONS_ENABLED, false) .putBoolean(PREF_DOUBLE_ACTIONS_ENABLED, false)
.putInt(PREF_SLIDE_SENSITIVITY, 50) .putInt(PREF_SLIDE_SENSITIVITY, 50)
// load action defaults Gesture.values().forEach { editor.putString(it.id, it.pickDefaultApp(context)) }
for (actionKey in ACTIONS)
editor.putString(actionKey, pickDefaultApp(actionKey, context))
editor.apply() editor.apply()
} }
@ -409,8 +349,9 @@ fun resetSettings(context: Context) {
fun setWindowFlags(window: Window) { fun setWindowFlags(window: Window) {
window.setFlags(0, 0) // clear flags window.setFlags(0, 0) // clear flags
val preferences = getPreferences(window.context)
// Display notification bar // Display notification bar
if (launcherPreferences.getBoolean(PREF_SCREEN_FULLSCREEN, true)) if (preferences.getBoolean(PREF_SCREEN_FULLSCREEN, true))
window.setFlags( window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN WindowManager.LayoutParams.FLAG_FULLSCREEN
@ -418,7 +359,7 @@ fun setWindowFlags(window: Window) {
else window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN) else window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
// Screen Timeout // Screen Timeout
if (launcherPreferences.getBoolean(PREF_SCREEN_TIMEOUT_DISABLED, false)) if (preferences.getBoolean(PREF_SCREEN_TIMEOUT_DISABLED, false))
window.setFlags( window.setFlags(
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
@ -426,46 +367,17 @@ fun setWindowFlags(window: Window) {
else window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) else window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
} }
fun pickDefaultApp(action: String, context: Context) : String {
val arrayResource = when (action) {
ACTION_UP -> R.array.default_up
ACTION_DOUBLE_UP -> R.array.default_double_up
ACTION_DOWN -> R.array.default_down
ACTION_DOUBLE_DOWN -> R.array.default_double_down
ACTION_RIGHT -> R.array.default_right
ACTION_DOUBLE_RIGHT -> R.array.default_double_right
ACTION_LEFT -> R.array.default_left
ACTION_DOUBLE_LEFT -> R.array.default_double_left
ACTION_VOL_UP -> R.array.default_volume_up
ACTION_VOL_DOWN -> R.array.default_volume_down
ACTION_DOUBLE_CLICK -> R.array.default_double_click
ACTION_LONG_CLICK -> R.array.default_long_click
ACTION_TIME -> R.array.default_time
ACTION_DATE -> R.array.default_date
else -> return "" // just prevent crashing on unknown input
}
val list = context.resources.getStringArray(arrayResource)
for (packageName in list)
if (isInstalled(packageName, context)) return packageName
return ""
}
// Used in Tutorial and Settings `ActivityOnResult` // Used in Tutorial and Settings `ActivityOnResult`
fun saveListActivityChoice(data: Intent?) { fun saveListActivityChoice(context: Context, data: Intent?) {
val value = data?.getStringExtra("value") val value = data?.getStringExtra("value")
val forApp = data?.getStringExtra("forApp") ?: return val forGesture = data?.getStringExtra("forGesture") ?: return
launcherPreferences.edit() Gesture.byId(forGesture)?.setApp(context, value.toString())
.putString("action_$forApp", value.toString())
.apply()
loadSettings() loadSettings(context)
} }
// Taken form https://stackoverflow.com/a/50743764/12787264 // Taken from https://stackoverflow.com/a/50743764/12787264
fun openSoftKeyboard(context: Context, view: View) { fun openSoftKeyboard(context: Context, view: View) {
view.requestFocus() view.requestFocus()
// open the soft keyboard // open the soft keyboard

View file

@ -0,0 +1,89 @@
package de.jrpie.android.launcher
import android.app.Activity
import android.content.Context
/**
* @param id internal id to serialize the action. Used as a key in shared preferences.
* @param defaultsResource res id of array of default actions for the gesture.
* @param labelResource res id of the name of the gesture.
* @param animationIn res id of transition animation (in) when using the gesture to launch an app.
* @param animationOut res id of transition animation (out) when using the gesture to launch an app.
*/
enum class Gesture (val id: String, private val labelResource: Int,
private val defaultsResource: Int,
private val animationIn: Int = android.R.anim.fade_in,
private val animationOut: Int = android.R.anim.fade_out){
VOLUME_UP("action_volumeUpApp", R.string.settings_gesture_vol_up, R.array.default_volume_up, 0,0),
VOLUME_DOWN("action_volumeDownApp", R.string.settings_gesture_vol_down, R.array.default_volume_down,0,0),
TIME("action_timeApp", R.string.settings_gesture_time, R.array.default_time),
DATE("action_dateApp", R.string.settings_gesture_date, R.array.default_date),
LONG_CLICK("action_longClickApp", R.string.settings_gesture_long_click, R.array.default_long_click, 0,0),
DOUBLE_CLICK("action_doubleClickApp", R.string.settings_gesture_double_click, R.array.default_double_click,0,0),
SWIPE_UP("action_upApp", R.string.settings_gesture_up, R.array.default_up, R.anim.bottom_up),
SWIPE_UP_DOUBLE( "action_doubleUpApp", R.string.settings_gesture_double_up, R.array.default_double_up, R.anim.bottom_up),
SWIPE_DOWN("action_downApp", R.string.settings_gesture_down, R.array.default_down, R.anim.top_down),
SWIPE_DOWN_DOUBLE("action_doubleDownApp", R.string.settings_gesture_double_down, R.array.default_double_down, R.anim.top_down),
SWIPE_LEFT("action_leftApp", R.string.settings_gesture_left, R.array.default_left, R.anim.right_left),
SWIPE_LEFT_DOUBLE("action_doubleLeftApp", R.string.settings_gesture_double_left, R.array.default_double_left, R.anim.right_left),
SWIPE_RIGHT("action_rightApp", R.string.settings_gesture_right, R.array.default_right, R.anim.left_right),
SWIPE_RIGHT_DOUBLE("action_doubleRightApp", R.string.settings_gesture_double_right, R.array.default_double_right, R.anim.left_right);
fun getApp(context: Context): String {
return getPreferences(context).getString(this.id, "")!!
}
fun removeApp(context: Context) {
getPreferences(context).edit()
.putString(this.id, "") // clear it
.apply()
}
fun setApp(context: Context, app: String) {
getPreferences(context).edit()
.putString(this.id, app)
.apply()
}
fun getLabel(context: Context): String {
return context.resources.getString(this.labelResource)
}
fun pickDefaultApp(context: Context) : String {
return context.resources
.getStringArray(this.defaultsResource)
.firstOrNull { isInstalled(it, context) }
?: ""
}
fun getDoubleVariant(): Gesture {
return when(this) {
SWIPE_UP -> SWIPE_UP_DOUBLE
SWIPE_DOWN -> SWIPE_DOWN_DOUBLE
SWIPE_LEFT -> SWIPE_LEFT_DOUBLE
SWIPE_RIGHT -> SWIPE_RIGHT_DOUBLE
else -> this
}
}
fun isDoubleVariant(): Boolean {
return when(this){
SWIPE_UP_DOUBLE,
SWIPE_DOWN_DOUBLE,
SWIPE_LEFT_DOUBLE,
SWIPE_RIGHT_DOUBLE -> true
else -> false
}
}
operator fun invoke(activity: Activity) {
launch(this.getApp(activity), activity, this.animationIn, this.animationOut)
}
companion object {
fun byId(id: String): Gesture? {
return Gesture.values().firstOrNull {it.id == id }
}
}
}

View file

@ -1,6 +1,5 @@
package de.jrpie.android.launcher package de.jrpie.android.launcher
import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.AsyncTask import android.os.AsyncTask
import android.os.Bundle import android.os.Bundle
@ -44,18 +43,15 @@ class HomeActivity: UIObject, AppCompatActivity(),
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
// Initialise globals val preferences = getPreferences(this)
launcherPreferences = this.getSharedPreferences(
getString(R.string.preference_file_key), Context.MODE_PRIVATE)
windowManager.defaultDisplay.getMetrics(displayMetrics) windowManager.defaultDisplay.getMetrics(displayMetrics)
loadSettings() loadSettings(this)
// First time opening the app: show Tutorial, else: check versions // First time opening the app: show Tutorial, else: check versions
if (!launcherPreferences.getBoolean(PREF_STARTED, false)) if (!preferences.getBoolean(PREF_STARTED, false))
startActivity(Intent(this, TutorialActivity::class.java)) startActivity(Intent(this, TutorialActivity::class.java))
else when (launcherPreferences.getString(PREF_VERSION, "")) { else when (preferences.getString(PREF_VERSION, "")) {
// Check versions, make sure transitions between versions go well // Check versions, make sure transitions between versions go well
VERSION_NAME -> { /* the version installed and used previously are the same */ } VERSION_NAME -> { /* the version installed and used previously are the same */ }
@ -67,12 +63,12 @@ class HomeActivity: UIObject, AppCompatActivity(),
* were not stored anywhere. Now they have to be stored: * were not stored anywhere. Now they have to be stored:
* -> we just reset them using newly implemented functions * -> we just reset them using newly implemented functions
*/ */
when (getSavedTheme()) { when (getSavedTheme(this)) {
"finn" -> resetToDefaultTheme(this) "finn" -> resetToDefaultTheme(this)
"dark" -> resetToDarkTheme(this) "dark" -> resetToDarkTheme(this)
} }
launcherPreferences.edit() preferences.edit()
.putString(PREF_VERSION, VERSION_NAME) // save new version .putString(PREF_VERSION, VERSION_NAME) // save new version
.apply() .apply()
@ -95,7 +91,7 @@ class HomeActivity: UIObject, AppCompatActivity(),
mDetector.setOnDoubleTapListener(this) mDetector.setOnDoubleTapListener(this)
// for if the settings changed // for if the settings changed
loadSettings() loadSettings(this)
super<UIObject>.onStart() super<UIObject>.onStart()
} }
@ -103,7 +99,7 @@ class HomeActivity: UIObject, AppCompatActivity(),
super.onResume() super.onResume()
// Applying the date / time format (changeable in settings) // Applying the date / time format (changeable in settings)
val dFormat = launcherPreferences.getInt(PREF_DATE_FORMAT, 0) val dFormat = getPreferences(this).getInt(PREF_DATE_FORMAT, 0)
val upperFMT = resources.getStringArray(R.array.settings_launcher_time_formats_upper) val upperFMT = resources.getStringArray(R.array.settings_launcher_time_formats_upper)
val lowerFMT = resources.getStringArray(R.array.settings_launcher_time_formats_lower) val lowerFMT = resources.getStringArray(R.array.settings_launcher_time_formats_lower)
@ -131,8 +127,8 @@ class HomeActivity: UIObject, AppCompatActivity(),
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean { override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
when (keyCode) { when (keyCode) {
KeyEvent.KEYCODE_BACK -> LauncherAction.CHOOSE.launch(this) KeyEvent.KEYCODE_BACK -> LauncherAction.CHOOSE.launch(this)
KeyEvent.KEYCODE_VOLUME_UP -> launch(volumeUpApp, this,0, 0) KeyEvent.KEYCODE_VOLUME_UP -> Gesture.VOLUME_UP(this)
KeyEvent.KEYCODE_VOLUME_DOWN -> launch(volumeDownApp, this,0, 0) KeyEvent.KEYCODE_VOLUME_DOWN -> Gesture.VOLUME_DOWN(this)
} }
return true return true
} }
@ -145,45 +141,43 @@ class HomeActivity: UIObject, AppCompatActivity(),
val diffX = e1.x - e2.x val diffX = e1.x - e2.x
val diffY = e1.y - e2.y val diffY = e1.y - e2.y
val doubleActions = launcherPreferences.getBoolean(PREF_DOUBLE_ACTIONS_ENABLED, false) val preferences = getPreferences(this)
val doubleActions = preferences.getBoolean(PREF_DOUBLE_ACTIONS_ENABLED, false)
// how distinguished the swipe has to be to launch something // how distinguished the swipe has to be to launch something
// strictness = opposite of sensitivity. TODO - May have to be adjusted // strictness = opposite of sensitivity. TODO - May have to be adjusted
val strictness = (4 / bufferedPointerCount) * ((100 - launcherPreferences.getInt(PREF_SLIDE_SENSITIVITY, 50)) / 50) val strictness = (4 / bufferedPointerCount) * ((100 - preferences.getInt(PREF_SLIDE_SENSITIVITY, 50)) / 50)
var gesture = if(abs(diffX) > abs(diffY)) { // horizontal swipe
if(abs(diffX) > abs(diffY)) { // horizontal swipe if (diffX > width / 4 && abs(diffX) > strictness * abs(diffY))
if (diffX > width / 4 && abs(diffX) > strictness * abs(diffY)) { Gesture.SWIPE_LEFT
if (bufferedPointerCount == 1) launch(leftApp,this, R.anim.right_left) else if (diffX < -width / 4 && abs(diffX) > strictness * abs(diffY))
else if (bufferedPointerCount == 2 && doubleActions) launch(doubleLeftApp,this, R.anim.right_left) Gesture.SWIPE_RIGHT
} else null
else if (diffX < -width / 4 && abs(diffX) > strictness * abs(diffY)) {
if (bufferedPointerCount == 1) launch(rightApp, this, R.anim.left_right)
else if (bufferedPointerCount == 2 && doubleActions) launch(doubleRightApp, this, R.anim.left_right)
}
} else { // vertical swipe } else { // vertical swipe
// Only open if the swipe was not from the phones top edge // Only open if the swipe was not from the phones top edge
if (diffY < -height / 8 && abs(diffY) > strictness * abs(diffX) && e1.y > 100) { if (diffY < -height / 8 && abs(diffY) > strictness * abs(diffX) && e1.y > 100)
if (bufferedPointerCount == 1) launch(downApp, this, R.anim.top_down) Gesture.SWIPE_DOWN
else if (bufferedPointerCount == 2 && doubleActions) launch(doubleDownApp, this, R.anim.top_down) else if (diffY > height / 8 && abs(diffY) > strictness * abs(diffX))
} Gesture.SWIPE_UP
else if (diffY > height / 8 && abs(diffY) > strictness * abs(diffX)) { else null
if (bufferedPointerCount == 1) launch(upApp, this, R.anim.bottom_up)
else if (bufferedPointerCount == 2 && doubleActions) launch(doubleUpApp, this, R.anim.bottom_up)
}
} }
if (doubleActions && bufferedPointerCount > 1) {
gesture = gesture?.let(Gesture::getDoubleVariant)
}
gesture?.invoke(this)
return true return true
} }
override fun onLongPress(event: MotionEvent) { override fun onLongPress(event: MotionEvent) {
launch(longClickApp, this) Gesture.LONG_CLICK(this)
overridePendingTransition(0, 0)
} }
override fun onDoubleTap(event: MotionEvent): Boolean { override fun onDoubleTap(event: MotionEvent): Boolean {
launch(doubleClickApp, this) Gesture.DOUBLE_CLICK(this)
overridePendingTransition(0, 0)
return false return false
} }
@ -209,17 +203,18 @@ class HomeActivity: UIObject, AppCompatActivity(),
override fun setOnClicks() { override fun setOnClicks() {
val preferences = getPreferences(this)
home_upper_view.setOnClickListener { home_upper_view.setOnClickListener {
when (launcherPreferences.getInt(PREF_DATE_FORMAT, 0)) { when (preferences.getInt(PREF_DATE_FORMAT, 0)) {
0 -> launch(dateApp, this) 0 -> Gesture.DATE(this)
else -> launch(timeApp,this) else -> Gesture.TIME(this)
} }
} }
home_lower_view.setOnClickListener { home_lower_view.setOnClickListener {
when (launcherPreferences.getInt(PREF_DATE_FORMAT, 0)) { when (preferences.getInt(PREF_DATE_FORMAT, 0)) {
0 -> launch(timeApp, this) 0 -> Gesture.TIME(this)
else -> launch(dateApp,this) else -> Gesture.DATE(this)
} }
} }
} }

View file

@ -26,8 +26,8 @@ import kotlinx.android.synthetic.main.list.*
var intendedChoosePause = false // know when to close var intendedChoosePause = false // know when to close
// TODO: Better solution for this intercommunication functionality (used in list-fragments) // TODO: Better solution for this intercommunication functionality (used in list-fragments)
var intention = "view" var intention = ListActivity.ListActivityIntention.VIEW
var forApp = "" var forGesture: String? = null
/** /**
* The [ListActivity] is the most general purpose activity in Launcher: * The [ListActivity] is the most general purpose activity in Launcher:
@ -37,7 +37,10 @@ var forApp = ""
* The activity itself can also be chosen to be launched as an action. * The activity itself can also be chosen to be launched as an action.
*/ */
class ListActivity : AppCompatActivity(), UIObject { class ListActivity : AppCompatActivity(), UIObject {
enum class ListActivityIntention(val titleResource: Int) {
VIEW(R.string.list_title_view), /* view list of apps */
PICK(R.string.list_title_pick) /* choose app or action to associate to a gesture */
}
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -46,7 +49,7 @@ class ListActivity : AppCompatActivity(), UIObject {
list_settings.setOnClickListener { list_settings.setOnClickListener {
launch(LauncherAction.SETTINGS.id, this@ListActivity, R.anim.bottom_up) launch(LauncherAction.SETTINGS.id, this@ListActivity, R.anim.bottom_up)
LauncherAction.SETTINGS.launch(this@ListActivity); LauncherAction.SETTINGS.launch(this@ListActivity)
} }
} }
@ -57,13 +60,7 @@ class ListActivity : AppCompatActivity(), UIObject {
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
intendedSettingsPause = false finish()
if(!intendedChoosePause) finish()
}
override fun onResume() {
super.onResume()
intendedChoosePause = false
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
@ -91,22 +88,21 @@ class ListActivity : AppCompatActivity(), UIObject {
override fun adjustLayout() { override fun adjustLayout() {
// get info about which action this activity is open for // get info about which action this activity is open for
val bundle = intent.extras intent.extras?.let { bundle ->
if (bundle != null) { intention = bundle.getString("intention")
intention = bundle.getString("intention")!! // why choose an app ?.let { ListActivityIntention.valueOf(it) }
if (intention != "view") ?: ListActivityIntention.VIEW
forApp = bundle.getString("forApp")!! // which app we choose
if (intention != ListActivityIntention.VIEW)
forGesture = bundle.getString("forGesture")
} }
// Hide tabs for the "view" action // Hide tabs for the "view" action
if (intention == "view") { if (intention == ListActivityIntention.VIEW) {
list_tabs.visibility = View.GONE list_tabs.visibility = View.GONE
} }
when (intention) { list_heading.text = getString(intention.titleResource)
"view" -> list_heading.text = getString(R.string.list_title_view)
"pick" -> list_heading.text = getString(R.string.list_title_pick)
}
val sectionsPagerAdapter = ListSectionsPagerAdapter(this, supportFragmentManager) val sectionsPagerAdapter = ListSectionsPagerAdapter(this, supportFragmentManager)
val viewPager: ViewPager = findViewById(R.id.list_viewpager) val viewPager: ViewPager = findViewById(R.id.list_viewpager)
@ -142,7 +138,7 @@ class ListSectionsPagerAdapter(private val context: Context, fm: FragmentManager
override fun getCount(): Int { override fun getCount(): Int {
return when (intention) { return when (intention) {
"view" -> 1 ListActivity.ListActivityIntention.VIEW -> 1
else -> 2 else -> 2
} }
} }

View file

@ -18,9 +18,10 @@ import de.jrpie.android.launcher.R
import de.jrpie.android.launcher.REQUEST_CHOOSE_APP import de.jrpie.android.launcher.REQUEST_CHOOSE_APP
import de.jrpie.android.launcher.REQUEST_UNINSTALL import de.jrpie.android.launcher.REQUEST_UNINSTALL
import de.jrpie.android.launcher.appsList import de.jrpie.android.launcher.appsList
import de.jrpie.android.launcher.getPreferences
import de.jrpie.android.launcher.getSavedTheme import de.jrpie.android.launcher.getSavedTheme
import de.jrpie.android.launcher.launch import de.jrpie.android.launcher.launch
import de.jrpie.android.launcher.launcherPreferences import de.jrpie.android.launcher.list.ListActivity
import de.jrpie.android.launcher.list.intendedChoosePause import de.jrpie.android.launcher.list.intendedChoosePause
import de.jrpie.android.launcher.loadApps import de.jrpie.android.launcher.loadApps
import de.jrpie.android.launcher.openAppSettings import de.jrpie.android.launcher.openAppSettings
@ -33,11 +34,12 @@ import java.util.*
* *
* @param activity - the activity this is in * @param activity - the activity this is in
* @param intention - why the list is displayed ("view", "pick") * @param intention - why the list is displayed ("view", "pick")
* @param forApp - the action which an app is chosen for (when the intention is "pick") * @param forGesture - the action which an app is chosen for (when the intention is "pick")
*/ */
class AppsRecyclerAdapter(val activity: Activity, class AppsRecyclerAdapter(val activity: Activity,
val intention: String? = "view", val intention: ListActivity.ListActivityIntention
val forApp: String? = ""): = ListActivity.ListActivityIntention.VIEW,
val forGesture: String? = ""):
RecyclerView.Adapter<AppsRecyclerAdapter.ViewHolder>() { RecyclerView.Adapter<AppsRecyclerAdapter.ViewHolder>() {
private val appsListDisplayed: MutableList<AppInfo> private val appsListDisplayed: MutableList<AppInfo>
@ -54,15 +56,15 @@ class AppsRecyclerAdapter(val activity: Activity,
val appPackageName = appsListDisplayed[pos].packageName.toString() val appPackageName = appsListDisplayed[pos].packageName.toString()
when (intention){ when (intention){
"view" -> { ListActivity.ListActivityIntention.VIEW -> {
val launchIntent: Intent = context.packageManager val launchIntent: Intent = context.packageManager
.getLaunchIntentForPackage(appPackageName)!! .getLaunchIntentForPackage(appPackageName)!!
context.startActivity(launchIntent) context.startActivity(launchIntent)
} }
"pick" -> { ListActivity.ListActivityIntention.PICK -> {
val returnIntent = Intent() val returnIntent = Intent()
returnIntent.putExtra("value", appPackageName) returnIntent.putExtra("value", appPackageName)
returnIntent.putExtra("forApp", forApp) returnIntent.putExtra("forGesture", forGesture)
activity.setResult(REQUEST_CHOOSE_APP, returnIntent) activity.setResult(REQUEST_CHOOSE_APP, returnIntent)
activity.finish() activity.finish()
} }
@ -81,12 +83,12 @@ class AppsRecyclerAdapter(val activity: Activity,
viewHolder.textView.text = appLabel viewHolder.textView.text = appLabel
viewHolder.img.setImageDrawable(appIcon) viewHolder.img.setImageDrawable(appIcon)
if (getSavedTheme() == "dark") transformGrayscale( if (getSavedTheme(activity) == "dark") transformGrayscale(
viewHolder.img viewHolder.img
) )
// decide when to show the options popup menu about // decide when to show the options popup menu about
if (isSystemApp || intention == "pick") { if (isSystemApp || intention == ListActivity.ListActivityIntention.PICK) {
viewHolder.menuDots.visibility = View.INVISIBLE viewHolder.menuDots.visibility = View.INVISIBLE
} }
else { else {
@ -166,7 +168,7 @@ class AppsRecyclerAdapter(val activity: Activity,
fun filter(text: String) { fun filter(text: String) {
// normalize text for search // normalize text for search
fun normalize(text: String): String{ fun normalize(text: String): String{
return text.toLowerCase(Locale.ROOT).replace("[^a-z0-9]".toRegex(), "") return text.lowercase(Locale.ROOT).replace("[^a-z0-9]".toRegex(), "")
} }
appsListDisplayed.clear() appsListDisplayed.clear()
if (text.isEmpty()) { if (text.isEmpty()) {
@ -189,8 +191,8 @@ class AppsRecyclerAdapter(val activity: Activity,
// Launch apps automatically if only one result is found and the user wants it // Launch apps automatically if only one result is found and the user wants it
// Disabled at the moment. The Setting 'PREF_SEARCH_AUTO_LAUNCH' may be // Disabled at the moment. The Setting 'PREF_SEARCH_AUTO_LAUNCH' may be
// modifiable at some later point. // modifiable at some later point.
if (appsListDisplayed.size == 1 && intention == "view" if (appsListDisplayed.size == 1 && intention == ListActivity.ListActivityIntention.VIEW
&& launcherPreferences.getBoolean(PREF_SEARCH_AUTO_LAUNCH, false)) { && getPreferences(activity).getBoolean(PREF_SEARCH_AUTO_LAUNCH, false)) {
launch(appsListDisplayed[0].packageName.toString(), activity) launch(appsListDisplayed[0].packageName.toString(), activity)
val inputMethodManager = activity.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager val inputMethodManager = activity.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager

View file

@ -9,8 +9,9 @@ import androidx.recyclerview.widget.LinearLayoutManager
import de.jrpie.android.launcher.PREF_SEARCH_AUTO_KEYBOARD import de.jrpie.android.launcher.PREF_SEARCH_AUTO_KEYBOARD
import de.jrpie.android.launcher.R import de.jrpie.android.launcher.R
import de.jrpie.android.launcher.UIObject import de.jrpie.android.launcher.UIObject
import de.jrpie.android.launcher.launcherPreferences import de.jrpie.android.launcher.getPreferences
import de.jrpie.android.launcher.list.forApp import de.jrpie.android.launcher.list.ListActivity
import de.jrpie.android.launcher.list.forGesture
import de.jrpie.android.launcher.list.intention import de.jrpie.android.launcher.list.intention
import de.jrpie.android.launcher.openSoftKeyboard import de.jrpie.android.launcher.openSoftKeyboard
import kotlinx.android.synthetic.main.list_apps.* import kotlinx.android.synthetic.main.list_apps.*
@ -42,7 +43,7 @@ class ListFragmentApps : Fragment(), UIObject {
override fun adjustLayout() { override fun adjustLayout() {
val appsRViewAdapter = AppsRecyclerAdapter(activity!!, intention, forApp) val appsRViewAdapter = AppsRecyclerAdapter(activity!!, intention, forGesture)
// set up the list / recycler // set up the list / recycler
list_apps_rview.apply { list_apps_rview.apply {
@ -66,7 +67,9 @@ class ListFragmentApps : Fragment(), UIObject {
} }
}) })
if (intention == "view" && launcherPreferences.getBoolean(PREF_SEARCH_AUTO_KEYBOARD, true)) { if (intention == ListActivity.ListActivityIntention.VIEW
&& getPreferences(context!!)
.getBoolean(PREF_SEARCH_AUTO_KEYBOARD, true)) {
openSoftKeyboard(context!!, list_apps_searchview) openSoftKeyboard(context!!, list_apps_searchview)
} }
} }

View file

@ -28,11 +28,11 @@ enum class LauncherAction(val id: String, val label: Int, val icon: Int, val lau
companion object { companion object {
fun byId(id: String): LauncherAction? { fun byId(id: String): LauncherAction? {
return LauncherAction.values().singleOrNull { it.id == id }; return LauncherAction.values().singleOrNull { it.id == id }
} }
fun isOtherAction(id: String): Boolean { fun isOtherAction(id: String): Boolean {
return id.startsWith("launcher"); return id.startsWith("launcher")
} }
} }
} }

View file

@ -10,7 +10,7 @@ import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import de.jrpie.android.launcher.R import de.jrpie.android.launcher.R
import de.jrpie.android.launcher.REQUEST_CHOOSE_APP import de.jrpie.android.launcher.REQUEST_CHOOSE_APP
import de.jrpie.android.launcher.list.forApp import de.jrpie.android.launcher.list.forGesture
/** /**
* The [OtherRecyclerAdapter] will only be displayed in the ListActivity, * The [OtherRecyclerAdapter] will only be displayed in the ListActivity,
@ -22,7 +22,7 @@ import de.jrpie.android.launcher.list.forApp
class OtherRecyclerAdapter(val activity: Activity): class OtherRecyclerAdapter(val activity: Activity):
RecyclerView.Adapter<OtherRecyclerAdapter.ViewHolder>() { RecyclerView.Adapter<OtherRecyclerAdapter.ViewHolder>() {
private val othersList: Array<LauncherAction> = LauncherAction.values(); private val othersList: Array<LauncherAction> = LauncherAction.values()
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView),
View.OnClickListener { View.OnClickListener {
@ -34,14 +34,14 @@ class OtherRecyclerAdapter(val activity: Activity):
val pos = adapterPosition val pos = adapterPosition
val content = othersList[pos] val content = othersList[pos]
returnChoiceIntent(forApp, content.id) forGesture?.let { returnChoiceIntent(it, content.id) }
} }
init { itemView.setOnClickListener(this) } init { itemView.setOnClickListener(this) }
} }
override fun onBindViewHolder(viewHolder: ViewHolder, i: Int) { override fun onBindViewHolder(viewHolder: ViewHolder, i: Int) {
val otherLabel = activity.getString(othersList[i].label); val otherLabel = activity.getString(othersList[i].label)
val icon = othersList[i].icon val icon = othersList[i].icon
viewHolder.textView.text = otherLabel viewHolder.textView.text = otherLabel
@ -59,7 +59,7 @@ class OtherRecyclerAdapter(val activity: Activity):
private fun returnChoiceIntent(forApp: String, value: String) { private fun returnChoiceIntent(forApp: String, value: String) {
val returnIntent = Intent() val returnIntent = Intent()
returnIntent.putExtra("value", value) returnIntent.putExtra("value", value)
returnIntent.putExtra("forApp", forApp) returnIntent.putExtra("forGesture", forApp)
activity.setResult(REQUEST_CHOOSE_APP, returnIntent) activity.setResult(REQUEST_CHOOSE_APP, returnIntent)
activity.finish() activity.finish()
} }

View file

@ -77,7 +77,7 @@ class SettingsActivity: AppCompatActivity(), UIObject {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) { when (requestCode) {
REQUEST_CHOOSE_APP -> saveListActivityChoice(data) REQUEST_CHOOSE_APP -> saveListActivityChoice(this, data)
else -> super.onActivityResult(requestCode, resultCode, data) else -> super.onActivityResult(requestCode, resultCode, data)
} }
} }

View file

@ -1,11 +0,0 @@
package de.jrpie.android.launcher.settings.actions
/**
* Stores information used in [ActionsRecyclerAdapter] rows.
*
* Represents an action - something to be triggered by swiping, clicking etc.
*
* @param data - a string identifying the app / action / intent to be launched
*/
class ActionInfo(val actionText: CharSequence, val actionName: CharSequence, val data: CharSequence) {
}

View file

@ -47,7 +47,7 @@ class SettingsFragmentActions : Fragment(), UIObject {
// App management buttons // App management buttons
settings_actions_button_view_apps.setOnClickListener{ settings_actions_button_view_apps.setOnClickListener{
val intent = Intent(this.context, ListActivity::class.java) val intent = Intent(this.context, ListActivity::class.java)
intent.putExtra("intention", "view") intent.putExtra("intention", ListActivity.ListActivityIntention.VIEW.toString())
intendedSettingsPause = true intendedSettingsPause = true
startActivity(intent) startActivity(intent)
} }

View file

@ -55,7 +55,7 @@ class SettingsFragmentActionsRecycler : Fragment(), UIObject {
class ActionsRecyclerAdapter(val activity: Activity): class ActionsRecyclerAdapter(val activity: Activity):
RecyclerView.Adapter<ActionsRecyclerAdapter.ViewHolder>() { RecyclerView.Adapter<ActionsRecyclerAdapter.ViewHolder>() {
private val actionsList: MutableList<ActionInfo> private val gesturesList: List<Gesture>
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView),
View.OnClickListener { View.OnClickListener {
@ -70,54 +70,45 @@ class ActionsRecyclerAdapter(val activity: Activity):
} }
override fun onBindViewHolder(viewHolder: ViewHolder, i: Int) { override fun onBindViewHolder(viewHolder: ViewHolder, i: Int) {
val actionText = actionsList[i].actionText val gesture = gesturesList[i]
val actionName = actionsList[i].actionName viewHolder.textView.text = gesture.getLabel(activity)
val content = actionsList[i].data setButtonColor(viewHolder.chooseButton, vibrantColor)
if (getSavedTheme(activity) == "dark") transformGrayscale(
viewHolder.textView.text = actionText viewHolder.img
)
viewHolder.removeAction.setOnClickListener{ fun updateViewHolder() {
val content = gesture.getApp(activity)
launcherPreferences.edit() if (content == ""){
.putString("action_$actionName", "") // clear it
.apply()
loadSettings() // apply new settings to the app
viewHolder.img.visibility = View.INVISIBLE
viewHolder.removeAction.visibility = View.GONE
viewHolder.chooseButton.visibility = View.VISIBLE
viewHolder.chooseButton.setOnClickListener{ chooseApp(actionName.toString()) }
setButtonColor(viewHolder.chooseButton, vibrantColor)
}
if (LauncherAction.isOtherAction(content.toString())) {
viewHolder.img.setOnClickListener{ chooseApp(actionName.toString()) }
LauncherAction.byId(content.toString())?.let {
viewHolder.img.setImageResource(it.icon)
}
} else {
// Set image icon (by packageName)
try {
viewHolder.img.setImageDrawable(activity.packageManager.getApplicationIcon(content.toString()))
viewHolder.img.setOnClickListener{ chooseApp(actionName.toString()) }
if (getSavedTheme() == "dark") transformGrayscale(
viewHolder.img
)
} catch (e : Exception) { // the button is shown, user asked to select an action
viewHolder.img.visibility = View.INVISIBLE viewHolder.img.visibility = View.INVISIBLE
viewHolder.removeAction.visibility = View.GONE viewHolder.removeAction.visibility = View.GONE
viewHolder.chooseButton.visibility = View.VISIBLE viewHolder.chooseButton.visibility = View.VISIBLE
viewHolder.chooseButton.setOnClickListener{ chooseApp(actionName.toString()) }
setButtonColor(viewHolder.chooseButton, vibrantColor)
} }
else if (LauncherAction.isOtherAction(content)) {
LauncherAction.byId(content)?.let {
viewHolder.img.setImageResource(it.icon)
}
} else {
// Set image icon (by packageName)
try {
viewHolder.img.setImageDrawable(activity.packageManager.getApplicationIcon(content))
} catch (e : Exception) {
// the button is shown, user asked to select an action
viewHolder.img.visibility = View.INVISIBLE
viewHolder.removeAction.visibility = View.GONE
viewHolder.chooseButton.visibility = View.VISIBLE
}
}
}
updateViewHolder()
viewHolder.img.setOnClickListener{ chooseApp(gesture) }
viewHolder.chooseButton.setOnClickListener{ chooseApp(gesture) }
viewHolder.removeAction.setOnClickListener{
gesture.removeApp(activity)
updateViewHolder()
} }
} }
override fun getItemCount(): Int { return actionsList.size } override fun getItemCount(): Int { return gesturesList.size }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val inflater = LayoutInflater.from(parent.context) val inflater = LayoutInflater.from(parent.context)
@ -126,58 +117,15 @@ class ActionsRecyclerAdapter(val activity: Activity):
} }
init { init {
val doubleActions = launcherPreferences.getBoolean(PREF_DOUBLE_ACTIONS_ENABLED, false) val doubleActions = getPreferences(activity).getBoolean(PREF_DOUBLE_ACTIONS_ENABLED, false)
gesturesList = Gesture.values().filter { doubleActions || !it.isDoubleVariant() }
actionsList = ArrayList()
actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_up),"upApp",
upApp
))
if ( doubleActions) actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_double_up), "doubleUpApp",
doubleUpApp
))
actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_down),"downApp",
downApp
))
if ( doubleActions) actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_double_down), "doubleDownApp",
doubleDownApp
))
actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_left), "leftApp",
leftApp
))
if ( doubleActions) actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_double_left), "doubleLeftApp",
doubleLeftApp
))
actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_right), "rightApp",
rightApp
))
if ( doubleActions) actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_double_right), "doubleRightApp",
doubleRightApp
))
actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_vol_up), "volumeUpApp",
volumeUpApp
))
actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_vol_down), "volumeDownApp",
volumeDownApp
))
actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_double_click), "doubleClickApp",
doubleClickApp
))
actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_long_click), "longClickApp",
longClickApp
))
actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_time), "timeApp",
timeApp
))
actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_date), "dateApp",
dateApp
))
} }
/* */ /* */
private fun chooseApp(forAction: String) { private fun chooseApp(gesture: Gesture) {
val intent = Intent(activity, ListActivity::class.java) val intent = Intent(activity, ListActivity::class.java)
intent.putExtra("intention", "pick") intent.putExtra("intention", ListActivity.ListActivityIntention.PICK.toString())
intent.putExtra("forApp", forAction) // for which action we choose the app intent.putExtra("forGesture", gesture.id) // for which action we choose the app
intendedSettingsPause = true intendedSettingsPause = true
activity.startActivityForResult(intent, activity.startActivityForResult(intent,
REQUEST_CHOOSE_APP REQUEST_CHOOSE_APP

View file

@ -19,8 +19,8 @@ import de.jrpie.android.launcher.PREF_SEARCH_AUTO_LAUNCH
import de.jrpie.android.launcher.PREF_SLIDE_SENSITIVITY import de.jrpie.android.launcher.PREF_SLIDE_SENSITIVITY
import de.jrpie.android.launcher.R import de.jrpie.android.launcher.R
import de.jrpie.android.launcher.UIObject import de.jrpie.android.launcher.UIObject
import de.jrpie.android.launcher.getPreferences
import de.jrpie.android.launcher.getSavedTheme import de.jrpie.android.launcher.getSavedTheme
import de.jrpie.android.launcher.launcherPreferences
import de.jrpie.android.launcher.resetToDarkTheme import de.jrpie.android.launcher.resetToDarkTheme
import de.jrpie.android.launcher.resetToDefaultTheme import de.jrpie.android.launcher.resetToDefaultTheme
import de.jrpie.android.launcher.setButtonColor import de.jrpie.android.launcher.setButtonColor
@ -74,40 +74,42 @@ class SettingsFragmentLauncher : Fragment(), UIObject {
startActivity(intent) startActivity(intent)
} }
settings_launcher_switch_screen_timeout.isChecked = launcherPreferences.getBoolean(PREF_SCREEN_TIMEOUT_DISABLED, false) val preferences = getPreferences(activity!!)
settings_launcher_switch_screen_timeout.isChecked = preferences.getBoolean(PREF_SCREEN_TIMEOUT_DISABLED, false)
settings_launcher_switch_screen_timeout.setOnCheckedChangeListener { _, isChecked -> // Toggle screen timeout settings_launcher_switch_screen_timeout.setOnCheckedChangeListener { _, isChecked -> // Toggle screen timeout
launcherPreferences.edit() preferences.edit()
.putBoolean(PREF_SCREEN_TIMEOUT_DISABLED, isChecked) .putBoolean(PREF_SCREEN_TIMEOUT_DISABLED, isChecked)
.apply() .apply()
setWindowFlags(activity!!.window) setWindowFlags(activity!!.window)
} }
settings_launcher_switch_screen_full.isChecked = launcherPreferences.getBoolean(PREF_SCREEN_FULLSCREEN, true) settings_launcher_switch_screen_full.isChecked = preferences.getBoolean(PREF_SCREEN_FULLSCREEN, true)
settings_launcher_switch_screen_full.setOnCheckedChangeListener { _, isChecked -> // Toggle fullscreen settings_launcher_switch_screen_full.setOnCheckedChangeListener { _, isChecked -> // Toggle fullscreen
launcherPreferences.edit() preferences.edit()
.putBoolean(PREF_SCREEN_FULLSCREEN, isChecked) .putBoolean(PREF_SCREEN_FULLSCREEN, isChecked)
.apply() .apply()
setWindowFlags(activity!!.window) setWindowFlags(activity!!.window)
} }
settings_launcher_switch_auto_launch.isChecked = launcherPreferences.getBoolean(PREF_SEARCH_AUTO_LAUNCH, false) settings_launcher_switch_auto_launch.isChecked = preferences.getBoolean(PREF_SEARCH_AUTO_LAUNCH, false)
settings_launcher_switch_auto_launch.setOnCheckedChangeListener { _, isChecked -> // Toggle double actions settings_launcher_switch_auto_launch.setOnCheckedChangeListener { _, isChecked -> // Toggle double actions
launcherPreferences.edit() preferences.edit()
.putBoolean(PREF_SEARCH_AUTO_LAUNCH, isChecked) .putBoolean(PREF_SEARCH_AUTO_LAUNCH, isChecked)
.apply() .apply()
} }
settings_launcher_switch_auto_keyboard.isChecked = launcherPreferences.getBoolean(PREF_SEARCH_AUTO_KEYBOARD, true) settings_launcher_switch_auto_keyboard.isChecked = preferences.getBoolean(PREF_SEARCH_AUTO_KEYBOARD, true)
settings_launcher_switch_auto_keyboard.setOnCheckedChangeListener { _, isChecked -> // Toggle double actions settings_launcher_switch_auto_keyboard.setOnCheckedChangeListener { _, isChecked -> // Toggle double actions
launcherPreferences.edit() preferences.edit()
.putBoolean(PREF_SEARCH_AUTO_KEYBOARD, isChecked) .putBoolean(PREF_SEARCH_AUTO_KEYBOARD, isChecked)
.apply() .apply()
} }
settings_launcher_switch_enable_double.isChecked = launcherPreferences.getBoolean(PREF_DOUBLE_ACTIONS_ENABLED, false) settings_launcher_switch_enable_double.isChecked = preferences.getBoolean(PREF_DOUBLE_ACTIONS_ENABLED, false)
settings_launcher_switch_enable_double.setOnCheckedChangeListener { _, isChecked -> // Toggle double actions settings_launcher_switch_enable_double.setOnCheckedChangeListener { _, isChecked -> // Toggle double actions
launcherPreferences.edit() preferences.edit()
.putBoolean(PREF_DOUBLE_ACTIONS_ENABLED, isChecked) .putBoolean(PREF_DOUBLE_ACTIONS_ENABLED, isChecked)
.apply() .apply()
@ -120,7 +122,7 @@ class SettingsFragmentLauncher : Fragment(), UIObject {
override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {} override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {}
override fun onStartTrackingTouch(p0: SeekBar?) {} override fun onStartTrackingTouch(p0: SeekBar?) {}
override fun onStopTrackingTouch(p0: SeekBar?) { override fun onStopTrackingTouch(p0: SeekBar?) {
launcherPreferences.edit() preferences.edit()
.putInt(PREF_SLIDE_SENSITIVITY, p0!!.progress * 100 / 4) // scale to % .putInt(PREF_SLIDE_SENSITIVITY, p0!!.progress * 100 / 4) // scale to %
.apply() .apply()
} }
@ -130,6 +132,7 @@ class SettingsFragmentLauncher : Fragment(), UIObject {
override fun adjustLayout() { override fun adjustLayout() {
val preferences = getPreferences(activity!!)
// Load values into the date-format spinner // Load values into the date-format spinner
val staticAdapter = ArrayAdapter.createFromResource( val staticAdapter = ArrayAdapter.createFromResource(
activity!!, R.array.settings_launcher_time_format_spinner_items, activity!!, R.array.settings_launcher_time_format_spinner_items,
@ -138,11 +141,11 @@ class SettingsFragmentLauncher : Fragment(), UIObject {
staticAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) staticAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
settings_launcher_format_spinner.adapter = staticAdapter settings_launcher_format_spinner.adapter = staticAdapter
settings_launcher_format_spinner.setSelection(launcherPreferences.getInt(PREF_DATE_FORMAT, 0)) settings_launcher_format_spinner.setSelection(preferences.getInt(PREF_DATE_FORMAT, 0))
settings_launcher_format_spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { settings_launcher_format_spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) { override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
launcherPreferences.edit() preferences.edit()
.putInt(PREF_DATE_FORMAT, position) .putInt(PREF_DATE_FORMAT, position)
.apply() .apply()
} }
@ -158,7 +161,7 @@ class SettingsFragmentLauncher : Fragment(), UIObject {
staticThemeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) staticThemeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
settings_launcher_theme_spinner.adapter = staticThemeAdapter settings_launcher_theme_spinner.adapter = staticThemeAdapter
val themeInt = when (getSavedTheme()) { val themeInt = when (getSavedTheme(activity!!)) {
"finn" -> 0 "finn" -> 0
"dark" -> 1 "dark" -> 1
else -> 0 else -> 0
@ -169,13 +172,13 @@ class SettingsFragmentLauncher : Fragment(), UIObject {
settings_launcher_theme_spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { settings_launcher_theme_spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) { override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
when (position) { when (position) {
0 -> if (getSavedTheme() != "finn") resetToDefaultTheme(activity!!) 0 -> if (getSavedTheme(activity!!) != "finn") resetToDefaultTheme(activity!!)
1 -> if (getSavedTheme() != "dark") resetToDarkTheme(activity!!) 1 -> if (getSavedTheme(activity!!) != "dark") resetToDarkTheme(activity!!)
} }
} }
override fun onNothingSelected(parent: AdapterView<*>?) { } override fun onNothingSelected(parent: AdapterView<*>?) { }
} }
settings_seekbar_sensitivity.progress = launcherPreferences.getInt(PREF_SLIDE_SENSITIVITY, 2) * 4 / 100 settings_seekbar_sensitivity.progress = preferences.getInt(PREF_SLIDE_SENSITIVITY, 2) * 4 / 100
} }
} }

View file

@ -12,7 +12,7 @@ import de.jrpie.android.launcher.PREF_STARTED
import de.jrpie.android.launcher.R import de.jrpie.android.launcher.R
import de.jrpie.android.launcher.REQUEST_CHOOSE_APP import de.jrpie.android.launcher.REQUEST_CHOOSE_APP
import de.jrpie.android.launcher.UIObject import de.jrpie.android.launcher.UIObject
import de.jrpie.android.launcher.launcherPreferences import de.jrpie.android.launcher.getPreferences
import de.jrpie.android.launcher.loadSettings import de.jrpie.android.launcher.loadSettings
import de.jrpie.android.launcher.resetSettings import de.jrpie.android.launcher.resetSettings
import de.jrpie.android.launcher.saveListActivityChoice import de.jrpie.android.launcher.saveListActivityChoice
@ -37,11 +37,12 @@ class TutorialActivity: AppCompatActivity(), UIObject {
// Initialise layout // Initialise layout
setContentView(R.layout.tutorial) setContentView(R.layout.tutorial)
val preferences = getPreferences(this)
// Check if the app was started before // Check if the app was started before
if (!launcherPreferences.getBoolean(PREF_STARTED, false)) if (!preferences.getBoolean(PREF_STARTED, false))
resetSettings(this) resetSettings(this)
loadSettings() loadSettings(this)
// set up tabs and swiping in settings // set up tabs and swiping in settings
val sectionsPagerAdapter = TutorialSectionsPagerAdapter(supportFragmentManager) val sectionsPagerAdapter = TutorialSectionsPagerAdapter(supportFragmentManager)
@ -58,14 +59,14 @@ class TutorialActivity: AppCompatActivity(), UIObject {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) { when (requestCode) {
REQUEST_CHOOSE_APP -> saveListActivityChoice(data) REQUEST_CHOOSE_APP -> saveListActivityChoice(this,data)
else -> super.onActivityResult(requestCode, resultCode, data) else -> super.onActivityResult(requestCode, resultCode, data)
} }
} }
// Default: prevent going back, allow if viewed again later // Default: prevent going back, allow if viewed again later
override fun onBackPressed() { override fun onBackPressed() {
if (launcherPreferences.getBoolean(PREF_STARTED, false)) if (getPreferences(this).getBoolean(PREF_STARTED, false))
super.onBackPressed() super.onBackPressed()
} }

View file

@ -39,13 +39,18 @@ class TutorialFragmentFinish : Fragment(), UIObject {
} }
private fun finishTutorial() { private fun finishTutorial() {
if (!launcherPreferences.getBoolean(PREF_STARTED, false)){ context?.let { getPreferences(it) }?.let {
launcherPreferences.edit() if (!it.getBoolean(PREF_STARTED, false)) {
.putBoolean(PREF_STARTED, true) // never auto run this again it.edit()
.putLong(PREF_STARTED_TIME, System.currentTimeMillis() / 1000L) // record first startup timestamp .putBoolean(PREF_STARTED, true) // never auto run this again
.putString(PREF_VERSION, VERSION_NAME) // save current launcher version .putLong(
.apply() PREF_STARTED_TIME,
System.currentTimeMillis() / 1000L
) // record first startup timestamp
.putString(PREF_VERSION, VERSION_NAME) // save current launcher version
.apply()
}
} }
activity!!.finish() activity?.finish()
} }
} }

View file

@ -5,8 +5,8 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import de.jrpie.android.launcher.* import de.jrpie.android.launcher.R
import kotlinx.android.synthetic.main.tutorial_usage.* import de.jrpie.android.launcher.UIObject
/** /**
* The [TutorialFragmentUsage] is a used as a tab in the TutorialActivity. * The [TutorialFragmentUsage] is a used as a tab in the TutorialActivity.

View file

@ -25,20 +25,20 @@
- Settings : Apps - Settings : Apps
- -
--> -->
<string name="settings_apps_up">Hochwischen</string> <string name="settings_gesture_up">Hochwischen</string>
<string name="settings_apps_double_up">Doppelt hoch</string> <string name="settings_gesture_double_up">Doppelt hoch</string>
<string name="settings_apps_down">Runterwischen</string> <string name="settings_gesture_down">Runterwischen</string>
<string name="settings_apps_double_down">Doppelt runter</string> <string name="settings_gesture_double_down">Doppelt runter</string>
<string name="settings_apps_left">Linkswischen</string> <string name="settings_gesture_left">Linkswischen</string>
<string name="settings_apps_double_left">Doppelt links</string> <string name="settings_gesture_double_left">Doppelt links</string>
<string name="settings_apps_right">Rechtswischen</string> <string name="settings_gesture_right">Rechtswischen</string>
<string name="settings_apps_double_right">Doppelt rechts</string> <string name="settings_gesture_double_right">Doppelt rechts</string>
<string name="settings_apps_vol_up">Lautstärke +</string> <string name="settings_gesture_vol_up">Lautstärke +</string>
<string name="settings_apps_vol_down">Lautstärke -</string> <string name="settings_gesture_vol_down">Lautstärke -</string>
<string name="settings_apps_double_click">Doppelklick</string> <string name="settings_gesture_double_click">Doppelklick</string>
<string name="settings_apps_long_click">Langer Klick</string> <string name="settings_gesture_long_click">Langer Klick</string>
<string name="settings_apps_date">Datum antippen</string> <string name="settings_gesture_date">Datum antippen</string>
<string name="settings_apps_time">Uhr antippen</string> <string name="settings_gesture_time">Uhr antippen</string>
<string name="settings_apps_choose">App wählen</string> <string name="settings_apps_choose">App wählen</string>

View file

@ -35,20 +35,20 @@
- Settings : Apps - Settings : Apps
- -
--> -->
<string name="settings_apps_up">Deslizar Arriba</string> <string name="settings_gesture_up">Deslizar Arriba</string>
<string name="settings_apps_double_up">Doble Arriba</string> <string name="settings_gesture_double_up">Doble Arriba</string>
<string name="settings_apps_down">Deslizar Abajo</string> <string name="settings_gesture_down">Deslizar Abajo</string>
<string name="settings_apps_double_down">Doble Abajo</string> <string name="settings_gesture_double_down">Doble Abajo</string>
<string name="settings_apps_left">Deslizar Izquierda</string> <string name="settings_gesture_left">Deslizar Izquierda</string>
<string name="settings_apps_double_left">Doble Izquierda</string> <string name="settings_gesture_double_left">Doble Izquierda</string>
<string name="settings_apps_right">Deslizar Derecha</string> <string name="settings_gesture_right">Deslizar Derecha</string>
<string name="settings_apps_double_right">Doble Derecha</string> <string name="settings_gesture_double_right">Doble Derecha</string>
<string name="settings_apps_vol_up">Subir Volumen</string> <string name="settings_gesture_vol_up">Subir Volumen</string>
<string name="settings_apps_vol_down">Bajar Volumen</string> <string name="settings_gesture_vol_down">Bajar Volumen</string>
<string name="settings_apps_double_click">Doble Click</string> <string name="settings_gesture_double_click">Doble Click</string>
<string name="settings_apps_long_click">Click Largo</string> <string name="settings_gesture_long_click">Click Largo</string>
<string name="settings_apps_date">Toca la fecha</string> <string name="settings_gesture_date">Toca la fecha</string>
<string name="settings_apps_time">Toca el reloj</string> <string name="settings_gesture_time">Toca el reloj</string>
<string name="settings_apps_choose">Elegir Aplicación</string> <string name="settings_apps_choose">Elegir Aplicación</string>

View file

@ -25,20 +25,20 @@
- Settings : Apps - Settings : Apps
- -
--> -->
<string name="settings_apps_up">Balayez haut</string> <string name="settings_gesture_up">Balayez haut</string>
<string name="settings_apps_double_up">Double haut</string> <string name="settings_gesture_double_up">Double haut</string>
<string name="settings_apps_down">Balayez bas</string> <string name="settings_gesture_down">Balayez bas</string>
<string name="settings_apps_double_down">Double bas</string> <string name="settings_gesture_double_down">Double bas</string>
<string name="settings_apps_left">Balayez gauche</string> <string name="settings_gesture_left">Balayez gauche</string>
<string name="settings_apps_double_left">Double gauche</string> <string name="settings_gesture_double_left">Double gauche</string>
<string name="settings_apps_right">Balayez droit</string> <string name="settings_gesture_right">Balayez droit</string>
<string name="settings_apps_double_right">Double droit</string> <string name="settings_gesture_double_right">Double droit</string>
<string name="settings_apps_vol_up">Monter volume</string> <string name="settings_gesture_vol_up">Monter volume</string>
<string name="settings_apps_vol_down">Baisser volume</string> <string name="settings_gesture_vol_down">Baisser volume</string>
<string name="settings_apps_double_click">Double clic</string> <string name="settings_gesture_double_click">Double clic</string>
<string name="settings_apps_long_click">Clic long</string> <string name="settings_gesture_long_click">Clic long</string>
<string name="settings_apps_date">Touchez date</string> <string name="settings_gesture_date">Touchez date</string>
<string name="settings_apps_time">Touchez horloge</string> <string name="settings_gesture_time">Touchez horloge</string>
<string name="settings_apps_choose">Choisir App</string> <string name="settings_apps_choose">Choisir App</string>

View file

@ -33,20 +33,20 @@
- Settings : Apps - Settings : Apps
- -
--> -->
<string name="settings_apps_up">Swipe Up</string> <string name="settings_gesture_up">Swipe Up</string>
<string name="settings_apps_double_up">Double Up</string> <string name="settings_gesture_double_up">Double Up</string>
<string name="settings_apps_down">Swipe Down</string> <string name="settings_gesture_down">Swipe Down</string>
<string name="settings_apps_double_down">Double Down</string> <string name="settings_gesture_double_down">Double Down</string>
<string name="settings_apps_left">Swipe Left</string> <string name="settings_gesture_left">Swipe Left</string>
<string name="settings_apps_double_left">Double Left</string> <string name="settings_gesture_double_left">Double Left</string>
<string name="settings_apps_right">Swipe Right</string> <string name="settings_gesture_right">Swipe Right</string>
<string name="settings_apps_double_right">Double Right</string> <string name="settings_gesture_double_right">Double Right</string>
<string name="settings_apps_vol_up">Volume Up</string> <string name="settings_gesture_vol_up">Volume Up</string>
<string name="settings_apps_vol_down">Volume Down</string> <string name="settings_gesture_vol_down">Volume Down</string>
<string name="settings_apps_double_click">Double Click</string> <string name="settings_gesture_double_click">Double Click</string>
<string name="settings_apps_long_click">Long Click</string> <string name="settings_gesture_long_click">Long Click</string>
<string name="settings_apps_date">Click on Date</string> <string name="settings_gesture_date">Click on Date</string>
<string name="settings_apps_time">Click on Time</string> <string name="settings_gesture_time">Click on Time</string>
<string name="settings_apps_choose">Choose App</string> <string name="settings_apps_choose">Choose App</string>