abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2/EmojiGridView.java
diff options
context:
space:
mode:
authorJules Aguillon2022-11-11 15:39:28 +0100
committerJules Aguillon2022-11-11 15:39:28 +0100
commitef34303c7eaa781ed4655016538aac47f0aef002 (patch)
treefd35fdfa1d75de5bd7216677b4f25cf263bee286 /srcs/juloo.keyboard2/EmojiGridView.java
parentf1ce6abe5a37c9ca57d885ecb9a3218969bc7fdf (diff)
downloadunexpected-keyboard-ef34303c7eaa781ed4655016538aac47f0aef002.tar.gz
unexpected-keyboard-ef34303c7eaa781ed4655016538aac47f0aef002.zip
Avoid crashing in direct-boot mode
The settings activity can't open in direct-boot mode. The emoji pane opens without the "last used" data.
Diffstat (limited to 'srcs/juloo.keyboard2/EmojiGridView.java')
-rw-r--r--srcs/juloo.keyboard2/EmojiGridView.java13
1 files changed, 9 insertions, 4 deletions
diff --git a/srcs/juloo.keyboard2/EmojiGridView.java b/srcs/juloo.keyboard2/EmojiGridView.java
index 581200c..749ce3e 100644
--- a/srcs/juloo.keyboard2/EmojiGridView.java
+++ b/srcs/juloo.keyboard2/EmojiGridView.java
@@ -83,7 +83,9 @@ public class EmojiGridView extends GridView
private void saveLastUsed()
{
- SharedPreferences.Editor edit = emojiSharedPreferences().edit();
+ SharedPreferences.Editor edit;
+ try { edit = emojiSharedPreferences().edit(); }
+ catch (Exception _e) { return; }
HashSet<String> set = new HashSet<String>();
for (Emoji emoji : _lastUsed.keySet())
set.add(String.valueOf(_lastUsed.get(emoji)) + "-" + emoji.name());
@@ -93,15 +95,18 @@ public class EmojiGridView extends GridView
private void loadLastUsed()
{
- SharedPreferences prefs = emojiSharedPreferences();
- Set<String> lastUseSet = prefs.getStringSet(LAST_USE_PREF, null);
_lastUsed = new HashMap<Emoji, Integer>();
+ SharedPreferences prefs;
+ // Storage might not be available (eg. the device is locked), avoid
+ // crashing.
+ try { prefs = emojiSharedPreferences(); }
+ catch (Exception _e) { return; }
+ Set<String> lastUseSet = prefs.getStringSet(LAST_USE_PREF, null);
if (lastUseSet != null)
for (String emojiData : lastUseSet)
{
String[] data = emojiData.split("-", 2);
Emoji emoji;
-
if (data.length != 2)
continue ;
emoji = Emoji.getEmojiByName(data[1]);