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

Ability to reorder popup characters. #1921

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

ArenaL5
Copy link
Contributor

@ArenaL5 ArenaL5 commented Dec 19, 2019

This pull request is mainly to close the issue discussed at the end of AnySoftKeyboard/LanguagePack#231. This will immediately fix #1681 and, with time, several issues in both LanguagePack and AnySoftKeyboard repos.

It's... underwhelming, because @martholomew had the perfect interface for configuring this:

These would all be re-orderable checkboxes ([edit] not sure the exact name, but its the thing that looks like this) in settings.
I think that this would solve all sorts of problems people have.

But I realized I don't have the ability to implement that. The closest preference class in the Android libraries is MultiSelectListPreference, but that doesn't save the order of the checked elements. Writing event listeners for Android is already complex, and the drag-and-drop mechanism that @martholomew describes is so complex that several Maven libraries exist to implement it. And even then, we'd still have to add the checkboxes.

As I had already work half-done and I'd rather not delay this upwards of month, I implemented a very basic EditTextPreference, as seen in commit c7ba078. You can configure it from UI → Tweaks and more → Order of popup characters. I hope that this preference will be replaced for a more user-friendly one.

The instructions are very short but I think you devs will understand it pretty easily. The preference value is not case-sensitive, characters other than N, L, O, S have no effect, an empty string will disable popupCharacters altogether, and any duplicate character that would remain in the popup after reordering them all is discarded.

Besides all that, there's also fixes for some other issues, as you can see in the commit summaries (#1914, #1418, #1662) and a small addition to README.md.

@codecov
Copy link

codecov bot commented Dec 19, 2019

Codecov Report

Merging #1921 (a0adb61) into master (28bf659) will increase coverage by 0.05%.
The diff coverage is 89.65%.

@@             Coverage Diff              @@
##             master    #1921      +/-   ##
============================================
+ Coverage     65.10%   65.15%   +0.05%     
- Complexity     3004     3023      +19     
============================================
  Files           237      237              
  Lines         15863    15903      +40     
  Branches       2087     2101      +14     
============================================
+ Hits          10327    10362      +35     
  Misses         4776     4776              
- Partials        760      765       +5     
Impacted Files Coverage Δ Complexity Δ
...ava/com/anysoftkeyboard/keyboards/AnyKeyboard.java 90.57% <ø> (-0.10%) 108.00 <0.00> (-2.00)
...om/anysoftkeyboard/keyboards/AnyPopupKeyboard.java 87.27% <75.00%> (+1.43%) 24.00 <2.00> (+1.00)
...yboards/views/PopupKeyboardPositionCalculator.java 80.76% <77.77%> (-8.12%) 5.00 <0.00> (+2.00) ⬇️
...anysoftkeyboard/keyboards/ExternalAnyKeyboard.java 73.21% <92.77%> (+0.92%) 74.00 <0.00> (+14.00)
...om/anysoftkeyboard/ime/AnySoftKeyboardRxPrefs.java 95.69% <100.00%> (+0.09%) 23.00 <0.00> (+1.00)
...n/java/com/anysoftkeyboard/keyboards/Keyboard.java 84.65% <100.00%> (-0.18%) 62.00 <0.00> (ø)
...yboards/views/AnyKeyboardViewWithMiniKeyboard.java 91.72% <100.00%> (+0.12%) 41.00 <2.00> (+2.00)
...nysoftkeyboard/ui/tutorials/VersionChangeLogs.java 98.86% <100.00%> (+0.02%) 1.00 <0.00> (ø)
... and 1 more

@ArenaL5
Copy link
Contributor Author

ArenaL5 commented Dec 19, 2019

Sorry, I always forget to use the automated tests.

The entirety of testShortPressWhenNoPrimaryKeyAndPopupCharactersShouldShowPopupWindow is throwing assertion errors because I broke something (I suppose with my first commit) and I hadn't noticed while testing it manually because it's not really a common occurence: a key with popupCharacters but no keycode.

