1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.inputmethod.keyboard.internal;
18 
19 import android.content.res.TypedArray;
20 
21 import com.android.inputmethod.latin.R;
22 
23 /**
24  * This class holds parameters to control how a gesture stroke is sampled and drawn on the screen.
25  *
26  * @attr ref R.styleable#MainKeyboardView_gestureTrailMinSamplingDistance
27  * @attr ref R.styleable#MainKeyboardView_gestureTrailMaxInterpolationAngularThreshold
28  * @attr ref R.styleable#MainKeyboardView_gestureTrailMaxInterpolationDistanceThreshold
29  * @attr ref R.styleable#MainKeyboardView_gestureTrailMaxInterpolationSegments
30  */
31 public final class GestureStrokeDrawingParams {
32     public final double mMinSamplingDistance; // in pixel
33     public final double mMaxInterpolationAngularThreshold; // in radian
34     public final double mMaxInterpolationDistanceThreshold; // in pixel
35     public final int mMaxInterpolationSegments;
36 
37     private static final float DEFAULT_MIN_SAMPLING_DISTANCE = 0.0f; // dp
38     private static final int DEFAULT_MAX_INTERPOLATION_ANGULAR_THRESHOLD = 15; // in degree
39     private static final float DEFAULT_MAX_INTERPOLATION_DISTANCE_THRESHOLD = 0.0f; // dp
40     private static final int DEFAULT_MAX_INTERPOLATION_SEGMENTS = 4;
41 
GestureStrokeDrawingParams(final TypedArray mainKeyboardViewAttr)42     public GestureStrokeDrawingParams(final TypedArray mainKeyboardViewAttr) {
43         mMinSamplingDistance = mainKeyboardViewAttr.getDimension(
44                 R.styleable.MainKeyboardView_gestureTrailMinSamplingDistance,
45                 DEFAULT_MIN_SAMPLING_DISTANCE);
46         final int interpolationAngularDegree = mainKeyboardViewAttr.getInteger(R.styleable
47                 .MainKeyboardView_gestureTrailMaxInterpolationAngularThreshold, 0);
48         mMaxInterpolationAngularThreshold = (interpolationAngularDegree <= 0)
49                 ? Math.toRadians(DEFAULT_MAX_INTERPOLATION_ANGULAR_THRESHOLD)
50                 : Math.toRadians(interpolationAngularDegree);
51         mMaxInterpolationDistanceThreshold = mainKeyboardViewAttr.getDimension(R.styleable
52                 .MainKeyboardView_gestureTrailMaxInterpolationDistanceThreshold,
53                 DEFAULT_MAX_INTERPOLATION_DISTANCE_THRESHOLD);
54         mMaxInterpolationSegments = mainKeyboardViewAttr.getInteger(
55                 R.styleable.MainKeyboardView_gestureTrailMaxInterpolationSegments,
56                 DEFAULT_MAX_INTERPOLATION_SEGMENTS);
57     }
58 }
59