Search in sources :

Example 1 with LocalBluetoothAdapter

use of com.android.settingslib.bluetooth.LocalBluetoothAdapter in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class LocalBluetoothPreferences method shouldShowDialogInForeground.

static boolean shouldShowDialogInForeground(Context context, String deviceAddress, String deviceName) {
    LocalBluetoothManager manager = Utils.getLocalBtManager(context);
    if (manager == null) {
        if (DEBUG)
            Log.v(TAG, "manager == null - do not show dialog.");
        return false;
    }
    // If Bluetooth Settings is visible
    if (manager.isForegroundActivity()) {
        return true;
    }
    // If in appliance mode, do not show dialog in foreground.
    if ((context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_TYPE_APPLIANCE) == Configuration.UI_MODE_TYPE_APPLIANCE) {
        if (DEBUG)
            Log.v(TAG, "in appliance mode - do not show dialog.");
        return false;
    }
    long currentTimeMillis = System.currentTimeMillis();
    SharedPreferences sharedPreferences = getSharedPreferences(context);
    // If the device was in discoverABLE mode recently
    long lastDiscoverableEndTime = sharedPreferences.getLong(KEY_DISCOVERABLE_END_TIMESTAMP, 0);
    if ((lastDiscoverableEndTime + GRACE_PERIOD_TO_SHOW_DIALOGS_IN_FOREGROUND) > currentTimeMillis) {
        return true;
    }
    // If the device was discoverING recently
    LocalBluetoothAdapter adapter = manager.getBluetoothAdapter();
    if (adapter != null && adapter.isDiscovering()) {
        return true;
    } else if ((sharedPreferences.getLong(KEY_DISCOVERING_TIMESTAMP, 0) + GRACE_PERIOD_TO_SHOW_DIALOGS_IN_FOREGROUND) > currentTimeMillis) {
        return true;
    }
    // If the device was picked in the device picker recently
    if (deviceAddress != null) {
        String lastSelectedDevice = sharedPreferences.getString(KEY_LAST_SELECTED_DEVICE, null);
        if (deviceAddress.equals(lastSelectedDevice)) {
            long lastDeviceSelectedTime = sharedPreferences.getLong(KEY_LAST_SELECTED_DEVICE_TIME, 0);
            if ((lastDeviceSelectedTime + GRACE_PERIOD_TO_SHOW_DIALOGS_IN_FOREGROUND) > currentTimeMillis) {
                return true;
            }
        }
    }
    if (!TextUtils.isEmpty(deviceName)) {
        // If the device is a custom BT keyboard specifically for this device
        String packagedKeyboardName = context.getString(com.android.internal.R.string.config_packagedKeyboardName);
        if (deviceName.equals(packagedKeyboardName)) {
            if (DEBUG)
                Log.v(TAG, "showing dialog for packaged keyboard");
            return true;
        }
    }
    if (DEBUG)
        Log.v(TAG, "Found no reason to show the dialog - do not show dialog.");
    return false;
}
Also used : SharedPreferences(android.content.SharedPreferences) LocalBluetoothManager(com.android.settingslib.bluetooth.LocalBluetoothManager) LocalBluetoothAdapter(com.android.settingslib.bluetooth.LocalBluetoothAdapter)

Aggregations

SharedPreferences (android.content.SharedPreferences)1 LocalBluetoothAdapter (com.android.settingslib.bluetooth.LocalBluetoothAdapter)1 LocalBluetoothManager (com.android.settingslib.bluetooth.LocalBluetoothManager)1