mirror of
https://github.com/yuliskov/LeanKeyboard.git
synced 2026-06-11 09:04:17 -04:00
keyboard chooser (bugfixes)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -56,7 +56,6 @@ public class LeanbackImeService extends InputMethodService {
|
||||
if (!this.enableHardwareAcceleration()) {
|
||||
Log.w("LbImeService", "Could not enable hardware acceleration");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void clearSuggestionsDelayed() {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,6 @@ public class SettingsActivity extends Activity
|
||||
|
||||
protected void onCreate(final Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
// new ChooseKeyboardDialog(this).run();
|
||||
this.launchApp();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Useful links: -->
|
||||
<!-- com.android.internal.widget.DialogTitle: https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/layout/alert_dialog.xml -->
|
||||
<!-- <declare-styleable name="TextAppearance">: https://github.com/aosp-mirror/platform_frameworks_base/blob/master/core/res/res/values/attrs.xml -->
|
||||
<!-- https://android.googlesource.com/platform/frameworks/base/+/de47f1c358c8186ff3e14b887d5869f69b9a9d6c/core/java/com/android/internal/widget/DialogTitle.java -->
|
||||
<!-- https://android.googlesource.com/platform/frameworks/base.git/+/master/core/java/com/android/internal/app/AlertController.java -->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/title_template"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="10dip">
|
||||
<!-- Use the same widget as used in AlertDialog -->
|
||||
<TextView android:id="@+id/alertTitle1"
|
||||
android:text="@string/language_dialog_title"
|
||||
style="?android:attr/textAppearanceLarge"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"/>
|
||||
<TextView android:id="@+id/alertTitle2"
|
||||
android:text="@string/language_dialog_subtitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"/>
|
||||
</LinearLayout>
|
||||
@@ -28,4 +28,5 @@
|
||||
<dimen name="function_key_mode_change_font_size">16.0sp</dimen>
|
||||
<dimen name="resize_move_distance">12.0dip</dimen>
|
||||
<dimen name="text_size_dp">15dp</dimen>
|
||||
<dimen name="text_size_big_dp">25dp</dimen>
|
||||
</resources>
|
||||
|
||||
@@ -25,4 +25,5 @@
|
||||
<string name="keyboard_headset_required_to_hear_password">Plug in a headset to hear password keys spoken.</string>
|
||||
<string name="keyboard_password_character_no_headset">Dot.</string>
|
||||
<string name="language_dialog_title">Select desired keyboards</string>
|
||||
<string name="language_dialog_subtitle">To open dialog next time, long press on \'world\' button</string>
|
||||
</resources>
|
||||
|
||||
41
leankeykeyboard/src/main/res/values/text_appearance.xml
Normal file
41
leankeykeyboard/src/main/res/values/text_appearance.xml
Normal file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<declare-styleable name="TextAppearance">
|
||||
<!-- Text color. -->
|
||||
<attr name="textColor" format="color" />
|
||||
<!-- Size of the text. Recommended dimension type for text is "sp" for scaled-pixels (example: 15sp). -->
|
||||
<attr name="textSize" format="dimension" />
|
||||
<!-- Style (bold, italic, bolditalic) for the text. -->
|
||||
<attr name="textStyle" format="reference" />
|
||||
<!-- Typeface (normal, sans, serif, monospace) for the text. -->
|
||||
<attr name="typeface" format="string" />
|
||||
<!-- Font family (named by string) for the text. -->
|
||||
<attr name="fontFamily" format="string" />
|
||||
<!-- Color of the text selection highlight. -->
|
||||
<attr name="textColorHighlight" format="color" />
|
||||
<!-- Color of the hint text. -->
|
||||
<attr name="textColorHint" format="color" />
|
||||
<!-- Color of the links. -->
|
||||
<attr name="textColorLink" format="color" />
|
||||
<!-- Present the text in ALL CAPS. This may use a small-caps form when available. -->
|
||||
<attr name="textAllCaps" format="boolean" />
|
||||
<!-- Place a blurred shadow of text underneath the text, drawn with the
|
||||
specified color. The text shadow produced does not interact with
|
||||
properties on View that are responsible for real time shadows,
|
||||
{@link android.R.styleable#View_elevation elevation} and
|
||||
{@link android.R.styleable#View_translationZ translationZ}. -->
|
||||
<attr name="shadowColor" format="color" />
|
||||
<!-- Horizontal offset of the text shadow. -->
|
||||
<attr name="shadowDx" format="float" />
|
||||
<!-- Vertical offset of the text shadow. -->
|
||||
<attr name="shadowDy" format="float" />
|
||||
<!-- Blur radius of the text shadow. -->
|
||||
<attr name="shadowRadius" format="float" />
|
||||
<!-- Elegant text height, especially for less compacted complex script text. -->
|
||||
<attr name="elegantTextHeight" format="boolean" />
|
||||
<!-- Text letter-spacing. -->
|
||||
<attr name="letterSpacing" format="float" />
|
||||
<!-- Font feature settings. -->
|
||||
<attr name="fontFeatureSettings" format="string" />
|
||||
</declare-styleable>
|
||||
</resources>
|
||||
BIN
screenshots/screen4.png
Normal file
BIN
screenshots/screen4.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 68 KiB |
Reference in New Issue
Block a user