Add dynamic shortcuts
Closes #44 Closes termux/termux-app#1730
Current implementation: Two new buttons in widget main view.
- Create button: adds all shortcuts as dynamic shortcuts. Those can then be used in minimalistic launchers. (Icons supported as well)
- Clear button: clears all shortcuts.
AOSP Android forces a limit of 10 shortcuts per app. One can change this limit with root permissions:
su -c 'settings put global shortcut_manager_constants max_shortcuts=1000'
Todo:
- [x] refactor/modularize code
- [x] add user feedback/logging
- [x] try to hide app name that gets displayed in front of shortcut name: probably not possible
- [x] add mention in readme (also on how to increase limit)
- [ ] move those dynamic shortcuts to different folder than normal shortcuts (
~/.shortcuts) - [ ] move FileFilter SHORTCUT_FILES_FILTER to enumerateShortcutFiles?
This PR is basically ready from my side. The last two points in the TODO above still need to be discussed.
This had been on my wishlist for years. Thanks! Tested: works and looks good to me. However I'd rather have someone more knowledgeable take a look at this before merging.
A few things:
- I'm not an expert at java, but the code that shortens the shortcuts array when its size is > maximumShortcuts is a bit opaque. Assuming there isn't a way to directly slice an array in java, perhaps one could do something like
while (shortcuts.size() > maximumShortcuts)
shortcuts.remove(shortcuts.size()-1)
which is theoretically slower than the for loop because shortcuts.size() is called shortcuts.size() - maximumShortcuts times instead of once, but I don't think anyone's ever going to have so many shortcuts as to make this difference relevant.
- I see you use static/dynamic/pinned shortcuts but there's no mention in the readme regarding this.
- Your code is much more readable and mine is actually wrong 😅. I will apply that change. To understand why it's wrong you need to know that the break condition in the for loop is actually evaluated in each iteration of the loop. But even if the condition would only be executed once in for loops vs. multiple times in while loops we would have no real performance difference since
ArrayList.size()isO(1). Take a look at the openjdk implementation ofArrayList. - The pinned and static shortcuts are those that have been used for a while now on the home screen. I only added the dynamic ones. I would say we do not need a remark on them in the readme since they are somewhat "normal" for android.
Thanks for the pull request. Good work. I have made refactored the code to fix some issues and add improvements. It seems to be working fine on Android 11, and without it on Android 7.0. Nice idea on ShortcutFile and ShortcutUtils extraction, about time for that.
I have also changed the dynamic shortcuts directory to ~/.termux/widget/dynamic_shortcuts since shouldn't just add all shortcuts in shortcuts directory as dynamic and shortcuts default directory will be moved to under ~/.termux/widget in future from ~/.shortcuts, so should move for this now.
Also in future, please remove unused imports when you move around code before committing, had to spent time figuring out which import got removed when and fixing the commits. Also use same case for commit messages as being used in repo.
I will merge this soon since need these changes for other work.
Nice, thanks for your work. 👍🏼 Glad to see this finally coming to master.
You are welcome. Any issues that occur can be fixed in master.
When will a new version be released that includes the feature?