1/*
2 * Copyright (C) 2008 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.policy;
18
19import android.app.ActivityManager;
20import android.content.Context;
21import android.content.res.TypedArray;
22import android.os.RemoteException;
23import android.util.AttributeSet;
24import android.util.Slog;
25import android.view.View;
26import android.widget.ImageView;
27
28import com.android.systemui.R;
29
30public class CompatModeButton extends ImageView {
31    private static final boolean DEBUG = false;
32    private static final String TAG = "StatusBar.CompatModeButton";
33
34    private ActivityManager mAM;
35
36    public CompatModeButton(Context context, AttributeSet attrs) {
37        this(context, attrs, 0);
38    }
39
40    public CompatModeButton(Context context, AttributeSet attrs, int defStyle) {
41        super(context, attrs);
42
43        setClickable(true);
44
45        mAM = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
46
47        refresh();
48    }
49
50    public void refresh() {
51        int mode = mAM.getFrontActivityScreenCompatMode();
52        if (mode == ActivityManager.COMPAT_MODE_UNKNOWN) {
53            // If in an unknown state, don't change.
54            return;
55        }
56        final boolean vis = (mode != ActivityManager.COMPAT_MODE_NEVER
57                          && mode != ActivityManager.COMPAT_MODE_ALWAYS);
58        if (DEBUG) Slog.d(TAG, "compat mode is " + mode + "; icon will " + (vis ? "show" : "hide"));
59        setVisibility(vis ? View.VISIBLE : View.GONE);
60    }
61}
62