diff --git a/android/UDPtest000/.gitignore b/android/UDPtest000/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/android/UDPtest000/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/android/UDPtest000/.idea/.gitignore b/android/UDPtest000/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/android/UDPtest000/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/android/UDPtest000/.idea/compiler.xml b/android/UDPtest000/.idea/compiler.xml new file mode 100644 index 0000000..b589d56 --- /dev/null +++ b/android/UDPtest000/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/android/UDPtest000/.idea/gradle.xml b/android/UDPtest000/.idea/gradle.xml new file mode 100644 index 0000000..239e8d2 --- /dev/null +++ b/android/UDPtest000/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/android/UDPtest000/.idea/misc.xml b/android/UDPtest000/.idea/misc.xml new file mode 100644 index 0000000..a8a2b16 --- /dev/null +++ b/android/UDPtest000/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/android/UDPtest000/app/.gitignore b/android/UDPtest000/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/android/UDPtest000/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/android/UDPtest000/app/build.gradle b/android/UDPtest000/app/build.gradle new file mode 100644 index 0000000..1c2232b --- /dev/null +++ b/android/UDPtest000/app/build.gradle @@ -0,0 +1,39 @@ +plugins { + id 'com.android.application' +} + +android { + namespace 'com.example.udptest000' + compileSdk 33 + + defaultConfig { + applicationId "com.example.udptest000" + minSdk 30 + targetSdk 33 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation 'androidx.appcompat:appcompat:1.4.1' + implementation 'com.google.android.material:material:1.5.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' +} \ No newline at end of file diff --git a/android/UDPtest000/app/proguard-rules.pro b/android/UDPtest000/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/android/UDPtest000/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# 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 *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/android/UDPtest000/app/src/androidTest/java/com/example/udptest000/ExampleInstrumentedTest.java b/android/UDPtest000/app/src/androidTest/java/com/example/udptest000/ExampleInstrumentedTest.java new file mode 100644 index 0000000..fe7d6d5 --- /dev/null +++ b/android/UDPtest000/app/src/androidTest/java/com/example/udptest000/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.udptest000; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.udptest000", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/android/UDPtest000/app/src/main/AndroidManifest.xml b/android/UDPtest000/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..e6f57f9 --- /dev/null +++ b/android/UDPtest000/app/src/main/AndroidManifest.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/UDPtest000/app/src/main/java/com/example/udptest000 (1).zip b/android/UDPtest000/app/src/main/java/com/example/udptest000 (1).zip new file mode 100644 index 0000000..78a8164 Binary files /dev/null and b/android/UDPtest000/app/src/main/java/com/example/udptest000 (1).zip differ diff --git a/android/UDPtest000/app/src/main/java/com/example/udptest000 (2).zip b/android/UDPtest000/app/src/main/java/com/example/udptest000 (2).zip new file mode 100644 index 0000000..7372dd3 Binary files /dev/null and b/android/UDPtest000/app/src/main/java/com/example/udptest000 (2).zip differ diff --git a/android/UDPtest000/app/src/main/java/com/example/udptest000.zip b/android/UDPtest000/app/src/main/java/com/example/udptest000.zip new file mode 100644 index 0000000..3293656 Binary files /dev/null and b/android/UDPtest000/app/src/main/java/com/example/udptest000.zip differ diff --git a/android/UDPtest000/app/src/main/java/com/example/udptest000/MainActivity.java b/android/UDPtest000/app/src/main/java/com/example/udptest000/MainActivity.java new file mode 100644 index 0000000..c9dba99 --- /dev/null +++ b/android/UDPtest000/app/src/main/java/com/example/udptest000/MainActivity.java @@ -0,0 +1,52 @@ +package com.example.udptest000; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; +import android.view.MotionEvent; +import android.view.View; +import android.widget.Button; +import android.widget.FrameLayout; + +public class MainActivity extends AppCompatActivity { + + Button button; + Button left; + FrameLayout frameLayout; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + button=findViewById(R.id.button); + left=findViewById(R.id.left); + + frameLayout=findViewById(R.id.framelayout); + + frameLayout.addView(new TrackpadView(getBaseContext())); + + button.setOnClickListener(v -> { + UDP_Client Client = new UDP_Client(); + Client.Message = "HW"; + Client.Send(); + }); + + left.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + UDP_Client Client = new UDP_Client(); + switch(event.getAction()) { + case MotionEvent.ACTION_DOWN: + Client.Message = "BLD"; + break; + case MotionEvent.ACTION_UP: + Client.Message = "BLU"; + } + if(Client.Message!=null) { + Client.Send(); + return true; + } + return false; + } + }); + } +} \ No newline at end of file diff --git a/android/UDPtest000/app/src/main/java/com/example/udptest000/TrackpadView.java b/android/UDPtest000/app/src/main/java/com/example/udptest000/TrackpadView.java new file mode 100644 index 0000000..28badbe --- /dev/null +++ b/android/UDPtest000/app/src/main/java/com/example/udptest000/TrackpadView.java @@ -0,0 +1,171 @@ +package com.example.udptest000; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Path; +import android.graphics.PointF; +import android.view.MotionEvent; +import android.view.View; + +public class TrackpadView extends View { + + private final Paint mPaint; + private Bitmap mBitmap; + private final Path mPath; + private final Paint mBitmapPaint; + final int CLICK = 3; + Canvas canvas; + PointF start = new PointF(); + long downStart = 0; + boolean touching = false; + + // coordinate rounding errors + private float reX = 0; + private float reY = 0; + + + public TrackpadView(Context c) { + super(c); + + mPaint = new Paint(); + mPaint.setAntiAlias(true); + mPaint.setDither(true); + + mPaint.setStyle(Paint.Style.STROKE); + mPaint.setStrokeJoin(Paint.Join.ROUND); + mPaint.setStrokeCap(Paint.Cap.ROUND); + + mPath = new Path(); + mBitmapPaint = new Paint(Paint.DITHER_FLAG); + } + + @Override + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w, h, oldw, oldh); + mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); + + } + + @Override + protected void onDraw(Canvas c) { + canvas=c; + canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); + + mPaint.setColor(Color.BLUE); + mPaint.setStrokeWidth(3); + + mPaint.setStrokeWidth(10); + canvas.drawPath(mPath, mPaint); + + if(touching) { + mPaint.setColor(Color.BLACK); + + canvas.drawCircle(mX, mY, 80, mPaint); + + } + + + } + + private float mX=0; + private float mY=0; + private final float TOUCH_TOLERANCE = 4; + private PointF curr; + + private void touch_start(float x, float y) { + touching=true; + + + mPath.reset(); + mPath.moveTo(x, y); + mX = x; + mY = y; + + } + private void touch_move(float x, float y, boolean silent) { + + + + + float rx = x - mX; + float ry = y - mY; + float dx = Math.abs(rx); + float dy = Math.abs(ry); + + + if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) { + if(!silent) mPath.quadTo(mX, mY, (x+mX)/2, (y+mY)/2); + mX = x; + mY = y; + + + UDP_Client Client = new UDP_Client(); + int frx= (int) rx; + int fry= (int) ry; + Client.Message = "MRX"+frx+"Y"+fry; + Client.Send(); + } + + + } + private void touch_up() { + mPath.lineTo(mX, mY); + // kill this so we don't double draw + mPath.reset(); + touching=false; + } + + + @Override + public boolean onTouchEvent(MotionEvent event) { + float x = event.getX(); + float y = event.getY(); + curr = new PointF(event.getX(), event.getY()); + double newDist = 0; + + + switch (event.getAction()) { + case MotionEvent.ACTION_DOWN: + + downStart = System.currentTimeMillis(); + start.set(curr); + touch_start(x, y); + + invalidate(); + break; + case MotionEvent.ACTION_MOVE: + + int xDiff1 = (int) Math.abs(curr.x - start.x); + int yDiff1 = (int) Math.abs(curr.y - start.y); + + + //Log.d("onTouchEvent",xDiff1+" "+yDiff1+" "+CLICK); + long thisTime = System.currentTimeMillis() - downStart; + + touch_move(x, y, false); + + invalidate(); + break; + case MotionEvent.ACTION_UP: + + int xDiff = (int) Math.abs(curr.x - start.x); + int yDiff = (int) Math.abs(curr.y - start.y); + if (xDiff < CLICK && yDiff < CLICK) { + + UDP_Client Client = new UDP_Client(); + Client.Message = "CL"; + Client.Send(); + + } + + touch_up(); + invalidate(); + + break; + } + return true; + } +} \ No newline at end of file diff --git a/android/UDPtest000/app/src/main/java/com/example/udptest000/UDP_Client.java b/android/UDPtest000/app/src/main/java/com/example/udptest000/UDP_Client.java new file mode 100644 index 0000000..35e45e7 --- /dev/null +++ b/android/UDPtest000/app/src/main/java/com/example/udptest000/UDP_Client.java @@ -0,0 +1,87 @@ +package com.example.udptest000; + +import android.annotation.SuppressLint; +import android.os.AsyncTask; + +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; + +public class UDP_Client { + private InetAddress IPAddress = null; + private String message = "OO" ; + private AsyncTask async_cient; + public String Message; + + + @SuppressLint("NewApi") + public void Send() + { + new Thread(() -> { + DatagramSocket ds = null; + + try + { + byte[] ipAddr = new byte[]{ (byte) 192, (byte) 168,(byte)4, (byte) 1}; + InetAddress addr = InetAddress.getByAddress(ipAddr); + ds = new DatagramSocket(9696); + DatagramPacket dp; + dp = new DatagramPacket(Message.getBytes(), Message.getBytes().length, addr, 9696); + ds.setBroadcast(true); + ds.send(dp); + } + catch (Exception e) + { + e.printStackTrace(); + } + finally + { + if (ds != null) + { + ds.close(); + } + } + }).start(); + + /* + async_cient = new AsyncTask() + { + @Override + protected Void doInBackground(Void... params) + { + DatagramSocket ds = null; + + try + { + byte[] ipAddr = new byte[]{ (byte) 192, (byte) 168,(byte)4, (byte) 1}; + InetAddress addr = InetAddress.getByAddress(ipAddr); + ds = new DatagramSocket(9696); + DatagramPacket dp; + dp = new DatagramPacket(Message.getBytes(), Message.getBytes().length, addr, 9696); + ds.setBroadcast(true); + ds.send(dp); + } + catch (Exception e) + { + e.printStackTrace(); + } + finally + { + if (ds != null) + { + ds.close(); + } + } + return null; + } + + protected void onPostExecute(Void result) + { + super.onPostExecute(result); + } + }; + + if (Build.VERSION.SDK_INT >= 11) async_cient.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + else async_cient.execute();*/ + } +} diff --git a/android/UDPtest000/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/android/UDPtest000/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/android/UDPtest000/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/android/UDPtest000/app/src/main/res/drawable/ic_launcher_background.xml b/android/UDPtest000/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/android/UDPtest000/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/UDPtest000/app/src/main/res/layout/activity_main.xml b/android/UDPtest000/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..e19bd4e --- /dev/null +++ b/android/UDPtest000/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,40 @@ + + + +