OSDN Git Service

Update the print job dialog and added notification assets.
authorSvetoslav Ganov <svetoslavganov@google.com>
Wed, 7 Aug 2013 06:49:25 +0000 (23:49 -0700)
committerSvetoslav Ganov <svetoslavganov@google.com>
Wed, 7 Aug 2013 06:52:38 +0000 (23:52 -0700)
1. Update the transition between the print job edit dialog and the
   generating print job dialog. Now the former shrinks into the
   latter.

2. Added most of the notification assets.

Change-Id: I84f35df5cb4f71b86a103c16ab87fd4d108b055b

18 files changed:
packages/PrintSpooler/AndroidManifest.xml
packages/PrintSpooler/res/drawable-hdpi/stat_notify_cancelling.png [new file with mode: 0644]
packages/PrintSpooler/res/drawable-hdpi/stat_notify_error.png [new file with mode: 0644]
packages/PrintSpooler/res/drawable-hdpi/stat_notify_print.png [new file with mode: 0644]
packages/PrintSpooler/res/drawable-mdpi/stat_notify_cancelling.png [new file with mode: 0644]
packages/PrintSpooler/res/drawable-mdpi/stat_notify_error.png [new file with mode: 0644]
packages/PrintSpooler/res/drawable-mdpi/stat_notify_print.png [new file with mode: 0644]
packages/PrintSpooler/res/drawable-xhdpi/stat_notify_cancelling.png [new file with mode: 0644]
packages/PrintSpooler/res/drawable-xhdpi/stat_notify_error.png [new file with mode: 0644]
packages/PrintSpooler/res/drawable-xhdpi/stat_notify_print.png [new file with mode: 0644]
packages/PrintSpooler/res/layout/print_job_config_activity_container.xml [moved from packages/PrintSpooler/res/layout/generating_print_job_dialog.xml with 65% similarity]
packages/PrintSpooler/res/layout/print_job_config_activity_content_editing.xml [moved from packages/PrintSpooler/res/layout/print_job_config_activity.xml with 95% similarity]
packages/PrintSpooler/res/layout/print_job_config_activity_content_generating.xml [new file with mode: 0644]
packages/PrintSpooler/res/values/colors.xml [new file with mode: 0644]
packages/PrintSpooler/res/values/strings.xml
packages/PrintSpooler/res/values/themes.xml [new file with mode: 0644]
packages/PrintSpooler/src/com/android/printspooler/NotificationController.java
packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java

index 72d064a..74fd7a8 100644 (file)
@@ -46,8 +46,8 @@
 
         <activity
             android:name=".PrintJobConfigActivity"
-            android:exported="true"
-            android:theme="@android:style/Theme.Holo.Light.Dialog.NoActionBar">
+            android:exported="false"
+            android:theme="@style/PrintJobConfigActivityTheme">
         </activity>
 
         <receiver
diff --git a/packages/PrintSpooler/res/drawable-hdpi/stat_notify_cancelling.png b/packages/PrintSpooler/res/drawable-hdpi/stat_notify_cancelling.png
new file mode 100644 (file)
index 0000000..2757db0
Binary files /dev/null and b/packages/PrintSpooler/res/drawable-hdpi/stat_notify_cancelling.png differ
diff --git a/packages/PrintSpooler/res/drawable-hdpi/stat_notify_error.png b/packages/PrintSpooler/res/drawable-hdpi/stat_notify_error.png
new file mode 100644 (file)
index 0000000..7846a78
Binary files /dev/null and b/packages/PrintSpooler/res/drawable-hdpi/stat_notify_error.png differ
diff --git a/packages/PrintSpooler/res/drawable-hdpi/stat_notify_print.png b/packages/PrintSpooler/res/drawable-hdpi/stat_notify_print.png
new file mode 100644 (file)
index 0000000..aaff3dd
Binary files /dev/null and b/packages/PrintSpooler/res/drawable-hdpi/stat_notify_print.png differ
diff --git a/packages/PrintSpooler/res/drawable-mdpi/stat_notify_cancelling.png b/packages/PrintSpooler/res/drawable-mdpi/stat_notify_cancelling.png
new file mode 100644 (file)
index 0000000..c1b380a
Binary files /dev/null and b/packages/PrintSpooler/res/drawable-mdpi/stat_notify_cancelling.png differ
diff --git a/packages/PrintSpooler/res/drawable-mdpi/stat_notify_error.png b/packages/PrintSpooler/res/drawable-mdpi/stat_notify_error.png
new file mode 100644 (file)
index 0000000..44109eb
Binary files /dev/null and b/packages/PrintSpooler/res/drawable-mdpi/stat_notify_error.png differ
diff --git a/packages/PrintSpooler/res/drawable-mdpi/stat_notify_print.png b/packages/PrintSpooler/res/drawable-mdpi/stat_notify_print.png
new file mode 100644 (file)
index 0000000..a3954b5
Binary files /dev/null and b/packages/PrintSpooler/res/drawable-mdpi/stat_notify_print.png differ
diff --git a/packages/PrintSpooler/res/drawable-xhdpi/stat_notify_cancelling.png b/packages/PrintSpooler/res/drawable-xhdpi/stat_notify_cancelling.png
new file mode 100644 (file)
index 0000000..fedc00e
Binary files /dev/null and b/packages/PrintSpooler/res/drawable-xhdpi/stat_notify_cancelling.png differ
diff --git a/packages/PrintSpooler/res/drawable-xhdpi/stat_notify_error.png b/packages/PrintSpooler/res/drawable-xhdpi/stat_notify_error.png
new file mode 100644 (file)
index 0000000..c3faa42
Binary files /dev/null and b/packages/PrintSpooler/res/drawable-xhdpi/stat_notify_error.png differ
diff --git a/packages/PrintSpooler/res/drawable-xhdpi/stat_notify_print.png b/packages/PrintSpooler/res/drawable-xhdpi/stat_notify_print.png
new file mode 100644 (file)
index 0000000..6b55a14
Binary files /dev/null and b/packages/PrintSpooler/res/drawable-xhdpi/stat_notify_print.png differ
      limitations under the License.
 -->
 
-<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/progress"
-    android:layout_width="fill_parent"
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/content_container"
+    android:layout_width="wrap_content"
     android:layout_height="wrap_content"
-    android:layout_margin="16dip"
-    android:layout_gravity="center_horizontal"
-    style="?android:attr/progressBarStyleLarge">
-</ProgressBar>
+    android:layout_gravity="center"
+    android:background="@color/print_job_config_activity_content_background">
+
+    <include
+        layout="@layout/print_job_config_activity_content_editing">
+    </include>
+
+</FrameLayout>
 -->
 
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="fill_parent"
+    android:id="@+id/content_editing"
+    android:layout_width="wrap_content"
     android:layout_height="wrap_content"
-    android:orientation="vertical">
+    android:orientation="vertical"
+    android:divider="?android:attr/dividerHorizontal"
+    android:showDividers="middle">
 
     <ScrollView
-        android:layout_width="fill_parent"
+        android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:orientation="vertical"
         android:scrollbars="vertical">
                 android:contentDescription="@null">
             </ImageView>
 
-            <ImageView
-                android:layout_width="fill_parent"
-                android:layout_height="wrap_content"
-                android:layout_gravity="fill_horizontal"
-                android:layout_row="10"
-                android:layout_column="0"
-                android:layout_columnSpan="2"
-                android:background="?android:attr/listDivider"
-                android:contentDescription="@null">
-            </ImageView>
-
         </GridLayout>
 
     </ScrollView>
diff --git a/packages/PrintSpooler/res/layout/print_job_config_activity_content_generating.xml b/packages/PrintSpooler/res/layout/print_job_config_activity_content_generating.xml
new file mode 100644 (file)
index 0000000..6352afc
--- /dev/null
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2013 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/content_generating"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:orientation="vertical"
+    android:divider="?android:attr/dividerHorizontal"
+    android:showDividers="middle">
+
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        style="?android:attr/buttonBarButtonStyle"
+        android:singleLine="true"
+        android:ellipsize="end"
+        android:textAlignment="viewStart"
+        android:text="@string/generating_print_job" >
+    </TextView>
+
+    <ProgressBar
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_margin="32dip"
+        android:layout_gravity="center_horizontal"
+        style="?android:attr/progressBarStyleLarge">
+    </ProgressBar>
+
+    <Button
+        android:id="@+id/cancel_button"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:layout_gravity="fill_horizontal"
+        android:text="@string/cancel_button"
+        style="?android:attr/buttonBarButtonStyle">
+    </Button>
+
+</LinearLayout>
diff --git a/packages/PrintSpooler/res/values/colors.xml b/packages/PrintSpooler/res/values/colors.xml
new file mode 100644 (file)
index 0000000..3d8ba22
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2013 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>
+    <color name="print_job_config_activity_content_background">#FFF2F2F2</color>
+</resources>
\ No newline at end of file
index fbddf43..8391509 100644 (file)
@@ -22,6 +22,9 @@
     <!-- Label of the print dialog's print button. [CHAR LIMIT=16] -->
     <string name="print_button">PRINT</string>
 
