Calculator: preserve basic/advanced panel on orientation change.

Bug 2154998.

Change-Id: Ie40ebe485cdb0721a5394c4d19450fddf035134f
diff --git a/src/com/android/calculator2/Calculator.java b/src/com/android/calculator2/Calculator.java
index d5c5030..a871c00 100644
--- a/src/com/android/calculator2/Calculator.java
+++ b/src/com/android/calculator2/Calculator.java
@@ -50,10 +50,11 @@
     private static final String LOG_TAG = "Calculator";
     private static final boolean DEBUG  = false;
     private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;
+    private static final String STATE_CURRENT_VIEW = "state-current-view";
 
     @Override
-    public void onCreate(Bundle icicle) {
-        super.onCreate(icicle);
+    public void onCreate(Bundle state) {
+        super.onCreate(state);
 
         setContentView(R.layout.main);
 
@@ -65,14 +66,15 @@
         mLogic = new Logic(this, mHistory, mDisplay, (Button) findViewById(R.id.equal));
         HistoryAdapter historyAdapter = new HistoryAdapter(this, mHistory, mLogic);
         mHistory.setObserver(historyAdapter);
-        View view;
+
         mPanelSwitcher = (PanelSwitcher) findViewById(R.id.panelswitch);
-                                       
+        mPanelSwitcher.setCurrentIndex(state==null ? 0 : state.getInt(STATE_CURRENT_VIEW, 0));
+
         mListener.setHandler(mLogic, mPanelSwitcher);
 
         mDisplay.setOnKeyListener(mListener);
 
-
+        View view;
         if ((view = findViewById(R.id.del)) != null) {
 //            view.setOnClickListener(mListener);
             view.setOnLongClickListener(mListener);
@@ -138,9 +140,9 @@
     }
 
     @Override
-    protected void onSaveInstanceState(Bundle icicle) {
-        // as work-around for ClassCastException in TextView on restart
-        // avoid calling superclass, to keep icicle empty
+    protected void onSaveInstanceState(Bundle state) {
+        super.onSaveInstanceState(state);
+        state.putInt(STATE_CURRENT_VIEW, mPanelSwitcher.getCurrentIndex());
     }
 
     @Override