1
0
Fork 0
mirror of https://github.com/rfc2822/GfxTablet synced 2025-10-04 10:09:16 +02:00

Major update

* use AndroidStudio/gradle instead of Eclipse/ant
* upgrade to SDK v22 and build tools v22
* manage network connection from CanvasActivity instead of CanvasView
* show a "No host configured" message instead of opening Settings automatically when no host is configured
* use Android 4.4 immersive full-screen (fixes #59)
* use Material design (using support library)
* add setting for dark canvas (closes #54, #73, closes #76)
This commit is contained in:
Ricki Hirner 2015-06-21 18:34:18 +02:00
parent ff865c297b
commit 29e84b8fd0
41 changed files with 675 additions and 462 deletions

View file

@ -1,132 +0,0 @@
package at.bitfire.gfxtablet;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;
import at.bitfire.gfxtablet.NetEvent.Type;
@SuppressLint("ViewConstructor")
public class CanvasView extends View implements OnSharedPreferenceChangeListener {
NetworkClient netClient;
SharedPreferences settings;
boolean acceptStylusOnly;
int maxX, maxY;
public CanvasView(Context context, NetworkClient netClient) {
super(context);
// disable until networking has been configured
setEnabled(false);
setBackgroundColor(0xFFD0D0D0);
settings = PreferenceManager.getDefaultSharedPreferences(context);
settings.registerOnSharedPreferenceChangeListener(this);
reconfigureAcceptedInputDevices();
this.netClient = netClient;
new ConfigureNetworkingTask().execute();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences pref, String key) {
if (key.equals(SettingsActivity.KEY_PREF_HOST))
new ConfigureNetworkingTask().execute();
else if (key.equals(SettingsActivity.KEY_PREF_STYLUS_ONLY))
reconfigureAcceptedInputDevices();
}
void reconfigureAcceptedInputDevices() {
acceptStylusOnly = settings.getBoolean(SettingsActivity.KEY_PREF_STYLUS_ONLY, false);
}
@Override
protected void onSizeChanged (int w, int h, int oldw, int oldh) {
maxX = w;
maxY = h;
}
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
if (isEnabled()) {
for (int ptr = 0; ptr < event.getPointerCount(); ptr++)
if (!acceptStylusOnly || (event.getToolType(ptr) == MotionEvent.TOOL_TYPE_STYLUS)) {
//Log.i("XorgTablet", String.format("Generic motion event logged: %f|%f, pressure %f", event.getX(ptr), event.getY(ptr), event.getPressure(ptr)));
if (event.getActionMasked() == MotionEvent.ACTION_HOVER_MOVE)
netClient.getQueue().add(new NetEvent(Type.TYPE_MOTION,
normalizeX(event.getX(ptr)),
normalizeY(event.getY(ptr)),
normalizePressure(event.getPressure(ptr))
));
}
return true;
}
return false;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (isEnabled()) {
for (int ptr = 0; ptr < event.getPointerCount(); ptr++)
if (!acceptStylusOnly || (event.getToolType(ptr) == MotionEvent.TOOL_TYPE_STYLUS)) {
short nx = normalizeX(event.getX(ptr)),
ny = normalizeY(event.getY(ptr)),
npressure = normalizePressure(event.getPressure(ptr));
//Log.i("XorgTablet", String.format("Touch event logged: %f|%f, pressure %f", event.getX(ptr), event.getY(ptr), event.getPressure(ptr)));
switch (event.getActionMasked()) {
case MotionEvent.ACTION_MOVE:
netClient.getQueue().add(new NetEvent(Type.TYPE_MOTION, nx, ny, npressure));
break;
case MotionEvent.ACTION_DOWN:
netClient.getQueue().add(new NetEvent(Type.TYPE_BUTTON, nx, ny, npressure, 0, true));
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
netClient.getQueue().add(new NetEvent(Type.TYPE_BUTTON, nx, ny, npressure, 0, false));
break;
}
}
return true;
}
return false;
}
short normalizeX(float x) {
return (short)(Math.min(Math.max(0, x), maxX) * Short.MAX_VALUE/maxX);
}
short normalizeY(float x) {
return (short)(Math.min(Math.max(0, x), maxY) * Short.MAX_VALUE/maxY);
}
short normalizePressure(float x) {
return (short)(Math.min(Math.max(0, x), 2.0) * Short.MAX_VALUE/2.0);
}
private class ConfigureNetworkingTask extends AsyncTask<Void, Void, Boolean> {
@Override
protected Boolean doInBackground(Void... params) {
return netClient.configureNetworking();
}
protected void onPostExecute(Boolean success) {
if (success)
setEnabled(true);
else {
setEnabled(false);
Toast.makeText(getContext(), "Unknown host name, please configure", Toast.LENGTH_LONG).show();
getContext().startActivity(new Intent(getContext(), SettingsActivity.class));
}
}
}
}