package com.example.calculator;

//import Fragment classes from the support library
import android.support.v4.app.FragmentActivity; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentManager; 
import android.support.v4.app.FragmentTransaction; 
import android.content.res.Configuration;
import android.os.Bundle;

public class CalculatorActivity extends FragmentActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            // if we are in landscape mode, then this activity
            // is not necessary
            finish();
            return;
        }

        if (savedInstanceState == null) {
            // first time - use the extras to determine which
            // fragment to display within this activity
            Bundle extras = getIntent().getExtras();
            Calculator calculatorType = (Calculator) extras
                    .getSerializable("calculatorType");
            Fragment fragment = calculatorType.getFragment();

            FragmentManager fm = getSupportFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            ft.add(android.R.id.content, fragment);
            ft.commit();
        }
    }
}
