Merge branch 'sdl_android' of github.com:pelya/commandergenius into sdl_android

Conflicts:
	project/jni/application/commandergenius/commandergenius
This commit is contained in:
Gerhard Stein
2013-09-20 19:45:39 +02:00
30 changed files with 1803 additions and 95 deletions

View File

@@ -317,7 +317,7 @@ class DataDownloader extends Thread
stream1.close();
} catch( Exception e ) {
try {
stream1 = Parent.getAssets().open(url + "00");
stream1 = Parent.getAssets().open(url + "000");
stream1.close();
} catch( Exception ee ) {
Log.i("SDL", "Failed to open file in assets: " + url);
@@ -367,8 +367,8 @@ class DataDownloader extends Thread
while( true )
{
try {
// Make string ".zip00", ".zip01" etc for multipart archives
String url1 = url + String.format("%02d", multipartCounter);
// Make string ".zip000", ".zip001" etc for multipart archives
String url1 = url + String.format("%03d", multipartCounter);
CountingInputStream stream1 = new CountingInputStream(Parent.getAssets().open(url1), 8192);
while( stream1.skip(65536) > 0 ) { };
totalLen += stream1.getBytesRead();
@@ -420,6 +420,8 @@ class DataDownloader extends Thread
}
}
long updateStatusTime = 0;
if(DoNotUnzip)
{
Log.i("SDL", "Saving file '" + path + "'");
@@ -477,7 +479,11 @@ class DataDownloader extends Thread
float percent = 0.0f;
if( totalLen > 0 )
percent = (stream.getBytesRead() + partialDownloadLen) * 100.0f / (totalLen + partialDownloadLen);
Status.setText( downloadCount + "/" + downloadTotal + ": " + res.getString(R.string.dl_progress, percent, path) );
if( System.currentTimeMillis() > updateStatusTime + 1000 )
{
updateStatusTime = System.currentTimeMillis();
Status.setText( downloadCount + "/" + downloadTotal + ": " + res.getString(R.string.dl_progress, percent, path) );
}
}
out.flush();
out.close();
@@ -547,7 +553,11 @@ class DataDownloader extends Thread
Log.i("SDL", "File '" + path + "' exists and passed CRC check - not overwriting it");
if( totalLen > 0 )
percent = stream.getBytesRead() * 100.0f / totalLen;
Status.setText( downloadCount + "/" + downloadTotal + ": " + res.getString(R.string.dl_progress, percent, path) );
if( System.currentTimeMillis() > updateStatusTime + 1000 )
{
updateStatusTime = System.currentTimeMillis();
Status.setText( downloadCount + "/" + downloadTotal + ": " + res.getString(R.string.dl_progress, percent, path) );
}
continue;
} catch( Exception e ) { }
@@ -567,7 +577,11 @@ class DataDownloader extends Thread
if( totalLen > 0 )
percent = stream.getBytesRead() * 100.0f / totalLen;
Status.setText( downloadCount + "/" + downloadTotal + ": " + res.getString(R.string.dl_progress, percent, path) );
if( System.currentTimeMillis() > updateStatusTime + 1000 )
{
updateStatusTime = System.currentTimeMillis();
Status.setText( downloadCount + "/" + downloadTotal + ": " + res.getString(R.string.dl_progress, percent, path) );
}
try {
int len = zip.read(buf);
@@ -580,7 +594,11 @@ class DataDownloader extends Thread
percent = 0.0f;
if( totalLen > 0 )
percent = stream.getBytesRead() * 100.0f / totalLen;
Status.setText( downloadCount + "/" + downloadTotal + ": " + res.getString(R.string.dl_progress, percent, path) );
if( System.currentTimeMillis() > updateStatusTime + 1000 )
{
updateStatusTime = System.currentTimeMillis();
Status.setText( downloadCount + "/" + downloadTotal + ": " + res.getString(R.string.dl_progress, percent, path) );
}
}
out.flush();
out.close();

View File

@@ -121,4 +121,5 @@ class Globals
public static boolean BrokenLibCMessageShown = false;
// Gyroscope calibration
public static float gyro_x1, gyro_x2, gyro_xc, gyro_y1, gyro_y2, gyro_yc, gyro_z1, gyro_z2, gyro_zc;
public static boolean OuyaEmulation = false; // For debugging
}

View File

@@ -38,6 +38,7 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.FrameLayout;
import android.graphics.drawable.Drawable;
import android.graphics.Color;
import android.content.res.Configuration;
import android.app.Notification;
import android.app.NotificationManager;
@@ -70,6 +71,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import java.util.concurrent.Semaphore;
import android.content.pm.ActivityInfo;
import android.view.Display;
@@ -218,7 +220,8 @@ public class MainActivity extends Activity
if( Parent._tv == null )
{
Parent._tv = new TextView(Parent);
Parent._tv.setMaxLines(2);
Parent._tv.setMaxLines(2); // To show some long texts on smaller devices
Parent._tv.setMinLines(2); // Otherwise the background picture is getting resized at random, which does not look good
Parent._tv.setText(R.string.init);
Parent._layout2.addView(Parent._tv);
}
@@ -404,6 +407,7 @@ public class MainActivity extends Activity
{
_inputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
_inputManager.showSoftInput(mGLView, InputMethodManager.SHOW_FORCED);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
}
public void showScreenKeyboard(final String oldText, boolean sendBackspace)
@@ -420,9 +424,20 @@ public class MainActivity extends Activity
MainActivity _parent;
boolean sendBackspace;
simpleKeyListener(MainActivity parent, boolean sendBackspace) { _parent = parent; this.sendBackspace = sendBackspace; };
public boolean onKey(View v, int keyCode, KeyEvent event)
public boolean onKey(View v, int keyCode, KeyEvent event)
{
if ((event.getAction() == KeyEvent.ACTION_UP) && ((keyCode == KeyEvent.KEYCODE_ENTER) || (keyCode == KeyEvent.KEYCODE_BACK)))
if ((event.getAction() == KeyEvent.ACTION_UP) && (
keyCode == KeyEvent.KEYCODE_ENTER ||
keyCode == KeyEvent.KEYCODE_BACK ||
keyCode == KeyEvent.KEYCODE_MENU ||
keyCode == KeyEvent.KEYCODE_BUTTON_A ||
keyCode == KeyEvent.KEYCODE_BUTTON_B ||
keyCode == KeyEvent.KEYCODE_BUTTON_X ||
keyCode == KeyEvent.KEYCODE_BUTTON_Y ||
keyCode == KeyEvent.KEYCODE_BUTTON_1 ||
keyCode == KeyEvent.KEYCODE_BUTTON_2 ||
keyCode == KeyEvent.KEYCODE_BUTTON_3 ||
keyCode == KeyEvent.KEYCODE_BUTTON_4 ))
{
_parent.hideScreenKeyboard();
return true;
@@ -475,14 +490,41 @@ public class MainActivity extends Activity
String hint = _screenKeyboardHintMessage;
_screenKeyboard.setHint(hint != null ? hint : getString(R.string.text_edit_click_here));
_screenKeyboard.setText(oldText);
_screenKeyboard.setSelection(_screenKeyboard.getText().length());
_screenKeyboard.setOnKeyListener(new simpleKeyListener(this, sendBackspace));
_screenKeyboard.setBackgroundColor(Color.BLACK); // Full opaque - do not show semi-transparent edit box, it's confusing
_screenKeyboard.setTextColor(Color.WHITE); // Just to be sure about gamma
if( isRunningOnOUYA() )
_screenKeyboard.setPadding(100, 100, 100, 100); // Bad bad HDMI TVs all have cropped borders
_videoLayout.addView(_screenKeyboard);
//_screenKeyboard.setKeyListener(new TextKeyListener(TextKeyListener.Capitalize.NONE, false));
_screenKeyboard.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
_screenKeyboard.setInputType(InputType.TYPE_CLASS_TEXT);
_screenKeyboard.setFocusableInTouchMode(true);
_screenKeyboard.setFocusable(true);
_screenKeyboard.requestFocus();
_inputManager.showSoftInput(_screenKeyboard, InputMethodManager.SHOW_FORCED);
_inputManager.showSoftInput(_screenKeyboard, InputMethodManager.SHOW_IMPLICIT);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
// Hack to try to force on-screen keyboard
final EditText keyboard = _screenKeyboard;
keyboard.postDelayed( new Runnable()
{
public void run()
{
keyboard.requestFocus();
//_inputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
_inputManager.showSoftInput(keyboard, InputMethodManager.SHOW_FORCED);
// Hack from Stackoverflow, to force text input on Ouya
keyboard.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN , 0, 0, 0));
keyboard.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP , 0, 0, 0));
keyboard.postDelayed( new Runnable()
{
public void run()
{
keyboard.setSelection(keyboard.getText().length());
}
}, 100 );
}
}, 500 );
};
public void hideScreenKeyboard()
@@ -1045,7 +1087,7 @@ public class MainActivity extends Activity
return true;
} catch (PackageManager.NameNotFoundException e) {
}
return false;
return Globals.OuyaEmulation;
}
public boolean isCurrentOrientationHorizontal()

View File

@@ -170,6 +170,8 @@ class Settings
out.writeFloat(Globals.gyro_z2);
out.writeFloat(Globals.gyro_zc);
out.writeBoolean(Globals.OuyaEmulation);
out.close();
settingsLoaded = true;
@@ -349,6 +351,8 @@ class Settings
Globals.gyro_z2 = settingsFile.readFloat();
Globals.gyro_zc = settingsFile.readFloat();
Globals.OuyaEmulation = settingsFile.readBoolean();
settingsLoaded = true;
Log.i("SDL", "libSDL: Settings.Load(): loaded settings successfully");
@@ -514,6 +518,8 @@ class Settings
for( int i = 0; i < Globals.ScreenKbControlsShown.length; i++ )
if( Globals.ScreenKbControlsShown[i] )
screenKbReallyUsed = true;
if( p.isRunningOnOUYA() )
screenKbReallyUsed = false;
if( screenKbReallyUsed )
{
nativeSetTouchscreenKeyboardUsed();

View File

@@ -332,6 +332,7 @@ class SettingsMenuMisc extends SettingsMenu
static class VideoSettingsConfig extends Menu
{
static int debugMenuShowCount = 0;
String title(final MainActivity p)
{
return p.getResources().getString(R.string.video);
@@ -339,6 +340,7 @@ class SettingsMenuMisc extends SettingsMenu
//boolean enabled() { return true; };
void run (final MainActivity p)
{
debugMenuShowCount++;
CharSequence[] items = {
p.getResources().getString(R.string.pointandclick_keepaspectratio),
p.getResources().getString(R.string.video_smooth)
@@ -391,6 +393,48 @@ class SettingsMenuMisc extends SettingsMenu
}
});
builder.setPositiveButton(p.getResources().getString(R.string.ok), new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int item)
{
dialog.dismiss();
if( debugMenuShowCount > 5 || Globals.OuyaEmulation )
showDebugMenu(p);
else
goBack(p);
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener()
{
public void onCancel(DialogInterface dialog)
{
goBack(p);
}
});
AlertDialog alert = builder.create();
alert.setOwnerActivity(p);
alert.show();
}
void showDebugMenu (final MainActivity p)
{
CharSequence[] items = {
"OUYA emulation"
};
boolean defaults[] = {
Globals.OuyaEmulation,
};
AlertDialog.Builder builder = new AlertDialog.Builder(p);
builder.setTitle("Debug settings");
builder.setMultiChoiceItems(items, defaults, new DialogInterface.OnMultiChoiceClickListener()
{
public void onClick(DialogInterface dialog, int item, boolean isChecked)
{
if( item == 0 )
Globals.OuyaEmulation = isChecked;
}
});
builder.setPositiveButton(p.getResources().getString(R.string.ok), new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int item)
{
@@ -425,6 +469,8 @@ class SettingsMenuMisc extends SettingsMenu
{
String readmes[] = Globals.ReadmeText.split("\\^");
String lang = new String(Locale.getDefault().getLanguage()) + ":";
if( p.isRunningOnOUYA() )
lang = "ouya:";
String readme = readmes[0];
String buttonName = "", buttonUrl = "";
for( String r: readmes )

View File

@@ -112,6 +112,8 @@ abstract class DifferentTouchInput
Log.i("SDL", "Device model: " + android.os.Build.MODEL);
if( android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH )
{
if( DetectCrappyDragonRiseDatexGamepad() )
return CrappyDragonRiseDatexGamepadInputWhichNeedsItsOwnHandlerBecauseImTooCheapAndStupidToBuyProperGamepad.Holder.sInstance;
return IcsTouchInput.Holder.sInstance;
}
if( android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD )
@@ -131,6 +133,13 @@ abstract class DifferentTouchInput
}
}
}
private static boolean DetectCrappyDragonRiseDatexGamepad()
{
if( CrappyDragonRiseDatexGamepadInputWhichNeedsItsOwnHandlerBecauseImTooCheapAndStupidToBuyProperGamepad.Holder.sInstance == null )
return false;
return CrappyDragonRiseDatexGamepadInputWhichNeedsItsOwnHandlerBecauseImTooCheapAndStupidToBuyProperGamepad.Holder.sInstance.detect();
}
private static class SingleTouchInput extends DifferentTouchInput
{
private static class Holder
@@ -351,7 +360,6 @@ abstract class DifferentTouchInput
// Joysticks are supported since Honeycomb, but I don't care about it, because very little devices have it
if( (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK )
{
// event.getAxisValue(AXIS_HAT_X) and event.getAxisValue(AXIS_HAT_Y) are joystick arrow keys, they also send keyboard events
DemoGLSurfaceView.nativeGamepadAnalogJoystickInput(
event.getAxisValue(MotionEvent.AXIS_X), event.getAxisValue(MotionEvent.AXIS_Y),
event.getAxisValue(MotionEvent.AXIS_Z), event.getAxisValue(MotionEvent.AXIS_RZ),
@@ -369,6 +377,69 @@ abstract class DifferentTouchInput
super.processGenericEvent(event);
}
}
private static class CrappyDragonRiseDatexGamepadInputWhichNeedsItsOwnHandlerBecauseImTooCheapAndStupidToBuyProperGamepad extends IcsTouchInput
{
private static class Holder
{
private static final CrappyDragonRiseDatexGamepadInputWhichNeedsItsOwnHandlerBecauseImTooCheapAndStupidToBuyProperGamepad sInstance = new CrappyDragonRiseDatexGamepadInputWhichNeedsItsOwnHandlerBecauseImTooCheapAndStupidToBuyProperGamepad();
}
float hatX = 0.0f, hatY = 0.0f;
public void processGenericEvent(final MotionEvent event)
{
// Joysticks are supported since Honeycomb, but I don't care about it, because very little devices have it
if( (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK )
{
// event.getAxisValue(AXIS_HAT_X) and event.getAxisValue(AXIS_HAT_Y) are joystick arrow keys, they also send keyboard events
DemoGLSurfaceView.nativeGamepadAnalogJoystickInput(
event.getAxisValue(MotionEvent.AXIS_X), event.getAxisValue(MotionEvent.AXIS_Y),
event.getAxisValue(MotionEvent.AXIS_RX), event.getAxisValue(MotionEvent.AXIS_RZ),
0, 0);
if( event.getAxisValue(MotionEvent.AXIS_HAT_X) != hatX )
{
hatX = event.getAxisValue(MotionEvent.AXIS_HAT_X);
if( hatX == 0.0f )
{
DemoGLSurfaceView.nativeKey(KeyEvent.KEYCODE_DPAD_LEFT, 0);
DemoGLSurfaceView.nativeKey(KeyEvent.KEYCODE_DPAD_RIGHT, 0);
}
else
DemoGLSurfaceView.nativeKey(hatX < 0.0f ? KeyEvent.KEYCODE_DPAD_LEFT : KeyEvent.KEYCODE_DPAD_RIGHT, 1);
}
if( event.getAxisValue(MotionEvent.AXIS_HAT_Y) != hatY )
{
hatY = event.getAxisValue(MotionEvent.AXIS_HAT_Y);
if( hatY == 0.0f )
{
DemoGLSurfaceView.nativeKey(KeyEvent.KEYCODE_DPAD_UP, 0);
DemoGLSurfaceView.nativeKey(KeyEvent.KEYCODE_DPAD_DOWN, 0);
}
else
DemoGLSurfaceView.nativeKey(hatY < 0.0f ? KeyEvent.KEYCODE_DPAD_UP : KeyEvent.KEYCODE_DPAD_DOWN, 1);
}
return;
}
super.processGenericEvent(event);
}
public boolean detect()
{
int[] devIds = InputDevice.getDeviceIds();
for( int id : devIds )
{
InputDevice device = InputDevice.getDevice(id);
if( device == null )
continue;
System.out.println("libSDL: input device ID " + id + " type " + device.getSources() + " name " + device.getName() );
if( (device.getSources() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD &&
(device.getSources() & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK &&
device.getName().indexOf("DragonRise Inc") == 0 )
{
System.out.println("libSDL: Detected crappy DragonRise gamepad, enabling special hack for it. Please press button labeled 'Analog', otherwise it won't work, because it's cheap and crappy");
return true;
}
}
return false;
}
}
}