Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/Layout-Editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ layout-editor/
├── layout-editor-documentation.html # full reference for this plugin
├── src/main/
│ ├── AndroidManifest.xml # plugin id, main class, icons, permissions
│ ├── assets/ # icons, tooltips.json, widgetclasses.json, palette/, attributes/, editor/
│ ├── assets/ # icons, widgetclasses.json, palette/, attributes/, editor/
│ ├── kotlin|java/.../layouteditor/
│ │ ├── LayoutEditorPlugin.kt # entry point: toolbar action, enable rule, tooltips, build-status
│ │ ├── LayoutEditorFragment.kt # full-screen editor: canvas, palette, component tree, drawer
Expand Down
4 changes: 2 additions & 2 deletions plugins/Layout-Editor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {
applicationId = "org.appdevforall.codeonthego.layouteditor"
minSdk = 26
targetSdk = 36
versionCode = 1
versionName = "1.0.0"
versionCode = 2
versionName = "2.0.0"
}

buildTypes {
Expand Down
2 changes: 1 addition & 1 deletion plugins/Layout-Editor/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<meta-data
android:name="plugin.min_ide_version"
android:value="1.0.0" />
android:value="26.48" />

<meta-data
android:name="plugin.permissions"
Expand Down
800 changes: 0 additions & 800 deletions plugins/Layout-Editor/src/main/assets/tooltips.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class LayoutEditorFragment : Fragment() {
drawerLayout.closeDrawer(GravityCompat.END)
}
onItemLongClickListener = { view ->
view.javaClass.superclass?.name?.let { LayoutEditorDocs.show(view, it) }
view.javaClass.superclass?.name?.let { LayoutEditorDocs.showWidget(view, it) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AppliedAttributesAdapter(
holder.binding.root.apply {
setOnClickListener { onClick(position) }
setOnLongClickListener {
LayoutEditorDocs.show(it, attributeName.substringAfterLast(":"))
LayoutEditorDocs.showAttribute(it, attributeName)
true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PaletteListAdapter(private val drawerLayout: DrawerLayout) :
binding.root.contentDescription = widgetItem["name"].toString()
binding.root.setupGestureHandling(
onLongPress = { view ->
getSuperClassName(widgetItem["className"].toString())?.let { LayoutEditorDocs.show(view, it) }
getSuperClassName(widgetItem["className"].toString())?.let { LayoutEditorDocs.showWidget(view, it) }
},
onDrag = { view ->
if (ViewCompat.startDragAndDrop(view, null, DragShadowBuilder(view), widgetItem, 0)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ class DesignEditor : LinearLayout {

view.handleLongClicksAndDrag(
onLongPress = { view ->
view.javaClass.superclass?.name?.let { LayoutEditorDocs.show(view, it) }
view.javaClass.superclass?.name?.let { LayoutEditorDocs.showWidget(view, it) }
},
onDrop = { child, x, y ->
positionAtDrop(child, x, y, viewAttributeMap)
Expand Down Expand Up @@ -757,7 +757,7 @@ class DesignEditor : LinearLayout {
}

binding.viewLayout.setOnLongClickListener {
target.javaClass.superclass?.name?.let { name -> LayoutEditorDocs.show(it, name) }
target.javaClass.superclass?.name?.let { name -> LayoutEditorDocs.showWidget(it, name) }
true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import com.itsaky.androidide.plugins.services.IdeTooltipService
object LayoutEditorDocs {

const val CATEGORY = "plugin_org.appdevforall.codeonthego.layouteditor"
private const val IDE_CATEGORY_JAVA = "java"
private const val IDE_CATEGORY_XML = "xml"

const val TAG_OVERVIEW = "layouteditor.overview"
const val TAG_HELP = "layouteditor.help"
Expand All @@ -27,6 +29,14 @@ object LayoutEditorDocs {
service()?.showTooltip(anchor, tag)
}

fun showWidget(anchor: View, className: String) {
service()?.showTooltip(anchor, IDE_CATEGORY_JAVA, className)
}

fun showAttribute(anchor: View, attributeName: String) {
service()?.showTooltip(anchor, IDE_CATEGORY_XML, attributeName.substringAfterLast(":"))
}

fun bindLongPress(view: View, tag: String) {
view.setOnLongClickListener {
show(it, tag)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.appdevforall.codeonthego.layouteditor

import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.itsaky.androidide.plugins.IPlugin
import com.itsaky.androidide.plugins.PluginContext
import com.itsaky.androidide.plugins.base.PluginFragmentHelper
Expand Down Expand Up @@ -221,52 +219,12 @@ class LayoutEditorPlugin : IPlugin, UIExtension, DocumentationExtension, BuildSt
"<code>layout_width</code> and <code>layout_height</code> can't be removed.",
buttons = docButtons(),
),
) + widgetAndAttributeEntries()
)

private fun docButtons(): List<PluginTooltipButton> = listOf(
PluginTooltipButton(description = "Learn more", uri = "i/plugins-adfa.html", order = 0, directPath = true),
)

private data class TooltipDef(
val tag: String,
val summary: String,
val detail: String = "",
val uri: String = "",
val label: String = "",
)

private fun widgetAndAttributeEntries(): List<PluginTooltipEntry> {
val assets = PluginFragmentHelper.getPluginContext(PLUGIN_ID)?.assets ?: return emptyList()
return try {
val json = assets.open("tooltips.json").bufferedReader().use { it.readText() }
val defs: List<TooltipDef> =
Gson().fromJson(json, object : TypeToken<List<TooltipDef>>() {}.type)
defs.map { def ->
PluginTooltipEntry(
tag = def.tag,
summary = def.summary,
detail = def.detail,
buttons = if (def.uri.isNotBlank()) {
listOf(
PluginTooltipButton(
description = def.label.ifBlank { "Learn more" },
uri = def.uri,
order = 0,
directPath = true,
)
)
} else {
emptyList()
},
)
}
} catch (e: Exception) {
context.logger.warn("Failed to load tooltips.json: ${e.message}")
emptyList()
}
}


companion object {
const val PLUGIN_ID = "org.appdevforall.codeonthego.layouteditor"
private const val PREVIEW_LAYOUT_ORDER = 7
Expand Down
Loading