Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-26176

Android: Opening/Closing a dialog should fire a window's blur/focus events (parity)

    Details

      Description

      Summary:
      When opening and closing a dialog, the parent window should fire a "blur" and "focus" event respectively. This is to match iOS' behavior.

      Steps to reproduce:

      1. Build and run the below code on Android.
      2. Tap on the "Show Alert" button.
      3. View the Android log. Notice that a "blur" event was not received.
      4. Close the alert dialog.
      5. View the Android log. Notice that a "focus" event was not received.

      var window = Ti.UI.createWindow({
      	layout: "vertical",
      	fullscreen: true,
      });
      var alertButton = Ti.UI.createButton({
      	title: "Show Alert",
      	top: "20%",
      });
      alertButton.addEventListener("click", function(e) {
      	// An alert dialog does not trigger window focus/blur events.
      	alert("Alert!");
      });
      window.add(alertButton);
      var windowButton = Ti.UI.createButton({
      	title: "Show Child Window",
      	top: "20%",
      });
      windowButton.addEventListener("click", function(e) {
      	// Displaying a child window does trigger parent window's focus/blur events.
      	var childWindow = Ti.UI.createWindow({ backgroundColor: "orange" });
      	var closeButton = Ti.UI.createButton({ title: "Close Me" });
      	closeButton.addEventListener("click", function(e) {
      		childWindow.close();
      	});
      	childWindow.add(closeButton);
      	childWindow.open();
      });
      window.add(windowButton);
      window.addEventListener("focus", function(e) {
      	Ti.API.info("@@@ Window 'focus' event received.");
      });
      window.addEventListener("blur", function(e) {
      	Ti.API.info("@@@ Window 'blur' event received.");
      });
      window.open();
      

      Expected Result:
      Opening a dialog should fire the window's "blur" event.
      Close a dialog should fire the window's "focus" event.

      Notes:
      The window's focus/blur events are correctly fired when displaying a child window or when doing a suspend/resume. This is only an issue with displaying dialogs within a window.

      Recommended Solution:
      Override the Java Activity.onWindowFocusChanged() method. This method will be invoked when opening/closing dialogs and child activities.
      https://developer.android.com/reference/android/app/Activity.html#onWindowFocusChanged(boolean)

      We'll need to re-evaluate the focus/blur handling via our TiBaseActivity class' onResume() and onPause() methods since the onWindowFocusChanged() method provides what we need. The current handling is used to handle focus/blur for TabGroup tabs.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jquick Joshua Quick
                Reporter:
                jquick Joshua Quick
              • Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Backbone Issue Sync

                  • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                    Git Source Code