mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 06:21:31 +01:00
Clean up unnecessary code and files
Also move the code to the right places (Functions.kt created)
This commit is contained in:
parent
9f48a13d33
commit
49baed4d65
8 changed files with 81 additions and 216 deletions
Binary file not shown.
Binary file not shown.
|
@ -1,33 +0,0 @@
|
|||
package com.finnmglas.launcher;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class FontAwesome extends androidx.appcompat.widget.AppCompatTextView {
|
||||
|
||||
public FontAwesome(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
init();
|
||||
}
|
||||
|
||||
public FontAwesome(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public FontAwesome(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
|
||||
//Font name should not contain "/".
|
||||
Typeface tf = Typeface.createFromAsset(getContext().getAssets(),
|
||||
"fonts/fa-solid-900.ttf");
|
||||
setTypeface(tf);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package com.finnmglas.launcher;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
public class FontAwesomeBrand extends androidx.appcompat.widget.AppCompatTextView {
|
||||
|
||||
public FontAwesomeBrand(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
init();
|
||||
}
|
||||
|
||||
public FontAwesomeBrand(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public FontAwesomeBrand(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
|
||||
//Font name should not contain "/".
|
||||
Typeface tf = Typeface.createFromAsset(getContext().getAssets(),
|
||||
"fonts/fa-brand-400.ttf");
|
||||
setTypeface(tf);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,14 +1,16 @@
|
|||
package com.finnmglas.launcher
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.provider.Settings
|
||||
import androidx.core.content.ContextCompat.startActivity
|
||||
import android.widget.Toast
|
||||
|
||||
val none_msg = "None found"
|
||||
/** Activity related */
|
||||
|
||||
fun isInstalled(uri: String, context: Context): Boolean {
|
||||
try {
|
||||
|
@ -19,6 +21,39 @@ fun isInstalled(uri: String, context: Context): Boolean {
|
|||
return false
|
||||
}
|
||||
|
||||
private fun getIntent(packageName: String, context: Context): Intent? {
|
||||
val intent: Intent? = context.packageManager.getLaunchIntentForPackage(packageName)
|
||||
intent?.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
return intent
|
||||
}
|
||||
|
||||
fun launchApp(packageName: String, context: Context) {
|
||||
val intent1 = getIntent(packageName, context)
|
||||
|
||||
if (intent1 != null) {
|
||||
context.startActivity(intent1)
|
||||
//overridePendingTransition(0, 0)
|
||||
} else {
|
||||
if (isInstalled(packageName, context)){
|
||||
|
||||
AlertDialog.Builder(context)
|
||||
.setTitle("Can't open app")
|
||||
.setMessage("Want to change its settings ('add it to the apps screen')?")
|
||||
.setPositiveButton(android.R.string.yes,
|
||||
DialogInterface.OnClickListener { dialog, which ->
|
||||
openAppSettings(packageName, context)
|
||||
})
|
||||
.setNegativeButton(android.R.string.no, null)
|
||||
.setIcon(android.R.drawable.ic_dialog_info)
|
||||
.show()
|
||||
} else {
|
||||
Toast.makeText( context, "Open settings to choose an app for this action", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Settings related */
|
||||
|
||||
fun openAppSettings(pkg :String, context:Context){
|
||||
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
||||
intent.data = Uri.parse("package:$pkg")
|
||||
|
@ -37,7 +72,6 @@ fun loadSettings(sharedPref : SharedPreferences){
|
|||
clockApp = sharedPref.getString("action_clockApp", "").toString()
|
||||
}
|
||||
|
||||
// Default settings are set here.
|
||||
fun resetSettings(sharedPref : SharedPreferences, context: Context) : MutableList<String>{
|
||||
|
||||
val defaultList :MutableList<String> = mutableListOf<String>()
|
||||
|
@ -86,7 +120,7 @@ fun pickDefaultUpApp(context :Context) : Pair<String, String>{
|
|||
else if(isInstalled("com.sec.android.app.sbrowser", context))
|
||||
return Pair("Samsung Internet", "com.sec.android.app.sbrowser")
|
||||
else
|
||||
return Pair("None, as we were unable to find one.", "")
|
||||
return Pair(context.getString(R.string.none_found), "")
|
||||
}
|
||||
|
||||
// Default downApps are Internal Search Apps
|
||||
|
@ -96,7 +130,7 @@ fun pickDefaultDownApp(context :Context) : Pair<String, String>{
|
|||
else if(isInstalled("com.prometheusinteractive.voice_launcher", context))
|
||||
return Pair("VoiceSearch", "com.prometheusinteractive.voice_launcher")
|
||||
else
|
||||
return Pair(none_msg, "")
|
||||
return Pair(context.getString(R.string.none_found), "")
|
||||
}
|
||||
|
||||
// Default rightApps are Mailing Applications
|
||||
|
@ -108,7 +142,7 @@ fun pickDefaultRightApp(context :Context) : Pair<String, String>{
|
|||
else if(isInstalled("com.google.android.gm", context))
|
||||
return Pair("Google Mail", "com.google.android.gm")
|
||||
else
|
||||
return Pair(none_msg, "")
|
||||
return Pair(context.getString(R.string.none_found), "")
|
||||
}
|
||||
|
||||
// Default leftApps are Calendar Applications
|
||||
|
@ -118,7 +152,7 @@ fun pickDefaultLeftApp(context :Context) : Pair<String, String>{
|
|||
else if(isInstalled("com.samsung.android.calendar", context))
|
||||
return Pair("Samsung Calendar", "com.samsung.android.calendar")
|
||||
else
|
||||
return Pair(none_msg, "")
|
||||
return Pair(context.getString(R.string.none_found), "")
|
||||
}
|
||||
|
||||
// Default volumeUpApps are Messengers
|
||||
|
@ -138,7 +172,7 @@ fun pickDefaultVolumeUpApp(context: Context) : Pair<String, String>{
|
|||
else if(isInstalled("com.samsung.android.messaging", context))
|
||||
return Pair("Samsung SMS", "com.samsung.android.messaging")
|
||||
else
|
||||
return Pair(none_msg, "")
|
||||
return Pair(context.getString(R.string.none_found), "")
|
||||
}
|
||||
|
||||
// Default volumeDownApps are Utilities
|
||||
|
@ -150,5 +184,5 @@ fun pickDefaultVolumeDownApp(context: Context) : Pair<String, String>{
|
|||
else if(isInstalled("com.sec.android.app.popupcalculator", context))
|
||||
return Pair("Calculator", "com.sec.android.app.popupcalculator")
|
||||
else
|
||||
return Pair(none_msg, "")
|
||||
return Pair(context.getString(R.string.none_found), "")
|
||||
}
|
|
@ -1,10 +1,6 @@
|
|||
package com.finnmglas.launcher
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.AlertDialog
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.DisplayMetrics
|
||||
|
@ -18,7 +14,7 @@ import java.util.*
|
|||
import kotlin.concurrent.fixedRateTimer
|
||||
import kotlin.math.abs
|
||||
|
||||
// App Launch Actions
|
||||
/** Variables for all of the app */
|
||||
var upApp = ""
|
||||
var downApp = ""
|
||||
var rightApp = ""
|
||||
|
@ -30,90 +26,16 @@ var calendarApp = ""
|
|||
var clockApp = ""
|
||||
|
||||
class MainActivity : AppCompatActivity(),
|
||||
GestureDetector.OnGestureListener,
|
||||
GestureDetector.OnDoubleTapListener {
|
||||
GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
|
||||
|
||||
/** Variables for this activity */
|
||||
private lateinit var mDetector: GestureDetectorCompat
|
||||
|
||||
// get device dimensions
|
||||
private val displayMetrics = DisplayMetrics()
|
||||
private var clockTimer = Timer();
|
||||
|
||||
private fun getIntent(packageName: String): Intent? {
|
||||
val intent: Intent? = packageManager.getLaunchIntentForPackage(packageName)
|
||||
intent?.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
return intent
|
||||
}
|
||||
|
||||
private fun launchApp(packageName: String) {
|
||||
val intent1 = getIntent(packageName)
|
||||
|
||||
if (intent1 != null) {
|
||||
applicationContext.startActivity(intent1)
|
||||
overridePendingTransition(0, 0)
|
||||
} else {
|
||||
if (isInstalled(packageName, this)){
|
||||
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle("Can't open app")
|
||||
.setMessage("Want to change its settings ('add it to the apps screen')?")
|
||||
.setPositiveButton(android.R.string.yes,
|
||||
DialogInterface.OnClickListener { dialog, which ->
|
||||
openAppSettings(packageName, this)
|
||||
})
|
||||
.setNegativeButton(android.R.string.no, null)
|
||||
.setIcon(android.R.drawable.ic_dialog_info)
|
||||
.show()
|
||||
} else {
|
||||
Toast.makeText(
|
||||
this,
|
||||
"Open settings to choose an app for this action",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun launchCalendar(v: View) {
|
||||
launchApp(calendarApp)
|
||||
}
|
||||
|
||||
fun launchClock(v: View) {
|
||||
launchApp(clockApp)
|
||||
}
|
||||
|
||||
fun launchUpApp() {
|
||||
launchApp(upApp)
|
||||
}
|
||||
|
||||
fun launchDownApp() {
|
||||
launchApp(downApp)
|
||||
}
|
||||
|
||||
fun lauchLeftApp() {
|
||||
launchApp(leftApp)
|
||||
}
|
||||
|
||||
fun lauchRightApp() {
|
||||
launchApp(rightApp)
|
||||
}
|
||||
|
||||
fun lauchVolumeUpApp() {
|
||||
launchApp(volumeUpApp)
|
||||
}
|
||||
|
||||
fun lauchVolumeDownApp() {
|
||||
launchApp(volumeDownApp)
|
||||
}
|
||||
|
||||
/* Overrides */
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) return true
|
||||
else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) lauchVolumeUpApp()
|
||||
else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) lauchVolumeDownApp()
|
||||
return true
|
||||
}
|
||||
|
||||
/** Activity Lifecycle functions */
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
|
@ -135,7 +57,6 @@ GestureDetector.OnDoubleTapListener {
|
|||
setContentView(R.layout.activity_main)
|
||||
}
|
||||
|
||||
// After the app is created or when it restarts (inactivity) - Fixes Issue #9
|
||||
override fun onStart(){
|
||||
super.onStart()
|
||||
|
||||
|
@ -148,7 +69,7 @@ GestureDetector.OnDoubleTapListener {
|
|||
val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
|
||||
val timeFormat = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
|
||||
|
||||
fixedRateTimer("timer", false, 0L, 1000) {
|
||||
clockTimer = fixedRateTimer("timer", true, 0L, 1000) {
|
||||
this@MainActivity.runOnUiThread {
|
||||
dateView.text = dateFormat.format(Date())
|
||||
timeView.text = timeFormat.format(Date())
|
||||
|
@ -159,24 +80,19 @@ GestureDetector.OnDoubleTapListener {
|
|||
mDetector.setOnDoubleTapListener(this)
|
||||
}
|
||||
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||
return if (mDetector.onTouchEvent(event)) {
|
||||
true
|
||||
} else {
|
||||
super.onTouchEvent(event)
|
||||
}
|
||||
}
|
||||
/** Touch- and Key-related functions to start activities */
|
||||
|
||||
override fun onDown(event: MotionEvent): Boolean {
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) return true
|
||||
else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) launchApp(volumeUpApp, this)
|
||||
else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) launchApp(volumeDownApp, this)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onFling(
|
||||
e1: MotionEvent,
|
||||
e2: MotionEvent,
|
||||
differenceX: Float,
|
||||
differenceY: Float
|
||||
): Boolean {
|
||||
fun dateViewOnTouch(v: View) { launchApp(calendarApp, this) }
|
||||
fun timeViewOnTouch(v: View) { launchApp(clockApp, this) }
|
||||
|
||||
override fun onFling(e1: MotionEvent, e2: MotionEvent, dX: Float, dY: Float): Boolean {
|
||||
|
||||
windowManager.defaultDisplay.getMetrics(displayMetrics)
|
||||
val width = displayMetrics.widthPixels
|
||||
|
@ -185,55 +101,33 @@ GestureDetector.OnDoubleTapListener {
|
|||
val diffX = e1.x - e2.x
|
||||
val diffY = e1.y - e2.y
|
||||
|
||||
val strictness = 4 // of direction
|
||||
val strictness = 4 // how distinguished the swipe has to be to be accepted
|
||||
|
||||
/* 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()
|
||||
// Only open if the swipe was not from the phones top edge
|
||||
if (diffY < -height / 8 && abs(diffY) > strictness * abs(diffX) && e1.y > 100) launchApp(downApp, this)
|
||||
else if (diffY > height / 8 && abs(diffY) > strictness * abs(diffX)) launchApp(upApp, this)
|
||||
else if (diffX > width / 4 && abs(diffX) > strictness * abs(diffY)) launchApp(leftApp, this)
|
||||
else if (diffX < -width / 4 && abs(diffX) > strictness * abs(diffY)) launchApp(rightApp, this)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// Open Settings
|
||||
// Open Settings Activity
|
||||
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
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||
return if (mDetector.onTouchEvent(event)) { true } else { super.onTouchEvent(event) }
|
||||
}
|
||||
|
||||
/* TODO: Remove those. For now they are necessary
|
||||
* because this inherits from GestureDetector.OnGestureListener */
|
||||
override fun onDoubleTap(event: MotionEvent): Boolean { return true }
|
||||
override fun onDoubleTapEvent(event: MotionEvent): Boolean { return true }
|
||||
override fun onDown(event: MotionEvent): Boolean { return true }
|
||||
override fun onScroll(e1: MotionEvent, e2: MotionEvent, dX: Float, dY: Float): Boolean { return true }
|
||||
override fun onShowPress(event: MotionEvent) {}
|
||||
override fun onSingleTapUp(event: MotionEvent): Boolean { return true }
|
||||
override fun onSingleTapConfirmed(event: MotionEvent): Boolean { return true }
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="left|center_vertical"
|
||||
android:onClick="launchCalendar"
|
||||
android:onClick="dateViewOnTouch"
|
||||
android:textColor="#ccc"
|
||||
android:textSize="30sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
|
@ -27,7 +27,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="left|center_vertical"
|
||||
android:onClick="launchClock"
|
||||
android:onClick="timeViewOnTouch"
|
||||
android:textColor="#ccc"
|
||||
android:textSize="18sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<resources>
|
||||
<string name="app_name">Launcher</string>
|
||||
<string name="preference_file_key">V3RYR4ND0MK3YCR4P</string>
|
||||
|
||||
<string name="none_found">None found</string>
|
||||
</resources>
|
||||
|
|
Loading…
Add table
Reference in a new issue