This source file includes following definitions.
- onWindowFocusChanged
- onCreate
- registerWindowFocusChangedListener
- unregisterWindowFocusChangedListener
package org.chromium.base;
import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import android.view.Window;
public class BaseChromiumApplication extends Application {
public interface WindowFocusChangedListener {
public void onWindowFocusChanged(Activity activity, boolean hasFocus);
}
private ObserverList<WindowFocusChangedListener> mWindowFocusListeners =
new ObserverList<WindowFocusChangedListener>();
@Override
public void onCreate() {
super.onCreate();
ApplicationStatus.initialize(this);
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
@Override
public void onActivityCreated(final Activity activity, Bundle savedInstanceState) {
Window.Callback callback = activity.getWindow().getCallback();
activity.getWindow().setCallback(new WindowCallbackWrapper(callback) {
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
for (WindowFocusChangedListener listener : mWindowFocusListeners) {
listener.onWindowFocusChanged(activity, hasFocus);
}
}
});
}
@Override
public void onActivityDestroyed(Activity activity) {
assert activity.getWindow().getCallback() instanceof WindowCallbackWrapper;
}
@Override
public void onActivityPaused(Activity activity) {
assert activity.getWindow().getCallback() instanceof WindowCallbackWrapper;
}
@Override
public void onActivityResumed(Activity activity) {
assert activity.getWindow().getCallback() instanceof WindowCallbackWrapper;
}
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
assert activity.getWindow().getCallback() instanceof WindowCallbackWrapper;
}
@Override
public void onActivityStarted(Activity activity) {
assert activity.getWindow().getCallback() instanceof WindowCallbackWrapper;
}
@Override
public void onActivityStopped(Activity activity) {
assert activity.getWindow().getCallback() instanceof WindowCallbackWrapper;
}
});
}
public void registerWindowFocusChangedListener(WindowFocusChangedListener listener) {
mWindowFocusListeners.addObserver(listener);
}
public void unregisterWindowFocusChangedListener(WindowFocusChangedListener listener) {
mWindowFocusListeners.removeObserver(listener);
}
}