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 #APP_STL := stlport_static
XASH_SDL ?= 0 XASH_SDL ?= 0
XASH_LEGACY ?= 0
ifeq ($(XASH_SDL),1) ifeq ($(XASH_SDL),1)
APP_PLATFORM := android-12 APP_PLATFORM := android-12
else else
ifneq ($(XASH_LEGACY),1)
APP_PLATFORM := android-8 APP_PLATFORM := android-8
else
APP_PLATFORM := android-3
endif
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 := -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_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_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 CFLAGS_HARDFP := -D_NDK_MATH_NO_SOFTFP=1 -mhard-float -mfloat-abi=hard -DLOAD_HARDFP -DSOFTFP_LINK
APPLICATIONMK_PATH = $(call my-dir) APPLICATIONMK_PATH = $(call my-dir)

View file

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

View file

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

View file

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

View file

@ -3,12 +3,45 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.util.Log; import android.util.Log;
import java.io.FileOutputStream;
import java.io.InputStream;
import android.content.SharedPreferences;
public class InstallReceiver extends BroadcastReceiver { public class InstallReceiver extends BroadcastReceiver {
private static final String TAG = "XASH3D"; private static final String TAG = "XASH3D";
@Override @Override
public void onReceive(Context context, Intent arg1) { public void onReceive(Context context, Intent arg1) {
Log.d( TAG, "Install received, extracting PAK" ); 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 class LauncherActivity extends Activity {
// public final static String ARGV = "in.celest.xash3d.MESSAGE"; // public final static String ARGV = "in.celest.xash3d.MESSAGE";
public final static int sdk = Integer.valueOf(Build.VERSION.SDK);
static EditText cmdArgs; static EditText cmdArgs;
static ToggleButton useVolume; static ToggleButton useVolume;
static EditText resPath; static EditText resPath;
@ -47,7 +48,7 @@ public class LauncherActivity extends Activity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE); this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//super.setTheme( 0x01030005 ); //super.setTheme( 0x01030005 );
if ( Build.VERSION.SDK_INT >= 21 ) if ( sdk >= 21 )
super.setTheme( 0x01030224 ); super.setTheme( 0x01030224 );
setContentView(R.layout.activity_launcher); setContentView(R.layout.activity_launcher);
@ -66,7 +67,31 @@ public class LauncherActivity extends Activity {
tabSpec.setContent(R.id.tab2); tabSpec.setContent(R.id.tab2);
tabHost.addTab(tabSpec); 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 ) // if ( Build.VERSION.SDK_INT < 21 )
// selectFolder.setVisibility( View.GONE ); // selectFolder.setVisibility( View.GONE );
mPref = getSharedPreferences("engine", 0); mPref = getSharedPreferences("engine", 0);
@ -88,7 +113,6 @@ public class LauncherActivity extends Activity {
editor.putBoolean("usevolume",useVolume.isChecked()); editor.putBoolean("usevolume",useVolume.isChecked());
editor.putString("basedir", resPath.getText().toString()); editor.putString("basedir", resPath.getText().toString());
editor.commit(); editor.commit();
editor.apply();
startActivity(intent); startActivity(intent);
} }

View file

@ -8,6 +8,7 @@ import android.graphics.BitmapFactory;
import android.widget.Toast; import android.widget.Toast;
import in.celest.xash3d.hl.R; import in.celest.xash3d.hl.R;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Button;
import java.io.File; import java.io.File;
import java.io.FilenameFilter; import java.io.FilenameFilter;
@ -17,12 +18,13 @@ public class ShortcutActivity extends Activity
{ {
static EditText name, gamedir, pkgname, argv; static EditText name, gamedir, pkgname, argv;
String [] env = null; String [] env = null;
public static final int sdk = Integer.valueOf(Build.VERSION.SDK);
@Override @Override
protected void onCreate(Bundle bundle) protected void onCreate(Bundle bundle)
{ {
super.onCreate(bundle); super.onCreate(bundle);
//material dialog //material dialog
if ( Build.VERSION.SDK_INT >= 21 ) if ( sdk >= 21 )
super.setTheme( 0x01030225 ); super.setTheme( 0x01030225 );
setContentView(R.layout.activity_shortcut); setContentView(R.layout.activity_shortcut);
Intent intent=getIntent(); Intent intent=getIntent();
@ -30,6 +32,12 @@ public class ShortcutActivity extends Activity
pkgname = (EditText)findViewById(R.id.shortcut_pkgname); pkgname = (EditText)findViewById(R.id.shortcut_pkgname);
gamedir = (EditText)findViewById(R.id.shortcut_gamedir); gamedir = (EditText)findViewById(R.id.shortcut_gamedir);
argv = (EditText)findViewById(R.id.shortcut_cmdArgs); 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"); String argvs = intent.getStringExtra("argv");
if( argvs != null ) if( argvs != null )
argv.setText(argvs); argv.setText(argvs);

View file

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

View file

@ -65,7 +65,6 @@ import android.content.*;
*/ */
public class SDLActivity extends Activity { public class SDLActivity extends Activity {
private static final String TAG = "SDL"; private static final String TAG = "SDL";
private static final int PAK_VERSION = 5;
// Keep track of the paused state // Keep track of the paused state
public static boolean mIsPaused, mIsSurfaceReady, mHasFocus, mUseVolume; public static boolean mIsPaused, mIsSurfaceReady, mHasFocus, mUseVolume;
@ -226,7 +225,7 @@ public class SDLActivity extends Activity {
setenv("XASH3D_GAMELIBDIR", gamelibdir, true); setenv("XASH3D_GAMELIBDIR", gamelibdir, true);
setenv("XASH3D_GAMEDIR", gamedir, 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); setenv("XASH3D_EXTRAS_PAK1", getFilesDir().getPath() + "/extras.pak", true);
String pakfile = intent.getStringExtra("pakfile"); String pakfile = intent.getStringExtra("pakfile");
if( pakfile != null && pakfile != "" ) if( pakfile != null && pakfile != "" )
@ -1033,34 +1032,7 @@ public class SDLActivity extends Activity {
Log.e( TAG, "Failed to extract PAK:" + e.toString() ); 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() );
}
}
} }
/** /**

View file

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