From e82200787c662488c908c7973b9857ee6ce037b3 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 24 Dec 2013 16:57:32 +0900 Subject: [PATCH] Separate GestureStrokePreviewParams to top level class Change-Id: I4c6ac12dac9636760128625bb5b7138b7d56f3d1 --- .../inputmethod/keyboard/PointerTracker.java | 2 +- .../internal/GestureStrokePreviewParams.java | 50 +++++++++++++++++++ .../GestureStrokeWithPreviewPoints.java | 36 ------------- 3 files changed, 51 insertions(+), 37 deletions(-) create mode 100644 java/src/com/android/inputmethod/keyboard/internal/GestureStrokePreviewParams.java diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 15c441932..8f43dce95 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -26,8 +26,8 @@ import com.android.inputmethod.keyboard.internal.BogusMoveEventDetector; import com.android.inputmethod.keyboard.internal.GestureEnabler; import com.android.inputmethod.keyboard.internal.GestureStroke; import com.android.inputmethod.keyboard.internal.GestureStrokeParams; +import com.android.inputmethod.keyboard.internal.GestureStrokePreviewParams; import com.android.inputmethod.keyboard.internal.GestureStrokeWithPreviewPoints; -import com.android.inputmethod.keyboard.internal.GestureStrokeWithPreviewPoints.GestureStrokePreviewParams; import com.android.inputmethod.keyboard.internal.PointerTrackerQueue; import com.android.inputmethod.keyboard.internal.TypingTimeRecorder; import com.android.inputmethod.latin.Constants; diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureStrokePreviewParams.java b/java/src/com/android/inputmethod/keyboard/internal/GestureStrokePreviewParams.java new file mode 100644 index 000000000..6695476e1 --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/internal/GestureStrokePreviewParams.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.inputmethod.keyboard.internal; + +import android.content.res.TypedArray; + +import com.android.inputmethod.latin.R; + +public final class GestureStrokePreviewParams { + public final double mMinSamplingDistance; // in pixel + public final double mMaxInterpolationAngularThreshold; // in radian + public final double mMaxInterpolationDistanceThreshold; // in pixel + public final int mMaxInterpolationSegments; + + private static final float DEFAULT_MIN_SAMPLING_DISTANCE = 0.0f; // dp + private static final int DEFAULT_MAX_INTERPOLATION_ANGULAR_THRESHOLD = 15; // in degree + private static final float DEFAULT_MAX_INTERPOLATION_DISTANCE_THRESHOLD = 0.0f; // dp + private static final int DEFAULT_MAX_INTERPOLATION_SEGMENTS = 4; + + public GestureStrokePreviewParams(final TypedArray mainKeyboardViewAttr) { + mMinSamplingDistance = mainKeyboardViewAttr.getDimension( + R.styleable.MainKeyboardView_gestureTrailMinSamplingDistance, + DEFAULT_MIN_SAMPLING_DISTANCE); + final int interpolationAngularDegree = mainKeyboardViewAttr.getInteger(R.styleable + .MainKeyboardView_gestureTrailMaxInterpolationAngularThreshold, 0); + mMaxInterpolationAngularThreshold = (interpolationAngularDegree <= 0) + ? Math.toRadians(DEFAULT_MAX_INTERPOLATION_ANGULAR_THRESHOLD) + : Math.toRadians(interpolationAngularDegree); + mMaxInterpolationDistanceThreshold = mainKeyboardViewAttr.getDimension(R.styleable + .MainKeyboardView_gestureTrailMaxInterpolationDistanceThreshold, + DEFAULT_MAX_INTERPOLATION_DISTANCE_THRESHOLD); + mMaxInterpolationSegments = mainKeyboardViewAttr.getInteger( + R.styleable.MainKeyboardView_gestureTrailMaxInterpolationSegments, + DEFAULT_MAX_INTERPOLATION_SEGMENTS); + } +} diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureStrokeWithPreviewPoints.java b/java/src/com/android/inputmethod/keyboard/internal/GestureStrokeWithPreviewPoints.java index 9ce204393..22407d8af 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/GestureStrokeWithPreviewPoints.java +++ b/java/src/com/android/inputmethod/keyboard/internal/GestureStrokeWithPreviewPoints.java @@ -16,9 +16,6 @@ package com.android.inputmethod.keyboard.internal; -import android.content.res.TypedArray; - -import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.utils.ResizableIntArray; public final class GestureStrokeWithPreviewPoints extends GestureStroke { @@ -39,39 +36,6 @@ public final class GestureStrokeWithPreviewPoints extends GestureStroke { private int mLastY; private double mDistanceFromLastSample; - public static final class GestureStrokePreviewParams { - public final double mMinSamplingDistance; // in pixel - public final double mMaxInterpolationAngularThreshold; // in radian - public final double mMaxInterpolationDistanceThreshold; // in pixel - public final int mMaxInterpolationSegments; - - private static final float DEFAULT_MIN_SAMPLING_DISTANCE = 0.0f; // dp - private static final int DEFAULT_MAX_INTERPOLATION_ANGULAR_THRESHOLD = 15; // in degree - private static final float DEFAULT_MAX_INTERPOLATION_DISTANCE_THRESHOLD = 0.0f; // dp - private static final int DEFAULT_MAX_INTERPOLATION_SEGMENTS = 4; - - private static double degreeToRadian(final int degree) { - return degree / 180.0d * Math.PI; - } - - public GestureStrokePreviewParams(final TypedArray mainKeyboardViewAttr) { - mMinSamplingDistance = mainKeyboardViewAttr.getDimension( - R.styleable.MainKeyboardView_gestureTrailMinSamplingDistance, - DEFAULT_MIN_SAMPLING_DISTANCE); - final int interpolationAngularDegree = mainKeyboardViewAttr.getInteger(R.styleable - .MainKeyboardView_gestureTrailMaxInterpolationAngularThreshold, 0); - mMaxInterpolationAngularThreshold = (interpolationAngularDegree <= 0) - ? degreeToRadian(DEFAULT_MAX_INTERPOLATION_ANGULAR_THRESHOLD) - : degreeToRadian(interpolationAngularDegree); - mMaxInterpolationDistanceThreshold = mainKeyboardViewAttr.getDimension(R.styleable - .MainKeyboardView_gestureTrailMaxInterpolationDistanceThreshold, - DEFAULT_MAX_INTERPOLATION_DISTANCE_THRESHOLD); - mMaxInterpolationSegments = mainKeyboardViewAttr.getInteger( - R.styleable.MainKeyboardView_gestureTrailMaxInterpolationSegments, - DEFAULT_MAX_INTERPOLATION_SEGMENTS); - } - } - public GestureStrokeWithPreviewPoints(final int pointerId, final GestureStrokeParams strokeParams, final GestureStrokePreviewParams previewParams) {