Fix compatibility problems, add setTitle, setIcon

This commit is contained in:
mittorn 2017-03-26 22:11:27 +00:00
parent fa43690519
commit b3777bd7c0
8 changed files with 254 additions and 178 deletions

View file

@ -5,7 +5,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="in.celest.xash3d.hl"
android:versionCode="531"
android:versionName="0.18.1"
android:versionName="0.19"
android:installLocation="auto">
<application android:label="@string/app_name"

@ -1 +1 @@
Subproject commit 8dcecbaac9204a87200f2ce7e95c2b8f23a7a616
Subproject commit d5db3fd807075e21ea19bd99cf338fd829a1f921

View file

@ -7,8 +7,8 @@
<ImageView
android:id="@+id/status_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="32sp"
android:layout_height="32sp"
android:src="@drawable/ic_launcher"
android:layout_weight="00"
android:layout_gravity="center_vertical" />

36
res/layout/notify_21.xml Normal file
View file

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="65sp"
android:orientation="horizontal"
android:background="#FFFFFF">
<ImageView
android:id="@+id/status_image_21"
android:src="@drawable/ic_launcher"
android:layout_weight="00"
android:layout_gravity="center_vertical"
android:layout_width="32sp"
android:layout_height="32sp"/>
<TextView
android:id="@+id/status_text_21"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dip"
android:singleLine="true"
android:layout_weight="90"
android:text="Xash3D"
android:layout_gravity="center_vertical"
android:textColor="#000000"/>
<Button
android:id="@+id/status_exit_button_21"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exit"
android:layout_weight="0"
android:layout_alignParentLeft="true"
android:layout_gravity="center_vertical" />
</LinearLayout>

View file

@ -1,157 +0,0 @@
package in.celest.xash3d;
import android.app.*;
import android.content.*;
import android.view.*;
import android.os.*;
import android.util.*;
import android.graphics.*;
import android.text.method.*;
import android.text.*;
import android.media.*;
import android.hardware.*;
import android.content.*;
import android.widget.*;
import android.content.pm.*;
import java.lang.*;
import java.util.List;
import in.celest.xash3d.hl.BuildConfig;
import in.celest.xash3d.XashConfig;
import in.celest.xash3d.XashActivity;
class JoystickHandler
{
public int getSource(KeyEvent event)
{
return InputDevice.SOURCE_UNKNOWN;
}
public int getSource(MotionEvent event)
{
return InputDevice.SOURCE_UNKNOWN;
}
public boolean handleAxis(MotionEvent event)
{
return false;
}
public boolean isGamepadButton(int keyCode)
{
return false;
}
public String keyCodeToString(int keyCode)
{
return String.valueOf(keyCode);
}
public void init()
{
}
}
class JoystickHandler_v12 extends JoystickHandler
{
private static float prevSide, prevFwd, prevYaw, prevPtch, prevLT, prevRT, prevHX, prevHY;
@Override
public void init()
{
XashActivity.mSurface.setOnGenericMotionListener(new MotionListener());
}
@Override
public int getSource(KeyEvent event)
{
return event.getSource();
}
@Override
public int getSource(MotionEvent event)
{
return event.getSource();
}
@Override
public boolean handleAxis( MotionEvent event )
{
// how event can be from null device, Android?
final InputDevice device = event.getDevice();
if( device == null )
return false;
// maybe I need to cache this...
for( InputDevice.MotionRange range: device.getMotionRanges() )
{
// normalize in -1.0..1.0 (copied from SDL2)
final float cur = ( event.getAxisValue( range.getAxis(), event.getActionIndex() ) - range.getMin() ) / range.getRange() * 2.0f - 1.0f;
final float dead = range.getFlat(); // get axis dead zone
switch( range.getAxis() )
{
// typical axes
// move
case MotionEvent.AXIS_X:
prevSide = XashActivity.performEngineAxisEvent(cur, XashActivity.JOY_AXIS_SIDE, prevSide, dead);
break;
case MotionEvent.AXIS_Y:
prevFwd = XashActivity.performEngineAxisEvent(cur, XashActivity.JOY_AXIS_FWD, prevFwd, dead);
break;
// rotate. Invert, so by default this works as it's should
case MotionEvent.AXIS_Z:
prevPtch = XashActivity.performEngineAxisEvent(-cur, XashActivity.JOY_AXIS_PITCH, prevPtch, dead);
break;
case MotionEvent.AXIS_RZ:
prevYaw = XashActivity.performEngineAxisEvent(-cur, XashActivity.JOY_AXIS_YAW, prevYaw, dead);
break;
// trigger
case MotionEvent.AXIS_RTRIGGER:
prevLT = XashActivity.performEngineAxisEvent(cur, XashActivity.JOY_AXIS_RT, prevLT, dead);
break;
case MotionEvent.AXIS_LTRIGGER:
prevRT = XashActivity.performEngineAxisEvent(cur, XashActivity.JOY_AXIS_LT, prevRT, dead);
break;
// hats
case MotionEvent.AXIS_HAT_X:
prevHX = XashActivity.performEngineHatEvent(cur, true, prevHX);
break;
case MotionEvent.AXIS_HAT_Y:
prevHY = XashActivity.performEngineHatEvent(cur, false, prevHY);
break;
}
}
return true;
}
@Override
public boolean isGamepadButton(int keyCode)
{
return KeyEvent.isGamepadButton(keyCode);
}
@Override
public String keyCodeToString(int keyCode)
{
return KeyEvent.keyCodeToString(keyCode);
}
class MotionListener implements View.OnGenericMotionListener
{
@Override
public boolean onGenericMotion(View view, MotionEvent event)
{
final int source = XashActivity.handler.getSource(event);
final int axisDevices = InputDevice.SOURCE_CLASS_JOYSTICK | InputDevice.SOURCE_GAMEPAD;
if( (source & axisDevices) != 0 )
return XashActivity.handler.handleAxis( event );
// TODO: Add it someday
// else if( (event.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == InputDevice.SOURCE_CLASS_TRACKBALL )
// return XashActivity.handleBall( event );
//return super.onGenericMotion( view, event );
return false;
}
}
}

