keyboard chooser (bugfixes)

This commit is contained in:
Yuriy Liskov
2018-03-20 22:31:30 +02:00
parent 1c65d017fb
commit f948ba3bd4
11 changed files with 204 additions and 9 deletions

View File

@@ -37,7 +37,7 @@ import com.google.android.leanback.ime.voice.RecognizerView;
import com.google.android.leanback.ime.voice.SpeechLevelSource;
import com.google.leanback.ime.LeanbackImeService;
import com.liskovsoft.inputchooser.ChooseKeyboardDialog;
import com.liskovsoft.inputchooser.SettingsActivity;
import com.liskovsoft.inputchooser.LeanKeyPreferences;
import com.liskovsoft.keyboardaddons.KeyboardManager;
import com.liskovsoft.leankeykeyboard.R;
@@ -210,7 +210,7 @@ public class LeanbackKeyboardContainer {
}
});
}
private void configureFocus(LeanbackKeyboardContainer.KeyFocus focus, Rect rect, int index, int type) {
focus.type = type;
focus.index = index;
@@ -871,9 +871,7 @@ public class LeanbackKeyboardContainer {
setTouchState(LeanbackKeyboardContainer.TOUCH_STATE_NO_TOUCH);
return true;
} else if (keyCode == LeanbackKeyboardView.KEYCODE_LANG_TOGGLE) {
//Intent intent = new Intent(mContext, SettingsActivity.class);
//intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//mContext.startActivity(intent);
// NOTE: normal constructor cannot be applied here
new ChooseKeyboardDialog(mContext, mMainKeyboardView).run();
return true;
} else {
@@ -1123,6 +1121,8 @@ public class LeanbackKeyboardContainer {
Keyboard keyboard = mKeyboardManager.getNextKeyboard();
mInitialMainKeyboard = keyboard;
keyboardView.setKeyboard(keyboard);
showRunOnceDialog();
}
public void updateAddonKeyboard() {
@@ -1157,7 +1157,21 @@ public class LeanbackKeyboardContainer {
public void onLangKeyClick() {
switchToNextKeyboard();
setTouchState(LeanbackKeyboardContainer.TOUCH_STATE_NO_TOUCH);
// setTouchState(LeanbackKeyboardContainer.TOUCH_STATE_NO_TOUCH);
}
private void showRunOnceDialog() {
LeanKeyPreferences prefs = LeanKeyPreferences.instance(mContext);
boolean runOnce = prefs.isRunOnce();
if (runOnce) {
return;
}
prefs.setRunOnce(true);
// NOTE: normal constructor cannot be applied here
new ChooseKeyboardDialog(mContext, mMainKeyboardView).run();
}
public interface DismissListener {

View File

@@ -56,7 +56,6 @@ public class LeanbackImeService extends InputMethodService {
if (!this.enableHardwareAcceleration()) {
Log.w("LbImeService", "Could not enable hardware acceleration");
}
}
private void clearSuggestionsDelayed() {

View File

@@ -55,8 +55,10 @@ public class ChooseKeyboardDialog implements OnClickListener {
@TargetApi(17)
private void showDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
View title = LayoutInflater.from(mContext).inflate(R.layout.lang_selection_dialog_title, null);
alertDialog = builder
.setTitle(R.string.language_dialog_title)
//.setTitle(R.string.language_dialog_title)
.setCustomTitle(title)
.setView(buildView(builder.getContext()))
.setOnDismissListener(new OnDismissListener() {
@Override

View File

@@ -0,0 +1,33 @@
package com.liskovsoft.inputchooser;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
public final class LeanKeyPreferences {
private static final String APP_RUN_ONCE = "appRunOnce";
private static LeanKeyPreferences sInstance;
private final Context mContext;
private SharedPreferences mPrefs;
public static LeanKeyPreferences instance(Context ctx) {
if (sInstance == null)
sInstance = new LeanKeyPreferences(ctx);
return sInstance;
}
public LeanKeyPreferences(Context context) {
mContext = context.getApplicationContext();
mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
}
public boolean isRunOnce() {
return mPrefs.getBoolean(APP_RUN_ONCE, false);
}
public void setRunOnce(boolean runOnce) {
mPrefs.edit()
.putBoolean(APP_RUN_ONCE, runOnce)
.apply();
}
}

View File

@@ -72,7 +72,6 @@ public class SettingsActivity extends Activity
protected void onCreate(final Bundle bundle) {
super.onCreate(bundle);
// new ChooseKeyboardDialog(this).run();
this.launchApp();
}
}

View File

@@ -0,0 +1,79 @@
/*
* Copyright (C) 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Useful links:
// https://android.googlesource.com/platform/frameworks/base/+/de47f1c358c8186ff3e14b887d5869f69b9a9d6c/core/java/com/android/internal/widget/DialogTitle.java
// com.android.internal.widget.DialogTitle: https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/layout/alert_dialog.xml
// https://android.googlesource.com/platform/frameworks/base.git/+/master/core/java/com/android/internal/app/AlertController.java
// <declare-styleable name="TextAppearance">: https://github.com/aosp-mirror/platform_frameworks_base/blob/master/core/res/res/values/attrs.xml
package com.liskovsoft.inputchooser.widgets;
import android.content.Context;
import android.content.res.TypedArray;
import android.text.Layout;
import android.util.AttributeSet;
import android.util.TypedValue;
import com.liskovsoft.leankeykeyboard.R;
/**
* Used by dialogs to change the font size and number of lines to try to fit
* the text to the available space.
*/
public class DialogTitle extends android.support.v7.widget.AppCompatTextView {
public DialogTitle(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
public DialogTitle(Context context, AttributeSet attrs) {
super(context, attrs);
}
public DialogTitle(Context context) {
super(context);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
final Layout layout = getLayout();
if (layout != null) {
final int lineCount = layout.getLineCount();
if (lineCount > 0) {
final int ellipsisCount = layout.getEllipsisCount(lineCount - 1);
if (ellipsisCount > 0) {
setSingleLine(false);
TypedArray a = getContext().obtainStyledAttributes(null,
R.styleable.TextAppearance,
android.R.attr.textAppearanceMedium,
android.R.style.TextAppearance_Medium);
final int textSize = a.getDimensionPixelSize(
R.styleable.TextAppearance_textSize,
(int) (20 * getResources().getDisplayMetrics().density));
final int textColor = a.getColor(
R.styleable.TextAppearance_textColor, 0xffffffff);
// textSize is already expressed in pixels
setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
setTextColor(textColor);
setMaxLines(2);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
}
}
}