mirror of
https://github.com/rfc2822/GfxTablet
synced 2025-10-03 09:39:16 +02:00
initial commit
This commit is contained in:
commit
49b61c7f7e
28 changed files with 673 additions and 0 deletions
61
.gitignore
vendored
Normal file
61
.gitignore
vendored
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
### ANDROID
|
||||||
|
|
||||||
|
# built application files
|
||||||
|
*.apk
|
||||||
|
*.ap_
|
||||||
|
|
||||||
|
# files for the dex VM
|
||||||
|
*.dex
|
||||||
|
|
||||||
|
# Java class files
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# generated files
|
||||||
|
bin/
|
||||||
|
gen/
|
||||||
|
|
||||||
|
# Local configuration file (sdk path, etc)
|
||||||
|
local.properties
|
||||||
|
|
||||||
|
# Eclipse project files
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
|
||||||
|
# Proguard folder generated by Eclipse
|
||||||
|
proguard/
|
||||||
|
|
||||||
|
# Intellij project files
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
|
||||||
|
### ECLIPSE
|
||||||
|
|
||||||
|
*.pydevproject
|
||||||
|
.project
|
||||||
|
.metadata
|
||||||
|
bin/**
|
||||||
|
tmp/**
|
||||||
|
tmp/**/*
|
||||||
|
*.tmp
|
||||||
|
*.bak
|
||||||
|
*.swp
|
||||||
|
*~.nib
|
||||||
|
local.properties
|
||||||
|
.classpath
|
||||||
|
.settings/
|
||||||
|
.loadpath
|
||||||
|
|
||||||
|
# External tool builders
|
||||||
|
.externalToolBuilders/
|
||||||
|
|
||||||
|
# Locally stored "Eclipse launch configurations"
|
||||||
|
*.launch
|
||||||
|
|
||||||
|
# CDT-specific
|
||||||
|
.cproject
|
||||||
|
|
||||||
|
# PDT-specific
|
||||||
|
.buildpath
|
36
AndroidManifest.xml
Normal file
36
AndroidManifest.xml
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.gimpusers.xorgtablet"
|
||||||
|
android:versionCode="1"
|
||||||
|
android:versionName="1.0" >
|
||||||
|
|
||||||
|
<uses-sdk
|
||||||
|
android:minSdkVersion="14"
|
||||||
|
android:targetSdkVersion="14" />
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:allowBackup="true"
|
||||||
|
android:icon="@drawable/ic_launcher"
|
||||||
|
android:label="@string/app_name" >
|
||||||
|
<activity
|
||||||
|
android:name="com.gimpusers.xorgtablet.CanvasActivity"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:screenOrientation="landscape" >
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
<activity
|
||||||
|
android:name="com.gimpusers.xorgtablet.SettingsActivity"
|
||||||
|
android:label="@string/title_activity_settings" >
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
|
android:value="com.gimpusers.xorgtablet.CanvasActivity" />
|
||||||
|
</activity>
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</manifest>
|
3
README.md
Normal file
3
README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
|
||||||
|
XorgTablet
|
||||||
|
==========
|
BIN
libs/android-support-v4.jar
Normal file
BIN
libs/android-support-v4.jar
Normal file
Binary file not shown.
20
proguard-project.txt
Normal file
20
proguard-project.txt
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# To enable ProGuard in your project, edit project.properties
|
||||||
|
# to define the proguard.config property as described in that file.
|
||||||
|
#
|
||||||
|
# Add project specific ProGuard rules here.
|
||||||
|
# By default, the flags in this file are appended to flags specified
|
||||||
|
# in ${sdk.dir}/tools/proguard/proguard-android.txt
|
||||||
|
# You can edit the include path and order by changing the ProGuard
|
||||||
|
# include property in project.properties.
|
||||||
|
#
|
||||||
|
# For more details, see
|
||||||
|
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||||
|
|
||||||
|
# Add any project specific keep options here:
|
||||||
|
|
||||||
|
# If your project uses WebView with JS, uncomment the following
|
||||||
|
# and specify the fully qualified class name to the JavaScript interface
|
||||||
|
# class:
|
||||||
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
|
# public *;
|
||||||
|
#}
|
14
project.properties
Normal file
14
project.properties
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
# This file is automatically generated by Android Tools.
|
||||||
|
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||||
|
#
|
||||||
|
# This file must be checked in Version Control Systems.
|
||||||
|
#
|
||||||
|
# To customize properties used by the Ant build system edit
|
||||||
|
# "ant.properties", and override values to adapt the script to your
|
||||||
|
# project structure.
|
||||||
|
#
|
||||||
|
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
|
||||||
|
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
||||||
|
|
||||||
|
# Project target.
|
||||||
|
target=android-14
|
BIN
res/drawable-hdpi/ic_launcher.png
Normal file
BIN
res/drawable-hdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.2 KiB |
BIN
res/drawable-mdpi/ic_launcher.png
Normal file
BIN
res/drawable-mdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.5 KiB |
BIN
res/drawable-xhdpi/ic_launcher.png
Normal file
BIN
res/drawable-xhdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
17
res/layout/activity_canvas.xml
Normal file
17
res/layout/activity_canvas.xml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".CanvasActivity" >
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/canvas_layout"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:orientation="vertical" >
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
8
res/menu/activity_canvas.xml
Normal file
8
res/menu/activity_canvas.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:orderInCategory="100"
|
||||||
|
android:showAsAction="ifRoom"
|
||||||
|
android:title="@string/menu_settings" android:onClick="showSettings"/>
|
||||||
|
|
||||||
|
</menu>
|
11
res/values-v11/styles.xml
Normal file
11
res/values-v11/styles.xml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Base application theme for API 11+. This theme completely replaces
|
||||||
|
AppBaseTheme from res/values/styles.xml on API 11+ devices.
|
||||||
|
-->
|
||||||
|
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
|
||||||
|
<!-- API 11 theme customizations can go here. -->
|
||||||
|
</style>
|
||||||
|
|
||||||
|
</resources>
|
12
res/values-v14/styles.xml
Normal file
12
res/values-v14/styles.xml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Base application theme for API 14+. This theme completely replaces
|
||||||
|
AppBaseTheme from BOTH res/values/styles.xml and
|
||||||
|
res/values-v11/styles.xml on API 14+ devices.
|
||||||
|
-->
|
||||||
|
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
|
||||||
|
<!-- API 14 theme customizations can go here. -->
|
||||||
|
</style>
|
||||||
|
|
||||||
|
</resources>
|
9
res/values/strings.xml
Normal file
9
res/values/strings.xml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<string name="app_name">XorgTablet</string>
|
||||||
|
<string name="menu_settings">Settings</string>
|
||||||
|
<string name="preferences_host_title">X.org host</string>
|
||||||
|
<string name="stylus_preference">Sense stylus only</string>
|
||||||
|
|
||||||
|
</resources>
|
14
res/values/strings_activity_settings.xml
Normal file
14
res/values/strings_activity_settings.xml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<string name="title_activity_settings">Settings</string>
|
||||||
|
|
||||||
|
<!-- Strings related to Settings -->
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Example General settings -->
|
||||||
|
|
||||||
|
<!-- Example settings for Data & Sync -->
|
||||||
|
|
||||||
|
<!-- Example settings for Notifications -->
|
||||||
|
|
||||||
|
</resources>
|
20
res/values/styles.xml
Normal file
20
res/values/styles.xml
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Base application theme, dependent on API level. This theme is replaced
|
||||||
|
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
|
||||||
|
-->
|
||||||
|
<style name="AppBaseTheme" parent="android:Theme.Light">
|
||||||
|
<!--
|
||||||
|
Theme customizations available in newer API levels can go in
|
||||||
|
res/values-vXX/styles.xml, while customizations related to
|
||||||
|
backward-compatibility can go here.
|
||||||
|
-->
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<!-- Application theme. -->
|
||||||
|
<style name="AppTheme" parent="AppBaseTheme">
|
||||||
|
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
|
||||||
|
</style>
|
||||||
|
|
||||||
|
</resources>
|
4
res/xml/drawing_preferences.xml
Normal file
4
res/xml/drawing_preferences.xml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
|
<CheckBoxPreference android:title="@string/stylus_preference" android:key="stylus_only_preference" android:defaultValue="false"/>
|
||||||
|
</PreferenceScreen>
|
4
res/xml/network_preferences.xml
Normal file
4
res/xml/network_preferences.xml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
|
<EditTextPreference android:title="@string/preferences_host_title" android:key="host_preference" android:defaultValue="127.0.0.1" android:singleLine="true"/>
|
||||||
|
</PreferenceScreen>
|
10
res/xml/preference_headers.xml
Normal file
10
res/xml/preference_headers.xml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<preference-headers
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<header android:fragment="com.gimpusers.xorgtablet.SettingsActivity$NetworkPrefsFragment"
|
||||||
|
android:title="Networking" />
|
||||||
|
|
||||||
|
<header android:fragment="com.gimpusers.xorgtablet.SettingsActivity$DrawingPrefsFragment"
|
||||||
|
android:title="Drawing" />
|
||||||
|
|
||||||
|
</preference-headers>
|
50
src/com/gimpusers/xorgtablet/CanvasActivity.java
Normal file
50
src/com/gimpusers/xorgtablet/CanvasActivity.java
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
package com.gimpusers.xorgtablet;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
public class CanvasActivity extends Activity {
|
||||||
|
CanvasView canvas;
|
||||||
|
SharedPreferences prefs;
|
||||||
|
XorgClient xorgClient;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
PreferenceManager.setDefaultValues(this, R.xml.network_preferences, false);
|
||||||
|
PreferenceManager.setDefaultValues(this, R.xml.drawing_preferences, false);
|
||||||
|
|
||||||
|
setContentView(R.layout.activity_canvas);
|
||||||
|
LinearLayout layout = (LinearLayout)findViewById(R.id.canvas_layout);
|
||||||
|
|
||||||
|
new Thread(xorgClient = new XorgClient(PreferenceManager.getDefaultSharedPreferences(this))).start();
|
||||||
|
|
||||||
|
canvas = new CanvasView(this, xorgClient);
|
||||||
|
layout.addView(canvas);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
xorgClient.getQueue().add(new XDisconnectEvent());
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
getMenuInflater().inflate(R.menu.activity_canvas, menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showSettings(MenuItem item) {
|
||||||
|
startActivity(new Intent(CanvasActivity.this, SettingsActivity.class));
|
||||||
|
}
|
||||||
|
}
|
113
src/com/gimpusers/xorgtablet/CanvasView.java
Normal file
113
src/com/gimpusers/xorgtablet/CanvasView.java
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
package com.gimpusers.xorgtablet;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
@SuppressLint("ViewConstructor")
|
||||||
|
public class CanvasView extends View implements OnSharedPreferenceChangeListener {
|
||||||
|
final static int PRESSURE_RESOLUTION = 10000;
|
||||||
|
|
||||||
|
XorgClient xorgClient;
|
||||||
|
SharedPreferences settings;
|
||||||
|
boolean acceptStylusOnly;
|
||||||
|
|
||||||
|
public CanvasView(Context context, XorgClient xorgClient) {
|
||||||
|
super(context);
|
||||||
|
|
||||||
|
// disable until networking has been configured
|
||||||
|
setEnabled(false);
|
||||||
|
setBackgroundColor(0xFFD0D0D0);
|
||||||
|
|
||||||
|
settings = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
settings.registerOnSharedPreferenceChangeListener(this);
|
||||||
|
reconfigureAcceptedInputDevices();
|
||||||
|
|
||||||
|
this.xorgClient = xorgClient;
|
||||||
|
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) {
|
||||||
|
Toast.makeText(getContext(), String.format("%dx%d", w, h), Toast.LENGTH_SHORT).show();
|
||||||
|
xorgClient.getQueue().add(new XConfigurationEvent(w, h, PRESSURE_RESOLUTION));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@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)
|
||||||
|
xorgClient.getQueue().add(new XMotionEvent((int)event.getX(ptr), (int)event.getY(ptr), (int)event.getPressure(ptr)*PRESSURE_RESOLUTION));
|
||||||
|
}
|
||||||
|
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)) {
|
||||||
|
//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:
|
||||||
|
xorgClient.getQueue().add(new XMotionEvent((int)event.getX(ptr), (int)event.getY(ptr), (int)event.getPressure(ptr)*PRESSURE_RESOLUTION));
|
||||||
|
break;
|
||||||
|
case MotionEvent.ACTION_DOWN:
|
||||||
|
xorgClient.getQueue().add(new XButtonEvent((int)event.getX(ptr), (int)event.getY(ptr), (int)event.getPressure(ptr)*PRESSURE_RESOLUTION, true));
|
||||||
|
break;
|
||||||
|
case MotionEvent.ACTION_UP:
|
||||||
|
case MotionEvent.ACTION_CANCEL:
|
||||||
|
xorgClient.getQueue().add(new XButtonEvent((int)event.getX(ptr), (int)event.getY(ptr), (int)event.getPressure(ptr)*PRESSURE_RESOLUTION, false));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private class ConfigureNetworkingTask extends AsyncTask<Void, Void, Boolean> {
|
||||||
|
@Override
|
||||||
|
protected Boolean doInBackground(Void... params) {
|
||||||
|
return xorgClient.configureNetworking();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onPostExecute(Boolean success) {
|
||||||
|
if (success)
|
||||||
|
setEnabled(true);
|
||||||
|
else {
|
||||||
|
setEnabled(false);
|
||||||
|
Toast.makeText(getContext(), "Unknown host name, network tablet disabled!", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
64
src/com/gimpusers/xorgtablet/SettingsActivity.java
Normal file
64
src/com/gimpusers/xorgtablet/SettingsActivity.java
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
package com.gimpusers.xorgtablet;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
import android.media.Ringtone;
|
||||||
|
import android.media.RingtoneManager;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.ListPreference;
|
||||||
|
import android.preference.Preference;
|
||||||
|
import android.preference.PreferenceActivity;
|
||||||
|
import android.preference.PreferenceCategory;
|
||||||
|
import android.preference.PreferenceFragment;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.preference.RingtonePreference;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.support.v4.app.NavUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SettingsActivity extends PreferenceActivity {
|
||||||
|
public static final String
|
||||||
|
KEY_PREF_HOST = "host_preference",
|
||||||
|
KEY_PREF_STYLUS_ONLY = "stylus_only_preference";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBuildHeaders(List<Header> target) {
|
||||||
|
loadHeadersFromResource(R.xml.preference_headers, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
if (item.getItemId() == android.R.id.home)
|
||||||
|
finish();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class NetworkPrefsFragment extends PreferenceFragment {
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
addPreferencesFromResource(R.xml.network_preferences);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DrawingPrefsFragment extends PreferenceFragment {
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
addPreferencesFromResource(R.xml.drawing_preferences);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
34
src/com/gimpusers/xorgtablet/XButtonEvent.java
Normal file
34
src/com/gimpusers/xorgtablet/XButtonEvent.java
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
package com.gimpusers.xorgtablet;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class XButtonEvent extends XEvent {
|
||||||
|
boolean down;
|
||||||
|
|
||||||
|
public XButtonEvent(int x, int y, int pressure, boolean down) {
|
||||||
|
super(x, y, pressure);
|
||||||
|
this.down = down;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] toByteArray() {
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
DataOutputStream dos = new DataOutputStream(baos);
|
||||||
|
|
||||||
|
try {
|
||||||
|
dos.write(1); /* EVENT_TYPE_BUTTON */
|
||||||
|
dos.writeShort(x);
|
||||||
|
dos.writeShort(y);
|
||||||
|
dos.writeShort(pressure);
|
||||||
|
dos.write(1);
|
||||||
|
dos.write(down ? 1 : 0);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return baos.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
28
src/com/gimpusers/xorgtablet/XConfigurationEvent.java
Normal file
28
src/com/gimpusers/xorgtablet/XConfigurationEvent.java
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
package com.gimpusers.xorgtablet;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class XConfigurationEvent extends XEvent {
|
||||||
|
public XConfigurationEvent(int x, int y, int pressure) {
|
||||||
|
super(x, y, pressure);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] toByteArray() {
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
DataOutputStream dos = new DataOutputStream(baos);
|
||||||
|
|
||||||
|
try {
|
||||||
|
dos.write(2); /* EVENT_TYPE_SET_RESOLUTION */
|
||||||
|
dos.writeShort(x);
|
||||||
|
dos.writeShort(y);
|
||||||
|
dos.writeShort(pressure);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return baos.toByteArray();
|
||||||
|
}
|
||||||
|
}
|
12
src/com/gimpusers/xorgtablet/XDisconnectEvent.java
Normal file
12
src/com/gimpusers/xorgtablet/XDisconnectEvent.java
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package com.gimpusers.xorgtablet;
|
||||||
|
|
||||||
|
public class XDisconnectEvent extends XEvent {
|
||||||
|
public XDisconnectEvent() {
|
||||||
|
super(0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] toByteArray() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
17
src/com/gimpusers/xorgtablet/XEvent.java
Normal file
17
src/com/gimpusers/xorgtablet/XEvent.java
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package com.gimpusers.xorgtablet;
|
||||||
|
|
||||||
|
public abstract class XEvent {
|
||||||
|
int x, y, pressure;
|
||||||
|
|
||||||
|
public int getX() { return x; }
|
||||||
|
public int getY() { return y; }
|
||||||
|
public int getPressure() { return pressure; }
|
||||||
|
|
||||||
|
public XEvent(int x, int y, int pressure) {
|
||||||
|
this.x = Math.max(x, 0);
|
||||||
|
this.y = Math.max(y, 0);
|
||||||
|
this.pressure = pressure;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract byte[] toByteArray();
|
||||||
|
}
|
28
src/com/gimpusers/xorgtablet/XMotionEvent.java
Normal file
28
src/com/gimpusers/xorgtablet/XMotionEvent.java
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
package com.gimpusers.xorgtablet;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class XMotionEvent extends XEvent {
|
||||||
|
public XMotionEvent(int x, int y, int pressure) {
|
||||||
|
super(x, y, pressure);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] toByteArray() {
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
DataOutputStream dos = new DataOutputStream(baos);
|
||||||
|
|
||||||
|
try {
|
||||||
|
dos.write(0); /* EVENT_TYPE_MOTION */
|
||||||
|
dos.writeShort(x);
|
||||||
|
dos.writeShort(y);
|
||||||
|
dos.writeShort(pressure);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return baos.toByteArray();
|
||||||
|
}
|
||||||
|
}
|
84
src/com/gimpusers/xorgtablet/XorgClient.java
Normal file
84
src/com/gimpusers/xorgtablet/XorgClient.java
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
package com.gimpusers.xorgtablet;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.net.DatagramPacket;
|
||||||
|
import java.net.DatagramSocket;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.SocketException;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
|
||||||
|
import android.app.Service;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Binder;
|
||||||
|
import android.os.IBinder;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.provider.ContactsContract.Contacts.Data;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
// see protocol.h in xf86-networktablet driver for details about the protocol
|
||||||
|
|
||||||
|
|
||||||
|
public class XorgClient implements Runnable {
|
||||||
|
LinkedBlockingQueue<XEvent> motionQueue = new LinkedBlockingQueue<XEvent>();
|
||||||
|
LinkedBlockingQueue<XEvent> getQueue() { return motionQueue; }
|
||||||
|
|
||||||
|
InetAddress destAddress;
|
||||||
|
SharedPreferences preferences;
|
||||||
|
XConfigurationEvent lastConfiguration = null;
|
||||||
|
|
||||||
|
XorgClient(SharedPreferences preferences) {
|
||||||
|
this.preferences = preferences;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean configureNetworking() {
|
||||||
|
try {
|
||||||
|
String hostName = preferences.getString(SettingsActivity.KEY_PREF_HOST, "127.0.0.1");
|
||||||
|
destAddress = InetAddress.getByName(hostName);
|
||||||
|
|
||||||
|
if (lastConfiguration != null)
|
||||||
|
motionQueue.add(lastConfiguration);
|
||||||
|
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
destAddress = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
DatagramSocket socket = new DatagramSocket();
|
||||||
|
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
DataOutputStream dos = new DataOutputStream(baos);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
XEvent event = motionQueue.take();
|
||||||
|
|
||||||
|
if (destAddress == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (event.getClass() == XConfigurationEvent.class)
|
||||||
|
lastConfiguration = (XConfigurationEvent)event;
|
||||||
|
else if (event.getClass() == XDisconnectEvent.class)
|
||||||
|
break;
|
||||||
|
|
||||||
|
byte[] data = event.toByteArray();
|
||||||
|
DatagramPacket pkt = new DatagramPacket(data, data.length, destAddress, 40117);
|
||||||
|
socket.send(pkt);
|
||||||
|
|
||||||
|
baos.reset();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e("XorgTablet", "motionQueue failed: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue