Skip to content

Add tap-to-place text positioning - #592

Open
boardtc wants to merge 3 commits into
burhanrashid52:masterfrom
boardtc:codex/text-positioning-589
Open

Add tap-to-place text positioning#592
boardtc wants to merge 3 commits into
burhanrashid52:masterfrom
boardtc:codex/text-positioning-589

Conversation

@boardtc

@boardtc boardtc commented Jun 4, 2026

Copy link
Copy Markdown

Summary

This PR addresses issue #589 by adding support for initial text placement instead of always inserting text centered on the image.

What changed

  • Added a new Position type for overlay coordinates
  • Added PhotoEditor.addText(..., position) overloads
  • Preserved existing addText(...) behavior when no position is supplied
  • Updated the sample app so users:
    1. tap Text
    2. tap the image where the label should appear
    3. enter text in the dialog
  • Updated README.md for:
    • developer-facing API usage
    • end-user sample app instructions
    • adding multiple text labels in different positions

Tests / verification

Verified locally with:

.\gradlew.bat :photoeditor:testDebugUnitTest --tests "ja.burhanrashid52.photoeditor.GraphicManagerTest" :app:testDebugUnitTest :app:compileDebugAndroidTestKotlin :app:assembleDebug

Added/updated coverage includes:

  • GraphicManagerTest for default centered insertion and explicit placement
  • sample app Android test flow updated for tap-to-place text

Device verification:

  • tested on a Pixel 9a
  • confirmed the text dialog opens after tapping the image
  • confirmed multiple text labels can be added in different positions
  • confirmed existing text manipulation still works after insertion

Notes

  • This was also released in the fork as v3.1.1 after device verification

@boardtc

boardtc commented Jun 4, 2026

Copy link
Copy Markdown
Author

Additional device-validation note:

This change was tested successfully on a Pixel 9a after installing the rebuilt debug APK.

Confirmed on-device:

  • tapping Text shows the placement prompt
  • tapping the image opens the text dialog
  • the entered text is placed at the tapped location
  • multiple text labels can be added in different positions by repeating the flow
  • existing drag/scale/rotate behavior still works after insertion

@burhanrashid52

Copy link
Copy Markdown
Owner

@boardtc Please fix the tests first.

@boardtc

boardtc commented Jun 5, 2026

Copy link
Copy Markdown
Author

Addressed this.

I pushed commit 937d5f3 (Fix translations and document pre-PR checks) into this PR branch.

What changed:

  • added the missing msg_tap_image_for_text translations for fr and pl
  • added a small CONTRIBUTING.md note to run broader local gates before opening PRs:
    • ./gradlew check
    • ./gradlew build

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements issue #589 by introducing explicit initial placement for text overlays (instead of always centering), adding a Position coordinate type and new PhotoEditor.addText(..., position) overloads, and updating the sample app UX to “tap-to-place” before entering text.

Changes:

  • Added Position and plumbing through PhotoEditor/PhotoEditorImpl/GraphicManager to support initial text placement while preserving default centered behavior.
  • Updated sample app UI + instrumentation test flow to require a tap location before showing the text dialog.
  • Updated documentation/release artifacts (README, CHANGELOG, version bump, contributing checks) and added unit coverage around centered vs positioned insertion.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
