ScreenTouchEffects - Touch screen, returns the x, y position and touch effect.

ScreenTouchEffects
Touch screen, returns the x, y position and touch effect.

GIF_20251015_051127_904
GIF_20251015_051219_036
GIF_20251015_051319_807
GIF_20251015_050935_465
GIF_20251021_013142_637
GIF_20251021_013313_015
GIF_20251021_012921_160


Converts between DP (Density-independent Pixels) and PX (Physical Pixels) using the device's display density (DPI) to maintain visual consistency across different displays.

  • On different devices:

    • MDPI (160 DPI): 50dp = 50px, 25dp = 25px

    • HDPI (240 DPI): 50dp = 75px, 25dp = 38px

    • XHDPI (320 DPI): 50dp = 100px, 25dp = 50px

    • XXHDPI (480 DPI): 50dp = 150px, 25dp = 75px


EnableTouch

Starts listening for screen touches and creates effects.


DisableTouch

Disables the touch overlay.


StartInfinite

Starts infinite effect at specified coordinates with specified unit.

Unit:

  • dp = App Pixels
  • px = Device Pixels

StopInfinite

Stops the infinite effect.


ShowEffectAt

Creates a single effect at the specified coordinates with specified unit.

Unit:

  • dp = App Pixels
  • px = Device Pixels

InfiniteInterval

Sets the interval between effects in infinite mode (milliseconds).


Color

Sets the effect color.


Size

Sets the size of the effect.


Duration

Sets the duration of the effect animation in milliseconds.


EffectType

Sets the current effect type.
Options: Ripple, Particles, Rings, Spiral, Bubble DigitalRain, Snow, SnowDetailed.


Touched

Triggered when the screen is touched. Returns coordinates in both pixels (px) and density-independent pixels (dp).


ScreenDPI

Returns the screen density in DPI.

component_set_get


DensityScale

Returns the screen density scale factor.


WidthDevicePixels

Returns screen width in pixels.


HeightDevicePixels

Returns screen height in pixels.


WidthAppPixels

Returns screen width in density-independent pixels (dp).


HeightAppPixels

Returns screen height in density-independent pixels (dp).


v1.3 Oct 25, 2025.

Update:

  • Changed property, function, and event names from px to device pixels and dp to app pixels.

  • New effects added:

    • Spiral
    • Bubble
    • DigitalRain
    • Snow
    • SnowDetailed

ScreenTouchEffects.aia (122.9 KB)

joejsanz.joedevscreentoucheffects.aix (20.8 KB)


JDK: 11
Minimum API Level: 21
Updated On: 2025-10-25T07:00:00Z

Built using: FAST-CLI v5.2.2-premium


Thanks.

6 Likes

x,y returned/accepted in dpi not screen pixels ?

e.g. for effect in centre of screen, and to return pixel coords

1 Like

Yes, the values ​​entered and received were only in px.

I've updated the extension so that you can enter the value you choose between dp and px, and the event will return both values.


Update: v1.1

3 Likes

Hmmm, dp and px appear to be around the wrong way :upside_down_face: , with dp returning pixels and px returning dpi ?

That's true :grimacing: they're inverted.

I'll fix that as soon as I have time.

1 Like

I can't find the fault, I'm using DPI based DP-PX conversions.

These

image

return the effect at pixels, not dp

I would expect these to return pixels:

image

but they return dp

1 Like

Don't we have a similar extension?

componentTools2.aia (29.7 KB)

It's similar, except that in ComponentTools you pass an Arrangement to apply the touch to, and when you add a component inside the Arrangement like buttons and click on it, touch detection is not applied.

  • Although I liked that when you slide your finger across the screen it detects the position.

In my extension:

  • I'm applying rootLayout.addView(touchOverlay);
    and all touch events are captured without interfering with other components like buttons.
1 Like

It's weird, the example Anke gave me gives me the same result as my extension on my device.


:thinking:

1 Like

Do you agree with this?

image

I think the AI2 ScreenWidth and ScreenHeight blocks are in dp and not px.

component_set_get (6)
component_set_get (7)

I think there is that error in the documentation of those blocks.

Update v1.2

1 Like

Incorrect.

image

image

You carry on with an incorrectly labelled extension :wink:

Yes, I already looked in the code and it does use pixels but not real pixels, so it is limited.

Might be easier for others to understand if we called them "devicePixels" (the big numbers) and "appPixels" (the smaller numbers) - where appPixels relate to the Screen Height and Width values returned by the Appinventor blocks.

You're right, I'll change the names of the properties, functions and events where px and dp are located.

Update v1.3