Skip to content

Commit 91523d6

Browse files
committed
Candidates view message when no dictionary installed
The message is updated when the config is refreshed.
1 parent 926b528 commit 91523d6

File tree

6 files changed

+66
-4
lines changed

6 files changed

+66
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" style="@style/candidates_status">
3+
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/candidates_status_no_dict"/>
4+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/candidates_status_install" android:onClick="launch_dictionaries_activity"/>
5+
</LinearLayout>

res/layout/keyboard.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:hardwareAccelerated="false" android:orientation="vertical" android:background="?attr/colorKeyboard">
3-
<juloo.keyboard2.suggestions.CandidatesView android:id="@+id/candidates_view" android:layout_width="match_parent" android:layout_height="48dp" android:orientation="horizontal">
3+
<juloo.keyboard2.suggestions.CandidatesView android:id="@+id/candidates_view" android:layout_width="match_parent" android:layout_height="48dp" android:orientation="horizontal" android:gravity="center">
44
<TextView android:id="@+id/candidates_left" style="@style/candidates_item" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"/>
55
<TextView android:id="@+id/candidates_middle" style="@style/candidates_item" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"/>
66
<TextView android:id="@+id/candidates_right" style="@style/candidates_item" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"/>

res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,7 @@
153153
<string name="dictionaries_from_internet">Download a dictionary from the Internet</string>
154154
<string name="dictionaries_download_success">Dictionary installed</string>
155155
<string name="dictionaries_download_failed">Download failed</string>
156+
<string name="candidates_status_no_dict">No dictionary installed</string>
157+
<string name="candidates_status_install">Install</string>
156158
<string name="dict_name_fr">French</string>
157159
</resources>

res/values/styles.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
<item name="android:textSize">18sp</item>
77
<item name="android:textColor">?attr/colorLabel</item>
88
</style>
9+
<style name="candidates_status">
10+
<item name="android:layout_width">match_parent</item>
11+
<item name="android:layout_height">wrap_content</item>
12+
<item name="android:gravity">center</item>
13+
<item name="android:textSize">18sp</item>
14+
<item name="android:textColor">?attr/colorLabel</item>
15+
</style>
916
<!-- Emoji pane -->
1017
<style name="emojiTypeButton">
1118
<item name="android:padding">1px</item>

srcs/juloo.keyboard2/Keyboard2.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.List;
2727
import java.util.Set;
2828
import juloo.keyboard2.dict.Dictionaries;
29+
import juloo.keyboard2.dict.DictionariesActivity;
2930
import juloo.keyboard2.prefs.LayoutsPreference;
3031
import juloo.keyboard2.suggestions.CandidatesView;
3132

@@ -280,6 +281,7 @@ private void refresh_config()
280281
// Set keyboard background opacity
281282
_container_view.getBackground().setAlpha(_config.keyboardOpacity);
282283
_keyboardView.reset();
284+
_candidates_view.refresh_status();
283285
}
284286

285287
private KeyboardData refresh_special_layout(EditorInfo info)
@@ -424,6 +426,19 @@ public boolean onEvaluateFullscreenMode()
424426
return false;
425427
}
426428

429+
/** Called from [onClick] attributes. */
430+
public void launch_dictionaries_activity(View v)
431+
{
432+
start_activity(DictionariesActivity.class);
433+
}
434+
435+
void start_activity(Class cls)
436+
{
437+
Intent intent = new Intent(this, cls);
438+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
439+
startActivity(intent);
440+
}
441+
427442
/** Not static */
428443
public class Receiver implements KeyEventHandler.IReceiver
429444
{
@@ -432,9 +447,7 @@ public void handle_event_key(KeyValue.Event ev)
432447
switch (ev)
433448
{
434449
case CONFIG:
435-
Intent intent = new Intent(Keyboard2.this, SettingsActivity.class);
436-
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
437-
startActivity(intent);
450+
start_activity(SettingsActivity.class);
438451
break;
439452

440453
case SWITCH_TEXT:

srcs/juloo.keyboard2/suggestions/CandidatesView.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public class CandidatesView extends LinearLayout
2727
set to [GONE] when there are less than [NUM_CANDIDATES] suggestions. */
2828
TextView[] _item_views = new TextView[NUM_CANDIDATES];
2929

30+
/** Optional view showing a message to the user. Visible when no candidates
31+
are shown. Might be [null]. */
32+
View _status_no_dict = null; // Dictionary not installed
33+
3034
public CandidatesView(Context context, AttributeSet attrs)
3135
{
3236
super(context, attrs);
@@ -63,6 +67,36 @@ public void set_candidates(List<String> suggestions)
6367
}
6468
}
6569

70+
/** Refresh the status messages after a configuration refresh. The status
71+
message indicates whether the dictionaries should be installed. */
72+
public void refresh_status()
73+
{
74+
set_candidates(Suggestions.NO_SUGGESTIONS);
75+
_status_no_dict = inflate_and_show(_status_no_dict,
76+
(_config.current_dictionary == null),
77+
R.layout.candidates_status_no_dict);
78+
}
79+
80+
/** Show or hide a status view and inflate it if needed. */
81+
View inflate_and_show(View v, boolean show, int layout_id)
82+
{
83+
if (!show)
84+
{
85+
if (v != null)
86+
v.setVisibility(View.GONE);
87+
}
88+
else
89+
{
90+
if (v == null)
91+
{
92+
v = View.inflate(getContext(), layout_id, null);
93+
addView(v);
94+
}
95+
v.setVisibility(View.VISIBLE);
96+
}
97+
return v;
98+
}
99+
66100
private void setup_item_view(final int item_index, int item_id)
67101
{
68102
TextView v = (TextView)findViewById(item_id);
@@ -80,6 +114,7 @@ public void onClick(View _v)
80114
_item_views[item_index] = v;
81115
}
82116

117+
/** Whether the candidates view should be shown for a given editor. */
83118
public static boolean should_show(EditorInfo info)
84119
{
85120
int variation = info.inputType & InputType.TYPE_MASK_VARIATION;

0 commit comments

Comments
 (0)