summaryrefslogtreecommitdiff
path: root/SetupWizard/src/com/android/car/setupwizard/bluetooth/BluetoothDeviceHierarchy.java
diff options
context:
space:
mode:
authorRakesh Iyer <rni@google.com>2017-02-22 02:21:18 +0000
committerRakesh Iyer <rni@google.com>2017-02-22 02:21:18 +0000
commit9391baedbf4ad645d7c125279a19d7a2b6b285f9 (patch)
tree4b825dc642cb6eb9a060e54bf8d69288fbee4904 /SetupWizard/src/com/android/car/setupwizard/bluetooth/BluetoothDeviceHierarchy.java
parent2066ca63ba8f0765ee30e1be14552866da35d8ac (diff)
downloadUserManagement-oreo-m2-release.tar.gz
Revert "Bluetooth configuration for SetupWizard."HEADandroid-wear-p-preview-2android-wear-8.1.0_r1android-wear-8.0.0_r1android-vts-8.1_r9android-vts-8.1_r8android-vts-8.1_r7android-vts-8.1_r6android-vts-8.1_r5android-vts-8.1_r4android-vts-8.1_r3android-vts-8.1_r14android-vts-8.1_r13android-vts-8.1_r12android-vts-8.1_r11android-vts-8.1_r10android-vts-8.0_r9android-vts-8.0_r8android-vts-8.0_r7android-vts-8.0_r6android-vts-8.0_r2android-vts-8.0_r13android-vts-8.0_r12android-vts-8.0_r11android-vts-8.0_r10android-vts-8.0_r1android-security-8.1.0_r93android-security-8.1.0_r92android-security-8.1.0_r91android-security-8.1.0_r90android-security-8.1.0_r89android-security-8.1.0_r88android-security-8.1.0_r87android-security-8.1.0_r86android-security-8.1.0_r85android-security-8.1.0_r84android-security-8.1.0_r83android-security-8.1.0_r82android-p-preview-3android-p-preview-2android-p-preview-1android-o-mr1-preview-2android-o-mr1-preview-1android-o-mr1-iot-release-smart-display-r9android-o-mr1-iot-release-smart-display-r8android-o-mr1-iot-release-smart-display-r5android-o-mr1-iot-release-smart-display-r40.1Jandroid-o-mr1-iot-release-smart-display-r4android-o-mr1-iot-release-smart-display-r39android-o-mr1-iot-release-smart-display-r30android-o-mr1-iot-release-smart-display-r3android-o-mr1-iot-release-smart-display-r22android-o-mr1-iot-release-smart-display-r14android-o-mr1-iot-release-smart-clock-r6android-o-mr1-iot-release-smart-clock-r2android-o-mr1-iot-release-smart-clock-fsiandroid-o-mr1-iot-release-smart-clock-fcsandroid-o-mr1-iot-release-cube_r2android-o-mr1-iot-release-cube-fsiandroid-o-mr1-iot-release-cube-fcsandroid-o-mr1-iot-release-1.0.8android-o-mr1-iot-release-1.0.7android-o-mr1-iot-release-1.0.5android-o-mr1-iot-release-1.0.4android-o-mr1-iot-release-1.0.3android-o-mr1-iot-release-1.0.2android-o-mr1-iot-release-1.0.14android-o-mr1-iot-release-1.0.13android-o-mr1-iot-release-1.0.12android-o-mr1-iot-release-1.0.10android-o-mr1-iot-release-1.0.1android-o-mr1-iot-release-1.0.0android-o-mr1-iot-preview-8android-o-mr1-iot-preview-7android-cts-8.1_r9android-cts-8.1_r8android-cts-8.1_r7android-cts-8.1_r6android-cts-8.1_r5android-cts-8.1_r4android-cts-8.1_r3android-cts-8.1_r25android-cts-8.1_r24android-cts-8.1_r23android-cts-8.1_r22android-cts-8.1_r21android-cts-8.1_r20android-cts-8.1_r2android-cts-8.1_r19android-cts-8.1_r18android-cts-8.1_r17android-cts-8.1_r16android-cts-8.1_r15android-cts-8.1_r14android-cts-8.1_r13android-cts-8.1_r12android-cts-8.1_r11android-cts-8.1_r10android-cts-8.1_r1android-8.1.0_r9android-8.1.0_r81android-8.1.0_r80android-8.1.0_r8android-8.1.0_r79android-8.1.0_r78android-8.1.0_r77android-8.1.0_r76android-8.1.0_r75android-8.1.0_r74android-8.1.0_r73android-8.1.0_r72android-8.1.0_r71android-8.1.0_r70android-8.1.0_r7android-8.1.0_r69android-8.1.0_r68android-8.1.0_r67android-8.1.0_r66android-8.1.0_r65android-8.1.0_r64android-8.1.0_r63android-8.1.0_r62android-8.1.0_r61android-8.1.0_r60android-8.1.0_r6android-8.1.0_r53android-8.1.0_r52android-8.1.0_r51android-8.1.0_r50android-8.1.0_r5android-8.1.0_r48android-8.1.0_r47android-8.1.0_r46android-8.1.0_r45android-8.1.0_r43android-8.1.0_r42android-8.1.0_r41android-8.1.0_r40android-8.1.0_r4android-8.1.0_r39android-8.1.0_r38android-8.1.0_r37android-8.1.0_r36android-8.1.0_r35android-8.1.0_r33android-8.1.0_r32android-8.1.0_r31android-8.1.0_r30android-8.1.0_r3android-8.1.0_r29android-8.1.0_r28android-8.1.0_r27android-8.1.0_r26android-8.1.0_r25android-8.1.0_r23android-8.1.0_r22android-8.1.0_r21android-8.1.0_r20android-8.1.0_r2android-8.1.0_r19android-8.1.0_r18android-8.1.0_r17android-8.1.0_r16android-8.1.0_r15android-8.1.0_r14android-8.1.0_r13android-8.1.0_r12android-8.1.0_r11android-8.1.0_r10android-8.1.0_r1android-8.0.0_r34android-8.0.0_r33android-8.0.0_r27android-8.0.0_r26android-8.0.0_r25android-8.0.0_r24android-8.0.0_r23android-8.0.0_r22android-8.0.0_r21security-oc-mr1-releasesdk-releaseoreo-vts-releaseoreo-mr1-wear-releaseoreo-mr1-vts-releaseoreo-mr1-security-releaseoreo-mr1-s1-releaseoreo-mr1-releaseoreo-mr1-iot-releaseoreo-mr1-devoreo-mr1-cuttlefish-testingoreo-mr1-cts-releaseoreo-mr1-1.2-iot-releaseoreo-m8-releaseoreo-m7-releaseoreo-m6-s4-releaseoreo-m6-s3-releaseoreo-m6-s2-releaseoreo-m5-releaseoreo-m4-s9-releaseoreo-m4-s8-releaseoreo-m4-s7-releaseoreo-m4-s6-releaseoreo-m4-s5-releaseoreo-m4-s4-releaseoreo-m4-s3-releaseoreo-m4-s2-releaseoreo-m4-s12-releaseoreo-m4-s11-releaseoreo-m4-s10-releaseoreo-m4-s1-releaseoreo-m3-releaseoreo-m2-s5-releaseoreo-m2-s4-releaseoreo-m2-s3-releaseoreo-m2-s2-releaseoreo-m2-s1-releaseoreo-m2-releaseoreo-dr3-releaseoreo-dr2-releaseoreo-dr1-releaseoreo-dr1-devoreo-devo-mr1-iot-preview-8o-mr1-iot-preview-7mastermain
This reverts commit 2066ca63ba8f0765ee30e1be14552866da35d8ac. Change-Id: Icbec4a3c404729dc6489d65fc3fff975d55f7d71
Diffstat (limited to 'SetupWizard/src/com/android/car/setupwizard/bluetooth/BluetoothDeviceHierarchy.java')
-rw-r--r--SetupWizard/src/com/android/car/setupwizard/bluetooth/BluetoothDeviceHierarchy.java277
1 files changed, 0 insertions, 277 deletions
diff --git a/SetupWizard/src/com/android/car/setupwizard/bluetooth/BluetoothDeviceHierarchy.java b/SetupWizard/src/com/android/car/setupwizard/bluetooth/BluetoothDeviceHierarchy.java
deleted file mode 100644
index 02f76bf..0000000
--- a/SetupWizard/src/com/android/car/setupwizard/bluetooth/BluetoothDeviceHierarchy.java
+++ /dev/null
@@ -1,277 +0,0 @@
-/*
- * Copyright (C) 2017 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.car.setupwizard.bluetooth;
-
-import android.bluetooth.BluetoothClass.Device;
-import android.bluetooth.BluetoothDevice;
-import android.content.Context;
-import android.content.res.ColorStateList;
-import android.content.res.TypedArray;
-import android.graphics.drawable.Drawable;
-import android.support.annotation.DrawableRes;
-import android.support.annotation.IntDef;
-import android.support.annotation.Nullable;
-import android.support.annotation.VisibleForTesting;
-import android.text.TextUtils;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.View;
-
-import com.android.car.setupwizard.R;
-
-import com.android.setupwizardlib.items.AbstractItemHierarchy;
-import com.android.setupwizardlib.items.IItem;
-import com.android.setupwizardlib.items.Item;
-import com.android.setupwizardlib.items.ItemHierarchy;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-/**
- * An item hierarchy that represents a list of Bluetooth devices.
- */
-public class BluetoothDeviceHierarchy extends AbstractItemHierarchy {
- private static final String TAG = "BtDeviceHierarchy";
-
- /**
- * A set of all discovered bluetooth devices. The key of this map is the device's MAC address.
- */
- private final HashMap<String, BluetoothItem> mItems = new HashMap<>();
-
- /**
- * A list of all discovered bluetooth devices' MAC addresses. This list is sorted in the order
- * that the devices were discovered in.
- */
- private final List<String> mAddresses = new ArrayList<>();
-
- public BluetoothDeviceHierarchy(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
-
- /**
- * Clears the current list of all bluetooth devices.
- */
- public void clearAllDevices() {
- mItems.clear();
- mAddresses.clear();
- notifyChanged();
- }
-
- /**
- * Adds the given {@link BluetoothDevice} to be displayed. If the device has already been
- * added before, its information is updated based on the given {@code BluetoothDevice}.
- */
- public void addOrUpdateDevice(Context context, @Nullable BluetoothDevice device) {
- if (device == null) {
- return;
- }
-
- String address = device.getAddress();
- BluetoothItem item;
-
- if (mItems.containsKey(address)) {
- item = mItems.get(address);
- } else {
- // First time encountering this address, so keep track of it.
- mAddresses.add(address);
-
- int id = View.generateViewId();
- if (id >= 0x00ffffff) {
- // View.generateViewId returns an incrementing number from 1 to 0x00ffffff.
- // Since we are generating view IDs without recycling, it is theoretically possible
- // for the ID space to run out if the user encounters enough bluetooth devices.
- // Just log if this happens.
- Log.e(TAG, "Ran out of IDs to use for bluetooth item IDs");
- }
- item = new BluetoothItem(id);
- }
-
- item.update(context, device);
- mItems.put(address, item);
-
- notifyChanged();
- }
-
- @Override
- public ItemHierarchy findItemById(int id) {
- if (id == getId()) {
- return this;
- }
-
- // Child items have generated hash code IDs. Don't try to find those.
- return null;
- }
-
- @Override
- public int getCount() {
- return mItems.size();
- }
-
- @Override
- public IItem getItemAt(int position) {
- return mItems.get(mAddresses.get(position));
- }
-
- /**
- * A {@link Item} that is linked to a particular {@link BluetoothDevice} and is responsible
- * for binding this information to a View to be displayed.
- */
- public static class BluetoothItem extends Item {
- private BluetoothDevice mDevice;
-
- /**
- * Whether or not the icon for this particular BluetoothDevice has been updated to reflect
- * the type of Bluetooth device this is.
- */
- private boolean mIconUpdated;
-
- public static final int CONNECTION_STATE_DISCONNECTING = 0;
- public static final int CONNECTION_STATE_CONNECTING = 1;
- public static final int CONNECTION_STATE_CANCELLING = 2;
-
- @IntDef({
- CONNECTION_STATE_DISCONNECTING,
- CONNECTION_STATE_CONNECTING,
- CONNECTION_STATE_CANCELLING })
- public @interface ConnectionState {}
-
- public BluetoothItem(int id) {
- setId(id);
- }
-
- /**
- * Immediately updates the connection state of the device that is represented by this
- * {@link BluetoothItem}. This state is not necessarily tied to the bonded state that
- * will be returned by the {@link BluetoothDevice} associated with this item.
- */
- public void updateConnectionState(Context context, @ConnectionState int state) {
- if (mDevice == null) {
- return;
- }
-
- switch (state) {
- case CONNECTION_STATE_DISCONNECTING:
- setSummary(context.getString(R.string.bluetooth_device_disconnecting));
- break;
-
- case CONNECTION_STATE_CONNECTING:
- setSummary(context.getString(R.string.bluetooth_device_connecting));
- break;
-
- case CONNECTION_STATE_CANCELLING:
- setSummary(context.getString(R.string.bluetooth_device_cancelling));
- break;
-
- default:
- // Do nothing.
- }
- }
-
- /**
- * Associate a {@link BluetoothDevice} with this {@link BluetoothItem}.
- */
- public void update(Context context, BluetoothDevice device) {
- mIconUpdated = false;
- mDevice = device;
-
- String name = mDevice.getName();
- setTitle(TextUtils.isEmpty(name) ? mDevice.getAddress() : name);
-
- switch (mDevice.getBondState()) {
- case BluetoothDevice.BOND_BONDED:
- setSummary(context.getString(R.string.bluetooth_device_connected));
- break;
-
- case BluetoothDevice.BOND_BONDING:
- setSummary(context.getString(R.string.bluetooth_device_connecting));
- break;
-
- default:
- setSummary(null);
- }
- }
-
- /**
- * Returns the {@link BluetoothDevice} set via {@link #update(Context, BluetoothDevice)}.
- */
- public BluetoothDevice getBluetoothDevice() {
- return mDevice;
- }
-
- @Override
- public void onBindView(View view) {
- if (mIconUpdated && getIcon() != null) {
- super.onBindView(view);
- return;
- }
-
- Context context = view.getContext();
- TypedArray a = context.obtainStyledAttributes(
- new int[] { R.attr.suwListItemIconColor });
-
- try {
- ColorStateList bluetoothIconColor = a.getColorStateList(0);
- Drawable bluetoothIcon = getDeviceIcon(context).mutate();
- bluetoothIcon.setTintList(bluetoothIconColor);
- setIcon(bluetoothIcon);
- } finally {
- a.recycle();
- }
-
- mIconUpdated = true;
-
- super.onBindView(view);
- }
-
- /**
- * Returns an appropriate {@link Drawable} to use as the icon for the bluetooth device
- * associated with this {@link BluetoothItem}.
- */
- private Drawable getDeviceIcon(Context context) {
- if (mDevice == null) {
- return context.getDrawable(R.drawable.ic_bluetooth_item);
- }
-
- @DrawableRes int deviceIcon;
- switch (mDevice.getBluetoothClass().getDeviceClass()) {
- case Device.AUDIO_VIDEO_HEADPHONES:
- case Device.AUDIO_VIDEO_WEARABLE_HEADSET:
- deviceIcon = R.drawable.ic_headset;
- break;
-
- case Device.COMPUTER_DESKTOP:
- case Device.COMPUTER_LAPTOP:
- deviceIcon = R.drawable.ic_computer;
- break;
-
- case Device.PHONE_SMART:
- deviceIcon = R.drawable.ic_smartphone;
- break;
-
- case Device.WEARABLE_WRIST_WATCH:
- deviceIcon = R.drawable.ic_watch;
- break;
-
- default:
- deviceIcon = R.drawable.ic_bluetooth_item;
- }
-
- return context.getDrawable(deviceIcon);
- }
- }
-}