Move some methods from LatinKeyboardView up into LatinKeyboardBaseView
Bug: 5182291 Change-Id: I699ecef6fb8ea492d96fca1939f51faf0aac7fa6main
parent
b041412cd7
commit
6dde878d51
|
@ -141,7 +141,7 @@ public class LatinKeyboard extends Keyboard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboardView view) {
|
public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboardBaseView view) {
|
||||||
mSpacebarTextFadeFactor = fadeFactor;
|
mSpacebarTextFadeFactor = fadeFactor;
|
||||||
updateSpacebarForLocale(false);
|
updateSpacebarForLocale(false);
|
||||||
if (view != null)
|
if (view != null)
|
||||||
|
|
|
@ -20,6 +20,7 @@ import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.Canvas;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
@ -34,11 +35,14 @@ import android.widget.PopupWindow;
|
||||||
|
|
||||||
import com.android.inputmethod.accessibility.AccessibilityUtils;
|
import com.android.inputmethod.accessibility.AccessibilityUtils;
|
||||||
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
|
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
|
||||||
|
import com.android.inputmethod.deprecated.VoiceProxy;
|
||||||
import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
|
import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
|
||||||
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
|
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
|
||||||
import com.android.inputmethod.keyboard.internal.MiniKeyboardBuilder;
|
import com.android.inputmethod.keyboard.internal.MiniKeyboardBuilder;
|
||||||
|
import com.android.inputmethod.latin.LatinIME;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
|
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
|
||||||
|
import com.android.inputmethod.latin.Utils;
|
||||||
|
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
|
@ -266,6 +270,20 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke
|
||||||
return mKeyTimerHandler;
|
return mKeyTimerHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setKeyPreviewPopupEnabled(boolean previewEnabled, int delay) {
|
||||||
|
final Keyboard keyboard = getKeyboard();
|
||||||
|
if (keyboard instanceof LatinKeyboard) {
|
||||||
|
final LatinKeyboard latinKeyboard = (LatinKeyboard)keyboard;
|
||||||
|
if (latinKeyboard.isPhoneKeyboard() || latinKeyboard.isNumberKeyboard()) {
|
||||||
|
// Phone and number keyboard never shows popup preview.
|
||||||
|
super.setKeyPreviewPopupEnabled(false, delay);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.setKeyPreviewPopupEnabled(previewEnabled, delay);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attaches a keyboard to this view. The keyboard can be switched at any time and the
|
* Attaches a keyboard to this view. The keyboard can be switched at any time and the
|
||||||
* view will re-layout itself to accommodate the keyboard.
|
* view will re-layout itself to accommodate the keyboard.
|
||||||
|
@ -365,6 +383,15 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke
|
||||||
return mPopupPanel != null;
|
return mPopupPanel != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboard oldKeyboard) {
|
||||||
|
final Keyboard keyboard = getKeyboard();
|
||||||
|
// We should not set text fade factor to the keyboard which does not display the language on
|
||||||
|
// its spacebar.
|
||||||
|
if (keyboard instanceof LatinKeyboard && keyboard == oldKeyboard) {
|
||||||
|
((LatinKeyboard)keyboard).setSpacebarTextFadeFactor(fadeFactor, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a key is long pressed. By default this will open mini keyboard associated
|
* Called when a key is long pressed. By default this will open mini keyboard associated
|
||||||
* with this key.
|
* with this key.
|
||||||
|
@ -374,6 +401,42 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke
|
||||||
* method on the base class if the subclass doesn't wish to handle the call.
|
* method on the base class if the subclass doesn't wish to handle the call.
|
||||||
*/
|
*/
|
||||||
protected boolean onLongPress(Key parentKey, PointerTracker tracker) {
|
protected boolean onLongPress(Key parentKey, PointerTracker tracker) {
|
||||||
|
final int primaryCode = parentKey.mCode;
|
||||||
|
final Keyboard keyboard = getKeyboard();
|
||||||
|
if (keyboard instanceof LatinKeyboard) {
|
||||||
|
final LatinKeyboard latinKeyboard = (LatinKeyboard) keyboard;
|
||||||
|
if (primaryCode == Keyboard.CODE_DIGIT0 && latinKeyboard.isPhoneKeyboard()) {
|
||||||
|
tracker.onLongPressed();
|
||||||
|
// Long pressing on 0 in phone number keypad gives you a '+'.
|
||||||
|
return invokeOnKey(Keyboard.CODE_PLUS);
|
||||||
|
}
|
||||||
|
if (primaryCode == Keyboard.CODE_SHIFT && latinKeyboard.isAlphaKeyboard()) {
|
||||||
|
tracker.onLongPressed();
|
||||||
|
return invokeOnKey(Keyboard.CODE_CAPSLOCK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (primaryCode == Keyboard.CODE_SETTINGS || primaryCode == Keyboard.CODE_SPACE) {
|
||||||
|
// Both long pressing settings key and space key invoke IME switcher dialog.
|
||||||
|
if (getKeyboardActionListener().onCustomRequest(
|
||||||
|
LatinIME.CODE_SHOW_INPUT_METHOD_PICKER)) {
|
||||||
|
tracker.onLongPressed();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return openPopupPanel(parentKey, tracker);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return openPopupPanel(parentKey, tracker);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean invokeOnKey(int primaryCode) {
|
||||||
|
getKeyboardActionListener().onCodeInput(primaryCode, null,
|
||||||
|
KeyboardActionListener.NOT_A_TOUCH_COORDINATE,
|
||||||
|
KeyboardActionListener.NOT_A_TOUCH_COORDINATE);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean openPopupPanel(Key parentKey, PointerTracker tracker) {
|
||||||
PopupPanel popupPanel = mPopupPanelCache.get(parentKey);
|
PopupPanel popupPanel = mPopupPanelCache.get(parentKey);
|
||||||
if (popupPanel == null) {
|
if (popupPanel == null) {
|
||||||
popupPanel = onCreatePopupPanel(parentKey);
|
popupPanel = onCreatePopupPanel(parentKey);
|
||||||
|
@ -556,6 +619,26 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke
|
||||||
return dismissPopupPanel();
|
return dismissPopupPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(Canvas c) {
|
||||||
|
Utils.GCUtils.getInstance().reset();
|
||||||
|
boolean tryGC = true;
|
||||||
|
for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) {
|
||||||
|
try {
|
||||||
|
super.draw(c);
|
||||||
|
tryGC = false;
|
||||||
|
} catch (OutOfMemoryError e) {
|
||||||
|
tryGC = Utils.GCUtils.getInstance().tryGCOrWait("LatinKeyboardView", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onAttachedToWindow() {
|
||||||
|
// Token is available from here.
|
||||||
|
VoiceProxy.getInstance().onAttachedToWindow();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchTouchEvent(MotionEvent event) {
|
public boolean dispatchTouchEvent(MotionEvent event) {
|
||||||
// Drop non-hover touch events when touch exploration is enabled.
|
// Drop non-hover touch events when touch exploration is enabled.
|
||||||
|
|
|
@ -22,8 +22,6 @@ import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
import com.android.inputmethod.deprecated.VoiceProxy;
|
|
||||||
import com.android.inputmethod.latin.LatinIME;
|
|
||||||
import com.android.inputmethod.latin.LatinImeLogger;
|
import com.android.inputmethod.latin.LatinImeLogger;
|
||||||
import com.android.inputmethod.latin.Utils;
|
import com.android.inputmethod.latin.Utils;
|
||||||
|
|
||||||
|
@ -52,20 +50,6 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setKeyPreviewPopupEnabled(boolean previewEnabled, int delay) {
|
|
||||||
final Keyboard keyboard = getKeyboard();
|
|
||||||
if (keyboard instanceof LatinKeyboard) {
|
|
||||||
final LatinKeyboard latinKeyboard = (LatinKeyboard)keyboard;
|
|
||||||
if (latinKeyboard.isPhoneKeyboard() || latinKeyboard.isNumberKeyboard()) {
|
|
||||||
// Phone and number keyboard never shows popup preview.
|
|
||||||
super.setKeyPreviewPopupEnabled(false, delay);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
super.setKeyPreviewPopupEnabled(previewEnabled, delay);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setKeyboard(Keyboard newKeyboard) {
|
public void setKeyboard(Keyboard newKeyboard) {
|
||||||
super.setKeyboard(newKeyboard);
|
super.setKeyboard(newKeyboard);
|
||||||
|
@ -74,52 +58,6 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
|
||||||
mJumpThresholdSquare = jumpThreshold * jumpThreshold;
|
mJumpThresholdSquare = jumpThreshold * jumpThreshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboard oldKeyboard) {
|
|
||||||
final Keyboard keyboard = getKeyboard();
|
|
||||||
// We should not set text fade factor to the keyboard which does not display the language on
|
|
||||||
// its spacebar.
|
|
||||||
if (keyboard instanceof LatinKeyboard && keyboard == oldKeyboard) {
|
|
||||||
((LatinKeyboard)keyboard).setSpacebarTextFadeFactor(fadeFactor, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean onLongPress(Key key, PointerTracker tracker) {
|
|
||||||
final int primaryCode = key.mCode;
|
|
||||||
final Keyboard keyboard = getKeyboard();
|
|
||||||
if (keyboard instanceof LatinKeyboard) {
|
|
||||||
final LatinKeyboard latinKeyboard = (LatinKeyboard) keyboard;
|
|
||||||
if (primaryCode == Keyboard.CODE_DIGIT0 && latinKeyboard.isPhoneKeyboard()) {
|
|
||||||
tracker.onLongPressed();
|
|
||||||
// Long pressing on 0 in phone number keypad gives you a '+'.
|
|
||||||
return invokeOnKey(Keyboard.CODE_PLUS);
|
|
||||||
}
|
|
||||||
if (primaryCode == Keyboard.CODE_SHIFT && latinKeyboard.isAlphaKeyboard()) {
|
|
||||||
tracker.onLongPressed();
|
|
||||||
return invokeOnKey(Keyboard.CODE_CAPSLOCK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (primaryCode == Keyboard.CODE_SETTINGS || primaryCode == Keyboard.CODE_SPACE) {
|
|
||||||
// Both long pressing settings key and space key invoke IME switcher dialog.
|
|
||||||
if (getKeyboardActionListener().onCustomRequest(
|
|
||||||
LatinIME.CODE_SHOW_INPUT_METHOD_PICKER)) {
|
|
||||||
tracker.onLongPressed();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return super.onLongPress(key, tracker);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return super.onLongPress(key, tracker);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean invokeOnKey(int primaryCode) {
|
|
||||||
getKeyboardActionListener().onCodeInput(primaryCode, null,
|
|
||||||
KeyboardActionListener.NOT_A_TOUCH_COORDINATE,
|
|
||||||
KeyboardActionListener.NOT_A_TOUCH_COORDINATE);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function checks to see if we need to handle any sudden jumps in the pointer location
|
* This function checks to see if we need to handle any sudden jumps in the pointer location
|
||||||
* that could be due to a multi-touch being treated as a move by the firmware or hardware.
|
* that could be due to a multi-touch being treated as a move by the firmware or hardware.
|
||||||
|
@ -211,24 +149,4 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
|
||||||
|
|
||||||
return super.onTouchEvent(me);
|
return super.onTouchEvent(me);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw(Canvas c) {
|
|
||||||
Utils.GCUtils.getInstance().reset();
|
|
||||||
boolean tryGC = true;
|
|
||||||
for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) {
|
|
||||||
try {
|
|
||||||
super.draw(c);
|
|
||||||
tryGC = false;
|
|
||||||
} catch (OutOfMemoryError e) {
|
|
||||||
tryGC = Utils.GCUtils.getInstance().tryGCOrWait("LatinKeyboardView", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onAttachedToWindow() {
|
|
||||||
// Token is available from here.
|
|
||||||
VoiceProxy.getInstance().onAttachedToWindow();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue