diff --git a/leankeykeyboard/src/main/java/com/google/android/leanback/ime/LeanbackKeyboardContainer.java b/leankeykeyboard/src/main/java/com/google/android/leanback/ime/LeanbackKeyboardContainer.java index 44170e1..e9c03cd 100644 --- a/leankeykeyboard/src/main/java/com/google/android/leanback/ime/LeanbackKeyboardContainer.java +++ b/leankeykeyboard/src/main/java/com/google/android/leanback/ime/LeanbackKeyboardContainer.java @@ -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 { diff --git a/leankeykeyboard/src/main/java/com/google/leanback/ime/LeanbackImeService.java b/leankeykeyboard/src/main/java/com/google/leanback/ime/LeanbackImeService.java index 44acaa4..8e07d04 100644 --- a/leankeykeyboard/src/main/java/com/google/leanback/ime/LeanbackImeService.java +++ b/leankeykeyboard/src/main/java/com/google/leanback/ime/LeanbackImeService.java @@ -56,7 +56,6 @@ public class LeanbackImeService extends InputMethodService { if (!this.enableHardwareAcceleration()) { Log.w("LbImeService", "Could not enable hardware acceleration"); } - } private void clearSuggestionsDelayed() { diff --git a/leankeykeyboard/src/main/java/com/liskovsoft/inputchooser/ChooseKeyboardDialog.java b/leankeykeyboard/src/main/java/com/liskovsoft/inputchooser/ChooseKeyboardDialog.java index 96d8fcb..6be05cf 100644 --- a/leankeykeyboard/src/main/java/com/liskovsoft/inputchooser/ChooseKeyboardDialog.java +++ b/leankeykeyboard/src/main/java/com/liskovsoft/inputchooser/ChooseKeyboardDialog.java @@ -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 diff --git a/leankeykeyboard/src/main/java/com/liskovsoft/inputchooser/LeanKeyPreferences.java b/leankeykeyboard/src/main/java/com/liskovsoft/inputchooser/LeanKeyPreferences.java new file mode 100644 index 0000000..ef982e5 --- /dev/null +++ b/leankeykeyboard/src/main/java/com/liskovsoft/inputchooser/LeanKeyPreferences.java @@ -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(); + } +} diff --git a/leankeykeyboard/src/main/java/com/liskovsoft/inputchooser/SettingsActivity.java b/leankeykeyboard/src/main/java/com/liskovsoft/inputchooser/SettingsActivity.java index 39d5847..fe39960 100644 --- a/leankeykeyboard/src/main/java/com/liskovsoft/inputchooser/SettingsActivity.java +++ b/leankeykeyboard/src/main/java/com/liskovsoft/inputchooser/SettingsActivity.java @@ -72,7 +72,6 @@ public class SettingsActivity extends Activity protected void onCreate(final Bundle bundle) { super.onCreate(bundle); - // new ChooseKeyboardDialog(this).run(); this.launchApp(); } } diff --git a/leankeykeyboard/src/main/java/com/liskovsoft/inputchooser/widgets/DialogTitle.java b/leankeykeyboard/src/main/java/com/liskovsoft/inputchooser/widgets/DialogTitle.java new file mode 100644 index 0000000..8d0f2be --- /dev/null +++ b/leankeykeyboard/src/main/java/com/liskovsoft/inputchooser/widgets/DialogTitle.java @@ -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 +// : 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); + } + } + } + } +} diff --git a/leankeykeyboard/src/main/res/layout/lang_selection_dialog_title.xml b/leankeykeyboard/src/main/res/layout/lang_selection_dialog_title.xml new file mode 100644 index 0000000..7904ad5 --- /dev/null +++ b/leankeykeyboard/src/main/res/layout/lang_selection_dialog_title.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + diff --git a/leankeykeyboard/src/main/res/values/dimens.xml b/leankeykeyboard/src/main/res/values/dimens.xml index b3f860e..e57b747 100644 --- a/leankeykeyboard/src/main/res/values/dimens.xml +++ b/leankeykeyboard/src/main/res/values/dimens.xml @@ -28,4 +28,5 @@ 16.0sp 12.0dip 15dp + 25dp diff --git a/leankeykeyboard/src/main/res/values/strings.xml b/leankeykeyboard/src/main/res/values/strings.xml index c6957f8..af423a3 100644 --- a/leankeykeyboard/src/main/res/values/strings.xml +++ b/leankeykeyboard/src/main/res/values/strings.xml @@ -25,4 +25,5 @@ Plug in a headset to hear password keys spoken. Dot. Select desired keyboards + To open dialog next time, long press on \'world\' button diff --git a/leankeykeyboard/src/main/res/values/text_appearance.xml b/leankeykeyboard/src/main/res/values/text_appearance.xml new file mode 100644 index 0000000..b1a6e36 --- /dev/null +++ b/leankeykeyboard/src/main/res/values/text_appearance.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/screenshots/screen4.png b/screenshots/screen4.png new file mode 100644 index 0000000..e7898e2 Binary files /dev/null and b/screenshots/screen4.png differ