Skip to content
Snippets Groups Projects
Commit ff082d08 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka
Browse files

Refactor KeyboardView and create MiniKeyboardView

Change-Id: I8d68b944762ccde05020978f20b3742eb6ab945b
parent aac2d87d
No related branches found
No related tags found
No related merge requests found
Showing
with 302 additions and 199 deletions
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<com.android.inputmethod.keyboard.LatinKeyboardView <com.android.inputmethod.keyboard.LatinKeyboardView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
android:id="@+id/LatinkeyboardBaseView" android:id="@+id/latin_keyboard_view"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<com.android.inputmethod.keyboard.LatinKeyboardView <com.android.inputmethod.keyboard.LatinKeyboardView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
android:id="@+id/LatinkeyboardBaseView" android:id="@+id/latin_keyboard_view"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<com.android.inputmethod.keyboard.LatinKeyboardView <com.android.inputmethod.keyboard.LatinKeyboardView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
android:id="@+id/LatinkeyboardBaseView" android:id="@+id/latin_keyboard_view"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<com.android.inputmethod.keyboard.LatinKeyboardView <com.android.inputmethod.keyboard.LatinKeyboardView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
android:id="@+id/LatinkeyboardBaseView" android:id="@+id/latin_keyboard_view"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<com.android.inputmethod.keyboard.LatinKeyboardView <com.android.inputmethod.keyboard.LatinKeyboardView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
android:id="@+id/LatinkeyboardBaseView" android:id="@+id/latin_keyboard_view"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<com.android.inputmethod.keyboard.LatinKeyboardView <com.android.inputmethod.keyboard.LatinKeyboardView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
android:id="@+id/LatinkeyboardBaseView" android:id="@+id/latin_keyboard_view"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
......
...@@ -26,9 +26,9 @@ ...@@ -26,9 +26,9 @@
android:paddingLeft="@dimen/mini_keyboard_horizontal_padding" android:paddingLeft="@dimen/mini_keyboard_horizontal_padding"
android:paddingRight="@dimen/mini_keyboard_horizontal_padding" android:paddingRight="@dimen/mini_keyboard_horizontal_padding"
> >
<com.android.inputmethod.keyboard.KeyboardView <com.android.inputmethod.keyboard.PopupMiniKeyboardView
xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
android:id="@+id/KeyboardView" android:id="@+id/mini_keyboard_view"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
......
...@@ -26,9 +26,9 @@ ...@@ -26,9 +26,9 @@
android:paddingLeft="@dimen/mini_keyboard_horizontal_padding_holo" android:paddingLeft="@dimen/mini_keyboard_horizontal_padding_holo"
android:paddingRight="@dimen/mini_keyboard_horizontal_padding_holo" android:paddingRight="@dimen/mini_keyboard_horizontal_padding_holo"
> >
<com.android.inputmethod.keyboard.KeyboardView <com.android.inputmethod.keyboard.PopupMiniKeyboardView
xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
android:id="@+id/KeyboardView" android:id="@+id/mini_keyboard_view"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
......
...@@ -25,9 +25,9 @@ ...@@ -25,9 +25,9 @@
android:orientation="horizontal" android:orientation="horizontal"
android:background="@drawable/keyboard_popup_panel_background" android:background="@drawable/keyboard_popup_panel_background"
> >
<com.android.inputmethod.keyboard.KeyboardView <com.android.inputmethod.keyboard.PopupMiniKeyboardView
xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
android:id="@+id/KeyboardView" android:id="@+id/mini_keyboard_view"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
<item name="backgroundDimAmount">0.5</item> <item name="backgroundDimAmount">0.5</item>
<item name="colorScheme">white</item> <item name="colorScheme">white</item>
</style> </style>
<style name="MiniKeyboardAnimation"> <style name="PopupMiniKeyboardAnimation">
<item name="android:windowEnterAnimation">@anim/mini_keyboard_fadein</item> <item name="android:windowEnterAnimation">@anim/mini_keyboard_fadein</item>
<item name="android:windowExitAnimation">@anim/mini_keyboard_fadeout</item> <item name="android:windowExitAnimation">@anim/mini_keyboard_fadeout</item>
</style> </style>
......
This diff is collapsed.
...@@ -18,6 +18,8 @@ package com.android.inputmethod.keyboard; ...@@ -18,6 +18,8 @@ package com.android.inputmethod.keyboard;
import android.content.Context; import android.content.Context;
import java.util.List;
public class MiniKeyboard extends Keyboard { public class MiniKeyboard extends Keyboard {
private int mDefaultKeyCoordX; private int mDefaultKeyCoordX;
...@@ -32,4 +34,19 @@ public class MiniKeyboard extends Keyboard { ...@@ -32,4 +34,19 @@ public class MiniKeyboard extends Keyboard {
public int getDefaultCoordX() { public int getDefaultCoordX() {
return mDefaultKeyCoordX; return mDefaultKeyCoordX;
} }
public boolean isOneRowKeyboard() {
final List<Key> keys = getKeys();
if (keys.size() == 0) return false;
final int edgeFlags = keys.get(0).mEdgeFlags;
// HACK: The first key of mini keyboard which was inflated from xml and has multiple rows,
// does not have both top and bottom edge flags on at the same time. On the other hand,
// the first key of mini keyboard that was created with popupCharacters must have both top
// and bottom edge flags on.
// When you want to use one row mini-keyboard from xml file, make sure that the row has
// both top and bottom edge flags set.
return (edgeFlags & Keyboard.EDGE_TOP) != 0
&& (edgeFlags & Keyboard.EDGE_BOTTOM) != 0;
}
} }
/*
* Copyright (C) 2011 The Android Open Source Project
*
* 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.
*/
package com.android.inputmethod.keyboard;
import com.android.inputmethod.latin.R;
import android.content.Context;
import android.content.res.Resources;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.PopupWindow;
/**
* A view that renders a virtual {@link MiniKeyboard}. It handles rendering of keys and detecting
* key presses and touch movements.
*/
public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel {
private final int[] mCoordinates = new int[2];
private final boolean mConfigShowMiniKeyboardAtTouchedPoint;
private int mOriginX;
private int mOriginY;
private int mTrackerId;
private long mDownTime;
public PopupMiniKeyboardView(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.keyboardViewStyle);
}
public PopupMiniKeyboardView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
final Resources res = context.getResources();
mConfigShowMiniKeyboardAtTouchedPoint = res.getBoolean(
R.bool.config_show_mini_keyboard_at_touched_point);
// Override default ProximityKeyDetector.
mKeyDetector = new MiniKeyboardKeyDetector(res.getDimension(
R.dimen.mini_keyboard_slide_allowance));
// Remove gesture detector on mini-keyboard
mGestureDetector = null;
setKeyPreviewEnabled(false);
}
@Override
public void setKeyPreviewEnabled(boolean previewEnabled) {
// Mini keyboard needs no pop-up key preview displayed.
super.setKeyPreviewEnabled(false);
}
@Override
public void showPanel(KeyboardView parentKeyboardView, Key parentKey,
PointerTracker tracker, int keyPreviewY, PopupWindow window) {
final View container = (View)getParent();
final MiniKeyboard miniKeyboard = (MiniKeyboard)getKeyboard();
final Keyboard parentKeyboard = parentKeyboardView.getKeyboard();
parentKeyboardView.getLocationInWindow(mCoordinates);
final int pointX = (mConfigShowMiniKeyboardAtTouchedPoint) ? tracker.getLastX()
: parentKey.mX + parentKey.mWidth / 2;
final int pointY = parentKey.mY;
final int miniKeyboardX = pointX - miniKeyboard.getDefaultCoordX()
- container.getPaddingLeft()
+ parentKeyboardView.getPaddingLeft() + mCoordinates[0];
final int miniKeyboardY = pointY - parentKeyboard.getVerticalGap()
- (container.getMeasuredHeight() - container.getPaddingBottom())
+ parentKeyboardView.getPaddingTop() + mCoordinates[1];
final int x = miniKeyboardX;
final int y = parentKeyboardView.isKeyPreviewEnabled() && miniKeyboard.isOneRowKeyboard()
? keyPreviewY : miniKeyboardY;
if (miniKeyboard.setShifted(parentKeyboard.isShiftedOrShiftLocked())) {
invalidateAllKeys();
}
window.setContentView(container);
window.setWidth(container.getMeasuredWidth());
window.setHeight(container.getMeasuredHeight());
window.showAtLocation(parentKeyboardView, Gravity.NO_GRAVITY, x, y);
mOriginX = x + container.getPaddingLeft() - mCoordinates[0];
mOriginY = y + container.getPaddingTop() - mCoordinates[1];
mTrackerId = tracker.mPointerId;
mDownTime = SystemClock.uptimeMillis();
// Inject down event on the key to mini keyboard.
final MotionEvent downEvent = translateMotionEvent(MotionEvent.ACTION_DOWN, pointX,
pointY + parentKey.mHeight / 2, mDownTime);
onTouchEvent(downEvent);
downEvent.recycle();
}
private MotionEvent translateMotionEvent(int action, float x, float y, long eventTime) {
return MotionEvent.obtain(mDownTime, eventTime, action, x - mOriginX, y - mOriginY, 0);
}
@Override
public boolean onTouchEvent(MotionEvent me) {
final int index = me.getActionIndex();
final int id = me.getPointerId(index);
if (id == mTrackerId) {
final MotionEvent translated = translateMotionEvent(me.getAction(), me.getX(index),
me.getY(index), me.getEventTime());
super.onTouchEvent(translated);
translated.recycle();
}
return true;
}
}
/*
* Copyright (C) 2011 The Android Open Source Project
*
* 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.
*/
package com.android.inputmethod.keyboard;
import android.view.MotionEvent;
import android.widget.PopupWindow;
public interface PopupPanel {
/**
* Show popup panel.
* @param parentKeyboardView the parent KeyboardView that has the parent key.
* @param parentKey the parent key that is the source of this popup panel
* @param tracker the pointer tracker that pressesd the parent key
* @param keyPreviewY the Y-coordinate of key preview
* @param window PopupWindow to be used to show this popup panel
*/
public void showPanel(KeyboardView parentKeyboardView, Key parentKey,
PointerTracker tracker, int keyPreviewY, PopupWindow window);
/**
* Check if the pointer is in siding key input mode.
* @return true if the pointer is sliding key input mode.
*/
public boolean isInSlidingKeyInput();
/**
* The motion event handler.
* @param me the MotionEvent to be processed.
* @return true if the motion event is processed and should be consumed.
*/
public boolean onTouchEvent(MotionEvent me);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment