Skip to content

Commit 57f47cb

Browse files
committed
feat: show shortcut overlay on handwriting canvas when plugin missing
1 parent 714d679 commit 57f47cb

3 files changed

Lines changed: 110 additions & 6 deletions

File tree

app/src/main/java/helium314/keyboard/latin/handwriting/HandwritingView.kt

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import android.content.Context
55
import android.util.AttributeSet
66
import android.view.View
77
import android.widget.ImageButton
8+
import android.widget.ImageView
89
import android.widget.LinearLayout
910
import android.widget.TextView
11+
import android.graphics.drawable.GradientDrawable
1012
import helium314.keyboard.keyboard.KeyboardActionListener
1113
import helium314.keyboard.keyboard.KeyboardId
1214
import helium314.keyboard.keyboard.KeyboardLayoutSet
@@ -113,6 +115,45 @@ class HandwritingView @JvmOverloads constructor(
113115

114116
clearCanvasAndComposition()
115117

118+
val hasPlugin = HandwritingLoader.hasPlugin(context)
119+
val overlay = findViewById<View>(R.id.handwriting_plugin_overlay)
120+
if (!hasPlugin) {
121+
overlay?.visibility = View.VISIBLE
122+
val titleText = findViewById<TextView>(R.id.handwriting_plugin_title)
123+
val summaryText = findViewById<TextView>(R.id.handwriting_plugin_summary)
124+
val iconView = findViewById<ImageView>(R.id.handwriting_plugin_icon)
125+
val button = findViewById<TextView>(R.id.handwriting_plugin_button)
126+
127+
if (titleText != null) titleText.setTextColor(colors.get(ColorType.KEY_TEXT))
128+
if (summaryText != null) summaryText.setTextColor(colors.get(ColorType.KEY_HINT_TEXT))
129+
if (iconView != null) colors.setColor(iconView, ColorType.KEY_ICON)
130+
131+
if (button != null) {
132+
val btnBackground = GradientDrawable().apply {
133+
shape = GradientDrawable.RECTANGLE
134+
cornerRadius = 8f * context.resources.displayMetrics.density
135+
setColor(colors.get(ColorType.ACTION_KEY_BACKGROUND))
136+
}
137+
button.background = btnBackground
138+
button.setTextColor(colors.get(ColorType.KEY_TEXT))
139+
140+
button.setOnClickListener {
141+
val intent = android.content.Intent()
142+
intent.setClass(context, helium314.keyboard.settings.SettingsActivity2::class.java)
143+
intent.putExtra("screen", helium314.keyboard.settings.SettingsDestination.Libraries)
144+
intent.flags = android.content.Intent.FLAG_ACTIVITY_NEW_TASK or android.content.Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED or android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP
145+
try {
146+
context.startActivity(intent)
147+
} catch (e: Exception) {
148+
Log.e("HandwritingView", "Failed to start settings activity", e)
149+
}
150+
KeyboardSwitcher.getInstance().latinIME?.requestHideSelf(0)
151+
}
152+
}
153+
} else {
154+
overlay?.visibility = View.GONE
155+
}
156+
116157
val recognizer = HandwritingLoader.getRecognizer(context)
117158
if (recognizer != null) {
118159
recognizer.setLanguage(language)
@@ -144,8 +185,6 @@ class HandwritingView @JvmOverloads constructor(
144185
}
145186
}
146187
}
147-
} else {
148-
android.widget.Toast.makeText(context, "Please load handwriting plugin in Settings -> Libraries hub", android.widget.Toast.LENGTH_LONG).show()
149188
}
150189
}
151190

app/src/main/res/layout/handwriting_view.xml

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,74 @@
4141
android:contentDescription="Clear" />
4242
</RelativeLayout>
4343

44-
<helium314.keyboard.latin.handwriting.HandwritingCanvas
45-
android:id="@+id/handwriting_canvas"
44+
<FrameLayout
4645
android:layout_width="match_parent"
4746
android:layout_height="0dp"
48-
android:layout_weight="1"
49-
android:background="?android:attr/colorBackground" />
47+
android:layout_weight="1">
48+
49+
<helium314.keyboard.latin.handwriting.HandwritingCanvas
50+
android:id="@+id/handwriting_canvas"
51+
android:layout_width="match_parent"
52+
android:layout_height="match_parent"
53+
android:background="?android:attr/colorBackground" />
54+
55+
<LinearLayout
56+
android:id="@+id/handwriting_plugin_overlay"
57+
android:layout_width="match_parent"
58+
android:layout_height="match_parent"
59+
android:orientation="vertical"
60+
android:gravity="center"
61+
android:clickable="true"
62+
android:focusable="true"
63+
android:padding="24dp"
64+
android:visibility="gone"
65+
android:background="@android:color/transparent">
66+
67+
<ImageView
68+
android:id="@+id/handwriting_plugin_icon"
69+
android:layout_width="48dp"
70+
android:layout_height="48dp"
71+
android:src="@drawable/ic_edit"
72+
android:contentDescription="" />
73+
74+
<TextView
75+
android:id="@+id/handwriting_plugin_title"
76+
android:layout_width="wrap_content"
77+
android:layout_height="wrap_content"
78+
android:layout_marginTop="8dp"
79+
android:text="@string/handwriting_plugin_required"
80+
android:gravity="center"
81+
android:textSize="16sp"
82+
android:textStyle="bold" />
83+
84+
<TextView
85+
android:id="@+id/handwriting_plugin_summary"
86+
android:layout_width="wrap_content"
87+
android:layout_height="wrap_content"
88+
android:layout_marginTop="4dp"
89+
android:text="@string/handwriting_plugin_summary_text"
90+
android:gravity="center"
91+
android:textSize="12sp" />
92+
93+
<TextView
94+
android:id="@+id/handwriting_plugin_button"
95+
android:layout_width="wrap_content"
96+
android:layout_height="wrap_content"
97+
android:layout_marginTop="16dp"
98+
android:paddingTop="8dp"
99+
android:paddingBottom="8dp"
100+
android:paddingStart="16dp"
101+
android:paddingEnd="16dp"
102+
android:text="@string/handwriting_plugin_load_button"
103+
android:gravity="center"
104+
android:textSize="14sp"
105+
android:textStyle="bold"
106+
android:clickable="true"
107+
android:focusable="true" />
108+
109+
</LinearLayout>
110+
111+
</FrameLayout>
50112

51113
</LinearLayout>
52114

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@
300300
<string name="load_handwriting_plugin_success">Handwriting plugin imported successfully</string>
301301
<string name="load_handwriting_plugin_failed">Failed to load handwriting plugin APK</string>
302302
<string name="handwriting">Handwriting</string>
303+
<string name="handwriting_plugin_required">Handwriting plugin required</string>
304+
<string name="handwriting_plugin_summary_text">Please load the handwriting plugin library to enable drawing recognition.</string>
305+
<string name="handwriting_plugin_load_button">Load Plugin</string>
303306
<!-- Preferences item for inserting space after punctuation -->
304307
<string name="autospace_after_punctuation">Autospace after punctuation</string>
305308
<!-- Description for "autospace_after_punctuation" setting -->

0 commit comments

Comments
 (0)