1c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock/*
2c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock * Copyright (C) 2014 The Android Open Source Project
3c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock *
4c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock * Licensed under the Apache License, Version 2.0 (the "License");
5c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock * you may not use this file except in compliance with the License.
6c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock * You may obtain a copy of the License at
7c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock *
8c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock *      http://www.apache.org/licenses/LICENSE-2.0
9c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock *
10c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock * Unless required by applicable law or agreed to in writing, software
11c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock * distributed under the License is distributed on an "AS IS" BASIS,
12c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock * See the License for the specific language governing permissions and
14c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock * limitations under the License.
15c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock */
16c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
17c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlockpackage com.example.android.demomodecontroller;
18c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
19c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlockimport android.app.Activity;
20c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlockimport android.content.Context;
21c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlockimport android.content.Intent;
22c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlockimport android.graphics.Color;
23c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlockimport android.graphics.PointF;
24c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlockimport android.os.Bundle;
25c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlockimport android.os.Handler;
26c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlockimport android.os.HandlerThread;
27c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlockimport android.os.SystemClock;
28c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlockimport android.util.Log;
29c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlockimport android.view.MotionEvent;
30c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlockimport android.view.View;
31c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlockimport android.view.View.OnTouchListener;
32c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlockimport android.view.ViewConfiguration;
33c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlockimport android.view.WindowManager;
34c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlockimport android.widget.Toast;
35c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
36c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlockpublic class DemoModeController extends Activity implements OnTouchListener {
37c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private static final String TAG = DemoModeController.class.getSimpleName();
38c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private static final boolean DEBUG = false;
39c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
40c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private final Context mContext = this;
41c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private final Handler mHandler = new Handler();
42c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private final PointF mLastDown = new PointF();
43c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
44c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private View mContent;
45c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private Handler mBackground;
46c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private int mTouchSlop;
47c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private long mLastDownTime;
48c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private boolean mControllingColor;
49c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private Toast mToast;
50c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
51c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    @Override
52c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    protected void onCreate(Bundle savedInstanceState) {
53c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        super.onCreate(savedInstanceState);
54c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
55c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS  // so WM gives us enough room
56c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
57c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        getActionBar().hide();
58c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        mContent = new View(mContext);
59c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        mContent.setBackgroundColor(0xff33b5e5);
60c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        mContent.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
61c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
62c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
63c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        mContent.setOnTouchListener(this);
64c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        setContentView(mContent);
65c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        mTouchSlop = ViewConfiguration.get(mContext).getScaledTouchSlop();
66c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
67c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        final HandlerThread background = new HandlerThread("background");
68c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        background.start();
69c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        mBackground = new Handler(background.getLooper());
70c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        updateMode();
71c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    }
72c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
73c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    @Override
74c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    protected void onPause() {
75c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        super.onPause();
76c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        exitDemoMode();
77c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    }
78c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
79c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    @Override
80c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    protected void onResume() {
81c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        super.onResume();
82c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        exitDemoMode();
83c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        mToast = Toast.makeText(mContext, R.string.help_text, Toast.LENGTH_LONG);
84c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        mToast.show();
85c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    }
86c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
87c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    @Override
88c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    public boolean onTouch(View v, MotionEvent event) {
89c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (mToast != null) {
90c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mToast.cancel();
91c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mToast = null;
92c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        }
93c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        final int action = event.getAction();
94c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (action == MotionEvent.ACTION_DOWN) {
95c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            if (DEBUG) Log.d(TAG, "down");
96c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mHandler.postDelayed(mLongPressCheck, 500);
97c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            final long now = SystemClock.uptimeMillis();
98c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            if (now - mLastDownTime < 200) {
99c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock                toggleMode();
100c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            }
101c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mLastDownTime = now;
102c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mLastDown.x = event.getX();
103c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mLastDown.y = event.getY();
104c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            return true;
105c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        }
106c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
107c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            if (DEBUG) Log.d(TAG, "upOrCancel");
108c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mControllingColor = false;
109c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mHandler.removeCallbacks(mLongPressCheck);
110c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        }
111c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (action != MotionEvent.ACTION_MOVE) return false;
112c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
113c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        float x = event.getX();
114c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        float y = event.getY();
115c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (Math.abs(mLastDown.x - x) > mTouchSlop || Math.abs(mLastDown.y - y) > mTouchSlop) {
116c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mHandler.removeCallbacks(mLongPressCheck);
117c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        }
118c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        x = Math.max(x, 0);
119c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        y = Math.max(y, 0);
120c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        final int h = mContent.getMeasuredHeight();
121c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        final int w = mContent.getMeasuredWidth();
122c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        x = Math.min(x, w);
123c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        y = Math.min(y, h);
124c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
125c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        y = h - y;
126c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        x = w - x;
127c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
128c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (mControllingColor) {
129c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            final float hue = y / (h / 360);
130c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            final float sat = 1 - (x / (float)w);
131c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            final float val = x / (float)w;
132c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            final int color = Color.HSVToColor(new float[]{hue, sat, val});
133c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            if (DEBUG) Log.d(TAG, String.format("hsv=(%s,%s,%s) argb=#%08x", hue, sat, val, color));
134c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mContent.setBackgroundColor(color);
135c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            return true;
136c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        }
137c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
138c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        final int hh = (int)x / (w / 12);
139c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (hh != mHH) {
140c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mHH = hh;
141c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mBackground.removeCallbacks(mUpdateClock);
142c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mBackground.post(mUpdateClock);
143c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        }
144c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
145c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        final int mm = (int)y / (h / 60);
146c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (mm != mMM) {
147c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mMM = mm;
148c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mBackground.removeCallbacks(mUpdateClock);
149c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mBackground.post(mUpdateClock);
150c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        }
151c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
152c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        final int batteryLevel = (int)y / (h / 101);
153c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (batteryLevel != mBatteryLevel) {
154c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mBatteryLevel = batteryLevel;
155c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mBackground.removeCallbacks(mUpdateBattery);
156c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mBackground.post(mUpdateBattery);
157c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        }
158c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
159c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        final boolean batteryPlugged = x >= w / 2;
160c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (batteryPlugged != mBatteryPlugged) {
161c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mBatteryPlugged = batteryPlugged;
162c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mBackground.removeCallbacks(mUpdateBattery);
163c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mBackground.post(mUpdateBattery);
164c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        }
165c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
166c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        final int mobileLevel = (int)y / (h / 10);
167c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (mobileLevel != mMobileLevel) {
168c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mMobileLevel = mobileLevel;
169c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mBackground.removeCallbacks(mUpdateMobile);
170c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mBackground.post(mUpdateMobile);
171c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        }
172c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
173c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        final int wifiLevel = (int)y / (h / 10);
174c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (wifiLevel != mWifiLevel) {
175c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mWifiLevel = wifiLevel;
176c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mBackground.removeCallbacks(mUpdateWifi);
177c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mBackground.post(mUpdateWifi);
178c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        }
179c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
180c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        final int statusSlots = (int)x / (w / 13);
181c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (statusSlots != mStatusSlots) {
182c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mStatusSlots = statusSlots;
183c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mBackground.removeCallbacks(mUpdateStatus);
184c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mBackground.post(mUpdateStatus);
185c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        }
186c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
187c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        final int networkIcons = (int)x / (w / 4);
188c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (networkIcons != mNetworkIcons) {
189c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mNetworkIcons = networkIcons;
190c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mBackground.removeCallbacks(mUpdateNetwork);
191c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mBackground.post(mUpdateNetwork);
192c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        }
193c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
194c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        final int mobileDataType = (int)y / (h / 9);
195c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (mobileDataType != mMobileDataType) {
196c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mMobileDataType = mobileDataType;
197c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mBackground.removeCallbacks(mUpdateMobile);
198c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mBackground.post(mUpdateMobile);
199c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        }
200c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        return true;
201c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    }
202c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
203c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private void toggleMode() {
204c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (DEBUG) Log.d(TAG, "toggleMode");
205c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        mBarMode = (mBarMode + 1) % 3;
206c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        updateMode();
207c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    }
208c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
209c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private void updateMode() {
210c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        mBackground.removeCallbacks(mUpdateBarMode);
211c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        mBackground.post(mUpdateBarMode);
212c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    }
213c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
214c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private final Runnable mLongPressCheck = new Runnable() {
215c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        @Override
216c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        public void run() {
217c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            if (DEBUG) Log.d(TAG, "mControllingColor = true");
218c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mControllingColor = true;
219c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
220c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        }
221c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    };
222c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
223c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private void exitDemoMode() {
224c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (DEBUG) Log.d(TAG, "exitDemoMode");
225c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        final Intent intent = new Intent("com.android.systemui.demo");
226c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        intent.putExtra("command", "exit");
227c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        mContext.sendBroadcast(intent);
228c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    }
229c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
230c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private int mStatusSlots; // 0 - 12
231c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private final Runnable mUpdateStatus = new Runnable() {
232c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        @Override
233c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        public void run() {
234c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            final Intent intent = new Intent("com.android.systemui.demo");
235c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("command", "status");
236c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("volume", mStatusSlots < 1 ? "hide"
237c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock                    : mStatusSlots < 2 ? "silent" : "vibrate");
238c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("bluetooth", mStatusSlots < 3 ? "hide"
239c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock                    : mStatusSlots < 4 ? "disconnected" : "connected");
240c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("location", mStatusSlots < 5 ? "hide" : "show");
241c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("alarm", mStatusSlots < 6 ? "hide" : "show");
242c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("sync", mStatusSlots < 7 ? "hide" : "show");
243c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("tty", mStatusSlots < 8 ? "hide" : "show");
244c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("eri", mStatusSlots < 9 ? "hide" : "show");
245c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("secure", mStatusSlots < 10 ? "hide" : "show");
246c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("mute", mStatusSlots < 11 ? "hide" : "show");
247c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("speakerphone", mStatusSlots < 12 ? "hide" : "show");
248c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mContext.sendBroadcast(intent);
249c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        }
250c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    };
251c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
252c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private int mNetworkIcons;  // 0:airplane  1:mobile  2:airplane+wifi  3:mobile+wifi
253c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private final Runnable mUpdateNetwork = new Runnable() {
254c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        @Override
255c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        public void run() {
256c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            final Intent intent = new Intent("com.android.systemui.demo");
257c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("command", "network");
258c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("airplane", mNetworkIcons % 2 == 0 ? "show" : "hide");
259c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("wifi", mNetworkIcons >= 2 ? "show" : "hide");
260c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("mobile", mNetworkIcons % 2 == 1 ? "show" : "hide");
261c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mContext.sendBroadcast(intent);
262c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        }
263c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    };
264c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
265c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private int mWifiLevel; // 0 - 4, 5 - 9, fully
266c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private final Runnable mUpdateWifi = new Runnable() {
267c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        @Override
268c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        public void run() {
269c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            final Intent intent = new Intent("com.android.systemui.demo");
270c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("command", "network");
271c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("wifi", mNetworkIcons >= 2 ? "show" : "hide");
272c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("level", Integer.toString(mWifiLevel % 5));
273c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("fully", Boolean.toString(mWifiLevel > 4));
274c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mContext.sendBroadcast(intent);
275c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        }
276c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    };
277c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
278c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private int mMobileLevel; // 0 - 4, 5 - 9, fully
279c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private int mMobileDataType; // 0 - 8
280c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private static final String getDataType(int dataType) {
281c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (dataType == 1) return "1x";
282c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (dataType == 2) return "3g";
283c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (dataType == 3) return "4g";
284c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (dataType == 4) return "e";
285c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (dataType == 5) return "g";
286c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (dataType == 6) return "h";
287c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (dataType == 7) return "lte";
288c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        if (dataType == 8) return "roam";
289c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        return "";
290c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    }
291c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private final Runnable mUpdateMobile = new Runnable() {
292c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        @Override
293c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        public void run() {
294c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            final Intent intent = new Intent("com.android.systemui.demo");
295c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("command", "network");
296c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("mobile", mNetworkIcons % 2 == 1 ? "show" : "hide");
297c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("level", Integer.toString(mMobileLevel % 5));
298c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("fully", Boolean.toString(mMobileLevel > 4));
299c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("datatype", getDataType(mMobileDataType));
300c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mContext.sendBroadcast(intent);
301c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        }
302c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    };
303c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
304c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private boolean mBatteryPlugged;
305c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private int mBatteryLevel; // 0 - 100
306c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private final Runnable mUpdateBattery = new Runnable() {
307c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        @Override
308c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        public void run() {
309c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            final Intent intent = new Intent("com.android.systemui.demo");
310c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("command", "battery");
311c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("level", Integer.toString(mBatteryLevel));
312c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("plugged", Boolean.toString(mBatteryPlugged));
313c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mContext.sendBroadcast(intent);
314c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        }
315c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    };
316c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
317c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private int mHH; // 0 - 11
318c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private int mMM; // 0 - 59
319c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private final Runnable mUpdateClock = new Runnable() {
320c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        @Override
321c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        public void run() {
322c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            final Intent intent = new Intent("com.android.systemui.demo");
323c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("command", "clock");
324c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("hhmm", String.format("%02d%02d", mHH + 1, mMM));
325c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mContext.sendBroadcast(intent);
326c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        }
327c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    };
328c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock
329c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private int mBarMode; // 0 - 2  (opaque, semi-transparent, translucent)
330c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    private final Runnable mUpdateBarMode = new Runnable() {
331c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        @Override
332c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        public void run() {
333c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            final Intent intent = new Intent("com.android.systemui.demo");
334c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("command", "bars");
335c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            intent.putExtra("mode", mBarMode == 1 ? "semi-transparent"
336c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock                    : mBarMode == 2 ? "translucent" : "opaque");
337c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock            mContext.sendBroadcast(intent);
338c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock        }
339c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock    };
340c23929c3a34eb12663278fa323d3252a1ac3e57bJohn Spurlock}
341