165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane/*
265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Copyright (C) 2014 The Android Open Source Project
365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane *
465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Licensed under the Apache License, Version 2.0 (the "License");
565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * you may not use this file except in compliance with the License.
665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * You may obtain a copy of the License at
765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane *
865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane *      http://www.apache.org/licenses/LICENSE-2.0
965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane *
1065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Unless required by applicable law or agreed to in writing, software
1165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * distributed under the License is distributed on an "AS IS" BASIS,
1265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * See the License for the specific language governing permissions and
1465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * limitations under the License.
1565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */
1665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
1765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lanepackage com.android.tv.settings.util;
1865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
1965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.animation.ObjectAnimator;
2065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.res.Resources;
2165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.util.TypedValue;
2265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
2365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport com.android.tv.settings.R;
2465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
2565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane/**
2665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Utility class for handling transition animations.
2765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */
2865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lanepublic class TransitionUtils {
2965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
3065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    /**
3165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane     * Creates an object animator that use implements the alpha fade-in for an
3265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane     * Activity's background.
3365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane     */
3465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    public static ObjectAnimator createActivityFadeInAnimator(Resources res, boolean useFloats) {
3565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        TypedValue startAlpha = new TypedValue();
3665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        res.getValue(R.dimen.alpha_activity_in_bkg_start, startAlpha, true);
3765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
3865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        TypedValue endAlpha = new TypedValue();
3965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        res.getValue(R.dimen.alpha_activity_in_bkg_end, endAlpha, true);
4065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
4165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        ObjectAnimator animator = new ObjectAnimator();
4265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        animator.setPropertyName("alpha");
4365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        if (useFloats) {
4465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane            animator.setFloatValues(startAlpha.getFloat(), endAlpha.getFloat());
4565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        } else {
4665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane            animator.setIntValues(Float.valueOf(startAlpha.getFloat() * 255).intValue(),
4765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane                    Float.valueOf(endAlpha.getFloat() * 255).intValue());
4865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        }
4965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        animator.setDuration(res.getInteger(R.integer.alpha_activity_in_bkg_duration));
5065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        animator.setStartDelay(res.getInteger(R.integer.alpha_activity_in_bkg_delay));
5165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        return animator;
5265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
5365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
5465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    public static ObjectAnimator createActivityFadeOutAnimator(Resources res, boolean useFloats) {
5565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        TypedValue startAlpha = new TypedValue();
5665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        res.getValue(R.dimen.alpha_activity_out_bkg_start, startAlpha, true);
5765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
5865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        TypedValue endAlpha = new TypedValue();
5965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        res.getValue(R.dimen.alpha_activity_out_bkg_end, endAlpha, true);
6065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
6165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        ObjectAnimator animator = new ObjectAnimator();
6265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        animator.setPropertyName("alpha");
6365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        if (useFloats) {
6465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane            animator.setFloatValues(startAlpha.getFloat(), endAlpha.getFloat());
6565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        } else {
6665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane            animator.setIntValues(Float.valueOf(startAlpha.getFloat() * 255).intValue(),
6765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane                    Float.valueOf(endAlpha.getFloat() * 255).intValue());
6865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        }
6965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        animator.setDuration(res.getInteger(R.integer.alpha_activity_out_bkg_duration));
7065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        animator.setStartDelay(res.getInteger(R.integer.alpha_activity_out_bkg_delay));
7165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        return animator;
7265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
7365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane}
74