Example usage for android.content Intent ACTION_DOCK_EVENT

List of usage examples for android.content Intent ACTION_DOCK_EVENT

Introduction

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

Prototype

String ACTION_DOCK_EVENT

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

Click Source Link

Document

Broadcast Action: A sticky broadcast for changes in the physical docking state of the device.

Usage

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

public DeskClock() {
    super();/*  w ww . j  a v a2 s. co  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();
            }
        }
    };
}

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

/** Called when the activity becomes visible. */
@Override//from w  w w .j  av a  2 s.  c  om
public void onStart() {
    super.onStart();

    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_DOCK_EVENT);
    filter.addAction(Intent.ACTION_TIME_TICK);
    registerReceiver(intentReceiver, filter);

    isRunning = true;
    updateTime();
    handler.postDelayed(runMoveDisplay, prefsScreenSaverSpeed);
    if (prefsShowHints)
        Toast.makeText(getApplicationContext(), R.string.startup_toast, Toast.LENGTH_SHORT).show();
}