Merge "Companion device chooser UI enchancements"
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
42
packages/CompanionDeviceManager/res/layout/buttons.xml
Normal file
42
packages/CompanionDeviceManager/res/layout/buttons.xml
Normal file
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
25
packages/CompanionDeviceManager/res/layout/title.xml
Normal file
25
packages/CompanionDeviceManager/res/layout/title.xml
Normal file
@@ -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"
|
||||
/>
|
||||
@@ -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>
|
||||
|
||||
29
packages/CompanionDeviceManager/res/values/styles.xml
Normal file
29
packages/CompanionDeviceManager/res/values/styles.xml
Normal file
@@ -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>
|
||||
@@ -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>
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user