You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-17 14:11:06 +00:00
Improve android java support
- Use Log.d/Log.w instead of System.printf
- Remove commented code
- Cherry-pick: Manual backport of d698814367
This commit is contained in:
@@ -78,3 +78,4 @@ public class Dictionary extends HashMap<String, Object> {
|
||||
keys_cache = null;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ import android.os.Messenger;
|
||||
import android.os.SystemClock;
|
||||
|
||||
public class Godot extends Activity implements SensorEventListener, IDownloaderClient {
|
||||
|
||||
private static final String TAG = "Godot";
|
||||
static final int MAX_SINGLETONS = 64;
|
||||
private IStub mDownloaderClientStub;
|
||||
private IDownloaderService mRemoteService;
|
||||
@@ -149,21 +149,16 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
Method[] methods = clazz.getDeclaredMethods();
|
||||
for (Method method : methods) {
|
||||
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");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
continue;
|
||||
|
||||
Log.d("XXX", "METHOD FOUND: %s\n" + method.getName());
|
||||
|
||||
List<String> ptr = new ArrayList<String>();
|
||||
|
||||
Class[] paramTypes = method.getParameterTypes();
|
||||
@@ -190,21 +185,10 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
|
||||
protected void onGLDrawFrame(GL10 gl) {}
|
||||
protected void onGLSurfaceChanged(GL10 gl, int width, int height) {} // singletons will always miss first onGLSurfaceChanged call
|
||||
//protected void onGLSurfaceCreated(GL10 gl, EGLConfig config) {} // singletons won't be ready until first GodotLib.step()
|
||||
|
||||
public void registerMethods() {}
|
||||
}
|
||||
|
||||
/*
|
||||
protected List<SingletonBase> singletons = new ArrayList<SingletonBase>();
|
||||
protected void instanceSingleton(SingletonBase s) {
|
||||
|
||||
s.registerMethods();
|
||||
singletons.add(s);
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
private String[] command_line;
|
||||
|
||||
public GodotView mView;
|
||||
@@ -222,7 +206,6 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
static public GodotIO io;
|
||||
|
||||
public static void setWindowTitle(String title) {
|
||||
//setTitle(title);
|
||||
}
|
||||
|
||||
static SingletonBase singletons[] = new SingletonBase[MAX_SINGLETONS];
|
||||
@@ -253,9 +236,6 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
|
||||
public void onVideoInit(boolean use_gl2) {
|
||||
|
||||
// mView = new GodotView(getApplication(),io,use_gl2);
|
||||
// setContentView(mView);
|
||||
|
||||
layout = new FrameLayout(this);
|
||||
layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
|
||||
setContentView(layout);
|
||||
@@ -273,7 +253,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
edittext.setView(mView);
|
||||
io.setEdit(edittext);
|
||||
|
||||
// Ad layout
|
||||
// Add layout
|
||||
adLayout = new RelativeLayout(this);
|
||||
adLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
|
||||
layout.addView(adLayout);
|
||||
@@ -323,8 +303,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
byte[] len = new byte[4];
|
||||
int r = is.read(len);
|
||||
if (r < 4) {
|
||||
Log.d("XXX", "**ERROR** Wrong cmdline length.\n");
|
||||
Log.d("GODOT", "**ERROR** Wrong cmdline length.\n");
|
||||
Log.w(TAG, "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));
|
||||
@@ -334,12 +313,12 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
r = is.read(len);
|
||||
if (r < 4) {
|
||||
|
||||
Log.d("GODOT", "**ERROR** Wrong cmdline param lenght.\n");
|
||||
Log.w(TAG, "Wrong cmdline param length.\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) {
|
||||
Log.d("GODOT", "**ERROR** Wrong command len\n");
|
||||
Log.w(TAG, "Wrong command length\n");
|
||||
return new String[0];
|
||||
}
|
||||
byte[] arg = new byte[strlen];
|
||||
@@ -351,7 +330,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
return cmdline;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.d("GODOT", "**ERROR** Exception " + e.getClass().getName() + ":" + e.getMessage());
|
||||
Log.w(TAG, "Exception " + e.getClass().getName() + ":" + e.getMessage());
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
@@ -365,14 +344,14 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
String[] new_cmdline;
|
||||
int cll = 0;
|
||||
if (command_line != null) {
|
||||
Log.d("GODOT", "initializeGodot: command_line: is not null");
|
||||
Log.d(TAG, "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");
|
||||
Log.d(TAG, "initializeGodot: command_line: is null");
|
||||
new_cmdline = new String[2];
|
||||
}
|
||||
|
||||
@@ -384,13 +363,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
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"));
|
||||
/*if(command_line != null){
|
||||
Log.d("GODOT", "Command Line:");
|
||||
for(int w=0;w <command_line.length;w++){
|
||||
Log.d("GODOT"," " + command_line[w]);
|
||||
}
|
||||
}*/
|
||||
Log.d(TAG, "command_line is null? " + ((command_line == null) ? "yes" : "no"));
|
||||
GodotLib.initialize(this, io.needsReloadHooks(), command_line, getAssets());
|
||||
mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
|
||||
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
|
||||
@@ -417,15 +390,13 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
@Override
|
||||
protected void onCreate(Bundle icicle) {
|
||||
|
||||
Log.d("GODOT", "** GODOT ACTIVITY CREATED HERE ***\n");
|
||||
Log.d(TAG, "** GODOT ACTIVITY CREATED HERE ***\n");
|
||||
|
||||
super.onCreate(icicle);
|
||||
_self = this;
|
||||
Window window = getWindow();
|
||||
//window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
|
||||
|
||||
//check for apk expansion API
|
||||
if (true) {
|
||||
boolean md5mismatch = false;
|
||||
command_line = getCommandLine();
|
||||
@@ -477,7 +448,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
if (use_apk_expansion && main_pack_md5 != null && main_pack_key != null) {
|
||||
//check that environment is ok!
|
||||
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||
Log.d("GODOT", "**ERROR! No media mounted!");
|
||||
Log.d(TAG, "**ERROR! No media mounted!");
|
||||
//show popup and die
|
||||
}
|
||||
|
||||
@@ -493,25 +464,25 @@ 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(TAG, "**PACK** - Path " + expansion_pack_path);
|
||||
|
||||
if (!f.exists()) {
|
||||
|
||||
pack_valid = false;
|
||||
Log.d("GODOT", "**PACK** - File does not exist");
|
||||
Log.d(TAG, "**PACK** - File does not exist");
|
||||
|
||||
} else if (obbIsCorrupted(expansion_pack_path, main_pack_md5)) {
|
||||
Log.d("GODOT", "**PACK** - Expansion pack (obb) is corrupted");
|
||||
Log.d(TAG, "**PACK** - Expansion pack (obb) is corrupted");
|
||||
pack_valid = false;
|
||||
try {
|
||||
f.delete();
|
||||
} catch (Exception e) {
|
||||
Log.d("GODOT", "**PACK** - Error deleting corrupted expansion pack (obb)");
|
||||
Log.d(TAG, "**PACK** - Error deleting corrupted expansion pack (obb)");
|
||||
}
|
||||
}
|
||||
|
||||
if (!pack_valid) {
|
||||
Log.d("GODOT", "Pack Invalid, try re-downloading.");
|
||||
Log.d(TAG, "Pack Invalid, try re-downloading.");
|
||||
|
||||
Intent notifierIntent = new Intent(this, this.getClass());
|
||||
notifierIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
|
||||
@@ -522,15 +493,15 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
|
||||
int startResult;
|
||||
try {
|
||||
Log.d("GODOT", "INITIALIZING DOWNLOAD");
|
||||
Log.d(TAG, "INITIALIZING DOWNLOAD");
|
||||
startResult = DownloaderClientMarshaller.startDownloadServiceIfRequired(
|
||||
getApplicationContext(),
|
||||
pendingIntent,
|
||||
GodotDownloaderService.class);
|
||||
Log.d("GODOT", "DOWNLOAD SERVICE FINISHED:" + startResult);
|
||||
Log.d(TAG, "DOWNLOAD SERVICE FINISHED:" + startResult);
|
||||
|
||||
if (startResult != DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED) {
|
||||
Log.d("GODOT", "DOWNLOAD REQUIRED");
|
||||
Log.d(TAG, "DOWNLOAD REQUIRED");
|
||||
// This is where you do set up to display the download
|
||||
// progress (next step)
|
||||
mDownloaderClientStub = DownloaderClientMarshaller.CreateStub(this,
|
||||
@@ -550,11 +521,10 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
|
||||
return;
|
||||
} else {
|
||||
Log.d("GODOT", "NO DOWNLOAD REQUIRED");
|
||||
Log.d(TAG, "NO DOWNLOAD REQUIRED");
|
||||
}
|
||||
} catch (NameNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
Log.d("GODOT", "Error downloading expansion package:" + e.getMessage());
|
||||
Log.w(TAG, "Error downloading expansion package:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -563,8 +533,6 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
mCurrentIntent = getIntent();
|
||||
|
||||
initializeGodot();
|
||||
|
||||
// instanceSingleton( new GodotFacebook(this) );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -645,11 +613,11 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
|
||||
float[] adjustedValues = new float[3];
|
||||
final int axisSwap[][] = {
|
||||
{ 1, -1, 0, 1 }, // ROTATION_0
|
||||
{ 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, 0, 1 }, // ROTATION_180
|
||||
{ 1, 1, 1, 0 } // ROTATION_270
|
||||
};
|
||||
|
||||
final int[] as = axisSwap[displayRotation];
|
||||
adjustedValues[0] = (float)as[0] * event.values[as[2]];
|
||||
@@ -680,22 +648,6 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
// Do something here if sensor accuracy changes.
|
||||
}
|
||||
|
||||
/*
|
||||
@Override public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
|
||||
if (event.getKeyCode()==KeyEvent.KEYCODE_BACK) {
|
||||
|
||||
System.out.printf("** BACK REQUEST!\n");
|
||||
|
||||
GodotLib.quit();
|
||||
return true;
|
||||
}
|
||||
System.out.printf("** OTHER KEY!\n");
|
||||
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
boolean shouldQuit = true;
|
||||
@@ -751,15 +703,14 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
}
|
||||
String md5str = hexString.toString();
|
||||
|
||||
//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.w(TAG, "Pack MD5 Mismatch - actual: " + md5str + " " + Integer.toString(md5str.length()) + " - 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.w(TAG, "Pack failed");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -781,36 +732,26 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
arr[i * 3 + 2] = (int)event.getY(i);
|
||||
}
|
||||
|
||||
//System.out.printf("gaction: %d\n",event.getAction());
|
||||
switch (event.getAction() & MotionEvent.ACTION_MASK) {
|
||||
|
||||
case MotionEvent.ACTION_DOWN: {
|
||||
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);
|
||||
//for(int i=0;i<event.getPointerCount();i++) {
|
||||
// System.out.printf("%d - moved to: %f,%f\n",i, event.getX(i),event.getY(i));
|
||||
//}
|
||||
} break;
|
||||
case MotionEvent.ACTION_POINTER_UP: {
|
||||
final int indexPointUp = event.getActionIndex();
|
||||
final int pointer_idx = event.getPointerId(indexPointUp);
|
||||
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);
|
||||
//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);
|
||||
//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;
|
||||
@@ -852,10 +793,6 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
return mPaymentsManager;
|
||||
}
|
||||
|
||||
// public void setPaymentsManager(PaymentsManager mPaymentsManager) {
|
||||
// this.mPaymentsManager = mPaymentsManager;
|
||||
// };
|
||||
|
||||
// Audio
|
||||
|
||||
/**
|
||||
@@ -865,7 +802,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
*/
|
||||
@Override
|
||||
public void onDownloadStateChanged(int newState) {
|
||||
Log.d("GODOT", "onDownloadStateChanged:" + newState);
|
||||
Log.d(TAG, "onDownloadStateChanged:" + newState);
|
||||
setState(newState);
|
||||
boolean showDashboard = true;
|
||||
boolean showCellMessage = false;
|
||||
@@ -873,7 +810,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
boolean indeterminate;
|
||||
switch (newState) {
|
||||
case IDownloaderClient.STATE_IDLE:
|
||||
Log.d("GODOT", "STATE IDLE");
|
||||
Log.d(TAG, "Download state changed to: STATE IDLE");
|
||||
// STATE_IDLE means the service is listening, so it's
|
||||
// safe to start making calls via mRemoteService.
|
||||
paused = false;
|
||||
@@ -881,13 +818,13 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
break;
|
||||
case IDownloaderClient.STATE_CONNECTING:
|
||||
case IDownloaderClient.STATE_FETCHING_URL:
|
||||
Log.d("GODOT", "STATE CONNECTION / FETCHING URL");
|
||||
Log.d(TAG, "Download state changed to: STATE CONNECTION / FETCHING URL");
|
||||
showDashboard = true;
|
||||
paused = false;
|
||||
indeterminate = true;
|
||||
break;
|
||||
case IDownloaderClient.STATE_DOWNLOADING:
|
||||
Log.d("GODOT", "STATE DOWNLOADING");
|
||||
Log.d(TAG, "Download state changed to: STATE DOWNLOADING");
|
||||
paused = false;
|
||||
showDashboard = true;
|
||||
indeterminate = false;
|
||||
@@ -897,14 +834,14 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
case IDownloaderClient.STATE_FAILED:
|
||||
case IDownloaderClient.STATE_FAILED_FETCHING_URL:
|
||||
case IDownloaderClient.STATE_FAILED_UNLICENSED:
|
||||
Log.d("GODOT", "MANY TYPES OF FAILING");
|
||||
Log.d(TAG, "Download state changed to: MANY TYPES OF FAILING");
|
||||
paused = true;
|
||||
showDashboard = false;
|
||||
indeterminate = false;
|
||||
break;
|
||||
case IDownloaderClient.STATE_PAUSED_NEED_CELLULAR_PERMISSION:
|
||||
case IDownloaderClient.STATE_PAUSED_WIFI_DISABLED_NEED_CELLULAR_PERMISSION:
|
||||
Log.d("GODOT", "PAUSED FOR SOME STUPID REASON");
|
||||
Log.d(TAG, "Download state changed to: PAUSED FOR NETWORK PERMISSION NEEDED");
|
||||
showDashboard = false;
|
||||
paused = true;
|
||||
indeterminate = false;
|
||||
@@ -912,26 +849,26 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
break;
|
||||
|
||||
case IDownloaderClient.STATE_PAUSED_BY_REQUEST:
|
||||
Log.d("GODOT", "PAUSED BY STUPID USER");
|
||||
Log.d(TAG, "Download state changed to: PAUSED BY USER");
|
||||
paused = true;
|
||||
indeterminate = false;
|
||||
break;
|
||||
case IDownloaderClient.STATE_PAUSED_ROAMING:
|
||||
case IDownloaderClient.STATE_PAUSED_SDCARD_UNAVAILABLE:
|
||||
Log.d("GODOT", "PAUSED BY ROAMING WTF!?");
|
||||
Log.d(TAG, "Download state changed to: PAUSED BY ROAMING");
|
||||
paused = true;
|
||||
indeterminate = false;
|
||||
break;
|
||||
case IDownloaderClient.STATE_COMPLETED:
|
||||
Log.d("GODOT", "COMPLETED");
|
||||
Log.d(TAG, "Download state changed to: COMPLETED");
|
||||
showDashboard = false;
|
||||
paused = false;
|
||||
indeterminate = false;
|
||||
// validateXAPKZipFiles();
|
||||
initializeGodot();
|
||||
return;
|
||||
default:
|
||||
Log.d("GODOT", "DEFAULT ????");
|
||||
Log.w(TAG, "Invalid download state");
|
||||
|
||||
paused = true;
|
||||
indeterminate = true;
|
||||
showDashboard = true;
|
||||
|
||||
@@ -45,15 +45,15 @@ import android.util.Log;
|
||||
* <receiver android:name=".GodotDownloaderAlarmReceiver"/>
|
||||
*/
|
||||
public class GodotDownloaderAlarmReceiver extends BroadcastReceiver {
|
||||
private static final String TAG = "GodotDownloaderAlarmReceiver";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.d("GODOT", "Alarma recivida");
|
||||
try {
|
||||
DownloaderClientMarshaller.startDownloadServiceIfRequired(context, intent, GodotDownloaderService.class);
|
||||
} catch (NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
Log.d("GODOT", "Exception: " + e.getClass().getName() + ":" + e.getMessage());
|
||||
Log.d(TAG, "Exception: " + e.getClass().getName() + ":" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,8 @@ import com.google.android.vending.expansion.downloader.impl.DownloaderService;
|
||||
* DownloaderService from the Downloader library.
|
||||
*/
|
||||
public class GodotDownloaderService extends DownloaderService {
|
||||
private static final String TAG = "GodotDownloaderService";
|
||||
|
||||
// stuff for LVL -- MODIFY FOR YOUR APPLICATION!
|
||||
private static final String BASE64_PUBLIC_KEY = "REPLACE THIS WITH YOUR PUBLIC KEY";
|
||||
// used by the preference obfuscater
|
||||
@@ -55,10 +57,8 @@ public class GodotDownloaderService extends DownloaderService {
|
||||
@Override
|
||||
public String getPublicKey() {
|
||||
SharedPreferences prefs = getApplicationContext().getSharedPreferences("app_data_keys", Context.MODE_PRIVATE);
|
||||
Log.d("GODOT", "getting public key:" + prefs.getString("store_public_key", null));
|
||||
Log.d(TAG, "getting public key:" + prefs.getString("store_public_key", null));
|
||||
return prefs.getString("store_public_key", null);
|
||||
|
||||
// return BASE64_PUBLIC_KEY;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +78,7 @@ public class GodotDownloaderService extends DownloaderService {
|
||||
*/
|
||||
@Override
|
||||
public String getAlarmReceiverClassName() {
|
||||
Log.d("GODOT", "getAlarmReceiverClassName()");
|
||||
Log.d(TAG, "getAlarmReceiverClassName()");
|
||||
return GodotDownloaderAlarmReceiver.class.getName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,8 @@ import org.godotengine.godot.input.*;
|
||||
|
||||
public class GodotIO {
|
||||
|
||||
private static String TAG = "GodotIO";
|
||||
|
||||
AssetManager am;
|
||||
Godot activity;
|
||||
GodotEditText edit;
|
||||
@@ -103,7 +105,7 @@ public class GodotIO {
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
//System.out.printf("Exception on file_open: %s\n",path);
|
||||
// Cannot open file
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -111,7 +113,7 @@ public class GodotIO {
|
||||
ad.len = ad.is.available();
|
||||
} catch (Exception e) {
|
||||
|
||||
System.out.printf("Exception availabling on file_open: %s\n", path);
|
||||
Log.w(TAG, "Exception availabling on file_open: " + path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -125,7 +127,8 @@ public class GodotIO {
|
||||
public int file_get_size(int id) {
|
||||
|
||||
if (!streams.containsKey(id)) {
|
||||
System.out.printf("file_get_size: Invalid file id: %d\n", id);
|
||||
|
||||
Log.w(TAG, "file_get_size: Invalid file id: " + id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -134,10 +137,12 @@ public class GodotIO {
|
||||
public void file_seek(int id, int bytes) {
|
||||
|
||||
if (!streams.containsKey(id)) {
|
||||
System.out.printf("file_get_size: Invalid file id: %d\n", id);
|
||||
|
||||
Log.w(TAG, "file_get_size: Invalid file id: " + id);
|
||||
return;
|
||||
}
|
||||
//seek sucks
|
||||
|
||||
// More efficient than "seek" built-in function
|
||||
AssetData ad = streams.get(id);
|
||||
if (bytes > ad.len)
|
||||
bytes = ad.len;
|
||||
@@ -166,7 +171,7 @@ public class GodotIO {
|
||||
ad.eof = false;
|
||||
} catch (IOException e) {
|
||||
|
||||
System.out.printf("Exception on file_seek: %s\n", e);
|
||||
Log.w(TAG, "Exception on file_seek: " + e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -174,7 +179,8 @@ public class GodotIO {
|
||||
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);
|
||||
|
||||
Log.w(TAG, "file_read: Can't tell eof for invalid file id: " + id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -184,7 +190,8 @@ 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);
|
||||
|
||||
Log.w(TAG, "file_read: Can't check eof for invalid file id: " + id);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -195,7 +202,8 @@ 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);
|
||||
|
||||
Log.w(TAG, "file_read: Can't read invalid file id: " + id);
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
@@ -218,7 +226,7 @@ public class GodotIO {
|
||||
r = ad.is.read(buf1);
|
||||
} catch (IOException e) {
|
||||
|
||||
System.out.printf("Exception on file_read: %s\n", e);
|
||||
Log.w(TAG, "Exception on file_read: " + e);
|
||||
return new byte[bytes];
|
||||
}
|
||||
|
||||
@@ -243,7 +251,8 @@ public class GodotIO {
|
||||
public void file_close(int id) {
|
||||
|
||||
if (!streams.containsKey(id)) {
|
||||
System.out.printf("file_close: Can't close invalid file id: %d\n", id);
|
||||
|
||||
Log.w(TAG, "file_close: Can't close invalid file id: " + id);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -280,7 +289,7 @@ public class GodotIO {
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
System.out.printf("Exception on dir_open: %s\n", e);
|
||||
Log.w(TAG, "Exception on dir_open: " + e);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -293,7 +302,7 @@ public class GodotIO {
|
||||
|
||||
public boolean dir_is_dir(int id) {
|
||||
if (!dirs.containsKey(id)) {
|
||||
System.out.printf("dir_next: invalid dir id: %d\n", id);
|
||||
Log.w(TAG, "dir_next: invalid dir id: " + id);
|
||||
return false;
|
||||
}
|
||||
AssetDir ad = dirs.get(id);
|
||||
@@ -320,7 +329,8 @@ public class GodotIO {
|
||||
public String dir_next(int id) {
|
||||
|
||||
if (!dirs.containsKey(id)) {
|
||||
System.out.printf("dir_next: invalid dir id: %d\n", id);
|
||||
|
||||
Log.w(TAG, "dir_next: invalid dir id: " + id);
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -339,7 +349,8 @@ public class GodotIO {
|
||||
public void dir_close(int id) {
|
||||
|
||||
if (!dirs.containsKey(id)) {
|
||||
System.out.printf("dir_close: invalid dir id: %d\n", id);
|
||||
|
||||
Log.w(TAG, "dir_next: invalid dir id: " + id);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -368,9 +379,7 @@ public class GodotIO {
|
||||
int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
|
||||
int frameSize = 4;
|
||||
|
||||
System.out.printf("audioInit: initializing audio:\n");
|
||||
|
||||
//Log.v("Godot", "Godot audio: wanted " + (isStereo ? "stereo" : "mono") + " " + (is16Bit ? "16-bit" : "8-bit") + " " + ((float)sampleRate / 1000f) + "kHz, " + desiredFrames + " frames buffer");
|
||||
Log.d(TAG, "audioInit: initializing audio: ");
|
||||
|
||||
// Let the user pick a larger buffer if they really want -- but ye
|
||||
// gods they probably shouldn't, the minimums are horrifyingly high
|
||||
@@ -396,7 +405,7 @@ public class GodotIO {
|
||||
}
|
||||
});
|
||||
|
||||
// I'd take REALTIME if I could get it!
|
||||
// Max priority
|
||||
mAudioThread.setPriority(Thread.MAX_PRIORITY);
|
||||
mAudioThread.start();
|
||||
}
|
||||
@@ -410,10 +419,10 @@ public class GodotIO {
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
// Nom nom
|
||||
// Action interrupted, nothing to do
|
||||
}
|
||||
} else {
|
||||
Log.w("Godot", "Godot audio: error return from write(short)");
|
||||
Log.w(TAG, "Godot audio: error return from write(short)");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -424,11 +433,10 @@ public class GodotIO {
|
||||
try {
|
||||
mAudioThread.join();
|
||||
} catch (Exception e) {
|
||||
Log.v("Godot", "Problem stopping audio thread: " + e);
|
||||
Log.v(TAG, "Problem stopping audio thread: " + e);
|
||||
}
|
||||
mAudioThread = null;
|
||||
|
||||
//Log.v("Godot", "Finished waiting for audio thread");
|
||||
}
|
||||
|
||||
if (mAudioTrack != null) {
|
||||
@@ -452,11 +460,11 @@ public class GodotIO {
|
||||
public int openURI(String p_uri) {
|
||||
|
||||
try {
|
||||
Log.v("MyApp", "TRYING TO OPEN URI: " + p_uri);
|
||||
Log.v(TAG, "Trying to open uri: " + p_uri);
|
||||
String path = p_uri;
|
||||
String type = "";
|
||||
if (path.startsWith("/")) {
|
||||
//absolute path to filesystem, prepend file://
|
||||
// Absolute path to filesystem, prepend file://
|
||||
path = "file://" + path;
|
||||
if (p_uri.endsWith(".png") || p_uri.endsWith(".jpg") || p_uri.endsWith(".gif") || p_uri.endsWith(".webp")) {
|
||||
|
||||
@@ -508,8 +516,6 @@ public class GodotIO {
|
||||
if (edit != null)
|
||||
edit.showKeyboard(p_existing_text);
|
||||
|
||||
//InputMethodManager inputMgr = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
//inputMgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
|
||||
};
|
||||
|
||||
public void hideKeyboard() {
|
||||
@@ -567,7 +573,7 @@ public class GodotIO {
|
||||
mediaPlayer.prepare();
|
||||
mediaPlayer.start();
|
||||
} catch (IOException e) {
|
||||
System.out.println("IOError while playing video");
|
||||
Log.w(TAG, "IOError while playing video");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -605,7 +611,6 @@ public class GodotIO {
|
||||
String what = "";
|
||||
switch (idx) {
|
||||
case SYSTEM_DIR_DESKTOP: {
|
||||
//what=Environment.DIRECTORY_DOCUMENTS;
|
||||
what = Environment.DIRECTORY_DOWNLOADS;
|
||||
} break;
|
||||
case SYSTEM_DIR_DCIM: {
|
||||
@@ -614,7 +619,6 @@ public class GodotIO {
|
||||
} break;
|
||||
case SYSTEM_DIR_DOCUMENTS: {
|
||||
what = Environment.DIRECTORY_DOWNLOADS;
|
||||
//what=Environment.DIRECTORY_DOCUMENTS;
|
||||
} break;
|
||||
case SYSTEM_DIR_DOWNLOADS: {
|
||||
what = Environment.DIRECTORY_DOWNLOADS;
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
package org.godotengine.godot;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.util.Log;
|
||||
|
||||
import org.godotengine.godot.payments.PaymentsManager;
|
||||
import org.json.JSONException;
|
||||
@@ -92,7 +91,6 @@ public class GodotPaymentV3 extends Godot.SingletonBase {
|
||||
}
|
||||
|
||||
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 });
|
||||
}
|
||||
|
||||
|
||||
@@ -278,7 +278,6 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
};
|
||||
|
||||
int source = event.getSource();
|
||||
//Log.e(TAG, String.format("Key down! source %d, device %d, joystick %d, %d, %d", event.getDeviceId(), source, (source & InputDevice.SOURCE_JOYSTICK), (source & InputDevice.SOURCE_DPAD), (source & InputDevice.SOURCE_GAMEPAD)));
|
||||
|
||||
if ((source & InputDevice.SOURCE_JOYSTICK) != 0 || (source & InputDevice.SOURCE_DPAD) != 0 || (source & InputDevice.SOURCE_GAMEPAD) != 0) {
|
||||
|
||||
@@ -287,8 +286,6 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
int button = get_godot_button(keyCode);
|
||||
int device = find_joy_device(event.getDeviceId());
|
||||
|
||||
//Log.e(TAG, String.format("joy button down! button %x, %d, device %d", keyCode, button, device));
|
||||
|
||||
GodotLib.joybutton(device, button, true);
|
||||
return true;
|
||||
|
||||
@@ -309,14 +306,12 @@ 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;
|
||||
//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) {
|
||||
int hatX = Math.round(event.getAxisValue(joy.hats.get(i).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);
|
||||
}
|
||||
return true;
|
||||
@@ -598,7 +593,6 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
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)
|
||||
;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,6 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
|
||||
|
||||
@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++) {
|
||||
GodotLib.key(KeyEvent.KEYCODE_DEL, 0, true);
|
||||
@@ -95,7 +94,6 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
|
||||
|
||||
@Override
|
||||
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++) {
|
||||
int ch = pCharSequence.charAt(i);
|
||||
@@ -111,11 +109,6 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
|
||||
for (int i = this.mOriginText.length(); i > 0; i--) {
|
||||
GodotLib.key(KeyEvent.KEYCODE_DEL, 0, true);
|
||||
GodotLib.key(KeyEvent.KEYCODE_DEL, 0, false);
|
||||
/*
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.d(TAG, "deleteBackward");
|
||||
}
|
||||
*/
|
||||
}
|
||||
String text = pTextView.getText().toString();
|
||||
|
||||
@@ -133,11 +126,6 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
|
||||
GodotLib.key(0, ch, true);
|
||||
GodotLib.key(0, ch, false);
|
||||
}
|
||||
/*
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.d(TAG, "insertText(" + insertText + ")");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
if (pActionID == EditorInfo.IME_ACTION_DONE) {
|
||||
@@ -145,12 +133,4 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===========================================================
|
||||
// Methods
|
||||
// ===========================================================
|
||||
|
||||
// ===========================================================
|
||||
// Inner and Anonymous Classes
|
||||
// ===========================================================
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.util.Map;
|
||||
import java.util.Queue;
|
||||
|
||||
public class InputManagerV9 implements InputManagerCompat {
|
||||
private static final String LOG_TAG = "InputManagerV9";
|
||||
private static final String TAG = "InputManagerV9";
|
||||
private static final int MESSAGE_TEST_FOR_DISCONNECT = 101;
|
||||
private static final long CHECK_ELAPSED_TIME = 3000L;
|
||||
|
||||
@@ -175,7 +175,7 @@ public class InputManagerV9 implements InputManagerCompat {
|
||||
mListener.onInputDeviceRemoved(mId);
|
||||
break;
|
||||
default:
|
||||
Log.e(LOG_TAG, "Unknown Message Type");
|
||||
Log.e(TAG, "Unknown Message Type");
|
||||
break;
|
||||
}
|
||||
// dump this runnable back in the queue
|
||||
|
||||
@@ -47,19 +47,15 @@ abstract public class ConsumeTask {
|
||||
}
|
||||
|
||||
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);
|
||||
// Consuming product, nothing to do
|
||||
} else if (!isBlocked) {
|
||||
// Log.d("XXX", "It is not blocked ¿?");
|
||||
return;
|
||||
} else if (_token == null) {
|
||||
// Log.d("XXX", "No token available");
|
||||
// Token is not available
|
||||
this.error("No token for sku:" + sku);
|
||||
return;
|
||||
}
|
||||
@@ -69,9 +65,8 @@ abstract public class ConsumeTask {
|
||||
@Override
|
||||
protected String doInBackground(String... params) {
|
||||
try {
|
||||
// Log.d("XXX", "Requesting to release item.");
|
||||
// Requesting to release item
|
||||
int response = mService.consumePurchase(3, context.getPackageName(), token);
|
||||
// Log.d("XXX", "release response code: " + response);
|
||||
if (response == 0 || response == 8) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
abstract public class GenericConsumeTask extends AsyncTask<String, String, String> {
|
||||
|
||||
private static String TAG = "GenericConsumeTask";
|
||||
private Context context;
|
||||
private IInAppBillingService mService;
|
||||
|
||||
@@ -58,14 +58,12 @@ 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);
|
||||
int response = mService.consumePurchase(3, context.getPackageName(), token);
|
||||
// Log.d("godot", "consumePurchase response: " + response);
|
||||
if (response == 0 || response == 8) {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.d("godot", "Error " + e.getClass().getName() + ":" + e.getMessage());
|
||||
Log.d(TAG, "Error " + e.getClass().getName() + ":" + e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -56,28 +56,16 @@ abstract public class HandlePurchaseTask {
|
||||
}
|
||||
|
||||
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);
|
||||
String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");
|
||||
//Log.d("XXX", "Purchase signature:" + dataSignature);
|
||||
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
|
||||
try {
|
||||
// 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 productId = jo.getString("productId");
|
||||
// Long purchaseTime = jo.getLong("purchaseTime");
|
||||
// Integer state = jo.getInt("purchaseState");
|
||||
String developerPayload = jo.getString("developerPayload");
|
||||
String purchaseToken = jo.getString("purchaseToken");
|
||||
|
||||
@@ -85,7 +73,7 @@ abstract public class HandlePurchaseTask {
|
||||
error("Untrusted callback");
|
||||
return;
|
||||
}
|
||||
// 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);
|
||||
|
||||
@@ -58,14 +58,12 @@ public class PaymentsCache {
|
||||
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);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public String getConsumableValue(String set, String sku) {
|
||||
SharedPreferences sharedPref = context.getSharedPreferences(
|
||||
"consumables_" + set, Context.MODE_PRIVATE);
|
||||
// Log.d("XXX", "Getting asset: consumables_" + set + ":" + sku);
|
||||
return sharedPref.getString(sku, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ import java.util.Arrays;
|
||||
|
||||
public class PaymentsManager {
|
||||
|
||||
private static String TAG = "PaymentsManager";
|
||||
public static final int BILLING_RESPONSE_RESULT_OK = 0;
|
||||
public static final int REQUEST_CODE_FOR_PURCHASE = 0x1001;
|
||||
private static boolean auto_consume = true;
|
||||
@@ -146,13 +147,13 @@ public class PaymentsManager {
|
||||
|
||||
@Override
|
||||
protected void error(String message) {
|
||||
Log.d("godot", "consumeUnconsumedPurchases :" + message);
|
||||
Log.d(TAG, "consumeUnconsumedPurchases :" + message);
|
||||
godotPaymentV3.callbackFailConsume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void notRequired() {
|
||||
Log.d("godot", "callbackSuccessNoUnconsumedPurchases :");
|
||||
Log.d(TAG, "callbackSuccessNoUnconsumedPurchases :");
|
||||
godotPaymentV3.callbackSuccessNoUnconsumedPurchases();
|
||||
}
|
||||
}
|
||||
@@ -198,10 +199,10 @@ public class PaymentsManager {
|
||||
}
|
||||
}
|
||||
continueToken = bundle.getString("INAPP_CONTINUATION_TOKEN");
|
||||
Log.d("godot", "continue token = " + continueToken);
|
||||
Log.d(TAG, "continue token = " + continueToken);
|
||||
} while (!TextUtils.isEmpty(continueToken));
|
||||
} catch (Exception e) {
|
||||
Log.d("godot", "Error requesting purchased products:" + e.getClass().getName() + ":" + e.getMessage());
|
||||
Log.d(TAG, "Error requesting purchased products:" + e.getClass().getName() + ":" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,7 +409,7 @@ public class PaymentsManager {
|
||||
ArrayList<String> responseList = skuDetails.getStringArrayList("DETAILS_LIST");
|
||||
|
||||
for (String thisResponse : responseList) {
|
||||
Log.d("godot", "response = " + thisResponse);
|
||||
Log.d(TAG, "response = " + thisResponse);
|
||||
godotPaymentV3.addSkuDetail(thisResponse);
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
|
||||
@@ -49,6 +49,8 @@ import android.util.Log;
|
||||
|
||||
abstract public class PurchaseTask {
|
||||
|
||||
private static String TAG = "PurchaseTask";
|
||||
|
||||
private Activity context;
|
||||
|
||||
private IInAppBillingService mService;
|
||||
@@ -60,21 +62,16 @@ abstract public class PurchaseTask {
|
||||
private boolean isLooping = false;
|
||||
|
||||
public void purchase(final String sku, final String transactionId) {
|
||||
Log.d("XXX", "Starting purchase for: " + sku);
|
||||
Log.d(TAG, "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;
|
||||
// }
|
||||
|
||||
final String hash = transactionId;
|
||||
|
||||
Bundle buyIntentBundle;
|
||||
try {
|
||||
buyIntentBundle = mService.getBuyIntent(3, context.getApplicationContext().getPackageName(), sku, "inapp", hash);
|
||||
} catch (RemoteException e) {
|
||||
// Log.d("XXX", "Error: " + e.getMessage());
|
||||
error(e.getMessage());
|
||||
return;
|
||||
}
|
||||
@@ -87,7 +84,7 @@ abstract public class PurchaseTask {
|
||||
} 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) {
|
||||
canceled();
|
||||
return;
|
||||
@@ -100,13 +97,6 @@ abstract public class PurchaseTask {
|
||||
PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
|
||||
pc.setConsumableValue("validation_hash", sku, hash);
|
||||
try {
|
||||
if (context == null) {
|
||||
// Log.d("XXX", "No context!");
|
||||
}
|
||||
if (pendingIntent == null) {
|
||||
// Log.d("XXX", "No pending intent");
|
||||
}
|
||||
// Log.d("XXX", "Starting activity for purchase!");
|
||||
context.startIntentSenderForResult(
|
||||
pendingIntent.getIntentSender(),
|
||||
PaymentsManager.REQUEST_CODE_FOR_PURCHASE,
|
||||
|
||||
@@ -46,6 +46,7 @@ import android.util.Log;
|
||||
|
||||
abstract public class ReleaseAllConsumablesTask {
|
||||
|
||||
private static final String TAG = "ReleaseAllConsumablesTask";
|
||||
private Context context;
|
||||
private IInAppBillingService mService;
|
||||
|
||||
@@ -56,13 +57,12 @@ abstract public class ReleaseAllConsumablesTask {
|
||||
|
||||
public void consumeItAll() {
|
||||
try {
|
||||
// Log.d("godot", "consumeItall for " + context.getPackageName());
|
||||
Bundle bundle = mService.getPurchases(3, context.getPackageName(), "inapp", null);
|
||||
|
||||
// TODO:
|
||||
// Check if this loop is useful and remove it if not
|
||||
for (String key : bundle.keySet()) {
|
||||
Object value = bundle.get(key);
|
||||
// Log.d("godot", String.format("%s %s (%s)", key,
|
||||
// value.toString(), value.getClass().getName()));
|
||||
}
|
||||
|
||||
if (bundle.getInt("RESPONSE_CODE") == 0) {
|
||||
@@ -71,12 +71,10 @@ abstract public class ReleaseAllConsumablesTask {
|
||||
final ArrayList<String> mySignatures = bundle.getStringArrayList("INAPP_DATA_SIGNATURE_LIST");
|
||||
|
||||
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++) {
|
||||
|
||||
try {
|
||||
@@ -85,7 +83,6 @@ abstract public class ReleaseAllConsumablesTask {
|
||||
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) {
|
||||
|
||||
@Override
|
||||
@@ -100,7 +97,7 @@ abstract public class ReleaseAllConsumablesTask {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.d("godot", "Error releasing products:" + e.getClass().getName() + ":" + e.getMessage());
|
||||
Log.d(TAG, "Error releasing products:" + e.getClass().getName() + ":" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -79,14 +79,9 @@ 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);
|
||||
param.put("package", context.getApplicationContext().getPackageName());
|
||||
HttpRequester requester = new HttpRequester();
|
||||
String jsonResponse = requester.post(param);
|
||||
// Log.d("XXX", "Validation response:\n"+jsonResponse);
|
||||
return jsonResponse;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,17 +73,19 @@ import android.util.Log;
|
||||
*/
|
||||
public class HttpRequester {
|
||||
|
||||
private static String TAG = "HttpRequester";
|
||||
|
||||
private Context context;
|
||||
private static final int TTL = 600000; // 10 minutos
|
||||
private static final int TTL = 600000; // 10 minutes
|
||||
private long cttl = 0;
|
||||
|
||||
public HttpRequester() {
|
||||
// Log.d("XXX", "Creando http request sin contexto");
|
||||
// Creating a HTTP request without context, nothing to do
|
||||
}
|
||||
|
||||
public HttpRequester(Context context) {
|
||||
// Creating a HTTP request with context
|
||||
this.context = context;
|
||||
// Log.d("XXX", "Creando http request con contexto");
|
||||
}
|
||||
|
||||
public String post(RequestParams params) {
|
||||
@@ -99,7 +101,7 @@ public class HttpRequester {
|
||||
public String get(RequestParams params) {
|
||||
String response = getResponseFromCache(params.getUrl());
|
||||
if (response == null) {
|
||||
// Log.d("XXX", "Cache miss!");
|
||||
// Cache miss, trying to get data
|
||||
HttpGet httpget = new HttpGet(params.getUrl());
|
||||
long timeInit = new Date().getTime();
|
||||
response = request(httpget);
|
||||
@@ -111,14 +113,13 @@ public class HttpRequester {
|
||||
saveResponseIntoCache(params.getUrl(), response);
|
||||
}
|
||||
}
|
||||
Log.d("XXX", "Req: " + params.getUrl());
|
||||
Log.d("XXX", "Resp: " + response);
|
||||
Log.d(TAG, "Req: " + params.getUrl());
|
||||
Log.d(TAG, "Resp: " + response);
|
||||
return response;
|
||||
}
|
||||
|
||||
private String request(HttpUriRequest request) {
|
||||
// Log.d("XXX", "Haciendo request a: " + request.getURI() );
|
||||
Log.d("PPP", "Haciendo request a: " + request.getURI());
|
||||
Log.d(TAG, "Sending request to uri: " + request.getURI());
|
||||
long init = new Date().getTime();
|
||||
HttpClient httpclient = getNewHttpClient();
|
||||
HttpParams httpParameters = httpclient.getParams();
|
||||
@@ -127,21 +128,19 @@ 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());
|
||||
Log.d(TAG, "Fin de request (" + (new Date().getTime() - init) + ") a: " + request.getURI());
|
||||
if (response.getStatusLine().getStatusCode() == 200) {
|
||||
String strResponse = EntityUtils.toString(response.getEntity());
|
||||
// Log.d("XXX2", strResponse);
|
||||
return strResponse;
|
||||
} else {
|
||||
Log.d("XXX3", "Response status code:" + response.getStatusLine().getStatusCode() + "\n" + EntityUtils.toString(response.getEntity()));
|
||||
Log.d(TAG, "Response status code:" + response.getStatusLine().getStatusCode() + "\n" + EntityUtils.toString(response.getEntity()));
|
||||
return null;
|
||||
}
|
||||
|
||||
} catch (ClientProtocolException e) {
|
||||
Log.d("XXX3", e.getMessage());
|
||||
Log.d(TAG, e.getMessage());
|
||||
} catch (IOException e) {
|
||||
Log.d("XXX4", e.getMessage());
|
||||
Log.d(TAG, e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -192,7 +191,6 @@ public class HttpRequester {
|
||||
|
||||
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);
|
||||
@@ -204,13 +202,13 @@ public class HttpRequester {
|
||||
|
||||
public String getResponseFromCache(String request) {
|
||||
if (context == null) {
|
||||
Log.d("XXX", "No context, cache miss");
|
||||
Log.d(TAG, "No context, cache miss");
|
||||
return null;
|
||||
}
|
||||
SharedPreferences sharedPref = context.getSharedPreferences("http_get_cache", Context.MODE_PRIVATE);
|
||||
long ttl = getResponseTtl(request);
|
||||
if (ttl == 0l || (new Date().getTime() - ttl) > 0l) {
|
||||
Log.d("XXX", "Cache invalid ttl:" + ttl + " vs now:" + new Date().getTime());
|
||||
Log.d(TAG, "Cache invalid ttl:" + ttl + " vs now:" + new Date().getTime());
|
||||
return null;
|
||||
}
|
||||
return sharedPref.getString("request_" + Crypt.md5(request), null);
|
||||
|
||||
Reference in New Issue
Block a user