am ffa88f0e: Merge "Move inflating mini keyboard code into separate method" into gingerbread

Merge commit 'ffa88f0ef546d6393ecf4cec1ccb68229124f208' into gingerbread-plus-aosp

* commit 'ffa88f0ef546d6393ecf4cec1ccb68229124f208':
  Move inflating mini keyboard code into separate method
main
Tadashi G. Takaoka 2010-09-03 02:56:42 -07:00 committed by Android Git Automerger
commit c93ac9db71
1 changed files with 93 additions and 82 deletions

View File

@ -971,24 +971,15 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
return result; return result;
} }
/** private View inflateMiniKeyboardContainer(Key popupKey) {
* Called when a key is long pressed. By default this will open any popup keyboard associated
* with this key through the attributes popupLayout and popupCharacters.
* @param popupKey the key that was long pressed
* @return true if the long press is handled, false otherwise. Subclasses should call the
* method on the base class if the subclass doesn't wish to handle the call.
*/
protected boolean onLongPress(Key popupKey) {
int popupKeyboardId = popupKey.popupResId; int popupKeyboardId = popupKey.popupResId;
if (popupKeyboardId != 0) {
View container = mMiniKeyboardCache.get(popupKey);
if (container == null) {
LayoutInflater inflater = (LayoutInflater)getContext().getSystemService( LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE); Context.LAYOUT_INFLATER_SERVICE);
container = inflater.inflate(mPopupLayout, null); View container = inflater.inflate(mPopupLayout, null);
mMiniKeyboard = (LatinKeyboardBaseView) container.findViewById( if (container == null)
R.id.LatinKeyboardBaseView); throw new NullPointerException();
mMiniKeyboard = (LatinKeyboardBaseView)container.findViewById(R.id.LatinKeyboardBaseView);
mMiniKeyboard.setOnKeyboardActionListener(new OnKeyboardActionListener() { mMiniKeyboard.setOnKeyboardActionListener(new OnKeyboardActionListener() {
public void onKey(int primaryCode, int[] keyCodes, int x, int y) { public void onKey(int primaryCode, int[] keyCodes, int x, int y) {
mKeyboardActionListener.onKey(primaryCode, keyCodes, x, y); mKeyboardActionListener.onKey(primaryCode, keyCodes, x, y);
@ -1000,10 +991,14 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
dismissPopupKeyboard(); dismissPopupKeyboard();
} }
public void swipeLeft() { } public void swipeLeft() {
public void swipeRight() { } }
public void swipeUp() { } public void swipeRight() {
public void swipeDown() { } }
public void swipeUp() {
}
public void swipeDown() {
}
public void onPress(int primaryCode) { public void onPress(int primaryCode) {
mKeyboardActionListener.onPress(primaryCode); mKeyboardActionListener.onPress(primaryCode);
} }
@ -1014,22 +1009,40 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
Keyboard keyboard; Keyboard keyboard;
if (popupKey.popupCharacters != null) { if (popupKey.popupCharacters != null) {
keyboard = new Keyboard(getContext(), popupKeyboardId, keyboard = new Keyboard(getContext(), popupKeyboardId, popupKey.popupCharacters,
popupKey.popupCharacters, -1, getPaddingLeft() + getPaddingRight()); -1, getPaddingLeft() + getPaddingRight());
} else { } else {
keyboard = new Keyboard(getContext(), popupKeyboardId); keyboard = new Keyboard(getContext(), popupKeyboardId);
} }
mMiniKeyboard.setKeyboard(keyboard); mMiniKeyboard.setKeyboard(keyboard);
mMiniKeyboard.setPopupParent(this); mMiniKeyboard.setPopupParent(this);
container.measure(
MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.AT_MOST), container.measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.AT_MOST),
MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.AT_MOST)); MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.AT_MOST));
mMiniKeyboardCache.put(popupKey, container); return container;
} else {
mMiniKeyboard = (LatinKeyboardBaseView) container.findViewById(
R.id.LatinKeyboardBaseView);
} }
/**
* Called when a key is long pressed. By default this will open any popup keyboard associated
* with this key through the attributes popupLayout and popupCharacters.
* @param popupKey the key that was long pressed
* @return true if the long press is handled, false otherwise. Subclasses should call the
* method on the base class if the subclass doesn't wish to handle the call.
*/
protected boolean onLongPress(Key popupKey) {
// TODO if popupKey.popupCharacters has only one letter, send it as key without opening
// mini keyboard.
if (popupKey.popupResId == 0)
return false;
View container = mMiniKeyboardCache.get(popupKey);
if (container == null) {
container = inflateMiniKeyboardContainer(popupKey);
mMiniKeyboardCache.put(popupKey, container);
}
mMiniKeyboard = (LatinKeyboardBaseView)container.findViewById(R.id.LatinKeyboardBaseView);
if (mWindowOffset == null) { if (mWindowOffset == null) {
mWindowOffset = new int[2]; mWindowOffset = new int[2];
getLocationInWindow(mWindowOffset); getLocationInWindow(mWindowOffset);
@ -1055,16 +1068,14 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
// Inject down event on the key to mini keyboard. // Inject down event on the key to mini keyboard.
long eventTime = System.currentTimeMillis(); long eventTime = System.currentTimeMillis();
mMiniKeyboardPopupTime = eventTime; mMiniKeyboardPopupTime = eventTime;
MotionEvent downEvent = generateMiniKeyboardMotionEvent(MotionEvent.ACTION_DOWN, MotionEvent downEvent = generateMiniKeyboardMotionEvent(MotionEvent.ACTION_DOWN, popupKey.x
popupKey.x + popupKey.width / 2, popupKey.y + popupKey.height / 2, eventTime); + popupKey.width / 2, popupKey.y + popupKey.height / 2, eventTime);
mMiniKeyboard.onTouchEvent(downEvent); mMiniKeyboard.onTouchEvent(downEvent);
downEvent.recycle(); downEvent.recycle();
invalidateAllKeys(); invalidateAllKeys();
return true; return true;
} }
return false;
}
private MotionEvent generateMiniKeyboardMotionEvent(int action, int x, int y, long eventTime) { private MotionEvent generateMiniKeyboardMotionEvent(int action, int x, int y, long eventTime) {
return MotionEvent.obtain(mMiniKeyboardPopupTime, eventTime, action, return MotionEvent.obtain(mMiniKeyboardPopupTime, eventTime, action,