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.java190
1 files changed, 122 insertions, 68 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 184956d8ef..33f4f77360 100644
--- a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java
+++ b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java
@@ -496,6 +496,17 @@ public class QtActivityDelegate
private static final int CursorHandleShowSelection = 2;
private static final int CursorHandleShowEdit = 0x100;
+ public int getSelectHandleWidth()
+ {
+ int width = 0;
+ if (m_leftSelectionHandle != null && m_rightSelectionHandle != null)
+ width = Math.max(m_leftSelectionHandle.width(), m_rightSelectionHandle.width());
+ else if (m_cursorHandle != null)
+ width = m_cursorHandle.width();
+
+ return width;
+ }
+
/* called from the C++ code when the position of the cursor or selection handles needs to
be adjusted.
mode is one of QAndroidInputContext::CursorHandleShowMode
@@ -568,6 +579,100 @@ public class QtActivityDelegate
}
}
+ private final DisplayManager.DisplayListener displayListener = new DisplayManager.DisplayListener()
+ {
+ @Override
+ public void onDisplayAdded(int displayId) { }
+
+ private boolean isSimilarRotation(int r1, int r2)
+ {
+ return (r1 == r2)
+ || (r1 == Surface.ROTATION_0 && r2 == Surface.ROTATION_180)
+ || (r1 == Surface.ROTATION_180 && r2 == Surface.ROTATION_0)
+ || (r1 == Surface.ROTATION_90 && r2 == Surface.ROTATION_270)
+ || (r1 == Surface.ROTATION_270 && r2 == Surface.ROTATION_90);
+ }
+
+ @Override
+ public void onDisplayChanged(int displayId)
+ {
+ Display display = (Build.VERSION.SDK_INT < Build.VERSION_CODES.R)
+ ? m_activity.getWindowManager().getDefaultDisplay()
+ : m_activity.getDisplay();
+ m_currentRotation = display.getRotation();
+ m_layout.setActivityDisplayRotation(m_currentRotation);
+ // Process orientation change only if it comes after the size
+ // change, or if the screen is rotated by 180 degrees.
+ // Otherwise it will be processed in QtLayout.
+ if (isSimilarRotation(m_currentRotation, m_layout.displayRotation()))
+ QtNative.handleOrientationChanged(m_currentRotation, m_nativeOrientation);
+
+ float refreshRate = display.getRefreshRate();
+ QtNative.handleRefreshRateChanged(refreshRate);
+ }
+
+ @Override
+ public void onDisplayRemoved(int displayId) { }
+ };
+
+ public boolean updateActivity(Activity activity)
+ {
+ try {
+ // set new activity
+ loadActivity(activity);
+
+ // update the new activity content view to old layout
+ ViewGroup layoutParent = (ViewGroup)m_layout.getParent();
+ if (layoutParent != null)
+ layoutParent.removeView(m_layout);
+
+ m_activity.setContentView(m_layout);
+
+ // force c++ native activity object to update
+ return QtNative.updateNativeActivity();
+ } catch (Exception e) {
+ Log.w(QtNative.QtTAG, "Failed to update the activity.");
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ private void loadActivity(Activity activity)
+ throws NoSuchMethodException, PackageManager.NameNotFoundException
+ {
+ m_activity = activity;
+
+ QtNative.setActivity(m_activity, this);
+ setActionBarVisibility(false);
+
+ Class<?> activityClass = m_activity.getClass();
+ m_super_dispatchKeyEvent =
+ activityClass.getMethod("super_dispatchKeyEvent", KeyEvent.class);
+ m_super_onRestoreInstanceState =
+ activityClass.getMethod("super_onRestoreInstanceState", Bundle.class);
+ m_super_onRetainNonConfigurationInstance =
+ activityClass.getMethod("super_onRetainNonConfigurationInstance");
+ m_super_onSaveInstanceState =
+ activityClass.getMethod("super_onSaveInstanceState", Bundle.class);
+ m_super_onKeyDown =
+ activityClass.getMethod("super_onKeyDown", Integer.TYPE, KeyEvent.class);
+ m_super_onKeyUp =
+ activityClass.getMethod("super_onKeyUp", Integer.TYPE, KeyEvent.class);
+ m_super_onConfigurationChanged =
+ activityClass.getMethod("super_onConfigurationChanged", Configuration.class);
+ m_super_onActivityResult =
+ activityClass.getMethod("super_onActivityResult", Integer.TYPE, Integer.TYPE, Intent.class);
+ m_super_onWindowFocusChanged =
+ activityClass.getMethod("super_onWindowFocusChanged", Boolean.TYPE);
+ m_super_dispatchGenericMotionEvent =
+ activityClass.getMethod("super_dispatchGenericMotionEvent", MotionEvent.class);
+
+ m_softInputMode = m_activity.getPackageManager().getActivityInfo(m_activity.getComponentName(), 0).softInputMode;
+
+ DisplayManager displayManager = (DisplayManager)m_activity.getSystemService(Context.DISPLAY_SERVICE);
+ displayManager.registerDisplayListener(displayListener, null);
+ }
+
public boolean loadApplication(Activity activity, ClassLoader classLoader, Bundle loaderParams)
{
/// check parameters integrity
@@ -577,10 +682,14 @@ public class QtActivityDelegate
return false;
}
- m_activity = activity;
- setActionBarVisibility(false);
- QtNative.setActivity(m_activity, this);
- QtNative.setClassLoader(classLoader);
+ try {
+ loadActivity(activity);
+ QtNative.setClassLoader(classLoader);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+
if (loaderParams.containsKey(STATIC_INIT_CLASSES_KEY)) {
for (String className: Objects.requireNonNull(loaderParams.getStringArray(STATIC_INIT_CLASSES_KEY))) {
if (className.length() == 0)
@@ -625,22 +734,6 @@ public class QtActivityDelegate
loaderParams.getBoolean(EXTRACT_STYLE_MINIMAL_KEY));
}
- try {
- m_super_dispatchKeyEvent = m_activity.getClass().getMethod("super_dispatchKeyEvent", KeyEvent.class);
- m_super_onRestoreInstanceState = m_activity.getClass().getMethod("super_onRestoreInstanceState", Bundle.class);
- m_super_onRetainNonConfigurationInstance = m_activity.getClass().getMethod("super_onRetainNonConfigurationInstance");
- m_super_onSaveInstanceState = m_activity.getClass().getMethod("super_onSaveInstanceState", Bundle.class);
- 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);
- m_super_onWindowFocusChanged = m_activity.getClass().getMethod("super_onWindowFocusChanged", Boolean.TYPE);
- m_super_dispatchGenericMotionEvent = m_activity.getClass().getMethod("super_dispatchGenericMotionEvent", MotionEvent.class);
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
-
int necessitasApiLevel = 1;
if (loaderParams.containsKey(NECESSITAS_API_LEVEL_KEY))
necessitasApiLevel = loaderParams.getInt(NECESSITAS_API_LEVEL_KEY);
@@ -666,52 +759,6 @@ public class QtActivityDelegate
else
m_applicationParameters = "";
- try {
- m_softInputMode = m_activity.getPackageManager().getActivityInfo(m_activity.getComponentName(), 0).softInputMode;
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- DisplayManager.DisplayListener displayListener = new DisplayManager.DisplayListener() {
- @Override
- public void onDisplayAdded(int displayId) { }
-
- private boolean isSimilarRotation(int r1, int r2)
- {
- return (r1 == r2)
- || (r1 == Surface.ROTATION_0 && r2 == Surface.ROTATION_180)
- || (r1 == Surface.ROTATION_180 && r2 == Surface.ROTATION_0)
- || (r1 == Surface.ROTATION_90 && r2 == Surface.ROTATION_270)
- || (r1 == Surface.ROTATION_270 && r2 == Surface.ROTATION_90);
- }
-
- @Override
- public void onDisplayChanged(int displayId) {
- Display display = (Build.VERSION.SDK_INT < Build.VERSION_CODES.R)
- ? m_activity.getWindowManager().getDefaultDisplay()
- : m_activity.getDisplay();
- m_currentRotation = display.getRotation();
- m_layout.setActivityDisplayRotation(m_currentRotation);
- // Process orientation change only if it comes after the size
- // change, or if the screen is rotated by 180 degrees.
- // Otherwise it will be processed in QtLayout.
- if (isSimilarRotation(m_currentRotation, m_layout.displayRotation()))
- QtNative.handleOrientationChanged(m_currentRotation, m_nativeOrientation);
- float refreshRate = display.getRefreshRate();
- QtNative.handleRefreshRateChanged(refreshRate);
- }
-
- @Override
- public void onDisplayRemoved(int displayId) { }
- };
-
- try {
- DisplayManager displayManager = (DisplayManager) m_activity.getSystemService(Context.DISPLAY_SERVICE);
- displayManager.registerDisplayListener(displayListener, null);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
m_mainLib = QtNative.loadMainLibrary(m_mainLib, nativeLibsDir);
return m_mainLib != null;
}
@@ -800,7 +847,7 @@ public class QtActivityDelegate
m_splashScreenSticky = info.metaData.containsKey("android.app.splash_screen_sticky") && info.metaData.getBoolean("android.app.splash_screen_sticky");
int id = info.metaData.getInt(splashScreenKey);
m_splashScreen = new ImageView(m_activity);
- m_splashScreen.setImageDrawable(m_activity.getResources().getDrawable(id));
+ m_splashScreen.setImageDrawable(m_activity.getResources().getDrawable(id, m_activity.getTheme()));
m_splashScreen.setScaleType(ImageView.ScaleType.FIT_XY);
m_splashScreen.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
m_layout.addView(m_splashScreen);
@@ -922,6 +969,13 @@ public class QtActivityDelegate
m_accessibilityDelegate.notifyValueChanged(viewId, value);
}
+ public void notifyScrolledEvent(int viewId)
+ {
+ if (m_accessibilityDelegate == null)
+ return;
+ m_accessibilityDelegate.notifyScrolledEvent(viewId);
+ }
+
public void notifyQtAndroidPluginRunning(boolean running)
{
m_isPluginRunning = running;
@@ -1239,7 +1293,7 @@ public class QtActivityDelegate
if (attr.type >= TypedValue.TYPE_FIRST_COLOR_INT && attr.type <= TypedValue.TYPE_LAST_COLOR_INT) {
m_activity.getWindow().setBackgroundDrawable(new ColorDrawable(attr.data));
} else {
- m_activity.getWindow().setBackgroundDrawable(m_activity.getResources().getDrawable(attr.resourceId));
+ m_activity.getWindow().setBackgroundDrawable(m_activity.getResources().getDrawable(attr.resourceId, m_activity.getTheme()));
}
if (m_dummyView != null) {
m_layout.removeView(m_dummyView);