|
30 | 30 |
|
31 | 31 | package org.godotengine.godot; |
32 | 32 |
|
33 | | -import org.godotengine.godot.utils.ProcessPhoenix; |
34 | | - |
35 | | -import android.content.Intent; |
36 | | -import android.os.Bundle; |
37 | | -import android.util.Log; |
38 | | - |
39 | | -import androidx.annotation.CallSuper; |
40 | | -import androidx.annotation.NonNull; |
41 | | -import androidx.annotation.Nullable; |
42 | | -import androidx.fragment.app.Fragment; |
43 | | -import androidx.fragment.app.FragmentActivity; |
44 | | - |
45 | 33 | /** |
46 | | - * Base activity for Android apps intending to use Godot as the primary and only screen. |
| 34 | + * Base abstract activity for Android apps intending to use Godot as the primary screen. |
47 | 35 | * |
48 | | - * It's also a reference implementation for how to setup and use the {@link Godot} fragment |
49 | | - * within an Android app. |
| 36 | + * @deprecated Use {@link GodotActivity} |
50 | 37 | */ |
51 | | -public abstract class FullScreenGodotApp extends FragmentActivity implements GodotHost { |
52 | | - private static final String TAG = FullScreenGodotApp.class.getSimpleName(); |
53 | | - |
54 | | - protected static final String EXTRA_FORCE_QUIT = "force_quit_requested"; |
55 | | - protected static final String EXTRA_NEW_LAUNCH = "new_launch_requested"; |
56 | | - |
57 | | - @Nullable |
58 | | - private Godot godotFragment; |
59 | | - |
60 | | - @Override |
61 | | - public void onCreate(Bundle savedInstanceState) { |
62 | | - super.onCreate(savedInstanceState); |
63 | | - setContentView(R.layout.godot_app_layout); |
64 | | - |
65 | | - handleStartIntent(getIntent(), true); |
66 | | - |
67 | | - Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.godot_fragment_container); |
68 | | - if (currentFragment instanceof Godot) { |
69 | | - Log.v(TAG, "Reusing existing Godot fragment instance."); |
70 | | - godotFragment = (Godot)currentFragment; |
71 | | - } else { |
72 | | - Log.v(TAG, "Creating new Godot fragment instance."); |
73 | | - godotFragment = initGodotInstance(); |
74 | | - getSupportFragmentManager().beginTransaction().replace(R.id.godot_fragment_container, godotFragment).setPrimaryNavigationFragment(godotFragment).commitNowAllowingStateLoss(); |
75 | | - } |
76 | | - } |
77 | | - |
78 | | - @Override |
79 | | - public void onDestroy() { |
80 | | - Log.v(TAG, "Destroying Godot app..."); |
81 | | - super.onDestroy(); |
82 | | - terminateGodotInstance(godotFragment); |
83 | | - } |
84 | | - |
85 | | - @Override |
86 | | - public final void onGodotForceQuit(Godot instance) { |
87 | | - runOnUiThread(() -> { |
88 | | - terminateGodotInstance(instance); |
89 | | - }); |
90 | | - } |
91 | | - |
92 | | - private void terminateGodotInstance(Godot instance) { |
93 | | - if (instance == godotFragment) { |
94 | | - Log.v(TAG, "Force quitting Godot instance"); |
95 | | - ProcessPhoenix.forceQuit(FullScreenGodotApp.this); |
96 | | - } |
97 | | - } |
98 | | - |
99 | | - @Override |
100 | | - public final void onGodotRestartRequested(Godot instance) { |
101 | | - runOnUiThread(() -> { |
102 | | - if (instance == godotFragment) { |
103 | | - // It's very hard to properly de-initialize Godot on Android to restart the game |
104 | | - // from scratch. Therefore, we need to kill the whole app process and relaunch it. |
105 | | - // |
106 | | - // Restarting only the activity, wouldn't be enough unless it did proper cleanup (including |
107 | | - // releasing and reloading native libs or resetting their state somehow and clearing static data). |
108 | | - Log.v(TAG, "Restarting Godot instance..."); |
109 | | - ProcessPhoenix.triggerRebirth(FullScreenGodotApp.this); |
110 | | - } |
111 | | - }); |
112 | | - } |
113 | | - |
114 | | - @Override |
115 | | - public void onNewIntent(Intent intent) { |
116 | | - super.onNewIntent(intent); |
117 | | - setIntent(intent); |
118 | | - |
119 | | - handleStartIntent(intent, false); |
120 | | - |
121 | | - if (godotFragment != null) { |
122 | | - godotFragment.onNewIntent(intent); |
123 | | - } |
124 | | - } |
125 | | - |
126 | | - private void handleStartIntent(Intent intent, boolean newLaunch) { |
127 | | - boolean forceQuitRequested = intent.getBooleanExtra(EXTRA_FORCE_QUIT, false); |
128 | | - if (forceQuitRequested) { |
129 | | - Log.d(TAG, "Force quit requested, terminating.."); |
130 | | - ProcessPhoenix.forceQuit(this); |
131 | | - return; |
132 | | - } |
133 | | - |
134 | | - if (!newLaunch) { |
135 | | - boolean newLaunchRequested = intent.getBooleanExtra(EXTRA_NEW_LAUNCH, false); |
136 | | - if (newLaunchRequested) { |
137 | | - Log.d(TAG, "New launch requested, restarting.."); |
138 | | - |
139 | | - Intent restartIntent = new Intent(intent).putExtra(EXTRA_NEW_LAUNCH, false); |
140 | | - ProcessPhoenix.triggerRebirth(this, restartIntent); |
141 | | - return; |
142 | | - } |
143 | | - } |
144 | | - } |
145 | | - |
146 | | - @CallSuper |
147 | | - @Override |
148 | | - public void onActivityResult(int requestCode, int resultCode, Intent data) { |
149 | | - super.onActivityResult(requestCode, resultCode, data); |
150 | | - if (godotFragment != null) { |
151 | | - godotFragment.onActivityResult(requestCode, resultCode, data); |
152 | | - } |
153 | | - } |
154 | | - |
155 | | - @CallSuper |
156 | | - @Override |
157 | | - public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { |
158 | | - super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
159 | | - if (godotFragment != null) { |
160 | | - godotFragment.onRequestPermissionsResult(requestCode, permissions, grantResults); |
161 | | - } |
162 | | - } |
163 | | - |
164 | | - @Override |
165 | | - public void onBackPressed() { |
166 | | - if (godotFragment != null) { |
167 | | - godotFragment.onBackPressed(); |
168 | | - } else { |
169 | | - super.onBackPressed(); |
170 | | - } |
171 | | - } |
172 | | - |
173 | | - /** |
174 | | - * Used to initialize the Godot fragment instance in {@link FullScreenGodotApp#onCreate(Bundle)}. |
175 | | - */ |
176 | | - @NonNull |
177 | | - protected Godot initGodotInstance() { |
178 | | - return new Godot(); |
179 | | - } |
180 | | - |
181 | | - @Nullable |
182 | | - protected final Godot getGodotFragment() { |
183 | | - return godotFragment; |
184 | | - } |
185 | | -} |
| 38 | +@Deprecated |
| 39 | +public abstract class FullScreenGodotApp extends GodotActivity {} |
0 commit comments