Advertisement
Guest User

QtActivity.java

a guest
Jul 24th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 61.30 KB | None | 0 0
  1. /*
  2.     Copyright (c) 2012-2013, BogDan Vatra <bogdan@kde.org>
  3.     Contact: http://www.qt-project.org/legal
  4.  
  5.     Commercial License Usage
  6.     Licensees holding valid commercial Qt licenses may use this file in
  7.     accordance with the commercial license agreement provided with the
  8.     Software or, alternatively, in accordance with the terms contained in
  9.     a written agreement between you and Digia.  For licensing terms and
  10.     conditions see http://qt.digia.com/licensing.  For further information
  11.     use the contact form at http://qt.digia.com/contact-us.
  12.  
  13.     BSD License Usage
  14.     Alternatively, this file may be used under the BSD license as follows:
  15.     Redistribution and use in source and binary forms, with or without
  16.     modification, are permitted provided that the following conditions
  17.     are met:
  18.  
  19.     1. Redistributions of source code must retain the above copyright
  20.     notice, this list of conditions and the following disclaimer.
  21.     2. Redistributions in binary form must reproduce the above copyright
  22.     notice, this list of conditions and the following disclaimer in the
  23.     documentation and/or other materials provided with the distribution.
  24.  
  25.     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  26.     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  27.     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  28.     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  29.     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  30.     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31.     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32.     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33.     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  34.     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. */
  36.  
  37. package org.qtproject.qt5.android.bindings;
  38.  
  39. import java.io.File;
  40. import java.io.IOException;
  41. import java.io.OutputStream;
  42. import java.io.InputStream;
  43. import java.io.FileOutputStream;
  44. import java.io.FileInputStream;
  45. import java.io.DataOutputStream;
  46. import java.io.DataInputStream;
  47. import java.lang.reflect.Field;
  48. import java.lang.reflect.Method;
  49. import java.util.ArrayList;
  50. import java.util.Arrays;
  51.  
  52. import org.kde.necessitas.ministro.IMinistro;
  53. import org.kde.necessitas.ministro.IMinistroCallback;
  54.  
  55. import android.app.Activity;
  56. import android.app.AlertDialog;
  57. import android.app.Dialog;
  58. import android.content.ComponentName;
  59. import android.content.Context;
  60. import android.content.DialogInterface;
  61. import android.content.Intent;
  62. import android.content.ServiceConnection;
  63. import android.content.pm.ActivityInfo;
  64. import android.content.pm.PackageManager;
  65. import android.content.pm.PackageManager.NameNotFoundException;
  66. import android.content.pm.PackageInfo;
  67. import android.content.res.Configuration;
  68. import android.content.res.Resources.Theme;
  69. import android.content.res.AssetManager;
  70. import android.graphics.Bitmap;
  71. import android.graphics.Canvas;
  72. import android.graphics.drawable.ColorDrawable;
  73. import android.net.Uri;
  74. import android.os.Build;
  75. import android.os.Bundle;
  76. import android.os.IBinder;
  77. import android.os.RemoteException;
  78. import android.util.AttributeSet;
  79. import android.util.Log;
  80. import android.view.ContextMenu;
  81. import android.view.ContextMenu.ContextMenuInfo;
  82. import android.view.KeyEvent;
  83. import android.view.Menu;
  84. import android.view.MenuItem;
  85. import android.view.MotionEvent;
  86. import android.view.View;
  87. import android.view.Window;
  88. import android.view.WindowManager.LayoutParams;
  89. import android.view.accessibility.AccessibilityEvent;
  90. import dalvik.system.DexClassLoader;
  91.  
  92.  
  93.  
  94. public class QtActivity extends Activity
  95. {
  96.     private final static int MINISTRO_INSTALL_REQUEST_CODE = 0xf3ee; // request code used to know when Ministro instalation is finished
  97.     private static final int MINISTRO_API_LEVEL = 5; // Ministro api level (check IMinistro.aidl file)
  98.     private static final int NECESSITAS_API_LEVEL = 2; // Necessitas api level used by platform plugin
  99.     private static final int QT_VERSION = 0x050100; // This app requires at least Qt version 5.1.0
  100.  
  101.     private static final String ERROR_CODE_KEY = "error.code";
  102.     private static final String ERROR_MESSAGE_KEY = "error.message";
  103.     private static final String DEX_PATH_KEY = "dex.path";
  104.     private static final String LIB_PATH_KEY = "lib.path";
  105.     private static final String LOADER_CLASS_NAME_KEY = "loader.class.name";
  106.     private static final String NATIVE_LIBRARIES_KEY = "native.libraries";
  107.     private static final String ENVIRONMENT_VARIABLES_KEY = "environment.variables";
  108.     private static final String APPLICATION_PARAMETERS_KEY = "application.parameters";
  109.     private static final String BUNDLED_LIBRARIES_KEY = "bundled.libraries";
  110.     private static final String BUNDLED_IN_LIB_RESOURCE_ID_KEY = "android.app.bundled_in_lib_resource_id";
  111.     private static final String BUNDLED_IN_ASSETS_RESOURCE_ID_KEY = "android.app.bundled_in_assets_resource_id";
  112.     private static final String MAIN_LIBRARY_KEY = "main.library";
  113.     private static final String STATIC_INIT_CLASSES_KEY = "static.init.classes";
  114.     private static final String NECESSITAS_API_LEVEL_KEY = "necessitas.api.level";
  115.     private static final String EXTRACT_STYLE_KEY = "extract.android.style";
  116.  
  117.     /// Ministro server parameter keys
  118.     private static final String REQUIRED_MODULES_KEY = "required.modules";
  119.     private static final String APPLICATION_TITLE_KEY = "application.title";
  120.     private static final String MINIMUM_MINISTRO_API_KEY = "minimum.ministro.api";
  121.     private static final String MINIMUM_QT_VERSION_KEY = "minimum.qt.version";
  122.     private static final String SOURCES_KEY = "sources";               // needs MINISTRO_API_LEVEL >=3 !!!
  123.                                                                        // Use this key to specify any 3rd party sources urls
  124.                                                                        // Ministro will download these repositories into their
  125.                                                                        // own folders, check http://community.kde.org/Necessitas/Ministro
  126.                                                                        // for more details.
  127.  
  128.     private static final String REPOSITORY_KEY = "repository";         // use this key to overwrite the default ministro repsitory
  129.     private static final String ANDROID_THEMES_KEY = "android.themes"; // themes that your application uses
  130.  
  131.  
  132.     public String APPLICATION_PARAMETERS = null; // use this variable to pass any parameters to your application,
  133.                                                                // the parameters must not contain any white spaces
  134.                                                                // and must be separated with "\t"
  135.                                                                // e.g "-param1\t-param2=value2\t-param3\tvalue3"
  136.  
  137.     public String ENVIRONMENT_VARIABLES = "QT_USE_ANDROID_NATIVE_STYLE=1\tQT_USE_ANDROID_NATIVE_DIALOGS=1\t";
  138.                                                                // use this variable to add any environment variables to your application.
  139.                                                                // the env vars must be separated with "\t"
  140.                                                                // e.g. "ENV_VAR1=1\tENV_VAR2=2\t"
  141.                                                                // Currently the following vars are used by the android plugin:
  142.                                                                // * QT_USE_ANDROID_NATIVE_STYLE - 1 to use the android widget style if available.
  143.                                                                // * QT_USE_ANDROID_NATIVE_DIALOGS -1 to use the android native dialogs.
  144.  
  145.     public String[] QT_ANDROID_THEMES = null;     // A list with all themes that your application want to use.
  146.                                                   // The name of the theme must be the same with any theme from
  147.                                                   // http://developer.android.com/reference/android/R.style.html
  148.                                                   // The most used themes are:
  149.                                                   //  * "Theme" - (fallback) check http://developer.android.com/reference/android/R.style.html#Theme
  150.                                                   //  * "Theme_Black" - check http://developer.android.com/reference/android/R.style.html#Theme_Black
  151.                                                   //  * "Theme_Light" - (default for API <=10) check http://developer.android.com/reference/android/R.style.html#Theme_Light
  152.                                                   //  * "Theme_Holo" - check http://developer.android.com/reference/android/R.style.html#Theme_Holo
  153.                                                   //  * "Theme_Holo_Light" - (default for API 11-13) check http://developer.android.com/reference/android/R.style.html#Theme_Holo_Light
  154.                                                   //  * "Theme_DeviceDefault" - check http://developer.android.com/reference/android/R.style.html#Theme_DeviceDefault
  155.                                                   //  * "Theme_DeviceDefault_Light" - (default for API 14+) check http://developer.android.com/reference/android/R.style.html#Theme_DeviceDefault_Light
  156.  
  157.     public String QT_ANDROID_DEFAULT_THEME = null; // sets the default theme.
  158.  
  159.     private static final int INCOMPATIBLE_MINISTRO_VERSION = 1; // Incompatible Ministro version. Ministro needs to be upgraded.
  160.     private static final int BUFFER_SIZE = 1024;
  161.  
  162.     private ActivityInfo m_activityInfo = null; // activity info object, used to access the libs and the strings
  163.     private DexClassLoader m_classLoader = null; // loader object
  164.     private String[] m_sources = {"https://download.qt-project.org/ministro/android/qt5/qt-5.2"}; // Make sure you are using ONLY secure locations
  165.     private String m_repository = "default"; // Overwrites the default Ministro repository
  166.                                                         // Possible values:
  167.                                                         // * default - Ministro default repository set with "Ministro configuration tool".
  168.                                                         // By default the stable version is used. Only this or stable repositories should
  169.                                                         // be used in production.
  170.                                                         // * stable - stable repository, only this and default repositories should be used
  171.                                                         // in production.
  172.                                                         // * testing - testing repository, DO NOT use this repository in production,
  173.                                                         // this repository is used to push a new release, and should be used to test your application.
  174.                                                         // * unstable - unstable repository, DO NOT use this repository in production,
  175.                                                         // this repository is used to push Qt snapshots.
  176.     private String[] m_qtLibs = null; // required qt libs
  177.     private int m_displayDensity = -1;
  178.  
  179.     public QtActivity()
  180.     {
  181.         if (Build.VERSION.SDK_INT <= 10) {
  182.             QT_ANDROID_THEMES = new String[] {"Theme_Light"};
  183.             QT_ANDROID_DEFAULT_THEME = "Theme_Light";
  184.         }
  185.         else if ((Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT <= 13) || Build.VERSION.SDK_INT >= 21){
  186.             QT_ANDROID_THEMES = new String[] {"Theme_Holo_Light"};
  187.             QT_ANDROID_DEFAULT_THEME = "Theme_Holo_Light";
  188.         } else {
  189.             QT_ANDROID_THEMES = new String[] {"Theme_DeviceDefault_Light"};
  190.             QT_ANDROID_DEFAULT_THEME = "Theme_DeviceDefault_Light";
  191.         }
  192.     }
  193.  
  194.     // this function is used to load and start the loader
  195.     private void loadApplication(Bundle loaderParams)
  196.     {
  197.         try {
  198.             final int errorCode = loaderParams.getInt(ERROR_CODE_KEY);
  199.             if (errorCode != 0) {
  200.                 if (errorCode == INCOMPATIBLE_MINISTRO_VERSION) {
  201.                     downloadUpgradeMinistro(loaderParams.getString(ERROR_MESSAGE_KEY));
  202.                     return;
  203.                 }
  204.  
  205.                 // fatal error, show the error and quit
  206.                 AlertDialog errorDialog = new AlertDialog.Builder(QtActivity.this).create();
  207.                 errorDialog.setMessage(loaderParams.getString(ERROR_MESSAGE_KEY));
  208.                 errorDialog.setButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {
  209.                     @Override
  210.                     public void onClick(DialogInterface dialog, int which) {
  211.                         finish();
  212.                     }
  213.                 });
  214.                 errorDialog.show();
  215.                 return;
  216.             }
  217.  
  218.             // add all bundled Qt libs to loader params
  219.             ArrayList<String> libs = new ArrayList<String>();
  220.             if ( m_activityInfo.metaData.containsKey("android.app.bundled_libs_resource_id") )
  221.                 libs.addAll(Arrays.asList(getResources().getStringArray(m_activityInfo.metaData.getInt("android.app.bundled_libs_resource_id"))));
  222.  
  223.             String libName = null;
  224.             if ( m_activityInfo.metaData.containsKey("android.app.lib_name") ) {
  225.                 libName = m_activityInfo.metaData.getString("android.app.lib_name");
  226.                 loaderParams.putString(MAIN_LIBRARY_KEY, libName); //main library contains main() function
  227.             }
  228.  
  229.             loaderParams.putStringArrayList(BUNDLED_LIBRARIES_KEY, libs);
  230.             loaderParams.putInt(NECESSITAS_API_LEVEL_KEY, NECESSITAS_API_LEVEL);
  231.  
  232.             // load and start QtLoader class
  233.             m_classLoader = new DexClassLoader(loaderParams.getString(DEX_PATH_KEY), // .jar/.apk files
  234.                                                getDir("outdex", Context.MODE_PRIVATE).getAbsolutePath(), // directory where optimized DEX files should be written.
  235.                                                loaderParams.containsKey(LIB_PATH_KEY) ? loaderParams.getString(LIB_PATH_KEY) : null, // libs folder (if exists)
  236.                                                getClassLoader()); // parent loader
  237.  
  238.             @SuppressWarnings("rawtypes")
  239.             Class loaderClass = m_classLoader.loadClass(loaderParams.getString(LOADER_CLASS_NAME_KEY)); // load QtLoader class
  240.             Object qtLoader = loaderClass.newInstance(); // create an instance
  241.             Method perpareAppMethod = qtLoader.getClass().getMethod("loadApplication",
  242.                                                                     Activity.class,
  243.                                                                     ClassLoader.class,
  244.                                                                     Bundle.class);
  245.             if (!(Boolean)perpareAppMethod.invoke(qtLoader, this, m_classLoader, loaderParams))
  246.                 throw new Exception("");
  247.  
  248.             QtApplication.setQtActivityDelegate(qtLoader);
  249.  
  250.             // now load the application library so it's accessible from this class loader
  251.             if (libName != null)
  252.                 System.loadLibrary(libName);
  253.  
  254.             Method startAppMethod=qtLoader.getClass().getMethod("startApplication");
  255.             if (!(Boolean)startAppMethod.invoke(qtLoader))
  256.                 throw new Exception("");
  257.  
  258.         } catch (Exception e) {
  259.             e.printStackTrace();
  260.             AlertDialog errorDialog = new AlertDialog.Builder(QtActivity.this).create();
  261.             if (m_activityInfo.metaData.containsKey("android.app.fatal_error_msg"))
  262.                 errorDialog.setMessage(m_activityInfo.metaData.getString("android.app.fatal_error_msg"));
  263.             else
  264.                 errorDialog.setMessage("Fatal error, your application can't be started.");
  265.  
  266.             errorDialog.setButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {
  267.                 @Override
  268.                 public void onClick(DialogInterface dialog, int which) {
  269.                     finish();
  270.                 }
  271.             });
  272.             errorDialog.show();
  273.         }
  274.     }
  275.  
  276.     private ServiceConnection m_ministroConnection=new ServiceConnection() {
  277.         private IMinistro m_service = null;
  278.         @Override
  279.         public void onServiceConnected(ComponentName name, IBinder service)
  280.         {
  281.             m_service = IMinistro.Stub.asInterface(service);
  282.             try {
  283.                 if (m_service != null) {
  284.                     Bundle parameters = new Bundle();
  285.                     parameters.putStringArray(REQUIRED_MODULES_KEY, m_qtLibs);
  286.                     parameters.putString(APPLICATION_TITLE_KEY, (String)QtActivity.this.getTitle());
  287.                     parameters.putInt(MINIMUM_MINISTRO_API_KEY, MINISTRO_API_LEVEL);
  288.                     parameters.putInt(MINIMUM_QT_VERSION_KEY, QT_VERSION);
  289.                     parameters.putString(ENVIRONMENT_VARIABLES_KEY, ENVIRONMENT_VARIABLES);
  290.                     if (APPLICATION_PARAMETERS != null)
  291.                         parameters.putString(APPLICATION_PARAMETERS_KEY, APPLICATION_PARAMETERS);
  292.                     parameters.putStringArray(SOURCES_KEY, m_sources);
  293.                     parameters.putString(REPOSITORY_KEY, m_repository);
  294.                     if (QT_ANDROID_THEMES != null)
  295.                         parameters.putStringArray(ANDROID_THEMES_KEY, QT_ANDROID_THEMES);
  296.                     m_service.requestLoader(m_ministroCallback, parameters);
  297.                 }
  298.             } catch (RemoteException e) {
  299.                     e.printStackTrace();
  300.             }
  301.         }
  302.  
  303.         private IMinistroCallback m_ministroCallback = new IMinistroCallback.Stub() {
  304.             // this function is called back by Ministro.
  305.             @Override
  306.             public void loaderReady(final Bundle loaderParams) throws RemoteException {
  307.                 runOnUiThread(new Runnable() {
  308.                     @Override
  309.                     public void run() {
  310.                         unbindService(m_ministroConnection);
  311.                         loadApplication(loaderParams);
  312.                     }
  313.                 });
  314.             }
  315.         };
  316.  
  317.         @Override
  318.         public void onServiceDisconnected(ComponentName name) {
  319.             m_service = null;
  320.         }
  321.     };
  322.  
  323.     private void downloadUpgradeMinistro(String msg)
  324.     {
  325.         AlertDialog.Builder downloadDialog = new AlertDialog.Builder(this);
  326.         downloadDialog.setMessage(msg);
  327.         downloadDialog.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
  328.             @Override
  329.             public void onClick(DialogInterface dialogInterface, int i) {
  330.                 try {
  331.                     Uri uri = Uri.parse("market://search?q=pname:org.kde.necessitas.ministro");
  332.                     Intent intent = new Intent(Intent.ACTION_VIEW, uri);
  333.                     startActivityForResult(intent, MINISTRO_INSTALL_REQUEST_CODE);
  334.                 } catch (Exception e) {
  335.                     e.printStackTrace();
  336.                     ministroNotFound();
  337.                 }
  338.             }
  339.         });
  340.  
  341.         downloadDialog.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
  342.             @Override
  343.             public void onClick(DialogInterface dialogInterface, int i) {
  344.                 QtActivity.this.finish();
  345.             }
  346.         });
  347.         downloadDialog.show();
  348.     }
  349.  
  350.     private void ministroNotFound()
  351.     {
  352.         AlertDialog errorDialog = new AlertDialog.Builder(QtActivity.this).create();
  353.  
  354.         if (m_activityInfo.metaData.containsKey("android.app.ministro_not_found_msg"))
  355.             errorDialog.setMessage(m_activityInfo.metaData.getString("android.app.ministro_not_found_msg"));
  356.         else
  357.             errorDialog.setMessage("Can't find Ministro service.\nThe application can't start.");
  358.  
  359.         errorDialog.setButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {
  360.             @Override
  361.             public void onClick(DialogInterface dialog, int which) {
  362.                 finish();
  363.             }
  364.         });
  365.         errorDialog.show();
  366.     }
  367.  
  368.     static private void copyFile(InputStream inputStream, OutputStream outputStream)
  369.         throws IOException
  370.     {
  371.         byte[] buffer = new byte[BUFFER_SIZE];
  372.  
  373.         int count;
  374.         while ((count = inputStream.read(buffer)) > 0)
  375.             outputStream.write(buffer, 0, count);
  376.     }
  377.  
  378.  
  379.     private void copyAsset(String source, String destination)
  380.         throws IOException
  381.     {
  382.         // Already exists, we don't have to do anything
  383.         File destinationFile = new File(destination);
  384.         if (destinationFile.exists())
  385.             return;
  386.  
  387.         File parentDirectory = destinationFile.getParentFile();
  388.         if (!parentDirectory.exists())
  389.             parentDirectory.mkdirs();
  390.  
  391.         destinationFile.createNewFile();
  392.  
  393.         AssetManager assetsManager = getAssets();
  394.         InputStream inputStream = assetsManager.open(source);
  395.         OutputStream outputStream = new FileOutputStream(destinationFile);
  396.         copyFile(inputStream, outputStream);
  397.  
  398.         inputStream.close();
  399.         outputStream.close();
  400.     }
  401.  
  402.     private static void createBundledBinary(String source, String destination)
  403.         throws IOException
  404.     {
  405.         // Already exists, we don't have to do anything
  406.         File destinationFile = new File(destination);
  407.         if (destinationFile.exists())
  408.             return;
  409.  
  410.         File parentDirectory = destinationFile.getParentFile();
  411.         if (!parentDirectory.exists())
  412.             parentDirectory.mkdirs();
  413.  
  414.         destinationFile.createNewFile();
  415.  
  416.         InputStream inputStream = new FileInputStream(source);
  417.         OutputStream outputStream = new FileOutputStream(destinationFile);
  418.         copyFile(inputStream, outputStream);
  419.  
  420.         inputStream.close();
  421.         outputStream.close();
  422.     }
  423.  
  424.     private boolean cleanCacheIfNecessary(String pluginsPrefix, long packageVersion)
  425.     {
  426.         File versionFile = new File(pluginsPrefix + "cache.version");
  427.  
  428.         long cacheVersion = 0;
  429.         if (versionFile.exists() && versionFile.canRead()) {
  430.             try {
  431.                 DataInputStream inputStream = new DataInputStream(new FileInputStream(versionFile));
  432.                 cacheVersion = inputStream.readLong();
  433.                 inputStream.close();
  434.              } catch (Exception e) {
  435.                 e.printStackTrace();
  436.              }
  437.         }
  438.  
  439.         if (cacheVersion != packageVersion) {
  440.             deleteRecursively(new File(pluginsPrefix));
  441.             return true;
  442.         } else {
  443.             return false;
  444.         }
  445.     }
  446.  
  447.     private void extractBundledPluginsAndImports(String pluginsPrefix)
  448.         throws IOException
  449.     {
  450.         ArrayList<String> libs = new ArrayList<String>();
  451.  
  452.         String dataDir = getApplicationInfo().dataDir + "/";
  453.  
  454.         long packageVersion = -1;
  455.         try {
  456.             PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
  457.             packageVersion = packageInfo.lastUpdateTime;
  458.         } catch (Exception e) {
  459.             e.printStackTrace();
  460.         }
  461.  
  462.         if (!cleanCacheIfNecessary(pluginsPrefix, packageVersion))
  463.             return;
  464.  
  465.         {
  466.             File versionFile = new File(pluginsPrefix + "cache.version");
  467.  
  468.             File parentDirectory = versionFile.getParentFile();
  469.             if (!parentDirectory.exists())
  470.                 parentDirectory.mkdirs();
  471.  
  472.             versionFile.createNewFile();
  473.  
  474.             DataOutputStream outputStream = new DataOutputStream(new FileOutputStream(versionFile));
  475.             outputStream.writeLong(packageVersion);
  476.             outputStream.close();
  477.         }
  478.  
  479.         {
  480.             String key = BUNDLED_IN_LIB_RESOURCE_ID_KEY;
  481.             java.util.Set<String> keys = m_activityInfo.metaData.keySet();
  482.             if (m_activityInfo.metaData.containsKey(key)) {
  483.                 String[] list = getResources().getStringArray(m_activityInfo.metaData.getInt(key));
  484.  
  485.                 for (String bundledImportBinary : list) {
  486.                     String[] split = bundledImportBinary.split(":");
  487.                     String sourceFileName = dataDir + "lib/" + split[0];
  488.                     String destinationFileName = pluginsPrefix + split[1];
  489.                     createBundledBinary(sourceFileName, destinationFileName);
  490.                 }
  491.             }
  492.         }
  493.  
  494.         {
  495.             String key = BUNDLED_IN_ASSETS_RESOURCE_ID_KEY;
  496.             if (m_activityInfo.metaData.containsKey(key)) {
  497.                 String[] list = getResources().getStringArray(m_activityInfo.metaData.getInt(key));
  498.  
  499.                 for (String fileName : list) {
  500.                     String[] split = fileName.split(":");
  501.                     String sourceFileName = split[0];
  502.                     String destinationFileName = pluginsPrefix + split[1];
  503.                     copyAsset(sourceFileName, destinationFileName);
  504.                 }
  505.             }
  506.  
  507.         }
  508.     }
  509.  
  510.     private void deleteRecursively(File directory)
  511.     {
  512.         File[] files = directory.listFiles();
  513.         if (files != null) {
  514.             for (File file : files) {
  515.                 if (file.isDirectory())
  516.                     deleteRecursively(file);
  517.                 else
  518.                     file.delete();
  519.             }
  520.  
  521.             directory.delete();
  522.         }
  523.     }
  524.  
  525.     private void cleanOldCacheIfNecessary(String oldLocalPrefix, String localPrefix)
  526.     {
  527.         File newCache = new File(localPrefix);
  528.         if (!newCache.exists()) {
  529.             {
  530.                 File oldPluginsCache = new File(oldLocalPrefix + "plugins/");
  531.                 if (oldPluginsCache.exists() && oldPluginsCache.isDirectory())
  532.                     deleteRecursively(oldPluginsCache);
  533.             }
  534.  
  535.             {
  536.                 File oldImportsCache = new File(oldLocalPrefix + "imports/");
  537.                 if (oldImportsCache.exists() && oldImportsCache.isDirectory())
  538.                     deleteRecursively(oldImportsCache);
  539.             }
  540.  
  541.             {
  542.                 File oldQmlCache = new File(oldLocalPrefix + "qml/");
  543.                 if (oldQmlCache.exists() && oldQmlCache.isDirectory())
  544.                     deleteRecursively(oldQmlCache);
  545.             }
  546.         }
  547.     }
  548.  
  549.     private void startApp(final boolean firstStart)
  550.     {
  551.         try {
  552.             if (m_activityInfo.metaData.containsKey("android.app.qt_sources_resource_id")) {
  553.                 int resourceId = m_activityInfo.metaData.getInt("android.app.qt_sources_resource_id");
  554.                 m_sources = getResources().getStringArray(resourceId);
  555.             }
  556.  
  557.             if (m_activityInfo.metaData.containsKey("android.app.repository"))
  558.                 m_repository = m_activityInfo.metaData.getString("android.app.repository");
  559.  
  560.             if (m_activityInfo.metaData.containsKey("android.app.qt_libs_resource_id")) {
  561.                 int resourceId = m_activityInfo.metaData.getInt("android.app.qt_libs_resource_id");
  562.                 m_qtLibs = getResources().getStringArray(resourceId);
  563.             }
  564.  
  565.             if (m_activityInfo.metaData.containsKey("android.app.use_local_qt_libs")
  566.                     && m_activityInfo.metaData.getInt("android.app.use_local_qt_libs") == 1) {
  567.                 ArrayList<String> libraryList = new ArrayList<String>();
  568.  
  569.  
  570.                 String localPrefix = "/data/local/tmp/qt/";
  571.                 if (m_activityInfo.metaData.containsKey("android.app.libs_prefix"))
  572.                     localPrefix = m_activityInfo.metaData.getString("android.app.libs_prefix");
  573.  
  574.                 String pluginsPrefix = localPrefix;
  575.  
  576.                 boolean bundlingQtLibs = false;
  577.                 if (m_activityInfo.metaData.containsKey("android.app.bundle_local_qt_libs")
  578.                     && m_activityInfo.metaData.getInt("android.app.bundle_local_qt_libs") == 1) {
  579.                     localPrefix = getApplicationInfo().dataDir + "/";
  580.                     pluginsPrefix = localPrefix + "qt-reserved-files/";
  581.                     cleanOldCacheIfNecessary(localPrefix, pluginsPrefix);
  582.                     extractBundledPluginsAndImports(pluginsPrefix);
  583.                     bundlingQtLibs = true;
  584.                 }
  585.  
  586.                 if (m_qtLibs != null) {
  587.                     for (int i=0;i<m_qtLibs.length;i++) {
  588.                         libraryList.add(localPrefix
  589.                                         + "lib/lib"
  590.                                         + m_qtLibs[i]
  591.                                         + ".so");
  592.                     }
  593.                 }
  594.  
  595.                 if (m_activityInfo.metaData.containsKey("android.app.load_local_libs")) {
  596.                     String[] extraLibs = m_activityInfo.metaData.getString("android.app.load_local_libs").split(":");
  597.                     for (String lib : extraLibs) {
  598.                         if (lib.length() > 0) {
  599.                             if (lib.startsWith("lib/"))
  600.                                 libraryList.add(localPrefix + lib);
  601.                             else
  602.                                 libraryList.add(pluginsPrefix + lib);
  603.                         }
  604.                     }
  605.                 }
  606.  
  607.  
  608.                 String dexPaths = new String();
  609.                 String pathSeparator = System.getProperty("path.separator", ":");
  610.                 if (!bundlingQtLibs && m_activityInfo.metaData.containsKey("android.app.load_local_jars")) {
  611.                     String[] jarFiles = m_activityInfo.metaData.getString("android.app.load_local_jars").split(":");
  612.                     for (String jar:jarFiles) {
  613.                         if (jar.length() > 0) {
  614.                             if (dexPaths.length() > 0)
  615.                                 dexPaths += pathSeparator;
  616.                             dexPaths += localPrefix + jar;
  617.                         }
  618.                     }
  619.                 }
  620.  
  621.                 Bundle loaderParams = new Bundle();
  622.                 loaderParams.putInt(ERROR_CODE_KEY, 0);
  623.                 loaderParams.putString(DEX_PATH_KEY, dexPaths);
  624.                 loaderParams.putString(LOADER_CLASS_NAME_KEY, "org.qtproject.qt5.android.QtActivityDelegate");
  625.                 if (m_activityInfo.metaData.containsKey("android.app.static_init_classes")) {
  626.                     loaderParams.putStringArray(STATIC_INIT_CLASSES_KEY,
  627.                                                 m_activityInfo.metaData.getString("android.app.static_init_classes").split(":"));
  628.                 }
  629.                 loaderParams.putStringArrayList(NATIVE_LIBRARIES_KEY, libraryList);
  630.  
  631.  
  632.                 String themePath = getApplicationInfo().dataDir + "/qt-reserved-files/android-style/";
  633.                 String stylePath = themePath + m_displayDensity + "/";
  634.                 if (!(new File(stylePath)).exists())
  635.                     loaderParams.putString(EXTRACT_STYLE_KEY, stylePath);
  636.                 ENVIRONMENT_VARIABLES += "\tMINISTRO_ANDROID_STYLE_PATH=" + stylePath
  637.                                        + "\tQT_ANDROID_THEMES_ROOT_PATH=" + themePath;
  638.  
  639.                 loaderParams.putString(ENVIRONMENT_VARIABLES_KEY, ENVIRONMENT_VARIABLES
  640.                                                                   + "\tQML2_IMPORT_PATH=" + pluginsPrefix + "/qml"
  641.                                                                   + "\tQML_IMPORT_PATH=" + pluginsPrefix + "/imports"
  642.                                                                   + "\tQT_PLUGIN_PATH=" + pluginsPrefix + "/plugins");
  643.  
  644.                 if (APPLICATION_PARAMETERS != null) {
  645.                     loaderParams.putString(APPLICATION_PARAMETERS_KEY, APPLICATION_PARAMETERS);
  646.                 } else {
  647.                     Intent intent = getIntent();
  648.                     if (intent != null) {
  649.                         String parameters = intent.getStringExtra("applicationArguments");
  650.                         if (parameters != null)
  651.                             loaderParams.putString(APPLICATION_PARAMETERS_KEY, parameters.replace(' ', '\t'));
  652.                     }
  653.                 }
  654.  
  655.                 loadApplication(loaderParams);
  656.                 return;
  657.             }
  658.  
  659.             try {
  660.                 if (!bindService(new Intent(org.kde.necessitas.ministro.IMinistro.class.getCanonicalName()),
  661.                                  m_ministroConnection,
  662.                                  Context.BIND_AUTO_CREATE)) {
  663.                     throw new SecurityException("");
  664.                 }
  665.             } catch (Exception e) {
  666.                 if (firstStart) {
  667.                     String msg = "This application requires Ministro service. Would you like to install it?";
  668.                     if (m_activityInfo.metaData.containsKey("android.app.ministro_needed_msg"))
  669.                         msg = m_activityInfo.metaData.getString("android.app.ministro_needed_msg");
  670.                     downloadUpgradeMinistro(msg);
  671.                 } else {
  672.                     ministroNotFound();
  673.                 }
  674.             }
  675.         } catch (Exception e) {
  676.             Log.e(QtApplication.QtTAG, "Can't create main activity", e);
  677.         }
  678.     }
  679.  
  680.  
  681.  
  682.     /////////////////////////// forward all notifications ////////////////////////////
  683.     /////////////////////////// Super class calls ////////////////////////////////////
  684.     /////////////// PLEASE DO NOT CHANGE THE FOLLOWING CODE //////////////////////////
  685.     //////////////////////////////////////////////////////////////////////////////////
  686.  
  687.     @Override
  688.     public boolean dispatchKeyEvent(KeyEvent event)
  689.     {
  690.         if (QtApplication.m_delegateObject != null && QtApplication.dispatchKeyEvent != null)
  691.             return (Boolean) QtApplication.invokeDelegateMethod(QtApplication.dispatchKeyEvent, event);
  692.         else
  693.             return super.dispatchKeyEvent(event);
  694.     }
  695.     public boolean super_dispatchKeyEvent(KeyEvent event)
  696.     {
  697.         return super.dispatchKeyEvent(event);
  698.     }
  699.     //---------------------------------------------------------------------------
  700.  
  701.     @Override
  702.     public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event)
  703.     {
  704.         if (QtApplication.m_delegateObject != null && QtApplication.dispatchPopulateAccessibilityEvent != null)
  705.             return (Boolean) QtApplication.invokeDelegateMethod(QtApplication.dispatchPopulateAccessibilityEvent, event);
  706.         else
  707.             return super.dispatchPopulateAccessibilityEvent(event);
  708.     }
  709.     public boolean super_dispatchPopulateAccessibilityEvent(AccessibilityEvent event)
  710.     {
  711.         return super_dispatchPopulateAccessibilityEvent(event);
  712.     }
  713.     //---------------------------------------------------------------------------
  714.  
  715.     @Override
  716.     public boolean dispatchTouchEvent(MotionEvent ev)
  717.     {
  718.         if (QtApplication.m_delegateObject != null && QtApplication.dispatchTouchEvent != null)
  719.             return (Boolean) QtApplication.invokeDelegateMethod(QtApplication.dispatchTouchEvent, ev);
  720.         else
  721.             return super.dispatchTouchEvent(ev);
  722.     }
  723.     public boolean super_dispatchTouchEvent(MotionEvent event)
  724.     {
  725.         return super.dispatchTouchEvent(event);
  726.     }
  727.     //---------------------------------------------------------------------------
  728.  
  729.     @Override
  730.     public boolean dispatchTrackballEvent(MotionEvent ev)
  731.     {
  732.         if (QtApplication.m_delegateObject != null && QtApplication.dispatchTrackballEvent != null)
  733.             return (Boolean) QtApplication.invokeDelegateMethod(QtApplication.dispatchTrackballEvent, ev);
  734.         else
  735.             return super.dispatchTrackballEvent(ev);
  736.     }
  737.     public boolean super_dispatchTrackballEvent(MotionEvent event)
  738.     {
  739.         return super.dispatchTrackballEvent(event);
  740.     }
  741.     //---------------------------------------------------------------------------
  742.  
  743.     @Override
  744.     protected void onActivityResult(int requestCode, int resultCode, Intent data)
  745.     {
  746.  
  747.         if (QtApplication.m_delegateObject != null && QtApplication.onActivityResult != null) {
  748.             QtApplication.invokeDelegateMethod(QtApplication.onActivityResult, requestCode, resultCode, data);
  749.             return;
  750.         }
  751.         if (requestCode == MINISTRO_INSTALL_REQUEST_CODE)
  752.             startApp(false);
  753.         super.onActivityResult(requestCode, resultCode, data);
  754.     }
  755.     public void super_onActivityResult(int requestCode, int resultCode, Intent data)
  756.     {
  757.         super.onActivityResult(requestCode, resultCode, data);
  758.     }
  759.     //---------------------------------------------------------------------------
  760.  
  761.     @Override
  762.     protected void onApplyThemeResource(Theme theme, int resid, boolean first)
  763.     {
  764.         if (!QtApplication.invokeDelegate(theme, resid, first).invoked)
  765.             super.onApplyThemeResource(theme, resid, first);
  766.     }
  767.     public void super_onApplyThemeResource(Theme theme, int resid, boolean first)
  768.     {
  769.         super.onApplyThemeResource(theme, resid, first);
  770.     }
  771.     //---------------------------------------------------------------------------
  772.  
  773.  
  774.     @Override
  775.     protected void onChildTitleChanged(Activity childActivity, CharSequence title)
  776.     {
  777.         if (!QtApplication.invokeDelegate(childActivity, title).invoked)
  778.             super.onChildTitleChanged(childActivity, title);
  779.     }
  780.     public void super_onChildTitleChanged(Activity childActivity, CharSequence title)
  781.     {
  782.         super.onChildTitleChanged(childActivity, title);
  783.     }
  784.     //---------------------------------------------------------------------------
  785.  
  786.     @Override
  787.     public void onConfigurationChanged(Configuration newConfig)
  788.     {
  789.         if (!QtApplication.invokeDelegate(newConfig).invoked)
  790.             super.onConfigurationChanged(newConfig);
  791.     }
  792.     public void super_onConfigurationChanged(Configuration newConfig)
  793.     {
  794.         super.onConfigurationChanged(newConfig);
  795.     }
  796.     //---------------------------------------------------------------------------
  797.  
  798.     @Override
  799.     public void onContentChanged()
  800.     {
  801.         if (!QtApplication.invokeDelegate().invoked)
  802.             super.onContentChanged();
  803.     }
  804.     public void super_onContentChanged()
  805.     {
  806.         super.onContentChanged();
  807.     }
  808.     //---------------------------------------------------------------------------
  809.  
  810.     @Override
  811.     public boolean onContextItemSelected(MenuItem item)
  812.     {
  813.         QtApplication.InvokeResult res = QtApplication.invokeDelegate(item);
  814.         if (res.invoked)
  815.             return (Boolean)res.methodReturns;
  816.         else
  817.             return super.onContextItemSelected(item);
  818.     }
  819.     public boolean super_onContextItemSelected(MenuItem item)
  820.     {
  821.         return super.onContextItemSelected(item);
  822.     }
  823.     //---------------------------------------------------------------------------
  824.  
  825.     @Override
  826.     public void onContextMenuClosed(Menu menu)
  827.     {
  828.         if (!QtApplication.invokeDelegate(menu).invoked)
  829.             super.onContextMenuClosed(menu);
  830.     }
  831.     public void super_onContextMenuClosed(Menu menu)
  832.     {
  833.         super.onContextMenuClosed(menu);
  834.     }
  835.     //---------------------------------------------------------------------------
  836.  
  837.     @Override
  838.     public void onCreate(Bundle savedInstanceState)
  839.     {
  840.         super.onCreate(savedInstanceState);
  841.  
  842.         try {
  843.             m_activityInfo = getPackageManager().getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
  844.             for (Field f : Class.forName("android.R$style").getDeclaredFields()) {
  845.                 if (f.getInt(null) == m_activityInfo.getThemeResource()) {
  846.                     QT_ANDROID_THEMES = new String[] {f.getName()};
  847.                     QT_ANDROID_DEFAULT_THEME = f.getName();
  848.                 }
  849.             }
  850.         } catch (Exception e) {
  851.             e.printStackTrace();
  852.             finish();
  853.             return;
  854.         }
  855.  
  856.         try {
  857.             setTheme(Class.forName("android.R$style").getDeclaredField(QT_ANDROID_DEFAULT_THEME).getInt(null));
  858.         } catch (Exception e) {
  859.             e.printStackTrace();
  860.         }
  861.  
  862.         if (Build.VERSION.SDK_INT > 10) {
  863.             try {
  864.                 requestWindowFeature(Window.class.getField("FEATURE_ACTION_BAR").getInt(null));
  865.             } catch (Exception e) {
  866.                 e.printStackTrace();
  867.             }
  868.         } else {
  869.             requestWindowFeature(Window.FEATURE_NO_TITLE);
  870.         }
  871.  
  872.         if (QtApplication.m_delegateObject != null && QtApplication.onCreate != null) {
  873.             QtApplication.invokeDelegateMethod(QtApplication.onCreate, savedInstanceState);
  874.             return;
  875.         }
  876.  
  877.         m_displayDensity = getResources().getDisplayMetrics().densityDpi;
  878.  
  879.         ENVIRONMENT_VARIABLES += "\tQT_ANDROID_THEME=" + QT_ANDROID_DEFAULT_THEME
  880.                               + "/\tQT_ANDROID_THEME_DISPLAY_DPI=" + m_displayDensity + "\t";
  881.  
  882.         if (null == getLastNonConfigurationInstance()) {
  883.             // if splash screen is defined, then show it
  884.             if (m_activityInfo.metaData.containsKey("android.app.splash_screen_drawable"))
  885.                 getWindow().setBackgroundDrawableResource(m_activityInfo.metaData.getInt("android.app.splash_screen_drawable"));
  886.             else
  887.                 getWindow().setBackgroundDrawable(new ColorDrawable(0xff000000));
  888.  
  889.             if (m_activityInfo.metaData.containsKey("android.app.background_running")
  890.                 && m_activityInfo.metaData.getBoolean("android.app.background_running")) {
  891.                 ENVIRONMENT_VARIABLES += "QT_BLOCK_EVENT_LOOPS_WHEN_SUSPENDED=0\t";
  892.             } else {
  893.                 ENVIRONMENT_VARIABLES += "QT_BLOCK_EVENT_LOOPS_WHEN_SUSPENDED=1\t";
  894.             }
  895.             startApp(true);
  896.         }
  897.     }
  898.     //---------------------------------------------------------------------------
  899.  
  900.     @Override
  901.     public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
  902.     {
  903.         if (!QtApplication.invokeDelegate(menu, v, menuInfo).invoked)
  904.             super.onCreateContextMenu(menu, v, menuInfo);
  905.     }
  906.     public void super_onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
  907.     {
  908.         super.onCreateContextMenu(menu, v, menuInfo);
  909.     }
  910.     //---------------------------------------------------------------------------
  911.  
  912.     @Override
  913.     public CharSequence onCreateDescription()
  914.     {
  915.         QtApplication.InvokeResult res = QtApplication.invokeDelegate();
  916.         if (res.invoked)
  917.             return (CharSequence)res.methodReturns;
  918.         else
  919.             return super.onCreateDescription();
  920.     }
  921.     public CharSequence super_onCreateDescription()
  922.     {
  923.         return super.onCreateDescription();
  924.     }
  925.     //---------------------------------------------------------------------------
  926.  
  927.     @Override
  928.     protected Dialog onCreateDialog(int id)
  929.     {
  930.         QtApplication.InvokeResult res = QtApplication.invokeDelegate(id);
  931.         if (res.invoked)
  932.             return (Dialog)res.methodReturns;
  933.         else
  934.             return super.onCreateDialog(id);
  935.     }
  936.     public Dialog super_onCreateDialog(int id)
  937.     {
  938.         return super.onCreateDialog(id);
  939.     }
  940.     //---------------------------------------------------------------------------
  941.  
  942.     @Override
  943.     public boolean onCreateOptionsMenu(Menu menu)
  944.     {
  945.         QtApplication.InvokeResult res = QtApplication.invokeDelegate(menu);
  946.         if (res.invoked)
  947.             return (Boolean)res.methodReturns;
  948.         else
  949.             return super.onCreateOptionsMenu(menu);
  950.     }
  951.     public boolean super_onCreateOptionsMenu(Menu menu)
  952.     {
  953.         return super.onCreateOptionsMenu(menu);
  954.     }
  955.     //---------------------------------------------------------------------------
  956.  
  957.     @Override
  958.     public boolean onCreatePanelMenu(int featureId, Menu menu)
  959.     {
  960.         QtApplication.InvokeResult res = QtApplication.invokeDelegate(featureId, menu);
  961.         if (res.invoked)
  962.             return (Boolean)res.methodReturns;
  963.         else
  964.             return super.onCreatePanelMenu(featureId, menu);
  965.     }
  966.     public boolean super_onCreatePanelMenu(int featureId, Menu menu)
  967.     {
  968.         return super.onCreatePanelMenu(featureId, menu);
  969.     }
  970.     //---------------------------------------------------------------------------
  971.  
  972.  
  973.     @Override
  974.     public View onCreatePanelView(int featureId)
  975.     {
  976.         QtApplication.InvokeResult res = QtApplication.invokeDelegate(featureId);
  977.         if (res.invoked)
  978.             return (View)res.methodReturns;
  979.         else
  980.             return super.onCreatePanelView(featureId);
  981.     }
  982.     public View super_onCreatePanelView(int featureId)
  983.     {
  984.         return super.onCreatePanelView(featureId);
  985.     }
  986.     //---------------------------------------------------------------------------
  987.  
  988.     @Override
  989.     public boolean onCreateThumbnail(Bitmap outBitmap, Canvas canvas)
  990.     {
  991.         QtApplication.InvokeResult res = QtApplication.invokeDelegate(outBitmap, canvas);
  992.         if (res.invoked)
  993.             return (Boolean)res.methodReturns;
  994.         else
  995.             return super.onCreateThumbnail(outBitmap, canvas);
  996.     }
  997.     public boolean super_onCreateThumbnail(Bitmap outBitmap, Canvas canvas)
  998.     {
  999.         return super.onCreateThumbnail(outBitmap, canvas);
  1000.     }
  1001.     //---------------------------------------------------------------------------
  1002.  
  1003.     @Override
  1004.     public View onCreateView(String name, Context context, AttributeSet attrs)
  1005.     {
  1006.         QtApplication.InvokeResult res = QtApplication.invokeDelegate(name, context, attrs);
  1007.         if (res.invoked)
  1008.             return (View)res.methodReturns;
  1009.         else
  1010.             return super.onCreateView(name, context, attrs);
  1011.     }
  1012.     public View super_onCreateView(String name, Context context, AttributeSet attrs)
  1013.     {
  1014.         return super.onCreateView(name, context, attrs);
  1015.     }
  1016.     //---------------------------------------------------------------------------
  1017.  
  1018.     @Override
  1019.     protected void onDestroy()
  1020.     {
  1021.         super.onDestroy();
  1022.         QtApplication.invokeDelegate();
  1023.     }
  1024.     //---------------------------------------------------------------------------
  1025.  
  1026.  
  1027.     @Override
  1028.     public boolean onKeyDown(int keyCode, KeyEvent event)
  1029.     {
  1030.         if (QtApplication.m_delegateObject != null && QtApplication.onKeyDown != null)
  1031.             return (Boolean) QtApplication.invokeDelegateMethod(QtApplication.onKeyDown, keyCode, event);
  1032.         else
  1033.             return super.onKeyDown(keyCode, event);
  1034.     }
  1035.     public boolean super_onKeyDown(int keyCode, KeyEvent event)
  1036.     {
  1037.         return super.onKeyDown(keyCode, event);
  1038.     }
  1039.     //---------------------------------------------------------------------------
  1040.  
  1041.  
  1042.     @Override
  1043.     public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)
  1044.     {
  1045.         if (QtApplication.m_delegateObject != null && QtApplication.onKeyMultiple != null)
  1046.             return (Boolean) QtApplication.invokeDelegateMethod(QtApplication.onKeyMultiple, keyCode, repeatCount, event);
  1047.         else
  1048.             return super.onKeyMultiple(keyCode, repeatCount, event);
  1049.     }
  1050.     public boolean super_onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)
  1051.     {
  1052.         return super.onKeyMultiple(keyCode, repeatCount, event);
  1053.     }
  1054.     //---------------------------------------------------------------------------
  1055.  
  1056.     @Override
  1057.     public boolean onKeyUp(int keyCode, KeyEvent event)
  1058.     {
  1059.         if (QtApplication.m_delegateObject != null  && QtApplication.onKeyDown != null)
  1060.             return (Boolean) QtApplication.invokeDelegateMethod(QtApplication.onKeyUp, keyCode, event);
  1061.         else
  1062.             return super.onKeyUp(keyCode, event);
  1063.     }
  1064.     public boolean super_onKeyUp(int keyCode, KeyEvent event)
  1065.     {
  1066.         return super.onKeyUp(keyCode, event);
  1067.     }
  1068.     //---------------------------------------------------------------------------
  1069.  
  1070.     @Override
  1071.     public void onLowMemory()
  1072.     {
  1073.         if (!QtApplication.invokeDelegate().invoked)
  1074.             super.onLowMemory();
  1075.     }
  1076.     //---------------------------------------------------------------------------
  1077.  
  1078.     @Override
  1079.     public boolean onMenuItemSelected(int featureId, MenuItem item)
  1080.     {
  1081.         QtApplication.InvokeResult res = QtApplication.invokeDelegate(featureId, item);
  1082.         if (res.invoked)
  1083.             return (Boolean)res.methodReturns;
  1084.         else
  1085.             return super.onMenuItemSelected(featureId, item);
  1086.     }
  1087.     public boolean super_onMenuItemSelected(int featureId, MenuItem item)
  1088.     {
  1089.         return super.onMenuItemSelected(featureId, item);
  1090.     }
  1091.     //---------------------------------------------------------------------------
  1092.  
  1093.     @Override
  1094.     public boolean onMenuOpened(int featureId, Menu menu)
  1095.     {
  1096.         QtApplication.InvokeResult res = QtApplication.invokeDelegate(featureId, menu);
  1097.         if (res.invoked)
  1098.             return (Boolean)res.methodReturns;
  1099.         else
  1100.             return super.onMenuOpened(featureId, menu);
  1101.     }
  1102.     public boolean super_onMenuOpened(int featureId, Menu menu)
  1103.     {
  1104.         return super.onMenuOpened(featureId, menu);
  1105.     }
  1106.     //---------------------------------------------------------------------------
  1107.  
  1108.     @Override
  1109.     protected void onNewIntent(Intent intent)
  1110.     {
  1111.         if (!QtApplication.invokeDelegate(intent).invoked)
  1112.             super.onNewIntent(intent);
  1113.     }
  1114.     public void super_onNewIntent(Intent intent)
  1115.     {
  1116.         super.onNewIntent(intent);
  1117.     }
  1118.     //---------------------------------------------------------------------------
  1119.  
  1120.     @Override
  1121.     public boolean onOptionsItemSelected(MenuItem item)
  1122.     {
  1123.         QtApplication.InvokeResult res = QtApplication.invokeDelegate(item);
  1124.         if (res.invoked)
  1125.             return (Boolean)res.methodReturns;
  1126.         else
  1127.             return super.onOptionsItemSelected(item);
  1128.     }
  1129.     public boolean super_onOptionsItemSelected(MenuItem item)
  1130.     {
  1131.         return super.onOptionsItemSelected(item);
  1132.     }
  1133.     //---------------------------------------------------------------------------
  1134.  
  1135.     @Override
  1136.     public void onOptionsMenuClosed(Menu menu)
  1137.     {
  1138.         if (!QtApplication.invokeDelegate(menu).invoked)
  1139.             super.onOptionsMenuClosed(menu);
  1140.     }
  1141.     public void super_onOptionsMenuClosed(Menu menu)
  1142.     {
  1143.         super.onOptionsMenuClosed(menu);
  1144.     }
  1145.     //---------------------------------------------------------------------------
  1146.  
  1147.     @Override
  1148.     public void onPanelClosed(int featureId, Menu menu)
  1149.     {
  1150.         if (!QtApplication.invokeDelegate(featureId, menu).invoked)
  1151.             super.onPanelClosed(featureId, menu);
  1152.     }
  1153.     public void super_onPanelClosed(int featureId, Menu menu)
  1154.     {
  1155.         super.onPanelClosed(featureId, menu);
  1156.     }
  1157.     //---------------------------------------------------------------------------
  1158.  
  1159.     @Override
  1160.     protected void onPause()
  1161.     {
  1162.         super.onPause();
  1163.         QtApplication.invokeDelegate();
  1164.     }
  1165.     //---------------------------------------------------------------------------
  1166.  
  1167.     @Override
  1168.     protected void onPostCreate(Bundle savedInstanceState)
  1169.     {
  1170.         super.onPostCreate(savedInstanceState);
  1171.         QtApplication.invokeDelegate(savedInstanceState);
  1172.     }
  1173.     //---------------------------------------------------------------------------
  1174.  
  1175.     @Override
  1176.     protected void onPostResume()
  1177.     {
  1178.         super.onPostResume();
  1179.         QtApplication.invokeDelegate();
  1180.     }
  1181.     //---------------------------------------------------------------------------
  1182.  
  1183.     @Override
  1184.     protected void onPrepareDialog(int id, Dialog dialog)
  1185.     {
  1186.         if (!QtApplication.invokeDelegate(id, dialog).invoked)
  1187.             super.onPrepareDialog(id, dialog);
  1188.     }
  1189.     public void super_onPrepareDialog(int id, Dialog dialog)
  1190.     {
  1191.         super.onPrepareDialog(id, dialog);
  1192.     }
  1193.     //---------------------------------------------------------------------------
  1194.  
  1195.     @Override
  1196.     public boolean onPrepareOptionsMenu(Menu menu)
  1197.     {
  1198.         QtApplication.InvokeResult res = QtApplication.invokeDelegate(menu);
  1199.         if (res.invoked)
  1200.             return (Boolean)res.methodReturns;
  1201.         else
  1202.             return super.onPrepareOptionsMenu(menu);
  1203.     }
  1204.     public boolean super_onPrepareOptionsMenu(Menu menu)
  1205.     {
  1206.         return super.onPrepareOptionsMenu(menu);
  1207.     }
  1208.     //---------------------------------------------------------------------------
  1209.  
  1210.     @Override
  1211.     public boolean onPreparePanel(int featureId, View view, Menu menu)
  1212.     {
  1213.         QtApplication.InvokeResult res = QtApplication.invokeDelegate(featureId, view, menu);
  1214.         if (res.invoked)
  1215.             return (Boolean)res.methodReturns;
  1216.         else
  1217.             return super.onPreparePanel(featureId, view, menu);
  1218.     }
  1219.     public boolean super_onPreparePanel(int featureId, View view, Menu menu)
  1220.     {
  1221.         return super.onPreparePanel(featureId, view, menu);
  1222.     }
  1223.     //---------------------------------------------------------------------------
  1224.  
  1225.     @Override
  1226.     protected void onRestart()
  1227.     {
  1228.         super.onRestart();
  1229.         QtApplication.invokeDelegate();
  1230.     }
  1231.     //---------------------------------------------------------------------------
  1232.  
  1233.     @Override
  1234.     protected void onRestoreInstanceState(Bundle savedInstanceState)
  1235.     {
  1236.         if (!QtApplication.invokeDelegate(savedInstanceState).invoked)
  1237.             super.onRestoreInstanceState(savedInstanceState);
  1238.     }
  1239.     public void super_onRestoreInstanceState(Bundle savedInstanceState)
  1240.     {
  1241.         super.onRestoreInstanceState(savedInstanceState);
  1242.     }
  1243.     //---------------------------------------------------------------------------
  1244.  
  1245.     @Override
  1246.     protected void onResume()
  1247.     {
  1248.         super.onResume();
  1249.         QtApplication.invokeDelegate();
  1250.     }
  1251.     //---------------------------------------------------------------------------
  1252.  
  1253.     @Override
  1254.     public Object onRetainNonConfigurationInstance()
  1255.     {
  1256.         QtApplication.InvokeResult res = QtApplication.invokeDelegate();
  1257.         if (res.invoked)
  1258.             return res.methodReturns;
  1259.         else
  1260.             return super.onRetainNonConfigurationInstance();
  1261.     }
  1262.     public Object super_onRetainNonConfigurationInstance()
  1263.     {
  1264.         return super.onRetainNonConfigurationInstance();
  1265.     }
  1266.     //---------------------------------------------------------------------------
  1267.  
  1268.     @Override
  1269.     protected void onSaveInstanceState(Bundle outState)
  1270.     {
  1271.         if (!QtApplication.invokeDelegate(outState).invoked)
  1272.             super.onSaveInstanceState(outState);
  1273.     }
  1274.     public void super_onSaveInstanceState(Bundle outState)
  1275.     {
  1276.         super.onSaveInstanceState(outState);
  1277.  
  1278.     }
  1279.     //---------------------------------------------------------------------------
  1280.  
  1281.     @Override
  1282.     public boolean onSearchRequested()
  1283.     {
  1284.         QtApplication.InvokeResult res = QtApplication.invokeDelegate();
  1285.         if (res.invoked)
  1286.             return (Boolean)res.methodReturns;
  1287.         else
  1288.             return super.onSearchRequested();
  1289.     }
  1290.     public boolean super_onSearchRequested()
  1291.     {
  1292.         return super.onSearchRequested();
  1293.     }
  1294.     //---------------------------------------------------------------------------
  1295.  
  1296.     @Override
  1297.     protected void onStart()
  1298.     {
  1299.         super.onStart();
  1300.         QtApplication.invokeDelegate();
  1301.     }
  1302.     //---------------------------------------------------------------------------
  1303.  
  1304.     @Override
  1305.     protected void onStop()
  1306.     {
  1307.         super.onStop();
  1308.         QtApplication.invokeDelegate();
  1309.     }
  1310.     //---------------------------------------------------------------------------
  1311.  
  1312.     @Override
  1313.     protected void onTitleChanged(CharSequence title, int color)
  1314.     {
  1315.         if (!QtApplication.invokeDelegate(title, color).invoked)
  1316.             super.onTitleChanged(title, color);
  1317.     }
  1318.     public void super_onTitleChanged(CharSequence title, int color)
  1319.     {
  1320.         super.onTitleChanged(title, color);
  1321.     }
  1322.     //---------------------------------------------------------------------------
  1323.  
  1324.     @Override
  1325.     public boolean onTouchEvent(MotionEvent event)
  1326.     {
  1327.         if (QtApplication.m_delegateObject != null  && QtApplication.onTouchEvent != null)
  1328.             return (Boolean) QtApplication.invokeDelegateMethod(QtApplication.onTouchEvent, event);
  1329.         else
  1330.             return super.onTouchEvent(event);
  1331.     }
  1332.     public boolean super_onTouchEvent(MotionEvent event)
  1333.     {
  1334.         return super.onTouchEvent(event);
  1335.     }
  1336.     //---------------------------------------------------------------------------
  1337.  
  1338.     @Override
  1339.     public boolean onTrackballEvent(MotionEvent event)
  1340.     {
  1341.         if (QtApplication.m_delegateObject != null  && QtApplication.onTrackballEvent != null)
  1342.             return (Boolean) QtApplication.invokeDelegateMethod(QtApplication.onTrackballEvent, event);
  1343.         else
  1344.             return super.onTrackballEvent(event);
  1345.     }
  1346.     public boolean super_onTrackballEvent(MotionEvent event)
  1347.     {
  1348.         return super.onTrackballEvent(event);
  1349.     }
  1350.     //---------------------------------------------------------------------------
  1351.  
  1352.     @Override
  1353.     public void onUserInteraction()
  1354.     {
  1355.         if (!QtApplication.invokeDelegate().invoked)
  1356.             super.onUserInteraction();
  1357.     }
  1358.     public void super_onUserInteraction()
  1359.     {
  1360.         super.onUserInteraction();
  1361.     }
  1362.     //---------------------------------------------------------------------------
  1363.  
  1364.     @Override
  1365.     protected void onUserLeaveHint()
  1366.     {
  1367.         if (!QtApplication.invokeDelegate().invoked)
  1368.             super.onUserLeaveHint();
  1369.     }
  1370.     public void super_onUserLeaveHint()
  1371.     {
  1372.         super.onUserLeaveHint();
  1373.     }
  1374.     //---------------------------------------------------------------------------
  1375.  
  1376.     @Override
  1377.     public void onWindowAttributesChanged(LayoutParams params)
  1378.     {
  1379.         if (!QtApplication.invokeDelegate(params).invoked)
  1380.             super.onWindowAttributesChanged(params);
  1381.     }
  1382.     public void super_onWindowAttributesChanged(LayoutParams params)
  1383.     {
  1384.         super.onWindowAttributesChanged(params);
  1385.     }
  1386.     //---------------------------------------------------------------------------
  1387.  
  1388.     @Override
  1389.     public void onWindowFocusChanged(boolean hasFocus)
  1390.     {
  1391.         if (!QtApplication.invokeDelegate(hasFocus).invoked)
  1392.             super.onWindowFocusChanged(hasFocus);
  1393.     }
  1394.     public void super_onWindowFocusChanged(boolean hasFocus)
  1395.     {
  1396.         super.onWindowFocusChanged(hasFocus);
  1397.     }
  1398.     //---------------------------------------------------------------------------
  1399.  
  1400.     //////////////// Activity API 5 /////////////
  1401. //@ANDROID-5
  1402.     @Override
  1403.     public void onAttachedToWindow()
  1404.     {
  1405.         if (!QtApplication.invokeDelegate().invoked)
  1406.             super.onAttachedToWindow();
  1407.     }
  1408.     public void super_onAttachedToWindow()
  1409.     {
  1410.         super.onAttachedToWindow();
  1411.     }
  1412.     //---------------------------------------------------------------------------
  1413.  
  1414.     @Override
  1415.     public void onBackPressed()
  1416.     {
  1417.         if (!QtApplication.invokeDelegate().invoked)
  1418.             super.onBackPressed();
  1419.     }
  1420.     public void super_onBackPressed()
  1421.     {
  1422.         super.onBackPressed();
  1423.     }
  1424.     //---------------------------------------------------------------------------
  1425.  
  1426.     @Override
  1427.     public void onDetachedFromWindow()
  1428.     {
  1429.         if (!QtApplication.invokeDelegate().invoked)
  1430.             super.onDetachedFromWindow();
  1431.     }
  1432.     public void super_onDetachedFromWindow()
  1433.     {
  1434.         super.onDetachedFromWindow();
  1435.     }
  1436.     //---------------------------------------------------------------------------
  1437.  
  1438.     @Override
  1439.     public boolean onKeyLongPress(int keyCode, KeyEvent event)
  1440.     {
  1441.         if (QtApplication.m_delegateObject != null  && QtApplication.onKeyLongPress != null)
  1442.             return (Boolean) QtApplication.invokeDelegateMethod(QtApplication.onKeyLongPress, keyCode, event);
  1443.         else
  1444.             return super.onKeyLongPress(keyCode, event);
  1445.     }
  1446.     public boolean super_onKeyLongPress(int keyCode, KeyEvent event)
  1447.     {
  1448.         return super.onKeyLongPress(keyCode, event);
  1449.     }
  1450.     //---------------------------------------------------------------------------
  1451. //@ANDROID-5
  1452.  
  1453. //////////////// Activity API 8 /////////////
  1454. //@ANDROID-8
  1455. @Override
  1456.     protected Dialog onCreateDialog(int id, Bundle args)
  1457.     {
  1458.         QtApplication.InvokeResult res = QtApplication.invokeDelegate(id, args);
  1459.         if (res.invoked)
  1460.             return (Dialog)res.methodReturns;
  1461.         else
  1462.             return super.onCreateDialog(id, args);
  1463.     }
  1464.     public Dialog super_onCreateDialog(int id, Bundle args)
  1465.     {
  1466.         return super.onCreateDialog(id, args);
  1467.     }
  1468.     //---------------------------------------------------------------------------
  1469.  
  1470.     @Override
  1471.     protected void onPrepareDialog(int id, Dialog dialog, Bundle args)
  1472.     {
  1473.         if (!QtApplication.invokeDelegate(id, dialog, args).invoked)
  1474.             super.onPrepareDialog(id, dialog, args);
  1475.     }
  1476.     public void super_onPrepareDialog(int id, Dialog dialog, Bundle args)
  1477.     {
  1478.         super.onPrepareDialog(id, dialog, args);
  1479.     }
  1480.     //---------------------------------------------------------------------------
  1481. //@ANDROID-8
  1482.     //////////////// Activity API 11 /////////////
  1483.  
  1484.     //////////////// Activity API 12 /////////////
  1485.  
  1486.  
  1487. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement