Backport of clang-format 7cb6e6b723
This commit is contained in:
parent
ddcbdbd67c
commit
0af3f8e053
@ -113,4 +113,8 @@ Language: ObjC
|
||||
ObjCBlockIndentWidth: 4
|
||||
# ObjCSpaceAfterProperty: false
|
||||
# ObjCSpaceBeforeProtocolList: true
|
||||
---
|
||||
### Java specific config ###
|
||||
Language: Java
|
||||
# BreakAfterJavaFieldAnnotations: false
|
||||
...
|
||||
|
@ -31,7 +31,7 @@ PARSE_EXTS=true
|
||||
|
||||
# File types to parse. Only effective when PARSE_EXTS is true.
|
||||
# FILE_EXTS=".c .h .cpp .hpp"
|
||||
FILE_EXTS=".c .h .cpp .hpp .cc .hh .cxx .m .mm .inc"
|
||||
FILE_EXTS=".c .h .cpp .hpp .cc .hh .cxx .m .mm .inc *.java"
|
||||
|
||||
# Use pygmentize instead of cat to parse diff with highlighting.
|
||||
# Install it with `pip install pygments` (Linux) or `easy_install Pygments` (Mac)
|
||||
|
@ -11,7 +11,7 @@ else
|
||||
RANGE=HEAD
|
||||
fi
|
||||
|
||||
FILES=$(git diff-tree --no-commit-id --name-only -r $RANGE | grep -v thirdparty/ | grep -E "\.(c|h|cpp|hpp|cc|hh|cxx|m|mm|inc)$")
|
||||
FILES=$(git diff-tree --no-commit-id --name-only -r $RANGE | grep -v thirdparty/ | grep -E "\.(c|h|cpp|hpp|cc|hh|cxx|m|mm|inc|java)$")
|
||||
echo "Checking files:\n$FILES"
|
||||
|
||||
# create a random filename to store our generated patch
|
||||
|
@ -32,7 +32,6 @@ package org.godotengine.godot;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class Dictionary extends HashMap<String, Object> {
|
||||
|
||||
protected String[] keys_cache;
|
||||
@ -40,7 +39,7 @@ public class Dictionary extends HashMap<String, Object> {
|
||||
public String[] get_keys() {
|
||||
|
||||
String[] ret = new String[size()];
|
||||
int i=0;
|
||||
int i = 0;
|
||||
Set<String> keys = keySet();
|
||||
for (String key : keys) {
|
||||
|
||||
@ -54,7 +53,7 @@ public class Dictionary extends HashMap<String, Object> {
|
||||
public Object[] get_values() {
|
||||
|
||||
Object[] ret = new Object[size()];
|
||||
int i=0;
|
||||
int i = 0;
|
||||
Set<String> keys = keySet();
|
||||
for (String key : keys) {
|
||||
|
||||
@ -71,7 +70,7 @@ public class Dictionary extends HashMap<String, Object> {
|
||||
|
||||
public void set_values(Object[] vals) {
|
||||
|
||||
int i=0;
|
||||
int i = 0;
|
||||
for (String key : keys_cache) {
|
||||
put(key, vals[i]);
|
||||
i++;
|
||||
|
@ -90,9 +90,7 @@ import android.os.Bundle;
|
||||
import android.os.Messenger;
|
||||
import android.os.SystemClock;
|
||||
|
||||
|
||||
public class Godot extends Activity implements SensorEventListener, IDownloaderClient
|
||||
{
|
||||
public class Godot extends Activity implements SensorEventListener, IDownloaderClient {
|
||||
|
||||
static final int MAX_SINGLETONS = 64;
|
||||
private IStub mDownloaderClientStub;
|
||||
@ -110,15 +108,16 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
private Button mPauseButton;
|
||||
private Button mWiFiSettingsButton;
|
||||
|
||||
private boolean use_32_bits=false;
|
||||
private boolean use_immersive=false;
|
||||
private boolean use_32_bits = false;
|
||||
private boolean use_immersive = false;
|
||||
private boolean mStatePaused;
|
||||
private int mState;
|
||||
private boolean keep_screen_on=true;
|
||||
private boolean keep_screen_on = true;
|
||||
|
||||
static private Intent mCurrentIntent;
|
||||
|
||||
@Override public void onNewIntent(Intent intent) {
|
||||
@Override
|
||||
public void onNewIntent(Intent intent) {
|
||||
mCurrentIntent = intent;
|
||||
}
|
||||
|
||||
@ -144,26 +143,26 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
|
||||
protected void registerClass(String p_name, String[] p_methods) {
|
||||
|
||||
GodotLib.singleton(p_name,this);
|
||||
GodotLib.singleton(p_name, this);
|
||||
|
||||
Class clazz = getClass();
|
||||
Method[] methods = clazz.getDeclaredMethods();
|
||||
for (Method method : methods) {
|
||||
boolean found=false;
|
||||
Log.d("XXX","METHOD: %s\n" + method.getName());
|
||||
boolean found = false;
|
||||
Log.d("XXX", "METHOD: %s\n" + method.getName());
|
||||
|
||||
for (String s : p_methods) {
|
||||
Log.d("XXX", "METHOD CMP WITH: %s\n" + s);
|
||||
if (s.equals(method.getName())) {
|
||||
found=true;
|
||||
Log.d("XXX","METHOD CMP VALID");
|
||||
found = true;
|
||||
Log.d("XXX", "METHOD CMP VALID");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
continue;
|
||||
|
||||
Log.d("XXX","METHOD FOUND: %s\n" + method.getName());
|
||||
Log.d("XXX", "METHOD FOUND: %s\n" + method.getName());
|
||||
|
||||
List<String> ptr = new ArrayList<String>();
|
||||
|
||||
@ -175,17 +174,13 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
String[] pt = new String[ptr.size()];
|
||||
ptr.toArray(pt);
|
||||
|
||||
GodotLib.method(p_name,method.getName(),method.getReturnType().getName(),pt);
|
||||
|
||||
|
||||
GodotLib.method(p_name, method.getName(), method.getReturnType().getName(), pt);
|
||||
}
|
||||
|
||||
Godot.singletons[Godot.singleton_count++]=this;
|
||||
Godot.singletons[Godot.singleton_count++] = this;
|
||||
}
|
||||
|
||||
protected void onMainActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected void onMainPause() {}
|
||||
@ -200,7 +195,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
public void registerMethods() {}
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
protected List<SingletonBase> singletons = new ArrayList<SingletonBase>();
|
||||
protected void instanceSingleton(SingletonBase s) {
|
||||
|
||||
@ -213,8 +208,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
private String[] command_line;
|
||||
|
||||
public GodotView mView;
|
||||
private boolean godot_initialized=false;
|
||||
|
||||
private boolean godot_initialized = false;
|
||||
|
||||
private SensorManager mSensorManager;
|
||||
private Sensor mAccelerometer;
|
||||
@ -225,56 +219,55 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
public FrameLayout layout;
|
||||
public RelativeLayout adLayout;
|
||||
|
||||
|
||||
static public GodotIO io;
|
||||
|
||||
public static void setWindowTitle(String title) {
|
||||
//setTitle(title);
|
||||
}
|
||||
|
||||
|
||||
static SingletonBase singletons[] = new SingletonBase[MAX_SINGLETONS];
|
||||
static int singleton_count=0;
|
||||
|
||||
static int singleton_count = 0;
|
||||
|
||||
public interface ResultCallback {
|
||||
public void callback(int requestCode, int resultCode, Intent data);
|
||||
};
|
||||
}
|
||||
;
|
||||
public ResultCallback result_callback;
|
||||
|
||||
private PaymentsManager mPaymentsManager = null;
|
||||
|
||||
@Override protected void onActivityResult (int requestCode, int resultCode, Intent data) {
|
||||
if(requestCode == PaymentsManager.REQUEST_CODE_FOR_PURCHASE){
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == PaymentsManager.REQUEST_CODE_FOR_PURCHASE) {
|
||||
mPaymentsManager.processPurchaseResponse(resultCode, data);
|
||||
}else if (result_callback != null) {
|
||||
} else if (result_callback != null) {
|
||||
result_callback.callback(requestCode, resultCode, data);
|
||||
result_callback = null;
|
||||
};
|
||||
|
||||
for(int i=0;i<singleton_count;i++) {
|
||||
for (int i = 0; i < singleton_count; i++) {
|
||||
|
||||
singletons[i].onMainActivityResult(requestCode,resultCode,data);
|
||||
singletons[i].onMainActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
};
|
||||
|
||||
public void onVideoInit(boolean use_gl2) {
|
||||
|
||||
// mView = new GodotView(getApplication(),io,use_gl2);
|
||||
// setContentView(mView);
|
||||
// mView = new GodotView(getApplication(),io,use_gl2);
|
||||
// setContentView(mView);
|
||||
|
||||
layout = new FrameLayout(this);
|
||||
layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
|
||||
layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_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.FILL_PARENT, LayoutParams.WRAP_CONTENT));
|
||||
// ...add to FrameLayout
|
||||
layout.addView(edittext);
|
||||
|
||||
mView = new GodotView(getApplication(),io,use_gl2,use_32_bits, this);
|
||||
layout.addView(mView,new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
|
||||
mView = new GodotView(getApplication(), io, use_gl2, use_32_bits, this);
|
||||
layout.addView(mView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
|
||||
setKeepScreenOn(GodotLib.getGlobal("display/keep_screen_on").equals("True"));
|
||||
|
||||
edittext.setView(mView);
|
||||
@ -282,14 +275,13 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
|
||||
// Ad layout
|
||||
adLayout = new RelativeLayout(this);
|
||||
adLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
|
||||
adLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
|
||||
layout.addView(adLayout);
|
||||
|
||||
}
|
||||
|
||||
public void setKeepScreenOn(final boolean p_enabled) {
|
||||
keep_screen_on = p_enabled;
|
||||
if (mView != null){
|
||||
if (mView != null) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -320,41 +312,40 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
|
||||
private static Godot _self;
|
||||
|
||||
public static Godot getInstance(){
|
||||
public static Godot getInstance() {
|
||||
return Godot._self;
|
||||
}
|
||||
|
||||
|
||||
private String[] getCommandLine() {
|
||||
InputStream is;
|
||||
try {
|
||||
is = getAssets().open("_cl_");
|
||||
byte[] len = new byte[4];
|
||||
int r = is.read(len);
|
||||
if (r<4) {
|
||||
Log.d("XXX","**ERROR** Wrong cmdline length.\n");
|
||||
if (r < 4) {
|
||||
Log.d("XXX", "**ERROR** Wrong cmdline length.\n");
|
||||
Log.d("GODOT", "**ERROR** Wrong cmdline length.\n");
|
||||
return new String[0];
|
||||
}
|
||||
int argc=((int)(len[3]&0xFF)<<24) | ((int)(len[2]&0xFF)<<16) | ((int)(len[1]&0xFF)<<8) | ((int)(len[0]&0xFF));
|
||||
int argc = ((int)(len[3] & 0xFF) << 24) | ((int)(len[2] & 0xFF) << 16) | ((int)(len[1] & 0xFF) << 8) | ((int)(len[0] & 0xFF));
|
||||
String[] cmdline = new String[argc];
|
||||
|
||||
for(int i=0;i<argc;i++) {
|
||||
for (int i = 0; i < argc; i++) {
|
||||
r = is.read(len);
|
||||
if (r<4) {
|
||||
if (r < 4) {
|
||||
|
||||
Log.d("GODOT", "**ERROR** Wrong cmdline param lenght.\n");
|
||||
return new String[0];
|
||||
}
|
||||
int strlen=((int)(len[3]&0xFF)<<24) | ((int)(len[2]&0xFF)<<16) | ((int)(len[1]&0xFF)<<8) | ((int)(len[0]&0xFF));
|
||||
if (strlen>65535) {
|
||||
int strlen = ((int)(len[3] & 0xFF) << 24) | ((int)(len[2] & 0xFF) << 16) | ((int)(len[1] & 0xFF) << 8) | ((int)(len[0] & 0xFF));
|
||||
if (strlen > 65535) {
|
||||
Log.d("GODOT", "**ERROR** Wrong command len\n");
|
||||
return new String[0];
|
||||
}
|
||||
byte[] arg = new byte[strlen];
|
||||
r = is.read(arg);
|
||||
if (r==strlen) {
|
||||
cmdline[i]=new String(arg,"UTF-8");
|
||||
if (r == strlen) {
|
||||
cmdline[i] = new String(arg, "UTF-8");
|
||||
}
|
||||
}
|
||||
return cmdline;
|
||||
@ -363,49 +354,45 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
Log.d("GODOT", "**ERROR** Exception " + e.getClass().getName() + ":" + e.getMessage());
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
String expansion_pack_path;
|
||||
|
||||
|
||||
private void initializeGodot() {
|
||||
|
||||
if (expansion_pack_path!=null) {
|
||||
if (expansion_pack_path != null) {
|
||||
|
||||
String[] new_cmdline;
|
||||
int cll=0;
|
||||
if (command_line!=null) {
|
||||
Log.d("GODOT", "initializeGodot: command_line: is not null" );
|
||||
new_cmdline = new String[ command_line.length + 2 ];
|
||||
cll=command_line.length;
|
||||
for(int i=0;i<command_line.length;i++) {
|
||||
new_cmdline[i]=command_line[i];
|
||||
int cll = 0;
|
||||
if (command_line != null) {
|
||||
Log.d("GODOT", "initializeGodot: command_line: is not null");
|
||||
new_cmdline = new String[command_line.length + 2];
|
||||
cll = command_line.length;
|
||||
for (int i = 0; i < command_line.length; i++) {
|
||||
new_cmdline[i] = command_line[i];
|
||||
}
|
||||
} else {
|
||||
Log.d("GODOT", "initializeGodot: command_line: is null" );
|
||||
new_cmdline = new String[ 2 ];
|
||||
Log.d("GODOT", "initializeGodot: command_line: is null");
|
||||
new_cmdline = new String[2];
|
||||
}
|
||||
|
||||
new_cmdline[cll]="-main_pack";
|
||||
new_cmdline[cll+1]=expansion_pack_path;
|
||||
command_line=new_cmdline;
|
||||
new_cmdline[cll] = "-main_pack";
|
||||
new_cmdline[cll + 1] = expansion_pack_path;
|
||||
command_line = new_cmdline;
|
||||
}
|
||||
|
||||
io = new GodotIO(this);
|
||||
io.unique_id = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
|
||||
GodotLib.io=io;
|
||||
Log.d("GODOT", "command_line is null? " + ((command_line == null)?"yes":"no"));
|
||||
GodotLib.io = io;
|
||||
Log.d("GODOT", "command_line is null? " + ((command_line == null) ? "yes" : "no"));
|
||||
/*if(command_line != null){
|
||||
Log.d("GODOT", "Command Line:");
|
||||
for(int w=0;w <command_line.length;w++){
|
||||
Log.d("GODOT"," " + command_line[w]);
|
||||
}
|
||||
}*/
|
||||
GodotLib.initialize(this,io.needsReloadHooks(),command_line,getAssets());
|
||||
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
|
||||
GodotLib.initialize(this, io.needsReloadHooks(), command_line, getAssets());
|
||||
mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
|
||||
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
|
||||
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
|
||||
mGravity = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
|
||||
@ -418,8 +405,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
result_callback = null;
|
||||
|
||||
mPaymentsManager = PaymentsManager.createManager(this).initService();
|
||||
godot_initialized=true;
|
||||
|
||||
godot_initialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -428,8 +414,6 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
mRemoteService.onClientUpdated(mDownloaderClientStub.getMessenger());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle icicle) {
|
||||
|
||||
@ -441,63 +425,58 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
//window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
|
||||
|
||||
|
||||
//check for apk expansion API
|
||||
if (true) {
|
||||
boolean md5mismatch = false;
|
||||
command_line = getCommandLine();
|
||||
boolean use_apk_expansion=false;
|
||||
String main_pack_md5=null;
|
||||
String main_pack_key=null;
|
||||
boolean use_apk_expansion = false;
|
||||
String main_pack_md5 = null;
|
||||
String main_pack_key = null;
|
||||
|
||||
List<String> new_args = new LinkedList<String>();
|
||||
|
||||
for (int i = 0; i < command_line.length; i++) {
|
||||
|
||||
for(int i=0;i<command_line.length;i++) {
|
||||
|
||||
boolean has_extra = i< command_line.length -1;
|
||||
boolean has_extra = i < command_line.length - 1;
|
||||
if (command_line[i].equals("-use_depth_32")) {
|
||||
use_32_bits=true;
|
||||
use_32_bits = 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+
|
||||
use_immersive = true;
|
||||
if (Build.VERSION.SDK_INT >= 19.0) { // 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
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
|
||||
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 // hide nav bar
|
||||
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
|
||||
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
|
||||
|
||||
UiChangeListener();
|
||||
}
|
||||
} else if (command_line[i].equals("-use_apk_expansion")) {
|
||||
use_apk_expansion=true;
|
||||
use_apk_expansion = true;
|
||||
} else if (has_extra && command_line[i].equals("-apk_expansion_md5")) {
|
||||
main_pack_md5=command_line[i+1];
|
||||
main_pack_md5 = command_line[i + 1];
|
||||
i++;
|
||||
} else if (has_extra && command_line[i].equals("-apk_expansion_key")) {
|
||||
main_pack_key=command_line[i+1];
|
||||
main_pack_key = command_line[i + 1];
|
||||
SharedPreferences prefs = getSharedPreferences("app_data_keys", MODE_PRIVATE);
|
||||
Editor editor = prefs.edit();
|
||||
editor.putString("store_public_key", main_pack_key);
|
||||
|
||||
editor.commit();
|
||||
i++;
|
||||
} else if (command_line[i].trim().length()!=0){
|
||||
} else if (command_line[i].trim().length() != 0) {
|
||||
new_args.add(command_line[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (new_args.isEmpty()){
|
||||
command_line=null;
|
||||
}else{
|
||||
if (new_args.isEmpty()) {
|
||||
command_line = null;
|
||||
} else {
|
||||
|
||||
command_line = new_args.toArray(new String[new_args.size()]);
|
||||
}
|
||||
if (use_apk_expansion && main_pack_md5!=null && main_pack_key!=null) {
|
||||
if (use_apk_expansion && main_pack_md5 != null && main_pack_key != null) {
|
||||
//check that environment is ok!
|
||||
if (!Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED )) {
|
||||
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||
Log.d("GODOT", "**ERROR! No media mounted!");
|
||||
//show popup and die
|
||||
}
|
||||
@ -505,7 +484,8 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
// Build the full path to the app's expansion files
|
||||
try {
|
||||
expansion_pack_path = Helpers.getSaveFilePath(getApplicationContext());
|
||||
expansion_pack_path+="/"+"main."+getPackageManager().getPackageInfo(getPackageName(), 0).versionCode+"."+this.getPackageName()+".obb";
|
||||
expansion_pack_path += "/"
|
||||
+ "main." + getPackageManager().getPackageInfo(getPackageName(), 0).versionCode + "." + this.getPackageName() + ".obb";
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -513,19 +493,19 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
File f = new File(expansion_pack_path);
|
||||
|
||||
boolean pack_valid = true;
|
||||
Log.d("GODOT","**PACK** - Path "+expansion_pack_path);
|
||||
Log.d("GODOT", "**PACK** - Path " + expansion_pack_path);
|
||||
|
||||
if (!f.exists()) {
|
||||
|
||||
pack_valid=false;
|
||||
Log.d("GODOT","**PACK** - File does not exist");
|
||||
pack_valid = false;
|
||||
Log.d("GODOT", "**PACK** - File does not exist");
|
||||
|
||||
} else if( obbIsCorrupted(expansion_pack_path, main_pack_md5)){
|
||||
} else if (obbIsCorrupted(expansion_pack_path, main_pack_md5)) {
|
||||
Log.d("GODOT", "**PACK** - Expansion pack (obb) is corrupted");
|
||||
pack_valid = false;
|
||||
try{
|
||||
try {
|
||||
f.delete();
|
||||
}catch(Exception e){
|
||||
} catch (Exception e) {
|
||||
Log.d("GODOT", "**PACK** - Error deleting corrupted expansion pack (obb)");
|
||||
}
|
||||
}
|
||||
@ -557,28 +537,26 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
GodotDownloaderService.class);
|
||||
|
||||
setContentView(com.godot.game.R.layout.downloading_expansion);
|
||||
mPB = (ProgressBar) findViewById(com.godot.game.R.id.progressBar);
|
||||
mStatusText = (TextView) findViewById(com.godot.game.R.id.statusText);
|
||||
mProgressFraction = (TextView) findViewById(com.godot.game.R.id.progressAsFraction);
|
||||
mProgressPercent = (TextView) findViewById(com.godot.game.R.id.progressAsPercentage);
|
||||
mAverageSpeed = (TextView) findViewById(com.godot.game.R.id.progressAverageSpeed);
|
||||
mTimeRemaining = (TextView) findViewById(com.godot.game.R.id.progressTimeRemaining);
|
||||
mPB = (ProgressBar)findViewById(com.godot.game.R.id.progressBar);
|
||||
mStatusText = (TextView)findViewById(com.godot.game.R.id.statusText);
|
||||
mProgressFraction = (TextView)findViewById(com.godot.game.R.id.progressAsFraction);
|
||||
mProgressPercent = (TextView)findViewById(com.godot.game.R.id.progressAsPercentage);
|
||||
mAverageSpeed = (TextView)findViewById(com.godot.game.R.id.progressAverageSpeed);
|
||||
mTimeRemaining = (TextView)findViewById(com.godot.game.R.id.progressTimeRemaining);
|
||||
mDashboard = findViewById(com.godot.game.R.id.downloaderDashboard);
|
||||
mCellMessage = findViewById(com.godot.game.R.id.approveCellular);
|
||||
mPauseButton = (Button) findViewById(com.godot.game.R.id.pauseButton);
|
||||
mWiFiSettingsButton = (Button) findViewById(com.godot.game.R.id.wifiSettingsButton);
|
||||
mPauseButton = (Button)findViewById(com.godot.game.R.id.pauseButton);
|
||||
mWiFiSettingsButton = (Button)findViewById(com.godot.game.R.id.wifiSettingsButton);
|
||||
|
||||
return;
|
||||
} else{
|
||||
} else {
|
||||
Log.d("GODOT", "NO DOWNLOAD REQUIRED");
|
||||
}
|
||||
} catch (NameNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
Log.d("GODOT", "Error downloading expansion package:" + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -586,25 +564,23 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
|
||||
initializeGodot();
|
||||
|
||||
|
||||
// instanceSingleton( new GodotFacebook(this) );
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
|
||||
@Override protected void onDestroy(){
|
||||
|
||||
if(mPaymentsManager != null ) mPaymentsManager.destroy();
|
||||
for(int i=0;i<singleton_count;i++) {
|
||||
if (mPaymentsManager != null) mPaymentsManager.destroy();
|
||||
for (int i = 0; i < singleton_count; i++) {
|
||||
singletons[i].onMainDestroy();
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override protected void onPause() {
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
if (!godot_initialized){
|
||||
if (!godot_initialized) {
|
||||
if (null != mDownloaderClientStub) {
|
||||
mDownloaderClientStub.disconnect(this);
|
||||
}
|
||||
@ -614,14 +590,15 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
mSensorManager.unregisterListener(this);
|
||||
GodotLib.focusout();
|
||||
|
||||
for(int i=0;i<singleton_count;i++) {
|
||||
for (int i = 0; i < singleton_count; i++) {
|
||||
singletons[i].onMainPause();
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected void onResume() {
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (!godot_initialized){
|
||||
if (!godot_initialized) {
|
||||
if (null != mDownloaderClientStub) {
|
||||
mDownloaderClientStub.connect(this);
|
||||
}
|
||||
@ -634,58 +611,49 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_GAME);
|
||||
mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_GAME);
|
||||
GodotLib.focusin();
|
||||
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 >= 19.0) { // check if the application runs on an android 4.4+
|
||||
Window window = getWindow();
|
||||
window.getDecorView().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 // hide nav bar
|
||||
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 // hide nav bar
|
||||
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
|
||||
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
|
||||
}
|
||||
|
||||
for(int i=0;i<singleton_count;i++) {
|
||||
for (int i = 0; i < singleton_count; i++) {
|
||||
|
||||
singletons[i].onMainResume();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void UiChangeListener() {
|
||||
final View decorView = getWindow().getDecorView();
|
||||
decorView.setOnSystemUiVisibilityChangeListener (new View.OnSystemUiVisibilityChangeListener() {
|
||||
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
|
||||
@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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override public void onSensorChanged(SensorEvent event) {
|
||||
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
|
||||
int displayRotation = display.getRotation();
|
||||
|
||||
float[] adjustedValues = new float[3];
|
||||
final int axisSwap[][] = {
|
||||
{ 1, -1, 0, 1 }, // ROTATION_0
|
||||
{-1, -1, 1, 0 }, // ROTATION_90
|
||||
{-1, 1, 0, 1 }, // ROTATION_180
|
||||
{ 1, 1, 1, 0 } }; // ROTATION_270
|
||||
{ -1, -1, 1, 0 }, // ROTATION_90
|
||||
{ -1, 1, 0, 1 }, // ROTATION_180
|
||||
{ 1, 1, 1, 0 }
|
||||
}; // ROTATION_270
|
||||
|
||||
final int[] as = axisSwap[displayRotation];
|
||||
adjustedValues[0] = (float)as[0] * event.values[ as[2] ];
|
||||
adjustedValues[1] = (float)as[1] * event.values[ as[3] ];
|
||||
adjustedValues[0] = (float)as[0] * event.values[as[2]];
|
||||
adjustedValues[1] = (float)as[1] * event.values[as[3]];
|
||||
adjustedValues[2] = event.values[2];
|
||||
|
||||
float x = adjustedValues[0];
|
||||
@ -694,24 +662,25 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
|
||||
int typeOfSensor = event.sensor.getType();
|
||||
if (typeOfSensor == event.sensor.TYPE_ACCELEROMETER) {
|
||||
GodotLib.accelerometer(x,y,z);
|
||||
GodotLib.accelerometer(x, y, z);
|
||||
}
|
||||
if (typeOfSensor == event.sensor.TYPE_GRAVITY) {
|
||||
GodotLib.gravity(x,y,z);
|
||||
GodotLib.gravity(x, y, z);
|
||||
}
|
||||
if (typeOfSensor == event.sensor.TYPE_MAGNETIC_FIELD) {
|
||||
GodotLib.magnetometer(x,y,z);
|
||||
GodotLib.magnetometer(x, y, z);
|
||||
}
|
||||
if (typeOfSensor == event.sensor.TYPE_GYROSCOPE) {
|
||||
GodotLib.gyroscope(x,y,z);
|
||||
GodotLib.gyroscope(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public final void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
@Override
|
||||
public final void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
// Do something here if sensor accuracy changes.
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
@Override public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
|
||||
if (event.getKeyCode()==KeyEvent.KEYCODE_BACK) {
|
||||
@ -727,10 +696,11 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
}
|
||||
*/
|
||||
|
||||
@Override public void onBackPressed() {
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
boolean shouldQuit = true;
|
||||
|
||||
for(int i=0;i<singleton_count;i++) {
|
||||
for (int i = 0; i < singleton_count; i++) {
|
||||
if (singletons[i].onMainBackPressed()) {
|
||||
shouldQuit = false;
|
||||
}
|
||||
@ -748,9 +718,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private boolean obbIsCorrupted(String f, String main_pack_md5){
|
||||
private boolean obbIsCorrupted(String f, String main_pack_md5) {
|
||||
|
||||
try {
|
||||
|
||||
@ -768,17 +736,16 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
}
|
||||
} while (numRead != -1);
|
||||
|
||||
|
||||
fis.close();
|
||||
byte[] messageDigest = complete.digest();
|
||||
|
||||
// Create Hex String
|
||||
StringBuffer hexString = new StringBuffer();
|
||||
for (int i=0; i<messageDigest.length; i++) {
|
||||
for (int i = 0; i < messageDigest.length; i++) {
|
||||
String s = Integer.toHexString(0xFF & messageDigest[i]);
|
||||
|
||||
if (s.length()==1) {
|
||||
s="0"+s;
|
||||
if (s.length() == 1) {
|
||||
s = "0" + s;
|
||||
}
|
||||
hexString.append(s);
|
||||
}
|
||||
@ -786,13 +753,13 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
|
||||
//Log.d("GODOT","**PACK** - My MD5: "+hexString+" - APK md5: "+main_pack_md5);
|
||||
if (!md5str.equals(main_pack_md5)) {
|
||||
Log.d("GODOT","**PACK MD5 MISMATCH???** - MD5 Found: "+md5str+" "+Integer.toString(md5str.length())+" - MD5 Expected: "+main_pack_md5+" "+Integer.toString(main_pack_md5.length()));
|
||||
Log.d("GODOT", "**PACK MD5 MISMATCH???** - MD5 Found: " + md5str + " " + Integer.toString(md5str.length()) + " - MD5 Expected: " + main_pack_md5 + " " + Integer.toString(main_pack_md5.length()));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.d("GODOT","**PACK FAIL**");
|
||||
Log.d("GODOT", "**PACK FAIL**");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -801,28 +768,28 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
public boolean gotTouchEvent(MotionEvent event) {
|
||||
|
||||
super.onTouchEvent(event);
|
||||
int evcount=event.getPointerCount();
|
||||
if (evcount==0)
|
||||
int evcount = event.getPointerCount();
|
||||
if (evcount == 0)
|
||||
return true;
|
||||
|
||||
int[] arr = new int[event.getPointerCount()*3];
|
||||
int[] arr = new int[event.getPointerCount() * 3];
|
||||
|
||||
for(int i=0;i<event.getPointerCount();i++) {
|
||||
for (int i = 0; i < event.getPointerCount(); i++) {
|
||||
|
||||
arr[i*3+0]=(int)event.getPointerId(i);
|
||||
arr[i*3+1]=(int)event.getX(i);
|
||||
arr[i*3+2]=(int)event.getY(i);
|
||||
arr[i * 3 + 0] = (int)event.getPointerId(i);
|
||||
arr[i * 3 + 1] = (int)event.getX(i);
|
||||
arr[i * 3 + 2] = (int)event.getY(i);
|
||||
}
|
||||
|
||||
//System.out.printf("gaction: %d\n",event.getAction());
|
||||
switch(event.getAction()&MotionEvent.ACTION_MASK) {
|
||||
switch (event.getAction() & MotionEvent.ACTION_MASK) {
|
||||
|
||||
case MotionEvent.ACTION_DOWN: {
|
||||
GodotLib.touch(0,0,evcount,arr);
|
||||
GodotLib.touch(0, 0, evcount, arr);
|
||||
//System.out.printf("action down at: %f,%f\n", event.getX(),event.getY());
|
||||
} break;
|
||||
case MotionEvent.ACTION_MOVE: {
|
||||
GodotLib.touch(1,0,evcount,arr);
|
||||
GodotLib.touch(1, 0, evcount, arr);
|
||||
//for(int i=0;i<event.getPointerCount();i++) {
|
||||
// System.out.printf("%d - moved to: %f,%f\n",i, event.getX(i),event.getY(i));
|
||||
//}
|
||||
@ -830,34 +797,35 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
case MotionEvent.ACTION_POINTER_UP: {
|
||||
final int indexPointUp = event.getActionIndex();
|
||||
final int pointer_idx = event.getPointerId(indexPointUp);
|
||||
GodotLib.touch(4,pointer_idx,evcount,arr);
|
||||
GodotLib.touch(4, pointer_idx, evcount, arr);
|
||||
//System.out.printf("%d - s.up at: %f,%f\n",pointer_idx, event.getX(pointer_idx),event.getY(pointer_idx));
|
||||
} break;
|
||||
case MotionEvent.ACTION_POINTER_DOWN: {
|
||||
int pointer_idx = event.getActionIndex();
|
||||
GodotLib.touch(3,pointer_idx,evcount,arr);
|
||||
GodotLib.touch(3, pointer_idx, evcount, arr);
|
||||
//System.out.printf("%d - s.down at: %f,%f\n",pointer_idx, event.getX(pointer_idx),event.getY(pointer_idx));
|
||||
} break;
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
case MotionEvent.ACTION_UP: {
|
||||
GodotLib.touch(2,0,evcount,arr);
|
||||
GodotLib.touch(2, 0, evcount, arr);
|
||||
//for(int i=0;i<event.getPointerCount();i++) {
|
||||
// System.out.printf("%d - up! %f,%f\n",i, event.getX(i),event.getY(i));
|
||||
//}
|
||||
} break;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public boolean onKeyMultiple(final int inKeyCode, int repeatCount, KeyEvent event) {
|
||||
@Override
|
||||
public boolean onKeyMultiple(final int inKeyCode, int repeatCount, KeyEvent event) {
|
||||
String s = event.getCharacters();
|
||||
if (s == null || s.length() == 0)
|
||||
return super.onKeyMultiple(inKeyCode, repeatCount, event);
|
||||
|
||||
final char[] cc = s.toCharArray();
|
||||
int cnt = 0;
|
||||
for (int i = cc.length; --i >= 0; cnt += cc[i] != 0 ? 1 : 0);
|
||||
for (int i = cc.length; --i >= 0; cnt += cc[i] != 0 ? 1 : 0)
|
||||
;
|
||||
if (cnt == 0) return super.onKeyMultiple(inKeyCode, repeatCount, event);
|
||||
final Activity me = this;
|
||||
queueEvent(new Runnable() {
|
||||
@ -878,17 +846,15 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
|
||||
private void queueEvent(Runnable runnable) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public PaymentsManager getPaymentsManager() {
|
||||
return mPaymentsManager;
|
||||
}
|
||||
|
||||
// public void setPaymentsManager(PaymentsManager mPaymentsManager) {
|
||||
// this.mPaymentsManager = mPaymentsManager;
|
||||
// };
|
||||
|
||||
// public void setPaymentsManager(PaymentsManager mPaymentsManager) {
|
||||
// this.mPaymentsManager = mPaymentsManager;
|
||||
// };
|
||||
|
||||
// Audio
|
||||
|
||||
@ -961,7 +927,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
showDashboard = false;
|
||||
paused = false;
|
||||
indeterminate = false;
|
||||
// validateXAPKZipFiles();
|
||||
// validateXAPKZipFiles();
|
||||
initializeGodot();
|
||||
return;
|
||||
default:
|
||||
@ -983,7 +949,6 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
setButtonPausedState(paused);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDownloadProgress(DownloadProgressInfo progress) {
|
||||
mAverageSpeed.setText(getString(com.godot.game.R.string.kilobytes_per_second,
|
||||
@ -992,15 +957,12 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
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) + "%");
|
||||
mProgressFraction.setText(Helpers.getDownloadProgressString
|
||||
(progress.mOverallProgress,
|
||||
mPB.setMax((int)(progress.mOverallTotal >> 8));
|
||||
mPB.setProgress((int)(progress.mOverallProgress >> 8));
|
||||
mProgressPercent.setText(Long.toString(progress.mOverallProgress * 100 /
|
||||
progress.mOverallTotal) +
|
||||
"%");
|
||||
mProgressFraction.setText(Helpers.getDownloadProgressString(progress.mOverallProgress,
|
||||
progress.mOverallTotal));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public class GodotDownloaderService extends DownloaderService {
|
||||
Log.d("GODOT", "getting public key:" + prefs.getString("store_public_key", null));
|
||||
return prefs.getString("store_public_key", null);
|
||||
|
||||
// return BASE64_PUBLIC_KEY;
|
||||
// return BASE64_PUBLIC_KEY;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,5 +81,4 @@ public class GodotDownloaderService extends DownloaderService {
|
||||
Log.d("GODOT", "getAlarmReceiverClassName()");
|
||||
return GodotDownloaderAlarmReceiver.class.getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -56,7 +56,6 @@ import org.godotengine.godot.input.*;
|
||||
|
||||
public class GodotIO {
|
||||
|
||||
|
||||
AssetManager am;
|
||||
Godot activity;
|
||||
GodotEditText edit;
|
||||
@ -64,35 +63,32 @@ public class GodotIO {
|
||||
Context applicationContext;
|
||||
MediaPlayer mediaPlayer;
|
||||
|
||||
final int SCREEN_LANDSCAPE=0;
|
||||
final int SCREEN_PORTRAIT=1;
|
||||
final int SCREEN_REVERSE_LANDSCAPE=2;
|
||||
final int SCREEN_REVERSE_PORTRAIT=3;
|
||||
final int SCREEN_SENSOR_LANDSCAPE=4;
|
||||
final int SCREEN_SENSOR_PORTRAIT=5;
|
||||
final int SCREEN_SENSOR=6;
|
||||
final int SCREEN_LANDSCAPE = 0;
|
||||
final int SCREEN_PORTRAIT = 1;
|
||||
final int SCREEN_REVERSE_LANDSCAPE = 2;
|
||||
final int SCREEN_REVERSE_PORTRAIT = 3;
|
||||
final int SCREEN_SENSOR_LANDSCAPE = 4;
|
||||
final int SCREEN_SENSOR_PORTRAIT = 5;
|
||||
final int SCREEN_SENSOR = 6;
|
||||
|
||||
/////////////////////////
|
||||
/// FILES
|
||||
/////////////////////////
|
||||
|
||||
public int last_file_id=1;
|
||||
public int last_file_id = 1;
|
||||
|
||||
class AssetData {
|
||||
|
||||
|
||||
public boolean eof=false;
|
||||
public boolean eof = false;
|
||||
public String path;
|
||||
public InputStream is;
|
||||
public int len;
|
||||
public int pos;
|
||||
}
|
||||
|
||||
HashMap<Integer, AssetData> streams;
|
||||
|
||||
HashMap<Integer,AssetData> streams;
|
||||
|
||||
|
||||
public int file_open(String path,boolean write) {
|
||||
public int file_open(String path, boolean write) {
|
||||
|
||||
//System.out.printf("file_open: Attempt to Open %s\n",path);
|
||||
|
||||
@ -100,7 +96,6 @@ public class GodotIO {
|
||||
if (write)
|
||||
return -1;
|
||||
|
||||
|
||||
AssetData ad = new AssetData();
|
||||
|
||||
try {
|
||||
@ -113,76 +108,73 @@ public class GodotIO {
|
||||
}
|
||||
|
||||
try {
|
||||
ad.len=ad.is.available();
|
||||
ad.len = ad.is.available();
|
||||
} catch (Exception e) {
|
||||
|
||||
System.out.printf("Exception availabling on file_open: %s\n",path);
|
||||
System.out.printf("Exception availabling on file_open: %s\n", path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ad.path=path;
|
||||
ad.pos=0;
|
||||
ad.path = path;
|
||||
ad.pos = 0;
|
||||
++last_file_id;
|
||||
streams.put(last_file_id,ad);
|
||||
streams.put(last_file_id, ad);
|
||||
|
||||
return last_file_id;
|
||||
}
|
||||
public int file_get_size(int id) {
|
||||
|
||||
if (!streams.containsKey(id)) {
|
||||
System.out.printf("file_get_size: Invalid file id: %d\n",id);
|
||||
System.out.printf("file_get_size: Invalid file id: %d\n", id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return streams.get(id).len;
|
||||
|
||||
}
|
||||
public void file_seek(int id,int bytes) {
|
||||
public void file_seek(int id, int bytes) {
|
||||
|
||||
if (!streams.containsKey(id)) {
|
||||
System.out.printf("file_get_size: Invalid file id: %d\n",id);
|
||||
System.out.printf("file_get_size: Invalid file id: %d\n", id);
|
||||
return;
|
||||
}
|
||||
//seek sucks
|
||||
AssetData ad = streams.get(id);
|
||||
if (bytes>ad.len)
|
||||
bytes=ad.len;
|
||||
if (bytes<0)
|
||||
bytes=0;
|
||||
if (bytes > ad.len)
|
||||
bytes = ad.len;
|
||||
if (bytes < 0)
|
||||
bytes = 0;
|
||||
|
||||
try {
|
||||
|
||||
if (bytes > (int)ad.pos) {
|
||||
int todo=bytes-(int)ad.pos;
|
||||
while(todo>0) {
|
||||
todo-=ad.is.skip(todo);
|
||||
int todo = bytes - (int)ad.pos;
|
||||
while (todo > 0) {
|
||||
todo -= ad.is.skip(todo);
|
||||
}
|
||||
ad.pos=bytes;
|
||||
} else if (bytes<(int)ad.pos) {
|
||||
ad.pos = bytes;
|
||||
} else if (bytes < (int)ad.pos) {
|
||||
|
||||
ad.is=am.open(ad.path);
|
||||
ad.is = am.open(ad.path);
|
||||
|
||||
ad.pos=bytes;
|
||||
int todo=bytes;
|
||||
while(todo>0) {
|
||||
todo-=ad.is.skip(todo);
|
||||
ad.pos = bytes;
|
||||
int todo = bytes;
|
||||
while (todo > 0) {
|
||||
todo -= ad.is.skip(todo);
|
||||
}
|
||||
}
|
||||
|
||||
ad.eof=false;
|
||||
ad.eof = false;
|
||||
} catch (IOException e) {
|
||||
|
||||
System.out.printf("Exception on file_seek: %s\n",e);
|
||||
System.out.printf("Exception on file_seek: %s\n", e);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public int file_tell(int id) {
|
||||
|
||||
if (!streams.containsKey(id)) {
|
||||
System.out.printf("file_read: Can't tell eof for invalid file id: %d\n",id);
|
||||
System.out.printf("file_read: Can't tell eof for invalid file id: %d\n", id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -192,7 +184,7 @@ public class GodotIO {
|
||||
public boolean file_eof(int id) {
|
||||
|
||||
if (!streams.containsKey(id)) {
|
||||
System.out.printf("file_read: Can't check eof for invalid file id: %d\n",id);
|
||||
System.out.printf("file_read: Can't check eof for invalid file id: %d\n", id);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -203,73 +195,65 @@ public class GodotIO {
|
||||
public byte[] file_read(int id, int bytes) {
|
||||
|
||||
if (!streams.containsKey(id)) {
|
||||
System.out.printf("file_read: Can't read invalid file id: %d\n",id);
|
||||
System.out.printf("file_read: Can't read invalid file id: %d\n", id);
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
|
||||
AssetData ad = streams.get(id);
|
||||
|
||||
if (ad.pos + bytes > ad.len) {
|
||||
|
||||
bytes=ad.len-ad.pos;
|
||||
ad.eof=true;
|
||||
bytes = ad.len - ad.pos;
|
||||
ad.eof = true;
|
||||
}
|
||||
|
||||
|
||||
if (bytes==0) {
|
||||
if (bytes == 0) {
|
||||
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
|
||||
|
||||
byte[] buf1=new byte[bytes];
|
||||
int r=0;
|
||||
byte[] buf1 = new byte[bytes];
|
||||
int r = 0;
|
||||
try {
|
||||
r = ad.is.read(buf1);
|
||||
} catch (IOException e) {
|
||||
|
||||
System.out.printf("Exception on file_read: %s\n",e);
|
||||
System.out.printf("Exception on file_read: %s\n", e);
|
||||
return new byte[bytes];
|
||||
}
|
||||
|
||||
if (r==0) {
|
||||
if (r == 0) {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
ad.pos+=r;
|
||||
ad.pos += r;
|
||||
|
||||
if (r<bytes) {
|
||||
if (r < bytes) {
|
||||
|
||||
byte[] buf2=new byte[r];
|
||||
for(int i=0;i<r;i++)
|
||||
buf2[i]=buf1[i];
|
||||
byte[] buf2 = new byte[r];
|
||||
for (int i = 0; i < r; i++)
|
||||
buf2[i] = buf1[i];
|
||||
return buf2;
|
||||
} else {
|
||||
|
||||
return buf1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void file_close(int id) {
|
||||
|
||||
if (!streams.containsKey(id)) {
|
||||
System.out.printf("file_close: Can't close invalid file id: %d\n",id);
|
||||
System.out.printf("file_close: Can't close invalid file id: %d\n", id);
|
||||
return;
|
||||
}
|
||||
|
||||
streams.remove(id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////
|
||||
/// DIRECTORIES
|
||||
/////////////////////////
|
||||
|
||||
|
||||
class AssetDir {
|
||||
|
||||
public String[] files;
|
||||
@ -277,49 +261,48 @@ public class GodotIO {
|
||||
public String path;
|
||||
}
|
||||
|
||||
public int last_dir_id=1;
|
||||
public int last_dir_id = 1;
|
||||
|
||||
HashMap<Integer,AssetDir> dirs;
|
||||
HashMap<Integer, AssetDir> dirs;
|
||||
|
||||
public int dir_open(String path) {
|
||||
|
||||
AssetDir ad = new AssetDir();
|
||||
ad.current=0;
|
||||
ad.path=path;
|
||||
ad.current = 0;
|
||||
ad.path = path;
|
||||
|
||||
try {
|
||||
ad.files = am.list(path);
|
||||
// no way to find path is directory or file exactly.
|
||||
// but if ad.files.length==0, then it's an empty directory or file.
|
||||
if (ad.files.length==0) {
|
||||
if (ad.files.length == 0) {
|
||||
return -1;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
System.out.printf("Exception on dir_open: %s\n",e);
|
||||
System.out.printf("Exception on dir_open: %s\n", e);
|
||||
return -1;
|
||||
}
|
||||
|
||||
//System.out.printf("Opened dir: %s\n",path);
|
||||
++last_dir_id;
|
||||
dirs.put(last_dir_id,ad);
|
||||
dirs.put(last_dir_id, ad);
|
||||
|
||||
return last_dir_id;
|
||||
|
||||
}
|
||||
|
||||
public boolean dir_is_dir(int id) {
|
||||
if (!dirs.containsKey(id)) {
|
||||
System.out.printf("dir_next: invalid dir id: %d\n",id);
|
||||
System.out.printf("dir_next: invalid dir id: %d\n", id);
|
||||
return false;
|
||||
}
|
||||
AssetDir ad = dirs.get(id);
|
||||
//System.out.printf("go next: %d,%d\n",ad.current,ad.files.length);
|
||||
int idx = ad.current;
|
||||
if (idx>0)
|
||||
if (idx > 0)
|
||||
idx--;
|
||||
|
||||
if (idx>=ad.files.length)
|
||||
if (idx >= ad.files.length)
|
||||
return false;
|
||||
String fname = ad.files[idx];
|
||||
|
||||
@ -327,7 +310,7 @@ public class GodotIO {
|
||||
if (ad.path.equals(""))
|
||||
am.open(fname);
|
||||
else
|
||||
am.open(ad.path+"/"+fname);
|
||||
am.open(ad.path + "/" + fname);
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
return true;
|
||||
@ -337,46 +320,41 @@ public class GodotIO {
|
||||
public String dir_next(int id) {
|
||||
|
||||
if (!dirs.containsKey(id)) {
|
||||
System.out.printf("dir_next: invalid dir id: %d\n",id);
|
||||
System.out.printf("dir_next: invalid dir id: %d\n", id);
|
||||
return "";
|
||||
}
|
||||
|
||||
AssetDir ad = dirs.get(id);
|
||||
//System.out.printf("go next: %d,%d\n",ad.current,ad.files.length);
|
||||
|
||||
if (ad.current>=ad.files.length) {
|
||||
if (ad.current >= ad.files.length) {
|
||||
ad.current++;
|
||||
return "";
|
||||
}
|
||||
String r = ad.files[ad.current];
|
||||
ad.current++;
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
public void dir_close(int id) {
|
||||
|
||||
if (!dirs.containsKey(id)) {
|
||||
System.out.printf("dir_close: invalid dir id: %d\n",id);
|
||||
System.out.printf("dir_close: invalid dir id: %d\n", id);
|
||||
return;
|
||||
}
|
||||
|
||||
dirs.remove(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
GodotIO(Godot p_activity) {
|
||||
|
||||
am=p_activity.getAssets();
|
||||
activity=p_activity;
|
||||
streams=new HashMap<Integer,AssetData>();
|
||||
dirs=new HashMap<Integer,AssetDir>();
|
||||
am = p_activity.getAssets();
|
||||
activity = p_activity;
|
||||
streams = new HashMap<Integer, AssetData>();
|
||||
dirs = new HashMap<Integer, AssetDir>();
|
||||
applicationContext = activity.getApplicationContext();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////
|
||||
// AUDIO
|
||||
/////////////////////////
|
||||
@ -424,14 +402,14 @@ public class GodotIO {
|
||||
}
|
||||
|
||||
public void audioWriteShortBuffer(short[] buffer) {
|
||||
for (int i = 0; i < buffer.length; ) {
|
||||
for (int i = 0; i < buffer.length;) {
|
||||
int result = mAudioTrack.write(buffer, i, buffer.length - i);
|
||||
if (result > 0) {
|
||||
i += result;
|
||||
} else if (result == 0) {
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
} catch(InterruptedException e) {
|
||||
} catch (InterruptedException e) {
|
||||
// Nom nom
|
||||
}
|
||||
} else {
|
||||
@ -441,13 +419,11 @@ public class GodotIO {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void audioQuit() {
|
||||
if (mAudioThread != null) {
|
||||
try {
|
||||
mAudioThread.join();
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
Log.v("Godot", "Problem stopping audio thread: " + e);
|
||||
}
|
||||
mAudioThread = null;
|
||||
@ -473,20 +449,18 @@ public class GodotIO {
|
||||
// MISCELANEOUS OS IO
|
||||
/////////////////////////
|
||||
|
||||
|
||||
|
||||
public int openURI(String p_uri) {
|
||||
|
||||
try {
|
||||
Log.v("MyApp", "TRYING TO OPEN URI: " + p_uri);
|
||||
String path = p_uri;
|
||||
String type="";
|
||||
String type = "";
|
||||
if (path.startsWith("/")) {
|
||||
//absolute path to filesystem, prepend file://
|
||||
path="file://"+path;
|
||||
path = "file://" + path;
|
||||
if (p_uri.endsWith(".png") || p_uri.endsWith(".jpg") || p_uri.endsWith(".gif") || p_uri.endsWith(".webp")) {
|
||||
|
||||
type="image/*";
|
||||
type = "image/*";
|
||||
}
|
||||
}
|
||||
|
||||
@ -531,7 +505,7 @@ public class GodotIO {
|
||||
}
|
||||
|
||||
public void showKeyboard(String p_existing_text) {
|
||||
if(edit != null)
|
||||
if (edit != null)
|
||||
edit.showKeyboard(p_existing_text);
|
||||
|
||||
//InputMethodManager inputMgr = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
@ -539,7 +513,7 @@ public class GodotIO {
|
||||
};
|
||||
|
||||
public void hideKeyboard() {
|
||||
if(edit != null)
|
||||
if (edit != null)
|
||||
edit.hideKeyboard();
|
||||
|
||||
InputMethodManager inputMgr = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
@ -553,7 +527,7 @@ public class GodotIO {
|
||||
|
||||
public void setScreenOrientation(int p_orientation) {
|
||||
|
||||
switch(p_orientation) {
|
||||
switch (p_orientation) {
|
||||
|
||||
case SCREEN_LANDSCAPE: {
|
||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||
@ -576,7 +550,6 @@ public class GodotIO {
|
||||
case SCREEN_SENSOR: {
|
||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
|
||||
} break;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@ -584,8 +557,7 @@ public class GodotIO {
|
||||
edit = _edit;
|
||||
}
|
||||
|
||||
public void playVideo(String p_path)
|
||||
{
|
||||
public void playVideo(String p_path) {
|
||||
Uri filePath = Uri.parse(p_path);
|
||||
mediaPlayer = new MediaPlayer();
|
||||
|
||||
@ -594,9 +566,7 @@ public class GodotIO {
|
||||
mediaPlayer.setDataSource(applicationContext, filePath);
|
||||
mediaPlayer.prepare();
|
||||
mediaPlayer.start();
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
} catch (IOException e) {
|
||||
System.out.println("IOError while playing video");
|
||||
}
|
||||
}
|
||||
@ -621,49 +591,47 @@ public class GodotIO {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static final int SYSTEM_DIR_DESKTOP=0;
|
||||
public static final int SYSTEM_DIR_DCIM=1;
|
||||
public static final int SYSTEM_DIR_DOCUMENTS=2;
|
||||
public static final int SYSTEM_DIR_DOWNLOADS=3;
|
||||
public static final int SYSTEM_DIR_MOVIES=4;
|
||||
public static final int SYSTEM_DIR_MUSIC=5;
|
||||
public static final int SYSTEM_DIR_PICTURES=6;
|
||||
public static final int SYSTEM_DIR_RINGTONES=7;
|
||||
|
||||
public static final int SYSTEM_DIR_DESKTOP = 0;
|
||||
public static final int SYSTEM_DIR_DCIM = 1;
|
||||
public static final int SYSTEM_DIR_DOCUMENTS = 2;
|
||||
public static final int SYSTEM_DIR_DOWNLOADS = 3;
|
||||
public static final int SYSTEM_DIR_MOVIES = 4;
|
||||
public static final int SYSTEM_DIR_MUSIC = 5;
|
||||
public static final int SYSTEM_DIR_PICTURES = 6;
|
||||
public static final int SYSTEM_DIR_RINGTONES = 7;
|
||||
|
||||
public String getSystemDir(int idx) {
|
||||
|
||||
String what="";
|
||||
switch(idx) {
|
||||
String what = "";
|
||||
switch (idx) {
|
||||
case SYSTEM_DIR_DESKTOP: {
|
||||
//what=Environment.DIRECTORY_DOCUMENTS;
|
||||
what=Environment.DIRECTORY_DOWNLOADS;
|
||||
what = Environment.DIRECTORY_DOWNLOADS;
|
||||
} break;
|
||||
case SYSTEM_DIR_DCIM: {
|
||||
what=Environment.DIRECTORY_DCIM;
|
||||
what = Environment.DIRECTORY_DCIM;
|
||||
|
||||
} break;
|
||||
case SYSTEM_DIR_DOCUMENTS: {
|
||||
what=Environment.DIRECTORY_DOWNLOADS;
|
||||
what = Environment.DIRECTORY_DOWNLOADS;
|
||||
//what=Environment.DIRECTORY_DOCUMENTS;
|
||||
} break;
|
||||
case SYSTEM_DIR_DOWNLOADS: {
|
||||
what=Environment.DIRECTORY_DOWNLOADS;
|
||||
what = Environment.DIRECTORY_DOWNLOADS;
|
||||
|
||||
} break;
|
||||
case SYSTEM_DIR_MOVIES: {
|
||||
what=Environment.DIRECTORY_MOVIES;
|
||||
what = Environment.DIRECTORY_MOVIES;
|
||||
|
||||
} break;
|
||||
case SYSTEM_DIR_MUSIC: {
|
||||
what=Environment.DIRECTORY_MUSIC;
|
||||
what = Environment.DIRECTORY_MUSIC;
|
||||
} break;
|
||||
case SYSTEM_DIR_PICTURES: {
|
||||
what=Environment.DIRECTORY_PICTURES;
|
||||
what = Environment.DIRECTORY_PICTURES;
|
||||
} break;
|
||||
case SYSTEM_DIR_RINGTONES: {
|
||||
what=Environment.DIRECTORY_RINGTONES;
|
||||
what = Environment.DIRECTORY_RINGTONES;
|
||||
|
||||
} break;
|
||||
}
|
||||
@ -676,10 +644,9 @@ public class GodotIO {
|
||||
protected static final String PREFS_FILE = "device_id.xml";
|
||||
protected static final String PREFS_DEVICE_ID = "device_id";
|
||||
|
||||
public static String unique_id="";
|
||||
public static String unique_id = "";
|
||||
public String getUniqueID() {
|
||||
|
||||
return unique_id;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ package org.godotengine.godot;
|
||||
|
||||
public class GodotLib {
|
||||
|
||||
|
||||
public static GodotIO io;
|
||||
|
||||
static {
|
||||
@ -45,12 +44,12 @@ public class GodotLib {
|
||||
* @param height the current view height
|
||||
*/
|
||||
|
||||
public static native void initialize(Godot p_instance,boolean need_reload_hook,String[] p_cmdline,Object p_asset_manager);
|
||||
public static native void resize(int width, int height,boolean reload);
|
||||
public static native void initialize(Godot p_instance, boolean need_reload_hook, String[] p_cmdline, Object p_asset_manager);
|
||||
public static native void resize(int width, int height, boolean reload);
|
||||
public static native void newcontext(boolean p_32_bits);
|
||||
public static native void quit();
|
||||
public static native void step();
|
||||
public static native void touch(int what,int pointer,int howmany, int[] arr);
|
||||
public static native void touch(int what, int pointer, int howmany, int[] arr);
|
||||
public static native void accelerometer(float x, float y, float z);
|
||||
public static native void gravity(float x, float y, float z);
|
||||
public static native void magnetometer(float x, float y, float z);
|
||||
@ -63,10 +62,9 @@ public class GodotLib {
|
||||
public static native void focusin();
|
||||
public static native void focusout();
|
||||
public static native void audio();
|
||||
public static native void singleton(String p_name,Object p_object);
|
||||
public static native void method(String p_sname,String p_name,String p_ret,String[] p_params);
|
||||
public static native void singleton(String p_name, Object p_object);
|
||||
public static native void method(String p_sname, String p_name, String p_ret, String[] p_params);
|
||||
public static native String getGlobal(String p_key);
|
||||
public static native void callobject(int p_ID, String p_method, Object[] p_params);
|
||||
public static native void calldeferred(int p_ID, String p_method, Object[] p_params);
|
||||
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class GodotPaymentV3 extends Godot.SingletonBase {
|
||||
|
||||
private Godot activity;
|
||||
@ -67,8 +66,8 @@ public class GodotPaymentV3 extends Godot.SingletonBase {
|
||||
|
||||
public GodotPaymentV3(Activity p_activity) {
|
||||
|
||||
registerClass("GodotPayments", new String[]{"purchase", "setPurchaseCallbackId", "setPurchaseValidationUrlPrefix", "setTransactionId", "getSignature", "consumeUnconsumedPurchases", "requestPurchased", "setAutoConsume", "consume", "querySkuDetails", "isConnected"});
|
||||
activity = (Godot) p_activity;
|
||||
registerClass("GodotPayments", new String[] { "purchase", "setPurchaseCallbackId", "setPurchaseValidationUrlPrefix", "setTransactionId", "getSignature", "consumeUnconsumedPurchases", "requestPurchased", "setAutoConsume", "consume", "querySkuDetails", "isConnected" });
|
||||
activity = (Godot)p_activity;
|
||||
mPaymentManager = activity.getPaymentsManager();
|
||||
mPaymentManager.setBaseSingleton(this);
|
||||
}
|
||||
@ -89,32 +88,32 @@ public class GodotPaymentV3 extends Godot.SingletonBase {
|
||||
}
|
||||
|
||||
public void callbackSuccess(String ticket, String signature, String sku) {
|
||||
GodotLib.callobject(purchaseCallbackId, "purchase_success", new Object[]{ticket, signature, sku});
|
||||
GodotLib.callobject(purchaseCallbackId, "purchase_success", new Object[] { ticket, signature, sku });
|
||||
}
|
||||
|
||||
public void callbackSuccessProductMassConsumed(String ticket, String signature, String sku) {
|
||||
Log.d(this.getClass().getName(), "callbackSuccessProductMassConsumed > " + ticket + "," + signature + "," + sku);
|
||||
GodotLib.calldeferred(purchaseCallbackId, "consume_success", new Object[]{ticket, signature, sku});
|
||||
GodotLib.calldeferred(purchaseCallbackId, "consume_success", new Object[] { ticket, signature, sku });
|
||||
}
|
||||
|
||||
public void callbackSuccessNoUnconsumedPurchases() {
|
||||
GodotLib.calldeferred(purchaseCallbackId, "consume_not_required", new Object[]{});
|
||||
GodotLib.calldeferred(purchaseCallbackId, "consume_not_required", new Object[] {});
|
||||
}
|
||||
|
||||
public void callbackFailConsume() {
|
||||
GodotLib.calldeferred(purchaseCallbackId, "consume_fail", new Object[]{});
|
||||
GodotLib.calldeferred(purchaseCallbackId, "consume_fail", new Object[] {});
|
||||
}
|
||||
|
||||
public void callbackFail() {
|
||||
GodotLib.calldeferred(purchaseCallbackId, "purchase_fail", new Object[]{});
|
||||
GodotLib.calldeferred(purchaseCallbackId, "purchase_fail", new Object[] {});
|
||||
}
|
||||
|
||||
public void callbackCancel() {
|
||||
GodotLib.calldeferred(purchaseCallbackId, "purchase_cancel", new Object[]{});
|
||||
GodotLib.calldeferred(purchaseCallbackId, "purchase_cancel", new Object[] {});
|
||||
}
|
||||
|
||||
public void callbackAlreadyOwned(String sku) {
|
||||
GodotLib.calldeferred(purchaseCallbackId, "purchase_owned", new Object[]{sku});
|
||||
GodotLib.calldeferred(purchaseCallbackId, "purchase_owned", new Object[] { sku });
|
||||
}
|
||||
|
||||
public int getPurchaseCallbackId() {
|
||||
@ -161,15 +160,15 @@ public class GodotPaymentV3 extends Godot.SingletonBase {
|
||||
|
||||
// callback for requestPurchased()
|
||||
public void callbackPurchased(String receipt, String signature, String sku) {
|
||||
GodotLib.calldeferred(purchaseCallbackId, "has_purchased", new Object[]{receipt, signature, sku});
|
||||
GodotLib.calldeferred(purchaseCallbackId, "has_purchased", new Object[] { receipt, signature, sku });
|
||||
}
|
||||
|
||||
public void callbackDisconnected() {
|
||||
GodotLib.calldeferred(purchaseCallbackId, "iap_disconnected", new Object[]{});
|
||||
GodotLib.calldeferred(purchaseCallbackId, "iap_disconnected", new Object[] {});
|
||||
}
|
||||
|
||||
public void callbackConnected() {
|
||||
GodotLib.calldeferred(purchaseCallbackId, "iap_connected", new Object[]{});
|
||||
GodotLib.calldeferred(purchaseCallbackId, "iap_connected", new Object[] {});
|
||||
}
|
||||
|
||||
// true if connected, false otherwise
|
||||
@ -223,10 +222,10 @@ public class GodotPaymentV3 extends Godot.SingletonBase {
|
||||
}
|
||||
|
||||
public void completeSkuDetail() {
|
||||
GodotLib.calldeferred(purchaseCallbackId, "sku_details_complete", new Object[]{mSkuDetails});
|
||||
GodotLib.calldeferred(purchaseCallbackId, "sku_details_complete", new Object[] { mSkuDetails });
|
||||
}
|
||||
|
||||
public void errorSkuDetail(String errorMessage) {
|
||||
GodotLib.calldeferred(purchaseCallbackId, "sku_details_error", new Object[]{errorMessage});
|
||||
GodotLib.calldeferred(purchaseCallbackId, "sku_details_error", new Object[] { errorMessage });
|
||||
}
|
||||
}
|
||||
|
@ -77,20 +77,19 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
private static Context ctx;
|
||||
|
||||
private static GodotIO io;
|
||||
private static boolean firsttime=true;
|
||||
private static boolean use_gl2=false;
|
||||
private static boolean use_32=false;
|
||||
private static boolean firsttime = true;
|
||||
private static boolean use_gl2 = false;
|
||||
private static boolean use_32 = false;
|
||||
|
||||
private Godot activity;
|
||||
|
||||
|
||||
private InputManagerCompat mInputManager;
|
||||
public GodotView(Context context,GodotIO p_io,boolean p_use_gl2, boolean p_use_32_bits, Godot p_activity) {
|
||||
public GodotView(Context context, GodotIO p_io, boolean p_use_gl2, boolean p_use_32_bits, Godot p_activity) {
|
||||
super(context);
|
||||
ctx=context;
|
||||
io=p_io;
|
||||
use_gl2=p_use_gl2;
|
||||
use_32=p_use_32_bits;
|
||||
ctx = context;
|
||||
io = p_io;
|
||||
use_gl2 = p_use_gl2;
|
||||
use_32 = p_use_32_bits;
|
||||
|
||||
activity = p_activity;
|
||||
|
||||
@ -108,7 +107,8 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
init(translucent, depth, stencil);
|
||||
}
|
||||
|
||||
@Override public boolean onTouchEvent (MotionEvent event) {
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
|
||||
return activity.gotTouchEvent(event);
|
||||
};
|
||||
@ -196,7 +196,7 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
ArrayList<joystick> joy_devices = new ArrayList<joystick>();
|
||||
|
||||
private int find_joy_device(int device_id) {
|
||||
for (int i=0; i<joy_devices.size(); i++) {
|
||||
for (int i = 0; i < joy_devices.size(); i++) {
|
||||
if (joy_devices.get(i).device_id == device_id) {
|
||||
return i;
|
||||
}
|
||||
@ -205,7 +205,8 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
return joy_devices.size() - 1;
|
||||
}
|
||||
|
||||
@Override public void onInputDeviceAdded(int deviceId) {
|
||||
@Override
|
||||
public void onInputDeviceAdded(int deviceId) {
|
||||
joystick joy = new joystick();
|
||||
joy.device_id = deviceId;
|
||||
int id = joy_devices.size();
|
||||
@ -218,8 +219,7 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
for (InputDevice.MotionRange range : ranges) {
|
||||
if (range.getAxis() == MotionEvent.AXIS_HAT_X || range.getAxis() == MotionEvent.AXIS_HAT_Y) {
|
||||
joy.hats.add(range);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
joy.axes.add(range);
|
||||
}
|
||||
}
|
||||
@ -227,16 +227,18 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
GodotLib.joyconnectionchanged(id, true, joy.name);
|
||||
}
|
||||
|
||||
@Override public void onInputDeviceRemoved(int deviceId) {
|
||||
@Override
|
||||
public void onInputDeviceRemoved(int deviceId) {
|
||||
int id = find_joy_device(deviceId);
|
||||
joy_devices.remove(id);
|
||||
GodotLib.joyconnectionchanged(id, false, "");
|
||||
}
|
||||
|
||||
@Override public void onInputDeviceChanged(int deviceId) {
|
||||
|
||||
@Override
|
||||
public void onInputDeviceChanged(int deviceId) {
|
||||
}
|
||||
@Override public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
return true;
|
||||
@ -261,7 +263,8 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
return super.onKeyUp(keyCode, event);
|
||||
};
|
||||
|
||||
@Override public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
activity.onBackPressed();
|
||||
@ -295,7 +298,8 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@Override public boolean onGenericMotionEvent(MotionEvent event) {
|
||||
@Override
|
||||
public boolean onGenericMotionEvent(MotionEvent event) {
|
||||
|
||||
if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK && event.getAction() == MotionEvent.ACTION_MOVE) {
|
||||
|
||||
@ -304,14 +308,14 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
|
||||
for (int i = 0; i < joy.axes.size(); i++) {
|
||||
InputDevice.MotionRange range = joy.axes.get(i);
|
||||
float value = (event.getAxisValue(range.getAxis()) - range.getMin() ) / range.getRange() * 2.0f - 1.0f;
|
||||
float value = (event.getAxisValue(range.getAxis()) - range.getMin()) / range.getRange() * 2.0f - 1.0f;
|
||||
//Log.e(TAG, String.format("axis event: %d, value %f", i, value));
|
||||
GodotLib.joyaxis(device_id, i, value);
|
||||
}
|
||||
|
||||
for (int i = 0; i < joy.hats.size(); i+=2) {
|
||||
for (int i = 0; i < joy.hats.size(); i += 2) {
|
||||
int hatX = Math.round(event.getAxisValue(joy.hats.get(i).getAxis()));
|
||||
int hatY = Math.round(event.getAxisValue(joy.hats.get(i+1).getAxis()));
|
||||
int hatY = Math.round(event.getAxisValue(joy.hats.get(i + 1).getAxis()));
|
||||
//Log.e(TAG, String.format("HAT EVENT %d, %d", hatX, hatY));
|
||||
GodotLib.joyhat(device_id, hatX, hatY);
|
||||
}
|
||||
@ -321,7 +325,6 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
return super.onGenericMotionEvent(event);
|
||||
};
|
||||
|
||||
|
||||
private void init(boolean translucent, int depth, int stencil) {
|
||||
|
||||
this.setFocusableInTouchMode(true);
|
||||
@ -346,14 +349,14 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
*/
|
||||
|
||||
if (use_32) {
|
||||
setEGLConfigChooser( translucent ?
|
||||
setEGLConfigChooser(translucent ?
|
||||
new FallbackConfigChooser(8, 8, 8, 8, 24, stencil, new ConfigChooser(8, 8, 8, 8, 16, stencil)) :
|
||||
new FallbackConfigChooser(8, 8, 8, 8, 24, stencil, new ConfigChooser(5, 6, 5, 0, 16, stencil)) );
|
||||
new FallbackConfigChooser(8, 8, 8, 8, 24, stencil, new ConfigChooser(5, 6, 5, 0, 16, stencil)));
|
||||
|
||||
} else {
|
||||
setEGLConfigChooser( translucent ?
|
||||
setEGLConfigChooser(translucent ?
|
||||
new ConfigChooser(8, 8, 8, 8, 16, stencil) :
|
||||
new ConfigChooser(5, 6, 5, 0, 16, stencil) );
|
||||
new ConfigChooser(5, 6, 5, 0, 16, stencil));
|
||||
}
|
||||
|
||||
/* Set the renderer responsible for frame rendering */
|
||||
@ -369,8 +372,8 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
Log.w(TAG, "creating OpenGL ES 1.1 context :");
|
||||
|
||||
checkEglError("Before eglCreateContext", egl);
|
||||
int[] attrib_list2 = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
|
||||
EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, use_gl2?attrib_list2:null);
|
||||
int[] attrib_list2 = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
|
||||
EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, use_gl2 ? attrib_list2 : null);
|
||||
checkEglError("After eglCreateContext", egl);
|
||||
return context;
|
||||
}
|
||||
@ -401,7 +404,7 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
if (ec == null) {
|
||||
Log.w(TAG, "Trying ConfigChooser fallback");
|
||||
ec = fallback.chooseConfig(egl, display, configs);
|
||||
use_32=false;
|
||||
use_32 = false;
|
||||
}
|
||||
return ec;
|
||||
}
|
||||
@ -448,7 +451,7 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
/* Get the number of minimally matching EGL configurations
|
||||
*/
|
||||
int[] num_config = new int[1];
|
||||
egl.eglChooseConfig(display, use_gl2?s_configAttribs2:s_configAttribs, null, 0, num_config);
|
||||
egl.eglChooseConfig(display, use_gl2 ? s_configAttribs2 : s_configAttribs, null, 0, num_config);
|
||||
|
||||
int numConfigs = num_config[0];
|
||||
|
||||
@ -459,7 +462,7 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
/* Allocate then read the array of minimally matching EGL configs
|
||||
*/
|
||||
EGLConfig[] configs = new EGLConfig[numConfigs];
|
||||
egl.eglChooseConfig(display, use_gl2?s_configAttribs2:s_configAttribs, configs, numConfigs, num_config);
|
||||
egl.eglChooseConfig(display, use_gl2 ? s_configAttribs2 : s_configAttribs, configs, numConfigs, num_config);
|
||||
|
||||
if (DEBUG) {
|
||||
printConfigs(egl, display, configs);
|
||||
@ -471,7 +474,7 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
|
||||
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display,
|
||||
EGLConfig[] configs) {
|
||||
for(EGLConfig config : configs) {
|
||||
for (EGLConfig config : configs) {
|
||||
int d = findConfigAttrib(egl, display, config,
|
||||
EGL10.EGL_DEPTH_SIZE, 0);
|
||||
int s = findConfigAttrib(egl, display, config,
|
||||
@ -592,11 +595,12 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
for (int i = 0; i < attributes.length; i++) {
|
||||
int attribute = attributes[i];
|
||||
String name = names[i];
|
||||
if ( egl.eglGetConfigAttrib(display, config, attribute, value)) {
|
||||
if (egl.eglGetConfigAttrib(display, config, attribute, value)) {
|
||||
Log.w(TAG, String.format(" %s: %d\n", name, value[0]));
|
||||
} else {
|
||||
// Log.w(TAG, String.format(" %s: failed\n", name));
|
||||
while (egl.eglGetError() != EGL10.EGL_SUCCESS);
|
||||
while (egl.eglGetError() != EGL10.EGL_SUCCESS)
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -613,19 +617,18 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
|
||||
private static class Renderer implements GLSurfaceView.Renderer {
|
||||
|
||||
|
||||
public void onDrawFrame(GL10 gl) {
|
||||
GodotLib.step();
|
||||
for(int i=0;i<Godot.singleton_count;i++) {
|
||||
for (int i = 0; i < Godot.singleton_count; i++) {
|
||||
Godot.singletons[i].onGLDrawFrame(gl);
|
||||
}
|
||||
}
|
||||
|
||||
public void onSurfaceChanged(GL10 gl, int width, int height) {
|
||||
|
||||
GodotLib.resize(width, height,!firsttime);
|
||||
firsttime=false;
|
||||
for(int i=0;i<Godot.singleton_count;i++) {
|
||||
GodotLib.resize(width, height, !firsttime);
|
||||
firsttime = false;
|
||||
for (int i = 0; i < Godot.singleton_count; i++) {
|
||||
Godot.singletons[i].onGLSurfaceChanged(gl, width, height);
|
||||
}
|
||||
}
|
||||
|
@ -79,33 +79,28 @@ public class GodotEditText extends EditText {
|
||||
@Override
|
||||
public void handleMessage(final Message msg) {
|
||||
switch (msg.what) {
|
||||
case HANDLER_OPEN_IME_KEYBOARD:
|
||||
{
|
||||
GodotEditText edit = (GodotEditText) msg.obj;
|
||||
case HANDLER_OPEN_IME_KEYBOARD: {
|
||||
GodotEditText edit = (GodotEditText)msg.obj;
|
||||
String text = edit.mOriginText;
|
||||
if (edit.requestFocus())
|
||||
{
|
||||
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);
|
||||
final InputMethodManager imm = (InputMethodManager)mView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.showSoftInput(edit, 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case HANDLER_CLOSE_IME_KEYBOARD:
|
||||
{
|
||||
GodotEditText edit = (GodotEditText) msg.obj;
|
||||
case HANDLER_CLOSE_IME_KEYBOARD: {
|
||||
GodotEditText edit = (GodotEditText)msg.obj;
|
||||
|
||||
edit.removeTextChangedListener(mInputWrapper);
|
||||
final InputMethodManager imm = (InputMethodManager) mView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
final InputMethodManager imm = (InputMethodManager)mView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(edit.getWindowToken(), 0);
|
||||
edit.mView.requestFocus();
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -116,7 +111,7 @@ public class GodotEditText extends EditText {
|
||||
// ===========================================================
|
||||
public void setView(final GodotView view) {
|
||||
this.mView = view;
|
||||
if(mInputWrapper == null)
|
||||
if (mInputWrapper == null)
|
||||
mInputWrapper = new GodotTextInputWrapper(mView, this);
|
||||
this.setOnEditorActionListener(mInputWrapper);
|
||||
view.requestFocus();
|
||||
|
@ -67,7 +67,7 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
|
||||
|
||||
private boolean isFullScreenEdit() {
|
||||
final TextView textField = this.mEdit;
|
||||
final InputMethodManager imm = (InputMethodManager) textField.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
final InputMethodManager imm = (InputMethodManager)textField.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
return imm.isFullscreenMode();
|
||||
}
|
||||
|
||||
@ -81,14 +81,13 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(final Editable s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(final CharSequence pCharSequence, final int start, final int count, final int after) {
|
||||
//Log.d(TAG, "beforeTextChanged(" + pCharSequence + ")start: " + start + ",count: " + count + ",after: " + after);
|
||||
|
||||
for (int i=0;i<count;i++){
|
||||
for (int i = 0; i < count; i++) {
|
||||
GodotLib.key(KeyEvent.KEYCODE_DEL, 0, true);
|
||||
GodotLib.key(KeyEvent.KEYCODE_DEL, 0, false);
|
||||
}
|
||||
@ -98,12 +97,11 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
|
||||
public void onTextChanged(final CharSequence pCharSequence, final int start, final int before, final int count) {
|
||||
//Log.d(TAG, "onTextChanged(" + pCharSequence + ")start: " + start + ",count: " + count + ",before: " + before);
|
||||
|
||||
for (int i=start;i<start+count;i++){
|
||||
for (int i = start; i < start + count; i++) {
|
||||
int ch = pCharSequence.charAt(i);
|
||||
GodotLib.key(0, ch, true);
|
||||
GodotLib.key(0, ch, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -130,7 +128,7 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
|
||||
text += '\n';
|
||||
}
|
||||
|
||||
for(int i = 0; i < text.length(); i++) {
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
int ch = text.codePointAt(i);
|
||||
GodotLib.key(0, ch, true);
|
||||
GodotLib.key(0, ch, false);
|
||||
|
@ -34,7 +34,7 @@ public class InputManagerV16 implements InputManagerCompat {
|
||||
private final Map<InputManagerCompat.InputDeviceListener, V16InputDeviceListener> mListeners;
|
||||
|
||||
public InputManagerV16(Context context) {
|
||||
mInputManager = (InputManager) context.getSystemService(Context.INPUT_SERVICE);
|
||||
mInputManager = (InputManager)context.getSystemService(Context.INPUT_SERVICE);
|
||||
mListeners = new HashMap<InputManagerCompat.InputDeviceListener, V16InputDeviceListener>();
|
||||
}
|
||||
|
||||
@ -69,7 +69,6 @@ public class InputManagerV16 implements InputManagerCompat {
|
||||
public void onInputDeviceRemoved(int deviceId) {
|
||||
mIDL.onInputDeviceRemoved(deviceId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -82,11 +81,9 @@ public class InputManagerV16 implements InputManagerCompat {
|
||||
@Override
|
||||
public void unregisterInputDeviceListener(InputDeviceListener listener) {
|
||||
V16InputDeviceListener curListener = mListeners.remove(listener);
|
||||
if (null != curListener)
|
||||
{
|
||||
if (null != curListener) {
|
||||
mInputManager.unregisterInputDeviceListener(curListener);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -103,5 +100,4 @@ public class InputManagerV16 implements InputManagerCompat {
|
||||
public void onResume() {
|
||||
// unused in V16
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -82,7 +82,6 @@ public class InputManagerV9 implements InputManagerCompat {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public InputManagerV9() {
|
||||
@ -105,9 +104,9 @@ public class InputManagerV9 implements InputManagerCompat {
|
||||
// collection of watched input devices
|
||||
int[] activeDevices = InputDevice.getDeviceIds();
|
||||
long time = SystemClock.elapsedRealtime();
|
||||
for ( int id : activeDevices ) {
|
||||
for (int id : activeDevices) {
|
||||
long[] lastContact = mDevices.get(id);
|
||||
if ( null == lastContact ) {
|
||||
if (null == lastContact) {
|
||||
// we have a new device
|
||||
mDevices.put(id, new long[] { time });
|
||||
}
|
||||
@ -207,5 +206,4 @@ public class InputManagerV9 implements InputManagerCompat {
|
||||
public void onResume() {
|
||||
mDefaultHandler.sendEmptyMessage(MESSAGE_TEST_FOR_DISCONNECT);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -41,60 +41,58 @@ abstract public class ConsumeTask {
|
||||
private Context context;
|
||||
|
||||
private IInAppBillingService mService;
|
||||
public ConsumeTask(IInAppBillingService mService, Context context ){
|
||||
public ConsumeTask(IInAppBillingService mService, Context context) {
|
||||
this.context = context;
|
||||
this.mService = mService;
|
||||
}
|
||||
|
||||
|
||||
public void consume(final String sku){
|
||||
// Log.d("XXX", "Consuming product " + sku);
|
||||
public void consume(final String sku) {
|
||||
// Log.d("XXX", "Consuming product " + 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);
|
||||
}else if(!isBlocked){
|
||||
// Log.d("XXX", "It is not blocked ¿?");
|
||||
// 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);
|
||||
} else if (!isBlocked) {
|
||||
// Log.d("XXX", "It is not blocked ¿?");
|
||||
return;
|
||||
}else if(_token == null){
|
||||
// Log.d("XXX", "No token available");
|
||||
} else if (_token == null) {
|
||||
// Log.d("XXX", "No token available");
|
||||
this.error("No token for sku:" + sku);
|
||||
return;
|
||||
}
|
||||
final String token = _token;
|
||||
new AsyncTask<String, String, String>(){
|
||||
new AsyncTask<String, String, String>() {
|
||||
|
||||
@Override
|
||||
protected String doInBackground(String... params) {
|
||||
try {
|
||||
// Log.d("XXX", "Requesting to release item.");
|
||||
// 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){
|
||||
// Log.d("XXX", "release response code: " + response);
|
||||
if (response == 0 || response == 8) {
|
||||
return null;
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
return e.getMessage();
|
||||
|
||||
}
|
||||
return "Some error";
|
||||
}
|
||||
|
||||
protected void onPostExecute(String param){
|
||||
if(param == null){
|
||||
success( new PaymentsCache(context).getConsumableValue("ticket", sku) );
|
||||
}else{
|
||||
protected void onPostExecute(String param) {
|
||||
if (param == null) {
|
||||
success(new PaymentsCache(context).getConsumableValue("ticket", sku));
|
||||
} else {
|
||||
error(param);
|
||||
}
|
||||
}
|
||||
|
||||
}.execute();
|
||||
}
|
||||
.execute();
|
||||
}
|
||||
|
||||
abstract protected void success(String ticket);
|
||||
abstract protected void error(String message);
|
||||
|
||||
}
|
||||
|
@ -36,15 +36,12 @@ import android.os.AsyncTask;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
abstract public class GenericConsumeTask extends AsyncTask<String, String, String>{
|
||||
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){
|
||||
public GenericConsumeTask(Context context, IInAppBillingService mService, String sku, String receipt, String signature, String token) {
|
||||
this.context = context;
|
||||
this.mService = mService;
|
||||
this.sku = sku;
|
||||
@ -61,10 +58,10 @@ abstract public class GenericConsumeTask extends AsyncTask<String, String, Strin
|
||||
@Override
|
||||
protected String doInBackground(String... params) {
|
||||
try {
|
||||
// Log.d("godot", "Requesting to consume an item with token ." + token);
|
||||
// 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){
|
||||
// Log.d("godot", "consumePurchase response: " + response);
|
||||
if (response == 0 || response == 8) {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -73,10 +70,9 @@ abstract public class GenericConsumeTask extends AsyncTask<String, String, Strin
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void onPostExecute(String sarasa){
|
||||
protected void onPostExecute(String sarasa) {
|
||||
onSuccess(sku, receipt, signature, token);
|
||||
}
|
||||
|
||||
abstract public void onSuccess(String sku, String receipt, String signature, String token);
|
||||
|
||||
}
|
||||
|
@ -51,43 +51,41 @@ abstract public class HandlePurchaseTask {
|
||||
|
||||
private Activity context;
|
||||
|
||||
public HandlePurchaseTask(Activity context ){
|
||||
public HandlePurchaseTask(Activity context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
public void handlePurchaseRequest(int resultCode, Intent data){
|
||||
// Log.d("XXX", "Handling purchase response");
|
||||
// int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
|
||||
public void handlePurchaseRequest(int resultCode, Intent data) {
|
||||
// Log.d("XXX", "Handling purchase response");
|
||||
// int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
|
||||
PaymentsCache pc = new PaymentsCache(context);
|
||||
|
||||
String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
|
||||
// Log.d("XXX", "Purchase data:" + purchaseData);
|
||||
// Log.d("XXX", "Purchase data:" + purchaseData);
|
||||
String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");
|
||||
//Log.d("XXX", "Purchase signature:" + dataSignature);
|
||||
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
|
||||
try {
|
||||
// Log.d("SARLANGA", purchaseData);
|
||||
|
||||
// Log.d("SARLANGA", purchaseData);
|
||||
|
||||
JSONObject jo = new JSONObject(purchaseData);
|
||||
// String sku = jo.getString("productId");
|
||||
// alert("You have bought the " + sku + ". Excellent choice, aventurer!");
|
||||
// String orderId = jo.getString("orderId");
|
||||
// String packageName = jo.getString("packageName");
|
||||
// String sku = jo.getString("productId");
|
||||
// alert("You have bought the " + sku + ". Excellent choice, aventurer!");
|
||||
// String orderId = jo.getString("orderId");
|
||||
// String packageName = jo.getString("packageName");
|
||||
String productId = jo.getString("productId");
|
||||
// Long purchaseTime = jo.getLong("purchaseTime");
|
||||
// Integer state = jo.getInt("purchaseState");
|
||||
// Long purchaseTime = jo.getLong("purchaseTime");
|
||||
// Integer state = jo.getInt("purchaseState");
|
||||
String developerPayload = jo.getString("developerPayload");
|
||||
String purchaseToken = jo.getString("purchaseToken");
|
||||
|
||||
if(! pc.getConsumableValue("validation_hash", productId).equals(developerPayload) ) {
|
||||
if (!pc.getConsumableValue("validation_hash", productId).equals(developerPayload)) {
|
||||
error("Untrusted callback");
|
||||
return;
|
||||
}
|
||||
// Log.d("XXX", "Este es el product ID:" + productId);
|
||||
// Log.d("XXX", "Este es el product ID:" + productId);
|
||||
pc.setConsumableValue("ticket_signautre", productId, dataSignature);
|
||||
pc.setConsumableValue("ticket", productId, purchaseData);
|
||||
pc.setConsumableFlag("block", productId, true);
|
||||
@ -98,7 +96,7 @@ abstract public class HandlePurchaseTask {
|
||||
} catch (JSONException e) {
|
||||
error(e.getMessage());
|
||||
}
|
||||
}else if( resultCode == Activity.RESULT_CANCELED){
|
||||
} else if (resultCode == Activity.RESULT_CANCELED) {
|
||||
canceled();
|
||||
}
|
||||
}
|
||||
@ -106,6 +104,4 @@ abstract public class HandlePurchaseTask {
|
||||
abstract protected void success(String sku, String signature, String ticket);
|
||||
abstract protected void error(String message);
|
||||
abstract protected void canceled();
|
||||
|
||||
|
||||
}
|
||||
|
@ -37,38 +37,35 @@ public class PaymentsCache {
|
||||
|
||||
public Context context;
|
||||
|
||||
public PaymentsCache(Context context){
|
||||
public PaymentsCache(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
public void setConsumableFlag(String set, String sku, Boolean flag){
|
||||
public void setConsumableFlag(String set, String sku, Boolean flag) {
|
||||
SharedPreferences sharedPref = context.getSharedPreferences("consumables_" + set, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedPref.edit();
|
||||
editor.putBoolean(sku, flag);
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getConsumableFlag(String set, String sku){
|
||||
public boolean getConsumableFlag(String set, String sku) {
|
||||
SharedPreferences sharedPref = context.getSharedPreferences(
|
||||
"consumables_" + set, Context.MODE_PRIVATE);
|
||||
return sharedPref.getBoolean(sku, false);
|
||||
}
|
||||
|
||||
|
||||
public void setConsumableValue(String set, String sku, String value){
|
||||
public void setConsumableValue(String set, String sku, String value) {
|
||||
SharedPreferences sharedPref = context.getSharedPreferences("consumables_" + set, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedPref.edit();
|
||||
editor.putString(sku, value);
|
||||
// Log.d("XXX", "Setting asset: consumables_" + set + ":" + sku);
|
||||
// Log.d("XXX", "Setting asset: consumables_" + set + ":" + sku);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public String getConsumableValue(String set, String sku){
|
||||
public String getConsumableValue(String set, String sku) {
|
||||
SharedPreferences sharedPref = context.getSharedPreferences(
|
||||
"consumables_" + set, Context.MODE_PRIVATE);
|
||||
// Log.d("XXX", "Getting asset: consumables_" + set + ":" + sku);
|
||||
// Log.d("XXX", "Getting asset: consumables_" + set + ":" + sku);
|
||||
return sharedPref.getString(sku, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -116,7 +116,6 @@ public class PaymentsManager {
|
||||
@Override
|
||||
protected void error(String message) {
|
||||
godotPaymentV3.callbackFail();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -129,8 +128,8 @@ public class PaymentsManager {
|
||||
godotPaymentV3.callbackAlreadyOwned(sku);
|
||||
}
|
||||
|
||||
}.purchase(sku, transactionId);
|
||||
|
||||
}
|
||||
.purchase(sku, transactionId);
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
@ -149,16 +148,15 @@ public class PaymentsManager {
|
||||
protected void error(String message) {
|
||||
Log.d("godot", "consumeUnconsumedPurchases :" + message);
|
||||
godotPaymentV3.callbackFailConsume();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void notRequired() {
|
||||
Log.d("godot", "callbackSuccessNoUnconsumedPurchases :");
|
||||
godotPaymentV3.callbackSuccessNoUnconsumedPurchases();
|
||||
|
||||
}
|
||||
}.consumeItAll();
|
||||
}
|
||||
.consumeItAll();
|
||||
}
|
||||
|
||||
public void requestPurchased() {
|
||||
@ -224,9 +222,9 @@ public class PaymentsManager {
|
||||
@Override
|
||||
protected void error(String message) {
|
||||
godotPaymentV3.callbackFail();
|
||||
|
||||
}
|
||||
}.consume(sku);
|
||||
}
|
||||
.consume(sku);
|
||||
}
|
||||
}
|
||||
|
||||
@ -239,7 +237,8 @@ public class PaymentsManager {
|
||||
protected void canceled() {
|
||||
godotPaymentV3.callbackCancel();
|
||||
}
|
||||
}.handlePurchaseRequest(resultCode, data);
|
||||
}
|
||||
.handlePurchaseRequest(resultCode, data);
|
||||
}
|
||||
|
||||
public void validatePurchase(String purchaseToken, final String sku) {
|
||||
@ -260,8 +259,8 @@ public class PaymentsManager {
|
||||
protected void error(String message) {
|
||||
godotPaymentV3.callbackFail();
|
||||
}
|
||||
}.consume(sku);
|
||||
|
||||
}
|
||||
.consume(sku);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -273,7 +272,8 @@ public class PaymentsManager {
|
||||
protected void canceled() {
|
||||
godotPaymentV3.callbackCancel();
|
||||
}
|
||||
}.validatePurchase(sku);
|
||||
}
|
||||
.validatePurchase(sku);
|
||||
}
|
||||
|
||||
public void setAutoConsume(boolean autoConsume) {
|
||||
@ -292,7 +292,8 @@ public class PaymentsManager {
|
||||
protected void error(String message) {
|
||||
godotPaymentV3.callbackFailConsume();
|
||||
}
|
||||
}.consume(sku);
|
||||
}
|
||||
.consume(sku);
|
||||
}
|
||||
|
||||
// Workaround to bug where sometimes response codes come as Long instead of Integer
|
||||
@ -301,8 +302,10 @@ public class PaymentsManager {
|
||||
if (o == null) {
|
||||
//logDebug("Bundle with null response code, assuming OK (known issue)");
|
||||
return BILLING_RESPONSE_RESULT_OK;
|
||||
} else if (o instanceof Integer) return ((Integer) o).intValue();
|
||||
else if (o instanceof Long) return (int) ((Long) o).longValue();
|
||||
} else if (o instanceof Integer)
|
||||
return ((Integer)o).intValue();
|
||||
else if (o instanceof Long)
|
||||
return (int)((Long)o).longValue();
|
||||
else {
|
||||
//logError("Unexpected type for bundle response code.");
|
||||
//logError(o.getClass().getName());
|
||||
@ -318,25 +321,41 @@ public class PaymentsManager {
|
||||
* It also includes the result code numerically.
|
||||
*/
|
||||
public static String getResponseDesc(int code) {
|
||||
String[] iab_msgs = ("0:OK/1:User Canceled/2:Unknown/" +
|
||||
"3:Billing Unavailable/4:Item unavailable/" +
|
||||
"5:Developer Error/6:Error/7:Item Already Owned/" +
|
||||
"8:Item not owned").split("/");
|
||||
String[] iabhelper_msgs = ("0:OK/-1001:Remote exception during initialization/" +
|
||||
"-1002:Bad response received/" +
|
||||
"-1003:Purchase signature verification failed/" +
|
||||
"-1004:Send intent failed/" +
|
||||
"-1005:User cancelled/" +
|
||||
"-1006:Unknown purchase response/" +
|
||||
"-1007:Missing token/" +
|
||||
"-1008:Unknown error/" +
|
||||
"-1009:Subscriptions not available/" +
|
||||
"-1010:Invalid consumption attempt").split("/");
|
||||
String[] iab_msgs = ("0:OK/1:User Canceled/2:Unknown/"
|
||||
+
|
||||
"3:Billing Unavailable/4:Item unavailable/"
|
||||
+
|
||||
"5:Developer Error/6:Error/7:Item Already Owned/"
|
||||
+
|
||||
"8:Item not owned")
|
||||
.split("/");
|
||||
String[] iabhelper_msgs = ("0:OK/-1001:Remote exception during initialization/"
|
||||
+
|
||||
"-1002:Bad response received/"
|
||||
+
|
||||
"-1003:Purchase signature verification failed/"
|
||||
+
|
||||
"-1004:Send intent failed/"
|
||||
+
|
||||
"-1005:User cancelled/"
|
||||
+
|
||||
"-1006:Unknown purchase response/"
|
||||
+
|
||||
"-1007:Missing token/"
|
||||
+
|
||||
"-1008:Unknown error/"
|
||||
+
|
||||
"-1009:Subscriptions not available/"
|
||||
+
|
||||
"-1010:Invalid consumption attempt")
|
||||
.split("/");
|
||||
|
||||
if (code <= -1000) {
|
||||
int index = -1000 - code;
|
||||
if (index >= 0 && index < iabhelper_msgs.length) return iabhelper_msgs[index];
|
||||
else return String.valueOf(code) + ":Unknown IAB Helper Error";
|
||||
if (index >= 0 && index < iabhelper_msgs.length)
|
||||
return iabhelper_msgs[index];
|
||||
else
|
||||
return String.valueOf(code) + ":Unknown IAB Helper Error";
|
||||
} else if (code < 0 || code >= iab_msgs.length)
|
||||
return String.valueOf(code) + ":Unknown";
|
||||
else
|
||||
@ -389,7 +408,7 @@ public class PaymentsManager {
|
||||
ArrayList<String> responseList = skuDetails.getStringArrayList("DETAILS_LIST");
|
||||
|
||||
for (String thisResponse : responseList) {
|
||||
Log.d("godot", "response = "+thisResponse);
|
||||
Log.d("godot", "response = " + thisResponse);
|
||||
godotPaymentV3.addSkuDetail(thisResponse);
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
@ -399,7 +418,8 @@ public class PaymentsManager {
|
||||
}
|
||||
godotPaymentV3.completeSkuDetail();
|
||||
}
|
||||
})).start();
|
||||
}))
|
||||
.start();
|
||||
}
|
||||
|
||||
private GodotPaymentV3 godotPaymentV3;
|
||||
@ -407,5 +427,4 @@ public class PaymentsManager {
|
||||
public void setBaseSingleton(GodotPaymentV3 godotPaymentV3) {
|
||||
this.godotPaymentV3 = godotPaymentV3;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -52,63 +52,61 @@ abstract public class PurchaseTask {
|
||||
private Activity context;
|
||||
|
||||
private IInAppBillingService mService;
|
||||
public PurchaseTask(IInAppBillingService mService, Activity context ){
|
||||
public PurchaseTask(IInAppBillingService mService, Activity context) {
|
||||
this.context = context;
|
||||
this.mService = mService;
|
||||
}
|
||||
|
||||
|
||||
private boolean isLooping = false;
|
||||
|
||||
public void purchase(final String sku, final String transactionId){
|
||||
public void purchase(final String sku, final String transactionId) {
|
||||
Log.d("XXX", "Starting purchase for: " + sku);
|
||||
PaymentsCache pc = new PaymentsCache(context);
|
||||
Boolean isBlocked = pc.getConsumableFlag("block", sku);
|
||||
// if(isBlocked){
|
||||
// Log.d("XXX", "Is awaiting payment confirmation");
|
||||
// error("Awaiting payment confirmation");
|
||||
// return;
|
||||
// }
|
||||
// if(isBlocked){
|
||||
// Log.d("XXX", "Is awaiting payment confirmation");
|
||||
// error("Awaiting payment confirmation");
|
||||
// return;
|
||||
// }
|
||||
final String hash = transactionId;
|
||||
|
||||
Bundle buyIntentBundle;
|
||||
try {
|
||||
buyIntentBundle = mService.getBuyIntent(3, context.getApplicationContext().getPackageName(), sku, "inapp", hash );
|
||||
buyIntentBundle = mService.getBuyIntent(3, context.getApplicationContext().getPackageName(), sku, "inapp", hash);
|
||||
} catch (RemoteException e) {
|
||||
// Log.d("XXX", "Error: " + e.getMessage());
|
||||
// Log.d("XXX", "Error: " + e.getMessage());
|
||||
error(e.getMessage());
|
||||
return;
|
||||
}
|
||||
Object rc = buyIntentBundle.get("RESPONSE_CODE");
|
||||
int responseCode = 0;
|
||||
if(rc == null){
|
||||
if (rc == null) {
|
||||
responseCode = PaymentsManager.BILLING_RESPONSE_RESULT_OK;
|
||||
}else if( rc instanceof Integer){
|
||||
} else if (rc instanceof Integer) {
|
||||
responseCode = ((Integer)rc).intValue();
|
||||
}else if( rc instanceof Long){
|
||||
} else if (rc instanceof Long) {
|
||||
responseCode = (int)((Long)rc).longValue();
|
||||
}
|
||||
// Log.d("XXX", "Buy intent response code: " + responseCode);
|
||||
if(responseCode == 1 || responseCode == 3 || responseCode == 4){
|
||||
// Log.d("XXX", "Buy intent response code: " + responseCode);
|
||||
if (responseCode == 1 || responseCode == 3 || responseCode == 4) {
|
||||
canceled();
|
||||
return;
|
||||
}
|
||||
if(responseCode == 7){
|
||||
if (responseCode == 7) {
|
||||
alreadyOwned();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
|
||||
pc.setConsumableValue("validation_hash", sku, hash);
|
||||
try {
|
||||
if(context == null){
|
||||
// Log.d("XXX", "No context!");
|
||||
if (context == null) {
|
||||
// Log.d("XXX", "No context!");
|
||||
}
|
||||
if(pendingIntent == null){
|
||||
// Log.d("XXX", "No pending intent");
|
||||
if (pendingIntent == null) {
|
||||
// Log.d("XXX", "No pending intent");
|
||||
}
|
||||
// Log.d("XXX", "Starting activity for purchase!");
|
||||
// Log.d("XXX", "Starting activity for purchase!");
|
||||
context.startIntentSenderForResult(
|
||||
pendingIntent.getIntentSender(),
|
||||
PaymentsManager.REQUEST_CODE_FOR_PURCHASE,
|
||||
@ -118,13 +116,9 @@ abstract public class PurchaseTask {
|
||||
} catch (SendIntentException e) {
|
||||
error(e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
abstract protected void error(String message);
|
||||
abstract protected void canceled();
|
||||
abstract protected void alreadyOwned();
|
||||
|
||||
}
|
||||
|
@ -49,62 +49,57 @@ abstract public class ReleaseAllConsumablesTask {
|
||||
private Context context;
|
||||
private IInAppBillingService mService;
|
||||
|
||||
public ReleaseAllConsumablesTask(IInAppBillingService mService, Context context ){
|
||||
public ReleaseAllConsumablesTask(IInAppBillingService mService, Context context) {
|
||||
this.context = context;
|
||||
this.mService = mService;
|
||||
}
|
||||
|
||||
|
||||
public void consumeItAll(){
|
||||
try{
|
||||
// Log.d("godot", "consumeItall for " + context.getPackageName());
|
||||
Bundle bundle = mService.getPurchases(3, context.getPackageName(), "inapp",null);
|
||||
public void consumeItAll() {
|
||||
try {
|
||||
// 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()));
|
||||
// Log.d("godot", String.format("%s %s (%s)", key,
|
||||
// value.toString(), value.getClass().getName()));
|
||||
}
|
||||
|
||||
|
||||
if (bundle.getInt("RESPONSE_CODE") == 0){
|
||||
if (bundle.getInt("RESPONSE_CODE") == 0) {
|
||||
|
||||
final ArrayList<String> myPurchases = bundle.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
|
||||
final ArrayList<String> mySignatures = bundle.getStringArrayList("INAPP_DATA_SIGNATURE_LIST");
|
||||
|
||||
|
||||
if (myPurchases == null || myPurchases.size() == 0){
|
||||
// Log.d("godot", "No purchases!");
|
||||
if (myPurchases == null || myPurchases.size() == 0) {
|
||||
// Log.d("godot", "No purchases!");
|
||||
notRequired();
|
||||
return;
|
||||
}
|
||||
|
||||
// Log.d("godot", "# products to be consumed:" + myPurchases.size());
|
||||
for (int i = 0; i < myPurchases.size(); i++) {
|
||||
|
||||
// Log.d("godot", "# products to be consumed:" + myPurchases.size());
|
||||
for (int i=0;i<myPurchases.size();i++)
|
||||
{
|
||||
|
||||
try{
|
||||
try {
|
||||
String receipt = myPurchases.get(i);
|
||||
JSONObject inappPurchaseData = new JSONObject(receipt);
|
||||
String sku = inappPurchaseData.getString("productId");
|
||||
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) {
|
||||
// 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();
|
||||
}
|
||||
.execute();
|
||||
|
||||
} catch (JSONException e) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}catch(Exception e){
|
||||
} catch (Exception e) {
|
||||
Log.d("godot", "Error releasing products:" + e.getClass().getName() + ":" + e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -112,5 +107,4 @@ abstract public class ReleaseAllConsumablesTask {
|
||||
abstract protected void success(String sku, String receipt, String signature, String token);
|
||||
abstract protected void error(String message);
|
||||
abstract protected void notRequired();
|
||||
|
||||
}
|
||||
|
@ -55,19 +55,18 @@ abstract public class ValidateTask {
|
||||
|
||||
private Activity context;
|
||||
private GodotPaymentV3 godotPaymentsV3;
|
||||
public ValidateTask(Activity context, GodotPaymentV3 godotPaymentsV3){
|
||||
public ValidateTask(Activity context, GodotPaymentV3 godotPaymentsV3) {
|
||||
this.context = context;
|
||||
this.godotPaymentsV3 = godotPaymentsV3;
|
||||
}
|
||||
|
||||
public void validatePurchase(final String sku){
|
||||
new AsyncTask<String, String, String>(){
|
||||
|
||||
public void validatePurchase(final String sku) {
|
||||
new AsyncTask<String, String, String>() {
|
||||
|
||||
private ProgressDialog dialog;
|
||||
|
||||
@Override
|
||||
protected void onPreExecute(){
|
||||
protected void onPreExecute() {
|
||||
dialog = ProgressDialog.show(context, null, "Please wait...");
|
||||
}
|
||||
|
||||
@ -80,47 +79,44 @@ abstract public class ValidateTask {
|
||||
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);
|
||||
// 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);
|
||||
// Log.d("XXX", "Validation response:\n"+jsonResponse);
|
||||
return jsonResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String response){
|
||||
if(dialog != null){
|
||||
protected void onPostExecute(String response) {
|
||||
if (dialog != null) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
JSONObject j;
|
||||
try {
|
||||
j = new JSONObject(response);
|
||||
if(j.getString("status").equals("OK")){
|
||||
if (j.getString("status").equals("OK")) {
|
||||
success();
|
||||
return;
|
||||
}else if(j.getString("status") != null){
|
||||
} else if (j.getString("status") != null) {
|
||||
error(j.getString("message"));
|
||||
}else{
|
||||
} else {
|
||||
error("Connection error");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
error(e.getMessage());
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
error(e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}.execute();
|
||||
}
|
||||
.execute();
|
||||
}
|
||||
abstract protected void success();
|
||||
abstract protected void error(String message);
|
||||
abstract protected void canceled();
|
||||
|
||||
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ import java.util.Random;
|
||||
|
||||
public class Crypt {
|
||||
|
||||
public static String md5(String input){
|
||||
public static String md5(String input) {
|
||||
try {
|
||||
// Create MD5 Hash
|
||||
MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
|
||||
@ -43,7 +43,7 @@ public class Crypt {
|
||||
|
||||
// Create Hex String
|
||||
StringBuffer hexString = new StringBuffer();
|
||||
for (int i=0; i<messageDigest.length; i++)
|
||||
for (int i = 0; i < messageDigest.length; i++)
|
||||
hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
|
||||
return hexString.toString();
|
||||
|
||||
@ -53,15 +53,15 @@ public class Crypt {
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String createRandomHash(){
|
||||
public static String createRandomHash() {
|
||||
return md5(Long.toString(createRandomLong()));
|
||||
}
|
||||
|
||||
public static long createAbsRandomLong(){
|
||||
public static long createAbsRandomLong() {
|
||||
return Math.abs(createRandomLong());
|
||||
}
|
||||
|
||||
public static long createRandomLong(){
|
||||
public static long createRandomLong() {
|
||||
Random r = new Random();
|
||||
return r.nextLong();
|
||||
}
|
||||
|
@ -42,7 +42,6 @@ import javax.net.ssl.TrustManagerFactory;
|
||||
|
||||
import org.apache.http.conn.ssl.SSLSocketFactory;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Luis Linietsky <luis.linietsky@gmail.com>
|
||||
|
@ -63,7 +63,6 @@ import org.apache.http.params.HttpProtocolParams;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
@ -76,18 +75,18 @@ public class HttpRequester {
|
||||
|
||||
private Context context;
|
||||
private static final int TTL = 600000; // 10 minutos
|
||||
private long cttl=0;
|
||||
private long cttl = 0;
|
||||
|
||||
public HttpRequester(){
|
||||
// Log.d("XXX", "Creando http request sin contexto");
|
||||
public HttpRequester() {
|
||||
// Log.d("XXX", "Creando http request sin contexto");
|
||||
}
|
||||
|
||||
public HttpRequester(Context context){
|
||||
this.context=context;
|
||||
// Log.d("XXX", "Creando http request con contexto");
|
||||
public HttpRequester(Context context) {
|
||||
this.context = context;
|
||||
// Log.d("XXX", "Creando http request con contexto");
|
||||
}
|
||||
|
||||
public String post(RequestParams params){
|
||||
public String post(RequestParams params) {
|
||||
HttpPost httppost = new HttpPost(params.getUrl());
|
||||
try {
|
||||
httppost.setEntity(new UrlEncodedFormEntity(params.toPairsList()));
|
||||
@ -97,18 +96,18 @@ public class HttpRequester {
|
||||
}
|
||||
}
|
||||
|
||||
public String get(RequestParams params){
|
||||
public String get(RequestParams params) {
|
||||
String response = getResponseFromCache(params.getUrl());
|
||||
if(response == null){
|
||||
// Log.d("XXX", "Cache miss!");
|
||||
if (response == null) {
|
||||
// Log.d("XXX", "Cache miss!");
|
||||
HttpGet httpget = new HttpGet(params.getUrl());
|
||||
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");
|
||||
if(response == null || response.length() == 0){
|
||||
Log.d("com.app11tt.android.utils.HttpRequest::get(url)", "Url: " + params.getUrl() + " downloaded in " + String.format("%.03f", delay / 1000.0f) + " seconds");
|
||||
if (response == null || response.length() == 0) {
|
||||
response = "";
|
||||
}else{
|
||||
} else {
|
||||
saveResponseIntoCache(params.getUrl(), response);
|
||||
}
|
||||
}
|
||||
@ -117,9 +116,9 @@ public class HttpRequester {
|
||||
return response;
|
||||
}
|
||||
|
||||
private String request(HttpUriRequest request){
|
||||
// Log.d("XXX", "Haciendo request a: " + request.getURI() );
|
||||
Log.d("PPP", "Haciendo request a: " + request.getURI() );
|
||||
private String request(HttpUriRequest request) {
|
||||
// Log.d("XXX", "Haciendo request a: " + request.getURI() );
|
||||
Log.d("PPP", "Haciendo request a: " + request.getURI());
|
||||
long init = new Date().getTime();
|
||||
HttpClient httpclient = getNewHttpClient();
|
||||
HttpParams httpParameters = httpclient.getParams();
|
||||
@ -128,13 +127,13 @@ public class HttpRequester {
|
||||
HttpConnectionParams.setTcpNoDelay(httpParameters, true);
|
||||
try {
|
||||
HttpResponse response = httpclient.execute(request);
|
||||
Log.d("PPP", "Fin de request (" + (new Date().getTime() - init) + ") a: " + request.getURI() );
|
||||
// Log.d("XXX1", "Status:" + response.getStatusLine().toString());
|
||||
if(response.getStatusLine().getStatusCode() == 200){
|
||||
Log.d("PPP", "Fin de request (" + (new Date().getTime() - init) + ") a: " + request.getURI());
|
||||
// Log.d("XXX1", "Status:" + response.getStatusLine().toString());
|
||||
if (response.getStatusLine().getStatusCode() == 200) {
|
||||
String strResponse = EntityUtils.toString(response.getEntity());
|
||||
// Log.d("XXX2", strResponse);
|
||||
// Log.d("XXX2", strResponse);
|
||||
return strResponse;
|
||||
}else{
|
||||
} else {
|
||||
Log.d("XXX3", "Response status code:" + response.getStatusLine().getStatusCode() + "\n" + EntityUtils.toString(response.getEntity()));
|
||||
return null;
|
||||
}
|
||||
@ -191,9 +190,9 @@ public class HttpRequester {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void saveResponseIntoCache(String request, String response){
|
||||
if(context == null){
|
||||
// Log.d("XXX", "No context, cache failed!");
|
||||
public void saveResponseIntoCache(String request, String response) {
|
||||
if (context == null) {
|
||||
// Log.d("XXX", "No context, cache failed!");
|
||||
return;
|
||||
}
|
||||
SharedPreferences sharedPref = context.getSharedPreferences("http_get_cache", Context.MODE_PRIVATE);
|
||||
@ -203,22 +202,21 @@ public class HttpRequester {
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
|
||||
public String getResponseFromCache(String request){
|
||||
if(context == null){
|
||||
public String getResponseFromCache(String request) {
|
||||
if (context == null) {
|
||||
Log.d("XXX", "No context, cache miss");
|
||||
return null;
|
||||
}
|
||||
SharedPreferences sharedPref = context.getSharedPreferences( "http_get_cache", Context.MODE_PRIVATE);
|
||||
SharedPreferences sharedPref = context.getSharedPreferences("http_get_cache", Context.MODE_PRIVATE);
|
||||
long ttl = getResponseTtl(request);
|
||||
if(ttl == 0l || (new Date().getTime() - ttl) > 0l){
|
||||
if (ttl == 0l || (new Date().getTime() - ttl) > 0l) {
|
||||
Log.d("XXX", "Cache invalid ttl:" + ttl + " vs now:" + new Date().getTime());
|
||||
return null;
|
||||
}
|
||||
return sharedPref.getString("request_" + Crypt.md5(request), null);
|
||||
}
|
||||
|
||||
public long getResponseTtl(String request){
|
||||
public long getResponseTtl(String request) {
|
||||
SharedPreferences sharedPref = context.getSharedPreferences(
|
||||
"http_get_cache", Context.MODE_PRIVATE);
|
||||
return sharedPref.getLong("request_" + Crypt.md5(request) + "_ttl", 0l);
|
||||
@ -229,7 +227,6 @@ public class HttpRequester {
|
||||
}
|
||||
|
||||
public void setTtl(long ttl) {
|
||||
this.cttl = (ttl*1000) + new Date().getTime();
|
||||
this.cttl = (ttl * 1000) + new Date().getTime();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,33 +43,33 @@ import org.apache.http.message.BasicNameValuePair;
|
||||
*/
|
||||
public class RequestParams {
|
||||
|
||||
private HashMap<String,String> params;
|
||||
private HashMap<String, String> params;
|
||||
private String url;
|
||||
|
||||
public RequestParams(){
|
||||
params = new HashMap<String,String>();
|
||||
public RequestParams() {
|
||||
params = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
public void put(String key, String value){
|
||||
public void put(String key, String value) {
|
||||
params.put(key, value);
|
||||
}
|
||||
|
||||
public String get(String key){
|
||||
public String get(String key) {
|
||||
return params.get(key);
|
||||
}
|
||||
|
||||
public void remove(Object key){
|
||||
public void remove(Object key) {
|
||||
params.remove(key);
|
||||
}
|
||||
|
||||
public boolean has(String key){
|
||||
public boolean has(String key) {
|
||||
return params.containsKey(key);
|
||||
}
|
||||
|
||||
public List<NameValuePair> toPairsList(){
|
||||
public List<NameValuePair> toPairsList() {
|
||||
List<NameValuePair> fields = new ArrayList<NameValuePair>();
|
||||
|
||||
for(String key : params.keySet()){
|
||||
for (String key : params.keySet()) {
|
||||
fields.add(new BasicNameValuePair(key, this.get(key)));
|
||||
}
|
||||
return fields;
|
||||
@ -82,6 +82,4 @@ public class RequestParams {
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user