-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
./deb/* |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# android-virtual-pen |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
plugins { | ||
alias(libs.plugins.androidApplication) | ||
} | ||
|
||
android { | ||
namespace = "com.pen_input" | ||
compileSdk = 34 | ||
|
||
defaultConfig { | ||
applicationId = "com.pen_input" | ||
minSdk = 24 | ||
targetSdk = 34 | ||
versionCode = 1 | ||
versionName = "1.0" | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation(libs.appcompat) | ||
implementation(libs.material) | ||
implementation(libs.activity) | ||
implementation(libs.constraintlayout) | ||
testImplementation(libs.junit) | ||
androidTestImplementation(libs.ext.junit) | ||
androidTestImplementation(libs.espresso.core) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.pen_input; | ||
|
||
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 <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); | ||
assertEquals("com.pen_input", appContext.getPackageName()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" > | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:dataExtractionRules="@xml/data_extraction_rules" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.Peninput" | ||
tools:targetApi="33" > | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true" > | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity | ||
android:name=".UsbConnectedActivity" | ||
android:exported="true" > | ||
<intent-filter> | ||
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" /> | ||
</intent-filter> | ||
<meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" | ||
android:resource="@xml/accessory_filter" /> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.pen_input; | ||
|
||
import static android.content.ContentValues.TAG; | ||
|
||
import android.app.AlertDialog; | ||
import android.content.Context; | ||
import android.hardware.usb.UsbAccessory; | ||
import android.hardware.usb.UsbManager; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.View; | ||
|
||
import androidx.activity.EdgeToEdge; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.core.graphics.Insets; | ||
import androidx.core.view.ViewCompat; | ||
import androidx.core.view.WindowInsetsCompat; | ||
|
||
import java.util.Optional; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
private UsbManager usbManager; | ||
private View mainView; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
EdgeToEdge.enable(this); | ||
setContentView(R.layout.activity_main); | ||
mainView = findViewById(R.id.main); | ||
ViewCompat.setOnApplyWindowInsetsListener(mainView, (v, insets) -> { | ||
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); | ||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); | ||
return insets; | ||
}); | ||
usbManager = (UsbManager) getSystemService(Context.USB_SERVICE); | ||
CompletableFuture<Optional<UsbAccessory>> usbAccessoryCompletableFuture = CompletableFuture.supplyAsync(this::acquireUsbAccessory); | ||
usbAccessoryCompletableFuture.thenAcceptAsync(maybeUsbAccessory -> maybeUsbAccessory.ifPresent(usbAccessory -> UsbStreamService.streamTouchInputToUsb(usbManager, usbAccessory, mainView))); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
UsbStreamService.closeStream(); | ||
} | ||
|
||
private Optional<UsbAccessory> acquireUsbAccessory() { | ||
boolean isDisplayingUsbConnectionAlert = false; | ||
while (true) { | ||
UsbAccessory[] accessories = usbManager.getAccessoryList(); | ||
if (accessories == null || accessories.length == 0) { | ||
if(!isDisplayingUsbConnectionAlert){ | ||
openAlertDialog("Usb link not established. Make sure your device is connected to the PC and launch the usb-host application."); | ||
isDisplayingUsbConnectionAlert = true; | ||
} | ||
Log.d(TAG, "Empty accessories list, you should initialize the connected PC as accessory"); | ||
} else { | ||
UsbAccessory accessory = accessories[0]; | ||
if(usbManager.hasPermission(accessory)){ | ||
return Optional.of(accessory); | ||
} | ||
} | ||
try { | ||
//noinspection BusyWait | ||
Thread.sleep(1000); | ||
} catch (InterruptedException e) { | ||
return Optional.empty(); | ||
} | ||
} | ||
} | ||
|
||
private void openAlertDialog(String message){ | ||
runOnUiThread(() -> { | ||
new AlertDialog.Builder(mainView.getContext()).setTitle("Warning") | ||
.setMessage(message) | ||
.show(); | ||
}); | ||
} | ||
} |