mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-05 01:47:24 +00:00
Added the ability to swap out the clock and calendar apps for any other app
This commit is contained in:
parent
be4dd79e89
commit
55ed5ea42d
4 changed files with 106 additions and 13 deletions
|
|
@ -94,6 +94,9 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
private val swipeThreshold = 100
|
private val swipeThreshold = 100
|
||||||
private val swipeVelocityThreshold = 100
|
private val swipeVelocityThreshold = 100
|
||||||
|
|
||||||
|
private lateinit var clockApp: Pair<LauncherActivityInfo?, Int?>
|
||||||
|
private lateinit var dateApp: Pair<LauncherActivityInfo?, Int?>
|
||||||
|
|
||||||
private lateinit var leftSwipeActivity: Pair<LauncherActivityInfo?, Int?>
|
private lateinit var leftSwipeActivity: Pair<LauncherActivityInfo?, Int?>
|
||||||
private lateinit var rightSwipeActivity: Pair<LauncherActivityInfo?, Int?>
|
private lateinit var rightSwipeActivity: Pair<LauncherActivityInfo?, Int?>
|
||||||
|
|
||||||
|
|
@ -311,6 +314,9 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
uiUtils.setStatusBar(window)
|
uiUtils.setStatusBar(window)
|
||||||
}, 0)
|
}, 0)
|
||||||
|
|
||||||
|
clockApp = gestureUtils.getSwipeInfo(launcherApps, "clock")
|
||||||
|
dateApp = gestureUtils.getSwipeInfo(launcherApps, "date")
|
||||||
|
|
||||||
leftSwipeActivity = gestureUtils.getSwipeInfo(launcherApps, "left")
|
leftSwipeActivity = gestureUtils.getSwipeInfo(launcherApps, "left")
|
||||||
rightSwipeActivity = gestureUtils.getSwipeInfo(launcherApps, "right")
|
rightSwipeActivity = gestureUtils.getSwipeInfo(launcherApps, "right")
|
||||||
}
|
}
|
||||||
|
|
@ -333,15 +339,23 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
|
|
||||||
clock.setOnClickListener {_ ->
|
clock.setOnClickListener {_ ->
|
||||||
if (sharedPreferenceManager.isClockGestureEnabled()) {
|
if (sharedPreferenceManager.isClockGestureEnabled()) {
|
||||||
|
if (sharedPreferenceManager.isGestureEnabled("clock") && clockApp.first != null && clockApp.second != null) {
|
||||||
|
launcherApps.startMainActivity(clockApp.first!!.componentName, launcherApps.profiles[clockApp.second!!], null, null)
|
||||||
|
} else {
|
||||||
val intent = Intent(AlarmClock.ACTION_SHOW_ALARMS)
|
val intent = Intent(AlarmClock.ACTION_SHOW_ALARMS)
|
||||||
if (intent.resolveActivity(packageManager) != null) {
|
if (intent.resolveActivity(packageManager) != null) {
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dateText.setOnClickListener { _ ->
|
dateText.setOnClickListener { _ ->
|
||||||
if (sharedPreferenceManager.isDateGestureEnabled()) {
|
if (sharedPreferenceManager.isDateGestureEnabled()) {
|
||||||
|
|
||||||
|
if (sharedPreferenceManager.isGestureEnabled("date") && dateApp.first != null && dateApp.second != null) {
|
||||||
|
launcherApps.startMainActivity(dateApp.first!!.componentName, launcherApps.profiles[dateApp.second!!], null, null)
|
||||||
|
} else {
|
||||||
startActivity(
|
startActivity(
|
||||||
Intent(
|
Intent(
|
||||||
Intent.makeMainSelectorActivity(
|
Intent.makeMainSelectorActivity(
|
||||||
|
|
@ -352,6 +366,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
clock.setOnLongClickListener {_ ->
|
clock.setOnLongClickListener {_ ->
|
||||||
startActivity(Intent(this@MainActivity, SettingsActivity::class.java))
|
startActivity(Intent(this@MainActivity, SettingsActivity::class.java))
|
||||||
|
|
@ -463,6 +478,30 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
uiUtils.setStatusBar(window)
|
uiUtils.setStatusBar(window)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"clockSwipe" -> {
|
||||||
|
clockApp = gestureUtils.getSwipeInfo(launcherApps, "clock")
|
||||||
|
}
|
||||||
|
|
||||||
|
"dateSwipe" -> {
|
||||||
|
dateApp = gestureUtils.getSwipeInfo(launcherApps, "date")
|
||||||
|
}
|
||||||
|
|
||||||
|
"clockSwipeApp" -> {
|
||||||
|
clockApp = gestureUtils.getSwipeInfo(launcherApps, "clock")
|
||||||
|
}
|
||||||
|
|
||||||
|
"dateSwipeApp" -> {
|
||||||
|
dateApp = gestureUtils.getSwipeInfo(launcherApps, "date")
|
||||||
|
}
|
||||||
|
|
||||||
|
"leftSwipe" -> {
|
||||||
|
leftSwipeActivity = gestureUtils.getSwipeInfo(launcherApps, "left")
|
||||||
|
}
|
||||||
|
|
||||||
|
"rightSwipe" -> {
|
||||||
|
rightSwipeActivity = gestureUtils.getSwipeInfo(launcherApps, "right")
|
||||||
|
}
|
||||||
|
|
||||||
"leftSwipeApp" -> {
|
"leftSwipeApp" -> {
|
||||||
leftSwipeActivity = gestureUtils.getSwipeInfo(launcherApps, "left")
|
leftSwipeActivity = gestureUtils.getSwipeInfo(launcherApps, "left")
|
||||||
}
|
}
|
||||||
|
|
@ -817,7 +856,6 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
|
|
||||||
// Swipe left
|
// Swipe left
|
||||||
else if (deltaX < -swipeThreshold && abs(velocityX) > swipeVelocityThreshold && sharedPreferenceManager.isGestureEnabled("left")){
|
else if (deltaX < -swipeThreshold && abs(velocityX) > swipeVelocityThreshold && sharedPreferenceManager.isGestureEnabled("left")){
|
||||||
|
|
||||||
if (leftSwipeActivity.first != null && leftSwipeActivity.second != null) {
|
if (leftSwipeActivity.first != null && leftSwipeActivity.second != null) {
|
||||||
launcherApps.startMainActivity(leftSwipeActivity.first!!.componentName, launcherApps.profiles[leftSwipeActivity.second!!], null, null)
|
launcherApps.startMainActivity(leftSwipeActivity.first!!.componentName, launcherApps.profiles[leftSwipeActivity.second!!], null, null)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,17 @@ class HomeSettingsFragment : PreferenceFragmentCompat(), TitleProvider {
|
||||||
private var manualLocationPref: Preference? = null
|
private var manualLocationPref: Preference? = null
|
||||||
private var leftSwipePref: Preference? = null
|
private var leftSwipePref: Preference? = null
|
||||||
private var rightSwipePref: Preference? = null
|
private var rightSwipePref: Preference? = null
|
||||||
|
private var clockApp: Preference? = null
|
||||||
|
private var dateApp: Preference? = null
|
||||||
|
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
setPreferencesFromResource(R.xml.home_preferences, rootKey)
|
setPreferencesFromResource(R.xml.home_preferences, rootKey)
|
||||||
|
|
||||||
sharedPreferenceManager = SharedPreferenceManager(requireContext())
|
sharedPreferenceManager = SharedPreferenceManager(requireContext())
|
||||||
|
|
||||||
|
clockApp = findPreference("clockSwipeApp")
|
||||||
|
dateApp = findPreference("dateSwipeApp")
|
||||||
|
|
||||||
val gpsLocationPref = findPreference<SwitchPreference?>("gpsLocation")
|
val gpsLocationPref = findPreference<SwitchPreference?>("gpsLocation")
|
||||||
manualLocationPref = findPreference("manualLocation")
|
manualLocationPref = findPreference("manualLocation")
|
||||||
leftSwipePref = findPreference("leftSwipeApp")
|
leftSwipePref = findPreference("leftSwipeApp")
|
||||||
|
|
@ -63,10 +68,32 @@ class HomeSettingsFragment : PreferenceFragmentCompat(), TitleProvider {
|
||||||
.addToBackStack(null)
|
.addToBackStack(null)
|
||||||
.commit()
|
.commit()
|
||||||
true }
|
true }
|
||||||
|
|
||||||
|
clockApp?.onPreferenceClickListener =
|
||||||
|
Preference.OnPreferenceClickListener {
|
||||||
|
requireActivity().supportFragmentManager
|
||||||
|
.beginTransaction()
|
||||||
|
.replace(R.id.settingsLayout, GestureAppsFragment("clock"))
|
||||||
|
.addToBackStack(null)
|
||||||
|
.commit()
|
||||||
|
true }
|
||||||
|
|
||||||
|
dateApp?.onPreferenceClickListener =
|
||||||
|
Preference.OnPreferenceClickListener {
|
||||||
|
requireActivity().supportFragmentManager
|
||||||
|
.beginTransaction()
|
||||||
|
.replace(R.id.settingsLayout, GestureAppsFragment("date"))
|
||||||
|
.addToBackStack(null)
|
||||||
|
.commit()
|
||||||
|
true }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
clockApp?.summary = sharedPreferenceManager.getGestureName("clock")
|
||||||
|
|
||||||
|
dateApp?.summary = sharedPreferenceManager.getGestureName("date")
|
||||||
|
|
||||||
manualLocationPref?.summary = sharedPreferenceManager.getWeatherRegion()
|
manualLocationPref?.summary = sharedPreferenceManager.getWeatherRegion()
|
||||||
|
|
||||||
leftSwipePref?.summary = sharedPreferenceManager.getGestureName("left")
|
leftSwipePref?.summary = sharedPreferenceManager.getGestureName("left")
|
||||||
|
|
|
||||||
|
|
@ -139,9 +139,9 @@ class SharedPreferenceManager (private val context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gestures
|
// Gestures
|
||||||
fun setGestures(direction: String, appName: String?) {
|
fun setGestures(direction: String, appInfo: String?) {
|
||||||
val editor = preferences.edit()
|
val editor = preferences.edit()
|
||||||
editor.putString("${direction}SwipeApp", appName)
|
editor.putString("${direction}SwipeApp", appInfo)
|
||||||
editor.apply()
|
editor.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,20 @@
|
||||||
android:title="Clicking Time Opens Clock"
|
android:title="Clicking Time Opens Clock"
|
||||||
app:dependency="clockEnabled"
|
app:dependency="clockEnabled"
|
||||||
app:key="clockClick" />
|
app:key="clockClick" />
|
||||||
|
<SwitchPreference
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:title="Custom Clock"
|
||||||
|
app:dependency="clockClick"
|
||||||
|
app:key="clockSwipe" />
|
||||||
|
<Preference
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:dependency="clockSwipe"
|
||||||
|
app:key="clockSwipeApp"
|
||||||
|
app:selectable="true"
|
||||||
|
app:title="Set Clock App" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:title="Date"
|
android:title="Date"
|
||||||
|
|
@ -74,6 +88,20 @@
|
||||||
android:title="Clicking Date Opens Calendar"
|
android:title="Clicking Date Opens Calendar"
|
||||||
app:dependency="dateEnabled"
|
app:dependency="dateEnabled"
|
||||||
app:key="dateClick" />
|
app:key="dateClick" />
|
||||||
|
<SwitchPreference
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:title="Custom Calendar"
|
||||||
|
app:dependency="dateClick"
|
||||||
|
app:key="dateSwipe" />
|
||||||
|
<Preference
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:dependency="dateSwipe"
|
||||||
|
app:key="dateSwipeApp"
|
||||||
|
app:selectable="true"
|
||||||
|
app:title="Set Calendar App" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue