From 162b1f280f60edfdfbf4cd24ea2820a377e3fa7e Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Mon, 11 Apr 2022 10:22:41 +0600 Subject: [PATCH 1/2] 5246-Fix_initial_dialog_not_responsive_issue issue: https://gitlab.e.foundation/e/backlog/-/issues/5246 When camera first launch, it bounches to landscape mode, then bounch back to portrait mode for the initial alertDialog. Looks like 20ms delay is not enough for the initial dialog to layout correctly. This commit increase the delay for initial dialog to 500ms. --- .../sourceforge/opencamera/MainActivity.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/net/sourceforge/opencamera/MainActivity.java b/app/src/main/java/net/sourceforge/opencamera/MainActivity.java index eae8cc046..e508f433b 100644 --- a/app/src/main/java/net/sourceforge/opencamera/MainActivity.java +++ b/app/src/main/java/net/sourceforge/opencamera/MainActivity.java @@ -571,7 +571,7 @@ public class MainActivity extends Activity { launchOnlineHelp(); } }); - showAlertDialog(alertDialog, "first time load dialog dismissed"); + showAlertDialog(alertDialog, "first time load dialog dismissed", 500L); //On application start 20millisecond delay is not enough for all screen rotating animation to be complete (if user use the camera in portrait mode, then it moves from portrait to landscape & then again landscape to portrait). 500milliseconds delay would do the trick. } setFirstTimeFlag(); @@ -1518,6 +1518,14 @@ public class MainActivity extends Activity { } private void showAlertDialog(AlertDialog.Builder alertDialog, final String logMessageOnDismiss) { + showAlertDialog(alertDialog, logMessageOnDismiss, -1L); + } + + /** + * @param delay how much time in milliseconds should the alertDialog wait to popup. + * If delay <= 0, then use default delay time (20 milliseconds) + */ + private void showAlertDialog(AlertDialog.Builder alertDialog, final String logMessageOnDismiss, long delay) { final AlertDialog alert = alertDialog.create(); alert.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override @@ -1531,6 +1539,10 @@ public class MainActivity extends Activity { showPreview(false); setWindowFlagsForSettings(); + if (delay > 0) { + showAlert(alert, delay); + return; + } showAlert(alert); } @@ -2942,7 +2954,7 @@ public class MainActivity extends Activity { * the dialog doesn't show properly if the phone is held in portrait. A workaround seems to be * to use postDelayed. Note that postOnAnimation() doesn't work. */ - public void showAlert(final AlertDialog alert) { + public void showAlert(final AlertDialog alert, long delay) { if( MyDebug.LOG ) Log.d(TAG, "showAlert"); Handler handler = new Handler(); @@ -2950,7 +2962,11 @@ public class MainActivity extends Activity { public void run() { alert.show(); } - }, 20); + }, delay); + } + + public void showAlert(final AlertDialog alert) { + showAlert(alert, 20L); // note that 1ms usually fixes the problem, but not always; 10ms seems fine, have set 20ms // just in case } -- GitLab From 8b256aeee57f8b2cd8e028f2409db7f4ee1fd415 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Mon, 11 Apr 2022 19:43:39 +0600 Subject: [PATCH 2/2] Update comment according to review --- .../sourceforge/opencamera/MainActivity.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/net/sourceforge/opencamera/MainActivity.java b/app/src/main/java/net/sourceforge/opencamera/MainActivity.java index e508f433b..632cb693c 100644 --- a/app/src/main/java/net/sourceforge/opencamera/MainActivity.java +++ b/app/src/main/java/net/sourceforge/opencamera/MainActivity.java @@ -571,7 +571,10 @@ public class MainActivity extends Activity { launchOnlineHelp(); } }); - showAlertDialog(alertDialog, "first time load dialog dismissed", 500L); //On application start 20millisecond delay is not enough for all screen rotating animation to be complete (if user use the camera in portrait mode, then it moves from portrait to landscape & then again landscape to portrait). 500milliseconds delay would do the trick. + /* On application start 20 millisecond delay is not enough for all screen rotating animation to be complete + (if user use the camera in portrait mode, then it moves from portrait to landscape & then again landscape to portrait). + 500 milliseconds delay would do the trick. */ + showAlertDialog(alertDialog, "first time load dialog dismissed", 500L); } setFirstTimeFlag(); @@ -1522,10 +1525,10 @@ public class MainActivity extends Activity { } /** - * @param delay how much time in milliseconds should the alertDialog wait to popup. + * @param delayInMs how much time in milliseconds should the alertDialog wait to popup. * If delay <= 0, then use default delay time (20 milliseconds) */ - private void showAlertDialog(AlertDialog.Builder alertDialog, final String logMessageOnDismiss, long delay) { + private void showAlertDialog(AlertDialog.Builder alertDialog, final String logMessageOnDismiss, long delayInMs) { final AlertDialog alert = alertDialog.create(); alert.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override @@ -1539,8 +1542,8 @@ public class MainActivity extends Activity { showPreview(false); setWindowFlagsForSettings(); - if (delay > 0) { - showAlert(alert, delay); + if (delayInMs > 0) { + showAlert(alert, delayInMs); return; } showAlert(alert); @@ -2954,7 +2957,7 @@ public class MainActivity extends Activity { * the dialog doesn't show properly if the phone is held in portrait. A workaround seems to be * to use postDelayed. Note that postOnAnimation() doesn't work. */ - public void showAlert(final AlertDialog alert, long delay) { + public void showAlert(final AlertDialog alert, long delayInMs) { if( MyDebug.LOG ) Log.d(TAG, "showAlert"); Handler handler = new Handler(); @@ -2962,7 +2965,7 @@ public class MainActivity extends Activity { public void run() { alert.show(); } - }, delay); + }, delayInMs); } public void showAlert(final AlertDialog alert) { -- GitLab