Home | History | Annotate | Download | only in egg
      1 /*
      2  * Copyright (C) 2015 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.android.systemui.egg;
     18 
     19 import android.app.Activity;
     20 import android.os.Bundle;
     21 import android.view.View;
     22 
     23 import com.android.systemui.R;
     24 
     25 public class MLandActivity extends Activity {
     26     MLand mLand;
     27 
     28     @Override
     29     public void onCreate(Bundle savedInstanceState) {
     30         super.onCreate(savedInstanceState);
     31         setContentView(R.layout.mland);
     32         mLand = findViewById(R.id.world);
     33         mLand.setScoreFieldHolder(findViewById(R.id.scores));
     34         final View welcome = findViewById(R.id.welcome);
     35         mLand.setSplash(welcome);
     36         final int numControllers = mLand.getGameControllers().size();
     37         if (numControllers > 0) {
     38             mLand.setupPlayers(numControllers);
     39         }
     40     }
     41 
     42     public void updateSplashPlayers() {
     43         final int N = mLand.getNumPlayers();
     44         final View minus = findViewById(R.id.player_minus_button);
     45         final View plus = findViewById(R.id.player_plus_button);
     46         if (N == 1) {
     47             minus.setVisibility(View.INVISIBLE);
     48             plus.setVisibility(View.VISIBLE);
     49             plus.requestFocus();
     50         } else if (N == mLand.MAX_PLAYERS) {
     51             minus.setVisibility(View.VISIBLE);
     52             plus.setVisibility(View.INVISIBLE);
     53             minus.requestFocus();
     54         } else {
     55             minus.setVisibility(View.VISIBLE);
     56             plus.setVisibility(View.VISIBLE);
     57         }
     58     }
     59 
     60     @Override
     61     public void onPause() {
     62         mLand.stop();
     63         super.onPause();
     64     }
     65 
     66     @Override
     67     public void onResume() {
     68         super.onResume();
     69 
     70         mLand.onAttachedToWindow(); // resets and starts animation
     71         updateSplashPlayers();
     72         mLand.showSplash();
     73     }
     74 
     75     public void playerMinus(View v) {
     76         mLand.removePlayer();
     77         updateSplashPlayers();
     78     }
     79 
     80     public void playerPlus(View v) {
     81         mLand.addPlayer();
     82         updateSplashPlayers();
     83     }
     84 
     85     public void startButtonPressed(View v) {
     86         findViewById(R.id.player_minus_button).setVisibility(View.INVISIBLE);
     87         findViewById(R.id.player_plus_button).setVisibility(View.INVISIBLE);
     88         mLand.start(true);
     89     }
     90 }
     91