XSession: implement XorgClient
This commit is contained in:
parent
0fda37d443
commit
881f2b101a
@ -41,18 +41,19 @@ import java.util.concurrent.Semaphore;
|
||||
import android.Manifest;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import io.neoterm.xorg.NeoXorgViewClient;
|
||||
|
||||
@SuppressWarnings("JniMissingFunction")
|
||||
class AudioThread
|
||||
{
|
||||
|
||||
private MainActivity mParent;
|
||||
private NeoXorgViewClient mClient;
|
||||
private AudioTrack mAudio;
|
||||
private byte[] mAudioBuffer;
|
||||
private int mVirtualBufSize;
|
||||
|
||||
public AudioThread(MainActivity parent)
|
||||
public AudioThread(NeoXorgViewClient client)
|
||||
{
|
||||
mParent = parent;
|
||||
this.mClient = client;
|
||||
mAudio = null;
|
||||
mAudioBuffer = null;
|
||||
nativeAudioInitJavaCallbacks();
|
||||
@ -60,7 +61,7 @@ class AudioThread
|
||||
|
||||
public int fillBuffer()
|
||||
{
|
||||
if( mParent.isPaused() )
|
||||
if( mClient.isPaused() )
|
||||
{
|
||||
try{
|
||||
Thread.sleep(500);
|
||||
@ -168,16 +169,6 @@ class AudioThread
|
||||
|
||||
private byte[] startRecording(int rate, int channels, int encoding, int bufsize)
|
||||
{
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M)
|
||||
{
|
||||
int permissionCheck = mParent.checkSelfPermission(Manifest.permission.RECORD_AUDIO);
|
||||
if (permissionCheck != PackageManager.PERMISSION_GRANTED)
|
||||
{
|
||||
mParent.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, 0);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if( mRecordThread == null )
|
||||
{
|
||||
mRecordThread = new RecordingThread();
|
||||
|
@ -24,7 +24,7 @@ package io.neoterm;
|
||||
|
||||
import android.view.KeyEvent;
|
||||
|
||||
class Globals {
|
||||
public class Globals {
|
||||
public static String XLIB_DIR = "/data/data/io.neoterm/files/usr/lib/";
|
||||
public static String XLIBS[] = {
|
||||
"x11_sdl_native_helpers",
|
||||
@ -81,10 +81,6 @@ class Globals {
|
||||
public static int AppMinimumRAM = 0;
|
||||
public static SettingsMenu.Menu HiddenMenuOptions[] = {}; // If you see error here - update HiddenMenuOptions in your AndroidAppSettings.cfg: change OptionalDownloadConfig to SettingsMenuMisc.OptionalDownloadConfig etc.
|
||||
public static SettingsMenu.Menu FirstStartMenuOptions[] = {new SettingsMenuMisc.GyroscopeCalibration(), new SettingsMenuMisc.OptionalDownloadConfig(),};
|
||||
public static String AdmobPublisherId = "";
|
||||
public static String AdmobTestDeviceId = "";
|
||||
public static String AdmobBannerSize = "";
|
||||
public static String GooglePlayGameServicesId = "";
|
||||
|
||||
// Phone-specific config, modified by user in "Change phone config" startup dialog
|
||||
public static int VideoDepthBpp = 16;
|
||||
|
@ -64,16 +64,15 @@ import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import io.neoterm.xorg.NeoGLViewClient;
|
||||
import io.neoterm.xorg.NeoXorgViewClient;
|
||||
import io.neoterm.xorg.R;
|
||||
|
||||
|
||||
public class MainActivity extends Activity implements NeoGLViewClient {
|
||||
public class MainActivity extends Activity implements NeoXorgViewClient {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -206,20 +205,6 @@ public class MainActivity extends Activity implements NeoGLViewClient {
|
||||
;
|
||||
(new Thread(new Callback(this))).start();
|
||||
// Request SD card permission right during start, because game devs don't care about runtime permissions and stuff
|
||||
try {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
||||
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_PERMISSIONS | PackageManager.GET_META_DATA);
|
||||
Log.v("SDL", "SD card permission 1: " + getPackageName() + " perms " + info.requestedPermissions + " name " + info.packageName + " ver " + info.versionName);
|
||||
if (info.requestedPermissions != null && Arrays.asList(info.requestedPermissions).contains(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||
Log.v("SDL", "SD card permission 4: REQUEST");
|
||||
int permissionCheck = checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
if (permissionCheck != PackageManager.PERMISSION_GRANTED && !writeExternalStoragePermissionDialogAnswered) {
|
||||
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void setUpStatusLabel() {
|
||||
@ -902,7 +887,6 @@ public class MainActivity extends Activity implements NeoGLViewClient {
|
||||
|
||||
public void updateScreenOrientation() {
|
||||
int rotation = Surface.ROTATION_0;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.FROYO)
|
||||
rotation = getWindowManager().getDefaultDisplay().getRotation();
|
||||
AccelerometerReader.gyro.invertedOrientation = (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270);
|
||||
//Log.d("SDL", "updateScreenOrientation(): screen orientation: " + rotation + " inverted " + AccelerometerReader.gyro.invertedOrientation);
|
||||
|
17
Xorg/src/main/java/io/neoterm/NeoAccelerometerReader.java
Normal file
17
Xorg/src/main/java/io/neoterm/NeoAccelerometerReader.java
Normal file
@ -0,0 +1,17 @@
|
||||
package io.neoterm;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* @author kiva
|
||||
*/
|
||||
|
||||
public class NeoAccelerometerReader extends AccelerometerReader {
|
||||
public NeoAccelerometerReader(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public static void setGyroInvertedOrientation(boolean invertedOrientation) {
|
||||
gyro.invertedOrientation = invertedOrientation;
|
||||
}
|
||||
}
|
13
Xorg/src/main/java/io/neoterm/NeoAudioThread.java
Normal file
13
Xorg/src/main/java/io/neoterm/NeoAudioThread.java
Normal file
@ -0,0 +1,13 @@
|
||||
package io.neoterm;
|
||||
|
||||
import io.neoterm.xorg.NeoXorgViewClient;
|
||||
|
||||
/**
|
||||
* @author kiva
|
||||
*/
|
||||
|
||||
public class NeoAudioThread extends AudioThread {
|
||||
public NeoAudioThread(NeoXorgViewClient client) {
|
||||
super(client);
|
||||
}
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
package io.neoterm;
|
||||
|
||||
import io.neoterm.xorg.NeoGLViewClient;
|
||||
import io.neoterm.xorg.NeoXorgViewClient;
|
||||
|
||||
/**
|
||||
* @author kiva
|
||||
*/
|
||||
|
||||
public class NeoGLView extends DemoGLSurfaceView {
|
||||
public NeoGLView(NeoGLViewClient client) {
|
||||
public NeoGLView(NeoXorgViewClient client) {
|
||||
super(client);
|
||||
}
|
||||
}
|
||||
|
@ -22,14 +22,7 @@ freely, subject to the following restrictions:
|
||||
|
||||
package io.neoterm;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
import android.util.Log;
|
||||
import java.io.*;
|
||||
import android.app.AlertDialog;
|
||||
@ -38,46 +31,15 @@ import android.os.Environment;
|
||||
import android.os.StatFs;
|
||||
import java.util.Locale;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.Collections;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import java.lang.String;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.RectF;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.FrameLayout;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Bitmap;
|
||||
import android.widget.TextView;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.Button;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.text.Editable;
|
||||
import android.text.SpannedString;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.AlarmManager;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.net.Uri;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.Arrays;
|
||||
import android.graphics.Color;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.Sensor;
|
||||
import android.widget.Toast;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.content.Intent;
|
||||
|
||||
import io.neoterm.xorg.NeoGLViewClient;
|
||||
import io.neoterm.xorg.NeoXorgViewClient;
|
||||
import io.neoterm.xorg.R;
|
||||
|
||||
|
||||
@ -538,7 +500,7 @@ public class Settings
|
||||
Globals.ScreenFollowsMouse ? 1 : 0 );
|
||||
}
|
||||
|
||||
static void Apply(NeoGLViewClient p)
|
||||
static void Apply(NeoXorgViewClient p)
|
||||
{
|
||||
setEnvVars(p);
|
||||
nativeSetVideoDepth(Globals.VideoDepthBpp, Globals.NeedGles2 ? 1 : 0, Globals.NeedGles3 ? 1 : 0);
|
||||
@ -605,7 +567,7 @@ public class Settings
|
||||
Globals.TouchscreenCalibration[2], Globals.TouchscreenCalibration[3]);
|
||||
}
|
||||
|
||||
static void setEnvVars(NeoGLViewClient p)
|
||||
static void setEnvVars(NeoXorgViewClient p)
|
||||
{
|
||||
String lang = new String(Locale.getDefault().getLanguage());
|
||||
if( Locale.getDefault().getCountry().length() > 0 )
|
||||
|
@ -46,7 +46,7 @@ import android.view.Display;
|
||||
import android.net.Uri;
|
||||
import android.hardware.input.InputManager;
|
||||
|
||||
import io.neoterm.xorg.NeoGLViewClient;
|
||||
import io.neoterm.xorg.NeoXorgViewClient;
|
||||
|
||||
|
||||
class Mouse
|
||||
@ -610,7 +610,7 @@ abstract class DifferentTouchInput
|
||||
@SuppressWarnings("JniMissingFunction")
|
||||
class DemoRenderer extends GLSurfaceView_SDL.Renderer
|
||||
{
|
||||
public DemoRenderer(NeoGLViewClient client)
|
||||
public DemoRenderer(NeoXorgViewClient client)
|
||||
{
|
||||
mClient = client;
|
||||
Clipboard.get().setListener(mClient.getContext(), new Runnable()
|
||||
@ -732,7 +732,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
|
||||
Settings.nativeSetEnv( "DISPLAY_RESOLUTION_WIDTH", String.valueOf(Math.max(mWidth, mHeight)) );
|
||||
Settings.nativeSetEnv( "DISPLAY_RESOLUTION_HEIGHT", String.valueOf(Math.min(mWidth, mHeight)) ); // In Kitkat with immersive mode, getWindowManager().getDefaultDisplay().getMetrics() return inaccurate height
|
||||
|
||||
accelerometer = new AccelerometerReader(mClient.getContext());
|
||||
accelerometer = new NeoAccelerometerReader(mClient.getContext());
|
||||
if( Globals.MoveMouseWithGyroscope )
|
||||
startAccelerometerGyroscope(1);
|
||||
// Tweak video thread priority, if user selected big audio buffer
|
||||
@ -814,7 +814,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
|
||||
{
|
||||
class Callback implements Runnable
|
||||
{
|
||||
public NeoGLViewClient client;
|
||||
public NeoXorgViewClient client;
|
||||
public String oldText;
|
||||
public void run()
|
||||
{
|
||||
@ -831,7 +831,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
|
||||
{
|
||||
class Callback implements Runnable
|
||||
{
|
||||
public NeoGLViewClient client;
|
||||
public NeoXorgViewClient client;
|
||||
public void run()
|
||||
{
|
||||
client.hideScreenKeyboard();
|
||||
@ -952,7 +952,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
|
||||
public static native void nativeTextInputFinished();
|
||||
public static native void nativeClipboardChanged();
|
||||
|
||||
private NeoGLViewClient mClient = null;
|
||||
private NeoXorgViewClient mClient = null;
|
||||
public AccelerometerReader accelerometer = null;
|
||||
|
||||
private GL10 mGl = null;
|
||||
@ -974,7 +974,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
|
||||
@SuppressWarnings("JniMissingFunction")
|
||||
class DemoGLSurfaceView extends GLSurfaceView_SDL {
|
||||
|
||||
public DemoGLSurfaceView(NeoGLViewClient client) {
|
||||
public DemoGLSurfaceView(NeoXorgViewClient client) {
|
||||
super(client.getContext());
|
||||
mClient = client;
|
||||
setEGLConfigChooser(Globals.VideoDepthBpp, Globals.NeedDepthBuffer, Globals.NeedStencilBuffer, Globals.NeedGles2, Globals.NeedGles3);
|
||||
@ -1128,7 +1128,7 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL {
|
||||
};
|
||||
|
||||
DemoRenderer mRenderer;
|
||||
NeoGLViewClient mClient;
|
||||
NeoXorgViewClient mClient;
|
||||
|
||||
public static native void nativeMotionEvent( int x, int y, int action, int pointerId, int pressure, int radius );
|
||||
public static native int nativeKey( int keyCode, int down, int unicode, int gamepadId );
|
||||
|
@ -10,7 +10,7 @@ import io.neoterm.NeoGLView;
|
||||
* @author kiva
|
||||
*/
|
||||
|
||||
public interface NeoGLViewClient {
|
||||
public interface NeoXorgViewClient {
|
||||
Context getContext();
|
||||
|
||||
boolean isKeyboardWithoutTextInputShown();
|
||||
@ -40,4 +40,6 @@ public interface NeoGLViewClient {
|
||||
WindowManager getWindowManager();
|
||||
|
||||
void setSystemMousePointerVisible(int visible);
|
||||
|
||||
boolean isPaused();
|
||||
}
|
@ -1,18 +1,112 @@
|
||||
package io.neoterm.frontend.xorg
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.UiModeManager
|
||||
import android.content.Context
|
||||
import io.neoterm.backend.TerminalSession
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.Configuration
|
||||
import android.view.Surface
|
||||
import android.view.WindowManager
|
||||
import io.neoterm.Globals
|
||||
import io.neoterm.NeoAccelerometerReader
|
||||
import io.neoterm.NeoAudioThread
|
||||
import io.neoterm.xorg.NeoXorgViewClient
|
||||
|
||||
/**
|
||||
* @author kiva
|
||||
*/
|
||||
|
||||
class XSession private constructor() {
|
||||
class XSession private constructor(val mActivity: Activity, val sessionData: XSessionData) : NeoXorgViewClient {
|
||||
companion object {
|
||||
fun createSession(context: Context, parameter: XParameter) : XSession {
|
||||
return XSession()
|
||||
fun createSession(activity: Activity, parameter: XParameter): XSession {
|
||||
return XSession(activity, XSessionData())
|
||||
}
|
||||
}
|
||||
|
||||
var mSessionName = "";
|
||||
var keyboardWithoutTextInputShown = false;
|
||||
|
||||
init {
|
||||
if (Globals.InhibitSuspend) {
|
||||
window.setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
|
||||
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
|
||||
if (sessionData.audioThread == null) {
|
||||
sessionData.audioThread = NeoAudioThread(this)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getContext() = mActivity
|
||||
|
||||
override fun isKeyboardWithoutTextInputShown() = keyboardWithoutTextInputShown
|
||||
|
||||
override fun showScreenKeyboardWithoutTextInputField(flags: Int) {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun setScreenKeyboardHintMessage(hideMessage: String?) {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun isScreenKeyboardShown(): Boolean {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun showScreenKeyboard(message: String?) {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun hideScreenKeyboard() {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun runOnUiThread(runnable: Runnable?) = mActivity.runOnUiThread(runnable)
|
||||
|
||||
override fun updateScreenOrientation() {
|
||||
var rotation: Int = windowManager.defaultDisplay.rotation
|
||||
NeoAccelerometerReader.setGyroInvertedOrientation(
|
||||
rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270)
|
||||
}
|
||||
|
||||
override fun initScreenOrientation() {
|
||||
Globals.AutoDetectOrientation = true
|
||||
if (Globals.AutoDetectOrientation) {
|
||||
mActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_FULL_USER
|
||||
return
|
||||
}
|
||||
mActivity.requestedOrientation =
|
||||
if (Globals.HorizontalOrientation) ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
|
||||
else ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
|
||||
}
|
||||
|
||||
override fun isRunningOnOUYA(): Boolean {
|
||||
try {
|
||||
mActivity.packageManager.getPackageInfo("tv.ouya", 0)
|
||||
return true
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
}
|
||||
|
||||
val uiModeManager = mActivity.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager?
|
||||
return uiModeManager?.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION || Globals.OuyaEmulation
|
||||
}
|
||||
|
||||
override fun getGLView() = sessionData.glView
|
||||
|
||||
override fun getWindow() = mActivity.window!!
|
||||
|
||||
override fun getWindowManager() = mActivity.windowManager!!
|
||||
|
||||
override fun setSystemMousePointerVisible(visible: Int) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
|
||||
glView?.pointerIcon = android.view.PointerIcon.getSystemIcon(mActivity,
|
||||
if (visible == 0) android.view.PointerIcon.TYPE_NULL
|
||||
else android.view.PointerIcon.TYPE_DEFAULT)
|
||||
}
|
||||
}
|
||||
|
||||
override fun isPaused(): Boolean {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,14 @@
|
||||
package io.neoterm.frontend.xorg
|
||||
|
||||
import io.neoterm.NeoAudioThread
|
||||
import io.neoterm.NeoGLView
|
||||
import io.neoterm.xorg.NeoGLViewClient
|
||||
import io.neoterm.xorg.NeoXorgViewClient
|
||||
|
||||
/**
|
||||
* @author kiva
|
||||
*/
|
||||
class XSessionData {
|
||||
var audioThread: NeoAudioThread? = null
|
||||
var glView: NeoGLView? = null
|
||||
var client: NeoGLViewClient? = null
|
||||
var client: NeoXorgViewClient? = null
|
||||
}
|
@ -92,8 +92,8 @@ class NeoTermService : Service() {
|
||||
return indexOfRemoved
|
||||
}
|
||||
|
||||
fun createXSession(parameter: XParameter): XSession {
|
||||
val session = XSession.createSession(this, parameter)
|
||||
fun createXSession(activity: Activity, parameter: XParameter): XSession {
|
||||
val session = XSession.createSession(activity, parameter)
|
||||
mXSessions.add(session)
|
||||
updateNotification()
|
||||
return session
|
||||
|
@ -482,7 +482,7 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
|
||||
|
||||
// TODO: Start X server
|
||||
val parameter = XParameter()
|
||||
val session = termService!!.createXSession(parameter)
|
||||
val session = termService!!.createXSession(this, parameter)
|
||||
|
||||
session.mSessionName = generateXSessionName("X")
|
||||
val tab = createXTab(session.mSessionName) as XSessionTab
|
||||
|
Loading…
x
Reference in New Issue
Block a user