mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 14:31:30 +01:00
Merge pull request #3 from finnmglas/feature/select-apps
Feature/select apps
This commit is contained in:
commit
7064490e70
9 changed files with 626 additions and 143 deletions
|
@ -23,10 +23,10 @@
|
||||||
<activity android:name=".ChooseActivity"
|
<activity android:name=".ChooseActivity"
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
tools:ignore="LockedOrientationActivity">
|
tools:ignore="LockedOrientationActivity">
|
||||||
<intent-filter>
|
</activity>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<activity android:name=".SettingsActivity"
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
android:screenOrientation="portrait"
|
||||||
</intent-filter>
|
tools:ignore="LockedOrientationActivity">
|
||||||
</activity>
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,9 @@ package com.finnmglas.launcher
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.ApplicationInfo
|
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.View
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
@ -13,44 +13,8 @@ import kotlinx.android.synthetic.main.activity_choose.*
|
||||||
|
|
||||||
class ChooseActivity : AppCompatActivity() {
|
class ChooseActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private fun listApps() {
|
fun backHome(view: View) {
|
||||||
val mainIntent = Intent(Intent.ACTION_MAIN, null)
|
finish()
|
||||||
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER)
|
|
||||||
|
|
||||||
val pm = packageManager
|
|
||||||
val apps = pm.getInstalledApplications(0)
|
|
||||||
|
|
||||||
val installedApps: MutableList<ApplicationInfo> = ArrayList()
|
|
||||||
|
|
||||||
// list
|
|
||||||
for (app in apps) {
|
|
||||||
|
|
||||||
if (app.flags and ApplicationInfo.FLAG_UPDATED_SYSTEM_APP != 0) {
|
|
||||||
//checks for flags; if flagged, check if updated system app
|
|
||||||
installedApps.add(app)
|
|
||||||
} else if (app.flags and ApplicationInfo.FLAG_SYSTEM != 0) {
|
|
||||||
//it's a system app, not interested
|
|
||||||
} else {
|
|
||||||
//in this case, it should be a user-installed app
|
|
||||||
installedApps.add(app)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ui
|
|
||||||
for (app in installedApps) {
|
|
||||||
//packageInfo.sourceDir
|
|
||||||
pm.getLaunchIntentForPackage(app.packageName)
|
|
||||||
|
|
||||||
// creating TextView programmatically
|
|
||||||
val tvdynamic = TextView(this)
|
|
||||||
tvdynamic.textSize = 20f
|
|
||||||
tvdynamic.text = app.loadLabel(pm).toString()
|
|
||||||
tvdynamic.setTextColor(Color.parseColor("#cccccc"))
|
|
||||||
|
|
||||||
tvdynamic.setOnClickListener { startActivity(pm.getLaunchIntentForPackage(app.packageName)) }
|
|
||||||
|
|
||||||
apps_list.addView(tvdynamic)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n") // I do not care
|
@SuppressLint("SetTextI18n") // I do not care
|
||||||
|
@ -61,6 +25,51 @@ class ChooseActivity : AppCompatActivity() {
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
|
|
||||||
setContentView(R.layout.activity_choose)
|
setContentView(R.layout.activity_choose)
|
||||||
listApps()
|
|
||||||
|
val bundle = intent.extras
|
||||||
|
val action = bundle!!.getString("action") // why choose an app
|
||||||
|
val forApp = bundle.getString("forApp") // which app we choose
|
||||||
|
|
||||||
|
/* Build Layout */
|
||||||
|
|
||||||
|
// TODO: Make this more efficient, faster, generate the list before
|
||||||
|
|
||||||
|
val mainIntent = Intent(Intent.ACTION_MAIN, null)
|
||||||
|
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||||
|
|
||||||
|
val pm = packageManager
|
||||||
|
val i = Intent(Intent.ACTION_MAIN)
|
||||||
|
i.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||||
|
val apps = pm.queryIntentActivities(i, 0)
|
||||||
|
|
||||||
|
apps.sortBy { it.activityInfo.loadLabel(pm).toString() }
|
||||||
|
|
||||||
|
for (resolveInfo in apps) {
|
||||||
|
val app = resolveInfo.activityInfo
|
||||||
|
pm.getLaunchIntentForPackage(app.packageName)
|
||||||
|
|
||||||
|
// creating TextView programmatically
|
||||||
|
val tvdynamic = TextView(this)
|
||||||
|
tvdynamic.textSize = 24f
|
||||||
|
tvdynamic.text = app.loadLabel(pm).toString()
|
||||||
|
tvdynamic.setTextColor(Color.parseColor("#cccccc"))
|
||||||
|
|
||||||
|
if (action == "run"){
|
||||||
|
tvdynamic.setOnClickListener { startActivity(pm.getLaunchIntentForPackage(app.packageName)) }
|
||||||
|
}
|
||||||
|
else if (action == "pick"){
|
||||||
|
tvdynamic.setOnClickListener {
|
||||||
|
val returnIntent = Intent()
|
||||||
|
returnIntent.putExtra("value", app.packageName)
|
||||||
|
returnIntent.putExtra("forApp", forApp)
|
||||||
|
setResult(
|
||||||
|
5000,
|
||||||
|
returnIntent
|
||||||
|
)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
apps_list.addView(tvdynamic)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,135 +1,105 @@
|
||||||
package com.finnmglas.launcher
|
package com.finnmglas.launcher
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.SharedPreferences
|
||||||
import android.content.pm.ResolveInfo
|
import android.content.SharedPreferences.Editor
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.DisplayMetrics
|
import android.util.DisplayMetrics
|
||||||
import android.view.KeyEvent
|
import android.view.*
|
||||||
import android.view.MotionEvent
|
|
||||||
import android.view.View
|
|
||||||
import android.view.WindowManager
|
|
||||||
import android.widget.TextView
|
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.view.MotionEventCompat
|
import androidx.core.view.GestureDetectorCompat
|
||||||
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
|
||||||
|
import kotlin.math.abs
|
||||||
|
|
||||||
|
// App Launch Actions
|
||||||
|
var upApp = ""
|
||||||
|
var downApp = ""
|
||||||
|
var rightApp = ""
|
||||||
|
var leftApp = ""
|
||||||
|
var volumeUpApp = ""
|
||||||
|
var volumeDownApp = ""
|
||||||
|
|
||||||
|
class MainActivity : AppCompatActivity(),
|
||||||
|
GestureDetector.OnGestureListener,
|
||||||
|
GestureDetector.OnDoubleTapListener {
|
||||||
|
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
private lateinit var mDetector: GestureDetectorCompat
|
||||||
|
|
||||||
// get device dimensions
|
// get device dimensions
|
||||||
val displayMetrics = DisplayMetrics()
|
val displayMetrics = DisplayMetrics()
|
||||||
|
|
||||||
private fun getIntent(packageName: String) : Intent? {
|
private fun getIntent(packageName: String): Intent? {
|
||||||
val pm = applicationContext.packageManager
|
val pm = applicationContext.packageManager
|
||||||
val intent:Intent? = pm.getLaunchIntentForPackage(packageName)
|
val intent: Intent? = pm.getLaunchIntentForPackage(packageName)
|
||||||
intent?.addCategory(Intent.CATEGORY_LAUNCHER)
|
intent?.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||||
return intent;
|
return intent
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun launchApp(packageName: String, fallback: String = "") {
|
private fun launchApp(packageName: String, fallback: String = "") {
|
||||||
val intent1 = getIntent(packageName)
|
val intent1 = getIntent(packageName)
|
||||||
|
|
||||||
if(intent1!=null){
|
if (intent1 != null) {
|
||||||
applicationContext.startActivity(intent1)
|
applicationContext.startActivity(intent1)
|
||||||
overridePendingTransition(0,0)
|
overridePendingTransition(0, 0)
|
||||||
} else {
|
} else {
|
||||||
val intent2 = getIntent(fallback)
|
val intent2 = getIntent(fallback)
|
||||||
|
|
||||||
if(intent2!=null){
|
if (intent2 != null) {
|
||||||
applicationContext.startActivity(intent2)
|
applicationContext.startActivity(intent2)
|
||||||
overridePendingTransition(0,0)
|
overridePendingTransition(0, 0)
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this, "Package '$packageName' not found.", Toast.LENGTH_SHORT).show()
|
Toast.makeText(
|
||||||
|
this,
|
||||||
|
"Package '$packageName' not found. Change your Settings.",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun launchInstagram(v: View){ launchApp("com.instagram.android") }
|
fun launchCalendar(v: View) {
|
||||||
fun launchWhatsapp(v: View){ launchApp("com.whatsapp") }
|
launchApp("com.google.android.calendar", "com.samsung.android.calendar")
|
||||||
|
}
|
||||||
|
|
||||||
fun launchFinder(v: View){ launchApp("com.samsung.android.app.galaxyfinder") }
|
fun launchClock(v: View) {
|
||||||
fun launchMail(v: View){ launchApp("com.samsung.android.email.provider", "com.google.android.gm") }
|
launchApp("com.sec.android.app.clockpackage")
|
||||||
fun launchCalendar(v: View){ launchApp("com.google.android.calendar", "com.samsung.android.calendar") }
|
}
|
||||||
fun launchClock(v: View){ launchApp("com.sec.android.app.clockpackage") }
|
|
||||||
fun launchBrowser(v: View){ launchApp("org.mozilla.firefox", "com.sec.android.app.sbrowser") }
|
|
||||||
|
|
||||||
fun launchUpApp() { launchBrowser(container) }
|
fun launchUpApp() {
|
||||||
fun launchDownApp() { launchFinder(container) }
|
launchApp(upApp)
|
||||||
fun lauchLeftApp() { launchCalendar(container) }
|
}
|
||||||
fun lauchRightApp() { launchMail(container) }
|
|
||||||
|
fun launchDownApp() {
|
||||||
|
launchApp(downApp)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun lauchLeftApp() {
|
||||||
|
launchApp(leftApp)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun lauchRightApp() {
|
||||||
|
launchApp(rightApp)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun lauchVolumeUpApp() {
|
||||||
|
launchApp(volumeUpApp)
|
||||||
|
}
|
||||||
|
|
||||||
fun lauchVolumeUpApp() { }
|
|
||||||
fun lauchVolumeDownApp() {
|
fun lauchVolumeDownApp() {
|
||||||
val intent = Intent(this, ChooseActivity::class.java)
|
launchApp(volumeDownApp)
|
||||||
startActivity(intent)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overrides
|
/* Overrides */
|
||||||
|
|
||||||
var touchX : Float = 0F
|
|
||||||
var touchY : Float = 0F
|
|
||||||
|
|
||||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
|
||||||
|
|
||||||
return when (MotionEventCompat.getActionMasked(event)) {
|
|
||||||
MotionEvent.ACTION_DOWN -> {
|
|
||||||
touchX = event.x
|
|
||||||
touchY = event.y
|
|
||||||
true
|
|
||||||
}
|
|
||||||
MotionEvent.ACTION_MOVE -> {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
MotionEvent.ACTION_UP -> {
|
|
||||||
windowManager.defaultDisplay.getMetrics(displayMetrics)
|
|
||||||
|
|
||||||
val width = displayMetrics.widthPixels
|
|
||||||
val height = displayMetrics.heightPixels
|
|
||||||
|
|
||||||
val diffX = touchX - event.x
|
|
||||||
val diffY = touchY - event.y
|
|
||||||
|
|
||||||
val strictness = 4 // of direction
|
|
||||||
|
|
||||||
// Decide which one to open
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
MotionEvent.ACTION_CANCEL -> {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
MotionEvent.ACTION_OUTSIDE -> {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
else -> super.onTouchEvent(event)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) { return true }
|
if (keyCode == KeyEvent.KEYCODE_BACK) return true
|
||||||
else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) lauchVolumeUpApp()
|
else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) lauchVolumeUpApp()
|
||||||
else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) lauchVolumeDownApp()
|
else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) lauchVolumeDownApp()
|
||||||
return true
|
return true
|
||||||
|
@ -139,15 +109,27 @@ class MainActivity : AppCompatActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
// Preferences
|
||||||
|
val sharedPref = this.getSharedPreferences(
|
||||||
|
getString(R.string.preference_file_key), Context.MODE_PRIVATE)
|
||||||
|
|
||||||
|
// First Startup
|
||||||
|
if (!sharedPref.getBoolean("startedBefore", false))
|
||||||
|
resetSettings(sharedPref)
|
||||||
|
|
||||||
|
loadSettings(sharedPref)
|
||||||
|
|
||||||
|
// Flags
|
||||||
|
|
||||||
|
window.setFlags(
|
||||||
|
WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||||
|
WindowManager.LayoutParams.FLAG_FULLSCREEN
|
||||||
|
)
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
|
|
||||||
val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
|
val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
|
||||||
val timeFormat = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
|
val timeFormat = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
|
||||||
|
|
||||||
//dateFormat.timeZone = TimeZone.getTimeZone("GMT")
|
|
||||||
//timeFormat.timeZone = TimeZone.getTimeZone("GMT")
|
|
||||||
|
|
||||||
fixedRateTimer("timer", false, 0L, 1000) {
|
fixedRateTimer("timer", false, 0L, 1000) {
|
||||||
this@MainActivity.runOnUiThread {
|
this@MainActivity.runOnUiThread {
|
||||||
dateView.text = dateFormat.format(Date())
|
dateView.text = dateFormat.format(Date())
|
||||||
|
@ -157,5 +139,85 @@ class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
|
mDetector = GestureDetectorCompat(this, this)
|
||||||
|
mDetector.setOnDoubleTapListener(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||||
|
return if (mDetector.onTouchEvent(event)) {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
super.onTouchEvent(event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDown(event: MotionEvent): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFling(
|
||||||
|
e1: MotionEvent,
|
||||||
|
e2: MotionEvent,
|
||||||
|
differenceX: Float,
|
||||||
|
differenceY: Float
|
||||||
|
): Boolean {
|
||||||
|
|
||||||
|
windowManager.defaultDisplay.getMetrics(displayMetrics)
|
||||||
|
val width = displayMetrics.widthPixels
|
||||||
|
val height = displayMetrics.heightPixels
|
||||||
|
|
||||||
|
val diffX = e1.x - e2.x
|
||||||
|
val diffY = e1.y - e2.y
|
||||||
|
|
||||||
|
val strictness = 4 // of direction
|
||||||
|
|
||||||
|
/* Decide for an action */
|
||||||
|
|
||||||
|
if (diffY > height / 8 && abs(diffY) > strictness * abs(diffX)) launchUpApp()
|
||||||
|
// Only open if the swipe was not from the phone edge
|
||||||
|
else if (diffY < -height / 8 && abs(diffY) > strictness * abs(diffX) && e1.y > 100) launchDownApp()
|
||||||
|
else if (diffX > width / 4 && abs(diffX) > strictness * abs(diffY)) lauchLeftApp()
|
||||||
|
else if (diffX < -width / 4 && abs(diffX) > strictness * abs(diffY)) lauchRightApp()
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open Settings
|
||||||
|
override fun onLongPress(event: MotionEvent) {
|
||||||
|
startActivity(Intent(this, SettingsActivity::class.java))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onScroll(
|
||||||
|
e1: MotionEvent,
|
||||||
|
e2: MotionEvent,
|
||||||
|
diffX: Float,
|
||||||
|
diffY: Float
|
||||||
|
): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onShowPress(event: MotionEvent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSingleTapUp(event: MotionEvent): Boolean {
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDoubleTap(event: MotionEvent): Boolean {
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDoubleTapEvent(event: MotionEvent): Boolean {
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSingleTapConfirmed(event: MotionEvent): Boolean {
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
27
app/src/main/java/com/finnmglas/launcher/Settings.kt
Normal file
27
app/src/main/java/com/finnmglas/launcher/Settings.kt
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
package com.finnmglas.launcher
|
||||||
|
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
|
||||||
|
fun resetSettings(sharedPref : SharedPreferences){
|
||||||
|
val editor: SharedPreferences.Editor = sharedPref.edit()
|
||||||
|
|
||||||
|
// Set Defaults
|
||||||
|
editor.putString("action_upApp", "org.mozilla.firefox")
|
||||||
|
editor.putString("action_downApp", "com.samsung.android.app.galaxyfinder")
|
||||||
|
editor.putString("action_rightApp", "com.samsung.android.email.provider")
|
||||||
|
editor.putString("action_leftApp", "com.google.android.calendar")
|
||||||
|
editor.putString("action_volumeUpApp", "com.whatsapp")
|
||||||
|
editor.putString("action_volumeDownApp", "com.sec.android.app.popupcalculator")
|
||||||
|
|
||||||
|
editor.putBoolean("startedBefore", true) // never run this again
|
||||||
|
editor.apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun loadSettings(sharedPref : SharedPreferences){
|
||||||
|
upApp = sharedPref.getString("action_upApp", "").toString()
|
||||||
|
downApp = sharedPref.getString("action_downApp", "").toString()
|
||||||
|
rightApp = sharedPref.getString("action_rightApp", "").toString()
|
||||||
|
leftApp = sharedPref.getString("action_leftApp", "").toString()
|
||||||
|
volumeUpApp = sharedPref.getString("action_volumeUpApp", "").toString()
|
||||||
|
volumeDownApp = sharedPref.getString("action_volumeDownApp", "").toString()
|
||||||
|
}
|
104
app/src/main/java/com/finnmglas/launcher/SettingsActivity.kt
Normal file
104
app/src/main/java/com/finnmglas/launcher/SettingsActivity.kt
Normal file
|
@ -0,0 +1,104 @@
|
||||||
|
package com.finnmglas.launcher
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.app.AlertDialog
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.DialogInterface
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.View
|
||||||
|
import android.view.WindowManager
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
|
||||||
|
|
||||||
|
class SettingsActivity : AppCompatActivity() {
|
||||||
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
|
if(requestCode == 5000)
|
||||||
|
{
|
||||||
|
val value = data?.getStringExtra("value")
|
||||||
|
val forApp = data?.getStringExtra("forApp") ?: return
|
||||||
|
|
||||||
|
// Save the new App to Preferences
|
||||||
|
val sharedPref = this.getSharedPreferences(
|
||||||
|
getString(R.string.preference_file_key), Context.MODE_PRIVATE)
|
||||||
|
|
||||||
|
val editor :SharedPreferences.Editor = sharedPref.edit()
|
||||||
|
editor.putString("action_$forApp", value.toString())
|
||||||
|
editor.apply()
|
||||||
|
|
||||||
|
// Update running App
|
||||||
|
if (forApp == "downApp") downApp = value.toString()
|
||||||
|
else if (forApp == "upApp") upApp = value.toString()
|
||||||
|
else if (forApp == "leftApp") leftApp = value.toString()
|
||||||
|
else if (forApp == "rightApp") rightApp = value.toString()
|
||||||
|
else if (forApp == "volumeDownApp") volumeDownApp = value.toString()
|
||||||
|
else if (forApp == "volumeUpApp") volumeUpApp = value.toString()
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun chooseDownApp(view: View) {chooseApp("downApp")}
|
||||||
|
fun chooseUpApp(view: View) {chooseApp("upApp")}
|
||||||
|
fun chooseLeftApp(view: View) {chooseApp("leftApp")}
|
||||||
|
fun chooseRightApp(view: View) {chooseApp("rightApp")}
|
||||||
|
fun chooseVolumeDownApp(view: View) {chooseApp("volumeDownApp")}
|
||||||
|
fun chooseVolumeUpApp(view: View) {chooseApp("volumeUpApp")}
|
||||||
|
|
||||||
|
fun chooseApp(forAction :String) {
|
||||||
|
val intent = Intent(this, ChooseActivity::class.java)
|
||||||
|
intent.putExtra("action", "pick") // why choose an app
|
||||||
|
intent.putExtra("forApp", forAction) // which app we choose
|
||||||
|
startActivityForResult(intent, 5000)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun openNewTabWindow(urls: String, context : Context) {
|
||||||
|
val uris = Uri.parse(urls)
|
||||||
|
val intents = Intent(Intent.ACTION_VIEW, uris)
|
||||||
|
val b = Bundle()
|
||||||
|
b.putBoolean("new_window", true)
|
||||||
|
intents.putExtras(b)
|
||||||
|
context.startActivity(intents)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun openFinnWebsite(view: View) {
|
||||||
|
openNewTabWindow("https://www.finnmglas.com/", this)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun openGithubRepo(view: View) {
|
||||||
|
openNewTabWindow("https://github.com/finnmglas/Launcher", this)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun backHome(view: View) {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show a dialog prompting for confirmation
|
||||||
|
fun resetSettingsClick(view: View) {
|
||||||
|
AlertDialog.Builder(this)
|
||||||
|
.setTitle("Reset Settings")
|
||||||
|
.setMessage("This will discard all your App Choices. Sure you want to continue?")
|
||||||
|
.setPositiveButton(android.R.string.yes,
|
||||||
|
DialogInterface.OnClickListener { dialog, which ->
|
||||||
|
resetSettings(this.getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE))
|
||||||
|
finish()
|
||||||
|
})
|
||||||
|
.setNegativeButton(android.R.string.no, null)
|
||||||
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n") // I do not care
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||||
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
|
|
||||||
|
setContentView(R.layout.activity_settings)
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,19 +7,33 @@
|
||||||
android:background="?attr/colorPrimaryDark"
|
android:background="?attr/colorPrimaryDark"
|
||||||
tools:context=".ChooseActivity">
|
tools:context=".ChooseActivity">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/heading"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Choose App"
|
||||||
|
android:textColor="#cccccc"
|
||||||
|
android:textSize="36sp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintVertical_bias="0.100000024" />
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
|
android:id="@+id/scrollView3"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="16dp"
|
||||||
android:layout_marginLeft="16dp"
|
android:layout_marginLeft="16dp"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="86dp"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
android:layout_marginRight="16dp"
|
android:layout_marginRight="16dp"
|
||||||
android:layout_marginBottom="16dp"
|
android:layout_marginBottom="128dp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent">
|
app:layout_constraintTop_toTopOf="@id/heading">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/apps_list"
|
android:id="@+id/apps_list"
|
||||||
|
@ -28,4 +42,15 @@
|
||||||
android:orientation="vertical" />
|
android:orientation="vertical" />
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:onClick="backHome"
|
||||||
|
android:text="Back to Settings"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/scrollView3" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -5,6 +5,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="?attr/colorPrimaryDark"
|
android:background="?attr/colorPrimaryDark"
|
||||||
|
android:longClickable="false"
|
||||||
tools:context=".MainActivity">
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
@ -13,7 +14,7 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="left|center_vertical"
|
android:gravity="left|center_vertical"
|
||||||
android:onClick="launchCalendar"
|
android:onClick="launchCalendar"
|
||||||
android:textColor="#fff"
|
android:textColor="#ccc"
|
||||||
android:textSize="30sp"
|
android:textSize="30sp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
@ -27,7 +28,7 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="left|center_vertical"
|
android:gravity="left|center_vertical"
|
||||||
android:onClick="launchClock"
|
android:onClick="launchClock"
|
||||||
android:textColor="#fff"
|
android:textColor="#ccc"
|
||||||
android:textSize="18sp"
|
android:textSize="18sp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
|
254
app/src/main/res/layout/activity_settings.xml
Normal file
254
app/src/main/res/layout/activity_settings.xml
Normal file
|
@ -0,0 +1,254 @@
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="?attr/colorPrimaryDark"
|
||||||
|
tools:context=".SettingsActivity">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/heading"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Settings"
|
||||||
|
android:textColor="#cccccc"
|
||||||
|
android:textSize="36sp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintVertical_bias="0.100000024" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/sub_head_1"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Actions"
|
||||||
|
android:textColor="#999"
|
||||||
|
android:textSize="18sp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintHorizontal_bias=".1"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintVertical_bias="0.189" />
|
||||||
|
|
||||||
|
<TableLayout
|
||||||
|
android:id="@+id/actionschooser"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_horizontal|center_vertical"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintHorizontal_bias="0.5"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="@id/sub_head_1"
|
||||||
|
app:layout_constraintVertical_bias="0.120000005">
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_up"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Swipe Up"
|
||||||
|
android:textColor="#ccc"
|
||||||
|
android:textSize="24sp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btn_choose_up"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:onClick="chooseUpApp"
|
||||||
|
android:text="Choose App" />
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_down"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Swipe Down"
|
||||||
|
android:textColor="#ccc"
|
||||||
|
android:textSize="24sp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btn_choose_down"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:onClick="chooseDownApp"
|
||||||
|
android:text="Choose App" />
|
||||||
|
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_left"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Swipe Left"
|
||||||
|
android:textColor="#ccc"
|
||||||
|
android:textSize="24sp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btn_choose_left"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:onClick="chooseLeftApp"
|
||||||
|
android:text="Choose App" />
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_right"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Swipe Right"
|
||||||
|
android:textColor="#ccc"
|
||||||
|
android:textSize="24sp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btn_choose_right"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:onClick="chooseRightApp"
|
||||||
|
android:text="Choose App" />
|
||||||
|
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_vol_up"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Volume Up"
|
||||||
|
android:textColor="#ccc"
|
||||||
|
android:textSize="24sp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btn_choose_volume_up"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:onClick="chooseVolumeUpApp"
|
||||||
|
android:text="Choose App" />
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_vol_down"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Volume Down "
|
||||||
|
android:textColor="#ccc"
|
||||||
|
android:textSize="24sp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btn_choose_volume_down"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:onClick="chooseVolumeDownApp"
|
||||||
|
android:text="Choose App" />
|
||||||
|
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
</TableLayout>
|
||||||
|
|
||||||
|
<TableLayout
|
||||||
|
android:id="@+id/buttons"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/actionschooser">
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button2"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:onClick="resetSettingsClick"
|
||||||
|
android:text="Reset" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button3"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:onClick="backHome"
|
||||||
|
android:text="Back Home" />
|
||||||
|
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
</TableLayout>
|
||||||
|
|
||||||
|
<TableLayout
|
||||||
|
android:id="@+id/about_footer"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/actionschooser"
|
||||||
|
app:layout_constraintVertical_bias="0.9">
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="By "
|
||||||
|
android:textColor="#999"
|
||||||
|
android:textSize="18sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:onClick="openFinnWebsite"
|
||||||
|
android:text="Finn M Glas"
|
||||||
|
android:textColor="?attr/colorAccent"
|
||||||
|
android:textSize="18sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text=" | "
|
||||||
|
android:textColor="#999"
|
||||||
|
android:textSize="18sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:onClick="openGithubRepo"
|
||||||
|
android:text="Open Source"
|
||||||
|
android:textColor="?attr/colorAccent"
|
||||||
|
android:textSize="18sp" />
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
</TableLayout>
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -1,3 +1,4 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Launcher</string>
|
<string name="app_name">Launcher</string>
|
||||||
|
<string name ="preference_file_key">V3RYR4ND0MK3YCR4P</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Add table
Reference in a new issue