mirror of
https://github.com/yuliskov/LeanKeyboard.git
synced 2026-04-20 15:06:53 -04:00
new options: launcher icon and suggestions
This commit is contained in:
@@ -33,7 +33,7 @@
|
||||
android:theme="@style/Theme.Leanback">
|
||||
|
||||
<activity
|
||||
android:name="com.liskovsoft.leankeyboard.activity.settings.KbSettingsActivity"
|
||||
android:name="com.liskovsoft.leankeyboard.activity.settings.KbSettingsActivity2"
|
||||
android:launchMode="singleTop">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
@@ -43,6 +43,10 @@
|
||||
<category android:name="android.intent.category.LEANBACK_LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.liskovsoft.leankeyboard.activity.settings.KbSettingsActivity"
|
||||
android:launchMode="singleTop">
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.liskovsoft.leankeyboard.activity.settings.KbLayoutActivity"
|
||||
android:launchMode="singleTop">
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.liskovsoft.leankeyboard.activity.settings;
|
||||
|
||||
public class KbSettingsActivity2 extends KbSettingsActivity {
|
||||
}
|
||||
@@ -1,24 +1,33 @@
|
||||
package com.liskovsoft.leankeyboard.fragments.settings;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.leanback.widget.GuidanceStylist.Guidance;
|
||||
import com.liskovsoft.leankeyboard.activity.settings.KbSettingsActivity;
|
||||
import com.liskovsoft.leankeyboard.activity.settings.KbSettingsActivity2;
|
||||
import com.liskovsoft.leankeyboard.helpers.Helpers;
|
||||
import com.liskovsoft.leankeyboard.utils.LeanKeySettings;
|
||||
import com.liskovsoft.leankeykeyboard.R;
|
||||
|
||||
public class MiscFragment extends BaseSettingsFragment {
|
||||
private LeanKeySettings mPrefs;
|
||||
private Context mContext;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
|
||||
mContext = context;
|
||||
mPrefs = LeanKeySettings.instance(getActivity());
|
||||
addCheckedAction(R.string.keep_on_screen, R.string.keep_on_screen_desc, mPrefs::getForceShowKeyboard, mPrefs::setForceShowKeyboard);
|
||||
addCheckedAction(R.string.increase_kbd_size, R.string.increase_kbd_size_desc, mPrefs::getEnlargeKeyboard, mPrefs::setEnlargeKeyboard);
|
||||
addCheckedAction(R.string.enable_suggestions, R.string.enable_suggestions_desc, mPrefs::getSuggestionsEnabled, mPrefs::setSuggestionsEnabled);
|
||||
addCheckedAction(R.string.show_launcher_icon, R.string.show_launcher_icon_desc, this::getLauncherIconShown, this::setLauncherIconShown);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -35,4 +44,12 @@ public class MiscFragment extends BaseSettingsFragment {
|
||||
icon
|
||||
);
|
||||
}
|
||||
|
||||
private void setLauncherIconShown(boolean shown) {
|
||||
Helpers.setLauncherIconShown(mContext, KbSettingsActivity2.class, shown);
|
||||
}
|
||||
|
||||
private boolean getLauncherIconShown() {
|
||||
return Helpers.getLauncherIconShown(mContext, KbSettingsActivity2.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.liskovsoft.leankeyboard.helpers;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.ComponentName;
|
||||
@@ -11,6 +12,7 @@ import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import com.liskovsoft.leankeyboard.activity.settings.KbSettingsActivity;
|
||||
import com.liskovsoft.leankeyboard.utils.LocaleUtility;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -224,4 +226,20 @@ public class Helpers {
|
||||
|
||||
return deviceName.contains("(vbox86p)");
|
||||
}
|
||||
|
||||
public static void setLauncherIconShown(Context context, Class<?> activityClass, boolean shown) {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
ComponentName component = new ComponentName(context, activityClass);
|
||||
pm.setComponentEnabledSetting(
|
||||
component,
|
||||
shown ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||
PackageManager.DONT_KILL_APP
|
||||
);
|
||||
}
|
||||
|
||||
public static boolean getLauncherIconShown(Context context, Class<?> activityClass) {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
ComponentName component = new ComponentName(context, activityClass);
|
||||
return pm.getComponentEnabledSetting(component) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,12 @@ public class LeanbackImeService extends InputMethodService {
|
||||
}
|
||||
|
||||
private void initSettings() {
|
||||
mForceShowKbd = LeanKeySettings.instance(this).getForceShowKeyboard();
|
||||
LeanKeySettings prefs = LeanKeySettings.instance(this);
|
||||
mForceShowKbd = prefs.getForceShowKeyboard();
|
||||
|
||||
if (mKeyboardController != null) {
|
||||
mKeyboardController.setSuggestionsEnabled(prefs.getSuggestionsEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
private void clearSuggestionsDelayed() {
|
||||
|
||||
@@ -113,6 +113,7 @@ public class LeanbackKeyboardContainer {
|
||||
private View mSuggestionsBg;
|
||||
private HorizontalScrollView mSuggestionsContainer;
|
||||
private boolean mSuggestionsEnabled;
|
||||
private boolean mForceDisableSuggestions;
|
||||
private Keyboard mSymKeyboard;
|
||||
private KeyFocus mTempKeyInfo = new KeyFocus();
|
||||
private PointF mTempPoint = new PointF();
|
||||
@@ -404,6 +405,10 @@ public class LeanbackKeyboardContainer {
|
||||
// mCapCharacters = true;
|
||||
//}
|
||||
|
||||
if (mForceDisableSuggestions) {
|
||||
mSuggestionsEnabled = false;
|
||||
}
|
||||
|
||||
if (info.privateImeOptions != null) {
|
||||
if (info.privateImeOptions.contains(IME_PRIVATE_OPTIONS_ESCAPE_NORTH)) {
|
||||
mEscapeNorthEnabled = true;
|
||||
@@ -559,6 +564,11 @@ public class LeanbackKeyboardContainer {
|
||||
return mSuggestionsEnabled;
|
||||
}
|
||||
|
||||
public void setSuggestionsEnabled(boolean enabled) {
|
||||
mSuggestionsEnabled = enabled;
|
||||
mForceDisableSuggestions = !enabled;
|
||||
}
|
||||
|
||||
public void cancelVoiceRecording() {
|
||||
mVoiceAnimator.startExitAnimation();
|
||||
}
|
||||
|
||||
@@ -621,6 +621,12 @@ public class LeanbackKeyboardController implements LeanbackKeyboardContainer.Voi
|
||||
return mContainer != null && mContainer.areSuggestionsEnabled();
|
||||
}
|
||||
|
||||
public void setSuggestionsEnabled(boolean enabled) {
|
||||
if (mContainer != null) {
|
||||
mContainer.setSuggestionsEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean enableAutoEnterSpace() {
|
||||
return mContainer != null && mContainer.enableAutoEnterSpace();
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ public final class LeanKeySettings {
|
||||
private static final String KEYBOARD_THEME = "keyboardTheme";
|
||||
public static final String DEFAULT_THEME_ID = "Default";
|
||||
public static final String DARK_THEME_ID = "Dark";
|
||||
private static final String SUGGESTIONS_ENABLED = "suggestionsEnabled";
|
||||
private static LeanKeySettings sInstance;
|
||||
private final Context mContext;
|
||||
private SharedPreferences mPrefs;
|
||||
@@ -87,4 +88,14 @@ public final class LeanKeySettings {
|
||||
public String getCurrentTheme() {
|
||||
return mPrefs.getString(KEYBOARD_THEME, DEFAULT_THEME_ID);
|
||||
}
|
||||
|
||||
public void setSuggestionsEnabled(boolean enabled) {
|
||||
mPrefs.edit()
|
||||
.putBoolean(SUGGESTIONS_ENABLED, enabled)
|
||||
.apply();
|
||||
}
|
||||
|
||||
public boolean getSuggestionsEnabled() {
|
||||
return mPrefs.getBoolean(SUGGESTIONS_ENABLED, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,4 +44,8 @@
|
||||
<string name="kb_theme">Тема</string>
|
||||
<string name="kb_theme_desc">Тема клавиатуры</string>
|
||||
<string name="change_theme">Выбрать тему</string>
|
||||
<string name="enable_suggestions">Отображать подсказки</string>
|
||||
<string name="enable_suggestions_desc">Отображать ряд с подсказками при вводе</string>
|
||||
<string name="show_launcher_icon">Отображать иконку</string>
|
||||
<string name="show_launcher_icon_desc">Отображать иконку лаунчера</string>
|
||||
</resources>
|
||||
|
||||
@@ -55,4 +55,8 @@
|
||||
<string name="kb_theme">Theme</string>
|
||||
<string name="kb_theme_desc">Keyboard Theme</string>
|
||||
<string name="change_theme">Change Theme</string>
|
||||
<string name="enable_suggestions">Enable suggestions</string>
|
||||
<string name="enable_suggestions_desc">Enable suggestions row</string>
|
||||
<string name="show_launcher_icon">Show icon</string>
|
||||
<string name="show_launcher_icon_desc">Show launcher icon</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user