Home | History | Annotate | Download | only in tictactoe
      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.tictactoe;
     18 
     19 import android.app.Activity;
     20 import android.content.Intent;
     21 import android.os.Bundle;
     22 import android.view.View;
     23 import android.view.View.OnClickListener;
     24 
     25 import com.example.android.tictactoe.library.GameActivity;
     26 import com.example.android.tictactoe.library.GameView.State;
     27 
     28 public class MainActivity extends Activity {
     29     /** Called when the activity is first created. */
     30     @Override
     31     public void onCreate(Bundle savedInstanceState) {
     32         super.onCreate(savedInstanceState);
     33         setContentView(R.layout.main);
     34 
     35         findViewById(R.id.start_player).setOnClickListener(
     36                 new OnClickListener() {
     37             public void onClick(View v) {
     38                 startGame(true);
     39             }
     40         });
     41 
     42         findViewById(R.id.start_comp).setOnClickListener(
     43                 new OnClickListener() {
     44             public void onClick(View v) {
     45                 startGame(false);
     46             }
     47         });
     48     }
     49 
     50     private void startGame(boolean startWithHuman) {
     51         Intent i = new Intent(this, GameActivity.class);
     52         i.putExtra(GameActivity.EXTRA_START_PLAYER,
     53                 startWithHuman ? State.PLAYER1.getValue() : State.PLAYER2.getValue());
     54         startActivity(i);
     55     }
     56 }