Bladeren bron

Cleaned up unused imports in java files and added a JNI function to toggle the android keyboard along with a script binding for it

Tim Newell 12 jaren geleden
bovenliggende
commit
822f765399

+ 0 - 2
engine/compilers/android/src/com/garagegames/torque2d/FileWalker.java

@@ -1,9 +1,7 @@
 package com.garagegames.torque2d;
 package com.garagegames.torque2d;
 
 
 import java.io.IOException;
 import java.io.IOException;
-import java.io.InputStream;
 import java.util.Hashtable;
 import java.util.Hashtable;
-import java.util.List;
 import java.util.Vector;
 import java.util.Vector;
 
 
 import android.content.Context;
 import android.content.Context;

+ 0 - 2
engine/compilers/android/src/com/garagegames/torque2d/FontManager.java

@@ -6,7 +6,6 @@ package com.garagegames.torque2d;
  */
  */
  
  
 import java.io.File;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.IOException;
@@ -15,7 +14,6 @@ import java.io.RandomAccessFile;
 import java.util.HashMap;
 import java.util.HashMap;
 
 
 import android.content.Context;
 import android.content.Context;
-import android.content.res.AssetFileDescriptor;
 import android.content.res.AssetManager;
 import android.content.res.AssetManager;
 import android.util.Log;
 import android.util.Log;
  
  

+ 0 - 1
engine/compilers/android/src/com/garagegames/torque2d/MyNativeActivity.java

@@ -1,7 +1,6 @@
 package com.garagegames.torque2d;
 package com.garagegames.torque2d;
 
 
 import android.app.NativeActivity;
 import android.app.NativeActivity;
