            :surface-available? true
            :intermediate-bitmap new-bitmap
            :draw-canvas canvas)
-    (.drawColor canvas Color/WHITE)
+    (when-not use-old-bitmap?
+      (redraw-indermed-bitmap this))
     (draw-scene this)))
 
 (defn -surfaceCreated [^org.turtle.geometry.TurtleGraphics this

     ;; ignore it
     nil)))

(def save-state-config
  (letfn [(save-matrix [activity-key
                        key
                        ^org.turtle.geometry.TurtleGraphics activity
                        ^Bundle bundle]
            (let [values (float-array 9 0)]
              (.getValues ^Matrix (get-in @activity activity-key) values)
              (.putFloatArray bundle key values)))
          (restore-matrix [activity-key
                           key
                           ^org.turtle.geometry.TurtleGraphics activity
                           ^Bundle bundle]
            (let [m (Matrix.)]
              (.setValues m (.getFloatArray bundle key))
              (swap! (.state activity) assoc-in
                     activity-key
                     m)))]
    [["intermediate-bitmap"
      (fn [key
           ^org.turtle.geometry.TurtleGraphics activity
           ^Bundle bundle]
        (.putParcelable bundle key (get-in @activity
                                           [:draw-state :intermediate-bitmap])))
      (fn [key
           ^org.turtle.geometry.TurtleGraphics activity
           ^Bundle bundle]
        (swap! (.state activity) assoc-in
               [:draw-state :intermediate-bitmap]
               (.getParcelable bundle key)))]
     ["program-source"
      (fn [key
           ^org.turtle.geometry.TurtleGraphics activity
           ^Bundle bundle]
        (.putString bundle key (str (.getText (program-source-editor @activity)))))
      (fn [key
           ^org.turtle.geometry.TurtleGraphics activity
           ^Bundle bundle]
        (.setText (program-source-editor @activity)
                  (.getString bundle key)))]
     ["turtle-view-transform"
      (fn [key
           ^org.turtle.geometry.TurtleGraphics activity
           ^Bundle bundle]
        (save-matrix [:draw-area-view-transform] key activity bundle))
      (fn [key
           ^org.turtle.geometry.TurtleGraphics activity
           ^Bundle bundle]
        (restore-matrix [:draw-area-view-transform] key activity bundle))]
     ["intermediate-transform"
      (fn [key
           ^org.turtle.geometry.TurtleGraphics activity
           ^Bundle bundle]
        (save-matrix [:intermediate-transform] key activity bundle))
      (fn [key
           ^org.turtle.geometry.TurtleGraphics activity
           ^Bundle bundle]
        (restore-matrix [:intermediate-transform] key activity bundle))]]))


(defn -onSaveInstanceState [^org.turtle.geometry.TurtleGraphics this
                            ^Bundle bundle]
  (.superOnSaveInstanceState this bundle)
  (doseq [[key save _] save-state-config]
    (save key this bundle)))

(defn -onRestoreInstanceState [^org.turtle.geometry.TurtleGraphics this
                               ^Bundle bundle]
  (.superOnRestoreInstanceState this bundle)
  (doseq [[key _ restore] save-state-config]
    (restore key this bundle)))


(defn clear-intermed-bitmap [^org.turtle.geometry.TurtleGraphics this]
  (when-let [intermed-canvas (get-in @this [:draw-state :draw-canvas])]

                                onDestroy superOnDestroy
                                onBackPressed superOnBackPressed
                                onActivityResult superOnActivityResult
                                onSaveInstanceState superOnSaveInstanceState}
              :state ^{:tag ActivityState} state
              :init init
              :constructors {[] []})
