Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Keyboard refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro committed May 3, 2019
1 parent a555d88 commit 3b343a5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ public class AutoCompletionView extends FrameLayout {
private int mLineHeight;
private UIButton mExtendButton;
private int mExtendedHeight;
private final int kMaxItemsPerLine = 12;
private final int kMaxItemsPerLine = 15;
private ArrayList<Words> mExtraItems = new ArrayList<>();
private boolean mIsExtended;
private Delegate mDelegate;

public interface Delegate {
void onAutoCompletionItemClick(Words aItem);
void onAutoCompletionExtendedChanged();
}

public AutoCompletionView(Context aContext) {
Expand Down Expand Up @@ -71,8 +72,7 @@ private void initialize(Context aContext) {
enterExtend();
}
});
mKeyWidth = WidgetPlacement.pixelDimension(getContext(), R.dimen.keyboard_key_width);
mKeyHeight = WidgetPlacement.pixelDimension(getContext(), R.dimen.keyboard_key_height);
mKeyWidth = mKeyHeight = WidgetPlacement.pixelDimension(getContext(), R.dimen.autocompletion_widget_button_size);
mLineHeight = WidgetPlacement.pixelDimension(getContext(), R.dimen.autocompletion_widget_line_height);
mExtendedHeight = mLineHeight * 6;
setFocusable(false);
Expand All @@ -90,7 +90,6 @@ private UITextButton createButton(Words aWords, OnClickListener aHandler) {
UITextButton key = new UITextButton(getContext());
key.setTintColorList(R.drawable.main_button_icon_color);
key.setBackground(getContext().getDrawable(R.drawable.keyboard_key_background));
//key.setBackgroundColor(Color.RED);
if (aHandler != null) {
key.setOnClickListener(aHandler);
}
Expand Down Expand Up @@ -137,6 +136,10 @@ public void setItems(List<Words> aItems) {
mExtendButton.setVisibility(n >= kMaxItemsPerLine ? View.VISIBLE : View.GONE);
}

public boolean isExtended() {
return mIsExtended;
}

private OnClickListener clickHandler = v -> {
UITextButton button = (UITextButton) v;
if (mIsExtended) {
Expand Down Expand Up @@ -178,6 +181,9 @@ private void enterExtend() {
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams();
params.height = mExtendedHeight;
setLayoutParams(params);
if (mDelegate != null) {
mDelegate.onAutoCompletionExtendedChanged();
}
}

private void exitExtend() {
Expand All @@ -190,5 +196,8 @@ private void exitExtend() {
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams();
params.height = WidgetPlacement.pixelDimension(getContext(), R.dimen.autocompletion_widget_line_height);
setLayoutParams(params);
if (mDelegate != null) {
mDelegate.onAutoCompletionExtendedChanged();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public class KeyboardWidget extends UIWidget implements CustomKeyboardView.OnKey
private InputConnection mInputConnection;
private EditorInfo mEditorInfo = new EditorInfo();
private VoiceSearchWidget mVoiceSearchWidget;
private LinearLayout mKeyboardContainer;
private AutoCompletionView mAutoCompletionView;

private int mKeyWidth;
Expand Down Expand Up @@ -108,7 +107,6 @@ private void initialize(Context aContext) {
mKeyboardNumericView = findViewById(R.id.keyboardNumeric);
mPopupKeyboardview = findViewById(R.id.popupKeyboard);
mPopupKeyboardLayer = findViewById(R.id.popupKeyboardLayer);
mKeyboardContainer = findViewById(R.id.keyboardContainer);

mKeyboards = new ArrayList<>();
mKeyboards.add(new EnglishKeyboard(aContext));
Expand Down Expand Up @@ -622,13 +620,14 @@ private void postUICommand(Runnable aRunnable) {
}

private void updateCandidates() {
setAutoCompletionVisible(mCurrentKeyboard.supportsAutoCompletion());
if (mInputConnection == null) {
if (mInputConnection == null || !mCurrentKeyboard.supportsAutoCompletion()) {
setAutoCompletionVisible(false);
return;
}

if (mCurrentKeyboard.usesComposingText()) {
final KeyboardInterface.CandidatesResult candidates = mCurrentKeyboard.getCandidates(mComposingText);
setAutoCompletionVisible(candidates != null && candidates.words.size() > 0);
mAutoCompletionView.setItems(candidates != null ? candidates.words : null);
if (candidates != null && candidates.action == KeyboardInterface.CandidatesResult.Action.AUTO_COMPOSE) {
onAutoCompletionItemClick(candidates.words.get(0));
Expand All @@ -646,6 +645,7 @@ private void updateCandidates() {
String fullText = mInputConnection.getExtractedText(new ExtractedTextRequest(),0).text.toString();
String beforeText = mInputConnection.getTextBeforeCursor(fullText.length(),0).toString();
final KeyboardInterface.CandidatesResult candidates = mCurrentKeyboard.getCandidates(beforeText);
setAutoCompletionVisible(candidates != null && candidates.words.size() > 0);
mAutoCompletionView.setItems(candidates != null ? candidates.words : null);
}

Expand All @@ -666,14 +666,6 @@ private void updateSpecialKeyLabels() {

private void setAutoCompletionVisible(boolean aVisible) {
mAutoCompletionView.setVisibility(aVisible ? View.VISIBLE : View.GONE);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mKeyboardContainer.getLayoutParams();
if (aVisible) {
params.topMargin = WidgetPlacement.pixelDimension(getContext(), R.dimen.autocompletion_widget_line_height);
params.topMargin += WidgetPlacement.pixelDimension(getContext(), R.dimen.keyboard_autocompletion_padding);
} else {
params.topMargin = 0;
}
mKeyboardContainer.setLayoutParams(params);
}

// Must be called in the input thread, see postInputCommand.
Expand Down Expand Up @@ -805,6 +797,11 @@ public void onAutoCompletionItemClick(final KeyboardInterface.Words aItem) {
}
}

@Override
public void onAutoCompletionExtendedChanged() {
mKeyboardView.setVisibility(mAutoCompletionView.isExtended() ? View.INVISIBLE : View.VISIBLE);
}

// TextWatcher
private String mTextBefore = "";
@Override
Expand Down
17 changes: 8 additions & 9 deletions app/src/main/res/layout/keyboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
android:id="@+id/keyboardContainer"
android:layout_width="match_parent"
android:layout_height="@dimen/keyboard_height"
android:layout_marginTop="@dimen/autocompletion_widget_line_height"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="@dimen/keyboard_alphabetic_width"
android:layout_height="match_parent">

<org.mozilla.vrbrowser.ui.views.CustomKeyboardView
android:id="@+id/keyboard"
android:padding="20dp"
android:padding="15dp"
android:background="@drawable/keyboard_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -31,12 +32,11 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="20dp"
android:layout_margin="15dp"
android:background="@color/asphalt"
android:alpha="0.5"
android:visibility="visible"/>


<org.mozilla.vrbrowser.ui.views.CustomKeyboardView
android:id="@+id/popupKeyboard"
android:layout_width="wrap_content"
Expand All @@ -58,7 +58,7 @@
android:id="@+id/keyboardNumeric"
android:layout_width="@dimen/keyboard_numeric_width"
android:layout_height="match_parent"
android:padding="20dp"
android:padding="15dp"
android:background="@drawable/keyboard_background"
android:keyBackground="@drawable/keyboard_key_background"
android:shadowColor="@android:color/transparent"
Expand All @@ -69,22 +69,21 @@

<org.mozilla.vrbrowser.ui.views.AutoCompletionView
android:id="@+id/autoCompletionView"
android:layout_width="@dimen/keyboard_alphabetic_width"
android:layout_width="match_parent"
android:layout_height="@dimen/autocompletion_widget_line_height"
android:layout_marginStart="38dp"
android:visibility="gone">

</org.mozilla.vrbrowser.ui.views.AutoCompletionView>

<org.mozilla.vrbrowser.ui.views.UIButton
android:id="@+id/keyboardCloseButton"
android:visibility="gone"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_width="@dimen/autocompletion_widget_line_height"
android:layout_height="@dimen/autocompletion_widget_line_height"
app:tintColorList="@drawable/url_button_icon_color"
android:padding="10dp"
android:src="@drawable/ic_icon_exit"
android:scaleType="fitCenter"
android:layout_marginLeft="240dp"
android:background="@drawable/keyboard_key_background"/>

</RelativeLayout>
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/res/values/dimen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
<item name="keyboard_y_distance_from_browser" format="float" type="dimen">-0.18</item>
<item name="keyboard_z_distance_from_browser" format="float" type="dimen">2.0</item>
<item name="keyboard_world_rotation" format="float" type="dimen">-35.0</item>
<dimen name="keyboard_width">672dp</dimen>
<dimen name="keyboard_height">190dp</dimen>
<dimen name="keyboard_alphabetic_width">516dp</dimen>
<dimen name="keyboard_numeric_width">156dp</dimen>
<dimen name="keyboard_width">674dp</dimen>
<dimen name="keyboard_height">188dp</dimen>
<dimen name="keyboard_alphabetic_width">526dp</dimen>
<dimen name="keyboard_numeric_width">148dp</dimen>
<dimen name="keyboard_horizontal_gap">4dp</dimen>
<dimen name="keyboard_vertical_gap">4dp</dimen>
<dimen name="keyboard_key_width">34dp</dimen>
<dimen name="keyboard_key_height">34dp</dimen>
<dimen name="keyboard_key_width">36dp</dimen>
<dimen name="keyboard_key_height">36dp</dimen>
<dimen name="keyboard_key_rounded_corner">18dp</dimen>
<dimen name="keyboard_key_space_width">186dp</dimen>
<dimen name="keyboard_key_backspace_width">50dp</dimen>
Expand Down Expand Up @@ -95,10 +95,10 @@
<dimen name="no_internet_z_distance" format="float" type="dimen">2.5</dimen>

<!-- Autocompletion Widget -->
<dimen name="autocompletion_widget_default_width">40dp</dimen>
<dimen name="autocompletion_widget_line_height">40dp</dimen>
<dimen name="autocompletion_widget_line_height">36dp</dimen>
<dimen name="autocompletion_widget_extended_height">160dp</dimen>
<dimen name="autocompletion_widget_margin">35dp</dimen>
<dimen name="autocompletion_widget_margin">4dp</dimen>
<dimen name="autocompletion_widget_button_size">34dp</dimen>

<!-- Tray -->
<item name="tray_world_y" format="float" type="dimen">0.1</item>
Expand Down

0 comments on commit 3b343a5

Please sign in to comment.