mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-04 17:37:25 +00:00
Some kind of a preliminary widget menu
This commit is contained in:
parent
114bb560ea
commit
757c55fa29
9 changed files with 196 additions and 3 deletions
|
|
@ -50,4 +50,6 @@ dependencies {
|
||||||
implementation("com.google.android.material:material:1.12.0")
|
implementation("com.google.android.material:material:1.12.0")
|
||||||
implementation("androidx.recyclerview:recyclerview:1.3.2")
|
implementation("androidx.recyclerview:recyclerview:1.3.2")
|
||||||
implementation("androidx.preference:preference-ktx:1.2.1")
|
implementation("androidx.preference:preference-ktx:1.2.1")
|
||||||
|
implementation("androidx.activity:activity:1.9.2")
|
||||||
|
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
|
||||||
}
|
}
|
||||||
|
|
@ -8,7 +8,8 @@
|
||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||||
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||||
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
|
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
|
||||||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
|
<uses-permission
|
||||||
|
android:name="android.permission.QUERY_ALL_PACKAGES"
|
||||||
tools:ignore="QueryAllPackagesPermission" />
|
tools:ignore="QueryAllPackagesPermission" />
|
||||||
|
|
||||||
<queries>
|
<queries>
|
||||||
|
|
@ -28,12 +29,15 @@
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.YamLauncher"
|
android:theme="@style/Theme.YamLauncher"
|
||||||
tools:targetApi="34">
|
tools:targetApi="34">
|
||||||
|
<activity
|
||||||
|
android:name=".widgets.WidgetsActivity"
|
||||||
|
android:exported="false" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".settings.SettingsActivity"
|
android:name=".settings.SettingsActivity"
|
||||||
android:theme="@style/SettingsTheme"
|
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
tools:ignore="DiscouragedApi,LockedOrientationActivity"/>
|
android:theme="@style/SettingsTheme"
|
||||||
|
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:excludeFromRecents="true"
|
android:excludeFromRecents="true"
|
||||||
|
|
@ -51,6 +55,7 @@
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".tasks.ScreenLockService"
|
android:name=".tasks.ScreenLockService"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ import eu.ottop.yamlauncher.utils.PermissionUtils
|
||||||
import eu.ottop.yamlauncher.utils.StringUtils
|
import eu.ottop.yamlauncher.utils.StringUtils
|
||||||
import eu.ottop.yamlauncher.utils.UIUtils
|
import eu.ottop.yamlauncher.utils.UIUtils
|
||||||
import eu.ottop.yamlauncher.utils.WeatherSystem
|
import eu.ottop.yamlauncher.utils.WeatherSystem
|
||||||
|
import eu.ottop.yamlauncher.widgets.WidgetsActivity
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
@ -161,6 +162,10 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setupApps()
|
setupApps()
|
||||||
|
|
||||||
|
binding.widgets.setOnClickListener {
|
||||||
|
startActivity(Intent(this@MainActivity, WidgetsActivity::class.java))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setMainVariables() {
|
private fun setMainVariables() {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
package eu.ottop.yamlauncher.widgets
|
||||||
|
|
||||||
|
import android.appwidget.AppWidgetProviderInfo
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.ImageView
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import eu.ottop.yamlauncher.R
|
||||||
|
|
||||||
|
class WidgetAdapter(
|
||||||
|
private val widgetItems: List<WidgetItem>,
|
||||||
|
private val onWidgetSelected: (AppWidgetProviderInfo) -> Unit
|
||||||
|
) : RecyclerView.Adapter<WidgetAdapter.WidgetViewHolder>() {
|
||||||
|
|
||||||
|
inner class WidgetViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||||
|
val iconView: ImageView = view.findViewById(R.id.widget_icon)
|
||||||
|
val labelView: TextView = view.findViewById(R.id.widget_label)
|
||||||
|
|
||||||
|
fun bind(item: WidgetItem) {
|
||||||
|
iconView.setImageDrawable(item.icon)
|
||||||
|
labelView.text = item.label
|
||||||
|
itemView.setOnClickListener { onWidgetSelected(item.widgetInfo) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WidgetViewHolder {
|
||||||
|
val view = LayoutInflater.from(parent.context).inflate(R.layout.widget_item, parent, false)
|
||||||
|
return WidgetViewHolder(view)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: WidgetViewHolder, position: Int) {
|
||||||
|
holder.bind(widgetItems[position])
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemCount() = widgetItems.size
|
||||||
|
}
|
||||||
10
app/src/main/java/eu/ottop/yamlauncher/widgets/WidgetItem.kt
Normal file
10
app/src/main/java/eu/ottop/yamlauncher/widgets/WidgetItem.kt
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
package eu.ottop.yamlauncher.widgets
|
||||||
|
|
||||||
|
import android.appwidget.AppWidgetProviderInfo
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
|
||||||
|
data class WidgetItem(
|
||||||
|
val label: String,
|
||||||
|
val icon: Drawable?,
|
||||||
|
val widgetInfo: AppWidgetProviderInfo
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
package eu.ottop.yamlauncher.widgets
|
||||||
|
|
||||||
|
import android.app.PendingIntent
|
||||||
|
import android.appwidget.AppWidgetHost
|
||||||
|
import android.appwidget.AppWidgetManager
|
||||||
|
import android.appwidget.AppWidgetProviderInfo
|
||||||
|
import android.content.ComponentName
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.util.DisplayMetrics
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.activity.enableEdgeToEdge
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.view.ViewCompat
|
||||||
|
import androidx.core.view.WindowInsetsCompat
|
||||||
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import eu.ottop.yamlauncher.R
|
||||||
|
import eu.ottop.yamlauncher.databinding.ActivityMainBinding
|
||||||
|
import eu.ottop.yamlauncher.databinding.ActivityWidgetsBinding
|
||||||
|
|
||||||
|
class WidgetsActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
private lateinit var binding: ActivityWidgetsBinding
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
binding = ActivityWidgetsBinding.inflate(layoutInflater)
|
||||||
|
|
||||||
|
setContentView(binding.root)
|
||||||
|
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
|
||||||
|
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||||
|
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
|
||||||
|
insets
|
||||||
|
}
|
||||||
|
binding.button.setOnClickListener {
|
||||||
|
showWidgetSelectionRecyclerDialog(this) {println("hi")}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun showWidgetSelectionRecyclerDialog(context: Context, onWidgetSelected: (AppWidgetProviderInfo) -> Unit) {
|
||||||
|
val dialog = AlertDialog.Builder(context).create()
|
||||||
|
val recyclerView = RecyclerView(context).apply {
|
||||||
|
layoutManager = GridLayoutManager(this@WidgetsActivity, 2)
|
||||||
|
adapter = WidgetAdapter(prepareWidgetItems(context), onWidgetSelected)
|
||||||
|
}
|
||||||
|
dialog.setView(recyclerView)
|
||||||
|
dialog.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun prepareWidgetItems(context: Context): List<WidgetItem> {
|
||||||
|
val widgets = getAvailableWidgets(context)
|
||||||
|
return widgets.map { widgetInfo ->
|
||||||
|
val icon = widgetInfo.loadPreviewImage(this, DisplayMetrics.DENSITY_DEFAULT) ?: widgetInfo.loadIcon(this, DisplayMetrics.DENSITY_DEFAULT)
|
||||||
|
WidgetItem(widgetInfo.loadLabel(packageManager), icon, widgetInfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getAvailableWidgets(context: Context): List<AppWidgetProviderInfo> {
|
||||||
|
val appWidgetManager = AppWidgetManager.getInstance(context)
|
||||||
|
return appWidgetManager.installedProviders
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -190,6 +190,22 @@
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="0.22" />
|
android:layout_weight="0.22" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/widgets"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="0.09"
|
||||||
|
android:autoSizeTextType="uniform"
|
||||||
|
android:clickable="false"
|
||||||
|
android:drawablePadding="3dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:paddingHorizontal="20dp"
|
||||||
|
android:shadowColor="#00FFFFFF"
|
||||||
|
android:shadowRadius="10"
|
||||||
|
android:text="Widgets"
|
||||||
|
android:textAppearance="@android:style/TextAppearance.DeviceDefault"
|
||||||
|
android:textColor="#F3F3F3"
|
||||||
|
android:visibility="visible" />
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/app1"
|
android:id="@+id/app1"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
||||||
24
app/src/main/res/layout/activity_widgets.xml
Normal file
24
app/src/main/res/layout/activity_widgets.xml
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout 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/main"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".widgets.WidgetsActivity">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="160dp"
|
||||||
|
android:layout_marginTop="341dp"
|
||||||
|
android:layout_marginEnd="160dp"
|
||||||
|
android:layout_marginBottom="342dp"
|
||||||
|
android:clickable="false"
|
||||||
|
android:text="Button"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
26
app/src/main/res/layout/widget_item.xml
Normal file
26
app/src/main/res/layout/widget_item.xml
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- res/layout/widget_item.xml -->
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="8dp">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/widget_icon"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="100dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:contentDescription=""
|
||||||
|
android:paddingBottom="10dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/widget_label"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:paddingBottom="20dp"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textAllCaps="false"
|
||||||
|
android:textSize="16sp" />
|
||||||
|
</LinearLayout>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue