Home | History | Annotate | Download | only in app
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.example.android.apis.app;
     18 
     19 import com.example.android.apis.R;
     20 import com.example.android.apis.app.LocalServiceActivities.Controller;
     21 
     22 import android.app.Activity;
     23 import android.content.Intent;
     24 import android.os.Bundle;
     25 import android.util.Log;
     26 import android.view.View;
     27 import android.view.View.OnClickListener;
     28 import android.widget.Button;
     29 
     30 public class ActivityRecreate extends Activity {
     31     int mCurTheme;
     32 
     33     @Override
     34     protected void onCreate(Bundle savedInstanceState) {
     35         super.onCreate(savedInstanceState);
     36 
     37         if (savedInstanceState != null) {
     38             mCurTheme = savedInstanceState.getInt("theme");
     39 
     40             // Switch to a new theme different from last theme.
     41             switch (mCurTheme) {
     42                 case android.R.style.Theme_Holo_Light:
     43                     mCurTheme = android.R.style.Theme_Holo_Dialog;
     44                     break;
     45                 case android.R.style.Theme_Holo_Dialog:
     46                     mCurTheme = android.R.style.Theme_Holo;
     47                     break;
     48                 default:
     49                     mCurTheme = android.R.style.Theme_Holo_Light;
     50                     break;
     51             }
     52             setTheme(mCurTheme);
     53         }
     54 
     55         setContentView(R.layout.activity_recreate);
     56 
     57         // Watch for button clicks.
     58         Button button = (Button)findViewById(R.id.recreate);
     59         button.setOnClickListener(mRecreateListener);
     60     }
     61 
     62     @Override
     63     protected void onSaveInstanceState(Bundle savedInstanceState) {
     64         super.onSaveInstanceState(savedInstanceState);
     65         savedInstanceState.putInt("theme", mCurTheme);
     66     }
     67 
     68     private OnClickListener mRecreateListener = new OnClickListener() {
     69         public void onClick(View v) {
     70             recreate();
     71         }
     72     };
     73 }
     74