-
-
Notifications
You must be signed in to change notification settings - Fork 361
Add floating keyboard toggle button on the candidates strip #1377
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
20714e0
161a75a
515f71a
67f4380
69b9ac3
39be83c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,5 @@ | |
| # Directory _build is not used anymore | ||
| /_build | ||
| /release | ||
| /.opencode | ||
| /openspec | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| <item android:state_selected="true" android:drawable="@drawable/ic_floating_toggle_selected"/> | ||
| <item android:drawable="@drawable/ic_floating_toggle"/> | ||
| </selector> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- From materialdesignicons.com "keyboard", converted using android-studio --> | ||
| <vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:width="24dp" | ||
| android:height="24dp" | ||
| android:viewportWidth="24" | ||
| android:viewportHeight="24"> | ||
| <path | ||
| android:fillColor="?attr/colorSubLabel" | ||
| android:pathData="M20,5H4A2,2 0 0,0 2,7V17A2,2 0 0,0 4,19H20A2,2 0 0,0 22,17V7A2,2 0 0,0 20,5M20,17H4V7H20V17M8,9V11H6V9H8M12,9V11H10V9H12M16,9V11H14V9H16M5,15H19V17H5V15Z"/> | ||
| </vector> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- From materialdesignicons.com "keyboard", highlighted when floating mode is active --> | ||
| <vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:width="24dp" | ||
| android:height="24dp" | ||
| android:viewportWidth="24" | ||
| android:viewportHeight="24"> | ||
| <path | ||
| android:fillColor="?attr/colorLabelActivated" | ||
| android:pathData="M20,5H4A2,2 0 0,0 2,7V17A2,2 0 0,0 4,19H20A2,2 0 0,0 22,17V7A2,2 0 0,0 20,5M20,17H4V7H20V17M8,9V11H6V9H8M12,9V11H10V9H12M16,9V11H14V9H16M5,15H19V17H5V15Z"/> | ||
| </vector> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,13 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:hardwareAccelerated="false" android:orientation="vertical" android:background="?attr/colorKeyboard"> | ||
| <juloo.keyboard2.FloatingHandleView android:id="@+id/floating_handle" android:layout_width="match_parent" android:layout_height="24dp" android:visibility="gone"/> | ||
| <juloo.keyboard2.suggestions.CandidatesView android:id="@+id/candidates_view" style="@style/candidates_view"> | ||
| <TextView android:id="@+id/candidates_emoji" style="@style/candidates_emoji"/> | ||
| <TextView android:id="@+id/candidates_left" style="@style/candidates_item"/> | ||
| <TextView android:id="@+id/candidates_middle" style="@style/candidates_item"/> | ||
| <TextView android:id="@+id/candidates_right" style="@style/candidates_item"/> | ||
| <Button android:id="@+id/dictionary_switch" style="@style/change_dictionary"/> | ||
| <Button android:id="@+id/floating_toggle" style="@style/change_dictionary" android:background="@drawable/btn_floating_toggle" android:contentDescription="@string/floating_toggle_description"/> | ||
| </juloo.keyboard2.suggestions.CandidatesView> | ||
| <juloo.keyboard2.Keyboard2View android:id="@+id/keyboard_view" android:layout_width="match_parent" android:layout_height="wrap_content"/> | ||
| </LinearLayout> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #!/usr/bin/env bash | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain a bit more ? I'm not sure this should live in the repo. Instead, you should distribute it to other aarch64 users separately. |
||
| # | ||
| # The official Android NDK only ships Linux x86_64 host toolchains and its | ||
| # ndk-build script rejects aarch64 hosts with: | ||
| # ERROR: Unknown host CPU architecture: aarch64 | ||
| # | ||
| # On aarch64 Linux hosts with qemu-user binfmt enabled, the x86_64 toolchain | ||
| # runs fine transparently. This script patches the NDK's host detection so it | ||
| # uses the linux-x86_64 prebuilt directory on aarch64 hosts. | ||
| # | ||
| # Usage: scripts/fix-ndk-arm64-host.sh [NDK_PATH] | ||
| # NDK_PATH defaults to $ANDROID_HOME/ndk (all installed versions are patched). | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| SCRIPT=$0 | ||
| TARGET_LINE=' aarch64) HOST_ARCH=x86_64;;' | ||
| ANCHOR=' arm64) HOST_ARCH=arm64;;' | ||
|
|
||
| patch_ndk() { | ||
| local file=$1 | ||
| if ! grep -qF 'aarch64) HOST_ARCH=x86_64;;' "$file"; then | ||
| sed -i "/$ANCHOR/a\\$TARGET_LINE" "$file" | ||
| echo "Patched $file" | ||
| else | ||
| echo "Already patched: $file" | ||
| fi | ||
| } | ||
|
|
||
| if [ $# -gt 0 ]; then | ||
| for ndk in "$@"; do | ||
| [ -f "$ndk/build/tools/ndk_bin_common.sh" ] && patch_ndk "$ndk/build/tools/ndk_bin_common.sh" \ | ||
| || echo "Skipping $ndk (not an NDK directory)" | ||
| done | ||
| exit 0 | ||
| fi | ||
|
|
||
| if [ -z "${ANDROID_HOME:-}" ]; then | ||
| echo "ERROR: set ANDROID_HOME or pass an NDK path." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ -d "$ANDROID_HOME/ndk" ]; then | ||
| shopt -s nullglob | ||
| for ndk in "$ANDROID_HOME"/ndk/*/; do | ||
| patch_ndk "$ndk/build/tools/ndk_bin_common.sh" | ||
| done | ||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package juloo.keyboard2; | ||
|
|
||
| import android.content.Context; | ||
| import android.content.res.TypedArray; | ||
| import android.graphics.Canvas; | ||
| import android.graphics.Paint; | ||
| import android.util.AttributeSet; | ||
| import android.view.View; | ||
|
|
||
| /** A small grabber handle used to drag the floating keyboard window. */ | ||
| public class FloatingHandleView extends View | ||
| { | ||
| private static final float HANDLE_WIDTH_DP = 32; | ||
| private static final float HANDLE_THICKNESS_DP = 3; | ||
| private static final float HANDLE_SPACING_DP = 6; | ||
| private static final int HANDLE_ALPHA = 120; | ||
|
|
||
| private final Paint _paint; | ||
|
|
||
| public FloatingHandleView(Context context, AttributeSet attrs) | ||
| { | ||
| super(context, attrs); | ||
| _paint = new Paint(Paint.ANTI_ALIAS_FLAG); | ||
| _paint.setStyle(Paint.Style.STROKE); | ||
| _paint.setStrokeCap(Paint.Cap.ROUND); | ||
| _paint.setStrokeWidth(dp(context, HANDLE_THICKNESS_DP)); | ||
| TypedArray a = context.getTheme().obtainStyledAttributes(R.styleable.keyboard); | ||
| _paint.setColor(a.getColor(R.styleable.keyboard_colorLabel, 0)); | ||
| a.recycle(); | ||
| _paint.setAlpha(HANDLE_ALPHA); | ||
| } | ||
|
|
||
| @Override | ||
| protected void onDraw(Canvas canvas) | ||
| { | ||
| float width = dp(getContext(), HANDLE_WIDTH_DP); | ||
| float spacing = dp(getContext(), HANDLE_SPACING_DP); | ||
| float cx = getWidth() / 2.f; | ||
| float cy = getHeight() / 2.f; | ||
| for (int i = -1; i <= 1; i++) | ||
| { | ||
| float y = cy + i * spacing; | ||
| canvas.drawLine(cx - width / 2.f, y, cx + width / 2.f, y, _paint); | ||
| } | ||
| } | ||
|
|
||
| private static float dp(Context context, float value) | ||
| { | ||
| return value * context.getResources().getDisplayMetrics().density; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ public static enum Event | |
| SWITCH_VOICE_TYPING_CHOOSER, | ||
| HIDE_SELF, | ||
| CHANGE_DICTIONARY, | ||
| TOGGLE_FLOATING, | ||
| } | ||
|
|
||
| // Must be evaluated in the reverse order of their values. | ||
|
|
@@ -663,6 +664,7 @@ public static KeyValue getSpecialKeyByName(String name) | |
| case "complete_emoji": return statefulKey(Stateful.Complete_emoji); | ||
| case "hide_self": return eventKey("⊻", Event.HIDE_SELF, FLAG_SMALLER_FONT); | ||
| case "change_dictionary": return eventKey(0xE01D, Event.CHANGE_DICTIONARY, 0); | ||
| case "toggle_float": return eventKey("Float", Event.TOGGLE_FLOATING, FLAG_SMALLER_FONT); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You added an icon for the button in the status bar, so the key could use it too.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The key should perhaps be called |
||
|
|
||
| /* Key events */ | ||
| case "esc": return keyeventKey("Esc", KeyEvent.KEYCODE_ESCAPE, FLAG_SMALLER_FONT); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add these to your personal gitignore. I don't want to support dev environments in this file because it creates constant maintenance.