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 URL opening using libportal
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <gtk/gtk.h>
|
||||
#include <libportal/portal.h>
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
@@ -106,3 +107,14 @@ JNIEXPORT void JNICALL Java_android_app_Activity_nativeFinish(JNIEnv *env, jobje
|
||||
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) {
|
||||
if (!portal) {
|
||||
portal = xdp_portal_new();
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,14 @@ JNIEXPORT void JNICALL Java_android_app_Activity_nativeFinish
|
||||
JNIEXPORT void JNICALL Java_android_app_Activity_nativeStartActivity
|
||||
(JNIEnv *, jclass, jobject);
|
||||
|
||||
/*
|
||||
* Class: android_app_Activity
|
||||
* Method: nativeOpenURI
|
||||
* Signature: (Ljava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_app_Activity_nativeOpenURI
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -296,6 +296,11 @@ public class Activity extends Context implements Window.Callback {
|
||||
|
||||
public void startActivity(Intent intent) {
|
||||
System.out.println("startActivity(" + intent + ") called");
|
||||
if (intent.getComponent() == null) {
|
||||
System.out.println("starting extern activity with intent: " + intent);
|
||||
nativeOpenURI(String.valueOf(intent.getData()));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Class<? extends Activity> cls = Class.forName(intent.getComponent().getClassName()).asSubclass(Activity.class);
|
||||
Constructor<? extends Activity> constructor = cls.getConstructor();
|
||||
@@ -336,6 +341,7 @@ public class Activity extends Context implements Window.Callback {
|
||||
|
||||
private native void nativeFinish(long native_window);
|
||||
private static native void nativeStartActivity(Activity activity);
|
||||
private static native void nativeOpenURI(String uri);
|
||||
|
||||
@Override
|
||||
public void onContentChanged() {
|
||||
|
||||
@@ -8,15 +8,30 @@ import java.io.Serializable;
|
||||
public class Intent {
|
||||
private ComponentName component;
|
||||
private Bundle extras = new Bundle();
|
||||
private String action;
|
||||
private Uri data;
|
||||
|
||||
public Intent() {}
|
||||
public Intent(Intent o) {}
|
||||
public Intent(String action) {}
|
||||
public Intent(String action, Uri uri) {}
|
||||
public Intent(Intent o) {
|
||||
this.action = o.action;
|
||||
this.data = o.data;
|
||||
this.extras = o.extras;
|
||||
this.component = o.component;
|
||||
}
|
||||
public Intent(String action) {
|
||||
this.action = action;
|
||||
}
|
||||
public Intent(String action, Uri uri) {
|
||||
this.action = action;
|
||||
this.data = uri;
|
||||
}
|
||||
public Intent(Context packageContext, Class<?> cls) {
|
||||
setClass(packageContext, cls);
|
||||
}
|
||||
public Intent(String action, Uri uri, Context packageContext, Class<?> cls) {}
|
||||
public Intent(String action, Uri uri, Context packageContext, Class<?> cls) {
|
||||
this(action, uri);
|
||||
setClass(packageContext, cls);
|
||||
}
|
||||
|
||||
public Intent addFlags(int flags) {
|
||||
return this; //??
|
||||
@@ -159,7 +174,7 @@ public class Intent {
|
||||
}
|
||||
|
||||
public Uri getData() {
|
||||
return null;
|
||||
return data;
|
||||
}
|
||||
|
||||
public boolean getBooleanExtra(String name, boolean defaultValue) {
|
||||
@@ -209,7 +224,11 @@ public class Intent {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Intent [component=" + component + ", extras=" + extras + "]";
|
||||
return "Intent [component=" + component + ", extras=" + extras + ", action=" + action + ", uri=" + data + "]";
|
||||
}
|
||||
|
||||
public static Intent createChooser(Intent target, CharSequence title) {
|
||||
return target;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ public class PackageItemInfo {
|
||||
|
||||
public PackageItemInfo() {
|
||||
metaData = new Bundle();
|
||||
packageName = "android";
|
||||
}
|
||||
|
||||
public PackageItemInfo(PackageItemInfo orig) {
|
||||
|
||||
@@ -2132,7 +2132,7 @@ public class PackageManager {
|
||||
* @see #GET_RESOLVED_FILTER
|
||||
*/
|
||||
public ResolveInfo resolveActivity(Intent intent, int flags) {
|
||||
return null;
|
||||
return new ResolveInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package android.content.pm;
|
||||
|
||||
public class ResolveInfo {
|
||||
public ActivityInfo activityInfo = new ActivityInfo();
|
||||
}
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
package android.net;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
public class Uri {
|
||||
private URI uri;
|
||||
|
||||
public static Uri parse(String s) {
|
||||
return new Uri();
|
||||
Uri ret = new Uri();
|
||||
try {
|
||||
ret.uri = URI.create(s);
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Builder buildUpon() {
|
||||
@@ -14,4 +23,9 @@ public class Uri {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(uri);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user