I'll try to fix it soon.

@menny menny added this to the 1.10-r4 milestone Dec 27, 2019
@ArenaL5
Copy link
Contributor Author

ArenaL5 commented Jan 4, 2020

I don't know if I made it clear, this works now. I fixed the bug I created with my last commit.

Is there anything left to fix before merging this?

@menny
Copy link
Member

menny commented Feb 13, 2020

@ArenaL5 would you mind trying to rebase this?

@ArenaL5
Copy link
Contributor Author

ArenaL5 commented Feb 14, 2020

No problem!

EDIT: Please wait a bit, somehow I lost an edit during rebase.

@ArenaL5
Copy link
Contributor Author

ArenaL5 commented Feb 14, 2020

This should do it. I've done all the automated tests and I tested it manually. ./scripts/ci/ci_check.sh throws an error because it finds duplicate IDs I didn't edit. (for dictionaries and keyboards)

Everything else is okay.

UPDATE FROM 8TH OF MARCH: What the hell, I just clicked a button to merge changes from master. ...good for me. ¯_(ツ)_/¯

@ArenaL5 ArenaL5 requested review from a team as code owners March 8, 2020 16:59
@nicoursi
Copy link
Contributor

nicoursi commented Mar 23, 2020

-------------------------edit----------------------------------
I made some more tests, and I think that it's not working at all. It doesn't matter how I change those letters order, the popups always appear at the same order. I don't know if this is device specific or if something got broken by this: Merge branch 'master' into patches
-------------------------edit----------------------------------

Hi! I was curious about this commit, so I compiled it to test it on my device. I was surprised to see how this commit breaks a symbols layout.

As an example, try to use qwerty with symbols. You'll notice that none of those symbols designed for that layout will be available in the supposed order. I tried to change all the combinations with the letters NLOS, but there was no way that layout could be useful to me any more.
I don't know if I just didn't grasp its functioning or if this is really what this fix does.

If I may give you my opinion, I think L, or a new letter, should leave the active layout as it is. And then the user can play with the other letters if he wants to change it.

I notice, though, that it doesn't afffect long press popups like this one:

<Key android:codes="101" android:popupKeyboard="@xml/popup_qwerty_e"/>

So, if this PL is going to be merged, I hope there'll be a letter to preserve the current layout popup caracters order ;)

@menny menny modified the milestones: 1.10-r4, 1.10-r5 Mar 24, 2020
@ArenaL5
Copy link
Contributor Author

ArenaL5 commented Mar 26, 2020

Sorry for the late reply.

popupKeyboard are custom layouts which can even have pre-recorded phrases, and my code can't analyze them, so they stay as they are.

My patch is only supposed to reorder symbols in popupCharacters, and no, I didn't think of adding an option to leave them as they are. Did you intend to have symbols at both sides of the pop-up or something?

About it not working, it's possible, I haven't tested it on a long time. I'll rebase this branch and try to fix it. Thank you! I'll let you know when I know something.

Copy link
Member

@menny menny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I love it.
A few comments and also, please, add some unit-tests.
And add an entry in the change-log here and here.

@nicoursi
Copy link
Contributor

nicoursi commented Mar 27, 2020

Sorry for the late reply.

popupKeyboard are custom layouts which can even have pre-recorded phrases, and my code can't analyze them, so they stay as they are.

My patch is only supposed to reorder symbols in popupCharacters, and no, I didn't think of adding an option to leave them as they are. Did you intend to have symbols at both sides of the pop-up or something?

About it not working, it's possible, I haven't tested it on a long time. I'll rebase this branch and try to fix it. Thank you! I'll let you know when I know something.

Thanks for answering back. I tested it again after rebasing.

About not working. I found out it does indeed work but changes in the string do not happen straight away. They take effect after the app is cleared from recents. This can be very confusing.

