mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-05 01:47:24 +00:00
Renaming implemented and added a clock to main view.
This commit is contained in:
parent
109b849a6e
commit
3adaa4a8b0
2 changed files with 61 additions and 16 deletions
|
|
@ -15,6 +15,7 @@ import android.os.UserHandle
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.inputmethod.EditorInfo
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import android.webkit.RenderProcessGoneDetail
|
import android.webkit.RenderProcessGoneDetail
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
|
|
@ -224,11 +225,8 @@ class AppMenuActivity : AppCompatActivity() {
|
||||||
focusable = View.FOCUSABLE
|
focusable = View.FOCUSABLE
|
||||||
gravity = Gravity.START
|
gravity = Gravity.START
|
||||||
|
|
||||||
text = if (workProfile != 0) {
|
text = getAppName(appInfo.packageName, workProfile, appInfo.loadLabel(packageManager))
|
||||||
"*" + appInfo.loadLabel(packageManager)
|
if (workProfile != 0) {text = "*" + text}
|
||||||
} else {
|
|
||||||
appInfo.loadLabel(packageManager)
|
|
||||||
}
|
|
||||||
setTextColor(ColorStateList(states, colors))
|
setTextColor(ColorStateList(states, colors))
|
||||||
}
|
}
|
||||||
with(editText) {
|
with(editText) {
|
||||||
|
|
@ -245,6 +243,7 @@ class AppMenuActivity : AppCompatActivity() {
|
||||||
isSingleLine = true
|
isSingleLine = true
|
||||||
setTextColor(ColorStateList(states, colors))
|
setTextColor(ColorStateList(states, colors))
|
||||||
background = null
|
background = null
|
||||||
|
imeOptions = EditorInfo.IME_ACTION_DONE
|
||||||
}
|
}
|
||||||
editText.setText(textView.text)
|
editText.setText(textView.text)
|
||||||
}
|
}
|
||||||
|
|
@ -305,7 +304,6 @@ class AppMenuActivity : AppCompatActivity() {
|
||||||
textView.visibility = View.INVISIBLE
|
textView.visibility = View.INVISIBLE
|
||||||
|
|
||||||
popupWindow.showAsDropDown(textView, 0, -textView.height)
|
popupWindow.showAsDropDown(textView, 0, -textView.height)
|
||||||
|
|
||||||
var editing = false
|
var editing = false
|
||||||
popupWindow.setOnDismissListener {
|
popupWindow.setOnDismissListener {
|
||||||
if (!editing) {textView.visibility = View.VISIBLE}
|
if (!editing) {textView.visibility = View.VISIBLE}
|
||||||
|
|
@ -339,14 +337,37 @@ class AppMenuActivity : AppCompatActivity() {
|
||||||
editing = true
|
editing = true
|
||||||
popupWindow.dismiss()
|
popupWindow.dismiss()
|
||||||
val editText = editLayout.findViewById<EditText>(R.id.app_name)
|
val editText = editLayout.findViewById<EditText>(R.id.app_name)
|
||||||
|
|
||||||
editText.requestFocus()
|
editText.requestFocus()
|
||||||
val imm = this.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
|
||||||
|
|
||||||
val handler = Handler(Looper.getMainLooper())
|
val handler = Handler(Looper.getMainLooper())
|
||||||
handler.postDelayed({
|
handler.postDelayed({
|
||||||
val imm = this.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT)
|
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT)
|
||||||
}, 100) // Adjust delay as needed
|
binding.appList.scrollToDescendant(textView)
|
||||||
|
}, 100)
|
||||||
|
|
||||||
|
binding.root.addOnLayoutChangeListener {
|
||||||
|
_, _, top, _, bottom, _, oldTop, _, oldBottom ->
|
||||||
|
if (bottom - top > oldBottom - oldTop) {
|
||||||
|
editing = false
|
||||||
|
editLayout.clearFocus()
|
||||||
|
|
||||||
|
editLayout.visibility = View.GONE
|
||||||
|
textView.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
editText.setOnEditorActionListener { _, actionId, _ ->
|
||||||
|
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||||
|
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
|
imm.hideSoftInputFromWindow(editText.windowToken, 0)
|
||||||
|
setAppName(appInfo.packageName, workProfile, editText.text.toString())
|
||||||
|
refreshAppMenu()
|
||||||
|
|
||||||
|
return@setOnEditorActionListener true
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
popupView.findViewById<TextView>(R.id.hide).setOnClickListener {
|
popupView.findViewById<TextView>(R.id.hide).setOnClickListener {
|
||||||
|
|
@ -362,7 +383,7 @@ class AppMenuActivity : AppCompatActivity() {
|
||||||
private fun setAppHidden(packageName: String, profile: Int, hidden: Boolean) {
|
private fun setAppHidden(packageName: String, profile: Int, hidden: Boolean) {
|
||||||
// Get the shared preferences editor
|
// Get the shared preferences editor
|
||||||
val editor = getSharedPreferences("hidden_apps", MODE_PRIVATE).edit()
|
val editor = getSharedPreferences("hidden_apps", MODE_PRIVATE).edit()
|
||||||
val key = "$packageName-${profile}"
|
val key = "$packageName-$profile"
|
||||||
editor.putBoolean(key, hidden)
|
editor.putBoolean(key, hidden)
|
||||||
editor.apply()
|
editor.apply()
|
||||||
}
|
}
|
||||||
|
|
@ -370,15 +391,28 @@ class AppMenuActivity : AppCompatActivity() {
|
||||||
private fun isAppHidden(packageName: String, profile: Int): Boolean {
|
private fun isAppHidden(packageName: String, profile: Int): Boolean {
|
||||||
// Get the shared preferences object
|
// Get the shared preferences object
|
||||||
val sharedPref = getSharedPreferences("hidden_apps", MODE_PRIVATE)
|
val sharedPref = getSharedPreferences("hidden_apps", MODE_PRIVATE)
|
||||||
val key = "$packageName-${profile}"
|
val key = "$packageName-$profile"
|
||||||
return sharedPref.getBoolean(key, false) // Default to false (visible)
|
return sharedPref.getBoolean(key, false) // Default to false (visible)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setAppVisible(packageName: String, profile: Int) {
|
private fun setAppVisible(packageName: String, profile: Int) {
|
||||||
// Get the shared preferences editor
|
// Get the shared preferences editor
|
||||||
val editor = getSharedPreferences("hidden_apps", MODE_PRIVATE).edit()
|
val editor = getSharedPreferences("hidden_apps", MODE_PRIVATE).edit()
|
||||||
val key = "$packageName-${profile}"
|
val key = "$packageName-$profile"
|
||||||
editor.remove(key)
|
editor.remove(key)
|
||||||
editor.apply()
|
editor.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setAppName(packageName: String, profile: Int, newName: String) {
|
||||||
|
val editor = getSharedPreferences("renamed_apps", MODE_PRIVATE).edit()
|
||||||
|
val key = "$packageName-$profile"
|
||||||
|
editor.putString(key, newName)
|
||||||
|
editor.apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getAppName(packageName: String, profile: Int, appName: CharSequence): CharSequence? {
|
||||||
|
val sharedPreferences = getSharedPreferences("renamed_apps", MODE_PRIVATE)
|
||||||
|
val key = "$packageName-$profile"
|
||||||
|
return sharedPreferences.getString(key, appName.toString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,9 +2,9 @@
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/apps"
|
android:id="@+id/home_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="bottom"
|
android:layout_gravity="bottom"
|
||||||
android:fillViewport="true"
|
android:fillViewport="true"
|
||||||
android:fitsSystemWindows="true"
|
android:fitsSystemWindows="true"
|
||||||
|
|
@ -12,11 +12,22 @@
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:context=".MainActivity">
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
|
<TextClock
|
||||||
|
android:id="@+id/text_clock"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_marginVertical="20dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textColor="#F3F3F3"
|
||||||
|
android:textSize="70sp" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button"
|
android:id="@+id/button"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Button"
|
android:layout_weight="0.1"
|
||||||
android:onClick="openAppMenuActivity"/>
|
android:onClick="openAppMenuActivity"
|
||||||
|
android:text="Button" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue