Android 1.5 support

This commit is contained in:
mittorn 2016-05-06 08:58:01 +00:00
parent 11a29ac213
commit 126433c42c
10 changed files with 141 additions and 83 deletions

View file

@ -4,17 +4,21 @@
#APP_STL := stlport_static
XASH_SDL ?= 0
XASH_LEGACY ?= 0
ifeq ($(XASH_SDL),1)
APP_PLATFORM := android-12
else
ifneq ($(XASH_LEGACY),1)
APP_PLATFORM := android-8
else
APP_PLATFORM := android-3
endif
endif
CFLAGS_OPT := -O3 -fomit-frame-pointer -ggdb -funsafe-math-optimizations -ftree-vectorize -fgraphite-identity -floop-interchange -funsafe-loop-optimizations -finline-limit=1024
CFLAGS_OPT_ARM := -mthumb -mfpu=neon -mcpu=cortex-a9 -pipe -mvectorize-with-neon-quad -DVECTORIZE_SINCOS -fPIC
CFLAGS_OPT_ARMv5 :=-march=armv6 -mfpu=vfp -marm -pipe
CFLAGS_OPT_ARMv5 :=-march=armv5te -marm -pipe -msoft-float
CFLAGS_OPT_X86 := -mtune=atom -march=atom -mssse3 -mfpmath=sse -funroll-loops -pipe -DVECTORIZE_SINCOS
CFLAGS_HARDFP := -D_NDK_MATH_NO_SOFTFP=1 -mhard-float -mfloat-abi=hard -DLOAD_HARDFP -DSOFTFP_LINK
APPLICATIONMK_PATH = $(call my-dir)

View file

@ -19,7 +19,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/folder"
android:id="@+id/button2"
android:id="@+id/button_fpicker_select"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="onFileClick" />

View file

@ -224,7 +224,7 @@
<Button
android:id="@+id/button"
android:id="@+id/button_shortcut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
@ -263,7 +263,7 @@
android:orientation="horizontal">
<Button
android:id="@+id/button"
android:id="@+id/button_about"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"

View file

@ -18,6 +18,7 @@ import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.Button;
import java.io.File;
import java.text.DateFormat;
@ -32,15 +33,22 @@ public class FPicker extends Activity {
private File currentDir;
private FileArrayAdapter adapter;
static ListView delta;
public static final int sdk = Integer.valueOf(Build.VERSION.SDK);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if ( Build.VERSION.SDK_INT >= 21 )
if ( sdk >= 21 )
super.setTheme( 0x01030224 );
setContentView(R.layout.activity_fpicker);
String path = Environment.getExternalStorageDirectory().toString();
currentDir = new File(path);
((Button)findViewById( R.id.button_fpicker_select )).setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
onFileClick(v);
}
});
fill(currentDir);
}

View file

@ -3,12 +3,45 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import java.io.FileOutputStream;
import java.io.InputStream;
import android.content.SharedPreferences;
public class InstallReceiver extends BroadcastReceiver {
private static final String TAG = "XASH3D";
@Override
public void onReceive(Context context, Intent arg1) {
Log.d( TAG, "Install received, extracting PAK" );
org.libsdl.app.SDLActivity.extractPAK( context, true );
if( context.getPackageName() == arg1.getData().getEncodedSchemeSpecificPart() )
extractPAK(context, true);
}
public static SharedPreferences mPref = null;
private static final int PAK_VERSION = 5;
public static void extractPAK(Context context, Boolean force) {
InputStream is = null;
FileOutputStream os = null;
try {
if( mPref == null )
mPref = context.getSharedPreferences("engine", 0);
if( mPref.getInt( "pakversion", 0 ) == PAK_VERSION && !force )
return;
String path = context.getFilesDir().getPath()+"/extras.pak";
is = context.getAssets().open("extras.pak");
os = new FileOutputStream(path);
byte[] buffer = new byte[1024];
int length;
while ((length = is.read(buffer)) > 0) {
os.write(buffer, 0, length);
}
os.close();
is.close();
SharedPreferences.Editor editor = mPref.edit();
editor.putInt( "pakversion", PAK_VERSION );
editor.commit();
} catch( Exception e )
{
Log.e( TAG, "Failed to extract PAK:" + e.toString() );
}
}
}

View file

