TheOathMan / Godot-Android-Live-Wallpaper

Make your Android Godot application run as a live wallpaper in the background.
MIT License
18 stars 4 forks source link

getting current screen index / horizontal scrolling #2

Closed skeddles closed 5 months ago

skeddles commented 8 months ago

In android you can usually add multiple home screens to organize your icons onto, and swipe horizontally between them. Most versions allow you to set a static wallpaper that scrolls slightly with a parallax effect as you scroll between them.

example: EAcsX

Is there any way to get the current scroll position of the home screen, or the current screen, so I can emulate that effect with this plugin?

I took a look at your signals and static functions, but didn't see anything that seemed related. If it's not currently possible, then consider this a feature request

Anyway thanks for making this, seems like a great plugin, and everything else seems to be working!

TheOathMan commented 8 months ago

The plugin has an offset callback but was not implemented yet. Every time you scroll the home screen, the wallpaper plugin sends X and Y offset values range from 0.0 to 1.0, representing the current position of the home screen relative to the available space. It also sends other useful values for pixel perfect positioning.

I will implement it soon. It should be fairly straightforward implementation.

Thank you for letting me know you need this. Good luck.

skeddles commented 8 months ago

Thanks! Looking forward to it! I will make a parallax wallpaper with it as soon as it's implemented!

TheOathMan commented 8 months ago

Thanks! Looking forward to it! I will make a parallax wallpaper with it as soon as it's implemented!

Check out the new on_offset_changed signal. It should do what you want. Both a new release and a repo update have been uploaded.

skeddles commented 8 months ago

I tried it out but unfortunately could not get it working.

I deleted the livewallpaper addon folder and used the one from the releases tab, and restarted. I found the signal on the LiveWallpaper node and connected it, but it doesn't seem to be firing when I scroll my screen (my positions aren't changing and it's not showing in the log)

maybe I installed/used it wrong? I hope my phone isn't too old (android 11)

func _on_live_wallpaper_on_offsets_changed(Offset, OffsetStep, PixelOffset):
    consolelog('offset')
    $moveme.offset.x = (Offset.x-0.5) * 100
    $moveme2.offset.x = PixelOffset.x

my project: LospecWallpaperShoppe.zip video: https://drive.google.com/file/d/1kGyWCXPbTb_ogBjbMXOde6aNA6BIhlcC/view?usp=sharing

TheOathMan commented 8 months ago

It's a Godot issue. For some reason, in Godot 4.2.2.stable, the Engine can not register on_offset_changed signal, but when I tried your project in Godot 4.3.beta3, everything seems to be working. The little character moves as you scroll. I will investigate further and see what I can do.

TheOathMan commented 8 months ago

I found the Issue, Godot 4.2 can not handle 6 parameters for the signal coming from the android native calls, but Godot 4.3 can. I will just remove OffsetStep because its not necessary to the function of the signal.

TheOathMan commented 8 months ago

Now The Plugin tested with 4.2.2.stable works as well.

skeddles commented 8 months ago

yup, after updating to that version, and removing the offsetstep parameter, it seems to be working nicely!

Thanks so much for implementing this, it definitely opens a lot of options for us.

skeddles commented 8 months ago

i dont suppose there's a way to get a count of how many home screens the user has?

TheOathMan commented 8 months ago

Offsetstep parameter contain NumberOfHomeScreen÷1. So if x value is 0.333, that means there are 3 horizontal home screens.

The problem is, we removed that parameter because JNI breaks where there are too many parameters in 4.2.

TheOathMan commented 8 months ago

I'm adding a separate signal that sends home screen count

TheOathMan commented 8 months ago

try the new homescreen_count_updated(count_x:int,count_y:int) signals. It should receive home screen count when available.

tmape commented 7 months ago

Thanks for sharing your awesome Live Wallpaper plugin! I'm trying to get it working on Godot, but I've hit a few issues.

After following these steps:

  1. Downloading and installing the Android Build Template
  2. Updating the plugin to v1.2 (it came with v1.1)
  3. Setting up the homescreen_count_updated and on_offsets_changed signals
  4. Running the project on Android via Remote Debug

I'm experiencing issues where the values don't update when changing screens, adding screen or tapping/swiping the screen. I've tried this on different Godot versions and Android devices with various Android OS versions (e.g., 8, 14), but still get the same result.

Could you help me figure out what I've done wrong? Specifically:

  1. Shouldn't the values update when adding a new screen, swiping to another screen, or tapping the screen?
  2. Am I setting up the signals incorrectly?
  3. The plugin version shown in Project Settings > Plugins doesn't seem to match the released version - have I installed it correctly?"

OS: Windows 11 Android OS: version 8 and version 11 Godot Version(Gd Script version): 4.2.2 stable.official, 4.3.stable.official

TheOathMan commented 7 months ago

try the new demo project. I have updated the plugin sdk target and fixed a previous (maybe unrelated) issue with integer rounding of home screen count.

homescreen_count_updated signal is supposed to give you the total home screens available. So if you have 3 home screen, the signal will report 3. the offset.x from on_offset_changed signal is a range from 0 to 1. 1 means you've scrolled horizontally to the last home screen page.

TheOathMan commented 7 months ago

You are right, home screen related signals don't seem to work on Android 9, but works fine in android 14. I will see what I can find but maybe its an android sdk related issue.

tmape commented 7 months ago

Thanks for your prompt response! Unfortunately, I've tried installing the latest version (v1.3.3) of the Live Wallpaper plugin, but I'm still experiencing issues getting it to work.

Specifically:

I've tried this on Samsung S23 (OS: 14). Could you please help me troubleshoot what's going wrong?

GodotLiveWallpaperProject_v1.3.3.zip

TheOathMan commented 6 months ago

Samsung's One UI launcher is known to have issues with calling the onOffsetsChanged() callback for live wallpapers. This problem has been observed in several Samsung devices across different Android versions, including older devices like the Note 8 and newer ones like the Galaxy S23. As a workaround, you can download Pixel Launcher which is what I'm using or Smart Launcher 6. These Launchers should call all home screen signals just fine. I tested the plugin in Samsung Note 8 using the default One UI Launcher, the signal don't work, but once I changed the launcher, the signal work perfectly.

Samsung heavily customizes Android, including the launcher, and these customizations can interfere with certain system callbacks like onOffsetsChanged().

To change the Launcher go to Settings>apps>(click 3 dots on top) Default apps > Home Screen:

My bad, I forgot to update the plugin files in the sample project. I did a reupload.

tmape commented 6 months ago

After switching to a different launcher, everything is working as expected. So, it appears that Samsung's launcher was the culprit!

I'm grateful for your help in troubleshooting this problem. Just to confirm, I've also tested the plugin on my devices and Android versions, specifically on Samsung S7 (OS: 8) and S23 (OS: 14), with both v1.3.2 and v1.3.3 versions of the plugin, and it's working without any issues on all of them.

TheOathMan commented 6 months ago

I added the issue to the Known issues for future users. thanks for reporting. Good luck.