This repository was archived by the owner on Aug 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 413
Expand file tree
/
Copy pathMainActivity.java
More file actions
81 lines (65 loc) · 2.19 KB
/
MainActivity.java
File metadata and controls
81 lines (65 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.snatik.matches;
import android.graphics.Bitmap;
import android.media.Image;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.snatik.matches.common.Shared;
import com.snatik.matches.engine.Engine;
import com.snatik.matches.engine.ScreenController;
import com.snatik.matches.engine.ScreenController.Screen;
import com.snatik.matches.events.EventBus;
import com.snatik.matches.events.ui.BackGameEvent;
import com.snatik.matches.ui.PopupManager;
import com.snatik.matches.utils.Utils;
public class MainActivity extends FragmentActivity {
private ImageView mBackgroundImage;
private LinearLayout mBackButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Shared.context = getApplicationContext();
Shared.engine = Engine.getInstance();
Shared.eventBus = EventBus.getInstance();
setContentView(R.layout.activity_main);
mBackgroundImage = (ImageView) findViewById(R.id.background_image);
mBackButton = (LinearLayout) findViewById(R.id.back_button);
Shared.activity = this;
Shared.engine.start();
Shared.engine.setBackgroundImageView(mBackgroundImage);
// set background
setBackgroundImage();
// set menu
ScreenController.getInstance().openScreen(Screen.MENU);
mBackButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
}
@Override
protected void onDestroy() {
Shared.engine.stop();
super.onDestroy();
}
@Override
public void onBackPressed() {
if (PopupManager.isShown()) {
PopupManager.closePopup();
if (ScreenController.getLastScreen() == Screen.GAME) {
Shared.eventBus.notify(new BackGameEvent());
}
} else if (ScreenController.getInstance().onBack()) {
super.onBackPressed();
}
}
private void setBackgroundImage() {
Bitmap bitmap = Utils.scaleDown(R.drawable.background, Utils.screenWidth(), Utils.screenHeight());
bitmap = Utils.crop(bitmap, Utils.screenHeight(), Utils.screenWidth());
bitmap = Utils.downscaleBitmap(bitmap, 2);
mBackgroundImage.setImageBitmap(bitmap);
}
}