Bug 1476106 - Part 5 - Subscribe PromptService to OrientationChangeListener, too. r?snorp
Now that GeckoScreenOrientation generally offers notifications of screen
orientation changes, the PromptService no longer needs to do its own orientation
tracking and require to be fed orientation changes from each activity using it.
MozReview-Commit-ID: K7KbDsQip7b
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -2170,20 +2170,16 @@ public abstract class GeckoApp extends G
Log.d(LOGTAG, "onConfigurationChanged: " + newConfig.locale);
final LocaleManager localeManager = BrowserLocaleManager.getInstance();
final Locale changed = localeManager.onSystemConfigurationChanged(this, getResources(), newConfig, mLastLocale);
if (changed != null) {
onLocaleChanged(Locales.getLanguageTag(changed));
}
- if (mPromptService != null) {
- mPromptService.changePromptOrientation(newConfig.orientation);
- }
-
super.onConfigurationChanged(newConfig);
}
public String getContentProcessName() {
return AppConstants.MOZ_CHILD_PROCESS_NAME;
}
public void addEnvToIntent(Intent intent) {
--- a/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
@@ -4,17 +4,16 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.customtabs;
import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.pm.ResolveInfo;
-import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Browser;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
@@ -182,25 +181,16 @@ public class CustomTabsActivity extends
}
@Override
public void onRequestPermissionsResult(final int requestCode, final String[] permissions,
final int[] grantResults) {
Permissions.onRequestPermissionsResult(this, permissions, grantResults);
}
- @Override
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
-
- if (mPromptService != null) {
- mPromptService.changePromptOrientation(newConfig.orientation);
- }
- }
-
private void sendTelemetry() {
final SafeIntent startIntent = new SafeIntent(getIntent());
Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.INTENT, "customtab");
if (IntentUtil.hasToolbarColor(startIntent)) {
Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.INTENT, "customtab-hasToolbarColor");
}
if (IntentUtil.hasActionButton(startIntent)) {
--- a/mobile/android/base/java/org/mozilla/gecko/prompts/PromptService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/prompts/PromptService.java
@@ -1,58 +1,62 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.prompts;
import org.mozilla.gecko.EventDispatcher;
+import org.mozilla.gecko.GeckoScreenOrientation;
+import org.mozilla.gecko.GeckoScreenOrientation.ScreenOrientation;
import org.mozilla.gecko.util.BundleEventListener;
import org.mozilla.gecko.util.EventCallback;
import org.mozilla.gecko.util.GeckoBundle;
import android.content.Context;
-public class PromptService implements BundleEventListener {
+public class PromptService implements BundleEventListener,
+ GeckoScreenOrientation.OrientationChangeListener {
private static final String LOGTAG = "GeckoPromptService";
private final Context context;
private final EventDispatcher dispatcher;
private Prompt currentPrompt;
- private int currentOrientation;
public PromptService(final Context context, final EventDispatcher dispatcher) {
this.context = context;
- this.currentOrientation = context.getResources().getConfiguration().orientation;
+ GeckoScreenOrientation.getInstance().addListener(this);
this.dispatcher = dispatcher;
this.dispatcher.registerUiThreadListener(this,
"Prompt:Show",
"Prompt:ShowTop");
}
public void destroy() {
dispatcher.unregisterUiThreadListener(this,
"Prompt:Show",
"Prompt:ShowTop");
+ GeckoScreenOrientation.getInstance().removeListener(this);
}
// BundleEventListener implementation
@Override
public void handleMessage(final String event, final GeckoBundle message,
final EventCallback callback) {
currentPrompt = new Prompt(context, new Prompt.PromptCallback() {
@Override
public void onPromptFinished(final GeckoBundle result) {
callback.sendSuccess(result);
currentPrompt = null;
}
});
currentPrompt.show(message);
}
- public void changePromptOrientation(int newOrientation) {
- if (currentPrompt != null && currentOrientation != newOrientation) {
+ // OrientationChangeListener implementation
+ @Override
+ public void onScreenOrientationChanged(ScreenOrientation newOrientation) {
+ if (currentPrompt != null) {
currentPrompt.resetLayout();
}
- currentOrientation = newOrientation;
}
}
--- a/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
@@ -4,17 +4,16 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.webapps;
import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.content.ActivityNotFoundException;
import android.content.Intent;
-import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.customtabs.CustomTabsIntent;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.ActionMode;
import android.util.Log;
@@ -169,25 +168,16 @@ public class WebAppActivity extends AppC
return;
}
updateFromManifest();
mGeckoSession.loadUri(mManifest.getStartUri().toString());
}
- @Override
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
-
- if (mPromptService != null) {
- mPromptService.changePromptOrientation(newConfig.orientation);
- }
- }
-
private void fallbackToFennec(String message) {
if (message != null) {
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
try {
Intent intent = new Intent(this, BrowserApp.class);
intent.setAction(Intent.ACTION_VIEW);