View file

@ -53,8 +53,9 @@ public class XashActivity extends Activity {
public static ImmersiveMode mImmersiveMode;
public static boolean keyboardVisible = false;
public static boolean mEngineReady = false;
public static boolean mEnginePaused = false;
public static Vibrator mVibrator;
private static Vibrator mVibrator;
private static boolean mHasVibrator;
private int mReturingWithResultCode = 0;
@ -88,7 +89,6 @@ public class XashActivity extends Activity {
System.loadLibrary("xash");
}
// Setup
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -230,6 +230,8 @@ public class XashActivity extends Activity {
if( mEngineReady )
nativeOnResume();
mEnginePaused = false;
super.onResume();
}
@ -417,8 +419,12 @@ public class XashActivity extends Activity {
mDecorView = getWindow().getDecorView();
mVibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
mHasVibrator = ( mVibrator != null ) && ( mVibrator.hasVibrator() );
mHasVibrator = ( mVibrator != null );
if( sdk >= 11 )
mHasVibrator = ( mVibrator != null ) && ( handler.hasVibrator() );
if( sdk >= 5 )
startService(new Intent(getBaseContext(), XashService.class));
mEngineReady = true;
@ -768,6 +774,37 @@ public class XashActivity extends Activity {
mSingleton.runOnUiThread(new ShowTextInputTask(show));
}
public static void setIcon(String path)
{
Log.v(TAG,"setIcon("+path+")");
if( sdk < 5 )
return;
try{
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
Bitmap icon = BitmapFactory.decodeFile(path,o);
if( icon.getWidth() < 16 )
return;
XashService.notification.contentView.setImageViewUri (XashService.status_image, Uri.parse("file://"+path));
((NotificationManager) mSingleton.getApplicationContext()
.getSystemService(Context.NOTIFICATION_SERVICE)).notify(100,XashService.notification);
}
catch( Exception e)
{
}
}
public static void setTitle(String title)
{
Log.v(TAG,"setTitle("+title+")");
if( sdk < 5 )
return;
XashService.notification.contentView.setTextViewText(XashService.status_text, title);
((NotificationManager) mSingleton.getApplicationContext()
.getSystemService(Context.NOTIFICATION_SERVICE)).notify(100,XashService.notification);
}
}
@ -827,6 +864,7 @@ class EngineSurface extends SurfaceView implements SurfaceHolder.Callback, View.
if( mEGL == null )
return;
XashActivity.nativeSetPause(0);
XashActivity.mEnginePaused = false;
}
// Called when we lose the surface
@ -1300,3 +1338,144 @@ class ImmersiveMode_v19 extends ImmersiveMode
}
}
class JoystickHandler
{
public int getSource(KeyEvent event)
{
return InputDevice.SOURCE_UNKNOWN;
}
public int getSource(MotionEvent event)
{
return InputDevice.SOURCE_UNKNOWN;
}
public boolean handleAxis(MotionEvent event)
{
return false;
}
public boolean isGamepadButton(int keyCode)
{
return false;
}
public String keyCodeToString(int keyCode)
{
return String.valueOf(keyCode);
}
public void init()
{
}
public boolean hasVibrator()
{
return true;
}
}
class JoystickHandler_v12 extends JoystickHandler
{
private static float prevSide, prevFwd, prevYaw, prevPtch, prevLT, prevRT, prevHX, prevHY;
@Override
public void init()
{
XashActivity.mSurface.setOnGenericMotionListener(new MotionListener());
}
@Override
public int getSource(KeyEvent event)
{
return event.getSource();
}
@Override
public int getSource(MotionEvent event)
{
return event.getSource();
}
@Override
public boolean handleAxis( MotionEvent event )
{
// how event can be from null device, Android?
final InputDevice device = event.getDevice();
if( device == null )
return false;
// maybe I need to cache this...
for( InputDevice.MotionRange range: device.getMotionRanges() )
{
// normalize in -1.0..1.0 (copied from SDL2)
final float cur = ( event.getAxisValue( range.getAxis(), event.getActionIndex() ) - range.getMin() ) / range.getRange() * 2.0f - 1.0f;
final float dead = range.getFlat(); // get axis dead zone
switch( range.getAxis() )
{
// typical axes
// move
case MotionEvent.AXIS_X:
prevSide = XashActivity.performEngineAxisEvent(cur, XashActivity.JOY_AXIS_SIDE, prevSide, dead);
break;
case MotionEvent.AXIS_Y:
prevFwd = XashActivity.performEngineAxisEvent(cur, XashActivity.JOY_AXIS_FWD, prevFwd, dead);
break;
// rotate. Invert, so by default this works as it's should
case MotionEvent.AXIS_Z:
prevPtch = XashActivity.performEngineAxisEvent(-cur, XashActivity.JOY_AXIS_PITCH, prevPtch, dead);
break;
case MotionEvent.AXIS_RZ:
prevYaw = XashActivity.performEngineAxisEvent(-cur, XashActivity.JOY_AXIS_YAW, prevYaw, dead);
break;
// trigger
case MotionEvent.AXIS_RTRIGGER:
prevLT = XashActivity.performEngineAxisEvent(cur, XashActivity.JOY_AXIS_RT, prevLT, dead);
break;
case MotionEvent.AXIS_LTRIGGER:
prevRT = XashActivity.performEngineAxisEvent(cur, XashActivity.JOY_AXIS_LT, prevRT, dead);
break;
// hats
case MotionEvent.AXIS_HAT_X:
prevHX = XashActivity.performEngineHatEvent(cur, true, prevHX);
break;
case MotionEvent.AXIS_HAT_Y:
prevHY = XashActivity.performEngineHatEvent(cur, false, prevHY);
break;
}
}
return true;
}
@Override
public boolean isGamepadButton(int keyCode)
{
return KeyEvent.isGamepadButton(keyCode);
}
@Override
public String keyCodeToString(int keyCode)
{
return KeyEvent.keyCodeToString(keyCode);
}
class MotionListener implements View.OnGenericMotionListener
{
@Override
public boolean onGenericMotion(View view, MotionEvent event)
{
final int source = XashActivity.handler.getSource(event);
final int axisDevices = InputDevice.SOURCE_CLASS_JOYSTICK | InputDevice.SOURCE_GAMEPAD;
if( (source & axisDevices) != 0 )
return XashActivity.handler.handleAxis( event );
// TODO: Add it someday
// else if( (event.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == InputDevice.SOURCE_CLASS_TRACKBALL )
// return XashActivity.handleBall( event );
//return super.onGenericMotion( view, event );
return false;
}
}
public boolean hasVibrator()
{
return XashActivity.mVibrator.hasVibrator();
}
}

View file

@ -37,6 +37,9 @@ import in.celest.xash3d.CertCheck;
public class XashService extends Service {
public static Notification notification;
public static int status_image = R.id.status_image;
public static int status_text = R.id.status_text;
@Override
public IBinder onBind(Intent intent) {
@ -52,26 +55,37 @@ public class XashService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
int status_exit_button = R.id.status_exit_button;
int notify = R.layout.notify;
if( XashActivity.sdk >= 21 )
{
status_image = R.id.status_image_21;
status_text = R.id.status_text_21;
status_exit_button = R.id.status_exit_button_21;
notify = R.layout.notify_21;
}
Log.d("XashService", "Service Started");
Intent intent_ = new Intent(this, XashActivity.class);
intent_.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
final PendingIntent pendingIntent = PendingIntent.getActivity(
getApplicationContext(), 0, intent_, 0);
Notification notification = new Notification(R.drawable.ic_launcher,
notification = new Notification(R.drawable.ic_launcher,
"Xash3D", System.currentTimeMillis());
notification.contentView = new RemoteViews(getApplicationContext()
.getPackageName(), R.layout.notify);
.getPackageName(), notify);
notification.contentIntent = pendingIntent;
notification.flags = notification.flags
| Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE;
notification.contentView.setTextViewText(R.id.status_text, "Xash3D");
notification.contentView.setTextViewText(status_text, "Xash3D Engine");
Intent exitIntent = new Intent(this, exitButtonListener.class);
PendingIntent pendingExitIntent = PendingIntent.getBroadcast(this, 0,
exitIntent, 0);
notification.contentView.setOnClickPendingIntent(R.id.status_exit_button, pendingExitIntent);
notification.contentView.setOnClickPendingIntent(status_exit_button, pendingExitIntent);
startForeground(100, notification);
return START_NOT_STICKY;
}
@ -91,8 +105,12 @@ public class XashService extends Service {
@Override
public void onTaskRemoved(Intent rootIntent) {
Log.e("XashService", "OnTaskRemoved");
if( XashActivity.mEngineReady )
{
XashActivity.mEngineReady = false;
XashActivity.nativeUnPause();
XashActivity.nativeOnDestroy();
}
stopSelf();
}

View file

@ -5,7 +5,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="in.celest.xash3d.hl.test"
android:versionCode="1"
android:versionName="0.18.1-beta"
android:versionName="0.19"
android:installLocation="auto">
<!-- Create a Java class extending SDLActivity and place it in a