OSDN Git Service

Minor UI improvements and code cleanup:
authorFelipe Leme <felipeal@google.com>
Tue, 15 Mar 2016 01:03:41 +0000 (18:03 -0700)
committerFelipe Leme <felipeal@google.com>
Tue, 15 Mar 2016 02:07:43 +0000 (19:07 -0700)
- 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

packages/Shell/res/layout/dialog_bugreport_info.xml
packages/Shell/src/com/android/shell/BugreportProgressService.java
packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java

index b6b8d6b..bb3084f 100644 (file)
@@ -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">
     <TextView
@@ -30,7 +31,6 @@
         android:id="@+id/name"
         android:maxLength="30"
         android:singleLine="true"
-        android:selectAllOnFocus="true"
         android:inputType="textNoSuggestions"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"/>
index 10c5416..5b19bd2 100644 (file)
@@ -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();
                     }
                 });
index 47e3b3b..17f6f6b 100644 (file)
@@ -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() {