Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable touchHelper on non-Boox devices #423

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ android {

packagingOptions {
exclude("META-INF/DEPENDENCIES")
exclude("META-INF/INDEX.LIST")
}

buildFeatures {
Expand Down Expand Up @@ -136,9 +137,9 @@ dependencies {
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.google.android.gms:play-services-ads:23.6.0'
implementation 'com.google.android.gms:play-services-auth:21.3.0'
implementation 'com.google.apis:google-api-services-drive:v3-rev197-1.25.0'
implementation 'com.google.apis:google-api-services-drive:v3-rev20250122-2.0.0'
implementation 'com.google.http-client:google-http-client-gson:1.45.3'
implementation 'com.google.api-client:google-api-client-android:1.26.0'
implementation 'com.google.api-client:google-api-client-android:2.7.2'

// AndroidX dependencies
implementation 'androidx.appcompat:appcompat:1.7.0'
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/toolsboox/di/GoogleDriveModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import com.google.android.gms.auth.api.signin.GoogleSignInClient
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.google.android.gms.common.api.Scope
import com.google.api.client.extensions.android.http.AndroidHttp
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential
import com.google.api.client.http.javanet.NetHttpTransport
import com.google.api.client.json.gson.GsonFactory
import com.google.api.services.drive.Drive
import com.google.api.services.drive.DriveScopes
Expand Down Expand Up @@ -49,7 +49,7 @@ object GoogleDriveModule {
*/
fun provideDrive(credential: GoogleAccountCredential): Drive {
return Drive.Builder(
AndroidHttp.newCompatibleTransport(),
NetHttpTransport(),
GsonFactory(),
credential
).setApplicationName(R.string.app_name.toString()).build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,7 @@ import javax.inject.Inject
class DashboardFragment @Inject constructor() : ScreenFragment() {

companion object {
/**
* User already notified about device mismatch.
*/
private var notifiedAboutDeviceMismatch: Boolean = false

/**
* User already notified about new version.
*/
// User already notified about new version.
private var notifiedAboutNewVersion: Boolean = false
}

Expand Down Expand Up @@ -245,11 +238,12 @@ class DashboardFragment @Inject constructor() : ScreenFragment() {
val brand = Build.BRAND.lowercase().contains("onyx")
val device = Build.DEVICE.lowercase().contains("onyx")
val manufacturer = Build.MANUFACTURER.lowercase().contains("onyx")
val notifiedAboutDeviceMismatch = sharedPreferences.getBoolean("notifiedAboutDeviceMismatch", false)
if (brand || device || manufacturer || notifiedAboutDeviceMismatch) return

val message = getString(R.string.dashboard_device_mismatch_message).format(Build.BRAND, Build.DEVICE)

notifiedAboutDeviceMismatch = true
sharedPreferences.edit().putBoolean("notifiedAboutDeviceMismatch", true).apply()
val builder: AlertDialog.Builder = AlertDialog.Builder(this.requireContext())
builder.setTitle(R.string.dashboard_device_mismatch_title)
.setMessage(message)
Expand Down
31 changes: 16 additions & 15 deletions app/src/main/java/com/toolsboox/ui/plugin/SurfaceFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.onyx.android.sdk.data.note.TouchPoint
import com.onyx.android.sdk.pen.RawInputCallback
import com.onyx.android.sdk.pen.TouchHelper
import com.onyx.android.sdk.pen.data.TouchPointList
import com.onyx.android.sdk.utils.DeviceFeatureUtil
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import com.toolsboox.R
Expand Down Expand Up @@ -57,7 +58,7 @@ abstract class SurfaceFragment : ScreenFragment() {
/**
* TouchHelper of the Onyx's pen.
*/
private lateinit var touchHelper: TouchHelper
private var touchHelper: TouchHelper? = null

/**
* The gesture detector
Expand Down Expand Up @@ -171,8 +172,8 @@ abstract class SurfaceFragment : ScreenFragment() {
super.onResume()

initializeSurface()
touchHelper.setRawDrawingEnabled(true)
touchHelper.isRawDrawingRenderEnabled = true
touchHelper?.setRawDrawingEnabled(true)
touchHelper?.isRawDrawingRenderEnabled = true

penState = true
provideToolbarDrawing().toolbarPen.background.setTint(Color.GRAY)
Expand Down Expand Up @@ -261,10 +262,10 @@ abstract class SurfaceFragment : ScreenFragment() {
override fun onPause() {
super.onPause()

touchHelper.setRawDrawingEnabled(false)
touchHelper.isRawDrawingRenderEnabled = false
touchHelper?.setRawDrawingEnabled(false)
touchHelper?.isRawDrawingRenderEnabled = false

touchHelper.closeRawDrawing()
touchHelper?.closeRawDrawing()
bitmap?.recycle()
}

Expand Down Expand Up @@ -298,8 +299,10 @@ abstract class SurfaceFragment : ScreenFragment() {
* @param first first initialization flag
*/
fun initializeSurface(first: Boolean = false) {
val hasStylus = DeviceFeatureUtil.hasStylus(requireContext())

if (first) {
touchHelper = TouchHelper.create(provideSurfaceView(), callback)
if (hasStylus) touchHelper = TouchHelper.create(provideSurfaceView(), callback)
provideSurfaceView().setZOrderOnTop(true)
provideSurfaceView().holder.setFormat(PixelFormat.TRANSPARENT)
}
Expand Down Expand Up @@ -329,10 +332,8 @@ abstract class SurfaceFragment : ScreenFragment() {

clearSurface()

touchHelper.setLimitRect(limit, ArrayList())
.setStrokeWidth(3.0f)
.openRawDrawing()
touchHelper.setStrokeStyle(TouchHelper.STROKE_STYLE_PENCIL)
touchHelper?.setLimitRect(limit, ArrayList())?.setStrokeWidth(3.0f)?.openRawDrawing()
touchHelper?.setStrokeStyle(TouchHelper.STROKE_STYLE_PENCIL)
}

override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
Expand Down Expand Up @@ -419,11 +420,11 @@ abstract class SurfaceFragment : ScreenFragment() {
}
}

touchHelper.setRawDrawingEnabled(false)
touchHelper.isRawDrawingRenderEnabled = false
touchHelper?.setRawDrawingEnabled(false)
touchHelper?.isRawDrawingRenderEnabled = false
provideSurfaceView().holder.unlockCanvasAndPost(lockCanvas)
touchHelper.setRawDrawingEnabled(true)
touchHelper.isRawDrawingRenderEnabled = true
touchHelper?.setRawDrawingEnabled(true)
touchHelper?.isRawDrawingRenderEnabled = true
}

/**
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ plugins {

ext {
applicationName = 'toolboox'
parentVersionCode = 1_06_01_00
parentVersionName = '1.06.01-00'
parentVersionCode = 1_06_02_00
parentVersionName = '1.06.02-00'
}

allprojects {
Expand Down