diff options
11 files changed, 195 insertions, 60 deletions
diff --git a/packages/CompanionDeviceManager/AndroidManifest.xml b/packages/CompanionDeviceManager/AndroidManifest.xml index 3eede5454d6f..65cac09a09b3 100644 --- a/packages/CompanionDeviceManager/AndroidManifest.xml +++ b/packages/CompanionDeviceManager/AndroidManifest.xml @@ -41,7 +41,7 @@ <activity android:name=".DeviceChooserActivity" - android:theme="@*android:style/Theme.Dialog.NoFrame" + android:theme="@style/ChooserActivity" android:permission="android.permission.BIND_COMPANION_DEVICE_MANAGER_SERVICE"> <!--TODO include url scheme filter similar to PrintSpooler --> <intent-filter> diff --git a/packages/CompanionDeviceManager/res/drawable/dialog_background.xml b/packages/CompanionDeviceManager/res/drawable/dialog_background.xml new file mode 100644 index 000000000000..af2c83f7d8b3 --- /dev/null +++ b/packages/CompanionDeviceManager/res/drawable/dialog_background.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2017 The Android Open Source Project + + 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. +--> + +<inset xmlns:android="http://schemas.android.com/apk/res/android"> + <shape android:shape="rectangle"> + <corners android:radius="2dp" /> + <solid android:color="?android:attr/colorBackground" /> + </shape> +</inset> diff --git a/packages/CompanionDeviceManager/res/layout/buttons.xml b/packages/CompanionDeviceManager/res/layout/buttons.xml new file mode 100644 index 000000000000..350a791ac30e --- /dev/null +++ b/packages/CompanionDeviceManager/res/layout/buttons.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2017 The Android Open Source Project + + 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. +--> + + +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/buttons" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal" + android:layout_alignParentBottom="true" + android:layout_alignParentEnd="true" + android:gravity="end" +> + <Button + android:id="@+id/button_cancel" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/cancel" + style="@android:style/Widget.Material.Light.Button.Borderless.Colored" + /> + <Button + android:id="@+id/button_pair" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/pair" + style="@android:style/Widget.Material.Light.Button.Borderless.Colored" + /> +</LinearLayout>
\ No newline at end of file diff --git a/packages/CompanionDeviceManager/res/layout/device_chooser.xml b/packages/CompanionDeviceManager/res/layout/device_chooser.xml index ee08582ba2df..88de33f89442 100644 --- a/packages/CompanionDeviceManager/res/layout/device_chooser.xml +++ b/packages/CompanionDeviceManager/res/layout/device_chooser.xml @@ -16,52 +16,22 @@ <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="vertical" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:layout_weight="0.1" + android:id="@+id/container" + android:layout_height="400dp" + style="@style/ContainerLayout" > - <TextView - android:id="@+id/title" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:textColor="@android:color/black" - style="@*android:style/TextAppearance.Widget.Toolbar.Title" - /> + <include layout="@layout/title" /> <ListView android:id="@+id/device_list" android:layout_width="match_parent" - android:layout_height="wrap_content" + android:layout_height="match_parent" android:layout_below="@+id/title" android:layout_above="@+id/buttons" style="@android:style/Widget.Material.Light.ListView" /> - <LinearLayout - android:id="@+id/buttons" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:orientation="horizontal" - android:layout_alignParentBottom="true" - android:layout_alignParentEnd="true" - android:gravity="end" - > - <Button - android:id="@+id/button_cancel" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="Cancel" - style="@android:style/Widget.Material.Light.Button.Borderless.Colored" - /> - <Button - android:id="@+id/button_pair" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="Pair" - style="@android:style/Widget.Material.Light.Button.Borderless.Colored" - /> - </LinearLayout> + <include layout="@layout/buttons" /> </RelativeLayout>
\ No newline at end of file diff --git a/packages/CompanionDeviceManager/res/layout/device_confirmation.xml b/packages/CompanionDeviceManager/res/layout/device_confirmation.xml new file mode 100644 index 000000000000..7cde41ac2894 --- /dev/null +++ b/packages/CompanionDeviceManager/res/layout/device_confirmation.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2017 The Android Open Source Project + + 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. +--> + +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/container" + android:layout_height="wrap_content" + style="@style/ContainerLayout" + > + + <include layout="@layout/title" /> + + <include layout="@layout/buttons" /> + +</LinearLayout>
\ No newline at end of file diff --git a/packages/CompanionDeviceManager/res/layout/title.xml b/packages/CompanionDeviceManager/res/layout/title.xml new file mode 100644 index 000000000000..dfa71e243815 --- /dev/null +++ b/packages/CompanionDeviceManager/res/layout/title.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2017 The Android Open Source Project + + 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. +--> + + +<TextView + xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/title" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textColor="@android:color/black" + style="@*android:style/TextAppearance.Widget.Toolbar.Title" +/>
\ No newline at end of file diff --git a/packages/CompanionDeviceManager/res/values/strings.xml b/packages/CompanionDeviceManager/res/values/strings.xml index c4195b5090a3..469c1fbf22ad 100644 --- a/packages/CompanionDeviceManager/res/values/strings.xml +++ b/packages/CompanionDeviceManager/res/values/strings.xml @@ -22,4 +22,13 @@ <!-- Title of the device selection dialog. --> <string name="chooser_title">Pair with <strong><xliff:g id="app_name" example="Android Wear">%1$s</xliff:g></strong> via Bluetooth?</string> + <!-- Title of the device pairing confirmation dialog. --> + <string name="confirmation_title">Pair <strong><xliff:g id="app_name" example="Android Wear">%1$s</xliff:g></strong> with <strong><xliff:g id="device_name" example="ASUS ZenWatch 2">%2$s</xliff:g></strong> via Bluetooth?</string> + + <!-- Label on the pair button in a companion device chooser/confirmation dialog --> + <string name="pair">Pair</string> + + <!-- Label on the cancel button in a companion device chooser/confirmation dialog --> + <string name="cancel">Cancel</string> + </resources> diff --git a/packages/CompanionDeviceManager/res/values/styles.xml b/packages/CompanionDeviceManager/res/values/styles.xml new file mode 100644 index 000000000000..9dced47bb36f --- /dev/null +++ b/packages/CompanionDeviceManager/res/values/styles.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2017 The Android Open Source Project + + 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. +--> + +<resources> + <style name="ContainerLayout"> + <item name="android:orientation">vertical</item> + <item name="android:layout_width">match_parent</item> + <item name="android:elevation">16dp</item> + <item name="android:background">@drawable/dialog_background</item> + <item name="android:paddingTop">18dip</item> + <item name="android:paddingStart">20dip</item> + <item name="android:paddingEnd">16dip</item> + <item name="android:paddingBottom">16dip</item> + <item name="android:layout_gravity">center</item> + </style> +</resources>
\ No newline at end of file diff --git a/packages/CompanionDeviceManager/res/values/themes.xml b/packages/CompanionDeviceManager/res/values/themes.xml index 465f8fc6d5ac..e3fc67c50d75 100644 --- a/packages/CompanionDeviceManager/res/values/themes.xml +++ b/packages/CompanionDeviceManager/res/values/themes.xml @@ -16,10 +16,11 @@ <resources> - <!--TODO--> - <!--<style name="Theme.ChooserActivity" parent="@*android:style/Theme.Dialog.NoFrame">--> - <!--<!–<item name="android:windowBackground">@android:color/light_grey</item>–>--> - <!--<item name="android:backgroundColor">@android:color/light_grey</item>--> - <!--</style>--> + <style name="ChooserActivity" + parent="@android:style/Theme.DeviceDefault.Light.Dialog.NoActionBar"> + <item name="*android:windowFixedHeightMajor">100%</item> + <item name="*android:windowFixedHeightMinor">100%</item> + <item name="android:windowBackground">@android:color/transparent</item> + </style> </resources> diff --git a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceChooserActivity.java b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceChooserActivity.java index c95f940807a9..8a970da474e6 100644 --- a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceChooserActivity.java +++ b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceChooserActivity.java @@ -16,6 +16,8 @@ package com.android.companiondevicemanager; +import static android.companion.BluetoothDeviceFilterUtils.getDeviceDisplayName; + import android.app.Activity; import android.bluetooth.BluetoothDevice; import android.companion.CompanionDeviceManager; @@ -23,7 +25,6 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.content.res.Resources; import android.database.DataSetObserver; -import android.graphics.Color; import android.os.Bundle; import android.text.Html; import android.util.Log; @@ -49,29 +50,38 @@ public class DeviceChooserActivity extends Activity { if (DEBUG) Log.i(LOG_TAG, "Started with intent " + getIntent()); - setContentView(R.layout.device_chooser); - setTitle(Html.fromHtml(getString(R.string.chooser_title, getCallingAppName()), 0)); - getWindow().getDecorView().getRootView().setBackgroundColor(Color.LTGRAY); //TODO theme - if (getService().mDevicesFound.isEmpty()) { Log.e(LOG_TAG, "About to show UI, but no devices to show"); } - final DeviceDiscoveryService.DevicesAdapter adapter = getService().mDevicesAdapter; - mDeviceListView = (ListView) findViewById(R.id.device_list); - mDeviceListView.setAdapter(adapter); - mDeviceListView.addFooterView(getProgressBar(), null, false); + if (getService().mRequest.isSingleDevice()) { + setContentView(R.layout.device_confirmation); + final BluetoothDevice selectedDevice = getService().mDevicesFound.get(0); + setTitle(Html.fromHtml(getString( + R.string.confirmation_title, + getCallingAppName(), + getDeviceDisplayName(selectedDevice)), 0)); + getService().mSelectedDevice = selectedDevice; + } else { + setContentView(R.layout.device_chooser); + setTitle(Html.fromHtml(getString(R.string.chooser_title, getCallingAppName()), 0)); + mDeviceListView = (ListView) findViewById(R.id.device_list); + final DeviceDiscoveryService.DevicesAdapter adapter = getService().mDevicesAdapter; + mDeviceListView.setAdapter(adapter); + adapter.registerDataSetObserver(new DataSetObserver() { + @Override + public void onChanged() { + updatePairButtonEnabled(); + } + }); + mDeviceListView.addFooterView(getProgressBar(), null, false); + } mPairButton = findViewById(R.id.button_pair); mPairButton.setOnClickListener((view) -> onPairTapped(getService().mSelectedDevice)); - adapter.registerDataSetObserver(new DataSetObserver() { - @Override - public void onChanged() { - updatePairButtonEnabled(); - } - }); updatePairButtonEnabled(); + mCancelButton = findViewById(R.id.button_cancel); mCancelButton.setOnClickListener((view) -> { setResult(RESULT_CANCELED); @@ -108,9 +118,6 @@ public class DeviceChooserActivity extends Activity { static int getPadding(Resources r) { return r.getDimensionPixelSize(R.dimen.padding); - //TODO -// final float dp = r.getDisplayMetrics().density; -// return (int)(12 * dp); } private void updatePairButtonEnabled() { diff --git a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceDiscoveryService.java b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceDiscoveryService.java index a3eec0dd5cb5..ccbee2ae196e 100644 --- a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceDiscoveryService.java +++ b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceDiscoveryService.java @@ -66,6 +66,7 @@ public class DeviceDiscoveryService extends Service { private BluetoothLEDeviceFilter mFilter; private ScanFilter mScanFilter; private ScanSettings mDefaultScanSettings = new ScanSettings.Builder().build(); + AssociationRequest<?> mRequest; List<BluetoothDevice> mDevicesFound; BluetoothDevice mSelectedDevice; DevicesAdapter mDevicesAdapter; @@ -141,6 +142,7 @@ public class DeviceDiscoveryService extends Service { private void startDiscovery(AssociationRequest<?> request) { //TODO support other protocols as well + mRequest = request; mFilter = nullsafe((BluetoothLEDeviceFilter) request.getDeviceFilter()); mScanFilter = mFilter.getScanFilter(); |