BarTransitions.java revision e932e30eadb5978591316ffe3d21d60604c0cd91
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 com.android.systemui.statusbar.phone;
18
19import android.app.ActivityManager;
20import android.content.Context;
21import android.content.res.Resources;
22import android.graphics.drawable.ColorDrawable;
23import android.graphics.drawable.Drawable;
24import android.view.View;
25
26import com.android.systemui.R;
27
28public class BarTransitions {
29
30    public static final int MODE_NORMAL = 0;
31    public static final int MODE_TRANSIENT = 1;
32    public static final int MODE_TRANSPARENT = 2;
33
34    private final View mTarget;
35    private final Drawable mOpaque;
36    private final Drawable mTransient;
37
38    private Drawable mTransparent;
39    private int mMode;
40
41    public BarTransitions(Context context, View target, Drawable transparent) {
42        mTarget = target;
43        final Resources res = context.getResources();
44        mOpaque = new ColorDrawable(res.getColor(R.drawable.status_bar_background));
45        mTransient = new ColorDrawable(res.getColor(R.color.status_bar_background_transient));
46        mTransparent = transparent;
47    }
48
49    public void setTransparent(Drawable transparent) {
50        mTransparent = transparent;
51        if (mMode == MODE_TRANSPARENT) {
52            transitionTo(MODE_TRANSPARENT);
53        }
54    }
55
56    public void transitionTo(int mode) {
57        mMode = mode;
58        if (!ActivityManager.isHighEndGfx()) return;
59        Drawable background = mode == MODE_TRANSIENT ? mTransient
60                : mode == MODE_TRANSPARENT ? mTransparent
61                : mOpaque;
62        mTarget.setBackground(background);
63    }
64}
65