- Cleanup code.

- Auto-scroll down the textual printer.
- Fix the printer icon in the Eric's script "real49gp-lc.kml" and "real50g-lc.kml".
- Improve the swipe gesture.
This commit is contained in:
dgis 2019-07-07 17:15:14 +02:00
parent 90d2cb40b9
commit 26425625dd
17 changed files with 923 additions and 942 deletions

View file

@ -66,6 +66,8 @@ Version 1.5 (2019-06-xx)
- Prevent the ESC key from leaving the application (Github Fix: #6). - Prevent the ESC key from leaving the application (Github Fix: #6).
- Map the keyboard DELETE key like it should (Github Fix: #6). - Map the keyboard DELETE key like it should (Github Fix: #6).
- Map the +, -, * and / keys catching the typed character instead of the virtual key (Github Fix: #6). - Map the +, -, * and / keys catching the typed character instead of the virtual key (Github Fix: #6).
- Fix the printer icon in the Eric's script "real49gp-lc.kml" and "real50g-lc.kml".
- Improve the swipe gesture.
Version 1.4 (2019-06-08) Version 1.4 (2019-06-08)
@ -146,12 +148,20 @@ Note: some included files are not covered by the GPL; these include ROM image fi
The Eric's Real scripts ("real*.kml" and "real*.bmp/png") are embedded in this application with the kind permission of Eric Rechlin. The Eric's Real scripts ("real*.kml" and "real*.bmp/png") are embedded in this application with the kind permission of Eric Rechlin.
DONE
- Cleanup code.
- Auto-scroll down the textual printer.
- Fix the printer icon in the Eric's script "real49gp-lc.kml" and "real50g-lc.kml".
- Improve the swipe gesture.
TODO TODO
- With HP49, On+D does not work even with version 2.10 (2.15 should not work)!
- In Chrome OS: - In Chrome OS:
- The timezone seems to be GMT (localtime_r not right?)! - The timezone seems to be GMT (localtime_r not right?)!
- sometimes there is no OK button in the KML Script Compilation Result. - sometimes there is no OK button in the KML Script Compilation Result.
- Improve the swipe gesture.
- The clock seems unsynchronized sometimes. - The clock seems unsynchronized sometimes.
- Add KML script loading dependencies fallback to the inner ROM (and may be KML include?). - Add KML script loading dependencies fallback to the inner ROM (and may be KML include?).
- Add a separation between the pixels (Suggestion from Jaime Meza). - Add a separation between the pixels (Suggestion from Jaime Meza).

View file

@ -1 +0,0 @@
This folder contains several files usefull for emu48 mor the mac. It contains kml, kmi, bitmaps, rom files for 48SX, 48GX, 49G, 38G, 39G, 40G The roms are copyrighted Hewlett-Packard Other files are property of their respective authors.

View file

@ -83,37 +83,37 @@ End
Annunciator 1 Annunciator 1
Size 24 18 Size 24 18
Offset 84 2 Offset 40 2
Down 443 927 Down 443 927
End End
Annunciator 2 Annunciator 2
Size 24 18 Size 24 18
Offset 147 2 Offset 103 2
Down 467 927 Down 467 927
End End
Annunciator 3 Annunciator 3
Size 24 18 Size 24 18
Offset 220 2 Offset 176 2
Down 491 927 Down 491 927
End End
Annunciator 4 Annunciator 4
Size 24 18 Size 24 18
Offset 290 2 Offset 246 2
Down 515 927 Down 515 927
End End
Annunciator 5 Annunciator 5
Size 24 18 Size 24 18
Offset 355 2 Offset 311 2
Down 539 927 Down 539 927
End End
Annunciator 6 Annunciator 6
Size 24 18 Size 24 18
Offset 424 2 Offset 380 2
Down 564 927 Down 564 927
End End

View file

@ -115,7 +115,7 @@ End
Annunciator 6 Annunciator 6
Size 24 17 Size 24 17
Offset 377 3 Offset 377 3
Down 457 923 Down 557 923
End End
Button 11 Button 11

View file

@ -932,8 +932,6 @@ JNIEXPORT jint JNICALL Java_org_emulator_calculator_NativeLib_onViewScript(JNIEn
ResetDocument(); // close document ResetDocument(); // close document
SetWindowTitle(NULL); SetWindowTitle(NULL);
} }
// mainViewResizeCallback(nBackgroundW, nBackgroundH);
//draw(); //TODO CRASH
return result; return result;
} }

View file

@ -575,24 +575,11 @@ typedef struct _HANDLE * HANDLE;
typedef HANDLE HMENU; typedef HANDLE HMENU;
typedef HANDLE HINSTANCE; typedef HANDLE HINSTANCE;
//typedef HANDLE HWND;
typedef HANDLE HCURSOR; typedef HANDLE HCURSOR;
typedef HANDLE HLOCAL; //TODO typedef HANDLE HLOCAL; //TODO
typedef struct _OVERLAPPED { typedef struct _OVERLAPPED {
/*
ULONG_PTR Internal;
ULONG_PTR InternalHigh;
union {
struct {
DWORD Offset;
DWORD OffsetHigh;
} DUMMYSTRUCTNAME;
PVOID Pointer;
} DUMMYUNIONNAME;
*/
HANDLE hEvent; HANDLE hEvent;
} OVERLAPPED, *LPOVERLAPPED; } OVERLAPPED, *LPOVERLAPPED;

View file

