mirror of
https://github.com/dgis/emu48android
synced 2024-12-27 09:58:46 +01:00
Improve source code
This commit is contained in:
parent
d2c75a0699
commit
90d2cb40b9
7 changed files with 134 additions and 85 deletions
|
@ -56,7 +56,7 @@ CHANGES
|
||||||
|
|
||||||
Version 1.5 (2019-06-xx)
|
Version 1.5 (2019-06-xx)
|
||||||
|
|
||||||
- Add the Ir printer simulator (set delay to 0 to speed up!).
|
- Add the Ir printer simulator based on the Christoph Giesselink's HP82240B Printer Simulator for Windows.
|
||||||
- Add the macro support.
|
- Add the macro support.
|
||||||
- Refactor the code for easier code sharing between Emu48, Emu42 and Emu71.
|
- Refactor the code for easier code sharing between Emu48, Emu42 and Emu71.
|
||||||
- Fix: Bad text characters when copy/paste the stack.
|
- Fix: Bad text characters when copy/paste the stack.
|
||||||
|
|
|
@ -12,7 +12,7 @@ cmake_minimum_required(VERSION 3.4.1)
|
||||||
#add_compile_options(-DDEBUG_IO)
|
#add_compile_options(-DDEBUG_IO)
|
||||||
#add_compile_options(-DDEBUG_SERIAL)
|
#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_TIMER)
|
||||||
#add_compile_options(-DDEBUG_ANDROID_PAINT)
|
#add_compile_options(-DDEBUG_ANDROID_PAINT)
|
||||||
#add_compile_options(-DDEBUG_ANDROID_THREAD)
|
#add_compile_options(-DDEBUG_ANDROID_THREAD)
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.util.ArrayList;
|
||||||
public class PrinterSimulator {
|
public class PrinterSimulator {
|
||||||
|
|
||||||
private static final String TAG = "PrinterSimulator";
|
private static final String TAG = "PrinterSimulator";
|
||||||
|
private boolean debug = false;
|
||||||
private ArrayList<Integer> data = new ArrayList<>();
|
private ArrayList<Integer> data = new ArrayList<>();
|
||||||
private StringBuilder m_Text = new StringBuilder();
|
private StringBuilder m_Text = new StringBuilder();
|
||||||
private StringBuilder textUpdate = new StringBuilder();
|
private StringBuilder textUpdate = new StringBuilder();
|
||||||
|
@ -70,6 +71,15 @@ public class PrinterSimulator {
|
||||||
m_bPrinter82240A = enable;
|
m_bPrinter82240A = enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* true to prevent the line wrapping for the textual printer when the character '\4' is sent by the calc.
|
||||||
|
* @param preventLineWrap true to prevent the line wrapping; false otherwise.
|
||||||
|
*/
|
||||||
|
public void setPreventLineWrap(boolean preventLineWrap) {
|
||||||
|
this.preventLineWrap = preventLineWrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the paper, so we cleanup everything.
|
* Change the paper, so we cleanup everything.
|
||||||
*/
|
*/
|
||||||
|
@ -245,6 +255,8 @@ public class PrinterSimulator {
|
||||||
|
|
||||||
// Text Printer
|
// Text Printer
|
||||||
|
|
||||||
|
private boolean preventLineWrap = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ROMAN8 Unicode table
|
* ROMAN8 Unicode table
|
||||||
*/
|
*/
|
||||||
|
@ -294,9 +306,10 @@ public class PrinterSimulator {
|
||||||
private void addTextData(int byData) {
|
private void addTextData(int byData) {
|
||||||
do {
|
do {
|
||||||
// special LF and LF characters
|
// special LF and LF characters
|
||||||
if (byData == 0x04 || byData == 0x0A) {
|
if (!preventLineWrap && byData == 0x04 || byData == 0x0A) {
|
||||||
textUpdate.append('\r');
|
textUpdate.append('\r');
|
||||||
textUpdate.append('\n');
|
textUpdate.append('\n');
|
||||||
|
if(debug) Log.d(TAG, "addTextData(" + byData + ")");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -277,7 +277,7 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment {
|
||||||
|
|
||||||
private void commonInitialization() {
|
private void commonInitialization() {
|
||||||
setShowScaleThumbnail(true);
|
setShowScaleThumbnail(true);
|
||||||
scaleThumbnailColor = Color.RED;
|
scaleThumbnailColor = Color.GRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBitmap(Bitmap bitmap) {
|
public void setBitmap(Bitmap bitmap) {
|
||||||
|
|
|
@ -67,6 +67,7 @@ import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -178,7 +179,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||||
Set<String> savedMRU = sharedPreferences.getStringSet("MRU", null);
|
Set<String> savedMRU = sharedPreferences.getStringSet("MRU", null);
|
||||||
if(savedMRU != null) {
|
if(savedMRU != null) {
|
||||||
for (String url : savedMRU) {
|
for (String url : savedMRU) {
|
||||||
if(url != null & !url.isEmpty())
|
if(url != null && !url.isEmpty())
|
||||||
mruLinkedHashMap.put(url, null);
|
mruLinkedHashMap.put(url, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -335,7 +336,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||||
@Override
|
@Override
|
||||||
public boolean onNavigationItemSelected(MenuItem item) {
|
public boolean onNavigationItemSelected(MenuItem item) {
|
||||||
// Handle navigation view item clicks here.
|
// Handle navigation view item clicks here.
|
||||||
int id = item.getItemId();
|
int id = item != null ? item.getItemId() : -1;
|
||||||
if (id == R.id.nav_new) {
|
if (id == R.id.nav_new) {
|
||||||
OnFileNew();
|
OnFileNew();
|
||||||
} else if (id == R.id.nav_open) {
|
} else if (id == R.id.nav_open) {
|
||||||
|
@ -465,7 +466,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||||
if (calculatorFilename.toLowerCase().lastIndexOf(".kml") != -1) {
|
if (calculatorFilename.toLowerCase().lastIndexOf(".kml") != -1) {
|
||||||
BufferedReader reader = null;
|
BufferedReader reader = null;
|
||||||
try {
|
try {
|
||||||
reader = new BufferedReader(new InputStreamReader(assetManager.open("calculators/" + calculatorFilename), "UTF-8"));
|
reader = new BufferedReader(new InputStreamReader(assetManager.open("calculators/" + calculatorFilename), StandardCharsets.UTF_8));
|
||||||
// do reading, usually loop until end of file reading
|
// do reading, usually loop until end of file reading
|
||||||
String mLine;
|
String mLine;
|
||||||
boolean inGlobal = false;
|
boolean inGlobal = false;
|
||||||
|
@ -519,14 +520,16 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||||
List<String> calculatorsAssetFilenames = new LinkedList<>();
|
List<String> calculatorsAssetFilenames = new LinkedList<>();
|
||||||
|
|
||||||
DocumentFile kmlFolderDocumentFile = DocumentFile.fromTreeUri(this, kmlFolderUri);
|
DocumentFile kmlFolderDocumentFile = DocumentFile.fromTreeUri(this, kmlFolderUri);
|
||||||
for (DocumentFile file : kmlFolderDocumentFile.listFiles()) {
|
if(kmlFolderDocumentFile != null) {
|
||||||
final String url = file.getUri().toString();
|
for (DocumentFile file : kmlFolderDocumentFile.listFiles()) {
|
||||||
final String name = file.getName();
|
final String url = file.getUri().toString();
|
||||||
final String mime = file.getType();
|
final String name = file.getName();
|
||||||
Log.d(TAG, "url: " + url + ", name: " + name + ", mime: " + mime);
|
final String mime = file.getType();
|
||||||
if(kmlMimeType.equals(mime)) {
|
Log.d(TAG, "url: " + url + ", name: " + name + ", mime: " + mime);
|
||||||
calculatorsAssetFilenames.add(url);
|
if(kmlMimeType.equals(mime)) {
|
||||||
}
|
calculatorsAssetFilenames.add(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
kmlScripts.clear();
|
kmlScripts.clear();
|
||||||
Pattern patternGlobalTitle = Pattern.compile("\\s*Title\\s+\"(.*)\"");
|
Pattern patternGlobalTitle = Pattern.compile("\\s*Title\\s+\"(.*)\"");
|
||||||
|
@ -538,41 +541,43 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||||
try {
|
try {
|
||||||
Uri calculatorsAssetFilenameUri = Uri.parse(calculatorFilename);
|
Uri calculatorsAssetFilenameUri = Uri.parse(calculatorFilename);
|
||||||
DocumentFile documentFile = DocumentFile.fromSingleUri(this, calculatorsAssetFilenameUri);
|
DocumentFile documentFile = DocumentFile.fromSingleUri(this, calculatorsAssetFilenameUri);
|
||||||
Uri fileUri = documentFile.getUri();
|
if(documentFile != null) {
|
||||||
InputStream inputStream = getContentResolver().openInputStream(fileUri);
|
Uri fileUri = documentFile.getUri();
|
||||||
reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
|
InputStream inputStream = getContentResolver().openInputStream(fileUri);
|
||||||
// do reading, usually loop until end of file reading
|
reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
|
||||||
String mLine;
|
// do reading, usually loop until end of file reading
|
||||||
boolean inGlobal = false;
|
String mLine;
|
||||||
String title = null;
|
boolean inGlobal = false;
|
||||||
String model = null;
|
String title = null;
|
||||||
while ((mLine = reader.readLine()) != null) {
|
String model = null;
|
||||||
//process line
|
while ((mLine = reader.readLine()) != null) {
|
||||||
if (mLine.indexOf("Global") == 0) {
|
//process line
|
||||||
inGlobal = true;
|
if (mLine.indexOf("Global") == 0) {
|
||||||
title = null;
|
inGlobal = true;
|
||||||
model = null;
|
title = null;
|
||||||
continue;
|
model = null;
|
||||||
}
|
continue;
|
||||||
if (inGlobal) {
|
}
|
||||||
if (mLine.indexOf("End") == 0) {
|
if (inGlobal) {
|
||||||
KMLScriptItem newKMLScriptItem = new KMLScriptItem();
|
if (mLine.indexOf("End") == 0) {
|
||||||
newKMLScriptItem.filename = kmlFolderUseDefault ? calculatorFilename : "document:" + kmlFolderURL + "|" + calculatorFilename;
|
KMLScriptItem newKMLScriptItem = new KMLScriptItem();
|
||||||
newKMLScriptItem.title = title;
|
newKMLScriptItem.filename = kmlFolderUseDefault ? calculatorFilename : "document:" + kmlFolderURL + "|" + calculatorFilename;
|
||||||
newKMLScriptItem.model = model;
|
newKMLScriptItem.title = title;
|
||||||
kmlScripts.add(newKMLScriptItem);
|
newKMLScriptItem.model = model;
|
||||||
break;
|
kmlScripts.add(newKMLScriptItem);
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
m = patternGlobalTitle.matcher(mLine);
|
m = patternGlobalTitle.matcher(mLine);
|
||||||
if (m.find()) {
|
if (m.find()) {
|
||||||
title = m.group(1);
|
title = m.group(1);
|
||||||
}
|
}
|
||||||
m = patternGlobalModel.matcher(mLine);
|
m = patternGlobalModel.matcher(mLine);
|
||||||
if (m.find()) {
|
if (m.find()) {
|
||||||
model = m.group(1);
|
model = m.group(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
//log the exception
|
//log the exception
|
||||||
|
@ -852,7 +857,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||||
|
|
||||||
final ArrayList<KMLScriptItem> kmlScriptsForCurrentModel;
|
final ArrayList<KMLScriptItem> kmlScriptsForCurrentModel;
|
||||||
if(changeKML) {
|
if(changeKML) {
|
||||||
kmlScriptsForCurrentModel = new ArrayList<KMLScriptItem>();
|
kmlScriptsForCurrentModel = new ArrayList<>();
|
||||||
char m = (char) NativeLib.getCurrentModel();
|
char m = (char) NativeLib.getCurrentModel();
|
||||||
for (int i = 0; i < kmlScripts.size(); i++) {
|
for (int i = 0; i < kmlScripts.size(); i++) {
|
||||||
KMLScriptItem kmlScriptItem = kmlScripts.get(i);
|
KMLScriptItem kmlScriptItem = kmlScripts.get(i);
|
||||||
|
@ -1037,7 +1042,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||||
if (openResult > 0) {
|
if (openResult > 0) {
|
||||||
saveLastDocument(url);
|
saveLastDocument(url);
|
||||||
makeUriPersistable(data, uri);
|
makeUriPersistable(data, uri);
|
||||||
} else if(openResult == -2) {
|
} else if(openResult == -2 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // >= API 21
|
||||||
// For security reason, you must select the folder where are the KML and ROM files and then, reopen this file!
|
// For security reason, you must select the folder where are the KML and ROM files and then, reopen this file!
|
||||||
new AlertDialog.Builder(this)
|
new AlertDialog.Builder(this)
|
||||||
.setTitle(getString(R.string.message_open_security))
|
.setTitle(getString(R.string.message_open_security))
|
||||||
|
@ -1110,16 +1115,18 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||||
//Log.d(TAG, "onActivityResult INTENT_CREATE_RAM_CARD " + url);
|
//Log.d(TAG, "onActivityResult INTENT_CREATE_RAM_CARD " + url);
|
||||||
if(selectedRAMSize > 0) {
|
if(selectedRAMSize > 0) {
|
||||||
int size = 2 * selectedRAMSize;
|
int size = 2 * selectedRAMSize;
|
||||||
FileOutputStream fileOutputStream = null;
|
FileOutputStream fileOutputStream;
|
||||||
try {
|
try {
|
||||||
ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(uri, "w");
|
ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(uri, "w");
|
||||||
fileOutputStream = new FileOutputStream(pfd.getFileDescriptor());
|
if(pfd != null) {
|
||||||
byte[] zero = new byte[1024];
|
fileOutputStream = new FileOutputStream(pfd.getFileDescriptor());
|
||||||
Arrays.fill(zero, (byte) 0);
|
byte[] zero = new byte[1024];
|
||||||
for (int i = 0; i < size; i++)
|
Arrays.fill(zero, (byte) 0);
|
||||||
fileOutputStream.write(zero);
|
for (int i = 0; i < size; i++)
|
||||||
fileOutputStream.flush();
|
fileOutputStream.write(zero);
|
||||||
fileOutputStream.close();
|
fileOutputStream.flush();
|
||||||
|
fileOutputStream.close();
|
||||||
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -1246,10 +1253,12 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||||
}).show();
|
}).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Method used from JNI!
|
||||||
|
|
||||||
final int GENERIC_READ = 1;
|
final int GENERIC_READ = 1;
|
||||||
final int GENERIC_WRITE = 2;
|
final int GENERIC_WRITE = 2;
|
||||||
Map<Integer, ParcelFileDescriptor> parcelFileDescriptorPerFd = null;
|
Map<Integer, ParcelFileDescriptor> parcelFileDescriptorPerFd = null;
|
||||||
int openFileFromContentResolver(String fileURL, int writeAccess) {
|
public int openFileFromContentResolver(String fileURL, int writeAccess) {
|
||||||
//https://stackoverflow.com/a/31677287
|
//https://stackoverflow.com/a/31677287
|
||||||
Uri uri = Uri.parse(fileURL);
|
Uri uri = Uri.parse(fileURL);
|
||||||
ParcelFileDescriptor filePfd;
|
ParcelFileDescriptor filePfd;
|
||||||
|
@ -1274,20 +1283,22 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||||
parcelFileDescriptorPerFd.put(fd, filePfd);
|
parcelFileDescriptorPerFd.put(fd, filePfd);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
int openFileInFolderFromContentResolver(String filename, String folderURL, int writeAccess) {
|
public int openFileInFolderFromContentResolver(String filename, String folderURL, int writeAccess) {
|
||||||
Uri folderURI = Uri.parse(folderURL);
|
Uri folderURI = Uri.parse(folderURL);
|
||||||
DocumentFile folderDocumentFile = DocumentFile.fromTreeUri(this, folderURI);
|
DocumentFile folderDocumentFile = DocumentFile.fromTreeUri(this, folderURI);
|
||||||
for (DocumentFile file : folderDocumentFile.listFiles()) {
|
if(folderDocumentFile != null) {
|
||||||
final String url = file.getUri().toString();
|
for (DocumentFile file : folderDocumentFile.listFiles()) {
|
||||||
final String name = file.getName();
|
final String url = file.getUri().toString();
|
||||||
//Log.d(TAG, "url: " + url + ", name: " + name);
|
final String name = file.getName();
|
||||||
if(filename.equals(name)) {
|
//Log.d(TAG, "url: " + url + ", name: " + name);
|
||||||
return openFileFromContentResolver(url, writeAccess);
|
if (filename.equals(name)) {
|
||||||
|
return openFileFromContentResolver(url, writeAccess);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int closeFileFromContentResolver(int fd) {
|
public int closeFileFromContentResolver(int fd) {
|
||||||
if(parcelFileDescriptorPerFd != null) {
|
if(parcelFileDescriptorPerFd != null) {
|
||||||
ParcelFileDescriptor filePfd = parcelFileDescriptorPerFd.get(fd);
|
ParcelFileDescriptor filePfd = parcelFileDescriptorPerFd.get(fd);
|
||||||
if(filePfd != null) {
|
if(filePfd != null) {
|
||||||
|
@ -1307,7 +1318,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||||
Utils.showAlert(this, text);
|
Utils.showAlert(this, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendMenuItemCommand(int menuItem) {
|
public void sendMenuItemCommand(int menuItem) {
|
||||||
switch (menuItem) {
|
switch (menuItem) {
|
||||||
case 1: // FILE_NEW
|
case 1: // FILE_NEW
|
||||||
OnFileNew();
|
OnFileNew();
|
||||||
|
@ -1385,7 +1396,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String getFirstKMLFilenameForType(char chipsetType) {
|
public String getFirstKMLFilenameForType(char chipsetType) {
|
||||||
extractKMLScripts();
|
extractKMLScripts();
|
||||||
|
|
||||||
for (int i = 0; i < kmlScripts.size(); i++) {
|
for (int i = 0; i < kmlScripts.size(); i++) {
|
||||||
|
@ -1411,7 +1422,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clipboardCopyText(String text) {
|
public void clipboardCopyText(String text) {
|
||||||
// Gets a handle to the clipboard service.
|
// Gets a handle to the clipboard service.
|
||||||
ClipboardManager clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
|
ClipboardManager clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
if(clipboard != null) {
|
if(clipboard != null) {
|
||||||
|
@ -1420,7 +1431,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||||
clipboard.setPrimaryClip(clip);
|
clipboard.setPrimaryClip(clip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String clipboardPasteText() {
|
public String clipboardPasteText() {
|
||||||
ClipboardManager clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
|
ClipboardManager clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
if (clipboard != null && clipboard.hasPrimaryClip()) {
|
if (clipboard != null && clipboard.hasPrimaryClip()) {
|
||||||
ClipData clipData = clipboard.getPrimaryClip();
|
ClipData clipData = clipboard.getPrimaryClip();
|
||||||
|
@ -1435,12 +1446,12 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void performHapticFeedback() {
|
public void performHapticFeedback() {
|
||||||
if(sharedPreferences.getBoolean("settings_haptic_feedback", true))
|
if(sharedPreferences.getBoolean("settings_haptic_feedback", true))
|
||||||
mainScreenView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
mainScreenView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendByteUdp(int byteSent) {
|
public void sendByteUdp(int byteSent) {
|
||||||
printerSimulator.write(byteSent);
|
printerSimulator.write(byteSent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1458,7 +1469,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||||
String[] settingKeys = {
|
String[] settingKeys = {
|
||||||
"settings_realspeed", "settings_grayscale", "settings_rotation", "settings_auto_layout",
|
"settings_realspeed", "settings_grayscale", "settings_rotation", "settings_auto_layout",
|
||||||
"settings_hide_bar", "settings_hide_button_menu", "settings_sound_volume", "settings_haptic_feedback",
|
"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_macro",
|
"settings_background_kml_color", "settings_background_fallback_color",
|
||||||
|
"settings_printer_model", "settings_printer_prevent_line_wrap", "settings_macro",
|
||||||
"settings_kml", "settings_port1", "settings_port2" };
|
"settings_kml", "settings_port1", "settings_port2" };
|
||||||
for (String settingKey : settingKeys) {
|
for (String settingKey : settingKeys) {
|
||||||
updateFromPreferences(settingKey, false);
|
updateFromPreferences(settingKey, false);
|
||||||
|
@ -1475,15 +1487,23 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||||
case "settings_rotation":
|
case "settings_rotation":
|
||||||
int rotationMode = 0;
|
int rotationMode = 0;
|
||||||
try {
|
try {
|
||||||
rotationMode = Integer.parseInt(sharedPreferences.getString("settings_rotation", "0"));
|
String rotationModeValue = sharedPreferences.getString("settings_rotation", "0");
|
||||||
} catch (NumberFormatException ex) {}
|
if(rotationModeValue != null)
|
||||||
|
rotationMode = Integer.parseInt(rotationModeValue);
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
// Catch bad number format
|
||||||
|
}
|
||||||
mainScreenView.setRotationMode(rotationMode, isDynamic);
|
mainScreenView.setRotationMode(rotationMode, isDynamic);
|
||||||
break;
|
break;
|
||||||
case "settings_auto_layout":
|
case "settings_auto_layout":
|
||||||
int autoLayoutMode = 1;
|
int autoLayoutMode = 1;
|
||||||
try {
|
try {
|
||||||
autoLayoutMode = Integer.parseInt(sharedPreferences.getString("settings_auto_layout", "1"));
|
String autoLayoutModeValue = sharedPreferences.getString("settings_auto_layout", "1");
|
||||||
} catch (NumberFormatException ex) {}
|
if(autoLayoutModeValue != null)
|
||||||
|
autoLayoutMode = Integer.parseInt(autoLayoutModeValue);
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
// Catch bad number format
|
||||||
|
}
|
||||||
mainScreenView.setAutoLayout(autoLayoutMode, isDynamic);
|
mainScreenView.setAutoLayout(autoLayoutMode, isDynamic);
|
||||||
break;
|
break;
|
||||||
case "settings_hide_bar":
|
case "settings_hide_bar":
|
||||||
|
@ -1514,14 +1534,23 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||||
case "settings_background_fallback_color":
|
case "settings_background_fallback_color":
|
||||||
String fallbackColor = sharedPreferences.getString("settings_background_fallback_color", "0");
|
String fallbackColor = sharedPreferences.getString("settings_background_fallback_color", "0");
|
||||||
try {
|
try {
|
||||||
mainScreenView.setBackgroundFallbackColor(Integer.parseInt(fallbackColor));
|
if(fallbackColor != null)
|
||||||
} catch (NumberFormatException ex) {}
|
mainScreenView.setBackgroundFallbackColor(Integer.parseInt(fallbackColor));
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
// Catch bad number format
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "settings_printer_model":
|
case "settings_printer_model":
|
||||||
String printerModel = sharedPreferences.getString("settings_printer_model", "1");
|
String printerModel = sharedPreferences.getString("settings_printer_model", "1");
|
||||||
try {
|
try {
|
||||||
printerSimulator.setPrinterModel82240A(Integer.parseInt(printerModel) == 0);
|
if(printerModel != null)
|
||||||
} catch (NumberFormatException ex) {}
|
printerSimulator.setPrinterModel82240A(Integer.parseInt(printerModel) == 0);
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
// Catch bad number format
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "settings_printer_prevent_line_wrap":
|
||||||
|
printerSimulator.setPreventLineWrap(sharedPreferences.getBoolean("settings_printer_prevent_line_wrap", false));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "settings_kml":
|
case "settings_kml":
|
||||||
|
|
|
@ -83,7 +83,7 @@
|
||||||
<string name="message_printer">Printer Simulator</string>
|
<string name="message_printer">Printer Simulator</string>
|
||||||
<string name="message_printer_share_text">Save printer paper as text</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_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="message_printer_out_of_paper">Out of paper error for the graphic printer (max line: %d, max pixel line: %d).</string>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -125,6 +125,8 @@
|
||||||
<string name="settings_category_printer_title">Printer Simulator</string>
|
<string name="settings_category_printer_title">Printer Simulator</string>
|
||||||
<string name="settings_printer_model_title">Printer Model</string>
|
<string name="settings_printer_model_title">Printer Model</string>
|
||||||
<string name="settings_printer_model_summary">You can choose the printer model</string>
|
<string name="settings_printer_model_summary">You can choose the printer model</string>
|
||||||
|
<string name="settings_printer_prevent_line_wrap">Prevent Line Wrapping</string>
|
||||||
|
<string name="settings_printer_prevent_line_wrap_summary">Prevent the calc to wrap the line in the textual printer simulator</string>
|
||||||
|
|
||||||
<string name="settings_category_macro_title">Macro</string>
|
<string name="settings_category_macro_title">Macro</string>
|
||||||
<string name="settings_macro_real_speed_title">Use Real Replay Speed</string>
|
<string name="settings_macro_real_speed_title">Use Real Replay Speed</string>
|
||||||
|
|
|
@ -106,6 +106,11 @@
|
||||||
android:entryValues="@array/settings_printer_model_value"
|
android:entryValues="@array/settings_printer_model_value"
|
||||||
android:defaultValue="1"
|
android:defaultValue="1"
|
||||||
/>
|
/>
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="settings_printer_prevent_line_wrap"
|
||||||
|
android:title="@string/settings_printer_prevent_line_wrap"
|
||||||
|
android:summary="@string/settings_printer_prevent_line_wrap_summary"
|
||||||
|
android:defaultValue="false" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue