diff --git a/app/src/main/java/eu/ottop/yamlauncher/AppActionMenu.kt b/app/src/main/java/eu/ottop/yamlauncher/AppActionMenu.kt index e6e4169..297a657 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/AppActionMenu.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/AppActionMenu.kt @@ -20,12 +20,10 @@ import eu.ottop.yamlauncher.databinding.ActivityMainBinding import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext class AppActionMenu { private val sharedPreferenceManager = SharedPreferenceManager() - private val appUtils = AppUtils() private val animations = Animations() fun setActionListeners( @@ -39,8 +37,7 @@ class AppActionMenu { userHandle: UserHandle, workProfile: Int, launcherApps: LauncherApps, - mainActivity: LauncherActivityInfo?, - position: Int + mainActivity: LauncherActivityInfo? ){ actionMenu.findViewById(R.id.info).setOnClickListener { diff --git a/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt b/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt index f40f969..27db6fa 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt @@ -2,6 +2,7 @@ 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 @@ -12,9 +13,11 @@ import android.view.inputmethod.InputMethodManager import android.widget.EditText import android.widget.FrameLayout import android.widget.LinearLayout +import android.widget.Space import android.widget.TextView import androidx.appcompat.widget.AppCompatButton import androidx.core.content.res.ResourcesCompat +import androidx.core.view.marginLeft import androidx.fragment.app.FragmentActivity import androidx.recyclerview.widget.RecyclerView @@ -55,8 +58,9 @@ class AppMenuAdapter( 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) - val editView: LinearLayout = listItem.findViewById(R.id.rename_view) + 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 @@ -116,7 +120,6 @@ class AppMenuAdapter( 1 = center 2 = right */ - when (sharedPreferenceManager.getAppMenuAlignment(activity)) { 0 -> { holder.textView.setCompoundDrawablesWithIntrinsicBounds(holder.textView.compoundDrawables.filterNotNull().first(),null, null, null) @@ -125,6 +128,7 @@ class AppMenuAdapter( 1 -> { holder.textView.setCompoundDrawablesWithIntrinsicBounds(holder.textView.compoundDrawables.filterNotNull().first(),null,holder.textView.compoundDrawables.filterNotNull().first(), null) holder.textView.gravity = Gravity.CENTER + } 2 -> { holder.textView.setCompoundDrawablesWithIntrinsicBounds(null,null, holder.textView.compoundDrawables.filterNotNull().first(), null) @@ -132,28 +136,42 @@ class AppMenuAdapter( } } + /* + 0 = small + 1 = medium + 2 = large + + Text sizes hardcoded because code returns 77 instead of 28 + */ + when (sharedPreferenceManager.getAppSize(activity)) { + 0 -> { + holder.textView.textSize = 24F + holder.editText.textSize = 24F + } + + 1 -> { + holder.textView.textSize = 26F + holder.editText.textSize = 26F + } + + 2 -> { + 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.editView.findViewById(R.id.app_name_edit).setText(holder.textView.text) - holder.textView.visibility = View.VISIBLE - } + holder.editText.setText(holder.textView.text) - override fun onViewAttachedToWindow(holder: AppViewHolder) { - super.onViewAttachedToWindow(holder) - when (sharedPreferenceManager.getAppMenuAlignment(activity)) { - 0 -> { - holder.textView.setCompoundDrawablesWithIntrinsicBounds(holder.textView.compoundDrawables.filterNotNull().first(),null, null, null) - holder.textView.gravity = Gravity.CENTER_VERTICAL or Gravity.START - } - 1 -> { - holder.textView.setCompoundDrawablesWithIntrinsicBounds(holder.textView.compoundDrawables.filterNotNull().first(),null,holder.textView.compoundDrawables.filterNotNull().first(), null) - holder.textView.gravity = Gravity.CENTER - } - 2 -> { - holder.textView.setCompoundDrawablesWithIntrinsicBounds(null,null, holder.textView.compoundDrawables.filterNotNull().first(), null) - holder.textView.gravity = Gravity.CENTER_VERTICAL or Gravity.END - } + if (appInfo.flags and ApplicationInfo.FLAG_SYSTEM != 0) { + holder.actionMenuLayout.findViewById(R.id.uninstall).visibility = View.GONE } + else { + holder.actionMenuLayout.findViewById(R.id.uninstall).visibility = View.VISIBLE + } + + holder.textView.visibility = View.VISIBLE } override fun getItemCount(): Int { diff --git a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt index 822244e..4fdfc7d 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt @@ -17,7 +17,6 @@ import android.view.GestureDetector import android.view.Gravity import android.view.MotionEvent import android.view.View -import android.view.ViewTreeObserver import android.view.inputmethod.InputMethodManager import android.widget.EditText import android.widget.LinearLayout @@ -83,6 +82,8 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap setContentView(binding.root) setSupportActionBar(null) + searchView = findViewById(R.id.searchView) + launcherApps = getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps gestureDetector = GestureDetector(this, GestureListener()) @@ -131,14 +132,16 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap @SuppressLint("NotifyDataSetChanged") override fun onStart() { - setShortcutSize(binding.homeView) + setTextSizes() super.onStart() startTask() // Keyboard is sometimes open when going back to the app, so close it. closeKeyboard() + setClockAlignment() setShortCutAlignment() + setSearchAlignment() adapter?.notifyDataSetChanged() @@ -207,7 +210,6 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap setupRecyclerView(newApps) - searchView = findViewById(R.id.searchView) setupSearch() } @@ -489,8 +491,7 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap userHandle, userProfile, launcherApps, - mainActivity, - position + mainActivity ) } @@ -595,7 +596,7 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap 1 = medium 2 = large */ - when (sharedPreferenceManager.getAppSize(this@MainActivity)) { + when (sharedPreferenceManager.getShortcutSize(this@MainActivity)) { 0 -> { it.setPadding( it.paddingLeft, @@ -608,9 +609,9 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap 1 -> { it.setPadding( it.paddingLeft, - it.height / 5, + (it.height / 4.5).toInt(), it.paddingRight, - it.height / 5 + (it.height / 4.5).toInt() ) } @@ -655,6 +656,72 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap } } + private fun setSearchAlignment() { + + /* + 0 = left + 1 = center + 2 = right + */ + when (sharedPreferenceManager.getSearchAlignment(this@MainActivity)) { + 0 -> { + searchView.textAlignment = View.TEXT_ALIGNMENT_VIEW_START + } + 1 -> { + searchView.textAlignment = View.TEXT_ALIGNMENT_CENTER + } + 2 -> { + searchView.textAlignment = View.TEXT_ALIGNMENT_VIEW_END + } + } + } + + private fun setTextSizes() { + setShortcutSize(binding.homeView) + + /* + 0 = small + 1 = medium + 2 = large + */ + + when (sharedPreferenceManager.getClockSize(this@MainActivity)) { + 0 -> { + clock.textSize = 48F + } + 1 -> { + clock.textSize = 58F + } + 2 -> { + clock.textSize = 68F + } + } + + when (sharedPreferenceManager.getDateSize(this@MainActivity)) { + 0 -> { + dateText.textSize = 17F + } + 1 -> { + dateText.textSize = 20F + } + 2 -> { + dateText.textSize = 23F + } + } + + when (sharedPreferenceManager.getSearchSize(this@MainActivity)) { + 0 -> { + searchView.textSize = 21F + } + 1 -> { + searchView.textSize = 23F + } + 2 -> { + searchView.textSize = 25F + } + } + } + fun isJobActive(): Boolean { return if (job != null) { job!!.isActive diff --git a/app/src/main/java/eu/ottop/yamlauncher/SettingsActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/SettingsActivity.kt index 8e8c997..075c3c2 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/SettingsActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/SettingsActivity.kt @@ -51,6 +51,54 @@ class SettingsActivity : AppCompatActivity() { } } + binding.searchAlignment.setSelection(sharedPreferenceManager.getSearchAlignment(this@SettingsActivity)) + + binding.searchAlignment.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected(parent: AdapterView<*>, view: View?, position: Int, id: Long) { + // Get the selected item + sharedPreferenceManager.setSearchAlignment(this@SettingsActivity, position) + } + + override fun onNothingSelected(parent: AdapterView<*>) { + } + } + + binding.clockSize.setSelection(sharedPreferenceManager.getClockSize(this@SettingsActivity)) + + binding.clockSize.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected(parent: AdapterView<*>, view: View?, position: Int, id: Long) { + // Get the selected item + sharedPreferenceManager.setClockSize(this@SettingsActivity, position) + } + + override fun onNothingSelected(parent: AdapterView<*>) { + } + } + + binding.dateSize.setSelection(sharedPreferenceManager.getDateSize(this@SettingsActivity)) + + binding.dateSize.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected(parent: AdapterView<*>, view: View?, position: Int, id: Long) { + // Get the selected item + sharedPreferenceManager.setDateSize(this@SettingsActivity, position) + } + + override fun onNothingSelected(parent: AdapterView<*>) { + } + } + + binding.shortcutSize.setSelection(sharedPreferenceManager.getShortcutSize(this@SettingsActivity)) + + binding.shortcutSize.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected(parent: AdapterView<*>, view: View?, position: Int, id: Long) { + // Get the selected item + sharedPreferenceManager.setShortcutSize(this@SettingsActivity, position) + } + + override fun onNothingSelected(parent: AdapterView<*>) { + } + } + binding.appSize.setSelection(sharedPreferenceManager.getAppSize(this@SettingsActivity)) binding.appSize.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { @@ -62,5 +110,17 @@ class SettingsActivity : AppCompatActivity() { override fun onNothingSelected(parent: AdapterView<*>) { } } + + binding.searchSize.setSelection(sharedPreferenceManager.getSearchSize(this@SettingsActivity)) + + binding.searchSize.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected(parent: AdapterView<*>, view: View?, position: Int, id: Long) { + // Get the selected item + sharedPreferenceManager.setSearchSize(this@SettingsActivity, position) + } + + override fun onNothingSelected(parent: AdapterView<*>) { + } + } } } \ No newline at end of file diff --git a/app/src/main/java/eu/ottop/yamlauncher/SharedPreferenceManager.kt b/app/src/main/java/eu/ottop/yamlauncher/SharedPreferenceManager.kt index a8ca78f..4b9ef9d 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/SharedPreferenceManager.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/SharedPreferenceManager.kt @@ -112,6 +112,58 @@ class SharedPreferenceManager { return sharedPreferences.getInt(key, 0) } + fun setSearchAlignment(cont: Context, alignment: Int) { + val editor = cont.getSharedPreferences("preferences", AppCompatActivity.MODE_PRIVATE).edit() + val key = "search_alignment" + editor.putInt(key, alignment) + editor.apply() + } + + fun getSearchAlignment(cont: Context) : Int { + val sharedPreferences = cont.getSharedPreferences("preferences", AppCompatActivity.MODE_PRIVATE) + val key = "search_alignment" + return sharedPreferences.getInt(key, 0) + } + + fun setClockSize(cont: Context, alignment: Int) { + val editor = cont.getSharedPreferences("preferences", AppCompatActivity.MODE_PRIVATE).edit() + val key = "clock_size" + editor.putInt(key, alignment) + editor.apply() + } + + fun getClockSize(cont: Context) : Int { + val sharedPreferences = cont.getSharedPreferences("preferences", AppCompatActivity.MODE_PRIVATE) + val key = "clock_size" + return sharedPreferences.getInt(key, 2) + } + + fun setDateSize(cont: Context, alignment: Int) { + val editor = cont.getSharedPreferences("preferences", AppCompatActivity.MODE_PRIVATE).edit() + val key = "date_size" + editor.putInt(key, alignment) + editor.apply() + } + + fun getDateSize(cont: Context) : Int { + val sharedPreferences = cont.getSharedPreferences("preferences", AppCompatActivity.MODE_PRIVATE) + val key = "date_size" + return sharedPreferences.getInt(key, 2) + } + + fun setShortcutSize(cont: Context, alignment: Int) { + val editor = cont.getSharedPreferences("preferences", AppCompatActivity.MODE_PRIVATE).edit() + val key = "shortcut_size" + editor.putInt(key, alignment) + editor.apply() + } + + fun getShortcutSize(cont: Context) : Int { + val sharedPreferences = cont.getSharedPreferences("preferences", AppCompatActivity.MODE_PRIVATE) + val key = "shortcut_size" + return sharedPreferences.getInt(key, 2) + } + fun setAppSize(cont: Context, alignment: Int) { val editor = cont.getSharedPreferences("preferences", AppCompatActivity.MODE_PRIVATE).edit() val key = "app_size" @@ -124,4 +176,17 @@ class SharedPreferenceManager { val key = "app_size" return sharedPreferences.getInt(key, 2) } + + fun setSearchSize(cont: Context, alignment: Int) { + val editor = cont.getSharedPreferences("preferences", AppCompatActivity.MODE_PRIVATE).edit() + val key = "search_size" + editor.putInt(key, alignment) + editor.apply() + } + + fun getSearchSize(cont: Context) : Int { + val sharedPreferences = cont.getSharedPreferences("preferences", AppCompatActivity.MODE_PRIVATE) + val key = "search_size" + return sharedPreferences.getInt(key, 2) + } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 4ac2768..b725bdd 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -65,6 +65,7 @@ android:editTextColor="#f3f3f3" android:hint="@string/search" android:singleLine="true" + android:textAlignment="viewStart" android:textAppearance="@android:style/TextAppearance.DeviceDefault" android:textSize="25sp" /> @@ -92,13 +93,16 @@ android:layout_marginHorizontal="32dp" android:layout_marginStart="32dp" android:layout_marginTop="40dp" + android:layout_marginBottom="27dp" android:fontFamily="@null" android:format12Hour="hh:mm a" android:format24Hour="HH:mm" + android:gravity="bottom" android:textAlignment="textStart" android:textAppearance="@android:style/TextAppearance.DeviceDefault" android:textColor="#F3F3F3" android:textSize="68sp" + app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -122,7 +126,7 @@ + android:layout_weight="0.25" /> + + + + + + + + + + + + + + + + + + + + + + + + + app:layout_constraintStart_toEndOf="@+id/shortcut_size_label" + app:layout_constraintTop_toTopOf="@+id/app_size_label" /> + + + + + + \ No newline at end of file