Example usage for android.content Intent EXTRA_DOCK_STATE

List of usage examples for android.content Intent EXTRA_DOCK_STATE

Introduction

In this page you can find the example usage for android.content Intent EXTRA_DOCK_STATE.

Prototype

String EXTRA_DOCK_STATE

To view the source code for android.content Intent EXTRA_DOCK_STATE.

Click Source Link

Document

Used as an int extra field in android.content.Intent#ACTION_DOCK_EVENT intents to request the dock state.

Usage

From source file:com.slushpupie.deskclock.DeskClock.java

public DeskClock() {
    super();// w  w  w .  j av  a 2 s.c  o m
    // determine if multitouch is really supported
    try {
        getXMethod = MotionEvent.class.getMethod("getX", new Class[] { int.class });
        getYMethod = MotionEvent.class.getMethod("getY", new Class[] { int.class });
        supportMultiTouch = true;
    } catch (NoSuchMethodException nsme) {
        supportMultiTouch = false;
    }

    intentReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();

            if (Intent.ACTION_DOCK_EVENT.equals(action)) {
                int dockState = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, 0);
                switch (dockState) {
                case Intent.EXTRA_DOCK_STATE_UNDOCKED:
                    Log.d(LOG_TAG, "received EXTRA_DOCK_STATE_UNDOCKED");
                    if (prefsUndockExit)
                        finish();
                    else
                        Log.d(LOG_TAG, "Ignoring...");
                    break;
                case Intent.EXTRA_DOCK_STATE_DESK:
                    Log.d(LOG_TAG, "received EXTRA_DOCK_STATE_DESK");
                    break;
                }
            }
            if (Intent.ACTION_TIME_TICK.equals(action)) {
                updateTime();
            }
        }
    };
}