diff --git a/ReadMe.txt b/ReadMe.txt
index ae35c77..15283b9 100644
--- a/ReadMe.txt
+++ b/ReadMe.txt
@@ -60,6 +60,7 @@ CHANGES
Version 1.5 (2019-06-xx)
+- Add Change Paper (clean) action in the printer simulator.
- Fix: Selecting an empty KML folder prevent to select the default embedded KML folder (Github Fix: #5)!
- Fix: Bad text characters when copy/paste the stack.
diff --git a/app/build.gradle b/app/build.gradle
index c2f45f5..ac028ee 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -27,6 +27,12 @@ if (keystorePropertiesFile.exists()) {
""")
}
+//allprojects {
+// tasks.withType(JavaCompile) {
+// options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
+// }
+//}
+
android {
compileSdkVersion 28
defaultConfig {
@@ -76,13 +82,13 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
- implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
- implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha5'
+ implementation 'androidx.appcompat:appcompat:1.1.0-beta01'
+ implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
implementation 'androidx.preference:preference:1.0.0'
- implementation 'com.google.android.material:material:1.1.0-alpha05'
+ implementation 'com.google.android.material:material:1.1.0-alpha07'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
- androidTestImplementation 'androidx.test:runner:1.2.0-alpha04'
- androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha04'
+ androidTestImplementation 'androidx.test:runner:1.3.0-alpha01'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha01'
implementation 'androidx.viewpager:viewpager:1.0.0'
}
diff --git a/app/src/main/cpp/emu-jni.c b/app/src/main/cpp/emu-jni.c
index 708e987..f1dba37 100644
--- a/app/src/main/cpp/emu-jni.c
+++ b/app/src/main/cpp/emu-jni.c
@@ -240,7 +240,7 @@ const TCHAR * clipboardPasteText() {
for (int i = 0; i <= length; ++i)
pasteText[i] = strReturn[i] & 0xFF;
pasteText[length] = 0;
- (*jniEnv)->ReleaseStringUTFChars(jniEnv, result, strReturn);
+ (*jniEnv)->ReleaseStringChars(jniEnv, result, strReturn);
return pasteText;
}
}
diff --git a/app/src/main/java/org/emulator/forty/eight/PrinterSimulator.java b/app/src/main/java/org/emulator/forty/eight/PrinterSimulator.java
index 31925e1..587d414 100644
--- a/app/src/main/java/org/emulator/forty/eight/PrinterSimulator.java
+++ b/app/src/main/java/org/emulator/forty/eight/PrinterSimulator.java
@@ -15,16 +15,10 @@
package org.emulator.forty.eight;
import android.graphics.Bitmap;
-import android.opengl.GLES10;
import android.util.Log;
import java.util.ArrayList;
-import javax.microedition.khronos.egl.EGL10;
-import javax.microedition.khronos.egl.EGLConfig;
-import javax.microedition.khronos.egl.EGLContext;
-import javax.microedition.khronos.egl.EGLDisplay;
-
/*
* Based on the free HP82240B Printer Simulator by Christoph Giesselink
*/
@@ -54,12 +48,12 @@ public class PrinterSimulator {
int maxBitmapHeight = 2048;
try {
- maxBitmapHeight = getMaximumTextureSize();
+ maxBitmapHeight = Utils.getMaximumTextureSize();
} catch(Exception ex) {
Log.d(TAG, "Cannot get the MaximumTextureSize (Set default to 2048). Error: " + ex.getMessage());
}
- maxBitmapHeight = Math.max(maxBitmapHeight, 8192); //32768);
+ 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.eraseColor(0xFFFFFFFF);
@@ -76,6 +70,25 @@ public class PrinterSimulator {
// }
}
+ /**
+ * Set the printer type.
+ * @param enable true to set the printer as a model 82240A or 82240B otherwise.
+ */
+ public void setPrinterModel82240A(boolean enable) {
+ m_bPrinter82240A = enable;
+ }
+
+ /**
+ * Change the paper, so we cleanup everything.
+ */
+ public void changePaper() {
+ reset();
+ m_Text.setLength(0);
+ mBitmap.eraseColor(0xFFFFFFFF);
+ m_nCurCol = 0;
+ m_nCurRow = 0;
+ }
+
/**
* Interface definition for a callback to be invoked when the printer just has print something.
*/
@@ -96,9 +109,9 @@ public class PrinterSimulator {
this.onPrinterUpdateListener = onPrinterUpdateListener;
}
- //
- // reset printer state machine
- //
+ /**
+ * Reset the printer state machine.
+ */
void reset() {
m_bExpChar = false; // printing normal-width characters
m_bUnderLined = false; // printing non underlined characters
@@ -110,9 +123,9 @@ public class PrinterSimulator {
m_byGraphLength = 0; // no remaining graphic bytes
}
- //
- // printer selftest
- //
+ /**
+ * Printer self test.
+ */
void selftest() {
// self test normally run in an endless loop, that's very hard to implement,
// so this implementation printing all characters only one time and then
@@ -143,6 +156,10 @@ public class PrinterSimulator {
}
}
+ /**
+ * Entry point of the data coming in the printer.
+ * @param byData
+ */
public synchronized void write(int byData) {
data.add(byData);
@@ -211,7 +228,9 @@ public class PrinterSimulator {
// Text Printer
- // ROMAN8 Unicode table
+ /**
+ * ROMAN8 Unicode table
+ */
static final int[] wcRoman8 = new int[]
{
0x00A0, 0x00F7, 0x00D7, 0x221A, 0x222B, 0x03A3, 0x25B6, 0x03C0,
@@ -232,7 +251,9 @@ public class PrinterSimulator {
0x00BD, 0x00AA, 0x00BA, 0x00AB, 0x2587, 0x00BB, 0x00B1, 0x00A0
};
- // ECMA94 Unicode table
+ /**
+ * ECMA94 Unicode table
+ */
static final int[] wcEcma94 = new int[]
{
0x2221, 0x0101, 0x2207, 0x221A, 0x222B, 0x03A3, 0x25B6, 0x03C0,
@@ -280,6 +301,10 @@ public class PrinterSimulator {
} while (false);
}
+ /**
+ * Get all the text sent to the printer.
+ * @return All the text.
+ */
public String getText() {
return m_Text.toString();
}
@@ -288,25 +313,42 @@ public class PrinterSimulator {
private final Bitmap mBitmap;
+ /**
+ * Get the full paper as an image limited by the paper height (see getPaperHeight().
+ * The size of the bitmap is limited by the hardware constraint (max texture size).
+ * @return The image containing all the paper.
+ */
public Bitmap getImage() {
return mBitmap;
}
+ /**
+ * Get the current printer head position to know the paper length.
+ * @return The current printer head position in pixel from the start of the paper in the bitmap.
+ */
public int getPaperHeight() {
return m_nCurRow + 1;
}
+ /**
+ * Get the printer title following the configuration.
+ * @return The printer title.
+ */
+ public String getTitle() {
+ return "HP-82240" + (m_bPrinter82240A ? "A" : "B") + " Printer";
+ }
+
private int MAXPRTLINES = 500; //32768; // maximum printable lines (out of paper)
private final int LINE_WIDTH = 166;
private final int LINE_HEIGHT = 8;
- int m_nCurCol; // current column in bitmap
- int m_nCurRow; // current row in bitmap
+ private int m_nCurCol; // current column in bitmap
+ private int m_nCurRow; // current row in bitmap
- boolean m_bPrinter82240A; // HP82240A ROMAN8 font only
+ private boolean m_bPrinter82240A = false; // HP82240A ROMAN8 font only
- void SetColumn(int byData)
+ private void SetColumn(int byData)
{
// set column in line
if (m_nCurCol >= LINE_WIDTH)
@@ -334,7 +376,7 @@ public class PrinterSimulator {
return;
}
- void SetSeparatorColumn()
+ private void SetSeparatorColumn()
{
int byData = m_bUnderLined ? 0x80 : 0x00;
@@ -424,7 +466,9 @@ public class PrinterSimulator {
// the printer font data
- // HP82240A ROMAN8 font table
+ /**
+ * HP82240A ROMAN8 font table.
+ */
private static final int sFontRoman8_A[][] =
{
{ 0x00, 0x00, 0x00, 0x00, 0x00 }, // 32
@@ -653,7 +697,9 @@ public class PrinterSimulator {
{ 0x00, 0x00, 0x00, 0x00, 0x00 } // 255
};
- // HP82240B ROMAN8 font table
+ /**
+ * HP82240B ROMAN8 font table.
+ */
private static final int sFontRoman8_B[][] =
{
{ 0x00, 0x00, 0x00, 0x00, 0x00 }, // 32
@@ -882,7 +928,9 @@ public class PrinterSimulator {
{ 0x00, 0x00, 0x00, 0x00, 0x00 } // 255
};
- // HP82240B ECMA94 font table
+ /**
+ * HP82240B ECMA94 font table.
+ */
private static final int sFontEcma94_B[][] =
{
{ 0x00, 0x00, 0x00, 0x00, 0x00 }, // 32
@@ -1110,50 +1158,4 @@ public class PrinterSimulator {
{ 0x00, 0xFE, 0x24, 0x24, 0x18 }, // 254
{ 0x18, 0xA1, 0xA0, 0xA1, 0x78 } // 255
};
-
-
-
- // Misc
-
- // https://community.khronos.org/t/get-maximum-texture-size/67795
- public int getMaximumTextureSize() {
- EGL10 egl = (EGL10) EGLContext.getEGL();
- EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
-
- // Initialise
- int[] version = new int[2];
- egl.eglInitialize(display, version);
-
- // Query total number of configurations
- int[] totalConfigurations = new int[1];
- egl.eglGetConfigs(display, null, 0, totalConfigurations);
-
- // Query actual list configurations
- EGLConfig[] configurationsList = new EGLConfig[totalConfigurations[0]];
- egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations);
-
- int[] textureSize = new int[1];
- int maximumTextureSize = 0;
-
- // Iterate through all the configurations to located the maximum texture size
- for (int i = 0; i < totalConfigurations[0]; i++)
- {
- // Only need to check for width since opengl textures are always squared
- egl.eglGetConfigAttrib(display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize);
-
- // Keep track of the maximum texture size
- if (maximumTextureSize < textureSize[0])
- {
- maximumTextureSize = textureSize[0];
- }
-
- Log.i("GLHelper", Integer.toString(textureSize[0]));
- }
-
- // Release
- egl.eglTerminate(display);
- Log.i("GLHelper", "Maximum GL texture size: " + Integer.toString(maximumTextureSize));
-
- return maximumTextureSize;
- }
}
diff --git a/app/src/main/java/org/emulator/forty/eight/PrinterSimulatorFragment.java b/app/src/main/java/org/emulator/forty/eight/PrinterSimulatorFragment.java
index ff60389..dc4eee8 100644
--- a/app/src/main/java/org/emulator/forty/eight/PrinterSimulatorFragment.java
+++ b/app/src/main/java/org/emulator/forty/eight/PrinterSimulatorFragment.java
@@ -24,6 +24,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatDialogFragment;
import androidx.appcompat.widget.Toolbar;
+import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
@@ -60,6 +61,7 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment {
//setStyle(STYLE_NO_FRAME, android.R.style.Theme_Holo_Light);
//setStyle(STYLE_NO_FRAME, 0);
+ //setStyle(STYLE_NO_TITLE, android.R.style.Theme_Material_Light_Dialog_Alert); //Theme_Holo_Light);
setStyle(STYLE_NO_TITLE, android.R.style.Theme_Holo_Light);
//setStyle(STYLE_NO_TITLE, 0);
}
@@ -85,6 +87,8 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
String title = getString(R.string.dialog_printer_simulator_title);
+ if(printerSimulator != null)
+ title = printerSimulator.getTitle();
getDialog().setTitle(title);
@@ -95,6 +99,7 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment {
toolbar = view.findViewById(R.id.my_toolbar);
toolbar.setTitle(title);
+ toolbar.setOverflowIcon(ContextCompat.getDrawable(getActivity(), R.drawable.ic_more_vert_white_24dp));
//toolbar.setLogo(R.drawable.ic_launcher);
toolbar.setNavigationIcon(R.drawable.ic_keyboard_backspace_white_24dp);
toolbar.setNavigationOnClickListener(
@@ -146,7 +151,10 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment {
e.printStackTrace();
((MainActivity)getActivity()).showAlert(e.getMessage());
}
-
+ } else if(item.getItemId() == R.id.menu_printer_simulator_change_paper) {
+ printerSimulator.changePaper();
+ printerGraphView.updatePaper();
+ updatePaper();
}
return true;
}
@@ -175,91 +183,6 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment {
case 0: {
ViewGroup layoutPagePrinterText = container.findViewById(R.id.page_printer_text);
textViewPrinterText = container.findViewById(R.id.printer_text);
-// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
-// textViewPrinterText.setOnScrollChangeListener(new View.OnScrollChangeListener() {
-// @Override
-// public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
-// int virtualHeight = -1;
-// final Layout layout = textViewPrinterText.getLayout();
-// if(layout != null) {
-// virtualHeight = layout.getLineTop(textViewPrinterText.getLineCount());
-// }
-//
-// Log.d(TAG, "onScrollChange() getScrollY: " + textViewPrinterText.getScrollY() + ", getHeight: " + textViewPrinterText.getHeight() + ", virtualHeight: " + virtualHeight);
-//
-// }
-// });
-// }
-
-// if(textViewPrinterText != null) {
-// textViewPrinterText.setTextIsSelectable(true);
-// final Context context = getActivity();
-//
-//// final ColorStateList colors = textViewPrinterText.getTextColors();
-//// textViewPrinterText.setTextColor(colors.withAlpha(255));
-//
-// textViewPrinterText.setHorizontallyScrolling(true);
-//
-// // http://stackoverflow.com/a/34316896
-// final Scroller scroller = new Scroller(context);
-// textViewPrinterText.setMovementMethod(new ScrollingMovementMethod());
-// textViewPrinterText.setScroller(scroller);
-// //final Layout textViewResultLayout = textViewPrinterText.getLayout();
-// textViewPrinterText.setOnTouchListener(new View.OnTouchListener() {
-//
-// // Could make this a field member on your activity
-// GestureDetector gesture = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
-// @Override
-// public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
-//
-// Layout textViewResultLayout = textViewPrinterText.getLayout();
-// if(textViewResultLayout != null) {
-// int scrollWidth = (int) textViewResultLayout.getLineWidth(0);
-// int maxX = scrollWidth - textViewPrinterText.getWidth();
-// int scrollHeight = textViewResultLayout.getHeight();
-// //int scrollHeight = textViewPrinterText.getLineCount() * textViewPrinterText.getLineHeight();
-// int maxY = scrollHeight - textViewPrinterText.getHeight();
-// scroller.fling(
-// textViewPrinterText.getScrollX(), textViewPrinterText.getScrollY(), // int startX, int startY
-// (int) -velocityX, (int) -velocityY, // int velocityX, int velocityY,
-// 0, maxX, // int minX, int maxX
-// 0, maxY // int minY, int maxY
-// );
-// }
-//
-// return super.onFling(e1, e2, velocityX, velocityY);
-// }
-//
-// });
-//
-// @Override
-// public boolean onTouch(View v, MotionEvent event) {
-// gesture.onTouchEvent(event);
-// return false;
-// }
-//
-// });
-// textViewPrinterText.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
-// @Override
-// public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
-// Layout textViewResultLayout = textViewPrinterText.getLayout();
-// if(textViewResultLayout != null) {
-// int scrollWidth = (int) textViewResultLayout.getLineWidth(0);
-// int maxX = Math.max(0, scrollWidth - textViewPrinterText.getWidth());
-// int scrollHeight = textViewResultLayout.getHeight();
-// //int scrollHeight = textViewPrinterText.getLineCount() * textViewPrinterText.getLineHeight();
-// int maxY = Math.max(0, scrollHeight - textViewPrinterText.getHeight());
-//
-// int scrollX = textViewPrinterText.getScrollX();
-// if(scrollX > maxX)
-// textViewPrinterText.setScrollX(maxX);
-// int scrollY = textViewPrinterText.getScrollY();
-// if(scrollY > maxY)
-// textViewPrinterText.setScrollY(maxY);
-// }
-// }
-// });
-// }
addToPrinterText(printerSimulator.getText());
return layoutPagePrinterText;
}
@@ -348,17 +271,20 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment {
Runnable onPrinterUpdate = new Runnable() {
@Override
public void run() {
- if(textViewPrinterText != null) {
- addToPrinterText(printerSimulator.getText());
- }
- if(printerGraphView != null) {
- printerGraphView.setVirtualSize(printerSimulator.getImage().getWidth(), printerSimulator.getPaperHeight());
- printerGraphView.updateLayoutView();
- printerGraphView.invalidate();
- }
+ updatePaper();
}
};
+ private void updatePaper() {
+ if(textViewPrinterText != null) {
+ addToPrinterText(printerSimulator.getText());
+ }
+ if(printerGraphView != null) {
+ printerGraphView.updatePaper();
+ printerGraphView.invalidate();
+ }
+ }
+
public void setPrinterSimulator(final PrinterSimulator printerSimulator) {
this.printerSimulator = printerSimulator;
this.printerSimulator.setOnPrinterUpdateListener(new PrinterSimulator.OnPrinterUpdateListener() {
@@ -421,6 +347,11 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment {
}
}
+ public void updatePaper() {
+ setVirtualSize(bitmap.getWidth(), printerSimulator.getPaperHeight());
+ updateLayoutView();
+ }
+
@Override
protected void onSizeChanged(int viewWidth, int viewHeight, int oldViewWidth, int oldViewHeight) {
//super.onSizeChanged(viewWidth, viewHeight, oldViewWidth, oldViewHeight);
@@ -428,8 +359,7 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment {
viewSizeWidth = viewWidth;
viewSizeHeight = viewHeight;
- setVirtualSize(bitmap.getWidth(), printerSimulator.getPaperHeight());
- updateLayoutView();
+ updatePaper();
}
@Override
diff --git a/app/src/main/java/org/emulator/forty/eight/Utils.java b/app/src/main/java/org/emulator/forty/eight/Utils.java
index b69aa6e..adf82ea 100644
--- a/app/src/main/java/org/emulator/forty/eight/Utils.java
+++ b/app/src/main/java/org/emulator/forty/eight/Utils.java
@@ -4,6 +4,12 @@ import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.OpenableColumns;
+import android.util.Log;
+
+import javax.microedition.khronos.egl.EGL10;
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.egl.EGLContext;
+import javax.microedition.khronos.egl.EGLDisplay;
public class Utils {
static String getFileName(Context context, String url) {
@@ -39,4 +45,46 @@ public class Utils {
return result;
}
+
+ // https://community.khronos.org/t/get-maximum-texture-size/67795
+ static int getMaximumTextureSize() {
+ EGL10 egl = (EGL10) EGLContext.getEGL();
+ EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
+
+ // Initialise
+ int[] version = new int[2];
+ egl.eglInitialize(display, version);
+
+ // Query total number of configurations
+ int[] totalConfigurations = new int[1];
+ egl.eglGetConfigs(display, null, 0, totalConfigurations);
+
+ // Query actual list configurations
+ EGLConfig[] configurationsList = new EGLConfig[totalConfigurations[0]];
+ egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations);
+
+ int[] textureSize = new int[1];
+ int maximumTextureSize = 0;
+
+ // Iterate through all the configurations to located the maximum texture size
+ for (int i = 0; i < totalConfigurations[0]; i++)
+ {
+ // Only need to check for width since opengl textures are always squared
+ egl.eglGetConfigAttrib(display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize);
+
+ // Keep track of the maximum texture size
+ if (maximumTextureSize < textureSize[0])
+ {
+ maximumTextureSize = textureSize[0];
+ }
+
+ Log.i("GLHelper", Integer.toString(textureSize[0]));
+ }
+
+ // Release
+ egl.eglTerminate(display);
+ Log.i("GLHelper", "Maximum GL texture size: " + Integer.toString(maximumTextureSize));
+
+ return maximumTextureSize;
+ }
}
diff --git a/app/src/main/res/drawable/ic_menu_share_graphic.xml b/app/src/main/res/drawable/ic_menu_share_graphic.xml
deleted file mode 100644
index 3054659..0000000
--- a/app/src/main/res/drawable/ic_menu_share_graphic.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-