Skip to content

Commit

Permalink
Refactor: Worked out a better way for moving around the app.
Browse files Browse the repository at this point in the history
Changed from using ViewPager2 for changing apps of the app.
Added animations for changing to different fragments of the app
  • Loading branch information
CreativeCodeCat committed May 25, 2024
1 parent fc81f75 commit 8b1c0a3
Show file tree
Hide file tree
Showing 32 changed files with 361 additions and 291 deletions.
16 changes: 7 additions & 9 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />

<uses-permission android:name="android.permission.USE_BIOMETRIC" />
Expand All @@ -13,11 +14,11 @@
tools:ignore="QueryAllPackagesPermission" />
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-permission android:name="android.permission.BIND_APPWIDGET"
<uses-permission
android:name="android.permission.BIND_APPWIDGET"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />


<queries>
<intent>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -34,10 +35,6 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Launcher">
<activity
android:name=".ui.activities.SettingsActivity"
android:exported="false" />

<activity
android:name=".ui.activities.LauncherActivity"
android:enabled="false"
Expand Down Expand Up @@ -95,13 +92,14 @@
android:resource="@xml/policies" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
<action android:name="android.app.action.DEVICE_ADMIN_DISABLED" />
</intent-filter>
</receiver>

<service
android:name=".accessibility.MyAccessibilityService"
android:name=".accessibility.ActionService"
android:exported="false"
android:label="@string/app_name"
android:label="@string/accessibility_service_name"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<meta-data
android:name="android.accessibilityservice"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,4 @@ object Constants {
const val APP_WIDGET_HOST_ID = 1024
const val TRIPLE_TAP_DELAY_MS = 300
const val LONG_PRESS_DELAY_MS = 500
const val REQUEST_CODE_ENABLE_ADMIN = 123
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ import com.github.droidworksstudio.launcher.R
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.lang.ref.WeakReference

class MyAccessibilityService : AccessibilityService() {
class ActionService : AccessibilityService() {

private var info: AccessibilityServiceInfo = AccessibilityServiceInfo()

override fun onServiceConnected() {
mInstance = WeakReference(this)

info.apply {
eventTypes = AccessibilityEvent.TYPE_VIEW_CLICKED or AccessibilityEvent.TYPE_VIEW_FOCUSED
eventTypes =
AccessibilityEvent.TYPE_VIEW_CLICKED or AccessibilityEvent.TYPE_VIEW_FOCUSED

feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC

Expand Down Expand Up @@ -95,8 +96,8 @@ class MyAccessibilityService : AccessibilityService() {
return
}

private var mInstance: WeakReference<MyAccessibilityService> = WeakReference(null)
fun instance(): MyAccessibilityService? {
private var mInstance: WeakReference<ActionService> = WeakReference(null)
fun instance(): ActionService? {
return mInstance.get()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import androidx.appcompat.widget.LinearLayoutCompat
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.github.droidworksstudio.launcher.Constants
import com.github.droidworksstudio.launcher.R
import com.github.droidworksstudio.launcher.accessibility.MyAccessibilityService
import com.github.droidworksstudio.launcher.accessibility.ActionService
import com.github.droidworksstudio.launcher.data.entities.AppInfo
import com.github.droidworksstudio.launcher.ui.activities.FakeHomeActivity
import java.util.Calendar
Expand Down Expand Up @@ -95,8 +95,8 @@ class AppHelper @Inject constructor() {
.invoke(context.getSystemService(Constants.NOTIFICATION_SERVICE))
} catch (exception: Exception) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
MyAccessibilityService.runAccessibilityMode(context)
MyAccessibilityService.instance()?.openNotifications()
ActionService.runAccessibilityMode(context)
ActionService.instance()?.openNotifications()
}
exception.printStackTrace()
}
Expand All @@ -110,8 +110,8 @@ class AppHelper @Inject constructor() {
.invoke(context.getSystemService(Constants.QUICKSETTINGS_SERVICE))
} catch (exception: Exception) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
MyAccessibilityService.runAccessibilityMode(context)
MyAccessibilityService.instance()?.openQuickSettings()
ActionService.runAccessibilityMode(context)
ActionService.instance()?.openQuickSettings()
}
exception.printStackTrace()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.github.droidworksstudio.launcher.helper

import android.content.Intent
import androidx.biometric.BiometricManager
import androidx.biometric.BiometricPrompt
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.github.droidworksstudio.launcher.R
import com.github.droidworksstudio.launcher.data.entities.AppInfo
import javax.inject.Inject
Expand Down Expand Up @@ -56,32 +56,46 @@ class FingerprintHelper @Inject constructor(private val fragment: Fragment) {
}
}

fun startFingerprintSettingsAuth(targetClass: Class<*>) {
fun startFingerprintSettingsAuth(runNavigation: Int) {
val executor = ContextCompat.getMainExecutor(fragment.requireContext())

val biometricPrompt = BiometricPrompt(fragment, executor, object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
sendToTargetActivity(targetClass)
}
val biometricPrompt =
BiometricPrompt(fragment, executor, object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
fragment.findNavController().navigate(runNavigation)
}

override fun onAuthenticationFailed() {
appHelper.showToast(fragment.requireContext(), fragment.getString(R.string.authentication_failed))
}
override fun onAuthenticationFailed() {
appHelper.showToast(
fragment.requireContext(),
fragment.getString(R.string.authentication_failed)
)
}

override fun onAuthenticationError(errorCode: Int, errorMessage: CharSequence) {
when (errorCode) {
BiometricPrompt.ERROR_USER_CANCELED -> appHelper.showToast(fragment.requireContext(), fragment.getString(R.string.authentication_cancel))
else -> appHelper.showToast(fragment.requireContext(), fragment.getString(R.string.authentication_error).format(errorMessage, errorCode))
override fun onAuthenticationError(errorCode: Int, errorMessage: CharSequence) {
when (errorCode) {
BiometricPrompt.ERROR_USER_CANCELED -> appHelper.showToast(
fragment.requireContext(),
fragment.getString(R.string.authentication_cancel)
)

else -> appHelper.showToast(
fragment.requireContext(),
fragment.getString(R.string.authentication_error)
.format(errorMessage, errorCode)
)
}
}
}
})
})

val promptInfoBuilder = BiometricPrompt.PromptInfo.Builder()
.setTitle(fragment.getString(R.string.authentication_title))
.setSubtitle(fragment.getString(R.string.authentication_subtitle))

val authenticators = BiometricManager.Authenticators.BIOMETRIC_WEAK or BiometricManager.Authenticators.DEVICE_CREDENTIAL
val canAuthenticate = BiometricManager.from(fragment.requireContext()).canAuthenticate(authenticators)
val authenticators =
BiometricManager.Authenticators.BIOMETRIC_WEAK or BiometricManager.Authenticators.DEVICE_CREDENTIAL
val canAuthenticate =
BiometricManager.from(fragment.requireContext()).canAuthenticate(authenticators)

if (canAuthenticate == BiometricManager.BIOMETRIC_SUCCESS) {
promptInfoBuilder.setAllowedAuthenticators(authenticators)
Expand All @@ -95,17 +109,23 @@ class FingerprintHelper @Inject constructor(private val fragment: Fragment) {
BiometricManager.BIOMETRIC_SUCCESS -> biometricPrompt.authenticate(promptInfo)
BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE,
BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE,
BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED -> sendToTargetActivity(targetClass)
else -> appHelper.showToast(fragment.requireContext(), fragment.getString(R.string.authentication_failed))
BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED -> sendToTarget(runNavigation)

else -> appHelper.showToast(
fragment.requireContext(),
fragment.getString(R.string.authentication_failed)
)
}
}

fun sendToTargetActivity(targetClass: Class<*>) {
private fun sendToTarget(runNavigation: Int) {
try {
val intent = Intent(fragment.requireActivity(), targetClass)
fragment.requireActivity().startActivity(intent)
fragment.findNavController().navigate(runNavigation)
} catch (e: Exception) {
appHelper.showToast(fragment.requireContext(), fragment.getString(R.string.authentication_failed))
appHelper.showToast(
fragment.requireContext(),
fragment.getString(R.string.authentication_failed)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ internal open class OnSwipeTouchListener(c: Context?) : OnTouchListener {
open fun onLongClick() {}
open fun onDoubleClick() {}
open fun onTripleClick() {}

init {
gestureDetector = GestureDetector(c, GestureListener())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.github.droidworksstudio.launcher.ui.activities

import android.annotation.SuppressLint
import android.app.admin.DevicePolicyManager
import android.content.Intent
import android.content.pm.ActivityInfo
import android.os.Build
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
import android.widget.Toast
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
Expand All @@ -15,6 +18,7 @@ import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import com.github.droidworksstudio.launcher.Constants
import com.github.droidworksstudio.launcher.R
import com.github.droidworksstudio.launcher.databinding.ActivityMainBinding
import com.github.droidworksstudio.launcher.helper.AppHelper
Expand Down Expand Up @@ -143,5 +147,4 @@ class MainActivity : AppCompatActivity() {
if (navController.currentDestination?.id != R.id.HomeFragment)
navController.popBackStack(R.id.HomeFragment, false)
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import com.github.droidworksstudio.launcher.databinding.ItemDrawBinding
import com.github.droidworksstudio.launcher.helper.PreferenceHelper
import com.github.droidworksstudio.launcher.listener.OnItemClickedListener

class DrawAdapter(private val onAppClickedListener: OnItemClickedListener.OnAppsClickedListener,
private val onAppLongClickedListener: OnItemClickedListener.OnAppLongClickedListener,
private val preferenceHelperProvider: PreferenceHelper
class DrawAdapter(
private val onAppClickedListener: OnItemClickedListener.OnAppsClickedListener,
private val onAppLongClickedListener: OnItemClickedListener.OnAppLongClickedListener,
private val preferenceHelperProvider: PreferenceHelper
) :
ListAdapter<AppInfo, RecyclerView.ViewHolder>(DiffCallback()) {

Expand All @@ -27,7 +28,12 @@ class DrawAdapter(private val onAppClickedListener: OnItemClickedListener.OnApps
)
val preferenceHelper = preferenceHelperProvider

return DrawViewHolder(binding, onAppClickedListener, onAppLongClickedListener, preferenceHelper)
return DrawViewHolder(
binding,
onAppClickedListener,
onAppLongClickedListener,
preferenceHelper
)
}

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
Expand All @@ -36,7 +42,7 @@ class DrawAdapter(private val onAppClickedListener: OnItemClickedListener.OnApps
(holder as DrawViewHolder).bind(appInfo)
}

class DiffCallback : DiffUtil.ItemCallback<AppInfo>() {
class DiffCallback : DiffUtil.ItemCallback<AppInfo>() {
override fun areItemsTheSame(oldItem: AppInfo, newItem: AppInfo) =
oldItem.id == newItem.id

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ import javax.inject.Inject
* A simple [Fragment] subclass as the second destination in the navigation.
*/
@AndroidEntryPoint
class DrawFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener,
class DrawFragment : Fragment(),
OnItemClickedListener.OnAppsClickedListener,
OnItemClickedListener.OnAppLongClickedListener,
OnItemClickedListener.BottomSheetDismissListener,
OnItemClickedListener.OnAppStateClickListener,
Expand Down Expand Up @@ -143,7 +144,8 @@ class DrawFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener,

@SuppressLint("ClickableViewAccessibility")
private fun observeSwipeTouchListener() {
binding.mainView.setOnTouchListener(getSwipeGestureListener(context))
binding.touchArea.setOnTouchListener(getSwipeGestureListener(context))
binding.drawAdapter.setOnTouchListener(getSwipeGestureListener(context))
}

private fun getSwipeGestureListener(context: Context): View.OnTouchListener {
Expand Down
Loading

0 comments on commit 8b1c0a3

Please sign in to comment.