FileDocCategorySizeDatePackage
DemoModeController.javaAPI DocAndroid 5.1 API12770Thu Mar 12 22:22:44 GMT 2015com.example.android.demomodecontroller

DemoModeController

public class DemoModeController extends android.app.Activity implements android.view.View.OnTouchListener

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private final android.content.Context
mContext
private final android.os.Handler
mHandler
private final android.graphics.PointF
mLastDown
private android.view.View
mContent
private android.os.Handler
mBackground
private int
mTouchSlop
private long
mLastDownTime
private boolean
mControllingColor
private android.widget.Toast
mToast
private final Runnable
mLongPressCheck
private int
mStatusSlots
private final Runnable
mUpdateStatus
private int
mNetworkIcons
private final Runnable
mUpdateNetwork
private int
mWifiLevel
private final Runnable
mUpdateWifi
private int
mMobileLevel
private int
mMobileDataType
private final Runnable
mUpdateMobile
private boolean
mBatteryPlugged
private int
mBatteryLevel
private final Runnable
mUpdateBattery
private int
mHH
private int
mMM
private final Runnable
mUpdateClock
private int
mBarMode
private final Runnable
mUpdateBarMode
Constructors Summary
Methods Summary
private voidexitDemoMode()


       
        if (DEBUG) Log.d(TAG, "exitDemoMode");
        final Intent intent = new Intent("com.android.systemui.demo");
        intent.putExtra("command", "exit");
        mContext.sendBroadcast(intent);
    
private static final java.lang.StringgetDataType(int dataType)

 // 0 - 8
          
        if (dataType == 1) return "1x";
        if (dataType == 2) return "3g";
        if (dataType == 3) return "4g";
        if (dataType == 4) return "e";
        if (dataType == 5) return "g";
        if (dataType == 6) return "h";
        if (dataType == 7) return "lte";
        if (dataType == 8) return "roam";
        return "";
    
protected voidonCreate(android.os.Bundle savedInstanceState)


    
        
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS  // so WM gives us enough room
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        getActionBar().hide();
        mContent = new View(mContext);
        mContent.setBackgroundColor(0xff33b5e5);
        mContent.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        mContent.setOnTouchListener(this);
        setContentView(mContent);
        mTouchSlop = ViewConfiguration.get(mContext).getScaledTouchSlop();

        final HandlerThread background = new HandlerThread("background");
        background.start();
        mBackground = new Handler(background.getLooper());
        updateMode();
    
protected voidonPause()

        super.onPause();
        exitDemoMode();
    
protected voidonResume()

        super.onResume();
        exitDemoMode();
        mToast = Toast.makeText(mContext, R.string.help_text, Toast.LENGTH_LONG);
        mToast.show();
    
public booleanonTouch(android.view.View v, android.view.MotionEvent event)

        if (mToast != null) {
            mToast.cancel();
            mToast = null;
        }
        final int action = event.getAction();
        if (action == MotionEvent.ACTION_DOWN) {
            if (DEBUG) Log.d(TAG, "down");
            mHandler.postDelayed(mLongPressCheck, 500);
            final long now = SystemClock.uptimeMillis();
            if (now - mLastDownTime < 200) {
                toggleMode();
            }
            mLastDownTime = now;
            mLastDown.x = event.getX();
            mLastDown.y = event.getY();
            return true;
        }
        if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
            if (DEBUG) Log.d(TAG, "upOrCancel");
            mControllingColor = false;
            mHandler.removeCallbacks(mLongPressCheck);
        }
        if (action != MotionEvent.ACTION_MOVE) return false;

        float x = event.getX();
        float y = event.getY();
        if (Math.abs(mLastDown.x - x) > mTouchSlop || Math.abs(mLastDown.y - y) > mTouchSlop) {
            mHandler.removeCallbacks(mLongPressCheck);
        }
        x = Math.max(x, 0);
        y = Math.max(y, 0);
        final int h = mContent.getMeasuredHeight();
        final int w = mContent.getMeasuredWidth();
        x = Math.min(x, w);
        y = Math.min(y, h);

        y = h - y;
        x = w - x;

        if (mControllingColor) {
            final float hue = y / (h / 360);
            final float sat = 1 - (x / (float)w);
            final float val = x / (float)w;
            final int color = Color.HSVToColor(new float[]{hue, sat, val});
            if (DEBUG) Log.d(TAG, String.format("hsv=(%s,%s,%s) argb=#%08x", hue, sat, val, color));
            mContent.setBackgroundColor(color);
            return true;
        }

        final int hh = (int)x / (w / 12);
        if (hh != mHH) {
            mHH = hh;
            mBackground.removeCallbacks(mUpdateClock);
            mBackground.post(mUpdateClock);
        }

        final int mm = (int)y / (h / 60);
        if (mm != mMM) {
            mMM = mm;
            mBackground.removeCallbacks(mUpdateClock);
            mBackground.post(mUpdateClock);
        }

        final int batteryLevel = (int)y / (h / 101);
        if (batteryLevel != mBatteryLevel) {
            mBatteryLevel = batteryLevel;
            mBackground.removeCallbacks(mUpdateBattery);
            mBackground.post(mUpdateBattery);
        }

        final boolean batteryPlugged = x >= w / 2;
        if (batteryPlugged != mBatteryPlugged) {
            mBatteryPlugged = batteryPlugged;
            mBackground.removeCallbacks(mUpdateBattery);
            mBackground.post(mUpdateBattery);
        }

        final int mobileLevel = (int)y / (h / 10);
        if (mobileLevel != mMobileLevel) {
            mMobileLevel = mobileLevel;
            mBackground.removeCallbacks(mUpdateMobile);
            mBackground.post(mUpdateMobile);
        }

        final int wifiLevel = (int)y / (h / 10);
        if (wifiLevel != mWifiLevel) {
            mWifiLevel = wifiLevel;
            mBackground.removeCallbacks(mUpdateWifi);
            mBackground.post(mUpdateWifi);
        }

        final int statusSlots = (int)x / (w / 13);
        if (statusSlots != mStatusSlots) {
            mStatusSlots = statusSlots;
            mBackground.removeCallbacks(mUpdateStatus);
            mBackground.post(mUpdateStatus);
        }

        final int networkIcons = (int)x / (w / 4);
        if (networkIcons != mNetworkIcons) {
            mNetworkIcons = networkIcons;
            mBackground.removeCallbacks(mUpdateNetwork);
            mBackground.post(mUpdateNetwork);
        }

        final int mobileDataType = (int)y / (h / 9);
        if (mobileDataType != mMobileDataType) {
            mMobileDataType = mobileDataType;
            mBackground.removeCallbacks(mUpdateMobile);
            mBackground.post(mUpdateMobile);
        }
        return true;
    
private voidtoggleMode()

        if (DEBUG) Log.d(TAG, "toggleMode");
        mBarMode = (mBarMode + 1) % 3;
        updateMode();
    
private voidupdateMode()

        mBackground.removeCallbacks(mUpdateBarMode);
        mBackground.post(mUpdateBarMode);