Simpler thread management
using the alarm thread to refresh the surface
This commit is contained in:
parent
10f6023e98
commit
1a572bd955
5 changed files with 49 additions and 28 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -32,3 +32,5 @@ app/app.iml
|
|||
ehthumbs.db
|
||||
Thumbs.db
|
||||
|
||||
|
||||
app/app-all-release.apk
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.ab.x48" android:installLocation="auto" android:versionCode="72" android:versionName="1.72">
|
||||
package="org.ab.x48" android:installLocation="auto" android:versionCode="73" android:versionName="1.73">
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
||||
<activity android:name=".X48"
|
||||
android:label="@string/app_name"
|
||||
|
|
|
@ -35,10 +35,9 @@ import android.view.MotionEvent;
|
|||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
|
||||
public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runnable {
|
||||
public class HPView extends SurfaceView implements SurfaceHolder.Callback {
|
||||
|
||||
private static final int MAX_TOUCHES = 49;
|
||||
private Thread drawThread;
|
||||
private X48 x48;
|
||||
private Bitmap mainScreen;
|
||||
private SurfaceHolder mSurfaceHolder;
|
||||
|
@ -1028,19 +1027,23 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna
|
|||
|
||||
public void key(int code, boolean down, int pointerID) {
|
||||
if (code < MAX_TOUCHES) {
|
||||
synchronized(queuedCodes) {
|
||||
if (down) {
|
||||
Integer cI = code + 1;
|
||||
synchronized(queuedCodes) {
|
||||
queuedCodes.add(cI);
|
||||
}
|
||||
touches[code] = pointerID;
|
||||
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
|
||||
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
||||
} else {
|
||||
Integer cI = code + 100;
|
||||
synchronized(queuedCodes) {
|
||||
queuedCodes.add(cI);
|
||||
}
|
||||
touches[code] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//x48.SIGALRM();
|
||||
x48.flipScreen();
|
||||
}
|
||||
}
|
||||
|
@ -1082,8 +1085,6 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna
|
|||
Log.i("x48", "Surface created");
|
||||
|
||||
surfaceValid = true;
|
||||
drawThread = new Thread(this);
|
||||
drawThread.start();
|
||||
|
||||
}
|
||||
|
||||
|
@ -1114,24 +1115,13 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna
|
|||
pause = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Log.i("x48", "drawing thread started");
|
||||
x48.flipScreen();
|
||||
while (surfaceValid) {
|
||||
public void refresh() {
|
||||
if (surfaceValid) {
|
||||
if (needFlip || x48.fillScreenData(buf, ann) == 1) {
|
||||
needFlip = false;
|
||||
refreshMainScreen(buf);
|
||||
}
|
||||
do {
|
||||
try {
|
||||
Thread.sleep(40);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} while (pause && surfaceValid);
|
||||
}
|
||||
//Log.i("x48", "drawing thread stopped");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -215,11 +215,14 @@ public class X48 extends Activity {
|
|||
SIGALRM = null;
|
||||
}
|
||||
SIGALRM = new Timer();
|
||||
SIGALRM.schedule(new TimerTask() {
|
||||
SIGALRM.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (thread != null)
|
||||
if (thread != null) {
|
||||
SIGALRM();
|
||||
if (mainView != null)
|
||||
mainView.refresh();
|
||||
}
|
||||
}
|
||||
}, 0, 20);
|
||||
if (mainView != null)
|
||||
|
|
|
@ -622,12 +622,38 @@ GetEvent()
|
|||
#endif
|
||||
{
|
||||
|
||||
int wake = 0;
|
||||
static int release_pending = 0;
|
||||
static int release_pending_code = 0;
|
||||
int wake = 1;
|
||||
/*wake = (*android_env)->CallIntMethod(android_env, android_callback, waitEvent);
|
||||
return wake;
|
||||
*/
|
||||
|
||||
int code = (*android_env)->CallIntMethod(android_env, android_callback, waitEvent);
|
||||
if (release_pending)
|
||||
{
|
||||
key_event(release_pending_code, 0);
|
||||
wake = 1;
|
||||
release_pending = 0;
|
||||
return wake;
|
||||
}
|
||||
|
||||
unsigned int code = 0;
|
||||
while ((code=(*android_env)->CallIntMethod(android_env, android_callback, waitEvent)) > 0) {
|
||||
//LOGI("code %u", code);
|
||||
if (code < 100)
|
||||
{
|
||||
key_event(code - 1, 1);
|
||||
wake = 1;
|
||||
break;
|
||||
} else {
|
||||
//key_event(code - 100, 0);
|
||||
release_pending = 1;
|
||||
release_pending_code = code - 100;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return wake;
|
||||
|
||||
//LOGI("code: %d", code);
|
||||
//FIX for Zenfone 2
|
||||
|
@ -636,7 +662,7 @@ GetEvent()
|
|||
req.tv_nsec = 100L;
|
||||
nanosleep(&req , &rem);*/
|
||||
|
||||
if (code < 0)
|
||||
/*if (code < 0)
|
||||
{
|
||||
code = -code;
|
||||
wake = 0;
|
||||
|
@ -655,7 +681,7 @@ GetEvent()
|
|||
|
||||
// LOGI("wake: %d", wake);
|
||||
|
||||
return wake;
|
||||
return wake;*/
|
||||
}
|
||||
|
||||
int
|
||||
|
|
Loading…
Reference in a new issue