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.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import at.bitfire.gfxtablet.NetEvent.Type;
|
||||
|
||||
@SuppressLint("ViewConstructor")
|
||||
public class CanvasView extends View implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
final SharedPreferences settings;
|
||||
private static final String TAG = "GfxTablet.CanvasView";
|
||||
|
||||
private enum InRangeStatus {
|
||||
OutOfRange,
|
||||
InRange,
|
||||
FakeInRange
|
||||
}
|
||||
|
||||
final SharedPreferences settings;
|
||||
NetworkClient netClient;
|
||||
boolean acceptStylusOnly;
|
||||
int maxX, maxY;
|
||||
InRangeStatus inRangeStatus;
|
||||
|
||||
private NetworkClient netClient;
|
||||
private boolean acceptStylusOnly;
|
||||
private int maxX, maxY;
|
||||
private InRangeStatus inRangeStatus;
|
||||
|
||||
// setup
|
||||
public CanvasView(Context context, AttributeSet attributeSet) {
|
||||
super(context, attributeSet);
|
||||
|
||||
// view is disabled until a network client is set
|
||||
setEnabled(false);
|
||||
|
||||
settings = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
settings.registerOnSharedPreferenceChangeListener(this);
|
||||
setInputMethods();
|
||||
|
@ -48,7 +41,6 @@ public class CanvasView extends View implements SharedPreferences.OnSharedPrefer
|
|||
setEnabled(true);
|
||||
}
|
||||
|
||||
|
||||
// settings
|
||||
protected void setInputMethods() {
|
||||
acceptStylusOnly = settings.getBoolean(SettingsActivity.KEY_PREF_STYLUS_ONLY, false);
|
||||
|
@ -61,9 +53,7 @@ public class CanvasView extends View implements SharedPreferences.OnSharedPrefer
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// drawing
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int 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) {
|
||||
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.IOException;
|
||||
|
||||
public class NetEvent {
|
||||
class NetEvent {
|
||||
enum Type {
|
||||
TYPE_MOTION,
|
||||
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
|
||||
}
|
||||
static final String signature = "GfxTablet";
|
||||
static final short protocol_version = 2;
|
||||
private static final String signature = "GfxTablet";
|
||||
private static final short protocol_version = 2;
|
||||
|
||||
final Type type;
|
||||
short x, y, pressure;
|
||||
byte button, button_down;
|
||||
|
||||
|
||||
public NetEvent(Type type) {
|
||||
NetEvent(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.x = x;
|
||||
this.y = y;
|
||||
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.button = (byte)button;
|
||||
this.button_down = (byte)(button_down ? 1 : 0);
|
||||
}
|
||||
|
||||
public byte[] toByteArray() {
|
||||
byte[] toByteArray() {
|
||||
if (type == Type.TYPE_DISCONNECT)
|
||||
return null;
|
||||
|
||||
|
|
|
@ -15,11 +15,11 @@ import at.bitfire.gfxtablet.NetEvent.Type;
|
|||
public class NetworkClient implements Runnable {
|
||||
static final int GFXTABLET_PORT = 40118;
|
||||
|
||||
final LinkedBlockingQueue<NetEvent> motionQueue = new LinkedBlockingQueue<>();
|
||||
private final LinkedBlockingQueue<NetEvent> motionQueue = new LinkedBlockingQueue<>();
|
||||
LinkedBlockingQueue<NetEvent> getQueue() { return motionQueue; }
|
||||
|
||||
InetAddress destAddress;
|
||||
final SharedPreferences preferences;
|
||||
private final SharedPreferences preferences;
|
||||
|
||||
NetworkClient(SharedPreferences preferences) {
|
||||
this.preferences = preferences;
|
||||
|
@ -40,7 +40,7 @@ public class NetworkClient implements Runnable {
|
|||
public void run() {
|
||||
try {
|
||||
DatagramSocket socket = new DatagramSocket();
|
||||
|
||||
|
||||
while (true) {
|
||||
NetEvent event = motionQueue.take();
|
||||
|
||||
|
|
|
@ -3,17 +3,14 @@ package at.bitfire.gfxtablet;
|
|||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
public class NetworkServer implements Runnable {
|
||||
static final int GFXTABLET_PORT = 40118;
|
||||
NetworkClient netClient;
|
||||
final SharedPreferences preferences;
|
||||
private static final int GFXTABLET_PORT = 40118;
|
||||
private final SharedPreferences preferences;
|
||||
|
||||
NetworkServer(SharedPreferences preferences) {
|
||||
this.preferences = preferences;
|
||||
|
@ -36,7 +33,7 @@ public class NetworkServer implements Runnable {
|
|||
DatagramPacket packet = new DatagramPacket(buf, buf.length);
|
||||
socket.receive(packet);
|
||||
int n = buf[60029];
|
||||
Log.i("receive:", String.valueOf(n));
|
||||
//Log.i("receive:", String.valueOf(n));
|
||||
if (n != 0){
|
||||
packets = buf[60030];
|
||||
buffer.put(n, buf);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package at.bitfire.gfxtablet;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
|
@ -14,10 +13,7 @@ public class SettingsActivity extends AppCompatActivity {
|
|||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
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"
|
||||
app:showAsAction="ifRoom"
|
||||
android:title="@string/menu_settings"/>
|
||||
|
||||
</menu>
|
Loading…
Add table
Add a link
Reference in a new issue