1/*
2 * Copyright (C) 2015 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.settingslib.animation;
18
19import android.content.Context;
20import android.view.animation.AnimationUtils;
21import android.view.animation.Interpolator;
22
23/**
24 * A class to make nice disappear transitions for views in a tabular layout.
25 */
26public class DisappearAnimationUtils extends AppearAnimationUtils {
27
28    public DisappearAnimationUtils(Context ctx) {
29        this(ctx, DEFAULT_APPEAR_DURATION,
30                1.0f, 1.0f,
31                AnimationUtils.loadInterpolator(ctx, android.R.interpolator.fast_out_linear_in));
32    }
33
34    public DisappearAnimationUtils(Context ctx, long duration, float translationScaleFactor,
35            float delayScaleFactor, Interpolator interpolator) {
36        this(ctx, duration, translationScaleFactor, delayScaleFactor, interpolator,
37                ROW_TRANSLATION_SCALER);
38    }
39
40    public DisappearAnimationUtils(Context ctx, long duration, float translationScaleFactor,
41            float delayScaleFactor, Interpolator interpolator, RowTranslationScaler rowScaler) {
42        super(ctx, duration, translationScaleFactor, delayScaleFactor, interpolator);
43        mRowTranslationScaler = rowScaler;
44        mAppearing = false;
45    }
46
47    protected long calculateDelay(int row, int col) {
48        return (long) ((row * 60 + col * (Math.pow(row, 0.4) + 0.4) * 10) * mDelayScale);
49    }
50
51    private static final RowTranslationScaler ROW_TRANSLATION_SCALER = new RowTranslationScaler() {
52
53        @Override
54        public float getRowTranslationScale(int row, int numRows) {
55            return (float) (Math.pow((numRows - row), 2) / numRows);
56        }
57    };
58}
59