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 android.support.v4.view;
18
19import android.os.Build;
20import android.view.ScaleGestureDetector;
21
22/**
23 * Helper for accessing features in {@link ScaleGestureDetector} in a backwards compatible fashion.
24 */
25public final class ScaleGestureDetectorCompat {
26    private ScaleGestureDetectorCompat() {}
27
28    /**
29     * Sets whether the associated {@link ScaleGestureDetector.OnScaleGestureListener} should
30     * receive onScale callbacks when the user performs a doubleTap followed by a swipe. Note that
31     * this is enabled by default if the app targets API 19 and newer.
32     *
33     * @param enabled true to enable quick scaling, false to disable
34     *
35     * @deprecated Use {@link #setQuickScaleEnabled(ScaleGestureDetector, boolean)} that takes
36     * {@link ScaleGestureDetector} instead of {@link Object}.
37     */
38    @Deprecated
39    public static void setQuickScaleEnabled(Object scaleGestureDetector, boolean enabled) {
40        ScaleGestureDetectorCompat.setQuickScaleEnabled(
41                (ScaleGestureDetector) scaleGestureDetector, enabled);
42    }
43
44    /**
45     * Sets whether the associated {@link ScaleGestureDetector.OnScaleGestureListener} should
46     * receive onScale callbacks when the user performs a doubleTap followed by a swipe. Note that
47     * this is enabled by default if the app targets API 19 and newer.
48     *
49     * @param enabled true to enable quick scaling, false to disable
50     */
51    public static void setQuickScaleEnabled(
52            ScaleGestureDetector scaleGestureDetector, boolean enabled) {
53        if (Build.VERSION.SDK_INT >= 19) {
54            scaleGestureDetector.setQuickScaleEnabled(enabled);
55        }
56    }
57
58    /**
59     * Returns whether the quick scale gesture, in which the user performs a double tap followed by
60     * a swipe, should perform scaling. See
61     * {@link #setQuickScaleEnabled(ScaleGestureDetector, boolean)}.
62     *
63     * @deprecated Use {@link #isQuickScaleEnabled(ScaleGestureDetector)} that takes
64     * {@link ScaleGestureDetector} instead of {@link Object}.
65     */
66    @Deprecated
67    public static boolean isQuickScaleEnabled(Object scaleGestureDetector) {
68        return ScaleGestureDetectorCompat.isQuickScaleEnabled(
69                (ScaleGestureDetector) scaleGestureDetector);
70    }
71
72    /**
73     * Returns whether the quick scale gesture, in which the user performs a double tap followed by
74     * a swipe, should perform scaling. See
75     * {@link #setQuickScaleEnabled(ScaleGestureDetector, boolean)}.
76     */
77    public static boolean isQuickScaleEnabled(ScaleGestureDetector scaleGestureDetector) {
78        if (Build.VERSION.SDK_INT >= 19) {
79            return scaleGestureDetector.isQuickScaleEnabled();
80        } else {
81            return false;
82        }
83    }
84}
85