diff options
Diffstat (limited to 'platform/android/java/lib')
6 files changed, 25 insertions, 270 deletions
| diff --git a/platform/android/java/lib/src/org/godotengine/godot/FullScreenGodotApp.java b/platform/android/java/lib/src/org/godotengine/godot/FullScreenGodotApp.java index e8ffbb9481..fb1604f6af 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/FullScreenGodotApp.java +++ b/platform/android/java/lib/src/org/godotengine/godot/FullScreenGodotApp.java @@ -65,10 +65,6 @@ public abstract class FullScreenGodotApp extends FragmentActivity implements God  		} else {  			Log.v(TAG, "Creating new Godot fragment instance.");  			godotFragment = initGodotInstance(); -			if (godotFragment == null) { -				throw new IllegalStateException("Godot instance must be non-null."); -			} -  			getSupportFragmentManager().beginTransaction().replace(R.id.godot_fragment_container, godotFragment).setPrimaryNavigationFragment(godotFragment).commitNowAllowingStateLoss();  		}  	} diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.java b/platform/android/java/lib/src/org/godotengine/godot/Godot.java index 8a86136daf..6e597163ab 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/Godot.java +++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.java @@ -509,17 +509,14 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC  				use_debug_opengl = true;  			} else if (command_line[i].equals("--use_immersive")) {  				use_immersive = true; -				if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // check if the application runs on an android 4.4+ -					window.getDecorView().setSystemUiVisibility( -							View.SYSTEM_UI_FLAG_LAYOUT_STABLE | -							View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | -							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(); -				} +				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_FULLSCREEN | // hide status bar +						View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); +				UiChangeListener();  			} else if (command_line[i].equals("--use_apk_expansion")) {  				use_apk_expansion = true;  			} else if (has_extra && command_line[i].equals("--apk_expansion_md5")) { @@ -699,7 +696,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC  		mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_GAME);  		mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_GAME); -		if (use_immersive && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // check if the application runs on an android 4.4+ +		if (use_immersive) {  			Window window = getActivity().getWindow();  			window.getDecorView().setSystemUiVisibility(  					View.SYSTEM_UI_FLAG_LAYOUT_STABLE | @@ -719,15 +716,13 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC  		final View decorView = getActivity().getWindow().getDecorView();  		decorView.setOnSystemUiVisibilityChangeListener(visibility -> {  			if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { -				if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { -					decorView.setSystemUiVisibility( -							View.SYSTEM_UI_FLAG_LAYOUT_STABLE | -							View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | -							View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | -							View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | -							View.SYSTEM_UI_FLAG_FULLSCREEN | -							View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); -				} +				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);  			}  		});  	} @@ -888,9 +883,8 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC  			// Create Hex String  			StringBuilder hexString = new StringBuilder(); -			for (int i = 0; i < messageDigest.length; i++) { -				String s = Integer.toHexString(0xFF & messageDigest[i]); - +			for (byte b : messageDigest) { +				String s = Integer.toHexString(0xFF & b);  				if (s.length() == 1) {  					s = "0" + s;  				} diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java b/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java index c06d89b843..8694bb91e1 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java +++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java @@ -34,8 +34,9 @@ import static org.godotengine.godot.utils.GLUtils.DEBUG;  import org.godotengine.godot.GodotLib;  import org.godotengine.godot.GodotRenderView; -import org.godotengine.godot.input.InputManagerCompat.InputDeviceListener; +import android.content.Context; +import android.hardware.input.InputManager;  import android.os.Build;  import android.util.Log;  import android.util.SparseArray; @@ -53,9 +54,9 @@ import java.util.Set;  /**   * Handles input related events for the {@link GodotRenderView} view.   */ -public class GodotInputHandler implements InputDeviceListener { +public class GodotInputHandler implements InputManager.InputDeviceListener {  	private final GodotRenderView mRenderView; -	private final InputManagerCompat mInputManager; +	private final InputManager mInputManager;  	private final String tag = this.getClass().getSimpleName(); @@ -64,7 +65,7 @@ public class GodotInputHandler implements InputDeviceListener {  	public GodotInputHandler(GodotRenderView godotView) {  		mRenderView = godotView; -		mInputManager = InputManagerCompat.Factory.getInputManager(mRenderView.getView().getContext()); +		mInputManager = (InputManager)mRenderView.getView().getContext().getSystemService(Context.INPUT_SERVICE);  		mInputManager.registerInputDeviceListener(this, null);  	} diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/InputManagerCompat.java b/platform/android/java/lib/src/org/godotengine/godot/input/InputManagerCompat.java deleted file mode 100644 index 21fdc658bb..0000000000 --- a/platform/android/java/lib/src/org/godotengine/godot/input/InputManagerCompat.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - *      http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.godotengine.godot.input; - -import android.content.Context; -import android.os.Handler; -import android.view.InputDevice; -import android.view.MotionEvent; - -public interface InputManagerCompat { -	/** -	 * Gets information about the input device with the specified id. -	 * -	 * @param id The device id -	 * @return The input device or null if not found -	 */ -	InputDevice getInputDevice(int id); - -	/** -	 * Gets the ids of all input devices in the system. -	 * -	 * @return The input device ids. -	 */ -	int[] getInputDeviceIds(); - -	/** -	 * Registers an input device listener to receive notifications about when -	 * input devices are added, removed or changed. -	 * -	 * @param listener The listener to register. -	 * @param handler The handler on which the listener should be invoked, or -	 *            null if the listener should be invoked on the calling thread's -	 *            looper. -	 */ -	void registerInputDeviceListener(InputManagerCompat.InputDeviceListener listener, -			Handler handler); - -	/** -	 * Unregisters an input device listener. -	 * -	 * @param listener The listener to unregister. -	 */ -	void unregisterInputDeviceListener(InputManagerCompat.InputDeviceListener listener); - -	/* -	 * The following three calls are to simulate V16 behavior on pre-Jellybean -	 * devices. If you don't call them, your callback will never be called -	 * pre-API 16. -	 */ - -	/** -	 * Pass the motion events to the InputManagerCompat. This is used to -	 * optimize for polling for controllers. If you do not pass these events in, -	 * polling will cause regular object creation. -	 * -	 * @param event the motion event from the app -	 */ -	void onGenericMotionEvent(MotionEvent event); - -	/** -	 * Tell the V9 input manager that it should stop polling for disconnected -	 * devices. You can call this during onPause in your activity, although you -	 * might want to call it whenever your game is not active (or whenever you -	 * don't care about being notified of new input devices) -	 */ -	void onPause(); - -	/** -	 * Tell the V9 input manager that it should start polling for disconnected -	 * devices. You can call this during onResume in your activity, although you -	 * might want to call it less often (only when the gameplay is actually -	 * active) -	 */ -	void onResume(); - -	interface InputDeviceListener { -		/** -		 * Called whenever the input manager detects that a device has been -		 * added. This will only be called in the V9 version when a motion event -		 * is detected. -		 * -		 * @param deviceId The id of the input device that was added. -		 */ -		void onInputDeviceAdded(int deviceId); - -		/** -		 * Called whenever the properties of an input device have changed since -		 * they were last queried. This will not be called for the V9 version of -		 * the API. -		 * -		 * @param deviceId The id of the input device that changed. -		 */ -		void onInputDeviceChanged(int deviceId); - -		/** -		 * Called whenever the input manager detects that a device has been -		 * removed. For the V9 version, this can take some time depending on the -		 * poll rate. -		 * -		 * @param deviceId The id of the input device that was removed. -		 */ -		void onInputDeviceRemoved(int deviceId); -	} - -	/** -	 * Use this to construct a compatible InputManager. -	 */ -	class Factory { -		/** -		 * Constructs and returns a compatible InputManger -		 * -		 * @param context the Context that will be used to get the system -		 *            service from -		 * @return a compatible implementation of InputManager -		 */ -		public static InputManagerCompat getInputManager(Context context) { -			return new InputManagerV16(context); -		} -	} -} diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/InputManagerV16.java b/platform/android/java/lib/src/org/godotengine/godot/input/InputManagerV16.java deleted file mode 100644 index 0dbc13c77b..0000000000 --- a/platform/android/java/lib/src/org/godotengine/godot/input/InputManagerV16.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - *      http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.godotengine.godot.input; - -import android.annotation.TargetApi; -import android.content.Context; -import android.hardware.input.InputManager; -import android.os.Build; -import android.os.Handler; -import android.view.InputDevice; -import android.view.MotionEvent; - -import java.util.HashMap; -import java.util.Map; - -@TargetApi(Build.VERSION_CODES.JELLY_BEAN) -public class InputManagerV16 implements InputManagerCompat { -	private final InputManager mInputManager; -	private final Map<InputManagerCompat.InputDeviceListener, V16InputDeviceListener> mListeners; - -	public InputManagerV16(Context context) { -		mInputManager = (InputManager)context.getSystemService(Context.INPUT_SERVICE); -		mListeners = new HashMap<>(); -	} - -	@Override -	public InputDevice getInputDevice(int id) { -		return mInputManager.getInputDevice(id); -	} - -	@Override -	public int[] getInputDeviceIds() { -		return mInputManager.getInputDeviceIds(); -	} - -	static class V16InputDeviceListener implements InputManager.InputDeviceListener { -		final InputManagerCompat.InputDeviceListener mIDL; - -		public V16InputDeviceListener(InputDeviceListener idl) { -			mIDL = idl; -		} - -		@Override -		public void onInputDeviceAdded(int deviceId) { -			mIDL.onInputDeviceAdded(deviceId); -		} - -		@Override -		public void onInputDeviceChanged(int deviceId) { -			mIDL.onInputDeviceChanged(deviceId); -		} - -		@Override -		public void onInputDeviceRemoved(int deviceId) { -			mIDL.onInputDeviceRemoved(deviceId); -		} -	} - -	@Override -	public void registerInputDeviceListener(InputDeviceListener listener, Handler handler) { -		V16InputDeviceListener v16Listener = new V16InputDeviceListener(listener); -		mInputManager.registerInputDeviceListener(v16Listener, handler); -		mListeners.put(listener, v16Listener); -	} - -	@Override -	public void unregisterInputDeviceListener(InputDeviceListener listener) { -		V16InputDeviceListener curListener = mListeners.remove(listener); -		if (null != curListener) { -			mInputManager.unregisterInputDeviceListener(curListener); -		} -	} - -	@Override -	public void onGenericMotionEvent(MotionEvent event) { -		// unused in V16 -	} - -	@Override -	public void onPause() { -		// unused in V16 -	} - -	@Override -	public void onResume() { -		// unused in V16 -	} -} diff --git a/platform/android/java/lib/src/org/godotengine/godot/utils/Crypt.java b/platform/android/java/lib/src/org/godotengine/godot/utils/Crypt.java index 39a57f587a..47df23fe1a 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/utils/Crypt.java +++ b/platform/android/java/lib/src/org/godotengine/godot/utils/Crypt.java @@ -43,8 +43,8 @@ public class Crypt {  			// Create Hex String  			StringBuilder hexString = new StringBuilder(); -			for (int i = 0; i < messageDigest.length; i++) -				hexString.append(Integer.toHexString(0xFF & messageDigest[i])); +			for (byte b : messageDigest) +				hexString.append(Integer.toHexString(0xFF & b));  			return hexString.toString();  		} catch (Exception e) { |