summaryrefslogtreecommitdiff
path: root/platform/android/java/src/org
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/java/src/org')
-rw-r--r--platform/android/java/src/org/godotengine/godot/Godot.java148
-rw-r--r--platform/android/java/src/org/godotengine/godot/GodotIO.java38
-rw-r--r--platform/android/java/src/org/godotengine/godot/GodotView.java59
-rw-r--r--platform/android/java/src/org/godotengine/godot/input/GodotEditText.java72
-rw-r--r--platform/android/java/src/org/godotengine/godot/input/InputManagerCompat.java7
-rw-r--r--platform/android/java/src/org/godotengine/godot/input/InputManagerV9.java209
-rw-r--r--platform/android/java/src/org/godotengine/godot/payments/ConsumeTask.java88
-rw-r--r--platform/android/java/src/org/godotengine/godot/payments/GenericConsumeTask.java79
-rw-r--r--platform/android/java/src/org/godotengine/godot/payments/PaymentsCache.java4
-rw-r--r--platform/android/java/src/org/godotengine/godot/payments/PaymentsManager.java4
-rw-r--r--platform/android/java/src/org/godotengine/godot/payments/ReleaseAllConsumablesTask.java82
-rw-r--r--platform/android/java/src/org/godotengine/godot/payments/ValidateTask.java129
-rw-r--r--platform/android/java/src/org/godotengine/godot/utils/HttpRequester.java4
13 files changed, 365 insertions, 558 deletions
diff --git a/platform/android/java/src/org/godotengine/godot/Godot.java b/platform/android/java/src/org/godotengine/godot/Godot.java
index 88194f00d1..e3878754a0 100644
--- a/platform/android/java/src/org/godotengine/godot/Godot.java
+++ b/platform/android/java/src/org/godotengine/godot/Godot.java
@@ -30,59 +30,48 @@
package org.godotengine.godot;
-import android.R;
+//import android.R;
+
import android.app.Activity;
+import android.app.ActivityManager;
+import android.app.AlertDialog;
+import android.app.PendingIntent;
+import android.content.ClipData;
+import android.content.ClipboardManager;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
import android.content.pm.ConfigurationInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.graphics.Point;
+import android.graphics.Rect;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
+import android.os.Build;
import android.os.Bundle;
+import android.os.Environment;
+import android.os.Messenger;
+import android.provider.Settings.Secure;
+import android.util.Log;
+import android.view.Display;
+import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
+import android.view.ViewGroup;
+import android.view.ViewGroup.LayoutParams;
+import android.view.ViewTreeObserver;
+import android.view.Window;
+import android.view.WindowManager;
import android.widget.Button;
+import android.widget.FrameLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
-import android.widget.LinearLayout;
import android.widget.TextView;
-import android.view.ViewGroup.LayoutParams;
-import android.app.*;
-import android.content.*;
-import android.content.SharedPreferences.Editor;
-import android.view.*;
-import android.view.inputmethod.InputMethodManager;
-import android.os.*;
-import android.util.Log;
-import android.graphics.*;
-import android.text.method.*;
-import android.text.*;
-import android.media.*;
-import android.hardware.*;
-import android.content.*;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.net.Uri;
-import android.media.MediaPlayer;
-
-import android.content.ClipboardManager;
-import android.content.ClipData;
-
-import java.lang.reflect.Method;
-import java.util.List;
-import java.util.ArrayList;
-
-import org.godotengine.godot.payments.PaymentsManager;
-import java.io.IOException;
-
-import android.provider.Settings.Secure;
-import android.widget.FrameLayout;
-
-import org.godotengine.godot.input.*;
-
-import java.io.InputStream;
-import javax.microedition.khronos.opengles.GL10;
-import java.security.MessageDigest;
-import java.io.File;
-import java.io.FileInputStream;
-import java.util.LinkedList;
-
-import com.google.android.vending.expansion.downloader.Constants;
import com.google.android.vending.expansion.downloader.DownloadProgressInfo;
import com.google.android.vending.expansion.downloader.DownloaderClientMarshaller;
import com.google.android.vending.expansion.downloader.DownloaderServiceMarshaller;
@@ -91,9 +80,20 @@ import com.google.android.vending.expansion.downloader.IDownloaderClient;
import com.google.android.vending.expansion.downloader.IDownloaderService;
import com.google.android.vending.expansion.downloader.IStub;
-import android.os.Bundle;
-import android.os.Messenger;
-import android.os.SystemClock;
+import org.godotengine.godot.input.GodotEditText;
+import org.godotengine.godot.payments.PaymentsManager;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.lang.reflect.Method;
+import java.security.MessageDigest;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+
+import javax.microedition.khronos.opengles.GL10;
public class Godot extends Activity implements SensorEventListener, IDownloaderClient {
@@ -222,9 +222,8 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
private Sensor mGyroscope;
public FrameLayout layout;
- public RelativeLayout adLayout;
- static public GodotIO io;
+ public static GodotIO io;
public static void setWindowTitle(String title) {
//setTitle(title);
@@ -263,24 +262,23 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
};
public void onVideoInit() {
-
boolean use_gl3 = getGLESVersionCode() >= 0x00030000;
//mView = new GodotView(getApplication(),io,use_gl3);
//setContentView(mView);
layout = new FrameLayout(this);
- layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
+ layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
setContentView(layout);
// GodotEditText layout
GodotEditText edittext = new GodotEditText(this);
- edittext.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
+ edittext.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
// ...add to FrameLayout
layout.addView(edittext);
mView = new GodotView(getApplication(), io, use_gl3, use_32_bits, use_debug_opengl, this);
- layout.addView(mView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
+ layout.addView(mView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
edittext.setView(mView);
io.setEdit(edittext);
@@ -298,11 +296,6 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
}
});
- // Ad layout
- adLayout = new RelativeLayout(this);
- adLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
- layout.addView(adLayout);
-
final String[] current_command_line = command_line;
final GodotView view = mView;
mView.queueEvent(new Runnable() {
@@ -332,10 +325,11 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
}
public void alert(final String message, final String title) {
+ final Activity activity = this;
runOnUiThread(new Runnable() {
@Override
public void run() {
- AlertDialog.Builder builder = new AlertDialog.Builder(getInstance());
+ AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setMessage(message).setTitle(title);
builder.setPositiveButton(
"OK",
@@ -350,14 +344,8 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
});
}
- private static Godot _self;
-
- public static Godot getInstance() {
- return Godot._self;
- }
-
public int getGLESVersionCode() {
- ActivityManager am = (ActivityManager)Godot.getInstance().getSystemService(Context.ACTIVITY_SERVICE);
+ ActivityManager am = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE);
ConfigurationInfo deviceInfo = am.getDeviceConfigurationInfo();
return deviceInfo.reqGlEsVersion;
}
@@ -421,7 +409,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
}
io = new GodotIO(this);
- io.unique_id = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
+ io.unique_id = Secure.ANDROID_ID;
GodotLib.io = io;
mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
@@ -452,7 +440,6 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
- _self = this;
Window window = getWindow();
//window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
@@ -476,7 +463,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
use_debug_opengl = true;
} else if (command_line[i].equals("--use_immersive")) {
use_immersive = true;
- if (Build.VERSION.SDK_INT >= 19.0) { // check if the application runs on an android 4.4+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // check if the application runs on an android 4.4+
window.getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
@@ -498,7 +485,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
Editor editor = prefs.edit();
editor.putString("store_public_key", main_pack_key);
- editor.commit();
+ editor.apply();
i++;
} else if (command_line[i].trim().length() != 0) {
new_args.add(command_line[i]);
@@ -665,7 +652,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_GAME);
mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_GAME);
- if (use_immersive && Build.VERSION.SDK_INT >= 19.0) { // check if the application runs on an android 4.4+
+ if (use_immersive && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // check if the application runs on an android 4.4+
Window window = getWindow();
window.getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
@@ -688,13 +675,15 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
@Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
- decorView.setSystemUiVisibility(
- View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
- View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
- View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
- View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
- View.SYSTEM_UI_FLAG_FULLSCREEN |
- View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ decorView.setSystemUiVisibility(
+ View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
+ View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
+ View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
+ View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
+ View.SYSTEM_UI_FLAG_FULLSCREEN |
+ View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
+ }
}
}
});
@@ -1024,12 +1013,9 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
mTimeRemaining.setText(getString(com.godot.game.R.string.time_remaining,
Helpers.getTimeRemaining(progress.mTimeRemaining)));
- progress.mOverallTotal = progress.mOverallTotal;
mPB.setMax((int)(progress.mOverallTotal >> 8));
mPB.setProgress((int)(progress.mOverallProgress >> 8));
- mProgressPercent.setText(Long.toString(progress.mOverallProgress * 100 /
- progress.mOverallTotal) +
- "%");
+ mProgressPercent.setText(String.format(Locale.ENGLISH, "%d %%", progress.mOverallProgress * 100 / progress.mOverallTotal));
mProgressFraction.setText(Helpers.getDownloadProgressString(progress.mOverallProgress,
progress.mOverallTotal));
}
diff --git a/platform/android/java/src/org/godotengine/godot/GodotIO.java b/platform/android/java/src/org/godotengine/godot/GodotIO.java
index a95c508d21..75d67831d4 100644
--- a/platform/android/java/src/org/godotengine/godot/GodotIO.java
+++ b/platform/android/java/src/org/godotengine/godot/GodotIO.java
@@ -38,6 +38,7 @@ import java.io.InputStream;
import java.io.IOException;
import android.app.*;
import android.content.*;
+import android.util.SparseArray;
import android.view.*;
import android.view.inputmethod.InputMethodManager;
import android.os.*;
@@ -61,7 +62,6 @@ public class GodotIO {
Godot activity;
GodotEditText edit;
- Context applicationContext;
MediaPlayer mediaPlayer;
final int SCREEN_LANDSCAPE = 0;
@@ -87,7 +87,7 @@ public class GodotIO {
public int pos;
}
- HashMap<Integer, AssetData> streams;
+ SparseArray<AssetData> streams;
public int file_open(String path, boolean write) {
@@ -125,7 +125,7 @@ public class GodotIO {
}
public int file_get_size(int id) {
- if (!streams.containsKey(id)) {
+ if (streams.get(id) == null) {
System.out.printf("file_get_size: Invalid file id: %d\n", id);
return -1;
}
@@ -134,7 +134,7 @@ public class GodotIO {
}
public void file_seek(int id, int bytes) {
- if (!streams.containsKey(id)) {
+ if (streams.get(id) == null) {
System.out.printf("file_get_size: Invalid file id: %d\n", id);
return;
}
@@ -174,7 +174,7 @@ public class GodotIO {
public int file_tell(int id) {
- if (!streams.containsKey(id)) {
+ if (streams.get(id) == null) {
System.out.printf("file_read: Can't tell eof for invalid file id: %d\n", id);
return 0;
}
@@ -184,7 +184,7 @@ public class GodotIO {
}
public boolean file_eof(int id) {
- if (!streams.containsKey(id)) {
+ if (streams.get(id) == null) {
System.out.printf("file_read: Can't check eof for invalid file id: %d\n", id);
return false;
}
@@ -195,7 +195,7 @@ public class GodotIO {
public byte[] file_read(int id, int bytes) {
- if (!streams.containsKey(id)) {
+ if (streams.get(id) == null) {
System.out.printf("file_read: Can't read invalid file id: %d\n", id);
return new byte[0];
}
@@ -243,7 +243,7 @@ public class GodotIO {
public void file_close(int id) {
- if (!streams.containsKey(id)) {
+ if (streams.get(id) == null) {
System.out.printf("file_close: Can't close invalid file id: %d\n", id);
return;
}
@@ -264,7 +264,7 @@ public class GodotIO {
public int last_dir_id = 1;
- HashMap<Integer, AssetDir> dirs;
+ SparseArray<AssetDir> dirs;
public int dir_open(String path) {
@@ -293,7 +293,7 @@ public class GodotIO {
}
public boolean dir_is_dir(int id) {
- if (!dirs.containsKey(id)) {
+ if (dirs.get(id) == null) {
System.out.printf("dir_next: invalid dir id: %d\n", id);
return false;
}
@@ -320,7 +320,7 @@ public class GodotIO {
public String dir_next(int id) {
- if (!dirs.containsKey(id)) {
+ if (dirs.get(id) == null) {
System.out.printf("dir_next: invalid dir id: %d\n", id);
return "";
}
@@ -339,7 +339,7 @@ public class GodotIO {
public void dir_close(int id) {
- if (!dirs.containsKey(id)) {
+ if (dirs.get(id) == null) {
System.out.printf("dir_close: invalid dir id: %d\n", id);
return;
}
@@ -351,9 +351,9 @@ public class GodotIO {
am = p_activity.getAssets();
activity = p_activity;
- streams = new HashMap<Integer, AssetData>();
- dirs = new HashMap<Integer, AssetDir>();
- applicationContext = activity.getApplicationContext();
+ //streams = new HashMap<Integer, AssetData>();
+ streams = new SparseArray<AssetData>();
+ dirs = new SparseArray<AssetDir>();
}
/////////////////////////
@@ -365,7 +365,7 @@ public class GodotIO {
private AudioTrack mAudioTrack;
public Object audioInit(int sampleRate, int desiredFrames) {
- int channelConfig = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
+ int channelConfig = AudioFormat.CHANNEL_OUT_STEREO;
int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
int frameSize = 4;
@@ -496,13 +496,13 @@ public class GodotIO {
}
public int getScreenDPI() {
- DisplayMetrics metrics = applicationContext.getResources().getDisplayMetrics();
+ DisplayMetrics metrics = activity.getApplicationContext().getResources().getDisplayMetrics();
return (int)(metrics.density * 160f);
}
public boolean needsReloadHooks() {
- return android.os.Build.VERSION.SDK_INT < 11;
+ return false;
}
public void showKeyboard(String p_existing_text) {
@@ -564,7 +564,7 @@ public class GodotIO {
try {
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
- mediaPlayer.setDataSource(applicationContext, filePath);
+ mediaPlayer.setDataSource(activity.getApplicationContext(), filePath);
mediaPlayer.prepare();
mediaPlayer.start();
} catch (IOException e) {
diff --git a/platform/android/java/src/org/godotengine/godot/GodotView.java b/platform/android/java/src/org/godotengine/godot/GodotView.java
index 4cb4db33de..da5a8b11e2 100644
--- a/platform/android/java/src/org/godotengine/godot/GodotView.java
+++ b/platform/android/java/src/org/godotengine/godot/GodotView.java
@@ -29,6 +29,7 @@
/*************************************************************************/
package org.godotengine.godot;
+import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.PixelFormat;
import android.opengl.GLSurfaceView;
@@ -75,9 +76,9 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
private static String TAG = "GodotView";
private static final boolean DEBUG = false;
- private static Context ctx;
+ private Context ctx;
- private static GodotIO io;
+ private GodotIO io;
private static boolean firsttime = true;
private static boolean use_gl3 = false;
private static boolean use_32 = false;
@@ -105,20 +106,26 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
init(false, 16, 0);
}
+ public GodotView(Context context) {
+ super(context);
+ ctx = context;
+ }
+
public GodotView(Context context, boolean translucent, int depth, int stencil) {
super(context);
init(translucent, depth, stencil);
}
+ @SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
return activity.gotTouchEvent(event);
- };
+ }
public int get_godot_button(int keyCode) {
- int button = 0;
+ int button;
switch (keyCode) {
case KeyEvent.KEYCODE_BUTTON_A: // Android A is SNES B
button = 0;
@@ -178,7 +185,7 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
default:
button = keyCode - KeyEvent.KEYCODE_BUTTON_1 + 20;
break;
- };
+ }
return button;
};
@@ -440,6 +447,10 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
private static class ContextFactory implements GLSurfaceView.EGLContextFactory {
private static int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {
+ String driver_name = GodotLib.getGlobal("rendering/quality/driver/driver_name");
+ if (use_gl3 && !driver_name.equals("GLES3")) {
+ use_gl3 = false;
+ }
if (use_gl3)
Log.w(TAG, "creating OpenGL ES 3.0 context :");
else
@@ -508,26 +519,24 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
* perform actual matching in chooseConfig() below.
*/
private static int EGL_OPENGL_ES2_BIT = 4;
- private static int[] s_configAttribs2 =
- {
- EGL10.EGL_RED_SIZE, 4,
- EGL10.EGL_GREEN_SIZE, 4,
- EGL10.EGL_BLUE_SIZE, 4,
- // EGL10.EGL_DEPTH_SIZE, 16,
- // EGL10.EGL_STENCIL_SIZE, EGL10.EGL_DONT_CARE,
- EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
- EGL10.EGL_NONE
- };
- private static int[] s_configAttribs3 =
- {
- EGL10.EGL_RED_SIZE, 4,
- EGL10.EGL_GREEN_SIZE, 4,
- EGL10.EGL_BLUE_SIZE, 4,
- // EGL10.EGL_DEPTH_SIZE, 16,
- // EGL10.EGL_STENCIL_SIZE, EGL10.EGL_DONT_CARE,
- EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, //apparently there is no EGL_OPENGL_ES3_BIT
- EGL10.EGL_NONE
- };
+ private static int[] s_configAttribs2 = {
+ EGL10.EGL_RED_SIZE, 4,
+ EGL10.EGL_GREEN_SIZE, 4,
+ EGL10.EGL_BLUE_SIZE, 4,
+ // EGL10.EGL_DEPTH_SIZE, 16,
+ // EGL10.EGL_STENCIL_SIZE, EGL10.EGL_DONT_CARE,
+ EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+ EGL10.EGL_NONE
+ };
+ private static int[] s_configAttribs3 = {
+ EGL10.EGL_RED_SIZE, 4,
+ EGL10.EGL_GREEN_SIZE, 4,
+ EGL10.EGL_BLUE_SIZE, 4,
+ // EGL10.EGL_DEPTH_SIZE, 16,
+ // EGL10.EGL_STENCIL_SIZE, EGL10.EGL_DONT_CARE,
+ EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, //apparently there is no EGL_OPENGL_ES3_BIT
+ EGL10.EGL_NONE
+ };
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
diff --git a/platform/android/java/src/org/godotengine/godot/input/GodotEditText.java b/platform/android/java/src/org/godotengine/godot/input/GodotEditText.java
index 53fcf5ef70..b2ac2c0d67 100644
--- a/platform/android/java/src/org/godotengine/godot/input/GodotEditText.java
+++ b/platform/android/java/src/org/godotengine/godot/input/GodotEditText.java
@@ -39,6 +39,8 @@ import android.os.Message;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.EditorInfo;
+import java.lang.ref.WeakReference;
+
public class GodotEditText extends EditText {
// ===========================================================
// Constants
@@ -51,9 +53,24 @@ public class GodotEditText extends EditText {
// ===========================================================
private GodotView mView;
private GodotTextInputWrapper mInputWrapper;
- private static Handler sHandler;
+ private EditHandler sHandler = new EditHandler(this);
private String mOriginText;
+ private static class EditHandler extends Handler {
+ private final WeakReference<GodotEditText> mEdit;
+ public EditHandler(GodotEditText edit) {
+ mEdit = new WeakReference<>(edit);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ GodotEditText edit = mEdit.get();
+ if (edit != null) {
+ edit.handleMessage(msg);
+ }
+ }
+ }
+
// ===========================================================
// Constructors
// ===========================================================
@@ -75,36 +92,33 @@ public class GodotEditText extends EditText {
protected void initView() {
this.setPadding(0, 0, 0, 0);
this.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
+ }
- sHandler = new Handler() {
- @Override
- public void handleMessage(final Message msg) {
- switch (msg.what) {
- case HANDLER_OPEN_IME_KEYBOARD: {
- GodotEditText edit = (GodotEditText)msg.obj;
- String text = edit.mOriginText;
- if (edit.requestFocus()) {
- edit.removeTextChangedListener(edit.mInputWrapper);
- edit.setText("");
- edit.append(text);
- edit.mInputWrapper.setOriginText(text);
- edit.addTextChangedListener(edit.mInputWrapper);
- final InputMethodManager imm = (InputMethodManager)mView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.showSoftInput(edit, 0);
- }
- } break;
-
- case HANDLER_CLOSE_IME_KEYBOARD: {
- GodotEditText edit = (GodotEditText)msg.obj;
-
- edit.removeTextChangedListener(mInputWrapper);
- final InputMethodManager imm = (InputMethodManager)mView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.hideSoftInputFromWindow(edit.getWindowToken(), 0);
- edit.mView.requestFocus();
- } break;
+ private void handleMessage(final Message msg) {
+ switch (msg.what) {
+ case HANDLER_OPEN_IME_KEYBOARD: {
+ GodotEditText edit = (GodotEditText)msg.obj;
+ String text = edit.mOriginText;
+ if (edit.requestFocus()) {
+ edit.removeTextChangedListener(edit.mInputWrapper);
+ edit.setText("");
+ edit.append(text);
+ edit.mInputWrapper.setOriginText(text);
+ edit.addTextChangedListener(edit.mInputWrapper);
+ final InputMethodManager imm = (InputMethodManager)mView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.showSoftInput(edit, 0);
}
- }
- };
+ } break;
+
+ case HANDLER_CLOSE_IME_KEYBOARD: {
+ GodotEditText edit = (GodotEditText)msg.obj;
+
+ edit.removeTextChangedListener(mInputWrapper);
+ final InputMethodManager imm = (InputMethodManager)mView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.hideSoftInputFromWindow(edit.getWindowToken(), 0);
+ edit.mView.requestFocus();
+ } break;
+ }
}
// ===========================================================
diff --git a/platform/android/java/src/org/godotengine/godot/input/InputManagerCompat.java b/platform/android/java/src/org/godotengine/godot/input/InputManagerCompat.java
index 0a876d2b7f..4042c42e9d 100644
--- a/platform/android/java/src/org/godotengine/godot/input/InputManagerCompat.java
+++ b/platform/android/java/src/org/godotengine/godot/input/InputManagerCompat.java
@@ -17,7 +17,6 @@
package org.godotengine.godot.input;
import android.content.Context;
-import android.os.Build;
import android.os.Handler;
import android.view.InputDevice;
import android.view.MotionEvent;
@@ -130,11 +129,7 @@ public interface InputManagerCompat {
* @return a compatible implementation of InputManager
*/
public static InputManagerCompat getInputManager(Context context) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- return new InputManagerV16(context);
- } else {
- return new InputManagerV9();
- }
+ return new InputManagerV16(context);
}
}
}
diff --git a/platform/android/java/src/org/godotengine/godot/input/InputManagerV9.java b/platform/android/java/src/org/godotengine/godot/input/InputManagerV9.java
deleted file mode 100644
index a1418c5899..0000000000
--- a/platform/android/java/src/org/godotengine/godot/input/InputManagerV9.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.godotengine.godot.input;
-
-import android.os.Handler;
-import android.os.Message;
-import android.os.SystemClock;
-import android.util.Log;
-import android.util.SparseArray;
-import android.view.InputDevice;
-import android.view.MotionEvent;
-
-import java.lang.ref.WeakReference;
-import java.util.ArrayDeque;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Queue;
-
-public class InputManagerV9 implements InputManagerCompat {
- private static final String LOG_TAG = "InputManagerV9";
- private static final int MESSAGE_TEST_FOR_DISCONNECT = 101;
- private static final long CHECK_ELAPSED_TIME = 3000L;
-
- private static final int ON_DEVICE_ADDED = 0;
- private static final int ON_DEVICE_CHANGED = 1;
- private static final int ON_DEVICE_REMOVED = 2;
-
- private final SparseArray<long[]> mDevices;
- private final Map<InputDeviceListener, Handler> mListeners;
- private final Handler mDefaultHandler;
-
- private static class PollingMessageHandler extends Handler {
- private final WeakReference<InputManagerV9> mInputManager;
-
- PollingMessageHandler(InputManagerV9 im) {
- mInputManager = new WeakReference<InputManagerV9>(im);
- }
-
- @Override
- public void handleMessage(Message msg) {
- super.handleMessage(msg);
- switch (msg.what) {
- case MESSAGE_TEST_FOR_DISCONNECT:
- InputManagerV9 imv = mInputManager.get();
- if (null != imv) {
- long time = SystemClock.elapsedRealtime();
- int size = imv.mDevices.size();
- for (int i = 0; i < size; i++) {
- long[] lastContact = imv.mDevices.valueAt(i);
- if (null != lastContact) {
- if (time - lastContact[0] > CHECK_ELAPSED_TIME) {
- // check to see if the device has been
- // disconnected
- int id = imv.mDevices.keyAt(i);
- if (null == InputDevice.getDevice(id)) {
- // disconnected!
- imv.notifyListeners(ON_DEVICE_REMOVED, id);
- imv.mDevices.remove(id);
- } else {
- lastContact[0] = time;
- }
- }
- }
- }
- sendEmptyMessageDelayed(MESSAGE_TEST_FOR_DISCONNECT,
- CHECK_ELAPSED_TIME);
- }
- break;
- }
- }
- }
-
- public InputManagerV9() {
- mDevices = new SparseArray<long[]>();
- mListeners = new HashMap<InputDeviceListener, Handler>();
- mDefaultHandler = new PollingMessageHandler(this);
- // as a side-effect, populates our collection of watched
- // input devices
- getInputDeviceIds();
- }
-
- @Override
- public InputDevice getInputDevice(int id) {
- return InputDevice.getDevice(id);
- }
-
- @Override
- public int[] getInputDeviceIds() {
- // add any hitherto unknown devices to our
- // collection of watched input devices
- int[] activeDevices = InputDevice.getDeviceIds();
- long time = SystemClock.elapsedRealtime();
- for (int id : activeDevices) {
- long[] lastContact = mDevices.get(id);
- if (null == lastContact) {
- // we have a new device
- mDevices.put(id, new long[] { time });
- }
- }
- return activeDevices;
- }
-
- @Override
- public void registerInputDeviceListener(InputDeviceListener listener, Handler handler) {
- mListeners.remove(listener);
- if (handler == null) {
- handler = mDefaultHandler;
- }
- mListeners.put(listener, handler);
- }
-
- @Override
- public void unregisterInputDeviceListener(InputDeviceListener listener) {
- mListeners.remove(listener);
- }
-
- private void notifyListeners(int why, int deviceId) {
- // the state of some device has changed
- if (!mListeners.isEmpty()) {
- // yes... this will cause an object to get created... hopefully
- // it won't happen very often
- for (InputDeviceListener listener : mListeners.keySet()) {
- Handler handler = mListeners.get(listener);
- DeviceEvent odc = DeviceEvent.getDeviceEvent(why, deviceId, listener);
- handler.post(odc);
- }
- }
- }
-
- private static class DeviceEvent implements Runnable {
- private int mMessageType;
- private int mId;
- private InputDeviceListener mListener;
- private static Queue<DeviceEvent> sEventQueue = new ArrayDeque<DeviceEvent>();
-
- private DeviceEvent() {
- }
-
- static DeviceEvent getDeviceEvent(int messageType, int id,
- InputDeviceListener listener) {
- DeviceEvent curChanged = sEventQueue.poll();
- if (null == curChanged) {
- curChanged = new DeviceEvent();
- }
- curChanged.mMessageType = messageType;
- curChanged.mId = id;
- curChanged.mListener = listener;
- return curChanged;
- }
-
- @Override
- public void run() {
- switch (mMessageType) {
- case ON_DEVICE_ADDED:
- mListener.onInputDeviceAdded(mId);
- break;
- case ON_DEVICE_CHANGED:
- mListener.onInputDeviceChanged(mId);
- break;
- case ON_DEVICE_REMOVED:
- mListener.onInputDeviceRemoved(mId);
- break;
- default:
- Log.e(LOG_TAG, "Unknown Message Type");
- break;
- }
- // dump this runnable back in the queue
- sEventQueue.offer(this);
- }
- }
-
- @Override
- public void onGenericMotionEvent(MotionEvent event) {
- // detect new devices
- int id = event.getDeviceId();
- long[] timeArray = mDevices.get(id);
- if (null == timeArray) {
- notifyListeners(ON_DEVICE_ADDED, id);
- timeArray = new long[1];
- mDevices.put(id, timeArray);
- }
- long time = SystemClock.elapsedRealtime();
- timeArray[0] = time;
- }
-
- @Override
- public void onPause() {
- mDefaultHandler.removeMessages(MESSAGE_TEST_FOR_DISCONNECT);
- }
-
- @Override
- public void onResume() {
- mDefaultHandler.sendEmptyMessage(MESSAGE_TEST_FOR_DISCONNECT);
- }
-}
diff --git a/platform/android/java/src/org/godotengine/godot/payments/ConsumeTask.java b/platform/android/java/src/org/godotengine/godot/payments/ConsumeTask.java
index 5d94e77cd7..fe67f42f19 100644
--- a/platform/android/java/src/org/godotengine/godot/payments/ConsumeTask.java
+++ b/platform/android/java/src/org/godotengine/godot/payments/ConsumeTask.java
@@ -37,59 +37,81 @@ import android.os.AsyncTask;
import android.os.RemoteException;
import android.util.Log;
+import java.lang.ref.WeakReference;
+
abstract public class ConsumeTask {
private Context context;
-
private IInAppBillingService mService;
+
+ private String mSku;
+ private String mToken;
+
+ private static class ConsumeAsyncTask extends AsyncTask<String, String, String> {
+
+ private WeakReference<ConsumeTask> mTask;
+
+ ConsumeAsyncTask(ConsumeTask consume) {
+ mTask = new WeakReference<>(consume);
+ }
+
+ @Override
+ protected String doInBackground(String... strings) {
+ ConsumeTask consume = mTask.get();
+ if (consume != null) {
+ return consume.doInBackground(strings);
+ }
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(String param) {
+ ConsumeTask consume = mTask.get();
+ if (consume != null) {
+ consume.onPostExecute(param);
+ }
+ }
+ }
+
public ConsumeTask(IInAppBillingService mService, Context context) {
this.context = context;
this.mService = mService;
}
public void consume(final String sku) {
- //Log.d("XXX", "Consuming product " + sku);
+ mSku = sku;
PaymentsCache pc = new PaymentsCache(context);
Boolean isBlocked = pc.getConsumableFlag("block", sku);
- String _token = pc.getConsumableValue("token", sku);
- //Log.d("XXX", "token " + _token);
- if (!isBlocked && _token == null) {
- //_token = "inapp:"+context.getPackageName()+":android.test.purchased";
- //Log.d("XXX", "Consuming product " + sku + " with token " + _token);
+ mToken = pc.getConsumableValue("token", sku);
+ if (!isBlocked && mToken == null) {
+ // Consuming task is processing
} else if (!isBlocked) {
- //Log.d("XXX", "It is not blocked ¿?");
return;
- } else if (_token == null) {
- //Log.d("XXX", "No token available");
+ } else if (mToken == null) {
this.error("No token for sku:" + sku);
return;
}
- final String token = _token;
- new AsyncTask<String, String, String>() {
- @Override
- protected String doInBackground(String... params) {
- try {
- //Log.d("XXX", "Requesting to release item.");
- int response = mService.consumePurchase(3, context.getPackageName(), token);
- //Log.d("XXX", "release response code: " + response);
- if (response == 0 || response == 8) {
- return null;
- }
- } catch (RemoteException e) {
- return e.getMessage();
- }
- return "Some error";
- }
+ new ConsumeAsyncTask(this).execute();
+ }
- protected void onPostExecute(String param) {
- if (param == null) {
- success(new PaymentsCache(context).getConsumableValue("ticket", sku));
- } else {
- error(param);
- }
+ private String doInBackground(String... params) {
+ try {
+ int response = mService.consumePurchase(3, context.getPackageName(), mToken);
+ if (response == 0 || response == 8) {
+ return null;
}
+ } catch (RemoteException e) {
+ return e.getMessage();
+ }
+ return "Some error";
+ }
+
+ private void onPostExecute(String param) {
+ if (param == null) {
+ success(new PaymentsCache(context).getConsumableValue("ticket", mSku));
+ } else {
+ error(param);
}
- .execute();
}
abstract protected void success(String ticket);
diff --git a/platform/android/java/src/org/godotengine/godot/payments/GenericConsumeTask.java b/platform/android/java/src/org/godotengine/godot/payments/GenericConsumeTask.java
deleted file mode 100644
index 8b48193ae2..0000000000
--- a/platform/android/java/src/org/godotengine/godot/payments/GenericConsumeTask.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*************************************************************************/
-/* GenericConsumeTask.java */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-
-package org.godotengine.godot.payments;
-
-import com.android.vending.billing.IInAppBillingService;
-
-import android.content.Context;
-import android.os.AsyncTask;
-import android.os.RemoteException;
-import android.util.Log;
-
-abstract public class GenericConsumeTask extends AsyncTask<String, String, String> {
-
- private Context context;
- private IInAppBillingService mService;
-
- public GenericConsumeTask(Context context, IInAppBillingService mService, String sku, String receipt, String signature, String token) {
- this.context = context;
- this.mService = mService;
- this.sku = sku;
- this.receipt = receipt;
- this.signature = signature;
- this.token = token;
- }
-
- private String sku;
- private String receipt;
- private String signature;
- private String token;
-
- @Override
- protected String doInBackground(String... params) {
- try {
- //Log.d("godot", "Requesting to consume an item with token ." + token);
- int response = mService.consumePurchase(3, context.getPackageName(), token);
- //Log.d("godot", "consumePurchase response: " + response);
- if (response == 0 || response == 8) {
- return null;
- }
- } catch (Exception e) {
- Log.d("godot", "Error " + e.getClass().getName() + ":" + e.getMessage());
- }
- return null;
- }
-
- protected void onPostExecute(String sarasa) {
- onSuccess(sku, receipt, signature, token);
- }
-
- abstract public void onSuccess(String sku, String receipt, String signature, String token);
-}
diff --git a/platform/android/java/src/org/godotengine/godot/payments/PaymentsCache.java b/platform/android/java/src/org/godotengine/godot/payments/PaymentsCache.java
index 40cdeea72e..715f6e6f93 100644
--- a/platform/android/java/src/org/godotengine/godot/payments/PaymentsCache.java
+++ b/platform/android/java/src/org/godotengine/godot/payments/PaymentsCache.java
@@ -46,7 +46,7 @@ public class PaymentsCache {
SharedPreferences sharedPref = context.getSharedPreferences("consumables_" + set, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putBoolean(sku, flag);
- editor.commit();
+ editor.apply();
}
public boolean getConsumableFlag(String set, String sku) {
@@ -60,7 +60,7 @@ public class PaymentsCache {
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString(sku, value);
//Log.d("XXX", "Setting asset: consumables_" + set + ":" + sku);
- editor.commit();
+ editor.apply();
}
public String getConsumableValue(String set, String sku) {
diff --git a/platform/android/java/src/org/godotengine/godot/payments/PaymentsManager.java b/platform/android/java/src/org/godotengine/godot/payments/PaymentsManager.java
index d4c7380424..b3b27ec1b9 100644
--- a/platform/android/java/src/org/godotengine/godot/payments/PaymentsManager.java
+++ b/platform/android/java/src/org/godotengine/godot/payments/PaymentsManager.java
@@ -112,7 +112,7 @@ public class PaymentsManager {
};
public void requestPurchase(final String sku, String transactionId) {
- new PurchaseTask(mService, Godot.getInstance()) {
+ new PurchaseTask(mService, activity) {
@Override
protected void error(String message) {
godotPaymentV3.callbackFail(message);
@@ -159,7 +159,7 @@ public class PaymentsManager {
public void requestPurchased() {
try {
- PaymentsCache pc = new PaymentsCache(Godot.getInstance());
+ PaymentsCache pc = new PaymentsCache(activity);
String continueToken = null;
diff --git a/platform/android/java/src/org/godotengine/godot/payments/ReleaseAllConsumablesTask.java b/platform/android/java/src/org/godotengine/godot/payments/ReleaseAllConsumablesTask.java
index eccc6f671b..fd6fff3fa9 100644
--- a/platform/android/java/src/org/godotengine/godot/payments/ReleaseAllConsumablesTask.java
+++ b/platform/android/java/src/org/godotengine/godot/payments/ReleaseAllConsumablesTask.java
@@ -30,26 +30,59 @@
package org.godotengine.godot.payments;
-import java.util.ArrayList;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import org.godotengine.godot.Dictionary;
-import org.godotengine.godot.Godot;
-import com.android.vending.billing.IInAppBillingService;
-
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
-import android.os.RemoteException;
import android.util.Log;
+import com.android.vending.billing.IInAppBillingService;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+
abstract public class ReleaseAllConsumablesTask {
private Context context;
private IInAppBillingService mService;
+ private static class ReleaseAllConsumablesAsyncTask extends AsyncTask<String, String, String> {
+
+ private WeakReference<ReleaseAllConsumablesTask> mTask;
+ private String mSku;
+ private String mReceipt;
+ private String mSignature;
+ private String mToken;
+
+ ReleaseAllConsumablesAsyncTask(ReleaseAllConsumablesTask task, String sku, String receipt, String signature, String token) {
+ mTask = new WeakReference<ReleaseAllConsumablesTask>(task);
+
+ mSku = sku;
+ mReceipt = receipt;
+ mSignature = signature;
+ mToken = token;
+ }
+
+ @Override
+ protected String doInBackground(String... params) {
+ ReleaseAllConsumablesTask consume = mTask.get();
+ if (consume != null) {
+ return consume.doInBackground(mToken);
+ }
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(String param) {
+ ReleaseAllConsumablesTask consume = mTask.get();
+ if (consume != null) {
+ consume.success(mSku, mReceipt, mSignature, mToken);
+ }
+ }
+ }
+
public ReleaseAllConsumablesTask(IInAppBillingService mService, Context context) {
this.context = context;
this.mService = mService;
@@ -60,12 +93,6 @@ abstract public class ReleaseAllConsumablesTask {
//Log.d("godot", "consumeItall for " + context.getPackageName());
Bundle bundle = mService.getPurchases(3, context.getPackageName(), "inapp", null);
- for (String key : bundle.keySet()) {
- Object value = bundle.get(key);
- //Log.d("godot", String.format("%s %s (%s)", key,
- //value.toString(), value.getClass().getName()));
- }
-
if (bundle.getInt("RESPONSE_CODE") == 0) {
final ArrayList<String> myPurchases = bundle.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
@@ -87,14 +114,7 @@ abstract public class ReleaseAllConsumablesTask {
String token = inappPurchaseData.getString("purchaseToken");
String signature = mySignatures.get(i);
//Log.d("godot", "A punto de consumir un item con token:" + token + "\n" + receipt);
- new GenericConsumeTask(context, mService, sku, receipt, signature, token) {
- @Override
- public void onSuccess(String sku, String receipt, String signature, String token) {
- ReleaseAllConsumablesTask.this.success(sku, receipt, signature, token);
- }
- }
- .execute();
-
+ new ReleaseAllConsumablesAsyncTask(this, sku, receipt, signature, token).execute();
} catch (JSONException e) {
}
}
@@ -104,6 +124,20 @@ abstract public class ReleaseAllConsumablesTask {
}
}
+ private String doInBackground(String token) {
+ try {
+ //Log.d("godot", "Requesting to consume an item with token ." + token);
+ int response = mService.consumePurchase(3, context.getPackageName(), token);
+ //Log.d("godot", "consumePurchase response: " + response);
+ if (response == 0 || response == 8) {
+ return null;
+ }
+ } catch (Exception e) {
+ Log.d("godot", "Error " + e.getClass().getName() + ":" + e.getMessage());
+ }
+ return null;
+ }
+
abstract protected void success(String sku, String receipt, String signature, String token);
abstract protected void error(String message);
abstract protected void notRequired();
diff --git a/platform/android/java/src/org/godotengine/godot/payments/ValidateTask.java b/platform/android/java/src/org/godotengine/godot/payments/ValidateTask.java
index 0626e50bb1..2d1c467235 100644
--- a/platform/android/java/src/org/godotengine/godot/payments/ValidateTask.java
+++ b/platform/android/java/src/org/godotengine/godot/payments/ValidateTask.java
@@ -52,69 +52,104 @@ import android.os.Bundle;
import android.os.RemoteException;
import android.util.Log;
+import java.lang.ref.WeakReference;
+
abstract public class ValidateTask {
private Activity context;
private GodotPaymentV3 godotPaymentsV3;
+ private ProgressDialog dialog;
+ private String mSku;
+
+ private static class ValidateAsyncTask extends AsyncTask<String, String, String> {
+ private WeakReference<ValidateTask> mTask;
+
+ ValidateAsyncTask(ValidateTask task) {
+ mTask = new WeakReference<>(task);
+ }
+
+ @Override
+ protected void onPreExecute() {
+ ValidateTask task = mTask.get();
+ if (task != null) {
+ task.onPreExecute();
+ }
+ }
+
+ @Override
+ protected String doInBackground(String... params) {
+ ValidateTask task = mTask.get();
+ if (task != null) {
+ return task.doInBackground(params);
+ }
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(String response) {
+ ValidateTask task = mTask.get();
+ if (task != null) {
+ task.onPostExecute(response);
+ }
+ }
+ }
+
public ValidateTask(Activity context, GodotPaymentV3 godotPaymentsV3) {
this.context = context;
this.godotPaymentsV3 = godotPaymentsV3;
}
public void validatePurchase(final String sku) {
- new AsyncTask<String, String, String>() {
- private ProgressDialog dialog;
+ mSku = sku;
+ new ValidateAsyncTask(this).execute();
+ }
- @Override
- protected void onPreExecute() {
- dialog = ProgressDialog.show(context, null, "Please wait...");
- }
+ private void onPreExecute() {
+ dialog = ProgressDialog.show(context, null, "Please wait...");
+ }
- @Override
- protected String doInBackground(String... params) {
- PaymentsCache pc = new PaymentsCache(context);
- String url = godotPaymentsV3.getPurchaseValidationUrlPrefix();
- RequestParams param = new RequestParams();
- param.setUrl(url);
- param.put("ticket", pc.getConsumableValue("ticket", sku));
- param.put("purchaseToken", pc.getConsumableValue("token", sku));
- param.put("sku", sku);
- //Log.d("XXX", "Haciendo request a " + url);
- //Log.d("XXX", "ticket: " + pc.getConsumableValue("ticket", sku));
- //Log.d("XXX", "purchaseToken: " + pc.getConsumableValue("token", sku));
- //Log.d("XXX", "sku: " + sku);
- param.put("package", context.getApplicationContext().getPackageName());
- HttpRequester requester = new HttpRequester();
- String jsonResponse = requester.post(param);
- //Log.d("XXX", "Validation response:\n"+jsonResponse);
- return jsonResponse;
- }
+ private String doInBackground(String... params) {
+ PaymentsCache pc = new PaymentsCache(context);
+ String url = godotPaymentsV3.getPurchaseValidationUrlPrefix();
+ RequestParams param = new RequestParams();
+ param.setUrl(url);
+ param.put("ticket", pc.getConsumableValue("ticket", mSku));
+ param.put("purchaseToken", pc.getConsumableValue("token", mSku));
+ param.put("sku", mSku);
+ //Log.d("XXX", "Haciendo request a " + url);
+ //Log.d("XXX", "ticket: " + pc.getConsumableValue("ticket", sku));
+ //Log.d("XXX", "purchaseToken: " + pc.getConsumableValue("token", sku));
+ //Log.d("XXX", "sku: " + sku);
+ param.put("package", context.getApplicationContext().getPackageName());
+ HttpRequester requester = new HttpRequester();
+ String jsonResponse = requester.post(param);
+ //Log.d("XXX", "Validation response:\n"+jsonResponse);
+ return jsonResponse;
+ }
- @Override
- protected void onPostExecute(String response) {
- if (dialog != null) {
- dialog.dismiss();
- }
- JSONObject j;
- try {
- j = new JSONObject(response);
- if (j.getString("status").equals("OK")) {
- success();
- return;
- } else if (j.getString("status") != null) {
- error(j.getString("message"));
- } else {
- error("Connection error");
- }
- } catch (JSONException e) {
- error(e.getMessage());
- } catch (Exception e) {
- error(e.getMessage());
- }
+ private void onPostExecute(String response) {
+ if (dialog != null) {
+ dialog.dismiss();
+ dialog = null;
+ }
+ JSONObject j;
+ try {
+ j = new JSONObject(response);
+ if (j.getString("status").equals("OK")) {
+ success();
+ return;
+ } else if (j.getString("status") != null) {
+ error(j.getString("message"));
+ } else {
+ error("Connection error");
}
+ } catch (JSONException e) {
+ error(e.getMessage());
+ } catch (Exception e) {
+ error(e.getMessage());
}
- .execute();
}
+
abstract protected void success();
abstract protected void error(String message);
abstract protected void canceled();
diff --git a/platform/android/java/src/org/godotengine/godot/utils/HttpRequester.java b/platform/android/java/src/org/godotengine/godot/utils/HttpRequester.java
index cfe9c4fef0..e1958390a5 100644
--- a/platform/android/java/src/org/godotengine/godot/utils/HttpRequester.java
+++ b/platform/android/java/src/org/godotengine/godot/utils/HttpRequester.java
@@ -105,7 +105,7 @@ public class HttpRequester {
long timeInit = new Date().getTime();
response = request(httpget);
long delay = new Date().getTime() - timeInit;
- Log.d("com.app11tt.android.utils.HttpRequest::get(url)", "Url: " + params.getUrl() + " downloaded in " + String.format("%.03f", delay / 1000.0f) + " seconds");
+ Log.d("HttpRequest::get(url)", "Url: " + params.getUrl() + " downloaded in " + String.format("%.03f", delay / 1000.0f) + " seconds");
if (response == null || response.length() == 0) {
response = "";
} else {
@@ -200,7 +200,7 @@ public class HttpRequester {
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("request_" + Crypt.md5(request), response);
editor.putLong("request_" + Crypt.md5(request) + "_ttl", new Date().getTime() + getTtl());
- editor.commit();
+ editor.apply();
}
public String getResponseFromCache(String request) {