From 4c618f358fba9289360efd0d530d0ff562a28675 Mon Sep 17 00:00:00 2001 From: dgis Date: Tue, 25 Jun 2019 23:55:58 +0200 Subject: [PATCH] Improve menu button and printer - Fix the menu button which was not visible when white on white. - Fix the Graphical Printer Simulator which was not working with API19 or 21. - Add the printer model choice in the settings. --- ReadMe.txt | 3 +- app/CMakeLists.txt | 2 +- app/src/main/cpp/win32-layer.c | 5 +- .../org/emulator/calculator/InfoActivity.java | 10 +- .../emulator/calculator/MainScreenView.java | 22 ++-- .../emulator/calculator/PanAndScaleView.java | 33 ++++-- .../emulator/calculator/PrinterSimulator.java | 40 +++++-- .../calculator/PrinterSimulatorFragment.java | 108 +++++------------- .../emulator/forty/eight/MainActivity.java | 51 +++++++-- app/src/main/res/layout/content_main.xml | 6 +- app/src/main/res/values/arrays.xml | 11 ++ app/src/main/res/values/strings.xml | 16 ++- app/src/main/res/xml/pref_general.xml | 16 ++- 13 files changed, 186 insertions(+), 137 deletions(-) diff --git a/ReadMe.txt b/ReadMe.txt index 2fc031c..1ca8635 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -63,6 +63,8 @@ Version 1.5 (2019-06-xx) - Refactor the code for easier code sharing between Emu48, Emu42 and Emu71. - Fix: Bad text characters when copy/paste the stack. - Fix: Selecting an empty KML folder prevent to select the default embedded KML folder (Github Fix: #5)! +- Fix a crash with waveOutClose(). +- Fix an issue with the Pan and zoom which was possible after closing the calc. Version 1.4 (2019-06-08) @@ -145,7 +147,6 @@ The Eric's Real scripts ("real*.kml" and "real*.bmp") are embedded in this appli TODO -- Pan and zoom seems possible after closing the calc. - In Chrome OS: - The timezone seems to be GMT (localtime_r not right?)! - sometimes there is no OK button in the KML Script Compilation Result. diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index f5e9f39..c2cca8c 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -12,7 +12,7 @@ cmake_minimum_required(VERSION 3.4.1) #add_compile_options(-DDEBUG_IO) #add_compile_options(-DDEBUG_SERIAL) -#add_compile_options(-DDEBUG_ANDROID_WAVE_OUT) +add_compile_options(-DDEBUG_ANDROID_WAVE_OUT) #add_compile_options(-DDEBUG_ANDROID_TIMER) #add_compile_options(-DDEBUG_ANDROID_PAINT) #add_compile_options(-DDEBUG_ANDROID_THREAD) diff --git a/app/src/main/cpp/win32-layer.c b/app/src/main/cpp/win32-layer.c index dad3e87..6fecaca 100644 --- a/app/src/main/cpp/win32-layer.c +++ b/app/src/main/cpp/win32-layer.c @@ -1197,7 +1197,8 @@ MMRESULT waveOutClose(HWAVEOUT handle) { sem_destroy(&handle->waveOutLock); #else onPlayerDone(handle); - timer_delete(handle->playerDoneTimer); + if(handle->playerDoneTimer) + timer_delete(handle->playerDoneTimer); #endif memset(handle, 0, sizeof(struct _HWAVEOUT)); @@ -2562,7 +2563,7 @@ VOID GetLocalTime(LPSYSTEMTIME lpSystemTime) { ULONGLONG GetTickCount64(VOID) { struct timespec now; if (clock_gettime(CLOCK_MONOTONIC, &now)) - return 0; + return 0; return (ULONGLONG) ((ULONGLONG)now.tv_sec * 1000UL + (ULONGLONG)now.tv_nsec / 1000000UL); } DWORD GetTickCount(VOID) { diff --git a/app/src/main/java/org/emulator/calculator/InfoActivity.java b/app/src/main/java/org/emulator/calculator/InfoActivity.java index c7ab6ed..4224b6a 100644 --- a/app/src/main/java/org/emulator/calculator/InfoActivity.java +++ b/app/src/main/java/org/emulator/calculator/InfoActivity.java @@ -42,24 +42,24 @@ public class InfoActivity extends AppCompatActivity { // need to convert it to UTF-16. try { InputStream is = getAssets().open(filepath); - + // We guarantee that the available method returns the total // size of the asset... of course, this does mean that a single // asset can't be more than 2 gigs. int size = is.available(); - + // Read the entire asset into a local byte buffer. byte[] buffer = new byte[size]; //noinspection ResultOfMethodCallIgnored is.read(buffer); is.close(); - + // Convert the buffer into a string. String text = new String(buffer); - + // Finally stick the string into the text view. TextView textViewInfo = findViewById(Utils.resId(this, "id", "textViewInfo")); - textViewInfo.setMovementMethod(new ScrollingMovementMethod()); + textViewInfo.setMovementMethod(new ScrollingMovementMethod()); textViewInfo.setText(text); Linkify.addLinks(textViewInfo, Linkify.ALL); } catch (IOException e) { diff --git a/app/src/main/java/org/emulator/calculator/MainScreenView.java b/app/src/main/java/org/emulator/calculator/MainScreenView.java index ecba820..d9bdec5 100644 --- a/app/src/main/java/org/emulator/calculator/MainScreenView.java +++ b/app/src/main/java/org/emulator/calculator/MainScreenView.java @@ -183,9 +183,9 @@ public class MainScreenView extends PanAndScaleView { int actionIndex = event.getActionIndex(); int action = event.getActionMasked(); switch (action) { - case MotionEvent.ACTION_DOWN: - case MotionEvent.ACTION_POINTER_DOWN: - //Log.d(TAG, "ACTION_DOWN/ACTION_POINTER_DOWN count: " + touchCount + ", actionIndex: " + actionIndex); + case MotionEvent.ACTION_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); if(actionIndex == 0 && event.getPointerCount() == 1) @@ -200,10 +200,10 @@ public class MainScreenView extends PanAndScaleView { if (debug) Log.d(TAG, "onTouchEvent() ACTION_DOWN false, actionIndex: " + actionIndex + ", currentButtonTouched: " + currentButtonTouched.size() + ", preventToScroll: " + preventToScroll + ", getPointerCount: " + event.getPointerCount()); - break; - case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_POINTER_UP: - //Log.d(TAG, "ACTION_UP/ACTION_POINTER_UP count: " + touchCount + ", actionIndex: " + actionIndex); + break; + case MotionEvent.ACTION_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)); currentButtonTouched.remove(actionIndex); @@ -214,9 +214,9 @@ public class MainScreenView extends PanAndScaleView { currentButtonTouched.remove(actionIndex); preventToScroll = currentButtonTouched.size() > 0; if (debug) Log.d(TAG, "onTouchEvent() ACTION_CANCEL, actionIndex: " + actionIndex + ", currentButtonTouched: " + currentButtonTouched.size() + ", preventToScroll: " + preventToScroll); - break; - default: - break; + break; + default: + break; } return super.onTouchEvent(event); } @@ -402,7 +402,7 @@ public class MainScreenView extends PanAndScaleView { return kmlBackgroundColor; } else switch(fallbackBackgroundColorType) { case 0: - return 0; + return 0xFF000000; case 1: return statusBarColor; } diff --git a/app/src/main/java/org/emulator/calculator/PanAndScaleView.java b/app/src/main/java/org/emulator/calculator/PanAndScaleView.java index fb1b22e..2b11acf 100644 --- a/app/src/main/java/org/emulator/calculator/PanAndScaleView.java +++ b/app/src/main/java/org/emulator/calculator/PanAndScaleView.java @@ -66,6 +66,7 @@ public class PanAndScaleView extends View { protected int scaleThumbnailColor = Color.WHITE; protected boolean allowDoubleTapZoom = true; protected boolean fillBounds = false; + protected boolean enablePanAndScale = false; protected Paint paint = null; protected OnTapListener onTapDownListener; @@ -197,12 +198,27 @@ public class PanAndScaleView extends View { } /** - * @param fillBounds true to allow the virtual space to fill view bounds the ; false otherwise. + * @param fillBounds true to allow the virtual space to fill the view bounds; false otherwise. */ public void setFillBounds(boolean fillBounds) { this.fillBounds = fillBounds; } + /** + * @return true to allow to pan and scale; false otherwise. + */ + public boolean getEnablePanAndScale() { + return enablePanAndScale; + } + + /** + * @param enablePanAndScale true to allow to pan and scale; false otherwise. + */ + public void setEnablePanAndScale(boolean enablePanAndScale) { + this.enablePanAndScale = enablePanAndScale; + } + + public void setVirtualSize(float width, float height) { virtualSizeWidth = width; virtualSizeHeight = height; @@ -408,14 +424,17 @@ public class PanAndScaleView extends View { @Override public boolean onTouchEvent(MotionEvent event) { - boolean result = scaleDetector.onTouchEvent(event); - result = gestureDetector.onTouchEvent(event) || result; - return result || super.onTouchEvent(event); + if(enablePanAndScale) { + boolean result = scaleDetector.onTouchEvent(event); + result = gestureDetector.onTouchEvent(event) || result; + return result || super.onTouchEvent(event); + } else + return super.onTouchEvent(event); } @Override public boolean onGenericMotionEvent(MotionEvent event) { - if (!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)) { switch (event.getAction()) { case MotionEvent.ACTION_SCROLL: @@ -433,7 +452,7 @@ public class PanAndScaleView extends View { @Override public boolean onKeyUp(int keyCode, KeyEvent event) { - if(!fillBounds) { + if(enablePanAndScale && !fillBounds) { char character = (char) event.getUnicodeChar(); if (character == '+') { scaleByStep(scaleStep, getWidth() / 2.0f, getHeight() / 2.0f); @@ -633,7 +652,7 @@ public class PanAndScaleView extends View { if(firstTime) { firstTime = false; } else - startOSDTimer(); + startOSDTimer(); } if(!fillBounds && osdAllowed && showScaleThumbnail diff --git a/app/src/main/java/org/emulator/calculator/PrinterSimulator.java b/app/src/main/java/org/emulator/calculator/PrinterSimulator.java index a574e5a..b8e7e37 100644 --- a/app/src/main/java/org/emulator/calculator/PrinterSimulator.java +++ b/app/src/main/java/org/emulator/calculator/PrinterSimulator.java @@ -56,19 +56,10 @@ public class PrinterSimulator { maxBitmapHeight = Math.min(maxBitmapHeight, 8192); //32768); MAXPRTLINES = maxBitmapHeight / LINE_HEIGHT; - mBitmap = Bitmap.createBitmap(LINE_WIDTH, MAXPRTLINES*LINE_HEIGHT, Bitmap.Config.ALPHA_8); //ARGB_8888); //ALPHA_8); + mBitmap = Bitmap.createBitmap(LINE_WIDTH, MAXPRTLINES*LINE_HEIGHT, Bitmap.Config.ARGB_8888); //ARGB_8888); //ALPHA_8); mBitmap.eraseColor(0xFFFFFFFF); reset(); // reset printer state machine - -// for (int i = 32; i < 256; i++) { -// if(i % 16 == 0) { -// addTextData(10); -// addGraphData(10, false); -// } -// addTextData(i); -// addGraphData(i, false); -// } } /** @@ -103,13 +94,33 @@ public class PrinterSimulator { private OnPrinterUpdateListener onPrinterUpdateListener; /** - * Register a callback to be invoked when this view is tapped down. + * Register a callback to be invoked when the printer just has print something. * @param onPrinterUpdateListener The callback that will run */ public void setOnPrinterUpdateListener(OnPrinterUpdateListener onPrinterUpdateListener) { this.onPrinterUpdateListener = onPrinterUpdateListener; } + /** + * Interface definition for a callback to be invoked when the printer is out of paper. + */ + public interface OnPrinterOutOfPaperListener { + /** + * Called when the printer just has print something. + */ + void onPrinterOutOfPaper(int currentLine, int maxLine, int currentPixelRow, int maxPixelRow); + } + + private OnPrinterOutOfPaperListener onPrinterOutOfPaperListener; + + /** + * Register a callback to be invoked when the printer is out of paper. + * @param onPrinterOutOfPaperListener The callback that will run + */ + public void setOnPrinterOutOfPaperListener(OnPrinterOutOfPaperListener onPrinterOutOfPaperListener) { + this.onPrinterOutOfPaperListener = onPrinterOutOfPaperListener; + } + /** * Reset the printer state machine. */ @@ -122,6 +133,8 @@ public class PrinterSimulator { m_bEsc = false; // not ESC sequence m_byGraphLength = 0; // no remaining graphic bytes + + outOfPaper = false; } /** @@ -347,6 +360,8 @@ public class PrinterSimulator { private int MAXPRTLINES = 500; //32768; // maximum printable lines (out of paper) private final int LINE_WIDTH = 166; private final int LINE_HEIGHT = 8; + private boolean outOfPaper = false; + private int m_nCurCol; // current column in bitmap private int m_nCurRow; // current row in bitmap @@ -399,6 +414,9 @@ public class PrinterSimulator { private void addGraphData(int byData, boolean bGraphicData) { if (m_nCurRow >= MAXPRTLINES*LINE_HEIGHT) // reached bitmap size { + if(!outOfPaper && this.onPrinterOutOfPaperListener != null) + this.onPrinterOutOfPaperListener.onPrinterOutOfPaper(m_nCurRow / LINE_HEIGHT, MAXPRTLINES, m_nCurRow, MAXPRTLINES*LINE_HEIGHT); + outOfPaper = true; return; // paper empty } diff --git a/app/src/main/java/org/emulator/calculator/PrinterSimulatorFragment.java b/app/src/main/java/org/emulator/calculator/PrinterSimulatorFragment.java index 9eaf3b2..791c5d9 100644 --- a/app/src/main/java/org/emulator/calculator/PrinterSimulatorFragment.java +++ b/app/src/main/java/org/emulator/calculator/PrinterSimulatorFragment.java @@ -58,12 +58,12 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment { private TextView textViewPrinterText; 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 - }); +// 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() { @@ -133,22 +133,17 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment { if(item.getItemId() == Utils.resId(PrinterSimulatorFragment.this, "id", "menu_printer_simulator_share_text")) { Intent intent = new Intent(android.content.Intent.ACTION_SEND); intent.setType("text/plain"); - //intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(Intent.EXTRA_SUBJECT, Utils.resId(PrinterSimulatorFragment.this, "string", "message_printer_share_text")); intent.putExtra(Intent.EXTRA_TEXT, printerSimulator.getText()); -// 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_text")))); - //dismiss(); } else if(item.getItemId() == Utils.resId(PrinterSimulatorFragment.this, "id", "menu_printer_simulator_share_graphic")) { String imageFilename = "HPPrinter-" + new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.US).format(new Date()); try { Bitmap paperBitmap = printerSimulator.getImage(); Bitmap croppedPaperBitmap = Bitmap.createBitmap(paperBitmap.getWidth(), printerSimulator.getPaperHeight(), Bitmap.Config.ARGB_8888); - //convertedBitmap.eraseColor(0xFFFFFFFF); Canvas canvas = new Canvas(croppedPaperBitmap); Paint paint = new Paint(); - paint.setColorFilter(colorFilterAlpha8ToRGB); + //paint.setColorFilter(colorFilterAlpha8ToRGB); canvas.drawBitmap(paperBitmap, 0, 0, paint); File storagePath = new File(getActivity().getExternalCacheDir(), ""); @@ -164,7 +159,6 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment { 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")))); - //dismiss(); } catch (Exception e) { e.printStackTrace(); Utils.showAlert(getActivity(), e.getMessage()); @@ -172,21 +166,15 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment { } else if(item.getItemId() == Utils.resId(PrinterSimulatorFragment.this, "id", "menu_printer_simulator_change_paper")) { printerSimulator.changePaper(); printerGraphView.updatePaperLayout(); - updatePaper(null); + textViewPrinterText.setText(""); + if(printerGraphView != null) { + printerGraphView.updatePaperLayout(); + printerGraphView.invalidate(); + } } return true; } }); -// Context context = getContext(); -// if(context != null) { -// Resources.Theme theme = context.getTheme(); -// if (theme != null) { -// TypedValue tv = new TypedValue(); -// theme.resolveAttribute(androidx.appcompat.R.attr.actionBarSize, tv, true); -// int actionBarHeight = getResources().getDimensionPixelSize(tv.resourceId); -// toolbar.setMinimumHeight(actionBarHeight); -// } -// } setMenuVisibility(true); // ViewPager with Text and Graph @@ -200,7 +188,7 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment { case 0: { ViewGroup layoutPagePrinterText = container.findViewById(Utils.resId(PrinterSimulatorFragment.this, "id", "page_printer_text")); textViewPrinterText = container.findViewById(Utils.resId(PrinterSimulatorFragment.this, "id", "printer_text")); - updatePaper(null); + updatePaper(printerSimulator.getText()); return layoutPagePrinterText; } case 1: { @@ -242,42 +230,10 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment { return view; } - private void appendTextToPrinter(String fullText, String text) { - if(textViewPrinterText != null) { - if(fullText != null) - textViewPrinterText.setText(fullText); - if (text != null && text.length() > 0) { -// boolean isAtMaxScrollPosition; -// int currentScrollPosition = textViewPrinterText.getScrollY(); // SP -// int viewHeight = textViewPrinterText.getHeight(); // VH -// if(debug) Log.d(TAG, "appendTextToPrinter() getScrollY: " + currentScrollPosition + ", getHeight: " + viewHeight + ", text: " + text); -// Layout layout = textViewPrinterText.getLayout(); -// if(layout != null) { -// int virtualHeight1 = layout.getLineTop(textViewPrinterText.getLineCount()); // IH -// int maxScrollPosition1 = virtualHeight1 - viewHeight; -// isAtMaxScrollPosition = (maxScrollPosition1 < 0 || currentScrollPosition == maxScrollPosition1); -// textViewPrinterText.append(text); -// if(isAtMaxScrollPosition) { -// int virtualHeight2 = layout.getLineTop(textViewPrinterText.getLineCount()); -// int maxScrollPosition2 = virtualHeight2 - viewHeight; -// if (maxScrollPosition2 > 0) { -// if(debug) Log.d(TAG, "appendTextToPrinter() NEED to scroll to: " + maxScrollPosition2); -// textViewPrinterText.scrollTo(0, maxScrollPosition2); -// } -// } else { -// if(debug) Log.d(TAG, "appendTextToPrinter() NEED to scroll BACK to old position: " + currentScrollPosition); -// textViewPrinterText.scrollTo(0, currentScrollPosition); -// } -// } else - textViewPrinterText.append(text); - } - } - } - private void updatePaper(String textAppended) { if(debug) Log.d(TAG, "updatePaper(" + textAppended + ")"); if(textViewPrinterText != null) { - appendTextToPrinter(textAppended == null ? printerSimulator.getText() : null, textAppended); + textViewPrinterText.append(textAppended); } if(printerGraphView != null) { printerGraphView.updatePaperLayout(); @@ -320,10 +276,8 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment { } private void commonInitialization() { - //setLayerType(View.LAYER_TYPE_SOFTWARE, null); setShowScaleThumbnail(true); scaleThumbnailColor = Color.RED; - //setWillNotDraw(false); } public void setBitmap(Bitmap bitmap) { @@ -331,24 +285,18 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment { } public void updateLayoutView() { - if(bitmap != null && virtualSizeHeight > 1) { - if (bitmap.getWidth() > 0.0f && getWidth() > 0.0f) { - float translateX, translateY, scale; - scale = viewSizeWidth / virtualSizeWidth; - translateX = 0; - translateY = viewSizeHeight - scale * virtualSizeHeight; + if(bitmap != null && virtualSizeHeight > 1 && bitmap.getWidth() > 0.0f && getWidth() > 0.0f) { + float translateX, translateY, scale; + scale = viewSizeWidth / virtualSizeWidth; + translateX = 0; + translateY = viewSizeHeight - scale * virtualSizeHeight; - viewScaleFactorX = scale; - viewScaleFactorY = scale; - scaleFactorMin = scale; - scaleFactorMax = maxZoom * scaleFactorMin; - viewPanOffsetX = translateX; - viewPanOffsetY = translateY; - - //constrainPan(false); - return; - } - //resetViewport(); + viewScaleFactorX = scale; + viewScaleFactorY = scale; + scaleFactorMin = scale; + scaleFactorMax = maxZoom * scaleFactorMin; + viewPanOffsetX = translateX; + viewPanOffsetY = translateY; } } @@ -407,7 +355,9 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment { } public void updatePaperLayout() { - setVirtualSize(bitmap.getWidth(), printerSimulator.getPaperHeight()); + int paperHeight = printerSimulator.getPaperHeight(); + setEnablePanAndScale(paperHeight > 1); + setVirtualSize(bitmap.getWidth(), paperHeight); updateLayoutView(); } @@ -420,7 +370,7 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment { @Override protected void onCustomDraw(Canvas canvas) { - paintBitmap.setColorFilter(colorFilterAlpha8ToRGB); + //paintBitmap.setColorFilter(colorFilterAlpha8ToRGB); canvas.drawColor(Color.BLACK); // LTGRAY); Rect paperclip = new Rect(0, 0, bitmap.getWidth(), printerSimulator.getPaperHeight()); canvas.drawBitmap(this.bitmap, paperclip, paperclip, paintBitmap); 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 0f312c3..5a6b43c 100644 --- a/app/src/main/java/org/emulator/forty/eight/MainActivity.java +++ b/app/src/main/java/org/emulator/forty/eight/MainActivity.java @@ -38,6 +38,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageButton; import android.widget.TextView; +import android.widget.Toast; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBarDrawerToggle; @@ -122,7 +123,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On } }; - private PrinterSimulator printer = new PrinterSimulator(); + private PrinterSimulator printerSimulator = new PrinterSimulator(); private PrinterSimulatorFragment fragmentPrinterSimulator = new PrinterSimulatorFragment(); @@ -157,7 +158,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On mainScreenContainer.addView(mainScreenView, 0); imageButtonMenu = findViewById(R.id.button_menu); - imageButtonMenu.setColorFilter(Color.argb(255, 255, 255, 255)); // White Tint imageButtonMenu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -165,6 +165,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On drawer.openDrawer(GravityCompat.START); } }); + showCalculatorView(false); AssetManager assetManager = getResources().getAssets(); NativeLib.start(assetManager, mainScreenView.getBitmapMainScreen(), this, mainScreenView); @@ -185,7 +186,20 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On updateNavigationDrawerItems(); - fragmentPrinterSimulator.setPrinterSimulator(printer); + fragmentPrinterSimulator.setPrinterSimulator(printerSimulator); + printerSimulator.setOnPrinterOutOfPaperListener(new PrinterSimulator.OnPrinterOutOfPaperListener() { + @Override + public void onPrinterOutOfPaper(final int currentLine, final int maxLine, final int currentPixelRow, final int maxPixelRow) { + runOnUiThread(new Runnable() { + @Override + public void run() { + Toast.makeText(MainActivity.this, String.format(Locale.US, + getString(R.string.message_printer_out_of_paper), + maxLine, maxPixelRow), Toast.LENGTH_LONG).show(); + } + }); + } + }); //android.os.Debug.waitForDebugger(); @@ -631,6 +645,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On private void newFileFromKML(String kmlScriptFilename) { int result = NativeLib.onFileNew(kmlScriptFilename); if(result > 0) { + showCalculatorView(true); displayFilename(""); showKMLLog(); } else @@ -694,6 +709,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On @Override public void run() { NativeLib.onFileClose(); + showCalculatorView(false); saveLastDocument(""); updateNavigationDrawerItems(); displayFilename(""); @@ -707,6 +723,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On } }, true); } + private void OnSettings() { startActivityForResult(new Intent(this, SettingsActivity.class), INTENT_SETTINGS); } @@ -1108,10 +1125,22 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On getContentResolver().takePersistableUriPermission(uri, takeFlags); } + private void showCalculatorView(boolean show) { + if(show) { + mainScreenView.setEnablePanAndScale(true); + mainScreenView.setVisibility(View.VISIBLE); + imageButtonMenu.setColorFilter(Color.argb(255, 255, 255, 255)); // White Tint + } else { + mainScreenView.setEnablePanAndScale(false); + mainScreenView.setVisibility(View.GONE); + imageButtonMenu.setColorFilter(Color.argb(255, 0, 0, 0)); // Black Tint + } + } private int onFileOpen(String url) { int result = NativeLib.onFileOpen(url); if(result > 0) { + showCalculatorView(true); setPort1Settings(NativeLib.getPort1Plugged(), NativeLib.getPort1Writable()); displayFilename(url); showKMLLog(); @@ -1359,7 +1388,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On } void sendByteUdp(int byteSent) { - printer.write(byteSent); + printerSimulator.write(byteSent); } private void setPort1Settings(boolean port1Plugged, boolean port1Writable) { @@ -1375,8 +1404,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On if(key == null) { String[] settingKeys = { "settings_realspeed", "settings_grayscale", "settings_rotation", "settings_auto_layout", - "settings_hide_bar", "settings_hide_button_menu", /*"settings_allow_sound",*/ "settings_sound_volume", "settings_haptic_feedback", - "settings_background_kml_color", "settings_background_fallback_color", + "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_kml", "settings_port1", "settings_port2" }; for (String settingKey : settingKeys) { updateFromPreferences(settingKey, false); @@ -1417,10 +1446,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On imageButtonMenu.setVisibility(sharedPreferences.getBoolean("settings_hide_button_menu", false) ? View.GONE : View.VISIBLE); break; -// case "settings_allow_sound": -// NativeLib.setConfiguration("settings_sound_volume", isDynamicValue, -// sharedPreferences.getBoolean("settings_allow_sound", true) ? 64 : 0, 0, null); -// break; case "settings_sound_volume": { int volumeOption = sharedPreferences.getInt("settings_sound_volume", 64); NativeLib.setConfiguration("settings_sound_volume", isDynamicValue, volumeOption, 0, null); @@ -1439,6 +1464,12 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On mainScreenView.setBackgroundFallbackColor(Integer.parseInt(fallbackColor)); } catch (NumberFormatException ex) {} break; + case "settings_printer_model": + String printerModel = sharedPreferences.getString("settings_printer_model", "1"); + try { + printerSimulator.setPrinterModel82240A(Integer.parseInt(printerModel) == 0); + } catch (NumberFormatException ex) {} + break; case "settings_kml": case "settings_kml_default": diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml index 0c4b9d6..d1fc952 100644 --- a/app/src/main/res/layout/content_main.xml +++ b/app/src/main/res/layout/content_main.xml @@ -1,10 +1,11 @@ @@ -18,5 +19,6 @@ android:background="@android:color/transparent" android:src="@drawable/ic_more_vert_black_24dp" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toTopOf="parent" + android:contentDescription="@string/button_main_menu_content_description" /> \ No newline at end of file diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index bf77418..02bd6ab 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -46,4 +46,15 @@ 4mb (32 ports: 2 through 33) + + HP82240A + HP82240B (default) + + + + 0 + 1 + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0d6b274..feb029f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,24 +1,25 @@ - + About ReadMe.txt - + Help file:///android_asset/Emu48.htm - + Settings - + Emu48 Settings Open navigation drawer Close navigation drawer + Open the main menu New... Open... Save @@ -76,6 +77,9 @@ Printer Simulator Save printer paper as text Save printer paper as image + Out of paper error for the graphic printer (max line: %s, max pixel line: %s). + + General Authentic Calculator Speed @@ -112,4 +116,8 @@ Port 2 is Writable Port 2 File + Printer Simulator + Printer Model + You can choose the printer model + diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index 97e28dc..73d6853 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -96,10 +96,18 @@ - + + + +