From 208b1881ae924cd0c2bed326555e4aa18424d927 Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Mon, 14 Mar 2016 18:03:41 -0700 Subject: [PATCH] Minor UI improvements and code cleanup: - Removed initial selection of name field. - Set notification type as system. - Refactored some notification code. - Removed initial focus on details UI. BUG: 26906985 BUG: 27494227 Change-Id: I5aab95c06830da3850331a2dba09abae88cf59fc --- .../Shell/res/layout/dialog_bugreport_info.xml | 2 +- .../android/shell/BugreportProgressService.java | 36 +++++++++------------- .../com/android/shell/BugreportReceiverTest.java | 31 +++++++++++-------- 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/packages/Shell/res/layout/dialog_bugreport_info.xml b/packages/Shell/res/layout/dialog_bugreport_info.xml index b6b8d6bcf2b2..bb3084f5c10a 100644 --- a/packages/Shell/res/layout/dialog_bugreport_info.xml +++ b/packages/Shell/res/layout/dialog_bugreport_info.xml @@ -19,6 +19,7 @@ android:paddingTop="15dp" android:paddingStart="24dp" android:paddingEnd="24dp" + android:focusableInTouchMode="true" android:layout_width="wrap_content" android:layout_height="wrap_content"> diff --git a/packages/Shell/src/com/android/shell/BugreportProgressService.java b/packages/Shell/src/com/android/shell/BugreportProgressService.java index 10c541600d87..5b19bd274309 100644 --- a/packages/Shell/src/com/android/shell/BugreportProgressService.java +++ b/packages/Shell/src/com/android/shell/BugreportProgressService.java @@ -454,21 +454,15 @@ public class BugreportProgressService extends Service { final String name = info.name != null ? info.name : mContext.getString(R.string.bugreport_unnamed); - final Notification notification = new Notification.Builder(mContext) - .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb) + final Notification notification = newBaseNotification(mContext) .setContentTitle(title) .setTicker(title) .setContentText(name) .setContentInfo(percentText) .setProgress(info.max, info.progress, false) .setOngoing(true) - .setLocalOnly(true) - .setColor(mContext.getColor( - com.android.internal.R.color.system_notification_accent_color)) .setContentIntent(infoPendingIntent) - .addAction(infoAction) - .addAction(screenshotAction) - .addAction(cancelAction) + .setActions(infoAction, screenshotAction, cancelAction) .build(); if (info.finished) { @@ -928,17 +922,13 @@ public class BugreportProgressService extends Service { title = context.getString(R.string.bugreport_finished_title, info.id); content = context.getString(R.string.bugreport_finished_text); } - final Notification.Builder builder = new Notification.Builder(context) - .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb) + final Notification.Builder builder = newBaseNotification(context) .setContentTitle(title) .setTicker(title) .setContentText(content) .setContentIntent(PendingIntent.getService(context, info.id, shareIntent, PendingIntent.FLAG_UPDATE_CURRENT)) - .setDeleteIntent(newCancelIntent(context, info)) - .setLocalOnly(true) - .setColor(context.getColor( - com.android.internal.R.color.system_notification_accent_color)); + .setDeleteIntent(newCancelIntent(context, info)); if (!TextUtils.isEmpty(info.name)) { builder.setContentInfo(info.name); @@ -955,16 +945,21 @@ public class BugreportProgressService extends Service { */ private static void sendBugreportBeingUpdatedNotification(Context context, int id) { final String title = context.getString(R.string.bugreport_updating_title); - final Notification.Builder builder = new Notification.Builder(context) - .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb) + final Notification.Builder builder = newBaseNotification(context) .setContentTitle(title) .setTicker(title) - .setContentText(context.getString(R.string.bugreport_updating_wait)) + .setContentText(context.getString(R.string.bugreport_updating_wait)); + Log.v(TAG, "Sending 'Updating zip' notification for ID " + id + ": " + title); + NotificationManager.from(context).notify(TAG, id, builder.build()); + } + + private static Notification.Builder newBaseNotification(Context context) { + return new Notification.Builder(context) + .setCategory(Notification.CATEGORY_SYSTEM) + .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb) .setLocalOnly(true) .setColor(context.getColor( com.android.internal.R.color.system_notification_accent_color)); - Log.v(TAG, "Sending 'Updating zip' notification for ID " + id + ": " + title); - NotificationManager.from(context).notify(TAG, id, builder.build()); } /** @@ -1281,9 +1276,6 @@ public class BugreportProgressService extends Service { if (hasFocus) { return; } - // Select-all is useful just initially, since the date-based filename is - // full of hyphens. - mInfoName.setSelectAllOnFocus(false); sanitizeName(); } }); diff --git a/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java b/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java index 47e3b3b8f8f3..17f6f6b5ac89 100644 --- a/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java +++ b/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java @@ -291,6 +291,7 @@ public class BugreportReceiverTest extends InstrumentationTestCase { detailsUi.assertName(NAME); // Change name - it should have changed system property once focus is changed. + detailsUi.focusOnName(); detailsUi.nameField.setText(NEW_NAME); detailsUi.focusAwayFromName(); assertPropertyValue(NAME_PROPERTY, NEW_NAME); @@ -966,40 +967,44 @@ public class BugreportReceiverTest extends InstrumentationTestCase { cancelButton = mUiBot.getObjectById("android:id/button2"); } - private void assertField(String name, UiObject field, String expected) { - try { - String actual = field.getText().toString(); - assertEquals("Wrong value on field '" + name + "'", expected, actual); - } catch (UiObjectNotFoundException e) { - // Should not happen... - throw new IllegalStateException("field not found: " + name, e); - } + private void assertField(String name, UiObject field, String expected) + throws UiObjectNotFoundException { + String actual = field.getText().toString(); + assertEquals("Wrong value on field '" + name + "'", expected, actual); } - void assertName(String expected) { + void assertName(String expected) throws UiObjectNotFoundException { assertField("name", nameField, expected); } - void assertTitle(String expected) { + void assertTitle(String expected) throws UiObjectNotFoundException { assertField("title", titleField, expected); } - void assertDescription(String expected) { + void assertDescription(String expected) throws UiObjectNotFoundException { assertField("description", descField, expected); } /** + * Set focus on the name field so it can be validated once focus is lost. + */ + void focusOnName() throws UiObjectNotFoundException { + mUiBot.click(nameField, "name_field"); + assertTrue("name_field not focused", nameField.isFocused()); + } + + /** * Takes focus away from the name field so it can be validated. */ - void focusAwayFromName() { + void focusAwayFromName() throws UiObjectNotFoundException { mUiBot.click(titleField, "title_field"); // Change focus. mUiBot.pressBack(); // Dismiss keyboard. + assertFalse("name_field is focused", nameField.isFocused()); } void reOpen() { openProgressNotification(ID); mUiBot.click(detailsButton, "details_button"); - } void clickOk() { -- 2.11.0