/*
 * 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 android.support.v4.view;

/**
 * Helper for accessing features in {@link ScaleGestureDetector} introduced
 * after API level 19 (KitKat) in a backwards compatible fashion.
 */
public class ScaleGestureDetectorCompat {
    static final ScaleGestureDetectorImpl IMPL;

    interface ScaleGestureDetectorImpl {

        public void setQuickScaleEnabled(Object o, boolean enabled);

        public boolean isQuickScaleEnabled(Object o);
    }

    private static class BaseScaleGestureDetectorImpl implements ScaleGestureDetectorImpl {
        @Override
        public void setQuickScaleEnabled(Object o, boolean enabled) {
            // Intentionally blank
        }

        @Override
        public boolean isQuickScaleEnabled(Object o) {
            return false;
        }
    }

    private static class ScaleGestureDetectorCompatKitKatImpl implements ScaleGestureDetectorImpl {
        @Override
        public void setQuickScaleEnabled(Object o, boolean enabled) {
            ScaleGestureDetectorCompatKitKat.setQuickScaleEnabled(o, enabled);
        }

        @Override
        public boolean isQuickScaleEnabled(Object o) {
            return ScaleGestureDetectorCompatKitKat.isQuickScaleEnabled(o);
        }
    }

    static {
        final int version = android.os.Build.VERSION.SDK_INT;
        if (version >= 18) { // KitKat
            IMPL = new ScaleGestureDetectorCompatKitKatImpl();
        } else {
            IMPL = new BaseScaleGestureDetectorImpl();
        }
    }

    private ScaleGestureDetectorCompat() {}

    /**
     * Set whether the associated <code>OnScaleGestureListener</code> should receive onScale callbacks
     * when the user performs a doubleTap followed by a swipe. Note that this is enabled by default
     * if the app targets API 19 and newer.
     * @param scales true to enable quick scaling, false to disable
     */
    public static void setQuickScaleEnabled(Object scaleGestureDetector, boolean enabled) {
        IMPL.setQuickScaleEnabled(scaleGestureDetector, enabled);
    }

    /**
     * Return whether the quick scale gesture, in which the user performs a double tap followed by a
     * swipe, should perform scaling. {@see #setQuickScaleEnabled(Object, boolean)}.
     */
    public static boolean isQuickScaleEnabled(Object scaleGestureDetector) {
        return IMPL.isQuickScaleEnabled(scaleGestureDetector); // KitKat
    }
}

@@ -692,15 +692,14 @@
  in 
-%7B@link 
+%3Ccode%3E
 Scal
@@ -714,17 +714,23 @@
 Detector
-%7D
+%3C/code%3E
  introdu
@@ -2264,16 +2264,23 @@
  onScale
+%0A     *
  callbac
@@ -2281,23 +2281,16 @@
 allbacks
-%0A     *
  when th
@@ -2363,16 +2363,23 @@
  enabled
+%0A     *
  by defa
@@ -2381,23 +2381,16 @@
  default
-%0A     *
  if the 
@@ -2437,14 +2437,15 @@
 ram 
-scales
+enabled
  tru
@@ -2812,15 +2812,18 @@
 ng. 
-%7B@see #
+See %3Ccode%3E
 setQ
@@ -2855,17 +2855,22 @@
 boolean)
-%7D
+%3Ccode%3E
 .%0A     *

Fix the docs for the ScaleGestureDetector