/* * 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.graphics.drawable; import android.graphics.drawable.Drawable; /** * Helper for accessing features in {@link android.graphics.drawable.Drawable} * introduced after API level 4 in a backwards compatible fashion. */ public class DrawableCompat { /** * Interface for the full API. */ interface DrawableImpl { void jumpToCurrentState(Drawable drawable); } /** * Interface implementation that doesn't use anything about v4 APIs. */ static class BaseDrawableImpl implements DrawableImpl { @Override public void jumpToCurrentState(Drawable drawable) { } } /** * Interface implementation for devices with at least v11 APIs. */ static class HoneycombDrawableImpl implements DrawableImpl { @Override public void jumpToCurrentState(Drawable drawable) { DrawableCompatHoneycomb.jumpToCurrentState(drawable); } } /** * Select the correct implementation to use for the current platform. */ static final DrawableImpl IMPL; static { final int version = android.os.Build.VERSION.SDK_INT; if (version >= 11) { IMPL = new HoneycombDrawableImpl(); } else { IMPL = new BaseDrawableImpl(); } } /** * Call {@link Drawable#jumpToCurrentState() Drawable.jumpToCurrentState()}. * If running on a pre-{@link android.os.Build.VERSION_CODES#HONEYCOMB} device * this method does nothing. */ public static void jumpToCurrentState(Drawable drawable) { IMPL.jumpToCurrentState(drawable); } }