Skip to content

Commit 5f9166b

Browse files
committed
support enable suggestion on setting
1 parent f001961 commit 5f9166b

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

lib-n-ide/src/main/java/com/duy/ide/editor/EditorDelegate.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,9 +641,6 @@ public void setCodeFormatProvider(@Nullable CodeFormatProvider codeFormatProvide
641641
@Override
642642
public void setSuggestionProvider(@Nullable SuggestionProvider provider) {
643643
this.mSuggestionProvider = provider;
644-
if (this.mEditText != null) {
645-
this.mEditText.setSuggestEnable(true);
646-
}
647644
}
648645

649646
public static class SavedState implements Parcelable {

lib-n-ide/src/main/java/com/duy/ide/editor/view/SuggestionEditor.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.annotation.SuppressLint;
44
import android.content.Context;
5+
import android.content.SharedPreferences;
56
import android.graphics.Rect;
67
import android.graphics.drawable.GradientDrawable;
78
import android.os.Build;
@@ -14,11 +15,11 @@
1415
import android.view.View;
1516
import android.view.ViewGroup;
1617
import android.view.WindowManager;
17-
import android.view.inputmethod.InputMethodManager;
1818
import android.widget.AdapterView;
1919

2020
import com.duy.common.DLog;
2121
import com.duy.ide.code.api.SuggestItem;
22+
import com.duy.ide.editor.editor.R;
2223
import com.duy.ide.editor.internal.suggestion.OnSuggestItemClickListener;
2324
import com.duy.ide.editor.internal.suggestion.SuggestionAdapter;
2425
import com.duy.ide.editor.theme.model.EditorTheme;
@@ -87,6 +88,8 @@ private void init(Context context, AttributeSet attrs, int defStyleAttr) {
8788
if (getEditorTheme() != null) {
8889
setThemeForPopup(getEditorTheme());
8990
}
91+
92+
setSuggestEnable(mPreferences.isUseAutoComplete());
9093
}
9194

9295
private void setThemeForPopup(EditorTheme theme) {
@@ -338,12 +341,12 @@ public boolean isPopupShowing() {
338341
* <p>Closes the drop down if present on screen.</p>
339342
*/
340343
public void dismissDropDown() {
341-
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
342-
if (imm != null) {
343-
imm.displayCompletions(this, null);
344+
try {
345+
if (mPopup.isShowing()) {
346+
mPopup.dismiss();
347+
}
348+
} catch (Exception e) {
344349
}
345-
mPopup.dismiss();
346-
347350
}
348351

349352
public void setAdapter(SuggestionAdapter adapter) {
@@ -488,4 +491,13 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
488491
public void clearListSelection() {
489492
mPopup.clearListSelection();
490493
}
494+
495+
@Override
496+
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
497+
super.onSharedPreferenceChanged(sharedPreferences, key);
498+
if (key.equals(getContext().getString(R.string.pref_auto_complete))) {
499+
mSuggestionEnable = mPreferences.isUseAutoComplete();
500+
setSuggestEnable(mSuggestionEnable);
501+
}
502+
}
491503
}

lib-n-ide/src/main/java/com/jecelyin/editor/v2/Preferences.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public static Preferences getInstance(Context context) {
134134
}
135135
return instance;
136136
}
137+
137138
public int getMaxEditor() {
138139
return 3;
139140
}
@@ -390,6 +391,9 @@ public boolean isUseVolumeToMove() {
390391
return preferences.getBoolean(KEY_VOLUME_MOVE, true);
391392
}
392393

394+
public boolean isUseAutoComplete() {
395+
return getBoolean(context.getString(R.string.pref_auto_complete), true);
396+
}
393397

394398
@IntDef({SCREEN_ORIENTATION_AUTO, SCREEN_ORIENTATION_LANDSCAPE, SCREEN_ORIENTATION_PORTRAIT})
395399
public @interface ScreenOrientation {

lib-n-ide/src/main/res/values/do_not_translate.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<string name="pref_touch_to_adjust_text_size" translatable="false">pref_touch_to_adjust_text_size</string>
1616
<string name="pref_cursor_width" translatable="false">pref_cursor_width</string>
1717
<string name="pref_font_size" translatable="false">pref_font_size</string>
18+
<string name="pref_auto_complete" translatable="false">pref_auto_complete</string>
1819
<string name="pref_auto_capitalize" translatable="false">pref_auto_capitalize</string>
1920
<string name="pref_symbol" translatable="false">pref_symbol</string>
2021
<string name="pref_volume_move" translatable="false">pref_volume_move</string>

lib-n-ide/src/main/res/xml/preference_editor.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
android:key="@string/pref_show_whitespace"
2525
android:title="@string/show_whitespace" />
2626

27+
<CheckBoxPreference
28+
android:defaultValue="true"
29+
android:key="@string/pref_auto_complete"
30+
android:summary="Show small popup to suggest code when you typing. It can be not supported current language"
31+
android:title="Auto complete" />
32+
2733
<CheckBoxPreference
2834
android:key="@string/pref_auto_indent"
2935
android:title="@string/auto_indent" />
@@ -59,8 +65,8 @@
5965
android:title="@string/custom_symbol_list" />
6066

6167
<CheckBoxPreference
62-
android:key="@string/pref_volume_move"
6368
android:defaultValue="true"
69+
android:key="@string/pref_volume_move"
6470
android:summary="Press volume up (+) to move cursor to right, press volume down (-) to move cursor to left"
6571
android:title="Volume move" />
6672
</PreferenceCategory>

0 commit comments

Comments
 (0)