Merge "Remove CarUsbHandler dialog visibility." into qt-dev am: d211abef2e
am: 195ac10017
Change-Id: I9f168f49c7c0e6e9e491cf55859c7fa954e53915
diff --git a/car-usb-handler/AndroidManifest.xml b/car-usb-handler/AndroidManifest.xml
index 8887bc6..848548f 100644
--- a/car-usb-handler/AndroidManifest.xml
+++ b/car-usb-handler/AndroidManifest.xml
@@ -25,7 +25,7 @@
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher"
android:directBootAware="true">
<activity android:name=".UsbHostManagementActivity"
- android:theme="@android:style/Theme.Material.Light.Dialog"
+ android:theme="@android:style/Theme.DeviceDefault.Dialog"
android:launchMode="singleTop">
<meta-data
android:name="distractionOptimized"
diff --git a/car-usb-handler/res/layout/usb_host.xml b/car-usb-handler/res/layout/usb_host.xml
index 7a13c4f..8ee83c2 100644
--- a/car-usb-handler/res/layout/usb_host.xml
+++ b/car-usb-handler/res/layout/usb_host.xml
@@ -14,27 +14,21 @@
limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
- <LinearLayout
- android:id="@+id/usb_handlers_progress"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal"
- android:visibility="gone"
- android:gravity="center">
- <ProgressBar
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"/>
- <TextView
- android:text="@string/usb_resolving_handlers"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:orientation="vertical" />
- </LinearLayout>
- <ListView
- android:id="@+id/usb_handlers_list"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" />
+ android:id="@+id/usb_handlers_dialog"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:visibility="gone" >
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="@dimen/title_view_padding"
+ android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"
+ android:background="@*android:color/primary_dark_device_default_dark"
+ android:id="@+id/usb_handler_heading"
+ android:text="@string/app_name"/>
+ <ListView
+ android:id="@+id/usb_handlers_list"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"/>
</LinearLayout>
diff --git a/car-usb-handler/res/values/dimens.xml b/car-usb-handler/res/values/dimens.xml
new file mode 100644
index 0000000..7299844
--- /dev/null
+++ b/car-usb-handler/res/values/dimens.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2019 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>
+ <dimen name="title_view_padding">8dp</dimen>
+</resources>
diff --git a/car-usb-handler/src/android/car/usb/handler/UsbHostController.java b/car-usb-handler/src/android/car/usb/handler/UsbHostController.java
index 2762e6f..7af4f22 100644
--- a/car-usb-handler/src/android/car/usb/handler/UsbHostController.java
+++ b/car-usb-handler/src/android/car/usb/handler/UsbHostController.java
@@ -45,7 +45,7 @@
/** Host controller ready for shutdown */
void shutdown();
/** Change of processing state */
- void processingStateChanged(boolean processing);
+ void processingStarted();
/** Title of processing changed */
void titleChanged(String title);
/** Options for USB device changed */
@@ -157,7 +157,7 @@
Log.w(TAG, "Currently, other device is being processed");
}
mCallback.optionsUpdated(mEmptyList);
- mCallback.processingStateChanged(true);
+ mCallback.processingStarted();
UsbDeviceSettings settings = mUsbSettingsStorage.getSettings(device);
@@ -205,7 +205,6 @@
Log.d(TAG, "onHandlersResolveComplete: " + device);
}
if (deviceMatchedActiveDevice(device)) {
- mCallback.processingStateChanged(false);
if (handlers.isEmpty()) {
onDeviceDispatched();
} else if (handlers.size() == 1) {
diff --git a/car-usb-handler/src/android/car/usb/handler/UsbHostManagementActivity.java b/car-usb-handler/src/android/car/usb/handler/UsbHostManagementActivity.java
index d571d5d..f710960 100644
--- a/car-usb-handler/src/android/car/usb/handler/UsbHostManagementActivity.java
+++ b/car-usb-handler/src/android/car/usb/handler/UsbHostManagementActivity.java
@@ -35,12 +35,14 @@
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
+import android.view.Window;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
+
import java.util.List;
/**
@@ -51,13 +53,13 @@
* handlers will be captured, and user will be presented with choice to assign default handler.
* After that handler will be launched.
*/
-public class UsbHostManagementActivity extends Activity
- implements UsbHostController.UsbHostControllerCallbacks {
+public class UsbHostManagementActivity extends Activity {
private static final String TAG = UsbHostManagementActivity.class.getSimpleName();
private HandlersAdapter mListAdapter;
private ListView mHandlersList;
- private LinearLayout mProgressInfo;
+ private TextView mHandlerTitle;
+ private LinearLayout mUsbHandlersDialog;
private UsbHostController mController;
private PackageManager mPackageManager;
@@ -107,13 +109,15 @@
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.usb_host);
- mHandlersList = (ListView) findViewById(R.id.usb_handlers_list);
- mProgressInfo = (LinearLayout) findViewById(R.id.usb_handlers_progress);
+ mUsbHandlersDialog = findViewById(R.id.usb_handlers_dialog);
+ mHandlersList = findViewById(R.id.usb_handlers_list);
+ mHandlerTitle = findViewById(R.id.usb_handler_heading);
mListAdapter = new HandlersAdapter(this);
mHandlersList.setAdapter(mListAdapter);
mHandlersList.setOnItemClickListener(mHandlerClickListener);
- mController = new UsbHostController(this, this);
+ mController = new UsbHostController(this, new UsbCallbacks());
mPackageManager = getPackageManager();
}
@@ -146,47 +150,53 @@
}
}
- @Override
- public void shutdown() {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- finish();
- }
- });
- }
+ class UsbCallbacks implements UsbHostController.UsbHostControllerCallbacks {
+ private boolean mProcessing = false;
- @Override
- public void processingStateChanged(final boolean processing) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mProgressInfo.setVisibility(processing ? View.VISIBLE : View.GONE);
- }
- });
- }
+ @Override
+ public void shutdown() {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ finish();
+ }
+ });
+ }
- @Override
- public void titleChanged(final String title) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- setTitle(title);
- }
- });
- }
+ @Override
+ public void processingStarted() {
+ mProcessing = true;
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ if (mProcessing && !mListAdapter.isEmpty()) {
+ mUsbHandlersDialog.setVisibility(View.VISIBLE);
+ }
+ }
+ });
+ }
- @Override
- public void optionsUpdated(final List<UsbDeviceSettings> options) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mListAdapter.clear();
- mListAdapter.addAll(options);
- }
- });
- }
+ @Override
+ public void titleChanged(final String title) {
+ runOnUiThread(() -> mHandlerTitle.setText(title));
+ }
+ @Override
+ public void optionsUpdated(final List<UsbDeviceSettings> options) {
+ if (options != null && !options.isEmpty()) {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ if (mProcessing) {
+ mUsbHandlersDialog.setVisibility(View.VISIBLE);
+ }
+ mListAdapter.clear();
+ mListAdapter.addAll(options);
+ }
+ });
+ }
+ }
+ }
@Override
public void onNewIntent(Intent intent) {