Android: guard against null objects
And minor warning fixes for unused imports. Task-number: QTBUG-118077 Change-Id: I8296ae019da9d40692687e49ac926f96af901870 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>bb10
parent
5c15990534
commit
3e35db6997
|
|
@ -9,6 +9,7 @@ import android.content.Context;
|
|||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
|
@ -42,7 +43,7 @@ class CursorView extends ImageView
|
|||
switch (ev.getActionMasked()) {
|
||||
case MotionEvent.ACTION_DOWN: {
|
||||
m_offsetX = ev.getRawX();
|
||||
m_offsetY = ev.getRawY() + getHeight() / 2;
|
||||
m_offsetY = ev.getRawY() + (float) getHeight() / 2;
|
||||
m_pressed = true;
|
||||
break;
|
||||
}
|
||||
|
|
@ -67,6 +68,7 @@ class CursorView extends ImageView
|
|||
// Helper class that manages a cursor or selection handle
|
||||
class CursorHandle implements ViewTreeObserver.OnPreDrawListener
|
||||
{
|
||||
private static final String QtTag = "QtCursorHandle";
|
||||
private final View m_layout;
|
||||
private CursorView m_cursorView = null;
|
||||
private PopupWindow m_popup = null;
|
||||
|
|
@ -109,8 +111,13 @@ class CursorHandle implements ViewTreeObserver.OnPreDrawListener
|
|||
m_popup.setSplitTouchEnabled(true);
|
||||
m_popup.setClippingEnabled(false);
|
||||
m_popup.setContentView(m_cursorView);
|
||||
m_popup.setWidth(drawable.getIntrinsicWidth());
|
||||
m_popup.setHeight(drawable.getIntrinsicHeight());
|
||||
if (drawable != null) {
|
||||
m_popup.setWidth(drawable.getIntrinsicWidth());
|
||||
m_popup.setHeight(drawable.getIntrinsicHeight());
|
||||
} else {
|
||||
Log.w(QtTag, "initOverlay(): cannot get width/height for popup " +
|
||||
"from null drawable for attribute " + m_attr);
|
||||
}
|
||||
|
||||
m_layout.getViewTreeObserver().addOnPreDrawListener(this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
package org.qtproject.qt.android;
|
||||
|
||||
import android.R;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Point;
|
||||
|
|
@ -136,16 +135,16 @@ class EditPopupMenu implements ViewTreeObserver.OnPreDrawListener, View.OnLayout
|
|||
@Override
|
||||
public void contextButtonClicked(int buttonId) {
|
||||
switch (buttonId) {
|
||||
case R.string.cut:
|
||||
case android.R.string.cut:
|
||||
QtNativeInputConnection.cut();
|
||||
break;
|
||||
case R.string.copy:
|
||||
case android.R.string.copy:
|
||||
QtNativeInputConnection.copy();
|
||||
break;
|
||||
case R.string.paste:
|
||||
case android.R.string.paste:
|
||||
QtNativeInputConnection.paste();
|
||||
break;
|
||||
case R.string.selectAll:
|
||||
case android.R.string.selectAll:
|
||||
QtNativeInputConnection.selectAll();
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import android.os.Build;
|
|||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Display;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.animation.AccelerateInterpolator;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
|
|
@ -29,7 +30,6 @@ import android.view.WindowInsetsController;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.PopupMenu;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
class QtActivityDelegate
|
||||
|
|
@ -187,10 +187,10 @@ class QtActivityDelegate
|
|||
|
||||
handleUiModeChange(m_activity.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK);
|
||||
|
||||
float refreshRate = (Build.VERSION.SDK_INT < Build.VERSION_CODES.R)
|
||||
? m_activity.getWindowManager().getDefaultDisplay().getRefreshRate()
|
||||
: m_activity.getDisplay().getRefreshRate();
|
||||
QtDisplayManager.handleRefreshRateChanged(refreshRate);
|
||||
Display display = (Build.VERSION.SDK_INT < Build.VERSION_CODES.R)
|
||||
? m_activity.getWindowManager().getDefaultDisplay()
|
||||
: m_activity.getDisplay();
|
||||
QtDisplayManager.handleRefreshRateChanged(QtDisplayManager.getRefreshRate(display));
|
||||
|
||||
m_layout.getViewTreeObserver().addOnPreDrawListener(() -> {
|
||||
if (!m_inputDelegate.isKeyboardVisible())
|
||||
|
|
@ -448,10 +448,16 @@ class QtActivityDelegate
|
|||
QtNative.runAction(() -> {
|
||||
if (m_surfaces.containsKey(id)) {
|
||||
QtSurface surface = m_surfaces.get(id);
|
||||
surface.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
|
||||
if (surface != null)
|
||||
surface.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
|
||||
else
|
||||
Log.e(QtNative.QtTAG, "setSurfaceGeometry(): surface is null!");
|
||||
} else if (m_nativeViews.containsKey(id)) {
|
||||
View view = m_nativeViews.get(id);
|
||||
view.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
|
||||
if (view != null)
|
||||
view.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
|
||||
else
|
||||
Log.e(QtNative.QtTAG, "setSurfaceGeometry(): view is null!");
|
||||
} else {
|
||||
Log.e(QtNative.QtTAG, "Surface " + id + " not found!");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ class QtDisplayManager {
|
|||
Display display = (Build.VERSION.SDK_INT < Build.VERSION_CODES.R)
|
||||
? m_activity.getWindowManager().getDefaultDisplay()
|
||||
: m_activity.getDisplay();
|
||||
int rotation = display.getRotation();
|
||||
int rotation = display != null ? display.getRotation() : Surface.ROTATION_0;
|
||||
layout.setActivityDisplayRotation(rotation);
|
||||
// Process orientation change only if it comes after the size
|
||||
// change, or if the screen is rotated by 180 degrees.
|
||||
|
|
@ -83,7 +83,7 @@ class QtDisplayManager {
|
|||
getNativeOrientation(m_activity, rotation));
|
||||
}
|
||||
|
||||
float refreshRate = display.getRefreshRate();
|
||||
float refreshRate = getRefreshRate(display);
|
||||
QtDisplayManager.handleRefreshRateChanged(refreshRate);
|
||||
QtDisplayManager.handleScreenChanged(displayId);
|
||||
}
|
||||
|
|
@ -95,6 +95,11 @@ class QtDisplayManager {
|
|||
};
|
||||
}
|
||||
|
||||
static float getRefreshRate(Display display)
|
||||
{
|
||||
return display != null ? display.getRefreshRate() : 60.0f;
|
||||
}
|
||||
|
||||
public void registerDisplayListener()
|
||||
{
|
||||
DisplayManager displayManager =
|
||||
|
|
@ -274,14 +279,9 @@ class QtDisplayManager {
|
|||
double density = displayMetrics.density;
|
||||
double scaledDensity = displayMetrics.scaledDensity;
|
||||
|
||||
float refreshRate = 60.0f;
|
||||
if (display != null) {
|
||||
refreshRate = display.getRefreshRate();
|
||||
}
|
||||
|
||||
setDisplayMetrics(maxWidth, maxHeight, insetLeft, insetTop,
|
||||
width, height, xdpi, ydpi,
|
||||
scaledDensity, density, refreshRate);
|
||||
scaledDensity, density, getRefreshRate(display));
|
||||
}
|
||||
|
||||
public static int getDisplayRotation(Activity activity) {
|
||||
|
|
|
|||
|
|
@ -13,8 +13,10 @@ import android.graphics.drawable.Drawable;
|
|||
import android.text.ClipboardManager;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
|
|
@ -145,7 +147,11 @@ class QtMessageDialogHelper
|
|||
m_dialog.dismiss();
|
||||
|
||||
m_dialog = new AlertDialog.Builder(m_activity).create();
|
||||
m_theme = m_dialog.getWindow().getContext().getTheme();
|
||||
Window window = m_dialog.getWindow();
|
||||
if (window != null)
|
||||
m_theme = window.getContext().getTheme();
|
||||
else
|
||||
Log.w(QtTAG, "show(): cannot set theme from null window!");
|
||||
|
||||
if (m_title != null)
|
||||
m_dialog.setTitle(m_title);
|
||||
|
|
@ -327,6 +333,7 @@ class QtMessageDialogHelper
|
|||
m_handler = 0;
|
||||
}
|
||||
|
||||
private static final String QtTAG = "QtMessageDialogHelper";
|
||||
private final Activity m_activity;
|
||||
private int m_standardIcon = 0;
|
||||
private Spanned m_title, m_text, m_informativeText, m_detailedText;
|
||||
|
|
|
|||
Loading…
Reference in New Issue