Only update UI when bound

If the PrintActivity gets destroyed (e.g. due to low memory) it gets
re-created when the PrintToPDF activity returns in onActivityResult. In
this case onActivityResult is called right after onCreate and before the
UI is bound. This resulted in a NullPointerException when accessing the
unbound UI elements.

Bug: 21749058
Change-Id: I44e625e8c4f10432591d0afcf7825d7e0dbee6f5
diff --git a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java
index 743df99..edbb6a5 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java
@@ -167,6 +167,8 @@
 
     public static final PageRange[] ALL_PAGES_ARRAY = new PageRange[]{PageRange.ALL_PAGES};
 
+    private boolean mIsOptionsUiBound = false;
+
     private final PrinterAvailabilityDetector mPrinterAvailabilityDetector =
             new PrinterAvailabilityDetector();
 
@@ -1214,6 +1216,9 @@
         mPrintButton = (ImageView) findViewById(R.id.print_button);
         mPrintButton.setOnClickListener(clickListener);
 
+        // The UI is now initialized
+        mIsOptionsUiBound = true;
+
         // Special prompt instead of destination spinner for the first time the user printed
         if (!hasUserEverPrinted()) {
             mShowDestinationPrompt = true;
@@ -1390,6 +1395,10 @@
     }
 
     void updateOptionsUi() {
+        if (!mIsOptionsUiBound) {
+            return;
+        }
+
         // Always update the summary.
         updateSummary();
 
@@ -1725,6 +1734,10 @@
     }
 
     private void updateSummary() {
+        if (!mIsOptionsUiBound) {
+            return;
+        }
+
         CharSequence copiesText = null;
         CharSequence mediaSizeText = null;