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
71 lines (54 loc) · 1.87 KB
/
MainActivity.java
File metadata and controls
71 lines (54 loc) · 1.87 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
package com.snatik.matches;
import android.graphics.Bitmap;
import android.os.Bundle;
import androidx.fragment.app.FragmentActivity;
import android.widget.ImageView;
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;
@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);
Shared.activity = this;
Shared.engine.start();
Shared.engine.setBackgroundImageView(mBackgroundImage);
// set background
setBackgroundImage();
// set menu
ScreenController.getInstance().openScreen(Screen.MENU);
}
@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);
}
}