mirror of
https://github.com/jrpie/Launcher.git
synced 2025-05-17 16:01:10 +02:00
add debug info widget in debug mode
This commit is contained in:
parent
5f2d0aa426
commit
8173993601
11 changed files with 112 additions and 24 deletions
|
@ -16,6 +16,7 @@ import de.jrpie.android.launcher.preferences.legacy.migratePreferencesFromVersio
|
|||
import de.jrpie.android.launcher.preferences.legacy.migratePreferencesFromVersionUnknown
|
||||
import de.jrpie.android.launcher.ui.HomeActivity
|
||||
import de.jrpie.android.launcher.widgets.ClockWidget
|
||||
import de.jrpie.android.launcher.widgets.DebugInfoWidget
|
||||
import de.jrpie.android.launcher.widgets.WidgetPanel
|
||||
import de.jrpie.android.launcher.widgets.WidgetPosition
|
||||
import de.jrpie.android.launcher.widgets.deleteAllWidgets
|
||||
|
@ -95,17 +96,33 @@ fun resetPreferences(context: Context) {
|
|||
)
|
||||
)
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
LauncherPreferences.widgets().widgets(
|
||||
LauncherPreferences.widgets().widgets().also {
|
||||
it.add(
|
||||
DebugInfoWidget(
|
||||
(context.applicationContext as Application).appWidgetHost.allocateAppWidgetId(),
|
||||
WidgetPosition(1, 1, 10, 4),
|
||||
WidgetPanel.HOME.id
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
val hidden: MutableSet<AbstractAppInfo> = mutableSetOf()
|
||||
val launcher = DetailedAppInfo.fromAppInfo(
|
||||
AppInfo(
|
||||
BuildConfig.APPLICATION_ID,
|
||||
HomeActivity::class.java.name,
|
||||
INVALID_USER
|
||||
), context
|
||||
)
|
||||
launcher?.getRawInfo()?.let { hidden.add(it) }
|
||||
Log.i(TAG,"Hiding ${launcher?.getRawInfo()}")
|
||||
|
||||
if (!BuildConfig.DEBUG) {
|
||||
val launcher = DetailedAppInfo.fromAppInfo(
|
||||
AppInfo(
|
||||
BuildConfig.APPLICATION_ID,
|
||||
HomeActivity::class.java.name,
|
||||
INVALID_USER
|
||||
), context
|
||||
)
|
||||
launcher?.getRawInfo()?.let { hidden.add(it) }
|
||||
Log.i(TAG, "Hiding ${launcher?.getRawInfo()}")
|
||||
}
|
||||
LauncherPreferences.apps().hidden(hidden)
|
||||
|
||||
Action.resetToDefaultActions(context)
|
||||
|
|
|
@ -12,11 +12,10 @@ import android.view.MotionEvent
|
|||
import android.view.View
|
||||
import android.window.OnBackInvokedDispatcher
|
||||
import de.jrpie.android.launcher.Application
|
||||
import de.jrpie.android.launcher.R
|
||||
import de.jrpie.android.launcher.actions.Action
|
||||
import de.jrpie.android.launcher.actions.Gesture
|
||||
import de.jrpie.android.launcher.actions.LauncherAction
|
||||
import de.jrpie.android.launcher.databinding.HomeBinding
|
||||
import de.jrpie.android.launcher.databinding.ActivityHomeBinding
|
||||
import de.jrpie.android.launcher.openTutorial
|
||||
import de.jrpie.android.launcher.preferences.LauncherPreferences
|
||||
import de.jrpie.android.launcher.ui.tutorial.TutorialActivity
|
||||
|
@ -35,7 +34,7 @@ import de.jrpie.android.launcher.ui.tutorial.TutorialActivity
|
|||
*/
|
||||
class HomeActivity : UIObject, Activity() {
|
||||
|
||||
private lateinit var binding: HomeBinding
|
||||
private lateinit var binding: ActivityHomeBinding
|
||||
private var touchGestureDetector: TouchGestureDetector? = null
|
||||
|
||||
private var sharedPreferencesListener =
|
||||
|
@ -60,7 +59,7 @@ class HomeActivity : UIObject, Activity() {
|
|||
|
||||
|
||||
// Initialise layout
|
||||
binding = HomeBinding.inflate(layoutInflater)
|
||||
binding = ActivityHomeBinding.inflate(layoutInflater)
|
||||
|
||||
setContentView(binding.root)
|
||||
|
||||
|
|
|
@ -6,13 +6,13 @@ import android.view.LayoutInflater
|
|||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.view.isVisible
|
||||
import de.jrpie.android.launcher.actions.Gesture
|
||||
import de.jrpie.android.launcher.databinding.ClockBinding
|
||||
import de.jrpie.android.launcher.databinding.WidgetClockBinding
|
||||
import de.jrpie.android.launcher.preferences.LauncherPreferences
|
||||
import java.util.Locale
|
||||
|
||||
class ClockView(context: Context, attrs: AttributeSet? = null, val appWidgetId: Int): ConstraintLayout(context, attrs) {
|
||||
|
||||
val binding: ClockBinding = ClockBinding.inflate(LayoutInflater.from(context), this, true)
|
||||
val binding: WidgetClockBinding = WidgetClockBinding.inflate(LayoutInflater.from(context), this, true)
|
||||
init {
|
||||
initClock()
|
||||
setOnClicks()
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package de.jrpie.android.launcher.ui.widgets
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import de.jrpie.android.launcher.databinding.WidgetDebugInfoBinding
|
||||
import de.jrpie.android.launcher.getDeviceInfo
|
||||
|
||||
class DebugInfoView(context: Context, attrs: AttributeSet? = null, val appWidgetId: Int): ConstraintLayout(context, attrs) {
|
||||
|
||||
val binding: WidgetDebugInfoBinding = WidgetDebugInfoBinding.inflate(LayoutInflater.from(context), this, true)
|
||||
|
||||
init {
|
||||
binding.debugInfoText.text = getDeviceInfo()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package de.jrpie.android.launcher.widgets
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.view.View
|
||||
import de.jrpie.android.launcher.ui.widgets.DebugInfoView
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
|
||||
@Serializable
|
||||
@SerialName("widget:debuginfo")
|
||||
class DebugInfoWidget(
|
||||
override val id: Int,
|
||||
override var position: WidgetPosition,
|
||||
override val panelId: Int,
|
||||
override var allowInteraction: Boolean = true
|
||||
) : Widget() {
|
||||
|
||||
override fun createView(activity: Activity): View {
|
||||
return DebugInfoView(activity, null, id)
|
||||
}
|
||||
|
||||
override fun findView(views: Sequence<View>): DebugInfoView? {
|
||||
return views.mapNotNull { it as? DebugInfoView }.firstOrNull { it.appWidgetId == id }
|
||||
}
|
||||
|
||||
override fun getPreview(context: Context): Drawable? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getIcon(context: Context): Drawable? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun isConfigurable(context: Context): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun configure(activity: Activity, requestCode: Int) { }
|
||||
}
|
|
@ -37,13 +37,14 @@ class LauncherAppWidgetProvider(val info: AppWidgetProviderInfo) : LauncherWidge
|
|||
}
|
||||
|
||||
}
|
||||
class LauncherClockWidgetProvider : LauncherWidgetProvider() {
|
||||
|
||||
override fun loadLabel(context: Context): CharSequence? {
|
||||
data object LauncherClockWidgetProvider : LauncherWidgetProvider() {
|
||||
|
||||
override fun loadLabel(context: Context): CharSequence {
|
||||
return context.getString(R.string.widget_clock_label)
|
||||
}
|
||||
|
||||
override fun loadDescription(context: Context): CharSequence? {
|
||||
override fun loadDescription(context: Context): CharSequence {
|
||||
return context.getString(R.string.widget_clock_description)
|
||||
}
|
||||
|
||||
|
@ -54,5 +55,4 @@ class LauncherClockWidgetProvider : LauncherWidgetProvider() {
|
|||
override fun loadIcon(context: Context): Drawable? {
|
||||
return AppCompatResources.getDrawable(context, R.drawable.baseline_clock_24)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -4,7 +4,6 @@ import android.app.Activity
|
|||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.view.View
|
||||
import de.jrpie.android.launcher.Application
|
||||
import de.jrpie.android.launcher.preferences.LauncherPreferences
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
|
|
|
@ -53,7 +53,7 @@ fun bindAppWidgetOrRequestPermission(activity: Activity, providerInfo: AppWidget
|
|||
|
||||
|
||||
fun getAppWidgetProviders( context: Context ): List<LauncherWidgetProvider> {
|
||||
val list = mutableListOf<LauncherWidgetProvider>(LauncherClockWidgetProvider())
|
||||
val list = mutableListOf<LauncherWidgetProvider>(LauncherClockWidgetProvider)
|
||||
val appWidgetManager = context.getAppWidgetManager()
|
||||
val profiles =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
|
@ -68,11 +68,9 @@ fun getAppWidgetProviders( context: Context ): List<LauncherWidgetProvider> {
|
|||
}.flatten()
|
||||
)
|
||||
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
|
||||
fun updateWidget(widget: Widget) {
|
||||
LauncherPreferences.widgets().widgets(
|
||||
(LauncherPreferences.widgets().widgets() ?: setOf())
|
||||
|
|
16
app/src/main/res/layout/widget_debug_info.xml
Normal file
16
app/src/main/res/layout/widget_debug_info.xml
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:longClickable="false"
|
||||
android:fitsSystemWindows="true"
|
||||
tools:context=".ui.widgets.DebugInfoView">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/debugInfoText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Add table
Add a link
Reference in a new issue