mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-09 16:17:44 +00:00
move PopupSuggestionsView to Kotlin
and rename to MoreSuggestionsView
This commit is contained in:
parent
538a26a9b8
commit
32099748e5
7 changed files with 95 additions and 119 deletions
|
@ -38,7 +38,7 @@ import helium314.keyboard.latin.common.Constants;
|
||||||
import helium314.keyboard.latin.common.StringUtilsKt;
|
import helium314.keyboard.latin.common.StringUtilsKt;
|
||||||
import helium314.keyboard.latin.settings.Settings;
|
import helium314.keyboard.latin.settings.Settings;
|
||||||
import helium314.keyboard.latin.suggestions.MoreSuggestions;
|
import helium314.keyboard.latin.suggestions.MoreSuggestions;
|
||||||
import helium314.keyboard.latin.suggestions.PopupSuggestionsView;
|
import helium314.keyboard.latin.suggestions.MoreSuggestionsView;
|
||||||
import helium314.keyboard.latin.utils.TypefaceUtils;
|
import helium314.keyboard.latin.utils.TypefaceUtils;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -109,7 +109,7 @@ public class KeyboardView extends View {
|
||||||
|
|
||||||
final TypedArray keyboardViewAttr = context.obtainStyledAttributes(attrs,
|
final TypedArray keyboardViewAttr = context.obtainStyledAttributes(attrs,
|
||||||
R.styleable.KeyboardView, defStyle, R.style.KeyboardView);
|
R.styleable.KeyboardView, defStyle, R.style.KeyboardView);
|
||||||
if (this instanceof PopupSuggestionsView)
|
if (this instanceof MoreSuggestionsView)
|
||||||
mKeyBackground = mColors.selectAndColorDrawable(keyboardViewAttr, ColorType.MORE_SUGGESTIONS_WORD_BACKGROUND);
|
mKeyBackground = mColors.selectAndColorDrawable(keyboardViewAttr, ColorType.MORE_SUGGESTIONS_WORD_BACKGROUND);
|
||||||
else if (this instanceof PopupKeysKeyboardView)
|
else if (this instanceof PopupKeysKeyboardView)
|
||||||
mKeyBackground = mColors.selectAndColorDrawable(keyboardViewAttr, ColorType.POPUP_KEYS_BACKGROUND);
|
mKeyBackground = mColors.selectAndColorDrawable(keyboardViewAttr, ColorType.POPUP_KEYS_BACKGROUND);
|
||||||
|
|
|
@ -19,7 +19,7 @@ import helium314.keyboard.accessibility.AccessibilityUtils;
|
||||||
import helium314.keyboard.keyboard.MainKeyboardView;
|
import helium314.keyboard.keyboard.MainKeyboardView;
|
||||||
import helium314.keyboard.latin.common.ColorType;
|
import helium314.keyboard.latin.common.ColorType;
|
||||||
import helium314.keyboard.latin.settings.Settings;
|
import helium314.keyboard.latin.settings.Settings;
|
||||||
import helium314.keyboard.latin.suggestions.PopupSuggestionsView;
|
import helium314.keyboard.latin.suggestions.MoreSuggestionsView;
|
||||||
import helium314.keyboard.latin.suggestions.SuggestionStripView;
|
import helium314.keyboard.latin.suggestions.SuggestionStripView;
|
||||||
import kotlin.Unit;
|
import kotlin.Unit;
|
||||||
|
|
||||||
|
@ -230,8 +230,8 @@ public final class InputView extends FrameLayout {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class forwards {@link MotionEvent}s happened in the {@link MainKeyboardView} to
|
* This class forwards {@link MotionEvent}s happened in the {@link MainKeyboardView} to
|
||||||
* {@link SuggestionStripView} when the {@link PopupSuggestionsView} is showing.
|
* {@link SuggestionStripView} when the {@link MoreSuggestionsView} is showing.
|
||||||
* {@link SuggestionStripView} dismisses {@link PopupSuggestionsView} when it receives any event
|
* {@link SuggestionStripView} dismisses {@link MoreSuggestionsView} when it receives any event
|
||||||
* outside of it.
|
* outside of it.
|
||||||
*/
|
*/
|
||||||
private static class MoreSuggestionsViewCanceler
|
private static class MoreSuggestionsViewCanceler
|
||||||
|
|
|
@ -168,12 +168,12 @@ public final class MoreSuggestions extends Keyboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class Builder extends KeyboardBuilder<MoreSuggestionsParam> {
|
public static final class Builder extends KeyboardBuilder<MoreSuggestionsParam> {
|
||||||
private final PopupSuggestionsView mPaneView;
|
private final MoreSuggestionsView mPaneView;
|
||||||
private SuggestedWords mSuggestedWords;
|
private SuggestedWords mSuggestedWords;
|
||||||
private int mFromIndex;
|
private int mFromIndex;
|
||||||
private int mToIndex;
|
private int mToIndex;
|
||||||
|
|
||||||
public Builder(final Context context, final PopupSuggestionsView paneView) {
|
public Builder(final Context context, final MoreSuggestionsView paneView) {
|
||||||
super(context, new MoreSuggestionsParam());
|
super(context, new MoreSuggestionsParam());
|
||||||
mPaneView = paneView;
|
mPaneView = paneView;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2011 The Android Open Source Project
|
||||||
|
* modified
|
||||||
|
* SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
|
||||||
|
*/
|
||||||
|
package helium314.keyboard.latin.suggestions
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import helium314.keyboard.keyboard.Key
|
||||||
|
import helium314.keyboard.keyboard.Keyboard
|
||||||
|
import helium314.keyboard.keyboard.KeyboardActionListener
|
||||||
|
import helium314.keyboard.keyboard.PopupKeysKeyboardView
|
||||||
|
import helium314.keyboard.latin.R
|
||||||
|
import helium314.keyboard.latin.SuggestedWords.SuggestedWordInfo
|
||||||
|
import helium314.keyboard.latin.suggestions.MoreSuggestions.MoreSuggestionKey
|
||||||
|
import helium314.keyboard.latin.utils.Log
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A view that renders a virtual [MoreSuggestions]. It handles rendering of keys and detecting
|
||||||
|
* key presses and touch movements.
|
||||||
|
*/
|
||||||
|
class MoreSuggestionsView @JvmOverloads constructor(
|
||||||
|
context: Context, attrs: AttributeSet?,
|
||||||
|
defStyle: Int = R.attr.popupKeysKeyboardViewStyle
|
||||||
|
) : PopupKeysKeyboardView(context, attrs, defStyle) {
|
||||||
|
abstract class MoreSuggestionsListener : KeyboardActionListener.Adapter() {
|
||||||
|
abstract fun onSuggestionSelected(wordInfo: SuggestedWordInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
var isInModalMode = false
|
||||||
|
private set
|
||||||
|
|
||||||
|
// TODO: Remove redundant override method.
|
||||||
|
override fun setKeyboard(keyboard: Keyboard) {
|
||||||
|
super.setKeyboard(keyboard)
|
||||||
|
isInModalMode = false
|
||||||
|
// With accessibility mode off, mAccessibilityDelegate is set to null at the above PopupKeysKeyboardView#setKeyboard call.
|
||||||
|
// With accessibility mode on, mAccessibilityDelegate is set to a PopupKeysKeyboardAccessibilityDelegate object at the above
|
||||||
|
// PopupKeysKeyboardView#setKeyboard call.
|
||||||
|
if (mAccessibilityDelegate != null) {
|
||||||
|
mAccessibilityDelegate.setOpenAnnounce(R.string.spoken_open_more_suggestions)
|
||||||
|
mAccessibilityDelegate.setCloseAnnounce(R.string.spoken_close_more_suggestions)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getDefaultCoordX() = (keyboard as MoreSuggestions).mOccupiedWidth / 2
|
||||||
|
|
||||||
|
fun updateKeyboardGeometry(keyHeight: Int) {
|
||||||
|
updateKeyDrawParams(keyHeight)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setModalMode() {
|
||||||
|
isInModalMode = true
|
||||||
|
// Set vertical correction to zero (Reset popup keys keyboard sliding allowance R#dimen.config_popup_keys_keyboard_slide_allowance).
|
||||||
|
mKeyDetector.setKeyboard(keyboard, -paddingLeft.toFloat(), -paddingTop.toFloat())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onKeyInput(key: Key, x: Int, y: Int) {
|
||||||
|
if (key !is MoreSuggestionKey) {
|
||||||
|
Log.e(TAG, "Expected key is MoreSuggestionKey, but found ${key.javaClass.name}")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val keyboard = keyboard
|
||||||
|
if (keyboard !is MoreSuggestions) {
|
||||||
|
Log.e(TAG, "Expected keyboard is MoreSuggestions, but found ${keyboard?.javaClass?.name}")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val suggestedWords = keyboard.mSuggestedWords
|
||||||
|
val index = key.mSuggestedWordIndex
|
||||||
|
if (index < 0 || index >= suggestedWords.size()) {
|
||||||
|
Log.e(TAG, "Selected suggestion has an illegal index: $index")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (mListener !is MoreSuggestionsListener) {
|
||||||
|
Log.e(TAG, "Expected mListener is MoreSuggestionsListener, but found " + mListener.javaClass.name)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
(mListener as MoreSuggestionsListener).onSuggestionSelected(suggestedWords.getInfo(index))
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val TAG = MoreSuggestionsView::class.java.simpleName
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,109 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2011 The Android Open Source Project
|
|
||||||
* modified
|
|
||||||
* SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
|
|
||||||
*/
|
|
||||||
|
|
||||||
package helium314.keyboard.latin.suggestions;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
import helium314.keyboard.latin.utils.Log;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import helium314.keyboard.keyboard.Key;
|
|
||||||
import helium314.keyboard.keyboard.Keyboard;
|
|
||||||
import helium314.keyboard.keyboard.KeyboardActionListener;
|
|
||||||
import helium314.keyboard.keyboard.PopupKeysKeyboardView;
|
|
||||||
import helium314.keyboard.latin.R;
|
|
||||||
import helium314.keyboard.latin.SuggestedWords;
|
|
||||||
import helium314.keyboard.latin.SuggestedWords.SuggestedWordInfo;
|
|
||||||
import helium314.keyboard.latin.suggestions.MoreSuggestions.MoreSuggestionKey;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A view that renders a virtual {@link MoreSuggestions}. It handles rendering of keys and detecting
|
|
||||||
* key presses and touch movements.
|
|
||||||
*/
|
|
||||||
public final class PopupSuggestionsView extends PopupKeysKeyboardView {
|
|
||||||
private static final String TAG = PopupSuggestionsView.class.getSimpleName();
|
|
||||||
|
|
||||||
public static abstract class MoreSuggestionsListener extends KeyboardActionListener.Adapter {
|
|
||||||
public abstract void onSuggestionSelected(final SuggestedWordInfo info);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean mIsInModalMode;
|
|
||||||
|
|
||||||
public PopupSuggestionsView(final Context context, final AttributeSet attrs) {
|
|
||||||
this(context, attrs, R.attr.popupKeysKeyboardViewStyle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PopupSuggestionsView(final Context context, final AttributeSet attrs,
|
|
||||||
final int defStyle) {
|
|
||||||
super(context, attrs, defStyle);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Remove redundant override method.
|
|
||||||
@Override
|
|
||||||
public void setKeyboard(@NonNull final Keyboard keyboard) {
|
|
||||||
super.setKeyboard(keyboard);
|
|
||||||
mIsInModalMode = false;
|
|
||||||
// With accessibility mode off, {@link #mAccessibilityDelegate} is set to null at the
|
|
||||||
// above {@link PopupKeysKeyboardView#setKeyboard(Keyboard)} call.
|
|
||||||
// With accessibility mode on, {@link #mAccessibilityDelegate} is set to a
|
|
||||||
// {@link PopupKeysKeyboardAccessibilityDelegate} object at the above
|
|
||||||
// {@link PopupKeysKeyboardView#setKeyboard(Keyboard)} call.
|
|
||||||
if (mAccessibilityDelegate != null) {
|
|
||||||
mAccessibilityDelegate.setOpenAnnounce(R.string.spoken_open_more_suggestions);
|
|
||||||
mAccessibilityDelegate.setCloseAnnounce(R.string.spoken_close_more_suggestions);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getDefaultCoordX() {
|
|
||||||
final MoreSuggestions pane = (MoreSuggestions) getKeyboard();
|
|
||||||
return pane.mOccupiedWidth / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateKeyboardGeometry(final int keyHeight) {
|
|
||||||
updateKeyDrawParams(keyHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setModalMode() {
|
|
||||||
mIsInModalMode = true;
|
|
||||||
// Set vertical correction to zero (Reset popup keys keyboard sliding allowance
|
|
||||||
// {@link R#dimen.config_popup_keys_keyboard_slide_allowance}).
|
|
||||||
mKeyDetector.setKeyboard(getKeyboard(), -getPaddingLeft(), -getPaddingTop());
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isInModalMode() {
|
|
||||||
return mIsInModalMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onKeyInput(final Key key, final int x, final int y) {
|
|
||||||
if (!(key instanceof MoreSuggestionKey)) {
|
|
||||||
Log.e(TAG, "Expected key is MoreSuggestionKey, but found "
|
|
||||||
+ key.getClass().getName());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final Keyboard keyboard = getKeyboard();
|
|
||||||
if (!(keyboard instanceof MoreSuggestions)) {
|
|
||||||
Log.e(TAG, "Expected keyboard is MoreSuggestions, but found "
|
|
||||||
+ keyboard.getClass().getName());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final SuggestedWords suggestedWords = ((MoreSuggestions)keyboard).mSuggestedWords;
|
|
||||||
final int index = ((MoreSuggestionKey)key).mSuggestedWordIndex;
|
|
||||||
if (index < 0 || index >= suggestedWords.size()) {
|
|
||||||
Log.e(TAG, "Selected suggestion has an illegal index: " + index);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!(mListener instanceof MoreSuggestionsListener)) {
|
|
||||||
Log.e(TAG, "Expected mListener is MoreSuggestionsListener, but found "
|
|
||||||
+ mListener.getClass().getName());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
((MoreSuggestionsListener)mListener).onSuggestionSelected(suggestedWords.getInfo(index));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -47,7 +47,7 @@ import helium314.keyboard.latin.define.DebugFlags
|
||||||
import helium314.keyboard.latin.settings.DebugSettings
|
import helium314.keyboard.latin.settings.DebugSettings
|
||||||
import helium314.keyboard.latin.settings.Defaults
|
import helium314.keyboard.latin.settings.Defaults
|
||||||
import helium314.keyboard.latin.settings.Settings
|
import helium314.keyboard.latin.settings.Settings
|
||||||
import helium314.keyboard.latin.suggestions.PopupSuggestionsView.MoreSuggestionsListener
|
import helium314.keyboard.latin.suggestions.MoreSuggestionsView.MoreSuggestionsListener
|
||||||
import helium314.keyboard.latin.utils.Log
|
import helium314.keyboard.latin.utils.Log
|
||||||
import helium314.keyboard.latin.utils.ToolbarKey
|
import helium314.keyboard.latin.utils.ToolbarKey
|
||||||
import helium314.keyboard.latin.utils.ToolbarMode
|
import helium314.keyboard.latin.utils.ToolbarMode
|
||||||
|
@ -180,7 +180,7 @@ class SuggestionStripView(context: Context, attrs: AttributeSet?, defStyle: Int)
|
||||||
|
|
||||||
// related to more suggestions
|
// related to more suggestions
|
||||||
// todo: maybe put most of this in a separate class?
|
// todo: maybe put most of this in a separate class?
|
||||||
private val moreSuggestionsView: PopupSuggestionsView = moreSuggestionsContainer.findViewById(R.id.more_suggestions_view)
|
private val moreSuggestionsView: MoreSuggestionsView = moreSuggestionsContainer.findViewById(R.id.more_suggestions_view)
|
||||||
private val moreSuggestionsBuilder = MoreSuggestions.Builder(context, moreSuggestionsView) // todo: why actually here?
|
private val moreSuggestionsBuilder = MoreSuggestions.Builder(context, moreSuggestionsView) // todo: why actually here?
|
||||||
private val moreSuggestionsModalTolerance = context.resources.getDimensionPixelOffset(R.dimen.config_more_suggestions_modal_tolerance)
|
private val moreSuggestionsModalTolerance = context.resources.getDimensionPixelOffset(R.dimen.config_more_suggestions_modal_tolerance)
|
||||||
private val moreSuggestionsListener = object : MoreSuggestionsListener() {
|
private val moreSuggestionsListener = object : MoreSuggestionsListener() {
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
>
|
>
|
||||||
<helium314.keyboard.latin.suggestions.PopupSuggestionsView
|
<helium314.keyboard.latin.suggestions.MoreSuggestionsView
|
||||||
xmlns:latin="http://schemas.android.com/apk/res-auto"
|
xmlns:latin="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/more_suggestions_view"
|
android:id="@+id/more_suggestions_view"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue