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

Commit

Permalink
Update keyboard placement (#1203)
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro authored May 10, 2019
1 parent b0d1e0b commit db8e0d4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.view.inputmethod.InputConnection;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

Expand Down Expand Up @@ -73,6 +74,7 @@ public class KeyboardWidget extends UIWidget implements CustomKeyboardView.OnKey
private Drawable mShiftOffIcon;
private Drawable mCapsLockOnIcon;
private View mFocusedView;
private LinearLayout mKeyboardLayout;
private RelativeLayout mKeyboardContainer;
private UIWidget mBrowserWidget;
private InputConnection mInputConnection;
Expand Down Expand Up @@ -119,6 +121,7 @@ private void initialize(Context aContext) {
mPopupKeyboardview = findViewById(R.id.popupKeyboard);
mPopupKeyboardLayer = findViewById(R.id.popupKeyboardLayer);
mLanguageSelectorView = findViewById(R.id.langSelectorView);
mKeyboardLayout = findViewById(R.id.keyboardLayout);
mKeyboardContainer = findViewById(R.id.keyboardContainer);
mLanguageSelectorView.setDelegate(aItem -> handleLanguageChange((KeyboardInterface) aItem.tag));
mAutoCompletionView = findViewById(R.id.autoCompletionView);
Expand Down Expand Up @@ -208,12 +211,11 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
aPlacement.height = WidgetPlacement.dpDimension(context, R.dimen.keyboard_height);
aPlacement.height += WidgetPlacement.dpDimension(context, R.dimen.autocompletion_widget_line_height);
aPlacement.height += WidgetPlacement.dpDimension(context, R.dimen.keyboard_layout_padding);
aPlacement.parentAnchorX = 0.5f;
aPlacement.parentAnchorY = 0.0f;
aPlacement.anchorX = 0.5f;
aPlacement.anchorY = 0.5f;
aPlacement.translationZ = WidgetPlacement.unitFromMeters(context, R.dimen.keyboard_z_distance_from_browser);
aPlacement.translationY = WidgetPlacement.unitFromMeters(context, R.dimen.keyboard_y_distance_from_browser);
aPlacement.anchorY = 0.0f;
aPlacement.translationX = WidgetPlacement.unitFromMeters(context, R.dimen.keyboard_x);
aPlacement.translationY = WidgetPlacement.unitFromMeters(context, R.dimen.keyboard_y);
aPlacement.translationZ = WidgetPlacement.unitFromMeters(context, R.dimen.keyboard_z);
aPlacement.rotationAxisX = 1.0f;
aPlacement.rotation = (float)Math.toRadians(WidgetPlacement.floatDimension(context, R.dimen.keyboard_world_rotation));
aPlacement.worldWidth = WidgetPlacement.floatDimension(context, R.dimen.keyboard_world_width);
Expand All @@ -231,9 +233,6 @@ private int getKeyboardWidth(float aAlphabeticWidth) {

public void setBrowserWidget(UIWidget aWidget) {
mBrowserWidget = aWidget;
if (mBrowserWidget != null) {
mWidgetPlacement.parentHandle = mBrowserWidget.getHandle();
}
}

private void resetKeyboardLayout() {
Expand Down Expand Up @@ -342,7 +341,7 @@ public void onLongPress(Keyboard.Key popupKey) {
maxCharsPerLine = MAX_CHARS_PER_LINE_LONG;
}
default: {
float totalWidth = WidgetPlacement.convertPixelsToDp(getContext(), mCurrentKeyboard.getAlphabeticKeyboardWidth());
float totalWidth = WidgetPlacement.convertDpToPixel(getContext(), mCurrentKeyboard.getAlphabeticKeyboardWidth());
rightAligned = (float)popupKey.x > totalWidth * 0.5f;
maxCharsPerLine = MAX_CHARS_PER_LINE_LONG;
}
Expand Down Expand Up @@ -611,6 +610,10 @@ private void handleLanguageChange(KeyboardInterface aKeyboard) {
mKeyboardContainer.setLayoutParams(params);
}

RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)mKeyboardLayout.getLayoutParams();
params.topMargin = mCurrentKeyboard.supportsAutoCompletion() ? WidgetPlacement.pixelDimension(getContext(), R.dimen.keyboard_margin_top_without_autocompletion) : 0;
mKeyboardLayout.setLayoutParams(params);

SettingsStore.getInstance(getContext()).setSelectedKeyboard(aKeyboard.getLocale());
mKeyboardView.setKeyboard(mCurrentKeyboard.getAlphabeticKeyboard());
hideOverlays();
Expand Down
24 changes: 15 additions & 9 deletions app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -935,24 +935,30 @@ BrowserWorld::LayoutWidget(int32_t aHandle) {
widget->GetWorldSize(worldWidth, worldHeight);

vrb::Matrix transform = vrb::Matrix::Identity();
if (aPlacement->rotationAxis.Magnitude() > std::numeric_limits<float>::epsilon()) {
transform = vrb::Matrix::Rotation(aPlacement->rotationAxis, aPlacement->rotation);
}

vrb::Vector translation = vrb::Vector(aPlacement->translation.x() * kWorldDPIRatio,
aPlacement->translation.y() * kWorldDPIRatio,
aPlacement->translation.z() * kWorldDPIRatio);

const float anchorX = (aPlacement->anchor.x() - 0.5f) * worldWidth;
const float anchorY = (aPlacement->anchor.y() - 0.5f) * worldHeight;

if (aPlacement->rotationAxis.Magnitude() > std::numeric_limits<float>::epsilon()) {
transform = vrb::Matrix::Rotation(aPlacement->rotationAxis, aPlacement->rotation);
// Rotate from anchor point
transform.PreMultiplyInPlace(vrb::Matrix::Translation(vrb::Vector(anchorX, anchorY, 0.0f)));
transform.PostMultiplyInPlace(vrb::Matrix::Translation(vrb::Vector(-anchorX, -anchorY, 0.0f)));
}

// Widget anchor point
translation -= vrb::Vector((aPlacement->anchor.x() - 0.5f) * worldWidth,
(aPlacement->anchor.y() - 0.5f) * worldHeight,
0.0f);
translation -= vrb::Vector(anchorX, anchorY, 0.0f);

// Parent anchor point
if (parent) {
translation += vrb::Vector(
parentWorldWith * aPlacement->parentAnchor.x() - parentWorldWith * 0.5f,
parentWorldHeight * aPlacement->parentAnchor.y() - parentWorldHeight * 0.5f,
0.0f);
parentWorldWith * aPlacement->parentAnchor.x() - parentWorldWith * 0.5f,
parentWorldHeight * aPlacement->parentAnchor.y() - parentWorldHeight * 0.5f,
0.0f);
}

transform.TranslateInPlace(translation);
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/keyboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/keyboardLayout"
android:layout_width="match_parent"
android:layout_height="@dimen/keyboard_height"
android:layout_marginTop="37dp"
android:layout_marginTop="0dp"
android:orientation="horizontal">
<org.mozilla.vrbrowser.ui.views.UIButton
android:id="@+id/keyboardCloseButton"
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/res/values/dimen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
<dimen name="url_bar_last_item_width">44dp</dimen>

<!-- Keyboard -->
<item name="keyboard_world_width" format="float" type="dimen">2.85</item>
<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_width" format="float" type="dimen">3.25</item>
<item name="keyboard_x" format="float" type="dimen">-0.15</item>
<item name="keyboard_y" format="float" type="dimen">-0.6</item>
<item name="keyboard_z" format="float" type="dimen">-2.5</item>
<item name="keyboard_world_rotation" format="float" type="dimen">-35.0</item>
<dimen name="keyboard_height">188dp</dimen>
<dimen name="keyboard_alphabetic_width">526dp</dimen>
Expand All @@ -45,6 +46,7 @@
<dimen name="keyboard_key_hovered_padding">0dp</dimen>
<dimen name="keyboard_key_pressed_padding">0dp</dimen>
<dimen name="keyboard_layout_padding">4dp</dimen>
<dimen name="keyboard_margin_top_without_autocompletion">37dp</dimen>
<!-- Permission PromptWidget -->
<item name="permission_world_width" format="float" type="dimen">1.6</item>
<dimen name="permission_width">320dp</dimen>
Expand Down

0 comments on commit db8e0d4

Please sign in to comment.