If someone uses some of the layouts with symbols (eg. QWERTY with symbols), after an ASK update (including this PR) he won't have easy access to those symbols on long press. And changing the settings won't work unless he clears everything in recents.

With NSLO I get most of the keys right except:

E: supposed to give 3 but gives
T: supposed to give 5 but gives ț
U: supposed to give 7 but gives ű
C: supposed to give - but gives ĉ

I hope you find this discussion useful, otherwise just let me know and I'll leave you alone with your tests 🙂

@ArenaL5
Copy link
Contributor Author

ArenaL5 commented Mar 27, 2020

@menny. Thanks for the compliment but I didn't do anything yet. I just rebased again to clean up the history. 😆 I'll try to fix those issues soon.

@nicoursi: It was useful, actually. I did notice that the keyboard retained its old settings for a while, but I didn't know what to do to load the new ones.

Options programmed for other people do take effect straight away, so there's probably a line of code to flush the cached keyboard. I'll investigate.

@menny
Copy link
Member

menny commented Mar 27, 2020

Yes, there is a way to flush the cache. Look for other places where we react to preference changes (in the AnySoftKeyboard* classes)

This commits also fixes a style issue at AnyKeyboardViewWithMiniKeyboard.java, and squashes two very minor bugs:
- The setting for popupCharacters order was still forcibly made uppercase, interfering with the 1-character groups;
- A key in a test at ExternalAnyKeyboardTest.java was not correctly checked.
Replacing info_footer.xml with actual code for an info footer that's compliant with https://developer.android.com/reference/android/preference/EditTextPreference would be appreciated.
@ArenaL5
Copy link
Contributor Author

ArenaL5 commented Dec 25, 2020

Okay, I've been using this branch for a couple days and I see no hint of memory leakage or any breaking. I think it's good to go.

@menny: Merging this branch will change how popupCharacters are laid out, as discussed earlier, but you have the final word on this.

Currently, for keys on the left half on the keyboard, symbols in popupCharacters (after reordering) will be laid out in columns, bottom to top, then left to right.

3 or less characters: 1 2 3

4-12 characters:      2  4  6  8 10 12
                      1  3  5  7  9 11

13-18 characters:     3  6  9 12 15 18
                      2  5  8 11 14 17
                      1  4  7 10 13 16

For keys on the right hand, the rules are the same but the result is mirrored. If you feel another order is better or want to add a user preference just in case, please say so. If you find no problems, merge away!

Merry Christmas. 🎄

Copy link
Member

@menny menny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another question: how does the reverse value affect the currency XMLs in the app? And did you do a quick survey of if/how this will affect XMLs in various language-packs?

