diff --git a/ReadMe.txt b/ReadMe.txt index 62782e5..f22fb2f 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -63,9 +63,11 @@ LINKS CHANGES -Version 1.8beta2 (2019-12-19) +Version 1.8beta3 (2020-04-XX) - Intercept the ESC keyboard key to allow the use of the BACK soft key. +- Add LCD pixel borders. +- Add support for the dark theme. Version 1.7 (2019-12-12) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c2939cf..9a64134 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,8 +10,6 @@ android:resizeableActivity="true" android:theme="@style/AppTheme" android:fullBackupContent="@xml/backup_descriptor"> - - realizedPalette && hLcdDC->realizedPalette->paletteLog && + hLcdDC->realizedPalette->paletteLog->palPalEntry) { + PALETTEENTRY *palPalEntry = hLcdDC->realizedPalette->paletteLog->palPalEntry; + return palPalEntry[0].peRed << 16 | palPalEntry[0].peGreen << 8 | palPalEntry[0].peBlue; + } + return -1; +} \ No newline at end of file diff --git a/app/src/main/cpp/win32-layer.c b/app/src/main/cpp/win32-layer.c index 40bd0dd..84afe10 100644 --- a/app/src/main/cpp/win32-layer.c +++ b/app/src/main/cpp/win32-layer.c @@ -306,6 +306,7 @@ DWORD GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh) { } else if(hFile->handleType == HANDLE_TYPE_FILE_ASSET) { return (DWORD) AAsset_getLength64(hFile->fileAsset); } + return 0; } //** https://www.ibm.com/developerworks/systems/library/es-MigratingWin32toLinux.html @@ -554,7 +555,7 @@ extern int jniDetachCurrentThread(); #define MAX_CREATED_THREAD 30 static HANDLE threads[MAX_CREATED_THREAD]; -static DWORD ThreadStart(LPVOID lpThreadParameter) { +static void ThreadStart(LPVOID lpThreadParameter) { HANDLE handle = (HANDLE)lpThreadParameter; if(handle) { handle->threadStartAddress(handle->threadParameter); diff --git a/app/src/main/java/org/emulator/calculator/LCDOverlappingView.java b/app/src/main/java/org/emulator/calculator/LCDOverlappingView.java index 693daff..0866061 100644 --- a/app/src/main/java/org/emulator/calculator/LCDOverlappingView.java +++ b/app/src/main/java/org/emulator/calculator/LCDOverlappingView.java @@ -38,7 +38,6 @@ public class LCDOverlappingView extends View { private Paint paint = new Paint(); private Rect srcBitmapCopy = new Rect(); private Rect dstBitmapCopy = new Rect(); - private Bitmap bitmapLCD; private float bitmapRatio = -1; private float minViewSize = 200.0f; public static int OVERLAPPING_LCD_MODE_NONE = 0; @@ -62,8 +61,6 @@ public class LCDOverlappingView extends View { DisplayMetrics displayMetrics = new DisplayMetrics(); ((Activity)context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); - bitmapLCD = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); - bitmapLCD.eraseColor(Color.BLACK); this.setFocusable(true); this.setFocusableInTouchMode(true); @@ -219,7 +216,7 @@ public class LCDOverlappingView extends View { protected void onDraw(Canvas canvas) { //if(debug) Log.d(TAG, "onDraw()"); - if(this.overlappingLCDMode != OVERLAPPING_LCD_MODE_NONE && bitmapLCD != null) { + if(this.overlappingLCDMode != OVERLAPPING_LCD_MODE_NONE) { int x = NativeLib.getScreenPositionX(); int y = NativeLib.getScreenPositionY(); srcBitmapCopy.set(x, y, x + NativeLib.getScreenWidth(), y + NativeLib.getScreenHeight()); @@ -228,37 +225,6 @@ public class LCDOverlappingView extends View { } } - public void updateCallback(int type, int param1, int param2, String param3, String param4) { - if(this.overlappingLCDMode == OVERLAPPING_LCD_MODE_NONE) - return; - switch (type) { - case NativeLib.CALLBACK_TYPE_INVALIDATE: - //if(debug) Log.d(TAG, "updateCallback() CALLBACK_TYPE_INVALIDATE"); - if(bitmapLCD.getWidth() > 1) - postInvalidate(); - break; - case NativeLib.CALLBACK_TYPE_WINDOW_RESIZE: - // New Bitmap size - int newLCDWidth = NativeLib.getScreenWidth(); - int newLCDHeight = NativeLib.getScreenHeight(); - if(bitmapLCD == null || bitmapLCD.getWidth() != newLCDWidth || bitmapLCD.getHeight() != newLCDHeight) { - int newWidth = Math.max(1, newLCDWidth); - int newHeight = Math.max(1, newLCDHeight); - - if(debug) Log.d(TAG, "updateCallback() Bitmap.createBitmap(x: " + newWidth + ", y: " + newHeight + ")"); - Bitmap oldBitmapLCD = bitmapLCD; - bitmapLCD = Bitmap.createBitmap(newWidth, newHeight, Bitmap.Config.ARGB_8888); - bitmapRatio = (float)newHeight / (float)newWidth; - if(oldBitmapLCD != null) - oldBitmapLCD.recycle(); - - if(viewSized) - updateLayout(); - } - break; - } - } - @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); @@ -353,7 +319,7 @@ public class LCDOverlappingView extends View { editor.putString("settings_lcd_overlapping_mode", Integer.toString(this.overlappingLCDMode)); editor.putInt("settings_lcd_overlapping_x", viewFlowLayout.leftMargin); editor.putInt("settings_lcd_overlapping_y", viewFlowLayout.topMargin); - editor.putFloat("settings_lcd_overlapping_scale", bitmapLCD != null && bitmapLCD.getWidth() > 0 ? (float)viewFlowLayout.width / (float)bitmapLCD.getWidth() : 1.0f); + editor.putFloat("settings_lcd_overlapping_scale", (float)viewFlowLayout.width / (float)Math.max(1, NativeLib.getScreenWidth())); editor.apply(); } diff --git a/app/src/main/java/org/emulator/calculator/MainScreenView.java b/app/src/main/java/org/emulator/calculator/MainScreenView.java index ed0ab53..9db5d9c 100644 --- a/app/src/main/java/org/emulator/calculator/MainScreenView.java +++ b/app/src/main/java/org/emulator/calculator/MainScreenView.java @@ -22,6 +22,7 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.graphics.Rect; import android.util.DisplayMetrics; import android.util.Log; import android.util.SparseIntArray; @@ -38,8 +39,10 @@ public class MainScreenView extends PanAndScaleView { protected static final String TAG = "MainScreenView"; protected final boolean debug = false; - private Paint paint = new Paint(); + private Paint paintFullCalc = new Paint(); + private Paint paintLCD = new Paint(); private Bitmap bitmapMainScreen; + private Rect srcBitmapCopy = new Rect(); private SparseIntArray vkmap; private HashMap charmap; private int kmlBackgroundColor = Color.BLACK; @@ -49,7 +52,8 @@ public class MainScreenView extends PanAndScaleView { private boolean viewSized = false; private int rotationMode = 0; private boolean autoRotation = false; - private boolean autoZoom = false; + private boolean autoZoom = false; + private boolean usePixelBorders = false; public float defaultViewScaleFactorX = 1.0f; public float defaultViewScaleFactorY = 1.0f; @@ -63,8 +67,12 @@ public class MainScreenView extends PanAndScaleView { setShowScaleThumbnail(true); setAllowDoubleTapZoom(false); - paint.setFilterBitmap(true); - paint.setAntiAlias(true); + paintFullCalc.setFilterBitmap(true); + paintFullCalc.setAntiAlias(true); + + paintLCD.setStyle(Paint.Style.STROKE); + paintLCD.setStrokeWidth(1.0f); + paintLCD.setAntiAlias(false); DisplayMetrics displayMetrics = new DisplayMetrics(); ((Activity)context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); @@ -248,6 +256,7 @@ public class MainScreenView extends PanAndScaleView { updateLayout(); } + @SuppressLint("SourceLockedOrientationActivity") protected void updateLayout() { if(bitmapMainScreen != null && virtualSizeHeight > 1) { if (virtualSizeWidth > 0.0f && viewSizeWidth > 0.0f) { @@ -335,13 +344,55 @@ public class MainScreenView extends PanAndScaleView { this.onUpdateLayoutListener = onUpdateLayoutListener; } + @Override + protected void onCustomDraw(Canvas canvas) { + //Log.d(TAG, "onCustomDraw()"); + + canvas.drawColor(getBackgroundColor()); + + // Copy the full calculator with antialiasing + canvas.drawBitmap(bitmapMainScreen, 0, 0, paintFullCalc); + + if(usePixelBorders) { + // Copy the LCD part only without antialiasing + int x = NativeLib.getScreenPositionX(); + int y = NativeLib.getScreenPositionY(); + srcBitmapCopy.set(x, y, x + NativeLib.getScreenWidth(), y + NativeLib.getScreenHeight()); + canvas.drawBitmap(bitmapMainScreen, srcBitmapCopy, srcBitmapCopy, paintLCD); + } + } @Override - protected void onCustomDraw(Canvas canvas) { - //Log.d(TAG, "onCustomDraw()"); + public void onDraw(Canvas canvas) { + super.onDraw(canvas); - canvas.drawColor(getBackgroundColor()); - canvas.drawBitmap(bitmapMainScreen, 0, 0, paint); + if(usePixelBorders) { + int lcdPositionX = NativeLib.getScreenPositionX(); + int lcdPositionY = NativeLib.getScreenPositionY(); + int lcdWidth = NativeLib.getScreenWidth(); + int lcdHeight = NativeLib.getScreenHeight(); + int lcdWidthNative = NativeLib.getScreenWidthNative(); + int lcdHeightNative = NativeLib.getScreenHeightNative(); + + float screenPositionX = lcdPositionX * viewScaleFactorX + viewPanOffsetX; + float screenPositionY = lcdPositionY * viewScaleFactorY + viewPanOffsetY; + float screenWidth = lcdWidth * viewScaleFactorX; + float screenHeight = lcdHeight * viewScaleFactorY; + + // Draw the LCD grid lines without antialiasing to emulate the genuine pixels borders + int lcdBackgroundColor = 0xFF000000 | NativeLib.getLCDBackgroundColor(); + paintLCD.setColor(lcdBackgroundColor); + float stepX = screenWidth / lcdWidthNative; + for(int x = 0; x < lcdWidthNative; x++) { + float screenX = screenPositionX + x * stepX; + canvas.drawLine(screenX, screenPositionY, screenX, screenPositionY + screenHeight, paintLCD); + } + float stepY = screenHeight / lcdHeightNative; + for(int y = 0; y < lcdHeightNative; y++) { + float screenY = screenPositionY + y * stepY; + canvas.drawLine(screenPositionX, screenY, screenPositionX + screenWidth, screenY, paintLCD); + } + } } public void updateCallback(int type, int param1, int param2, String param3, String param4) { @@ -406,6 +457,11 @@ public class MainScreenView extends PanAndScaleView { this.statusBarColor = statusBarColor; } + public void setUsePixelBorders(boolean usePixelBorders) { + this.usePixelBorders = usePixelBorders; + postInvalidate(); + } + private int getBackgroundColor() { diff --git a/app/src/main/java/org/emulator/calculator/NativeLib.java b/app/src/main/java/org/emulator/calculator/NativeLib.java index 5ad5563..af7326a 100644 --- a/app/src/main/java/org/emulator/calculator/NativeLib.java +++ b/app/src/main/java/org/emulator/calculator/NativeLib.java @@ -58,7 +58,7 @@ public class NativeLib { public static native String[] getObjectsToSave(); public static native int onObjectSave(String filename, boolean[] objectsToSaveItemChecked); - public static native void onViewCopy(Bitmap bitmapScreen); + public static native void onViewCopy(Bitmap bitmapScreen); public static native void onStackCopy(); public static native void onStackPaste(); public static native void onViewReset(); @@ -78,4 +78,7 @@ public class NativeLib { public static native int getScreenPositionY(); public static native int getScreenWidth(); public static native int getScreenHeight(); + public static native int getScreenWidthNative(); + public static native int getScreenHeightNative(); + public static native int getLCDBackgroundColor(); } diff --git a/app/src/main/java/org/emulator/calculator/PrinterSimulatorFragment.java b/app/src/main/java/org/emulator/calculator/PrinterSimulatorFragment.java index 65ba16a..e1a3b2a 100644 --- a/app/src/main/java/org/emulator/calculator/PrinterSimulatorFragment.java +++ b/app/src/main/java/org/emulator/calculator/PrinterSimulatorFragment.java @@ -63,7 +63,7 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setStyle(AppCompatDialogFragment.STYLE_NO_FRAME, android.R.style.Theme_Material); + setStyle(AppCompatDialogFragment.STYLE_NO_FRAME, Utils.resId(this, "style", "AppTheme")); } @NonNull @@ -241,6 +241,8 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment { private void commonInitialization() { setShowScaleThumbnail(true); scaleThumbnailColor = Color.GRAY; + + paintBitmap.setAntiAlias(false); } public void setBitmap(Bitmap bitmap) { diff --git a/app/src/main/java/org/emulator/forty/eight/MainActivity.java b/app/src/main/java/org/emulator/forty/eight/MainActivity.java index cb271c5..cff20f5 100644 --- a/app/src/main/java/org/emulator/forty/eight/MainActivity.java +++ b/app/src/main/java/org/emulator/forty/eight/MainActivity.java @@ -69,7 +69,6 @@ import org.emulator.calculator.Utils; import java.io.BufferedReader; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -702,9 +701,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On filename = emuXX + "-state.e38"; break; case 'E': // HP39G/(HP39G+/HP39GS)/HP40G/HP40GS - filename = emuXX + "-state.e39"; - break; - case 'P': // HP39G+/HP39GS + case 'P': // HP39G+/HP39GS filename = emuXX + "-state.e39"; break; case '2': // HP48GII @@ -1122,8 +1119,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On fileOutputStream.flush(); fileOutputStream.close(); } - } catch (FileNotFoundException e) { - e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } @@ -1259,7 +1254,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On public int updateCallback(int type, int param1, int param2, String param3, String param4) { mainScreenView.updateCallback(type, param1, param2, param3, param4); - lcdOverlappingView.updateCallback(type, param1, param2, param3, param4); return -1; } @@ -1531,7 +1525,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On int isDynamicValue = isDynamic ? 1 : 0; if(key == null) { String[] settingKeys = { - "settings_realspeed", "settings_grayscale", "settings_rotation", "settings_auto_layout", "settings_allow_pinch_zoom", "settings_lcd_overlapping_mode", + "settings_realspeed", "settings_grayscale", "settings_rotation", "settings_auto_layout", "settings_allow_pinch_zoom", "settings_lcd_overlapping_mode", "settings_lcd_pixel_borders", "settings_hide_bar", "settings_hide_button_menu", "settings_sound_volume", "settings_haptic_feedback", "settings_background_kml_color", "settings_background_fallback_color", "settings_printer_model", "settings_printer_prevent_line_wrap", "settings_macro", @@ -1578,6 +1572,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On } lcdOverlappingView.setOverlappingLCDMode(overlappingLCDMode); break; + case "settings_lcd_pixel_borders": + mainScreenView.setUsePixelBorders(sharedPreferences.getBoolean("settings_lcd_pixel_borders", false)); + break; case "settings_hide_bar": case "settings_hide_bar_status": case "settings_hide_bar_nav": diff --git a/app/src/main/res/layout/app_bar_main.xml b/app/src/main/res/layout/app_bar_main.xml index badf7c5..8898e60 100644 --- a/app/src/main/res/layout/app_bar_main.xml +++ b/app/src/main/res/layout/app_bar_main.xml @@ -1,23 +1,18 @@ - + android:layout_height="wrap_content"> + android:background="?attr/colorPrimary" /> diff --git a/app/src/main/res/layout/fragment_printer_simulator.xml b/app/src/main/res/layout/fragment_printer_simulator.xml index 91021e4..a422a29 100644 --- a/app/src/main/res/layout/fragment_printer_simulator.xml +++ b/app/src/main/res/layout/fragment_printer_simulator.xml @@ -10,9 +10,7 @@ android:id="@+id/my_toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?attr/colorPrimary" android:minHeight="?attr/actionBarSize" - android:theme="?attr/actionBarTheme" app:navigationIcon="?android:attr/homeAsUpIndicator" /> - + + + #AAAAAA + #32312B + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index baec973..5a2913a 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,9 +1,7 @@ - - - #444341 #32312B + #5A5A5A #8DB4D3 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 68f64a5..4d27a0a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -128,6 +128,9 @@ Auto (Double touch) Manual (Zoom or pan) + Show the LCD pixel borders + Experimental feature which show a more realistic pixel. Note: Due to the difference in screen resolution between Android and the calculator, the pixels are not necessarily uniform in size. + Hide the status bar Hide the navigation bar Hide the button menu diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index da35ddd..bcc8e95 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,26 +1,33 @@ - - + + + + - - -