feature: set launcher as home screen

This commit is contained in:
Josia Pietsch 2024-08-02 02:44:35 +02:00
parent 977c4618ef
commit 3935afa40d
Signed by: jrpie
GPG key ID: E70B571D66986A2D
7 changed files with 49 additions and 2 deletions

View file

@ -8,6 +8,11 @@
tools:ignore="QueryAllPackagesPermission" />
<queries>
<intent>
<category android:name="android.intent.category.HOME"/>
</intent>
</queries>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
@ -40,6 +45,7 @@
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity">
</activity>
</application>
</manifest>

View file

@ -2,10 +2,12 @@ package de.jrpie.android.launcher
import android.app.Activity
import android.app.AlertDialog
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import android.graphics.BlendMode
import android.graphics.BlendModeColorFilter
import android.graphics.ColorMatrix
@ -19,6 +21,7 @@ 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
@ -101,6 +104,20 @@ fun getPreferences(context: Context): SharedPreferences{
)
}
fun setDefaultHomeScreen(context: Context, checkDefault: Boolean = false) {
if(checkDefault) {
val testIntent = Intent(Intent.ACTION_MAIN)
testIntent.addCategory(Intent.CATEGORY_HOME)
val defaultHome = testIntent.resolveActivity(context.packageManager)?.packageName
if(defaultHome == context.packageName){
// Launcher is already the default home app
return
}
}
val intent = Intent(Settings.ACTION_HOME_SETTINGS)
context.startActivity(intent)
}
/* Activity related */
fun isInstalled(uri: String, context: Context): Boolean {

View file

@ -7,9 +7,8 @@ import android.view.ViewGroup
import androidx.fragment.app.Fragment
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.databinding.ListAppsBinding
import de.jrpie.android.launcher.UIObject
import de.jrpie.android.launcher.databinding.ListAppsBinding
import de.jrpie.android.launcher.getPreferences
import de.jrpie.android.launcher.list.ListActivity
import de.jrpie.android.launcher.list.forGesture

View file

@ -31,6 +31,7 @@ import de.jrpie.android.launcher.setWindowFlags
import de.jrpie.android.launcher.settings.intendedSettingsPause
import de.jrpie.android.launcher.vibrantColor
import de.jrpie.android.launcher.databinding.SettingsLauncherBinding
import de.jrpie.android.launcher.setDefaultHomeScreen
/**
@ -57,6 +58,7 @@ class SettingsFragmentLauncher : Fragment(), UIObject {
override fun applyTheme() {
setButtonColor(binding.settingsLauncherButtonChooseHomescreen, vibrantColor)
setSwitchColor(binding.settingsLauncherSwitchScreenTimeout, vibrantColor)
setSwitchColor(binding.settingsLauncherSwitchScreenFull, vibrantColor)
setSwitchColor(binding.settingsLauncherSwitchAutoLaunch, vibrantColor)
@ -83,6 +85,10 @@ class SettingsFragmentLauncher : Fragment(), UIObject {
}
}
binding.settingsLauncherButtonChooseHomescreen.setOnClickListener {
setDefaultHomeScreen(requireContext(), checkDefault = false)
}
binding.settingsLauncherButtonChooseWallpaper.setOnClickListener {
// https://github.com/LineageOS/android_packages_apps_Trebuchet/blob/6caab89b21b2b91f0a439e1fd8c4510dcb255819/src/com/android/launcher3/views/OptionsPopupView.java#L271
val intent = Intent(Intent.ACTION_SET_WALLPAPER)

View file

@ -54,6 +54,8 @@ class TutorialFragmentFinish : Fragment(), UIObject {
.apply()
}
}
context?.let { setDefaultHomeScreen(it, checkDefault = true) }
activity?.finish()
}
}

View file

@ -16,6 +16,21 @@
android:paddingRight="32sp"
tools:context=".settings.meta.SettingsFragmentMeta">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16sp"
android:orientation="horizontal">
<Button
android:id="@+id/settings_launcher_button_choose_homescreen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/settings_launcher_choose_homescreen"
android:textAllCaps="false" />
</LinearLayout>
<LinearLayout
android:id="@+id/settings_launcher_section_appearance"
android:layout_width="match_parent"

View file

@ -102,6 +102,8 @@
<string name="settings_launcher_choose_wallpaper">Choose a wallpaper</string>
<string name="settings_launcher_change_wallpaper">Change wallpaper</string>
<string name="settings_launcher_choose_homescreen">Set μLauncher as home screen</string>
<string name="settings_launcher_section_display">Display</string>
<string name="settings_launcher_disable_timeout">Keep screen on</string>