package edu.berkeley.cs.amplab.carat.android.ui;

import edu.berkeley.cs.amplab.carat.android.CaratMainActivity;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ViewFlipper;

public abstract class BaseVFActivity extends Activity implements VFActivity {

    protected int viewIndex = 0;
    protected int baseViewIndex = 0;
    protected ViewFlipper vf = null;

    @Override
    public void setViewId(int id) {
        this.viewIndex = id;
    }
    
    public int getViewId() {
        return this.viewIndex;
    }

    /* (non-Javadoc)
     * @see android.app.Activity#onRetainNonConfigurationInstance()
     */
    @Override
    public Object onRetainNonConfigurationInstance() {
        return this;
    }

    /* (non-Javadoc)
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Object oldInstance = getLastNonConfigurationInstance();
        if (oldInstance != null)
            viewIndex = ((VFActivity) oldInstance).getViewId();
        super.onCreate(savedInstanceState);
    }
    
    @Override
    public void onBackPressed() {
        if (vf.getDisplayedChild() != baseViewIndex) {
            vf.setOutAnimation(CaratMainActivity.outtoRight);
            vf.setInAnimation(CaratMainActivity.inFromLeft);
            vf.setDisplayedChild(baseViewIndex);
            viewIndex = baseViewIndex;
        } else
            finish();
    }
}

@@ -98,32 +98,79 @@
 atMainActivity;%0A
+import edu.berkeley.cs.amplab.carat.android.R;%0A
 import android.a
@@ -208,16 +208,42 @@
 Bundle;%0A
+import android.view.View;%0A
 import a
@@ -608,24 +608,662 @@
 Index;%0A    %7D
+%0A    %0A    /**%0A     * Switch to the given view by id and animate the change.%0A     * @param viewId The view to switch to, for findViewById().%0A     */%0A    public void switchView(int viewId)%7B%0A        View target = findViewById(viewId);%0A        switchView(target);%0A    %7D%0A    %0A    /**%0A     * Switch to the given view by object and animate the change.%0A     * @param v The view to switch to.%0A     */%0A    public void switchView(View v)%7B%0A        vf.setOutAnimation(CaratMainActivity.outtoLeft);%0A        vf.setInAnimation(CaratMainActivity.inFromRight);%0A        vf.setDisplayedChild(vf.indexOfChild(v));%0A        viewIndex = vf.indexOfChild(v);%0A    %7D
 %0A%0A    /* (no

Implement view changing in BaseVFActivity so that subclasses need not.