mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-05 01:47:24 +00:00
Hidden App Settings now open a view with hidden apps (can't unhide yet)
This commit is contained in:
parent
01f1be6235
commit
b7cf7af2eb
12 changed files with 371 additions and 52 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package eu.ottop.yamlauncher
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.LauncherActivityInfo
|
||||
|
|
@ -23,7 +24,7 @@ import androidx.preference.PreferenceManager
|
|||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
class AppMenuAdapter(
|
||||
private val activity: FragmentActivity,
|
||||
private val activity: MainActivity,
|
||||
var apps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>,
|
||||
private val itemClickListener: OnItemClickListener,
|
||||
private val shortcutListener: OnShortcutListener,
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
package eu.ottop.yamlauncher
|
||||
|
||||
import android.app.Activity
|
||||
import android.widget.EdgeEffect
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
class AppMenuEdgeFactory(private val activity: MainActivity) : RecyclerView.EdgeEffectFactory() {
|
||||
class AppMenuEdgeFactory(private val activity: Activity) : RecyclerView.EdgeEffectFactory() {
|
||||
|
||||
override fun createEdgeEffect(view: RecyclerView, direction: Int): EdgeEffect {
|
||||
return AppMenuEdgeEffect(activity)
|
||||
}
|
||||
|
||||
inner class AppMenuEdgeEffect(activity: MainActivity) : EdgeEffect(activity) {
|
||||
inner class AppMenuEdgeEffect(activity: Activity) : EdgeEffect(activity) {
|
||||
private val animationSpeedFactor = 0.75f
|
||||
override fun onAbsorb(velocity: Int) {
|
||||
super.onAbsorb((velocity * animationSpeedFactor).toInt())
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
package eu.ottop.yamlauncher
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
|
||||
|
||||
class ButtonPreference(context: Context?, attrs: AttributeSet?) :
|
||||
Preference(context!!, attrs) {
|
||||
init {
|
||||
widgetLayoutResource = R.layout.location_button;
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
super.onBindViewHolder(holder)
|
||||
|
||||
val view = holder.itemView
|
||||
view.setOnClickListener {
|
||||
when (this.key) {
|
||||
"manual_location" -> {
|
||||
println("Location pressed")
|
||||
}
|
||||
|
||||
"hidden_apps" -> {
|
||||
println("Hidden apps pressed")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
172
app/src/main/java/eu/ottop/yamlauncher/HiddenAppsAdapter.kt
Normal file
172
app/src/main/java/eu/ottop/yamlauncher/HiddenAppsAdapter.kt
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
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.fragment.app.FragmentActivity
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
class HiddenAppsAdapter(
|
||||
private val activity: Context,
|
||||
var apps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>,
|
||||
private val itemClickListener: OnItemClickListener,
|
||||
private val shortcutListener: OnShortcutListener,
|
||||
private val itemLongClickListener: OnItemLongClickListener
|
||||
) :
|
||||
RecyclerView.Adapter<HiddenAppsAdapter.AppViewHolder>() {
|
||||
|
||||
var menuMode: String = "app"
|
||||
var shortcutTextView: TextView? = null
|
||||
|
||||
private val sharedPreferenceManager = SharedPreferenceManager()
|
||||
private var preferences = PreferenceManager.getDefaultSharedPreferences(activity)
|
||||
|
||||
interface OnItemClickListener {
|
||||
fun onItemClick(appInfo: LauncherActivityInfo, userHandle: UserHandle)
|
||||
}
|
||||
|
||||
interface OnShortcutListener {
|
||||
fun onShortcut(appInfo: LauncherActivityInfo, userHandle: UserHandle, textView: TextView, userProfile: Int, shortcutView: TextView)
|
||||
}
|
||||
|
||||
interface OnItemLongClickListener {
|
||||
fun onItemLongClick(
|
||||
appInfo: LauncherActivityInfo,
|
||||
userHandle: UserHandle,
|
||||
userProfile: Int,
|
||||
textView: TextView,
|
||||
actionMenuLayout: LinearLayout,
|
||||
editView: LinearLayout,
|
||||
position: 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)
|
||||
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
|
||||
if (menuMode == "shortcut") {
|
||||
shortcutListener.onShortcut(app, apps[position].second.first, textView, apps[position].second.second, shortcutTextView!!)
|
||||
}
|
||||
else if (menuMode == "app") {
|
||||
itemClickListener.onItemClick(app, apps[position].second.first)
|
||||
}
|
||||
}
|
||||
|
||||
if (menuMode == "app") {
|
||||
textView.setOnLongClickListener {
|
||||
val position = bindingAdapterPosition
|
||||
|
||||
val app = apps[position].first
|
||||
itemLongClickListener.onItemLongClick(
|
||||
app,
|
||||
apps[position].second.first,
|
||||
apps[position].second.second,
|
||||
textView,
|
||||
actionMenuLayout,
|
||||
editView,
|
||||
position
|
||||
)
|
||||
return@setOnLongClickListener true
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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.editText.setText(holder.textView.text)
|
||||
|
||||
if (appInfo.flags and ApplicationInfo.FLAG_SYSTEM != 0) {
|
||||
holder.actionMenuLayout.findViewById<TextView>(R.id.uninstall).visibility = View.GONE
|
||||
}
|
||||
else {
|
||||
holder.actionMenuLayout.findViewById<TextView>(R.id.uninstall).visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
107
app/src/main/java/eu/ottop/yamlauncher/HiddenAppsFragment.kt
Normal file
107
app/src/main/java/eu/ottop/yamlauncher/HiddenAppsFragment.kt
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
package eu.ottop.yamlauncher
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.pm.LauncherActivityInfo
|
||||
import android.os.Bundle
|
||||
import android.os.UserHandle
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
// 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, HiddenAppsAdapter.OnShortcutListener, HiddenAppsAdapter.OnItemLongClickListener {
|
||||
// TODO: Rename and change types of parameters
|
||||
private var param1: String? = null
|
||||
private var param2: String? = null
|
||||
private val appUtils = AppUtils()
|
||||
|
||||
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?
|
||||
): View? {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_hidden_apps, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
val adapter = HiddenAppsAdapter(requireContext(), appUtils.getHiddenApps(activity as Activity).toMutableList(), this, this, this)
|
||||
val recyclerView = view.findViewById<RecyclerView>(R.id.hidden_app_recycler)
|
||||
val appMenuEdgeFactory = AppMenuEdgeFactory(requireActivity())
|
||||
|
||||
recyclerView.edgeEffectFactory = appMenuEdgeFactory
|
||||
recyclerView.adapter = adapter
|
||||
recyclerView.scrollToPosition(0)
|
||||
}
|
||||
|
||||
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, userHandle: UserHandle) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun onShortcut(
|
||||
appInfo: LauncherActivityInfo,
|
||||
userHandle: UserHandle,
|
||||
textView: TextView,
|
||||
userProfile: Int,
|
||||
shortcutView: TextView
|
||||
) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun onItemLongClick(
|
||||
appInfo: LauncherActivityInfo,
|
||||
userHandle: UserHandle,
|
||||
userProfile: Int,
|
||||
textView: TextView,
|
||||
actionMenuLayout: LinearLayout,
|
||||
editView: LinearLayout,
|
||||
position: Int
|
||||
) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
|
|
@ -77,9 +77,6 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
|
||||
private lateinit var dateText: TextClock
|
||||
|
||||
private var cameraSwipeEnabled = true
|
||||
private var phoneSwipeEnabled = true
|
||||
|
||||
private lateinit var preferences: SharedPreferences
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
|
|
|
|||
|
|
@ -20,6 +20,10 @@ class SettingsActivity : AppCompatActivity() {
|
|||
.commit()
|
||||
}
|
||||
|
||||
fun showHiddenApps() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
private lateinit var binding: ActivitySettingsBinding
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
setPreferencesFromResource(R.xml.root_preferences, rootKey)
|
||||
|
||||
val gpsLocationPref: SwitchPreference? = findPreference("gps_location")
|
||||
val manualLocationPref: ButtonPreference? = findPreference("manual_location")
|
||||
val manualLocationPref: Preference? = findPreference("manual_location")
|
||||
|
||||
if (gpsLocationPref != null && manualLocationPref != null) {
|
||||
// Initial setup
|
||||
|
|
@ -25,5 +25,14 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
true // Returning true means the change is persisted
|
||||
}
|
||||
}
|
||||
|
||||
findPreference<Preference?>("hidden_apps")?.onPreferenceClickListener =
|
||||
Preference.OnPreferenceClickListener {
|
||||
activity?.supportFragmentManager
|
||||
?.beginTransaction()
|
||||
?.replace(R.id.settings_layout, HiddenAppsFragment())
|
||||
?.addToBackStack(null)
|
||||
?.commit()
|
||||
true }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<FrameLayout 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/settingsLayout"
|
||||
|
|
@ -9,14 +9,11 @@
|
|||
android:orientation="vertical"
|
||||
tools:context=".SettingsActivity">
|
||||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/settings_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:paddingTop="40dp">
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
|
@ -460,4 +457,4 @@
|
|||
tools:layout_editor_absoluteY="810dp" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
67
app/src/main/res/layout/fragment_hidden_apps.xml
Normal file
67
app/src/main/res/layout/fragment_hidden_apps.xml
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
<?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/hidden_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/hidden_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="Unhide an app"
|
||||
android:textAppearance="@android:style/TextAppearance.DeviceDefault"
|
||||
android:textColor="#C1F3F3F3"
|
||||
android:textSize="36sp" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/hidden_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/hiddenAppSearch"
|
||||
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>
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/location_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
|
@ -120,7 +120,7 @@
|
|||
android:defaultValue="false"
|
||||
android:title="GPS Location"
|
||||
app:key="gps_location" />
|
||||
<eu.ottop.yamlauncher.ButtonPreference
|
||||
<Preference
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:key="manual_location"
|
||||
|
|
@ -132,7 +132,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
app:allowDividerAbove="false"
|
||||
app:title="Hidden Apps">
|
||||
<eu.ottop.yamlauncher.ButtonPreference
|
||||
<Preference
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:key="hidden_apps"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue