2012-06-11 15:18:40 -07: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;
|
|
|
|
|
2014-02-22 19:52:56 -08:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
import java.util.EnumSet;
|
2014-06-23 14:13:05 -07:00
|
|
|
import java.util.List;
|
2014-05-13 20:50:27 -07:00
|
|
|
import java.util.Locale;
|
2014-02-22 19:52:56 -08:00
|
|
|
import java.util.Vector;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
2014-06-25 09:29:07 -07:00
|
|
|
|
2014-03-13 12:29:39 -07:00
|
|
|
import org.mozilla.gecko.DynamicToolbar.PinReason;
|
|
|
|
import org.mozilla.gecko.DynamicToolbar.VisibilityTransition;
|
2014-03-03 15:27:42 -08:00
|
|
|
import org.mozilla.gecko.GeckoProfileDirectories.NoMozillaDirectoryException;
|
2013-05-07 10:04:11 -07:00
|
|
|
import org.mozilla.gecko.animation.PropertyAnimator;
|
2013-11-22 05:33:15 -08:00
|
|
|
import org.mozilla.gecko.animation.ViewHelper;
|
2012-08-26 21:33:11 -07:00
|
|
|
import org.mozilla.gecko.db.BrowserContract.Combined;
|
2014-03-12 14:53:25 -07:00
|
|
|
import org.mozilla.gecko.db.BrowserContract.ReadingListItems;
|
2012-08-26 21:33:11 -07:00
|
|
|
import org.mozilla.gecko.db.BrowserDB;
|
2014-05-09 08:34:55 -07:00
|
|
|
import org.mozilla.gecko.db.SuggestedSites;
|
2014-05-22 17:34:04 -07:00
|
|
|
import org.mozilla.gecko.distribution.Distribution;
|
2013-09-12 07:48:59 -07:00
|
|
|
import org.mozilla.gecko.favicons.Favicons;
|
2013-09-12 07:49:36 -07:00
|
|
|
import org.mozilla.gecko.favicons.LoadFaviconTask;
|
2014-02-22 19:52:56 -08:00
|
|
|
import org.mozilla.gecko.favicons.OnFaviconLoadedListener;
|
2014-01-17 19:24:28 -08:00
|
|
|
import org.mozilla.gecko.favicons.decoders.IconDirectoryEntry;
|
2014-02-18 19:20:27 -08:00
|
|
|
import org.mozilla.gecko.fxa.FirefoxAccounts;
|
2014-02-22 19:52:56 -08:00
|
|
|
import org.mozilla.gecko.fxa.activities.FxAccountGetStartedActivity;
|
2012-11-27 12:04:14 -08:00
|
|
|
import org.mozilla.gecko.gfx.BitmapUtils;
|
2013-03-07 02:17:32 -08:00
|
|
|
import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
|
2013-11-19 11:57:35 -08:00
|
|
|
import org.mozilla.gecko.gfx.LayerMarginsAnimator;
|
2014-04-11 17:49:44 -07:00
|
|
|
import org.mozilla.gecko.gfx.LayerView;
|
2013-09-06 16:25:27 -07:00
|
|
|
import org.mozilla.gecko.health.BrowserHealthRecorder;
|
2013-05-30 17:42:57 -07:00
|
|
|
import org.mozilla.gecko.health.BrowserHealthReporter;
|
2014-02-04 19:41:29 -08:00
|
|
|
import org.mozilla.gecko.health.HealthRecorder;
|
|
|
|
import org.mozilla.gecko.health.SessionInformation;
|
2013-06-25 10:00:09 -07:00
|
|
|
import org.mozilla.gecko.home.BrowserSearch;
|
2014-02-13 15:47:17 -08:00
|
|
|
import org.mozilla.gecko.home.HomeBanner;
|
2013-05-13 14:06:34 -07:00
|
|
|
import org.mozilla.gecko.home.HomePager;
|
2013-08-12 11:44:46 -07:00
|
|
|
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
|
2014-05-22 17:31:20 -07:00
|
|
|
import org.mozilla.gecko.home.HomePanelsManager;
|
2013-10-18 13:13:37 -07:00
|
|
|
import org.mozilla.gecko.home.SearchEngine;
|
2013-05-15 10:41:25 -07:00
|
|
|
import org.mozilla.gecko.menu.GeckoMenu;
|
2014-03-26 10:18:02 -07:00
|
|
|
import org.mozilla.gecko.menu.GeckoMenuItem;
|
2013-11-11 10:41:16 -08:00
|
|
|
import org.mozilla.gecko.preferences.GeckoPreferences;
|
2013-10-02 11:18:16 -07:00
|
|
|
import org.mozilla.gecko.prompts.Prompt;
|
2014-03-24 15:38:57 -07:00
|
|
|
import org.mozilla.gecko.prompts.PromptListItem;
|
2014-02-18 19:20:27 -08:00
|
|
|
import org.mozilla.gecko.sync.setup.SyncAccounts;
|
2014-04-29 11:20:59 -07:00
|
|
|
import org.mozilla.gecko.tabspanel.TabsPanel;
|
2013-11-19 07:46:48 -08:00
|
|
|
import org.mozilla.gecko.toolbar.AutocompleteHandler;
|
|
|
|
import org.mozilla.gecko.toolbar.BrowserToolbar;
|
2014-03-18 10:36:23 -07:00
|
|
|
import org.mozilla.gecko.toolbar.ToolbarProgressView;
|
2013-06-07 13:39:37 -07:00
|
|
|
import org.mozilla.gecko.util.Clipboard;
|
2014-05-20 13:09:55 -07:00
|
|
|
import org.mozilla.gecko.util.EventCallback;
|
2013-03-28 09:40:06 -07:00
|
|
|
import org.mozilla.gecko.util.GamepadUtils;
|
2014-05-20 13:09:54 -07:00
|
|
|
import org.mozilla.gecko.util.GeckoEventListener;
|
2014-05-20 13:09:55 -07:00
|
|
|
import org.mozilla.gecko.util.NativeEventListener;
|
|
|
|
import org.mozilla.gecko.util.NativeJSObject;
|
2013-04-02 07:03:39 -07:00
|
|
|
import org.mozilla.gecko.util.HardwareUtils;
|
2014-02-07 11:49:32 -08:00
|
|
|
import org.mozilla.gecko.util.MenuUtils;
|
2013-09-03 21:19:28 -07:00
|
|
|
import org.mozilla.gecko.util.StringUtils;
|
2013-03-15 03:52:53 -07:00
|
|
|
import org.mozilla.gecko.util.ThreadUtils;
|
2013-03-28 09:40:06 -07:00
|
|
|
import org.mozilla.gecko.util.UiAsyncTask;
|
2013-05-30 17:02:30 -07:00
|
|
|
import org.mozilla.gecko.widget.ButtonToast;
|
2014-02-22 19:52:56 -08:00
|
|
|
import org.mozilla.gecko.widget.GeckoActionProvider;
|
2012-06-11 15:18:40 -07:00
|
|
|
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.app.Activity;
|
2012-08-27 17:50:32 -07:00
|
|
|
import android.app.AlertDialog;
|
2014-03-12 14:53:25 -07:00
|
|
|
import android.content.ContentValues;
|
2014-02-04 19:41:29 -08:00
|
|
|
import android.content.Context;
|
2012-08-27 17:50:32 -07:00
|
|
|
import android.content.DialogInterface;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.content.Intent;
|
2013-04-08 00:51:56 -07:00
|
|
|
import android.content.SharedPreferences;
|
2013-02-21 23:22:37 -08:00
|
|
|
import android.content.res.Configuration;
|
2013-05-30 17:03:20 -07:00
|
|
|
import android.content.res.Resources;
|
2012-08-26 21:33:11 -07:00
|
|
|
import android.database.Cursor;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.graphics.Bitmap;
|
2012-10-12 16:23:20 -07:00
|
|
|
import android.graphics.Rect;
|
2013-09-17 07:27:37 -07:00
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
2013-04-08 00:51:56 -07:00
|
|
|
import android.graphics.drawable.Drawable;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.net.Uri;
|
2013-03-05 05:06:09 -08:00
|
|
|
import android.nfc.NdefMessage;
|
|
|
|
import android.nfc.NdefRecord;
|
2013-03-05 05:05:52 -08:00
|
|
|
import android.nfc.NfcAdapter;
|
2013-03-05 05:06:09 -08:00
|
|
|
import android.nfc.NfcEvent;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Bundle;
|
2013-10-18 11:39:32 -07:00
|
|
|
import android.support.v4.app.FragmentManager;
|
2013-05-13 09:27:53 -07:00
|
|
|
import android.text.TextUtils;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.util.Log;
|
2013-03-12 06:22:01 -07:00
|
|
|
import android.view.InputDevice;
|
2013-02-06 19:53:01 -08:00
|
|
|
import android.view.KeyEvent;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2012-10-12 16:23:20 -07:00
|
|
|
import android.view.MotionEvent;
|
2012-10-26 13:39:25 -07:00
|
|
|
import android.view.SubMenu;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2013-08-21 02:15:37 -07:00
|
|
|
import android.view.ViewStub;
|
2014-02-06 00:59:50 -08:00
|
|
|
import android.view.ViewTreeObserver;
|
2014-02-13 20:43:00 -08:00
|
|
|
import android.view.Window;
|
2012-10-12 04:57:06 -07:00
|
|
|
import android.view.animation.Interpolator;
|
2014-02-25 08:55:14 -08:00
|
|
|
import android.widget.ListView;
|
2014-05-22 17:31:20 -07:00
|
|
|
import android.widget.RelativeLayout;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.widget.Toast;
|
2013-11-22 15:18:04 -08:00
|
|
|
import android.widget.ViewFlipper;
|
2012-07-27 17:53:54 -07:00
|
|
|
|
2014-06-24 18:20:13 -07:00
|
|
|
public class BrowserApp extends GeckoApp
|
|
|
|
implements TabsPanel.TabsLayoutChangeListener,
|
|
|
|
PropertyAnimator.PropertyAnimationListener,
|
|
|
|
View.OnKeyListener,
|
|
|
|
LayerView.OnMetricsChangedListener,
|
|
|
|
BrowserSearch.OnSearchListener,
|
|
|
|
BrowserSearch.OnEditSuggestionListener,
|
|
|
|
HomePager.OnNewTabsListener,
|
|
|
|
OnUrlOpenListener,
|
|
|
|
ActionModeCompat.Presenter {
|
2012-06-11 15:18:40 -07:00
|
|
|
private static final String LOGTAG = "GeckoBrowserApp";
|
|
|
|
|
2013-03-20 16:43:47 -07:00
|
|
|
private static final int TABS_ANIMATION_DURATION = 450;
|
|
|
|
|
2013-04-17 03:43:22 -07:00
|
|
|
private static final int READER_ADD_SUCCESS = 0;
|
|
|
|
private static final int READER_ADD_FAILED = 1;
|
|
|
|
private static final int READER_ADD_DUPLICATE = 2;
|
|
|
|
|
2013-05-30 17:03:20 -07:00
|
|
|
private static final String ADD_SHORTCUT_TOAST = "add_shortcut_toast";
|
2013-08-26 16:41:13 -07:00
|
|
|
public static final String GUEST_BROWSING_ARG = "--guest";
|
2013-05-30 17:03:20 -07:00
|
|
|
|
2013-06-07 12:27:21 -07:00
|
|
|
private static final String STATE_ABOUT_HOME_TOP_PADDING = "abouthome_top_padding";
|
2013-05-13 10:20:49 -07:00
|
|
|
|
2013-06-11 09:57:45 -07:00
|
|
|
private static final String BROWSER_SEARCH_TAG = "browser_search";
|
2014-05-13 20:50:27 -07:00
|
|
|
|
|
|
|
// Request ID for startActivityForResult.
|
|
|
|
private static final int ACTIVITY_REQUEST_PREFERENCES = 1001;
|
|
|
|
|
2013-06-11 09:57:45 -07:00
|
|
|
private BrowserSearch mBrowserSearch;
|
|
|
|
private View mBrowserSearchContainer;
|
|
|
|
|
2013-11-19 11:57:35 -08:00
|
|
|
public ViewFlipper mViewFlipper;
|
|
|
|
public ActionModeCompatView mActionBar;
|
2013-11-08 07:04:19 -08:00
|
|
|
private BrowserToolbar mBrowserToolbar;
|
2014-03-18 10:36:23 -07:00
|
|
|
private ToolbarProgressView mProgressView;
|
2013-05-13 14:06:34 -07:00
|
|
|
private HomePager mHomePager;
|
2014-02-06 00:59:50 -08:00
|
|
|
private TabsPanel mTabsPanel;
|
2014-03-07 11:23:27 -08:00
|
|
|
private ViewGroup mHomePagerContainer;
|
2012-11-26 14:57:11 -08:00
|
|
|
protected Telemetry.Timer mAboutHomeStartupTimer = null;
|
2013-11-19 11:57:35 -08:00
|
|
|
private ActionModeCompat mActionMode;
|
2014-01-13 15:20:13 -08:00
|
|
|
private boolean mShowActionModeEndAnimation = false;
|
2012-06-11 15:18:40 -07:00
|
|
|
|
2013-07-08 22:47:10 -07:00
|
|
|
private static final int GECKO_TOOLS_MENU = -1;
|
2012-09-26 12:02:48 -07:00
|
|
|
private static final int ADDON_MENU_OFFSET = 1000;
|
2013-12-03 15:05:43 -08:00
|
|
|
private static class MenuItemInfo {
|
2012-10-26 13:39:25 -07:00
|
|
|
public int id;
|
|
|
|
public String label;
|
|
|
|
public String icon;
|
2013-04-03 15:10:06 -07:00
|
|
|
public boolean checkable = false;
|
|
|
|
public boolean checked = false;
|
|
|
|
public boolean enabled = true;
|
|
|
|
public boolean visible = true;
|
2012-10-26 13:39:25 -07:00
|
|
|
public int parent;
|
2013-12-03 15:05:43 -08:00
|
|
|
public boolean added = false; // So we can re-add after a locale change.
|
2012-09-27 11:22:08 -07:00
|
|
|
}
|
|
|
|
|
2013-07-26 09:14:04 -07:00
|
|
|
// The types of guest mdoe dialogs we show
|
|
|
|
private static enum GuestModeDialog {
|
|
|
|
ENTERING,
|
|
|
|
LEAVING
|
|
|
|
}
|
|
|
|
|
2012-09-27 11:22:08 -07:00
|
|
|
private Vector<MenuItemInfo> mAddonMenuItemsCache;
|
2012-06-12 22:47:52 -07:00
|
|
|
private PropertyAnimator mMainLayoutAnimator;
|
|
|
|
|
2012-10-12 04:57:06 -07:00
|
|
|
private static final Interpolator sTabsInterpolator = new Interpolator() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-10-12 04:57:06 -07:00
|
|
|
public float getInterpolation(float t) {
|
|
|
|
t -= 1.0f;
|
|
|
|
return t * t * t * t * t + 1.0f;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-26 23:52:41 -07:00
|
|
|
private FindInPageBar mFindInPageBar;
|
2014-01-20 14:26:30 -08:00
|
|
|
private MediaCastingBar mMediaCastingBar;
|
2012-07-26 23:52:41 -07:00
|
|
|
|
2012-08-26 21:33:11 -07:00
|
|
|
// We'll ask for feedback after the user launches the app this many times.
|
2012-10-18 12:13:12 -07:00
|
|
|
private static final int FEEDBACK_LAUNCH_COUNT = 15;
|
2012-08-26 21:33:11 -07:00
|
|
|
|
2013-03-18 08:43:03 -07:00
|
|
|
// Stored value of the toolbar height, so we know when it's changed.
|
|
|
|
private int mToolbarHeight = 0;
|
|
|
|
|
2013-05-25 00:59:48 -07:00
|
|
|
// Stored value of whether the last metrics change allowed for toolbar
|
|
|
|
// scrolling.
|
|
|
|
private boolean mDynamicToolbarCanScroll = false;
|
|
|
|
|
2013-05-10 19:46:25 -07:00
|
|
|
private SharedPreferencesHelper mSharedPreferencesHelper;
|
|
|
|
|
2013-05-10 19:47:40 -07:00
|
|
|
private OrderedBroadcastHelper mOrderedBroadcastHelper;
|
|
|
|
|
2013-05-30 17:42:57 -07:00
|
|
|
private BrowserHealthReporter mBrowserHealthReporter;
|
|
|
|
|
2013-10-21 12:11:08 -07:00
|
|
|
// The tab to be selected on editing mode exit.
|
|
|
|
private Integer mTargetTabForEditingMode = null;
|
|
|
|
|
2013-10-18 09:40:28 -07:00
|
|
|
// The animator used to toggle HomePager visibility has a race where if the HomePager is shown
|
|
|
|
// (starting the animation), the HomePager is hidden, and the HomePager animation completes,
|
|
|
|
// both the web content and the HomePager will be hidden. This flag is used to prevent the
|
|
|
|
// race by determining if the web content should be hidden at the animation's end.
|
|
|
|
private boolean mHideWebContentOnAnimationEnd = false;
|
|
|
|
|
2014-03-13 12:29:39 -07:00
|
|
|
private DynamicToolbar mDynamicToolbar = new DynamicToolbar();
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
@Override
|
|
|
|
public void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) {
|
2013-11-26 19:48:30 -08:00
|
|
|
if (tab == null) {
|
|
|
|
// Only RESTORED is allowed a null tab: it's the only event that
|
|
|
|
// isn't tied to a specific tab.
|
|
|
|
if (msg != Tabs.TabEvents.RESTORED) {
|
|
|
|
throw new IllegalArgumentException("onTabChanged:" + msg + " must specify a tab.");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Log.d(LOGTAG, "BrowserApp.onTabChanged: " + tab.getId() + ": " + msg);
|
2012-06-11 15:18:40 -07:00
|
|
|
switch(msg) {
|
|
|
|
case LOCATION_CHANGE:
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
2013-11-27 11:03:19 -08:00
|
|
|
maybeCancelFaviconLoad(tab);
|
2012-10-22 12:37:50 -07:00
|
|
|
}
|
|
|
|
// fall through
|
|
|
|
case SELECTED:
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
2013-09-17 06:13:54 -07:00
|
|
|
updateHomePagerForTab(tab);
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
break;
|
2013-03-06 13:11:05 -08:00
|
|
|
case START:
|
2013-03-07 02:17:32 -08:00
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
|
2014-03-13 12:29:39 -07:00
|
|
|
if (mDynamicToolbar.isEnabled()) {
|
|
|
|
mDynamicToolbar.setVisible(true, VisibilityTransition.ANIMATE);
|
2013-03-07 02:17:34 -08:00
|
|
|
}
|
2013-03-07 02:17:32 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LOAD_ERROR:
|
2012-06-14 20:12:06 -07:00
|
|
|
case STOP:
|
2012-07-24 16:12:12 -07:00
|
|
|
case MENU_UPDATED:
|
2012-06-14 20:12:06 -07:00
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
}
|
|
|
|
break;
|
2013-11-27 11:03:19 -08:00
|
|
|
case PAGE_SHOW:
|
|
|
|
loadFavicon(tab);
|
|
|
|
break;
|
2013-04-03 12:34:51 -07:00
|
|
|
case LINK_FAVICON:
|
2013-02-26 14:38:10 -08: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-24 20:51:04 -08:00
|
|
|
break;
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
super.onTabChanged(tab, msg, data);
|
|
|
|
}
|
|
|
|
|
2013-03-12 06:22:01 -07:00
|
|
|
@Override
|
|
|
|
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
2014-04-22 07:53:48 -07:00
|
|
|
if (AndroidGamepadManager.handleKeyEvent(event)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-12 06:22:01 -07:00
|
|
|
// 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-12 19:58:41 -07:00
|
|
|
// Gamepad support only exists in API-level >= 9
|
|
|
|
if (Build.VERSION.SDK_INT >= 9 &&
|
2013-03-12 14:34:29 -07:00
|
|
|
(event.getSource() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) {
|
2013-03-12 19:58:41 -07:00
|
|
|
switch (keyCode) {
|
|
|
|
case KeyEvent.KEYCODE_BUTTON_Y:
|
|
|
|
// Toggle/focus the address bar on gamepad-y button.
|
2013-11-19 11:57:35 -08:00
|
|
|
if (mViewFlipper.getVisibility() == View.VISIBLE) {
|
2014-03-13 12:29:39 -07:00
|
|
|
if (mDynamicToolbar.isEnabled() && !isHomePagerVisible()) {
|
|
|
|
mDynamicToolbar.setVisible(false, VisibilityTransition.ANIMATE);
|
2013-04-25 10:47:08 -07:00
|
|
|
if (mLayerView != null) {
|
|
|
|
mLayerView.requestFocus();
|
|
|
|
}
|
2013-03-12 19:58:41 -07:00
|
|
|
} else {
|
|
|
|
// Just focus the address bar when about:home is visible
|
|
|
|
// or when the dynamic toolbar isn't enabled.
|
|
|
|
mBrowserToolbar.requestFocusFromTouch();
|
|
|
|
}
|
|
|
|
} else {
|
2014-03-13 12:29:39 -07:00
|
|
|
mDynamicToolbar.setVisible(true, VisibilityTransition.ANIMATE);
|
2013-03-12 19:58:41 -07: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 06:22:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-08 14:28:56 -07: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 06:22:01 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
2013-05-13 10:20:49 -07:00
|
|
|
if (!mBrowserToolbar.isEditing() && onKey(null, keyCode, event)) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-03-12 06:22:01 -07:00
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
|
}
|
|
|
|
|
2014-04-22 07:53:48 -07:00
|
|
|
@Override
|
|
|
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
|
|
|
if (AndroidGamepadManager.handleKeyEvent(event)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.onKeyUp(keyCode, event);
|
|
|
|
}
|
|
|
|
|
2013-10-14 06:58:16 -07:00
|
|
|
void handleReaderListStatusRequest(final String url) {
|
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
final int inReadingList = BrowserDB.isReadingListItem(getContentResolver(), url) ? 1 : 0;
|
|
|
|
|
|
|
|
final JSONObject json = new JSONObject();
|
|
|
|
try {
|
|
|
|
json.put("url", url);
|
|
|
|
json.put("inReadingList", inReadingList);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.e(LOGTAG, "JSON error - failed to return inReadingList status", e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Reader:ListStatusReturn", json.toString()));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-03-12 14:53:25 -07:00
|
|
|
private void handleReaderAdded(int result, final ContentValues values) {
|
2013-04-17 03:43:22 -07:00
|
|
|
if (result != READER_ADD_SUCCESS) {
|
|
|
|
if (result == READER_ADD_FAILED) {
|
|
|
|
showToast(R.string.reading_list_failed, Toast.LENGTH_SHORT);
|
|
|
|
} else if (result == READER_ADD_DUPLICATE) {
|
|
|
|
showToast(R.string.reading_list_duplicate, Toast.LENGTH_SHORT);
|
|
|
|
}
|
|
|
|
|
2013-02-24 20:51:04 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2013-02-24 20:51:04 -08:00
|
|
|
public void run() {
|
2014-03-12 14:53:25 -07:00
|
|
|
BrowserDB.addReadingListItem(getContentResolver(), values);
|
2013-02-24 20:51:04 -08:00
|
|
|
showToast(R.string.reading_list_added, Toast.LENGTH_SHORT);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-03-12 14:53:25 -07:00
|
|
|
private ContentValues messageToReadingListContentValues(JSONObject message) {
|
|
|
|
final ContentValues values = new ContentValues();
|
|
|
|
values.put(ReadingListItems.URL, message.optString("url"));
|
|
|
|
values.put(ReadingListItems.TITLE, message.optString("title"));
|
|
|
|
values.put(ReadingListItems.LENGTH, message.optInt("length"));
|
|
|
|
values.put(ReadingListItems.EXCERPT, message.optString("excerpt"));
|
|
|
|
return values;
|
|
|
|
}
|
|
|
|
|
2014-06-10 15:03:46 -07:00
|
|
|
void handleReaderRemoved(final String url) {
|
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
BrowserDB.removeReadingListItemWithURL(getContentResolver(), url);
|
|
|
|
showToast(R.string.page_removed, Toast.LENGTH_SHORT);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-04-28 16:19:38 -07:00
|
|
|
private void handleReaderFaviconRequest(final String url) {
|
|
|
|
(new UiAsyncTask<Void, Void, String>(ThreadUtils.getBackgroundHandler()) {
|
|
|
|
@Override
|
|
|
|
public String doInBackground(Void... params) {
|
|
|
|
return Favicons.getFaviconURLForPageURL(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPostExecute(String faviconUrl) {
|
|
|
|
JSONObject args = new JSONObject();
|
|
|
|
|
|
|
|
if (faviconUrl != null) {
|
|
|
|
try {
|
|
|
|
args.put("url", url);
|
|
|
|
args.put("faviconUrl", faviconUrl);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.w(LOGTAG, "Error building JSON favicon arguments.", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Reader:FaviconReturn", args.toString()));
|
|
|
|
}
|
|
|
|
}).execute();
|
|
|
|
}
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2013-12-10 10:41:34 -08:00
|
|
|
mAboutHomeStartupTimer = new Telemetry.UptimeTimer("FENNEC_STARTUP_TIME_ABOUTHOME");
|
2012-11-26 14:57:11 -08:00
|
|
|
|
2013-09-20 12:22:35 -07:00
|
|
|
final Intent intent = getIntent();
|
|
|
|
|
|
|
|
String args = intent.getStringExtra("args");
|
2013-08-26 16:41:13 -07:00
|
|
|
if (args != null && args.contains(GUEST_BROWSING_ARG)) {
|
2013-07-18 11:43:34 -07:00
|
|
|
mProfile = GeckoProfile.createGuestProfile(this);
|
2013-09-10 11:17:42 -07:00
|
|
|
} else {
|
|
|
|
GeckoProfile.maybeCleanupGuestProfile(this);
|
2013-07-18 11:43:34 -07:00
|
|
|
}
|
|
|
|
|
2014-02-27 12:32:34 -08:00
|
|
|
// This has to be prepared prior to calling GeckoApp.onCreate, because
|
|
|
|
// widget code and BrowserToolbar need it, and they're created by the
|
|
|
|
// layout, which GeckoApp takes care of.
|
|
|
|
((GeckoApplication) getApplication()).prepareLightweightTheme();
|
2012-06-11 15:18:40 -07:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2014-05-09 08:34:55 -07:00
|
|
|
// Init suggested sites engine in BrowserDB.
|
|
|
|
final SuggestedSites suggestedSites = new SuggestedSites(getApplicationContext());
|
|
|
|
BrowserDB.setSuggestedSites(suggestedSites);
|
|
|
|
|
2013-11-19 11:57:35 -08:00
|
|
|
mViewFlipper = (ViewFlipper) findViewById(R.id.browser_actionbar);
|
|
|
|
mActionBar = (ActionModeCompatView) findViewById(R.id.actionbar);
|
|
|
|
|
2013-06-25 16:10:52 -07:00
|
|
|
mBrowserToolbar = (BrowserToolbar) findViewById(R.id.browser_toolbar);
|
2014-03-18 10:36:23 -07:00
|
|
|
mProgressView = (ToolbarProgressView) findViewById(R.id.progress);
|
|
|
|
mBrowserToolbar.setProgressBar(mProgressView);
|
2013-09-20 12:22:35 -07:00
|
|
|
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
2014-02-27 12:32:34 -08:00
|
|
|
// Show the target URL immediately in the toolbar.
|
2013-09-20 12:22:35 -07:00
|
|
|
mBrowserToolbar.setTitle(intent.getDataString());
|
2014-04-01 21:33:21 -07:00
|
|
|
|
|
|
|
Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.INTENT);
|
2013-09-20 12:22:35 -07:00
|
|
|
}
|
2012-06-11 15:18:40 -07:00
|
|
|
|
2014-06-12 09:31:47 -07:00
|
|
|
((GeckoApp.MainLayout) mMainLayout).setTouchEventInterceptor(new HideOnTouchListener());
|
2013-03-28 09:40:06 -07: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
|
2013-04-25 10:47:08 -07:00
|
|
|
if (mLayerView != null && !mLayerView.hasFocus() && GamepadUtils.isPanningControl(event)) {
|
2013-08-21 02:15:37 -07:00
|
|
|
if (mHomePager == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isHomePagerVisible()) {
|
2013-05-08 11:44:37 -07:00
|
|
|
mLayerView.requestFocus();
|
2013-05-08 15:47:23 -07:00
|
|
|
} else {
|
2013-05-13 14:06:34 -07:00
|
|
|
mHomePager.requestFocus();
|
2013-04-03 08:59:22 -07:00
|
|
|
}
|
2013-03-28 09:40:06 -07:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-03-07 11:23:27 -08:00
|
|
|
mHomePagerContainer = (ViewGroup) findViewById(R.id.home_pager_container);
|
2012-10-12 16:23:20 -07:00
|
|
|
|
2013-06-11 09:57:45 -07:00
|
|
|
mBrowserSearchContainer = findViewById(R.id.search_container);
|
|
|
|
mBrowserSearch = (BrowserSearch) getSupportFragmentManager().findFragmentByTag(BROWSER_SEARCH_TAG);
|
|
|
|
if (mBrowserSearch == null) {
|
|
|
|
mBrowserSearch = BrowserSearch.newInstance();
|
|
|
|
mBrowserSearch.setUserVisibleHint(false);
|
|
|
|
}
|
|
|
|
|
2014-04-16 14:04:46 -07:00
|
|
|
setBrowserToolbarListeners();
|
2013-03-12 06:22:01 -07:00
|
|
|
|
2012-07-26 23:52:41 -07:00
|
|
|
mFindInPageBar = (FindInPageBar) findViewById(R.id.find_in_page);
|
2014-01-20 14:26:30 -08:00
|
|
|
mMediaCastingBar = (MediaCastingBar) findViewById(R.id.media_casting);
|
2012-07-26 23:52:41 -07:00
|
|
|
|
2014-05-20 13:09:54 -07:00
|
|
|
EventDispatcher.getInstance().registerGeckoThreadListener((GeckoEventListener)this,
|
2014-05-20 13:09:55 -07:00
|
|
|
"Menu:Update",
|
|
|
|
"Reader:Added",
|
|
|
|
"Reader:FaviconRequest",
|
|
|
|
"Prompt:ShowTop",
|
|
|
|
"Accounts:Exist");
|
|
|
|
|
|
|
|
EventDispatcher.getInstance().registerGeckoThreadListener((NativeEventListener)this,
|
|
|
|
"Accounts:Create",
|
2014-05-02 11:34:40 -07:00
|
|
|
"CharEncoding:Data",
|
|
|
|
"CharEncoding:State",
|
|
|
|
"Feedback:LastUrl",
|
|
|
|
"Feedback:MaybeLater",
|
2014-05-20 13:09:55 -07:00
|
|
|
"Feedback:OpenPlayStore",
|
2014-05-02 11:34:40 -07:00
|
|
|
"Menu:Add",
|
|
|
|
"Menu:Remove",
|
|
|
|
"Reader:ListStatusRequest",
|
2014-06-10 15:03:46 -07:00
|
|
|
"Reader:Removed",
|
2014-05-02 11:34:40 -07:00
|
|
|
"Reader:Share",
|
2014-05-20 13:09:55 -07:00
|
|
|
"Settings:Show",
|
|
|
|
"Telemetry:Gather",
|
|
|
|
"Updater:Launch");
|
2013-02-01 15:45:33 -08:00
|
|
|
|
2013-10-16 19:25:13 -07:00
|
|
|
Distribution.init(this);
|
2013-02-15 12:21:41 -08:00
|
|
|
JavaAddonManager.getInstance().init(getApplicationContext());
|
2013-05-10 19:46:25 -07:00
|
|
|
mSharedPreferencesHelper = new SharedPreferencesHelper(getApplicationContext());
|
2013-05-10 19:47:40 -07:00
|
|
|
mOrderedBroadcastHelper = new OrderedBroadcastHelper(getApplicationContext());
|
2013-05-30 17:42:57 -07:00
|
|
|
mBrowserHealthReporter = new BrowserHealthReporter();
|
2013-03-05 05:06:09 -08:00
|
|
|
|
2013-04-17 13:08:11 -07:00
|
|
|
if (AppConstants.MOZ_ANDROID_BEAM && Build.VERSION.SDK_INT >= 14) {
|
2013-03-05 05:06:09 -08: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-09 14:52:43 -08:00
|
|
|
return new NdefMessage(new NdefRecord[] { NdefRecord.createUri(tab.getURL()) });
|
2013-03-05 05:06:09 -08:00
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
}
|
|
|
|
}
|
2013-03-07 02:17:34 -08:00
|
|
|
|
2013-05-23 11:29:43 -07:00
|
|
|
if (savedInstanceState != null) {
|
2014-03-13 12:29:39 -07:00
|
|
|
mDynamicToolbar.onRestoreInstanceState(savedInstanceState);
|
2013-07-25 14:26:01 -07:00
|
|
|
mHomePagerContainer.setPadding(0, savedInstanceState.getInt(STATE_ABOUT_HOME_TOP_PADDING), 0, 0);
|
2013-05-23 11:29:43 -07:00
|
|
|
}
|
|
|
|
|
2014-03-13 12:29:39 -07:00
|
|
|
mDynamicToolbar.setEnabledChangedListener(new DynamicToolbar.OnEnabledChangedListener() {
|
2013-03-07 02:17:34 -08:00
|
|
|
@Override
|
2014-03-13 12:29:39 -07:00
|
|
|
public void onEnabledChanged(boolean enabled) {
|
|
|
|
setDynamicToolbarEnabled(enabled);
|
2013-03-12 11:32:26 -07:00
|
|
|
}
|
2013-03-07 02:17:34 -08:00
|
|
|
});
|
2014-01-17 19:24:28 -08:00
|
|
|
|
|
|
|
// Set the maximum bits-per-pixel the favicon system cares about.
|
|
|
|
IconDirectoryEntry.setMaxBPP(GeckoAppShell.getScreenDepth());
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
|
2013-05-13 10:20:49 -07:00
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
2013-07-08 15:05:27 -07:00
|
|
|
if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
|
|
|
|
super.onBackPressed();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-11 16:28:14 -08:00
|
|
|
if (mBrowserToolbar.onBackPressed()) {
|
2013-07-03 17:08:31 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-19 11:57:35 -08:00
|
|
|
if (mActionMode != null) {
|
|
|
|
endActionModeCompat();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-13 10:20:49 -07:00
|
|
|
super.onBackPressed();
|
|
|
|
}
|
|
|
|
|
2013-07-31 15:38:48 -07:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
2014-05-20 13:09:54 -07:00
|
|
|
EventDispatcher.getInstance().unregisterGeckoThreadListener((GeckoEventListener)this,
|
|
|
|
"Prompt:ShowTop");
|
2013-07-31 15:38:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
// Register for Prompt:ShowTop so we can foreground this activity even if it's hidden.
|
2014-05-20 13:09:54 -07:00
|
|
|
EventDispatcher.getInstance().registerGeckoThreadListener((GeckoEventListener)this,
|
|
|
|
"Prompt:ShowTop");
|
2013-07-31 15:38:48 -07:00
|
|
|
}
|
|
|
|
|
2014-04-16 14:04:46 -07:00
|
|
|
private void setBrowserToolbarListeners() {
|
|
|
|
mBrowserToolbar.setOnActivateListener(new BrowserToolbar.OnActivateListener() {
|
|
|
|
public void onActivate() {
|
|
|
|
enterEditingMode();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mBrowserToolbar.setOnCommitListener(new BrowserToolbar.OnCommitListener() {
|
|
|
|
public void onCommit() {
|
|
|
|
commitEditingMode();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mBrowserToolbar.setOnDismissListener(new BrowserToolbar.OnDismissListener() {
|
|
|
|
public void onDismiss() {
|
|
|
|
mBrowserToolbar.cancelEdit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mBrowserToolbar.setOnFilterListener(new BrowserToolbar.OnFilterListener() {
|
|
|
|
public void onFilter(String searchText, AutocompleteHandler handler) {
|
|
|
|
filterEditingMode(searchText, handler);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mBrowserToolbar.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onFocusChange(View v, boolean hasFocus) {
|
|
|
|
if (isHomePagerVisible()) {
|
|
|
|
mHomePager.onToolbarFocusChange(hasFocus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mBrowserToolbar.setOnStartEditingListener(new BrowserToolbar.OnStartEditingListener() {
|
|
|
|
public void onStartEditing() {
|
|
|
|
// Temporarily disable doorhanger notifications.
|
|
|
|
mDoorHangerPopup.disable();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mBrowserToolbar.setOnStopEditingListener(new BrowserToolbar.OnStopEditingListener() {
|
|
|
|
public void onStopEditing() {
|
|
|
|
selectTargetTabForEditingMode();
|
|
|
|
|
|
|
|
// Since the underlying LayerView is set visible in hideHomePager, we would
|
|
|
|
// ordinarily want to call it first. However, hideBrowserSearch changes the
|
|
|
|
// visibility of the HomePager and hideHomePager will take no action if the
|
|
|
|
// HomePager is hidden, so we want to call hideBrowserSearch to restore the
|
|
|
|
// HomePager visibility first.
|
|
|
|
hideBrowserSearch();
|
|
|
|
hideHomePager();
|
|
|
|
|
|
|
|
// Re-enable doorhanger notifications. They may trigger on the selected tab above.
|
|
|
|
mDoorHangerPopup.enable();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Intercept key events for gamepad shortcuts
|
|
|
|
mBrowserToolbar.setOnKeyListener(this);
|
|
|
|
}
|
|
|
|
|
2014-03-24 15:38:57 -07:00
|
|
|
private void showBookmarkDialog() {
|
|
|
|
final Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
final Prompt ps = new Prompt(this, new Prompt.PromptCallback() {
|
|
|
|
@Override
|
|
|
|
public void onPromptFinished(String result) {
|
|
|
|
int itemId = -1;
|
|
|
|
try {
|
|
|
|
itemId = new JSONObject(result).getInt("button");
|
|
|
|
} catch(JSONException ex) {
|
|
|
|
Log.e(LOGTAG, "Exception reading bookmark prompt result", ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tab == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (itemId == 0) {
|
|
|
|
new EditBookmarkDialog(BrowserApp.this).show(tab.getURL());
|
|
|
|
} else if (itemId == 1) {
|
|
|
|
String url = tab.getURL();
|
|
|
|
String title = tab.getDisplayTitle();
|
|
|
|
Bitmap favicon = tab.getFavicon();
|
|
|
|
if (url != null && title != null) {
|
|
|
|
GeckoAppShell.createShortcut(title, url, url, favicon, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
final PromptListItem[] items = new PromptListItem[2];
|
|
|
|
Resources res = getResources();
|
|
|
|
items[0] = new PromptListItem(res.getString(R.string.contextmenu_edit_bookmark));
|
|
|
|
items[1] = new PromptListItem(res.getString(R.string.contextmenu_add_to_launcher));
|
|
|
|
|
|
|
|
ps.show("", "", items, ListView.CHOICE_MODE_NONE);
|
|
|
|
}
|
|
|
|
|
2013-04-12 08:51:56 -07:00
|
|
|
private void setDynamicToolbarEnabled(boolean enabled) {
|
2014-03-13 12:29:39 -07:00
|
|
|
ThreadUtils.assertOnUiThread();
|
|
|
|
|
2013-04-12 08:51:56 -07:00
|
|
|
if (enabled) {
|
2013-04-25 10:47:08 -07:00
|
|
|
if (mLayerView != null) {
|
2014-04-11 17:49:44 -07:00
|
|
|
mLayerView.setOnMetricsChangedListener(this);
|
2013-04-25 10:47:08 -07:00
|
|
|
}
|
2013-04-12 08:51:56 -07:00
|
|
|
setToolbarMargin(0);
|
2013-11-22 15:18:04 -08:00
|
|
|
mHomePagerContainer.setPadding(0, mViewFlipper.getHeight(), 0, 0);
|
2013-04-12 08:51:56 -07:00
|
|
|
} else {
|
|
|
|
// Immediately show the toolbar when disabling the dynamic
|
|
|
|
// toolbar.
|
2013-04-25 10:47:08 -07:00
|
|
|
if (mLayerView != null) {
|
2014-04-11 17:49:44 -07:00
|
|
|
mLayerView.setOnMetricsChangedListener(null);
|
2013-04-25 10:47:08 -07:00
|
|
|
}
|
2013-07-25 14:26:01 -07:00
|
|
|
mHomePagerContainer.setPadding(0, 0, 0, 0);
|
2013-11-22 15:18:04 -08:00
|
|
|
if (mViewFlipper != null) {
|
|
|
|
ViewHelper.setTranslationY(mViewFlipper, 0);
|
2013-04-25 10:47:08 -07:00
|
|
|
}
|
2013-04-12 08:51:56 -07:00
|
|
|
}
|
|
|
|
|
2013-04-25 10:47:08 -07:00
|
|
|
refreshToolbarHeight();
|
2013-04-12 08:51:56 -07:00
|
|
|
}
|
|
|
|
|
2013-11-21 23:33:28 -08:00
|
|
|
private static boolean isAboutHome(final Tab tab) {
|
|
|
|
return AboutPages.isAboutHome(tab.getURL());
|
2013-05-13 09:40:38 -07:00
|
|
|
}
|
|
|
|
|
2013-05-13 09:27:53 -07:00
|
|
|
@Override
|
|
|
|
public boolean onSearchRequested() {
|
2013-07-23 17:52:36 -07:00
|
|
|
enterEditingMode();
|
|
|
|
return true;
|
2013-05-13 09:27:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onContextItemSelected(MenuItem item) {
|
2013-08-13 16:44:00 -07:00
|
|
|
final int itemId = item.getItemId();
|
|
|
|
if (itemId == R.id.pasteandgo) {
|
|
|
|
String text = Clipboard.getText();
|
|
|
|
if (!TextUtils.isEmpty(text)) {
|
|
|
|
Tabs.getInstance().loadUrl(text);
|
2014-04-02 14:23:10 -07:00
|
|
|
Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.CONTEXT_MENU);
|
2013-05-13 09:27:53 -07:00
|
|
|
}
|
2013-08-13 16:44:00 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemId == R.id.site_settings) {
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Permissions:Get", null));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemId == R.id.paste) {
|
|
|
|
String text = Clipboard.getText();
|
|
|
|
if (!TextUtils.isEmpty(text)) {
|
2013-08-16 11:31:14 -07:00
|
|
|
enterEditingMode(text);
|
2013-05-13 09:27:53 -07:00
|
|
|
}
|
2013-08-13 16:44:00 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemId == R.id.subscribe) {
|
2014-03-24 15:38:57 -07:00
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null && tab.hasFeeds()) {
|
|
|
|
JSONObject args = new JSONObject();
|
|
|
|
try {
|
|
|
|
args.put("tabId", tab.getId());
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.e(LOGTAG, "error building json arguments");
|
|
|
|
}
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Feeds:Subscribe", args.toString()));
|
|
|
|
}
|
2013-08-13 16:44:00 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-06 15:21:56 -08:00
|
|
|
if (itemId == R.id.add_search_engine) {
|
2014-06-25 09:29:07 -07:00
|
|
|
// This can be selected from either the browser menu or the contextmenu, depending on the size and version (v11+) of the phone.
|
2013-11-06 15:21:56 -08:00
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null && tab.hasOpenSearch()) {
|
|
|
|
JSONObject args = new JSONObject();
|
|
|
|
try {
|
|
|
|
args.put("tabId", tab.getId());
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.e(LOGTAG, "error building json arguments");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SearchEngines:Add", args.toString()));
|
2014-06-25 09:29:07 -07:00
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
|
|
|
|
Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.CONTEXT_MENU, "add_search_engine");
|
|
|
|
}
|
2013-11-06 15:21:56 -08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-13 16:44:00 -07:00
|
|
|
if (itemId == R.id.copyurl) {
|
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null) {
|
|
|
|
String url = tab.getURL();
|
|
|
|
if (url != null) {
|
|
|
|
Clipboard.setText(url);
|
2013-05-13 09:27:53 -07:00
|
|
|
}
|
|
|
|
}
|
2013-08-13 16:44:00 -07:00
|
|
|
return true;
|
|
|
|
}
|
2013-07-02 10:11:48 -07:00
|
|
|
|
2014-03-24 15:38:57 -07:00
|
|
|
if (itemId == R.id.add_to_launcher) {
|
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab == null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
final String url = tab.getURL();
|
|
|
|
final String title = tab.getDisplayTitle();
|
|
|
|
if (url == null || title == null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
final OnFaviconLoadedListener listener = new GeckoAppShell.CreateShortcutFaviconLoadedListener(url, title);
|
|
|
|
Favicons.getSizedFavicon(url,
|
|
|
|
tab.getFaviconURL(),
|
|
|
|
Integer.MAX_VALUE,
|
|
|
|
LoadFaviconTask.FLAG_PERSIST,
|
|
|
|
listener);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-05-13 09:27:53 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-12 08:51:56 -07:00
|
|
|
@Override
|
|
|
|
public void setAccessibilityEnabled(boolean enabled) {
|
2014-03-13 12:29:39 -07:00
|
|
|
mDynamicToolbar.setAccessibilityEnabled(enabled);
|
2013-04-12 08:51:56 -07:00
|
|
|
}
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
2014-03-13 12:29:39 -07:00
|
|
|
mDynamicToolbar.destroy();
|
|
|
|
|
2013-01-25 10:51:41 -08:00
|
|
|
if (mBrowserToolbar != null)
|
|
|
|
mBrowserToolbar.onDestroy();
|
2012-08-26 21:33:11 -07:00
|
|
|
|
2013-07-28 13:36:47 -07:00
|
|
|
if (mFindInPageBar != null) {
|
|
|
|
mFindInPageBar.onDestroy();
|
|
|
|
mFindInPageBar = null;
|
|
|
|
}
|
|
|
|
|
2014-01-20 14:26:30 -08:00
|
|
|
if (mMediaCastingBar != null) {
|
|
|
|
mMediaCastingBar.onDestroy();
|
|
|
|
mMediaCastingBar = null;
|
|
|
|
}
|
|
|
|
|
2013-05-10 19:46:25 -07:00
|
|
|
if (mSharedPreferencesHelper != null) {
|
|
|
|
mSharedPreferencesHelper.uninit();
|
|
|
|
mSharedPreferencesHelper = null;
|
|
|
|
}
|
|
|
|
|
2013-05-10 19:47:40 -07:00
|
|
|
if (mOrderedBroadcastHelper != null) {
|
|
|
|
mOrderedBroadcastHelper.uninit();
|
|
|
|
mOrderedBroadcastHelper = null;
|
|
|
|
}
|
|
|
|
|
2013-05-30 17:42:57 -07:00
|
|
|
if (mBrowserHealthReporter != null) {
|
|
|
|
mBrowserHealthReporter.uninit();
|
|
|
|
mBrowserHealthReporter = null;
|
|
|
|
}
|
|
|
|
|
2014-05-20 13:09:54 -07:00
|
|
|
EventDispatcher.getInstance().unregisterGeckoThreadListener((GeckoEventListener)this,
|
2014-05-20 13:09:55 -07:00
|
|
|
"Menu:Update",
|
|
|
|
"Reader:Added",
|
|
|
|
"Reader:FaviconRequest",
|
|
|
|
"Prompt:ShowTop",
|
|
|
|
"Accounts:Exist");
|
|
|
|
|
|
|
|
EventDispatcher.getInstance().unregisterGeckoThreadListener((NativeEventListener)this,
|
|
|
|
"Accounts:Create",
|
2014-05-02 11:34:40 -07:00
|
|
|
"CharEncoding:Data",
|
|
|
|
"CharEncoding:State",
|
|
|
|
"Feedback:LastUrl",
|
|
|
|
"Feedback:MaybeLater",
|
2014-05-20 13:09:55 -07:00
|
|
|
"Feedback:OpenPlayStore",
|
2014-05-02 11:34:40 -07:00
|
|
|
"Menu:Add",
|
|
|
|
"Menu:Remove",
|
|
|
|
"Reader:ListStatusRequest",
|
2014-06-10 15:03:46 -07:00
|
|
|
"Reader:Removed",
|
2014-05-02 11:34:40 -07:00
|
|
|
"Reader:Share",
|
2014-05-20 13:09:55 -07:00
|
|
|
"Settings:Show",
|
|
|
|
"Telemetry:Gather",
|
|
|
|
"Updater:Launch");
|
2013-03-05 05:06:09 -08:00
|
|
|
|
2013-04-17 13:08:11 -07:00
|
|
|
if (AppConstants.MOZ_ANDROID_BEAM && Build.VERSION.SDK_INT >= 14) {
|
2013-03-05 05:06:09 -08: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-19 14:09:44 -07:00
|
|
|
|
|
|
|
super.onDestroy();
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
|
2012-10-15 10:40:16 -07:00
|
|
|
@Override
|
2013-05-16 15:07:43 -07:00
|
|
|
protected void initializeChrome() {
|
|
|
|
super.initializeChrome();
|
2012-10-15 10:40:16 -07:00
|
|
|
|
2013-11-08 07:11:42 -08:00
|
|
|
mDoorHangerPopup.setAnchor(mBrowserToolbar.getDoorHangerAnchor());
|
2013-08-27 15:03:38 -07:00
|
|
|
|
2014-03-13 12:29:39 -07:00
|
|
|
mDynamicToolbar.setLayerView(mLayerView);
|
|
|
|
setDynamicToolbarEnabled(mDynamicToolbar.isEnabled());
|
2013-04-25 10:47:08 -07:00
|
|
|
|
2013-03-12 06:22:01 -07:00
|
|
|
// Intercept key events for gamepad shortcuts
|
|
|
|
mLayerView.setOnKeyListener(this);
|
2014-02-13 20:43:00 -08:00
|
|
|
|
|
|
|
// Initialize the actionbar menu items on startup for both large and small tablets
|
|
|
|
if (HardwareUtils.isTablet()) {
|
|
|
|
onCreatePanelMenu(Window.FEATURE_OPTIONS_PANEL, null);
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
}
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
|
2013-05-13 09:27:53 -07:00
|
|
|
private void shareCurrentUrl() {
|
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
2013-11-21 23:33:28 -08:00
|
|
|
if (tab == null) {
|
|
|
|
return;
|
|
|
|
}
|
2013-05-13 09:27:53 -07:00
|
|
|
|
|
|
|
String url = tab.getURL();
|
2013-11-21 23:33:28 -08:00
|
|
|
if (url == null) {
|
2013-05-13 09:27:53 -07:00
|
|
|
return;
|
2013-11-21 23:33:28 -08:00
|
|
|
}
|
2013-05-13 09:27:53 -07:00
|
|
|
|
2013-11-21 23:33:28 -08:00
|
|
|
if (AboutPages.isAboutReader(url)) {
|
2013-05-13 09:27:53 -07:00
|
|
|
url = ReaderModeUtils.getUrlFromAboutReader(url);
|
2013-11-21 23:33:28 -08:00
|
|
|
}
|
2013-05-13 09:27:53 -07:00
|
|
|
|
|
|
|
GeckoAppShell.openUriExternal(url, "text/plain", "", "",
|
|
|
|
Intent.ACTION_SEND, tab.getDisplayTitle());
|
2014-05-01 19:02:29 -07:00
|
|
|
|
|
|
|
// Context: Sharing via chrome list (no explicit session is active)
|
|
|
|
Telemetry.sendUIEvent(TelemetryContract.Event.SHARE, TelemetryContract.Method.LIST);
|
2013-05-13 09:27:53 -07:00
|
|
|
}
|
|
|
|
|
2013-05-16 15:07:43 -07:00
|
|
|
@Override
|
|
|
|
protected void loadStartupTab(String url) {
|
|
|
|
// We aren't showing about:home, so cancel the telemetry timer
|
2013-09-10 11:17:42 -07:00
|
|
|
if (url != null || mShouldRestore) {
|
2013-05-16 15:07:43 -07:00
|
|
|
mAboutHomeStartupTimer.cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
super.loadStartupTab(url);
|
|
|
|
}
|
|
|
|
|
2013-03-22 03:26:26 -07:00
|
|
|
private void setToolbarMargin(int margin) {
|
|
|
|
((RelativeLayout.LayoutParams) mGeckoLayout.getLayoutParams()).topMargin = margin;
|
|
|
|
mGeckoLayout.requestLayout();
|
|
|
|
}
|
|
|
|
|
2013-04-25 10:47:08 -07:00
|
|
|
@Override
|
|
|
|
public void onMetricsChanged(ImmutableViewportMetrics aMetrics) {
|
2013-11-22 15:18:04 -08:00
|
|
|
if (isHomePagerVisible() || mViewFlipper == null) {
|
2013-04-25 10:47:08 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-25 00:59:48 -07:00
|
|
|
// If the page has shrunk so that the toolbar no longer scrolls, make
|
|
|
|
// sure the toolbar is visible.
|
2013-07-15 09:03:22 -07:00
|
|
|
if (aMetrics.getPageHeight() <= aMetrics.getHeight()) {
|
2013-05-25 00:59:48 -07:00
|
|
|
if (mDynamicToolbarCanScroll) {
|
|
|
|
mDynamicToolbarCanScroll = false;
|
2013-11-22 15:18:04 -08:00
|
|
|
if (mViewFlipper.getVisibility() != View.VISIBLE) {
|
2013-05-25 00:59:48 -07:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
|
|
|
public void run() {
|
2014-03-13 12:29:39 -07:00
|
|
|
mDynamicToolbar.setVisible(true, VisibilityTransition.ANIMATE);
|
2013-05-25 00:59:48 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mDynamicToolbarCanScroll = true;
|
|
|
|
}
|
|
|
|
|
2013-11-22 15:18:04 -08:00
|
|
|
final View toolbarLayout = mViewFlipper;
|
2013-04-25 10:47:08 -07:00
|
|
|
final int marginTop = Math.round(aMetrics.marginTop);
|
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
|
|
|
public void run() {
|
2014-03-18 10:36:23 -07:00
|
|
|
final float translationY = marginTop - toolbarLayout.getHeight();
|
|
|
|
ViewHelper.setTranslationY(toolbarLayout, translationY);
|
|
|
|
ViewHelper.setTranslationY(mProgressView, translationY);
|
2013-11-22 05:33:15 -08:00
|
|
|
|
2013-11-14 16:06:01 -08:00
|
|
|
if (mDoorHangerPopup.isShowing()) {
|
|
|
|
mDoorHangerPopup.updatePopup();
|
|
|
|
}
|
2013-04-25 10:47:08 -07:00
|
|
|
}
|
|
|
|
});
|
2013-06-19 08:35:44 -07:00
|
|
|
|
|
|
|
if (mFormAssistPopup != null)
|
|
|
|
mFormAssistPopup.onMetricsChanged(aMetrics);
|
2013-04-25 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPanZoomStopped() {
|
2014-03-13 12:29:39 -07:00
|
|
|
if (!mDynamicToolbar.isEnabled() || isHomePagerVisible()) {
|
2013-04-25 10:47:08 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-25 00:59:48 -07:00
|
|
|
// Make sure the toolbar is fully hidden or fully shown when the user
|
|
|
|
// lifts their finger. If the page is shorter than the viewport, the
|
|
|
|
// toolbar is always shown.
|
2013-04-25 10:47:08 -07:00
|
|
|
ImmutableViewportMetrics metrics = mLayerView.getViewportMetrics();
|
2013-05-25 00:59:48 -07:00
|
|
|
if (metrics.getPageHeight() < metrics.getHeight()
|
|
|
|
|| metrics.marginTop >= mToolbarHeight / 2) {
|
2014-03-13 12:29:39 -07:00
|
|
|
mDynamicToolbar.setVisible(true, VisibilityTransition.ANIMATE);
|
2013-04-25 10:47:08 -07:00
|
|
|
} else {
|
2014-03-13 12:29:39 -07:00
|
|
|
mDynamicToolbar.setVisible(false, VisibilityTransition.ANIMATE);
|
2013-04-25 10:47:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void refreshToolbarHeight() {
|
2014-03-13 12:29:39 -07:00
|
|
|
ThreadUtils.assertOnUiThread();
|
|
|
|
|
2013-04-25 10:47:08 -07:00
|
|
|
int height = 0;
|
2013-11-19 11:57:35 -08:00
|
|
|
if (mViewFlipper != null) {
|
|
|
|
height = mViewFlipper.getHeight();
|
2013-04-25 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
2014-03-13 12:29:39 -07:00
|
|
|
if (!mDynamicToolbar.isEnabled() || isHomePagerVisible()) {
|
2013-03-07 02:17:34 -08:00
|
|
|
// Use aVisibleHeight here so that when the dynamic toolbar is
|
|
|
|
// enabled, the padding will animate with the toolbar becoming
|
|
|
|
// visible.
|
2014-03-13 12:29:39 -07:00
|
|
|
if (mDynamicToolbar.isEnabled()) {
|
2013-03-07 02:17:34 -08:00
|
|
|
// 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.
|
2013-07-08 15:05:50 -07:00
|
|
|
mHomePagerContainer.setPadding(0, height, 0, 0);
|
2013-03-07 02:17:34 -08:00
|
|
|
} else {
|
2013-04-25 10:47:08 -07:00
|
|
|
setToolbarMargin(height);
|
|
|
|
height = 0;
|
2013-03-07 02:17:34 -08:00
|
|
|
}
|
|
|
|
} else {
|
2013-03-22 03:26:26 -07:00
|
|
|
setToolbarMargin(0);
|
2013-03-07 02:17:34 -08:00
|
|
|
}
|
|
|
|
|
2013-04-25 10:47:08 -07:00
|
|
|
if (mLayerView != null && height != mToolbarHeight) {
|
|
|
|
mToolbarHeight = height;
|
|
|
|
mLayerView.getLayerMarginsAnimator().setMaxMargins(0, height, 0, 0);
|
2014-03-13 12:29:39 -07:00
|
|
|
mDynamicToolbar.setVisible(true, VisibilityTransition.IMMEDIATE);
|
2013-03-07 02:17:34 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-27 12:18:01 -08:00
|
|
|
@Override
|
2012-06-11 15:18:40 -07:00
|
|
|
void toggleChrome(final boolean aShow) {
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-06-11 15:18:40 -07:00
|
|
|
public void run() {
|
|
|
|
if (aShow) {
|
2013-11-19 11:57:35 -08:00
|
|
|
mViewFlipper.setVisibility(View.VISIBLE);
|
2012-06-11 15:18:40 -07:00
|
|
|
} else {
|
2013-11-19 11:57:35 -08:00
|
|
|
mViewFlipper.setVisibility(View.GONE);
|
2012-11-27 12:18:16 -08:00
|
|
|
if (hasTabsSideBar()) {
|
|
|
|
hideTabs();
|
|
|
|
}
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
super.toggleChrome(aShow);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
void focusChrome() {
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-06-11 15:18:40 -07:00
|
|
|
public void run() {
|
2013-11-19 11:57:35 -08:00
|
|
|
mViewFlipper.setVisibility(View.VISIBLE);
|
|
|
|
mViewFlipper.requestFocusFromTouch();
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void refreshChrome() {
|
2012-06-19 14:09:44 -07:00
|
|
|
invalidateOptionsMenu();
|
2014-02-06 00:59:50 -08:00
|
|
|
|
|
|
|
if (mTabsPanel != null) {
|
|
|
|
updateSideBarState();
|
|
|
|
mTabsPanel.refresh();
|
|
|
|
}
|
|
|
|
|
2013-12-11 16:28:14 -08:00
|
|
|
mBrowserToolbar.refresh();
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
|
2012-07-23 13:08:48 -07:00
|
|
|
@Override
|
|
|
|
public boolean hasTabsSideBar() {
|
|
|
|
return (mTabsPanel != null && mTabsPanel.isSideBar());
|
|
|
|
}
|
|
|
|
|
2013-02-21 23:22:37 -08:00
|
|
|
private void updateSideBarState() {
|
2013-02-21 23:23:16 -08:00
|
|
|
if (mMainLayoutAnimator != null)
|
|
|
|
mMainLayoutAnimator.stop();
|
|
|
|
|
2014-02-20 09:50:18 -08:00
|
|
|
boolean isSideBar = (HardwareUtils.isTablet() && getOrientation() == Configuration.ORIENTATION_LANDSCAPE);
|
2013-05-03 06:16:57 -07:00
|
|
|
final int sidebarWidth = getResources().getDimensionPixelSize(R.dimen.tabs_sidebar_width);
|
2013-02-21 23:22:37 -08:00
|
|
|
|
2013-05-03 06:16:57 -07:00
|
|
|
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mTabsPanel.getLayoutParams();
|
2014-06-20 09:21:31 -07:00
|
|
|
lp.width = (isSideBar ? sidebarWidth : ViewGroup.LayoutParams.MATCH_PARENT);
|
2013-02-21 23:22:37 -08:00
|
|
|
mTabsPanel.requestLayout();
|
|
|
|
|
2013-05-03 06:16:57 -07:00
|
|
|
final boolean sidebarIsShown = (isSideBar && mTabsPanel.isShown());
|
|
|
|
final int mainLayoutScrollX = (sidebarIsShown ? -sidebarWidth : 0);
|
|
|
|
mMainLayout.scrollTo(mainLayoutScrollX, 0);
|
2013-02-21 23:23:16 -08:00
|
|
|
|
2013-05-03 06:16:57 -07:00
|
|
|
mTabsPanel.setIsSideBar(isSideBar);
|
2013-02-21 23:22:37 -08:00
|
|
|
}
|
|
|
|
|
2014-05-20 13:09:55 -07:00
|
|
|
@Override
|
|
|
|
public void handleMessage(final String event, final NativeJSObject message,
|
|
|
|
final EventCallback callback) {
|
|
|
|
if ("Accounts:Create".equals(event)) {
|
|
|
|
// Do exactly the same thing as if you tapped 'Sync' in Settings.
|
|
|
|
final Intent intent = new Intent(getContext(), FxAccountGetStartedActivity.class);
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
2014-06-22 12:01:15 -07:00
|
|
|
final NativeJSObject extras = message.optObject("extras", null);
|
|
|
|
if (extras != null) {
|
|
|
|
intent.putExtra("extras", extras.toString());
|
|
|
|
}
|
2014-05-20 13:09:55 -07:00
|
|
|
getContext().startActivity(intent);
|
|
|
|
|
|
|
|
} else if ("CharEncoding:Data".equals(event)) {
|
|
|
|
final NativeJSObject[] charsets = message.getObjectArray("charsets");
|
|
|
|
final int selected = message.getInt("selected");
|
|
|
|
|
|
|
|
final String[] titleArray = new String[charsets.length];
|
|
|
|
final String[] codeArray = new String[charsets.length];
|
|
|
|
for (int i = 0; i < charsets.length; i++) {
|
|
|
|
final NativeJSObject charset = charsets[i];
|
|
|
|
titleArray[i] = charset.getString("title");
|
|
|
|
codeArray[i] = charset.getString("code");
|
|
|
|
}
|
|
|
|
|
|
|
|
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
|
|
|
|
dialogBuilder.setSingleChoiceItems(titleArray, selected,
|
|
|
|
new AlertDialog.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(final DialogInterface dialog, final int which) {
|
|
|
|
GeckoAppShell.sendEventToGecko(
|
|
|
|
GeckoEvent.createBroadcastEvent("CharEncoding:Set", codeArray[which]));
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogBuilder.setNegativeButton(R.string.button_cancel,
|
|
|
|
new AlertDialog.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(final DialogInterface dialog, final int which) {
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
dialogBuilder.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
} else if ("CharEncoding:State".equals(event)) {
|
|
|
|
final boolean visible = message.getString("visible").equals("true");
|
|
|
|
GeckoPreferences.setCharEncodingState(visible);
|
|
|
|
final Menu menu = mMenu;
|
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (menu != null) {
|
|
|
|
menu.findItem(R.id.char_encoding).setVisible(visible);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
} else if ("Feedback:LastUrl".equals(event)) {
|
|
|
|
getLastUrl();
|
|
|
|
|
|
|
|
} else if ("Feedback:MaybeLater".equals(event)) {
|
|
|
|
resetFeedbackLaunchCount();
|
|
|
|
|
|
|
|
} else if ("Feedback:OpenPlayStore".equals(event)) {
|
|
|
|
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.setData(Uri.parse("market://details?id=" + getPackageName()));
|
|
|
|
startActivity(intent);
|
|
|
|
|
|
|
|
} else if ("Menu:Add".equals(event)) {
|
|
|
|
final MenuItemInfo info = new MenuItemInfo();
|
|
|
|
info.label = message.getString("name");
|
|
|
|
info.id = message.getInt("id") + ADDON_MENU_OFFSET;
|
|
|
|
info.icon = message.optString("icon", null);
|
|
|
|
info.checked = message.optBoolean("checked", false);
|
|
|
|
info.enabled = message.optBoolean("enabled", true);
|
|
|
|
info.visible = message.optBoolean("visible", true);
|
|
|
|
info.checkable = message.optBoolean("checkable", false);
|
|
|
|
final int parent = message.optInt("parent", 0);
|
|
|
|
info.parent = parent <= 0 ? parent : parent + ADDON_MENU_OFFSET;
|
|
|
|
final MenuItemInfo menuItemInfo = info;
|
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
addAddonMenuItem(menuItemInfo);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
} else if ("Menu:Remove".equals(event)) {
|
|
|
|
final int id = message.getInt("id") + ADDON_MENU_OFFSET;
|
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
removeAddonMenuItem(id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
} else if ("Reader:ListStatusRequest".equals(event)) {
|
|
|
|
handleReaderListStatusRequest(message.getString("url"));
|
|
|
|
|
2014-06-10 15:03:46 -07:00
|
|
|
} else if ("Reader:Removed".equals(event)) {
|
|
|
|
final String url = message.getString("url");
|
|
|
|
handleReaderRemoved(url);
|
|
|
|
|
2014-05-20 13:09:55 -07:00
|
|
|
} else if ("Reader:Share".equals(event)) {
|
|
|
|
final String title = message.getString("title");
|
|
|
|
final String url = message.getString("url");
|
|
|
|
GeckoAppShell.openUriExternal(url, "text/plain", "", "", Intent.ACTION_SEND, title);
|
|
|
|
|
|
|
|
} else if ("Settings:Show".equals(event)) {
|
|
|
|
final String resource =
|
|
|
|
message.optString(GeckoPreferences.INTENT_EXTRA_RESOURCES, null);
|
|
|
|
final Intent settingsIntent = new Intent(this, GeckoPreferences.class);
|
|
|
|
GeckoPreferences.setResourceToOpen(settingsIntent, resource);
|
|
|
|
startActivityForResult(settingsIntent, ACTIVITY_REQUEST_PREFERENCES);
|
|
|
|
|
|
|
|
} else if ("Telemetry:Gather".equals(event)) {
|
|
|
|
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"));
|
|
|
|
|
|
|
|
} else if ("Updater:Launch".equals(event)) {
|
|
|
|
handleUpdaterLaunch();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
super.handleMessage(event, message, callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-26 23:53:48 -07:00
|
|
|
@Override
|
|
|
|
public void handleMessage(String event, JSONObject message) {
|
|
|
|
try {
|
2014-05-20 13:09:55 -07:00
|
|
|
if (event.equals("Menu:Update")) {
|
2012-10-29 16:29:55 -07:00
|
|
|
final int id = message.getInt("id") + ADDON_MENU_OFFSET;
|
|
|
|
final JSONObject options = message.getJSONObject("options");
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-10-29 16:29:55 -07:00
|
|
|
public void run() {
|
|
|
|
updateAddonMenuItem(id, options);
|
|
|
|
}
|
|
|
|
});
|
2014-02-06 00:59:50 -08:00
|
|
|
} else if (event.equals("Gecko:DelayedStartup")) {
|
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
// Force tabs panel inflation once the initial
|
|
|
|
// pageload is finished.
|
|
|
|
ensureTabsPanelExists();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
super.handleMessage(event, message);
|
2012-08-30 11:15:19 -07: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 03:52:53 -07:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-08-30 11:15:19 -07:00
|
|
|
public void run() {
|
2014-05-22 13:31:40 -07:00
|
|
|
if (menu != null) {
|
2012-08-30 11:15:19 -07:00
|
|
|
menu.findItem(R.id.settings).setEnabled(true);
|
2014-05-22 13:31:40 -07:00
|
|
|
menu.findItem(R.id.help).setEnabled(true);
|
|
|
|
}
|
2012-08-30 11:15:19 -07:00
|
|
|
}
|
|
|
|
});
|
2013-05-10 21:29:09 -07:00
|
|
|
|
|
|
|
// Display notification for Mozilla data reporting, if data should be collected.
|
|
|
|
if (AppConstants.MOZ_DATA_REPORTING) {
|
2013-05-24 09:21:01 -07:00
|
|
|
DataReportingNotification.checkAndNotifyPolicy(GeckoAppShell.getContext());
|
2013-05-10 21:29:09 -07:00
|
|
|
}
|
|
|
|
|
2013-02-24 20:51:04 -08:00
|
|
|
} else if (event.equals("Reader:Added")) {
|
2013-04-17 03:43:22 -07:00
|
|
|
final int result = message.getInt("result");
|
2014-03-12 14:53:25 -07:00
|
|
|
handleReaderAdded(result, messageToReadingListContentValues(message));
|
2014-04-28 16:19:38 -07:00
|
|
|
} else if (event.equals("Reader:FaviconRequest")) {
|
|
|
|
final String url = message.getString("url");
|
|
|
|
handleReaderFaviconRequest(url);
|
2013-07-31 15:38:48 -07:00
|
|
|
} else if (event.equals("Prompt:ShowTop")) {
|
|
|
|
// Bring this activity to front so the prompt is visible..
|
|
|
|
Intent bringToFrontIntent = new Intent();
|
2014-04-01 22:00:46 -07:00
|
|
|
bringToFrontIntent.setClassName(AppConstants.ANDROID_PACKAGE_NAME, AppConstants.BROWSER_INTENT_CLASS_NAME);
|
2013-07-31 15:38:48 -07:00
|
|
|
bringToFrontIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
|
|
|
startActivity(bringToFrontIntent);
|
2014-02-18 19:20:27 -08:00
|
|
|
} else if (event.equals("Accounts:Exist")) {
|
|
|
|
final String kind = message.getString("kind");
|
|
|
|
final JSONObject response = new JSONObject();
|
|
|
|
|
|
|
|
if ("any".equals(kind)) {
|
|
|
|
response.put("exists", SyncAccounts.syncAccountsExist(getContext()) ||
|
|
|
|
FirefoxAccounts.firefoxAccountsExist(getContext()));
|
|
|
|
EventDispatcher.sendResponse(message, response);
|
|
|
|
} else if ("fxa".equals(kind)) {
|
|
|
|
response.put("exists", FirefoxAccounts.firefoxAccountsExist(getContext()));
|
|
|
|
EventDispatcher.sendResponse(message, response);
|
|
|
|
} else if ("sync11".equals(kind)) {
|
|
|
|
response.put("exists", SyncAccounts.syncAccountsExist(getContext()));
|
|
|
|
EventDispatcher.sendResponse(message, response);
|
|
|
|
} else {
|
|
|
|
response.put("error", "Unknown kind");
|
|
|
|
EventDispatcher.sendError(message, response);
|
|
|
|
}
|
2012-07-26 23:53:48 -07:00
|
|
|
} else {
|
|
|
|
super.handleMessage(event, message);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2013-01-02 13:43:01 -08:00
|
|
|
public void addTab() {
|
2013-12-17 22:43:30 -08:00
|
|
|
// Always load about:home when opening a new tab.
|
|
|
|
Tabs.getInstance().loadUrl(AboutPages.HOME, Tabs.LOADURL_NEW_TAB);
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2013-01-02 13:43:01 -08:00
|
|
|
public void addPrivateTab() {
|
2013-11-21 23:33:28 -08:00
|
|
|
Tabs.getInstance().loadUrl(AboutPages.PRIVATEBROWSING, Tabs.LOADURL_NEW_TAB | Tabs.LOADURL_PRIVATE);
|
2013-01-02 13:43:01 -08:00
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-12-18 17:04:39 -08:00
|
|
|
public void showNormalTabs() {
|
|
|
|
showTabs(TabsPanel.Panel.NORMAL_TABS);
|
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-12-18 17:04:39 -08:00
|
|
|
public void showPrivateTabs() {
|
|
|
|
showTabs(TabsPanel.Panel.PRIVATE_TABS);
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
2014-02-06 00:59:50 -08:00
|
|
|
/**
|
2014-04-15 04:13:00 -07:00
|
|
|
* Ensure the TabsPanel view is properly inflated and returns
|
|
|
|
* true when the view has been inflated, false otherwise.
|
|
|
|
*/
|
2014-02-06 00:59:50 -08:00
|
|
|
private boolean ensureTabsPanelExists() {
|
|
|
|
if (mTabsPanel != null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ViewStub tabsPanelStub = (ViewStub) findViewById(R.id.tabs_panel);
|
|
|
|
mTabsPanel = (TabsPanel) tabsPanelStub.inflate();
|
|
|
|
|
|
|
|
mTabsPanel.setTabsLayoutChangeListener(this);
|
|
|
|
updateSideBarState();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showTabs(final TabsPanel.Panel panel) {
|
2013-03-11 16:09:14 -07:00
|
|
|
if (Tabs.getInstance().getDisplayCount() == 0)
|
2012-06-11 15:18:40 -07:00
|
|
|
return;
|
|
|
|
|
2014-02-06 00:59:50 -08:00
|
|
|
if (ensureTabsPanelExists()) {
|
|
|
|
// If we've just inflated the tabs panel, only show it once the current
|
|
|
|
// layout pass is done to avoid displayed temporary UI states during
|
|
|
|
// relayout.
|
|
|
|
ViewTreeObserver vto = mTabsPanel.getViewTreeObserver();
|
|
|
|
if (vto.isAlive()) {
|
|
|
|
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
|
|
|
@Override
|
|
|
|
public void onGlobalLayout() {
|
|
|
|
mTabsPanel.getViewTreeObserver().removeGlobalOnLayoutListener(this);
|
|
|
|
mTabsPanel.show(panel);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mTabsPanel.show(panel);
|
|
|
|
}
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-06-11 15:18:40 -07:00
|
|
|
public void hideTabs() {
|
|
|
|
mTabsPanel.hide();
|
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-06-19 13:37:57 -07:00
|
|
|
public boolean autoHideTabs() {
|
2013-05-03 06:16:57 -07:00
|
|
|
if (areTabsShown()) {
|
2012-06-19 13:37:57 -07:00
|
|
|
hideTabs();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-06-11 15:18:40 -07:00
|
|
|
public boolean areTabsShown() {
|
2014-02-06 00:59:50 -08:00
|
|
|
return (mTabsPanel != null && mTabsPanel.isShown());
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
|
2012-06-12 22:47:52 -07:00
|
|
|
@Override
|
|
|
|
public void onTabsLayoutChange(int width, int height) {
|
2013-03-20 16:43:47 -07:00
|
|
|
int animationLength = TABS_ANIMATION_DURATION;
|
|
|
|
|
|
|
|
if (mMainLayoutAnimator != null) {
|
|
|
|
animationLength = Math.max(1, animationLength - (int)mMainLayoutAnimator.getRemainingTime());
|
|
|
|
mMainLayoutAnimator.stop(false);
|
|
|
|
}
|
2012-06-12 22:47:52 -07:00
|
|
|
|
2013-05-03 06:16:57 -07:00
|
|
|
if (areTabsShown()) {
|
2012-07-11 16:11:42 -07:00
|
|
|
mTabsPanel.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
|
2013-05-03 06:16:57 -07:00
|
|
|
}
|
2012-07-11 16:11:42 -07:00
|
|
|
|
2013-03-20 16:43:47 -07:00
|
|
|
mMainLayoutAnimator = new PropertyAnimator(animationLength, sTabsInterpolator);
|
2013-07-26 04:46:28 -07:00
|
|
|
mMainLayoutAnimator.addPropertyAnimationListener(this);
|
2012-06-12 22:47:52 -07:00
|
|
|
|
2012-07-23 13:08:48 -07:00
|
|
|
if (hasTabsSideBar()) {
|
2013-05-03 06:16:57 -07:00
|
|
|
mMainLayoutAnimator.attach(mMainLayout,
|
2013-02-21 23:22:37 -08:00
|
|
|
PropertyAnimator.Property.SCROLL_X,
|
|
|
|
-width);
|
2012-06-12 22:47:52 -07:00
|
|
|
} else {
|
|
|
|
mMainLayoutAnimator.attach(mMainLayout,
|
2013-02-21 23:22:37 -08:00
|
|
|
PropertyAnimator.Property.SCROLL_Y,
|
|
|
|
-height);
|
2012-06-12 22:47:52 -07:00
|
|
|
}
|
|
|
|
|
2013-05-03 06:16:57 -07:00
|
|
|
mTabsPanel.prepareTabsAnimation(mMainLayoutAnimator);
|
2013-05-30 11:47:44 -07:00
|
|
|
mBrowserToolbar.prepareTabsAnimation(mMainLayoutAnimator, areTabsShown());
|
2013-05-03 06:16:57 -07:00
|
|
|
|
2013-03-16 18:53:41 -07:00
|
|
|
// If the tabs layout is animating onto the screen, pin the dynamic
|
|
|
|
// toolbar.
|
2014-03-13 12:29:39 -07:00
|
|
|
if (mDynamicToolbar.isEnabled()) {
|
2013-04-25 10:47:08 -07:00
|
|
|
if (width > 0 && height > 0) {
|
2014-03-13 12:29:39 -07:00
|
|
|
mDynamicToolbar.setPinned(true, PinReason.RELAYOUT);
|
|
|
|
mDynamicToolbar.setVisible(true, VisibilityTransition.ANIMATE);
|
2013-04-25 10:47:08 -07:00
|
|
|
} else {
|
2014-03-13 12:29:39 -07:00
|
|
|
mDynamicToolbar.setPinned(false, PinReason.RELAYOUT);
|
2013-04-25 10:47:08 -07:00
|
|
|
}
|
2013-03-16 18:53:41 -07:00
|
|
|
}
|
|
|
|
|
2012-06-12 22:47:52 -07:00
|
|
|
mMainLayoutAnimator.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationStart() {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationEnd() {
|
2013-05-03 06:16:57 -07:00
|
|
|
if (!areTabsShown()) {
|
2013-02-19 12:39:05 -08:00
|
|
|
mTabsPanel.setVisibility(View.INVISIBLE);
|
2012-10-12 04:57:07 -07:00
|
|
|
mTabsPanel.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
|
|
|
|
}
|
2012-10-31 22:07:49 -07:00
|
|
|
|
2013-04-26 06:12:08 -07:00
|
|
|
mTabsPanel.finishTabsAnimation();
|
2013-05-07 10:19:19 -07:00
|
|
|
|
2013-03-20 16:43:47 -07:00
|
|
|
mMainLayoutAnimator = null;
|
2012-06-12 22:47:52 -07:00
|
|
|
}
|
|
|
|
|
2013-05-23 11:29:43 -07:00
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState(Bundle outState) {
|
|
|
|
super.onSaveInstanceState(outState);
|
2014-03-13 12:29:39 -07:00
|
|
|
mDynamicToolbar.onSaveInstanceState(outState);
|
2013-07-25 14:26:01 -07:00
|
|
|
outState.putInt(STATE_ABOUT_HOME_TOP_PADDING, mHomePagerContainer.getPaddingTop());
|
2013-05-23 11:29:43 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 11:44:46 -07:00
|
|
|
/**
|
|
|
|
* Attempts to switch to an open tab with the given URL.
|
|
|
|
*
|
|
|
|
* @return true if we successfully switched to a tab, false otherwise.
|
|
|
|
*/
|
|
|
|
private boolean maybeSwitchToTab(String url, EnumSet<OnUrlOpenListener.Flags> flags) {
|
|
|
|
if (!flags.contains(OnUrlOpenListener.Flags.ALLOW_SWITCH_TO_TAB)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
final Tabs tabs = Tabs.getInstance();
|
2014-05-20 15:55:46 -07:00
|
|
|
final Tab tab;
|
|
|
|
|
|
|
|
if (AboutPages.isAboutReader(url)) {
|
|
|
|
tab = tabs.getFirstReaderTabForUrl(url, tabs.getSelectedTab().isPrivate());
|
|
|
|
} else {
|
|
|
|
tab = tabs.getFirstTabForUrl(url, tabs.getSelectedTab().isPrivate());
|
|
|
|
}
|
|
|
|
|
2014-01-28 11:56:26 -08:00
|
|
|
if (tab == null) {
|
2013-08-12 11:44:46 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-23 15:18:22 -07:00
|
|
|
// Set the target tab to null so it does not get selected (on editing
|
|
|
|
// mode exit) in lieu of the tab we are about to select.
|
|
|
|
mTargetTabForEditingMode = null;
|
2014-01-28 11:56:26 -08:00
|
|
|
tabs.selectTab(tab.getId());
|
2013-08-12 11:44:46 -07:00
|
|
|
|
|
|
|
mBrowserToolbar.cancelEdit();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-14 17:10:27 -07:00
|
|
|
private void openUrlAndStopEditing(String url) {
|
|
|
|
openUrlAndStopEditing(url, null, false);
|
2013-07-12 14:51:28 -07:00
|
|
|
}
|
|
|
|
|
2013-10-14 17:10:27 -07:00
|
|
|
private void openUrlAndStopEditing(String url, boolean newTab) {
|
|
|
|
openUrlAndStopEditing(url, null, newTab);
|
2013-06-11 10:01:35 -07:00
|
|
|
}
|
|
|
|
|
2013-10-14 17:10:27 -07:00
|
|
|
private void openUrlAndStopEditing(String url, String searchEngine) {
|
|
|
|
openUrlAndStopEditing(url, searchEngine, false);
|
2013-07-12 14:51:28 -07:00
|
|
|
}
|
|
|
|
|
2013-10-14 17:10:27 -07:00
|
|
|
private void openUrlAndStopEditing(String url, String searchEngine, boolean newTab) {
|
2013-06-11 09:57:45 -07:00
|
|
|
int flags = Tabs.LOADURL_NONE;
|
2013-07-23 17:52:36 -07:00
|
|
|
if (newTab) {
|
2013-06-11 09:57:45 -07:00
|
|
|
flags |= Tabs.LOADURL_NEW_TAB;
|
|
|
|
}
|
|
|
|
|
2013-06-11 10:01:35 -07:00
|
|
|
Tabs.getInstance().loadUrl(url, searchEngine, -1, flags);
|
2013-06-11 09:57:45 -07:00
|
|
|
|
2013-06-11 09:57:45 -07:00
|
|
|
mBrowserToolbar.cancelEdit();
|
|
|
|
}
|
|
|
|
|
2013-08-21 02:15:37 -07:00
|
|
|
private boolean isHomePagerVisible() {
|
2014-04-10 13:52:12 -07:00
|
|
|
return (mHomePager != null && mHomePager.isVisible()
|
2014-02-13 15:43:48 -08:00
|
|
|
&& mHomePagerContainer != null && mHomePagerContainer.getVisibility() == View.VISIBLE);
|
2013-08-21 02:15:37 -07:00
|
|
|
}
|
|
|
|
|
2013-11-04 11:48:58 -08:00
|
|
|
/* Favicon stuff. */
|
|
|
|
private static OnFaviconLoadedListener sFaviconLoadedListener = new OnFaviconLoadedListener() {
|
|
|
|
@Override
|
|
|
|
public void onFaviconLoaded(String pageUrl, String faviconURL, Bitmap favicon) {
|
|
|
|
// If we failed to load a favicon, we use the default favicon instead.
|
|
|
|
Tabs.getInstance()
|
|
|
|
.updateFaviconForURL(pageUrl,
|
2014-03-12 09:20:38 -07:00
|
|
|
(favicon == null) ? Favicons.defaultFavicon : favicon);
|
2013-11-04 11:48:58 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
private void loadFavicon(final Tab tab) {
|
|
|
|
maybeCancelFaviconLoad(tab);
|
|
|
|
|
2013-10-11 16:42:39 -07:00
|
|
|
final int tabFaviconSize = getResources().getDimensionPixelSize(R.dimen.browser_toolbar_favicon_size);
|
2012-06-11 15:18:40 -07:00
|
|
|
|
2013-10-11 16:42:39 -07:00
|
|
|
int flags = (tab.isPrivate() || tab.getErrorType() != Tab.ErrorType.NONE) ? 0 : LoadFaviconTask.FLAG_PERSIST;
|
2014-01-08 13:42:45 -08:00
|
|
|
int id = Favicons.getSizedFavicon(tab.getURL(), tab.getFaviconURL(), tabFaviconSize, flags, sFaviconLoadedListener);
|
2013-12-18 11:37:41 -08:00
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
tab.setFaviconLoadId(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void maybeCancelFaviconLoad(Tab tab) {
|
2013-09-12 07:50:03 -07:00
|
|
|
int faviconLoadId = tab.getFaviconLoadId();
|
2012-06-11 15:18:40 -07:00
|
|
|
|
2013-11-26 19:48:30 -08:00
|
|
|
if (Favicons.NOT_LOADING == faviconLoadId) {
|
|
|
|
return;
|
|
|
|
}
|
2012-06-11 15:18:40 -07:00
|
|
|
|
2013-11-26 19:48:30 -08:00
|
|
|
// Cancel load task and reset favicon load state if it wasn't already
|
|
|
|
// in NOT_LOADING state.
|
|
|
|
Favicons.cancelFaviconLoad(faviconLoadId);
|
2012-06-11 15:18:40 -07:00
|
|
|
tab.setFaviconLoadId(Favicons.NOT_LOADING);
|
|
|
|
}
|
|
|
|
|
2013-09-06 03:41:36 -07:00
|
|
|
/**
|
|
|
|
* Enters editing mode with the current tab's URL. There might be no
|
|
|
|
* tabs loaded by the time the user enters editing mode e.g. just after
|
|
|
|
* the app starts. In this case, we simply fallback to an empty URL.
|
|
|
|
*/
|
2013-07-23 17:52:36 -07:00
|
|
|
private void enterEditingMode() {
|
2013-09-06 03:41:36 -07:00
|
|
|
String url = "";
|
2013-08-14 15:40:35 -07:00
|
|
|
|
|
|
|
final Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null) {
|
|
|
|
final String userSearch = tab.getUserSearch();
|
|
|
|
|
|
|
|
// Check to see if there's a user-entered search term,
|
|
|
|
// which we save whenever the user performs a search.
|
|
|
|
url = (TextUtils.isEmpty(userSearch) ? tab.getURL() : userSearch);
|
|
|
|
}
|
|
|
|
|
|
|
|
enterEditingMode(url);
|
2013-07-22 12:22:19 -07:00
|
|
|
}
|
|
|
|
|
2013-07-23 17:52:36 -07:00
|
|
|
/**
|
2013-09-06 03:41:36 -07:00
|
|
|
* Enters editing mode with the specified URL. This method will
|
|
|
|
* always open the HISTORY page on about:home.
|
2013-07-23 17:52:36 -07:00
|
|
|
*/
|
|
|
|
private void enterEditingMode(String url) {
|
2013-08-14 15:40:35 -07:00
|
|
|
if (url == null) {
|
|
|
|
throw new IllegalArgumentException("Cannot handle null URLs in enterEditingMode");
|
2013-05-13 10:20:49 -07:00
|
|
|
}
|
2014-05-30 09:42:41 -07:00
|
|
|
|
|
|
|
if (mBrowserToolbar.isEditing() || mBrowserToolbar.isAnimating()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-05-13 10:20:49 -07:00
|
|
|
|
2013-10-21 12:11:08 -07:00
|
|
|
final Tab selectedTab = Tabs.getInstance().getSelectedTab();
|
|
|
|
mTargetTabForEditingMode = (selectedTab != null ? selectedTab.getId() : null);
|
|
|
|
|
2013-08-16 15:08:05 -07:00
|
|
|
final PropertyAnimator animator = new PropertyAnimator(250);
|
2013-07-26 04:46:28 -07:00
|
|
|
animator.setUseHardwareLayer(false);
|
|
|
|
|
|
|
|
mBrowserToolbar.startEditing(url, animator);
|
2014-01-17 10:41:15 -08:00
|
|
|
|
|
|
|
final String panelId = selectedTab.getMostRecentHomePanel();
|
|
|
|
showHomePagerWithAnimator(panelId, animator);
|
2013-07-26 04:46:28 -07:00
|
|
|
|
|
|
|
animator.start();
|
2014-05-14 11:29:42 -07:00
|
|
|
Telemetry.startUISession(TelemetryContract.Session.AWESOMESCREEN);
|
2013-05-13 10:20:49 -07:00
|
|
|
}
|
|
|
|
|
2013-09-13 16:07:17 -07:00
|
|
|
private void commitEditingMode() {
|
2013-05-13 10:20:49 -07:00
|
|
|
if (!mBrowserToolbar.isEditing()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-14 11:29:42 -07:00
|
|
|
Telemetry.stopUISession(TelemetryContract.Session.AWESOMESCREEN,
|
|
|
|
TelemetryContract.Reason.COMMIT);
|
|
|
|
|
2013-05-17 14:24:10 -07:00
|
|
|
final String url = mBrowserToolbar.commitEdit();
|
2013-05-13 10:20:49 -07:00
|
|
|
|
2013-11-15 09:42:58 -08:00
|
|
|
// HACK: We don't know the url that will be loaded when hideHomePager is initially called
|
|
|
|
// in BrowserToolbar's onStopEditing listener so on the awesomescreen, hideHomePager will
|
|
|
|
// use the url "about:home" and return without taking any action. hideBrowserSearch is
|
|
|
|
// then called, but since hideHomePager changes both HomePager and LayerView visibility
|
|
|
|
// and exited without taking an action, no Views are displayed and graphical corruption is
|
|
|
|
// visible instead.
|
|
|
|
//
|
|
|
|
// Here we call hideHomePager for the second time with the URL to be loaded so that
|
|
|
|
// hideHomePager is called with the correct state for the upcoming page load.
|
|
|
|
//
|
|
|
|
// Expected to be fixed by bug 915825.
|
|
|
|
hideHomePager(url);
|
|
|
|
|
2013-09-03 21:19:28 -07:00
|
|
|
// Don't do anything if the user entered an empty URL.
|
|
|
|
if (TextUtils.isEmpty(url)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the URL doesn't look like a search query, just load it.
|
|
|
|
if (!StringUtils.isSearchQuery(url, true)) {
|
2013-07-23 17:52:36 -07:00
|
|
|
Tabs.getInstance().loadUrl(url, Tabs.LOADURL_USER_ENTERED);
|
2014-04-02 14:23:10 -07:00
|
|
|
|
|
|
|
Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL);
|
2013-09-03 21:19:28 -07:00
|
|
|
return;
|
2013-05-13 10:20:49 -07:00
|
|
|
}
|
2013-09-03 21:19:28 -07:00
|
|
|
|
|
|
|
// Otherwise, check for a bookmark keyword.
|
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
final String keyword;
|
|
|
|
final String keywordSearch;
|
|
|
|
|
|
|
|
final int index = url.indexOf(" ");
|
|
|
|
if (index == -1) {
|
|
|
|
keyword = url;
|
|
|
|
keywordSearch = "";
|
|
|
|
} else {
|
|
|
|
keyword = url.substring(0, index);
|
|
|
|
keywordSearch = url.substring(index + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
final String keywordUrl = BrowserDB.getUrlForKeyword(getContentResolver(), keyword);
|
|
|
|
|
2013-09-27 09:38:25 -07:00
|
|
|
// If there isn't a bookmark keyword, load the url. This may result in a query
|
|
|
|
// using the default search engine.
|
2013-09-03 21:19:28 -07:00
|
|
|
if (TextUtils.isEmpty(keywordUrl)) {
|
|
|
|
Tabs.getInstance().loadUrl(url, Tabs.LOADURL_USER_ENTERED);
|
2014-04-02 14:23:10 -07:00
|
|
|
Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL);
|
2013-09-03 21:19:28 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-06 16:25:27 -07:00
|
|
|
recordSearch(null, "barkeyword");
|
|
|
|
|
2013-09-03 21:19:28 -07:00
|
|
|
// Otherwise, construct a search query from the bookmark keyword.
|
|
|
|
final String searchUrl = keywordUrl.replace("%s", URLEncoder.encode(keywordSearch));
|
|
|
|
Tabs.getInstance().loadUrl(searchUrl, Tabs.LOADURL_USER_ENTERED);
|
2014-05-30 16:53:28 -07:00
|
|
|
Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL,
|
|
|
|
TelemetryContract.Method.NONE,
|
|
|
|
"keyword");
|
2013-09-03 21:19:28 -07:00
|
|
|
}
|
|
|
|
});
|
2013-05-13 10:20:49 -07:00
|
|
|
}
|
|
|
|
|
2013-09-06 16:25:27 -07:00
|
|
|
/**
|
|
|
|
* Record in Health Report that a search has occurred.
|
|
|
|
*
|
2013-10-18 13:13:37 -07:00
|
|
|
* @param engine
|
|
|
|
* a search engine instance. Can be null.
|
2013-09-06 16:25:27 -07:00
|
|
|
* @param where
|
|
|
|
* where the search was initialized; one of the values in
|
|
|
|
* {@link BrowserHealthRecorder#SEARCH_LOCATIONS}.
|
|
|
|
*/
|
2013-10-18 13:13:37 -07:00
|
|
|
private static void recordSearch(SearchEngine engine, String where) {
|
|
|
|
Log.i(LOGTAG, "Recording search: " +
|
|
|
|
((engine == null) ? "null" : engine.name) +
|
|
|
|
", " + where);
|
2013-09-06 16:25:27 -07:00
|
|
|
try {
|
2013-10-18 13:13:37 -07:00
|
|
|
String identifier = (engine == null) ? "other" : engine.getEngineIdentifier();
|
2013-09-06 16:25:27 -07:00
|
|
|
JSONObject message = new JSONObject();
|
|
|
|
message.put("type", BrowserHealthRecorder.EVENT_SEARCH);
|
|
|
|
message.put("location", where);
|
|
|
|
message.put("identifier", identifier);
|
2014-05-02 11:34:40 -07:00
|
|
|
EventDispatcher.getInstance().dispatchEvent(message, null);
|
2013-09-06 16:25:27 -07:00
|
|
|
} catch (Exception e) {
|
|
|
|
Log.w(LOGTAG, "Error recording search.", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-13 10:20:49 -07:00
|
|
|
void filterEditingMode(String searchTerm, AutocompleteHandler handler) {
|
2013-06-11 09:57:45 -07:00
|
|
|
if (TextUtils.isEmpty(searchTerm)) {
|
|
|
|
hideBrowserSearch();
|
|
|
|
} else {
|
|
|
|
showBrowserSearch();
|
2013-07-11 06:46:44 -07:00
|
|
|
mBrowserSearch.filter(searchTerm, handler);
|
2013-06-11 09:57:45 -07:00
|
|
|
}
|
2013-05-13 10:20:49 -07:00
|
|
|
}
|
|
|
|
|
2013-10-21 12:11:08 -07:00
|
|
|
/**
|
|
|
|
* Selects the target tab for editing mode. This is expected to be the tab selected on editing
|
|
|
|
* mode entry, unless it is subsequently overridden.
|
|
|
|
*
|
|
|
|
* A background tab may be selected while editing mode is active (e.g. popups), causing the
|
|
|
|
* new url to load in the newly selected tab. Call this method on editing mode exit to
|
|
|
|
* mitigate this.
|
|
|
|
*/
|
|
|
|
private void selectTargetTabForEditingMode() {
|
|
|
|
if (mTargetTabForEditingMode != null) {
|
|
|
|
Tabs.getInstance().selectTab(mTargetTabForEditingMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
mTargetTabForEditingMode = null;
|
|
|
|
}
|
|
|
|
|
2013-09-17 06:13:54 -07:00
|
|
|
/**
|
|
|
|
* Shows or hides the home pager for the given tab.
|
|
|
|
*/
|
|
|
|
private void updateHomePagerForTab(Tab tab) {
|
|
|
|
// Don't change the visibility of the home pager if we're in editing mode.
|
|
|
|
if (mBrowserToolbar.isEditing()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isAboutHome(tab)) {
|
2014-01-17 10:41:15 -08:00
|
|
|
String panelId = AboutPages.getPanelIdFromAboutHomeUrl(tab.getURL());
|
|
|
|
if (panelId == null) {
|
|
|
|
// No panel was specified in the URL. Try loading the most recent
|
|
|
|
// home panel for this tab.
|
|
|
|
panelId = tab.getMostRecentHomePanel();
|
|
|
|
}
|
|
|
|
showHomePager(panelId);
|
2013-09-17 06:13:54 -07:00
|
|
|
|
2014-03-13 12:29:39 -07:00
|
|
|
if (mDynamicToolbar.isEnabled()) {
|
|
|
|
mDynamicToolbar.setVisible(true, VisibilityTransition.ANIMATE);
|
2013-09-17 06:13:54 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
hideHomePager();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-03 15:05:43 -08:00
|
|
|
@Override
|
|
|
|
public void onLocaleReady(final String locale) {
|
2014-05-13 20:50:27 -07:00
|
|
|
Log.d(LOGTAG, "onLocaleReady: " + locale);
|
2013-12-03 15:05:43 -08:00
|
|
|
super.onLocaleReady(locale);
|
2014-01-08 13:17:24 -08:00
|
|
|
|
2014-04-23 07:22:34 -07:00
|
|
|
HomePanelsManager.getInstance().onLocaleReady(locale);
|
2014-02-21 02:47:45 -08:00
|
|
|
|
2013-12-03 15:05:43 -08:00
|
|
|
if (mMenu != null) {
|
|
|
|
mMenu.clear();
|
|
|
|
onCreateOptionsMenu(mMenu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-13 20:50:27 -07:00
|
|
|
@Override
|
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
Log.d(LOGTAG, "onActivityResult: " + requestCode + ", " + resultCode + ", " + data);
|
|
|
|
switch (requestCode) {
|
2014-05-27 14:18:07 -07:00
|
|
|
case ACTIVITY_REQUEST_PREFERENCES:
|
|
|
|
// We just returned from preferences. If our locale changed,
|
|
|
|
// we need to redisplay at this point, and do any other browser-level
|
|
|
|
// bookkeeping that we associate with a locale change.
|
|
|
|
if (resultCode != GeckoPreferences.RESULT_CODE_LOCALE_DID_CHANGE) {
|
|
|
|
Log.d(LOGTAG, "No locale change returning from preferences; nothing to do.");
|
|
|
|
return;
|
2014-05-13 20:50:27 -07:00
|
|
|
}
|
|
|
|
|
2014-05-27 14:18:07 -07:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
final LocaleManager localeManager = BrowserLocaleManager.getInstance();
|
|
|
|
final Locale locale = localeManager.getCurrentLocale(getApplicationContext());
|
|
|
|
Log.d(LOGTAG, "Read persisted locale " + locale);
|
|
|
|
if (locale == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
onLocaleChanged(BrowserLocaleManager.getLanguageTag(locale));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
2014-05-13 20:50:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-17 10:41:15 -08:00
|
|
|
private void showHomePager(String panelId) {
|
|
|
|
showHomePagerWithAnimator(panelId, null);
|
2013-12-12 04:04:31 -08:00
|
|
|
}
|
|
|
|
|
2014-01-17 10:41:15 -08:00
|
|
|
private void showHomePagerWithAnimator(String panelId, PropertyAnimator animator) {
|
2013-08-21 02:15:37 -07:00
|
|
|
if (isHomePagerVisible()) {
|
2014-01-17 10:41:15 -08:00
|
|
|
// Home pager already visible, make sure it shows the correct panel.
|
|
|
|
mHomePager.showPanel(panelId);
|
2012-09-28 09:34:45 -07:00
|
|
|
return;
|
2013-04-16 14:34:46 -07:00
|
|
|
}
|
2012-09-28 09:34:45 -07:00
|
|
|
|
2013-04-25 10:47:08 -07:00
|
|
|
// Refresh toolbar height to possibly restore the toolbar padding
|
|
|
|
refreshToolbarHeight();
|
|
|
|
|
|
|
|
// Show the toolbar before hiding about:home so the
|
|
|
|
// onMetricsChanged callback still works.
|
2014-03-13 12:29:39 -07:00
|
|
|
if (mDynamicToolbar.isEnabled()) {
|
|
|
|
mDynamicToolbar.setVisible(true, VisibilityTransition.IMMEDIATE);
|
2013-04-25 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
2013-08-21 02:15:37 -07:00
|
|
|
if (mHomePager == null) {
|
2013-09-06 03:29:29 -07:00
|
|
|
final ViewStub homePagerStub = (ViewStub) findViewById(R.id.home_pager_stub);
|
2014-02-03 10:02:42 -08:00
|
|
|
mHomePager = (HomePager) homePagerStub.inflate();
|
2014-02-13 15:47:17 -08:00
|
|
|
|
2014-01-17 10:41:15 -08:00
|
|
|
mHomePager.setOnPanelChangeListener(new HomePager.OnPanelChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onPanelSelected(String panelId) {
|
|
|
|
final Tab currentTab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (currentTab != null) {
|
|
|
|
currentTab.setMostRecentHomePanel(panelId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-03-14 11:41:46 -07:00
|
|
|
// Don't show the banner in guest mode.
|
|
|
|
if (!getProfile().inGuestMode()) {
|
2014-03-14 11:41:46 -07:00
|
|
|
final ViewStub homeBannerStub = (ViewStub) findViewById(R.id.home_banner_stub);
|
|
|
|
final HomeBanner homeBanner = (HomeBanner) homeBannerStub.inflate();
|
2014-03-14 11:41:46 -07:00
|
|
|
mHomePager.setBanner(homeBanner);
|
|
|
|
|
|
|
|
// Remove the banner from the view hierarchy if it is dismissed.
|
|
|
|
homeBanner.setOnDismissListener(new HomeBanner.OnDismissListener() {
|
|
|
|
@Override
|
|
|
|
public void onDismiss() {
|
|
|
|
mHomePager.setBanner(null);
|
|
|
|
mHomePagerContainer.removeView(homeBanner);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-08-21 02:15:37 -07:00
|
|
|
}
|
2013-10-18 09:40:28 -07:00
|
|
|
|
2014-02-13 15:43:48 -08:00
|
|
|
mHomePagerContainer.setVisibility(View.VISIBLE);
|
|
|
|
mHomePager.load(getSupportLoaderManager(),
|
2013-12-12 04:04:31 -08:00
|
|
|
getSupportFragmentManager(),
|
2014-01-17 10:41:15 -08:00
|
|
|
panelId, animator);
|
2013-10-18 09:40:28 -07:00
|
|
|
|
|
|
|
// Hide the web content so it cannot be focused by screen readers.
|
|
|
|
hideWebContentOnPropertyAnimationEnd(animator);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void hideWebContentOnPropertyAnimationEnd(final PropertyAnimator animator) {
|
|
|
|
if (animator == null) {
|
|
|
|
hideWebContent();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
animator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
|
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationStart() {
|
|
|
|
mHideWebContentOnAnimationEnd = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationEnd() {
|
|
|
|
if (mHideWebContentOnAnimationEnd) {
|
|
|
|
hideWebContent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void hideWebContent() {
|
|
|
|
// The view is set to INVISIBLE, rather than GONE, to avoid
|
|
|
|
// the additional requestLayout() call.
|
2013-11-21 08:06:22 -08:00
|
|
|
mLayerView.setVisibility(View.INVISIBLE);
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
|
2013-11-15 09:42:58 -08:00
|
|
|
/**
|
|
|
|
* Hides the HomePager, using the url of the currently selected tab as the url to be
|
|
|
|
* loaded.
|
|
|
|
*/
|
2013-05-13 14:06:34 -07:00
|
|
|
private void hideHomePager() {
|
2013-11-15 09:42:58 -08:00
|
|
|
final Tab selectedTab = Tabs.getInstance().getSelectedTab();
|
|
|
|
final String url = (selectedTab != null) ? selectedTab.getURL() : null;
|
2012-06-11 15:18:40 -07:00
|
|
|
|
2013-11-15 09:42:58 -08:00
|
|
|
hideHomePager(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the HomePager. The given url should be the url of the page to be loaded, or null
|
|
|
|
* if a new page is not being loaded.
|
|
|
|
*/
|
|
|
|
private void hideHomePager(final String url) {
|
2013-11-21 23:33:28 -08:00
|
|
|
if (!isHomePagerVisible() || AboutPages.isAboutHome(url)) {
|
2013-05-13 10:20:49 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-18 09:40:28 -07:00
|
|
|
// Prevent race in hiding web content - see declaration for more info.
|
|
|
|
mHideWebContentOnAnimationEnd = false;
|
|
|
|
|
|
|
|
// Display the previously hidden web content (which prevented screen reader access).
|
2013-11-21 08:06:22 -08:00
|
|
|
mLayerView.setVisibility(View.VISIBLE);
|
2014-02-13 15:43:48 -08:00
|
|
|
mHomePagerContainer.setVisibility(View.GONE);
|
2013-10-18 09:40:28 -07:00
|
|
|
|
2013-08-21 02:15:37 -07:00
|
|
|
if (mHomePager != null) {
|
2014-02-13 15:43:48 -08:00
|
|
|
mHomePager.unload();
|
2013-08-21 02:15:37 -07:00
|
|
|
}
|
2013-03-11 09:04:55 -07:00
|
|
|
|
2013-04-16 14:34:46 -07:00
|
|
|
mBrowserToolbar.setNextFocusDownId(R.id.layer_view);
|
|
|
|
|
2013-04-25 10:47:08 -07:00
|
|
|
// Refresh toolbar height to possibly restore the toolbar padding
|
|
|
|
refreshToolbarHeight();
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
|
2013-06-11 09:57:45 -07:00
|
|
|
private void showBrowserSearch() {
|
|
|
|
if (mBrowserSearch.getUserVisibleHint()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mBrowserSearchContainer.setVisibility(View.VISIBLE);
|
|
|
|
|
2013-11-14 14:13:54 -08:00
|
|
|
// Prevent overdraw by hiding the underlying HomePager View.
|
|
|
|
mHomePager.setVisibility(View.INVISIBLE);
|
|
|
|
|
2013-10-18 11:39:32 -07:00
|
|
|
final FragmentManager fm = getSupportFragmentManager();
|
|
|
|
|
|
|
|
// In certain situations, showBrowserSearch() can be called immediately after hideBrowserSearch()
|
|
|
|
// (see bug 925012). Because of an Android bug (http://code.google.com/p/android/issues/detail?id=61179),
|
|
|
|
// calling FragmentTransaction#add immediately after FragmentTransaction#remove won't add the fragment's
|
|
|
|
// view to the layout. Calling FragmentManager#executePendingTransactions before re-adding the fragment
|
|
|
|
// prevents this issue.
|
|
|
|
fm.executePendingTransactions();
|
|
|
|
|
|
|
|
fm.beginTransaction().add(R.id.search_container, mBrowserSearch, BROWSER_SEARCH_TAG).commitAllowingStateLoss();
|
2013-06-11 09:57:45 -07:00
|
|
|
mBrowserSearch.setUserVisibleHint(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void hideBrowserSearch() {
|
|
|
|
if (!mBrowserSearch.getUserVisibleHint()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-14 14:13:54 -08:00
|
|
|
// To prevent overdraw, the HomePager is hidden when BrowserSearch is displayed:
|
|
|
|
// reverse that.
|
|
|
|
mHomePager.setVisibility(View.VISIBLE);
|
|
|
|
|
2013-06-11 09:57:45 -07:00
|
|
|
mBrowserSearchContainer.setVisibility(View.INVISIBLE);
|
|
|
|
|
|
|
|
getSupportFragmentManager().beginTransaction()
|
|
|
|
.remove(mBrowserSearch).commitAllowingStateLoss();
|
|
|
|
mBrowserSearch.setUserVisibleHint(false);
|
|
|
|
}
|
|
|
|
|
2014-06-12 09:31:47 -07:00
|
|
|
/**
|
|
|
|
* Hides certain UI elements (e.g. button toast, tabs tray) when the
|
|
|
|
* user touches the main layout.
|
|
|
|
*/
|
|
|
|
private class HideOnTouchListener implements TouchEventInterceptor {
|
2012-10-12 16:23:20 -07:00
|
|
|
private boolean mIsHidingTabs = false;
|
2014-06-12 11:04:00 -07:00
|
|
|
private final Rect mTempRect = new Rect();
|
2012-10-12 16:23:20 -07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onInterceptTouchEvent(View view, MotionEvent event) {
|
2014-06-12 09:31:47 -07:00
|
|
|
// Only try to hide the button toast if it's already inflated.
|
|
|
|
if (mToast != null) {
|
|
|
|
mToast.hide(false, ButtonToast.ReasonHidden.TOUCH_OUTSIDE);
|
|
|
|
}
|
|
|
|
|
2012-10-12 16:23:20 -07:00
|
|
|
// 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) {
|
2014-06-12 11:04:00 -07:00
|
|
|
view.getHitRect(mTempRect);
|
|
|
|
mTempRect.offset(-view.getScrollX(), -view.getScrollY());
|
2012-10-12 16:23:20 -07:00
|
|
|
|
|
|
|
int[] viewCoords = new int[2];
|
|
|
|
view.getLocationOnScreen(viewCoords);
|
|
|
|
|
|
|
|
int x = (int) event.getRawX() - viewCoords[0];
|
|
|
|
int y = (int) event.getRawY() - viewCoords[1];
|
|
|
|
|
2014-06-12 11:04:00 -07:00
|
|
|
if (!mTempRect.contains(x, y))
|
2012-10-12 16:23:20 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-03 15:05:43 -08:00
|
|
|
private static Menu findParentMenu(Menu menu, MenuItem item) {
|
2013-07-08 22:47:10 -07:00
|
|
|
final int itemId = item.getItemId();
|
|
|
|
|
|
|
|
final int count = (menu != null) ? menu.size() : 0;
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
MenuItem menuItem = menu.getItem(i);
|
|
|
|
if (menuItem.getItemId() == itemId) {
|
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
if (menuItem.hasSubMenu()) {
|
|
|
|
Menu parent = findParentMenu(menuItem.getSubMenu(), item);
|
|
|
|
if (parent != null) {
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-12-03 15:05:43 -08:00
|
|
|
/**
|
|
|
|
* Add the provided item to the provided menu, which should be
|
|
|
|
* the root (mMenu).
|
|
|
|
*/
|
|
|
|
private void addAddonMenuItemToMenu(final Menu menu, final MenuItemInfo info) {
|
|
|
|
info.added = true;
|
2014-04-23 17:40:00 -07:00
|
|
|
|
2013-12-03 15:05:43 -08:00
|
|
|
final Menu destination;
|
2012-10-26 13:39:25 -07:00
|
|
|
if (info.parent == 0) {
|
2013-12-03 15:05:43 -08:00
|
|
|
destination = menu;
|
2013-07-08 22:47:10 -07:00
|
|
|
} else if (info.parent == GECKO_TOOLS_MENU) {
|
2013-12-03 15:05:43 -08:00
|
|
|
MenuItem tools = menu.findItem(R.id.tools);
|
|
|
|
destination = tools != null ? tools.getSubMenu() : menu;
|
2012-10-26 13:39:25 -07:00
|
|
|
} else {
|
2013-12-03 15:05:43 -08:00
|
|
|
MenuItem parent = menu.findItem(info.parent);
|
|
|
|
if (parent == null) {
|
2012-10-26 13:39:25 -07:00
|
|
|
return;
|
2013-12-03 15:05:43 -08:00
|
|
|
}
|
2012-10-26 13:39:25 -07:00
|
|
|
|
2013-12-03 15:05:43 -08:00
|
|
|
Menu parentMenu = findParentMenu(menu, parent);
|
2013-07-08 22:47:10 -07:00
|
|
|
|
2012-10-26 13:39:25 -07:00
|
|
|
if (!parent.hasSubMenu()) {
|
2013-07-08 22:47:10 -07:00
|
|
|
parentMenu.removeItem(parent.getItemId());
|
2013-12-03 15:05:43 -08:00
|
|
|
destination = parentMenu.addSubMenu(Menu.NONE, parent.getItemId(), Menu.NONE, parent.getTitle());
|
|
|
|
if (parent.getIcon() != null) {
|
|
|
|
((SubMenu) destination).getItem().setIcon(parent.getIcon());
|
|
|
|
}
|
2012-10-26 13:39:25 -07:00
|
|
|
} else {
|
2013-12-03 15:05:43 -08:00
|
|
|
destination = parent.getSubMenu();
|
2012-10-26 13:39:25 -07:00
|
|
|
}
|
|
|
|
}
|
2012-07-26 23:53:48 -07:00
|
|
|
|
2013-12-03 15:05:43 -08:00
|
|
|
MenuItem item = destination.add(Menu.NONE, info.id, Menu.NONE, info.label);
|
|
|
|
|
2012-07-26 23:53:48 -07:00
|
|
|
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
2013-12-03 15:05:43 -08:00
|
|
|
Log.i(LOGTAG, "Menu item clicked");
|
2012-10-26 13:39:25 -07:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Menu:Clicked", Integer.toString(info.id - ADDON_MENU_OFFSET)));
|
2012-07-26 23:53:48 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-12-03 15:05:43 -08:00
|
|
|
if (info.icon == null) {
|
|
|
|
item.setIcon(R.drawable.ic_menu_addons_filler);
|
|
|
|
} else {
|
2013-07-09 00:19:46 -07:00
|
|
|
final int id = info.id;
|
2013-07-16 01:33:05 -07:00
|
|
|
BitmapUtils.getDrawable(this, info.icon, new BitmapUtils.BitmapLoader() {
|
|
|
|
@Override
|
|
|
|
public void onBitmapFound(Drawable d) {
|
2013-12-03 15:05:43 -08:00
|
|
|
// TODO: why do we re-find the item?
|
|
|
|
MenuItem item = destination.findItem(id);
|
2013-07-25 05:33:38 -07:00
|
|
|
if (item == null) {
|
|
|
|
return;
|
|
|
|
}
|
2013-07-16 01:33:05 -07:00
|
|
|
if (d == null) {
|
|
|
|
item.setIcon(R.drawable.ic_menu_addons_filler);
|
|
|
|
return;
|
2012-07-26 23:53:48 -07:00
|
|
|
}
|
2013-07-16 01:33:05 -07:00
|
|
|
item.setIcon(d);
|
|
|
|
}
|
|
|
|
});
|
2012-07-26 23:53:48 -07:00
|
|
|
}
|
2012-10-26 13:39:25 -07:00
|
|
|
|
|
|
|
item.setCheckable(info.checkable);
|
2012-10-29 16:29:55 -07:00
|
|
|
item.setChecked(info.checked);
|
|
|
|
item.setEnabled(info.enabled);
|
|
|
|
item.setVisible(info.visible);
|
2012-07-26 23:53:48 -07:00
|
|
|
}
|
|
|
|
|
2013-12-03 15:05:43 -08:00
|
|
|
private void addAddonMenuItem(final MenuItemInfo info) {
|
|
|
|
if (mAddonMenuItemsCache == null) {
|
|
|
|
mAddonMenuItemsCache = new Vector<MenuItemInfo>();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark it as added if the menu was ready.
|
|
|
|
info.added = (mMenu != null);
|
|
|
|
|
|
|
|
// Always cache so we can rebuild after a locale switch.
|
|
|
|
mAddonMenuItemsCache.add(info);
|
|
|
|
|
|
|
|
if (mMenu == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
addAddonMenuItemToMenu(mMenu, info);
|
|
|
|
}
|
|
|
|
|
2012-07-26 23:53:48 -07:00
|
|
|
private void removeAddonMenuItem(int id) {
|
2012-09-27 11:22:08 -07: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-26 23:53:48 -07:00
|
|
|
}
|
|
|
|
}
|
2012-09-27 11:22:08 -07:00
|
|
|
|
|
|
|
if (mMenu == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
MenuItem menuItem = mMenu.findItem(id);
|
|
|
|
if (menuItem != null)
|
|
|
|
mMenu.removeItem(id);
|
2012-07-26 23:53:48 -07:00
|
|
|
}
|
|
|
|
|
2012-10-29 16:29:55 -07: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) {
|
2013-10-16 23:06:56 -07:00
|
|
|
if (item.id == id) {
|
|
|
|
item.label = options.optString("name", item.label);
|
|
|
|
item.checkable = options.optBoolean("checkable", item.checkable);
|
|
|
|
item.checked = options.optBoolean("checked", item.checked);
|
|
|
|
item.enabled = options.optBoolean("enabled", item.enabled);
|
|
|
|
item.visible = options.optBoolean("visible", item.visible);
|
2013-12-03 15:05:43 -08:00
|
|
|
item.added = (mMenu != null);
|
2013-10-16 23:06:56 -07:00
|
|
|
break;
|
|
|
|
}
|
2012-10-29 16:29:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-03 15:05:43 -08:00
|
|
|
if (mMenu == null) {
|
2012-10-29 16:29:55 -07:00
|
|
|
return;
|
2013-12-03 15:05:43 -08:00
|
|
|
}
|
2012-10-29 16:29:55 -07:00
|
|
|
|
|
|
|
MenuItem menuItem = mMenu.findItem(id);
|
|
|
|
if (menuItem != null) {
|
2013-10-16 23:06:56 -07:00
|
|
|
menuItem.setTitle(options.optString("name", menuItem.getTitle().toString()));
|
2013-04-03 15:10:06 -07:00
|
|
|
menuItem.setCheckable(options.optBoolean("checkable", menuItem.isCheckable()));
|
|
|
|
menuItem.setChecked(options.optBoolean("checked", menuItem.isChecked()));
|
|
|
|
menuItem.setEnabled(options.optBoolean("enabled", menuItem.isEnabled()));
|
|
|
|
menuItem.setVisible(options.optBoolean("visible", menuItem.isVisible()));
|
2012-10-29 16:29:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
@Override
|
2012-07-26 23:52:41 -07:00
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
2013-12-03 15:05:43 -08:00
|
|
|
// Sets mMenu = menu.
|
2012-07-26 23:52:41 -07:00
|
|
|
super.onCreateOptionsMenu(menu);
|
2012-06-11 15:18:40 -07:00
|
|
|
|
2014-04-23 17:40:00 -07:00
|
|
|
// Inform the menu about the action-items bar.
|
2013-12-03 15:05:43 -08:00
|
|
|
if (menu instanceof GeckoMenu &&
|
|
|
|
HardwareUtils.isTablet()) {
|
2012-06-11 15:18:40 -07:00
|
|
|
((GeckoMenu) menu).setActionItemBarPresenter(mBrowserToolbar);
|
2013-12-03 15:05:43 -08:00
|
|
|
}
|
2012-06-11 15:18:40 -07:00
|
|
|
|
|
|
|
MenuInflater inflater = getMenuInflater();
|
2012-07-26 23:52:41 -07:00
|
|
|
inflater.inflate(R.menu.browser_app_menu, mMenu);
|
2012-09-27 11:22:08 -07:00
|
|
|
|
2013-12-03 15:05:43 -08:00
|
|
|
// Add add-on menu items, if any exist.
|
2012-09-27 11:22:08 -07:00
|
|
|
if (mAddonMenuItemsCache != null && !mAddonMenuItemsCache.isEmpty()) {
|
|
|
|
for (MenuItemInfo item : mAddonMenuItemsCache) {
|
2013-12-03 15:05:43 -08:00
|
|
|
addAddonMenuItemToMenu(mMenu, item);
|
2012-09-27 11:22:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-15 10:55:06 -07:00
|
|
|
// Action providers are available only ICS+.
|
|
|
|
if (Build.VERSION.SDK_INT >= 14) {
|
2014-03-26 10:18:02 -07:00
|
|
|
GeckoMenuItem share = (GeckoMenuItem) mMenu.findItem(R.id.share);
|
2014-03-31 15:40:32 -07:00
|
|
|
GeckoActionProvider provider = GeckoActionProvider.getForType(GeckoActionProvider.DEFAULT_MIME_TYPE, this);
|
2013-05-15 10:55:06 -07:00
|
|
|
share.setActionProvider(provider);
|
|
|
|
}
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void openOptionsMenu() {
|
2014-02-18 16:09:00 -08:00
|
|
|
if (!hasTabsSideBar() && areTabsShown())
|
2012-07-24 21:30:46 -07:00
|
|
|
return;
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
// Scroll custom menu to the top
|
|
|
|
if (mMenuPanel != null)
|
|
|
|
mMenuPanel.scrollTo(0, 0);
|
|
|
|
|
|
|
|
if (!mBrowserToolbar.openOptionsMenu())
|
|
|
|
super.openOptionsMenu();
|
2013-03-22 03:26:32 -07:00
|
|
|
|
2014-03-13 12:29:39 -07:00
|
|
|
if (mDynamicToolbar.isEnabled()) {
|
|
|
|
mDynamicToolbar.setVisible(true, VisibilityTransition.ANIMATE);
|
|
|
|
}
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void closeOptionsMenu() {
|
2012-09-19 10:37:35 -07:00
|
|
|
if (!mBrowserToolbar.closeOptionsMenu())
|
2012-06-11 15:18:40 -07:00
|
|
|
super.closeOptionsMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setFullScreen(final boolean fullscreen) {
|
2013-02-26 21:48:00 -08:00
|
|
|
super.setFullScreen(fullscreen);
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
|
|
|
public void run() {
|
2013-07-11 09:21:25 -07:00
|
|
|
if (fullscreen) {
|
2013-11-19 11:57:35 -08:00
|
|
|
mViewFlipper.setVisibility(View.GONE);
|
2014-03-13 12:29:39 -07:00
|
|
|
if (mDynamicToolbar.isEnabled()) {
|
|
|
|
mDynamicToolbar.setVisible(false, VisibilityTransition.IMMEDIATE);
|
2013-07-11 09:21:25 -07:00
|
|
|
mLayerView.getLayerMarginsAnimator().setMaxMargins(0, 0, 0, 0);
|
2014-01-10 10:38:26 -08:00
|
|
|
} else {
|
|
|
|
setToolbarMargin(0);
|
2013-07-11 09:21:25 -07:00
|
|
|
}
|
|
|
|
} else {
|
2013-11-19 11:57:35 -08:00
|
|
|
mViewFlipper.setVisibility(View.VISIBLE);
|
2014-03-13 12:29:39 -07:00
|
|
|
if (mDynamicToolbar.isEnabled()) {
|
|
|
|
mDynamicToolbar.setVisible(true, VisibilityTransition.IMMEDIATE);
|
2013-07-11 09:21:25 -07:00
|
|
|
mLayerView.getLayerMarginsAnimator().setMaxMargins(0, mToolbarHeight, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
2013-02-26 21:48:00 -08:00
|
|
|
}
|
|
|
|
});
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
2012-06-18 10:03:03 -07:00
|
|
|
|
|
|
|
@Override
|
2012-07-26 23:52:41 -07:00
|
|
|
public boolean onPrepareOptionsMenu(Menu aMenu) {
|
2012-06-18 10:03:03 -07:00
|
|
|
if (aMenu == null)
|
|
|
|
return false;
|
|
|
|
|
2014-05-22 13:31:40 -07:00
|
|
|
if (!GeckoThread.checkLaunchState(GeckoThread.LaunchState.GeckoRunning)) {
|
2012-06-18 10:03:03 -07:00
|
|
|
aMenu.findItem(R.id.settings).setEnabled(false);
|
2014-05-22 13:31:40 -07:00
|
|
|
aMenu.findItem(R.id.help).setEnabled(false);
|
|
|
|
}
|
2012-06-18 10:03:03 -07:00
|
|
|
|
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
MenuItem bookmark = aMenu.findItem(R.id.bookmark);
|
2013-12-18 18:46:42 -08:00
|
|
|
MenuItem back = aMenu.findItem(R.id.back);
|
2012-06-18 10:03:03 -07:00
|
|
|
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 12:53:40 -07:00
|
|
|
MenuItem desktopMode = aMenu.findItem(R.id.desktop_mode);
|
2013-08-02 22:26:40 -07:00
|
|
|
MenuItem enterGuestMode = aMenu.findItem(R.id.new_guest_session);
|
|
|
|
MenuItem exitGuestMode = aMenu.findItem(R.id.exit_guest_session);
|
2012-06-18 10:03:03 -07:00
|
|
|
|
2013-04-02 07:03:39 -07: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 03:13:15 -08:00
|
|
|
|
2012-06-18 10:03:03 -07:00
|
|
|
if (tab == null || tab.getURL() == null) {
|
|
|
|
bookmark.setEnabled(false);
|
2013-12-18 18:46:42 -08:00
|
|
|
back.setEnabled(false);
|
2012-06-18 10:03:03 -07:00
|
|
|
forward.setEnabled(false);
|
|
|
|
share.setEnabled(false);
|
|
|
|
saveAsPDF.setEnabled(false);
|
|
|
|
findInPage.setEnabled(false);
|
2014-02-07 11:49:32 -08:00
|
|
|
|
|
|
|
// NOTE: Use MenuUtils.safeSetEnabled because some actions might
|
|
|
|
// be on the BrowserToolbar context menu
|
|
|
|
MenuUtils.safeSetEnabled(aMenu, R.id.page, false);
|
|
|
|
MenuUtils.safeSetEnabled(aMenu, R.id.subscribe, false);
|
|
|
|
MenuUtils.safeSetEnabled(aMenu, R.id.add_search_engine, false);
|
|
|
|
MenuUtils.safeSetEnabled(aMenu, R.id.site_settings, false);
|
|
|
|
MenuUtils.safeSetEnabled(aMenu, R.id.add_to_launcher, false);
|
|
|
|
|
2012-06-18 10:03:03 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-21 23:33:28 -08:00
|
|
|
bookmark.setEnabled(!AboutPages.isAboutReader(tab.getURL()));
|
2014-03-24 15:38:57 -07:00
|
|
|
bookmark.setVisible(!GeckoProfile.get(this).inGuestMode());
|
|
|
|
bookmark.setCheckable(true);
|
2012-09-27 11:04:02 -07:00
|
|
|
bookmark.setChecked(tab.isBookmark());
|
2014-03-24 15:38:57 -07:00
|
|
|
bookmark.setIcon(tab.isBookmark() ? R.drawable.ic_menu_bookmark_remove : R.drawable.ic_menu_bookmark_add);
|
2012-06-18 10:03:03 -07:00
|
|
|
|
2013-12-18 18:46:42 -08:00
|
|
|
back.setEnabled(tab.canDoBack());
|
2012-06-18 10:03:03 -07:00
|
|
|
forward.setEnabled(tab.canDoForward());
|
2012-06-22 12:53:40 -07:00
|
|
|
desktopMode.setChecked(tab.getDesktopMode());
|
2012-09-27 11:04:02 -07:00
|
|
|
desktopMode.setIcon(tab.getDesktopMode() ? R.drawable.ic_menu_desktop_mode_on : R.drawable.ic_menu_desktop_mode_off);
|
2012-06-18 10:03:03 -07:00
|
|
|
|
2012-09-11 10:51:44 -07:00
|
|
|
String url = tab.getURL();
|
2013-11-21 23:33:28 -08:00
|
|
|
if (AboutPages.isAboutReader(url)) {
|
2012-11-12 07:58:41 -08:00
|
|
|
String urlFromReader = ReaderModeUtils.getUrlFromAboutReader(url);
|
2013-11-21 23:33:28 -08:00
|
|
|
if (urlFromReader != null) {
|
2012-11-12 07:58:41 -08:00
|
|
|
url = urlFromReader;
|
2013-11-21 23:33:28 -08:00
|
|
|
}
|
2012-11-12 07:58:41 -08:00
|
|
|
}
|
2012-09-11 10:51:44 -07:00
|
|
|
|
2012-06-18 10:03:03 -07:00
|
|
|
// Disable share menuitem for about:, chrome:, file:, and resource: URIs
|
2014-06-04 14:41:30 -07:00
|
|
|
final boolean inGuestMode = GeckoProfile.get(this).inGuestMode();
|
|
|
|
share.setVisible(!inGuestMode);
|
|
|
|
share.setEnabled(StringUtils.isShareableUrl(url) && !inGuestMode);
|
2012-06-18 10:03:03 -07:00
|
|
|
|
2014-02-07 11:49:32 -08:00
|
|
|
// NOTE: Use MenuUtils.safeSetEnabled because some actions might
|
|
|
|
// be on the BrowserToolbar context menu
|
|
|
|
MenuUtils.safeSetEnabled(aMenu, R.id.page, !isAboutHome(tab));
|
|
|
|
MenuUtils.safeSetEnabled(aMenu, R.id.subscribe, tab.hasFeeds());
|
|
|
|
MenuUtils.safeSetEnabled(aMenu, R.id.add_search_engine, tab.hasOpenSearch());
|
|
|
|
MenuUtils.safeSetEnabled(aMenu, R.id.site_settings, !isAboutHome(tab));
|
|
|
|
MenuUtils.safeSetEnabled(aMenu, R.id.add_to_launcher, !isAboutHome(tab));
|
|
|
|
|
2013-05-15 10:55:06 -07:00
|
|
|
// Action providers are available only ICS+.
|
|
|
|
if (Build.VERSION.SDK_INT >= 14) {
|
2014-03-26 10:18:02 -07:00
|
|
|
final GeckoActionProvider provider = ((GeckoMenuItem) share).getGeckoActionProvider();
|
2013-05-15 10:55:06 -07:00
|
|
|
if (provider != null) {
|
2013-06-04 14:07:42 -07:00
|
|
|
Intent shareIntent = provider.getIntent();
|
|
|
|
|
2013-09-17 07:27:37 -07:00
|
|
|
// For efficiency, the provider's intent is only set once
|
2013-06-04 14:07:42 -07:00
|
|
|
if (shareIntent == null) {
|
2013-09-17 07:27:37 -07:00
|
|
|
shareIntent = new Intent(Intent.ACTION_SEND);
|
|
|
|
shareIntent.setType("text/plain");
|
2013-06-04 14:07:42 -07:00
|
|
|
provider.setIntent(shareIntent);
|
|
|
|
}
|
2013-09-17 07:27:37 -07:00
|
|
|
|
|
|
|
// Replace the existing intent's extras
|
|
|
|
shareIntent.putExtra(Intent.EXTRA_TEXT, url);
|
|
|
|
shareIntent.putExtra(Intent.EXTRA_SUBJECT, tab.getDisplayTitle());
|
|
|
|
shareIntent.putExtra(Intent.EXTRA_TITLE, tab.getDisplayTitle());
|
2013-09-17 07:27:37 -07:00
|
|
|
|
|
|
|
// Clear the existing thumbnail extras so we don't share an old thumbnail.
|
|
|
|
shareIntent.removeExtra("share_screenshot_uri");
|
|
|
|
|
|
|
|
// Include the thumbnail of the page being shared.
|
|
|
|
BitmapDrawable drawable = tab.getThumbnail();
|
|
|
|
if (drawable != null) {
|
|
|
|
Bitmap thumbnail = drawable.getBitmap();
|
|
|
|
|
|
|
|
// Kobo uses a custom intent extra for sharing thumbnails.
|
2013-09-23 16:16:08 -07:00
|
|
|
if (Build.MANUFACTURER.equals("Kobo") && thumbnail != null) {
|
2013-09-17 07:27:37 -07:00
|
|
|
File cacheDir = getExternalCacheDir();
|
|
|
|
|
|
|
|
if (cacheDir != null) {
|
|
|
|
File outFile = new File(cacheDir, "thumbnail.png");
|
|
|
|
|
|
|
|
try {
|
|
|
|
java.io.FileOutputStream out = new java.io.FileOutputStream(outFile);
|
|
|
|
thumbnail.compress(Bitmap.CompressFormat.PNG, 90, out);
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
Log.e(LOGTAG, "File not found", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
shareIntent.putExtra("share_screenshot_uri", Uri.parse(outFile.getPath()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-15 10:55:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-21 23:33:28 -08:00
|
|
|
// Disable save as PDF for about:home and xul pages.
|
|
|
|
saveAsPDF.setEnabled(!(isAboutHome(tab) ||
|
2012-06-18 10:03:03 -07:00
|
|
|
tab.getContentType().equals("application/vnd.mozilla.xul+xml")));
|
|
|
|
|
2013-11-21 23:33:28 -08:00
|
|
|
// Disable find in page for about:home, since it won't work on Java content.
|
2013-05-13 09:40:38 -07:00
|
|
|
findInPage.setEnabled(!isAboutHome(tab));
|
2012-06-18 10:03:03 -07:00
|
|
|
|
|
|
|
charEncoding.setVisible(GeckoPreferences.getCharEncodingState());
|
|
|
|
|
2013-07-18 11:43:34 -07:00
|
|
|
if (mProfile.inGuestMode())
|
|
|
|
exitGuestMode.setVisible(true);
|
|
|
|
else
|
|
|
|
enterGuestMode.setVisible(true);
|
|
|
|
|
2012-06-18 10:03:03 -07:00
|
|
|
return true;
|
|
|
|
}
|
2012-07-26 23:52:41 -07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
2014-03-24 15:38:57 -07:00
|
|
|
Tab tab = null;
|
2012-07-26 23:52:41 -07:00
|
|
|
Intent intent = null;
|
2013-08-13 16:44:00 -07:00
|
|
|
|
|
|
|
final int itemId = item.getItemId();
|
|
|
|
|
2014-05-02 08:00:19 -07:00
|
|
|
// Track the menu action. We don't know much about the context, but we can use this to determine
|
|
|
|
// the frequency of use for various actions.
|
|
|
|
Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.MENU, getResources().getResourceEntryName(itemId));
|
|
|
|
|
2013-08-13 16:44:00 -07:00
|
|
|
if (itemId == R.id.bookmark) {
|
2014-03-24 15:38:57 -07:00
|
|
|
tab = Tabs.getInstance().getSelectedTab();
|
2013-08-13 16:44:00 -07:00
|
|
|
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();
|
2014-02-19 09:56:03 -08:00
|
|
|
getButtonToast().show(false,
|
2013-08-13 16:44:00 -07:00
|
|
|
getResources().getString(R.string.bookmark_added),
|
2014-03-24 15:38:57 -07:00
|
|
|
getResources().getString(R.string.bookmark_options),
|
2013-08-13 16:44:00 -07:00
|
|
|
null,
|
|
|
|
new ButtonToast.ToastListener() {
|
|
|
|
@Override
|
|
|
|
public void onButtonClicked() {
|
2014-03-24 15:38:57 -07:00
|
|
|
showBookmarkDialog();
|
2013-08-13 16:44:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onToastHidden(ButtonToast.ReasonHidden reason) { }
|
|
|
|
});
|
|
|
|
item.setIcon(R.drawable.ic_menu_bookmark_remove);
|
2012-07-26 23:52:41 -07:00
|
|
|
}
|
2013-08-13 16:44:00 -07:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemId == R.id.share) {
|
|
|
|
shareCurrentUrl();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemId == R.id.reload) {
|
2014-03-24 15:38:57 -07:00
|
|
|
tab = Tabs.getInstance().getSelectedTab();
|
2013-08-13 16:44:00 -07:00
|
|
|
if (tab != null)
|
|
|
|
tab.doReload();
|
2013-12-18 18:46:42 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemId == R.id.back) {
|
2014-03-24 15:38:57 -07:00
|
|
|
tab = Tabs.getInstance().getSelectedTab();
|
2013-12-18 18:46:42 -08:00
|
|
|
if (tab != null)
|
|
|
|
tab.doBack();
|
2013-08-13 16:44:00 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemId == R.id.forward) {
|
2014-03-24 15:38:57 -07:00
|
|
|
tab = Tabs.getInstance().getSelectedTab();
|
2013-08-13 16:44:00 -07:00
|
|
|
if (tab != null)
|
|
|
|
tab.doForward();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemId == R.id.save_as_pdf) {
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SaveAs:PDF", null));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemId == R.id.settings) {
|
|
|
|
intent = new Intent(this, GeckoPreferences.class);
|
2014-05-13 20:50:27 -07:00
|
|
|
|
|
|
|
// We want to know when the Settings activity returns, because
|
|
|
|
// we might need to redisplay based on a locale change.
|
|
|
|
startActivityForResult(intent, ACTIVITY_REQUEST_PREFERENCES);
|
2013-08-13 16:44:00 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-22 13:31:40 -07:00
|
|
|
if (itemId == R.id.help) {
|
|
|
|
final String VERSION = AppConstants.MOZ_APP_VERSION;
|
|
|
|
final String OS = AppConstants.OS_TARGET;
|
|
|
|
final String LOCALE = BrowserLocaleManager.getLanguageTag(Locale.getDefault());
|
|
|
|
|
|
|
|
final String URL = getResources().getString(R.string.help_link, VERSION, OS, LOCALE);
|
|
|
|
Tabs.getInstance().loadUrlInTab(URL);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-13 16:44:00 -07:00
|
|
|
if (itemId == R.id.addons) {
|
2013-11-21 23:33:28 -08:00
|
|
|
Tabs.getInstance().loadUrlInTab(AboutPages.ADDONS);
|
2013-08-13 16:44:00 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-21 23:33:28 -08:00
|
|
|
if (itemId == R.id.apps) {
|
|
|
|
Tabs.getInstance().loadUrlInTab(AboutPages.APPS);
|
2013-08-13 16:44:00 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-21 23:33:28 -08:00
|
|
|
if (itemId == R.id.downloads) {
|
|
|
|
Tabs.getInstance().loadUrlInTab(AboutPages.DOWNLOADS);
|
2013-08-13 16:44:00 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemId == R.id.char_encoding) {
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("CharEncoding:Get", null));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemId == R.id.find_in_page) {
|
|
|
|
mFindInPageBar.show();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemId == R.id.desktop_mode) {
|
2014-03-24 15:38:57 -07:00
|
|
|
Tab selectedTab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (selectedTab == null)
|
2013-07-18 11:43:34 -07:00
|
|
|
return true;
|
2013-08-13 16:44:00 -07:00
|
|
|
JSONObject args = new JSONObject();
|
|
|
|
try {
|
|
|
|
args.put("desktopMode", !item.isChecked());
|
2014-03-24 15:38:57 -07:00
|
|
|
args.put("tabId", selectedTab.getId());
|
2013-08-13 16:44:00 -07:00
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.e(LOGTAG, "error building json arguments");
|
|
|
|
}
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("DesktopMode:Change", args.toString()));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemId == R.id.new_tab) {
|
|
|
|
addTab();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemId == R.id.new_private_tab) {
|
|
|
|
addPrivateTab();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemId == R.id.new_guest_session) {
|
|
|
|
showGuestModeDialog(GuestModeDialog.ENTERING);
|
|
|
|
return true;
|
2012-07-26 23:52:41 -07:00
|
|
|
}
|
2013-08-13 16:44:00 -07:00
|
|
|
|
|
|
|
if (itemId == R.id.exit_guest_session) {
|
|
|
|
showGuestModeDialog(GuestModeDialog.LEAVING);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-07 11:49:32 -08:00
|
|
|
// We have a few menu items that can also be in the context menu. If
|
|
|
|
// we have not already handled the item, give the context menu handler
|
|
|
|
// a chance.
|
|
|
|
if (onContextItemSelected(item)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-13 16:44:00 -07:00
|
|
|
return super.onOptionsItemSelected(item);
|
2012-07-26 23:52:41 -07:00
|
|
|
}
|
2012-08-26 21:33:11 -07:00
|
|
|
|
2013-07-26 09:14:04 -07:00
|
|
|
private void showGuestModeDialog(final GuestModeDialog type) {
|
|
|
|
final Prompt ps = new Prompt(this, new Prompt.PromptCallback() {
|
|
|
|
@Override
|
|
|
|
public void onPromptFinished(String result) {
|
|
|
|
try {
|
|
|
|
int itemId = new JSONObject(result).getInt("button");
|
|
|
|
if (itemId == 0) {
|
|
|
|
String args = "";
|
|
|
|
if (type == GuestModeDialog.ENTERING) {
|
2013-08-26 16:41:13 -07:00
|
|
|
args = GUEST_BROWSING_ARG;
|
2013-08-02 11:04:42 -07:00
|
|
|
} else {
|
|
|
|
GeckoProfile.leaveGuestSession(BrowserApp.this);
|
2013-07-26 09:14:04 -07:00
|
|
|
}
|
|
|
|
doRestart(args);
|
2014-02-27 05:49:51 -08:00
|
|
|
GeckoAppShell.systemExit();
|
2013-07-26 09:14:04 -07:00
|
|
|
}
|
|
|
|
} catch(JSONException ex) {
|
|
|
|
Log.e(LOGTAG, "Exception reading guest mode prompt result", ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Resources res = getResources();
|
|
|
|
ps.setButtons(new String[] {
|
2013-08-02 22:26:40 -07:00
|
|
|
res.getString(R.string.guest_session_dialog_continue),
|
|
|
|
res.getString(R.string.guest_session_dialog_cancel)
|
2013-07-26 09:14:04 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
int titleString = 0;
|
|
|
|
int msgString = 0;
|
|
|
|
if (type == GuestModeDialog.ENTERING) {
|
2013-08-02 22:26:40 -07:00
|
|
|
titleString = R.string.new_guest_session_title;
|
|
|
|
msgString = R.string.new_guest_session_text;
|
2013-07-26 09:14:04 -07:00
|
|
|
} else {
|
2013-08-02 22:26:40 -07:00
|
|
|
titleString = R.string.exit_guest_session_title;
|
|
|
|
msgString = R.string.exit_guest_session_text;
|
2013-07-26 09:14:04 -07:00
|
|
|
}
|
|
|
|
|
2014-02-25 08:55:14 -08:00
|
|
|
ps.show(res.getString(titleString), res.getString(msgString), null, ListView.CHOICE_MODE_NONE);
|
2013-07-26 09:14:04 -07:00
|
|
|
}
|
|
|
|
|
2013-02-06 19:53:01 -08: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-26 21:33:11 -07: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.
|
2014-04-23 17:40:00 -07:00
|
|
|
*/
|
2012-08-26 21:33:11 -07:00
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
2013-03-05 05:05:52 -08:00
|
|
|
String action = intent.getAction();
|
|
|
|
|
2014-06-16 09:49:37 -07:00
|
|
|
final boolean isViewAction = Intent.ACTION_VIEW.equals(action);
|
|
|
|
final boolean isBookmarkAction = GeckoApp.ACTION_BOOKMARK.equals(action);
|
|
|
|
|
|
|
|
if (mInitialized && (isViewAction || isBookmarkAction)) {
|
|
|
|
// Dismiss editing mode if the user is loading a URL from an external app.
|
|
|
|
mBrowserToolbar.cancelEdit();
|
|
|
|
|
|
|
|
// GeckoApp.ACTION_BOOKMARK means we're opening a bookmark that
|
|
|
|
// was added to Android's homescreen.
|
|
|
|
final TelemetryContract.Method method =
|
|
|
|
(isViewAction ? TelemetryContract.Method.INTENT : TelemetryContract.Method.HOMESCREEN);
|
|
|
|
|
|
|
|
Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, method);
|
|
|
|
}
|
|
|
|
|
|
|
|
super.onNewIntent(intent);
|
|
|
|
|
2013-04-17 13:08:11 -07:00
|
|
|
if (AppConstants.MOZ_ANDROID_BEAM && Build.VERSION.SDK_INT >= 10 && NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
|
2013-03-05 05:05:52 -08:00
|
|
|
String uri = intent.getDataString();
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createURILoadEvent(uri));
|
|
|
|
}
|
|
|
|
|
2013-09-17 06:14:00 -07:00
|
|
|
if (!mInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only solicit feedback when the app has been launched from the icon shortcut.
|
|
|
|
if (!Intent.ACTION_MAIN.equals(action)) {
|
2012-08-26 21:33:11 -07:00
|
|
|
return;
|
2013-03-05 05:05:52 -08:00
|
|
|
}
|
2012-08-26 21:33:11 -07:00
|
|
|
|
2013-03-15 03:52:53 -07:00
|
|
|
(new UiAsyncTask<Void, Void, Boolean>(ThreadUtils.getBackgroundHandler()) {
|
2012-08-26 21:33:11 -07: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)
|
2013-06-03 08:37:29 -07:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Feedback:Show", null));
|
2012-08-26 21:33:11 -07:00
|
|
|
}
|
|
|
|
}).execute();
|
|
|
|
}
|
|
|
|
|
2013-03-21 13:32:11 -07: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-26 21:33:11 -07:00
|
|
|
private void resetFeedbackLaunchCount() {
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
2012-08-26 21:33:11 -07: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 03:52:53 -07:00
|
|
|
(new UiAsyncTask<Void, Void, String>(ThreadUtils.getBackgroundHandler()) {
|
2012-08-26 21:33:11 -07:00
|
|
|
@Override
|
|
|
|
public synchronized String doInBackground(Void... params) {
|
|
|
|
// Get the most recent URL stored in browser history.
|
|
|
|
String url = "";
|
2013-07-11 07:43:36 -07:00
|
|
|
Cursor c = null;
|
|
|
|
try {
|
|
|
|
c = BrowserDB.getRecentHistory(getContentResolver(), 1);
|
|
|
|
if (c.moveToFirst()) {
|
|
|
|
url = c.getString(c.getColumnIndexOrThrow(Combined.URL));
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
if (c != null)
|
|
|
|
c.close();
|
2012-08-26 21:33:11 -07:00
|
|
|
}
|
|
|
|
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-08 13:01:51 -08:00
|
|
|
|
2013-07-12 14:51:29 -07:00
|
|
|
// HomePager.OnNewTabsListener
|
|
|
|
@Override
|
2014-06-23 14:13:05 -07:00
|
|
|
public void onNewTabs(List<String> urls) {
|
2013-09-23 16:35:46 -07:00
|
|
|
final EnumSet<OnUrlOpenListener.Flags> flags = EnumSet.of(OnUrlOpenListener.Flags.ALLOW_SWITCH_TO_TAB);
|
2014-04-23 17:40:00 -07:00
|
|
|
|
2013-07-12 14:51:29 -07:00
|
|
|
for (String url : urls) {
|
2013-09-23 16:35:46 -07:00
|
|
|
if (!maybeSwitchToTab(url, flags)) {
|
2013-10-14 17:10:27 -07:00
|
|
|
openUrlAndStopEditing(url, true);
|
2013-09-23 16:35:46 -07:00
|
|
|
}
|
2013-07-12 14:51:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-12 14:51:28 -07:00
|
|
|
// HomePager.OnUrlOpenListener
|
2013-03-08 13:01:51 -08:00
|
|
|
@Override
|
2013-08-12 11:44:46 -07:00
|
|
|
public void onUrlOpen(String url, EnumSet<OnUrlOpenListener.Flags> flags) {
|
2014-01-29 16:36:37 -08:00
|
|
|
if (flags.contains(OnUrlOpenListener.Flags.OPEN_WITH_INTENT)) {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.setData(Uri.parse(url));
|
|
|
|
startActivity(intent);
|
|
|
|
} else if (!maybeSwitchToTab(url, flags)) {
|
2013-10-14 17:10:27 -07:00
|
|
|
openUrlAndStopEditing(url);
|
2013-08-12 11:44:46 -07:00
|
|
|
}
|
2013-04-16 14:34:46 -07:00
|
|
|
}
|
2013-08-12 11:44:46 -07:00
|
|
|
|
2013-06-11 10:01:35 -07:00
|
|
|
// BrowserSearch.OnSearchListener
|
|
|
|
@Override
|
2013-10-18 13:13:37 -07:00
|
|
|
public void onSearch(SearchEngine engine, String text) {
|
|
|
|
recordSearch(engine, "barsuggest");
|
2013-10-30 19:34:54 -07:00
|
|
|
openUrlAndStopEditing(text, engine.name);
|
2013-06-11 10:01:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// BrowserSearch.OnEditSuggestionListener
|
|
|
|
@Override
|
|
|
|
public void onEditSuggestion(String suggestion) {
|
|
|
|
mBrowserToolbar.onEditSuggestion(suggestion);
|
|
|
|
}
|
|
|
|
|
2013-04-09 17:10:47 -07:00
|
|
|
@Override
|
|
|
|
public int getLayout() { return R.layout.gecko_app; }
|
|
|
|
|
|
|
|
@Override
|
2014-03-03 15:27:42 -08:00
|
|
|
protected String getDefaultProfileName() throws NoMozillaDirectoryException {
|
|
|
|
return GeckoProfile.getDefaultProfileName(this);
|
2013-04-09 17:10:47 -07:00
|
|
|
}
|
2013-06-21 14:00:40 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Launch UI that lets the user update Firefox.
|
|
|
|
*
|
|
|
|
* This depends on the current channel: Release and Beta both direct to the
|
|
|
|
* Google Play Store. If updating is enabled, Aurora, Nightly, and custom
|
|
|
|
* builds open about:, which provides an update interface.
|
|
|
|
*
|
|
|
|
* If updating is not enabled, this simply logs an error.
|
|
|
|
*
|
|
|
|
* @return true if update UI was launched.
|
|
|
|
*/
|
|
|
|
protected boolean handleUpdaterLaunch() {
|
2013-08-08 10:40:26 -07:00
|
|
|
if (AppConstants.RELEASE_BUILD) {
|
2013-06-21 14:00:40 -07:00
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.setData(Uri.parse("market://details?id=" + getPackageName()));
|
|
|
|
startActivity(intent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (AppConstants.MOZ_UPDATER) {
|
2013-11-21 23:33:28 -08:00
|
|
|
Tabs.getInstance().loadUrlInTab(AboutPages.UPDATER);
|
2013-06-21 14:00:40 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Log.w(LOGTAG, "No candidate updater found; ignoring launch request.");
|
|
|
|
return false;
|
|
|
|
}
|
2013-11-19 11:57:35 -08:00
|
|
|
|
|
|
|
/* Implementing ActionModeCompat.Presenter */
|
|
|
|
@Override
|
|
|
|
public void startActionModeCompat(final ActionModeCompat.Callback callback) {
|
|
|
|
// If actionMode is null, we're not currently showing one. Flip to the action mode view
|
|
|
|
if (mActionMode == null) {
|
|
|
|
mViewFlipper.showNext();
|
|
|
|
LayerMarginsAnimator margins = mLayerView.getLayerMarginsAnimator();
|
2013-12-04 08:35:58 -08:00
|
|
|
|
|
|
|
// If the toolbar is dynamic and not currently showing, just slide it in
|
2014-03-13 12:29:39 -07:00
|
|
|
if (mDynamicToolbar.isEnabled() && !margins.areMarginsShown()) {
|
2013-12-04 08:35:58 -08:00
|
|
|
margins.setMaxMargins(0, mViewFlipper.getHeight(), 0, 0);
|
2014-03-13 12:29:39 -07:00
|
|
|
mDynamicToolbar.setVisible(true, VisibilityTransition.ANIMATE);
|
2014-01-13 15:20:13 -08:00
|
|
|
mShowActionModeEndAnimation = true;
|
2013-12-04 08:35:58 -08:00
|
|
|
} else {
|
|
|
|
// Otherwise, we animate the actionbar itself
|
|
|
|
mActionBar.animateIn();
|
|
|
|
}
|
|
|
|
|
2014-03-13 12:29:39 -07:00
|
|
|
mDynamicToolbar.setPinned(true, PinReason.ACTION_MODE);
|
2013-11-19 11:57:35 -08:00
|
|
|
} else {
|
|
|
|
// Otherwise, we're already showing an action mode. Just finish it and show the new one
|
|
|
|
mActionMode.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
mActionMode = new ActionModeCompat(BrowserApp.this, callback, mActionBar);
|
|
|
|
if (callback.onCreateActionMode(mActionMode, mActionMode.getMenu())) {
|
|
|
|
mActionMode.invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Implementing ActionModeCompat.Presenter */
|
|
|
|
@Override
|
|
|
|
public void endActionModeCompat() {
|
|
|
|
if (mActionMode == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mActionMode.finish();
|
|
|
|
mActionMode = null;
|
2014-03-13 12:29:39 -07:00
|
|
|
mDynamicToolbar.setPinned(false, PinReason.ACTION_MODE);
|
2014-01-13 15:20:13 -08:00
|
|
|
|
2013-11-19 11:57:35 -08:00
|
|
|
mViewFlipper.showPrevious();
|
2014-01-13 15:20:13 -08:00
|
|
|
|
|
|
|
// Only slide the urlbar out if it was hidden when the action mode started
|
|
|
|
// Don't animate hiding it so that there's no flash as we switch back to url mode
|
|
|
|
if (mShowActionModeEndAnimation) {
|
2014-03-13 12:29:39 -07:00
|
|
|
mDynamicToolbar.setVisible(false, VisibilityTransition.IMMEDIATE);
|
2014-01-13 15:20:13 -08:00
|
|
|
mShowActionModeEndAnimation = false;
|
|
|
|
}
|
2013-11-19 11:57:35 -08:00
|
|
|
}
|
2014-02-04 19:41:29 -08:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected HealthRecorder createHealthRecorder(final Context context,
|
|
|
|
final String profilePath,
|
|
|
|
final EventDispatcher dispatcher,
|
|
|
|
final String osLocale,
|
|
|
|
final String appLocale,
|
2014-02-04 19:41:29 -08:00
|
|
|
final SessionInformation previousSession) {
|
2014-02-04 19:41:29 -08:00
|
|
|
return new BrowserHealthRecorder(context,
|
2014-04-02 18:33:24 -07:00
|
|
|
GeckoSharedPrefs.forApp(context),
|
2014-02-04 19:41:29 -08:00
|
|
|
profilePath,
|
|
|
|
dispatcher,
|
|
|
|
osLocale,
|
|
|
|
appLocale,
|
|
|
|
previousSession);
|
|
|
|
}
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|