2011-04-27 05:14:45 +00:00
|
|
|
/*
|
|
|
|
* 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.content.Context;
|
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.PopupWindow;
|
|
|
|
|
2011-07-11 01:09:15 +00:00
|
|
|
import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
|
|
|
|
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
|
2011-05-25 06:22:03 +00:00
|
|
|
import com.android.inputmethod.latin.R;
|
|
|
|
|
2011-04-27 05:14:45 +00:00
|
|
|
/**
|
2012-02-08 07:12:11 +00:00
|
|
|
* A view that renders a virtual {@link MoreKeysKeyboard}. It handles rendering of keys and
|
|
|
|
* detecting key presses and touch movements.
|
2011-04-27 05:14:45 +00:00
|
|
|
*/
|
2012-02-08 07:12:11 +00:00
|
|
|
public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel {
|
2011-04-27 05:14:45 +00:00
|
|
|
private final int[] mCoordinates = new int[2];
|
|
|
|
|
2011-07-11 01:09:15 +00:00
|
|
|
private final KeyDetector mKeyDetector;
|
|
|
|
|
2011-08-29 08:02:52 +00:00
|
|
|
private Controller mController;
|
|
|
|
private KeyboardActionListener mListener;
|
2011-04-27 05:14:45 +00:00
|
|
|
private int mOriginX;
|
|
|
|
private int mOriginY;
|
2011-07-11 01:09:15 +00:00
|
|
|
|
2011-08-24 05:44:46 +00:00
|
|
|
private static final TimerProxy EMPTY_TIMER_PROXY = new TimerProxy.Adapter();
|
2011-07-11 01:09:15 +00:00
|
|
|
|
2012-02-08 07:12:11 +00:00
|
|
|
private final KeyboardActionListener mMoreKeysKeyboardListener =
|
2011-08-29 10:09:56 +00:00
|
|
|
new KeyboardActionListener.Adapter() {
|
2011-07-11 01:09:15 +00:00
|
|
|
@Override
|
2012-03-06 05:56:46 +00:00
|
|
|
public void onCodeInput(int primaryCode, int x, int y) {
|
|
|
|
mListener.onCodeInput(primaryCode, x, y);
|
2011-07-11 01:09:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextInput(CharSequence text) {
|
2011-08-29 08:02:52 +00:00
|
|
|
mListener.onTextInput(text);
|
2011-07-11 01:09:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCancelInput() {
|
2011-08-29 08:02:52 +00:00
|
|
|
mListener.onCancelInput();
|
2011-07-11 01:09:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-01-17 08:08:26 +00:00
|
|
|
public void onPressKey(int primaryCode) {
|
|
|
|
mListener.onPressKey(primaryCode);
|
2011-07-11 01:09:15 +00:00
|
|
|
}
|
2012-01-17 08:08:26 +00:00
|
|
|
|
2011-07-11 01:09:15 +00:00
|
|
|
@Override
|
2012-01-17 08:08:26 +00:00
|
|
|
public void onReleaseKey(int primaryCode, boolean withSliding) {
|
|
|
|
mListener.onReleaseKey(primaryCode, withSliding);
|
2011-07-11 01:09:15 +00:00
|
|
|
}
|
|
|
|
};
|
2011-04-27 05:14:45 +00:00
|
|
|
|
2012-02-08 07:12:11 +00:00
|
|
|
public MoreKeysKeyboardView(Context context, AttributeSet attrs) {
|
|
|
|
this(context, attrs, R.attr.moreKeysKeyboardViewStyle);
|
2011-04-27 05:14:45 +00:00
|
|
|
}
|
|
|
|
|
2012-02-08 07:12:11 +00:00
|
|
|
public MoreKeysKeyboardView(Context context, AttributeSet attrs, int defStyle) {
|
2011-04-27 05:14:45 +00:00
|
|
|
super(context, attrs, defStyle);
|
|
|
|
|
|
|
|
final Resources res = context.getResources();
|
2011-09-06 02:37:51 +00:00
|
|
|
mKeyDetector = new MoreKeysDetector(
|
2012-02-08 07:12:11 +00:00
|
|
|
res.getDimension(R.dimen.more_keys_keyboard_slide_allowance));
|
2011-05-11 11:51:07 +00:00
|
|
|
setKeyPreviewPopupEnabled(false, 0);
|
2011-04-27 05:14:45 +00:00
|
|
|
}
|
|
|
|
|
2011-07-21 06:57:00 +00:00
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
final Keyboard keyboard = getKeyboard();
|
|
|
|
if (keyboard != null) {
|
2011-07-29 00:05:40 +00:00
|
|
|
final int width = keyboard.mOccupiedWidth + getPaddingLeft() + getPaddingRight();
|
|
|
|
final int height = keyboard.mOccupiedHeight + getPaddingTop() + getPaddingBottom();
|
2011-07-21 06:57:00 +00:00
|
|
|
setMeasuredDimension(width, height);
|
|
|
|
} else {
|
|
|
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-11 01:09:15 +00:00
|
|
|
@Override
|
|
|
|
public void setKeyboard(Keyboard keyboard) {
|
|
|
|
super.setKeyboard(keyboard);
|
|
|
|
mKeyDetector.setKeyboard(keyboard, -getPaddingLeft(),
|
|
|
|
-getPaddingTop() + mVerticalCorrection);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public KeyDetector getKeyDetector() {
|
|
|
|
return mKeyDetector;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public KeyboardActionListener getKeyboardActionListener() {
|
2012-02-08 07:12:11 +00:00
|
|
|
return mMoreKeysKeyboardListener;
|
2011-07-11 01:09:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DrawingProxy getDrawingProxy() {
|
2011-10-26 08:03:41 +00:00
|
|
|
return this;
|
2011-07-11 01:09:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TimerProxy getTimerProxy() {
|
|
|
|
return EMPTY_TIMER_PROXY;
|
|
|
|
}
|
|
|
|
|
2011-04-27 05:14:45 +00:00
|
|
|
@Override
|
2011-05-11 11:51:07 +00:00
|
|
|
public void setKeyPreviewPopupEnabled(boolean previewEnabled, int delay) {
|
2012-02-08 07:12:11 +00:00
|
|
|
// More keys keyboard needs no pop-up key preview displayed, so we pass always false with a
|
2011-05-11 11:51:07 +00:00
|
|
|
// delay of 0. The delay does not matter actually since the popup is not shown anyway.
|
|
|
|
super.setKeyPreviewPopupEnabled(false, 0);
|
2011-08-29 08:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-08-31 06:26:32 +00:00
|
|
|
public void showMoreKeysPanel(View parentView, Controller controller, int pointX, int pointY,
|
2011-08-29 08:02:52 +00:00
|
|
|
PopupWindow window, KeyboardActionListener listener) {
|
|
|
|
mController = controller;
|
|
|
|
mListener = listener;
|
2011-04-27 05:14:45 +00:00
|
|
|
final View container = (View)getParent();
|
2012-03-07 10:09:36 +00:00
|
|
|
final MoreKeysKeyboard pane = (MoreKeysKeyboard)getKeyboard();
|
|
|
|
final int defaultCoordX = pane.getDefaultCoordX();
|
|
|
|
// The coordinates of panel's left-top corner in parentView's coordinate system.
|
|
|
|
final int x = pointX - defaultCoordX - container.getPaddingLeft()
|
2011-08-29 08:02:52 +00:00
|
|
|
+ parentView.getPaddingLeft();
|
2012-03-07 10:09:36 +00:00
|
|
|
final int y = pointY - container.getMeasuredHeight() + container.getPaddingBottom()
|
|
|
|
+ parentView.getPaddingTop();
|
2011-04-27 05:14:45 +00:00
|
|
|
|
|
|
|
window.setContentView(container);
|
|
|
|
window.setWidth(container.getMeasuredWidth());
|
|
|
|
window.setHeight(container.getMeasuredHeight());
|
2012-03-07 10:09:36 +00:00
|
|
|
parentView.getLocationInWindow(mCoordinates);
|
|
|
|
window.showAtLocation(parentView, Gravity.NO_GRAVITY,
|
|
|
|
x + mCoordinates[0], y + mCoordinates[1]);
|
2011-04-27 05:14:45 +00:00
|
|
|
|
2012-03-07 10:09:36 +00:00
|
|
|
mOriginX = x + container.getPaddingLeft();
|
|
|
|
mOriginY = y + container.getPaddingTop();
|
2011-08-26 06:45:05 +00:00
|
|
|
}
|
|
|
|
|
2011-10-26 08:03:41 +00:00
|
|
|
private boolean mIsDismissing;
|
|
|
|
|
2011-07-23 08:16:56 +00:00
|
|
|
@Override
|
2011-08-31 06:26:32 +00:00
|
|
|
public boolean dismissMoreKeysPanel() {
|
2011-10-26 08:03:41 +00:00
|
|
|
if (mIsDismissing) return false;
|
|
|
|
mIsDismissing = true;
|
|
|
|
final boolean dismissed = mController.dismissMoreKeysPanel();
|
|
|
|
mIsDismissing = false;
|
|
|
|
return dismissed;
|
2011-07-23 08:16:56 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 05:14:45 +00:00
|
|
|
@Override
|
2011-07-11 01:09:15 +00:00
|
|
|
public int translateX(int x) {
|
|
|
|
return x - mOriginX;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int translateY(int y) {
|
|
|
|
return y - mOriginY;
|
2011-04-27 05:14:45 +00:00
|
|
|
}
|
|
|
|
}
|