+    <!-- Label of the print dialog's cancel button. [CHAR LIMIT=16] -->
+    <string name="cancel_button">CANCEL</string>
+
     <!-- Label of the destination widget. [CHAR LIMIT=20] -->
     <string name="label_destination">DESTIINATION</string>
 
diff --git a/packages/PrintSpooler/res/values/themes.xml b/packages/PrintSpooler/res/values/themes.xml
new file mode 100644 (file)
index 0000000..ab16c65
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2013 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="PrintJobConfigActivityTheme" parent="@android:style/Theme.Holo.Light.NoActionBar">
+        <item name="android:windowBackground">@android:color/transparent</item>
+        <item name="android:windowSoftInputMode">stateAlwaysHidden|adjustPan</item>
+        <item name="android:windowIsTranslucent">true</item>
+        <item name="android:backgroundDimEnabled">true</item>
+        <item name="android:colorBackgroundCacheHint">@android:color/transparent</item>
+    </style>
+
+</resources>
index 8b49c0e..130320b 100644 (file)
@@ -81,12 +81,10 @@ public class NotificationController {
 
     private void createPrintingNotificaiton(PrintJobInfo printJob) {
         Notification.Builder builder = new Notification.Builder(mContext)
-                // TODO: Use appropriate icon when assets are ready
-                .setSmallIcon(android.R.drawable.ic_secure)
+                .setSmallIcon(R.drawable.stat_notify_print)
                 .setContentTitle(mContext.getString(R.string.printing_notification_title_template,
                         printJob.getLabel()))
-                // TODO: Use appropriate icon when assets are ready
-                .addAction(android.R.drawable.ic_secure, mContext.getString(R.string.cancel),
+                .addAction(R.drawable.stat_notify_cancelling, mContext.getString(R.string.cancel),
                         createCancelIntent(printJob))
                 .setContentText(printJob.getPrinterId().getPrinterName())
                 .setWhen(System.currentTimeMillis())
@@ -97,12 +95,10 @@ public class NotificationController {
 
     private void createFailedNotificaiton(PrintJobInfo printJob) {
         Notification.Builder builder = new Notification.Builder(mContext)
-                // TODO: Use appropriate icon when assets are ready
-                .setSmallIcon(android.R.drawable.ic_secure)
+                .setSmallIcon(R.drawable.stat_notify_error)
                 .setContentTitle(mContext.getString(R.string.failed_notification_title_template,
                         printJob.getLabel()))
-                // TODO: Use appropriate icon when assets are ready
-                .addAction(android.R.drawable.ic_secure, mContext.getString(R.string.cancel),
+                .addAction(R.drawable.stat_notify_cancelling, mContext.getString(R.string.cancel),
                         createCancelIntent(printJob))
                 // TODO: Use appropriate icon when assets are ready
                 .addAction(android.R.drawable.ic_secure, mContext.getString(R.string.restart),
@@ -161,8 +157,7 @@ public class NotificationController {
             NotificationManager notificationManager = (NotificationManager)
                     context.getSystemService(Context.NOTIFICATION_SERVICE);
             Notification.Builder builder = new Notification.Builder(context)
-                    // TODO: Use appropriate icon when assets are ready
-                    .setSmallIcon(android.R.drawable.ic_secure)
+                    .setSmallIcon(R.drawable.stat_notify_cancelling)
                     .setContentTitle(context.getString(
                             R.string.cancelling_notification_title_template,
                             printJobLabel))
index 00a76b8..824815f 100644 (file)
 package com.android.printspooler;
 
 import android.app.Activity;
-import android.app.AlertDialog;
 import android.app.Dialog;
-import android.app.DialogFragment;
 import android.content.Context;
-import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
@@ -57,6 +54,7 @@ import android.util.Log;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
 import android.view.View;
+import android.view.View.MeasureSpec;
 import android.view.View.OnClickListener;
 import android.view.ViewGroup;
 import android.view.WindowManager;
@@ -147,7 +145,7 @@ public class PrintJobConfigActivity extends Activity {
     @Override
     protected void onCreate(Bundle bundle) {
         super.onCreate(bundle);
-        setContentView(R.layout.print_job_config_activity);
+        setContentView(R.layout.print_job_config_activity_container);
 
         getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
 
@@ -234,10 +232,14 @@ public class PrintJobConfigActivity extends Activity {
     }
 
     public boolean onKeyUp(int keyCode, KeyEvent event) {
-        if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking()
-                && !event.isCanceled()) {
-            if (!mController.isWorking()) {
-                PrintJobConfigActivity.this.finish();
+        if (keyCode == KeyEvent.KEYCODE_BACK) {
+            if (mEditor.isShwoingGeneratingPrintJobUi()) {
+                return true;
+            }
+            if (event.isTracking() && !event.isCanceled()) {
+                if (!mController.isWorking()) {
+                    PrintJobConfigActivity.this.finish();
+                }
             }
             mEditor.cancel();
             return true;
@@ -249,31 +251,6 @@ public class PrintJobConfigActivity extends Activity {
         return !mOldPrintAttributes.equals(mCurrPrintAttributes);
     }
 
-    private void showGeneratingPrintJobUi() {
-        getWindow().getDecorView().setVisibility(View.GONE);
-
-        DialogFragment fragment = new DialogFragment() {
-            @Override
-            public Dialog onCreateDialog(Bundle savedInstanceState) {
-                return new AlertDialog.Builder(PrintJobConfigActivity.this)
-                    .setTitle(getString(R.string.generating_print_job))
-                    .setView(PrintJobConfigActivity.this.getLayoutInflater().inflate(
-                            R.layout.generating_print_job_dialog, null))
-                    .setCancelable(false)
-                    .setPositiveButton(getString(R.string.cancel),
-                            new DialogInterface.OnClickListener() {
-                                @Override
-                                public void onClick(DialogInterface dialog, int which) {
-                                    mEditor.cancel();
-                                    PrintJobConfigActivity.this.finish();
-                                }
-                            })
-                    .create();
-            }
-        };
-        fragment.show(getFragmentManager(), getString(R.string.generating_print_job));
-    }
-
     private class PrintController {
         private final AtomicInteger mRequestCounter = new AtomicInteger();
 
@@ -915,6 +892,67 @@ public class PrintJobConfigActivity extends Activity {
             updateUi();
         }
 
+        public boolean isShwoingGeneratingPrintJobUi() {
+            return (findViewById(R.id.content_generating) != null);
+        }
+
+        private void showGeneratingPrintJobUi() {
+            // Find everything we will shuffle around.
+            final ViewGroup contentContainer = (ViewGroup) findViewById(R.id.content_container);
+            final View contentEditing = contentContainer.findViewById(R.id.content_editing);
+            final View contentGenerating = getLayoutInflater().inflate(
+                    R.layout.print_job_config_activity_content_generating,
+                    contentContainer, false);
+
+            // Wire the cancel action.
+            Button cancelButton = (Button) contentGenerating.findViewById(R.id.cancel_button);
+            cancelButton.setOnClickListener(new OnClickListener() {
+                @Override
+                public void onClick(View v) {
+                    if (!mController.isWorking()) {
+                        PrintJobConfigActivity.this.finish();
+                    }
+                    mEditor.cancel();
+                }
+            });
+
+            // First animation - fade out the old content.
+            contentEditing.animate().alpha(0.0f).withEndAction(new Runnable() {
+                @Override
+                public void run() {
+                    contentEditing.setVisibility(View.INVISIBLE);
+
+                    // Prepare the new content with correct size and alpha.
+                    contentGenerating.setMinimumWidth(contentContainer.getWidth());
+                    contentGenerating.setAlpha(0.0f);
+
+                    // Compute how to much shrink the container to fit around the new content.
+                    final int widthSpec = MeasureSpec.makeMeasureSpec(
+                            contentContainer.getWidth(), MeasureSpec.AT_MOST);
+                    final int heightSpec = MeasureSpec.makeMeasureSpec(
+                            contentContainer.getHeight(), MeasureSpec.AT_MOST);
+                    contentGenerating.measure(widthSpec, heightSpec);
+                    final float scaleY = (float) contentGenerating.getMeasuredHeight()
+                            / (float) contentContainer.getHeight();
+
+                    // Second animation - resize the container.
+                    contentContainer.animate().scaleY(scaleY).withEndAction(
+                            new Runnable() {
+                        @Override
+                        public void run() {
+                            // Swap the old and the new content.
+                            contentContainer.removeAllViews();
+                            contentContainer.setScaleY(1.0f);
+                            contentContainer.addView(contentGenerating);
+
+                            // Third animation - show the new content.
+                            contentGenerating.animate().alpha(1.0f);
+                        }
+                    });
+                }
+            });
+        }
+
         public void initialize() {
             mEditorState = EDITOR_STATE_INITIALIZED;
             if (mDestinationSpinner.getSelectedItemPosition() != AdapterView.INVALID_POSITION) {