refactoring KeyboardManager

This commit is contained in:
Yuriy Liskov
2018-01-23 12:00:53 +02:00
parent 558664f7fc
commit 3e02d5e4ef
4 changed files with 118 additions and 96 deletions

View File

@@ -16,8 +16,8 @@ public class KeyboardManager {
private final KeyboardFactory mKeyboardFactory;
private int mKeyboardIndex = 0;
public KeyboardManager(Context ctx, int defaultKeyboard1) {
this(ctx, new Keyboard(ctx, defaultKeyboard1));
public KeyboardManager(Context ctx, int keyboardResId) {
this(ctx, new Keyboard(ctx, keyboardResId));
}
public KeyboardManager(Context ctx, Keyboard englishKeyboard) {
@@ -40,16 +40,19 @@ public class KeyboardManager {
return keyboards;
}
/**
* Get next keyboard from internal source (looped)
* @return keyboard
*/
public Keyboard getNextKeyboard() {
++mKeyboardIndex;
mKeyboardIndex = mKeyboardIndex < mAllKeyboards.size() ? mKeyboardIndex : 0;
Keyboard kbd = mAllKeyboards.get(mKeyboardIndex);
if (kbd == null) {
throw new UnsupportedOperationException(String.format("Keyboard %s not initialized", mKeyboardIndex));
throw new IllegalStateException(String.format("Keyboard %s not initialized", mKeyboardIndex));
}
return kbd;
}
}