mirror of
https://github.com/dgis/emu48android
synced 2025-01-13 08:01:25 +01:00
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.
This commit is contained in:
parent
74a9994d53
commit
4c618f358f
13 changed files with 186 additions and 137 deletions
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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":
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/main_screen_container"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/main_screen_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#00808080"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:showIn="@layout/activity_main">
|
||||
|
||||
|
@ -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" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -46,4 +46,15 @@
|
|||
<item>4mb (32 ports: 2 through 33)</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="settings_printer_model_item">
|
||||
<item>HP82240A</item>
|
||||
<item>HP82240B (default)</item>
|
||||
<!--<item>Generic Serial</item>-->
|
||||
</string-array>
|
||||
<string-array name="settings_printer_model_value">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<!--<item>2</item>-->
|
||||
</string-array>
|
||||
|
||||
</resources>
|
|
@ -1,24 +1,25 @@
|
|||
<resources>
|
||||
|
||||
<!-- Info Activity -->
|
||||
<!-- InfoActivity -->
|
||||
|
||||
<string name="title_activity_info">About</string>
|
||||
<string name="info_readme">ReadMe.txt</string>
|
||||
|
||||
<!-- Info Activity -->
|
||||
<!-- InfoWebActivity -->
|
||||
<string name="title_web_activity_info">Help</string>
|
||||
<string name="help_url">file:///android_asset/Emu48.htm</string>
|
||||
|
||||
<!-- Settings Activity -->
|
||||
<!-- SettingsActivity -->
|
||||
|
||||
<string name="title_activity_settings">Settings</string>
|
||||
|
||||
<!-- PaintByNumber Activity -->
|
||||
<!-- MainActivity -->
|
||||
|
||||
<string name="app_name">Emu48</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="navigation_drawer_open">Open navigation drawer</string>
|
||||
<string name="navigation_drawer_close">Close navigation drawer</string>
|
||||
<string name="button_main_menu_content_description">Open the main menu</string>
|
||||
<string name="nav_new">New...</string>
|
||||
<string name="nav_open">Open...</string>
|
||||
<string name="nav_save">Save</string>
|
||||
|
@ -76,6 +77,9 @@
|
|||
<string name="message_printer">Printer Simulator</string>
|
||||
<string name="message_printer_share_text">Save printer paper as text</string>
|
||||
<string name="message_printer_share_graphic">Save printer paper as image</string>
|
||||
<string name="message_printer_out_of_paper">Out of paper error for the graphic printer (max line: %s, max pixel line: %s).</string>
|
||||
|
||||
|
||||
|
||||
<string name="settings_category_general_title">General</string>
|
||||
<string name="settings_realspeed_title">Authentic Calculator Speed</string>
|
||||
|
@ -112,4 +116,8 @@
|
|||
<string name="settings_port2wr_title">Port 2 is Writable</string>
|
||||
<string name="settings_port2load_title">Port 2 File</string>
|
||||
|
||||
<string name="settings_category_printer_title">Printer Simulator</string>
|
||||
<string name="settings_printer_model_title">Printer Model</string>
|
||||
<string name="settings_printer_model_summary">You can choose the printer model</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -96,10 +96,18 @@
|
|||
<!--/>-->
|
||||
</PreferenceCategory>
|
||||
|
||||
<!--<PreferenceCategory app:title="Style">
|
||||
"Show Title",IDC_SHOWTITLE
|
||||
"Show Menu",IDC_SHOWMENU
|
||||
</PreferenceCategory>-->
|
||||
<PreferenceCategory android:title="@string/settings_category_printer_title">
|
||||
<ListPreference
|
||||
android:key="settings_printer_model"
|
||||
android:title="@string/settings_printer_model_title"
|
||||
android:dialogTitle="@string/settings_printer_model_title"
|
||||
android:summary="@string/settings_printer_model_summary"
|
||||
android:entries="@array/settings_printer_model_item"
|
||||
android:entryValues="@array/settings_printer_model_value"
|
||||
android:defaultValue="1"
|
||||
/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<!--<PreferenceCategory app:title="Disassembler">
|
||||
"HP Mnemonics",IDC_DISASM_HP
|
||||
"Class Mnemonics",IDC_DISASM_CLASS
|
||||
|
|
Loading…
Reference in a new issue