/*
* Zirco Browser for Android
*
* Copyright (C) 2010 - 2012 J. Devauchelle and contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
package org.zirco.ui.activities;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.greendroid.QuickAction;
import org.greendroid.QuickActionGrid;
import org.greendroid.QuickActionWidget;
import org.greendroid.QuickActionWidget.OnQuickActionClickListener;
import org.zirco.R;
import org.zirco.controllers.Controller;
import org.zirco.events.EventConstants;
import org.zirco.events.EventController;
import org.zirco.events.IDownloadEventsListener;
import org.zirco.model.adapters.UrlSuggestionCursorAdapter;
import org.zirco.model.items.DownloadItem;
import org.zirco.providers.BookmarksProviderWrapper;
import org.zirco.providers.BookmarksProviderWrapper.BookmarksSource;
import org.zirco.ui.activities.preferences.PreferencesActivity;
import org.zirco.ui.components.CustomWebView;
import org.zirco.ui.components.CustomWebViewClient;
import org.zirco.ui.runnables.FaviconUpdaterRunnable;
import org.zirco.ui.runnables.HideToolbarsRunnable;
import org.zirco.ui.runnables.HistoryUpdater;
import org.zirco.utils.AnimationManager;
import org.zirco.utils.ApplicationUtils;
import org.zirco.utils.Constants;
import org.zirco.utils.UrlUtils;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.res.Configuration;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.ContextMenu;
import android.view.GestureDetector;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.inputmethod.InputMethodManager;
import android.webkit.DownloadListener;
import android.webkit.JsPromptResult;
import android.webkit.JsResult;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebIconDatabase;
import android.webkit.WebView;
import android.webkit.WebView.HitTestResult;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.FilterQueryProvider;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;
import android.widget.SimpleCursorAdapter.CursorToStringConverter;
/**
* The application main activity.
*/
public class MainActivity extends Activity implements IToolbarsContainer, OnTouchListener, IDownloadEventsListener {
public static MainActivity INSTANCE = null;
private static final int FLIP_PIXEL_THRESHOLD = 200;
private static final int FLIP_TIME_THRESHOLD = 400;
private static final int MENU_ADD_BOOKMARK = Menu.FIRST;
private static final int MENU_SHOW_BOOKMARKS = Menu.FIRST + 1;
private static final int MENU_SHOW_DOWNLOADS = Menu.FIRST + 2;
private static final int MENU_PREFERENCES = Menu.FIRST + 3;
private static final int MENU_EXIT = Menu.FIRST + 4;
private static final int CONTEXT_MENU_OPEN = Menu.FIRST + 10;
private static final int CONTEXT_MENU_OPEN_IN_NEW_TAB = Menu.FIRST + 11;
private static final int CONTEXT_MENU_DOWNLOAD = Menu.FIRST + 12;
private static final int CONTEXT_MENU_COPY = Menu.FIRST + 13;
private static final int CONTEXT_MENU_SEND_MAIL = Menu.FIRST + 14;
private static final int CONTEXT_MENU_SHARE = Menu.FIRST + 15;
private static final int OPEN_BOOKMARKS_HISTORY_ACTIVITY = 0;
private static final int OPEN_DOWNLOADS_ACTIVITY = 1;
private static final int OPEN_FILE_CHOOSER_ACTIVITY = 2;
protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
protected LayoutInflater mInflater = null;
private LinearLayout mTopBar;
private LinearLayout mBottomBar;
private LinearLayout mFindBar;
private ImageButton mFindPreviousButton;
private ImageButton mFindNextButton;
private ImageButton mFindCloseButton;
private EditText mFindText;
private ImageView mPreviousTabView;
private ImageView mNextTabView;
private ImageButton mToolsButton;
private AutoCompleteTextView mUrlEditText;
private ImageButton mGoButton;
private ProgressBar mProgressBar;
private ImageView mBubbleRightView;
private ImageView mBubbleLeftView;
private CustomWebView mCurrentWebView;
private List<CustomWebView> mWebViews;
private ImageButton mPreviousButton;
private ImageButton mNextButton;
private ImageButton mNewTabButton;
private ImageButton mRemoveTabButton;
private ImageButton mQuickButton;
private Drawable mCircularProgress;
private boolean mUrlBarVisible;
private boolean mToolsActionGridVisible = false;
private boolean mFindDialogVisible = false;
private TextWatcher mUrlTextWatcher;
private HideToolbarsRunnable mHideToolbarsRunnable;
private ViewFlipper mViewFlipper;
private GestureDetector mGestureDetector;
private SwitchTabsMethod mSwitchTabsMethod = SwitchTabsMethod.BOTH;
private QuickActionGrid mToolsActionGrid;
private ValueCallback<Uri> mUploadMessage;
private OnSharedPreferenceChangeListener mPreferenceChangeListener;
private View mCustomView;
private Bitmap mDefaultVideoPoster = null;
private View mVideoProgressView = null;
private FrameLayout mFullscreenContainer;
private WebChromeClient.CustomViewCallback mCustomViewCallback;
private enum SwitchTabsMethod {
BUTTONS,
FLING,
BOTH
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
INSTANCE = this;
Constants.initializeConstantsFromResources(this);
Controller.getInstance().setPreferences(PreferenceManager.getDefaultSharedPreferences(this));
if (Controller.getInstance().getPreferences().getBoolean(Constants.PREFERENCES_SHOW_FULL_SCREEN, false)) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
if (Controller.getInstance().getPreferences().getBoolean(Constants.PREFERENCES_GENERAL_HIDE_TITLE_BARS, true)) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
}
setProgressBarVisibility(true);