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
8 changes: 4 additions & 4 deletions plugins/Layout-Editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ and libraries and links only against the stable `plugin-api` contract.
## Architecture

```
layout-editor/
plugins/Layout-Editor/
├── build.gradle.kts, settings.gradle.kts, proguard-rules.pro
├── layout-editor-documentation.html # full reference for this plugin
├── layout-editor.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 Expand Up @@ -99,7 +99,7 @@ builder copies the built APK into the `.cgp` and then deletes the source APK.

## Documentation

`layout-editor-documentation.html` is the full reference for this plugin. In the IDE,
`layout-editor.html` is the full reference for this plugin. In the IDE,
long-press any control, palette item, or attribute for its tooltip.

## License
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
19 changes: 12 additions & 7 deletions plugins/Layout-Editor/layout-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@ <h3>Documentation on demand</h3>
<p>
Every control, palette item, and attribute carries a tooltip. Long-press it to
read a short description, with a button through to the IDE's fuller
documentation. The entries come from the plugin's
<code>DocumentationExtension</code>.
documentation. A widget shows the IDE's <code>java</code> entry for its class,
such as <code>android.widget.TextView</code>, and an attribute shows the IDE's
<code>xml</code> entry for its name. The editor's own controls use entries from
the plugin's <code>DocumentationExtension</code>.
</p>
</section>

Expand All @@ -189,11 +191,11 @@ <h3>File layout</h3>
<li>plugins/Layout-Editor/
<ul>
<li>build.gradle.kts, settings.gradle.kts, proguard-rules.pro</li>
<li>layout-editor-documentation.html (this page)</li>
<li>layout-editor.html (this page)</li>
<li>src/main/
<ul>
<li>AndroidManifest.xml (plugin id, main class, icons, permissions)</li>
<li>assets/ (<code>icon_day.png</code>, <code>icon_night.png</code>; <code>tooltips.json</code>, <code>widgetclasses.json</code>; <code>palette/</code>, <code>attributes/</code>, <code>editor/</code>; default font and image)</li>
<li>assets/ (<code>icon_day.png</code>, <code>icon_night.png</code>; <code>widgetclasses.json</code>; <code>palette/</code>, <code>attributes/</code>, <code>editor/</code>; default font and image)</li>
<li>kotlin/ and java/ org/appdevforall/codeonthego/layouteditor/
<ul>
<li><strong>LayoutEditorPlugin.kt</strong>: entry point; toolbar action, enable rule, tooltips, build-status tracking</li>
Expand Down Expand Up @@ -323,9 +325,12 @@ <h3>4.4 Build-status tracking (<code>BuildStatusListener</code>)</h3>
<h3>4.5 Documentation (<code>DocumentationExtension</code>)</h3>
<p>
<code>getTooltipCategory()</code> returns the plugin's tooltip category, and
<code>getTooltipEntries()</code> provides the toolbar-action tooltip, the
editor-control tooltips, and one entry per widget and attribute (loaded from
<code>assets/tooltips.json</code>). Tooltip buttons link into the IDE's
<code>getTooltipEntries()</code> provides the toolbar-action tooltip and the
editor-control tooltips. Widgets and attributes have no entries of their own:
<code>LayoutEditorDocs</code> looks a widget up in the IDE's <code>java</code>
category by its fully qualified class name, and an attribute in the IDE's
<code>xml</code> category by its name without the namespace prefix, so both show
the documentation the IDE maintains. Tooltip buttons link into the IDE's
documentation through direct paths, so the plugin does not bundle its own
documentation pages.
</p>
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