You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
implement WallpaperManager.setBitmap() using XDG Portal
This commit is contained in:
@@ -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_Dialog.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/audio/android_media_AudioTrack.c',
|
||||
'src/api-impl-jni/audio/android_media_SoundPool.c',
|
||||
|
||||
26
src/api-impl-jni/app/android_app_WallpaperManager.c
Normal file
26
src/api-impl-jni/app/android_app_WallpaperManager.c
Normal 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);
|
||||
}
|
||||
@@ -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
|
||||
@@ -1,5 +1,18 @@
|
||||
package android.app;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user