Revision: 2932
http://sourceforge.net/p/swingme/code/2932
Author: yuranet
Date: 2025-11-22 18:53:02 +0000 (Sat, 22 Nov 2025)
Log Message:
-----------
support edge-to-edge
Modified Paths:
--------------
AndroidME/src_MIDP/javax/microedition/lcdui/Canvas.java
Modified: AndroidME/src_MIDP/javax/microedition/lcdui/Canvas.java
===================================================================
--- AndroidME/src_MIDP/javax/microedition/lcdui/Canvas.java 2025-10-24 17:43:19 UTC (rev 2931)
+++ AndroidME/src_MIDP/javax/microedition/lcdui/Canvas.java 2025-11-22 18:53:02 UTC (rev 2932)
@@ -3,7 +3,6 @@
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Vector;
-import javax.microedition.midlet.MIDlet;
import net.yura.android.AndroidMeActivity;
import net.yura.android.AndroidMeApp;
import net.yura.android.MenuSystem;
@@ -11,6 +10,7 @@
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
+import android.graphics.Insets;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Build;
@@ -24,6 +24,7 @@
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
+import android.view.WindowInsets;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
@@ -162,7 +163,10 @@
int graphicsY = canvasView.getHeight() - getHeight();
y = y+graphicsY;
- this.canvasView.postInvalidate(x, y, x+w, y+h);
+ // TODO do we want to extend what we repaint to the view edge?
+ int left = getView().getPaddingLeft();
+ int top = getView().getPaddingTop();
+ this.canvasView.postInvalidate(left + x, top + y, left + x+w, top + y+h);
//#mdebug debug
if (net.yura.mobile.BuildConfig.DEBUG) {
@@ -431,9 +435,14 @@
}
@Override
+ public int getWidth() {
+ return super.getWidth() - canvasView.getPaddingLeft() - canvasView.getPaddingRight();
+ }
+
+ @Override
public int getHeight() {
- int h = canvasView.canvasH;
- return (h > 0) ? h : super.getHeight();
+ int h = canvasView.viewHeight;
+ return ((h > 0) ? h : super.getHeight()) - canvasView.getPaddingTop() - canvasView.getPaddingBottom();
}
public void hideSoftKeyboard() {
@@ -632,8 +641,8 @@
private static final int KEYBOARD_HIDE = -1;
javax.microedition.lcdui.Graphics graphics = new Graphics(new android.graphics.Canvas());
- private int canvasY;
- private int canvasH;
+ private int viewY;
+ private int viewHeight;
private int keyMenuCount = -1;
private int keyBackCount = -1;
private InputHelper inputConnectionView;
@@ -662,6 +671,23 @@
catch (Throwable ex) {
// Nothing. Methods not available.
}
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+ setOnApplyWindowInsetsListener(new OnApplyWindowInsetsListener() {
+ @Override
+ public WindowInsets onApplyWindowInsets(View v, WindowInsets windowInsets) {
+
+ // Get the system bar insets (top, bottom, left, right padding needed)
+ Insets insets = windowInsets.getInsets(WindowInsets.Type.systemBars() | WindowInsets.Type.displayCutout());
+
+ // Apply the insets as padding to this view
+ v.setPadding(insets.left, insets.top, insets.right, insets.bottom);
+
+ // Return CONSUMED to indicate that we have handled these insets
+ return WindowInsets.CONSUMED;
+ }
+ });
+ }
}
// Override > 2.1 only
@@ -689,7 +715,7 @@
return;
}
- if (usedWidth==0&&usedHeight==0) { // this is the first time paint is called
+ if (usedWidth == 0 && usedHeight == 0) { // this is the first time paint is called
try {
// sometimes even though the app starts in HW mode, it can suddenly switch back to SW
// "Mountain View, we've had a problem here. Switching back to software rendering."
@@ -718,33 +744,33 @@
if (location[1] >= 0) {
- canvasY = location[1];
+ viewY = location[1];
//canvasY = Math.max(canvasY, location[1]); // this avoid the wobble when the keyboard is closing,
// but also means it does not work with the clipboard bar on honeycomb tablets
- canvasH = getHeight();
+ viewHeight = getHeight();
}
else {
// 2 - Visible height if displaying the virtual keyboard
- canvasH = getHeight() + location[1] - canvasY; // needed for SE Xperia mini pro (when using old style text entry, none native)
+ viewHeight = getHeight() + location[1] - viewY; // needed for SE Xperia mini pro (when using old style text entry, none native)
}
+ int viewWidth = getWidth();
- int canvasW = this.getWidth();
-
+ int canvasWidth = Canvas.this.getWidth();
+ int canvasHeight = Canvas.this.getHeight();
// Check for size changes...
- if (usedWidth != canvasW || usedHeight != canvasH) {
+ if (usedWidth != canvasWidth || usedHeight != canvasHeight) {
// Notify Canvas clients
try {
- sizeChanged(Canvas.this.getWidth(), Canvas.this.getHeight());
+ sizeChanged(canvasWidth, canvasHeight);
}
catch (Throwable e) {
- Logger.warn(null, e);
+ Logger.warn("error in sizeChanged", e);
}
- usedWidth = canvasW;
- usedHeight = canvasH;
-
+ usedWidth = canvasWidth;
+ usedHeight = canvasHeight;
}
// if we are not in hardwareAccelerated mode we need to use a buffer bitmap or we will get black flicker
@@ -751,7 +777,7 @@
if (!hardwareAccelerated) {
if (graphicsBitmap != null) {
// only get rid of bitmap if the new screen size is bigger in either dimension
- if (graphicsBitmap.getWidth() < canvasW || graphicsBitmap.getHeight() < canvasH) {
+ if (graphicsBitmap.getWidth() < viewWidth || graphicsBitmap.getHeight() < viewHeight) {
graphicsBitmap.recycle();
graphicsBitmap = null;
@@ -765,16 +791,15 @@
// Help the GC to collect any previous graphicsBitmap
graphics.setCanvas(null);
try {
- graphicsBitmap = Bitmap.createBitmap(canvasW, canvasH, Bitmap.Config.ARGB_8888);
+ graphicsBitmap = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888);
}
catch (OutOfMemoryError e) {
System.gc();
Thread.sleep(200);
- graphicsBitmap = Bitmap.createBitmap(canvasW, canvasH, Bitmap.Config.ARGB_8888);
+ graphicsBitmap = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888);
}
graphics.setCanvas( new android.graphics.Canvas(graphicsBitmap) );
}
-
}
if (graphicsBitmap==null) {
@@ -784,7 +809,7 @@
// in case there was a error in the last paint, we HAVE to call reset here to reset the tx and ty
graphics.reset(); // reset to the last save, i.e. when the setCanvas was called
- int graphicsY = getHeight() - canvasH;
+ int graphicsY = getHeight() - viewHeight;
Rect dist = androidCanvas.getClipBounds();
graphics.clipRect(dist.left, dist.top -graphicsY, dist.right-dist.left, dist.bottom-dist.top);
@@ -799,6 +824,7 @@
dist.right = src.right;
// but just to be sure we do it anyway, as we ALWAYS want them to be the same size, or the image is stretched
+ graphics.translate(getPaddingLeft(), getPaddingTop());
paint(graphics);
if (graphicsBitmap!=null) {
@@ -952,9 +978,9 @@
int actionCode = event.getAction() & 0xFF; // 0xFF == MotionEvent.ACTION_MASK
int pointerCount = getPointerCount(event);
- int ySlide = getHeight() - canvasH;
- int x = Math.round(event.getX());
- int y = Math.round(event.getY() - ySlide);
+ int ySlide = getHeight() - viewHeight;
+ int x = Math.round(event.getX()) - getPaddingLeft();
+ int y = Math.round(event.getY() - ySlide) - getPaddingTop();
int action;
switch (actionCode) {
@@ -1030,11 +1056,11 @@
Arrays.fill(touchType, POINTER_RELEASED);
}
- int pX0 = Math.round(getX(event, 0));
- int pY0 = Math.round(getY(event, 0) - ySlide);
+ int pX0 = Math.round(getX(event, 0)) - getPaddingLeft();
+ int pY0 = Math.round(getY(event, 0) - ySlide) - getPaddingTop();
- int pX1 = Math.round(getX(event, 1));
- int pY1 = Math.round(getY(event, 1) - ySlide);
+ int pX1 = Math.round(getX(event, 1)) - getPaddingLeft();
+ int pY1 = Math.round(getY(event, 1) - ySlide) - getPaddingTop();
// touchDebug = new int[] {pX0, pY0, pX1, pY1};
// invalidate();
@@ -1292,10 +1318,12 @@
fontH = debugPaint.getFontMetricsInt(debugPaint.getFontMetricsInt()) + 2;
}
+ int left = getPaddingLeft();
+ int top = getPaddingTop();
debugPaint.setColor(0xFF000000);
- androidCanvas.drawRect(2, 5, 2 + w, 5 + fontH, debugPaint);
+ androidCanvas.drawRect(left + 2, top + 5, left + 2 + w, top + 5 + fontH, debugPaint);
debugPaint.setColor(0xFFFFFFFF);
- androidCanvas.drawText(fpsStr, 3, 1 + fontH, debugPaint);
+ androidCanvas.drawText(fpsStr, left + 3, top + 1 + fontH, debugPaint);
}
//#mdebug debug
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|