summaryrefslogtreecommitdiffstats
path: root/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java')
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java148
1 files changed, 106 insertions, 42 deletions
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java
index d8c560933f..4b80d68761 100644
--- a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java
+++ b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java
@@ -1,7 +1,7 @@
/****************************************************************************
**
+** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org>
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Copyright (C) 2012 BogDan Vatra <bogdan@kde.org>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Android port of the Qt Toolkit.
@@ -44,6 +44,7 @@ package org.qtproject.qt5.android;
import android.app.Activity;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
@@ -73,6 +74,7 @@ import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
public class QtActivityDelegate
@@ -85,6 +87,7 @@ public class QtActivityDelegate
private Method m_super_onKeyDown = null;
private Method m_super_onKeyUp = null;
private Method m_super_onConfigurationChanged = null;
+ private Method m_super_onActivityResult = null;
private static final String NATIVE_LIBRARIES_KEY = "native.libraries";
private static final String BUNDLED_LIBRARIES_KEY = "bundled.libraries";
@@ -105,7 +108,8 @@ public class QtActivityDelegate
private int m_lastChar = 0;
private boolean m_fullScreen = false;
private boolean m_started = false;
- private QtSurface m_surface = null;
+ private HashMap<Integer, QtSurface> m_surfaces = null;
+ private HashMap<Integer, View> m_nativeViews = null;
private QtLayout m_layout = null;
private QtEditText m_editText = null;
private InputMethodManager m_imm = null;
@@ -116,21 +120,6 @@ public class QtActivityDelegate
public boolean m_backKeyPressedSent = false;
- public QtLayout getQtLayout()
- {
- return m_layout;
- }
-
- public QtSurface getQtSurface()
- {
- return m_surface;
- }
-
- public void redrawWindow(int left, int top, int right, int bottom)
- {
- m_surface.drawBitmap(new Rect(left, top, right, bottom));
- }
-
public void setFullScreen(boolean enterFullScreen)
{
if (m_fullScreen == enterFullScreen)
@@ -175,6 +164,7 @@ public class QtActivityDelegate
}
}
}
+ m_layout.requestLayout();
}
@@ -233,7 +223,8 @@ public class QtActivityDelegate
{
if (m_imm == null)
return;
- if (height > m_surface.getHeight()*2/3)
+
+ if (height > m_layout.getHeight() * 2 / 3)
m_activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
else
m_activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
@@ -330,7 +321,7 @@ public class QtActivityDelegate
{
if (m_imm == null)
return;
- m_imm.hideSoftInputFromWindow(m_editText.getWindowToken(), 0, new ResultReceiver( new Handler()){
+ m_imm.hideSoftInputFromWindow(m_editText.getWindowToken(), 0, new ResultReceiver(new Handler()) {
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
switch (resultCode) {
@@ -358,7 +349,7 @@ public class QtActivityDelegate
if (size < 36 || size > 512) { // check size sanity
DisplayMetrics metrics = new DisplayMetrics();
a.getWindowManager().getDefaultDisplay().getMetrics(metrics);
- size = metrics.densityDpi/10*3;
+ size = metrics.densityDpi / 10 * 3;
if (size < 36)
size = 36;
@@ -421,6 +412,7 @@ public class QtActivityDelegate
m_super_onKeyDown = m_activity.getClass().getMethod("super_onKeyDown", Integer.TYPE, KeyEvent.class);
m_super_onKeyUp = m_activity.getClass().getMethod("super_onKeyUp", Integer.TYPE, KeyEvent.class);
m_super_onConfigurationChanged = m_activity.getClass().getMethod("super_onConfigurationChanged", Configuration.class);
+ m_super_onActivityResult = m_activity.getClass().getMethod("super_onActivityResult", Integer.TYPE, Integer.TYPE, Intent.class);
} catch (Exception e) {
e.printStackTrace();
return false;
@@ -626,13 +618,13 @@ public class QtActivityDelegate
m_applicationParameters += "\t-qmljsdebugger=" + qmljsdebugger;
}
- if (null == m_surface)
+ if (null == m_surfaces)
onCreate(null);
String nativeLibraryDir = QtNativeLibrariesDir.nativeLibrariesDir(m_activity);
- m_surface.applicationStarted( QtNative.startApplication(m_applicationParameters,
- m_environmentVariables,
- m_mainLib,
- nativeLibraryDir));
+ QtNative.startApplication(m_applicationParameters,
+ m_environmentVariables,
+ m_mainLib,
+ nativeLibraryDir);
m_started = true;
return true;
} catch (Exception e) {
@@ -657,14 +649,13 @@ public class QtActivityDelegate
metrics.xdpi, metrics.ydpi, metrics.scaledDensity);
}
m_layout = new QtLayout(m_activity);
- m_surface = new QtSurface(m_activity, 0);
m_editText = new QtEditText(m_activity, this);
m_imm = (InputMethodManager)m_activity.getSystemService(Context.INPUT_METHOD_SERVICE);
- m_layout.addView(m_surface, 0);
+ m_surfaces = new HashMap<Integer, QtSurface>();
+ m_nativeViews = new HashMap<Integer, View>();
m_activity.setContentView(m_layout,
- new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
- ViewGroup.LayoutParams.FILL_PARENT));
- m_layout.bringChildToFront(m_surface);
+ new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT));
m_activity.registerForContextMenu(m_layout);
int orientation = m_activity.getResources().getConfiguration().orientation;
@@ -704,18 +695,6 @@ public class QtActivityDelegate
}
}
- public void onRestoreInstanceState(Bundle savedInstanceState)
- {
- try {
- m_super_onRestoreInstanceState.invoke(m_activity, savedInstanceState);
- } catch (Exception e) {
- e.printStackTrace();
- }
- m_started = savedInstanceState.getBoolean("Started");
- if (m_started)
- m_surface.applicationStarted(true);
- }
-
public void onPause()
{
QtNative.updateApplicationState(ApplicationInactive);
@@ -744,6 +723,18 @@ public class QtActivityDelegate
}
}
+ public void onActivityResult(int requestCode, int resultCode, Intent data)
+ {
+ try {
+ m_super_onActivityResult.invoke(m_activity, requestCode, resultCode, data);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ QtNative.onActivityResult(requestCode, resultCode, data);
+ }
+
+
public void onStop()
{
QtNative.updateApplicationState(ApplicationSuspended);
@@ -768,6 +759,19 @@ public class QtActivityDelegate
}
outState.putBoolean("FullScreen", m_fullScreen);
outState.putBoolean("Started", m_started);
+ // It should never
+ }
+
+ public void onRestoreInstanceState(Bundle savedInstanceState)
+ {
+ try {
+ m_super_onRestoreInstanceState.invoke(m_activity, savedInstanceState);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ m_started = savedInstanceState.getBoolean("Started");
+ // FIXME restore all surfaces
+
}
public boolean onKeyDown(int keyCode, KeyEvent event)
@@ -967,4 +971,64 @@ public class QtActivityDelegate
}
}
}
+
+ public void insertNativeView(int id, View view, int x, int y, int w, int h) {
+ if (m_nativeViews.containsKey(id))
+ m_layout.removeView(m_nativeViews.remove(id));
+
+ if (w < 0 || h < 0) {
+ view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT));
+ } else {
+ view.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
+ }
+
+ m_layout.addView(view);
+ m_layout.bringChildToFront(view);
+ m_nativeViews.put(id, view);
+ }
+
+ public void createSurface(int id, boolean onTop, int x, int y, int w, int h) {
+ if (m_surfaces.containsKey(id))
+ m_layout.removeView(m_surfaces.remove(id));
+
+ QtSurface surface = new QtSurface(m_activity, id, onTop);
+ if (w < 0 || h < 0) {
+ surface.setLayoutParams( new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT));
+ } else {
+ surface.setLayoutParams( new QtLayout.LayoutParams(w, h, x, y));
+ }
+
+ m_layout.addView(surface);
+ if (onTop)
+ m_layout.bringChildToFront(surface);
+ m_surfaces.put(id, surface);
+ }
+
+ public void setSurfaceGeometry(int id, int x, int y, int w, int h) {
+ if (m_surfaces.containsKey(id)) {
+ QtSurface surface = m_surfaces.get(id);
+ surface.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
+ } else if (m_nativeViews.containsKey(id)) {
+ View view = m_nativeViews.get(id);
+ view.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
+ m_layout.bringChildToFront(view);
+ } else {
+ Log.e(QtNative.QtTAG, "Surface " + id +" not found!");
+ return;
+ }
+
+ m_layout.requestLayout();
+ }
+
+ public void destroySurface(int id) {
+ if (m_surfaces.containsKey(id)) {
+ m_layout.removeView(m_surfaces.remove(id));
+ } else if (m_nativeViews.containsKey(id)) {
+ m_layout.removeView(m_nativeViews.remove(id));
+ } else {
+ Log.e(QtNative.QtTAG, "Surface " + id +" not found!");
+ }
+ }
}