@@ -147,6 +147,8 @@ protected void onSharedPreferenceChange(String key) {
|| key.startsWith(KeyboardExtensionFactory.BOTTOM_ROW_PREF_ID_PREFIX)
|| key.startsWith(KeyboardExtensionFactory.TOP_ROW_PREF_ID_PREFIX)) {
onAddOnsCriticalChange();
} else if (key.equals("settings_key_popup_characters_order")) {
onAddOnsCriticalChange();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance to add a unit-test for this?
Basically, change this setting value and see that the cached keyboards were re-created.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the R.string.settings_key_popup_characters_order in the test. It is fine to use this string here in the keyboard code, but in tests we should use the value from the resources.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this enough? ad47846


if (count <= 3) return 1;
if (count <= 12) return 2;
return 3;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's strange that we do not have a unit-test for this.
Maybe in the allAddons variant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testCodesParsing() at ExternalAnyKeyboardTest.java tests it indirectly.

I could add a test-unit to test this directly, but how do I test a private method?

ime/app/src/main/res/values-en/strings.xml Outdated Show resolved Hide resolved
@@ -374,6 +374,8 @@

<string name="settings_key_allow_layouts_to_provide_generic_rows">settings_key_allow_layouts_to_provide_generic_rows</string>
<string name="settings_key_apply_remote_app_colors">settings_key_apply_remote_app_colors</string>
<string name="settings_key_popup_characters_order">settings_key_popup_characters_order</string>
<string name="settings_key_popup_characters_order_default">NLOS</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default value should be in settings_defaults_dont_translate.xml

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is there. The default value is NLOS, line 378.

Is there any other settings_defaults_dont_translate.xml?

@@ -485,6 +485,16 @@
<string name="bottom_generic_row_dialog_title">Select row type</string>
<string name="bottom_generic_row_summary">Selected bottom row: %s</string>

<string name="popup_characters_order_title">Characters shown upon long press</string>
<string name="popup_characters_order_summary">Order is important. Uppercase letters represent different characters for every layout:\n
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this long explanation look in the UI? Can you share a screenshot?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, here. Please excuse the Spanglish.

Screenshot_20210107-183045_AnySoftKeyboard_Dev

I don't remember the exact details, but I had to tweak a template for an info section in XML. It must be at 380af81 (“Add better instructions for the characters reordering”).

@menny
Copy link
Member

menny commented Dec 30, 2020

Overall, this is a great change!

@ArenaL5
Copy link
Contributor Author

ArenaL5 commented Jan 7, 2021

Thank you!

Sorry I've been a little disappeared lately. I'll push new commits to fulfill your requests. It should take a few days to close them all.

The only difference between the Spanish and the default symbols layout is an interrobang. There should probably not be a Spanish version for the common symbols layout anyways.
@ArenaL5
Copy link
Contributor Author

ArenaL5 commented Jan 11, 2021

Answering your first question (which I didn't see at the moment):

Another question: how does the reverse value affect the currency XMLs in the app? And did you do a quick survey of if/how this will affect XMLs in various language-packs?

I had only tried it with the Spanish layout, which only defines the main layout and popupCharacters (it doesn't include XML files for static popups).

I'm testing now other keyboards:

  • the Brazilian layout with no Ç or ' key: it reverses the popup for U, but this is consistent with the popups created from popupCharacters and this code)
  • emoji keyboards: it reverses the popup for some emojis, but this is confusing because the race selection switches directions for ~40% of the emojis.

I will push an extra commit to fix the emoji problem and any other layout my code breaks.

Only two files were changed by hand in this commit:
- buildSrc/src/main/java/emoji/EmojiKeyboardCreator.java
- gradle/emoji_generator.gradle

Every other change in this commit is the result of running
./gradlew makeEmojiKeyboards.

ime/app/src/main/res/xml-v27/quick_text_unicode_uncollected.xml deleted
after running that command, as it was unused.
@ArenaL5
Copy link
Contributor Author

ArenaL5 commented Jan 12, 2021

I made more tests; apparently these commits won't break anything. The currency key in the main symbols keyboard is a normal key with popupCharacters on the left hand of the keyboard, so it doesn't even get mirrored. The main symbol is the € sign for me.

The keyboards using predefined popups (most if not all of them could be changed to popupCharacters) appear correctly. Popups opened on the right half are mirrored exactly as they're supposed to do, no matter if they're defined as XML or built up from popupCharacters:

old_rendering
mirrored

Unless you remember some other popup that should not be mirrored (emojis were already taken care of), this looks good. Maybe the 16-keys keyboards, but the popups in that were already faulty (too uneven and often too wide). I propose myself to convert them to popupCharacters in a different PR; if you have a better idea, please tell me so.

I think I addressed everything now. If you notice something wrong, please tell me; if you're okay with merging this, warn me first so I can clean up the history.

@menny menny force-pushed the master branch 5 times, most recently from 2999072 to ebc9b44 Compare February 10, 2021 16:39
@menny menny modified the milestones: 1.11-r1, 1.11-r2 Jun 22, 2021
@menny menny modified the milestones: 1.11-r2, 1.11-r3 Apr 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request] Add ė, į, ų letters.
3 participants