mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-04 17:37:25 +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 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 rightSwipeActivity: Pair<LauncherActivityInfo?, Int?>
|
||||
|
||||
|
|
@ -311,6 +314,9 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
uiUtils.setStatusBar(window)
|
||||
}, 0)
|
||||
|
||||
clockApp = gestureUtils.getSwipeInfo(launcherApps, "clock")
|
||||
dateApp = gestureUtils.getSwipeInfo(launcherApps, "date")
|
||||
|
||||
leftSwipeActivity = gestureUtils.getSwipeInfo(launcherApps, "left")
|
||||
rightSwipeActivity = gestureUtils.getSwipeInfo(launcherApps, "right")
|
||||
}
|
||||
|
|
@ -333,23 +339,32 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
|
||||
clock.setOnClickListener {_ ->
|
||||
if (sharedPreferenceManager.isClockGestureEnabled()) {
|
||||
val intent = Intent(AlarmClock.ACTION_SHOW_ALARMS)
|
||||
if (intent.resolveActivity(packageManager) != null) {
|
||||
startActivity(intent)
|
||||
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)
|
||||
if (intent.resolveActivity(packageManager) != null) {
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dateText.setOnClickListener { _ ->
|
||||
if (sharedPreferenceManager.isDateGestureEnabled()) {
|
||||
startActivity(
|
||||
Intent(
|
||||
Intent.makeMainSelectorActivity(
|
||||
Intent.ACTION_MAIN,
|
||||
Intent.CATEGORY_APP_CALENDAR
|
||||
|
||||
if (sharedPreferenceManager.isGestureEnabled("date") && dateApp.first != null && dateApp.second != null) {
|
||||
launcherApps.startMainActivity(dateApp.first!!.componentName, launcherApps.profiles[dateApp.second!!], null, null)
|
||||
} else {
|
||||
startActivity(
|
||||
Intent(
|
||||
Intent.makeMainSelectorActivity(
|
||||
Intent.ACTION_MAIN,
|
||||
Intent.CATEGORY_APP_CALENDAR
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -463,6 +478,30 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
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" -> {
|
||||
leftSwipeActivity = gestureUtils.getSwipeInfo(launcherApps, "left")
|
||||
}
|
||||
|
|
@ -817,7 +856,6 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
|
||||
// Swipe left
|
||||
else if (deltaX < -swipeThreshold && abs(velocityX) > swipeVelocityThreshold && sharedPreferenceManager.isGestureEnabled("left")){
|
||||
|
||||
if (leftSwipeActivity.first != null && leftSwipeActivity.second != null) {
|
||||
launcherApps.startMainActivity(leftSwipeActivity.first!!.componentName, launcherApps.profiles[leftSwipeActivity.second!!], null, null)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -13,12 +13,17 @@ class HomeSettingsFragment : PreferenceFragmentCompat(), TitleProvider {
|
|||
private var manualLocationPref: Preference? = null
|
||||
private var leftSwipePref: 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)
|
||||
|
||||
sharedPreferenceManager = SharedPreferenceManager(requireContext())
|
||||
|
||||
clockApp = findPreference("clockSwipeApp")
|
||||
dateApp = findPreference("dateSwipeApp")
|
||||
|
||||
val gpsLocationPref = findPreference<SwitchPreference?>("gpsLocation")
|
||||
manualLocationPref = findPreference("manualLocation")
|
||||
leftSwipePref = findPreference("leftSwipeApp")
|
||||
|
|
@ -63,10 +68,32 @@ class HomeSettingsFragment : PreferenceFragmentCompat(), TitleProvider {
|
|||
.addToBackStack(null)
|
||||
.commit()
|
||||
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() {
|
||||
super.onResume()
|
||||
clockApp?.summary = sharedPreferenceManager.getGestureName("clock")
|
||||
|
||||
dateApp?.summary = sharedPreferenceManager.getGestureName("date")
|
||||
|
||||
manualLocationPref?.summary = sharedPreferenceManager.getWeatherRegion()
|
||||
|
||||
leftSwipePref?.summary = sharedPreferenceManager.getGestureName("left")
|
||||
|
|
|
|||
|
|
@ -139,9 +139,9 @@ class SharedPreferenceManager (private val context: Context) {
|
|||
}
|
||||
|
||||
// Gestures
|
||||
fun setGestures(direction: String, appName: String?) {
|
||||
fun setGestures(direction: String, appInfo: String?) {
|
||||
val editor = preferences.edit()
|
||||
editor.putString("${direction}SwipeApp", appName)
|
||||
editor.putString("${direction}SwipeApp", appInfo)
|
||||
editor.apply()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,20 @@
|
|||
android:title="Clicking Time Opens Clock"
|
||||
app:dependency="clockEnabled"
|
||||
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
|
||||
android:title="Date"
|
||||
|
|
@ -74,6 +88,20 @@
|
|||
android:title="Clicking Date Opens Calendar"
|
||||
app:dependency="dateEnabled"
|
||||
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
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue