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
handle 'SEND' intent by copying to clipboard, make Activity subclass ContextWrapper, code style fixes
This commit is contained in:
@@ -11,7 +11,8 @@
|
||||
static GList *activity_backlog = NULL;
|
||||
static jobject activity_current = NULL;
|
||||
|
||||
static void activity_close(JNIEnv *env, jobject activity) {
|
||||
static void activity_close(JNIEnv *env, jobject activity)
|
||||
{
|
||||
// in case some exception was left unhandled in native code, print it here so we don't confuse it with an exception thrown by onDestroy
|
||||
if((*env)->ExceptionCheck(env)) {
|
||||
fprintf(stderr, "app_exit: seems there was a pending exception... :");
|
||||
@@ -24,7 +25,8 @@ static void activity_close(JNIEnv *env, jobject activity) {
|
||||
(*env)->ExceptionDescribe(env);
|
||||
}
|
||||
|
||||
static void activity_update_current(JNIEnv *env) {
|
||||
static void activity_update_current(JNIEnv *env)
|
||||
{
|
||||
jobject activity_new = activity_backlog ? g_list_first(activity_backlog)->data : NULL;
|
||||
|
||||
if (activity_current != activity_new) {
|
||||
@@ -59,7 +61,8 @@ static void activity_update_current(JNIEnv *env) {
|
||||
}
|
||||
}
|
||||
|
||||
void activity_window_ready(void) {
|
||||
void activity_window_ready(void)
|
||||
{
|
||||
JNIEnv *env = get_jni_env();
|
||||
|
||||
for (GList *l = activity_backlog; l != NULL; l = l->next) {
|
||||
@@ -69,7 +72,8 @@ void activity_window_ready(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void activity_close_all(void) {
|
||||
void activity_close_all(void)
|
||||
{
|
||||
GList *activities, *l;
|
||||
JNIEnv *env = get_jni_env();
|
||||
// local backup of the backlog
|
||||
@@ -85,7 +89,8 @@ void activity_close_all(void) {
|
||||
g_list_free(activities);
|
||||
}
|
||||
|
||||
void activity_start(JNIEnv *env, jobject activity_object) {
|
||||
void activity_start(JNIEnv *env, jobject activity_object)
|
||||
{
|
||||
/* -- run the activity's onCreate -- */
|
||||
(*env)->CallVoidMethod(env, activity_object, handle_cache.activity.onCreate, NULL);
|
||||
if((*env)->ExceptionCheck(env))
|
||||
@@ -95,7 +100,8 @@ void activity_start(JNIEnv *env, jobject activity_object) {
|
||||
activity_update_current(env);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_app_Activity_nativeFinish(JNIEnv *env, jobject this, jlong window) {
|
||||
JNIEXPORT void JNICALL Java_android_app_Activity_nativeFinish(JNIEnv *env, jobject this, jlong window)
|
||||
{
|
||||
GList *l;
|
||||
jobject removed_activity = NULL;
|
||||
for (l = activity_backlog; l != NULL; l = l->next) {
|
||||
@@ -113,17 +119,29 @@ JNIEXPORT void JNICALL Java_android_app_Activity_nativeFinish(JNIEnv *env, jobje
|
||||
gtk_window_close(GTK_WINDOW(_PTR(window)));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_app_Activity_nativeStartActivity(JNIEnv *env, jclass class, jobject activity) {
|
||||
JNIEXPORT void JNICALL Java_android_app_Activity_nativeStartActivity(JNIEnv *env, jclass class, jobject activity)
|
||||
{
|
||||
activity_start(env, activity);
|
||||
}
|
||||
|
||||
static XdpPortal *portal = NULL;
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_app_Activity_nativeOpenURI(JNIEnv *env, jclass class, jstring uriString) {
|
||||
JNIEXPORT void JNICALL Java_android_app_Activity_nativeOpenURI(JNIEnv *env, jclass class, jstring uriString)
|
||||
{
|
||||
static XdpPortal *portal = NULL;
|
||||
if (!portal) {
|
||||
portal = xdp_portal_new();
|
||||
}
|
||||
const char* uri = (*env)->GetStringUTFChars(env, uriString, NULL);
|
||||
|
||||
const char *uri = (*env)->GetStringUTFChars(env, uriString, NULL);
|
||||
xdp_portal_open_uri(portal, NULL, uri, XDP_OPEN_URI_FLAG_NONE, NULL, NULL, NULL);
|
||||
(*env)->ReleaseStringUTFChars(env, uriString, uri);
|
||||
}
|
||||
|
||||
extern GtkWindow *window; // TODO: get this in a better way
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_app_Activity_nativeShare(JNIEnv *env, jclass class, jstring text_jstring)
|
||||
{
|
||||
const char *text = (*env)->GetStringUTFChars(env, text_jstring, NULL);
|
||||
GdkClipboard *clipboard = gdk_display_get_clipboard(gtk_root_get_display(GTK_ROOT(window)));
|
||||
gdk_clipboard_set_text(clipboard, text);
|
||||
(*env)->ReleaseStringUTFChars(env, text_jstring, text);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,14 @@ JNIEXPORT void JNICALL Java_android_app_Activity_nativeStartActivity
|
||||
JNIEXPORT void JNICALL Java_android_app_Activity_nativeOpenURI
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
/*
|
||||
* Class: android_app_Activity
|
||||
* Method: nativeShare
|
||||
* Signature: (Ljava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_app_Activity_nativeShare
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -22,19 +22,20 @@ static void location_updated (
|
||||
(*env)->CallStaticVoidMethod(env, class, _STATIC_METHOD(class, "locationUpdated", "(DDD)V"), latitude, longitude, heading);
|
||||
}
|
||||
|
||||
static XdpPortal *portal = NULL;
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_location_LocationManager_nativeGetLocation(JNIEnv *env, jobject) {
|
||||
if (!getenv("ATL_UGLY_ENABLE_LOCATION")) {
|
||||
// Location access is prohibited by default until sanboxing is implemented.
|
||||
// Set ATL_UGLY_ENABLE_LOCATION environment variable to enable it.
|
||||
return;
|
||||
}
|
||||
|
||||
static XdpPortal *portal = NULL;
|
||||
if (!portal) {
|
||||
portal = xdp_portal_new();
|
||||
JavaVM *jvm;
|
||||
(*env)->GetJavaVM(env, &jvm);
|
||||
g_signal_connect(portal, "location-updated", G_CALLBACK(location_updated), jvm);
|
||||
}
|
||||
|
||||
xdp_portal_location_monitor_start (portal, NULL, 0, 0, XDP_LOCATION_ACCURACY_EXACT, XDP_LOCATION_MONITOR_FLAG_NONE, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.R;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.XmlResourceParser;
|
||||
@@ -27,7 +28,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Activity extends Context implements Window.Callback {
|
||||
public class Activity extends ContextWrapper implements Window.Callback {
|
||||
LayoutInflater layout_inflater;
|
||||
Window window = new Window(this);
|
||||
int requested_orientation = -1 /*ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED*/; // dummy
|
||||
@@ -64,6 +65,7 @@ public class Activity extends Context implements Window.Callback {
|
||||
}
|
||||
|
||||
public Activity() {
|
||||
super(null);
|
||||
layout_inflater = new LayoutInflater();
|
||||
intent = new Intent();
|
||||
}
|
||||
@@ -320,10 +322,6 @@ public class Activity extends Context implements Window.Callback {
|
||||
|
||||
public boolean isChangingConfigurations() {return false;}
|
||||
|
||||
private native void nativeFinish(long native_window);
|
||||
public static native void nativeStartActivity(Activity activity);
|
||||
public static native void nativeOpenURI(String uri);
|
||||
|
||||
@Override
|
||||
public void onContentChanged() {
|
||||
// TODO Auto-generated method stub
|
||||
@@ -393,4 +391,9 @@ public class Activity extends Context implements Window.Callback {
|
||||
public void setIntent(Intent newIntent) {}
|
||||
|
||||
public void unregisterReceiver(BroadcastReceiver receiver) {}
|
||||
|
||||
private native void nativeFinish(long native_window);
|
||||
public static native void nativeStartActivity(Activity activity);
|
||||
public static native void nativeOpenURI(String uri);
|
||||
public static native void nativeShare(String text);
|
||||
}
|
||||
|
||||
@@ -393,12 +393,17 @@ public class Context extends Object {
|
||||
|
||||
public void startActivity(Intent intent) {
|
||||
Slog.i(TAG, "startActivity(" + intent + ") called");
|
||||
if ("android.intent.action.CHOOSER".equals(intent.getAction())) {
|
||||
if (intent.getAction() != null && intent.getAction().equals("android.intent.action.CHOOSER")) {
|
||||
intent = (Intent) intent.getExtras().get("android.intent.extra.INTENT");
|
||||
}
|
||||
if (intent.getComponent() == null) {
|
||||
Slog.i(TAG, "starting extern activity with intent: " + intent);
|
||||
Activity.nativeOpenURI(String.valueOf(intent.getData()));
|
||||
if(intent.getAction() != null && intent.getAction().equals("android.intent.action.SEND")) {
|
||||
Slog.i(TAG, "starting extern activity with intent: " + intent);
|
||||
Activity.nativeShare((String) intent.getExtras().get("android.intent.extra.TEXT"));
|
||||
} else if (intent.getData() != null) {
|
||||
Slog.i(TAG, "starting extern activity with intent: " + intent);
|
||||
Activity.nativeOpenURI(String.valueOf(intent.getData()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
||||
@@ -10,5 +10,4 @@ public class ContextWrapper extends Context {
|
||||
public Context getBaseContext() {
|
||||
return baseContext;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ public class Intent {
|
||||
private String action;
|
||||
private Uri data;
|
||||
private int flags;
|
||||
private String type;
|
||||
|
||||
public Intent() {}
|
||||
public Intent(Intent o) {
|
||||
@@ -43,10 +44,20 @@ public class Intent {
|
||||
this.flags = flags;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
public Intent setPackage(String packageName) {
|
||||
return this; //??
|
||||
}
|
||||
|
||||
public Intent setType(String type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Intent putExtra(String name, Parcelable value) {
|
||||
extras.putParcelable(name, value);
|
||||
return this;
|
||||
@@ -255,15 +266,10 @@ public class Intent {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Intent [component=" + component + ", extras=" + extras + ", action=" + action + ", uri=" + data + "]";
|
||||
return "Intent [component=" + component + ", extras=" + extras + ", action=" + action + ", type=" + type + ", uri=" + data + "]";
|
||||
}
|
||||
|
||||
public static Intent createChooser(Intent target, CharSequence title) {
|
||||
return target;
|
||||
}
|
||||
|
||||
public int getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user