mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-05 01:47:24 +00:00
Gesture apps can now be chosen freely (also Gradle updates)
This commit is contained in:
parent
7f7a7f4286
commit
2a0be96ee6
14 changed files with 499 additions and 87 deletions
|
|
@ -95,7 +95,7 @@ class Animations () {
|
|||
.setDuration(duration)
|
||||
.setListener(object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
visibility = View.GONE
|
||||
visibility = View.INVISIBLE
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ class AppMenuAdapter(
|
|||
) :
|
||||
RecyclerView.Adapter<AppMenuAdapter.AppViewHolder>() {
|
||||
|
||||
var menuMode: String = "app"
|
||||
var shortcutTextView: TextView? = null
|
||||
|
||||
private val sharedPreferenceManager = SharedPreferenceManager()
|
||||
|
|
@ -71,15 +70,15 @@ class AppMenuAdapter(
|
|||
textView.setOnClickListener {
|
||||
val position = bindingAdapterPosition
|
||||
val app = apps[position].first
|
||||
if (menuMode == "shortcut") {
|
||||
if (shortcutTextView != null) {
|
||||
shortcutListener.onShortcut(app, apps[position].second.first, textView, apps[position].second.second, shortcutTextView!!)
|
||||
}
|
||||
else if (menuMode == "app") {
|
||||
else {
|
||||
itemClickListener.onItemClick(app, apps[position].second.first)
|
||||
}
|
||||
}
|
||||
|
||||
if (menuMode == "app") {
|
||||
if (shortcutTextView == null) {
|
||||
textView.setOnLongClickListener {
|
||||
val position = bindingAdapterPosition
|
||||
|
||||
|
|
|
|||
119
app/src/main/java/eu/ottop/yamlauncher/GestureAppsAdapter.kt
Normal file
119
app/src/main/java/eu/ottop/yamlauncher/GestureAppsAdapter.kt
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
package eu.ottop.yamlauncher
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.LauncherActivityInfo
|
||||
import android.os.UserHandle
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.EditText
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
class GestureAppsAdapter(
|
||||
private val activity: Context,
|
||||
var apps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>,
|
||||
private val itemClickListener: OnItemClickListener
|
||||
) :
|
||||
RecyclerView.Adapter<GestureAppsAdapter.AppViewHolder>() {
|
||||
|
||||
private val sharedPreferenceManager = SharedPreferenceManager()
|
||||
private var preferences = PreferenceManager.getDefaultSharedPreferences(activity)
|
||||
|
||||
interface OnItemClickListener {
|
||||
fun onItemClick(appInfo: LauncherActivityInfo, profile: Int)
|
||||
}
|
||||
|
||||
inner class AppViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
private val listItem: FrameLayout = itemView.findViewById(R.id.list_item)
|
||||
val textView: TextView = listItem.findViewById(R.id.app_name)
|
||||
private val actionMenuLayout: LinearLayout = listItem.findViewById(R.id.action_menu)
|
||||
private val editView: LinearLayout = listItem.findViewById(R.id.rename_view)
|
||||
val editText: EditText = editView.findViewById(R.id.app_name_edit)
|
||||
|
||||
init {
|
||||
actionMenuLayout.visibility = View.INVISIBLE
|
||||
editView.visibility = View.INVISIBLE
|
||||
|
||||
textView.setOnClickListener {
|
||||
val position = bindingAdapterPosition
|
||||
val app = apps[position].first
|
||||
itemClickListener.onItemClick(app, apps[position].second.second)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AppViewHolder {
|
||||
val view = LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.app_item_layout, parent, false)
|
||||
return AppViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: AppViewHolder, position: Int) {
|
||||
val app = apps[position]
|
||||
|
||||
if (app.second.second != 0) {
|
||||
holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_work_app, null),null,null,null)
|
||||
}
|
||||
else {
|
||||
holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null,null,null)
|
||||
}
|
||||
|
||||
when (preferences.getString("appMenuAlignment", "left")) {
|
||||
"left" -> {
|
||||
holder.textView.setCompoundDrawablesWithIntrinsicBounds(holder.textView.compoundDrawables.filterNotNull().first(),null, null, null)
|
||||
holder.textView.gravity = Gravity.CENTER_VERTICAL or Gravity.START
|
||||
}
|
||||
"center" -> {
|
||||
holder.textView.setCompoundDrawablesWithIntrinsicBounds(holder.textView.compoundDrawables.filterNotNull().first(),null,holder.textView.compoundDrawables.filterNotNull().first(), null)
|
||||
holder.textView.gravity = Gravity.CENTER
|
||||
|
||||
}
|
||||
"right" -> {
|
||||
holder.textView.setCompoundDrawablesWithIntrinsicBounds(null,null, holder.textView.compoundDrawables.filterNotNull().first(), null)
|
||||
holder.textView.gravity = Gravity.CENTER_VERTICAL or Gravity.END
|
||||
}
|
||||
}
|
||||
|
||||
when (preferences.getString("appMenuSize", "medium")) {
|
||||
"small" -> {
|
||||
holder.textView.textSize = 24F
|
||||
holder.editText.textSize = 24F
|
||||
}
|
||||
|
||||
"medium" -> {
|
||||
holder.textView.textSize = 26F
|
||||
holder.editText.textSize = 26F
|
||||
}
|
||||
|
||||
"large" -> {
|
||||
holder.textView.textSize = 28F
|
||||
holder.editText.textSize = 28F
|
||||
}
|
||||
}
|
||||
|
||||
val appInfo = app.first.activityInfo.applicationInfo
|
||||
holder.textView.text = sharedPreferenceManager.getAppName(activity, app.first.applicationInfo.packageName,app.second.second, holder.itemView.context.packageManager.getApplicationLabel(appInfo))
|
||||
|
||||
holder.textView.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return apps.size
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun updateApps(newApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||
apps = newApps.toMutableList()
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
152
app/src/main/java/eu/ottop/yamlauncher/GestureAppsFragment.kt
Normal file
152
app/src/main/java/eu/ottop/yamlauncher/GestureAppsFragment.kt
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
package eu.ottop.yamlauncher
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.AlertDialog
|
||||
import android.content.pm.LauncherActivityInfo
|
||||
import android.os.Bundle
|
||||
import android.os.UserHandle
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.EditText
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.setFragmentResult
|
||||
import androidx.preference.Preference
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class GestureAppsFragment : Fragment(), GestureAppsAdapter.OnItemClickListener {
|
||||
|
||||
private var adapter: GestureAppsAdapter? = null
|
||||
private val sharedPreferenceManager = SharedPreferenceManager()
|
||||
private var stringUtils = StringUtils()
|
||||
private val appUtils = AppUtils()
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_gesture_apps, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
|
||||
withContext(Dispatchers.Default) {
|
||||
|
||||
adapter = GestureAppsAdapter(
|
||||
requireContext(),
|
||||
appUtils.getInstalledApps(activity as Activity).toMutableList(),
|
||||
this@GestureAppsFragment
|
||||
)
|
||||
}
|
||||
val recyclerView = view.findViewById<RecyclerView>(R.id.gesture_app_recycler)
|
||||
val appMenuEdgeFactory = AppMenuEdgeFactory(requireActivity())
|
||||
|
||||
recyclerView.edgeEffectFactory = appMenuEdgeFactory
|
||||
recyclerView.adapter = adapter
|
||||
|
||||
recyclerView.scrollToPosition(0)
|
||||
|
||||
val searchView = view.findViewById<EditText>(R.id.gestureAppSearch)
|
||||
|
||||
recyclerView.addOnLayoutChangeListener { _, _, top, _, bottom, _, oldTop, _, oldBottom ->
|
||||
|
||||
if (bottom - top > oldBottom - oldTop) {
|
||||
searchView.clearFocus()
|
||||
}
|
||||
}
|
||||
|
||||
searchView.addTextChangedListener(object :
|
||||
TextWatcher {
|
||||
override fun beforeTextChanged(
|
||||
s: CharSequence?,
|
||||
start: Int,
|
||||
count: Int,
|
||||
after: Int
|
||||
) {
|
||||
}
|
||||
|
||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
|
||||
filterItems(searchView.text.toString())
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private fun filterItems(query: String?) {
|
||||
|
||||
val cleanQuery = stringUtils.cleanString(query)
|
||||
val newFilteredApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
||||
val updatedApps = appUtils.getInstalledApps(requireActivity())
|
||||
|
||||
getFilteredApps(cleanQuery, newFilteredApps, updatedApps)
|
||||
|
||||
applySearch(newFilteredApps)
|
||||
|
||||
}
|
||||
|
||||
private fun getFilteredApps(cleanQuery: String?, newFilteredApps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>, updatedApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||
if (cleanQuery.isNullOrEmpty()) {
|
||||
newFilteredApps.addAll(updatedApps)
|
||||
} else {
|
||||
updatedApps.forEach {
|
||||
val cleanItemText = stringUtils.cleanString(sharedPreferenceManager.getAppName(requireActivity(), it.first.applicationInfo.packageName, it.second.second, requireActivity().packageManager.getApplicationLabel(it.first.applicationInfo)).toString())
|
||||
if (cleanItemText != null) {
|
||||
if (cleanItemText.contains(cleanQuery, ignoreCase = true)) {
|
||||
newFilteredApps.add(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun applySearch(newFilteredApps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||
adapter?.updateApps(newFilteredApps)
|
||||
}
|
||||
|
||||
private fun showConfirmationDialog(appInfo: LauncherActivityInfo, appName: String, profile: Int) {
|
||||
AlertDialog.Builder(requireContext()).apply {
|
||||
setTitle("Confirmation")
|
||||
setMessage("Are you sure you want to set $appName? as the gesture app")
|
||||
setPositiveButton("Yes") { _, _ ->
|
||||
// Perform action on confirmation
|
||||
performConfirmedAction(appInfo, appName, profile)
|
||||
}
|
||||
|
||||
setNegativeButton("Cancel") { _, _ ->
|
||||
}
|
||||
|
||||
}.create().show()
|
||||
}
|
||||
|
||||
private fun performConfirmedAction(appInfo: LauncherActivityInfo, appName: String, profile: Int) {
|
||||
val result = Bundle().apply {
|
||||
putString("gesture_app", "$appName-${appInfo.applicationInfo.packageName}-$profile")
|
||||
}
|
||||
setFragmentResult("request_key", result)
|
||||
requireActivity().supportFragmentManager.popBackStack()
|
||||
}
|
||||
|
||||
|
||||
override fun onItemClick(appInfo: LauncherActivityInfo, profile: Int) {
|
||||
showConfirmationDialog(appInfo, sharedPreferenceManager.getAppName(requireContext(), appInfo.applicationInfo.packageName,profile, requireContext().packageManager.getApplicationLabel(appInfo.applicationInfo)).toString(), profile)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -14,34 +14,12 @@ import android.view.ViewGroup
|
|||
import android.widget.EditText
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private const val ARG_PARAM1 = "param1"
|
||||
private const val ARG_PARAM2 = "param2"
|
||||
|
||||
/**
|
||||
* A simple [Fragment] subclass.
|
||||
* Use the [HiddenAppsFragment.newInstance] factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener {
|
||||
// TODO: Rename and change types of parameters
|
||||
private var param1: String? = null
|
||||
private var param2: String? = null
|
||||
private val appUtils = AppUtils()
|
||||
private val sharedPreferenceManager = SharedPreferenceManager()
|
||||
private var adapter: HiddenAppsAdapter? = null
|
||||
private var stringUtils = StringUtils()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
arguments?.let {
|
||||
param1 = it.getString(ARG_PARAM1)
|
||||
param2 = it.getString(ARG_PARAM2)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
|
|
@ -127,14 +105,6 @@ class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener {
|
|||
// Perform action on confirmation
|
||||
performConfirmedAction(appInfo, appName, profile)
|
||||
}
|
||||
setNegativeButton("Cancel") { _, _ ->
|
||||
// Handle cancellation
|
||||
handleCancellation()
|
||||
}
|
||||
setOnCancelListener {
|
||||
// Handle dialog cancel
|
||||
handleCancellation()
|
||||
}
|
||||
}.create().show()
|
||||
}
|
||||
|
||||
|
|
@ -147,30 +117,8 @@ class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener {
|
|||
// Handle the cancellation of the dialog
|
||||
}
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
*
|
||||
* @param param1 Parameter 1.
|
||||
* @param param2 Parameter 2.
|
||||
* @return A new instance of fragment HiddenAppsFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
@JvmStatic
|
||||
fun newInstance(param1: String, param2: String) =
|
||||
HiddenAppsFragment().apply {
|
||||
arguments = Bundle().apply {
|
||||
putString(ARG_PARAM1, param1)
|
||||
putString(ARG_PARAM2, param2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onItemClick(appInfo: LauncherActivityInfo, profile: Int) {
|
||||
showConfirmationDialog(appInfo, sharedPreferenceManager.getAppName(requireContext(), appInfo.applicationInfo.packageName,profile, requireContext().packageManager.getApplicationLabel(appInfo.applicationInfo)).toString(), profile)
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -16,6 +16,7 @@ import kotlinx.coroutines.CoroutineScope
|
|||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class LocationFragment : Fragment(), LocationListAdapter.OnItemClickListener {
|
||||
|
||||
private var adapter: LocationListAdapter? = null
|
||||
|
|
|
|||
|
|
@ -69,8 +69,6 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
private var adapter: AppMenuAdapter? = null
|
||||
private var job: Job? = null
|
||||
private var weatherJob: Job? = null
|
||||
val cameraIntent = Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE)
|
||||
val phoneIntent = Intent(Intent.ACTION_DIAL)
|
||||
private var batteryReceiver: BatteryReceiver? = null
|
||||
|
||||
private var appActionMenu = AppActionMenu()
|
||||
|
|
@ -100,6 +98,9 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
|
||||
private var isBatteryReceiverRegistered = false
|
||||
|
||||
private lateinit var leftSwipeActivity: Pair<LauncherActivityInfo?, Int?>
|
||||
private lateinit var rightSwipeActivity: Pair<LauncherActivityInfo?, Int?>
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
|
@ -119,6 +120,9 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
|
||||
launcherApps = getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
|
||||
|
||||
leftSwipeActivity = getSwipeInfo("left")
|
||||
rightSwipeActivity = getSwipeInfo("right")
|
||||
|
||||
gestureDetector = GestureDetector(this, GestureListener())
|
||||
shortcutGestureDetector = GestureDetector(this, TextGestureListener())
|
||||
|
||||
|
|
@ -257,6 +261,14 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
modifyDate("", 3)
|
||||
}
|
||||
}
|
||||
|
||||
"leftSwipeApp" -> {
|
||||
leftSwipeActivity = getSwipeInfo("left")
|
||||
}
|
||||
|
||||
"rightSwipeApp" -> {
|
||||
rightSwipeActivity = getSwipeInfo("right")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -328,8 +340,6 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
@SuppressLint("NotifyDataSetChanged")
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
binding.homeView.visibility = View.VISIBLE
|
||||
binding.appView.visibility = View.INVISIBLE
|
||||
adapter?.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
|
|
@ -361,13 +371,23 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
}
|
||||
|
||||
// Detect swipe left
|
||||
else if (deltaX < -swipeThreshold && abs(velocityX) > swipeVelocityThreshold && preferences.getBoolean("cameraSwipe", true)){
|
||||
startActivity(cameraIntent)
|
||||
else if (deltaX < -swipeThreshold && abs(velocityX) > swipeVelocityThreshold && preferences.getBoolean("leftSwipe", true)){
|
||||
|
||||
if (leftSwipeActivity.first != null && leftSwipeActivity.second != null) {
|
||||
launcherApps.startMainActivity(leftSwipeActivity.first!!.componentName, launcherApps.profiles[leftSwipeActivity.second!!], null, null)
|
||||
} else {
|
||||
Toast.makeText(this@MainActivity, "Cannot launch app", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Detect swipe right
|
||||
else if (deltaX > -swipeThreshold && abs(velocityX) > swipeVelocityThreshold && preferences.getBoolean("phoneSwipe", true)) {
|
||||
startActivity(phoneIntent)
|
||||
else if (deltaX > -swipeThreshold && abs(velocityX) > swipeVelocityThreshold && preferences.getBoolean("rightSwipe", true)) {
|
||||
if (rightSwipeActivity.first != null && rightSwipeActivity.second != null) {
|
||||
launcherApps.startMainActivity(rightSwipeActivity.first!!.componentName, launcherApps.profiles[rightSwipeActivity.second!!], null, null)
|
||||
} else {
|
||||
Toast.makeText(this@MainActivity, "Cannot launch app", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
|
|
@ -386,6 +406,22 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
}
|
||||
}
|
||||
|
||||
private fun getSwipeInfo(direction: String): Pair<LauncherActivityInfo?, Int?> {
|
||||
val app = preferences.getString("${direction}SwipeApp", "")?.split("-")
|
||||
|
||||
if (app != null) {
|
||||
if (app.size >= 3)
|
||||
|
||||
return Pair(
|
||||
launcherApps.getActivityList(
|
||||
app?.get(1), launcherApps.profiles[app.get(2)!!
|
||||
.toInt()]
|
||||
).firstOrNull(), app[2].toInt()
|
||||
)
|
||||
}
|
||||
return Pair(null, null)
|
||||
}
|
||||
|
||||
private fun setupApps() {
|
||||
handleListItems()
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
|
|
@ -444,7 +480,6 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
Toast.makeText(this, "Long click to select an app", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
textView.setOnLongClickListener {
|
||||
adapter?.menuMode = "shortcut"
|
||||
adapter?.shortcutTextView = textView
|
||||
toAppMenu()
|
||||
|
||||
|
|
@ -569,7 +604,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
}
|
||||
|
||||
fun openAppMenuActivity() {
|
||||
adapter?.menuMode = "app"
|
||||
adapter?.shortcutTextView = null
|
||||
binding.menutitle.visibility = View.GONE
|
||||
toAppMenu()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package eu.ottop.yamlauncher
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.clearFragmentResultListener
|
||||
import androidx.fragment.app.setFragmentResultListener
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.preference.SwitchPreference
|
||||
|
||||
class SettingsFragment : PreferenceFragmentCompat() {
|
||||
|
|
@ -18,8 +20,12 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
|
||||
val gpsLocationPref: SwitchPreference? = findPreference("gps_location")
|
||||
manualLocationPref = findPreference("manual_location")
|
||||
val leftSwipePref = findPreference<Preference?>("leftSwipeApp")
|
||||
val rightSwipePref = findPreference<Preference?>("rightSwipeApp")
|
||||
|
||||
manualLocationPref?.summary = sharedPreferenceManager.getWeatherRegion(requireContext())
|
||||
leftSwipePref?.summary = sharedPreferenceManager.getGestureName(requireContext(), "left")
|
||||
rightSwipePref?.summary = sharedPreferenceManager.getGestureName(requireContext(), "right")
|
||||
|
||||
if (gpsLocationPref != null && manualLocationPref != null) {
|
||||
// Initial setup
|
||||
|
|
@ -55,10 +61,65 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
.addToBackStack(null)
|
||||
.commit()
|
||||
true }
|
||||
|
||||
leftSwipePref?.onPreferenceClickListener =
|
||||
Preference.OnPreferenceClickListener {
|
||||
requireActivity().supportFragmentManager
|
||||
.beginTransaction()
|
||||
.replace(R.id.settings_layout, GestureAppsFragment())
|
||||
.addToBackStack(null)
|
||||
.commit()
|
||||
setFragmentResultListener("request_key") { requestKey, bundle ->
|
||||
clearFragmentResultListener("request_key")
|
||||
val result = bundle.getString("gesture_app")
|
||||
val appDetails = result?.split("-")
|
||||
if (leftSwipePref != null && result != null) {
|
||||
setPreference("leftSwipeApp", result)
|
||||
}
|
||||
sharedPreferenceManager.setGestures(requireContext(), "left",
|
||||
appDetails?.get(0), appDetails?.get(1), appDetails?.get(2)
|
||||
)
|
||||
val appName = appDetails?.get(0)
|
||||
leftSwipePref?.summary = appName
|
||||
}
|
||||
true }
|
||||
|
||||
rightSwipePref?.onPreferenceClickListener =
|
||||
Preference.OnPreferenceClickListener {
|
||||
requireActivity().supportFragmentManager
|
||||
.beginTransaction()
|
||||
.replace(R.id.settings_layout, GestureAppsFragment())
|
||||
.addToBackStack(null)
|
||||
.commit()
|
||||
setFragmentResultListener("request_key") { requestKey, bundle ->
|
||||
clearFragmentResultListener("request_key")
|
||||
val result = bundle.getString("gesture_app")
|
||||
val appDetails = result?.split("-")
|
||||
if (rightSwipePref != null && result != null) {
|
||||
setPreference("rightSwipeApp", result)
|
||||
}
|
||||
sharedPreferenceManager.setGestures(requireContext(), "right",
|
||||
appDetails?.get(0), appDetails?.get(1), appDetails?.get(2)
|
||||
)
|
||||
val appName = appDetails?.get(0)
|
||||
rightSwipePref?.summary = appName
|
||||
}
|
||||
true }
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
manualLocationPref?.summary = sharedPreferenceManager.getWeatherRegion(requireContext())
|
||||
}
|
||||
|
||||
private fun setPreference(key: String, value: String) {
|
||||
// Get the SharedPreferences instance
|
||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
|
||||
// Edit the SharedPreferences to update the value
|
||||
with(sharedPreferences.edit()) {
|
||||
putString(key, value)
|
||||
apply()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -81,4 +81,24 @@ class SharedPreferenceManager {
|
|||
return sharedPreferences.getString(key, "")
|
||||
}
|
||||
|
||||
fun setGestures(cont: Context, direction: String, appName: String?, packageName: String?, profile: String?) {
|
||||
val editor = cont.getSharedPreferences("gestures", AppCompatActivity.MODE_PRIVATE).edit()
|
||||
val nameKey = "$direction-name"
|
||||
editor.putString(direction, "$packageName-$profile")
|
||||
editor.putString(nameKey, appName)
|
||||
editor.apply()
|
||||
}
|
||||
|
||||
|
||||
fun getGestureApp(cont: Context, direction: String) : String? {
|
||||
val sharedPreferences = cont.getSharedPreferences("gestures", AppCompatActivity.MODE_PRIVATE)
|
||||
return sharedPreferences.getString(direction, "")
|
||||
}
|
||||
|
||||
fun getGestureName(cont: Context, direction: String) : String? {
|
||||
val sharedPreferences = cont.getSharedPreferences("gestures", AppCompatActivity.MODE_PRIVATE)
|
||||
val key = "$direction-name"
|
||||
return sharedPreferences.getString(key, "")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -31,9 +31,6 @@ class WeatherSystem {
|
|||
locationManager.removeUpdates(this)
|
||||
}
|
||||
|
||||
override fun onFlushComplete(requestCode: Int) {
|
||||
super.onFlushComplete(requestCode)
|
||||
}
|
||||
}
|
||||
|
||||
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
|
|
@ -99,6 +96,7 @@ class WeatherSystem {
|
|||
var currentWeather = ""
|
||||
|
||||
val location = sharedPreferenceManager.getWeatherLocation(context)
|
||||
|
||||
if (location != null) {
|
||||
if (location.isNotEmpty()) {
|
||||
val url = URL("https://api.open-meteo.com/v1/forecast?$location&temperature_unit=${tempUnits}¤t=temperature_2m,weather_code")
|
||||
|
|
|
|||
65
app/src/main/res/layout/fragment_gesture_apps.xml
Normal file
65
app/src/main/res/layout/fragment_gesture_apps.xml
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/gesture_app_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="bottom"
|
||||
android:orientation="vertical"
|
||||
android:visibility="visible">
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/gesture_menutitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="false"
|
||||
android:gravity="start"
|
||||
android:paddingLeft="40dp"
|
||||
android:paddingTop="20dp"
|
||||
android:paddingRight="40dp"
|
||||
android:paddingBottom="20dp"
|
||||
android:text="@string/select_an_app"
|
||||
android:textAppearance="@android:style/TextAppearance.DeviceDefault"
|
||||
android:textColor="#C1F3F3F3"
|
||||
android:textSize="36sp" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/gesture_app_recycler"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:clipToPadding="false"
|
||||
android:fadingEdgeLength="20dp"
|
||||
android:padding="0dp"
|
||||
android:requiresFadingEdge="vertical"
|
||||
android:scrollbars="none"
|
||||
app:layoutManager="LinearLayoutManager">
|
||||
|
||||
</androidx.recyclerview.widget.RecyclerView>
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/gestureAppSearch"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginHorizontal="32dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_weight="0.1"
|
||||
android:background="@android:color/transparent"
|
||||
android:cursorVisible="true"
|
||||
android:drawableStart="@android:drawable/ic_menu_search"
|
||||
android:drawablePadding="8dp"
|
||||
android:editTextColor="#f3f3f3"
|
||||
android:hint="@string/search"
|
||||
android:singleLine="true"
|
||||
android:textAlignment="viewStart"
|
||||
android:textAppearance="@android:style/TextAppearance.DeviceDefault"
|
||||
android:textSize="25sp"
|
||||
tools:ignore="RtlCompat" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
@ -124,14 +124,28 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:defaultValue="true"
|
||||
android:title="Camera Swipe Left"
|
||||
app:key="cameraSwipe" />
|
||||
android:title="Swipe Left"
|
||||
app:key="leftSwipe" />
|
||||
<Preference
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:dependency="leftSwipe"
|
||||
app:key="leftSwipeApp"
|
||||
app:selectable="true"
|
||||
app:title="Left Swipe App" />
|
||||
<SwitchPreference
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:defaultValue="true"
|
||||
android:title="Phone Swipe Right"
|
||||
app:key="phoneSwipe" />
|
||||
android:title="Swipe Right"
|
||||
app:key="rightSwipe" />
|
||||
<Preference
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:dependency="rightSwipe"
|
||||
app:key="rightSwipeApp"
|
||||
app:selectable="true"
|
||||
app:title="Right Swipe App" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:layout_width="wrap_content"
|
||||
|
|
@ -169,18 +183,6 @@
|
|||
app:title="Units"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:allowDividerAbove="false"
|
||||
app:title="Hidden Apps">
|
||||
<Preference
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:key="hidden_apps"
|
||||
app:selectable="true"
|
||||
app:title="Manage Hidden Apps" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
@ -193,5 +195,17 @@
|
|||
android:title="Battery Indicator"
|
||||
app:key="battery_enabled" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:allowDividerAbove="false"
|
||||
app:title="Hidden Apps">
|
||||
<Preference
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:key="hidden_apps"
|
||||
app:selectable="true"
|
||||
app:title="Manage Hidden Apps" />
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
Loading…
Add table
Add a link
Reference in a new issue