Java Code Examples for android.content.Intent#EXTRA_DOCK_STATE_LE_DESK

The following examples show how to use android.content.Intent#EXTRA_DOCK_STATE_LE_DESK . These examples are extracted from open source projects. 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
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
private static boolean isDeskDockState(int state) {
    switch (state) {
        case Intent.EXTRA_DOCK_STATE_DESK:
        case Intent.EXTRA_DOCK_STATE_LE_DESK:
        case Intent.EXTRA_DOCK_STATE_HE_DESK:
            return true;
        default:
            return false;
    }
}
 
Example 3
Source Project: android_9.0.0_r45   File: DockObserver.java    License: Apache License 2.0 4 votes vote down vote up
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 4
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 5
@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);
  	}
  }