4package org.qtproject.qt.android;
6import android.annotation.SuppressLint;
7import android.app.Activity;
8import android.app.AlertDialog;
9import android.app.Dialog;
10import android.content.Intent;
11import android.content.pm.ActivityInfo;
12import android.content.res.Configuration;
13import android.content.res.Resources;
14import android.net.Uri;
15import android.os.Build;
16import android.os.Bundle;
17import android.provider.Browser;
18import android.view.ContextMenu;
19import android.view.ContextMenu.ContextMenuInfo;
20import android.view.KeyEvent;
21import android.view.Menu;
22import android.view.MenuItem;
23import android.view.MotionEvent;
24import android.view.View;
25import android.view.Window;
26import java.lang.IllegalArgumentException;
32 private String m_applicationParams =
"";
33 private boolean m_isCustomThemeSet =
false;
34 private boolean m_retainNonConfigurationInstance =
false;
35 private Configuration m_prevConfig;
36 private final QtActivityDelegate m_delegate;
38 private void addReferrer(Intent intent)
40 Bundle extras = intent.getExtras();
45 Uri referrer = getReferrer();
46 if (referrer !=
null) {
47 String cleanReferrer = referrer.toString().replaceFirst(
"android-app://",
"");
51 String applicationId = extras.getString(Browser.EXTRA_APPLICATION_ID);
52 if (applicationId !=
null)
65 if (!m_applicationParams.isEmpty())
66 m_applicationParams +=
" ";
67 m_applicationParams +=
params;
72 super.setTheme(resId);
73 m_isCustomThemeSet =
true;
76 private void restartApplication() {
77 Intent intent = Intent.makeRestartActivityTask(getComponentName());
78 startActivity(intent);
80 Runtime.getRuntime().exit(0);
89 protected void onCreate(Bundle savedInstanceState)
91 super.onCreate(savedInstanceState);
92 requestWindowFeature(Window.FEATURE_ACTION_BAR);
94 if (!m_isCustomThemeSet) {
95 setTheme(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q ?
96 android.R.style.Theme_DeviceDefault_DayNight :
97 android.R.style.Theme_Holo_Light);
100 if (
QtNative.getStateDetails().isStarted) {
104 restartApplication();
108 addReferrer(getIntent());
111 QtActivityLoader loader = QtActivityLoader.getActivityLoader(
this);
112 loader.appendApplicationParameters(m_applicationParams);
114 QtLoader.LoadingResult
result = loader.loadQtLibraries();
116 if (
result == QtLoader.LoadingResult.Succeeded) {
117 m_delegate.startNativeApplication(loader.getApplicationParameters(),
118 loader.getMainLibraryPath());
119 }
else if (
result == QtLoader.LoadingResult.Failed) {
122 }
catch (IllegalArgumentException e) {
127 m_prevConfig =
new Configuration(
getResources().getConfiguration());
134 if (Build.VERSION.SDK_INT < 24 || !isInMultiWindowMode())
136 m_delegate.displayManager().unregisterDisplayListener();
144 if (
QtNative.getStateDetails().isStarted) {
145 m_delegate.displayManager().registerDisplayListener();
148 m_delegate.displayManager().updateFullScreen();
163 if (!m_retainNonConfigurationInstance) {
175 super.onConfigurationChanged(newConfig);
176 m_delegate.handleUiModeChange(newConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK);
178 int diff = newConfig.diff(m_prevConfig);
179 if ((diff & ActivityInfo.CONFIG_LOCALE) != 0)
182 m_prevConfig =
new Configuration(newConfig);
212 boolean handleResult =
m_delegate.getInputDelegate().handleDispatchKeyEvent(
event);
213 if (
QtNative.getStateDetails().isStarted && handleResult)
216 return super.dispatchKeyEvent(
event);
222 boolean handled =
m_delegate.getInputDelegate().handleDispatchGenericMotionEvent(
event);
223 if (
QtNative.getStateDetails().isStarted && handled)
226 return super.dispatchGenericMotionEvent(
event);
232 QtNative.ApplicationStateDetails stateDetails =
QtNative.getStateDetails();
233 if (!stateDetails.isStarted || !stateDetails.nativePluginIntegrationReady)
242 QtNative.ApplicationStateDetails stateDetails =
QtNative.getStateDetails();
243 if (!stateDetails.isStarted || !stateDetails.nativePluginIntegrationReady)
279 super.onRestoreInstanceState(savedInstanceState);
280 QtNative.setStarted(savedInstanceState.getBoolean(
"Started"));
281 int savedSystemUiVisibility = savedInstanceState.getInt(
"SystemUiVisibility");
282 m_delegate.displayManager().setSystemUiVisibility(savedSystemUiVisibility);
289 super.onRetainNonConfigurationInstance();
290 m_retainNonConfigurationInstance =
true;
297 super.onSaveInstanceState(outState);
298 outState.putInt(
"SystemUiVisibility",
m_delegate.displayManager().systemUiVisibility());
299 outState.putBoolean(
"Started",
QtNative.getStateDetails().isStarted);
305 super.onWindowFocusChanged(hasFocus);
307 m_delegate.displayManager().updateFullScreen();
320 super.onActivityResult(requestCode, resultCode,
data);
321 QtNative.onActivityResult(requestCode, resultCode,
data);
327 QtNative.sendRequestPermissionsResult(requestCode, grantResults);
336 private void showErrorDialog() {
338 String packageName = getPackageName();
339 AlertDialog errorDialog =
new AlertDialog.Builder(
this).create();
340 @SuppressLint(
"DiscouragedApi") int
id = resources.getIdentifier(
341 "fatal_error_msg", "
string", packageName);
342 errorDialog.setMessage(resources.
getString(
id));
343 errorDialog.setButton(Dialog.BUTTON_POSITIVE, resources.
getString(android.
R.
string.
ok),
344 (
dialog, which) -> finish());
DarwinBluetooth::DeviceInquiryDelegate * m_delegate
void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
boolean onPrepareOptionsMenu(Menu menu)
static final String EXTRA_SOURCE_INFO
boolean onOptionsItemSelected(MenuItem item)
boolean dispatchGenericMotionEvent(MotionEvent event)
void appendApplicationParameters(String params)
void onSaveInstanceState(Bundle outState)
boolean onKeyDown(int keyCode, KeyEvent event)
void onNewIntent(Intent intent)
void hideSplashScreen(final int duration)
void onCreate(Bundle savedInstanceState)
boolean dispatchKeyEvent(KeyEvent event)
void onActivityResult(int requestCode, int resultCode, Intent data)
boolean onContextItemSelected(MenuItem item)
void onWindowFocusChanged(boolean hasFocus)
void onConfigurationChanged(Configuration newConfig)
boolean onKeyUp(int keyCode, KeyEvent event)
void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
void onOptionsMenuClosed(Menu menu)
Object onRetainNonConfigurationInstance()
void onRestoreInstanceState(Bundle savedInstanceState)
boolean onCreateOptionsMenu(Menu menu)
void onContextMenuClosed(Menu menu)
static native void onNewIntent(Intent data)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
[0]
GLsizei const GLfloat * v
[13]
struct _cl_event * event
[0]
static QStringList getResources(const QString &resourceFile, QMakeVfs *vfs)
static QString getString(IMFActivate *device, const IID &id)
QFileDialog dialog(this)
[1]