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
17package com.android.inputmethod.keyboard.internal;
18
19import android.content.res.TypedArray;
20
21import com.android.inputmethod.latin.R;
22
23/**
24 * This class holds parameters to control how a gesture trail is drawn and animated on the screen.
25 *
26 * On the other hand, {@link GestureStrokeDrawingParams} class controls how each gesture stroke is
27 * sampled and interpolated. This class controls how those gesture strokes are displayed as a
28 * gesture trail and animated on the screen.
29 *
30 * @attr ref R.styleable#MainKeyboardView_gestureTrailFadeoutStartDelay
31 * @attr ref R.styleable#MainKeyboardView_gestureTrailFadeoutDuration
32 * @attr ref R.styleable#MainKeyboardView_gestureTrailUpdateInterval
33 * @attr ref R.styleable#MainKeyboardView_gestureTrailColor
34 * @attr ref R.styleable#MainKeyboardView_gestureTrailWidth
35 */
36final class GestureTrailDrawingParams {
37    private static final int FADEOUT_START_DELAY_FOR_DEBUG = 2000; // millisecond
38    private static final int FADEOUT_DURATION_FOR_DEBUG = 200; // millisecond
39
40    public final int mTrailColor;
41    public final float mTrailStartWidth;
42    public final float mTrailEndWidth;
43    public final float mTrailBodyRatio;
44    public boolean mTrailShadowEnabled;
45    public final float mTrailShadowRatio;
46    public final int mFadeoutStartDelay;
47    public final int mFadeoutDuration;
48    public final int mUpdateInterval;
49
50    public final int mTrailLingerDuration;
51
52    public GestureTrailDrawingParams(final TypedArray mainKeyboardViewAttr) {
53        mTrailColor = mainKeyboardViewAttr.getColor(
54                R.styleable.MainKeyboardView_gestureTrailColor, 0);
55        mTrailStartWidth = mainKeyboardViewAttr.getDimension(
56                R.styleable.MainKeyboardView_gestureTrailStartWidth, 0.0f);
57        mTrailEndWidth = mainKeyboardViewAttr.getDimension(
58                R.styleable.MainKeyboardView_gestureTrailEndWidth, 0.0f);
59        final int PERCENTAGE_INT = 100;
60        mTrailBodyRatio = (float)mainKeyboardViewAttr.getInt(
61                R.styleable.MainKeyboardView_gestureTrailBodyRatio, PERCENTAGE_INT)
62                / (float)PERCENTAGE_INT;
63        final int trailShadowRatioInt = mainKeyboardViewAttr.getInt(
64                R.styleable.MainKeyboardView_gestureTrailShadowRatio, 0);
65        mTrailShadowEnabled = (trailShadowRatioInt > 0);
66        mTrailShadowRatio = (float)trailShadowRatioInt / (float)PERCENTAGE_INT;
67        mFadeoutStartDelay = GestureTrailDrawingPoints.DEBUG_SHOW_POINTS
68                ? FADEOUT_START_DELAY_FOR_DEBUG
69                : mainKeyboardViewAttr.getInt(
70                        R.styleable.MainKeyboardView_gestureTrailFadeoutStartDelay, 0);
71        mFadeoutDuration = GestureTrailDrawingPoints.DEBUG_SHOW_POINTS
72                ? FADEOUT_DURATION_FOR_DEBUG
73                : mainKeyboardViewAttr.getInt(
74                        R.styleable.MainKeyboardView_gestureTrailFadeoutDuration, 0);
75        mTrailLingerDuration = mFadeoutStartDelay + mFadeoutDuration;
76        mUpdateInterval = mainKeyboardViewAttr.getInt(
77                R.styleable.MainKeyboardView_gestureTrailUpdateInterval, 0);
78    }
79}
80