TouchPositionCorrection.java revision 35ff94547c16c84c5b6fafdae0b4a683be782b97
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 2435ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka public boolean mEnabled; 2535ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka public float[] mXs; 2635ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka public float[] mYs; 2735ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka public 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 } 5635ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } catch (NumberFormatException e) { 5735ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka if (LatinImeLogger.sDBG) { 5835ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka throw new RuntimeException( 5935ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka "the number format for touch position correction data is invalid"); 6035ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 6135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mXs = null; 6235ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mYs = null; 6335ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mRadii = null; 6435ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 6535ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 6635ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka 6735ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka // TODO: Remove this method. 6835ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka public void setEnabled(final boolean enabled) { 6935ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka mEnabled = enabled; 7035ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 7135ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka 7235ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka public boolean isValid() { 7335ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka return mEnabled && mXs != null && mYs != null && mRadii != null 7435ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka && mXs.length > 0 && mYs.length > 0 && mRadii.length > 0; 7535ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka } 7635ff94547c16c84c5b6fafdae0b4a683be782b97Tadashi G. Takaoka} 77