当前位置: 首页>>代码示例>>Java>>正文


Java Key.squaredDistanceFrom方法代码示例

本文整理汇总了Java中android.inputmethodservice.Keyboard.Key.squaredDistanceFrom方法的典型用法代码示例。如果您正苦于以下问题:Java Key.squaredDistanceFrom方法的具体用法?Java Key.squaredDistanceFrom怎么用?Java Key.squaredDistanceFrom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.inputmethodservice.Keyboard.Key的用法示例。


在下文中一共展示了Key.squaredDistanceFrom方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getKeyIndexAndNearbyCodes

import android.inputmethodservice.Keyboard.Key; //导入方法依赖的package包/类
@Override
public int getKeyIndexAndNearbyCodes(int x, int y, int[] allKeys) {
    final Key[] keys = getKeys();
    final int touchX = getTouchX(x);
    final int touchY = getTouchY(y);
    int closestKeyIndex = LatinKeyboardBaseView.NOT_A_KEY;
    int closestKeyDist = (y < 0) ? mSlideAllowanceSquareTop : mSlideAllowanceSquare;
    final int keyCount = keys.length;
    for (int i = 0; i < keyCount; i++) {
        final Key key = keys[i];
        int dist = key.squaredDistanceFrom(touchX, touchY);
        if (dist < closestKeyDist) {
            closestKeyIndex = i;
            closestKeyDist = dist;
        }
    }
    if (allKeys != null && closestKeyIndex != LatinKeyboardBaseView.NOT_A_KEY)
        allKeys[0] = keys[closestKeyIndex].codes[0];
    return closestKeyIndex;
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:21,代码来源:MiniKeyboardKeyDetector.java

示例2: getKeyIndexAndNearbyCodes

import android.inputmethodservice.Keyboard.Key; //导入方法依赖的package包/类
@Override
public int getKeyIndexAndNearbyCodes(int x, int y, int[] allKeys) {
    final Key[] keys = getKeys();
    final int touchX = getTouchX(x);
    final int touchY = getTouchY(y);
    int primaryIndex = LatinKeyboardBaseView.NOT_A_KEY;
    int closestKey = LatinKeyboardBaseView.NOT_A_KEY;
    int closestKeyDist = mProximityThresholdSquare + 1;
    int[] distances = mDistances;
    Arrays.fill(distances, Integer.MAX_VALUE);
    int [] nearestKeyIndices = mKeyboard.getNearestKeys(touchX, touchY);
    final int keyCount = nearestKeyIndices.length;
    for (int i = 0; i < keyCount; i++) {
        final Key key = keys[nearestKeyIndices[i]];
        int dist = 0;
        boolean isInside = key.isInside(touchX, touchY);
        if (isInside) {
            primaryIndex = nearestKeyIndices[i];
        }

        if (((mProximityCorrectOn
                && (dist = key.squaredDistanceFrom(touchX, touchY)) < mProximityThresholdSquare)
                || isInside)
                && key.codes[0] > 32) {
            // Find insertion point
            final int nCodes = key.codes.length;
            if (dist < closestKeyDist) {
                closestKeyDist = dist;
                closestKey = nearestKeyIndices[i];
            }

            if (allKeys == null) continue;

            for (int j = 0; j < distances.length; j++) {
                if (distances[j] > dist) {
                    // Make space for nCodes codes
                    System.arraycopy(distances, j, distances, j + nCodes,
                            distances.length - j - nCodes);
                    System.arraycopy(allKeys, j, allKeys, j + nCodes,
                            allKeys.length - j - nCodes);
                    System.arraycopy(key.codes, 0, allKeys, j, nCodes);
                    Arrays.fill(distances, j, j + nCodes, dist);
                    break;
                }
            }
        }
    }
    if (primaryIndex == LatinKeyboardBaseView.NOT_A_KEY) {
        primaryIndex = closestKey;
    }
    return primaryIndex;
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:53,代码来源:ProximityKeyDetector.java

示例3: getKeyIndices

import android.inputmethodservice.Keyboard.Key; //导入方法依赖的package包/类
private int getKeyIndices(int x, int y, int[] allKeys) {
    final Key[] keys = mKeys;
    int primaryIndex = NOT_A_KEY;
    int closestKey = NOT_A_KEY;
    int closestKeyDist = mProximityThreshold + 1;
    java.util.Arrays.fill(mDistances, Integer.MAX_VALUE);
    int[] nearestKeyIndices = mKeyboard.getNearestKeys(x, y);
    final int keyCount = nearestKeyIndices.length;
    for (int i = 0; i < keyCount; i++) {
        final Key key = keys[nearestKeyIndices[i]];
        int dist = 0;
        boolean isInside = key.isInside(x, y);
        if (isInside) {
            primaryIndex = nearestKeyIndices[i];
        }

        if (((mProximityCorrectOn
                && (dist = key.squaredDistanceFrom(x, y)) < mProximityThreshold)
                || isInside)
                && key.codes[0] > 32) {
            // Find insertion point
            final int nCodes = key.codes.length;
            if (dist < closestKeyDist) {
                closestKeyDist = dist;
                closestKey = nearestKeyIndices[i];
            }

            if (allKeys == null) continue;

            for (int j = 0; j < mDistances.length; j++) {
                if (mDistances[j] > dist) {
                    // Make space for nCodes codes
                    System.arraycopy(mDistances, j, mDistances, j + nCodes,
                            mDistances.length - j - nCodes);
                    System.arraycopy(allKeys, j, allKeys, j + nCodes,
                            allKeys.length - j - nCodes);
                    for (int c = 0; c < nCodes; c++) {
                        allKeys[j + c] = key.codes[c];
                        mDistances[j + c] = dist;
                    }
                    break;
                }
            }
        }
    }
    if (primaryIndex == NOT_A_KEY) {
        primaryIndex = closestKey;
    }
    return primaryIndex;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:51,代码来源:MyKeyboardView.java

示例4: getKeyIndices

import android.inputmethodservice.Keyboard.Key; //导入方法依赖的package包/类
private int getKeyIndices(int x, int y, int[] allKeys) {
    final Key[] keys = mKeys;
    int primaryIndex = NOT_A_KEY;
    int closestKey = NOT_A_KEY;
    int closestKeyDist = mProximityThreshold + 1;
    java.util.Arrays.fill(mDistances, Integer.MAX_VALUE);
    int [] nearestKeyIndices = mKeyboard.getNearestKeys(x, y);
    final int keyCount = nearestKeyIndices.length;
    for (int i = 0; i < keyCount; i++) {
        final Key key = keys[nearestKeyIndices[i]];
        int dist = 0;
        boolean isInside = key.isInside(x,y);
        if (isInside) {
            primaryIndex = nearestKeyIndices[i];
        }

        if (((mProximityCorrectOn 
                && (dist = key.squaredDistanceFrom(x, y)) < mProximityThreshold) 
                || isInside)
                && key.codes[0] > 32) {
            // Find insertion point
            final int nCodes = key.codes.length;
            if (dist < closestKeyDist) {
                closestKeyDist = dist;
                closestKey = nearestKeyIndices[i];
            }
            
            if (allKeys == null) continue;
            
            for (int j = 0; j < mDistances.length; j++) {
                if (mDistances[j] > dist) {
                    // Make space for nCodes codes
                    System.arraycopy(mDistances, j, mDistances, j + nCodes,
                            mDistances.length - j - nCodes);
                    System.arraycopy(allKeys, j, allKeys, j + nCodes,
                            allKeys.length - j - nCodes);
                    for (int c = 0; c < nCodes; c++) {
                        allKeys[j + c] = key.codes[c];
                        mDistances[j + c] = dist;
                    }
                    break;
                }
            }
        }
    }
    if (primaryIndex == NOT_A_KEY) {
        primaryIndex = closestKey;
    }
    return primaryIndex;
}
 
开发者ID:michaelbarlow7,项目名称:dungeon-crawl-android,代码行数:51,代码来源:CrawlKeyboardView.java

示例5: getKeyIndices

import android.inputmethodservice.Keyboard.Key; //导入方法依赖的package包/类
private int getKeyIndices(int x, int y, int[] allKeys) {
    final Key[] keys = mKeys;
    int primaryIndex = NOT_A_KEY;
    int closestKey = NOT_A_KEY;
    int closestKeyDist = mProximityThreshold + 1;
    java.util.Arrays.fill(mDistances, Integer.MAX_VALUE);
    int [] nearestKeyIndices = mKeyboard.getNearestKeys(x, y);
    final int keyCount = nearestKeyIndices.length;
    for (int i = 0; i < keyCount; i++) {
        final Key key = keys[nearestKeyIndices[i]];
        int dist = 0;
        boolean isInside = key.isInside(x,y);
        if (isInside) {
            primaryIndex = nearestKeyIndices[i];
        }

        if (((mProximityCorrectOn
                && (dist = key.squaredDistanceFrom(x, y)) < mProximityThreshold)
                || isInside)
                && key.codes[0] > 32) {
            // Find insertion point
            final int nCodes = key.codes.length;
            if (dist < closestKeyDist) {
                closestKeyDist = dist;
                closestKey = nearestKeyIndices[i];
            }

            if (allKeys == null) continue;

            for (int j = 0; j < mDistances.length; j++) {
                if (mDistances[j] > dist) {
                    // Make space for nCodes codes
                    System.arraycopy(mDistances, j, mDistances, j + nCodes,
                            mDistances.length - j - nCodes);
                    System.arraycopy(allKeys, j, allKeys, j + nCodes,
                            allKeys.length - j - nCodes);
                    for (int c = 0; c < nCodes; c++) {
                        allKeys[j + c] = key.codes[c];
                        mDistances[j + c] = dist;
                    }
                    break;
                }
            }
        }
    }
    if (primaryIndex == NOT_A_KEY) {
        primaryIndex = closestKey;
    }
    return primaryIndex;
}
 
开发者ID:dyne,项目名称:ZShaolin,代码行数:51,代码来源:MyKeyboardView.java


注:本文中的android.inputmethodservice.Keyboard.Key.squaredDistanceFrom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。