@ -31,6 +31,7 @@ import in.celest.xash3d.hl.R;
public class LauncherActivity extends Activity {
// public final static String ARGV = "in.celest.xash3d.MESSAGE";
public final static int sdk = Integer.valueOf(Build.VERSION.SDK);
static EditText cmdArgs;
static ToggleButton useVolume;
static EditText resPath;
@ -47,10 +48,10 @@ public class LauncherActivity extends Activity {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//super.setTheme( 0x01030005 );
if ( Build.VERSION.SDK_INT >= 21 )
if ( sdk >= 21 )
super.setTheme( 0x01030224 );
setContentView(R.layout.activity_launcher);
TabHost tabHost = (TabHost) findViewById(R.id.tabhost);
tabHost.setup();
@ -60,13 +61,37 @@ public class LauncherActivity extends Activity {
tabSpec.setIndicator(getString(R.string.text_tab1));
tabSpec.setContent(R.id.tab1);
tabHost.addTab(tabSpec);
tabSpec = tabHost.newTabSpec("tabtag2");
tabSpec.setIndicator(getString(R.string.text_tab2));
tabSpec.setContent(R.id.tab2);
tabHost.addTab(tabSpec);
Button selectFolder = ( Button ) findViewById( R.id.button_select );
Button selectFolderButton = ( Button ) findViewById( R.id.button_select );
selectFolderButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
selectFolder(v);
}
});
((Button)findViewById( R.id.button_launch )).setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
startXash(v);
}
});
((Button)findViewById( R.id.button_shortcut )).setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
createShortcut(v);
}
});
((Button)findViewById( R.id.button_about )).setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
aboutXash(v);
}
});
// if ( Build.VERSION.SDK_INT < 21 )
// selectFolder.setVisibility( View.GONE );
mPref = getSharedPreferences("engine", 0);
@ -77,7 +102,7 @@ public class LauncherActivity extends Activity {
resPath = ( EditText ) findViewById( R.id.cmdPath );
resPath.setText(mPref.getString("basedir", getDefaultPath()));
}
public void startXash(View view)
{
Intent intent = new Intent(this, org.libsdl.app.SDLActivity.class);
@ -88,7 +113,6 @@ public class LauncherActivity extends Activity {
editor.putBoolean("usevolume",useVolume.isChecked());
editor.putString("basedir", resPath.getText().toString());
editor.commit();
editor.apply();
startActivity(intent);
}

View file

@ -8,6 +8,7 @@ import android.graphics.BitmapFactory;
import android.widget.Toast;
import in.celest.xash3d.hl.R;
import android.widget.EditText;
import android.widget.Button;
import java.io.File;
import java.io.FilenameFilter;
@ -17,12 +18,13 @@ public class ShortcutActivity extends Activity
{
static EditText name, gamedir, pkgname, argv;
String [] env = null;
public static final int sdk = Integer.valueOf(Build.VERSION.SDK);
@Override
protected void onCreate(Bundle bundle)
{
super.onCreate(bundle);
//material dialog
if ( Build.VERSION.SDK_INT >= 21 )
if ( sdk >= 21 )
super.setTheme( 0x01030225 );
setContentView(R.layout.activity_shortcut);
Intent intent=getIntent();
@ -30,6 +32,12 @@ public class ShortcutActivity extends Activity
pkgname = (EditText)findViewById(R.id.shortcut_pkgname);
gamedir = (EditText)findViewById(R.id.shortcut_gamedir);
argv = (EditText)findViewById(R.id.shortcut_cmdArgs);
((Button)findViewById( R.id.shortcut_buttonOk )).setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
saveShortcut(v);
}
});
String argvs = intent.getStringExtra("argv");
if( argvs != null )
argv.setText(argvs);
@ -43,7 +51,7 @@ public class ShortcutActivity extends Activity
if( names != null )
name.setText(names);
env = intent.getStringArrayExtra("env");
//name.setText("Name");
}
public void saveShortcut(View view)
@ -62,7 +70,7 @@ public class ShortcutActivity extends Activity
Intent wrapIntent = new Intent();
wrapIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
wrapIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name.getText().toString());
Bitmap icon = null;
// Try find icon
int size = (int) getResources().getDimension(android.R.dimen.app_icon_size);
@ -91,7 +99,7 @@ public class ShortcutActivity extends Activity
return false;
}
};
File gamedirfile = new File(gamedirstring);
String files[] = gamedirfile.list(icoFilter);
icon = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(gamedirstring+"/"+files[0]), size, size, false);

View file

@ -29,6 +29,7 @@ public class XashActivity extends Activity {
protected static XashActivity mSingleton;
private static EngineSurface mSurface;
private static String mArgv[];
public static final int sdk = Integer.valueOf(Build.VERSION.SDK);
// Preferences
public static SharedPreferences mPref = null;
@ -270,7 +271,8 @@ public class XashActivity extends Activity {
class XashMain implements Runnable {
public void run() {
// Runs SDL_main()
XashActivity.createGLContext();
XashActivity.createGLContext();
XashActivity.nativeInit(XashActivity.getArguments());
@ -286,7 +288,7 @@ class XashMain implements Runnable {
Because of this, that's where we set up the SDL thread
*/
class EngineSurface extends SurfaceView implements SurfaceHolder.Callback,
View.OnKeyListener, View.OnTouchListener {
View.OnKeyListener {
// This is what SDL runs in. It invokes SDL_main(), eventually
private Thread mEngThread;
@ -307,7 +309,10 @@ View.OnKeyListener, View.OnTouchListener {
setFocusableInTouchMode(true);
requestFocus();
setOnKeyListener(this);
setOnTouchListener(this);
if( XashActivity.sdk >= 5 )
setOnTouchListener(new EngineTouchListener_v5());
else
setOnTouchListener(new EngineTouchListener_v1());
}
// Called when we have a valid drawing surface
@ -412,11 +417,10 @@ View.OnKeyListener, View.OnTouchListener {
int[] configSpec = {
EGL10.EGL_DEPTH_SIZE, 8,
EGL10.EGL_RED_SIZE, 8,
EGL10.EGL_GREEN_SIZE, 8,
EGL10.EGL_BLUE_SIZE, 8,
EGL10.EGL_RED_SIZE, 5,
EGL10.EGL_GREEN_SIZE, 6,
EGL10.EGL_BLUE_SIZE, 5,
EGL10.EGL_ALPHA_SIZE, 0,
EGL10.EGL_RENDERABLE_TYPE, 1,
EGL10.EGL_NONE
};
EGLConfig[] configs = new EGLConfig[1];
@ -505,11 +509,18 @@ View.OnKeyListener, View.OnTouchListener {
}
return false;
}
// Touch events
}
class EngineTouchListener_v1 implements View.OnTouchListener{
// Touch events
public boolean onTouch(View v, MotionEvent event) {
/* Ref: http://developer.android.com/training/gestures/multi.html */
XashActivity.nativeTouch(0, event.getAction(), event.getX(), event.getY());
return true;
}
}
class EngineTouchListener_v5 implements View.OnTouchListener{
// Touch events
public boolean onTouch(View v, MotionEvent event) {
final int touchDevId = event.getDeviceId();
final int pointerCount = event.getPointerCount();
int action = event.getActionMasked();
@ -559,9 +570,7 @@ View.OnKeyListener, View.OnTouchListener {
default:
break;
}
}
return true;
}
}
}

View file

@ -65,19 +65,18 @@ import android.content.*;
*/
public class SDLActivity extends Activity {
private static final String TAG = "SDL";
private static final int PAK_VERSION = 5;
// Keep track of the paused state
public static boolean mIsPaused, mIsSurfaceReady, mHasFocus, mUseVolume;
public static boolean mExitCalledFromJava;
/** If shared libraries (e.g. SDL or the native application) could not be loaded. */
public static boolean mBrokenLibraries;
public static boolean mBrokenLibraries;
// If we want to separate mouse and touch events.
// This is only toggled in native code when a hint is set!
public static boolean mSeparateMouseAndTouch;
private static Vibrator mVibrator;
// Main components
@ -95,7 +94,7 @@ public class SDLActivity extends Activity {
// Preferences
public static SharedPreferences mPref = null;
// Arguments
public static String[] mArgv;
/**
@ -153,15 +152,15 @@ public class SDLActivity extends Activity {
Log.v("SDL", "Model: " + android.os.Build.MODEL);
Log.v("SDL", "onCreate():" + mSingleton);
super.onCreate(savedInstanceState);
// fullscreen
// fullscreen
requestWindowFeature(Window.FEATURE_NO_TITLE);
if(Build.VERSION.SDK_INT >= 12) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
// keep screen on
// keep screen on
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
@ -205,7 +204,7 @@ public class SDLActivity extends Activity {
return;
}
Intent intent=getIntent();
String argv = intent.getStringExtra("argv");
if(argv == null) argv = mPref.getString("argv", "-dev 3 -log");
@ -220,13 +219,13 @@ public class SDLActivity extends Activity {
String basedir = intent.getStringExtra("basedir");
if(basedir == null)
basedir = mPref.getString("basedir","/sdcard/xash/");
setenv("XASH3D_BASEDIR", basedir, true);
setenv("XASH3D_ENGLIBDIR", getFilesDir().getParentFile().getPath() + "/lib", true);
setenv("XASH3D_GAMELIBDIR", gamelibdir, true);
setenv("XASH3D_GAMEDIR", gamedir, true);
extractPAK(this, false);
in.celest.xash3d.InstallReceiver.extractPAK(this, false);
setenv("XASH3D_EXTRAS_PAK1", getFilesDir().getPath() + "/extras.pak", true);
String pakfile = intent.getStringExtra("pakfile");
if( pakfile != null && pakfile != "" )
@ -271,7 +270,7 @@ public class SDLActivity extends Activity {
}
if( mVibrator != null ) mVibrator.cancel();
SDLActivity.handlePause();
}
@ -322,10 +321,10 @@ public class SDLActivity extends Activity {
and kills process while engine is writing config.
it results in configuration loss, so we preferred to disable it
*/
/*
if( mVibrator != null ) mVibrator.cancel();
if (SDLActivity.mBrokenLibraries) {
super.onDestroy();
// Reset everything in case the user re opens the app
@ -352,7 +351,7 @@ public class SDLActivity extends Activity {
super.onDestroy();
// Reset everything in case the user re opens the app
finish();
}
@Override
@ -511,23 +510,23 @@ public class SDLActivity extends Activity {
public static native int nativeRemoveJoystick(int device_id);
public static native String nativeGetHint(String name);
public static native int setenv(String key, String value, boolean overwrite);
/**
* This method is called by SDL using JNI.
*/
public static void flipBuffers() {
SDLActivity.nativeFlipBuffers();
}
/**
* This method is called by Xash3D engine using JNI
*/
public void vibrate( short time ) {
mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
mVibrator.vibrate( time );
}
/**
* This method is called by SDL using JNI.
*/
@ -1033,34 +1032,7 @@ public class SDLActivity extends Activity {
Log.e( TAG, "Failed to extract PAK:" + e.toString() );
}
}*/
public static void extractPAK(Context context, Boolean force) {
InputStream is = null;
FileOutputStream os = null;
try {
if( mPref == null )
mPref = context.getSharedPreferences("engine", 0);
if( mPref.getInt( "pakversion", 0 ) == PAK_VERSION && !force )
return;
String path = context.getFilesDir().getPath()+"/extras.pak";
is = context.getAssets().open("extras.pak");
os = new FileOutputStream(path);
byte[] buffer = new byte[1024];
int length;
while ((length = is.read(buffer)) > 0) {
os.write(buffer, 0, length);
}
os.close();
is.close();
SharedPreferences.Editor editor = mPref.edit();
editor.putInt( "pakversion", PAK_VERSION );
editor.commit();
editor.apply();
} catch( Exception e )
{
Log.e( TAG, "Failed to extract PAK:" + e.toString() );
}
}
}
/**
@ -1070,7 +1042,7 @@ class SDLMain implements Runnable {
@Override
public void run() {
// Runs SDL_main()
SDLActivity.nativeInit(SDLActivity.mArgv);
SDLActivity.nativeInit(SDLActivity.mArgv);
//Log.v("SDL", "SDL thread terminated");
}
}
@ -1278,7 +1250,7 @@ View.OnKeyListener, View.OnTouchListener, SensorEventListener {
public boolean onTouch(View v, MotionEvent event) {
/* Ref: http://developer.android.com/training/gestures/multi.html */
final int touchDevId = event.getDeviceId();
final int pointerCount = event.getPointerCount();
int action = event.getActionMasked();

View file

@ -97,7 +97,7 @@
</application>
<!-- Android 2.3 -->
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="9" />
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="9" />
<!-- OpenGL ES 1.1 -->
<uses-feature android:glEsVersion="0x00010000" />