diff options
Diffstat (limited to 'platform/android/java/src/com')
7 files changed, 182 insertions, 50 deletions
| diff --git a/platform/android/java/src/com/android/godot/Godot.java b/platform/android/java/src/com/android/godot/Godot.java index 9b9b1ab2ad..4c5a313576 100644 --- a/platform/android/java/src/com/android/godot/Godot.java +++ b/platform/android/java/src/com/android/godot/Godot.java @@ -357,7 +357,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC  		        Log.d("GODOT","   " + command_line[w]);  		    }  		}*/ -		GodotLib.initialize(this,io.needsReloadHooks(),command_line); +		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); diff --git a/platform/android/java/src/com/android/godot/GodotIO.java b/platform/android/java/src/com/android/godot/GodotIO.java index addceb1528..a7dc0c2f75 100644 --- a/platform/android/java/src/com/android/godot/GodotIO.java +++ b/platform/android/java/src/com/android/godot/GodotIO.java @@ -94,6 +94,7 @@ public class GodotIO {  		//System.out.printf("file_open: Attempt to Open %s\n",path); +		//Log.v("MyApp", "TRYING TO OPEN FILE: " + path);  		if (write)  			return -1; @@ -105,7 +106,7 @@ public class GodotIO {  		} catch (Exception e) { -			//System.out.printf("Exception on file_open: %s\n",e); +			//System.out.printf("Exception on file_open: %s\n",path);  			return -1;  		} @@ -113,7 +114,7 @@ public class GodotIO {  			ad.len=ad.is.available();  		} catch (Exception e) { -			System.out.printf("Exception availabling on file_open: %s\n",e); +			System.out.printf("Exception availabling on file_open: %s\n",path);  			return -1;  		} diff --git a/platform/android/java/src/com/android/godot/GodotLib.java b/platform/android/java/src/com/android/godot/GodotLib.java index 71c31e9f83..3d870b3b1f 100644 --- a/platform/android/java/src/com/android/godot/GodotLib.java +++ b/platform/android/java/src/com/android/godot/GodotLib.java @@ -44,9 +44,9 @@ public class GodotLib {       * @param height the current view height       */ -     public static native void initialize(Godot p_instance,boolean need_reload_hook,String[] p_cmdline); +     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(); +     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); diff --git a/platform/android/java/src/com/android/godot/GodotPaymentV3.java b/platform/android/java/src/com/android/godot/GodotPaymentV3.java index 0fd102ac55..0799e1e83d 100644 --- a/platform/android/java/src/com/android/godot/GodotPaymentV3.java +++ b/platform/android/java/src/com/android/godot/GodotPaymentV3.java @@ -27,7 +27,7 @@ public class GodotPaymentV3 extends Godot.SingletonBase {  				activity.getPaymentsManager().requestPurchase(sku, transactionId);				  			}  		}); -	}; +	}  /*	public string requestPurchasedTicket(){  	    activity.getPaymentsManager() @@ -42,7 +42,7 @@ public class GodotPaymentV3 extends Godot.SingletonBase {  	public GodotPaymentV3(Activity p_activity) { -		registerClass("GodotPayments", new String[] {"purchase", "setPurchaseCallbackId", "setPurchaseValidationUrlPrefix", "setTransactionId", "getSignature", "consumeUnconsumedPurchases"}); +		registerClass("GodotPayments", new String[] {"purchase", "setPurchaseCallbackId", "setPurchaseValidationUrlPrefix", "setTransactionId", "getSignature", "consumeUnconsumedPurchases", "requestPurchased", "setAutoConsume", "consume"});  		activity=(Godot) p_activity;  	} @@ -54,7 +54,6 @@ public class GodotPaymentV3 extends Godot.SingletonBase {  				activity.getPaymentsManager().consumeUnconsumedPurchases();				  			}  		}); -		  	}  	private String signature; @@ -63,25 +62,26 @@ public class GodotPaymentV3 extends Godot.SingletonBase {  	} -	public void callbackSuccess(String ticket, String signature){ -//        Log.d(this.getClass().getName(), "PRE-Send callback to purchase success"); -        GodotLib.callobject(purchaseCallbackId, "purchase_success", new Object[]{ticket, signature}); -//    	Log.d(this.getClass().getName(), "POST-Send callback to purchase success"); +	public void callbackSuccess(String ticket, String signature, String sku){ +//		Log.d(this.getClass().getName(), "PRE-Send callback to purchase success"); +		GodotLib.callobject(purchaseCallbackId, "purchase_success", new Object[]{ticket, signature, sku}); +//		Log.d(this.getClass().getName(), "POST-Send callback to purchase success");  }  	public void callbackSuccessProductMassConsumed(String ticket, String signature, String sku){ -//        Log.d(this.getClass().getName(), "PRE-Send callback to consume success"); -        GodotLib.calldeferred(purchaseCallbackId, "consume_success", new Object[]{ticket, signature, sku}); -//    	Log.d(this.getClass().getName(), "POST-Send callback to consume success"); +//		Log.d(this.getClass().getName(), "PRE-Send callback to consume success"); +		Log.d(this.getClass().getName(), "callbackSuccessProductMassConsumed > "+ticket+","+signature+","+sku); +        	GodotLib.calldeferred(purchaseCallbackId, "consume_success", new Object[]{ticket, signature, sku}); +//		Log.d(this.getClass().getName(), "POST-Send callback to consume success");  	}  	public void callbackSuccessNoUnconsumedPurchases(){ -        GodotLib.calldeferred(purchaseCallbackId, "no_validation_required", new Object[]{}); +		GodotLib.calldeferred(purchaseCallbackId, "no_validation_required", new Object[]{});  	}  	public void callbackFail(){ -                GodotLib.calldeferred(purchaseCallbackId, "purchase_fail", new Object[]{}); -//                GodotLib.callobject(purchaseCallbackId, "purchase_fail", new Object[]{}); +		GodotLib.calldeferred(purchaseCallbackId, "purchase_fail", new Object[]{}); +//		GodotLib.callobject(purchaseCallbackId, "purchase_fail", new Object[]{});  	}  	public void callbackCancel(){ @@ -89,6 +89,10 @@ public class GodotPaymentV3 extends Godot.SingletonBase {  //		GodotLib.callobject(purchaseCallbackId, "purchase_cancel", new Object[]{});  	} +	public void callbackAlreadyOwned(String sku){ +		GodotLib.calldeferred(purchaseCallbackId, "purchase_owned", new Object[]{sku}); +	} +	  	public int getPurchaseCallbackId() {  		return purchaseCallbackId;  	} @@ -97,8 +101,6 @@ public class GodotPaymentV3 extends Godot.SingletonBase {  		this.purchaseCallbackId = purchaseCallbackId;  	} - -  	public String getPurchaseValidationUrlPrefix(){  		return this.purchaseValidationUrlPrefix ;  	} @@ -107,12 +109,10 @@ public class GodotPaymentV3 extends Godot.SingletonBase {  		this.purchaseValidationUrlPrefix = url;  	} -  	public String getAccessToken() {  		return accessToken;  	} -  	public void setAccessToken(String accessToken) {  		this.accessToken = accessToken;  	} @@ -125,4 +125,30 @@ public class GodotPaymentV3 extends Godot.SingletonBase {  		return this.transactionId;  	} +	// request purchased items are not consumed +	public void requestPurchased(){ +		activity.getPaymentsManager().setBaseSingleton(this); +		activity.runOnUiThread(new Runnable() { +			@Override +			public void run() { +				activity.getPaymentsManager().requestPurchased();				 +			} +		}); +	} +	 +	// callback for requestPurchased() +	public void callbackPurchased(String receipt, String signature, String sku){ +		GodotLib.calldeferred(purchaseCallbackId, "has_purchased", new Object[]{receipt, signature, sku}); +	} +	 +	// consume item automatically after purchase. default is true. +	public void setAutoConsume(boolean autoConsume){ +		activity.getPaymentsManager().setAutoConsume(autoConsume); +	} +	 +	// consume a specific item +	public void consume(String sku){ +		activity.getPaymentsManager().consume(sku); +	}  } + diff --git a/platform/android/java/src/com/android/godot/GodotView.java b/platform/android/java/src/com/android/godot/GodotView.java index ad0354e624..bc249d46c6 100644 --- a/platform/android/java/src/com/android/godot/GodotView.java +++ b/platform/android/java/src/com/android/godot/GodotView.java @@ -371,8 +371,8 @@ public class GodotView extends GLSurfaceView {  		if (use_32) {  			setEGLConfigChooser( translucent ? -						new ConfigChooser(8, 8, 8, 8, 24, stencil) : -						new ConfigChooser(8, 8, 8, 8, 24, stencil) ); +						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)) );  		} else {  			setEGLConfigChooser( translucent ? @@ -410,6 +410,26 @@ public class GodotView extends GLSurfaceView {  	    Log.e(TAG, String.format("%s: EGL error: 0x%x", prompt, error));  	}      } +    	/* Fallback if 32bit View is not supported*/ +	private static class FallbackConfigChooser extends ConfigChooser { +		private ConfigChooser fallback; +		 +		public FallbackConfigChooser(int r, int g, int b, int a, int depth, int stencil, ConfigChooser fallback) { +			super(r, g, b, a, depth, stencil); +			this.fallback = fallback; +		} +       +      		@Override +		public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display, EGLConfig[] configs) { +			EGLConfig ec = super.chooseConfig(egl, display, configs); +			if (ec == null) { +	  			Log.w(TAG, "Trying ConfigChooser fallback"); +	  			ec = fallback.chooseConfig(egl, display, configs); +				use_32=false; +			} +			return ec; +      		} +    	}  	private static class ConfigChooser implements GLSurfaceView.EGLConfigChooser { @@ -635,7 +655,7 @@ public class GodotView extends GLSurfaceView {  		}  		public void onSurfaceCreated(GL10 gl, EGLConfig config) { -			GodotLib.newcontext(); +			GodotLib.newcontext(use_32);  		}  	}  } diff --git a/platform/android/java/src/com/android/godot/payments/PaymentsManager.java b/platform/android/java/src/com/android/godot/payments/PaymentsManager.java index fd1a62738a..189f7108c1 100644 --- a/platform/android/java/src/com/android/godot/payments/PaymentsManager.java +++ b/platform/android/java/src/com/android/godot/payments/PaymentsManager.java @@ -25,10 +25,8 @@ import com.android.vending.billing.IInAppBillingService;  public class 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;  	private Activity activity;  	IInAppBillingService mService; @@ -47,8 +45,10 @@ public class PaymentsManager {  	}  	public PaymentsManager initService(){ +		Intent intent = new Intent("com.android.vending.billing.InAppBillingService.BIND"); +		intent.setPackage("com.android.vending");  		activity.bindService( -				new Intent("com.android.vending.billing.InAppBillingService.BIND"),  +				intent,   				mServiceConn,   				Context.BIND_AUTO_CREATE);  		return this; @@ -67,13 +67,12 @@ public class PaymentsManager {  	    }  	    @Override -	    public void onServiceConnected(ComponentName name,  -	    		IBinder service) { -		mService = IInAppBillingService.Stub.asInterface(service); +	    public void onServiceConnected(ComponentName name, IBinder service) { +			mService = IInAppBillingService.Stub.asInterface(service);  	    }  	}; -	public void requestPurchase(String sku, String transactionId){ +	public void requestPurchase(final String sku, String transactionId){  		new PurchaseTask(mService, Godot.getInstance()) {  			@Override @@ -86,6 +85,12 @@ public class PaymentsManager {  			protected void canceled() {  				godotPaymentV3.callbackCancel();  			} +			 +			@Override +			protected void alreadyOwned() { +				godotPaymentV3.callbackAlreadyOwned(sku); +			} +			  		}.purchase(sku, transactionId);  	} @@ -112,26 +117,82 @@ public class PaymentsManager {  		}.consumeItAll();  	} +	public void requestPurchased(){ +		try{ +			PaymentsCache pc = new PaymentsCache(Godot.getInstance()); + +//			Log.d("godot", "requestPurchased for " + activity.getPackageName()); +			Bundle bundle = mService.getPurchases(3, activity.getPackageName(), "inapp",null); + +/*			 +			for (String key : bundle.keySet()) { +			    Object value = bundle.get(key); +			    Log.d("godot", String.format("%s %s (%s)", key, value.toString(), value.getClass().getName())); +			} +*/			 +			 +			if (bundle.getInt("RESPONSE_CODE") == 0){ + +				final ArrayList<String> myPurchases = bundle.getStringArrayList("INAPP_PURCHASE_DATA_LIST"); +				final ArrayList<String> mySignatures = bundle.getStringArrayList("INAPP_DATA_SIGNATURE_LIST"); +				 + +				if (myPurchases == null || myPurchases.size() == 0){ +//					Log.d("godot", "No purchases!"); +					godotPaymentV3.callbackPurchased("", "", ""); +					return; +				} +		 +//				Log.d("godot", "# products are purchased:" + myPurchases.size()); +				for (int i=0;i<myPurchases.size();i++) +				{ +					 +					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", "purchased item:" + token + "\n" + receipt); + +						pc.setConsumableValue("ticket_signautre", sku, signature); +						pc.setConsumableValue("ticket", sku, receipt); +						pc.setConsumableFlag("block", sku, true); +						pc.setConsumableValue("token", sku, token); + +						godotPaymentV3.callbackPurchased(receipt, signature, sku); +					} catch (JSONException e) { +					} +				} + +			} +		}catch(Exception e){ +			Log.d("godot", "Error requesting purchased products:" + e.getClass().getName() + ":" + e.getMessage()); +		} +	} +	  	public void processPurchaseResponse(int resultCode, Intent data) {  		new HandlePurchaseTask(activity){  			@Override  			protected void success(final String sku, final String signature, final String ticket) { -				godotPaymentV3.callbackSuccess(ticket, signature); -				new ConsumeTask(mService, activity) { +				godotPaymentV3.callbackSuccess(ticket, signature, sku); + +				if (auto_consume){ +					new ConsumeTask(mService, activity) { -					@Override -					protected void success(String ticket) { -//						godotPaymentV3.callbackSuccess(""); -					} +						@Override +						protected void success(String ticket) { +//							godotPaymentV3.callbackSuccess(""); +						} -					@Override -					protected void error(String message) { -						godotPaymentV3.callbackFail(); +						@Override +						protected void error(String message) { +							godotPaymentV3.callbackFail(); -					} -				}.consume(sku); - +						} +					}.consume(sku); +				}  //				godotPaymentV3.callbackSuccess(new PaymentsCache(activity).getConsumableValue("ticket", sku),signature);  //			    godotPaymentV3.callbackSuccess(ticket); @@ -149,7 +210,7 @@ public class PaymentsManager {  				godotPaymentV3.callbackCancel();  			} -			}.handlePurchaseRequest(resultCode, data); +		}.handlePurchaseRequest(resultCode, data);  	}  	public void validatePurchase(String purchaseToken, final String sku){ @@ -163,7 +224,7 @@ public class PaymentsManager {  					@Override  					protected void success(String ticket) { -						godotPaymentV3.callbackSuccess(ticket, null); +						godotPaymentV3.callbackSuccess(ticket, null, sku);  					} @@ -190,11 +251,31 @@ public class PaymentsManager {  		}.validatePurchase(sku);  	} +	public void setAutoConsume(boolean autoConsume){ +		auto_consume = autoConsume; +	} +	 +	public void consume(final String sku){ +		new ConsumeTask(mService, activity) { +			 +			@Override +			protected void success(String ticket) { +				godotPaymentV3.callbackSuccessProductMassConsumed(ticket, "", sku); +				 +			} +			 +			@Override +			protected void error(String message) { +				godotPaymentV3.callbackFail(); +				 +			} +		}.consume(sku); +	} +	  	private GodotPaymentV3 godotPaymentV3;  	public void setBaseSingleton(GodotPaymentV3 godotPaymentV3) {  		this.godotPaymentV3 = godotPaymentV3; -		  	}  } diff --git a/platform/android/java/src/com/android/godot/payments/PurchaseTask.java b/platform/android/java/src/com/android/godot/payments/PurchaseTask.java index 75662a442e..c1f9d164a1 100644 --- a/platform/android/java/src/com/android/godot/payments/PurchaseTask.java +++ b/platform/android/java/src/com/android/godot/payments/PurchaseTask.java @@ -62,7 +62,11 @@ abstract public class PurchaseTask {  //		Log.d("XXX", "Buy intent response code: " + responseCode);  		if(responseCode == 1 || responseCode == 3 || responseCode == 4){  			canceled(); -			return ; +			return; +		} +		if(responseCode == 7){ +			alreadyOwned(); +			return;  		} @@ -92,6 +96,6 @@ abstract public class PurchaseTask {  	abstract protected void error(String message);  	abstract protected void canceled(); - +	abstract protected void alreadyOwned();  } |