TouchPositionCorrection.java revision 15f6d4ae34664ea3d92827a2c3003198c0bac70b
135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka/* 235ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * Copyright (C) 2012 The Android Open Source Project 335ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * 435ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * Licensed under the Apache License, Version 2.0 (the "License"); you may not 535ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * use this file except in compliance with the License. You may obtain a copy of 635ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * the License at 735ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * 835ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * http://www.apache.org/licenses/LICENSE-2.0 935ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * 1035ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * Unless required by applicable law or agreed to in writing, software 1135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 1235ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 1335ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * License for the specific language governing permissions and limitations under 1435ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka * the License. 1535ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka */ 1635ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka 1735ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaokapackage com.android.inputmethod.keyboard.internal; 1835ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka 1915f6d4ae34664ea3d92827a2c3003198c0bac70bTadashi G. Takaokaimport com.android.inputmethod.annotations.UsedForTesting; 2035ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaokaimport com.android.inputmethod.latin.LatinImeLogger; 2135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka 2217752016713b92a55e9c2356d07b7ed51c67416bTadashi G. Takaokapublic final class TouchPositionCorrection { 2335ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka private static final int TOUCH_POSITION_CORRECTION_RECORD_SIZE = 3; 2435ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka 256ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka private boolean mEnabled; 266ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka private float[] mXs; 276ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka private float[] mYs; 286ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka private float[] mRadii; 2935ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka 3035ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka public void load(final String[] data) { 3135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka final int dataLength = data.length; 3235ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka if (dataLength % TOUCH_POSITION_CORRECTION_RECORD_SIZE != 0) { 3335ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka if (LatinImeLogger.sDBG) { 3435ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka throw new RuntimeException( 3535ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka "the size of touch position correction data is invalid"); 3635ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 3735ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka return; 3835ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 3935ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka 4035ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka final int length = dataLength / TOUCH_POSITION_CORRECTION_RECORD_SIZE; 4135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mXs = new float[length]; 4235ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mYs = new float[length]; 4335ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mRadii = new float[length]; 4435ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka try { 4535ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka for (int i = 0; i < dataLength; ++i) { 4635ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka final int type = i % TOUCH_POSITION_CORRECTION_RECORD_SIZE; 4735ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka final int index = i / TOUCH_POSITION_CORRECTION_RECORD_SIZE; 4835ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka final float value = Float.parseFloat(data[i]); 4935ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka if (type == 0) { 5035ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mXs[index] = value; 5135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } else if (type == 1) { 5235ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mYs[index] = value; 5335ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } else { 5435ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mRadii[index] = value; 5535ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 5635ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 576ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka mEnabled = dataLength > 0; 5835ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } catch (NumberFormatException e) { 5935ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka if (LatinImeLogger.sDBG) { 6035ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka throw new RuntimeException( 6135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka "the number format for touch position correction data is invalid"); 6235ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 636ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka mEnabled = false; 6435ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mXs = null; 6535ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mYs = null; 6635ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mRadii = null; 6735ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 6835ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 6935ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka 7015f6d4ae34664ea3d92827a2c3003198c0bac70bTadashi G. Takaoka @UsedForTesting 7135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka public void setEnabled(final boolean enabled) { 7235ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mEnabled = enabled; 7335ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 7435ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka 7535ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka public boolean isValid() { 766ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka return mEnabled; 776ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka } 786ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka 796ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka public int getRows() { 806ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka return mRadii.length; 816ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka } 826ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka 836ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka public float getX(final int row) { 8417752016713b92a55e9c2356d07b7ed51c67416bTadashi G. Takaoka return 0.0f; 8517752016713b92a55e9c2356d07b7ed51c67416bTadashi G. Takaoka // Touch position correction data for X coordinate is obsolete. 8617752016713b92a55e9c2356d07b7ed51c67416bTadashi G. Takaoka // return mXs[row]; 876ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka } 886ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka 896ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka public float getY(final int row) { 906ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka return mYs[row]; 916ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka } 926ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka 936ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka public float getRadius(final int row) { 946ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka return mRadii[row]; 9535ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 9635ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka} 97