mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-03 11:13:44 +01:00
Android: Reformat Java files.
Mostly indentation, just ran a formatter tool and did some cleanup. No code changes.
This commit is contained in:
1 parent
ad1b75292f
commit
4846cfe6a5
16 files changed
+473
-536
No files matched your search
@@ -1,20 +1,20 @@
|
||||
package org.ppsspp.ppsspp;
|
||||
|
||||
import android.media.AudioManager;
|
||||
import android.media.AudioManager.OnAudioFocusChangeListener;
|
||||
|
||||
public class AudioFocusChangeListener implements OnAudioFocusChangeListener{
|
||||
public class AudioFocusChangeListener implements OnAudioFocusChangeListener {
|
||||
// not used right now, but we may need to use it sometime. So just store it
|
||||
// for now.
|
||||
private boolean hasAudioFocus = false;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onAudioFocusChange(int focusChange) {
|
||||
switch (focusChange){
|
||||
switch (focusChange) {
|
||||
case AudioManager.AUDIOFOCUS_GAIN:
|
||||
hasAudioFocus = true;
|
||||
break;
|
||||
|
||||
|
||||
case AudioManager.AUDIOFOCUS_LOSS:
|
||||
hasAudioFocus = false;
|
||||
break;
|
||||
|
||||
@@ -8,7 +8,6 @@ import android.graphics.SurfaceTexture;
|
||||
import android.graphics.YuvImage;
|
||||
import android.hardware.Camera;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@@ -42,10 +41,10 @@ class CameraHelper {
|
||||
|
||||
// crop to expected size and convert to Jpeg
|
||||
Rect rect = new Rect(
|
||||
(previewWidth-targetW)/2,
|
||||
(previewHeight-targetH)/2,
|
||||
previewWidth-(previewWidth-targetW)/2,
|
||||
previewHeight-(previewHeight-targetH)/2
|
||||
(previewWidth - targetW) / 2,
|
||||
(previewHeight - targetH) / 2,
|
||||
previewWidth - (previewWidth - targetW) / 2,
|
||||
previewHeight - (previewHeight - targetH) / 2
|
||||
);
|
||||
yuvImage.compressToJpeg(rect, 80, baos);
|
||||
NativeApp.pushCameraImage(baos.toByteArray());
|
||||
|
||||
@@ -11,42 +11,44 @@ import android.view.MotionEvent;
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
|
||||
public class InputDeviceState {
|
||||
private static final String TAG = "InputDeviceState";
|
||||
|
||||
|
||||
private static final int deviceId = NativeApp.DEVICE_ID_PAD_0;
|
||||
|
||||
private InputDevice mDevice;
|
||||
private int[] mAxes;
|
||||
|
||||
InputDevice getDevice() { return mDevice; }
|
||||
InputDevice getDevice() {
|
||||
return mDevice;
|
||||
}
|
||||
|
||||
@TargetApi(19)
|
||||
void logAdvanced(InputDevice device) {
|
||||
Log.i(TAG, "Vendor ID:" + device.getVendorId() + " productId: " + device.getProductId());
|
||||
Log.i(TAG, "Vendor ID:" + device.getVendorId() + " productId: " + device.getProductId());
|
||||
}
|
||||
|
||||
|
||||
public InputDeviceState(InputDevice device) {
|
||||
mDevice = device;
|
||||
int numAxes = 0;
|
||||
for (MotionRange range : device.getMotionRanges()) {
|
||||
if ((range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
|
||||
numAxes += 1;
|
||||
}
|
||||
}
|
||||
mDevice = device;
|
||||
int numAxes = 0;
|
||||
for (MotionRange range : device.getMotionRanges()) {
|
||||
if ((range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
|
||||
numAxes += 1;
|
||||
}
|
||||
}
|
||||
|
||||
mAxes = new int[numAxes];
|
||||
mAxes = new int[numAxes];
|
||||
|
||||
int i = 0;
|
||||
for (MotionRange range : device.getMotionRanges()) {
|
||||
if ((range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
|
||||
mAxes[i++] = range.getAxis();
|
||||
}
|
||||
}
|
||||
|
||||
Log.i(TAG, "Registering input device with " + numAxes + " axes: " + device.getName());
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
logAdvanced(device);
|
||||
}
|
||||
NativeApp.sendMessage("inputDeviceConnected", device.getName());
|
||||
int i = 0;
|
||||
for (MotionRange range : device.getMotionRanges()) {
|
||||
if ((range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
|
||||
mAxes[i++] = range.getAxis();
|
||||
}
|
||||
}
|
||||
|
||||
Log.i(TAG, "Registering input device with " + numAxes + " axes: " + device.getName());
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
logAdvanced(device);
|
||||
}
|
||||
NativeApp.sendMessage("inputDeviceConnected", device.getName());
|
||||
}
|
||||
|
||||
public boolean onKeyDown(KeyEvent event) {
|
||||
@@ -54,12 +56,12 @@ public class InputDeviceState {
|
||||
boolean repeat = event.getRepeatCount() > 0;
|
||||
return NativeApp.keyDown(deviceId, keyCode, repeat);
|
||||
}
|
||||
|
||||
|
||||
public boolean onKeyUp(KeyEvent event) {
|
||||
int keyCode = event.getKeyCode();
|
||||
return NativeApp.keyUp(deviceId, keyCode);
|
||||
return NativeApp.keyUp(deviceId, keyCode);
|
||||
}
|
||||
|
||||
|
||||
public boolean onJoystickMotion(MotionEvent event) {
|
||||
if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0) {
|
||||
return false;
|
||||
|
||||
@@ -48,12 +48,12 @@ class LocationHelper implements LocationListener {
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
float latitude = (float)location.getLatitude();
|
||||
float longitude = (float)location.getLongitude();
|
||||
float altitude = (float)location.getAltitude();
|
||||
float speed = location.getSpeed();
|
||||
float bearing = location.getBearing();
|
||||
long time = location.getTime() / 1000; // ms to s !!
|
||||
float latitude = (float) location.getLatitude();
|
||||
float longitude = (float) location.getLongitude();
|
||||
float altitude = (float) location.getAltitude();
|
||||
float speed = location.getSpeed();
|
||||
float bearing = location.getBearing();
|
||||
long time = location.getTime() / 1000; // ms to s !!
|
||||
|
||||
NativeApp.pushNewGpsData(latitude, longitude, altitude, speed, bearing, time);
|
||||
}
|
||||
|
||||
@@ -1,27 +1,25 @@
|
||||
/**
|
||||
* Mupen64PlusAE, an N64 emulator for the Android platform
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2013 Paul Lamb
|
||||
*
|
||||
*
|
||||
* This file is part of Mupen64PlusAE.
|
||||
*
|
||||
*
|
||||
* Mupen64PlusAE is free software: you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* Mupen64PlusAE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Mupen64PlusAE. If
|
||||
* not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
* Authors: Paul Lamb
|
||||
*/
|
||||
package org.ppsspp.ppsspp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -29,90 +27,73 @@ import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import com.bda.controller.Controller;
|
||||
import com.bda.controller.IControllerService;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Temporary hack for crash in MOGA library on Lollipop. This hack can be removed once MOGA fixes
|
||||
* their library. The actual issue is caused by the use of implicit service intents, which are
|
||||
* illegal in Lollipop, as seen in the logcat message below.
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* {@code Service Intent must be explicit: Intent { act=com.bda.controller.IControllerService } }
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @see <a href="http://www.mogaanywhere.com/developers/">MOGA developer site</a>
|
||||
* @see <a href="http://commonsware.com/blog/2014/06/29/dealing-deprecations-bindservice.html">
|
||||
* Discussion on explicit intents</a>
|
||||
*/
|
||||
public class MogaHack
|
||||
{
|
||||
public static void init(Controller controller, Context context )
|
||||
{
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT)
|
||||
{
|
||||
boolean mIsBound = false;
|
||||
java.lang.reflect.Field fIsBound = null;
|
||||
android.content.ServiceConnection mServiceConnection = null;
|
||||
java.lang.reflect.Field fServiceConnection = null;
|
||||
try
|
||||
{
|
||||
Class<?> cMogaController = controller.getClass();
|
||||
fIsBound = cMogaController.getDeclaredField( "mIsBound" );
|
||||
fIsBound.setAccessible( true );
|
||||
mIsBound = fIsBound.getBoolean( controller );
|
||||
fServiceConnection = cMogaController.getDeclaredField( "mServiceConnection" );
|
||||
fServiceConnection.setAccessible( true );
|
||||
mServiceConnection = ( android.content.ServiceConnection ) fServiceConnection.get( controller );
|
||||
}
|
||||
catch( NoSuchFieldException e )
|
||||
{
|
||||
Log.e( "MogaHack", "MOGA Lollipop Hack NoSuchFieldException (get)", e );
|
||||
}
|
||||
catch( IllegalAccessException e )
|
||||
{
|
||||
Log.e( "MogaHack", "MOGA Lollipop Hack IllegalAccessException (get)", e );
|
||||
}
|
||||
catch( IllegalArgumentException e )
|
||||
{
|
||||
Log.e( "MogaHack", "MOGA Lollipop Hack IllegalArgumentException (get)", e );
|
||||
}
|
||||
if( ( !mIsBound ) && ( mServiceConnection != null ) )
|
||||
{
|
||||
// Convert implicit intent to explicit intent, see http://stackoverflow.com/a/26318757
|
||||
Intent intent = new Intent( IControllerService.class.getName() );
|
||||
List<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentServices( intent, 0 );
|
||||
if( resolveInfos == null || resolveInfos.size() != 1 )
|
||||
{
|
||||
// What? this doesn't do anything.
|
||||
// Log.e( "MogaHack", "Somebody is trying to intercept our intent. Disabling MOGA controller for security." );
|
||||
}
|
||||
ServiceInfo serviceInfo = resolveInfos.get( 0 ).serviceInfo;
|
||||
String packageName = serviceInfo.packageName;
|
||||
String className = serviceInfo.name;
|
||||
intent.setComponent( new ComponentName( packageName, className ) );
|
||||
|
||||
// Start the service explicitly
|
||||
context.startService( intent );
|
||||
context.bindService( intent, mServiceConnection, 1 );
|
||||
try
|
||||
{
|
||||
fIsBound.setBoolean( controller, true );
|
||||
}
|
||||
catch( IllegalAccessException e )
|
||||
{
|
||||
Log.e( "MogaHack", "MOGA Lollipop Hack IllegalAccessException (set)", e );
|
||||
}
|
||||
catch( IllegalArgumentException e )
|
||||
{
|
||||
Log.e( "MogaHack", "MOGA Lollipop Hack IllegalArgumentException (set)", e );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
controller.init();
|
||||
}
|
||||
}
|
||||
public class MogaHack {
|
||||
public static void init(Controller controller, Context context) {
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
|
||||
boolean mIsBound = false;
|
||||
java.lang.reflect.Field fIsBound = null;
|
||||
android.content.ServiceConnection mServiceConnection = null;
|
||||
java.lang.reflect.Field fServiceConnection = null;
|
||||
|
||||
try {
|
||||
Class<?> cMogaController = controller.getClass();
|
||||
fIsBound = cMogaController.getDeclaredField("mIsBound");
|
||||
fIsBound.setAccessible(true);
|
||||
mIsBound = fIsBound.getBoolean(controller);
|
||||
fServiceConnection = cMogaController.getDeclaredField("mServiceConnection");
|
||||
fServiceConnection.setAccessible(true);
|
||||
mServiceConnection = (android.content.ServiceConnection) fServiceConnection.get(controller);
|
||||
} catch (NoSuchFieldException e) {
|
||||
Log.e("MogaHack", "MOGA Lollipop Hack NoSuchFieldException (get)", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
Log.e("MogaHack", "MOGA Lollipop Hack IllegalAccessException (get)", e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.e("MogaHack", "MOGA Lollipop Hack IllegalArgumentException (get)", e);
|
||||
}
|
||||
|
||||
if ((!mIsBound) && (mServiceConnection != null)) {
|
||||
// Convert implicit intent to explicit intent, see http://stackoverflow.com/a/26318757
|
||||
Intent intent = new Intent(IControllerService.class.getName());
|
||||
List<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentServices(intent, 0);
|
||||
if (resolveInfos == null || resolveInfos.size() != 1) {
|
||||
// What? this doesn't do anything.
|
||||
// Log.e("MogaHack", "Somebody is trying to intercept our intent. Disabling MOGA controller for security.");
|
||||
}
|
||||
ServiceInfo serviceInfo = resolveInfos.get(0).serviceInfo;
|
||||
String packageName = serviceInfo.packageName;
|
||||
String className = serviceInfo.name;
|
||||
intent.setComponent(new ComponentName(packageName, className));
|
||||
|
||||
// Start the service explicitly
|
||||
context.startService(intent);
|
||||
context.bindService(intent, mServiceConnection, 1);
|
||||
try {
|
||||
fIsBound.setBoolean(controller, true);
|
||||
} catch (IllegalAccessException e) {
|
||||
Log.e("MogaHack", "MOGA Lollipop Hack IllegalAccessException (set)", e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.e("MogaHack", "MOGA Lollipop Hack IllegalArgumentException (set)", e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
controller.init();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,6 @@ import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
@@ -116,14 +115,14 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
private int pixelHeight;
|
||||
|
||||
private static final String[] permissionsForStorage = {
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
};
|
||||
private static final String[] permissionsForLocation = {
|
||||
Manifest.permission.ACCESS_FINE_LOCATION,
|
||||
Manifest.permission.ACCESS_COARSE_LOCATION
|
||||
Manifest.permission.ACCESS_FINE_LOCATION,
|
||||
Manifest.permission.ACCESS_COARSE_LOCATION,
|
||||
};
|
||||
private static final String[] permissionsForCamera = {
|
||||
Manifest.permission.CAMERA
|
||||
Manifest.permission.CAMERA
|
||||
};
|
||||
|
||||
public static final int REQUEST_CODE_STORAGE_PERMISSION = 1;
|
||||
@@ -132,12 +131,12 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
|
||||
// Functions for the app activity to override to change behaviour.
|
||||
|
||||
public native void registerCallbacks();
|
||||
public native void unregisterCallbacks();
|
||||
public native void registerCallbacks();
|
||||
public native void unregisterCallbacks();
|
||||
|
||||
public boolean useLowProfileButtons() {
|
||||
return true;
|
||||
}
|
||||
public boolean useLowProfileButtons() {
|
||||
return true;
|
||||
}
|
||||
|
||||
NativeRenderer getRenderer() {
|
||||
return nativeRenderer;
|
||||
@@ -158,21 +157,21 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
}
|
||||
|
||||
String getApplicationLibraryDir(ApplicationInfo application) {
|
||||
String libdir = null;
|
||||
try {
|
||||
// Starting from Android 2.3, nativeLibraryDir is available:
|
||||
Field field = ApplicationInfo.class.getField("nativeLibraryDir");
|
||||
libdir = (String) field.get(application);
|
||||
} catch (SecurityException e1) {
|
||||
} catch (NoSuchFieldException e1) {
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (IllegalAccessException e) {
|
||||
}
|
||||
if (libdir == null) {
|
||||
// Fallback for Android < 2.3:
|
||||
libdir = application.dataDir + "/lib";
|
||||
}
|
||||
return libdir;
|
||||
String libdir = null;
|
||||
try {
|
||||
// Starting from Android 2.3, nativeLibraryDir is available:
|
||||
Field field = ApplicationInfo.class.getField("nativeLibraryDir");
|
||||
libdir = (String) field.get(application);
|
||||
} catch (SecurityException e1) {
|
||||
} catch (NoSuchFieldException e1) {
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (IllegalAccessException e) {
|
||||
}
|
||||
if (libdir == null) {
|
||||
// Fallback for Android < 2.3:
|
||||
libdir = application.dataDir + "/lib";
|
||||
}
|
||||
return libdir;
|
||||
}
|
||||
|
||||
@TargetApi(23)
|
||||
@@ -212,27 +211,26 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode,
|
||||
String permissions[], int[] grantResults) {
|
||||
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
|
||||
switch (requestCode) {
|
||||
case REQUEST_CODE_STORAGE_PERMISSION:
|
||||
if (permissionsGranted(permissions, grantResults)) {
|
||||
NativeApp.sendMessage("permission_granted", "storage");
|
||||
} else {
|
||||
NativeApp.sendMessage("permission_denied", "storage");
|
||||
}
|
||||
break;
|
||||
case REQUEST_CODE_LOCATION_PERMISSION:
|
||||
if (permissionsGranted(permissions, grantResults)) {
|
||||
mLocationHelper.startLocationUpdates();
|
||||
}
|
||||
break;
|
||||
case REQUEST_CODE_CAMERA_PERMISSION:
|
||||
if (mCameraHelper != null && permissionsGranted(permissions, grantResults)) {
|
||||
mCameraHelper.startCamera();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
case REQUEST_CODE_STORAGE_PERMISSION:
|
||||
if (permissionsGranted(permissions, grantResults)) {
|
||||
NativeApp.sendMessage("permission_granted", "storage");
|
||||
} else {
|
||||
NativeApp.sendMessage("permission_denied", "storage");
|
||||
}
|
||||
break;
|
||||
case REQUEST_CODE_LOCATION_PERMISSION:
|
||||
if (permissionsGranted(permissions, grantResults)) {
|
||||
mLocationHelper.startLocationUpdates();
|
||||
}
|
||||
break;
|
||||
case REQUEST_CODE_CAMERA_PERMISSION:
|
||||
if (mCameraHelper != null && permissionsGranted(permissions, grantResults)) {
|
||||
mCameraHelper.startCamera();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,65 +239,63 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
}
|
||||
|
||||
public void Initialize() {
|
||||
// Initialize audio classes. Do this here since detectOptimalAudioSettings()
|
||||
// Initialize audio classes. Do this here since detectOptimalAudioSettings()
|
||||
// needs audioManager
|
||||
this.audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
|
||||
this.audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
||||
this.audioFocusChangeListener = new AudioFocusChangeListener();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 17) {
|
||||
// Get the optimal buffer sz
|
||||
detectOptimalAudioSettings();
|
||||
}
|
||||
powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
if (Build.VERSION.SDK_INT >= 17) {
|
||||
// Get the optimal buffer sz
|
||||
detectOptimalAudioSettings();
|
||||
}
|
||||
powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
if (powerManager.isSustainedPerformanceModeSupported()) {
|
||||
sustainedPerfSupported = true;
|
||||
NativeApp.sendMessage("sustained_perf_supported", "1");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// isLandscape is used to trigger GetAppInfo currently, we
|
||||
boolean landscape = NativeApp.isLandscape();
|
||||
Log.d(TAG, "Landscape: " + landscape);
|
||||
// isLandscape is used to trigger GetAppInfo currently, we
|
||||
boolean landscape = NativeApp.isLandscape();
|
||||
Log.d(TAG, "Landscape: " + landscape);
|
||||
|
||||
// Get system information
|
||||
// Get system information
|
||||
ApplicationInfo appInfo = null;
|
||||
|
||||
PackageManager packMgmr = getPackageManager();
|
||||
String packageName = getPackageName();
|
||||
try {
|
||||
appInfo = packMgmr.getApplicationInfo(packageName, 0);
|
||||
} catch (NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Unable to locate assets, aborting...");
|
||||
}
|
||||
appInfo = packMgmr.getApplicationInfo(packageName, 0);
|
||||
} catch (NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Unable to locate assets, aborting...");
|
||||
}
|
||||
|
||||
int deviceType = NativeApp.DEVICE_TYPE_MOBILE;
|
||||
UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
|
||||
switch (uiModeManager.getCurrentModeType()) {
|
||||
case Configuration.UI_MODE_TYPE_TELEVISION:
|
||||
deviceType = NativeApp.DEVICE_TYPE_TV;
|
||||
Log.i(TAG, "Running on an Android TV Device");
|
||||
Log.i(TAG, "Running on an Android TV Device");
|
||||
break;
|
||||
case Configuration.UI_MODE_TYPE_DESK:
|
||||
deviceType = NativeApp.DEVICE_TYPE_DESKTOP;
|
||||
Log.i(TAG, "Running on an Android desktop computer (!)");
|
||||
Log.i(TAG, "Running on an Android desktop computer (!)");
|
||||
break;
|
||||
// All other device types are treated the same.
|
||||
}
|
||||
|
||||
|
||||
|
||||
isXperiaPlay = IsXperiaPlay();
|
||||
isXperiaPlay = IsXperiaPlay();
|
||||
|
||||
String libraryDir = getApplicationLibraryDir(appInfo);
|
||||
File sdcard = Environment.getExternalStorageDirectory();
|
||||
File sdcard = Environment.getExternalStorageDirectory();
|
||||
|
||||
String externalStorageDir = sdcard.getAbsolutePath();
|
||||
File filesDir = this.getFilesDir();
|
||||
String externalStorageDir = sdcard.getAbsolutePath();
|
||||
File filesDir = this.getFilesDir();
|
||||
String dataDir = null;
|
||||
if (filesDir != null) {
|
||||
// Null has been seen in Google Play stacktraces
|
||||
if (filesDir != null) {
|
||||
// Null has been seen in Google Play stacktraces
|
||||
dataDir = filesDir.getAbsolutePath();
|
||||
}
|
||||
String apkFilePath = appInfo.sourceDir;
|
||||
@@ -322,27 +318,26 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
updateScreenRotation("Initialize");
|
||||
}
|
||||
|
||||
// Detect OpenGL support.
|
||||
// We don't currently use this detection for anything but good to have in the log.
|
||||
if (!detectOpenGLES20()) {
|
||||
Log.i(TAG, "OpenGL ES 2.0 NOT detected. Things will likely go badly.");
|
||||
} else {
|
||||
if (detectOpenGLES30()) {
|
||||
Log.i(TAG, "OpenGL ES 3.0 detected.");
|
||||
}
|
||||
else {
|
||||
Log.i(TAG, "OpenGL ES 2.0 detected.");
|
||||
}
|
||||
}
|
||||
// Detect OpenGL support.
|
||||
// We don't currently use this detection for anything but good to have in the log.
|
||||
if (!detectOpenGLES20()) {
|
||||
Log.i(TAG, "OpenGL ES 2.0 NOT detected. Things will likely go badly.");
|
||||
} else {
|
||||
if (detectOpenGLES30()) {
|
||||
Log.i(TAG, "OpenGL ES 3.0 detected.");
|
||||
} else {
|
||||
Log.i(TAG, "OpenGL ES 2.0 detected.");
|
||||
}
|
||||
}
|
||||
|
||||
vibrator = (Vibrator)getSystemService(VIBRATOR_SERVICE);
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
checkForVibrator();
|
||||
}
|
||||
vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
checkForVibrator();
|
||||
}
|
||||
|
||||
mLocationHelper = new LocationHelper(this);
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
// android.graphics.SurfaceTexture is not available before version 11.
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
// android.graphics.SurfaceTexture is not available before version 11.
|
||||
mCameraHelper = new CameraHelper(this);
|
||||
}
|
||||
}
|
||||
@@ -426,11 +421,11 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
// Need API 11 to check for existence of a vibrator? Zany.
|
||||
@TargetApi(11)
|
||||
public void checkForVibrator() {
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
if (!vibrator.hasVibrator()) {
|
||||
vibrator = null;
|
||||
}
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
if (!vibrator.hasVibrator()) {
|
||||
vibrator = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Runnable mEmulationRunner = new Runnable() {
|
||||
@@ -460,7 +455,6 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
public void updateDisplayMeasurements() {
|
||||
Display display = getWindowManager().getDefaultDisplay();
|
||||
|
||||
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
if (useImmersive() && Build.VERSION.SDK_INT >= 17) {
|
||||
display.getRealMetrics(metrics);
|
||||
@@ -470,7 +464,7 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
densityDpi = metrics.densityDpi;
|
||||
refreshRate = display.getRefreshRate();
|
||||
|
||||
NativeApp.setDisplayParameters(metrics.widthPixels, metrics.heightPixels, (int)densityDpi, refreshRate);
|
||||
NativeApp.setDisplayParameters(metrics.widthPixels, metrics.heightPixels, (int) densityDpi, refreshRate);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -497,37 +491,37 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||
|
||||
gainAudioFocus(this.audioManager, this.audioFocusChangeListener);
|
||||
NativeApp.audioInit();
|
||||
NativeApp.audioInit();
|
||||
|
||||
if (javaGL) {
|
||||
mGLSurfaceView = new NativeGLView(this);
|
||||
if (javaGL) {
|
||||
mGLSurfaceView = new NativeGLView(this);
|
||||
nativeRenderer = new NativeRenderer(this);
|
||||
mGLSurfaceView.setEGLContextClientVersion(2);
|
||||
mGLSurfaceView.getHolder().addCallback(NativeActivity.this);
|
||||
|
||||
// Setup the GLSurface and ask android for the correct
|
||||
// Number of bits for r, g, b, a, depth and stencil components
|
||||
// The PSP only has 16-bit Z so that should be enough.
|
||||
// Might want to change this for other apps (24-bit might be useful).
|
||||
// Actually, we might be able to do without both stencil and depth in
|
||||
// the back buffer, but that would kill non-buffered rendering.
|
||||
// Setup the GLSurface and ask android for the correct
|
||||
// Number of bits for r, g, b, a, depth and stencil components
|
||||
// The PSP only has 16-bit Z so that should be enough.
|
||||
// Might want to change this for other apps (24-bit might be useful).
|
||||
// Actually, we might be able to do without both stencil and depth in
|
||||
// the back buffer, but that would kill non-buffered rendering.
|
||||
|
||||
// It appears some gingerbread devices blow up if you use a config chooser at all ???? (Xperia Play)
|
||||
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
// It appears some gingerbread devices blow up if you use a config chooser at all ???? (Xperia Play)
|
||||
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
|
||||
// On some (especially older devices), things blow up later (EGL_BAD_MATCH) if we don't set the format here,
|
||||
// if we specify that we want destination alpha in the config chooser, which we do.
|
||||
// http://grokbase.com/t/gg/android-developers/11bj40jm4w/fall-back
|
||||
// On some (especially older devices), things blow up later (EGL_BAD_MATCH) if we don't set
|
||||
// the format here, if we specify that we want destination alpha in the config chooser, which we do.
|
||||
// http://grokbase.com/t/gg/android-developers/11bj40jm4w/fall-back
|
||||
|
||||
// Needed to avoid banding on Ouya?
|
||||
if (Build.MANUFACTURER == "OUYA") {
|
||||
mGLSurfaceView.getHolder().setFormat(PixelFormat.RGBX_8888);
|
||||
mGLSurfaceView.setEGLConfigChooser(new NativeEGLConfigChooser());
|
||||
}
|
||||
// Tried to mess around with config choosers here but fail completely on Xperia Play.
|
||||
// Needed to avoid banding on Ouya?
|
||||
if (Build.MANUFACTURER == "OUYA") {
|
||||
mGLSurfaceView.getHolder().setFormat(PixelFormat.RGBX_8888);
|
||||
mGLSurfaceView.setEGLConfigChooser(new NativeEGLConfigChooser());
|
||||
}
|
||||
// Tried to mess around with config choosers here but fail completely on Xperia Play.
|
||||
mGLSurfaceView.setRenderer(nativeRenderer);
|
||||
setContentView(mGLSurfaceView);
|
||||
} else {
|
||||
} else {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||
updateSystemUiVisibility();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
@@ -536,16 +530,17 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
}
|
||||
|
||||
mSurfaceView = new NativeSurfaceView(NativeActivity.this);
|
||||
mSurfaceView.getHolder().addCallback(NativeActivity.this);
|
||||
Log.i(TAG, "setcontentview before");
|
||||
mSurfaceView.getHolder().addCallback(NativeActivity.this);
|
||||
Log.i(TAG, "setcontentview before");
|
||||
setContentView(mSurfaceView);
|
||||
Log.i(TAG, "setcontentview after");
|
||||
ensureRenderLoop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Point desiredSize = new Point();
|
||||
private int badOrientationCount = 0;
|
||||
|
||||
@Override
|
||||
public void surfaceCreated(SurfaceHolder holder) {
|
||||
pixelWidth = holder.getSurfaceFrame().width();
|
||||
@@ -568,7 +563,7 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
}
|
||||
|
||||
Log.d(TAG, "Surface created. pixelWidth=" + pixelWidth + ", pixelHeight=" + pixelHeight + " holder: " + holder.toString() + " or: " + requestedOr);
|
||||
NativeApp.setDisplayParameters(pixelWidth, pixelHeight, (int)densityDpi, refreshRate);
|
||||
NativeApp.setDisplayParameters(pixelWidth, pixelHeight, (int) densityDpi, refreshRate);
|
||||
getDesiredBackbufferSize(desiredSize);
|
||||
|
||||
// Note that desiredSize might be 0,0 here - but that's fine when calling setFixedSize! It means auto.
|
||||
@@ -586,15 +581,15 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
||||
Log.v(TAG, "surfaceChanged: isCreating:" + holder.isCreating() + " holder: " + holder.toString());
|
||||
if (holder.isCreating() && desiredSize.x > 0 && desiredSize.y > 0) {
|
||||
// We have called setFixedSize which will trigger another surfaceChanged after the initial one. This one is the original one
|
||||
// and we don't care about it.
|
||||
// We have called setFixedSize which will trigger another surfaceChanged after the initial
|
||||
// one. This one is the original one and we don't care about it.
|
||||
Log.w(TAG, "holder.isCreating = true, ignoring. width=" + width + " height=" + height + " desWidth=" + desiredSize.x + " desHeight=" + desiredSize.y);
|
||||
return;
|
||||
}
|
||||
Log.w(TAG, "Surface changed. Resolution: " + width + "x" + height + " Format: " + format);
|
||||
NativeApp.backbufferResize(width, height, format);
|
||||
mSurface = holder.getSurface();
|
||||
if (!javaGL) {
|
||||
if (!javaGL) {
|
||||
// If we got a surface, this starts the thread. If not, it doesn't.
|
||||
if (mSurface == null) {
|
||||
joinRenderLoopThread();
|
||||
@@ -619,8 +614,8 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
// Invariants: After this, mRenderLoopThread will be set, and the thread will be running.
|
||||
protected synchronized void ensureRenderLoop() {
|
||||
if (javaGL) {
|
||||
Log.e(TAG, "JavaGL - should not get into ensureRenderLoop.");
|
||||
return;
|
||||
Log.e(TAG, "JavaGL - should not get into ensureRenderLoop.");
|
||||
return;
|
||||
}
|
||||
if (mSurface == null) {
|
||||
Log.w(TAG, "ensureRenderLoop - not starting thread, needs surface");
|
||||
@@ -637,8 +632,8 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
// Invariants: After this, mRenderLoopThread will be null, and the thread has exited.
|
||||
private synchronized void joinRenderLoopThread() {
|
||||
if (javaGL) {
|
||||
Log.e(TAG, "JavaGL - should not get into joinRenderLoopThread.");
|
||||
return;
|
||||
Log.e(TAG, "JavaGL - should not get into joinRenderLoopThread.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (mRenderLoopThread != null) {
|
||||
@@ -656,23 +651,23 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(19)
|
||||
@TargetApi(19)
|
||||
void setupSystemUiCallback() {
|
||||
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new OnSystemUiVisibilityChangeListener() {
|
||||
@Override
|
||||
public void onSystemUiVisibilityChange(int visibility) {
|
||||
if (visibility == 0) {
|
||||
updateSystemUiVisibility();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new OnSystemUiVisibilityChangeListener() {
|
||||
@Override
|
||||
public void onSystemUiVisibilityChange(int visibility) {
|
||||
if (visibility == 0) {
|
||||
updateSystemUiVisibility();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
Log.i(TAG, "onStop - do nothing special");
|
||||
}
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
Log.i(TAG, "onStop - do nothing special");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
@@ -709,46 +704,46 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
Log.i(TAG, "onPause");
|
||||
loseAudioFocus(this.audioManager, this.audioFocusChangeListener);
|
||||
NativeApp.pause();
|
||||
if (!javaGL) {
|
||||
if (!javaGL) {
|
||||
mSurfaceView.onPause();
|
||||
Log.i(TAG, "Joining render thread...");
|
||||
joinRenderLoopThread();
|
||||
Log.i(TAG, "Joined render thread");
|
||||
} else {
|
||||
} else {
|
||||
if (mGLSurfaceView != null) {
|
||||
mGLSurfaceView.onPause();
|
||||
} else {
|
||||
Log.e(TAG, "mGLSurfaceView really shouldn't be null in onPause");
|
||||
}
|
||||
}
|
||||
}
|
||||
Log.i(TAG, "onPause completed");
|
||||
}
|
||||
|
||||
private boolean detectOpenGLES20() {
|
||||
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
||||
ConfigurationInfo info = am.getDeviceConfigurationInfo();
|
||||
return info.reqGlEsVersion >= 0x20000;
|
||||
}
|
||||
private boolean detectOpenGLES20() {
|
||||
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
||||
ConfigurationInfo info = am.getDeviceConfigurationInfo();
|
||||
return info.reqGlEsVersion >= 0x20000;
|
||||
}
|
||||
|
||||
private boolean detectOpenGLES30() {
|
||||
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
||||
ConfigurationInfo info = am.getDeviceConfigurationInfo();
|
||||
return info.reqGlEsVersion >= 0x30000;
|
||||
}
|
||||
private boolean detectOpenGLES30() {
|
||||
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
||||
ConfigurationInfo info = am.getDeviceConfigurationInfo();
|
||||
return info.reqGlEsVersion >= 0x30000;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
updateSustainedPerformanceMode();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||
updateSystemUiVisibility();
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||
updateSystemUiVisibility();
|
||||
}
|
||||
// OK, config should be initialized, we can query for screen rotation.
|
||||
if (javaGL || Build.VERSION.SDK_INT >= 9) {
|
||||
updateScreenRotation("onResume");
|
||||
@@ -776,80 +771,79 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
Log.i(TAG, "onConfigurationChanged");
|
||||
super.onConfigurationChanged(newConfig);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||
updateSystemUiVisibility();
|
||||
}
|
||||
densityDpi = (float)newConfig.densityDpi;
|
||||
}
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
Log.i(TAG, "onConfigurationChanged");
|
||||
super.onConfigurationChanged(newConfig);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||
updateSystemUiVisibility();
|
||||
}
|
||||
densityDpi = (float) newConfig.densityDpi;
|
||||
}
|
||||
|
||||
//keep this static so we can call this even if we don't
|
||||
//instantiate NativeAudioPlayer
|
||||
// keep this static so we can call this even if we don't
|
||||
// instantiate NativeAudioPlayer
|
||||
public static void gainAudioFocus(AudioManager audioManager, AudioFocusChangeListener focusChangeListener) {
|
||||
if (audioManager != null) {
|
||||
audioManager.requestAudioFocus(focusChangeListener,
|
||||
AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
|
||||
audioManager.requestAudioFocus(focusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
|
||||
}
|
||||
}
|
||||
|
||||
//keep this static so we can call this even if we don't
|
||||
//instantiate NativeAudioPlayer
|
||||
public static void loseAudioFocus(AudioManager audioManager,AudioFocusChangeListener focusChangeListener){
|
||||
// keep this static so we can call this even if we don't
|
||||
// instantiate NativeAudioPlayer
|
||||
public static void loseAudioFocus(AudioManager audioManager, AudioFocusChangeListener focusChangeListener) {
|
||||
if (audioManager != null) {
|
||||
audioManager.abandonAudioFocus(focusChangeListener);
|
||||
}
|
||||
}
|
||||
|
||||
// We simply grab the first input device to produce an event and ignore all others that are connected.
|
||||
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
|
||||
// We simply grab the first input device to produce an event and ignore all others that are connected.
|
||||
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
|
||||
private InputDeviceState getInputDeviceState(InputEvent event) {
|
||||
InputDevice device = event.getDevice();
|
||||
if (device == null) {
|
||||
return null;
|
||||
}
|
||||
if (inputPlayerA == null) {
|
||||
inputPlayerADesc = getInputDesc(device);
|
||||
Log.i(TAG, "Input player A registered: desc = " + inputPlayerADesc);
|
||||
inputPlayerA = new InputDeviceState(device);
|
||||
}
|
||||
InputDevice device = event.getDevice();
|
||||
if (device == null) {
|
||||
return null;
|
||||
}
|
||||
if (inputPlayerA == null) {
|
||||
inputPlayerADesc = getInputDesc(device);
|
||||
Log.i(TAG, "Input player A registered: desc = " + inputPlayerADesc);
|
||||
inputPlayerA = new InputDeviceState(device);
|
||||
}
|
||||
|
||||
if (inputPlayerA.getDevice() == device) {
|
||||
return inputPlayerA;
|
||||
}
|
||||
if (inputPlayerA.getDevice() == device) {
|
||||
return inputPlayerA;
|
||||
}
|
||||
|
||||
if (inputPlayerB == null) {
|
||||
Log.i(TAG, "Input player B registered: desc = " + getInputDesc(device));
|
||||
inputPlayerB = new InputDeviceState(device);
|
||||
}
|
||||
if (inputPlayerB == null) {
|
||||
Log.i(TAG, "Input player B registered: desc = " + getInputDesc(device));
|
||||
inputPlayerB = new InputDeviceState(device);
|
||||
}
|
||||
|
||||
if (inputPlayerB.getDevice() == device) {
|
||||
return inputPlayerB;
|
||||
}
|
||||
if (inputPlayerB.getDevice() == device) {
|
||||
return inputPlayerB;
|
||||
}
|
||||
|
||||
if (inputPlayerC == null) {
|
||||
Log.i(TAG, "Input player C registered");
|
||||
inputPlayerC = new InputDeviceState(device);
|
||||
}
|
||||
if (inputPlayerC == null) {
|
||||
Log.i(TAG, "Input player C registered");
|
||||
inputPlayerC = new InputDeviceState(device);
|
||||
}
|
||||
|
||||
if (inputPlayerC.getDevice() == device) {
|
||||
return inputPlayerC;
|
||||
}
|
||||
if (inputPlayerC.getDevice() == device) {
|
||||
return inputPlayerC;
|
||||
}
|
||||
|
||||
return inputPlayerA;
|
||||
}
|
||||
return inputPlayerA;
|
||||
}
|
||||
|
||||
public boolean IsXperiaPlay() {
|
||||
return android.os.Build.MODEL.equals("R800a") || android.os.Build.MODEL.equals("R800i") || android.os.Build.MODEL.equals("R800x") || android.os.Build.MODEL.equals("R800at") || android.os.Build.MODEL.equals("SO-01D") || android.os.Build.MODEL.equals("zeus");
|
||||
}
|
||||
public boolean IsXperiaPlay() {
|
||||
return android.os.Build.MODEL.equals("R800a") || android.os.Build.MODEL.equals("R800i") || android.os.Build.MODEL.equals("R800x") || android.os.Build.MODEL.equals("R800at") || android.os.Build.MODEL.equals("SO-01D") || android.os.Build.MODEL.equals("zeus");
|
||||
}
|
||||
|
||||
// We grab the keys before onKeyDown/... even see them. This is also better because it lets us
|
||||
// distinguish devices.
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1 && !isXperiaPlay) {
|
||||
// We grab the keys before onKeyDown/... even see them. This is also better because it lets us
|
||||
// distinguish devices.
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1 && !isXperiaPlay) {
|
||||
InputDeviceState state = getInputDeviceState(event);
|
||||
if (state == null) {
|
||||
return super.dispatchKeyEvent(event);
|
||||
@@ -892,14 +886,14 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Let's go through the old path (onKeyUp, onKeyDown).
|
||||
// Let's go through the old path (onKeyUp, onKeyDown).
|
||||
return super.dispatchKeyEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(16)
|
||||
static public String getInputDesc(InputDevice input) {
|
||||
public static String getInputDesc(InputDevice input) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
return input.getDescriptor();
|
||||
} else {
|
||||
@@ -916,27 +910,27 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
public boolean onGenericMotionEvent(MotionEvent event) {
|
||||
// Log.d(TAG, "onGenericMotionEvent: " + event);
|
||||
if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) != 0) {
|
||||
if (Build.VERSION.SDK_INT >= 12) {
|
||||
InputDeviceState state = getInputDeviceState(event);
|
||||
if (state == null) {
|
||||
Log.w(TAG, "Joystick event but failed to get input device state.");
|
||||
return super.onGenericMotionEvent(event);
|
||||
}
|
||||
state.onJoystickMotion(event);
|
||||
return true;
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= 12) {
|
||||
InputDeviceState state = getInputDeviceState(event);
|
||||
if (state == null) {
|
||||
Log.w(TAG, "Joystick event but failed to get input device state.");
|
||||
return super.onGenericMotionEvent(event);
|
||||
}
|
||||
state.onJoystickMotion(event);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_HOVER_MOVE:
|
||||
// process the mouse hover movement...
|
||||
return true;
|
||||
case MotionEvent.ACTION_SCROLL:
|
||||
NativeApp.mouseWheelEvent(event.getX(), event.getY());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_HOVER_MOVE:
|
||||
// process the mouse hover movement...
|
||||
return true;
|
||||
case MotionEvent.ACTION_SCROLL:
|
||||
NativeApp.mouseWheelEvent(event.getX(), event.getY());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.onGenericMotionEvent(event);
|
||||
}
|
||||
|
||||
@@ -1015,19 +1009,19 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
return NativeApp.keyUp(0, keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
|
||||
Uri selectedImage = data.getData();
|
||||
String[] filePathColumn = { MediaStore.Images.Media.DATA };
|
||||
Cursor cursor = getContentResolver().query(selectedImage,
|
||||
filePathColumn, null, null, null);
|
||||
String[] filePathColumn = {MediaStore.Images.Media.DATA};
|
||||
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
|
||||
String picturePath = cursor.getString(columnIndex);
|
||||
cursor.close();
|
||||
NativeApp.sendMessage("bgImage_updated" , picturePath);
|
||||
NativeApp.sendMessage("bgImage_updated", picturePath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1070,17 +1064,17 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
|
||||
// The return value is sent elsewhere. TODO in java, in SendMessage in C++.
|
||||
public void inputBox(final String title, String defaultText, String defaultAction) {
|
||||
final FrameLayout fl = new FrameLayout(this);
|
||||
final EditText input = new EditText(this);
|
||||
input.setGravity(Gravity.CENTER);
|
||||
final FrameLayout fl = new FrameLayout(this);
|
||||
final EditText input = new EditText(this);
|
||||
input.setGravity(Gravity.CENTER);
|
||||
|
||||
FrameLayout.LayoutParams editBoxLayout = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
|
||||
editBoxLayout.setMargins(2, 20, 2, 20);
|
||||
fl.addView(input, editBoxLayout);
|
||||
FrameLayout.LayoutParams editBoxLayout = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
|
||||
editBoxLayout.setMargins(2, 20, 2, 20);
|
||||
fl.addView(input, editBoxLayout);
|
||||
|
||||
input.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||
input.setText(defaultText);
|
||||
input.selectAll();
|
||||
input.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||
input.setText(defaultText);
|
||||
input.selectAll();
|
||||
|
||||
// Lovely!
|
||||
AlertDialog.Builder bld;
|
||||
@@ -1095,30 +1089,31 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
else
|
||||
bld = createDialogBuilderNew();
|
||||
|
||||
AlertDialog dlg = bld
|
||||
.setView(fl)
|
||||
.setTitle(title)
|
||||
.setPositiveButton(defaultAction, new DialogInterface.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(DialogInterface d, int which) {
|
||||
NativeApp.sendMessage("inputbox_completed", title + ":" + input.getText().toString());
|
||||
d.dismiss();
|
||||
}
|
||||
})
|
||||
.setNegativeButton("Cancel", new DialogInterface.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(DialogInterface d, int which) {
|
||||
NativeApp.sendMessage("inputbox_failed", "");
|
||||
d.cancel();
|
||||
}
|
||||
}).create();
|
||||
AlertDialog dlg = bld
|
||||
.setView(fl)
|
||||
.setTitle(title)
|
||||
.setPositiveButton(defaultAction, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface d, int which) {
|
||||
NativeApp.sendMessage("inputbox_completed", title + ":" + input.getText().toString());
|
||||
d.dismiss();
|
||||
}
|
||||
})
|
||||
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface d, int which) {
|
||||
NativeApp.sendMessage("inputbox_failed", "");
|
||||
d.cancel();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
|
||||
dlg.setCancelable(true);
|
||||
dlg.show();
|
||||
}
|
||||
dlg.setCancelable(true);
|
||||
dlg.show();
|
||||
}
|
||||
|
||||
public boolean processCommand(String command, String params) {
|
||||
SurfaceView surfView = javaGL ? mGLSurfaceView : mSurfaceView;
|
||||
public boolean processCommand(String command, String params) {
|
||||
SurfaceView surfView = javaGL ? mGLSurfaceView : mSurfaceView;
|
||||
if (command.equals("launchBrowser")) {
|
||||
try {
|
||||
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(params));
|
||||
@@ -1133,24 +1128,22 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
try {
|
||||
Intent send = new Intent(Intent.ACTION_SENDTO);
|
||||
String uriText;
|
||||
uriText = "mailto:email@gmail.com" + "?subject=Your app is..."
|
||||
+ "&body=great! Or?";
|
||||
uriText = "mailto:email@gmail.com" + "?subject=Your app is..." + "&body=great! Or?";
|
||||
uriText = uriText.replace(" ", "%20");
|
||||
Uri uri = Uri.parse(uriText);
|
||||
send.setData(uri);
|
||||
startActivity(Intent.createChooser(send, "E-mail the app author!"));
|
||||
return true;
|
||||
} catch (Exception e) { // For example, android.content.ActivityNotFoundException
|
||||
} catch (Exception e) { // For example, android.content.ActivityNotFoundException
|
||||
Log.e(TAG, e.toString());
|
||||
return false;
|
||||
}
|
||||
} else if (command.equals("bgImage_browse")) {
|
||||
try {
|
||||
Intent i = new Intent(Intent.ACTION_PICK,
|
||||
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
startActivityForResult(i, RESULT_LOAD_IMAGE);
|
||||
return true;
|
||||
} catch (Exception e) { // For example, android.content.ActivityNotFoundException
|
||||
} catch (Exception e) { // For example, android.content.ActivityNotFoundException
|
||||
Log.e(TAG, e.toString());
|
||||
return false;
|
||||
}
|
||||
@@ -1161,7 +1154,7 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + params));
|
||||
startActivity(Intent.createChooser(share, "Share Picture"));
|
||||
return true;
|
||||
} catch (Exception e) { // For example, android.content.ActivityNotFoundException
|
||||
} catch (Exception e) { // For example, android.content.ActivityNotFoundException
|
||||
Log.e(TAG, e.toString());
|
||||
return false;
|
||||
}
|
||||
@@ -1173,7 +1166,7 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
sendIntent.setAction(Intent.ACTION_SEND);
|
||||
startActivity(sendIntent);
|
||||
return true;
|
||||
} catch (Exception e) { // For example, android.content.ActivityNotFoundException
|
||||
} catch (Exception e) { // For example, android.content.ActivityNotFoundException
|
||||
Log.e(TAG, e.toString());
|
||||
return false;
|
||||
}
|
||||
@@ -1181,16 +1174,12 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
try {
|
||||
String twitter_user_name = params;
|
||||
try {
|
||||
startActivity(new Intent(Intent.ACTION_VIEW,
|
||||
Uri.parse("twitter://user?screen_name="
|
||||
+ twitter_user_name)));
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?screen_name=" + twitter_user_name)));
|
||||
} catch (Exception e) {
|
||||
startActivity(new Intent(
|
||||
Intent.ACTION_VIEW,
|
||||
Uri.parse("https://twitter.com/#!/" + twitter_user_name)));
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/#!/" + twitter_user_name)));
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) { // For example, android.content.ActivityNotFoundException
|
||||
} catch (Exception e) { // For example, android.content.ActivityNotFoundException
|
||||
Log.e(TAG, e.toString());
|
||||
return false;
|
||||
}
|
||||
@@ -1208,15 +1197,11 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
// No idea what the point of the ApplicationWindowToken is or if it
|
||||
// matters where we get it from...
|
||||
inputMethodManager.toggleSoftInputFromWindow(
|
||||
surfView.getApplicationWindowToken(),
|
||||
InputMethodManager.SHOW_FORCED, 0);
|
||||
inputMethodManager.toggleSoftInputFromWindow(surfView.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
|
||||
return true;
|
||||
} else if (command.equals("hideKeyboard") && surfView != null) {
|
||||
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
inputMethodManager.toggleSoftInputFromWindow(
|
||||
surfView.getApplicationWindowToken(),
|
||||
InputMethodManager.SHOW_FORCED, 0);
|
||||
inputMethodManager.toggleSoftInputFromWindow(surfView.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
|
||||
return true;
|
||||
} else if (command.equals("inputbox")) {
|
||||
String title = "Input";
|
||||
@@ -1246,19 +1231,19 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
// permission.
|
||||
if (surfView != null) {
|
||||
switch (milliseconds) {
|
||||
case -1:
|
||||
surfView.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
||||
break;
|
||||
case -2:
|
||||
surfView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
||||
break;
|
||||
case -3:
|
||||
surfView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
||||
break;
|
||||
default:
|
||||
// Requires the vibrate permission, which we don't have, so disabled.
|
||||
// vibrator.vibrate(milliseconds);
|
||||
break;
|
||||
case -1:
|
||||
surfView.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
||||
break;
|
||||
case -2:
|
||||
surfView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
||||
break;
|
||||
case -3:
|
||||
surfView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
||||
break;
|
||||
default:
|
||||
// Requires the vibrate permission, which we don't have, so disabled.
|
||||
// vibrator.vibrate(milliseconds);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "Can't vibrate, no surface view");
|
||||
@@ -1323,21 +1308,17 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
public void recreate()
|
||||
{
|
||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
|
||||
{
|
||||
super.recreate();
|
||||
}
|
||||
else
|
||||
{
|
||||
startActivity(getIntent());
|
||||
finish();
|
||||
}
|
||||
}
|
||||
public void recreate() {
|
||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
super.recreate();
|
||||
} else {
|
||||
startActivity(getIntent());
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
package org.ppsspp.ppsspp;
|
||||
|
||||
|
||||
// Note that the display* methods are in NativeRenderer.java
|
||||
|
||||
public class NativeApp {
|
||||
public final static int DEVICE_ID_DEFAULT = 0;
|
||||
public final static int DEVICE_ID_KEYBOARD = 1;
|
||||
public final static int DEVICE_ID_MOUSE = 2;
|
||||
public final static int DEVICE_ID_PAD_0 = 10;
|
||||
public static final int DEVICE_ID_DEFAULT = 0;
|
||||
public static final int DEVICE_ID_KEYBOARD = 1;
|
||||
public static final int DEVICE_ID_MOUSE = 2;
|
||||
public static final int DEVICE_ID_PAD_0 = 10;
|
||||
|
||||
public final static int DEVICE_TYPE_MOBILE = 0;
|
||||
public final static int DEVICE_TYPE_TV = 1;
|
||||
public final static int DEVICE_TYPE_DESKTOP = 2;
|
||||
public static final int DEVICE_TYPE_MOBILE = 0;
|
||||
public static final int DEVICE_TYPE_TV = 1;
|
||||
public static final int DEVICE_TYPE_DESKTOP = 2;
|
||||
|
||||
public static native void init(String model, int deviceType, String languageRegion, String apkPath, String dataDir, String externalDir, String libraryDir, String cacheDir, String shortcutParam, int androidVersion, String board);
|
||||
public static native void audioInit();
|
||||
@@ -56,4 +55,3 @@ public class NativeApp {
|
||||
|
||||
public static native void pushCameraImage(byte[] image);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package org.ppsspp.ppsspp;
|
||||
|
||||
import javax.microedition.khronos.egl.EGL10;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.egl.EGLDisplay;
|
||||
|
||||
import android.opengl.GLSurfaceView.EGLConfigChooser;
|
||||
import android.util.Log;
|
||||
import javax.microedition.khronos.egl.EGL10;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.egl.EGLDisplay;
|
||||
|
||||
public class NativeEGLConfigChooser implements EGLConfigChooser {
|
||||
private static final String TAG = "NativeEGLConfigChooser";
|
||||
@@ -24,6 +23,7 @@ public class NativeEGLConfigChooser implements EGLConfigChooser {
|
||||
public int stencil;
|
||||
public int depth;
|
||||
public int samples;
|
||||
|
||||
public void Log() {
|
||||
Log.i(TAG, "EGLConfig: red=" + red + " green=" + green + " blue=" + blue + " alpha=" + alpha + " depth=" + depth + " stencil=" + stencil + " samples=" + samples);
|
||||
}
|
||||
@@ -79,22 +79,22 @@ public class NativeEGLConfigChooser implements EGLConfigChooser {
|
||||
};
|
||||
|
||||
int[] num_config = new int[1];
|
||||
if (!egl.eglChooseConfig(display, configSpec, null, 0, num_config)) {
|
||||
throw new IllegalArgumentException("eglChooseConfig failed when counting");
|
||||
}
|
||||
if (!egl.eglChooseConfig(display, configSpec, null, 0, num_config)) {
|
||||
throw new IllegalArgumentException("eglChooseConfig failed when counting");
|
||||
}
|
||||
|
||||
int numConfigs = num_config[0];
|
||||
Log.i(TAG, "There are " + numConfigs + " egl configs");
|
||||
if (numConfigs <= 0) {
|
||||
throw new IllegalArgumentException("No configs match configSpec");
|
||||
}
|
||||
int numConfigs = num_config[0];
|
||||
Log.i(TAG, "There are " + numConfigs + " egl configs");
|
||||
if (numConfigs <= 0) {
|
||||
throw new IllegalArgumentException("No configs match configSpec");
|
||||
}
|
||||
|
||||
EGLConfig[] eglConfigs = new EGLConfig[numConfigs];
|
||||
if (!egl.eglChooseConfig(display, configSpec, eglConfigs, numConfigs, num_config)) {
|
||||
throw new IllegalArgumentException("eglChooseConfig failed when retrieving");
|
||||
}
|
||||
throw new IllegalArgumentException("eglChooseConfig failed when retrieving");
|
||||
}
|
||||
|
||||
ConfigAttribs [] configs = getConfigAttribs(egl, display, eglConfigs);
|
||||
ConfigAttribs[] configs = getConfigAttribs(egl, display, eglConfigs);
|
||||
|
||||
ConfigAttribs chosen = null;
|
||||
|
||||
@@ -103,7 +103,6 @@ public class NativeEGLConfigChooser implements EGLConfigChooser {
|
||||
configs[i].Log();
|
||||
}
|
||||
|
||||
|
||||
// We now ignore destination alpha as a workaround for the Mali issue
|
||||
// where we get badly composited if we use it.
|
||||
// Though, that may be possible to fix by using EGL10.EGL_TRANSPARENT_TYPE, EGL10.EGL_NONE.
|
||||
@@ -201,12 +200,11 @@ public class NativeEGLConfigChooser implements EGLConfigChooser {
|
||||
}
|
||||
|
||||
if (chosen == null) {
|
||||
throw new IllegalArgumentException("Failed to find a valid EGL config");
|
||||
throw new IllegalArgumentException("Failed to find a valid EGL config");
|
||||
}
|
||||
|
||||
Log.i(TAG, "Final chosen config: ");
|
||||
chosen.Log();
|
||||
return chosen.config;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,8 +18,6 @@ import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import com.bda.controller.*;
|
||||
|
||||
public class NativeGLView extends GLSurfaceView implements SensorEventListener, ControllerListener {
|
||||
@@ -37,7 +35,7 @@ public class NativeGLView extends GLSurfaceView implements SensorEventListener,
|
||||
super(activity);
|
||||
mActivity = activity;
|
||||
|
||||
mSensorManager = (SensorManager)activity.getSystemService(Activity.SENSOR_SERVICE);
|
||||
mSensorManager = (SensorManager) activity.getSystemService(Activity.SENSOR_SERVICE);
|
||||
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
|
||||
|
||||
mController = Controller.getInstance(activity);
|
||||
@@ -89,7 +87,7 @@ public class NativeGLView extends GLSurfaceView implements SensorEventListener,
|
||||
if (code != 0) {
|
||||
if (canReadToolType) {
|
||||
int tool = getToolType(ev, i);
|
||||
code |= tool << 10; // We use the Android tool type codes
|
||||
code |= tool << 10; // We use the Android tool type codes
|
||||
}
|
||||
// Can't use || due to short circuit evaluation
|
||||
numTouchesHandled += NativeApp.touch(ev.getX(i), ev.getY(i), code, pid) ? 1 : 0;
|
||||
@@ -161,7 +159,7 @@ public class NativeGLView extends GLSurfaceView implements SensorEventListener,
|
||||
}
|
||||
}
|
||||
|
||||
boolean repeat = false; // Moga has no repeats?
|
||||
boolean repeat = false; // Moga has no repeats?
|
||||
switch (event.getAction()) {
|
||||
case KeyEvent.ACTION_DOWN:
|
||||
NativeApp.keyDown(NativeApp.DEVICE_ID_PAD_0, event.getKeyCode(), repeat);
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
package org.ppsspp.ppsspp;
|
||||
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.util.Log;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
import android.graphics.Point;
|
||||
import android.opengl.GLES20;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
|
||||
public class NativeRenderer implements GLSurfaceView.Renderer {
|
||||
private static String TAG = "NativeRenderer";
|
||||
private NativeActivity mActivity;
|
||||
@@ -35,12 +30,13 @@ public class NativeRenderer implements GLSurfaceView.Renderer {
|
||||
// Actually, it seems that it is here we should recreate lost GL objects.
|
||||
displayInit();
|
||||
}
|
||||
|
||||
|
||||
public void onSurfaceChanged(GL10 unused, int width, int height) {
|
||||
}
|
||||
|
||||
// Note: This also means "device lost" and you should reload
|
||||
// all buffered objects.
|
||||
public native void displayInit();
|
||||
// all buffered objects.
|
||||
public native void displayInit();
|
||||
|
||||
public native void displayRender();
|
||||
}
|
||||
@@ -13,12 +13,9 @@ import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
// import android.os.Build;
|
||||
// import android.util.Log;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.SurfaceView;
|
||||
|
||||
import com.bda.controller.*;
|
||||
|
||||
public class NativeSurfaceView extends SurfaceView implements SensorEventListener, ControllerListener {
|
||||
@@ -35,7 +32,7 @@ public class NativeSurfaceView extends SurfaceView implements SensorEventListene
|
||||
|
||||
Log.i(TAG, "NativeSurfaceView");
|
||||
|
||||
mSensorManager = (SensorManager)activity.getSystemService(Activity.SENSOR_SERVICE);
|
||||
mSensorManager = (SensorManager) activity.getSystemService(Activity.SENSOR_SERVICE);
|
||||
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
|
||||
|
||||
mController = Controller.getInstance(activity);
|
||||
@@ -62,8 +59,6 @@ public class NativeSurfaceView extends SurfaceView implements SensorEventListene
|
||||
boolean canReadToolType = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
|
||||
|
||||
int numTouchesHandled = 0;
|
||||
//float scaleX = (float)mActivity.getRenderer().getDpiScaleX();
|
||||
//float scaleY = (float)mActivity.getRenderer().getDpiScaleY();
|
||||
for (int i = 0; i < ev.getPointerCount(); i++) {
|
||||
int pid = ev.getPointerId(i);
|
||||
int code = 0;
|
||||
@@ -92,7 +87,7 @@ public class NativeSurfaceView extends SurfaceView implements SensorEventListene
|
||||
if (code != 0) {
|
||||
if (canReadToolType) {
|
||||
int tool = getToolType(ev, i);
|
||||
code |= tool << 10; // We use the Android tool type codes
|
||||
code |= tool << 10; // We use the Android tool type codes
|
||||
}
|
||||
// Can't use || due to short circuit evaluation
|
||||
numTouchesHandled += NativeApp.touch(ev.getX(i), ev.getY(i), code, pid) ? 1 : 0;
|
||||
@@ -157,7 +152,7 @@ public class NativeSurfaceView extends SurfaceView implements SensorEventListene
|
||||
}
|
||||
}
|
||||
|
||||
boolean repeat = false; // Moga has no repeats?
|
||||
boolean repeat = false; // Moga has no repeats?
|
||||
switch (event.getAction()) {
|
||||
case KeyEvent.ACTION_DOWN:
|
||||
NativeApp.keyDown(NativeApp.DEVICE_ID_PAD_0, event.getKeyCode(), repeat);
|
||||
|
||||
@@ -55,7 +55,7 @@ public class PowerSaveModeReceiver extends BroadcastReceiver {
|
||||
|
||||
@TargetApi(21)
|
||||
private static boolean getNativePowerSaving(final Context context) {
|
||||
final PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
|
||||
final PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
return pm.isPowerSaveMode();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class PpssppActivity extends NativeActivity {
|
||||
private static final String TAG = "PpssppActivity";
|
||||
@@ -58,7 +57,6 @@ public class PpssppActivity extends NativeActivity {
|
||||
}
|
||||
Looper.loop();
|
||||
}
|
||||
|
||||
}.start();
|
||||
|
||||
try {
|
||||
@@ -95,7 +93,6 @@ public class PpssppActivity extends NativeActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
|
||||
// called by the C++ code through JNI. Dispatch anything we can't directly handle
|
||||
// on the gfx thread to the UI thread.
|
||||
public void postCommand(String command, String parameter) {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.ppsspp.ppsspp;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Intent;
|
||||
@@ -11,10 +9,11 @@ import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* This class will respond to android.intent.action.CREATE_SHORTCUT intent from
|
||||
* launcher homescreen. Register this class in AndroidManifest.xml.
|
||||
* This class will respond to android.intent.action.CREATE_SHORTCUT intent from launcher homescreen.
|
||||
* Register this class in AndroidManifest.xml.
|
||||
*/
|
||||
public class ShortcutActivity extends Activity {
|
||||
private static final String TAG = "PPSSPP";
|
||||
@@ -24,9 +23,7 @@ public class ShortcutActivity extends Activity {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Show file selector dialog here.
|
||||
SimpleFileChooser fileDialog = new SimpleFileChooser(this,
|
||||
Environment.getExternalStorageDirectory(),
|
||||
onFileSelectedListener);
|
||||
SimpleFileChooser fileDialog = new SimpleFileChooser(this, Environment.getExternalStorageDirectory(), onFileSelectedListener);
|
||||
fileDialog.showDialog();
|
||||
}
|
||||
|
||||
@@ -56,10 +53,8 @@ public class ShortcutActivity extends Activity {
|
||||
Intent responseIntent = new Intent();
|
||||
responseIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
||||
responseIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
|
||||
ShortcutIconResource iconResource = Intent.ShortcutIconResource
|
||||
.fromContext(this, R.drawable.ic_launcher);
|
||||
responseIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
|
||||
iconResource);
|
||||
ShortcutIconResource iconResource = ShortcutIconResource.fromContext(this, R.drawable.ic_launcher);
|
||||
responseIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
|
||||
|
||||
setResult(RESULT_OK, responseIntent);
|
||||
|
||||
@@ -97,5 +92,4 @@ public class ShortcutActivity extends Activity {
|
||||
respondToShortcutRequest(file.getAbsolutePath());
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,21 +1,17 @@
|
||||
package org.ppsspp.ppsspp;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Environment;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Environment;
|
||||
|
||||
/**
|
||||
* Simple dialog to pick file.
|
||||
*/
|
||||
/** Simple dialog to pick file. */
|
||||
public class SimpleFileChooser {
|
||||
|
||||
public interface FileSelectedListener {
|
||||
void onFileSelected(File file);
|
||||
}
|
||||
@@ -27,8 +23,7 @@ public class SimpleFileChooser {
|
||||
private String[] mFileList;
|
||||
private File mCurrentPath;
|
||||
|
||||
public SimpleFileChooser(Activity activity, File path,
|
||||
FileSelectedListener listener) {
|
||||
public SimpleFileChooser(Activity activity, File path, FileSelectedListener listener) {
|
||||
this.mActivity = activity;
|
||||
this.mFileListener = listener;
|
||||
if (!path.exists())
|
||||
@@ -83,8 +78,7 @@ public class SimpleFileChooser {
|
||||
return 1;
|
||||
else
|
||||
// when both are folders or both are files, sort by name
|
||||
return file1.getName().toUpperCase()
|
||||
.compareTo(file2.getName().toUpperCase());
|
||||
return file1.getName().toUpperCase().compareTo(file2.getName().toUpperCase());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -107,5 +101,4 @@ public class SimpleFileChooser {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,21 +1,22 @@
|
||||
package org.ppsspp.ppsspp;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.*;
|
||||
import android.util.Log;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class TextRenderer {
|
||||
private static Paint p;
|
||||
private static Paint bg;
|
||||
private static Typeface robotoCondensed;
|
||||
private static final String TAG = "TextRenderer";
|
||||
|
||||
static {
|
||||
p = new Paint(Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
|
||||
p.setColor(Color.WHITE);
|
||||
bg = new Paint();
|
||||
bg.setColor(Color.BLACK);
|
||||
}
|
||||
|
||||
public static void init(Context ctx) {
|
||||
robotoCondensed = Typeface.createFromAsset(ctx.getAssets(), "Roboto-Condensed.ttf");
|
||||
if (robotoCondensed != null) {
|
||||
@@ -25,23 +26,25 @@ public class TextRenderer {
|
||||
Log.e(TAG, "Failed to load Roboto Condensed");
|
||||
}
|
||||
}
|
||||
|
||||
private static Point measureLine(String string, double textSize) {
|
||||
int w;
|
||||
if (string.length() > 0) {
|
||||
p.setTextSize((float)textSize);
|
||||
w = (int)p.measureText(string);
|
||||
// Round width up to even already here to avoid annoyances from odd-width 16-bit textures which
|
||||
// OpenGL does not like - each line must be 4-byte aligned
|
||||
p.setTextSize((float) textSize);
|
||||
w = (int) p.measureText(string);
|
||||
// Round width up to even already here to avoid annoyances from odd-width 16-bit textures
|
||||
// which OpenGL does not like - each line must be 4-byte aligned
|
||||
w = (w + 5) & ~1;
|
||||
} else {
|
||||
w = 1;
|
||||
}
|
||||
int h = (int)(p.descent() - p.ascent() + 2.0f);
|
||||
int h = (int) (p.descent() - p.ascent() + 2.0f);
|
||||
Point p = new Point();
|
||||
p.x = w;
|
||||
p.y = h;
|
||||
return p;
|
||||
}
|
||||
|
||||
private static Point measure(String string, double textSize) {
|
||||
String lines[] = string.replaceAll("\\r", "").split("\n");
|
||||
Point total = new Point();
|
||||
@@ -50,13 +53,15 @@ public class TextRenderer {
|
||||
Point sz = measureLine(line, textSize);
|
||||
total.x = Math.max(sz.x, total.x);
|
||||
}
|
||||
total.y = (int)(p.descent() - p.ascent()) * lines.length + 2;
|
||||
total.y = (int) (p.descent() - p.ascent()) * lines.length + 2;
|
||||
return total;
|
||||
}
|
||||
|
||||
public static int measureText(String string, double textSize) {
|
||||
Point s = measure(string, textSize);
|
||||
return (s.x << 16) | s.y;
|
||||
}
|
||||
|
||||
public static int[] renderText(String string, double textSize) {
|
||||
Point s = measure(string, textSize);
|
||||
|
||||
@@ -79,7 +84,7 @@ public class TextRenderer {
|
||||
y += p.descent() - p.ascent();
|
||||
}
|
||||
|
||||
int [] pixels = new int[w * h];
|
||||
int[] pixels = new int[w * h];
|
||||
bmp.getPixels(pixels, 0, w, 0, 0, w, h);
|
||||
bmp.recycle();
|
||||
return pixels;
|
||||
|
||||
Reference in new issue
Block a user