-import android.util.Log;
 
 
 public class MyNativeActivity extends NativeActivity {
 public class MyNativeActivity extends NativeActivity {
   static {
   static {

+ 0 - 3
engine/compilers/android/src/com/garagegames/torque2d/SplashScreen.java

@@ -10,11 +10,8 @@ import android.content.res.AssetManager;
 import android.graphics.Bitmap;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.BitmapFactory;
 import android.graphics.Color;
 import android.graphics.Color;
-import android.util.Log;
-import android.view.ViewGroup;
 import android.view.Window;
 import android.view.Window;
 import android.view.WindowManager;
 import android.view.WindowManager;
-import android.view.WindowManager.LayoutParams;
 import android.widget.ImageView;
 import android.widget.ImageView;
 import android.widget.ImageView.ScaleType;
 import android.widget.ImageView.ScaleType;
 
 

+ 0 - 1
engine/compilers/android/src/com/garagegames/torque2d/T2DUtilities.java

@@ -6,7 +6,6 @@ import android.content.Context;
 import android.content.DialogInterface;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.Intent;
 import android.net.Uri;
 import android.net.Uri;
-import android.util.Log;
 
 
 public class T2DUtilities {
 public class T2DUtilities {
 		
 		

+ 91 - 0
engine/source/platformAndroid/T2DActivity.cpp

@@ -351,6 +351,92 @@ void androidKeyboardEvent(int keyval, bool make) {
    Game->postEvent(event);
    Game->postEvent(event);
 }
 }
 
 
+void displayKeyboard(bool pShow) {
+    // Attaches the current thread to the JVM.
+    jint lResult;
+    jint lFlags = 0;
+
+    JavaVM* lJavaVM = platState.engine->app->activity->vm;
+    JNIEnv* lJNIEnv = platState.engine->app->activity->env;
+
+    JavaVMAttachArgs lJavaVMAttachArgs;
+    lJavaVMAttachArgs.version = JNI_VERSION_1_6;
+    lJavaVMAttachArgs.name = "NativeThread";
+    lJavaVMAttachArgs.group = NULL;
+
+    lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs);
+    if (lResult == JNI_ERR) {
+        return;
+    }
+
+    // Retrieves NativeActivity.
+    jobject lNativeActivity = platState.engine->app->activity->clazz;
+    jclass ClassNativeActivity = lJNIEnv->GetObjectClass(lNativeActivity);
+
+    // Retrieves Context.INPUT_METHOD_SERVICE.
+    jclass ClassContext = lJNIEnv->FindClass("android/content/Context");
+    jfieldID FieldINPUT_METHOD_SERVICE =
+        lJNIEnv->GetStaticFieldID(ClassContext,
+            "INPUT_METHOD_SERVICE", "Ljava/lang/String;");
+    jobject INPUT_METHOD_SERVICE =
+        lJNIEnv->GetStaticObjectField(ClassContext,
+            FieldINPUT_METHOD_SERVICE);
+    //jniCheck(INPUT_METHOD_SERVICE);
+
+    // Runs getSystemService(Context.INPUT_METHOD_SERVICE).
+    jclass ClassInputMethodManager = lJNIEnv->FindClass(
+        "android/view/inputmethod/InputMethodManager");
+    jmethodID MethodGetSystemService = lJNIEnv->GetMethodID(
+        ClassNativeActivity, "getSystemService",
+        "(Ljava/lang/String;)Ljava/lang/Object;");
+    jobject lInputMethodManager = lJNIEnv->CallObjectMethod(
+        lNativeActivity, MethodGetSystemService,
+        INPUT_METHOD_SERVICE);
+
+    // Runs getWindow().getDecorView().
+    jmethodID MethodGetWindow = lJNIEnv->GetMethodID(
+        ClassNativeActivity, "getWindow",
+        "()Landroid/view/Window;");
+    jobject lWindow = lJNIEnv->CallObjectMethod(lNativeActivity,
+        MethodGetWindow);
+    jclass ClassWindow = lJNIEnv->FindClass(
+        "android/view/Window");
+    jmethodID MethodGetDecorView = lJNIEnv->GetMethodID(
+        ClassWindow, "getDecorView", "()Landroid/view/View;");
+    jobject lDecorView = lJNIEnv->CallObjectMethod(lWindow,
+        MethodGetDecorView);
+
+    if (pShow) {
+        // Runs lInputMethodManager.showSoftInput(...).
+        jmethodID MethodShowSoftInput = lJNIEnv->GetMethodID(
+            ClassInputMethodManager, "showSoftInput",
+            "(Landroid/view/View;I)Z");
+        jboolean lResult = lJNIEnv->CallBooleanMethod(
+            lInputMethodManager, MethodShowSoftInput,
+            lDecorView, lFlags);
+    } else {
+        // Runs lWindow.getViewToken()
+        jclass ClassView = lJNIEnv->FindClass(
+            "android/view/View");
+        jmethodID MethodGetWindowToken = lJNIEnv->GetMethodID(
+            ClassView, "getWindowToken", "()Landroid/os/IBinder;");
+        jobject lBinder = lJNIEnv->CallObjectMethod(lDecorView,
+            MethodGetWindowToken);
+
+        // lInputMethodManager.hideSoftInput(...).
+        jmethodID MethodHideSoftInput = lJNIEnv->GetMethodID(
+            ClassInputMethodManager, "hideSoftInputFromWindow",
+            "(Landroid/os/IBinder;I)Z");
+        jboolean lRes = lJNIEnv->CallBooleanMethod(
+            lInputMethodManager, MethodHideSoftInput,
+            lBinder, lFlags);
+    }
+
+    // Finished with the JVM.
+    lJavaVM->DetachCurrentThread();
+    keyboardShowing = pShow;
+}
+
 Point2I rawLastTouches[10];
 Point2I rawLastTouches[10];
 
 
 // Handle touch and keyboard input from android OS
 // Handle touch and keyboard input from android OS
@@ -2477,6 +2563,11 @@ ConsoleFunction(isAccelerometerActive, bool, 1, 1, "() Check to see if Accelerom
 	return activity.isAccelerometerActive();
 	return activity.isAccelerometerActive();
 }
 }
 
 
+ConsoleFunction(toggleAndroidKeyboard, void, 2, 2, "(show) show or hide android virtual keyboard")
+{
+	displayKeyboard(dAtob(argv[1]));
+
+}
 
 
 void adprintf(const char* fmt,...) {
 void adprintf(const char* fmt,...) {