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.os.SystemClock;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.PopupWindow;
|
|
|
|
|
2011-05-25 06:22:03 +00:00
|
|
|
import com.android.inputmethod.latin.R;
|
|
|
|
|
2011-04-27 05:14:45 +00:00
|
|
|
/**
|
|
|
|
* A view that renders a virtual {@link MiniKeyboard}. It handles rendering of keys and detecting
|
|
|
|
* key presses and touch movements.
|
|
|
|
*/
|
2011-07-01 04:07:59 +00:00
|
|
|
public class PopupMiniKeyboardView extends LatinKeyboardBaseView implements PopupPanel {
|
2011-04-27 05:14:45 +00:00
|
|
|
private final int[] mCoordinates = new int[2];
|
|
|
|
private final boolean mConfigShowMiniKeyboardAtTouchedPoint;
|
|
|
|
|
|
|
|
private int mOriginX;
|
|
|
|
private int mOriginY;
|
|
|
|
private long mDownTime;
|
|
|
|
|
|
|
|
public PopupMiniKeyboardView(Context context, AttributeSet attrs) {
|
2011-05-24 12:08:20 +00:00
|
|
|
this(context, attrs, R.attr.popupMiniKeyboardViewStyle);
|
2011-04-27 05:14:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2011-05-11 11:51:07 +00:00
|
|
|
setKeyPreviewPopupEnabled(false, 0);
|
2011-04-27 05:14:45 +00:00
|
|
|
}
|
|
|
|
|
2011-07-08 05:02:17 +00:00
|
|
|
@Override
|
|
|
|
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
|
|
|
// Do nothing for the mini keyboard.
|
|
|
|
}
|
|
|
|
|
2011-04-27 05:14:45 +00:00
|
|
|
@Override
|
2011-05-11 11:51:07 +00:00
|
|
|
public void setKeyPreviewPopupEnabled(boolean previewEnabled, int delay) {
|
|
|
|
// Mini keyboard needs no pop-up key preview displayed, so we pass always false with a
|
|
|
|
// delay of 0. The delay does not matter actually since the popup is not shown anyway.
|
|
|
|
super.setKeyPreviewPopupEnabled(false, 0);
|
2011-04-27 05:14:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void showPanel(KeyboardView parentKeyboardView, Key parentKey,
|
2011-06-23 12:14:55 +00:00
|
|
|
PointerTracker tracker, PopupWindow window) {
|
2011-04-27 05:14:45 +00:00
|
|
|
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;
|
2011-06-03 12:28:24 +00:00
|
|
|
final int miniKeyboardLeft = pointX - miniKeyboard.getDefaultCoordX()
|
|
|
|
+ parentKeyboardView.getPaddingLeft();
|
2011-06-21 11:10:51 +00:00
|
|
|
final int x = Math.max(0, Math.min(miniKeyboardLeft,
|
2011-06-03 12:28:24 +00:00
|
|
|
parentKeyboardView.getWidth() - miniKeyboard.getMinWidth()))
|
|
|
|
- container.getPaddingLeft() + mCoordinates[0];
|
2011-06-21 11:10:51 +00:00
|
|
|
final int y = pointY - parentKeyboard.getVerticalGap()
|
2011-04-27 05:14:45 +00:00
|
|
|
- (container.getMeasuredHeight() - container.getPaddingBottom())
|
|
|
|
+ parentKeyboardView.getPaddingTop() + mCoordinates[1];
|
|
|
|
|
|
|
|
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];
|
|
|
|
mDownTime = SystemClock.uptimeMillis();
|
|
|
|
|
|
|
|
// Inject down event on the key to mini keyboard.
|
2011-06-08 07:58:08 +00:00
|
|
|
final MotionEvent downEvent = MotionEvent.obtain(mDownTime, mDownTime,
|
|
|
|
MotionEvent.ACTION_DOWN, pointX - mOriginX,
|
|
|
|
pointY + parentKey.mHeight / 2 - mOriginY, 0);
|
2011-04-27 05:14:45 +00:00
|
|
|
onTouchEvent(downEvent);
|
|
|
|
downEvent.recycle();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent me) {
|
2011-06-08 07:58:08 +00:00
|
|
|
me.offsetLocation(-mOriginX, -mOriginY);
|
|
|
|
return super.onTouchEvent(me);
|
2011-04-27 05:14:45 +00:00
|
|
|
}
|
|
|
|
}
|