TouchPositionCorrection.java revision 6ca50d99208efdbcad96b3260fe7592bf95a6b00
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 1935ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaokaimport com.android.inputmethod.latin.LatinImeLogger; 2035ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka 2135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaokapublic class TouchPositionCorrection { 2235ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka private static final int TOUCH_POSITION_CORRECTION_RECORD_SIZE = 3; 2335ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka 246ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka private boolean mEnabled; 256ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka private float[] mXs; 266ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka private float[] mYs; 276ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka private float[] mRadii; 2835ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka 2935ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka public void load(final String[] data) { 3035ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka final int dataLength = data.length; 3135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka if (dataLength % TOUCH_POSITION_CORRECTION_RECORD_SIZE != 0) { 3235ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka if (LatinImeLogger.sDBG) { 3335ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka throw new RuntimeException( 3435ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka "the size of touch position correction data is invalid"); 3535ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 3635ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka return; 3735ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 3835ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka 3935ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka final int length = dataLength / TOUCH_POSITION_CORRECTION_RECORD_SIZE; 4035ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mXs = new float[length]; 4135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mYs = new float[length]; 4235ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mRadii = new float[length]; 4335ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka try { 4435ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka for (int i = 0; i < dataLength; ++i) { 4535ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka final int type = i % TOUCH_POSITION_CORRECTION_RECORD_SIZE; 4635ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka final int index = i / TOUCH_POSITION_CORRECTION_RECORD_SIZE; 4735ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka final float value = Float.parseFloat(data[i]); 4835ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka if (type == 0) { 4935ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mXs[index] = value; 5035ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } else if (type == 1) { 5135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mYs[index] = value; 5235ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } else { 5335ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mRadii[index] = value; 5435ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 5535ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 566ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka mEnabled = dataLength > 0; 5735ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } catch (NumberFormatException e) { 5835ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka if (LatinImeLogger.sDBG) { 5935ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka throw new RuntimeException( 6035ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka "the number format for touch position correction data is invalid"); 6135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 626ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka mEnabled = false; 6335ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mXs = null; 6435ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mYs = null; 6535ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mRadii = null; 6635ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 6735ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 6835ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka 696ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka // For test only 7035ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka public void setEnabled(final boolean enabled) { 7135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mEnabled = enabled; 7235ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 7335ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka 7435ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka public boolean isValid() { 756ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka return mEnabled; 766ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka } 776ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka 786ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka public int getRows() { 796ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka return mRadii.length; 806ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka } 816ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka 826ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka public float getX(final int row) { 836ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka return mXs[row]; 846ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka } 856ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka 866ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka public float getY(final int row) { 876ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka return mYs[row]; 886ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka } 896ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka 906ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka public float getRadius(final int row) { 916ca50d99208efdbcad96b3260fe7592bf95a6b00Tadashi G. Takaoka return mRadii[row]; 9235ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 9335ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka} 94