mirror of
https://github.com/rfc2822/GfxTablet
synced 2025-10-03 09:39:16 +02:00
Clean up
This commit is contained in:
parent
ece4f8c4c8
commit
3d8ece763b
10 changed files with 19 additions and 39 deletions
|
@ -3,40 +3,33 @@ package at.bitfire.gfxtablet;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import at.bitfire.gfxtablet.NetEvent.Type;
|
import at.bitfire.gfxtablet.NetEvent.Type;
|
||||||
|
|
||||||
@SuppressLint("ViewConstructor")
|
@SuppressLint("ViewConstructor")
|
||||||
public class CanvasView extends View implements SharedPreferences.OnSharedPreferenceChangeListener {
|
public class CanvasView extends View implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
final SharedPreferences settings;
|
||||||
private static final String TAG = "GfxTablet.CanvasView";
|
private static final String TAG = "GfxTablet.CanvasView";
|
||||||
|
|
||||||
private enum InRangeStatus {
|
private enum InRangeStatus {
|
||||||
OutOfRange,
|
OutOfRange,
|
||||||
InRange,
|
InRange,
|
||||||
FakeInRange
|
FakeInRange
|
||||||
}
|
}
|
||||||
|
private NetworkClient netClient;
|
||||||
final SharedPreferences settings;
|
private boolean acceptStylusOnly;
|
||||||
NetworkClient netClient;
|
private int maxX, maxY;
|
||||||
boolean acceptStylusOnly;
|
private InRangeStatus inRangeStatus;
|
||||||
int maxX, maxY;
|
|
||||||
InRangeStatus inRangeStatus;
|
|
||||||
|
|
||||||
|
|
||||||
// setup
|
// setup
|
||||||
public CanvasView(Context context, AttributeSet attributeSet) {
|
public CanvasView(Context context, AttributeSet attributeSet) {
|
||||||
super(context, attributeSet);
|
super(context, attributeSet);
|
||||||
|
|
||||||
// view is disabled until a network client is set
|
// view is disabled until a network client is set
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
|
|
||||||
settings = PreferenceManager.getDefaultSharedPreferences(context);
|
settings = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
settings.registerOnSharedPreferenceChangeListener(this);
|
settings.registerOnSharedPreferenceChangeListener(this);
|
||||||
setInputMethods();
|
setInputMethods();
|
||||||
|
@ -48,7 +41,6 @@ public class CanvasView extends View implements SharedPreferences.OnSharedPrefer
|
||||||
setEnabled(true);
|
setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// settings
|
// settings
|
||||||
protected void setInputMethods() {
|
protected void setInputMethods() {
|
||||||
acceptStylusOnly = settings.getBoolean(SettingsActivity.KEY_PREF_STYLUS_ONLY, false);
|
acceptStylusOnly = settings.getBoolean(SettingsActivity.KEY_PREF_STYLUS_ONLY, false);
|
||||||
|
@ -61,9 +53,7 @@ public class CanvasView extends View implements SharedPreferences.OnSharedPrefer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// drawing
|
// drawing
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||||
Log.i(TAG, "Canvas size changed: " + w + "x" + h + " (before: " + oldw + "x" + oldh + ")");
|
Log.i(TAG, "Canvas size changed: " + w + "x" + h + " (before: " + oldw + "x" + oldh + ")");
|
||||||
|
@ -148,5 +138,4 @@ public class CanvasView extends View implements SharedPreferences.OnSharedPrefer
|
||||||
short normalizePressure(float x) {
|
short normalizePressure(float x) {
|
||||||
return (short)(Math.min(Math.max(0, x), 2.0) * Short.MAX_VALUE);
|
return (short)(Math.min(Math.max(0, x), 2.0) * Short.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,40 +6,39 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class NetEvent {
|
class NetEvent {
|
||||||
enum Type {
|
enum Type {
|
||||||
TYPE_MOTION,
|
TYPE_MOTION,
|
||||||
TYPE_BUTTON,
|
TYPE_BUTTON,
|
||||||
|
// not specified in protocol, only needed to shut down network thread
|
||||||
// not specified in protocol, only needed to shut down network thread
|
|
||||||
TYPE_DISCONNECT
|
TYPE_DISCONNECT
|
||||||
}
|
}
|
||||||
static final String signature = "GfxTablet";
|
private static final String signature = "GfxTablet";
|
||||||
static final short protocol_version = 2;
|
private static final short protocol_version = 2;
|
||||||
|
|
||||||
final Type type;
|
final Type type;
|
||||||
short x, y, pressure;
|
short x, y, pressure;
|
||||||
byte button, button_down;
|
byte button, button_down;
|
||||||
|
|
||||||
|
|
||||||
public NetEvent(Type type) {
|
NetEvent(Type type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetEvent(Type type, short x, short y, short pressure) {
|
NetEvent(Type type, short x, short y, short pressure) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.pressure = pressure;
|
this.pressure = pressure;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetEvent(Type type, short x, short y, short pressure, int button, boolean button_down) {
|
NetEvent(Type type, short x, short y, short pressure, int button, boolean button_down) {
|
||||||
this(type, x, y, pressure);
|
this(type, x, y, pressure);
|
||||||
this.button = (byte)button;
|
this.button = (byte)button;
|
||||||
this.button_down = (byte)(button_down ? 1 : 0);
|
this.button_down = (byte)(button_down ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] toByteArray() {
|
byte[] toByteArray() {
|
||||||
if (type == Type.TYPE_DISCONNECT)
|
if (type == Type.TYPE_DISCONNECT)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,11 @@ import at.bitfire.gfxtablet.NetEvent.Type;
|
||||||
public class NetworkClient implements Runnable {
|
public class NetworkClient implements Runnable {
|
||||||
static final int GFXTABLET_PORT = 40118;
|
static final int GFXTABLET_PORT = 40118;
|
||||||
|
|
||||||
final LinkedBlockingQueue<NetEvent> motionQueue = new LinkedBlockingQueue<>();
|
private final LinkedBlockingQueue<NetEvent> motionQueue = new LinkedBlockingQueue<>();
|
||||||
LinkedBlockingQueue<NetEvent> getQueue() { return motionQueue; }
|
LinkedBlockingQueue<NetEvent> getQueue() { return motionQueue; }
|
||||||
|
|
||||||
InetAddress destAddress;
|
InetAddress destAddress;
|
||||||
final SharedPreferences preferences;
|
private final SharedPreferences preferences;
|
||||||
|
|
||||||
NetworkClient(SharedPreferences preferences) {
|
NetworkClient(SharedPreferences preferences) {
|
||||||
this.preferences = preferences;
|
this.preferences = preferences;
|
||||||
|
@ -40,7 +40,7 @@ public class NetworkClient implements Runnable {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
DatagramSocket socket = new DatagramSocket();
|
DatagramSocket socket = new DatagramSocket();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
NetEvent event = motionQueue.take();
|
NetEvent event = motionQueue.take();
|
||||||
|
|
||||||
|
|
|
@ -3,17 +3,14 @@ package at.bitfire.gfxtablet;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
|
||||||
public class NetworkServer implements Runnable {
|
public class NetworkServer implements Runnable {
|
||||||
static final int GFXTABLET_PORT = 40118;
|
private static final int GFXTABLET_PORT = 40118;
|
||||||
NetworkClient netClient;
|
private final SharedPreferences preferences;
|
||||||
final SharedPreferences preferences;
|
|
||||||
|
|
||||||
NetworkServer(SharedPreferences preferences) {
|
NetworkServer(SharedPreferences preferences) {
|
||||||
this.preferences = preferences;
|
this.preferences = preferences;
|
||||||
|
@ -36,7 +33,7 @@ public class NetworkServer implements Runnable {
|
||||||
DatagramPacket packet = new DatagramPacket(buf, buf.length);
|
DatagramPacket packet = new DatagramPacket(buf, buf.length);
|
||||||
socket.receive(packet);
|
socket.receive(packet);
|
||||||
int n = buf[60029];
|
int n = buf[60029];
|
||||||
Log.i("receive:", String.valueOf(n));
|
//Log.i("receive:", String.valueOf(n));
|
||||||
if (n != 0){
|
if (n != 0){
|
||||||
packets = buf[60030];
|
packets = buf[60030];
|
||||||
buffer.put(n, buf);
|
buffer.put(n, buf);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package at.bitfire.gfxtablet;
|
package at.bitfire.gfxtablet;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
|
||||||
public class SettingsActivity extends AppCompatActivity {
|
public class SettingsActivity extends AppCompatActivity {
|
||||||
|
@ -14,10 +13,7 @@ public class SettingsActivity extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
setContentView(R.layout.activity_settings);
|
setContentView(R.layout.activity_settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 469 B |
Binary file not shown.
Before Width: | Height: | Size: 373 B |
Binary file not shown.
Before Width: | Height: | Size: 653 B |
Binary file not shown.
Before Width: | Height: | Size: 1,019 B |
|
@ -14,5 +14,4 @@
|
||||||
android:onClick="showSettings"
|
android:onClick="showSettings"
|
||||||
app:showAsAction="ifRoom"
|
app:showAsAction="ifRoom"
|
||||||
android:title="@string/menu_settings"/>
|
android:title="@string/menu_settings"/>
|
||||||
|
|
||||||
</menu>
|
</menu>
|
Loading…
Add table
Add a link
Reference in a new issue