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