Repository navigation
fix: only pan screen for keyboard when Minecraft chat is open #379
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
Open
Vivo-Y12
wants to merge
10
commits into
AngelAuraMC:v3_openjdk
Choose a base branch
from
Vivo-Y12:meow
base: v3_openjdk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
159081e
feat: Imp now screen only pop up only when minecraft open & keyboard …
Vivo-Y12 18c5b6b
remove ci: build debug apk only for testing
Vivo-Y12 205e656
Merge branch 'AngelAuraMC:v3_openjdk' into meow
Vivo-Y12 428a53a
feat: make keyboard panning key lists configurable
Vivo-Y12 4587e88
refactor: use a name-based key picker for chat pan key lists v1
Vivo-Y12 7c4045d
refactor: track chat state from the software keyboard only
Vivo-Y12 7b3e66c
address review: move GLFW tracking to TouchCharInput, use null defaul…
Vivo-Y12 8bbc7e8
fix: use context for resources in key picker preference
Vivo-Y12 f250d47
feat: detect chat open from control buttons
Vivo-Y12 4fe0d8f
fix: reset the pan when the grab gate clears the chat flag
Vivo-Y12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/KeyboardPanKeysPreference.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| package net.kdt.pojavlaunch.prefs; | ||
|
|
||
| import android.content.Context; | ||
| import android.util.AttributeSet; | ||
| import android.view.Gravity; | ||
| import android.view.LayoutInflater; | ||
| import android.view.View; | ||
| import android.widget.ArrayAdapter; | ||
| import android.widget.Button; | ||
| import android.widget.LinearLayout; | ||
| import android.widget.Spinner; | ||
| import android.widget.TextView; | ||
|
|
||
| import androidx.annotation.NonNull; | ||
| import androidx.annotation.Nullable; | ||
| import androidx.appcompat.app.AlertDialog; | ||
| import androidx.preference.Preference; | ||
|
|
||
| import net.kdt.pojavlaunch.EfficientAndroidLWJGLKeycode; | ||
| import net.kdt.pojavlaunch.R; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Name-based picker for the keyboard panning chat key lists, similar to the | ||
| * key mapping spinner of the control editor. The stored value stays a | ||
| * comma-separated string of GLFW key codes, parsed by LauncherPreferences. | ||
| */ | ||
| public class KeyboardPanKeysPreference extends Preference { | ||
|
|
||
| private static final String ANDROID_NS = "http://schemas.android.com/apk/res/android"; | ||
| private final String mDefaultValue; | ||
|
|
||
| public KeyboardPanKeysPreference(@NonNull Context context, @Nullable AttributeSet attrs) { | ||
| super(context, attrs); | ||
| mDefaultValue = attrs.getAttributeValue(ANDROID_NS, "defaultValue"); | ||
| setOnPreferenceClickListener(preference -> { | ||
| showKeyPickerDialog(); | ||
| return true; | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public void onAttachedToHierarchy(@NonNull androidx.preference.PreferenceManager preferenceManager) { | ||
| super.onAttachedToHierarchy(preferenceManager); | ||
| refreshSummary(); | ||
| } | ||
|
|
||
| private void showKeyPickerDialog() { | ||
| Context ctx = getContext(); | ||
| List<Integer> keys = parseKeyCodes(getPersistedString(mDefaultValue)); | ||
|
|
||
| View dialogView = LayoutInflater.from(ctx).inflate(R.layout.dialog_keyboard_pan_keys, null); | ||
| LinearLayout keyList = dialogView.findViewById(R.id.chatPanKeys_list); | ||
| Spinner spinner = dialogView.findViewById(R.id.chatPanKeys_spinner); | ||
| Button addButton = dialogView.findViewById(R.id.chatPanKeys_addButton); | ||
|
|
||
| ArrayAdapter<String> adapter = new ArrayAdapter<>(ctx, R.layout.item_centered_textview, | ||
| EfficientAndroidLWJGLKeycode.generateKeyName()); | ||
| spinner.setAdapter(adapter); | ||
|
|
||
| rebuildKeyList(keyList, keys); | ||
|
|
||
| addButton.setOnClickListener(v -> { | ||
| int keycode = EfficientAndroidLWJGLKeycode.getValueByIndex(spinner.getSelectedItemPosition()); | ||
| if (!keys.contains(keycode)) { | ||
| keys.add(keycode); | ||
| rebuildKeyList(keyList, keys); | ||
| } | ||
| }); | ||
|
|
||
| new AlertDialog.Builder(ctx) | ||
| .setTitle(getTitle()) | ||
| .setView(dialogView) | ||
| .setPositiveButton(android.R.string.ok, (dialog, which) -> { | ||
| persistString(joinKeyCodes(keys)); | ||
| refreshSummary(); | ||
| }) | ||
| .setNegativeButton(android.R.string.cancel, null) | ||
| .show(); | ||
| } | ||
|
|
||
| /** Re-creates one tappable row per key; tapping a key removes it */ | ||
| private void rebuildKeyList(LinearLayout container, List<Integer> keys) { | ||
| container.removeAllViews(); | ||
| int padding = (int) (12 * getContext().getResources().getDisplayMetrics().density); | ||
| for (Integer key : keys) { | ||
| TextView keyView = new TextView(container.getContext()); | ||
| keyView.setText(getKeyName(key)); | ||
| keyView.setGravity(Gravity.CENTER); | ||
| keyView.setPadding(0, padding, 0, padding); | ||
| keyView.setOnClickListener(v -> { | ||
| keys.remove(key); | ||
| rebuildKeyList(container, keys); | ||
| }); | ||
| container.addView(keyView); | ||
| } | ||
| } | ||
|
|
||
| private void refreshSummary() { | ||
| List<Integer> keys = parseKeyCodes(getPersistedString(mDefaultValue)); | ||
| if (keys.isEmpty()) { | ||
| setSummary(R.string.mcl_setting_chat_pan_keys_none); | ||
| return; | ||
| } | ||
| StringBuilder nameList = new StringBuilder(); | ||
| for (int key : keys) { | ||
| if (nameList.length() > 0) nameList.append(", "); | ||
| nameList.append(getKeyName(key)); | ||
| } | ||
| setSummary(nameList.toString()); | ||
| } | ||
|
|
||
| private static String getKeyName(int keycode) { | ||
| return EfficientAndroidLWJGLKeycode.generateKeyName()[EfficientAndroidLWJGLKeycode.getIndexByValue(keycode)]; | ||
| } | ||
|
|
||
| private static List<Integer> parseKeyCodes(String stored) { | ||
| List<Integer> keys = new ArrayList<>(); | ||
| if (stored != null) { | ||
| for (String part : stored.split(",")) { | ||
| try { | ||
| keys.add(Integer.valueOf(part.trim())); | ||
| } catch (NumberFormatException ignored) { | ||
| } | ||
| } | ||
| } | ||
| return keys; | ||
| } | ||
|
|
||
| private static String joinKeyCodes(List<Integer> keys) { | ||
| StringBuilder joined = new StringBuilder(); | ||
| for (int key : keys) { | ||
| if (joined.length() > 0) joined.append(','); | ||
| joined.append(key); | ||
| } | ||
| return joined.toString(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
app_pojavlauncher/src/main/res/layout/dialog_keyboard_pan_keys.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:orientation="vertical" | ||
| android:padding="24dp" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content"> | ||
|
|
||
| <TextView | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:text="@string/mcl_setting_chat_pan_keys_hint" /> | ||
|
|
||
| <LinearLayout | ||
| android:id="@+id/chatPanKeys_list" | ||
| android:orientation="vertical" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" /> | ||
|
|
||
| <Spinner | ||
| android:id="@+id/chatPanKeys_spinner" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginTop="16dp" /> | ||
|
|
||
| <Button | ||
| android:id="@+id/chatPanKeys_addButton" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_gravity="center_horizontal" | ||
| android:text="@string/mcl_setting_chat_pan_keys_add" /> | ||
|
|
||
| </LinearLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.