Fields Summary |
---|
private int | mSkbXmlIdThe XML resource id for this soft keyboard. |
private boolean | mCacheFlagDo we need to cache this soft keyboard? |
private boolean | mStickyFlagAfter user switches to this soft keyboard, if this flag is true, this
soft keyboard will be kept unless explicit switching operation is
performed, otherwise IME will switch back to the previous keyboard layout
whenever user clicks on any none-function key. |
private int | mCacheIdThe cache id for this soft keyboard. It is used to identify it in the
soft keyboard pool. |
private boolean | mNewlyLoadedFlagUsed to indicate whether this soft keyboard is newly loaded from an XML
file or is just gotten from the soft keyboard pool. |
private int | mSkbCoreWidthThe width of the soft keyboard. |
private int | mSkbCoreHeightThe height of the soft keyboard. |
private SkbTemplate | mSkbTemplateThe soft keyboard template for this soft keyboard. |
private boolean | mIsQwertyUsed to indicate whether this soft keyboard is a QWERTY keyboard. |
private boolean | mIsQwertyUpperCaseWhen {@link #mIsQwerty} is true, this member is Used to indicate that the
soft keyboard should be displayed in uppercase. |
private int | mEnabledRowIdThe id of the rows which are enabled. Rows with id
{@link KeyRow#ALWAYS_SHOW_ROW_ID} are always enabled. |
private List | mKeyRowsRows in this soft keyboard. Each row has a id. Only matched rows will be
enabled. |
public android.graphics.drawable.Drawable | mSkbBgBackground of the soft keyboard. If it is null, the one in the soft
keyboard template will be used. |
private android.graphics.drawable.Drawable | mBalloonBgBackground for key balloon. If it is null, the one in the soft keyboard
template will be used. |
private android.graphics.drawable.Drawable | mPopupBgBackground for popup mini soft keyboard. If it is null, the one in the
soft keyboard template will be used. |
private float | mKeyXMarginThe left and right margin of a key. |
private float | mKeyYMarginThe top and bottom margin of a key. |
private android.graphics.Rect | mTmpRect |
Methods Summary |
---|
public boolean | addSoftKey(SoftKey softKey)
if (mKeyRows.size() == 0) return false;
KeyRow keyRow = mKeyRows.get(mKeyRows.size() - 1);
if (null == keyRow) return false;
List<SoftKey> softKeys = keyRow.mSoftKeys;
softKey.setSkbCoreSize(mSkbCoreWidth, mSkbCoreHeight);
softKeys.add(softKey);
if (softKey.mTopF < keyRow.mTopF) {
keyRow.mTopF = softKey.mTopF;
}
if (softKey.mBottomF > keyRow.mBottomF) {
keyRow.mBottomF = softKey.mBottomF;
}
return true;
|
public void | beginNewRow(int rowId, float yStartingPos)
if (null == mKeyRows) mKeyRows = new ArrayList<KeyRow>();
KeyRow keyRow = new KeyRow();
keyRow.mRowId = rowId;
keyRow.mTopF = yStartingPos;
keyRow.mBottomF = yStartingPos;
keyRow.mSoftKeys = new ArrayList<SoftKey>();
mKeyRows.add(keyRow);
|
public void | disableToggleState(int toggleStateId, boolean resetIfNotFound)
int rowNum = mKeyRows.size();
for (int row = 0; row < rowNum; row++) {
KeyRow keyRow = mKeyRows.get(row);
List<SoftKey> softKeys = keyRow.mSoftKeys;
int keyNum = softKeys.size();
for (int i = 0; i < keyNum; i++) {
SoftKey sKey = softKeys.get(i);
if (sKey instanceof SoftKeyToggle) {
((SoftKeyToggle) sKey).disableToggleState(toggleStateId,
resetIfNotFound);
}
}
}
|
private boolean | enableRow(int rowId)Enable a row with the give toggle Id. Rows with other toggle ids (except
the id {@link KeyRow#ALWAYS_SHOW_ROW_ID}) will be disabled.
if (KeyRow.ALWAYS_SHOW_ROW_ID == rowId) return false;
boolean enabled = false;
int rowNum = mKeyRows.size();
for (int row = rowNum - 1; row >= 0; row--) {
if (mKeyRows.get(row).mRowId == rowId) {
enabled = true;
break;
}
}
if (enabled) {
mEnabledRowId = rowId;
}
return enabled;
|
public void | enableToggleState(int toggleStateId, boolean resetIfNotFound)
int rowNum = mKeyRows.size();
for (int row = 0; row < rowNum; row++) {
KeyRow keyRow = mKeyRows.get(row);
List<SoftKey> softKeys = keyRow.mSoftKeys;
int keyNum = softKeys.size();
for (int i = 0; i < keyNum; i++) {
SoftKey sKey = softKeys.get(i);
if (sKey instanceof SoftKeyToggle) {
((SoftKeyToggle) sKey).enableToggleState(toggleStateId,
resetIfNotFound);
}
}
}
|
public void | enableToggleStates(com.android.inputmethod.pinyin.InputModeSwitcher.ToggleStates toggleStates)
if (null == toggleStates) return;
enableRow(toggleStates.mRowIdToEnable);
boolean isQwerty = toggleStates.mQwerty;
boolean isQwertyUpperCase = toggleStates.mQwertyUpperCase;
boolean needUpdateQwerty = (isQwerty && mIsQwerty && (mIsQwertyUpperCase != isQwertyUpperCase));
int states[] = toggleStates.mKeyStates;
int statesNum = toggleStates.mKeyStatesNum;
int rowNum = mKeyRows.size();
for (int row = 0; row < rowNum; row++) {
KeyRow keyRow = mKeyRows.get(row);
if (KeyRow.ALWAYS_SHOW_ROW_ID != keyRow.mRowId
&& keyRow.mRowId != mEnabledRowId) {
continue;
}
List<SoftKey> softKeys = keyRow.mSoftKeys;
int keyNum = softKeys.size();
for (int keyPos = 0; keyPos < keyNum; keyPos++) {
SoftKey sKey = softKeys.get(keyPos);
if (sKey instanceof SoftKeyToggle) {
for (int statePos = 0; statePos < statesNum; statePos++) {
((SoftKeyToggle) sKey).enableToggleState(
states[statePos], statePos == 0);
}
if (0 == statesNum) {
((SoftKeyToggle) sKey).disableAllToggleStates();
}
}
if (needUpdateQwerty) {
if (sKey.mKeyCode >= KeyEvent.KEYCODE_A
&& sKey.mKeyCode <= KeyEvent.KEYCODE_Z) {
sKey.changeCase(isQwertyUpperCase);
}
}
}
}
mIsQwertyUpperCase = isQwertyUpperCase;
|
public android.graphics.drawable.Drawable | getBalloonBackground()
if (null != mBalloonBg) return mBalloonBg;
return mSkbTemplate.getBalloonBackground();
|
public boolean | getCacheFlag()
return mCacheFlag;
|
public int | getCacheId()
return mCacheId;
|
public SoftKey | getKey(int row, int location)
if (null != mKeyRows && mKeyRows.size() > row) {
List<SoftKey> softKeys = mKeyRows.get(row).mSoftKeys;
if (softKeys.size() > location) {
return softKeys.get(location);
}
}
return null;
|
public com.android.inputmethod.pinyin.SoftKeyboard$KeyRow | getKeyRowForDisplay(int row)
if (null != mKeyRows && mKeyRows.size() > row) {
KeyRow keyRow = mKeyRows.get(row);
if (KeyRow.ALWAYS_SHOW_ROW_ID == keyRow.mRowId
|| keyRow.mRowId == mEnabledRowId) {
return keyRow;
}
}
return null;
|
public int | getKeyXMargin()
Environment env = Environment.getInstance();
return (int) (mKeyXMargin * mSkbCoreWidth * env.getKeyXMarginFactor());
|
public int | getKeyYMargin()
Environment env = Environment.getInstance();
return (int) (mKeyYMargin * mSkbCoreHeight * env.getKeyYMarginFactor());
|
public boolean | getNewlyLoadedFlag()
return mNewlyLoadedFlag;
|
private android.graphics.Rect | getPadding()
mTmpRect.set(0, 0, 0, 0);
Drawable skbBg = getSkbBackground();
if (null == skbBg) return mTmpRect;
skbBg.getPadding(mTmpRect);
return mTmpRect;
|
public android.graphics.drawable.Drawable | getPopupBackground()
if (null != mPopupBg) return mPopupBg;
return mSkbTemplate.getPopupBackground();
|
public int | getRowNum()
if (null != mKeyRows) {
return mKeyRows.size();
}
return 0;
|
public android.graphics.drawable.Drawable | getSkbBackground()
if (null != mSkbBg) return mSkbBg;
return mSkbTemplate.getSkbBackground();
|
public int | getSkbCoreHeight()
return mSkbCoreHeight;
|
public int | getSkbCoreWidth()
return mSkbCoreWidth;
|
public int | getSkbTotalHeight()
Rect padding = getPadding();
return mSkbCoreHeight + padding.top + padding.bottom;
|
public int | getSkbTotalWidth()
Rect padding = getPadding();
return mSkbCoreWidth + padding.left + padding.right;
|
public int | getSkbXmlId()
return mSkbXmlId;
|
public boolean | getStickyFlag()
return mStickyFlag;
|
public SoftKey | mapToKey(int x, int y)
if (null == mKeyRows) {
return null;
}
// If the position is inside the rectangle of a certain key, return that
// key.
int rowNum = mKeyRows.size();
for (int row = 0; row < rowNum; row++) {
KeyRow keyRow = mKeyRows.get(row);
if (KeyRow.ALWAYS_SHOW_ROW_ID != keyRow.mRowId
&& keyRow.mRowId != mEnabledRowId) continue;
if (keyRow.mTop > y && keyRow.mBottom <= y) continue;
List<SoftKey> softKeys = keyRow.mSoftKeys;
int keyNum = softKeys.size();
for (int i = 0; i < keyNum; i++) {
SoftKey sKey = softKeys.get(i);
if (sKey.mLeft <= x && sKey.mTop <= y && sKey.mRight > x
&& sKey.mBottom > y) {
return sKey;
}
}
}
// If the position is outside the rectangles of all keys, find the
// nearest one.
SoftKey nearestKey = null;
float nearestDis = Float.MAX_VALUE;
for (int row = 0; row < rowNum; row++) {
KeyRow keyRow = mKeyRows.get(row);
if (KeyRow.ALWAYS_SHOW_ROW_ID != keyRow.mRowId
&& keyRow.mRowId != mEnabledRowId) continue;
if (keyRow.mTop > y && keyRow.mBottom <= y) continue;
List<SoftKey> softKeys = keyRow.mSoftKeys;
int keyNum = softKeys.size();
for (int i = 0; i < keyNum; i++) {
SoftKey sKey = softKeys.get(i);
int disx = (sKey.mLeft + sKey.mRight) / 2 - x;
int disy = (sKey.mTop + sKey.mBottom) / 2 - y;
float dis = disx * disx + disy * disy;
if (dis < nearestDis) {
nearestDis = dis;
nearestKey = sKey;
}
}
}
return nearestKey;
|
public void | reset()
if (null != mKeyRows) mKeyRows.clear();
|
public void | setCacheId(int cacheId)
mCacheId = cacheId;
|
public void | setFlags(boolean cacheFlag, boolean stickyFlag, boolean isQwerty, boolean isQwertyUpperCase)
mCacheFlag = cacheFlag;
mStickyFlag = stickyFlag;
mIsQwerty = isQwerty;
mIsQwertyUpperCase = isQwertyUpperCase;
|
public void | setKeyBalloonBackground(android.graphics.drawable.Drawable balloonBg)
mBalloonBg = balloonBg;
|
public void | setKeyMargins(float xMargin, float yMargin)
mKeyXMargin = xMargin;
mKeyYMargin = yMargin;
|
public void | setNewlyLoadedFlag(boolean newlyLoadedFlag)
mNewlyLoadedFlag = newlyLoadedFlag;
|
public void | setPopupBackground(android.graphics.drawable.Drawable popupBg)
mPopupBg = popupBg;
|
public void | setSkbBackground(android.graphics.drawable.Drawable skbBg)
mSkbBg = skbBg;
|
public void | setSkbCoreSize(int skbCoreWidth, int skbCoreHeight)
if (null == mKeyRows
|| (skbCoreWidth == mSkbCoreWidth && skbCoreHeight == mSkbCoreHeight)) {
return;
}
for (int row = 0; row < mKeyRows.size(); row++) {
KeyRow keyRow = mKeyRows.get(row);
keyRow.mBottom = (int) (skbCoreHeight * keyRow.mBottomF);
keyRow.mTop = (int) (skbCoreHeight * keyRow.mTopF);
List<SoftKey> softKeys = keyRow.mSoftKeys;
for (int i = 0; i < softKeys.size(); i++) {
SoftKey softKey = softKeys.get(i);
softKey.setSkbCoreSize(skbCoreWidth, skbCoreHeight);
}
}
mSkbCoreWidth = skbCoreWidth;
mSkbCoreHeight = skbCoreHeight;
|
public void | switchQwertyMode(int toggle_state_id, boolean upperCase)
if (!mIsQwerty) return;
int rowNum = mKeyRows.size();
for (int row = 0; row < rowNum; row++) {
KeyRow keyRow = mKeyRows.get(row);
List<SoftKey> softKeys = keyRow.mSoftKeys;
int keyNum = softKeys.size();
for (int i = 0; i < keyNum; i++) {
SoftKey sKey = softKeys.get(i);
if (sKey instanceof SoftKeyToggle) {
((SoftKeyToggle) sKey).enableToggleState(toggle_state_id,
true);
}
if (sKey.mKeyCode >= KeyEvent.KEYCODE_A
&& sKey.mKeyCode <= KeyEvent.KEYCODE_Z) {
sKey.changeCase(upperCase);
}
}
}
|
public java.lang.String | toShortString()
return super.toString();
|
public java.lang.String | toString()
String str = "------------------SkbInfo----------------------\n";
String endStr = "-----------------------------------------------\n";
str += "Width: " + String.valueOf(mSkbCoreWidth) + "\n";
str += "Height: " + String.valueOf(mSkbCoreHeight) + "\n";
str += "KeyRowNum: " + mKeyRows == null ? "0" : String.valueOf(mKeyRows
.size())
+ "\n";
if (null == mKeyRows) return str + endStr;
int rowNum = mKeyRows.size();
for (int row = 0; row < rowNum; row++) {
KeyRow keyRow = mKeyRows.get(row);
List<SoftKey> softKeys = keyRow.mSoftKeys;
int keyNum = softKeys.size();
for (int i = 0; i < softKeys.size(); i++) {
str += "-key " + String.valueOf(i) + ":"
+ softKeys.get(i).toString();
}
}
return str + endStr;
|