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
move startActivity function to Context class
This way it can also be called on Application Context
This commit is contained in:
@@ -31,7 +31,7 @@ public class Activity extends Context implements Window.Callback {
|
||||
LayoutInflater layout_inflater;
|
||||
Window window = new Window(this);
|
||||
int requested_orientation = -1 /*ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED*/; // dummy
|
||||
private Intent intent;
|
||||
public Intent intent;
|
||||
private Activity resultActivity;
|
||||
private int resultRequestCode;
|
||||
private int pendingRequestCode;
|
||||
@@ -294,25 +294,6 @@ public class Activity extends Context implements Window.Callback {
|
||||
setResult(resultCode, null);
|
||||
}
|
||||
|
||||
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();
|
||||
Activity activity = constructor.newInstance();
|
||||
activity.intent = intent;
|
||||
activity.getWindow().native_window = getWindow().native_window;
|
||||
nativeStartActivity(activity);
|
||||
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public final void showDialog(int id) {
|
||||
System.out.println("Activity.showDialog(" + id + ") called");
|
||||
}
|
||||
@@ -340,8 +321,8 @@ public class Activity extends Context implements Window.Callback {
|
||||
public boolean isChangingConfigurations() {return false;}
|
||||
|
||||
private native void nativeFinish(long native_window);
|
||||
private static native void nativeStartActivity(Activity activity);
|
||||
private static native void nativeOpenURI(String uri);
|
||||
public static native void nativeStartActivity(Activity activity);
|
||||
public static native void nativeOpenURI(String uri);
|
||||
|
||||
@Override
|
||||
public void onContentChanged() {
|
||||
|
||||
@@ -13,6 +13,7 @@ import android.content.ContextWrapper;
|
||||
|
||||
public class Application extends ContextWrapper {
|
||||
private String app_icon_path = null;
|
||||
public long native_window;
|
||||
|
||||
private String get_app_icon_path() {
|
||||
return app_icon_path;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package android.content;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.Application;
|
||||
@@ -88,7 +89,7 @@ public class Context extends Object {
|
||||
}
|
||||
}
|
||||
|
||||
static Application createApplication() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException {
|
||||
static Application createApplication(long native_window) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException {
|
||||
Application application;
|
||||
ResXmlAttribute application_name = manifest.getApplicationElement().searchAttributeByResourceId(AndroidManifestBlock.ID_name);
|
||||
String className = (application_name != null) ? application_name.getValueAsString() : "android.app.Application";
|
||||
@@ -101,6 +102,7 @@ public class Context extends Object {
|
||||
ResXmlAttribute application_theme = manifest.getApplicationElement().searchAttributeByResourceId(AndroidManifestBlock.ID_theme);
|
||||
if (application_theme != null)
|
||||
application.setTheme(application_theme.getData());
|
||||
application.native_window = native_window;
|
||||
this_application = application;
|
||||
return application;
|
||||
}
|
||||
@@ -348,10 +350,25 @@ public class Context extends Object {
|
||||
}
|
||||
|
||||
public void startActivity(Intent intent) {
|
||||
Slog.w(TAG, "------------------");
|
||||
Slog.w(TAG, "app wants to startActivity("+intent+"), but we don't support that... :/");
|
||||
try { throw new java.lang.Exception(); } catch (java.lang.Exception e) { e.printStackTrace(); }
|
||||
Slog.w(TAG, "------------------");
|
||||
Slog.i(TAG, "startActivity(" + intent + ") called");
|
||||
if ("android.intent.action.CHOOSER".equals(intent.getAction())) {
|
||||
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()));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Class<? extends Activity> cls = Class.forName(intent.getComponent().getClassName()).asSubclass(Activity.class);
|
||||
Constructor<? extends Activity> constructor = cls.getConstructor();
|
||||
Activity activity = constructor.newInstance();
|
||||
activity.intent = intent;
|
||||
activity.getWindow().native_window = this_application.native_window;
|
||||
Activity.nativeStartActivity(activity);
|
||||
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public final TypedArray obtainStyledAttributes(AttributeSet set, int[] attrs) {
|
||||
|
||||
@@ -347,7 +347,7 @@ static void open(GtkApplication *app, GFile** files, gint nfiles, const gchar* h
|
||||
|
||||
// construct Application
|
||||
application_object = (*env)->CallStaticObjectMethod(env, handle_cache.context.class,
|
||||
_STATIC_METHOD(handle_cache.context.class, "createApplication", "()Landroid/app/Application;"));
|
||||
_STATIC_METHOD(handle_cache.context.class, "createApplication", "(J)Landroid/app/Application;"), window);
|
||||
if((*env)->ExceptionCheck(env))
|
||||
(*env)->ExceptionDescribe(env);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user