@ -14,6 +14,7 @@
package org.emulator.calculator; package org.emulator.calculator;
import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
@ -23,6 +24,7 @@ import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.util.SparseIntArray;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.MotionEvent; import android.view.MotionEvent;
@ -37,7 +39,7 @@ public class MainScreenView extends PanAndScaleView {
private Paint paint = new Paint(); private Paint paint = new Paint();
private Bitmap bitmapMainScreen; private Bitmap bitmapMainScreen;
private HashMap<Integer, Integer> vkmap; private SparseIntArray vkmap;
private HashMap<Character, Integer> charmap; private HashMap<Character, Integer> charmap;
private int kmlBackgroundColor = Color.BLACK; private int kmlBackgroundColor = Color.BLACK;
private boolean useKmlBackgroundColor = false; private boolean useKmlBackgroundColor = false;
@ -69,7 +71,7 @@ public class MainScreenView extends PanAndScaleView {
charmap.put('*', 0x6A); // VK_MULTIPLY charmap.put('*', 0x6A); // VK_MULTIPLY
charmap.put('/', 0x6F); // VK_DIVIDE charmap.put('/', 0x6F); // VK_DIVIDE
vkmap = new HashMap<>(); vkmap = new SparseIntArray();
//vkmap.put(KeyEvent.KEYCODE_BACK, 0x08); // VK_BACK //vkmap.put(KeyEvent.KEYCODE_BACK, 0x08); // VK_BACK
vkmap.put(KeyEvent.KEYCODE_TAB, 0x09); // VK_TAB vkmap.put(KeyEvent.KEYCODE_TAB, 0x09); // VK_TAB
vkmap.put(KeyEvent.KEYCODE_ENTER, 0x0D); // VK_RETURN vkmap.put(KeyEvent.KEYCODE_ENTER, 0x0D); // VK_RETURN
@ -87,16 +89,6 @@ public class MainScreenView extends PanAndScaleView {
vkmap.put(KeyEvent.KEYCODE_DPAD_UP, 0x26); // VK_UP vkmap.put(KeyEvent.KEYCODE_DPAD_UP, 0x26); // VK_UP
vkmap.put(KeyEvent.KEYCODE_DPAD_RIGHT, 0x27); // VK_RIGHT vkmap.put(KeyEvent.KEYCODE_DPAD_RIGHT, 0x27); // VK_RIGHT
vkmap.put(KeyEvent.KEYCODE_DPAD_DOWN, 0x28); // VK_DOWN vkmap.put(KeyEvent.KEYCODE_DPAD_DOWN, 0x28); // VK_DOWN
// vkmap.put(KeyEvent.KEYCODE_0, 0x30); // 0
// vkmap.put(KeyEvent.KEYCODE_1, 0x31); // 1
// vkmap.put(KeyEvent.KEYCODE_2, 0x32); // 2
// vkmap.put(KeyEvent.KEYCODE_3, 0x33); // 3
// vkmap.put(KeyEvent.KEYCODE_4, 0x34); // 4
// vkmap.put(KeyEvent.KEYCODE_5, 0x35); // 5
// vkmap.put(KeyEvent.KEYCODE_6, 0x36); // 6
// vkmap.put(KeyEvent.KEYCODE_7, 0x37); // 7
// vkmap.put(KeyEvent.KEYCODE_8, 0x38); // 8
// vkmap.put(KeyEvent.KEYCODE_9, 0x39); // 9
vkmap.put(KeyEvent.KEYCODE_A, 0x41); // A vkmap.put(KeyEvent.KEYCODE_A, 0x41); // A
vkmap.put(KeyEvent.KEYCODE_B, 0x42); // B vkmap.put(KeyEvent.KEYCODE_B, 0x42); // B
vkmap.put(KeyEvent.KEYCODE_C, 0x43); // C vkmap.put(KeyEvent.KEYCODE_C, 0x43); // C
@ -165,39 +157,17 @@ public class MainScreenView extends PanAndScaleView {
// This call is necessary, or else the // This call is necessary, or else the
// draw method will not be called. // draw method will not be called.
setWillNotDraw(false); setWillNotDraw(false);
// scroller.setFriction(0.00001f); // ViewConfiguration.getScrollFriction(); // ViewConfiguration.SCROLL_FRICTION = 0.015f;
// setOnTapDownListener(new OnTapListener() {
// @Override
// public boolean onTap(View v, float x, float y) {
// if(NativeLib.buttonDown((int)x, (int)y)) {
// if(debug) Log.d(TAG, "onTapDown() true");
// return true;
// }
// if(debug) Log.d(TAG, "onTapDown() false");
// return false;
// }
// });
// setOnTapUpListener(new OnTapListener() {
// @Override
// public boolean onTap(View v, float x, float y) {
// if(debug) Log.d(TAG, "onTapUp()");
// NativeLib.buttonUp((int)x, (int)y);
// return false;
// }
// });
} }
protected Set<Integer> currentButtonTouched = new HashSet<Integer>(); // Prevent accidental scroll when taping a calc button
protected Set<Integer> currentButtonTouched = new HashSet<>();
@SuppressLint("ClickableViewAccessibility")
public boolean onTouchEvent(MotionEvent event) { public boolean onTouchEvent(MotionEvent event) {
int actionIndex = event.getActionIndex(); int actionIndex = event.getActionIndex();
int action = event.getActionMasked(); int action = event.getActionMasked();
switch (action) { switch (action) {
case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN: case MotionEvent.ACTION_POINTER_DOWN:
//Log.d(TAG, "ACTION_DOWN/ACTION_POINTER_DOWN count: " + touchCount + ", actionIndex: " + actionIndex);
//NativeLib.buttonDown((int)((event.getX(actionIndex) - screenOffsetX) / screenScaleX), (int)((event.getY(actionIndex) - screenOffsetY) / screenScaleY));
currentButtonTouched.remove(actionIndex); currentButtonTouched.remove(actionIndex);
if(actionIndex == 0 && event.getPointerCount() == 1) if(actionIndex == 0 && event.getPointerCount() == 1)
currentButtonTouched.clear(); currentButtonTouched.clear();
@ -205,8 +175,6 @@ public class MainScreenView extends PanAndScaleView {
(int) ((event.getY(actionIndex) - viewPanOffsetY) / viewScaleFactorY))) { (int) ((event.getY(actionIndex) - viewPanOffsetY) / viewScaleFactorY))) {
currentButtonTouched.add(actionIndex); currentButtonTouched.add(actionIndex);
preventToScroll = true; preventToScroll = true;
// if (debug) Log.d(TAG, "onTouchEvent() ACTION_DOWN true, actionIndex: " + actionIndex + ", currentButtonTouched: " + currentButtonTouched.size());
// return true;
} }
if (debug) Log.d(TAG, "onTouchEvent() ACTION_DOWN false, actionIndex: " + actionIndex if (debug) Log.d(TAG, "onTouchEvent() ACTION_DOWN false, actionIndex: " + actionIndex
+ ", currentButtonTouched: " + currentButtonTouched.size() + ", currentButtonTouched: " + currentButtonTouched.size()
@ -214,8 +182,6 @@ public class MainScreenView extends PanAndScaleView {
break; break;
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_POINTER_UP:
//Log.d(TAG, "ACTION_UP/ACTION_POINTER_UP count: " + touchCount + ", actionIndex: " + actionIndex);
//NativeLib.buttonUp((int)((event.getX(actionIndex) - screenOffsetX) / screenScaleX), (int)((event.getY(actionIndex) - screenOffsetY) / screenScaleY));
NativeLib.buttonUp((int) ((event.getX(actionIndex) - viewPanOffsetX) / viewScaleFactorX), (int) ((event.getY(actionIndex) - viewPanOffsetY) / viewScaleFactorY)); NativeLib.buttonUp((int) ((event.getX(actionIndex) - viewPanOffsetX) / viewScaleFactorX), (int) ((event.getY(actionIndex) - viewPanOffsetY) / viewScaleFactorY));
currentButtonTouched.remove(actionIndex); currentButtonTouched.remove(actionIndex);
preventToScroll = currentButtonTouched.size() > 0; preventToScroll = currentButtonTouched.size() > 0;
@ -236,14 +202,13 @@ public class MainScreenView extends PanAndScaleView {
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
if((event.getFlags() & KeyEvent.FLAG_VIRTUAL_HARD_KEY) == 0) { if((event.getFlags() & KeyEvent.FLAG_VIRTUAL_HARD_KEY) == 0) {
char pressedKey = (char) event.getUnicodeChar(); char pressedKey = (char) event.getUnicodeChar();
//Log.d(TAG, "onKeyDown is: " + pressedKey); if(debug) Log.d(TAG, "onKeyDown is: " + pressedKey);
Integer windowsKeycode = charmap.get(pressedKey); Integer windowsKeycode = charmap.get(pressedKey);
if(windowsKeycode == null) if(windowsKeycode == null)
windowsKeycode = vkmap.get(keyCode); windowsKeycode = vkmap.get(keyCode);
if (windowsKeycode != null) if (windowsKeycode != 0)
NativeLib.keyDown(windowsKeycode); NativeLib.keyDown(windowsKeycode);
else else if(debug) Log.e(TAG, String.format("Unknown keyCode: %d", keyCode));
Log.e(TAG, String.format("Unknown keyCode: %d", keyCode));
} }
if(keyCode == KeyEvent.KEYCODE_BACK) if(keyCode == KeyEvent.KEYCODE_BACK)
return true; return true;
@ -254,14 +219,13 @@ public class MainScreenView extends PanAndScaleView {
public boolean onKeyUp(int keyCode, KeyEvent event) { public boolean onKeyUp(int keyCode, KeyEvent event) {
if((event.getFlags() & KeyEvent.FLAG_VIRTUAL_HARD_KEY) == 0) { if((event.getFlags() & KeyEvent.FLAG_VIRTUAL_HARD_KEY) == 0) {
char pressedKey = (char) event.getUnicodeChar(); char pressedKey = (char) event.getUnicodeChar();
//Log.d(TAG, "onKeyUp is: " + pressedKey); if(debug) Log.d(TAG, "onKeyUp is: " + pressedKey);
Integer windowsKeycode = charmap.get(pressedKey); Integer windowsKeycode = charmap.get(pressedKey);
if(windowsKeycode == null) if(windowsKeycode == null)
windowsKeycode = vkmap.get(keyCode); windowsKeycode = vkmap.get(keyCode);
if (windowsKeycode != null) if (windowsKeycode != 0)
NativeLib.keyUp(windowsKeycode); NativeLib.keyUp(windowsKeycode);
else else if(debug) Log.e(TAG, String.format("Unknown keyCode: %d", keyCode));
Log.e(TAG, String.format("Unknown keyCode: %d", keyCode));
} }
if(keyCode == KeyEvent.KEYCODE_BACK) if(keyCode == KeyEvent.KEYCODE_BACK)
return true; return true;
@ -270,8 +234,6 @@ public class MainScreenView extends PanAndScaleView {
@Override @Override
protected void onSizeChanged(int viewWidth, int viewHeight, int oldViewWidth, int oldViewHeight) { protected void onSizeChanged(int viewWidth, int viewHeight, int oldViewWidth, int oldViewHeight) {
// super.onSizeChanged(viewWidth, viewHeight, oldViewWidth, oldViewHeight);
viewSizeWidth = viewWidth; viewSizeWidth = viewWidth;
viewSizeHeight = viewHeight; viewSizeHeight = viewHeight;
@ -325,8 +287,6 @@ public class MainScreenView extends PanAndScaleView {
constrainPan(); constrainPan();
return; return;
} }
} else {
//((Activity) getContext()).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
} }
} }
} }
@ -350,7 +310,8 @@ public class MainScreenView extends PanAndScaleView {
final int CALLBACK_TYPE_INVALIDATE = 0; final int CALLBACK_TYPE_INVALIDATE = 0;
final int CALLBACK_TYPE_WINDOW_RESIZE = 1; final int CALLBACK_TYPE_WINDOW_RESIZE = 1;
int updateCallback(int type, int param1, int param2, String param3, String param4) { @SuppressWarnings("unused")
public int updateCallback(int type, int param1, int param2, String param3, String param4) {
switch (type) { switch (type) {
case CALLBACK_TYPE_INVALIDATE: case CALLBACK_TYPE_INVALIDATE:
//Log.d(TAG, "PAINT updateCallback() postInvalidate()"); //Log.d(TAG, "PAINT updateCallback() postInvalidate()");

View file

@ -14,6 +14,7 @@
package org.emulator.calculator; package org.emulator.calculator;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
@ -85,7 +86,13 @@ public class PanAndScaleView extends View {
protected boolean firstTime = false; protected boolean firstTime = false;
protected boolean viewHasChanged() { protected boolean viewHasChanged() {
if(viewPanOffsetX != previousViewPanOffsetX || viewPanOffsetY != previousViewPanOffsetY || viewScaleFactorX != previousViewScaleFactorX || viewScaleFactorY != previousViewScaleFactorY) { if((int)viewPanOffsetX != (int)previousViewPanOffsetX || (int)viewPanOffsetY != (int)previousViewPanOffsetY
|| (int)viewScaleFactorX != (int)previousViewScaleFactorX || (int)viewScaleFactorY != (int)previousViewScaleFactorY) {
if(debug) Log.d(TAG, "viewHasChanged() previousViewPanOffsetX: " + previousViewPanOffsetX + ", viewPanOffsetX: " + viewPanOffsetX
+ ", previousViewPanOffsetY: " + previousViewPanOffsetY + ", viewPanOffsetY: " + viewPanOffsetY
+ ", previousViewScaleFactorX: " + previousViewScaleFactorX + ", previousViewScaleFactorY: " + previousViewScaleFactorY
+ ", previousViewScaleFactorY: " + previousViewScaleFactorY + ", viewScaleFactorY: " + viewScaleFactorY);
previousViewPanOffsetX = viewPanOffsetX; previousViewPanOffsetX = viewPanOffsetX;
previousViewPanOffsetY = viewPanOffsetY; previousViewPanOffsetY = viewPanOffsetY;
previousViewScaleFactorX = viewScaleFactorX; previousViewScaleFactorX = viewScaleFactorX;
@ -126,6 +133,7 @@ public class PanAndScaleView extends View {
* Register a callback to be invoked when this view is tapped down. * Register a callback to be invoked when this view is tapped down.
* @param onTapDownListener The callback that will run * @param onTapDownListener The callback that will run
*/ */
@SuppressWarnings("unused")
public void setOnTapDownListener(OnTapListener onTapDownListener) { public void setOnTapDownListener(OnTapListener onTapDownListener) {
this.onTapDownListener = onTapDownListener; this.onTapDownListener = onTapDownListener;
} }
@ -134,30 +142,37 @@ public class PanAndScaleView extends View {
* Register a callback to be invoked when this view is tapped up. * Register a callback to be invoked when this view is tapped up.
* @param onTapUpListener The callback that will run * @param onTapUpListener The callback that will run
*/ */
@SuppressWarnings("unused")
public void setOnTapUpListener(OnTapListener onTapUpListener) { public void setOnTapUpListener(OnTapListener onTapUpListener) {
this.onTapUpListener = onTapUpListener; this.onTapUpListener = onTapUpListener;
} }
@SuppressWarnings("unused")
public float getMaxZoom() { public float getMaxZoom() {
return maxZoom; return maxZoom;
} }
@SuppressWarnings("unused")
public void setMaxZoom(float maxZoom) { public void setMaxZoom(float maxZoom) {
this.maxZoom = maxZoom; this.maxZoom = maxZoom;
} }
@SuppressWarnings("unused")
public boolean getShowCursor() { public boolean getShowCursor() {
return showCursor; return showCursor;
} }
@SuppressWarnings("unused")
public void setShowCursor(boolean showCursor) { public void setShowCursor(boolean showCursor) {
this.showCursor = showCursor; this.showCursor = showCursor;
} }
@SuppressWarnings("unused")
public PointF getCursorLocation() { public PointF getCursorLocation() {
return cursorLocation; return cursorLocation;
} }
@SuppressWarnings("unused")
public void setCursorLocation(float x, float y) { public void setCursorLocation(float x, float y) {
cursorLocation.set(x, y); cursorLocation.set(x, y);
} }
@ -165,6 +180,7 @@ public class PanAndScaleView extends View {
/** /**
* @return true to show a small scale thumbnail in the bottom right; false otherwise. * @return true to show a small scale thumbnail in the bottom right; false otherwise.
*/ */
@SuppressWarnings("unused")
public boolean getShowScaleThumbnail() { public boolean getShowScaleThumbnail() {
return showScaleThumbnail; return showScaleThumbnail;
} }
@ -172,6 +188,7 @@ public class PanAndScaleView extends View {
/** /**
* @param showScaleThumbnail true to show a small scale thumbnail in the bottom right; false otherwise. * @param showScaleThumbnail true to show a small scale thumbnail in the bottom right; false otherwise.
*/ */
@SuppressWarnings("unused")
public void setShowScaleThumbnail(boolean showScaleThumbnail) { public void setShowScaleThumbnail(boolean showScaleThumbnail) {
this.showScaleThumbnail = showScaleThumbnail; this.showScaleThumbnail = showScaleThumbnail;
} }
@ -179,6 +196,7 @@ public class PanAndScaleView extends View {
/** /**
* @return true to allow to zoom when double tapping; false otherwise. * @return true to allow to zoom when double tapping; false otherwise.
*/ */
@SuppressWarnings("unused")
public boolean getAllowDoubleTapZoom() { public boolean getAllowDoubleTapZoom() {
return allowDoubleTapZoom; return allowDoubleTapZoom;
} }
@ -186,6 +204,7 @@ public class PanAndScaleView extends View {
/** /**
* @param allowDoubleTapZoom true to allow to zoom when double tapping; false otherwise. * @param allowDoubleTapZoom true to allow to zoom when double tapping; false otherwise.
*/ */
@SuppressWarnings("unused")
public void setAllowDoubleTapZoom(boolean allowDoubleTapZoom) { public void setAllowDoubleTapZoom(boolean allowDoubleTapZoom) {
this.allowDoubleTapZoom = allowDoubleTapZoom; this.allowDoubleTapZoom = allowDoubleTapZoom;
} }
@ -194,6 +213,7 @@ public class PanAndScaleView extends View {
/** /**
* @return true to allow the virtual space to fill view bounds the ; false otherwise. * @return true to allow the virtual space to fill view bounds the ; false otherwise.
*/ */
@SuppressWarnings("unused")
public boolean getFillBounds() { public boolean getFillBounds() {
return fillBounds; return fillBounds;
} }
@ -201,6 +221,7 @@ public class PanAndScaleView extends View {
/** /**
* @param fillBounds true to allow the virtual space to fill the view bounds; false otherwise. * @param fillBounds true to allow the virtual space to fill the view bounds; false otherwise.
*/ */
@SuppressWarnings("unused")
public void setFillBounds(boolean fillBounds) { public void setFillBounds(boolean fillBounds) {
this.fillBounds = fillBounds; this.fillBounds = fillBounds;
} }
@ -208,6 +229,7 @@ public class PanAndScaleView extends View {
/** /**
* @return true to allow to pan and scale; false otherwise. * @return true to allow to pan and scale; false otherwise.
*/ */
@SuppressWarnings("unused")
public boolean getEnablePanAndScale() { public boolean getEnablePanAndScale() {
return enablePanAndScale; return enablePanAndScale;
} }
@ -276,7 +298,7 @@ public class PanAndScaleView extends View {
@Override @Override
public boolean onDown(MotionEvent e) { public boolean onDown(MotionEvent e) {
if(debug) Log.d(TAG, "onDown() actionIndex: " + e.getActionIndex()); if(debug) Log.d(TAG, "onDown() actionIndex: " + e.getActionIndex() + ", X: " + e.getX() + ", Y: " + e.getY());
scroller.forceFinished(true); scroller.forceFinished(true);
ViewCompat.postInvalidateOnAnimation(PanAndScaleView.this); ViewCompat.postInvalidateOnAnimation(PanAndScaleView.this);
if(onTapDownListener != null) { if(onTapDownListener != null) {
@ -288,14 +310,9 @@ public class PanAndScaleView extends View {
return super.onDown(e); return super.onDown(e);
} }
// @Override
// public void onShowPress(MotionEvent e) {
// super.onShowPress(e);
// }
@Override @Override
public boolean onSingleTapConfirmed(MotionEvent e) { public boolean onSingleTapConfirmed(MotionEvent e) {
if(debug) Log.d(TAG, "onSingleTapConfirmed() actionIndex: " + e.getActionIndex()); if(debug) Log.d(TAG, "onSingleTapConfirmed() actionIndex: " + e.getActionIndex() + ", X: " + e.getX() + ", Y: " + e.getY());
if(onTapUpListener != null) { if(onTapUpListener != null) {
float scaleAndPanX = (e.getX() - viewPanOffsetX) / viewScaleFactorX; float scaleAndPanX = (e.getX() - viewPanOffsetX) / viewScaleFactorX;
float scaleAndPanY = (e.getY() - viewPanOffsetY) / viewScaleFactorY; float scaleAndPanY = (e.getY() - viewPanOffsetY) / viewScaleFactorY;
@ -308,7 +325,7 @@ public class PanAndScaleView extends View {
@Override @Override
public boolean onDoubleTap(MotionEvent e) { public boolean onDoubleTap(MotionEvent e) {
if(debug) Log.d(TAG, "onDoubleTap() actionIndex: " + e.getActionIndex()); if(debug) Log.d(TAG, "onDoubleTap() actionIndex: " + e.getActionIndex() + ", X: " + e.getX() + ", Y: " + e.getY());
if(!allowDoubleTapZoom || fillBounds) if(!allowDoubleTapZoom || fillBounds)
return false; return false;
float scaleFactorPreviousX = viewScaleFactorX; float scaleFactorPreviousX = viewScaleFactorX;
@ -328,7 +345,11 @@ public class PanAndScaleView extends View {
@Override @Override
public boolean onScroll(MotionEvent downEvent, MotionEvent moveEvent, float distanceX, float distanceY) { public boolean onScroll(MotionEvent downEvent, MotionEvent moveEvent, float distanceX, float distanceY) {
if(debug) Log.d(TAG, "onScroll() downEvent.actionIndex: " + (downEvent != null ? downEvent.getActionIndex() : "null") + ", moveEvent.actionIndex: " + (downEvent != null ? moveEvent.getActionIndex() : "null")); if(debug)
Log.d(TAG, "onScroll() downEvent.actionIndex: " + (downEvent != null ? downEvent.getActionIndex() : "null")
+ ", moveEvent.actionIndex: " + (downEvent != null ? moveEvent.getActionIndex() : "null")
+ ", distanceX: " + distanceX + ", distanceY: " + distanceY
);
if(fillBounds || preventToScroll) if(fillBounds || preventToScroll)
return false; return false;
@ -355,10 +376,10 @@ public class PanAndScaleView extends View {
+ ", minX: " + viewPanMinX + ", maxX: " + 0 + ", minX: " + viewPanMinX + ", maxX: " + 0
+ ", minY: " + viewPanMinY + ", maxY: " + 0 + ", minY: " + viewPanMinY + ", maxY: " + 0
+ ")"); + ")");
scroller.fling((int) viewPanOffsetX, (int) viewPanOffsetY, scroller.fling(-(int)viewPanOffsetX, -(int)viewPanOffsetY,
(int)(velocityFactor * velocityX), (int)(velocityFactor * velocityY), (int)(velocityFactor * velocityX), (int)(velocityFactor * velocityY),
(int)viewPanMinX, 0, 0, -(int)viewPanMinX,
(int)viewPanMinY, 0); 0, -(int)viewPanMinY);
ViewCompat.postInvalidateOnAnimation(PanAndScaleView.this); ViewCompat.postInvalidateOnAnimation(PanAndScaleView.this);
return true; return true;
} }
@ -367,8 +388,7 @@ public class PanAndScaleView extends View {
this.setFocusable(true); this.setFocusable(true);
this.setFocusableInTouchMode(true); this.setFocusableInTouchMode(true);
// This call is necessary, or else the // This call is necessary, or else the draw method will not be called.
// draw method will not be called.
setWillNotDraw(false); setWillNotDraw(false);
} }
@ -412,6 +432,7 @@ public class PanAndScaleView extends View {
invalidate(); invalidate();
} }
@SuppressWarnings("unused")
public void postDoScroll(float deltaX, float deltaY, boolean center) { public void postDoScroll(float deltaX, float deltaY, boolean center) {
if(fillBounds) if(fillBounds)
return; return;
@ -423,9 +444,11 @@ public class PanAndScaleView extends View {
postInvalidate(); postInvalidate();
} }
@SuppressLint("ClickableViewAccessibility")
@Override @Override
public boolean onTouchEvent(MotionEvent event) { public boolean onTouchEvent(MotionEvent event) {
if(enablePanAndScale) { if(enablePanAndScale) {
// The order of operations is important
boolean result = scaleDetector.onTouchEvent(event); boolean result = scaleDetector.onTouchEvent(event);
result = gestureDetector.onTouchEvent(event) || result; result = gestureDetector.onTouchEvent(event) || result;
return result || super.onTouchEvent(event); return result || super.onTouchEvent(event);
@ -436,14 +459,12 @@ public class PanAndScaleView extends View {
@Override @Override
public boolean onGenericMotionEvent(MotionEvent event) { public boolean onGenericMotionEvent(MotionEvent event) {
if (enablePanAndScale && !fillBounds && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { if (enablePanAndScale && !fillBounds && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
//if (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) { if (event.getAction() == MotionEvent.ACTION_SCROLL) {
switch (event.getAction()) {
case MotionEvent.ACTION_SCROLL:
float wheelDelta = event.getAxisValue(MotionEvent.AXIS_VSCROLL); float wheelDelta = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
if(wheelDelta > 0f) if (wheelDelta > 0f)
scaleByStep(scaleStep, event.getX(), event.getY()); scaleByStep(scaleStep, event.getX(), event.getY());
else if(wheelDelta < 0f) else if (wheelDelta < 0f)
scaleByStep(1.0f / scaleStep, event.getX(), event.getY()); scaleByStep(1.0f / scaleStep, event.getX(), event.getY());
return true; return true;
} }
@ -466,12 +487,7 @@ public class PanAndScaleView extends View {
return super.onKeyUp(keyCode, event); return super.onKeyUp(keyCode, event);
} }
/** // Scale the view step by step following the mouse/touch position
* Scale the view step by step following the mouse/touch position
* @param scaleFactor
* @param x
* @param y
*/
private void scaleByStep(float scaleFactor, float x, float y) { private void scaleByStep(float scaleFactor, float x, float y) {
float scaleFactorPreviousX = viewScaleFactorX; float scaleFactorPreviousX = viewScaleFactorX;
float scaleFactorPreviousY = viewScaleFactorY; float scaleFactorPreviousY = viewScaleFactorY;
@ -490,9 +506,6 @@ public class PanAndScaleView extends View {
} }
private void scaleWithFocus(float focusX, float focusY, float scaleFactorPreviousX, float scaleFactorPreviousY) { private void scaleWithFocus(float focusX, float focusY, float scaleFactorPreviousX, float scaleFactorPreviousY) {
//float centeredScaleFactor = 1f - viewScaleFactor / scaleFactorPrevious;
//viewPanOffsetX += (focusX - viewPanOffsetX) * centeredScaleFactor;
//viewPanOffsetY += (focusY - viewPanOffsetY) * centeredScaleFactor;
viewPanOffsetX = viewPanOffsetX + (focusX - viewPanOffsetX) - (focusX - viewPanOffsetX) * viewScaleFactorX / scaleFactorPreviousX; viewPanOffsetX = viewPanOffsetX + (focusX - viewPanOffsetX) - (focusX - viewPanOffsetX) * viewScaleFactorX / scaleFactorPreviousX;
viewPanOffsetY = viewPanOffsetY + (focusY - viewPanOffsetY) - (focusY - viewPanOffsetY) * viewScaleFactorY / scaleFactorPreviousY; viewPanOffsetY = viewPanOffsetY + (focusY - viewPanOffsetY) - (focusY - viewPanOffsetY) * viewScaleFactorY / scaleFactorPreviousY;
} }
@ -616,6 +629,7 @@ public class PanAndScaleView extends View {
@Override @Override
protected void onSizeChanged(int viewWidth, int viewHeight, int oldViewWidth, int oldViewHeight) { protected void onSizeChanged(int viewWidth, int viewHeight, int oldViewWidth, int oldViewHeight) {
if(debug) Log.d(TAG, "onSizeChanged(viewWidth: " + viewWidth + ", viewHeight: " + viewHeight + ", oldViewWidth: " + oldViewWidth + ", oldViewHeight: " + oldViewHeight + ")");
super.onSizeChanged(viewWidth, viewHeight, oldViewWidth, oldViewHeight); super.onSizeChanged(viewWidth, viewHeight, oldViewWidth, oldViewHeight);
viewSizeWidth = viewWidth; viewSizeWidth = viewWidth;
@ -674,9 +688,6 @@ public class PanAndScaleView extends View {
viewSizeHeight - marginY viewSizeHeight - marginY
); );
canvas.drawRect(rectScaleImage, paint); canvas.drawRect(rectScaleImage, paint);
// rectBitmapSource.set(0, 0, (int) virtualSizeWidth, (int) virtualSizeHeight);
// if(mBitmap != null)
// canvas.drawBitmap(mBitmap, rectBitmapSource, rectScaleImage, paint);
rectScaleView.set(rectScaleImage.left + scale * (-viewPanOffsetX / viewScaleFactorX), rectScaleView.set(rectScaleImage.left + scale * (-viewPanOffsetX / viewScaleFactorX),
rectScaleImage.top + scale * (-viewPanOffsetY / viewScaleFactorY), rectScaleImage.top + scale * (-viewPanOffsetY / viewScaleFactorY),
rectScaleImage.left + scale * (viewSizeWidth - viewPanOffsetX) / viewScaleFactorX, rectScaleImage.left + scale * (viewSizeWidth - viewPanOffsetX) / viewScaleFactorX,

File diff suppressed because it is too large Load diff

View file

@ -14,7 +14,6 @@
package org.emulator.calculator; package org.emulator.calculator;
import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
@ -22,7 +21,6 @@ import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Bundle; import android.os.Bundle;
@ -33,6 +31,7 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
import android.widget.ScrollView;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -54,19 +53,11 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment {
private static final String TAG = "PrinterSimulator"; private static final String TAG = "PrinterSimulator";
private boolean debug = false; private boolean debug = false;
private PrinterSimulator printerSimulator; private PrinterSimulator printerSimulator;
private Toolbar toolbar;
private TextView textViewPrinterText; private TextView textViewPrinterText;
private ScrollView scrollViewPrinterText;
private PrinterGraphView printerGraphView; private PrinterGraphView printerGraphView;
// ColorMatrixColorFilter colorFilterAlpha8ToRGB = new ColorMatrixColorFilter(new float[]{
// 0, 0, 0, 1, 0,
// 0, 0, 0, 1, 0,
// 0, 0, 0, 1, 0,
// 0, 0, 0, 0, 255
// });
public PrinterSimulatorFragment() { public PrinterSimulatorFragment() {
} }
@Override @Override
@ -92,20 +83,25 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment {
// getDialog().getWindow().setAttributes((android.view.WindowManager.LayoutParams) params); // getDialog().getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
// } // }
@NonNull
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState); Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); Window window = dialog.getWindow();
if(window != null)
window.requestFeature(Window.FEATURE_NO_TITLE);
return dialog; return dialog;
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
String title = getString(Utils.resId(this, "string", "dialog_printer_simulator_title")); String title = getString(Utils.resId(this, "string", "dialog_printer_simulator_title"));
if(printerSimulator != null) if(printerSimulator != null)
title = printerSimulator.getTitle(); title = printerSimulator.getTitle();
getDialog().setTitle(title); Dialog dialog = getDialog();
if(dialog != null)
dialog.setTitle(title);
// Inflate the layout for this fragment // Inflate the layout for this fragment
@ -113,10 +109,8 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment {
// Toolbar // Toolbar
toolbar = view.findViewById(Utils.resId(this, "id", "my_toolbar")); Toolbar toolbar = view.findViewById(Utils.resId(this, "id", "my_toolbar"));
toolbar.setTitle(title); toolbar.setTitle(title);
//toolbar.setOverflowIcon(ContextCompat.getDrawable(getActivity(), Utils.resId(this, "drawable", "ic_more_vert_white_24dp")));
//toolbar.setLogo(R.drawable.ic_launcher);
toolbar.setNavigationIcon(Utils.resId(this, "drawable", "ic_keyboard_backspace_white_24dp")); toolbar.setNavigationIcon(Utils.resId(this, "drawable", "ic_keyboard_backspace_white_24dp"));
toolbar.setNavigationOnClickListener( toolbar.setNavigationOnClickListener(
new View.OnClickListener() { new View.OnClickListener() {
@ -143,22 +137,24 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment {
Bitmap croppedPaperBitmap = Bitmap.createBitmap(paperBitmap.getWidth(), printerSimulator.getPaperHeight(), Bitmap.Config.ARGB_8888); Bitmap croppedPaperBitmap = Bitmap.createBitmap(paperBitmap.getWidth(), printerSimulator.getPaperHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(croppedPaperBitmap); Canvas canvas = new Canvas(croppedPaperBitmap);
Paint paint = new Paint(); Paint paint = new Paint();
//paint.setColorFilter(colorFilterAlpha8ToRGB);
canvas.drawBitmap(paperBitmap, 0, 0, paint); canvas.drawBitmap(paperBitmap, 0, 0, paint);
File storagePath = new File(getActivity().getExternalCacheDir(), ""); Activity activity = getActivity();
File imageFile = File.createTempFile(imageFilename, ".png", storagePath); if(activity != null) {
FileOutputStream fileOutputStream = new FileOutputStream(imageFile); File storagePath = new File(activity.getExternalCacheDir(), "");
croppedPaperBitmap.compress(Bitmap.CompressFormat.PNG, 90, fileOutputStream); File imageFile = File.createTempFile(imageFilename, ".png", storagePath);
fileOutputStream.close(); FileOutputStream fileOutputStream = new FileOutputStream(imageFile);
String mimeType = "application/png"; croppedPaperBitmap.compress(Bitmap.CompressFormat.PNG, 90, fileOutputStream);
Intent intent = new Intent(android.content.Intent.ACTION_SEND); fileOutputStream.close();
intent.setType(mimeType); String mimeType = "application/png";
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_SUBJECT, Utils.resId(PrinterSimulatorFragment.this, "string", "message_printer_share_graphic")); intent.setType(mimeType);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(getActivity(),getActivity().getPackageName() + ".provider", imageFile)); intent.putExtra(Intent.EXTRA_SUBJECT, Utils.resId(PrinterSimulatorFragment.this, "string", "message_printer_share_graphic"));
startActivity(Intent.createChooser(intent, getString(Utils.resId(PrinterSimulatorFragment.this, "string", "message_printer_share_graphic")))); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(getActivity(), getActivity().getPackageName() + ".provider", imageFile));
startActivity(Intent.createChooser(intent, getString(Utils.resId(PrinterSimulatorFragment.this, "string", "message_printer_share_graphic"))));
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
Utils.showAlert(getActivity(), e.getMessage()); Utils.showAlert(getActivity(), e.getMessage());
@ -182,25 +178,22 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment {
ViewPager pager = view.findViewById(Utils.resId(this, "id", "viewPagerPrinter")); ViewPager pager = view.findViewById(Utils.resId(this, "id", "viewPagerPrinter"));
pager.setAdapter(new PagerAdapter() { pager.setAdapter(new PagerAdapter() {
@SuppressLint("ClickableViewAccessibility") @NonNull
public Object instantiateItem(ViewGroup container, int position) { public Object instantiateItem(@NonNull ViewGroup container, int position) {
switch (position) { if (position == 0) {
case 0: { ViewGroup layoutPagePrinterText = container.findViewById(Utils.resId(PrinterSimulatorFragment.this, "id", "page_printer_text"));
ViewGroup layoutPagePrinterText = container.findViewById(Utils.resId(PrinterSimulatorFragment.this, "id", "page_printer_text")); textViewPrinterText = container.findViewById(Utils.resId(PrinterSimulatorFragment.this, "id", "printer_text"));
textViewPrinterText = container.findViewById(Utils.resId(PrinterSimulatorFragment.this, "id", "printer_text")); scrollViewPrinterText = container.findViewById(Utils.resId(PrinterSimulatorFragment.this, "id", "printer_text_scroll"));
updatePaper(printerSimulator.getText()); updatePaper(printerSimulator.getText());
return layoutPagePrinterText; return layoutPagePrinterText;
} } else {
case 1: { ViewGroup layoutPagePrinterGraphic = container.findViewById(Utils.resId(PrinterSimulatorFragment.this, "id", "page_printer_graphic"));
ViewGroup layoutPagePrinterGraphic = container.findViewById(Utils.resId(PrinterSimulatorFragment.this, "id", "page_printer_graphic")); ViewGroup pagePrinterGraphicContainer = container.findViewById(Utils.resId(PrinterSimulatorFragment.this, "id", "printer_graphic_container"));
ViewGroup pagePrinterGraphicContainer = container.findViewById(Utils.resId(PrinterSimulatorFragment.this, "id", "printer_graphic_container")); printerGraphView = new PrinterGraphView(getActivity());
printerGraphView = new PrinterGraphView(getActivity()); printerGraphView.setBitmap(printerSimulator.getImage());
printerGraphView.setBitmap(printerSimulator.getImage()); pagePrinterGraphicContainer.addView(printerGraphView);
pagePrinterGraphicContainer.addView(printerGraphView); return layoutPagePrinterGraphic;
return layoutPagePrinterGraphic;
}
} }
return null;
} }
@Override @Override
@ -234,6 +227,7 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment {
if(debug) Log.d(TAG, "updatePaper(" + textAppended + ")"); if(debug) Log.d(TAG, "updatePaper(" + textAppended + ")");
if(textViewPrinterText != null) { if(textViewPrinterText != null) {
textViewPrinterText.append(textAppended); textViewPrinterText.append(textAppended);
scrollViewPrinterText.fullScroll(View.FOCUS_DOWN);
} }
if(printerGraphView != null) { if(printerGraphView != null) {
printerGraphView.updatePaperLayout(); printerGraphView.updatePaperLayout();
@ -370,8 +364,7 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment {
@Override @Override
protected void onCustomDraw(Canvas canvas) { protected void onCustomDraw(Canvas canvas) {
//paintBitmap.setColorFilter(colorFilterAlpha8ToRGB); canvas.drawColor(Color.BLACK);
canvas.drawColor(Color.BLACK); // LTGRAY);
Rect paperclip = new Rect(0, 0, bitmap.getWidth(), printerSimulator.getPaperHeight()); Rect paperclip = new Rect(0, 0, bitmap.getWidth(), printerSimulator.getPaperHeight());
canvas.drawBitmap(this.bitmap, paperclip, paperclip, paintBitmap); canvas.drawBitmap(this.bitmap, paperclip, paperclip, paintBitmap);
} }

View file

@ -37,7 +37,7 @@ public class Utils {
toast.show(); toast.show();
} }
public static int resId(Context context, String resourcename, String variableName) static int resId(Context context, String resourcename, String variableName)
{ {
try { try {
return context.getResources().getIdentifier(variableName, resourcename, context.getApplicationContext().getPackageName()); return context.getResources().getIdentifier(variableName, resourcename, context.getApplicationContext().getPackageName());
@ -47,14 +47,16 @@ public class Utils {
} }
} }
public static int resId(Fragment context, String resourcename, String variableName) static int resId(Fragment fragment, String resourcename, String variableName)
{ {
try { try {
return context.getResources().getIdentifier(variableName, resourcename, context.getContext().getApplicationContext().getPackageName()); Context context = fragment.getContext();
if(context != null)
return fragment.getResources().getIdentifier(variableName, resourcename, context.getApplicationContext().getPackageName());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return -1;
} }
return -1;
} }
public static String getFileName(Context context, String url) { public static String getFileName(Context context, String url) {
@ -92,7 +94,7 @@ public class Utils {
} }
// https://community.khronos.org/t/get-maximum-texture-size/67795 // https://community.khronos.org/t/get-maximum-texture-size/67795
public static int getMaximumTextureSize() { static int getMaximumTextureSize() {
EGL10 egl = (EGL10) EGLContext.getEGL(); EGL10 egl = (EGL10) EGLContext.getEGL();
EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
@ -128,7 +130,7 @@ public class Utils {
// Release // Release
egl.eglTerminate(display); egl.eglTerminate(display);
Log.i("GLHelper", "Maximum GL texture size: " + Integer.toString(maximumTextureSize)); Log.i("GLHelper", "Maximum GL texture size: " + maximumTextureSize);
return maximumTextureSize; return maximumTextureSize;
} }

View file

@ -14,6 +14,7 @@
package org.emulator.calculator; package org.emulator.calculator;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.MotionEvent; import android.view.MotionEvent;
@ -26,6 +27,7 @@ public class ViewPagerNoSwipe extends ViewPager {
super(context, attrs); super(context, attrs);
} }
@SuppressLint("ClickableViewAccessibility")
@Override @Override
public boolean onTouchEvent(MotionEvent event) { public boolean onTouchEvent(MotionEvent event) {
return false; return false;

View file

@ -30,6 +30,7 @@ import android.os.Bundle;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.util.SparseArray;
import android.view.HapticFeedbackConstants; import android.view.HapticFeedbackConstants;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -40,6 +41,7 @@ import android.widget.ImageButton;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
@ -334,9 +336,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
} }
@Override @Override
public boolean onNavigationItemSelected(MenuItem item) { public boolean onNavigationItemSelected(@NonNull MenuItem item) {
// Handle navigation view item clicks here. // Handle navigation view item clicks here.
int id = item != null ? item.getItemId() : -1; int id = item.getItemId();
if (id == R.id.nav_new) { if (id == R.id.nav_new) {
OnFileNew(); OnFileNew();
} else if (id == R.id.nav_open) { } else if (id == R.id.nav_open) {
@ -544,40 +546,42 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
if(documentFile != null) { if(documentFile != null) {
Uri fileUri = documentFile.getUri(); Uri fileUri = documentFile.getUri();
InputStream inputStream = getContentResolver().openInputStream(fileUri); InputStream inputStream = getContentResolver().openInputStream(fileUri);
reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); if(inputStream != null) {
// do reading, usually loop until end of file reading reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
String mLine; // do reading, usually loop until end of file reading
boolean inGlobal = false; String mLine;
String title = null; boolean inGlobal = false;
String model = null; String title = null;
while ((mLine = reader.readLine()) != null) { String model = null;
//process line while ((mLine = reader.readLine()) != null) {
if (mLine.indexOf("Global") == 0) { //process line
inGlobal = true; if (mLine.indexOf("Global") == 0) {
title = null; inGlobal = true;
model = null; title = null;
continue; model = null;
} continue;
if (inGlobal) { }
if (mLine.indexOf("End") == 0) { if (inGlobal) {
KMLScriptItem newKMLScriptItem = new KMLScriptItem(); if (mLine.indexOf("End") == 0) {
newKMLScriptItem.filename = kmlFolderUseDefault ? calculatorFilename : "document:" + kmlFolderURL + "|" + calculatorFilename; KMLScriptItem newKMLScriptItem = new KMLScriptItem();
newKMLScriptItem.title = title; newKMLScriptItem.filename = kmlFolderUseDefault ? calculatorFilename : "document:" + kmlFolderURL + "|" + calculatorFilename;
newKMLScriptItem.model = model; newKMLScriptItem.title = title;
kmlScripts.add(newKMLScriptItem); newKMLScriptItem.model = model;
break; kmlScripts.add(newKMLScriptItem);
} break;
}
m = patternGlobalTitle.matcher(mLine);
if (m.find()) { m = patternGlobalTitle.matcher(mLine);
title = m.group(1); if (m.find()) {
} title = m.group(1);
m = patternGlobalModel.matcher(mLine); }
if (m.find()) { m = patternGlobalModel.matcher(mLine);
model = m.group(1); if (m.find()) {
} model = m.group(1);
} }
} }
}
}
} }
} catch (IOException e) { } catch (IOException e) {
//log the exception //log the exception
@ -624,7 +628,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
if (continueCallback != null) if (continueCallback != null)
continueCallback.run(); continueCallback.run();
} else { } else {
//TODO SaveAs...
fileSaveAsCallback = continueCallback; fileSaveAsCallback = continueCallback;
OnFileSaveAs(); OnFileSaveAs();
} }
@ -1257,7 +1260,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
final int GENERIC_READ = 1; final int GENERIC_READ = 1;
final int GENERIC_WRITE = 2; final int GENERIC_WRITE = 2;
Map<Integer, ParcelFileDescriptor> parcelFileDescriptorPerFd = null; SparseArray<ParcelFileDescriptor> parcelFileDescriptorPerFd = null;
public int openFileFromContentResolver(String fileURL, int writeAccess) { public int openFileFromContentResolver(String fileURL, int writeAccess) {
//https://stackoverflow.com/a/31677287 //https://stackoverflow.com/a/31677287
Uri uri = Uri.parse(fileURL); Uri uri = Uri.parse(fileURL);
@ -1278,11 +1281,13 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
} }
int fd = filePfd != null ? filePfd.getFd() : 0; int fd = filePfd != null ? filePfd.getFd() : 0;
if(parcelFileDescriptorPerFd == null) { if(parcelFileDescriptorPerFd == null) {
parcelFileDescriptorPerFd = new HashMap<>(); parcelFileDescriptorPerFd = new SparseArray<>();
} }
parcelFileDescriptorPerFd.put(fd, filePfd); parcelFileDescriptorPerFd.put(fd, filePfd);
return fd; return fd;
} }
@SuppressWarnings("unused")
public int openFileInFolderFromContentResolver(String filename, String folderURL, int writeAccess) { public int openFileInFolderFromContentResolver(String filename, String folderURL, int writeAccess) {
Uri folderURI = Uri.parse(folderURL); Uri folderURI = Uri.parse(folderURL);
DocumentFile folderDocumentFile = DocumentFile.fromTreeUri(this, folderURI); DocumentFile folderDocumentFile = DocumentFile.fromTreeUri(this, folderURI);
@ -1298,6 +1303,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
} }
return -1; return -1;
} }
@SuppressWarnings("unused")
public int closeFileFromContentResolver(int fd) { public int closeFileFromContentResolver(int fd) {
if(parcelFileDescriptorPerFd != null) { if(parcelFileDescriptorPerFd != null) {
ParcelFileDescriptor filePfd = parcelFileDescriptorPerFd.get(fd); ParcelFileDescriptor filePfd = parcelFileDescriptorPerFd.get(fd);
@ -1318,6 +1325,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
Utils.showAlert(this, text); Utils.showAlert(this, text);
} }
@SuppressWarnings("unused")
public void sendMenuItemCommand(int menuItem) { public void sendMenuItemCommand(int menuItem) {
switch (menuItem) { switch (menuItem) {
case 1: // FILE_NEW case 1: // FILE_NEW
@ -1396,6 +1404,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
} }
} }
@SuppressWarnings("unused")
public String getFirstKMLFilenameForType(char chipsetType) { public String getFirstKMLFilenameForType(char chipsetType) {
extractKMLScripts(); extractKMLScripts();
@ -1422,6 +1431,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
return null; return null;
} }
@SuppressWarnings("unused")
public void clipboardCopyText(String text) { public void clipboardCopyText(String text) {
// Gets a handle to the clipboard service. // Gets a handle to the clipboard service.
ClipboardManager clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
@ -1431,6 +1441,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
clipboard.setPrimaryClip(clip); clipboard.setPrimaryClip(clip);
} }
} }
@SuppressWarnings("unused")
public String clipboardPasteText() { public String clipboardPasteText() {
ClipboardManager clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard != null && clipboard.hasPrimaryClip()) { if (clipboard != null && clipboard.hasPrimaryClip()) {
@ -1446,11 +1457,13 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
return ""; return "";
} }
@SuppressWarnings("unused")
public void performHapticFeedback() { public void performHapticFeedback() {
if(sharedPreferences.getBoolean("settings_haptic_feedback", true)) if(sharedPreferences.getBoolean("settings_haptic_feedback", true))
mainScreenView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); mainScreenView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
} }
@SuppressWarnings("unused")
public void sendByteUdp(int byteSent) { public void sendByteUdp(int byteSent) {
printerSimulator.write(byteSent); printerSimulator.write(byteSent);
} }
@ -1487,9 +1500,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
case "settings_rotation": case "settings_rotation":
int rotationMode = 0; int rotationMode = 0;
try { try {
String rotationModeValue = sharedPreferences.getString("settings_rotation", "0"); rotationMode = Integer.parseInt(sharedPreferences.getString("settings_rotation", "0"));
if(rotationModeValue != null)
rotationMode = Integer.parseInt(rotationModeValue);
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
// Catch bad number format // Catch bad number format
} }
@ -1498,9 +1509,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
case "settings_auto_layout": case "settings_auto_layout":
int autoLayoutMode = 1; int autoLayoutMode = 1;
try { try {
String autoLayoutModeValue = sharedPreferences.getString("settings_auto_layout", "1"); autoLayoutMode = Integer.parseInt(sharedPreferences.getString("settings_auto_layout", "1"));
if(autoLayoutModeValue != null)
autoLayoutMode = Integer.parseInt(autoLayoutModeValue);
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
// Catch bad number format // Catch bad number format
} }
@ -1532,19 +1541,15 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
mainScreenView.setBackgroundKmlColor(sharedPreferences.getBoolean("settings_background_kml_color", false)); mainScreenView.setBackgroundKmlColor(sharedPreferences.getBoolean("settings_background_kml_color", false));
break; break;
case "settings_background_fallback_color": case "settings_background_fallback_color":
String fallbackColor = sharedPreferences.getString("settings_background_fallback_color", "0");
try { try {
if(fallbackColor != null) mainScreenView.setBackgroundFallbackColor(Integer.parseInt(sharedPreferences.getString("settings_background_fallback_color", "0")));
mainScreenView.setBackgroundFallbackColor(Integer.parseInt(fallbackColor));
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
// Catch bad number format // Catch bad number format
} }
break; break;
case "settings_printer_model": case "settings_printer_model":
String printerModel = sharedPreferences.getString("settings_printer_model", "1");
try { try {
if(printerModel != null) printerSimulator.setPrinterModel82240A(Integer.parseInt(sharedPreferences.getString("settings_printer_model", "1")) == 0);
printerSimulator.setPrinterModel82240A(Integer.parseInt(printerModel) == 0);
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
// Catch bad number format // Catch bad number format
} }

View file

@ -130,7 +130,7 @@ public class SettingsActivity extends AppCompatActivity implements SharedPrefere
int backgroundFallbackColor = -1; int backgroundFallbackColor = -1;
try { try {
backgroundFallbackColor = Integer.parseInt(stringValue); backgroundFallbackColor = Integer.parseInt(stringValue);
} catch (NumberFormatException ex) {} } catch (NumberFormatException ignored) {}
if(backgroundFallbackColor >= 0 && backgroundFallbackColor < stringArrayBackgroundFallbackColor.length) if(backgroundFallbackColor >= 0 && backgroundFallbackColor < stringArrayBackgroundFallbackColor.length)
preference.setSummary(stringArrayBackgroundFallbackColor[backgroundFallbackColor]); preference.setSummary(stringArrayBackgroundFallbackColor[backgroundFallbackColor]);
// preferenceBackgroundCustomColor.setEnabled(backgroundFallbackColor == 2); // preferenceBackgroundCustomColor.setEnabled(backgroundFallbackColor == 2);
@ -216,13 +216,15 @@ public class SettingsActivity extends AppCompatActivity implements SharedPrefere
intent.addCategory(Intent.CATEGORY_OPENABLE); intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*"); intent.setType("*/*");
intent.putExtra(Intent.EXTRA_TITLE, "shared.bin"); intent.putExtra(Intent.EXTRA_TITLE, "shared.bin");
getActivity().startActivityForResult(intent, MainActivity.INTENT_PORT2LOAD); Activity activity = getActivity();
if(activity != null)
activity.startActivityForResult(intent, MainActivity.INTENT_PORT2LOAD);
return true; return true;
} }
}); });
} }
public void updatePort2LoadFilename(String port2Filename) { void updatePort2LoadFilename(String port2Filename) {
if(preferencePort2load != null) { if(preferencePort2load != null) {
String displayName = port2Filename; String displayName = port2Filename;
try { try {

View file

@ -7,6 +7,7 @@
android:id="@+id/textViewInfo" android:id="@+id/textViewInfo"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="5dp" /> android:padding="5dp"
android:textIsSelectable="true" />
</ScrollView> </ScrollView>

View file

@ -1,10 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/page_printer_graphic" android:id="@+id/page_printer_graphic"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="20dp"
android:layout_margin="10dp"> android:layout_margin="10dp">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
@ -19,7 +18,7 @@
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/printer_graphic_container" android:id="@+id/printer_graphic_margin"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_margin="1dp" android:layout_margin="1dp"
@ -29,6 +28,18 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/printer_graphic_container"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/page_printer_text" android:id="@+id/page_printer_text"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -19,7 +18,7 @@
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/printer_text_container" android:id="@+id/printer_text_margin"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_margin="1dp" android:layout_margin="1dp"
@ -29,20 +28,26 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
<TextView <ScrollView
android:id="@+id/printer_text" android:id="@+id/printer_text_scroll"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_margin="2dp" android:layout_margin="5dp"
android:background="#FFFFFFFF"
android:text=""
android:typeface="monospace"
android:textIsSelectable="true"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" >
<TextView
android:id="@+id/printer_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:typeface="monospace"
/>
<!--android:textSize="20sp"-->
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>