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
NotificationManager: add support for icons
This commit is contained in:
@@ -61,7 +61,7 @@ static void natification_callback(GObject* source_object, GAsyncResult* res, gpo
|
||||
callback_pending = 0;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_app_NotificationManager_nativeShowNotification(JNIEnv *env, jobject this, jlong builder_ptr, jint id, jstring title_jstr, jstring text_jstr, jint type, jstring action, jstring className)
|
||||
JNIEXPORT void JNICALL Java_android_app_NotificationManager_nativeShowNotification(JNIEnv *env, jobject this, jlong builder_ptr, jint id, jstring title_jstr, jstring text_jstr, jstring icon_jstr, jint type, jstring action, jstring className)
|
||||
{
|
||||
if (callback_pending) {
|
||||
return;
|
||||
@@ -85,6 +85,22 @@ JNIEXPORT void JNICALL Java_android_app_NotificationManager_nativeShowNotificati
|
||||
g_variant_builder_add(builder, "{sv}", "body", g_variant_new_string(text));
|
||||
(*env)->ReleaseStringUTFChars(env, text_jstr, text);
|
||||
}
|
||||
if (icon_jstr) {
|
||||
const char *icon_path = (*env)->GetStringUTFChars(env, icon_jstr, NULL);
|
||||
extract_from_apk(icon_path, icon_path);
|
||||
char *icon_path_full = g_strdup_printf("%s/%s", get_app_data_dir(), icon_path);
|
||||
GMappedFile *icon_file = g_mapped_file_new(icon_path_full, FALSE, NULL);
|
||||
GBytes *icon_bytes = g_mapped_file_get_bytes(icon_file);
|
||||
GIcon *icon = g_bytes_icon_new(icon_bytes);
|
||||
GVariant *icon_serialized = g_icon_serialize(icon);
|
||||
g_variant_builder_add(builder, "{sv}", "icon", icon_serialized);
|
||||
g_variant_unref(icon_serialized);
|
||||
g_object_unref(icon);
|
||||
g_bytes_unref(icon_bytes);
|
||||
g_mapped_file_unref(icon_file);
|
||||
g_free(icon_path_full);
|
||||
(*env)->ReleaseStringUTFChars(env, icon_jstr, icon_path);
|
||||
}
|
||||
g_variant_builder_add(builder, "{sv}", "default-action", g_variant_new_string("default-action"));
|
||||
g_variant_builder_add(builder, "{sv}", "default-action-target", serialize_intent(env, type, action, className));
|
||||
g_variant_builder_add(builder, "{sv}", "buttons", buttons);
|
||||
|
||||
@@ -26,10 +26,10 @@ JNIEXPORT void JNICALL Java_android_app_NotificationManager_nativeAddAction
|
||||
/*
|
||||
* Class: android_app_NotificationManager
|
||||
* Method: nativeShowNotification
|
||||
* Signature: (JILjava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)V
|
||||
* Signature: (JILjava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_app_NotificationManager_nativeShowNotification
|
||||
(JNIEnv *, jobject, jlong, jint, jstring, jstring, jint, jstring, jstring);
|
||||
(JNIEnv *, jobject, jlong, jint, jstring, jstring, jstring, jint, jstring, jstring);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -110,6 +110,7 @@ const char * attribute_set_get_string(JNIEnv *env, jobject attrs, char *attribut
|
||||
int attribute_set_get_int(JNIEnv *env, jobject attrs, char *attribute, char *schema, int default_value);
|
||||
void set_up_handle_cache(JNIEnv *env);
|
||||
void extract_from_apk(const char *path, const char *target);
|
||||
char *get_app_data_dir();
|
||||
|
||||
void prepare_main_looper(JNIEnv* env);
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ public class Notification {
|
||||
String title;
|
||||
List<Action> actions = new ArrayList<Action>();
|
||||
PendingIntent intent;
|
||||
String iconPath;
|
||||
|
||||
public String toString() {
|
||||
return "Notification [" + title + ", " + text + ", " + actions + "]";
|
||||
@@ -65,7 +66,10 @@ public class Notification {
|
||||
|
||||
public Builder setWhen(long when) {return this;}
|
||||
|
||||
public Builder setSmallIcon(int icon, int level) {return this;}
|
||||
public Builder setSmallIcon(int icon, int level) {
|
||||
notification.iconPath = Context.this_application.getString(icon);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setContent(RemoteViews contentView) {return this;}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public class NotificationManager {
|
||||
actionName = notification.intent.intent.getAction();
|
||||
className = notification.intent.intent.getComponent() != null ? notification.intent.intent.getComponent().getClassName() : null;
|
||||
}
|
||||
nativeShowNotification(builder, id, notification.title, notification.text, intentType, actionName, className);
|
||||
nativeShowNotification(builder, id, notification.title, notification.text, notification.iconPath, intentType, actionName, className);
|
||||
}
|
||||
|
||||
public void notify(int id, Notification notification) {
|
||||
@@ -55,5 +55,5 @@ public class NotificationManager {
|
||||
|
||||
protected native long nativeInitBuilder();
|
||||
protected native void nativeAddAction(long builder, String title, int intentType, String action, String className);
|
||||
protected native void nativeShowNotification(long builder, int id, String title, String text, int intentType, String action, String className);
|
||||
protected native void nativeShowNotification(long builder, int id, String title, String text, String iconPath, int intentType, String action, String className);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user