Bug 880118 - Allow GeckoView to be used as a view from a library project. r=blassey

This commit is contained in:
Shane Tully 2013-08-23 11:46:05 -07:00
Родитель 847303f911
Коммит 752ca102b7
3 изменённых файлов: 157 добавлений и 4 удалений

Просмотреть файл

@ -0,0 +1,137 @@
/* -*- 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;
import org.mozilla.gecko.util.HardwareUtils;
import org.mozilla.gecko.util.ThreadUtils;
import android.app.Activity;
import android.content.Context;
import android.graphics.RectF;
import android.hardware.SensorEventListener;
import android.location.LocationListener;
import android.os.Build;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AbsoluteLayout;
public class BaseGeckoInterface implements GeckoAppShell.GeckoInterface {
// Bug 908744: Implement GeckoEventListener
// Bug 908752: Implement SensorEventListener
// Bug 908755: Implement LocationListener
// Bug 908756: Implement Tabs.OnTabsChangedListener
// Bug 908760: Implement GeckoEventResponder
private Context mContext;
private GeckoProfile mProfile;
public BaseGeckoInterface(Context context) {
mContext = context;
}
public GeckoProfile getProfile() {
// Fall back to default profile if we didn't load a specific one
if (mProfile == null) {
mProfile = GeckoProfile.get(mContext);
}
return mProfile;
}
// Bug 908770: Implement this
public PromptService getPromptService() {
return null;
}
public Activity getActivity() {
return (Activity)mContext;
}
public String getDefaultUAString() {
return HardwareUtils.isTablet() ? AppConstants.USER_AGENT_FENNEC_TABLET :
AppConstants.USER_AGENT_FENNEC_MOBILE;
}
// Bug 908772: Implement this
public LocationListener getLocationListener() {
return null;
}
// Bug 908773: Implement this
public SensorEventListener getSensorEventListener() {
return null;
}
// Bug 908775: Implement this
public void doRestart() {}
public void setFullScreen(final boolean fullscreen) {
ThreadUtils.postToUiThread(new Runnable() {
@Override
public void run() {
// Hide/show the system notification bar
Window window = ((Activity)mContext).getWindow();
window.setFlags(fullscreen ?
WindowManager.LayoutParams.FLAG_FULLSCREEN : 0,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
if (Build.VERSION.SDK_INT >= 11)
window.getDecorView().setSystemUiVisibility(fullscreen ? 1 : 0);
}
});
}
// Bug 908779: Implement this
public void addPluginView(final View view, final RectF rect, final boolean isFullScreen) {}
// Bug 908781: Implement this
public void removePluginView(final View view, final boolean isFullScreen) {}
// Bug 908783: Implement this
public void enableCameraView() {}
// Bug 908785: Implement this
public void disableCameraView() {}
// Bug 908786: Implement this
public void addAppStateListener(GeckoAppShell.AppStateListener listener) {}
// Bug 908787: Implement this
public void removeAppStateListener(GeckoAppShell.AppStateListener listener) {}
// Bug 908788: Implement this
public View getCameraView() {
return null;
}
// Bug 908789: Implement this
public void notifyWakeLockChanged(String topic, String state) {}
// Bug 908790: Implement this
public FormAssistPopup getFormAssistPopup() {
return null;
}
public boolean areTabsShown() {
return false;
}
// Bug 908791: Implement this
public AbsoluteLayout getPluginContainer() {
return null;
}
public void notifyCheckUpdateResult(String result) {
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Update:CheckResult", result));
}
public boolean hasTabsSideBar() {
return false;
}
// Bug 908792: Implement this
public void invalidateOptionsMenu() {}
}

Просмотреть файл

@ -7,6 +7,8 @@ package org.mozilla.gecko;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.gfx.LayerView;
import org.mozilla.gecko.mozglue.GeckoLoader;
import org.mozilla.gecko.util.Clipboard;
import org.mozilla.gecko.util.GeckoEventListener;
import org.mozilla.gecko.util.ThreadUtils;
@ -20,15 +22,17 @@ import android.graphics.Canvas;
import android.graphics.Paint;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.os.Handler;
public class GeckoView extends LayerView
implements GeckoEventListener, ContextGetter {
private static final String LOGTAG = "GeckoView";
public GeckoView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GeckoView);
@ -42,6 +46,14 @@ public class GeckoView extends LayerView
// If running outside of a GeckoActivity (eg, from a library project),
// load the native code and disable content providers
if (!(context instanceof GeckoActivity)) {
// Set the GeckoInterface if the context is an activity and the GeckoInterface
// has not already been set
if (context instanceof Activity && getGeckoInterface() == null) {
setGeckoInterface(new BaseGeckoInterface(context));
}
Clipboard.init(context);
GeckoLoader.loadMozGlue();
BrowserDB.setEnableContentProviders(false);
}
@ -60,7 +72,6 @@ public class GeckoView extends LayerView
ThreadUtils.setUiThread(Thread.currentThread(), new Handler());
initializeView(GeckoAppShell.getEventDispatcher());
GeckoProfile profile = GeckoProfile.get(context);
BrowserDB.initialize(profile.getName());
@ -92,7 +103,11 @@ public class GeckoView extends LayerView
}
}
public static void setGeckoInterface(GeckoAppShell.GeckoInterface aGeckoInterface) {
GeckoAppShell.setGeckoInterface(aGeckoInterface);
public static void setGeckoInterface(final BaseGeckoInterface geckoInterface) {
GeckoAppShell.setGeckoInterface(geckoInterface);
}
public static GeckoAppShell.GeckoInterface getGeckoInterface() {
return GeckoAppShell.getGeckoInterface();
}
}

Просмотреть файл

@ -61,6 +61,7 @@ FENNEC_JAVA_FILES = \
animation/Rotate3DAnimation.java \
animation/ViewHelper.java \
BackButton.java \
BaseGeckoInterface.java \
BrowserApp.java \
BrowserToolbar.java \
BrowserToolbarBackground.java \