mirror of
https://github.com/yuliskov/LeanKeyboard.git
synced 2026-05-03 05:12:36 -04:00
fix: remember selected kbd
This commit is contained in:
@@ -166,7 +166,6 @@ public class LeanbackKeyboardContainer {
|
||||
mAlphaIn = res.getFraction(R.fraction.alpha_in, 1, 1);
|
||||
mAlphaOut = res.getFraction(R.fraction.alpha_out, 1, 1);
|
||||
mVoiceAnimator = new LeanbackKeyboardContainer.VoiceIntroAnimator(mVoiceEnterListener, mVoiceExitListener);
|
||||
initKeyboards();
|
||||
mRootView = (RelativeLayout) mContext.getLayoutInflater().inflate(R.layout.root_leanback, null);
|
||||
mKeyboardsContainer = mRootView.findViewById(R.id.keyboard);
|
||||
mSuggestionsBg = mRootView.findViewById(R.id.candidate_background);
|
||||
@@ -208,6 +207,7 @@ public class LeanbackKeyboardContainer {
|
||||
LeanbackKeyboardContainer.this.cancelVoiceRecording();
|
||||
}
|
||||
});
|
||||
initKeyboards();
|
||||
}
|
||||
|
||||
private void configureFocus(LeanbackKeyboardContainer.KeyFocus focus, Rect rect, int index, int type) {
|
||||
@@ -1128,9 +1128,8 @@ public class LeanbackKeyboardContainer {
|
||||
}
|
||||
|
||||
public void updateAddonKeyboard() {
|
||||
KeyboardManager manager = new KeyboardManager(mContext, mAbcKeyboard);
|
||||
mKeyboardManager = manager;
|
||||
mInitialMainKeyboard = manager.getNextKeyboard();
|
||||
mKeyboardManager = new KeyboardManager(mContext, mAbcKeyboard);
|
||||
switchToNextKeyboard();
|
||||
}
|
||||
|
||||
public void updateSuggestions(ArrayList<String> suggestions) {
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.liskovsoft.keyboardaddons;
|
||||
|
||||
import android.content.Context;
|
||||
import android.inputmethodservice.Keyboard;
|
||||
import com.liskovsoft.keyboardaddons.reslangfactory.ResKeyboardFactory;
|
||||
import com.liskovsoft.keyboardaddons.reskbdfactory.ResKeyboardFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -10,9 +10,11 @@ import java.util.List;
|
||||
public class KeyboardManager {
|
||||
private final Keyboard mEnglishKeyboard;
|
||||
private final Context mContext;
|
||||
private final KeyboardStateManager mStateManager;
|
||||
private List<? extends KeyboardBuilder> mKeyboardBuilders;
|
||||
private List<Keyboard> mAllKeyboards;
|
||||
private KeyboardFactory mKeyboardFactory;
|
||||
|
||||
private int mKeyboardIndex = 0;
|
||||
|
||||
public KeyboardManager(Context ctx, int keyboardResId) {
|
||||
@@ -22,6 +24,8 @@ public class KeyboardManager {
|
||||
public KeyboardManager(Context ctx, Keyboard englishKeyboard) {
|
||||
mContext = ctx;
|
||||
mEnglishKeyboard = englishKeyboard;
|
||||
mStateManager = new KeyboardStateManager(mContext, this);
|
||||
mStateManager.restore();
|
||||
init();
|
||||
}
|
||||
|
||||
@@ -42,6 +46,13 @@ public class KeyboardManager {
|
||||
return keyboards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs callback to event handlers
|
||||
*/
|
||||
private void onNextKeyboard() {
|
||||
mStateManager.onNextKeyboard();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next keyboard from internal source (looped)
|
||||
* @return keyboard
|
||||
@@ -58,8 +69,18 @@ public class KeyboardManager {
|
||||
throw new IllegalStateException(String.format("Keyboard %s not initialized", mKeyboardIndex));
|
||||
}
|
||||
|
||||
onNextKeyboard();
|
||||
|
||||
++mKeyboardIndex;
|
||||
|
||||
return kbd;
|
||||
}
|
||||
|
||||
public int getKeyboardIndex() {
|
||||
return mKeyboardIndex;
|
||||
}
|
||||
|
||||
public void setKeyboardIndex(int idx) {
|
||||
mKeyboardIndex = idx;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.liskovsoft.keyboardaddons;
|
||||
|
||||
import android.content.Context;
|
||||
import com.liskovsoft.utils.LeanKeyPreferences;
|
||||
|
||||
public class KeyboardStateManager {
|
||||
private final Context mContext;
|
||||
private final KeyboardManager mManager;
|
||||
private final LeanKeyPreferences mPrefs;
|
||||
|
||||
public KeyboardStateManager(Context context, KeyboardManager manager) {
|
||||
mContext = context;
|
||||
mManager = manager;
|
||||
mPrefs = LeanKeyPreferences.instance(mContext);
|
||||
}
|
||||
|
||||
public void restore() {
|
||||
int idx = mPrefs.getKeyboardIndex();
|
||||
mManager.setKeyboardIndex(idx);
|
||||
}
|
||||
|
||||
public void onNextKeyboard() {
|
||||
mPrefs.setKeyboardIndex(mManager.getKeyboardIndex());
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.addons;
|
||||
package com.liskovsoft.keyboardaddons.apkkbdfactory.addons;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.addons;
|
||||
package com.liskovsoft.keyboardaddons.apkkbdfactory.addons;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
@@ -23,7 +23,7 @@ import android.support.annotation.Nullable;
|
||||
import android.support.v4.util.SparseArrayCompat;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import com.liskovsoft.keyboardaddons.apklangfactory.utils.Logger;
|
||||
import com.liskovsoft.keyboardaddons.apkkbdfactory.utils.Logger;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Arrays;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.addons;
|
||||
package com.liskovsoft.keyboardaddons.apkkbdfactory.addons;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -27,7 +27,7 @@ import android.util.AttributeSet;
|
||||
import android.util.Xml;
|
||||
|
||||
//import com.liskovsoft.keyboardaddons.apklangfactory.AnySoftKeyboard;
|
||||
import com.liskovsoft.keyboardaddons.apklangfactory.utils.Logger;
|
||||
import com.liskovsoft.keyboardaddons.apkkbdfactory.utils.Logger;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.addons;
|
||||
package com.liskovsoft.keyboardaddons.apkkbdfactory.addons;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import com.liskovsoft.keyboardaddons.apklangfactory.utils.Logger;
|
||||
import com.liskovsoft.keyboardaddons.apkkbdfactory.utils.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -14,14 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.keyboards;
|
||||
package com.liskovsoft.keyboardaddons.apkkbdfactory.keyboards;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.liskovsoft.keyboardaddons.KeyboardBuilder;
|
||||
import com.liskovsoft.keyboardaddons.apklangfactory.addons.AddOn;
|
||||
import com.liskovsoft.keyboardaddons.apklangfactory.addons.AddOnImpl;
|
||||
import com.liskovsoft.keyboardaddons.apkkbdfactory.addons.AddOn;
|
||||
import com.liskovsoft.keyboardaddons.apkkbdfactory.addons.AddOnImpl;
|
||||
|
||||
public class ApkKeyboardAddOnAndBuilder extends AddOnImpl implements KeyboardBuilder {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.keyboards;
|
||||
package com.liskovsoft.keyboardaddons.apkkbdfactory.keyboards;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
@@ -25,9 +25,9 @@ import android.util.AttributeSet;
|
||||
|
||||
import com.liskovsoft.keyboardaddons.KeyboardBuilder;
|
||||
import com.liskovsoft.keyboardaddons.KeyboardFactory;
|
||||
import com.liskovsoft.keyboardaddons.apklangfactory.addons.AddOn;
|
||||
import com.liskovsoft.keyboardaddons.apklangfactory.addons.AddOnsFactory;
|
||||
import com.liskovsoft.keyboardaddons.apklangfactory.utils.Logger;
|
||||
import com.liskovsoft.keyboardaddons.apkkbdfactory.addons.AddOn;
|
||||
import com.liskovsoft.keyboardaddons.apkkbdfactory.addons.AddOnsFactory;
|
||||
import com.liskovsoft.keyboardaddons.apkkbdfactory.utils.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.utils;
|
||||
package com.liskovsoft.keyboardaddons.apkkbdfactory.utils;
|
||||
|
||||
public class BuildConfig {
|
||||
public final static boolean TESTING_BUILD = true;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.utils;
|
||||
package com.liskovsoft.keyboardaddons.apkkbdfactory.utils;
|
||||
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.utils;
|
||||
package com.liskovsoft.keyboardaddons.apkkbdfactory.utils;
|
||||
|
||||
public interface LogProvider {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.utils;
|
||||
package com.liskovsoft.keyboardaddons.apkkbdfactory.utils;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.utils;
|
||||
package com.liskovsoft.keyboardaddons.apkkbdfactory.utils;
|
||||
|
||||
/**
|
||||
* Doesn't do anything. For release.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.utils;
|
||||
package com.liskovsoft.keyboardaddons.apkkbdfactory.utils;
|
||||
|
||||
import android.util.Xml;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.utils;
|
||||
package com.liskovsoft.keyboardaddons.apkkbdfactory.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.liskovsoft.keyboardaddons.reslangfactory;
|
||||
package com.liskovsoft.keyboardaddons.reskbdfactory;
|
||||
|
||||
import android.inputmethodservice.Keyboard;
|
||||
import android.support.annotation.Nullable;
|
||||
import com.liskovsoft.keyboardaddons.KeyboardBuilder;
|
||||
|
||||
public class ResKeyboardBuilder implements KeyboardBuilder {
|
||||
class ResKeyboardBuilder implements KeyboardBuilder {
|
||||
@Nullable
|
||||
@Override
|
||||
public Keyboard createKeyboard() {
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.liskovsoft.keyboardaddons.reslangfactory;
|
||||
package com.liskovsoft.keyboardaddons.reskbdfactory;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
@@ -7,7 +7,6 @@ import android.support.annotation.Nullable;
|
||||
import com.liskovsoft.keyboardaddons.KeyboardBuilder;
|
||||
import com.liskovsoft.keyboardaddons.KeyboardFactory;
|
||||
import com.liskovsoft.keyboardaddons.KeyboardInfo;
|
||||
import com.liskovsoft.leankeykeyboard.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.liskovsoft.keyboardaddons.reslangfactory;
|
||||
package com.liskovsoft.keyboardaddons.reskbdfactory;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.liskovsoft.keyboardaddons.reslangfactory;
|
||||
package com.liskovsoft.keyboardaddons.reskbdfactory;
|
||||
|
||||
import com.liskovsoft.keyboardaddons.KeyboardInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ResKeyboardManager {
|
||||
class ResKeyboardManager {
|
||||
public List<KeyboardInfo> getAllKeyboardInfos() {
|
||||
return null;
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.CheckedTextView;
|
||||
import com.liskovsoft.keyboardaddons.KeyboardInfo;
|
||||
import com.liskovsoft.keyboardaddons.reslangfactory.ResKeyboardInfo;
|
||||
import com.liskovsoft.keyboardaddons.reskbdfactory.ResKeyboardInfo;
|
||||
import com.liskovsoft.leankeykeyboard.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.preference.PreferenceManager;
|
||||
public final class LeanKeyPreferences {
|
||||
private static final String APP_RUN_ONCE = "appRunOnce";
|
||||
private static final String BOOTSTRAP_SELECTED_LANGUAGE = "bootstrapSelectedLanguage";
|
||||
private static final String APP_KEYBOARD_INDEX = "appKeyboardIndex";
|
||||
private static LeanKeyPreferences sInstance;
|
||||
private final Context mContext;
|
||||
private SharedPreferences mPrefs;
|
||||
@@ -42,4 +43,15 @@ public final class LeanKeyPreferences {
|
||||
String name = mPrefs.getString(BOOTSTRAP_SELECTED_LANGUAGE, "");
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getKeyboardIndex() {
|
||||
int idx = mPrefs.getInt(APP_KEYBOARD_INDEX, 0);
|
||||
return idx;
|
||||
}
|
||||
|
||||
public void setKeyboardIndex(int idx) {
|
||||
mPrefs.edit()
|
||||
.putInt(APP_KEYBOARD_INDEX, idx)
|
||||
.apply();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user