Skip to content

Commit

Permalink
Update and fix the Notification Draw (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
HeCodes2Much committed Dec 23, 2022
1 parent 6bf581c commit 028e81e
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 88 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />

<application
android:enableOnBackInvokedCallback="true"
android:allowBackup="true"
android:icon="@mipmap/mlauncher"
android:label="@string/app_name"
Expand Down
32 changes: 30 additions & 2 deletions app/src/main/java/app/mlauncher/ui/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package app.mlauncher.ui

import android.annotation.SuppressLint
import android.app.admin.DevicePolicyManager
import android.content.ComponentName
import android.content.Context
import android.content.Context.VIBRATOR_SERVICE
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.os.Vibrator
Expand Down Expand Up @@ -32,6 +34,7 @@ import app.mlauncher.listener.OnSwipeTouchListener
import app.mlauncher.listener.ViewSwipeTouchListener
import kotlinx.coroutines.launch


class HomeFragment : Fragment(), View.OnClickListener, View.OnLongClickListener {

private lateinit var prefs: Prefs
Expand Down Expand Up @@ -192,6 +195,31 @@ class HomeFragment : Fragment(), View.OnClickListener, View.OnLongClickListener
}
}

@SuppressLint("WrongConstant", "PrivateApi")
private fun expandNotificationDrawer(context: Context) {
// Source: https://stackoverflow.com/a/51132142
try {
val statusBarService = context.getSystemService("statusbar")
val statusBarManager = Class.forName("android.app.StatusBarManager")
val method = statusBarManager.getMethod("expandNotificationsPanel")
method.invoke(statusBarService)
} catch (e: Exception) {
e.printStackTrace()
}
}

@SuppressLint("WrongConstant", "PrivateApi")
private fun expandQuickSettings(context: Context) {
try {
val statusBarService = context.getSystemService("statusbar")
val statusBarManager = Class.forName("android.app.StatusBarManager")
val method = statusBarManager.getMethod("expandSettingsPanel")
method.invoke(statusBarService)
} catch (e: Exception) {
e.printStackTrace()
}
}

private fun openSwipeLeftApp() {
if (prefs.appSwipeLeft.appPackage.isNotEmpty())
launchApp(prefs.appSwipeLeft)
Expand Down Expand Up @@ -238,11 +266,11 @@ class HomeFragment : Fragment(), View.OnClickListener, View.OnLongClickListener
@SuppressLint("NewApi")
private fun handleOtherAction(action: Action) {
when(action) {
Action.ShowNotification -> initActionService(requireContext())?.openNotifications()
Action.ShowNotification -> expandNotificationDrawer(requireContext())
Action.LockScreen -> lockPhone()
Action.ShowAppList -> showAppList(AppDrawerFlag.LaunchApp)
Action.OpenApp -> {} // this should be handled in the respective onSwipe[Down,Right,Left] functions
Action.OpenQuickSettings -> initActionService(requireContext())?.openQuickSettings()
Action.OpenQuickSettings -> expandQuickSettings(requireContext())
Action.ShowRecents -> initActionService(requireContext())?.showRecents()
Action.Disabled -> {}
}
Expand Down

0 comments on commit 028e81e

Please sign in to comment.