Java Code Examples for android.content.Intent#EXTRA_DOCK_STATE_UNDOCKED
The following examples show how to use
android.content.Intent#EXTRA_DOCK_STATE_UNDOCKED .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MyActivity.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 6 votes |
private void listing6_19() { // Listing 6-19: Determining docking state boolean isDocked = false; boolean isCar = false; boolean isDesk = false; IntentFilter dockIntentFilter = new IntentFilter(Intent.ACTION_DOCK_EVENT); Intent dock = registerReceiver(null, dockIntentFilter); if (dock != null) { int dockState = dock.getIntExtra(Intent.EXTRA_DOCK_STATE, Intent.EXTRA_DOCK_STATE_UNDOCKED); isDocked = dockState != Intent.EXTRA_DOCK_STATE_UNDOCKED; isCar = dockState == Intent.EXTRA_DOCK_STATE_CAR; isDesk = dockState == Intent.EXTRA_DOCK_STATE_DESK || dockState == Intent.EXTRA_DOCK_STATE_LE_DESK || dockState == Intent.EXTRA_DOCK_STATE_HE_DESK; } }
Example 2
Source File: DockObserver.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public void onBootPhase(int phase) { if (phase == PHASE_ACTIVITY_MANAGER_READY) { synchronized (mLock) { mSystemReady = true; // don't bother broadcasting undocked here if (mReportedDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED) { updateLocked(); } } } }
Example 3
Source File: DockingStateMonitor.java From habpanelviewer with GNU General Public License v3.0 | 5 votes |
@Override public synchronized void updateFromPreferences(SharedPreferences prefs) { mDockStateItem = prefs.getString(Constants.PREF_DOCKING_STATE_ITEM, ""); if (mDockStateEnabled != prefs.getBoolean(Constants.PREF_DOCKING_STATE_ENABLED, false)) { mDockStateEnabled = !mDockStateEnabled; if (mDockStateEnabled) { Log.d(TAG, "registering docking state receiver..."); mCtx.registerReceiver(mDockStateReceiver, mIntentFilter); Intent dockStatus = mCtx.registerReceiver(null, mIntentFilter); Log.d(TAG, "updateFromPreferences: dockStatus=" + dockStatus); int dockState = (dockStatus == null ? Intent.EXTRA_DOCK_STATE_UNDOCKED : dockStatus.getIntExtra(Intent.EXTRA_DOCK_STATE, -1)); Log.d(TAG, "updateFromPreferences: dockState=" + dockStatus); mDocked = dockState != Intent.EXTRA_DOCK_STATE_UNDOCKED; mServerConnection.updateState(mDockStateItem, mDocked ? "CLOSED" : "OPEN"); } else { Log.d(TAG, "unregistering docking state receiver..."); mCtx.unregisterReceiver(mDockStateReceiver); } } mServerConnection.subscribeItems(this, mDockStateItem); }
Example 4
Source File: DockObserver.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private void handleDockStateChange() { synchronized (mLock) { Slog.i(TAG, "Dock state changed from " + mPreviousDockState + " to " + mReportedDockState); final int previousDockState = mPreviousDockState; mPreviousDockState = mReportedDockState; // Skip the dock intent if not yet provisioned. final ContentResolver cr = getContext().getContentResolver(); if (Settings.Global.getInt(cr, Settings.Global.DEVICE_PROVISIONED, 0) == 0) { Slog.i(TAG, "Device not provisioned, skipping dock broadcast"); return; } // Pack up the values and broadcast them to everyone Intent intent = new Intent(Intent.ACTION_DOCK_EVENT); intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); intent.putExtra(Intent.EXTRA_DOCK_STATE, mReportedDockState); boolean dockSoundsEnabled = Settings.Global.getInt(cr, Settings.Global.DOCK_SOUNDS_ENABLED, 1) == 1; boolean dockSoundsEnabledWhenAccessibility = Settings.Global.getInt(cr, Settings.Global.DOCK_SOUNDS_ENABLED_WHEN_ACCESSIBILITY, 1) == 1; boolean accessibilityEnabled = Settings.Secure.getInt(cr, Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1; // Play a sound to provide feedback to confirm dock connection. // Particularly useful for flaky contact pins... if ((dockSoundsEnabled) || (accessibilityEnabled && dockSoundsEnabledWhenAccessibility)) { String whichSound = null; if (mReportedDockState == Intent.EXTRA_DOCK_STATE_UNDOCKED) { if ((previousDockState == Intent.EXTRA_DOCK_STATE_DESK) || (previousDockState == Intent.EXTRA_DOCK_STATE_LE_DESK) || (previousDockState == Intent.EXTRA_DOCK_STATE_HE_DESK)) { whichSound = Settings.Global.DESK_UNDOCK_SOUND; } else if (previousDockState == Intent.EXTRA_DOCK_STATE_CAR) { whichSound = Settings.Global.CAR_UNDOCK_SOUND; } } else { if ((mReportedDockState == Intent.EXTRA_DOCK_STATE_DESK) || (mReportedDockState == Intent.EXTRA_DOCK_STATE_LE_DESK) || (mReportedDockState == Intent.EXTRA_DOCK_STATE_HE_DESK)) { whichSound = Settings.Global.DESK_DOCK_SOUND; } else if (mReportedDockState == Intent.EXTRA_DOCK_STATE_CAR) { whichSound = Settings.Global.CAR_DOCK_SOUND; } } if (whichSound != null) { final String soundPath = Settings.Global.getString(cr, whichSound); if (soundPath != null) { final Uri soundUri = Uri.parse("file://" + soundPath); if (soundUri != null) { final Ringtone sfx = RingtoneManager.getRingtone( getContext(), soundUri); if (sfx != null) { sfx.setStreamType(AudioManager.STREAM_SYSTEM); sfx.play(); } } } } } // Send the dock event intent. // There are many components in the system watching for this so as to // adjust audio routing, screen orientation, etc. getContext().sendStickyBroadcastAsUser(intent, UserHandle.ALL); } }
Example 5
Source File: PowerManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * Returns true if the device should automatically nap and start dreaming when the user * activity timeout has expired and it's bedtime. */ private boolean shouldNapAtBedTimeLocked() { return mDreamsActivateOnSleepSetting || (mDreamsActivateOnDockSetting && mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED); }
Example 6
Source File: UiModeManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
void updateLocked(int enableFlags, int disableFlags) { String action = null; String oldAction = null; if (mLastBroadcastState == Intent.EXTRA_DOCK_STATE_CAR) { adjustStatusBarCarModeLocked(); oldAction = UiModeManager.ACTION_EXIT_CAR_MODE; } else if (isDeskDockState(mLastBroadcastState)) { oldAction = UiModeManager.ACTION_EXIT_DESK_MODE; } if (mCarModeEnabled) { if (mLastBroadcastState != Intent.EXTRA_DOCK_STATE_CAR) { adjustStatusBarCarModeLocked(); if (oldAction != null) { sendForegroundBroadcastToAllUsers(oldAction); } mLastBroadcastState = Intent.EXTRA_DOCK_STATE_CAR; action = UiModeManager.ACTION_ENTER_CAR_MODE; } } else if (isDeskDockState(mDockState)) { if (!isDeskDockState(mLastBroadcastState)) { if (oldAction != null) { sendForegroundBroadcastToAllUsers(oldAction); } mLastBroadcastState = mDockState; action = UiModeManager.ACTION_ENTER_DESK_MODE; } } else { mLastBroadcastState = Intent.EXTRA_DOCK_STATE_UNDOCKED; action = oldAction; } if (action != null) { if (LOG) { Slog.v(TAG, String.format( "updateLocked: preparing broadcast: action=%s enable=0x%08x disable=0x%08x", action, enableFlags, disableFlags)); } // Send the ordered broadcast; the result receiver will receive after all // broadcasts have been sent. If any broadcast receiver changes the result // code from the initial value of RESULT_OK, then the result receiver will // not launch the corresponding dock application. This gives apps a chance // to override the behavior and stay in their app even when the device is // placed into a dock. Intent intent = new Intent(action); intent.putExtra("enableFlags", enableFlags); intent.putExtra("disableFlags", disableFlags); intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); getContext().sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, null, mResultReceiver, null, Activity.RESULT_OK, null, null); // Attempting to make this transition a little more clean, we are going // to hold off on doing a configuration change until we have finished // the broadcast and started the home activity. mHoldingConfiguration = true; updateConfigurationLocked(); } else { String category = null; if (mCarModeEnabled) { if (mEnableCarDockLaunch && (enableFlags & UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) { category = Intent.CATEGORY_CAR_DOCK; } } else if (isDeskDockState(mDockState)) { if (ENABLE_LAUNCH_DESK_DOCK_APP && (enableFlags & UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) { category = Intent.CATEGORY_DESK_DOCK; } } else { if ((disableFlags & UiModeManager.DISABLE_CAR_MODE_GO_HOME) != 0) { category = Intent.CATEGORY_HOME; } } if (LOG) { Slog.v(TAG, "updateLocked: null action, mDockState=" + mDockState +", category=" + category); } sendConfigurationAndStartDreamOrDockAppLocked(category); } // keep screen on when charging and in car mode boolean keepScreenOn = mCharging && ((mCarModeEnabled && mCarModeKeepsScreenOn && (mCarModeEnableFlags & UiModeManager.ENABLE_CAR_MODE_ALLOW_SLEEP) == 0) || (mCurUiMode == Configuration.UI_MODE_TYPE_DESK && mDeskModeKeepsScreenOn)); if (keepScreenOn != mWakeLock.isHeld()) { if (keepScreenOn) { mWakeLock.acquire(); } else { mWakeLock.release(); } } }
Example 7
Source File: EventPreferencesPeripherals.java From PhoneProfilesPlus with Apache License 2.0 | 4 votes |
void doHandleEvent(EventsHandler eventsHandler/*, boolean forRestartEvents*/) { if (_enabled) { int oldSensorPassed = getSensorPassed(); if (Event.isEventPreferenceAllowed(EventPreferencesPeripherals.PREF_EVENT_PERIPHERAL_ENABLED, eventsHandler.context).allowed == PreferenceAllowed.PREFERENCE_ALLOWED) { if ((_peripheralType == EventPreferencesPeripherals.PERIPHERAL_TYPE_DESK_DOCK) || (_peripheralType == EventPreferencesPeripherals.PERIPHERAL_TYPE_CAR_DOCK)) { // get dock status IntentFilter iFilter = new IntentFilter(Intent.ACTION_DOCK_EVENT); Intent dockStatus = eventsHandler.context.registerReceiver(null, iFilter); if (dockStatus != null) { int dockState = dockStatus.getIntExtra(Intent.EXTRA_DOCK_STATE, -1); boolean isDocked = dockState != Intent.EXTRA_DOCK_STATE_UNDOCKED; boolean isCar = dockState == Intent.EXTRA_DOCK_STATE_CAR; boolean isDesk = dockState == Intent.EXTRA_DOCK_STATE_DESK || dockState == Intent.EXTRA_DOCK_STATE_LE_DESK || dockState == Intent.EXTRA_DOCK_STATE_HE_DESK; if (isDocked) { if ((_peripheralType == EventPreferencesPeripherals.PERIPHERAL_TYPE_DESK_DOCK) && isDesk) eventsHandler.peripheralPassed = true; else eventsHandler.peripheralPassed = (_peripheralType == EventPreferencesPeripherals.PERIPHERAL_TYPE_CAR_DOCK) && isCar; } else eventsHandler.peripheralPassed = false; //eventStart = eventStart && peripheralPassed; } else eventsHandler.notAllowedPeripheral = true; } else if ((_peripheralType == EventPreferencesPeripherals.PERIPHERAL_TYPE_WIRED_HEADSET) || (_peripheralType == EventPreferencesPeripherals.PERIPHERAL_TYPE_BLUETOOTH_HEADSET) || (_peripheralType == EventPreferencesPeripherals.PERIPHERAL_TYPE_HEADPHONES)) { boolean wiredHeadsetConnected = ApplicationPreferences.prefWiredHeadsetConnected; boolean wiredHeadsetMicrophone = ApplicationPreferences.prefWiredHeadsetMicrophone; boolean bluetoothHeadsetConnected = ApplicationPreferences.prefBluetoothHeadsetConnected; boolean bluetoothHeadsetMicrophone = ApplicationPreferences.prefBluetoothHeadsetMicrophone; eventsHandler.peripheralPassed = false; if (wiredHeadsetConnected) { if ((_peripheralType == EventPreferencesPeripherals.PERIPHERAL_TYPE_WIRED_HEADSET) && wiredHeadsetMicrophone) eventsHandler.peripheralPassed = true; else if ((_peripheralType == EventPreferencesPeripherals.PERIPHERAL_TYPE_HEADPHONES) && (!wiredHeadsetMicrophone)) eventsHandler.peripheralPassed = true; } if (bluetoothHeadsetConnected) { if ((_peripheralType == EventPreferencesPeripherals.PERIPHERAL_TYPE_BLUETOOTH_HEADSET) && bluetoothHeadsetMicrophone) eventsHandler.peripheralPassed = true; } //eventStart = eventStart && peripheralPassed; } if (!eventsHandler.notAllowedPeripheral) { if (eventsHandler.peripheralPassed) setSensorPassed(EventPreferences.SENSOR_PASSED_PASSED); else setSensorPassed(EventPreferences.SENSOR_PASSED_NOT_PASSED); } } else eventsHandler.notAllowedPeripheral = true; int newSensorPassed = getSensorPassed() & (~EventPreferences.SENSOR_PASSED_WAITING); if (oldSensorPassed != newSensorPassed) { //PPApplication.logE("[TEST BATTERY] EventPreferencesPeripherals.doHandleEvent", "peripherals - sensor pass changed"); setSensorPassed(newSensorPassed); DatabaseHandler.getInstance(eventsHandler.context).updateEventSensorPassed(_event, DatabaseHandler.ETYPE_PERIPHERAL); } } }
Example 8
Source File: DockReceiver.java From screenstandby with GNU General Public License v2.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { Logger.Log(context, intent); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); Boolean useDock = prefs.getBoolean("dockdetection", false); launchPackage = prefs.getString("dockrunpackage", ""); killPackage = prefs.getBoolean("dockrun_close", false); Boolean screenOff = false; if (useDock) { int state = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, Intent.EXTRA_DOCK_STATE_UNDOCKED); //if (state != Intent.EXTRA_DOCK_STATE_UNDOCKED) //{ if (prefs.getBoolean("dockatrix", false)) { if (getDeviceState("whisper_hid").equals("1") && getDeviceState("smartdock").equals("1")) { String docktype = getDeviceState("extdock"); if (docktype.equals("3")) //LAPDOCK { if (prefs.getBoolean("dockatrix_lapdock", true)) { ScreenOff(context); Toast.makeText(context, "Atrix Lapdock detected", Toast.LENGTH_SHORT).show(); } } else if (docktype.equals("4")) //HD DOCK { if (prefs.getBoolean("dockatrix_hddock", true)) { ScreenOff(context); Toast.makeText(context, "Atrix HD dock detected", Toast.LENGTH_SHORT).show(); } } } else ScreenOn(context); return; } //} switch (state) { case Intent.EXTRA_DOCK_STATE_CAR: screenOff = prefs.getBoolean("dockcar", true); break; case Intent.EXTRA_DOCK_STATE_DESK: screenOff = prefs.getBoolean("dockdesk", true); break; case Intent.EXTRA_DOCK_STATE_HE_DESK: screenOff = prefs.getBoolean("dockanalog", true); break; case Intent.EXTRA_DOCK_STATE_LE_DESK: screenOff = prefs.getBoolean("dockdigital", true); break; case Intent.EXTRA_DOCK_STATE_UNDOCKED: if (prefs.getBoolean("dockremoval", true)) ScreenOn(context); return; } if (screenOff) ScreenOff(context); } }