mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 14:31:30 +01:00
refactored code related to gestures
This commit is contained in:
parent
431f7b58ee
commit
3c6a883f39
20 changed files with 342 additions and 399 deletions
|
@ -19,7 +19,6 @@ import android.os.Bundle
|
|||
import android.os.SystemClock
|
||||
import android.provider.Settings
|
||||
import android.util.DisplayMetrics
|
||||
import android.util.Log
|
||||
import android.view.KeyEvent
|
||||
import android.view.View
|
||||
import android.view.Window
|
||||
|
@ -40,37 +39,8 @@ import de.jrpie.android.launcher.settings.intendedSettingsPause
|
|||
import de.jrpie.android.launcher.tutorial.TutorialActivity
|
||||
|
||||
|
||||
/* Preferences (global, initialised when app is started) */
|
||||
lateinit var launcherPreferences: SharedPreferences
|
||||
|
||||
/* 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_VIBRANT = "custom_vibrant"
|
||||
const val PREF_THEME = "theme"
|
||||
|
@ -96,24 +66,6 @@ val appsList: MutableList<AppInfo> = ArrayList()
|
|||
/* Variables containing settings */
|
||||
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 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 */
|
||||
|
||||
fun isInstalled(uri: String, context: Context): Boolean {
|
||||
|
@ -269,12 +228,12 @@ fun openNewTabWindow(urls: String, context: Context) {
|
|||
|
||||
/* Settings related functions */
|
||||
|
||||
fun getSavedTheme() : String {
|
||||
return launcherPreferences.getString(PREF_THEME, "finn").toString()
|
||||
fun getSavedTheme(context: Context) : String {
|
||||
return getPreferences(context).getString(PREF_THEME, "finn").toString()
|
||||
}
|
||||
|
||||
fun saveTheme(themeName: String) : String {
|
||||
launcherPreferences.edit()
|
||||
fun saveTheme(context: Context, themeName: String) : String {
|
||||
getPreferences(context).edit()
|
||||
.putString(PREF_THEME, themeName)
|
||||
.apply()
|
||||
|
||||
|
@ -285,13 +244,13 @@ fun resetToDefaultTheme(activity: Activity) {
|
|||
dominantColor = activity.resources.getColor(R.color.finnmglasTheme_background_color)
|
||||
vibrantColor = activity.resources.getColor(R.color.finnmglasTheme_accent_color)
|
||||
|
||||
launcherPreferences.edit()
|
||||
getPreferences(activity).edit()
|
||||
.putInt(PREF_DOMINANT, dominantColor)
|
||||
.putInt(PREF_VIBRANT, vibrantColor)
|
||||
.apply()
|
||||
|
||||
saveTheme("finn")
|
||||
loadSettings()
|
||||
saveTheme(activity,"finn")
|
||||
loadSettings(activity)
|
||||
|
||||
intendedSettingsPause = true
|
||||
activity.recreate()
|
||||
|
@ -301,12 +260,12 @@ fun resetToDarkTheme(activity: Activity) {
|
|||
dominantColor = activity.resources.getColor(R.color.darkTheme_background_color)
|
||||
vibrantColor = activity.resources.getColor(R.color.darkTheme_accent_color)
|
||||
|
||||
launcherPreferences.edit()
|
||||
getPreferences(activity).edit()
|
||||
.putInt(PREF_DOMINANT, dominantColor)
|
||||
.putInt(PREF_VIBRANT, vibrantColor)
|
||||
.apply()
|
||||
|
||||
saveTheme("dark")
|
||||
saveTheme(activity,"dark")
|
||||
|
||||
intendedSettingsPause = true
|
||||
activity.recreate()
|
||||
|
@ -329,9 +288,8 @@ fun openTutorial(activity: Activity){
|
|||
|
||||
fun openAppsList(activity: Activity){
|
||||
val intent = Intent(activity, ListActivity::class.java)
|
||||
intent.putExtra("intention", "view")
|
||||
intent.putExtra("intention", ListActivity.ListActivityIntention.VIEW.toString())
|
||||
intendedSettingsPause = true
|
||||
Log.i("de.jrpie", "openAppsList")
|
||||
activity.startActivity(intent)
|
||||
}
|
||||
|
||||
|
@ -358,31 +316,15 @@ fun loadApps(packageManager: PackageManager) {
|
|||
appsList.addAll(loadList)
|
||||
}
|
||||
|
||||
fun loadSettings() {
|
||||
upApp = launcherPreferences.getString(ACTION_UP, "")!!
|
||||
doubleUpApp = launcherPreferences.getString(ACTION_DOUBLE_UP, "")!!
|
||||
downApp = launcherPreferences.getString(ACTION_DOWN, "")!!
|
||||
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 loadSettings(context: Context) {
|
||||
val preferences = getPreferences(context)
|
||||
dominantColor = preferences.getInt(PREF_DOMINANT, 0)
|
||||
vibrantColor = preferences.getInt(PREF_VIBRANT, 0)
|
||||
}
|
||||
|
||||
fun resetSettings(context: Context) {
|
||||
|
||||
val editor = launcherPreferences.edit()
|
||||
val editor = getPreferences(context).edit()
|
||||
|
||||
// set default theme
|
||||
dominantColor = context.resources.getColor(R.color.finnmglasTheme_background_color)
|
||||
|
@ -399,9 +341,7 @@ fun resetSettings(context: Context) {
|
|||
.putBoolean(PREF_DOUBLE_ACTIONS_ENABLED, false)
|
||||
.putInt(PREF_SLIDE_SENSITIVITY, 50)
|
||||
|
||||
// load action defaults
|
||||
for (actionKey in ACTIONS)
|
||||
editor.putString(actionKey, pickDefaultApp(actionKey, context))
|
||||
Gesture.values().forEach { editor.putString(it.id, it.pickDefaultApp(context)) }
|
||||
|
||||
editor.apply()
|
||||
}
|
||||
|
@ -409,8 +349,9 @@ fun resetSettings(context: Context) {
|
|||
fun setWindowFlags(window: Window) {
|
||||
window.setFlags(0, 0) // clear flags
|
||||
|
||||
val preferences = getPreferences(window.context)
|
||||
// Display notification bar
|
||||
if (launcherPreferences.getBoolean(PREF_SCREEN_FULLSCREEN, true))
|
||||
if (preferences.getBoolean(PREF_SCREEN_FULLSCREEN, true))
|
||||
window.setFlags(
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN
|
||||
|
@ -418,7 +359,7 @@ fun setWindowFlags(window: Window) {
|
|||
else window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||
|
||||
// Screen Timeout
|
||||
if (launcherPreferences.getBoolean(PREF_SCREEN_TIMEOUT_DISABLED, false))
|
||||
if (preferences.getBoolean(PREF_SCREEN_TIMEOUT_DISABLED, false))
|
||||
window.setFlags(
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
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`
|
||||
fun saveListActivityChoice(data: Intent?) {
|
||||
fun saveListActivityChoice(context: Context, data: Intent?) {
|
||||
val value = data?.getStringExtra("value")
|
||||
val forApp = data?.getStringExtra("forApp") ?: return
|
||||
val forGesture = data?.getStringExtra("forGesture") ?: return
|
||||
|
||||
launcherPreferences.edit()
|
||||
.putString("action_$forApp", value.toString())
|
||||
.apply()
|
||||
Gesture.byId(forGesture)?.setApp(context, value.toString())
|
||||
|
||||
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) {
|
||||
view.requestFocus()
|
||||
// open the soft keyboard
|
||||
|
|
89
app/src/main/java/de/jrpie/android/launcher/Gesture.kt
Normal file
89
app/src/main/java/de/jrpie/android/launcher/Gesture.kt
Normal 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 }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package de.jrpie.android.launcher
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.AsyncTask
|
||||
import android.os.Bundle
|
||||
|
@ -44,18 +43,15 @@ class HomeActivity: UIObject, AppCompatActivity(),
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
// Initialise globals
|
||||
launcherPreferences = this.getSharedPreferences(
|
||||
getString(R.string.preference_file_key), Context.MODE_PRIVATE)
|
||||
|
||||
val preferences = getPreferences(this)
|
||||
windowManager.defaultDisplay.getMetrics(displayMetrics)
|
||||
|
||||
loadSettings()
|
||||
loadSettings(this)
|
||||
|
||||
// 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))
|
||||
else when (launcherPreferences.getString(PREF_VERSION, "")) {
|
||||
else when (preferences.getString(PREF_VERSION, "")) {
|
||||
// Check versions, make sure transitions between versions go well
|
||||
|
||||
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:
|
||||
* -> we just reset them using newly implemented functions
|
||||
*/
|
||||
when (getSavedTheme()) {
|
||||
when (getSavedTheme(this)) {
|
||||
"finn" -> resetToDefaultTheme(this)
|
||||
"dark" -> resetToDarkTheme(this)
|
||||
}
|
||||
|
||||
launcherPreferences.edit()
|
||||
preferences.edit()
|
||||
.putString(PREF_VERSION, VERSION_NAME) // save new version
|
||||
.apply()
|
||||
|
||||
|
@ -95,7 +91,7 @@ class HomeActivity: UIObject, AppCompatActivity(),
|
|||
mDetector.setOnDoubleTapListener(this)
|
||||
|
||||
// for if the settings changed
|
||||
loadSettings()
|
||||
loadSettings(this)
|
||||
super<UIObject>.onStart()
|
||||
}
|
||||
|
||||
|
@ -103,7 +99,7 @@ class HomeActivity: UIObject, AppCompatActivity(),
|
|||
super.onResume()
|
||||
|
||||
// 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 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 {
|
||||
when (keyCode) {
|
||||
KeyEvent.KEYCODE_BACK -> LauncherAction.CHOOSE.launch(this)
|
||||
KeyEvent.KEYCODE_VOLUME_UP -> launch(volumeUpApp, this,0, 0)
|
||||
KeyEvent.KEYCODE_VOLUME_DOWN -> launch(volumeDownApp, this,0, 0)
|
||||
KeyEvent.KEYCODE_VOLUME_UP -> Gesture.VOLUME_UP(this)
|
||||
KeyEvent.KEYCODE_VOLUME_DOWN -> Gesture.VOLUME_DOWN(this)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -145,45 +141,43 @@ class HomeActivity: UIObject, AppCompatActivity(),
|
|||
val diffX = e1.x - e2.x
|
||||
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
|
||||
// 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)
|
||||
|
||||
|
||||
if(abs(diffX) > abs(diffY)) { // horizontal swipe
|
||||
if (diffX > width / 4 && abs(diffX) > strictness * abs(diffY)) {
|
||||
if (bufferedPointerCount == 1) launch(leftApp,this, R.anim.right_left)
|
||||
else if (bufferedPointerCount == 2 && doubleActions) launch(doubleLeftApp,this, R.anim.right_left)
|
||||
}
|
||||
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)
|
||||
}
|
||||
var gesture = if(abs(diffX) > abs(diffY)) { // horizontal swipe
|
||||
if (diffX > width / 4 && abs(diffX) > strictness * abs(diffY))
|
||||
Gesture.SWIPE_LEFT
|
||||
else if (diffX < -width / 4 && abs(diffX) > strictness * abs(diffY))
|
||||
Gesture.SWIPE_RIGHT
|
||||
else null
|
||||
} else { // vertical swipe
|
||||
// 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 (bufferedPointerCount == 1) launch(downApp, this, R.anim.top_down)
|
||||
else if (bufferedPointerCount == 2 && doubleActions) launch(doubleDownApp, this, R.anim.top_down)
|
||||
}
|
||||
else if (diffY > height / 8 && abs(diffY) > strictness * abs(diffX)) {
|
||||
if (bufferedPointerCount == 1) launch(upApp, this, R.anim.bottom_up)
|
||||
else if (bufferedPointerCount == 2 && doubleActions) launch(doubleUpApp, this, R.anim.bottom_up)
|
||||
}
|
||||
if (diffY < -height / 8 && abs(diffY) > strictness * abs(diffX) && e1.y > 100)
|
||||
Gesture.SWIPE_DOWN
|
||||
else if (diffY > height / 8 && abs(diffY) > strictness * abs(diffX))
|
||||
Gesture.SWIPE_UP
|
||||
else null
|
||||
}
|
||||
|
||||
if (doubleActions && bufferedPointerCount > 1) {
|
||||
gesture = gesture?.let(Gesture::getDoubleVariant)
|
||||
}
|
||||
gesture?.invoke(this)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onLongPress(event: MotionEvent) {
|
||||
launch(longClickApp, this)
|
||||
overridePendingTransition(0, 0)
|
||||
Gesture.LONG_CLICK(this)
|
||||
}
|
||||
|
||||
override fun onDoubleTap(event: MotionEvent): Boolean {
|
||||
launch(doubleClickApp, this)
|
||||
overridePendingTransition(0, 0)
|
||||
Gesture.DOUBLE_CLICK(this)
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -209,17 +203,18 @@ class HomeActivity: UIObject, AppCompatActivity(),
|
|||
|
||||
override fun setOnClicks() {
|
||||
|
||||
val preferences = getPreferences(this)
|
||||
home_upper_view.setOnClickListener {
|
||||
when (launcherPreferences.getInt(PREF_DATE_FORMAT, 0)) {
|
||||
0 -> launch(dateApp, this)
|
||||
else -> launch(timeApp,this)
|
||||
when (preferences.getInt(PREF_DATE_FORMAT, 0)) {
|
||||
0 -> Gesture.DATE(this)
|
||||
else -> Gesture.TIME(this)
|
||||
}
|
||||
}
|
||||
|
||||
home_lower_view.setOnClickListener {
|
||||
when (launcherPreferences.getInt(PREF_DATE_FORMAT, 0)) {
|
||||
0 -> launch(timeApp, this)
|
||||
else -> launch(dateApp,this)
|
||||
when (preferences.getInt(PREF_DATE_FORMAT, 0)) {
|
||||
0 -> Gesture.TIME(this)
|
||||
else -> Gesture.DATE(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,8 +26,8 @@ import kotlinx.android.synthetic.main.list.*
|
|||
var intendedChoosePause = false // know when to close
|
||||
|
||||
// TODO: Better solution for this intercommunication functionality (used in list-fragments)
|
||||
var intention = "view"
|
||||
var forApp = ""
|
||||
var intention = ListActivity.ListActivityIntention.VIEW
|
||||
var forGesture: String? = null
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
|
@ -46,7 +49,7 @@ class ListActivity : AppCompatActivity(), UIObject {
|
|||
|
||||
list_settings.setOnClickListener {
|
||||
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() {
|
||||
super.onPause()
|
||||
intendedSettingsPause = false
|
||||
if(!intendedChoosePause) finish()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
intendedChoosePause = false
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
|
@ -91,22 +88,21 @@ class ListActivity : AppCompatActivity(), UIObject {
|
|||
|
||||
override fun adjustLayout() {
|
||||
// get info about which action this activity is open for
|
||||
val bundle = intent.extras
|
||||
if (bundle != null) {
|
||||
intention = bundle.getString("intention")!! // why choose an app
|
||||
if (intention != "view")
|
||||
forApp = bundle.getString("forApp")!! // which app we choose
|
||||
intent.extras?.let { bundle ->
|
||||
intention = bundle.getString("intention")
|
||||
?.let { ListActivityIntention.valueOf(it) }
|
||||
?: ListActivityIntention.VIEW
|
||||
|
||||
if (intention != ListActivityIntention.VIEW)
|
||||
forGesture = bundle.getString("forGesture")
|
||||
}
|
||||
|
||||
// Hide tabs for the "view" action
|
||||
if (intention == "view") {
|
||||
if (intention == ListActivityIntention.VIEW) {
|
||||
list_tabs.visibility = View.GONE
|
||||
}
|
||||
|
||||
when (intention) {
|
||||
"view" -> list_heading.text = getString(R.string.list_title_view)
|
||||
"pick" -> list_heading.text = getString(R.string.list_title_pick)
|
||||
}
|
||||
list_heading.text = getString(intention.titleResource)
|
||||
|
||||
val sectionsPagerAdapter = ListSectionsPagerAdapter(this, supportFragmentManager)
|
||||
val viewPager: ViewPager = findViewById(R.id.list_viewpager)
|
||||
|
@ -142,7 +138,7 @@ class ListSectionsPagerAdapter(private val context: Context, fm: FragmentManager
|
|||
|
||||
override fun getCount(): Int {
|
||||
return when (intention) {
|
||||
"view" -> 1
|
||||
ListActivity.ListActivityIntention.VIEW -> 1
|
||||
else -> 2
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,10 @@ import de.jrpie.android.launcher.R
|
|||
import de.jrpie.android.launcher.REQUEST_CHOOSE_APP
|
||||
import de.jrpie.android.launcher.REQUEST_UNINSTALL
|
||||
import de.jrpie.android.launcher.appsList
|
||||
import de.jrpie.android.launcher.getPreferences
|
||||
import de.jrpie.android.launcher.getSavedTheme
|
||||
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.loadApps
|
||||
import de.jrpie.android.launcher.openAppSettings
|
||||
|
@ -33,11 +34,12 @@ import java.util.*
|
|||
*
|
||||
* @param activity - the activity this is in
|
||||
* @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,
|
||||
val intention: String? = "view",
|
||||
val forApp: String? = ""):
|
||||
val intention: ListActivity.ListActivityIntention
|
||||
= ListActivity.ListActivityIntention.VIEW,
|
||||
val forGesture: String? = ""):
|
||||
RecyclerView.Adapter<AppsRecyclerAdapter.ViewHolder>() {
|
||||
|
||||
private val appsListDisplayed: MutableList<AppInfo>
|
||||
|
@ -54,15 +56,15 @@ class AppsRecyclerAdapter(val activity: Activity,
|
|||
val appPackageName = appsListDisplayed[pos].packageName.toString()
|
||||
|
||||
when (intention){
|
||||
"view" -> {
|
||||
ListActivity.ListActivityIntention.VIEW -> {
|
||||
val launchIntent: Intent = context.packageManager
|
||||
.getLaunchIntentForPackage(appPackageName)!!
|
||||
context.startActivity(launchIntent)
|
||||
}
|
||||
"pick" -> {
|
||||
ListActivity.ListActivityIntention.PICK -> {
|
||||
val returnIntent = Intent()
|
||||
returnIntent.putExtra("value", appPackageName)
|
||||
returnIntent.putExtra("forApp", forApp)
|
||||
returnIntent.putExtra("forGesture", forGesture)
|
||||
activity.setResult(REQUEST_CHOOSE_APP, returnIntent)
|
||||
activity.finish()
|
||||
}
|
||||
|
@ -81,12 +83,12 @@ class AppsRecyclerAdapter(val activity: Activity,
|
|||
viewHolder.textView.text = appLabel
|
||||
viewHolder.img.setImageDrawable(appIcon)
|
||||
|
||||
if (getSavedTheme() == "dark") transformGrayscale(
|
||||
if (getSavedTheme(activity) == "dark") transformGrayscale(
|
||||
viewHolder.img
|
||||
)
|
||||
|
||||
// decide when to show the options popup menu about
|
||||
if (isSystemApp || intention == "pick") {
|
||||
if (isSystemApp || intention == ListActivity.ListActivityIntention.PICK) {
|
||||
viewHolder.menuDots.visibility = View.INVISIBLE
|
||||
}
|
||||
else {
|
||||
|
@ -166,7 +168,7 @@ class AppsRecyclerAdapter(val activity: Activity,
|
|||
fun filter(text: String) {
|
||||
// normalize text for search
|
||||
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()
|
||||
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
|
||||
// Disabled at the moment. The Setting 'PREF_SEARCH_AUTO_LAUNCH' may be
|
||||
// modifiable at some later point.
|
||||
if (appsListDisplayed.size == 1 && intention == "view"
|
||||
&& launcherPreferences.getBoolean(PREF_SEARCH_AUTO_LAUNCH, false)) {
|
||||
if (appsListDisplayed.size == 1 && intention == ListActivity.ListActivityIntention.VIEW
|
||||
&& getPreferences(activity).getBoolean(PREF_SEARCH_AUTO_LAUNCH, false)) {
|
||||
launch(appsListDisplayed[0].packageName.toString(), activity)
|
||||
|
||||
val inputMethodManager = activity.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
|
|
|
@ -9,8 +9,9 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
|||
import de.jrpie.android.launcher.PREF_SEARCH_AUTO_KEYBOARD
|
||||
import de.jrpie.android.launcher.R
|
||||
import de.jrpie.android.launcher.UIObject
|
||||
import de.jrpie.android.launcher.launcherPreferences
|
||||
import de.jrpie.android.launcher.list.forApp
|
||||
import de.jrpie.android.launcher.getPreferences
|
||||
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.openSoftKeyboard
|
||||
import kotlinx.android.synthetic.main.list_apps.*
|
||||
|
@ -42,7 +43,7 @@ class ListFragmentApps : Fragment(), UIObject {
|
|||
|
||||
override fun adjustLayout() {
|
||||
|
||||
val appsRViewAdapter = AppsRecyclerAdapter(activity!!, intention, forApp)
|
||||
val appsRViewAdapter = AppsRecyclerAdapter(activity!!, intention, forGesture)
|
||||
|
||||
// set up the list / recycler
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,11 +28,11 @@ enum class LauncherAction(val id: String, val label: Int, val icon: Int, val lau
|
|||
|
||||
companion object {
|
||||
fun byId(id: String): LauncherAction? {
|
||||
return LauncherAction.values().singleOrNull { it.id == id };
|
||||
return LauncherAction.values().singleOrNull { it.id == id }
|
||||
}
|
||||
|
||||
fun isOtherAction(id: String): Boolean {
|
||||
return id.startsWith("launcher");
|
||||
return id.startsWith("launcher")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import android.widget.TextView
|
|||
import androidx.recyclerview.widget.RecyclerView
|
||||
import de.jrpie.android.launcher.R
|
||||
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,
|
||||
|
@ -22,7 +22,7 @@ import de.jrpie.android.launcher.list.forApp
|
|||
class OtherRecyclerAdapter(val activity: Activity):
|
||||
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),
|
||||
View.OnClickListener {
|
||||
|
@ -34,14 +34,14 @@ class OtherRecyclerAdapter(val activity: Activity):
|
|||
val pos = adapterPosition
|
||||
val content = othersList[pos]
|
||||
|
||||
returnChoiceIntent(forApp, content.id)
|
||||
forGesture?.let { returnChoiceIntent(it, content.id) }
|
||||
}
|
||||
|
||||
init { itemView.setOnClickListener(this) }
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
viewHolder.textView.text = otherLabel
|
||||
|
@ -59,7 +59,7 @@ class OtherRecyclerAdapter(val activity: Activity):
|
|||
private fun returnChoiceIntent(forApp: String, value: String) {
|
||||
val returnIntent = Intent()
|
||||
returnIntent.putExtra("value", value)
|
||||
returnIntent.putExtra("forApp", forApp)
|
||||
returnIntent.putExtra("forGesture", forApp)
|
||||
activity.setResult(REQUEST_CHOOSE_APP, returnIntent)
|
||||
activity.finish()
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ class SettingsActivity: AppCompatActivity(), UIObject {
|
|||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
when (requestCode) {
|
||||
REQUEST_CHOOSE_APP -> saveListActivityChoice(data)
|
||||
REQUEST_CHOOSE_APP -> saveListActivityChoice(this, data)
|
||||
else -> super.onActivityResult(requestCode, resultCode, data)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
}
|
|
@ -47,7 +47,7 @@ class SettingsFragmentActions : Fragment(), UIObject {
|
|||
// App management buttons
|
||||
settings_actions_button_view_apps.setOnClickListener{
|
||||
val intent = Intent(this.context, ListActivity::class.java)
|
||||
intent.putExtra("intention", "view")
|
||||
intent.putExtra("intention", ListActivity.ListActivityIntention.VIEW.toString())
|
||||
intendedSettingsPause = true
|
||||
startActivity(intent)
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ class SettingsFragmentActionsRecycler : Fragment(), UIObject {
|
|||
class ActionsRecyclerAdapter(val activity: Activity):
|
||||
RecyclerView.Adapter<ActionsRecyclerAdapter.ViewHolder>() {
|
||||
|
||||
private val actionsList: MutableList<ActionInfo>
|
||||
private val gesturesList: List<Gesture>
|
||||
|
||||
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView),
|
||||
View.OnClickListener {
|
||||
|
@ -70,54 +70,45 @@ class ActionsRecyclerAdapter(val activity: Activity):
|
|||
}
|
||||
|
||||
override fun onBindViewHolder(viewHolder: ViewHolder, i: Int) {
|
||||
val actionText = actionsList[i].actionText
|
||||
val actionName = actionsList[i].actionName
|
||||
val content = actionsList[i].data
|
||||
|
||||
viewHolder.textView.text = actionText
|
||||
|
||||
viewHolder.removeAction.setOnClickListener{
|
||||
|
||||
launcherPreferences.edit()
|
||||
.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
|
||||
val gesture = gesturesList[i]
|
||||
viewHolder.textView.text = gesture.getLabel(activity)
|
||||
setButtonColor(viewHolder.chooseButton, vibrantColor)
|
||||
if (getSavedTheme(activity) == "dark") transformGrayscale(
|
||||
viewHolder.img
|
||||
)
|
||||
fun updateViewHolder() {
|
||||
val content = gesture.getApp(activity)
|
||||
if (content == ""){
|
||||
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)
|
||||
}
|
||||
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 {
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
|
@ -126,58 +117,15 @@ class ActionsRecyclerAdapter(val activity: Activity):
|
|||
}
|
||||
|
||||
init {
|
||||
val doubleActions = launcherPreferences.getBoolean(PREF_DOUBLE_ACTIONS_ENABLED, false)
|
||||
|
||||
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
|
||||
))
|
||||
val doubleActions = getPreferences(activity).getBoolean(PREF_DOUBLE_ACTIONS_ENABLED, false)
|
||||
gesturesList = Gesture.values().filter { doubleActions || !it.isDoubleVariant() }
|
||||
}
|
||||
|
||||
/* */
|
||||
private fun chooseApp(forAction: String) {
|
||||
private fun chooseApp(gesture: Gesture) {
|
||||
val intent = Intent(activity, ListActivity::class.java)
|
||||
intent.putExtra("intention", "pick")
|
||||
intent.putExtra("forApp", forAction) // for which action we choose the app
|
||||
intent.putExtra("intention", ListActivity.ListActivityIntention.PICK.toString())
|
||||
intent.putExtra("forGesture", gesture.id) // for which action we choose the app
|
||||
intendedSettingsPause = true
|
||||
activity.startActivityForResult(intent,
|
||||
REQUEST_CHOOSE_APP
|
||||
|
|
|
@ -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.R
|
||||
import de.jrpie.android.launcher.UIObject
|
||||
import de.jrpie.android.launcher.getPreferences
|
||||
import de.jrpie.android.launcher.getSavedTheme
|
||||
import de.jrpie.android.launcher.launcherPreferences
|
||||
import de.jrpie.android.launcher.resetToDarkTheme
|
||||
import de.jrpie.android.launcher.resetToDefaultTheme
|
||||
import de.jrpie.android.launcher.setButtonColor
|
||||
|
@ -74,40 +74,42 @@ class SettingsFragmentLauncher : Fragment(), UIObject {
|
|||
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
|
||||
launcherPreferences.edit()
|
||||
preferences.edit()
|
||||
.putBoolean(PREF_SCREEN_TIMEOUT_DISABLED, isChecked)
|
||||
.apply()
|
||||
|
||||
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
|
||||
launcherPreferences.edit()
|
||||
preferences.edit()
|
||||
.putBoolean(PREF_SCREEN_FULLSCREEN, isChecked)
|
||||
.apply()
|
||||
|
||||
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
|
||||
launcherPreferences.edit()
|
||||
preferences.edit()
|
||||
.putBoolean(PREF_SEARCH_AUTO_LAUNCH, isChecked)
|
||||
.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
|
||||
launcherPreferences.edit()
|
||||
preferences.edit()
|
||||
.putBoolean(PREF_SEARCH_AUTO_KEYBOARD, isChecked)
|
||||
.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
|
||||
launcherPreferences.edit()
|
||||
preferences.edit()
|
||||
.putBoolean(PREF_DOUBLE_ACTIONS_ENABLED, isChecked)
|
||||
.apply()
|
||||
|
||||
|
@ -120,7 +122,7 @@ class SettingsFragmentLauncher : Fragment(), UIObject {
|
|||
override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {}
|
||||
override fun onStartTrackingTouch(p0: SeekBar?) {}
|
||||
override fun onStopTrackingTouch(p0: SeekBar?) {
|
||||
launcherPreferences.edit()
|
||||
preferences.edit()
|
||||
.putInt(PREF_SLIDE_SENSITIVITY, p0!!.progress * 100 / 4) // scale to %
|
||||
.apply()
|
||||
}
|
||||
|
@ -130,6 +132,7 @@ class SettingsFragmentLauncher : Fragment(), UIObject {
|
|||
|
||||
override fun adjustLayout() {
|
||||
|
||||
val preferences = getPreferences(activity!!)
|
||||
// Load values into the date-format spinner
|
||||
val staticAdapter = ArrayAdapter.createFromResource(
|
||||
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)
|
||||
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 {
|
||||
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
|
||||
launcherPreferences.edit()
|
||||
preferences.edit()
|
||||
.putInt(PREF_DATE_FORMAT, position)
|
||||
.apply()
|
||||
}
|
||||
|
@ -158,7 +161,7 @@ class SettingsFragmentLauncher : Fragment(), UIObject {
|
|||
staticThemeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
settings_launcher_theme_spinner.adapter = staticThemeAdapter
|
||||
|
||||
val themeInt = when (getSavedTheme()) {
|
||||
val themeInt = when (getSavedTheme(activity!!)) {
|
||||
"finn" -> 0
|
||||
"dark" -> 1
|
||||
else -> 0
|
||||
|
@ -169,13 +172,13 @@ class SettingsFragmentLauncher : Fragment(), UIObject {
|
|||
settings_launcher_theme_spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
|
||||
when (position) {
|
||||
0 -> if (getSavedTheme() != "finn") resetToDefaultTheme(activity!!)
|
||||
1 -> if (getSavedTheme() != "dark") resetToDarkTheme(activity!!)
|
||||
0 -> if (getSavedTheme(activity!!) != "finn") resetToDefaultTheme(activity!!)
|
||||
1 -> if (getSavedTheme(activity!!) != "dark") resetToDarkTheme(activity!!)
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import de.jrpie.android.launcher.PREF_STARTED
|
|||
import de.jrpie.android.launcher.R
|
||||
import de.jrpie.android.launcher.REQUEST_CHOOSE_APP
|
||||
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.resetSettings
|
||||
import de.jrpie.android.launcher.saveListActivityChoice
|
||||
|
@ -37,11 +37,12 @@ class TutorialActivity: AppCompatActivity(), UIObject {
|
|||
// Initialise layout
|
||||
setContentView(R.layout.tutorial)
|
||||
|
||||
val preferences = getPreferences(this)
|
||||
// Check if the app was started before
|
||||
if (!launcherPreferences.getBoolean(PREF_STARTED, false))
|
||||
if (!preferences.getBoolean(PREF_STARTED, false))
|
||||
resetSettings(this)
|
||||
|
||||
loadSettings()
|
||||
loadSettings(this)
|
||||
|
||||
// set up tabs and swiping in settings
|
||||
val sectionsPagerAdapter = TutorialSectionsPagerAdapter(supportFragmentManager)
|
||||
|
@ -58,14 +59,14 @@ class TutorialActivity: AppCompatActivity(), UIObject {
|
|||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
when (requestCode) {
|
||||
REQUEST_CHOOSE_APP -> saveListActivityChoice(data)
|
||||
REQUEST_CHOOSE_APP -> saveListActivityChoice(this,data)
|
||||
else -> super.onActivityResult(requestCode, resultCode, data)
|
||||
}
|
||||
}
|
||||
|
||||
// Default: prevent going back, allow if viewed again later
|
||||
override fun onBackPressed() {
|
||||
if (launcherPreferences.getBoolean(PREF_STARTED, false))
|
||||
if (getPreferences(this).getBoolean(PREF_STARTED, false))
|
||||
super.onBackPressed()
|
||||
}
|
||||
|
||||
|
|
|
@ -39,13 +39,18 @@ class TutorialFragmentFinish : Fragment(), UIObject {
|
|||
}
|
||||
|
||||
private fun finishTutorial() {
|
||||
if (!launcherPreferences.getBoolean(PREF_STARTED, false)){
|
||||
launcherPreferences.edit()
|
||||
.putBoolean(PREF_STARTED, true) // never auto run this again
|
||||
.putLong(PREF_STARTED_TIME, System.currentTimeMillis() / 1000L) // record first startup timestamp
|
||||
.putString(PREF_VERSION, VERSION_NAME) // save current launcher version
|
||||
.apply()
|
||||
context?.let { getPreferences(it) }?.let {
|
||||
if (!it.getBoolean(PREF_STARTED, false)) {
|
||||
it.edit()
|
||||
.putBoolean(PREF_STARTED, true) // never auto run this again
|
||||
.putLong(
|
||||
PREF_STARTED_TIME,
|
||||
System.currentTimeMillis() / 1000L
|
||||
) // record first startup timestamp
|
||||
.putString(PREF_VERSION, VERSION_NAME) // save current launcher version
|
||||
.apply()
|
||||
}
|
||||
}
|
||||
activity!!.finish()
|
||||
activity?.finish()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import de.jrpie.android.launcher.*
|
||||
import kotlinx.android.synthetic.main.tutorial_usage.*
|
||||
import de.jrpie.android.launcher.R
|
||||
import de.jrpie.android.launcher.UIObject
|
||||
|
||||
/**
|
||||
* The [TutorialFragmentUsage] is a used as a tab in the TutorialActivity.
|
||||
|
|
|
@ -25,20 +25,20 @@
|
|||
- Settings : Apps
|
||||
-
|
||||
-->
|
||||
<string name="settings_apps_up">Hochwischen</string>
|
||||
<string name="settings_apps_double_up">Doppelt hoch</string>
|
||||
<string name="settings_apps_down">Runterwischen</string>
|
||||
<string name="settings_apps_double_down">Doppelt runter</string>
|
||||
<string name="settings_apps_left">Linkswischen</string>
|
||||
<string name="settings_apps_double_left">Doppelt links</string>
|
||||
<string name="settings_apps_right">Rechtswischen</string>
|
||||
<string name="settings_apps_double_right">Doppelt rechts</string>
|
||||
<string name="settings_apps_vol_up">Lautstärke +</string>
|
||||
<string name="settings_apps_vol_down">Lautstärke -</string>
|
||||
<string name="settings_apps_double_click">Doppelklick</string>
|
||||
<string name="settings_apps_long_click">Langer Klick</string>
|
||||
<string name="settings_apps_date">Datum antippen</string>
|
||||
<string name="settings_apps_time">Uhr antippen</string>
|
||||
<string name="settings_gesture_up">Hochwischen</string>
|
||||
<string name="settings_gesture_double_up">Doppelt hoch</string>
|
||||
<string name="settings_gesture_down">Runterwischen</string>
|
||||
<string name="settings_gesture_double_down">Doppelt runter</string>
|
||||
<string name="settings_gesture_left">Linkswischen</string>
|
||||
<string name="settings_gesture_double_left">Doppelt links</string>
|
||||
<string name="settings_gesture_right">Rechtswischen</string>
|
||||
<string name="settings_gesture_double_right">Doppelt rechts</string>
|
||||
<string name="settings_gesture_vol_up">Lautstärke +</string>
|
||||
<string name="settings_gesture_vol_down">Lautstärke -</string>
|
||||
<string name="settings_gesture_double_click">Doppelklick</string>
|
||||
<string name="settings_gesture_long_click">Langer Klick</string>
|
||||
<string name="settings_gesture_date">Datum antippen</string>
|
||||
<string name="settings_gesture_time">Uhr antippen</string>
|
||||
|
||||
<string name="settings_apps_choose">App wählen</string>
|
||||
|
||||
|
|
|
@ -35,20 +35,20 @@
|
|||
- Settings : Apps
|
||||
-
|
||||
-->
|
||||
<string name="settings_apps_up">Deslizar Arriba</string>
|
||||
<string name="settings_apps_double_up">Doble Arriba</string>
|
||||
<string name="settings_apps_down">Deslizar Abajo</string>
|
||||
<string name="settings_apps_double_down">Doble Abajo</string>
|
||||
<string name="settings_apps_left">Deslizar Izquierda</string>
|
||||
<string name="settings_apps_double_left">Doble Izquierda</string>
|
||||
<string name="settings_apps_right">Deslizar Derecha</string>
|
||||
<string name="settings_apps_double_right">Doble Derecha</string>
|
||||
<string name="settings_apps_vol_up">Subir Volumen</string>
|
||||
<string name="settings_apps_vol_down">Bajar Volumen</string>
|
||||
<string name="settings_apps_double_click">Doble Click</string>
|
||||
<string name="settings_apps_long_click">Click Largo</string>
|
||||
<string name="settings_apps_date">Toca la fecha</string>
|
||||
<string name="settings_apps_time">Toca el reloj</string>
|
||||
<string name="settings_gesture_up">Deslizar Arriba</string>
|
||||
<string name="settings_gesture_double_up">Doble Arriba</string>
|
||||
<string name="settings_gesture_down">Deslizar Abajo</string>
|
||||
<string name="settings_gesture_double_down">Doble Abajo</string>
|
||||
<string name="settings_gesture_left">Deslizar Izquierda</string>
|
||||
<string name="settings_gesture_double_left">Doble Izquierda</string>
|
||||
<string name="settings_gesture_right">Deslizar Derecha</string>
|
||||
<string name="settings_gesture_double_right">Doble Derecha</string>
|
||||
<string name="settings_gesture_vol_up">Subir Volumen</string>
|
||||
<string name="settings_gesture_vol_down">Bajar Volumen</string>
|
||||
<string name="settings_gesture_double_click">Doble Click</string>
|
||||
<string name="settings_gesture_long_click">Click Largo</string>
|
||||
<string name="settings_gesture_date">Toca la fecha</string>
|
||||
<string name="settings_gesture_time">Toca el reloj</string>
|
||||
|
||||
<string name="settings_apps_choose">Elegir Aplicación</string>
|
||||
|
||||
|
|
|
@ -25,20 +25,20 @@
|
|||
- Settings : Apps
|
||||
-
|
||||
-->
|
||||
<string name="settings_apps_up">Balayez haut</string>
|
||||
<string name="settings_apps_double_up">Double haut</string>
|
||||
<string name="settings_apps_down">Balayez bas</string>
|
||||
<string name="settings_apps_double_down">Double bas</string>
|
||||
<string name="settings_apps_left">Balayez gauche</string>
|
||||
<string name="settings_apps_double_left">Double gauche</string>
|
||||
<string name="settings_apps_right">Balayez droit</string>
|
||||
<string name="settings_apps_double_right">Double droit</string>
|
||||
<string name="settings_apps_vol_up">Monter volume</string>
|
||||
<string name="settings_apps_vol_down">Baisser volume</string>
|
||||
<string name="settings_apps_double_click">Double clic</string>
|
||||
<string name="settings_apps_long_click">Clic long</string>
|
||||
<string name="settings_apps_date">Touchez date</string>
|
||||
<string name="settings_apps_time">Touchez horloge</string>
|
||||
<string name="settings_gesture_up">Balayez haut</string>
|
||||
<string name="settings_gesture_double_up">Double haut</string>
|
||||
<string name="settings_gesture_down">Balayez bas</string>
|
||||
<string name="settings_gesture_double_down">Double bas</string>
|
||||
<string name="settings_gesture_left">Balayez gauche</string>
|
||||
<string name="settings_gesture_double_left">Double gauche</string>
|
||||
<string name="settings_gesture_right">Balayez droit</string>
|
||||
<string name="settings_gesture_double_right">Double droit</string>
|
||||
<string name="settings_gesture_vol_up">Monter volume</string>
|
||||
<string name="settings_gesture_vol_down">Baisser volume</string>
|
||||
<string name="settings_gesture_double_click">Double clic</string>
|
||||
<string name="settings_gesture_long_click">Clic long</string>
|
||||
<string name="settings_gesture_date">Touchez date</string>
|
||||
<string name="settings_gesture_time">Touchez horloge</string>
|
||||
|
||||
<string name="settings_apps_choose">Choisir App</string>
|
||||
|
||||
|
|
|
@ -33,20 +33,20 @@
|
|||
- Settings : Apps
|
||||
-
|
||||
-->
|
||||
<string name="settings_apps_up">Swipe Up</string>
|
||||
<string name="settings_apps_double_up">Double Up</string>
|
||||
<string name="settings_apps_down">Swipe Down</string>
|
||||
<string name="settings_apps_double_down">Double Down</string>
|
||||
<string name="settings_apps_left">Swipe Left</string>
|
||||
<string name="settings_apps_double_left">Double Left</string>
|
||||
<string name="settings_apps_right">Swipe Right</string>
|
||||
<string name="settings_apps_double_right">Double Right</string>
|
||||
<string name="settings_apps_vol_up">Volume Up</string>
|
||||
<string name="settings_apps_vol_down">Volume Down</string>
|
||||
<string name="settings_apps_double_click">Double Click</string>
|
||||
<string name="settings_apps_long_click">Long Click</string>
|
||||
<string name="settings_apps_date">Click on Date</string>
|
||||
<string name="settings_apps_time">Click on Time</string>
|
||||
<string name="settings_gesture_up">Swipe Up</string>
|
||||
<string name="settings_gesture_double_up">Double Up</string>
|
||||
<string name="settings_gesture_down">Swipe Down</string>
|
||||
<string name="settings_gesture_double_down">Double Down</string>
|
||||
<string name="settings_gesture_left">Swipe Left</string>
|
||||
<string name="settings_gesture_double_left">Double Left</string>
|
||||
<string name="settings_gesture_right">Swipe Right</string>
|
||||
<string name="settings_gesture_double_right">Double Right</string>
|
||||
<string name="settings_gesture_vol_up">Volume Up</string>
|
||||
<string name="settings_gesture_vol_down">Volume Down</string>
|
||||
<string name="settings_gesture_double_click">Double Click</string>
|
||||
<string name="settings_gesture_long_click">Long Click</string>
|
||||
<string name="settings_gesture_date">Click on Date</string>
|
||||
<string name="settings_gesture_time">Click on Time</string>
|
||||
|
||||
<string name="settings_apps_choose">Choose App</string>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue