From f275cc8f0b0e5baaa2f1ca5dc3a1eeafcf7ed628 Mon Sep 17 00:00:00 2001 From: Joaquin Date: Wed, 5 Jul 2023 22:47:34 +0300 Subject: [PATCH] [android] Add Full UI pages and functional UDP -Added functional UDP protocol for communication with arduino with a linux-compliant protocol. -Added a settings and main menu pannel -Expanded Controller UI with further support for shoulder buttons -Fixed Scaling Issue on Controller Pannel --- {android/.idea => .idea}/.gitignore | 0 {android/.idea => .idea}/.name | 0 {android/.idea => .idea}/android.iml | 0 {android/.idea => .idea}/misc.xml | 0 {android/.idea => .idea}/modules.xml | 0 {android/.idea => .idea}/vcs.xml | 0 android/UDPtest000/.idea/kotlinc.xml | 6 + android/UDPtest000/.idea/misc.xml | 2 +- android/UDPtest000/app/build.gradle | 40 +++ .../app/src/main/AndroidManifest.xml | 18 +- .../com/example/udptest000/MainActivity.java | 271 +++++++++++++++- .../com/example/udptest000/MainScreen.java | 87 ++++++ .../example/udptest000/SettingsActivity.java | 37 +++ .../main/res/layout-land/activity_main.xml | 291 ++++++++++++++++++ .../app/src/main/res/layout/activity_main.xml | 179 ++++++++--- .../main/res/layout/activity_mainscreen.xml | 65 ++++ .../src/main/res/layout/settings_activity.xml | 20 ++ .../app/src/main/res/values/arrays.xml | 12 + .../app/src/main/res/values/strings.xml | 4 + .../app/src/main/res/xml/root_preferences.xml | 53 ++++ android/UDPtest000/build.gradle | 1 + 21 files changed, 1033 insertions(+), 53 deletions(-) rename {android/.idea => .idea}/.gitignore (100%) rename {android/.idea => .idea}/.name (100%) rename {android/.idea => .idea}/android.iml (100%) rename {android/.idea => .idea}/misc.xml (100%) rename {android/.idea => .idea}/modules.xml (100%) rename {android/.idea => .idea}/vcs.xml (100%) create mode 100644 android/UDPtest000/.idea/kotlinc.xml create mode 100644 android/UDPtest000/app/src/main/java/com/example/udptest000/MainScreen.java create mode 100644 android/UDPtest000/app/src/main/java/com/example/udptest000/SettingsActivity.java create mode 100644 android/UDPtest000/app/src/main/res/layout-land/activity_main.xml create mode 100644 android/UDPtest000/app/src/main/res/layout/activity_mainscreen.xml create mode 100644 android/UDPtest000/app/src/main/res/layout/settings_activity.xml create mode 100644 android/UDPtest000/app/src/main/res/values/arrays.xml create mode 100644 android/UDPtest000/app/src/main/res/xml/root_preferences.xml diff --git a/android/.idea/.gitignore b/.idea/.gitignore similarity index 100% rename from android/.idea/.gitignore rename to .idea/.gitignore diff --git a/android/.idea/.name b/.idea/.name similarity index 100% rename from android/.idea/.name rename to .idea/.name diff --git a/android/.idea/android.iml b/.idea/android.iml similarity index 100% rename from android/.idea/android.iml rename to .idea/android.iml diff --git a/android/.idea/misc.xml b/.idea/misc.xml similarity index 100% rename from android/.idea/misc.xml rename to .idea/misc.xml diff --git a/android/.idea/modules.xml b/.idea/modules.xml similarity index 100% rename from android/.idea/modules.xml rename to .idea/modules.xml diff --git a/android/.idea/vcs.xml b/.idea/vcs.xml similarity index 100% rename from android/.idea/vcs.xml rename to .idea/vcs.xml diff --git a/android/UDPtest000/.idea/kotlinc.xml b/android/UDPtest000/.idea/kotlinc.xml new file mode 100644 index 0000000..e1eea1d --- /dev/null +++ b/android/UDPtest000/.idea/kotlinc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/android/UDPtest000/.idea/misc.xml b/android/UDPtest000/.idea/misc.xml index 8978d23..9b0b092 100644 --- a/android/UDPtest000/.idea/misc.xml +++ b/android/UDPtest000/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/android/UDPtest000/app/build.gradle b/android/UDPtest000/app/build.gradle index 1c2232b..d5533f0 100644 --- a/android/UDPtest000/app/build.gradle +++ b/android/UDPtest000/app/build.gradle @@ -1,5 +1,6 @@ plugins { id 'com.android.application' + id 'org.jetbrains.kotlin.android' } android { @@ -14,6 +15,9 @@ android { versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + vectorDrawables { + useSupportLibrary true + } } buildTypes { @@ -26,6 +30,20 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } + buildFeatures { + compose true + } + composeOptions { + kotlinCompilerExtensionVersion '1.3.2' + } + packagingOptions { + resources { + excludes += '/META-INF/{AL2.0,LGPL2.1}' + } + } + kotlinOptions { + jvmTarget = '1.8' + } } dependencies { @@ -33,7 +51,29 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.4.1' implementation 'com.google.android.material:material:1.5.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'androidx.preference:preference:1.2.0' + implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1' + implementation 'androidx.activity:activity-compose:1.5.1' + implementation platform('androidx.compose:compose-bom:2022.10.00') + implementation 'androidx.compose.ui:ui' + implementation 'androidx.compose.ui:ui-graphics' + implementation 'androidx.compose.ui:ui-tooling-preview' + implementation 'androidx.compose.material3:material3' + implementation platform('androidx.compose:compose-bom:2022.10.00') + implementation platform('androidx.compose:compose-bom:2022.10.00') + implementation platform('androidx.compose:compose-bom:2022.10.00') + implementation platform('androidx.compose:compose-bom:2022.10.00') + implementation platform('androidx.compose:compose-bom:2022.10.00') testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00') + androidTestImplementation 'androidx.compose.ui:ui-test-junit4' + androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00') + androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00') + androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00') + androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00') + androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00') + debugImplementation 'androidx.compose.ui:ui-tooling' + debugImplementation 'androidx.compose.ui:ui-test-manifest' } \ No newline at end of file diff --git a/android/UDPtest000/app/src/main/AndroidManifest.xml b/android/UDPtest000/app/src/main/AndroidManifest.xml index e6f57f9..6943e17 100644 --- a/android/UDPtest000/app/src/main/AndroidManifest.xml +++ b/android/UDPtest000/app/src/main/AndroidManifest.xml @@ -3,6 +3,7 @@ xmlns:tools="http://schemas.android.com/tools"> + + android:name=".MainScreen" + android:exported="true" + android:label="@string/title_activity_main_screen" + android:theme="@style/Theme.UDPtest000"> + + + + + \ No newline at end of file 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 index 6844ce3..a28b1e3 100644 --- a/android/UDPtest000/app/src/main/java/com/example/udptest000/MainActivity.java +++ b/android/UDPtest000/app/src/main/java/com/example/udptest000/MainActivity.java @@ -6,46 +6,61 @@ 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 select; + Button start; Button leftb; Button rightb; Button upb; Button downb; + + Button leftb2; + Button rightb2; + Button upb2; + Button downb2; + + Button l1b; + Button r1b; + Button l2b; + Button r2b; //FrameLayout frameLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - button=findViewById(R.id.button); + select=findViewById(R.id.select); + start=findViewById(R.id.start); leftb=findViewById(R.id.leftb); rightb=findViewById(R.id.rightb); upb=findViewById(R.id.upb); downb=findViewById(R.id.downb); + leftb2=findViewById(R.id.leftb2); + rightb2=findViewById(R.id.rightb2); + upb2=findViewById(R.id.upb2); + downb2=findViewById(R.id.downb2); + + l1b=findViewById(R.id.l1b); + r1b=findViewById(R.id.r1b); + l2b=findViewById(R.id.l2b); + r2b=findViewById(R.id.r2b); + //frameLayout=findViewById(R.id.framelayout); //frameLayout.addView(new TrackpadView(getBaseContext())); - button.setOnClickListener(v -> { - UDP_Client Client = new UDP_Client(); - Client.Message = "HW"; - Client.Send(); - }); - leftb.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 = "GG:1|BTTN:1|BUPD:1|;"; + Client.Message = "GG:1|BTTN:4|BUPD:1|;"; break; case MotionEvent.ACTION_UP: - Client.Message = "GG:1|BTTN:1|BUPD:0|;"; + Client.Message = "GG:1|BTTN:4|BUPD:0|;"; } if(Client.Message!=null) { Client.Send(); @@ -61,10 +76,10 @@ public class MainActivity extends AppCompatActivity { UDP_Client Client = new UDP_Client(); switch(event.getAction()) { case MotionEvent.ACTION_DOWN: - Client.Message = "GG:1|BTTN:2|BUPD:1|;"; + Client.Message = "GG:1|BTTN:1|BUPD:1|;"; break; case MotionEvent.ACTION_UP: - Client.Message = "GG:1|BTTN:2|BUPD:0|;"; + Client.Message = "GG:1|BTTN:1|BUPD:0|;"; } if(Client.Message!=null) { Client.Send(); @@ -99,10 +114,100 @@ public class MainActivity extends AppCompatActivity { UDP_Client Client = new UDP_Client(); switch(event.getAction()) { case MotionEvent.ACTION_DOWN: - Client.Message = "GG:1|BTTN:4|BUPD:1|;"; + Client.Message = "GG:1|BTTN:0|BUPD:1|;"; break; case MotionEvent.ACTION_UP: - Client.Message = "GG:1|BTTN:1|BUPD:0|;"; + Client.Message = "GG:1|BTTN:0|BUPD:0|;"; + } + if(Client.Message!=null) { + Client.Send(); + return true; + } + return false; + } + }); + + + + //DPAD + + + + + + + + + + + + leftb2.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 = "GG:1|DBTN:7|DBUD:1|;"; + break; + case MotionEvent.ACTION_UP: + Client.Message = "GG:1|DBTN:7|DBUD:0|;"; + } + if(Client.Message!=null) { + Client.Send(); + return true; + } + return false; + } + }); + + rightb2.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 = "GG:1|DBTN:3|DBUD:1|;"; + break; + case MotionEvent.ACTION_UP: + Client.Message = "GG:1|DBTN:3|DBUD:0|;"; + } + if(Client.Message!=null) { + Client.Send(); + return true; + } + return false; + } + }); + + upb2.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 = "GG:1|DBTN:1|DBUD:1|;"; + break; + case MotionEvent.ACTION_UP: + Client.Message = "GG:1|DBTN:1|DBUD:0|;"; + } + if(Client.Message!=null) { + Client.Send(); + return true; + } + return false; + } + }); + + downb2.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 = "GG:1|DBTN:5|DBUD:1|;"; + break; + case MotionEvent.ACTION_UP: + Client.Message = "GG:1|DBTN:5|DBUD:0|;"; } if(Client.Message!=null) { Client.Send(); @@ -111,5 +216,141 @@ public class MainActivity extends AppCompatActivity { return false; } }); + + + + + + + + + + + + + + //SHOULDERS + + + + + + + l1b.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 = "GG:1|BTTN:6|BUPD:1|;"; + break; + case MotionEvent.ACTION_UP: + Client.Message = "GG:1|BTTN:6|BUPD:0|;"; + } + if(Client.Message!=null) { + Client.Send(); + return true; + } + return false; + } + }); + + r1b.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 = "GG:1|BTTN:7|BUPD:1|;"; + break; + case MotionEvent.ACTION_UP: + Client.Message = "GG:1|BTTN:7|BUPD:0|;"; + } + if(Client.Message!=null) { + Client.Send(); + return true; + } + return false; + } + }); + + l2b.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 = "GG:1|BTTN:8|BUPD:1|;"; + break; + case MotionEvent.ACTION_UP: + Client.Message = "GG:1|BTTN:8|BUPD:0|;"; + } + if(Client.Message!=null) { + Client.Send(); + return true; + } + return false; + } + }); + + r2b.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 = "GG:1|BTTN:9|BUPD:1|;"; + break; + case MotionEvent.ACTION_UP: + Client.Message = "GG:1|BTTN:9|BUPD:0|;"; + } + if(Client.Message!=null) { + Client.Send(); + return true; + } + return false; + } + }); + + + select.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 = "GG:1|BTTN:10|BUPD:1|;"; + break; + case MotionEvent.ACTION_UP: + Client.Message = "GG:1|BTTN:10|BUPD:0|;"; + } + if(Client.Message!=null) { + Client.Send(); + return true; + } + return false; + } + }); + + start.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 = "GG:1|BTTN:11|BUPD:1|;"; + break; + case MotionEvent.ACTION_UP: + Client.Message = "GG:1|BTTN:11|BUPD:0|;"; + } + 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/MainScreen.java b/android/UDPtest000/app/src/main/java/com/example/udptest000/MainScreen.java new file mode 100644 index 0000000..59b0473 --- /dev/null +++ b/android/UDPtest000/app/src/main/java/com/example/udptest000/MainScreen.java @@ -0,0 +1,87 @@ +package com.example.udptest000; + +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.util.Log; +import android.view.MotionEvent; +import android.view.View; +import android.widget.Button; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.preference.PreferenceManager; + +import java.util.Random; + +public class MainScreen extends AppCompatActivity { + @Override protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_mainscreen); + + + Button startbutt = findViewById(R.id.startbutt); + Button settbutt = findViewById(R.id.settbutt); + Button sendbutt = findViewById(R.id.sendbutt); + + SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); + + String ip = pref.getString("ip", "192.168.4.1"); + String port = pref.getString("port", "9696"); + boolean isHidden = pref.getBoolean("isHidden", false); + String ssid = pref.getString("ssid", "ggwifi"); + String pass = pref.getString("pass", "password"); + int adminToken = Integer.parseInt(pref.getString("admintoken", "1234")); + + + + + startbutt.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + Intent switchActivityIntent = new Intent(MainScreen.this, MainActivity.class); + startActivity(switchActivityIntent); + return true; + } + + + }); + + settbutt.setOnTouchListener(new View.OnTouchListener() { + + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + Intent switchActivityIntent = new Intent(MainScreen.this, SettingsActivity.class); + startActivity(switchActivityIntent); + return true; + } + }); + + sendbutt.setOnTouchListener(new View.OnTouchListener() { + + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + UDP_Client client = new UDP_Client(); + client.Message = "GG:1|PREF:" + String.valueOf(adminToken) + "|LCIP:" + ip + "|;"; + client.Send(); + client.Message = "GG:1|PREF:" + String.valueOf(adminToken) + "|PORT:" + port + "|;"; + client.Send(); + client.Message = "GG:1|PREF:" + String.valueOf(adminToken) + "|HIDD:" + (isHidden?"1":"0") + "|;"; + client.Send(); + client.Message = "GG:1|PREF:" + String.valueOf(adminToken) + "|SSID:" + ssid + "|;"; + client.Send(); + client.Message = "GG:1|PREF:" + String.valueOf(adminToken) + "|PASS:" + pass + "|;"; + client.Send(); + + Random rnd = new Random(System.currentTimeMillis()); + int newtok = rnd.nextInt(100000); + client.Message = "GG:1|PREF:" + String.valueOf(adminToken) + "|ATOK:" + String.valueOf(newtok) + "|;"; + client.Send(); + pref.edit().putString("admintoken", String.valueOf(newtok)).apply(); + Log.d("TEST ", String.valueOf(newtok)); + + + return true; + } + }); + } +} diff --git a/android/UDPtest000/app/src/main/java/com/example/udptest000/SettingsActivity.java b/android/UDPtest000/app/src/main/java/com/example/udptest000/SettingsActivity.java new file mode 100644 index 0000000..672a10e --- /dev/null +++ b/android/UDPtest000/app/src/main/java/com/example/udptest000/SettingsActivity.java @@ -0,0 +1,37 @@ +package com.example.udptest000; + +import android.os.Bundle; +import android.widget.EditText; + +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AppCompatActivity; +import androidx.preference.EditTextPreference; +import androidx.preference.PreferenceFragmentCompat; + + +public class SettingsActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.settings_activity); + if (savedInstanceState == null) { + getSupportFragmentManager() + .beginTransaction() + .replace(R.id.settings, new SettingsFragment()) + .commit(); + } + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setDisplayHomeAsUpEnabled(true); + } + + } + + public static class SettingsFragment extends PreferenceFragmentCompat { + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + setPreferencesFromResource(R.xml.root_preferences, rootKey); + } + } +} \ No newline at end of file diff --git a/android/UDPtest000/app/src/main/res/layout-land/activity_main.xml b/android/UDPtest000/app/src/main/res/layout-land/activity_main.xml new file mode 100644 index 0000000..4cf00ef --- /dev/null +++ b/android/UDPtest000/app/src/main/res/layout-land/activity_main.xml @@ -0,0 +1,291 @@ + + + +