am 2085d43d: Make abstract KeyDetector class
Merge commit '2085d43daf44752deae1b6b00a14cb0f517d69cb' into gingerbread-plus-aosp * commit '2085d43daf44752deae1b6b00a14cb0f517d69cb': Make abstract KeyDetector classmain
commit
57a41d09b6
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2010 Google Inc.
|
||||||
|
*
|
||||||
|
* 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.latin;
|
||||||
|
|
||||||
|
import android.inputmethodservice.Keyboard;
|
||||||
|
import android.inputmethodservice.Keyboard.Key;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
abstract class KeyDetector {
|
||||||
|
protected Keyboard mKeyboard;
|
||||||
|
protected Key[] mKeys;
|
||||||
|
|
||||||
|
protected boolean mProximityCorrectOn;
|
||||||
|
protected int mProximityThresholdSquare;
|
||||||
|
|
||||||
|
public Key[] setKeyboard(Keyboard keyboard) {
|
||||||
|
if (keyboard == null)
|
||||||
|
throw new NullPointerException();
|
||||||
|
mKeyboard = keyboard;
|
||||||
|
List<Key> keys = mKeyboard.getKeys();
|
||||||
|
Key[] array = keys.toArray(new Key[keys.size()]);
|
||||||
|
mKeys = array;
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProximityCorrectionEnabled(boolean enabled) {
|
||||||
|
mProximityCorrectOn = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isProximityCorrectionEnabled() {
|
||||||
|
return mProximityCorrectOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProximityThreshold(int threshold) {
|
||||||
|
mProximityThresholdSquare = threshold * threshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public int[] newCodeArray();
|
||||||
|
|
||||||
|
abstract public int getKeyIndexAndNearbyCodes(int x, int y, int[] allKeys);
|
||||||
|
}
|
|
@ -45,7 +45,6 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -202,7 +201,7 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
|
||||||
private final ArrayList<PointerTracker> mPointerTrackers = new ArrayList<PointerTracker>();
|
private final ArrayList<PointerTracker> mPointerTrackers = new ArrayList<PointerTracker>();
|
||||||
private final float mDebounceHysteresis;
|
private final float mDebounceHysteresis;
|
||||||
|
|
||||||
private final ProximityKeyDetector mProximityKeyDetector = new ProximityKeyDetector();
|
protected KeyDetector mKeyDetector = new ProximityKeyDetector();
|
||||||
|
|
||||||
// Swipe gesture detector
|
// Swipe gesture detector
|
||||||
private final GestureDetector mGestureDetector;
|
private final GestureDetector mGestureDetector;
|
||||||
|
@ -473,8 +472,7 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
|
||||||
public void setOnKeyboardActionListener(OnKeyboardActionListener listener) {
|
public void setOnKeyboardActionListener(OnKeyboardActionListener listener) {
|
||||||
mKeyboardActionListener = listener;
|
mKeyboardActionListener = listener;
|
||||||
for (PointerTracker tracker : mPointerTrackers) {
|
for (PointerTracker tracker : mPointerTrackers) {
|
||||||
if (tracker != null)
|
tracker.setOnKeyboardActionListener(listener);
|
||||||
tracker.setOnKeyboardActionListener(listener);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -501,13 +499,10 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
|
||||||
mHandler.cancelKeyTimers();
|
mHandler.cancelKeyTimers();
|
||||||
mHandler.cancelPopupPreview();
|
mHandler.cancelPopupPreview();
|
||||||
mKeyboard = keyboard;
|
mKeyboard = keyboard;
|
||||||
LatinImeLogger.onSetKeyboard(mKeyboard);
|
LatinImeLogger.onSetKeyboard(keyboard);
|
||||||
List<Key> keys = mKeyboard.getKeys();
|
mKeys = mKeyDetector.setKeyboard(keyboard);
|
||||||
mKeys = keys.toArray(new Key[keys.size()]);
|
|
||||||
mProximityKeyDetector.setKeyboard(keyboard, mKeys);
|
|
||||||
for (PointerTracker tracker : mPointerTrackers) {
|
for (PointerTracker tracker : mPointerTrackers) {
|
||||||
if (tracker != null)
|
tracker.setKeyboard(mKeys, mDebounceHysteresis);
|
||||||
tracker.setKeyboard(mKeys, mDebounceHysteresis);
|
|
||||||
}
|
}
|
||||||
requestLayout();
|
requestLayout();
|
||||||
// Hint to reallocate the buffer if the size changed
|
// Hint to reallocate the buffer if the size changed
|
||||||
|
@ -599,14 +594,14 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
|
||||||
* @param enabled whether or not the proximity correction is enabled
|
* @param enabled whether or not the proximity correction is enabled
|
||||||
*/
|
*/
|
||||||
public void setProximityCorrectionEnabled(boolean enabled) {
|
public void setProximityCorrectionEnabled(boolean enabled) {
|
||||||
mProximityKeyDetector.setProximityCorrectionEnabled(enabled);
|
mKeyDetector.setProximityCorrectionEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if proximity correction is enabled.
|
* Returns true if proximity correction is enabled.
|
||||||
*/
|
*/
|
||||||
public boolean isProximityCorrectionEnabled() {
|
public boolean isProximityCorrectionEnabled() {
|
||||||
return mProximityKeyDetector.isProximityCorrectionEnabled();
|
return mKeyDetector.isProximityCorrectionEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -658,7 +653,7 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
|
||||||
dimensionSum += Math.min(key.width, key.height) + key.gap;
|
dimensionSum += Math.min(key.width, key.height) + key.gap;
|
||||||
}
|
}
|
||||||
if (dimensionSum < 0 || length == 0) return;
|
if (dimensionSum < 0 || length == 0) return;
|
||||||
mProximityKeyDetector.setProximityThreshold((int) (dimensionSum * 1.4f / length));
|
mKeyDetector.setProximityThreshold((int) (dimensionSum * 1.4f / length));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1052,7 +1047,7 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
|
||||||
// Create pointer trackers until we can get 'id+1'-th tracker, if needed.
|
// Create pointer trackers until we can get 'id+1'-th tracker, if needed.
|
||||||
for (int i = pointers.size(); i <= id; i++) {
|
for (int i = pointers.size(); i <= id; i++) {
|
||||||
final PointerTracker tracker =
|
final PointerTracker tracker =
|
||||||
new PointerTracker(mHandler, mProximityKeyDetector, this);
|
new PointerTracker(mHandler, mKeyDetector, this);
|
||||||
if (keys != null)
|
if (keys != null)
|
||||||
tracker.setKeyboard(keys, mDebounceHysteresis);
|
tracker.setKeyboard(keys, mDebounceHysteresis);
|
||||||
if (listener != null)
|
if (listener != null)
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class PointerTracker {
|
||||||
|
|
||||||
private final UIProxy mProxy;
|
private final UIProxy mProxy;
|
||||||
private final UIHandler mHandler;
|
private final UIHandler mHandler;
|
||||||
private final ProximityKeyDetector mKeyDetector;
|
private final KeyDetector mKeyDetector;
|
||||||
private OnKeyboardActionListener mListener;
|
private OnKeyboardActionListener mListener;
|
||||||
|
|
||||||
private Key[] mKeys;
|
private Key[] mKeys;
|
||||||
|
@ -77,7 +77,7 @@ public class PointerTracker {
|
||||||
// pressed key
|
// pressed key
|
||||||
private int mPreviousKey = NOT_A_KEY;
|
private int mPreviousKey = NOT_A_KEY;
|
||||||
|
|
||||||
public PointerTracker(UIHandler handler, ProximityKeyDetector keyDetector, UIProxy proxy) {
|
public PointerTracker(UIHandler handler, KeyDetector keyDetector, UIProxy proxy) {
|
||||||
if (proxy == null || handler == null || keyDetector == null)
|
if (proxy == null || handler == null || keyDetector == null)
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
mProxy = proxy;
|
mProxy = proxy;
|
||||||
|
|
|
@ -16,48 +16,24 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin;
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
import android.inputmethodservice.Keyboard;
|
|
||||||
import android.inputmethodservice.Keyboard.Key;
|
import android.inputmethodservice.Keyboard.Key;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
class ProximityKeyDetector {
|
class ProximityKeyDetector extends KeyDetector {
|
||||||
private static final int MAX_NEARBY_KEYS = 12;
|
private static final int MAX_NEARBY_KEYS = 12;
|
||||||
|
|
||||||
private Keyboard mKeyboard;
|
|
||||||
private Key[] mKeys;
|
|
||||||
|
|
||||||
private boolean mProximityCorrectOn;
|
|
||||||
private int mProximityThresholdSquare;
|
|
||||||
|
|
||||||
// working area
|
// working area
|
||||||
private int[] mDistances = new int[MAX_NEARBY_KEYS];
|
private int[] mDistances = new int[MAX_NEARBY_KEYS];
|
||||||
|
|
||||||
public void setKeyboard(Keyboard keyboard, Key[] keys) {
|
@Override
|
||||||
if (keyboard == null || keys == null)
|
|
||||||
throw new NullPointerException();
|
|
||||||
mKeyboard = keyboard;
|
|
||||||
mKeys = keys;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProximityCorrectionEnabled(boolean enabled) {
|
|
||||||
mProximityCorrectOn = enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isProximityCorrectionEnabled() {
|
|
||||||
return mProximityCorrectOn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProximityThreshold(int threshold) {
|
|
||||||
mProximityThresholdSquare = threshold * threshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int[] newCodeArray() {
|
public int[] newCodeArray() {
|
||||||
int[] codes = new int[MAX_NEARBY_KEYS];
|
int[] codes = new int[MAX_NEARBY_KEYS];
|
||||||
Arrays.fill(codes, LatinKeyboardBaseView.NOT_A_KEY);
|
Arrays.fill(codes, LatinKeyboardBaseView.NOT_A_KEY);
|
||||||
return codes;
|
return codes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getKeyIndexAndNearbyCodes(int x, int y, int[] allKeys) {
|
public int getKeyIndexAndNearbyCodes(int x, int y, int[] allKeys) {
|
||||||
final Key[] keys = mKeys;
|
final Key[] keys = mKeys;
|
||||||
if (keys == null)
|
if (keys == null)
|
||||||
|
|
Loading…
Reference in New Issue