2012-06-12 02:18:40 +04:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; 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;
|
|
|
|
|
2012-08-27 08:33:11 +04:00
|
|
|
import org.mozilla.gecko.db.BrowserContract.Combined;
|
|
|
|
import org.mozilla.gecko.db.BrowserDB;
|
2012-11-28 00:04:14 +04:00
|
|
|
import org.mozilla.gecko.gfx.BitmapUtils;
|
2013-03-07 14:17:32 +04:00
|
|
|
import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
|
2013-03-28 20:40:06 +04:00
|
|
|
import org.mozilla.gecko.gfx.LayerView;
|
2013-03-18 19:43:03 +04:00
|
|
|
import org.mozilla.gecko.util.FloatUtils;
|
2013-03-28 20:40:06 +04:00
|
|
|
import org.mozilla.gecko.util.GamepadUtils;
|
2013-04-02 18:03:39 +04:00
|
|
|
import org.mozilla.gecko.util.HardwareUtils;
|
2013-03-15 14:52:53 +04:00
|
|
|
import org.mozilla.gecko.util.ThreadUtils;
|
2013-03-28 20:40:06 +04:00
|
|
|
import org.mozilla.gecko.util.UiAsyncTask;
|
2013-03-26 02:44:45 +04:00
|
|
|
import org.mozilla.gecko.widget.AboutHomeContent;
|
2013-03-26 02:45:33 +04:00
|
|
|
import org.mozilla.gecko.widget.TopSitesView;
|
2012-08-27 08:33:11 +04:00
|
|
|
|
2012-07-28 04:54:28 +04:00
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
2012-06-12 02:18:40 +04:00
|
|
|
|
2012-07-28 04:53:54 +04:00
|
|
|
import android.app.Activity;
|
2012-08-28 04:50:32 +04:00
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.content.DialogInterface;
|
2012-07-28 04:53:54 +04:00
|
|
|
import android.content.Intent;
|
2013-04-08 11:51:56 +04:00
|
|
|
import android.content.SharedPreferences;
|
2013-02-22 11:22:37 +04:00
|
|
|
import android.content.res.Configuration;
|
2012-08-27 08:33:11 +04:00
|
|
|
import android.database.Cursor;
|
2012-07-28 04:53:54 +04:00
|
|
|
import android.graphics.Bitmap;
|
2013-03-18 19:43:03 +04:00
|
|
|
import android.graphics.PointF;
|
2012-10-13 03:23:20 +04:00
|
|
|
import android.graphics.Rect;
|
2013-04-08 11:51:56 +04:00
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
|
|
import android.graphics.drawable.Drawable;
|
2012-07-28 04:53:54 +04:00
|
|
|
import android.net.Uri;
|
2013-03-05 17:06:09 +04:00
|
|
|
import android.nfc.NdefMessage;
|
|
|
|
import android.nfc.NdefRecord;
|
2013-03-05 17:05:52 +04:00
|
|
|
import android.nfc.NfcAdapter;
|
2013-03-05 17:06:09 +04:00
|
|
|
import android.nfc.NfcEvent;
|
2012-07-28 04:54:28 +04:00
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Bundle;
|
2012-07-28 04:53:54 +04:00
|
|
|
import android.util.Log;
|
2013-03-26 21:23:45 +04:00
|
|
|
import android.view.ContextMenu.ContextMenuInfo;
|
2013-03-12 17:22:01 +04:00
|
|
|
import android.view.InputDevice;
|
2013-02-07 07:53:01 +04:00
|
|
|
import android.view.KeyEvent;
|
2012-07-28 04:54:28 +04:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2012-10-13 03:23:20 +04:00
|
|
|
import android.view.MotionEvent;
|
2012-10-27 00:39:25 +04:00
|
|
|
import android.view.SubMenu;
|
2012-07-28 04:54:28 +04:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2012-10-12 15:57:06 +04:00
|
|
|
import android.view.animation.Interpolator;
|
2012-07-28 04:54:28 +04:00
|
|
|
import android.widget.LinearLayout;
|
2013-03-07 14:17:32 +04:00
|
|
|
import android.widget.RelativeLayout;
|
2012-07-28 04:54:28 +04:00
|
|
|
import android.widget.Toast;
|
2012-07-28 04:53:54 +04:00
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.Vector;
|
2012-06-12 02:18:40 +04:00
|
|
|
|
2012-07-18 04:54:54 +04:00
|
|
|
abstract public class BrowserApp extends GeckoApp
|
2012-06-13 09:47:52 +04:00
|
|
|
implements TabsPanel.TabsLayoutChangeListener,
|
2013-03-12 17:22:01 +04:00
|
|
|
PropertyAnimator.PropertyAnimationListener,
|
|
|
|
View.OnKeyListener {
|
2012-06-12 02:18:40 +04:00
|
|
|
private static final String LOGTAG = "GeckoBrowserApp";
|
|
|
|
|
2013-03-07 14:17:34 +04:00
|
|
|
private static final String PREF_CHROME_DYNAMICTOOLBAR = "browser.chrome.dynamictoolbar";
|
|
|
|
|
2013-03-21 03:43:47 +04:00
|
|
|
private static final int TABS_ANIMATION_DURATION = 450;
|
|
|
|
|
2012-06-12 02:18:40 +04:00
|
|
|
public static BrowserToolbar mBrowserToolbar;
|
|
|
|
private AboutHomeContent mAboutHomeContent;
|
2012-09-28 20:34:45 +04:00
|
|
|
private Boolean mAboutHomeShowing = null;
|
2012-11-27 02:57:11 +04:00
|
|
|
protected Telemetry.Timer mAboutHomeStartupTimer = null;
|
2012-06-12 02:18:40 +04:00
|
|
|
|
2012-09-26 23:02:48 +04:00
|
|
|
private static final int ADDON_MENU_OFFSET = 1000;
|
2012-09-27 22:22:08 +04:00
|
|
|
private class MenuItemInfo {
|
2012-10-27 00:39:25 +04:00
|
|
|
public int id;
|
|
|
|
public String label;
|
|
|
|
public String icon;
|
|
|
|
public boolean checkable;
|
2012-10-30 03:29:55 +04:00
|
|
|
public boolean checked;
|
|
|
|
public boolean enabled;
|
|
|
|
public boolean visible;
|
2012-10-27 00:39:25 +04:00
|
|
|
public int parent;
|
2012-09-27 22:22:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private Vector<MenuItemInfo> mAddonMenuItemsCache;
|
2012-07-27 10:53:48 +04:00
|
|
|
|
2012-06-13 09:47:52 +04:00
|
|
|
private PropertyAnimator mMainLayoutAnimator;
|
|
|
|
|
2012-10-12 15:57:06 +04:00
|
|
|
private static final Interpolator sTabsInterpolator = new Interpolator() {
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-10-12 15:57:06 +04:00
|
|
|
public float getInterpolation(float t) {
|
|
|
|
t -= 1.0f;
|
|
|
|
return t * t * t * t * t + 1.0f;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-27 10:52:41 +04:00
|
|
|
private FindInPageBar mFindInPageBar;
|
|
|
|
|
2012-08-27 08:33:11 +04:00
|
|
|
// We'll ask for feedback after the user launches the app this many times.
|
2012-10-18 23:13:12 +04:00
|
|
|
private static final int FEEDBACK_LAUNCH_COUNT = 15;
|
2012-08-27 08:33:11 +04:00
|
|
|
|
2013-03-17 05:53:41 +04:00
|
|
|
// Variables used for scrolling the toolbar on/off the page;
|
|
|
|
|
|
|
|
// A drag has to move this amount multiplied by the height of the toolbar
|
|
|
|
// before the toolbar will appear or disappear.
|
2013-03-12 21:58:13 +04:00
|
|
|
private static final float TOOLBAR_MOVEMENT_THRESHOLD = 0.3f;
|
2013-03-17 05:53:41 +04:00
|
|
|
|
|
|
|
// Whether the dynamic toolbar pref is enabled.
|
2013-03-07 14:17:34 +04:00
|
|
|
private boolean mDynamicToolbarEnabled = false;
|
2013-03-17 05:53:41 +04:00
|
|
|
|
|
|
|
// The last recorded touch event from onInterceptTouchEvent. These are
|
|
|
|
// not updated until the movement threshold has been exceeded.
|
2013-03-12 21:58:13 +04:00
|
|
|
private float mLastTouchX = 0.0f;
|
2013-03-07 14:17:32 +04:00
|
|
|
private float mLastTouchY = 0.0f;
|
2013-03-17 05:53:41 +04:00
|
|
|
|
|
|
|
// Because we can only scroll by integer amounts, we store the fractional
|
|
|
|
// amounts to be applied here.
|
2013-03-07 14:17:32 +04:00
|
|
|
private float mToolbarSubpixelAccumulation = 0.0f;
|
2013-03-17 05:53:41 +04:00
|
|
|
|
|
|
|
// Used by onInterceptTouchEvent to lock the toolbar into an off or on
|
|
|
|
// position.
|
2013-03-12 21:58:13 +04:00
|
|
|
private boolean mToolbarLocked = false;
|
2013-03-17 05:53:41 +04:00
|
|
|
|
|
|
|
// Whether the toolbar movement threshold has been passed by the current
|
|
|
|
// drag.
|
2013-03-12 21:58:13 +04:00
|
|
|
private boolean mToolbarThresholdPassed = false;
|
2013-03-07 14:17:32 +04:00
|
|
|
|
2013-03-17 05:53:41 +04:00
|
|
|
// Toggled when the tabs tray is made visible to disable toolbar movement.
|
|
|
|
private boolean mToolbarPinned = false;
|
|
|
|
|
2013-03-18 19:43:03 +04:00
|
|
|
// Stored value of the toolbar height, so we know when it's changed.
|
|
|
|
private int mToolbarHeight = 0;
|
|
|
|
|
2013-03-18 20:41:36 +04:00
|
|
|
private Integer mPrefObserverId;
|
|
|
|
|
2012-06-12 02:18:40 +04:00
|
|
|
@Override
|
|
|
|
public void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) {
|
|
|
|
switch(msg) {
|
|
|
|
case LOCATION_CHANGE:
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
2012-10-22 23:37:50 +04:00
|
|
|
maybeCancelFaviconLoad(tab);
|
|
|
|
}
|
|
|
|
// fall through
|
|
|
|
case SELECTED:
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
2013-03-07 14:17:32 +04:00
|
|
|
if ("about:home".equals(tab.getURL())) {
|
2012-06-12 02:18:40 +04:00
|
|
|
showAboutHome();
|
2013-03-07 14:17:32 +04:00
|
|
|
|
2013-03-07 14:17:34 +04:00
|
|
|
if (mDynamicToolbarEnabled) {
|
2013-03-17 05:53:40 +04:00
|
|
|
// Show the toolbar.
|
|
|
|
mBrowserToolbar.animateVisibility(true);
|
2013-03-07 14:17:34 +04:00
|
|
|
}
|
2013-03-07 14:17:32 +04:00
|
|
|
} else {
|
2012-06-12 02:18:40 +04:00
|
|
|
hideAboutHome();
|
2013-03-07 14:17:32 +04:00
|
|
|
}
|
2013-01-29 22:58:09 +04:00
|
|
|
|
2013-02-02 02:19:47 +04:00
|
|
|
// Dismiss any SiteIdentity Popup
|
|
|
|
SiteIdentityPopup.getInstance().dismiss();
|
|
|
|
|
2013-01-29 22:58:09 +04:00
|
|
|
final TabsPanel.Panel panel = tab.isPrivate()
|
|
|
|
? TabsPanel.Panel.PRIVATE_TABS
|
|
|
|
: TabsPanel.Panel.NORMAL_TABS;
|
2013-02-27 02:38:10 +04:00
|
|
|
// Delay calling showTabs so that it does not modify the mTabsChangedListeners
|
|
|
|
// array while we are still iterating through the array.
|
2013-03-15 14:52:53 +04:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2013-02-14 21:50:11 +04:00
|
|
|
public void run() {
|
|
|
|
if (areTabsShown() && mTabsPanel.getCurrentPanel() != panel)
|
2013-01-29 22:58:09 +04:00
|
|
|
showTabs(panel);
|
2013-02-14 21:50:11 +04:00
|
|
|
}
|
|
|
|
});
|
2012-06-12 02:18:40 +04:00
|
|
|
}
|
|
|
|
break;
|
2013-03-07 01:11:05 +04:00
|
|
|
case START:
|
2013-03-07 14:17:32 +04:00
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
|
2013-03-07 14:17:34 +04:00
|
|
|
if (mDynamicToolbarEnabled) {
|
|
|
|
// Show the toolbar.
|
2013-03-17 05:53:40 +04:00
|
|
|
mBrowserToolbar.animateVisibility(true);
|
2013-03-07 14:17:34 +04:00
|
|
|
}
|
2013-03-07 14:17:32 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LOAD_ERROR:
|
2012-06-15 07:12:06 +04:00
|
|
|
case STOP:
|
2012-07-25 03:12:12 +04:00
|
|
|
case MENU_UPDATED:
|
2012-06-15 07:12:06 +04:00
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
}
|
|
|
|
break;
|
2013-02-25 08:51:05 +04:00
|
|
|
case PAGE_SHOW:
|
2013-02-27 02:38:10 +04:00
|
|
|
loadFavicon(tab);
|
2013-02-25 08:51:05 +04:00
|
|
|
break;
|
2013-04-03 23:34:51 +04:00
|
|
|
case LINK_FAVICON:
|
2013-02-27 02:38:10 +04:00
|
|
|
// If tab is not loading and the favicon is updated, we
|
|
|
|
// want to load the image straight away. If tab is still
|
|
|
|
// loading, we only load the favicon once the page's content
|
|
|
|
// is fully loaded.
|
|
|
|
if (tab.getState() != Tab.STATE_LOADING) {
|
|
|
|
loadFavicon(tab);
|
|
|
|
}
|
2013-02-25 08:51:04 +04:00
|
|
|
break;
|
2012-06-12 02:18:40 +04:00
|
|
|
}
|
|
|
|
super.onTabChanged(tab, msg, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
void handleClearHistory() {
|
|
|
|
super.handleClearHistory();
|
2012-11-07 19:45:35 +04:00
|
|
|
updateAboutHomeTopSites();
|
2012-06-12 02:18:40 +04:00
|
|
|
}
|
|
|
|
|
2013-03-07 14:17:32 +04:00
|
|
|
@Override
|
|
|
|
public boolean onInterceptTouchEvent(View view, MotionEvent event) {
|
2013-03-17 05:53:41 +04:00
|
|
|
if (!mDynamicToolbarEnabled || mToolbarPinned) {
|
2013-03-07 14:17:34 +04:00
|
|
|
return super.onInterceptTouchEvent(view, event);
|
|
|
|
}
|
|
|
|
|
2013-03-21 15:23:49 +04:00
|
|
|
// Don't let the toolbar scroll at all if the page is shorter than
|
|
|
|
// the screen height.
|
|
|
|
ImmutableViewportMetrics metrics =
|
|
|
|
mLayerView.getLayerClient().getViewportMetrics();
|
|
|
|
if (metrics.getPageHeight() < metrics.getHeight()) {
|
|
|
|
return super.onInterceptTouchEvent(view, event);
|
|
|
|
}
|
|
|
|
|
2013-03-07 14:17:32 +04:00
|
|
|
int action = event.getActionMasked();
|
|
|
|
int pointerCount = event.getPointerCount();
|
|
|
|
|
2013-03-07 14:17:33 +04:00
|
|
|
// Whenever there are no pointers left on the screen, tell the page
|
|
|
|
// to clamp the viewport on fixed layer margin changes. This lets the
|
|
|
|
// toolbar scrolling off the top of the page make the page scroll up
|
|
|
|
// if it'd cause the page to go into overscroll, but only when there
|
|
|
|
// are no pointers held down.
|
|
|
|
mLayerView.getLayerClient().setClampOnFixedLayerMarginsChange(
|
|
|
|
pointerCount == 0 || action == MotionEvent.ACTION_CANCEL ||
|
|
|
|
action == MotionEvent.ACTION_UP);
|
|
|
|
|
2013-03-07 14:17:32 +04:00
|
|
|
View toolbarView = mBrowserToolbar.getLayout();
|
|
|
|
if (action == MotionEvent.ACTION_DOWN ||
|
|
|
|
action == MotionEvent.ACTION_POINTER_DOWN) {
|
|
|
|
if (pointerCount == 1) {
|
2013-03-12 21:58:13 +04:00
|
|
|
mToolbarLocked = mToolbarThresholdPassed = false;
|
2013-03-07 14:17:32 +04:00
|
|
|
mToolbarSubpixelAccumulation = 0.0f;
|
2013-03-12 21:58:13 +04:00
|
|
|
mLastTouchX = event.getX();
|
2013-03-07 14:17:32 +04:00
|
|
|
mLastTouchY = event.getY();
|
|
|
|
return super.onInterceptTouchEvent(view, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Animate the toolbar to the fully on/off position.
|
|
|
|
mBrowserToolbar.animateVisibility(
|
|
|
|
toolbarView.getScrollY() > toolbarView.getHeight() / 2 ?
|
2013-03-17 05:53:40 +04:00
|
|
|
false : true);
|
2013-03-07 14:17:32 +04:00
|
|
|
}
|
|
|
|
|
2013-03-12 21:58:13 +04:00
|
|
|
// If more than one pointer has been tracked, or we've locked the
|
|
|
|
// toolbar movement, let the event pass through and be handled by the
|
|
|
|
// PanZoomController for zooming.
|
|
|
|
if (pointerCount > 1 || mToolbarLocked) {
|
2013-03-07 14:17:32 +04:00
|
|
|
return super.onInterceptTouchEvent(view, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If a pointer has been lifted so that there's only one pointer left,
|
|
|
|
// unlock the toolbar and track that remaining pointer.
|
|
|
|
if (pointerCount == 1 && action == MotionEvent.ACTION_POINTER_UP) {
|
|
|
|
mLastTouchY = event.getY(1 - event.getActionIndex());
|
|
|
|
return super.onInterceptTouchEvent(view, event);
|
|
|
|
}
|
|
|
|
|
2013-03-17 05:53:40 +04:00
|
|
|
// Handle scrolling the toolbar
|
2013-03-12 21:58:13 +04:00
|
|
|
float eventX = event.getX();
|
2013-03-07 14:17:32 +04:00
|
|
|
float eventY = event.getY();
|
2013-03-17 05:53:40 +04:00
|
|
|
float deltaX = mLastTouchX - eventX;
|
|
|
|
float deltaY = mLastTouchY - eventY;
|
|
|
|
int toolbarY = toolbarView.getScrollY();
|
|
|
|
int toolbarHeight = toolbarView.getHeight();
|
|
|
|
|
|
|
|
// Check if we've passed the toolbar movement threshold
|
|
|
|
if (!mToolbarThresholdPassed) {
|
|
|
|
float threshold = toolbarHeight * TOOLBAR_MOVEMENT_THRESHOLD;
|
|
|
|
if (Math.abs(deltaY) > threshold) {
|
|
|
|
mToolbarThresholdPassed = true;
|
|
|
|
// If we're scrolling downwards and the toolbar was hidden
|
|
|
|
// when we started scrolling, lock it.
|
|
|
|
if (deltaY > 0 && toolbarY == toolbarHeight) {
|
2013-03-12 21:58:13 +04:00
|
|
|
mToolbarLocked = true;
|
|
|
|
return super.onInterceptTouchEvent(view, event);
|
|
|
|
}
|
2013-03-17 05:53:40 +04:00
|
|
|
} else if (Math.abs(deltaX) > threshold) {
|
|
|
|
// Any horizontal scrolling past the threshold should
|
|
|
|
// initiate toolbar lock.
|
|
|
|
mToolbarLocked = true;
|
|
|
|
mToolbarThresholdPassed = true;
|
|
|
|
return super.onInterceptTouchEvent(view, event);
|
|
|
|
} else {
|
|
|
|
// The threshold hasn't been passed. We don't want to update
|
|
|
|
// the stored last touch position, so return here.
|
|
|
|
return super.onInterceptTouchEvent(view, event);
|
|
|
|
}
|
|
|
|
} else if (action == MotionEvent.ACTION_MOVE) {
|
|
|
|
// Cancel any ongoing animation before we start moving the toolbar.
|
|
|
|
mBrowserToolbar.cancelVisibilityAnimation();
|
|
|
|
|
|
|
|
// Move the toolbar by the amount the touch event has moved,
|
|
|
|
// clamping to fully visible or fully hidden.
|
|
|
|
|
|
|
|
// Don't let the toolbar scroll off the top if it's just exposing
|
|
|
|
// overscroll area.
|
|
|
|
float toolbarMaxY = Math.min(toolbarHeight,
|
|
|
|
Math.max(0, toolbarHeight - (metrics.pageRectTop -
|
|
|
|
metrics.viewportRectTop)));
|
|
|
|
|
|
|
|
float newToolbarYf = Math.max(0, Math.min(toolbarMaxY,
|
|
|
|
toolbarY + deltaY + mToolbarSubpixelAccumulation));
|
|
|
|
int newToolbarY = Math.round(newToolbarYf);
|
|
|
|
mToolbarSubpixelAccumulation = (newToolbarYf - newToolbarY);
|
|
|
|
|
|
|
|
toolbarView.scrollTo(0, newToolbarY);
|
|
|
|
|
|
|
|
// Reset tracking when the toolbar is fully visible or hidden.
|
|
|
|
if (newToolbarY == 0 || newToolbarY == toolbarHeight) {
|
|
|
|
mLastTouchY = eventY;
|
2013-03-07 14:17:32 +04:00
|
|
|
}
|
2013-03-17 05:53:40 +04:00
|
|
|
} else if (action == MotionEvent.ACTION_UP ||
|
|
|
|
action == MotionEvent.ACTION_CANCEL) {
|
|
|
|
// Animate the toolbar to fully on or off, depending on how much
|
|
|
|
// of it is hidden and the current swipe velocity.
|
|
|
|
mBrowserToolbar.animateVisibilityWithVelocityBias(
|
|
|
|
toolbarY > toolbarHeight / 2 ? false : true,
|
|
|
|
mLayerView.getPanZoomController().getVelocityVector().y);
|
2013-03-07 14:17:32 +04:00
|
|
|
}
|
|
|
|
|
2013-03-12 21:58:13 +04:00
|
|
|
// Update the last recorded position.
|
|
|
|
mLastTouchX = eventX;
|
2013-03-07 14:17:32 +04:00
|
|
|
mLastTouchY = eventY;
|
|
|
|
|
|
|
|
return super.onInterceptTouchEvent(view, event);
|
|
|
|
}
|
|
|
|
|
2013-03-12 17:22:01 +04:00
|
|
|
@Override
|
|
|
|
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
|
|
|
// Global onKey handler. This is called if the focused UI doesn't
|
|
|
|
// handle the key event, and before Gecko swallows the events.
|
|
|
|
if (event.getAction() != KeyEvent.ACTION_DOWN) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-13 06:58:41 +04:00
|
|
|
// Gamepad support only exists in API-level >= 9
|
|
|
|
if (Build.VERSION.SDK_INT >= 9 &&
|
2013-03-13 01:34:29 +04:00
|
|
|
(event.getSource() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) {
|
2013-03-13 06:58:41 +04:00
|
|
|
switch (keyCode) {
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_Y:
|
|
|
|
// Toggle/focus the address bar on gamepad-y button.
|
|
|
|
if (mBrowserToolbar.isVisible()) {
|
|
|
|
if (mDynamicToolbarEnabled &&
|
|
|
|
Boolean.FALSE.equals(mAboutHomeShowing)) {
|
2013-03-17 05:53:40 +04:00
|
|
|
mBrowserToolbar.animateVisibility(false);
|
2013-03-13 06:58:41 +04:00
|
|
|
mLayerView.requestFocus();
|
|
|
|
} else {
|
|
|
|
// Just focus the address bar when about:home is visible
|
|
|
|
// or when the dynamic toolbar isn't enabled.
|
|
|
|
mBrowserToolbar.requestFocusFromTouch();
|
|
|
|
}
|
|
|
|
} else {
|
2013-03-17 05:53:40 +04:00
|
|
|
mBrowserToolbar.animateVisibility(true);
|
2013-03-13 06:58:41 +04:00
|
|
|
mBrowserToolbar.requestFocusFromTouch();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_L1:
|
|
|
|
// Go back on L1
|
|
|
|
Tabs.getInstance().getSelectedTab().doBack();
|
|
|
|
return true;
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_R1:
|
|
|
|
// Go forward on R1
|
|
|
|
Tabs.getInstance().getSelectedTab().doForward();
|
|
|
|
return true;
|
2013-03-12 17:22:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-09 01:28:56 +04:00
|
|
|
// Check if this was a shortcut. Meta keys exists only on 11+.
|
|
|
|
final Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (Build.VERSION.SDK_INT >= 11 && tab != null && event.isCtrlPressed()) {
|
|
|
|
switch (keyCode) {
|
|
|
|
case KeyEvent.KEYCODE_LEFT_BRACKET:
|
|
|
|
tab.doBack();
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case KeyEvent.KEYCODE_RIGHT_BRACKET:
|
|
|
|
tab.doForward();
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case KeyEvent.KEYCODE_R:
|
|
|
|
tab.doReload();
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case KeyEvent.KEYCODE_PERIOD:
|
|
|
|
tab.doStop();
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case KeyEvent.KEYCODE_T:
|
|
|
|
addTab();
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case KeyEvent.KEYCODE_W:
|
|
|
|
Tabs.getInstance().closeTab(tab);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case KeyEvent.KEYCODE_F:
|
|
|
|
mFindInPageBar.show();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-12 17:22:01 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
|
if (onKey(null, keyCode, event)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
|
}
|
|
|
|
|
2013-02-25 08:51:04 +04:00
|
|
|
void handleReaderAdded(boolean success, final String title, final String url) {
|
|
|
|
if (!success) {
|
|
|
|
showToast(R.string.reading_list_failed, Toast.LENGTH_SHORT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-15 14:52:53 +04:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2013-02-25 08:51:04 +04:00
|
|
|
public void run() {
|
|
|
|
BrowserDB.addReadingListItem(getContentResolver(), title, url);
|
|
|
|
showToast(R.string.reading_list_added, Toast.LENGTH_SHORT);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleReaderRemoved(final String url) {
|
2013-03-15 14:52:53 +04:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2013-02-25 08:51:04 +04:00
|
|
|
public void run() {
|
|
|
|
BrowserDB.removeReadingListItemWithURL(getContentResolver(), url);
|
|
|
|
showToast(R.string.reading_list_removed, Toast.LENGTH_SHORT);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-06-12 02:18:40 +04:00
|
|
|
@Override
|
|
|
|
void onStatePurged() {
|
2013-03-15 14:52:53 +04:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-06-12 02:18:40 +04:00
|
|
|
public void run() {
|
|
|
|
if (mAboutHomeContent != null)
|
|
|
|
mAboutHomeContent.setLastTabsVisibility(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
super.onStatePurged();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2012-11-27 02:57:11 +04:00
|
|
|
mAboutHomeStartupTimer = new Telemetry.Timer("FENNEC_STARTUP_TIME_ABOUTHOME");
|
|
|
|
|
2012-06-12 02:18:40 +04:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2012-07-20 23:58:42 +04:00
|
|
|
LinearLayout actionBar = (LinearLayout) getActionBarLayout();
|
2013-03-07 14:17:34 +04:00
|
|
|
mMainLayout.addView(actionBar, 2);
|
2012-06-12 02:18:40 +04:00
|
|
|
|
2013-03-28 20:40:06 +04:00
|
|
|
((GeckoApp.MainLayout) mMainLayout).setTouchEventInterceptor(new HideTabsTouchListener());
|
2013-03-28 20:40:06 +04:00
|
|
|
((GeckoApp.MainLayout) mMainLayout).setMotionEventInterceptor(new MotionEventInterceptor() {
|
|
|
|
@Override
|
|
|
|
public boolean onInterceptMotionEvent(View view, MotionEvent event) {
|
|
|
|
// If we get a gamepad panning MotionEvent while the focus is not on the layerview,
|
|
|
|
// put the focus on the layerview and carry on
|
|
|
|
LayerView layerView = mLayerView;
|
|
|
|
if (layerView != null && !layerView.hasFocus() && GamepadUtils.isPanningControl(event)) {
|
2013-04-03 19:59:22 +04:00
|
|
|
if (Boolean.FALSE.equals(mAboutHomeShowing)) {
|
|
|
|
layerView.requestFocus();
|
|
|
|
} else {
|
|
|
|
mAboutHomeContent.requestFocus();
|
|
|
|
}
|
2013-03-28 20:40:06 +04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-10-13 03:23:20 +04:00
|
|
|
|
2012-07-28 10:15:39 +04:00
|
|
|
mBrowserToolbar = new BrowserToolbar(this);
|
2012-06-12 02:18:40 +04:00
|
|
|
mBrowserToolbar.from(actionBar);
|
|
|
|
|
2013-03-12 17:22:01 +04:00
|
|
|
// Intercept key events for gamepad shortcuts
|
|
|
|
actionBar.setOnKeyListener(this);
|
|
|
|
|
2013-02-22 11:22:37 +04:00
|
|
|
if (mTabsPanel != null) {
|
2012-06-13 09:47:52 +04:00
|
|
|
mTabsPanel.setTabsLayoutChangeListener(this);
|
2013-02-22 11:22:37 +04:00
|
|
|
updateSideBarState();
|
|
|
|
}
|
2012-06-13 09:47:52 +04:00
|
|
|
|
2012-07-27 10:52:41 +04:00
|
|
|
mFindInPageBar = (FindInPageBar) findViewById(R.id.find_in_page);
|
|
|
|
|
2012-08-28 04:50:32 +04:00
|
|
|
registerEventListener("CharEncoding:Data");
|
|
|
|
registerEventListener("CharEncoding:State");
|
2012-08-27 08:33:11 +04:00
|
|
|
registerEventListener("Feedback:LastUrl");
|
|
|
|
registerEventListener("Feedback:OpenPlayStore");
|
|
|
|
registerEventListener("Feedback:MaybeLater");
|
2012-11-03 04:44:20 +04:00
|
|
|
registerEventListener("Telemetry:Gather");
|
2013-02-02 03:45:33 +04:00
|
|
|
|
2013-02-19 22:15:55 +04:00
|
|
|
Distribution.init(this, getPackageResourcePath());
|
2013-02-16 00:21:41 +04:00
|
|
|
JavaAddonManager.getInstance().init(getApplicationContext());
|
2013-03-05 17:06:09 +04:00
|
|
|
|
2013-03-08 04:15:54 +04:00
|
|
|
if (Build.VERSION.SDK_INT >= 14) {
|
2013-03-05 17:06:09 +04:00
|
|
|
NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
|
|
|
|
if (nfc != null) {
|
|
|
|
nfc.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {
|
|
|
|
@Override
|
|
|
|
public NdefMessage createNdefMessage(NfcEvent event) {
|
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab == null || tab.isPrivate()) {
|
|
|
|
return null;
|
|
|
|
}
|
2013-03-10 02:52:43 +04:00
|
|
|
return new NdefMessage(new NdefRecord[] { NdefRecord.createUri(tab.getURL()) });
|
2013-03-05 17:06:09 +04:00
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
}
|
|
|
|
}
|
2013-03-07 14:17:34 +04:00
|
|
|
|
2013-03-12 22:32:26 +04:00
|
|
|
// Listen to the dynamic toolbar pref
|
2013-03-18 20:41:36 +04:00
|
|
|
mPrefObserverId = PrefsHelper.getPref(PREF_CHROME_DYNAMICTOOLBAR, new PrefsHelper.PrefHandlerBase() {
|
2013-03-07 14:17:34 +04:00
|
|
|
@Override
|
|
|
|
public void prefValue(String pref, boolean value) {
|
|
|
|
if (value == mDynamicToolbarEnabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mDynamicToolbarEnabled = value;
|
|
|
|
|
2013-03-15 14:52:53 +04:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-03-07 14:17:34 +04:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (mDynamicToolbarEnabled) {
|
2013-03-22 14:26:26 +04:00
|
|
|
setToolbarMargin(0);
|
2013-03-07 14:17:34 +04:00
|
|
|
} else {
|
|
|
|
// Immediately show the toolbar when disabling the dynamic
|
|
|
|
// toolbar.
|
2013-04-11 20:33:59 +04:00
|
|
|
if (mAboutHomeContent != null) {
|
|
|
|
mAboutHomeContent.setPadding(0, 0, 0, 0);
|
|
|
|
}
|
2013-03-07 14:17:34 +04:00
|
|
|
mBrowserToolbar.cancelVisibilityAnimation();
|
|
|
|
mBrowserToolbar.getLayout().scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Refresh the margins to reset the padding on the spacer and
|
|
|
|
// make sure that Gecko is in sync.
|
|
|
|
((BrowserToolbarLayout)mBrowserToolbar.getLayout()).refreshMargins();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-03-12 22:32:26 +04:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isObserver() {
|
|
|
|
// We want to be notified of changes to be able to switch mode
|
|
|
|
// without restarting.
|
|
|
|
return true;
|
|
|
|
}
|
2013-03-07 14:17:34 +04:00
|
|
|
});
|
2012-06-12 02:18:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
2013-03-18 20:41:36 +04:00
|
|
|
if (mPrefObserverId != null) {
|
|
|
|
PrefsHelper.removeObserver(mPrefObserverId);
|
|
|
|
mPrefObserverId = null;
|
|
|
|
}
|
2012-06-12 02:18:40 +04:00
|
|
|
if (mAboutHomeContent != null)
|
|
|
|
mAboutHomeContent.onDestroy();
|
2013-01-25 22:51:41 +04:00
|
|
|
if (mBrowserToolbar != null)
|
|
|
|
mBrowserToolbar.onDestroy();
|
2012-08-27 08:33:11 +04:00
|
|
|
|
2012-08-28 04:50:32 +04:00
|
|
|
unregisterEventListener("CharEncoding:Data");
|
|
|
|
unregisterEventListener("CharEncoding:State");
|
2012-08-27 08:33:11 +04:00
|
|
|
unregisterEventListener("Feedback:LastUrl");
|
|
|
|
unregisterEventListener("Feedback:OpenPlayStore");
|
|
|
|
unregisterEventListener("Feedback:MaybeLater");
|
2012-11-03 04:44:20 +04:00
|
|
|
unregisterEventListener("Telemetry:Gather");
|
2013-03-05 17:06:09 +04:00
|
|
|
|
2013-03-08 04:15:54 +04:00
|
|
|
if (Build.VERSION.SDK_INT >= 14) {
|
2013-03-05 17:06:09 +04:00
|
|
|
NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
|
|
|
|
if (nfc != null) {
|
|
|
|
// null this out even though the docs say it's not needed,
|
|
|
|
// because the source code looks like it will only do this
|
|
|
|
// automatically on API 14+
|
|
|
|
nfc.setNdefPushMessageCallback(null, this);
|
|
|
|
}
|
|
|
|
}
|
2013-03-20 01:09:44 +04:00
|
|
|
|
|
|
|
super.onDestroy();
|
2012-06-12 02:18:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onContentChanged() {
|
|
|
|
super.onContentChanged();
|
|
|
|
if (mAboutHomeContent != null)
|
2012-07-28 10:31:42 +04:00
|
|
|
mAboutHomeContent.onActivityContentChanged();
|
2012-06-12 02:18:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void finishProfileMigration() {
|
|
|
|
// Update about:home with the new information.
|
|
|
|
updateAboutHomeTopSites();
|
|
|
|
|
|
|
|
super.finishProfileMigration();
|
|
|
|
}
|
|
|
|
|
2012-10-15 21:40:16 +04:00
|
|
|
@Override
|
2012-12-07 22:50:56 +04:00
|
|
|
protected void initializeChrome(String uri, boolean isExternalURL) {
|
2012-10-15 21:40:16 +04:00
|
|
|
super.initializeChrome(uri, isExternalURL);
|
|
|
|
|
2012-06-12 02:18:40 +04:00
|
|
|
mBrowserToolbar.updateBackButton(false);
|
|
|
|
mBrowserToolbar.updateForwardButton(false);
|
2013-04-08 19:35:00 +04:00
|
|
|
|
|
|
|
// Reset mToolbarHeight before setting margins so we force the
|
|
|
|
// Viewport:FixedMarginsChanged message to be sent again now that
|
|
|
|
// Gecko has loaded.
|
|
|
|
mToolbarHeight = 0;
|
2013-03-07 14:17:33 +04:00
|
|
|
((BrowserToolbarLayout)mBrowserToolbar.getLayout()).refreshMargins();
|
2012-06-12 02:18:40 +04:00
|
|
|
|
2013-01-04 04:33:38 +04:00
|
|
|
mDoorHangerPopup.setAnchor(mBrowserToolbar.mFavicon);
|
2012-10-15 21:40:16 +04:00
|
|
|
|
2012-12-07 22:50:56 +04:00
|
|
|
if (isExternalURL || mRestoreMode != RESTORE_NONE) {
|
|
|
|
mAboutHomeStartupTimer.cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mIsRestoringActivity) {
|
|
|
|
if (!isExternalURL) {
|
|
|
|
// show about:home if we aren't restoring previous session
|
|
|
|
if (mRestoreMode == RESTORE_NONE) {
|
|
|
|
Tab tab = Tabs.getInstance().loadUrl("about:home", Tabs.LOADURL_NEW_TAB);
|
|
|
|
} else {
|
|
|
|
hideAboutHome();
|
|
|
|
}
|
2012-10-30 03:34:29 +04:00
|
|
|
} else {
|
2012-12-07 22:50:56 +04:00
|
|
|
int flags = Tabs.LOADURL_NEW_TAB | Tabs.LOADURL_USER_ENTERED;
|
|
|
|
Tabs.getInstance().loadUrl(uri, flags);
|
2012-06-12 02:18:40 +04:00
|
|
|
}
|
|
|
|
}
|
2013-03-12 17:22:01 +04:00
|
|
|
|
|
|
|
// Intercept key events for gamepad shortcuts
|
|
|
|
mLayerView.setOnKeyListener(this);
|
2012-06-12 02:18:40 +04:00
|
|
|
}
|
|
|
|
|
2013-03-22 14:26:26 +04:00
|
|
|
private void setSidebarMargin(int margin) {
|
|
|
|
((RelativeLayout.LayoutParams) mGeckoLayout.getLayoutParams()).leftMargin = margin;
|
|
|
|
mGeckoLayout.requestLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setToolbarMargin(int margin) {
|
|
|
|
((RelativeLayout.LayoutParams) mGeckoLayout.getLayoutParams()).topMargin = margin;
|
|
|
|
mGeckoLayout.requestLayout();
|
|
|
|
}
|
|
|
|
|
2013-03-07 14:17:34 +04:00
|
|
|
public void setToolbarHeight(int aHeight, int aVisibleHeight) {
|
|
|
|
if (!mDynamicToolbarEnabled || Boolean.TRUE.equals(mAboutHomeShowing)) {
|
|
|
|
// Use aVisibleHeight here so that when the dynamic toolbar is
|
|
|
|
// enabled, the padding will animate with the toolbar becoming
|
|
|
|
// visible.
|
|
|
|
if (mDynamicToolbarEnabled) {
|
|
|
|
// When the dynamic toolbar is enabled, set the padding on the
|
|
|
|
// about:home widget directly - this is to avoid resizing the
|
|
|
|
// LayerView, which can cause visible artifacts.
|
|
|
|
mAboutHomeContent.setPadding(0, aVisibleHeight, 0, 0);
|
|
|
|
} else {
|
2013-03-22 14:26:26 +04:00
|
|
|
setToolbarMargin(aVisibleHeight);
|
2013-03-07 14:17:34 +04:00
|
|
|
}
|
|
|
|
aHeight = aVisibleHeight = 0;
|
|
|
|
} else {
|
2013-03-22 14:26:26 +04:00
|
|
|
setToolbarMargin(0);
|
2013-03-07 14:17:34 +04:00
|
|
|
}
|
|
|
|
|
2013-03-18 19:43:03 +04:00
|
|
|
// Update the Gecko-side global for fixed viewport margins.
|
|
|
|
if (aHeight != mToolbarHeight) {
|
|
|
|
mToolbarHeight = aHeight;
|
|
|
|
|
|
|
|
// In the current UI, this is the only place we have need of
|
|
|
|
// viewport margins (to stop the toolbar from obscuring fixed-pos
|
|
|
|
// content).
|
|
|
|
GeckoAppShell.sendEventToGecko(
|
|
|
|
GeckoEvent.createBroadcastEvent("Viewport:FixedMarginsChanged",
|
|
|
|
"{ \"top\" : " + aHeight + ", \"right\" : 0, \"bottom\" : 0, \"left\" : 0 }"));
|
|
|
|
}
|
2013-03-07 14:17:34 +04:00
|
|
|
|
|
|
|
if (mLayerView != null) {
|
|
|
|
mLayerView.getLayerClient().setFixedLayerMargins(0, aVisibleHeight, 0, 0);
|
2013-03-18 19:43:03 +04:00
|
|
|
|
|
|
|
// Force a redraw when the view isn't moving and the toolbar is
|
|
|
|
// fully visible or fully hidden. This is to make sure that the
|
|
|
|
// Gecko-side fixed viewport margins are in sync when the view and
|
|
|
|
// bar aren't animating.
|
|
|
|
PointF velocityVector = mLayerView.getPanZoomController().getVelocityVector();
|
|
|
|
if ((aVisibleHeight == 0 || aVisibleHeight == aHeight) &&
|
|
|
|
FloatUtils.fuzzyEquals(velocityVector.x, 0.0f) &&
|
|
|
|
FloatUtils.fuzzyEquals(velocityVector.y, 0.0f)) {
|
|
|
|
mLayerView.getLayerClient().forceRedraw();
|
|
|
|
}
|
2013-03-07 14:17:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 00:18:01 +04:00
|
|
|
@Override
|
2012-06-12 02:18:40 +04:00
|
|
|
void toggleChrome(final boolean aShow) {
|
2013-03-15 14:52:53 +04:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-06-12 02:18:40 +04:00
|
|
|
public void run() {
|
|
|
|
if (aShow) {
|
|
|
|
mBrowserToolbar.show();
|
|
|
|
} else {
|
|
|
|
mBrowserToolbar.hide();
|
2012-11-28 00:18:16 +04:00
|
|
|
if (hasTabsSideBar()) {
|
|
|
|
hideTabs();
|
|
|
|
}
|
2012-06-12 02:18:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
super.toggleChrome(aShow);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
void focusChrome() {
|
2013-03-15 14:52:53 +04:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-06-12 02:18:40 +04:00
|
|
|
public void run() {
|
2012-11-26 23:56:46 +04:00
|
|
|
mBrowserToolbar.show();
|
2012-06-12 02:18:40 +04:00
|
|
|
mBrowserToolbar.requestFocusFromTouch();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void refreshChrome() {
|
2012-06-20 01:09:44 +04:00
|
|
|
// Only ICS phones use a smaller action-bar in landscape mode.
|
2013-04-02 18:03:39 +04:00
|
|
|
if (Build.VERSION.SDK_INT >= 14 && !HardwareUtils.isTablet()) {
|
2012-06-20 01:09:44 +04:00
|
|
|
int index = mMainLayout.indexOfChild(mBrowserToolbar.getLayout());
|
|
|
|
mMainLayout.removeViewAt(index);
|
|
|
|
|
2012-07-20 23:58:42 +04:00
|
|
|
LinearLayout actionBar = (LinearLayout) getActionBarLayout();
|
2012-06-20 01:09:44 +04:00
|
|
|
mMainLayout.addView(actionBar, index);
|
|
|
|
mBrowserToolbar.from(actionBar);
|
2012-06-12 02:18:40 +04:00
|
|
|
mBrowserToolbar.refresh();
|
2012-08-09 19:31:05 +04:00
|
|
|
|
|
|
|
// The favicon view is different now, so we need to update the DoorHangerPopup anchor view.
|
|
|
|
if (mDoorHangerPopup != null)
|
|
|
|
mDoorHangerPopup.setAnchor(mBrowserToolbar.mFavicon);
|
2012-06-12 02:18:40 +04:00
|
|
|
}
|
2012-06-20 01:09:44 +04:00
|
|
|
|
|
|
|
invalidateOptionsMenu();
|
2013-02-22 11:22:37 +04:00
|
|
|
updateSideBarState();
|
2012-06-20 01:09:44 +04:00
|
|
|
mTabsPanel.refresh();
|
2012-08-07 04:27:04 +04:00
|
|
|
|
|
|
|
if (mAboutHomeContent != null)
|
|
|
|
mAboutHomeContent.refresh();
|
2012-06-12 02:18:40 +04:00
|
|
|
}
|
|
|
|
|
2012-12-03 14:50:41 +04:00
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
2013-02-12 04:51:02 +04:00
|
|
|
String url = resultCode == Activity.RESULT_OK ? data.getStringExtra(AwesomeBar.URL_KEY) : null;
|
|
|
|
mBrowserToolbar.fromAwesomeBarSearch(url);
|
2012-12-03 14:50:41 +04:00
|
|
|
}
|
|
|
|
|
2012-07-20 23:58:42 +04:00
|
|
|
public View getActionBarLayout() {
|
2012-07-13 02:03:09 +04:00
|
|
|
int actionBarRes;
|
|
|
|
|
2013-04-02 18:04:21 +04:00
|
|
|
if (!HardwareUtils.hasMenuButton() || HardwareUtils.isTablet())
|
2012-07-13 02:03:09 +04:00
|
|
|
actionBarRes = R.layout.browser_toolbar_menu;
|
|
|
|
else
|
|
|
|
actionBarRes = R.layout.browser_toolbar;
|
|
|
|
|
2012-07-28 10:31:42 +04:00
|
|
|
LinearLayout actionBar = (LinearLayout) LayoutInflater.from(this).inflate(actionBarRes, null);
|
2012-07-13 02:03:09 +04:00
|
|
|
actionBar.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
|
2012-07-28 10:31:42 +04:00
|
|
|
(int) getResources().getDimension(R.dimen.browser_toolbar_height)));
|
2012-07-13 02:03:09 +04:00
|
|
|
return actionBar;
|
|
|
|
}
|
|
|
|
|
2012-07-24 00:08:48 +04:00
|
|
|
@Override
|
|
|
|
public boolean hasTabsSideBar() {
|
|
|
|
return (mTabsPanel != null && mTabsPanel.isSideBar());
|
|
|
|
}
|
|
|
|
|
2013-02-22 11:22:37 +04:00
|
|
|
private void updateSideBarState() {
|
2013-02-22 11:23:16 +04:00
|
|
|
if (mMainLayoutAnimator != null)
|
|
|
|
mMainLayoutAnimator.stop();
|
|
|
|
|
2013-04-02 18:03:39 +04:00
|
|
|
boolean isSideBar = (HardwareUtils.isTablet() && mOrientation == Configuration.ORIENTATION_LANDSCAPE);
|
2013-02-22 11:22:37 +04:00
|
|
|
|
|
|
|
ViewGroup.LayoutParams lp = mTabsPanel.getLayoutParams();
|
|
|
|
if (isSideBar) {
|
|
|
|
lp.width = getResources().getDimensionPixelSize(R.dimen.tabs_sidebar_width);
|
|
|
|
} else {
|
|
|
|
lp.width = ViewGroup.LayoutParams.FILL_PARENT;
|
|
|
|
}
|
|
|
|
mTabsPanel.requestLayout();
|
|
|
|
|
2013-02-22 11:23:16 +04:00
|
|
|
final boolean changed = (mTabsPanel.isSideBar() != isSideBar);
|
|
|
|
final boolean needsRelayout = (changed && mTabsPanel.isShown());
|
|
|
|
|
|
|
|
if (needsRelayout) {
|
|
|
|
final int width;
|
|
|
|
final int scrollY;
|
|
|
|
|
|
|
|
if (isSideBar) {
|
|
|
|
width = lp.width;
|
|
|
|
mMainLayout.scrollTo(0, 0);
|
|
|
|
} else {
|
|
|
|
width = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mBrowserToolbar.adjustForTabsLayout(width);
|
2013-03-22 14:26:26 +04:00
|
|
|
setSidebarMargin(width);
|
2013-02-22 11:23:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (changed) {
|
|
|
|
// Cancel state of previous sidebar state
|
|
|
|
mBrowserToolbar.updateTabs(false);
|
|
|
|
|
|
|
|
mTabsPanel.setIsSideBar(isSideBar);
|
|
|
|
mBrowserToolbar.setIsSideBar(isSideBar);
|
|
|
|
|
|
|
|
// Update with new sidebar state
|
|
|
|
mBrowserToolbar.updateTabs(mTabsPanel.isShown());
|
|
|
|
}
|
2013-02-22 11:22:37 +04:00
|
|
|
}
|
|
|
|
|
2012-07-27 10:53:48 +04:00
|
|
|
@Override
|
|
|
|
public void handleMessage(String event, JSONObject message) {
|
|
|
|
try {
|
|
|
|
if (event.equals("Menu:Add")) {
|
2012-10-27 00:39:25 +04:00
|
|
|
MenuItemInfo info = new MenuItemInfo();
|
|
|
|
info.label = message.getString("name");
|
|
|
|
info.id = message.getInt("id") + ADDON_MENU_OFFSET;
|
2012-10-30 03:29:55 +04:00
|
|
|
info.checkable = false;
|
|
|
|
info.checked = false;
|
|
|
|
info.enabled = true;
|
|
|
|
info.visible = true;
|
2012-07-27 10:53:48 +04:00
|
|
|
String iconRes = null;
|
|
|
|
try { // icon is optional
|
|
|
|
iconRes = message.getString("icon");
|
|
|
|
} catch (Exception ex) { }
|
2012-10-27 00:39:25 +04:00
|
|
|
info.icon = iconRes;
|
|
|
|
try {
|
|
|
|
info.checkable = message.getBoolean("checkable");
|
|
|
|
} catch (Exception ex) { }
|
|
|
|
try { // parent is optional
|
|
|
|
info.parent = message.getInt("parent") + ADDON_MENU_OFFSET;
|
|
|
|
} catch (Exception ex) { }
|
|
|
|
final MenuItemInfo menuItemInfo = info;
|
2013-03-15 14:52:53 +04:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-07-27 10:53:48 +04:00
|
|
|
public void run() {
|
2012-10-27 00:39:25 +04:00
|
|
|
addAddonMenuItem(menuItemInfo);
|
2012-07-27 10:53:48 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (event.equals("Menu:Remove")) {
|
2012-09-26 23:02:48 +04:00
|
|
|
final int id = message.getInt("id") + ADDON_MENU_OFFSET;
|
2013-03-15 14:52:53 +04:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-07-27 10:53:48 +04:00
|
|
|
public void run() {
|
|
|
|
removeAddonMenuItem(id);
|
|
|
|
}
|
|
|
|
});
|
2012-10-30 03:29:55 +04:00
|
|
|
} else if (event.equals("Menu:Update")) {
|
|
|
|
final int id = message.getInt("id") + ADDON_MENU_OFFSET;
|
|
|
|
final JSONObject options = message.getJSONObject("options");
|
2013-03-15 14:52:53 +04:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-10-30 03:29:55 +04:00
|
|
|
public void run() {
|
|
|
|
updateAddonMenuItem(id, options);
|
|
|
|
}
|
|
|
|
});
|
2012-08-28 04:50:32 +04:00
|
|
|
} else if (event.equals("CharEncoding:Data")) {
|
|
|
|
final JSONArray charsets = message.getJSONArray("charsets");
|
|
|
|
int selected = message.getInt("selected");
|
|
|
|
|
|
|
|
final int len = charsets.length();
|
|
|
|
final String[] titleArray = new String[len];
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
JSONObject charset = charsets.getJSONObject(i);
|
|
|
|
titleArray[i] = charset.getString("title");
|
|
|
|
}
|
|
|
|
|
|
|
|
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
|
|
|
|
dialogBuilder.setSingleChoiceItems(titleArray, selected, new AlertDialog.OnClickListener() {
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-08-28 04:50:32 +04:00
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
try {
|
|
|
|
JSONObject charset = charsets.getJSONObject(which);
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("CharEncoding:Set", charset.getString("code")));
|
|
|
|
dialog.dismiss();
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.e(LOGTAG, "error parsing json", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogBuilder.setNegativeButton(R.string.button_cancel, new AlertDialog.OnClickListener() {
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-08-28 04:50:32 +04:00
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
});
|
2013-03-15 14:52:53 +04:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-08-28 04:50:32 +04:00
|
|
|
public void run() {
|
|
|
|
dialogBuilder.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (event.equals("CharEncoding:State")) {
|
|
|
|
final boolean visible = message.getString("visible").equals("true");
|
|
|
|
GeckoPreferences.setCharEncodingState(visible);
|
|
|
|
final Menu menu = mMenu;
|
2013-03-15 14:52:53 +04:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-08-28 04:50:32 +04:00
|
|
|
public void run() {
|
|
|
|
if (menu != null)
|
|
|
|
menu.findItem(R.id.char_encoding).setVisible(visible);
|
|
|
|
}
|
|
|
|
});
|
2012-08-27 08:33:11 +04:00
|
|
|
} else if (event.equals("Feedback:OpenPlayStore")) {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.setData(Uri.parse("market://details?id=" + getPackageName()));
|
|
|
|
startActivity(intent);
|
|
|
|
} else if (event.equals("Feedback:MaybeLater")) {
|
|
|
|
resetFeedbackLaunchCount();
|
|
|
|
} else if (event.equals("Feedback:LastUrl")) {
|
|
|
|
getLastUrl();
|
2012-08-30 22:15:19 +04:00
|
|
|
} else if (event.equals("Gecko:Ready")) {
|
|
|
|
// Handle this message in GeckoApp, but also enable the Settings
|
|
|
|
// menuitem, which is specific to BrowserApp.
|
|
|
|
super.handleMessage(event, message);
|
|
|
|
final Menu menu = mMenu;
|
2013-03-15 14:52:53 +04:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-08-30 22:15:19 +04:00
|
|
|
public void run() {
|
|
|
|
if (menu != null)
|
|
|
|
menu.findItem(R.id.settings).setEnabled(true);
|
|
|
|
}
|
|
|
|
});
|
2012-11-03 04:44:20 +04:00
|
|
|
} else if (event.equals("Telemetry:Gather")) {
|
|
|
|
Telemetry.HistogramAdd("PLACES_PAGES_COUNT", BrowserDB.getCount(getContentResolver(), "history"));
|
|
|
|
Telemetry.HistogramAdd("PLACES_BOOKMARKS_COUNT", BrowserDB.getCount(getContentResolver(), "bookmarks"));
|
|
|
|
Telemetry.HistogramAdd("FENNEC_FAVICONS_COUNT", BrowserDB.getCount(getContentResolver(), "favicons"));
|
|
|
|
Telemetry.HistogramAdd("FENNEC_THUMBNAILS_COUNT", BrowserDB.getCount(getContentResolver(), "thumbnails"));
|
2013-02-25 08:51:04 +04:00
|
|
|
} else if (event.equals("Reader:Added")) {
|
|
|
|
final boolean success = message.getBoolean("success");
|
|
|
|
final String title = message.getString("title");
|
|
|
|
final String url = message.getString("url");
|
|
|
|
handleReaderAdded(success, title, url);
|
|
|
|
} else if (event.equals("Reader:Removed")) {
|
|
|
|
final String url = message.getString("url");
|
|
|
|
handleReaderRemoved(url);
|
|
|
|
} else if (event.equals("Reader:Share")) {
|
|
|
|
final String title = message.getString("title");
|
|
|
|
final String url = message.getString("url");
|
|
|
|
GeckoAppShell.openUriExternal(url, "text/plain", "", "",
|
|
|
|
Intent.ACTION_SEND, title);
|
2012-07-27 10:53:48 +04:00
|
|
|
} else {
|
|
|
|
super.handleMessage(event, message);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2013-01-03 01:43:01 +04:00
|
|
|
public void addTab() {
|
2012-06-12 02:18:40 +04:00
|
|
|
showAwesomebar(AwesomeBar.Target.NEW_TAB);
|
|
|
|
}
|
|
|
|
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2013-01-03 01:43:01 +04:00
|
|
|
public void addPrivateTab() {
|
2013-01-08 03:29:45 +04:00
|
|
|
Tabs.getInstance().loadUrl("about:privatebrowsing", Tabs.LOADURL_NEW_TAB | Tabs.LOADURL_PRIVATE);
|
2013-01-03 01:43:01 +04:00
|
|
|
}
|
|
|
|
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-12-19 05:04:39 +04:00
|
|
|
public void showNormalTabs() {
|
|
|
|
showTabs(TabsPanel.Panel.NORMAL_TABS);
|
|
|
|
}
|
|
|
|
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-12-19 05:04:39 +04:00
|
|
|
public void showPrivateTabs() {
|
|
|
|
showTabs(TabsPanel.Panel.PRIVATE_TABS);
|
2012-06-12 02:18:40 +04:00
|
|
|
}
|
|
|
|
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-06-12 02:18:40 +04:00
|
|
|
public void showRemoteTabs() {
|
|
|
|
showTabs(TabsPanel.Panel.REMOTE_TABS);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showTabs(TabsPanel.Panel panel) {
|
2013-03-12 03:09:14 +04:00
|
|
|
if (Tabs.getInstance().getDisplayCount() == 0)
|
2012-06-12 02:18:40 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
mTabsPanel.show(panel);
|
|
|
|
}
|
|
|
|
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-06-12 02:18:40 +04:00
|
|
|
public void hideTabs() {
|
|
|
|
mTabsPanel.hide();
|
|
|
|
}
|
|
|
|
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-06-20 00:37:57 +04:00
|
|
|
public boolean autoHideTabs() {
|
2012-07-24 00:08:48 +04:00
|
|
|
if (!hasTabsSideBar() && areTabsShown()) {
|
2012-06-20 00:37:57 +04:00
|
|
|
hideTabs();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-06-12 02:18:40 +04:00
|
|
|
public boolean areTabsShown() {
|
|
|
|
return mTabsPanel.isShown();
|
|
|
|
}
|
|
|
|
|
2012-06-13 09:47:52 +04:00
|
|
|
@Override
|
|
|
|
public void onTabsLayoutChange(int width, int height) {
|
2013-03-21 03:43:47 +04:00
|
|
|
int animationLength = TABS_ANIMATION_DURATION;
|
|
|
|
|
|
|
|
if (mMainLayoutAnimator != null) {
|
|
|
|
animationLength = Math.max(1, animationLength - (int)mMainLayoutAnimator.getRemainingTime());
|
|
|
|
mMainLayoutAnimator.stop(false);
|
|
|
|
}
|
2012-06-13 09:47:52 +04:00
|
|
|
|
2012-07-12 03:11:42 +04:00
|
|
|
if (mTabsPanel.isShown())
|
|
|
|
mTabsPanel.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
|
|
|
|
|
2013-03-21 03:43:47 +04:00
|
|
|
mMainLayoutAnimator = new PropertyAnimator(animationLength, sTabsInterpolator);
|
2012-06-13 09:47:52 +04:00
|
|
|
mMainLayoutAnimator.setPropertyAnimationListener(this);
|
|
|
|
|
2012-10-12 15:57:07 +04:00
|
|
|
boolean usingTextureView = mLayerView.shouldUseTextureView();
|
|
|
|
mMainLayoutAnimator.setUseHardwareLayer(usingTextureView);
|
|
|
|
|
2012-07-24 00:08:48 +04:00
|
|
|
if (hasTabsSideBar()) {
|
2012-10-12 15:57:07 +04:00
|
|
|
mBrowserToolbar.prepareTabsAnimation(mMainLayoutAnimator, width);
|
2012-06-13 09:47:52 +04:00
|
|
|
|
|
|
|
// Set the gecko layout for sliding.
|
|
|
|
if (!mTabsPanel.isShown()) {
|
2013-02-22 11:22:37 +04:00
|
|
|
mGeckoLayout.scrollTo(mTabsPanel.getWidth() * -1, 0);
|
2013-03-22 14:26:26 +04:00
|
|
|
setSidebarMargin(0);
|
2012-06-13 09:47:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mMainLayoutAnimator.attach(mGeckoLayout,
|
2013-02-22 11:22:37 +04:00
|
|
|
PropertyAnimator.Property.SCROLL_X,
|
|
|
|
-width);
|
2012-06-13 09:47:52 +04:00
|
|
|
} else {
|
|
|
|
mMainLayoutAnimator.attach(mMainLayout,
|
2013-02-22 11:22:37 +04:00
|
|
|
PropertyAnimator.Property.SCROLL_Y,
|
|
|
|
-height);
|
2012-06-13 09:47:52 +04:00
|
|
|
}
|
|
|
|
|
2013-03-17 05:53:41 +04:00
|
|
|
// If the tabs layout is animating onto the screen, pin the dynamic
|
|
|
|
// toolbar.
|
|
|
|
if (width > 0 && height > 0) {
|
|
|
|
mToolbarPinned = true;
|
|
|
|
mBrowserToolbar.animateVisibility(true);
|
|
|
|
} else {
|
|
|
|
mToolbarPinned = false;
|
|
|
|
}
|
|
|
|
|
2012-06-13 09:47:52 +04:00
|
|
|
mMainLayoutAnimator.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationStart() {
|
2012-10-12 15:57:07 +04:00
|
|
|
mBrowserToolbar.updateTabs(true);
|
|
|
|
|
|
|
|
// Although the tabs panel is not animating per se, it will be re-drawn several
|
|
|
|
// times while the main/gecko layout slides to left/top. Adding a hardware layer
|
|
|
|
// here considerably improves the frame rate of the animation.
|
|
|
|
if (Build.VERSION.SDK_INT >= 11)
|
|
|
|
mTabsPanel.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
2012-10-15 19:18:30 +04:00
|
|
|
else
|
|
|
|
mTabsPanel.setDrawingCacheEnabled(true);
|
2012-06-13 09:47:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationEnd() {
|
2012-10-12 15:57:07 +04:00
|
|
|
// Destroy the hardware layer used during the animation
|
|
|
|
if (Build.VERSION.SDK_INT >= 11)
|
|
|
|
mTabsPanel.setLayerType(View.LAYER_TYPE_NONE, null);
|
2012-10-15 19:18:30 +04:00
|
|
|
else
|
|
|
|
mTabsPanel.setDrawingCacheEnabled(false);
|
2012-06-14 22:14:00 +04:00
|
|
|
|
2012-11-01 09:07:49 +04:00
|
|
|
if (mTabsPanel.isShown()) {
|
|
|
|
if (hasTabsSideBar()) {
|
2013-03-22 14:26:26 +04:00
|
|
|
setSidebarMargin(mTabsPanel.getWidth());
|
2013-02-22 11:22:37 +04:00
|
|
|
mGeckoLayout.scrollTo(0, 0);
|
2012-11-01 09:07:49 +04:00
|
|
|
}
|
2012-10-12 15:57:07 +04:00
|
|
|
|
|
|
|
mGeckoLayout.requestLayout();
|
2012-11-01 09:07:49 +04:00
|
|
|
} else {
|
2013-02-20 00:39:05 +04:00
|
|
|
mTabsPanel.setVisibility(View.INVISIBLE);
|
2012-10-12 15:57:07 +04:00
|
|
|
mBrowserToolbar.updateTabs(false);
|
|
|
|
mBrowserToolbar.finishTabsAnimation();
|
|
|
|
mTabsPanel.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
|
|
|
|
}
|
2012-11-01 09:07:49 +04:00
|
|
|
|
2012-11-01 09:12:02 +04:00
|
|
|
mBrowserToolbar.refreshBackground();
|
|
|
|
|
2012-11-01 09:07:49 +04:00
|
|
|
if (hasTabsSideBar())
|
|
|
|
mBrowserToolbar.adjustTabsAnimation(true);
|
2013-03-21 03:43:47 +04:00
|
|
|
|
|
|
|
mMainLayoutAnimator = null;
|
2012-06-13 09:47:52 +04:00
|
|
|
}
|
|
|
|
|
2012-06-12 02:18:40 +04:00
|
|
|
/* Favicon methods */
|
|
|
|
private void loadFavicon(final Tab tab) {
|
|
|
|
maybeCancelFaviconLoad(tab);
|
|
|
|
|
2012-12-03 12:59:17 +04:00
|
|
|
long id = Favicons.getInstance().loadFavicon(tab.getURL(), tab.getFaviconURL(), !tab.isPrivate(),
|
2012-06-12 02:18:40 +04:00
|
|
|
new Favicons.OnFaviconLoadedListener() {
|
|
|
|
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-11-05 15:42:25 +04:00
|
|
|
public void onFaviconLoaded(String pageUrl, Bitmap favicon) {
|
2012-06-12 02:18:40 +04:00
|
|
|
// Leave favicon UI untouched if we failed to load the image
|
|
|
|
// for some reason.
|
|
|
|
if (favicon == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// The tab might be pointing to another URL by the time the
|
|
|
|
// favicon is finally loaded, in which case we simply ignore it.
|
|
|
|
if (!tab.getURL().equals(pageUrl))
|
|
|
|
return;
|
|
|
|
|
|
|
|
tab.updateFavicon(favicon);
|
|
|
|
tab.setFaviconLoadId(Favicons.NOT_LOADING);
|
|
|
|
|
|
|
|
Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.FAVICON);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
tab.setFaviconLoadId(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void maybeCancelFaviconLoad(Tab tab) {
|
|
|
|
long faviconLoadId = tab.getFaviconLoadId();
|
|
|
|
|
|
|
|
if (faviconLoadId == Favicons.NOT_LOADING)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Cancel pending favicon load task
|
2012-12-03 12:59:17 +04:00
|
|
|
Favicons.getInstance().cancelFaviconLoad(faviconLoadId);
|
2012-06-12 02:18:40 +04:00
|
|
|
|
|
|
|
// Reset favicon load state
|
|
|
|
tab.setFaviconLoadId(Favicons.NOT_LOADING);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* About:home UI */
|
|
|
|
void updateAboutHomeTopSites() {
|
|
|
|
if (mAboutHomeContent == null)
|
|
|
|
return;
|
|
|
|
|
2012-07-28 10:31:42 +04:00
|
|
|
mAboutHomeContent.update(EnumSet.of(AboutHomeContent.UpdateFlags.TOP_SITES));
|
2012-06-12 02:18:40 +04:00
|
|
|
}
|
|
|
|
|
2012-09-28 20:34:45 +04:00
|
|
|
private void showAboutHome() {
|
|
|
|
// Don't create an additional AboutHomeRunnable if about:home
|
|
|
|
// is already visible.
|
|
|
|
if (mAboutHomeShowing != null && mAboutHomeShowing)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mAboutHomeShowing = true;
|
2012-06-12 02:18:40 +04:00
|
|
|
Runnable r = new AboutHomeRunnable(true);
|
2013-03-15 14:52:53 +04:00
|
|
|
ThreadUtils.getUiHandler().postAtFrontOfQueue(r);
|
2012-06-12 02:18:40 +04:00
|
|
|
}
|
|
|
|
|
2012-09-28 20:34:45 +04:00
|
|
|
private void hideAboutHome() {
|
|
|
|
// If hideAboutHome gets called before showAboutHome, we still need
|
|
|
|
// to create an AboutHomeRunnable to hide the about:home content.
|
|
|
|
if (mAboutHomeShowing != null && !mAboutHomeShowing)
|
|
|
|
return;
|
|
|
|
|
2012-10-30 03:34:29 +04:00
|
|
|
mBrowserToolbar.setShadowVisibility(true);
|
2012-09-28 20:34:45 +04:00
|
|
|
mAboutHomeShowing = false;
|
2012-06-12 02:18:40 +04:00
|
|
|
Runnable r = new AboutHomeRunnable(false);
|
2013-03-15 14:52:53 +04:00
|
|
|
ThreadUtils.getUiHandler().postAtFrontOfQueue(r);
|
2012-06-12 02:18:40 +04:00
|
|
|
}
|
|
|
|
|
2012-09-28 20:34:45 +04:00
|
|
|
private class AboutHomeRunnable implements Runnable {
|
2012-06-12 02:18:40 +04:00
|
|
|
boolean mShow;
|
|
|
|
AboutHomeRunnable(boolean show) {
|
|
|
|
mShow = show;
|
|
|
|
}
|
|
|
|
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-06-12 02:18:40 +04:00
|
|
|
public void run() {
|
|
|
|
if (mShow) {
|
|
|
|
if (mAboutHomeContent == null) {
|
|
|
|
mAboutHomeContent = (AboutHomeContent) findViewById(R.id.abouthome_content);
|
|
|
|
mAboutHomeContent.init();
|
2012-07-28 10:31:42 +04:00
|
|
|
mAboutHomeContent.update(AboutHomeContent.UpdateFlags.ALL);
|
2012-06-12 02:18:40 +04:00
|
|
|
mAboutHomeContent.setUriLoadCallback(new AboutHomeContent.UriLoadCallback() {
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-06-12 02:18:40 +04:00
|
|
|
public void callback(String url) {
|
|
|
|
mBrowserToolbar.setProgressVisibility(true);
|
2012-10-06 01:51:18 +04:00
|
|
|
Tabs.getInstance().loadUrl(url);
|
2012-06-12 02:18:40 +04:00
|
|
|
}
|
|
|
|
});
|
2012-10-02 00:57:00 +04:00
|
|
|
mAboutHomeContent.setLoadCompleteCallback(new AboutHomeContent.VoidCallback() {
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-11-27 02:57:11 +04:00
|
|
|
public void callback() {
|
|
|
|
mAboutHomeStartupTimer.stop();
|
|
|
|
}
|
2012-10-02 00:57:00 +04:00
|
|
|
});
|
2012-06-12 02:18:40 +04:00
|
|
|
} else {
|
2012-07-28 10:31:42 +04:00
|
|
|
mAboutHomeContent.update(EnumSet.of(AboutHomeContent.UpdateFlags.TOP_SITES,
|
2012-06-12 02:18:40 +04:00
|
|
|
AboutHomeContent.UpdateFlags.REMOTE_TABS));
|
|
|
|
}
|
|
|
|
mAboutHomeContent.setVisibility(View.VISIBLE);
|
2013-04-01 21:55:24 +04:00
|
|
|
mBrowserToolbar.setNextFocusDownId(R.id.abouthome_content);
|
2012-06-12 02:18:40 +04:00
|
|
|
} else {
|
|
|
|
findViewById(R.id.abouthome_content).setVisibility(View.GONE);
|
2013-04-01 21:55:24 +04:00
|
|
|
mBrowserToolbar.setNextFocusDownId(R.id.layer_view);
|
2012-06-12 02:18:40 +04:00
|
|
|
}
|
2013-03-11 20:04:55 +04:00
|
|
|
|
|
|
|
// Refresh margins to possibly restore the toolbar padding
|
|
|
|
((BrowserToolbarLayout)mBrowserToolbar.getLayout()).refreshMargins();
|
|
|
|
}
|
2012-06-12 02:18:40 +04:00
|
|
|
}
|
|
|
|
|
2013-03-28 20:40:06 +04:00
|
|
|
private class HideTabsTouchListener implements TouchEventInterceptor {
|
2012-10-13 03:23:20 +04:00
|
|
|
private boolean mIsHidingTabs = false;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onInterceptTouchEvent(View view, MotionEvent event) {
|
|
|
|
// We need to account for scroll state for the touched view otherwise
|
|
|
|
// tapping on an "empty" part of the view will still be considered a
|
|
|
|
// valid touch event.
|
|
|
|
if (view.getScrollX() != 0 || view.getScrollY() != 0) {
|
|
|
|
Rect rect = new Rect();
|
|
|
|
view.getHitRect(rect);
|
|
|
|
rect.offset(-view.getScrollX(), -view.getScrollY());
|
|
|
|
|
|
|
|
int[] viewCoords = new int[2];
|
|
|
|
view.getLocationOnScreen(viewCoords);
|
|
|
|
|
|
|
|
int x = (int) event.getRawX() - viewCoords[0];
|
|
|
|
int y = (int) event.getRawY() - viewCoords[1];
|
|
|
|
|
|
|
|
if (!rect.contains(x, y))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the tab tray is showing, hide the tab tray and don't send the event to content.
|
|
|
|
if (event.getActionMasked() == MotionEvent.ACTION_DOWN && autoHideTabs()) {
|
|
|
|
mIsHidingTabs = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View view, MotionEvent event) {
|
|
|
|
if (mIsHidingTabs) {
|
|
|
|
// Keep consuming events until the gesture finishes.
|
|
|
|
int action = event.getActionMasked();
|
|
|
|
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
|
|
|
|
mIsHidingTabs = false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-27 00:39:25 +04:00
|
|
|
private void addAddonMenuItem(final MenuItemInfo info) {
|
2012-09-27 22:22:08 +04:00
|
|
|
if (mMenu == null) {
|
|
|
|
if (mAddonMenuItemsCache == null)
|
|
|
|
mAddonMenuItemsCache = new Vector<MenuItemInfo>();
|
|
|
|
|
2012-10-27 00:39:25 +04:00
|
|
|
mAddonMenuItemsCache.add(info);
|
2012-07-27 10:53:48 +04:00
|
|
|
return;
|
2012-09-27 22:22:08 +04:00
|
|
|
}
|
2012-07-27 10:53:48 +04:00
|
|
|
|
2012-10-27 00:39:25 +04:00
|
|
|
Menu menu;
|
|
|
|
if (info.parent == 0) {
|
|
|
|
menu = mMenu;
|
|
|
|
} else {
|
|
|
|
MenuItem parent = mMenu.findItem(info.parent);
|
|
|
|
if (parent == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!parent.hasSubMenu()) {
|
|
|
|
mMenu.removeItem(parent.getItemId());
|
|
|
|
menu = mMenu.addSubMenu(Menu.NONE, parent.getItemId(), Menu.NONE, parent.getTitle());
|
|
|
|
if (parent.getIcon() != null)
|
|
|
|
((SubMenu) menu).getItem().setIcon(parent.getIcon());
|
|
|
|
} else {
|
|
|
|
menu = parent.getSubMenu();
|
|
|
|
}
|
|
|
|
}
|
2012-07-27 10:53:48 +04:00
|
|
|
|
2012-10-27 00:39:25 +04:00
|
|
|
final MenuItem item = menu.add(Menu.NONE, info.id, Menu.NONE, info.label);
|
2012-07-27 10:53:48 +04:00
|
|
|
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
Log.i(LOGTAG, "menu item clicked");
|
2012-10-27 00:39:25 +04:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Menu:Clicked", Integer.toString(info.id - ADDON_MENU_OFFSET)));
|
2012-07-27 10:53:48 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-10-27 00:39:25 +04:00
|
|
|
if (info.icon != null) {
|
|
|
|
if (info.icon.startsWith("data")) {
|
|
|
|
BitmapDrawable drawable = new BitmapDrawable(BitmapUtils.getBitmapFromDataURI(info.icon));
|
2012-07-27 10:53:48 +04:00
|
|
|
item.setIcon(drawable);
|
|
|
|
}
|
2012-10-27 00:39:25 +04:00
|
|
|
else if (info.icon.startsWith("jar:") || info.icon.startsWith("file://")) {
|
2013-03-15 14:52:53 +04:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
2012-07-27 10:53:48 +04:00
|
|
|
public void run() {
|
|
|
|
try {
|
2012-10-27 00:39:25 +04:00
|
|
|
URL url = new URL(info.icon);
|
2012-07-27 10:53:48 +04:00
|
|
|
InputStream is = (InputStream) url.getContent();
|
2012-08-31 22:15:50 +04:00
|
|
|
try {
|
|
|
|
Drawable drawable = Drawable.createFromStream(is, "src");
|
|
|
|
item.setIcon(drawable);
|
|
|
|
} finally {
|
|
|
|
is.close();
|
|
|
|
}
|
2012-07-27 10:53:48 +04:00
|
|
|
} catch (Exception e) {
|
|
|
|
Log.w(LOGTAG, "Unable to set icon", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2013-02-21 11:07:06 +04:00
|
|
|
} else {
|
|
|
|
item.setIcon(R.drawable.ic_menu_addons_filler);
|
2012-07-27 10:53:48 +04:00
|
|
|
}
|
2013-02-21 11:07:06 +04:00
|
|
|
} else {
|
|
|
|
item.setIcon(R.drawable.ic_menu_addons_filler);
|
2012-07-27 10:53:48 +04:00
|
|
|
}
|
2012-10-27 00:39:25 +04:00
|
|
|
|
|
|
|
item.setCheckable(info.checkable);
|
2012-10-30 03:29:55 +04:00
|
|
|
item.setChecked(info.checked);
|
|
|
|
item.setEnabled(info.enabled);
|
|
|
|
item.setVisible(info.visible);
|
2012-07-27 10:53:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private void removeAddonMenuItem(int id) {
|
2012-09-27 22:22:08 +04:00
|
|
|
// Remove add-on menu item from cache, if available.
|
|
|
|
if (mAddonMenuItemsCache != null && !mAddonMenuItemsCache.isEmpty()) {
|
|
|
|
for (MenuItemInfo item : mAddonMenuItemsCache) {
|
|
|
|
if (item.id == id) {
|
|
|
|
mAddonMenuItemsCache.remove(item);
|
|
|
|
break;
|
|
|
|
}
|
2012-07-27 10:53:48 +04:00
|
|
|
}
|
|
|
|
}
|
2012-09-27 22:22:08 +04:00
|
|
|
|
|
|
|
if (mMenu == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
MenuItem menuItem = mMenu.findItem(id);
|
|
|
|
if (menuItem != null)
|
|
|
|
mMenu.removeItem(id);
|
2012-07-27 10:53:48 +04:00
|
|
|
}
|
|
|
|
|
2012-10-30 03:29:55 +04:00
|
|
|
private void updateAddonMenuItem(int id, JSONObject options) {
|
|
|
|
// Set attribute for the menu item in cache, if available
|
|
|
|
if (mAddonMenuItemsCache != null && !mAddonMenuItemsCache.isEmpty()) {
|
|
|
|
for (MenuItemInfo item : mAddonMenuItemsCache) {
|
|
|
|
if (item.id == id) {
|
|
|
|
try {
|
|
|
|
item.checkable = options.getBoolean("checkable");
|
|
|
|
} catch (JSONException e) {}
|
|
|
|
|
|
|
|
try {
|
|
|
|
item.checked = options.getBoolean("checked");
|
|
|
|
} catch (JSONException e) {}
|
|
|
|
|
|
|
|
try {
|
|
|
|
item.enabled = options.getBoolean("enabled");
|
|
|
|
} catch (JSONException e) {}
|
|
|
|
|
|
|
|
try {
|
|
|
|
item.visible = options.getBoolean("visible");
|
|
|
|
} catch (JSONException e) {}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mMenu == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
MenuItem menuItem = mMenu.findItem(id);
|
|
|
|
if (menuItem != null) {
|
|
|
|
try {
|
|
|
|
menuItem.setCheckable(options.getBoolean("checkable"));
|
|
|
|
} catch (JSONException e) {}
|
|
|
|
|
|
|
|
try {
|
|
|
|
menuItem.setChecked(options.getBoolean("checked"));
|
|
|
|
} catch (JSONException e) {}
|
|
|
|
|
|
|
|
try {
|
|
|
|
menuItem.setEnabled(options.getBoolean("enabled"));
|
|
|
|
} catch (JSONException e) {}
|
|
|
|
|
|
|
|
try {
|
|
|
|
menuItem.setVisible(options.getBoolean("visible"));
|
|
|
|
} catch (JSONException e) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-12 02:18:40 +04:00
|
|
|
@Override
|
2012-07-27 10:52:41 +04:00
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
super.onCreateOptionsMenu(menu);
|
2012-06-12 02:18:40 +04:00
|
|
|
|
|
|
|
// Inform the menu about the action-items bar.
|
2013-04-02 18:03:39 +04:00
|
|
|
if (menu instanceof GeckoMenu && HardwareUtils.isTablet())
|
2012-06-12 02:18:40 +04:00
|
|
|
((GeckoMenu) menu).setActionItemBarPresenter(mBrowserToolbar);
|
|
|
|
|
|
|
|
MenuInflater inflater = getMenuInflater();
|
2012-07-27 10:52:41 +04:00
|
|
|
inflater.inflate(R.menu.browser_app_menu, mMenu);
|
2012-09-27 22:22:08 +04:00
|
|
|
|
|
|
|
// Add add-on menu items if any.
|
|
|
|
if (mAddonMenuItemsCache != null && !mAddonMenuItemsCache.isEmpty()) {
|
|
|
|
for (MenuItemInfo item : mAddonMenuItemsCache) {
|
2012-10-27 00:39:25 +04:00
|
|
|
addAddonMenuItem(item);
|
2012-09-27 22:22:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mAddonMenuItemsCache.clear();
|
|
|
|
}
|
|
|
|
|
2012-06-12 02:18:40 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void openOptionsMenu() {
|
2012-07-25 08:30:46 +04:00
|
|
|
if (!hasTabsSideBar() && areTabsShown())
|
|
|
|
return;
|
|
|
|
|
2012-06-12 02:18:40 +04:00
|
|
|
// Scroll custom menu to the top
|
|
|
|
if (mMenuPanel != null)
|
|
|
|
mMenuPanel.scrollTo(0, 0);
|
|
|
|
|
|
|
|
if (!mBrowserToolbar.openOptionsMenu())
|
|
|
|
super.openOptionsMenu();
|
2013-03-22 14:26:32 +04:00
|
|
|
|
|
|
|
if (mDynamicToolbarEnabled)
|
|
|
|
mBrowserToolbar.animateVisibility(true);
|
2012-06-12 02:18:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void closeOptionsMenu() {
|
2012-09-19 21:37:35 +04:00
|
|
|
if (!mBrowserToolbar.closeOptionsMenu())
|
2012-06-12 02:18:40 +04:00
|
|
|
super.closeOptionsMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setFullScreen(final boolean fullscreen) {
|
2013-02-27 09:48:00 +04:00
|
|
|
super.setFullScreen(fullscreen);
|
2013-03-15 14:52:53 +04:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-27 09:48:00 +04:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (fullscreen)
|
|
|
|
mBrowserToolbar.hide();
|
|
|
|
else
|
|
|
|
mBrowserToolbar.show();
|
|
|
|
}
|
|
|
|
});
|
2012-06-12 02:18:40 +04:00
|
|
|
}
|
2012-06-18 21:03:03 +04:00
|
|
|
|
|
|
|
@Override
|
2012-07-27 10:52:41 +04:00
|
|
|
public boolean onPrepareOptionsMenu(Menu aMenu) {
|
2012-06-18 21:03:03 +04:00
|
|
|
if (aMenu == null)
|
|
|
|
return false;
|
|
|
|
|
2013-01-23 18:38:57 +04:00
|
|
|
if (!GeckoThread.checkLaunchState(GeckoThread.LaunchState.GeckoRunning))
|
2012-06-18 21:03:03 +04:00
|
|
|
aMenu.findItem(R.id.settings).setEnabled(false);
|
|
|
|
|
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
MenuItem bookmark = aMenu.findItem(R.id.bookmark);
|
|
|
|
MenuItem forward = aMenu.findItem(R.id.forward);
|
|
|
|
MenuItem share = aMenu.findItem(R.id.share);
|
|
|
|
MenuItem saveAsPDF = aMenu.findItem(R.id.save_as_pdf);
|
|
|
|
MenuItem charEncoding = aMenu.findItem(R.id.char_encoding);
|
|
|
|
MenuItem findInPage = aMenu.findItem(R.id.find_in_page);
|
2012-06-22 23:53:40 +04:00
|
|
|
MenuItem desktopMode = aMenu.findItem(R.id.desktop_mode);
|
2012-06-18 21:03:03 +04:00
|
|
|
|
2013-04-02 18:03:39 +04:00
|
|
|
// Only show the "Quit" menu item on pre-ICS or television devices.
|
|
|
|
// In ICS+, it's easy to kill an app through the task switcher.
|
|
|
|
aMenu.findItem(R.id.quit).setVisible(Build.VERSION.SDK_INT < 14 || HardwareUtils.isTelevision());
|
2012-12-11 15:13:15 +04:00
|
|
|
|
2013-04-10 04:10:47 +04:00
|
|
|
if (AppConstants.MOZ_PROFILING) {
|
|
|
|
aMenu.findItem(R.id.toggle_profiling).setVisible(true);
|
|
|
|
}
|
|
|
|
|
2012-06-18 21:03:03 +04:00
|
|
|
if (tab == null || tab.getURL() == null) {
|
|
|
|
bookmark.setEnabled(false);
|
|
|
|
forward.setEnabled(false);
|
|
|
|
share.setEnabled(false);
|
|
|
|
saveAsPDF.setEnabled(false);
|
|
|
|
findInPage.setEnabled(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-29 19:55:54 +04:00
|
|
|
bookmark.setEnabled(!tab.getURL().startsWith("about:reader"));
|
2012-06-18 21:03:03 +04:00
|
|
|
bookmark.setCheckable(true);
|
2012-09-27 22:04:02 +04:00
|
|
|
bookmark.setChecked(tab.isBookmark());
|
|
|
|
bookmark.setIcon(tab.isBookmark() ? R.drawable.ic_menu_bookmark_remove : R.drawable.ic_menu_bookmark_add);
|
2012-06-18 21:03:03 +04:00
|
|
|
|
|
|
|
forward.setEnabled(tab.canDoForward());
|
2012-06-22 23:53:40 +04:00
|
|
|
desktopMode.setChecked(tab.getDesktopMode());
|
2012-09-27 22:04:02 +04:00
|
|
|
desktopMode.setIcon(tab.getDesktopMode() ? R.drawable.ic_menu_desktop_mode_on : R.drawable.ic_menu_desktop_mode_off);
|
2012-06-18 21:03:03 +04:00
|
|
|
|
2012-09-11 21:51:44 +04:00
|
|
|
String url = tab.getURL();
|
2012-11-12 19:58:41 +04:00
|
|
|
if (ReaderModeUtils.isAboutReader(url)) {
|
|
|
|
String urlFromReader = ReaderModeUtils.getUrlFromAboutReader(url);
|
|
|
|
if (urlFromReader != null)
|
|
|
|
url = urlFromReader;
|
|
|
|
}
|
2012-09-11 21:51:44 +04:00
|
|
|
|
2012-06-18 21:03:03 +04:00
|
|
|
// Disable share menuitem for about:, chrome:, file:, and resource: URIs
|
2012-09-11 21:51:44 +04:00
|
|
|
String scheme = Uri.parse(url).getScheme();
|
2012-06-18 21:03:03 +04:00
|
|
|
share.setEnabled(!(scheme.equals("about") || scheme.equals("chrome") ||
|
|
|
|
scheme.equals("file") || scheme.equals("resource")));
|
|
|
|
|
|
|
|
// Disable save as PDF for about:home and xul pages
|
|
|
|
saveAsPDF.setEnabled(!(tab.getURL().equals("about:home") ||
|
|
|
|
tab.getContentType().equals("application/vnd.mozilla.xul+xml")));
|
|
|
|
|
|
|
|
// Disable find in page for about:home, since it won't work on Java content
|
2012-06-26 21:32:55 +04:00
|
|
|
findInPage.setEnabled(!tab.getURL().equals("about:home"));
|
2012-06-18 21:03:03 +04:00
|
|
|
|
|
|
|
charEncoding.setVisible(GeckoPreferences.getCharEncodingState());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2012-07-27 10:52:41 +04:00
|
|
|
|
2012-12-29 01:46:10 +04:00
|
|
|
@Override
|
|
|
|
public boolean onContextItemSelected(MenuItem item) {
|
2013-03-26 21:23:45 +04:00
|
|
|
ContextMenuInfo info = item.getMenuInfo();
|
|
|
|
|
2012-12-29 01:46:10 +04:00
|
|
|
switch (item.getItemId()) {
|
2013-03-26 21:23:45 +04:00
|
|
|
case R.id.abouthome_open_new_tab:
|
|
|
|
mAboutHomeContent.openNewTab(info);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case R.id.abouthome_open_private_tab:
|
|
|
|
mAboutHomeContent.openNewPrivateTab(info);
|
|
|
|
return true;
|
|
|
|
|
2012-12-29 01:46:10 +04:00
|
|
|
case R.id.abouthome_topsites_edit:
|
2013-03-26 21:23:45 +04:00
|
|
|
mAboutHomeContent.editSite(info);
|
2012-12-29 01:46:10 +04:00
|
|
|
return true;
|
|
|
|
|
2013-01-04 23:18:38 +04:00
|
|
|
case R.id.abouthome_topsites_unpin:
|
2013-03-26 02:45:33 +04:00
|
|
|
mAboutHomeContent.unpinSite(info, TopSitesView.UnpinFlags.REMOVE_PIN);
|
2012-12-29 01:46:10 +04:00
|
|
|
return true;
|
|
|
|
|
2013-01-04 23:18:38 +04:00
|
|
|
case R.id.abouthome_topsites_pin:
|
2013-03-26 21:23:45 +04:00
|
|
|
mAboutHomeContent.pinSite(info);
|
2012-12-29 01:46:10 +04:00
|
|
|
return true;
|
2013-01-30 19:20:35 +04:00
|
|
|
|
|
|
|
case R.id.abouthome_topsites_remove:
|
2013-03-26 02:45:33 +04:00
|
|
|
mAboutHomeContent.unpinSite(info, TopSitesView.UnpinFlags.REMOVE_HISTORY);
|
2013-01-30 19:20:35 +04:00
|
|
|
return true;
|
|
|
|
|
2012-12-29 01:46:10 +04:00
|
|
|
}
|
2013-01-03 05:11:14 +04:00
|
|
|
return super.onContextItemSelected(item);
|
2012-12-29 01:46:10 +04:00
|
|
|
}
|
|
|
|
|
2012-07-27 10:52:41 +04:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
2013-04-10 04:10:47 +04:00
|
|
|
if (item.getItemId() == R.id.toggle_profiling) {
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("ToggleProfiling", null));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-27 10:52:41 +04:00
|
|
|
Tab tab = null;
|
|
|
|
Intent intent = null;
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.bookmark:
|
|
|
|
tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null) {
|
|
|
|
if (item.isChecked()) {
|
|
|
|
tab.removeBookmark();
|
|
|
|
Toast.makeText(this, R.string.bookmark_removed, Toast.LENGTH_SHORT).show();
|
|
|
|
item.setIcon(R.drawable.ic_menu_bookmark_add);
|
|
|
|
} else {
|
|
|
|
tab.addBookmark();
|
|
|
|
Toast.makeText(this, R.string.bookmark_added, Toast.LENGTH_SHORT).show();
|
|
|
|
item.setIcon(R.drawable.ic_menu_bookmark_remove);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case R.id.share:
|
|
|
|
shareCurrentUrl();
|
|
|
|
return true;
|
|
|
|
case R.id.reload:
|
|
|
|
tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null)
|
|
|
|
tab.doReload();
|
|
|
|
return true;
|
|
|
|
case R.id.forward:
|
|
|
|
tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null)
|
|
|
|
tab.doForward();
|
|
|
|
return true;
|
|
|
|
case R.id.save_as_pdf:
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SaveAs:PDF", null));
|
|
|
|
return true;
|
|
|
|
case R.id.settings:
|
|
|
|
intent = new Intent(this, GeckoPreferences.class);
|
|
|
|
startActivity(intent);
|
|
|
|
return true;
|
|
|
|
case R.id.addons:
|
2012-10-06 01:51:18 +04:00
|
|
|
Tabs.getInstance().loadUrlInTab("about:addons");
|
2012-07-27 10:52:41 +04:00
|
|
|
return true;
|
|
|
|
case R.id.downloads:
|
2012-10-06 01:51:18 +04:00
|
|
|
Tabs.getInstance().loadUrlInTab("about:downloads");
|
2012-07-27 10:52:41 +04:00
|
|
|
return true;
|
|
|
|
case R.id.apps:
|
2012-10-06 01:51:18 +04:00
|
|
|
Tabs.getInstance().loadUrlInTab("about:apps");
|
2012-07-27 10:52:41 +04:00
|
|
|
return true;
|
|
|
|
case R.id.char_encoding:
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("CharEncoding:Get", null));
|
|
|
|
return true;
|
|
|
|
case R.id.find_in_page:
|
|
|
|
mFindInPageBar.show();
|
|
|
|
return true;
|
|
|
|
case R.id.desktop_mode:
|
|
|
|
Tab selectedTab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (selectedTab == null)
|
|
|
|
return true;
|
|
|
|
JSONObject args = new JSONObject();
|
|
|
|
try {
|
|
|
|
args.put("desktopMode", !item.isChecked());
|
|
|
|
args.put("tabId", selectedTab.getId());
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.e(LOGTAG, "error building json arguments");
|
|
|
|
}
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("DesktopMode:Change", args.toString()));
|
|
|
|
return true;
|
2012-11-28 23:23:54 +04:00
|
|
|
case R.id.new_tab:
|
|
|
|
addTab();
|
|
|
|
return true;
|
|
|
|
case R.id.new_private_tab:
|
2013-01-03 01:43:01 +04:00
|
|
|
addPrivateTab();
|
2012-10-09 22:26:33 +04:00
|
|
|
return true;
|
2012-07-27 10:52:41 +04:00
|
|
|
default:
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
2012-08-27 08:33:11 +04:00
|
|
|
|
2013-02-07 07:53:01 +04:00
|
|
|
/**
|
|
|
|
* This will detect if the key pressed is back. If so, will show the history.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null) {
|
|
|
|
return tab.showAllHistory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.onKeyLongPress(keyCode, event);
|
|
|
|
}
|
|
|
|
|
2012-08-27 08:33:11 +04:00
|
|
|
/*
|
|
|
|
* If the app has been launched a certain number of times, and we haven't asked for feedback before,
|
|
|
|
* open a new tab with about:feedback when launching the app from the icon shortcut.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
super.onNewIntent(intent);
|
|
|
|
|
2013-03-05 17:05:52 +04:00
|
|
|
String action = intent.getAction();
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 10 && NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
|
|
|
|
String uri = intent.getDataString();
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createURILoadEvent(uri));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Intent.ACTION_MAIN.equals(action) || !mInitialized) {
|
2012-08-27 08:33:11 +04:00
|
|
|
return;
|
2013-03-05 17:05:52 +04:00
|
|
|
}
|
2012-08-27 08:33:11 +04:00
|
|
|
|
2013-03-15 14:52:53 +04:00
|
|
|
(new UiAsyncTask<Void, Void, Boolean>(ThreadUtils.getBackgroundHandler()) {
|
2012-08-27 08:33:11 +04:00
|
|
|
@Override
|
|
|
|
public synchronized Boolean doInBackground(Void... params) {
|
|
|
|
// Check to see how many times the app has been launched.
|
|
|
|
SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE);
|
|
|
|
String keyName = getPackageName() + ".feedback_launch_count";
|
|
|
|
int launchCount = settings.getInt(keyName, 0);
|
|
|
|
if (launchCount >= FEEDBACK_LAUNCH_COUNT)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Increment the launch count and store the new value.
|
|
|
|
launchCount++;
|
|
|
|
settings.edit().putInt(keyName, launchCount).commit();
|
|
|
|
|
|
|
|
// If we've reached our magic number, show the feedback page.
|
|
|
|
return launchCount == FEEDBACK_LAUNCH_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPostExecute(Boolean shouldShowFeedbackPage) {
|
|
|
|
if (shouldShowFeedbackPage)
|
2012-10-06 01:51:18 +04:00
|
|
|
Tabs.getInstance().loadUrlInTab("about:feedback");
|
2012-08-27 08:33:11 +04:00
|
|
|
}
|
|
|
|
}).execute();
|
|
|
|
}
|
|
|
|
|
2013-03-22 00:32:11 +04:00
|
|
|
@Override
|
|
|
|
protected NotificationClient makeNotificationClient() {
|
|
|
|
// The service is local to Fennec, so we can use it to keep
|
|
|
|
// Fennec alive during downloads.
|
|
|
|
return new ServiceNotificationClient(getApplicationContext());
|
|
|
|
}
|
|
|
|
|
2012-08-27 08:33:11 +04:00
|
|
|
private void resetFeedbackLaunchCount() {
|
2013-03-15 14:52:53 +04:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
2012-08-27 08:33:11 +04:00
|
|
|
@Override
|
|
|
|
public synchronized void run() {
|
|
|
|
SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE);
|
|
|
|
settings.edit().putInt(getPackageName() + ".feedback_launch_count", 0).commit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void getLastUrl() {
|
2013-03-15 14:52:53 +04:00
|
|
|
(new UiAsyncTask<Void, Void, String>(ThreadUtils.getBackgroundHandler()) {
|
2012-08-27 08:33:11 +04:00
|
|
|
@Override
|
|
|
|
public synchronized String doInBackground(Void... params) {
|
|
|
|
// Get the most recent URL stored in browser history.
|
|
|
|
String url = "";
|
|
|
|
Cursor c = BrowserDB.getRecentHistory(getContentResolver(), 1);
|
|
|
|
if (c.moveToFirst()) {
|
|
|
|
url = c.getString(c.getColumnIndexOrThrow(Combined.URL));
|
|
|
|
}
|
|
|
|
c.close();
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPostExecute(String url) {
|
|
|
|
// Don't bother sending a message if there is no URL.
|
|
|
|
if (url.length() > 0)
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Feedback:LastUrl", url));
|
|
|
|
}
|
|
|
|
}).execute();
|
|
|
|
}
|
2013-03-09 01:01:51 +04:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume()
|
|
|
|
{
|
|
|
|
super.onResume();
|
|
|
|
if (mAboutHomeContent != null) {
|
|
|
|
mAboutHomeContent.refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-04-10 04:10:47 +04:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getLayout() { return R.layout.gecko_app; }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected String getDefaultProfileName() {
|
|
|
|
String profile = GeckoProfile.findDefaultProfile(this);
|
|
|
|
return (profile != null ? profile : "default");
|
|
|
|
}
|
2012-06-12 02:18:40 +04:00
|
|
|
}
|