README.md Documents new Position API usage and updated sample app user flow.
photoeditor/src/test/java/ja/burhanrashid52/photoeditor/GraphicManagerTest.kt Adds unit tests for default centered placement and explicit positioned placement.
photoeditor/src/main/java/ja/burhanrashid52/photoeditor/Position.kt Introduces a pixel-based coordinate type for initial overlay placement.
photoeditor/src/main/java/ja/burhanrashid52/photoeditor/PhotoEditorImpl.kt Implements the new addText overloads and routes optional Position into editor insertion.
photoeditor/src/main/java/ja/burhanrashid52/photoeditor/PhotoEditor.kt Adds new addText(..., position) overloads to the public API.
photoeditor/src/main/java/ja/burhanrashid52/photoeditor/GraphicManager.kt Applies centered vs positioned layout params when adding a new overlay view.
photoeditor/build.gradle Bumps publish version to 3.1.1.
CONTRIBUTING.md Adds guidance to run ./gradlew check and ./gradlew build before opening PRs.
CHANGELOG.md Adds 3.1.1 release notes describing the feature, tests, and docs.
app/src/main/res/values/strings.xml Adds tap-to-place guidance string.
app/src/main/res/values-pl/strings.xml Adds Polish translation for tap-to-place guidance.
app/src/main/res/values-fr/strings.xml Adds French translation for tap-to-place guidance.
app/src/main/res/layout/activity_edit_image.xml Adds a transparent overlay view to capture tap-to-place input.
app/src/main/java/com/burhanrashid52/photoediting/EditImageActivity.kt Implements tap-to-place workflow and routes tap coordinates into addText(..., position).
app/src/androidTest/java/com/burhanrashid52/photoediting/EditImageActivityTest.kt Updates Espresso flows to include a placement tap before typing text.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if (position == null) {
params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE)
} else {
params.addRule(RelativeLayout.ALIGN_PARENT_START, RelativeLayout.TRUE)
Comment on lines +33 to +36
android:background="@android:color/transparent"
android:clickable="true"
android:focusable="true"
android:visibility="gone"
Comment thread README.md
Comment on lines +162 to +165
If you want the text to start at a specific location instead of the default centered position, use the overload with a `Position`:

`mPhotoEditor.addText(inputText, colorCode, Position(80, 160));`

Comment on lines +39 to +50
/**
* This adds the text on the [PhotoEditorView] at the provided initial [position].
* by default [TextView.setText] will be 18sp
*
* @param text text to display
* @param colorCodeTextView text color to be displayed
* @param position initial position in pixels from the top-left of the editor
*/
@SuppressLint("ClickableViewAccessibility")
fun addText(text: String, colorCodeTextView: Int, position: Position) {
addText(text, colorCodeTextView)
}
Comment on lines +63 to +75
/**
* This adds the text on the [PhotoEditorView] at the provided initial [position].
* by default [TextView.setText] will be 18sp
*
* @param textTypeface typeface for custom font in the text
* @param text text to display
* @param colorCodeTextView text color to be displayed
* @param position initial position in pixels from the top-left of the editor
*/
@SuppressLint("ClickableViewAccessibility")
fun addText(textTypeface: Typeface?, text: String, colorCodeTextView: Int, position: Position) {
addText(textTypeface, text, colorCodeTextView)
}
Comment on lines +87 to +98
/**
* This adds the text on the [PhotoEditorView] at the provided initial [position].
* by default [TextView.setText] will be 18sp
*
* @param text text to display
* @param styleBuilder text style builder with your style
* @param position initial position in pixels from the top-left of the editor
*/
@SuppressLint("ClickableViewAccessibility")
fun addText(text: String, styleBuilder: TextStyleBuilder?, position: Position) {
addText(text, styleBuilder)
}
@burhanrashid52

Copy link
Copy Markdown
Owner

@boardtc Can you please check copilot code review comments ?

@boardtc

boardtc commented Jun 9, 2026

Copy link
Copy Markdown
Author

Addressed the Copilot review comments in commit 0c31132 (Address Copilot review comments), now pushed to this PR branch.

Changes made:

  • fixed explicit placement to use left-based alignment so Position coordinates stay consistent with top-left docs in RTL layouts
  • made the text-placement overlay non-focusable and excluded it from accessibility traversal
  • corrected the README Java example to use new Position(...)
  • clarified the PhotoEditor overload KDoc so the default binary-compatibility fallback is documented

Verification rerun under Java 21:

  • :app:lintDebug
  • :photoeditor:testDebugUnitTest --tests ja.burhanrashid52.photoeditor.GraphicManagerTest
  • :app:testDebugUnitTest
  • :app:compileDebugAndroidTestKotlin

@boardtc

boardtc commented Jun 17, 2026

Copy link
Copy Markdown
Author

Hi, just checking in on this PR now that the test fix and the Copilot review follow-ups have been addressed. Please let me know if there’s anything else you’d like changed and I’m happy to update it.

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions Bot added the Stale label Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants