From 74a9994d53c7e8847a26971629f64c30bb89064c Mon Sep 17 00:00:00 2001 From: dgis Date: Mon, 24 Jun 2019 19:39:14 +0200 Subject: [PATCH] Fix the flickering issue when 2 SurfaceView are one above the other (with the Printer Simulator) --- ReadMe.txt | 2 +- .../emulator/calculator/PanAndScaleView.java | 4 +- .../calculator/PrinterSimulatorFragment.java | 40 +++++++++---------- .../emulator/forty/eight/MainActivity.java | 1 - 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/ReadMe.txt b/ReadMe.txt index 8ad9175..2fc031c 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -145,10 +145,10 @@ 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. -- Pan and zoom seems possible after closing the calc. - Improve the swipe gesture. - The clock seems unsynchronized sometimes. - Add KML script loading dependencies fallback to the inner ROM (and may be KML include?). diff --git a/app/src/main/java/org/emulator/calculator/PanAndScaleView.java b/app/src/main/java/org/emulator/calculator/PanAndScaleView.java index a73ef8e..fb1b22e 100644 --- a/app/src/main/java/org/emulator/calculator/PanAndScaleView.java +++ b/app/src/main/java/org/emulator/calculator/PanAndScaleView.java @@ -28,13 +28,13 @@ import android.view.InputDevice; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.ScaleGestureDetector; -import android.view.SurfaceView; import android.view.View; import android.widget.OverScroller; import androidx.core.view.ViewCompat; -public class PanAndScaleView extends SurfaceView { +/* Inherit from View and not SurfaceView to prevent 2 SurfaceView with one over the other! */ +public class PanAndScaleView extends View { protected static final String TAG = "PanAndScaleView"; protected final boolean debug = false; diff --git a/app/src/main/java/org/emulator/calculator/PrinterSimulatorFragment.java b/app/src/main/java/org/emulator/calculator/PrinterSimulatorFragment.java index 35a60a0..9eaf3b2 100644 --- a/app/src/main/java/org/emulator/calculator/PrinterSimulatorFragment.java +++ b/app/src/main/java/org/emulator/calculator/PrinterSimulatorFragment.java @@ -19,7 +19,6 @@ import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.content.Intent; -import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; @@ -27,22 +26,18 @@ import android.graphics.ColorMatrixColorFilter; import android.graphics.Paint; import android.graphics.Rect; import android.os.Bundle; -import android.text.Layout; import android.util.AttributeSet; import android.util.Log; -import android.util.TypedValue; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.Window; -import android.view.WindowManager; 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; @@ -144,6 +139,7 @@ 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_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 { @@ -168,6 +164,7 @@ 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()); @@ -180,16 +177,16 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment { return true; } }); - TypedValue tv = new TypedValue(); - Context context = getContext(); - if(context != null) { - Resources.Theme theme = context.getTheme(); - if (theme != null) { - theme.resolveAttribute(androidx.appcompat.R.attr.actionBarSize, tv, true); - int actionBarHeight = getResources().getDimensionPixelSize(tv.resourceId); - toolbar.setMinimumHeight(actionBarHeight); - } - } +// 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 @@ -245,9 +242,11 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment { return view; } - private void appendTextToPrinter(String text) { - if(textViewPrinterText != null && text != null && text.length() > 0) { - + 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 @@ -270,14 +269,15 @@ public class PrinterSimulatorFragment extends AppCompatDialogFragment { // textViewPrinterText.scrollTo(0, currentScrollPosition); // } // } else - textViewPrinterText.append(text); + textViewPrinterText.append(text); + } } } private void updatePaper(String textAppended) { if(debug) Log.d(TAG, "updatePaper(" + textAppended + ")"); if(textViewPrinterText != null) { - appendTextToPrinter(textAppended == null ? printerSimulator.getText() : textAppended); + appendTextToPrinter(textAppended == null ? printerSimulator.getText() : null, textAppended); } if(printerGraphView != null) { printerGraphView.updatePaperLayout(); 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 98cb472..0f312c3 100644 --- a/app/src/main/java/org/emulator/forty/eight/MainActivity.java +++ b/app/src/main/java/org/emulator/forty/eight/MainActivity.java @@ -38,7 +38,6 @@ 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;