implement WallpaperManager.setBitmap() using XDG Portal

This commit is contained in:
Julian Winkler
2024-12-10 23:48:50 +01:00
parent 5150564a5b
commit b087b82616
4 changed files with 61 additions and 0 deletions

View File

@@ -98,6 +98,7 @@ libtranslationlayer_so = shared_library('translation_layer_main', [
'src/api-impl-jni/app/android_app_AlertDialog.c', 'src/api-impl-jni/app/android_app_AlertDialog.c',
'src/api-impl-jni/app/android_app_Dialog.c', 'src/api-impl-jni/app/android_app_Dialog.c',
'src/api-impl-jni/app/android_app_NotificationManager.c', 'src/api-impl-jni/app/android_app_NotificationManager.c',
'src/api-impl-jni/app/android_app_WallpaperManager.c',
'src/api-impl-jni/AssetInputStream.c', 'src/api-impl-jni/AssetInputStream.c',
'src/api-impl-jni/audio/android_media_AudioTrack.c', 'src/api-impl-jni/audio/android_media_AudioTrack.c',
'src/api-impl-jni/audio/android_media_SoundPool.c', 'src/api-impl-jni/audio/android_media_SoundPool.c',

View File

@@ -0,0 +1,26 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <libportal/portal.h>
#include "../defines.h"
#include "../generated_headers/android_app_WallpaperManager.h"
static void wallpaper_ready_cb(GObject *source, GAsyncResult *res, gpointer user_data)
{
xdp_portal_set_wallpaper_finish(XDP_PORTAL(source), res, NULL);
GFile *file = user_data;
g_file_delete(file, NULL, NULL);
g_object_unref(file);
}
JNIEXPORT void JNICALL Java_android_app_WallpaperManager_set_1bitmap(JNIEnv *env, jclass clazz, jlong pixbuf_ptr)
{
GdkPixbuf *pixbuf = _PTR(pixbuf_ptr);
GFileIOStream *stream;
GFile *file = g_file_new_tmp("XXXXXX.png", &stream, NULL);
g_io_stream_close(G_IO_STREAM(stream), NULL, NULL);
g_object_unref(stream);
gdk_pixbuf_save(pixbuf, g_file_get_path(file), "png", NULL, NULL);
XdpPortal *portal = xdp_portal_new();
xdp_portal_set_wallpaper(portal, NULL, g_file_get_uri(file), XDP_WALLPAPER_FLAG_NONE, NULL, wallpaper_ready_cb, file);
g_object_unref(portal);
}

View File

@@ -0,0 +1,21 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class android_app_WallpaperManager */
#ifndef _Included_android_app_WallpaperManager
#define _Included_android_app_WallpaperManager
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: android_app_WallpaperManager
* Method: set_bitmap
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_android_app_WallpaperManager_set_1bitmap
(JNIEnv *, jclass, jlong);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,5 +1,18 @@
package android.app; package android.app;
import android.content.Context;
import android.graphics.Bitmap;
public class WallpaperManager { public class WallpaperManager {
public static WallpaperManager getInstance(Context context) {
return new WallpaperManager();
}
public void setBitmap(Bitmap bitmap) {
set_bitmap(bitmap.pixbuf);
}
private static native void set_bitmap(long pixbuf);
} }