mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 14:31:30 +01:00
Improve swipe actions, usability
This commit is contained in:
parent
7fd2e9c733
commit
a41ab50ed8
1 changed files with 30 additions and 10 deletions
|
@ -15,6 +15,7 @@ import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.view.MotionEventCompat
|
import androidx.core.view.MotionEventCompat
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
|
import kotlin.math.abs
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.concurrent.fixedRateTimer
|
import kotlin.concurrent.fixedRateTimer
|
||||||
|
@ -58,6 +59,11 @@ class MainActivity : AppCompatActivity() {
|
||||||
fun launchClock(v: View){ launchApp("com.sec.android.app.clockpackage") }
|
fun launchClock(v: View){ launchApp("com.sec.android.app.clockpackage") }
|
||||||
fun launchBrowser(v: View){ launchApp("org.mozilla.firefox") }
|
fun launchBrowser(v: View){ launchApp("org.mozilla.firefox") }
|
||||||
|
|
||||||
|
fun launchUpApp() { launchBrowser(container) }
|
||||||
|
fun launchDownApp() { launchFinder(container) }
|
||||||
|
fun lauchLeftApp() { launchCalendar(container) }
|
||||||
|
fun lauchRightApp() { launchMail(container) }
|
||||||
|
|
||||||
// Overrides
|
// Overrides
|
||||||
|
|
||||||
var touchX : Float = 0F
|
var touchX : Float = 0F
|
||||||
|
@ -77,18 +83,32 @@ class MainActivity : AppCompatActivity() {
|
||||||
MotionEvent.ACTION_UP -> {
|
MotionEvent.ACTION_UP -> {
|
||||||
windowManager.defaultDisplay.getMetrics(displayMetrics)
|
windowManager.defaultDisplay.getMetrics(displayMetrics)
|
||||||
|
|
||||||
var width = displayMetrics.widthPixels
|
val width = displayMetrics.widthPixels
|
||||||
var height = displayMetrics.heightPixels
|
val height = displayMetrics.heightPixels
|
||||||
|
|
||||||
//swipe up
|
val diffX = touchX - event.x;
|
||||||
if (touchY - event.y > height/3) launchBrowser(container);
|
val diffY = touchY - event.y;
|
||||||
//swipe down
|
|
||||||
if (touchY - event.y < -height/3) launchFinder(container);
|
|
||||||
|
|
||||||
//swipe left
|
val strictness = 4 // of direction
|
||||||
if (touchX - event.x > width/3) launchCalendar(container);
|
|
||||||
//swipe right
|
// Decide which one to open
|
||||||
if (touchX - event.x < -width/3) launchMail(container);
|
|
||||||
|
if (diffY > height/8
|
||||||
|
&& abs(diffY) > strictness * abs(diffX))
|
||||||
|
launchUpApp()
|
||||||
|
|
||||||
|
else if (diffY < -height/8
|
||||||
|
&& abs(diffY) > strictness * abs(diffX)
|
||||||
|
&& touchY > 100)
|
||||||
|
launchDownApp()
|
||||||
|
|
||||||
|
else if (diffX > width/4
|
||||||
|
&& abs(diffX) > strictness * abs(diffY))
|
||||||
|
lauchLeftApp()
|
||||||
|
|
||||||
|
else if (diffX < -width/4
|
||||||
|
&& abs(diffX) > strictness * abs(diffY))
|
||||||
|
lauchRightApp()
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue