Xash3D background service (prevend unload)

This commit is contained in:
mittorn 2017-03-24 22:03:00 +00:00
parent 6d9056c74c
commit 5368a7f56b
8 changed files with 203 additions and 58 deletions

View file

@ -66,13 +66,16 @@
<activity android:name="in.celest.xash3d.XashActivity"
android:screenOrientation="sensorLandscape"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation|screenSize|smallestScreenSize"
android:label="@string/app_name">
android:label="@string/app_name"
android:launchMode="singleTask">
<intent-filter>
<action android:name="in.celest.xash3d.START" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="in.celest.xash3d.FPicker"></activity>
<service android:name="in.celest.xash3d.XashService" android:stopWithTask="false" />
<receiver android:name="in.celest.xash3d.XashService$exitButtonListener" />
<receiver android:name="in.celest.xash3d.InstallReceiver">
<intent-filter android:priority="100">
<category android:name="android.intent.category.DEFAULT" />

View file

@ -1,4 +1,4 @@
ANDROID_JAR=../android-13.jar
ANDROID_JAR=../android-14_.jar
AAPT=./../aapt
DX=./../dx
APKBUILDER=./../apkbuilder

@ -1 +1 @@
Subproject commit 472f483e21b042a3fa04f2e559acf7c71c0c0325
Subproject commit 8dcecbaac9204a87200f2ce7e95c2b8f23a7a616

View file

@ -1,43 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
android:layout_height="65sp"
android:orientation="horizontal" >
<ImageView android:id="@+id/status_icon"
<ImageView
android:id="@+id/status_image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:layout_weight="00"
android:layout_gravity="center_vertical" />
<TextView
android:id="@+id/status_text"
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" />
<Button
android:id="@+id/status_exit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exit"
android:layout_weight="0"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp"/>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_toRightOf="@id/status_icon">
<TextView android:id="@+id/status_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<ProgressBar android:id="@+id/status_progress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/status_text"
android:indeterminate="false"
android:indeterminateOnly="false"
style="?android:attr/progressBarStyleHorizontal" />
</RelativeLayout>
</RelativeLayout>
android:layout_gravity="center_vertical" />
</LinearLayout>

View file

@ -155,15 +155,6 @@ public class XashActivity extends Activity {
setFolderAsk( false ); // don't ask on next run
Log.v(TAG, "Got new basedir from FPicker: " + newBaseDir );
}
else if( requestCode == OPEN_DOCUMENT_TREE_RESULT )
{
Uri uri = resultData.getData();
if( uri != null )
{
getContentResolver().takePersistableUriPermission(uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION );
}
}
}
}
@ -235,34 +226,41 @@ public class XashActivity extends Activity {
@Override
protected void onResume() {
Log.v(TAG, "onResume()");
if( mEngineReady )
nativeOnResume();
super.onResume();
}
@Override
protected void onStop() {
Log.v(TAG, "onStop()");
/*
if( mEngineReady )
{
nativeSetPause(0);
// let engine properly exit, instead of killing it's thread
nativeOnStop();
// wait for engine
mSurface.engineThreadWait();
}
*/
super.onStop();
}
@Override
protected void onDestroy() {
Log.v(TAG, "onStop()");
Log.v(TAG, "onDestroy()");
if( mEngineReady )
{
nativeUnPause();
// let engine a chance to properly exit
nativeOnDestroy();
//mSurface.engineThreadWait();
// wait until Xash will exit
mSurface.engineThreadJoin();
}
@ -274,6 +272,9 @@ public class XashActivity extends Activity {
@Override
public void onWindowFocusChanged(boolean hasFocus)
{
if( mEngineReady )
nativeOnFocusChange();
super.onWindowFocusChanged(hasFocus);
if( mImmersiveMode != null )
@ -418,6 +419,8 @@ public class XashActivity extends Activity {
mVibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
mHasVibrator = ( mVibrator != null ) && ( mVibrator.hasVibrator() );
startService(new Intent(getBaseContext(), XashService.class));
mEngineReady = true;
}
@ -469,8 +472,10 @@ public class XashActivity extends Activity {
public static native void nativeString( String text );
public static native void nativeSetPause(int pause);
public static native void nativeOnDestroy();
public static native void nativeOnStop();
public static native void nativeOnResume();
public static native void nativeOnFocusChange();
public static native void nativeOnPause();
public static native void nativeUnPause();
public static native void nativeHat(int id, byte hat, byte keycode, boolean down);
public static native void nativeAxis(int id, byte axis, short value);
public static native void nativeJoyButton(int id, byte button, boolean down);
@ -765,6 +770,7 @@ public class XashActivity extends Activity {
}
/**
Simple nativeInit() runnable
*/

View file

@ -0,0 +1,99 @@
package in.celest.xash3d;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.opengles.GL10;
import javax.microedition.khronos.egl.*;
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 android.net.Uri;
import android.provider.*;
import android.database.*;
import android.view.inputmethod.*;
import java.lang.*;
import java.util.List;
import java.security.MessageDigest;
import in.celest.xash3d.hl.R;
import in.celest.xash3d.hl.BuildConfig;
import in.celest.xash3d.XashConfig;
import in.celest.xash3d.JoystickHandler;
import in.celest.xash3d.CertCheck;
public class XashService extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}
public static class exitButtonListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
XashActivity.nativeUnPause();
XashActivity.nativeOnDestroy();
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
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,
"Xash3D", System.currentTimeMillis());
notification.contentView = new RemoteViews(getApplicationContext()
.getPackageName(), R.layout.notify);
notification.contentIntent = pendingIntent;
notification.flags = notification.flags
| Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE;
notification.contentView.setTextViewText(R.id.status_text, "Xash3D");
Intent exitIntent = new Intent(this, exitButtonListener.class);
PendingIntent pendingExitIntent = PendingIntent.getBroadcast(this, 0,
exitIntent, 0);
notification.contentView.setOnClickPendingIntent(R.id.status_exit_button, pendingExitIntent);
startForeground(100, notification);
return START_NOT_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
Log.d("XashService", "Service Destroyed");
}
@Override
public void onCreate()
{
}
@Override
public void onTaskRemoved(Intent rootIntent) {
Log.e("XashService", "OnTaskRemoved");
XashActivity.nativeUnPause();
XashActivity.nativeOnDestroy();
stopSelf();
}
};

View file

@ -77,12 +77,15 @@
android:screenOrientation="sensorLandscape"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation|screenSize|smallestScreenSize"
android:windowSoftInputMode="adjustResize"
android:label="@string/app_name">
android:label="@string/app_name"
android:launchMode="singleTask">
<intent-filter>
<action android:name="in.celest.xash3d.START" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service android:name="in.celest.xash3d.XashService" android:stopWithTask="false"/>
<receiver android:name="in.celest.xash3d.XashService$exitButtonListener" />
<receiver android:name="in.celest.xash3d.InstallReceiver">
<intent-filter android:priority="100">
<category android:name="android.intent.category.DEFAULT" />

43
unused/notify.xml Normal file
View file

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<ImageView android:id="@+id/status_icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp"/>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_toRightOf="@id/status_icon">
<TextView android:id="@+id/status_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<ProgressBar android:id="@+id/status_progress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/status_text"
android:indeterminate="false"
android:indeterminateOnly="false"
style="?android:attr/progressBarStyleHorizontal" />
</RelativeLayout>
</RelativeLayout>