You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2648 lines
78 KiB
2648 lines
78 KiB
10 years ago
|
/*
|
||
|
* Copyright 2014 A.C.R. Development
|
||
|
*/
|
||
|
|
||
|
package acr.browser.lightning;
|
||
|
|
||
9 years ago
|
import android.animation.ArgbEvaluator;
|
||
|
import android.animation.ValueAnimator;
|
||
|
import android.animation.ValueAnimator.AnimatorUpdateListener;
|
||
10 years ago
|
import android.annotation.SuppressLint;
|
||
10 years ago
|
import android.app.Activity;
|
||
|
import android.app.AlertDialog;
|
||
10 years ago
|
import android.content.*;
|
||
9 years ago
|
import android.content.res.Configuration;
|
||
9 years ago
|
import android.content.res.Resources.Theme;
|
||
10 years ago
|
import android.database.Cursor;
|
||
|
import android.database.sqlite.SQLiteException;
|
||
|
import android.graphics.Bitmap;
|
||
|
import android.graphics.BitmapFactory;
|
||
|
import android.graphics.Canvas;
|
||
9 years ago
|
import android.graphics.Color;
|
||
10 years ago
|
import android.graphics.ColorMatrix;
|
||
|
import android.graphics.ColorMatrixColorFilter;
|
||
10 years ago
|
import android.graphics.Paint;
|
||
9 years ago
|
import android.graphics.drawable.ColorDrawable;
|
||
10 years ago
|
import android.graphics.drawable.Drawable;
|
||
|
import android.media.MediaPlayer;
|
||
|
import android.net.Uri;
|
||
|
import android.os.AsyncTask;
|
||
9 years ago
|
import android.os.Build;
|
||
10 years ago
|
import android.os.Bundle;
|
||
10 years ago
|
import android.os.Handler;
|
||
10 years ago
|
import android.os.Message;
|
||
|
import android.provider.Browser;
|
||
9 years ago
|
import android.provider.MediaStore;
|
||
10 years ago
|
import android.support.v4.view.GravityCompat;
|
||
9 years ago
|
import android.support.v4.view.ViewCompat;
|
||
10 years ago
|
import android.support.v4.widget.DrawerLayout;
|
||
9 years ago
|
import android.support.v4.widget.DrawerLayout.DrawerListener;
|
||
10 years ago
|
import android.text.TextUtils;
|
||
|
import android.util.Log;
|
||
10 years ago
|
import android.view.*;
|
||
10 years ago
|
import android.view.View.OnClickListener;
|
||
9 years ago
|
import android.view.View.OnFocusChangeListener;
|
||
10 years ago
|
import android.view.View.OnKeyListener;
|
||
10 years ago
|
import android.view.View.OnLongClickListener;
|
||
10 years ago
|
import android.view.View.OnTouchListener;
|
||
10 years ago
|
import android.view.ViewGroup.LayoutParams;
|
||
9 years ago
|
import android.view.animation.Animation;
|
||
9 years ago
|
import android.view.animation.Animation.AnimationListener;
|
||
|
import android.view.animation.AnimationUtils;
|
||
10 years ago
|
import android.view.animation.DecelerateInterpolator;
|
||
9 years ago
|
import android.view.animation.Transformation;
|
||
10 years ago
|
import android.view.inputmethod.EditorInfo;
|
||
|
import android.view.inputmethod.InputMethodManager;
|
||
10 years ago
|
import android.webkit.*;
|
||
10 years ago
|
import android.webkit.WebChromeClient.CustomViewCallback;
|
||
10 years ago
|
import android.webkit.WebView.HitTestResult;
|
||
10 years ago
|
import android.widget.*;
|
||
9 years ago
|
import android.support.v7.app.ActionBar;
|
||
|
import android.support.v7.graphics.Palette;
|
||
|
import android.support.v7.widget.Toolbar;
|
||
10 years ago
|
import android.widget.AdapterView.OnItemClickListener;
|
||
|
import android.widget.TextView.OnEditorActionListener;
|
||
10 years ago
|
import info.guardianproject.onionkit.ui.OrbotHelper;
|
||
|
import info.guardianproject.onionkit.web.WebkitProxy;
|
||
|
|
||
|
import java.io.*;
|
||
10 years ago
|
import java.net.HttpURLConnection;
|
||
10 years ago
|
import java.net.URI;
|
||
|
import java.net.URISyntaxException;
|
||
10 years ago
|
import java.net.URL;
|
||
10 years ago
|
import java.net.URLEncoder;
|
||
|
import java.util.*;
|
||
10 years ago
|
|
||
9 years ago
|
public class BrowserActivity extends ThemableActivity implements BrowserController, OnClickListener {
|
||
10 years ago
|
|
||
9 years ago
|
// Layout
|
||
10 years ago
|
private DrawerLayout mDrawerLayout;
|
||
9 years ago
|
private FrameLayout mBrowserFrame;
|
||
|
private FullscreenHolder mFullscreenContainer;
|
||
9 years ago
|
private ListView mDrawerListLeft, mDrawerListRight;
|
||
9 years ago
|
private LinearLayout mDrawerLeft, mDrawerRight, mUiLayout, mToolbarLayout;
|
||
9 years ago
|
private RelativeLayout mNewTab, mSearchBar;
|
||
9 years ago
|
|
||
|
// List
|
||
|
private final List<LightningView> mWebViews = new ArrayList<LightningView>();
|
||
|
private List<HistoryItem> mBookmarkList;
|
||
10 years ago
|
private LightningView mCurrentView;
|
||
9 years ago
|
|
||
|
// View
|
||
|
private ActionBar mActionBar;
|
||
|
private AnimatedProgressBar mProgressBar;
|
||
|
private AutoCompleteTextView mSearch;
|
||
|
private ImageView mArrowImage;
|
||
9 years ago
|
private Toolbar mToolbar;
|
||
9 years ago
|
private VideoView mVideoView;
|
||
|
private View mCustomView, mVideoProgressView;
|
||
|
|
||
|
// Adapter
|
||
10 years ago
|
private BookmarkViewAdapter mBookmarkAdapter;
|
||
9 years ago
|
private LightningViewAdapter mTitleAdapter;
|
||
|
private SearchAdapter mSearchAdapter;
|
||
|
|
||
|
// Callback
|
||
10 years ago
|
private ClickHandler mClickHandler;
|
||
|
private CustomViewCallback mCustomViewCallback;
|
||
9 years ago
|
private ValueCallback<Uri> mUploadMessage;
|
||
9 years ago
|
private ValueCallback<Uri[]> mFilePathCallback;
|
||
9 years ago
|
|
||
|
// Context
|
||
|
private Activity mActivity;
|
||
|
|
||
|
// Native
|
||
|
private boolean mSystemBrowser = false, mIsNewIntent = false, mFullScreen, mColorMode,
|
||
|
mDarkTheme;
|
||
|
private int mOriginalOrientation, mBackgroundColor, mIdGenerator;
|
||
9 years ago
|
private String mSearchText, mUntitledTitle, mHomepage, mCameraPhotoPath;
|
||
9 years ago
|
|
||
|
// Storage
|
||
9 years ago
|
private HistoryDatabase mHistoryDatabase;
|
||
9 years ago
|
private BookmarkManager mBookmarkManager;
|
||
9 years ago
|
private PreferenceManager mPreferences;
|
||
9 years ago
|
|
||
|
// Image
|
||
|
private Bitmap mDefaultVideoPoster, mWebpageBitmap;
|
||
|
private final ColorDrawable mBackground = new ColorDrawable();
|
||
9 years ago
|
private Drawable mDeleteIcon, mRefreshIcon, mCopyIcon, mIcon;
|
||
9 years ago
|
private DrawerArrowDrawable mArrowDrawable;
|
||
|
|
||
|
// Constant
|
||
|
private static final int API = android.os.Build.VERSION.SDK_INT;
|
||
|
private static final LayoutParams MATCH_PARENT = new LayoutParams(LayoutParams.MATCH_PARENT,
|
||
10 years ago
|
LayoutParams.MATCH_PARENT);
|
||
9 years ago
|
private static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = new FrameLayout.LayoutParams(
|
||
|
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
protected void onCreate(Bundle savedInstanceState) {
|
||
|
super.onCreate(savedInstanceState);
|
||
|
initialize();
|
||
|
}
|
||
|
|
||
9 years ago
|
@SuppressLint("NewApi")
|
||
10 years ago
|
@SuppressWarnings("deprecation")
|
||
|
private synchronized void initialize() {
|
||
|
setContentView(R.layout.activity_main);
|
||
9 years ago
|
mToolbar = (Toolbar) findViewById(R.id.toolbar);
|
||
|
setSupportActionBar(mToolbar);
|
||
9 years ago
|
mActionBar = getSupportActionBar();
|
||
9 years ago
|
|
||
9 years ago
|
mPreferences = PreferenceManager.getInstance();
|
||
|
mDarkTheme = mPreferences.getUseDarkTheme() || isIncognito();
|
||
9 years ago
|
mActivity = this;
|
||
|
mWebViews.clear();
|
||
9 years ago
|
|
||
10 years ago
|
mClickHandler = new ClickHandler(this);
|
||
|
mBrowserFrame = (FrameLayout) findViewById(R.id.content_frame);
|
||
9 years ago
|
mToolbarLayout = (LinearLayout) findViewById(R.id.toolbar_layout);
|
||
9 years ago
|
// initialize background ColorDrawable
|
||
|
mBackground.setColor(((ColorDrawable) mToolbarLayout.getBackground()).getColor());
|
||
9 years ago
|
|
||
9 years ago
|
mUiLayout = (LinearLayout) findViewById(R.id.ui_layout);
|
||
9 years ago
|
mProgressBar = (AnimatedProgressBar) findViewById(R.id.progress_view);
|
||
10 years ago
|
mNewTab = (RelativeLayout) findViewById(R.id.new_tab_button);
|
||
9 years ago
|
mDrawerLeft = (LinearLayout) findViewById(R.id.left_drawer);
|
||
9 years ago
|
// Drawer stutters otherwise
|
||
|
mDrawerLeft.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
||
10 years ago
|
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||
10 years ago
|
mDrawerListLeft = (ListView) findViewById(R.id.left_drawer_list);
|
||
10 years ago
|
mDrawerRight = (LinearLayout) findViewById(R.id.right_drawer);
|
||
9 years ago
|
mDrawerRight.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
||
10 years ago
|
mDrawerListRight = (ListView) findViewById(R.id.right_drawer_list);
|
||
9 years ago
|
|
||
10 years ago
|
setNavigationDrawerWidth();
|
||
9 years ago
|
mDrawerLayout.setDrawerListener(new DrawerLocker());
|
||
9 years ago
|
|
||
9 years ago
|
mWebpageBitmap = Utils.getWebpageBitmap(getResources(), mDarkTheme);
|
||
10 years ago
|
|
||
9 years ago
|
mHomepage = mPreferences.getHomepage();
|
||
10 years ago
|
|
||
|
mTitleAdapter = new LightningViewAdapter(this, R.layout.tab_list_item, mWebViews);
|
||
10 years ago
|
mDrawerListLeft.setAdapter(mTitleAdapter);
|
||
|
mDrawerListLeft.setOnItemClickListener(new DrawerItemClickListener());
|
||
|
mDrawerListLeft.setOnItemLongClickListener(new DrawerItemLongClickListener());
|
||
10 years ago
|
|
||
|
mDrawerListRight.setOnItemClickListener(new BookmarkItemClickListener());
|
||
|
mDrawerListRight.setOnItemLongClickListener(new BookmarkItemLongClickListener());
|
||
|
|
||
9 years ago
|
mHistoryDatabase = HistoryDatabase.getInstance(getApplicationContext());
|
||
10 years ago
|
|
||
|
// set display options of the ActionBar
|
||
|
mActionBar.setDisplayShowTitleEnabled(false);
|
||
9 years ago
|
mActionBar.setDisplayShowHomeEnabled(false);
|
||
10 years ago
|
mActionBar.setDisplayShowCustomEnabled(true);
|
||
9 years ago
|
mActionBar.setCustomView(R.layout.toolbar_content);
|
||
|
|
||
|
View v = mActionBar.getCustomView();
|
||
|
LayoutParams lp = v.getLayoutParams();
|
||
|
lp.width = LayoutParams.MATCH_PARENT;
|
||
|
v.setLayoutParams(lp);
|
||
|
|
||
9 years ago
|
mArrowDrawable = new DrawerArrowDrawable(this);
|
||
|
mArrowImage = (ImageView) mActionBar.getCustomView().findViewById(R.id.arrow);
|
||
9 years ago
|
// Use hardware acceleration for the animation
|
||
|
mArrowImage.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
||
9 years ago
|
mArrowImage.setImageDrawable(mArrowDrawable);
|
||
9 years ago
|
LinearLayout arrowButton = (LinearLayout) mActionBar.getCustomView().findViewById(
|
||
|
R.id.arrow_button);
|
||
9 years ago
|
arrowButton.setOnClickListener(this);
|
||
10 years ago
|
|
||
|
RelativeLayout back = (RelativeLayout) findViewById(R.id.action_back);
|
||
9 years ago
|
back.setOnClickListener(this);
|
||
10 years ago
|
|
||
9 years ago
|
RelativeLayout forward = (RelativeLayout) findViewById(R.id.action_forward);
|
||
|
forward.setOnClickListener(this);
|
||
10 years ago
|
|
||
9 years ago
|
// create the search EditText in the ToolBar
|
||
10 years ago
|
mSearch = (AutoCompleteTextView) mActionBar.getCustomView().findViewById(R.id.search);
|
||
9 years ago
|
mUntitledTitle = (String) getString(R.string.untitled);
|
||
9 years ago
|
mBackgroundColor = getResources().getColor(R.color.primary_color);
|
||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||
|
mDeleteIcon = getResources().getDrawable(R.drawable.ic_action_delete);
|
||
|
mRefreshIcon = getResources().getDrawable(R.drawable.ic_action_refresh);
|
||
|
mCopyIcon = getResources().getDrawable(R.drawable.ic_action_copy);
|
||
|
} else {
|
||
9 years ago
|
Theme theme = getTheme();
|
||
9 years ago
|
mDeleteIcon = getResources().getDrawable(R.drawable.ic_action_delete, theme);
|
||
|
mRefreshIcon = getResources().getDrawable(R.drawable.ic_action_refresh, theme);
|
||
|
mCopyIcon = getResources().getDrawable(R.drawable.ic_action_copy, theme);
|
||
|
}
|
||
|
|
||
9 years ago
|
int iconBounds = Utils.convertDpToPixels(24);
|
||
|
mDeleteIcon.setBounds(0, 0, iconBounds, iconBounds);
|
||
|
mRefreshIcon.setBounds(0, 0, iconBounds, iconBounds);
|
||
|
mCopyIcon.setBounds(0, 0, iconBounds, iconBounds);
|
||
10 years ago
|
mIcon = mRefreshIcon;
|
||
9 years ago
|
SearchClass search = new SearchClass();
|
||
10 years ago
|
mSearch.setCompoundDrawables(null, null, mRefreshIcon, null);
|
||
9 years ago
|
mSearch.setOnKeyListener(search.new KeyListener());
|
||
|
mSearch.setOnFocusChangeListener(search.new FocusChangeListener());
|
||
|
mSearch.setOnEditorActionListener(search.new EditorActionListener());
|
||
|
mSearch.setOnTouchListener(search.new TouchListener());
|
||
|
|
||
|
mSystemBrowser = getSystemBrowser();
|
||
|
Thread initialize = new Thread(new Runnable() {
|
||
|
|
||
|
@Override
|
||
|
public void run() {
|
||
9 years ago
|
mBookmarkManager = BookmarkManager.getInstance(mActivity.getApplicationContext());
|
||
|
mBookmarkList = mBookmarkManager.getBookmarks(true);
|
||
9 years ago
|
if (mBookmarkList.size() == 0 && mPreferences.getDefaultBookmarks()) {
|
||
|
for (String[] array : BookmarkManager.DEFAULT_BOOKMARKS) {
|
||
|
HistoryItem bookmark = new HistoryItem(array[0], array[1]);
|
||
|
if (mBookmarkManager.addBookmark(bookmark)) {
|
||
|
mBookmarkList.add(bookmark);
|
||
|
}
|
||
|
}
|
||
|
Collections.sort(mBookmarkList, new SortIgnoreCase());
|
||
|
mPreferences.setDefaultBookmarks(false);
|
||
|
}
|
||
9 years ago
|
mBookmarkAdapter = new BookmarkViewAdapter(mActivity, R.layout.bookmark_list_item,
|
||
|
mBookmarkList);
|
||
|
mDrawerListRight.setAdapter(mBookmarkAdapter);
|
||
9 years ago
|
initializeSearchSuggestions(mSearch);
|
||
|
}
|
||
|
|
||
|
});
|
||
|
initialize.run();
|
||
|
|
||
9 years ago
|
mNewTab.setOnClickListener(this);
|
||
9 years ago
|
mNewTab.setOnLongClickListener(new OnLongClickListener() {
|
||
|
|
||
|
@Override
|
||
|
public boolean onLongClick(View v) {
|
||
9 years ago
|
String url = mPreferences.getSavedUrl();
|
||
9 years ago
|
if (url != null) {
|
||
|
newTab(url, true);
|
||
9 years ago
|
Toast.makeText(mActivity, R.string.deleted_tab, Toast.LENGTH_SHORT).show();
|
||
9 years ago
|
}
|
||
9 years ago
|
mPreferences.setSavedUrl(null);
|
||
9 years ago
|
return true;
|
||
|
}
|
||
|
|
||
|
});
|
||
|
|
||
|
mDrawerLayout.setDrawerShadow(R.drawable.drawer_right_shadow, GravityCompat.END);
|
||
|
mDrawerLayout.setDrawerShadow(R.drawable.drawer_left_shadow, GravityCompat.START);
|
||
|
initializeTabs();
|
||
|
|
||
|
if (API <= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||
|
WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath());
|
||
|
}
|
||
|
|
||
|
checkForTor();
|
||
|
}
|
||
|
|
||
|
private class SearchClass {
|
||
|
|
||
|
public class KeyListener implements OnKeyListener {
|
||
10 years ago
|
|
||
|
@Override
|
||
|
public boolean onKey(View arg0, int arg1, KeyEvent arg2) {
|
||
|
|
||
|
switch (arg1) {
|
||
10 years ago
|
case KeyEvent.KEYCODE_ENTER:
|
||
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||
|
imm.hideSoftInputFromWindow(mSearch.getWindowToken(), 0);
|
||
|
searchTheWeb(mSearch.getText().toString());
|
||
|
if (mCurrentView != null) {
|
||
|
mCurrentView.requestFocus();
|
||
|
}
|
||
|
return true;
|
||
|
default:
|
||
|
break;
|
||
10 years ago
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
9 years ago
|
}
|
||
|
|
||
|
public class EditorActionListener implements OnEditorActionListener {
|
||
|
@Override
|
||
|
public boolean onEditorAction(TextView arg0, int actionId, KeyEvent arg2) {
|
||
|
// hide the keyboard and search the web when the enter key
|
||
|
// button is pressed
|
||
|
if (actionId == EditorInfo.IME_ACTION_GO || actionId == EditorInfo.IME_ACTION_DONE
|
||
|
|| actionId == EditorInfo.IME_ACTION_NEXT
|
||
|
|| actionId == EditorInfo.IME_ACTION_SEND
|
||
|
|| actionId == EditorInfo.IME_ACTION_SEARCH
|
||
|
|| (arg2.getAction() == KeyEvent.KEYCODE_ENTER)) {
|
||
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||
|
imm.hideSoftInputFromWindow(mSearch.getWindowToken(), 0);
|
||
|
searchTheWeb(mSearch.getText().toString());
|
||
|
if (mCurrentView != null) {
|
||
|
mCurrentView.requestFocus();
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
public class FocusChangeListener implements OnFocusChangeListener {
|
||
10 years ago
|
@Override
|
||
9 years ago
|
public void onFocusChange(View v, final boolean hasFocus) {
|
||
10 years ago
|
if (!hasFocus && mCurrentView != null) {
|
||
9 years ago
|
if (mCurrentView.getProgress() < 100) {
|
||
|
setIsLoading();
|
||
|
} else {
|
||
|
setIsFinishedLoading();
|
||
10 years ago
|
}
|
||
9 years ago
|
updateUrl(mCurrentView.getUrl(), true);
|
||
10 years ago
|
} else if (hasFocus) {
|
||
9 years ago
|
String url = mCurrentView.getUrl();
|
||
|
if (url == null || url.startsWith(Constants.FILE)) {
|
||
|
mSearch.setText("");
|
||
|
} else {
|
||
|
mSearch.setText(url);
|
||
|
}
|
||
|
((AutoCompleteTextView) v).selectAll(); // Hack to make sure
|
||
|
// the text gets
|
||
|
// selected
|
||
10 years ago
|
mIcon = mCopyIcon;
|
||
|
mSearch.setCompoundDrawables(null, null, mCopyIcon, null);
|
||
|
}
|
||
9 years ago
|
final Animation anim = new Animation() {
|
||
|
|
||
|
@Override
|
||
|
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
||
|
if (!hasFocus) {
|
||
9 years ago
|
mArrowDrawable.setProgress(1.0f - interpolatedTime);
|
||
9 years ago
|
} else {
|
||
9 years ago
|
mArrowDrawable.setProgress(interpolatedTime);
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean willChangeBounds() {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
};
|
||
|
anim.setDuration(300);
|
||
|
anim.setInterpolator(new DecelerateInterpolator());
|
||
9 years ago
|
anim.setAnimationListener(new AnimationListener() {
|
||
9 years ago
|
|
||
|
@Override
|
||
|
public void onAnimationStart(Animation animation) {
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onAnimationEnd(Animation animation) {
|
||
|
if (!hasFocus) {
|
||
9 years ago
|
mArrowDrawable.setProgress(0.0f);
|
||
9 years ago
|
} else {
|
||
9 years ago
|
mArrowDrawable.setProgress(1.0f);
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onAnimationRepeat(Animation animation) {
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
});
|
||
9 years ago
|
new Handler().postDelayed(new Runnable() {
|
||
|
|
||
|
@Override
|
||
|
public void run() {
|
||
9 years ago
|
mArrowImage.startAnimation(anim);
|
||
9 years ago
|
}
|
||
|
|
||
|
}, 100);
|
||
|
|
||
|
if (!hasFocus) {
|
||
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||
|
imm.hideSoftInputFromWindow(mSearch.getWindowToken(), 0);
|
||
|
}
|
||
10 years ago
|
}
|
||
9 years ago
|
}
|
||
10 years ago
|
|
||
9 years ago
|
public class TouchListener implements OnTouchListener {
|
||
10 years ago
|
|
||
|
@SuppressLint("ClickableViewAccessibility")
|
||
|
@Override
|
||
|
public boolean onTouch(View v, MotionEvent event) {
|
||
|
if (mSearch.getCompoundDrawables()[2] != null) {
|
||
|
boolean tappedX = event.getX() > (mSearch.getWidth()
|
||
|
- mSearch.getPaddingRight() - mIcon.getIntrinsicWidth());
|
||
|
if (tappedX) {
|
||
|
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||
|
if (mSearch.hasFocus()) {
|
||
|
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||
|
ClipData clip = ClipData.newPlainText("label", mSearch.getText()
|
||
|
.toString());
|
||
|
clipboard.setPrimaryClip(clip);
|
||
|
Utils.showToast(
|
||
9 years ago
|
mActivity,
|
||
|
mActivity.getResources().getString(
|
||
10 years ago
|
R.string.message_text_copied));
|
||
|
} else {
|
||
|
refreshOrStop();
|
||
|
}
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
private class DrawerLocker implements DrawerListener {
|
||
|
|
||
|
@Override
|
||
|
public void onDrawerClosed(View v) {
|
||
9 years ago
|
if (v == mDrawerRight) {
|
||
9 years ago
|
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, mDrawerLeft);
|
||
|
} else {
|
||
|
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, mDrawerRight);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onDrawerOpened(View v) {
|
||
9 years ago
|
if (v == mDrawerRight) {
|
||
9 years ago
|
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, mDrawerLeft);
|
||
|
} else {
|
||
|
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, mDrawerRight);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onDrawerSlide(View v, float arg) {
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onDrawerStateChanged(int arg) {
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
}
|
||
10 years ago
|
|
||
|
/*
|
||
|
* If Orbot/Tor is installed, prompt the user if they want to enable
|
||
|
* proxying for this session
|
||
|
*/
|
||
|
public boolean checkForTor() {
|
||
9 years ago
|
boolean useProxy = mPreferences.getUseProxy();
|
||
10 years ago
|
|
||
|
OrbotHelper oh = new OrbotHelper(this);
|
||
9 years ago
|
if (oh.isOrbotInstalled() && !mPreferences.getCheckedForTor()) {
|
||
|
mPreferences.setCheckedForTor(true);
|
||
10 years ago
|
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int which) {
|
||
|
switch (which) {
|
||
10 years ago
|
case DialogInterface.BUTTON_POSITIVE:
|
||
9 years ago
|
mPreferences.setUseProxy(true);
|
||
10 years ago
|
initializeTor();
|
||
|
break;
|
||
|
case DialogInterface.BUTTON_NEGATIVE:
|
||
9 years ago
|
mPreferences.setUseProxy(false);
|
||
10 years ago
|
break;
|
||
10 years ago
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||
|
builder.setMessage(R.string.use_tor_prompt)
|
||
|
.setPositiveButton(R.string.yes, dialogClickListener)
|
||
|
.setNegativeButton(R.string.no, dialogClickListener).show();
|
||
|
|
||
|
return true;
|
||
9 years ago
|
} else if (oh.isOrbotInstalled() & useProxy) {
|
||
10 years ago
|
return true;
|
||
|
} else {
|
||
9 years ago
|
mPreferences.setUseProxy(false);
|
||
10 years ago
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* Initialize WebKit Proxying for Tor
|
||
|
*/
|
||
|
public void initializeTor() {
|
||
|
|
||
|
OrbotHelper oh = new OrbotHelper(this);
|
||
|
if (!oh.isOrbotRunning()) {
|
||
|
oh.requestOrbotStart(this);
|
||
|
}
|
||
|
try {
|
||
9 years ago
|
String host = mPreferences.getProxyHost();
|
||
|
int port = mPreferences.getProxyPort();
|
||
9 years ago
|
WebkitProxy.setProxy(this.getPackageName() + ".BrowserApp", getApplicationContext(),
|
||
|
host, port);
|
||
10 years ago
|
} catch (Exception e) {
|
||
|
Log.d(Constants.TAG, "error enabling web proxying", e);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
9 years ago
|
private boolean isTablet() {
|
||
|
return (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE;
|
||
|
}
|
||
|
|
||
|
private void setNavigationDrawerWidth() {
|
||
9 years ago
|
int width = getResources().getDisplayMetrics().widthPixels - Utils.convertDpToPixels(56);
|
||
9 years ago
|
int maxWidth;
|
||
9 years ago
|
if (isTablet()) {
|
||
9 years ago
|
maxWidth = Utils.convertDpToPixels(320);
|
||
|
} else {
|
||
|
maxWidth = Utils.convertDpToPixels(300);
|
||
|
}
|
||
10 years ago
|
if (width > maxWidth) {
|
||
10 years ago
|
DrawerLayout.LayoutParams params = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerLeft
|
||
10 years ago
|
.getLayoutParams();
|
||
|
params.width = maxWidth;
|
||
10 years ago
|
mDrawerLeft.setLayoutParams(params);
|
||
9 years ago
|
mDrawerLeft.requestLayout();
|
||
10 years ago
|
DrawerLayout.LayoutParams paramsRight = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerRight
|
||
|
.getLayoutParams();
|
||
|
paramsRight.width = maxWidth;
|
||
|
mDrawerRight.setLayoutParams(paramsRight);
|
||
9 years ago
|
mDrawerRight.requestLayout();
|
||
10 years ago
|
} else {
|
||
10 years ago
|
DrawerLayout.LayoutParams params = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerLeft
|
||
10 years ago
|
.getLayoutParams();
|
||
|
params.width = width;
|
||
10 years ago
|
mDrawerLeft.setLayoutParams(params);
|
||
9 years ago
|
mDrawerLeft.requestLayout();
|
||
10 years ago
|
DrawerLayout.LayoutParams paramsRight = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerRight
|
||
|
.getLayoutParams();
|
||
|
paramsRight.width = width;
|
||
|
mDrawerRight.setLayoutParams(paramsRight);
|
||
9 years ago
|
mDrawerRight.requestLayout();
|
||
10 years ago
|
}
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* Override this class
|
||
|
*/
|
||
|
public synchronized void initializeTabs() {
|
||
|
|
||
|
}
|
||
|
|
||
|
public void restoreOrNewTab() {
|
||
|
mIdGenerator = 0;
|
||
|
|
||
|
String url = null;
|
||
|
if (getIntent() != null) {
|
||
|
url = getIntent().getDataString();
|
||
|
if (url != null) {
|
||
|
if (url.startsWith(Constants.FILE)) {
|
||
|
Utils.showToast(this, getResources().getString(R.string.message_blocked_local));
|
||
|
url = null;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
9 years ago
|
if (mPreferences.getRestoreLostTabsEnabled()) {
|
||
|
String mem = mPreferences.getMemoryUrl();
|
||
|
mPreferences.setMemoryUrl("");
|
||
10 years ago
|
String[] array = Utils.getArray(mem);
|
||
|
int count = 0;
|
||
|
for (int n = 0; n < array.length; n++) {
|
||
|
if (array[n].length() > 0) {
|
||
9 years ago
|
if (url != null && url.compareTo(array[n]) == 0) {
|
||
|
url = null;
|
||
|
}
|
||
10 years ago
|
newTab(array[n], true);
|
||
|
count++;
|
||
|
}
|
||
|
}
|
||
|
if (url != null) {
|
||
|
newTab(url, true);
|
||
|
} else if (count == 0) {
|
||
|
newTab(null, true);
|
||
|
}
|
||
|
} else {
|
||
|
newTab(url, true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void initializePreferences() {
|
||
9 years ago
|
if (mPreferences == null) {
|
||
|
mPreferences = PreferenceManager.getInstance();
|
||
|
}
|
||
9 years ago
|
mFullScreen = mPreferences.getFullScreenEnabled();
|
||
|
mColorMode = mPreferences.getColorModeEnabled();
|
||
9 years ago
|
mColorMode &= !mDarkTheme;
|
||
|
if (!isIncognito() && !mColorMode && !mDarkTheme && mWebpageBitmap != null) {
|
||
9 years ago
|
changeToolbarBackground(mWebpageBitmap);
|
||
9 years ago
|
} else if (!isIncognito() && mCurrentView != null && !mDarkTheme
|
||
|
&& mCurrentView.getFavicon() != null) {
|
||
9 years ago
|
changeToolbarBackground(mCurrentView.getFavicon());
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
|
if (mFullScreen && mBrowserFrame.findViewById(R.id.toolbar_layout) == null) {
|
||
|
mUiLayout.removeView(mToolbarLayout);
|
||
|
mBrowserFrame.addView(mToolbarLayout);
|
||
|
mToolbarLayout.bringToFront();
|
||
|
} else if (mBrowserFrame.findViewById(R.id.toolbar_layout) != null) {
|
||
|
mBrowserFrame.removeView(mToolbarLayout);
|
||
|
mUiLayout.addView(mToolbarLayout, 0);
|
||
9 years ago
|
}
|
||
9 years ago
|
if (mPreferences.getHideStatusBarEnabled()) {
|
||
9 years ago
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||
|
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||
|
} else {
|
||
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
switch (mPreferences.getSearchChoice()) {
|
||
10 years ago
|
case 0:
|
||
9 years ago
|
mSearchText = mPreferences.getSearchUrl();
|
||
10 years ago
|
if (!mSearchText.startsWith(Constants.HTTP)
|
||
|
&& !mSearchText.startsWith(Constants.HTTPS)) {
|
||
|
mSearchText = Constants.GOOGLE_SEARCH;
|
||
|
}
|
||
|
break;
|
||
|
case 1:
|
||
10 years ago
|
mSearchText = Constants.GOOGLE_SEARCH;
|
||
10 years ago
|
break;
|
||
|
case 2:
|
||
9 years ago
|
mSearchText = Constants.ASK_SEARCH;
|
||
10 years ago
|
break;
|
||
|
case 3:
|
||
|
mSearchText = Constants.BING_SEARCH;
|
||
|
break;
|
||
|
case 4:
|
||
|
mSearchText = Constants.YAHOO_SEARCH;
|
||
|
break;
|
||
|
case 5:
|
||
|
mSearchText = Constants.STARTPAGE_SEARCH;
|
||
|
break;
|
||
|
case 6:
|
||
|
mSearchText = Constants.STARTPAGE_MOBILE_SEARCH;
|
||
|
break;
|
||
|
case 7:
|
||
|
mSearchText = Constants.DUCK_SEARCH;
|
||
|
break;
|
||
|
case 8:
|
||
|
mSearchText = Constants.DUCK_LITE_SEARCH;
|
||
|
break;
|
||
|
case 9:
|
||
|
mSearchText = Constants.BAIDU_SEARCH;
|
||
|
break;
|
||
|
case 10:
|
||
|
mSearchText = Constants.YANDEX_SEARCH;
|
||
|
break;
|
||
10 years ago
|
}
|
||
|
|
||
|
updateCookiePreference();
|
||
9 years ago
|
if (mPreferences.getUseProxy()) {
|
||
10 years ago
|
initializeTor();
|
||
|
} else {
|
||
|
try {
|
||
9 years ago
|
WebkitProxy.resetProxy(mActivity.getPackageName() + ".BrowserApp",
|
||
|
getApplicationContext());
|
||
10 years ago
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* Override this if class overrides BrowserActivity
|
||
|
*/
|
||
|
public void updateCookiePreference() {
|
||
|
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||
|
if (keyCode == KeyEvent.KEYCODE_ENTER) {
|
||
|
if (mSearch.hasFocus()) {
|
||
|
searchTheWeb(mSearch.getText().toString());
|
||
|
}
|
||
9 years ago
|
} else if ((keyCode == KeyEvent.KEYCODE_MENU) && (Build.VERSION.SDK_INT <= 16)
|
||
|
&& (Build.MANUFACTURER.compareTo("LGE") == 0)) {
|
||
|
// Workaround for stupid LG devices that crash
|
||
|
return true;
|
||
10 years ago
|
}
|
||
|
return super.onKeyDown(keyCode, event);
|
||
|
}
|
||
|
|
||
9 years ago
|
@Override
|
||
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||
|
if ((keyCode == KeyEvent.KEYCODE_MENU) && (Build.VERSION.SDK_INT <= 16)
|
||
|
&& (Build.MANUFACTURER.compareTo("LGE") == 0)) {
|
||
|
// Workaround for stupid LG devices that crash
|
||
|
openOptionsMenu();
|
||
|
return true;
|
||
|
}
|
||
|
return super.onKeyUp(keyCode, event);
|
||
|
}
|
||
|
|
||
10 years ago
|
@Override
|
||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||
|
return super.onCreateOptionsMenu(menu);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||
|
// Handle action buttons
|
||
|
switch (item.getItemId()) {
|
||
10 years ago
|
case android.R.id.home:
|
||
|
if (mDrawerLayout.isDrawerOpen(mDrawerRight)) {
|
||
|
mDrawerLayout.closeDrawer(mDrawerRight);
|
||
10 years ago
|
}
|
||
10 years ago
|
return true;
|
||
|
case R.id.action_back:
|
||
|
if (mCurrentView != null) {
|
||
|
if (mCurrentView.canGoBack()) {
|
||
|
mCurrentView.goBack();
|
||
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
return true;
|
||
|
case R.id.action_forward:
|
||
|
if (mCurrentView != null) {
|
||
|
if (mCurrentView.canGoForward()) {
|
||
|
mCurrentView.goForward();
|
||
|
}
|
||
|
}
|
||
|
return true;
|
||
|
case R.id.action_new_tab:
|
||
|
newTab(null, true);
|
||
|
return true;
|
||
|
case R.id.action_incognito:
|
||
|
startActivity(new Intent(this, IncognitoActivity.class));
|
||
|
return true;
|
||
|
case R.id.action_share:
|
||
10 years ago
|
if (!mCurrentView.getUrl().startsWith(Constants.FILE)) {
|
||
10 years ago
|
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
|
||
|
shareIntent.setType("text/plain");
|
||
|
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
|
||
|
mCurrentView.getTitle());
|
||
|
String shareMessage = mCurrentView.getUrl();
|
||
|
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareMessage);
|
||
|
startActivity(Intent.createChooser(shareIntent,
|
||
|
getResources().getString(R.string.dialog_title_share)));
|
||
10 years ago
|
}
|
||
10 years ago
|
return true;
|
||
|
case R.id.action_bookmarks:
|
||
|
openBookmarks();
|
||
|
return true;
|
||
|
case R.id.action_copy:
|
||
|
if (mCurrentView != null) {
|
||
|
if (!mCurrentView.getUrl().startsWith(Constants.FILE)) {
|
||
|
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||
9 years ago
|
ClipData clip = ClipData.newPlainText("label", mCurrentView.getUrl());
|
||
10 years ago
|
clipboard.setPrimaryClip(clip);
|
||
9 years ago
|
Utils.showToast(mActivity,
|
||
|
mActivity.getResources().getString(R.string.message_link_copied));
|
||
10 years ago
|
}
|
||
|
}
|
||
|
return true;
|
||
|
case R.id.action_settings:
|
||
|
startActivity(new Intent(this, SettingsActivity.class));
|
||
|
return true;
|
||
|
case R.id.action_history:
|
||
|
openHistory();
|
||
|
return true;
|
||
|
case R.id.action_add_bookmark:
|
||
|
if (!mCurrentView.getUrl().startsWith(Constants.FILE)) {
|
||
10 years ago
|
HistoryItem bookmark = new HistoryItem(mCurrentView.getUrl(),
|
||
|
mCurrentView.getTitle());
|
||
|
if (mBookmarkManager.addBookmark(bookmark)) {
|
||
|
mBookmarkList.add(bookmark);
|
||
|
Collections.sort(mBookmarkList, new SortIgnoreCase());
|
||
|
notifyBookmarkDataSetChanged();
|
||
|
mSearchAdapter.refreshBookmarks();
|
||
|
}
|
||
10 years ago
|
}
|
||
|
return true;
|
||
|
case R.id.action_find:
|
||
|
findInPage();
|
||
|
return true;
|
||
9 years ago
|
case R.id.action_reading_mode:
|
||
|
Intent read = new Intent(this, ReadingActivity.class);
|
||
|
read.putExtra(Constants.LOAD_READING_URL, mCurrentView.getUrl());
|
||
|
startActivity(read);
|
||
|
return true;
|
||
10 years ago
|
default:
|
||
|
return super.onOptionsItemSelected(item);
|
||
10 years ago
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* refreshes the underlying list of the Bookmark adapter since the bookmark
|
||
|
* adapter doesn't always change when notifyDataChanged gets called.
|
||
|
*/
|
||
|
private void notifyBookmarkDataSetChanged() {
|
||
|
mBookmarkAdapter.clear();
|
||
|
mBookmarkAdapter.addAll(mBookmarkList);
|
||
|
mBookmarkAdapter.notifyDataSetChanged();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* method that shows a dialog asking what string the user wishes to search
|
||
|
* for. It highlights the text entered.
|
||
|
*/
|
||
|
private void findInPage() {
|
||
|
final AlertDialog.Builder finder = new AlertDialog.Builder(mActivity);
|
||
|
finder.setTitle(getResources().getString(R.string.action_find));
|
||
|
final EditText getHome = new EditText(this);
|
||
|
getHome.setHint(getResources().getString(R.string.search_hint));
|
||
|
finder.setView(getHome);
|
||
|
finder.setPositiveButton(getResources().getString(R.string.search_hint),
|
||
|
new DialogInterface.OnClickListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int which) {
|
||
10 years ago
|
String query = getHome.getText().toString();
|
||
|
if (query.length() > 0)
|
||
|
showSearchInterfaceBar(query);
|
||
10 years ago
|
}
|
||
|
});
|
||
|
finder.show();
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
private void showSearchInterfaceBar(String text) {
|
||
10 years ago
|
if (mCurrentView != null) {
|
||
|
mCurrentView.find(text);
|
||
|
}
|
||
9 years ago
|
mSearchBar = (RelativeLayout) findViewById(R.id.search_bar);
|
||
|
mSearchBar.setVisibility(View.VISIBLE);
|
||
10 years ago
|
|
||
|
TextView tw = (TextView) findViewById(R.id.search_query);
|
||
|
tw.setText("'" + text + "'");
|
||
|
|
||
|
ImageButton up = (ImageButton) findViewById(R.id.button_next);
|
||
9 years ago
|
up.setOnClickListener(this);
|
||
|
|
||
10 years ago
|
ImageButton down = (ImageButton) findViewById(R.id.button_back);
|
||
9 years ago
|
down.setOnClickListener(this);
|
||
10 years ago
|
|
||
|
ImageButton quit = (ImageButton) findViewById(R.id.button_quit);
|
||
9 years ago
|
quit.setOnClickListener(this);
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
9 years ago
|
private void showCloseDialog(final int position) {
|
||
9 years ago
|
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
|
||
|
ArrayAdapter<String> adapter = new ArrayAdapter<>(mActivity,
|
||
9 years ago
|
android.R.layout.simple_dropdown_item_1line);
|
||
9 years ago
|
adapter.add(mActivity.getString(R.string.close_tab));
|
||
|
adapter.add(mActivity.getString(R.string.close_all_tabs));
|
||
9 years ago
|
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int which) {
|
||
|
switch (which) {
|
||
|
case 0:
|
||
|
deleteTab(position);
|
||
|
break;
|
||
|
case 1:
|
||
|
closeBrowser();
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
builder.show();
|
||
|
}
|
||
|
|
||
10 years ago
|
/**
|
||
|
* The click listener for ListView in the navigation drawer
|
||
|
*/
|
||
|
private class DrawerItemClickListener implements ListView.OnItemClickListener {
|
||
|
|
||
|
@Override
|
||
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||
|
mIsNewIntent = false;
|
||
9 years ago
|
showTab(mWebViews.get(position));
|
||
10 years ago
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* long click listener for Navigation Drawer
|
||
|
*/
|
||
|
private class DrawerItemLongClickListener implements ListView.OnItemLongClickListener {
|
||
|
|
||
|
@Override
|
||
9 years ago
|
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) {
|
||
9 years ago
|
showCloseDialog(position);
|
||
9 years ago
|
return true;
|
||
10 years ago
|
}
|
||
|
}
|
||
|
|
||
|
private class BookmarkItemClickListener implements ListView.OnItemClickListener {
|
||
|
|
||
|
@Override
|
||
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||
|
if (mCurrentView != null) {
|
||
|
mCurrentView.loadUrl(mBookmarkList.get(position).getUrl());
|
||
|
}
|
||
|
// keep any jank from happening when the drawer is closed after the
|
||
|
// URL starts to load
|
||
|
final Handler handler = new Handler();
|
||
|
handler.postDelayed(new Runnable() {
|
||
|
@Override
|
||
|
public void run() {
|
||
|
mDrawerLayout.closeDrawer(mDrawerRight);
|
||
|
}
|
||
|
}, 150);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private class BookmarkItemLongClickListener implements ListView.OnItemLongClickListener {
|
||
|
|
||
|
@Override
|
||
|
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) {
|
||
|
|
||
|
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
|
||
9 years ago
|
builder.setTitle(mActivity.getResources().getString(R.string.action_bookmarks));
|
||
10 years ago
|
builder.setMessage(getResources().getString(R.string.dialog_bookmark))
|
||
|
.setCancelable(true)
|
||
|
.setPositiveButton(getResources().getString(R.string.action_new_tab),
|
||
|
new DialogInterface.OnClickListener() {
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int id) {
|
||
|
newTab(mBookmarkList.get(position).getUrl(), false);
|
||
|
mDrawerLayout.closeDrawers();
|
||
|
}
|
||
|
})
|
||
|
.setNegativeButton(getResources().getString(R.string.action_delete),
|
||
|
new DialogInterface.OnClickListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int which) {
|
||
10 years ago
|
if (mBookmarkManager.deleteBookmark(mBookmarkList.get(position)
|
||
|
.getUrl())) {
|
||
|
mBookmarkList.remove(position);
|
||
|
notifyBookmarkDataSetChanged();
|
||
|
mSearchAdapter.refreshBookmarks();
|
||
|
openBookmarks();
|
||
|
}
|
||
10 years ago
|
}
|
||
|
})
|
||
|
.setNeutralButton(getResources().getString(R.string.action_edit),
|
||
|
new DialogInterface.OnClickListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int which) {
|
||
|
editBookmark(position);
|
||
|
}
|
||
|
});
|
||
|
AlertDialog alert = builder.create();
|
||
|
alert.show();
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Takes in the id of which bookmark was selected and shows a dialog that
|
||
|
* allows the user to rename and change the url of the bookmark
|
||
|
*
|
||
|
* @param id
|
||
|
* which id in the list was chosen
|
||
|
*/
|
||
|
public synchronized void editBookmark(final int id) {
|
||
|
final AlertDialog.Builder homePicker = new AlertDialog.Builder(mActivity);
|
||
|
homePicker.setTitle(getResources().getString(R.string.title_edit_bookmark));
|
||
9 years ago
|
final EditText getTitle = new EditText(mActivity);
|
||
10 years ago
|
getTitle.setHint(getResources().getString(R.string.hint_title));
|
||
|
getTitle.setText(mBookmarkList.get(id).getTitle());
|
||
|
getTitle.setSingleLine();
|
||
9 years ago
|
final EditText getUrl = new EditText(mActivity);
|
||
10 years ago
|
getUrl.setHint(getResources().getString(R.string.hint_url));
|
||
|
getUrl.setText(mBookmarkList.get(id).getUrl());
|
||
|
getUrl.setSingleLine();
|
||
9 years ago
|
LinearLayout layout = new LinearLayout(mActivity);
|
||
10 years ago
|
layout.setOrientation(LinearLayout.VERTICAL);
|
||
|
layout.addView(getTitle);
|
||
|
layout.addView(getUrl);
|
||
|
homePicker.setView(layout);
|
||
|
homePicker.setPositiveButton(getResources().getString(R.string.action_ok),
|
||
|
new DialogInterface.OnClickListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int which) {
|
||
|
mBookmarkList.get(id).setTitle(getTitle.getText().toString());
|
||
|
mBookmarkList.get(id).setUrl(getUrl.getText().toString());
|
||
10 years ago
|
mBookmarkManager.overwriteBookmarks(mBookmarkList);
|
||
10 years ago
|
Collections.sort(mBookmarkList, new SortIgnoreCase());
|
||
|
notifyBookmarkDataSetChanged();
|
||
|
if (mCurrentView != null) {
|
||
|
if (mCurrentView.getUrl().startsWith(Constants.FILE)
|
||
|
&& mCurrentView.getUrl().endsWith("bookmarks.html")) {
|
||
|
openBookmarkPage(mCurrentView.getWebView());
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
homePicker.show();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* displays the WebView contained in the LightningView Also handles the
|
||
|
* removal of previous views
|
||
|
*
|
||
|
* @param view
|
||
|
* the LightningView to show
|
||
|
*/
|
||
|
private synchronized void showTab(LightningView view) {
|
||
9 years ago
|
// Set the background color so the color mode color doesn't show through
|
||
|
mBrowserFrame.setBackgroundColor(mBackgroundColor);
|
||
10 years ago
|
if (view == null) {
|
||
|
return;
|
||
|
}
|
||
10 years ago
|
mBrowserFrame.removeAllViews();
|
||
10 years ago
|
if (mCurrentView != null) {
|
||
|
mCurrentView.setForegroundTab(false);
|
||
|
mCurrentView.onPause();
|
||
|
}
|
||
|
mCurrentView = view;
|
||
|
mCurrentView.setForegroundTab(true);
|
||
10 years ago
|
if (mCurrentView.getWebView() != null) {
|
||
9 years ago
|
updateUrl(mCurrentView.getUrl(), true);
|
||
10 years ago
|
updateProgress(mCurrentView.getProgress());
|
||
10 years ago
|
} else {
|
||
9 years ago
|
updateUrl("", true);
|
||
10 years ago
|
updateProgress(0);
|
||
|
}
|
||
|
|
||
9 years ago
|
mBrowserFrame.addView(mCurrentView.getWebView(), MATCH_PARENT);
|
||
9 years ago
|
// Remove browser frame background to reduce overdraw
|
||
|
mBrowserFrame.setBackgroundColor(0);
|
||
9 years ago
|
mCurrentView.requestFocus();
|
||
10 years ago
|
mCurrentView.onResume();
|
||
|
|
||
10 years ago
|
// Use a delayed handler to make the transition smooth
|
||
|
// otherwise it will get caught up with the showTab code
|
||
|
// and cause a janky motion
|
||
|
final Handler handler = new Handler();
|
||
|
handler.postDelayed(new Runnable() {
|
||
|
@Override
|
||
|
public void run() {
|
||
|
mDrawerLayout.closeDrawers();
|
||
|
}
|
||
|
}, 150);
|
||
10 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* creates a new tab with the passed in URL if it isn't null
|
||
|
*/
|
||
|
@Override
|
||
|
protected void onNewIntent(Intent intent) {
|
||
|
super.onNewIntent(intent);
|
||
|
}
|
||
|
|
||
|
public void handleNewIntent(Intent intent) {
|
||
|
|
||
|
String url = null;
|
||
|
if (intent != null) {
|
||
|
url = intent.getDataString();
|
||
|
}
|
||
|
int num = 0;
|
||
|
if (intent != null && intent.getExtras() != null) {
|
||
|
num = intent.getExtras().getInt(getPackageName() + ".Origin");
|
||
|
}
|
||
|
if (num == 1) {
|
||
|
mCurrentView.loadUrl(url);
|
||
|
} else if (url != null) {
|
||
|
if (url.startsWith(Constants.FILE)) {
|
||
|
Utils.showToast(this, getResources().getString(R.string.message_blocked_local));
|
||
|
url = null;
|
||
|
}
|
||
|
newTab(url, true);
|
||
|
mIsNewIntent = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void closeEmptyTab() {
|
||
|
if (mCurrentView != null && mCurrentView.getWebView().copyBackForwardList().getSize() == 0) {
|
||
|
closeCurrentTab();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void closeCurrentTab() {
|
||
|
// don't delete the tab because the browser will close and mess stuff up
|
||
|
}
|
||
|
|
||
9 years ago
|
@SuppressWarnings("deprecation")
|
||
10 years ago
|
@Override
|
||
9 years ago
|
public void onTrimMemory(int level) {
|
||
9 years ago
|
if (level > TRIM_MEMORY_MODERATE && Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||
9 years ago
|
Log.d(Constants.TAG, "Low Memory, Free Memory");
|
||
|
for (LightningView view : mWebViews) {
|
||
|
view.getWebView().freeMemory();
|
||
|
}
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
protected synchronized boolean newTab(String url, boolean show) {
|
||
9 years ago
|
// Limit number of tabs for limited version of app
|
||
|
if (!Constants.FULL_VERSION && mWebViews.size() >= 10) {
|
||
|
Utils.showToast(this, this.getString(R.string.max_tabs));
|
||
|
return false;
|
||
|
}
|
||
10 years ago
|
mIsNewIntent = false;
|
||
9 years ago
|
LightningView startingTab = new LightningView(mActivity, url, mDarkTheme);
|
||
10 years ago
|
if (mIdGenerator == 0) {
|
||
|
startingTab.resumeTimers();
|
||
|
}
|
||
|
mIdGenerator++;
|
||
|
mWebViews.add(startingTab);
|
||
|
|
||
|
mTitleAdapter.notifyDataSetChanged();
|
||
|
if (show) {
|
||
10 years ago
|
mDrawerListLeft.setItemChecked(mWebViews.size() - 1, true);
|
||
10 years ago
|
showTab(startingTab);
|
||
|
}
|
||
9 years ago
|
return true;
|
||
10 years ago
|
}
|
||
|
|
||
|
private synchronized void deleteTab(int position) {
|
||
|
if (position >= mWebViews.size()) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
10 years ago
|
int current = mDrawerListLeft.getCheckedItemPosition();
|
||
10 years ago
|
LightningView reference = mWebViews.get(position);
|
||
|
if (reference == null) {
|
||
|
return;
|
||
|
}
|
||
9 years ago
|
if (reference.getUrl() != null && !reference.getUrl().startsWith(Constants.FILE)
|
||
|
&& !isIncognito()) {
|
||
9 years ago
|
mPreferences.setSavedUrl(reference.getUrl());
|
||
10 years ago
|
}
|
||
10 years ago
|
boolean isShown = reference.isShown();
|
||
9 years ago
|
if (isShown) {
|
||
|
mBrowserFrame.setBackgroundColor(mBackgroundColor);
|
||
|
}
|
||
10 years ago
|
if (current > position) {
|
||
|
mWebViews.remove(position);
|
||
10 years ago
|
mDrawerListLeft.setItemChecked(current - 1, true);
|
||
10 years ago
|
reference.onDestroy();
|
||
|
} else if (mWebViews.size() > position + 1) {
|
||
10 years ago
|
if (current == position) {
|
||
|
showTab(mWebViews.get(position + 1));
|
||
|
mWebViews.remove(position);
|
||
10 years ago
|
mDrawerListLeft.setItemChecked(position, true);
|
||
10 years ago
|
} else {
|
||
|
mWebViews.remove(position);
|
||
|
}
|
||
|
|
||
10 years ago
|
reference.onDestroy();
|
||
|
} else if (mWebViews.size() > 1) {
|
||
10 years ago
|
if (current == position) {
|
||
|
showTab(mWebViews.get(position - 1));
|
||
|
mWebViews.remove(position);
|
||
10 years ago
|
mDrawerListLeft.setItemChecked(position - 1, true);
|
||
10 years ago
|
} else {
|
||
|
mWebViews.remove(position);
|
||
|
}
|
||
|
|
||
10 years ago
|
reference.onDestroy();
|
||
|
} else {
|
||
10 years ago
|
if (mCurrentView.getUrl() == null || mCurrentView.getUrl().startsWith(Constants.FILE)
|
||
10 years ago
|
|| mCurrentView.getUrl().equals(mHomepage)) {
|
||
|
closeActivity();
|
||
|
} else {
|
||
|
mWebViews.remove(position);
|
||
9 years ago
|
if (mPreferences.getClearCacheExit() && mCurrentView != null && !isIncognito()) {
|
||
10 years ago
|
mCurrentView.clearCache(true);
|
||
9 years ago
|
Log.d(Constants.TAG, "Cache Cleared");
|
||
10 years ago
|
|
||
|
}
|
||
9 years ago
|
if (mPreferences.getClearHistoryExitEnabled() && !isIncognito()) {
|
||
10 years ago
|
clearHistory();
|
||
9 years ago
|
Log.d(Constants.TAG, "History Cleared");
|
||
10 years ago
|
|
||
|
}
|
||
9 years ago
|
if (mPreferences.getClearCookiesExitEnabled() && !isIncognito()) {
|
||
10 years ago
|
clearCookies();
|
||
9 years ago
|
Log.d(Constants.TAG, "Cookies Cleared");
|
||
10 years ago
|
|
||
|
}
|
||
9 years ago
|
reference.pauseTimers();
|
||
|
reference.onDestroy();
|
||
10 years ago
|
mCurrentView = null;
|
||
|
mTitleAdapter.notifyDataSetChanged();
|
||
|
finish();
|
||
|
|
||
|
}
|
||
|
}
|
||
|
mTitleAdapter.notifyDataSetChanged();
|
||
|
|
||
|
if (mIsNewIntent && isShown) {
|
||
|
mIsNewIntent = false;
|
||
|
closeActivity();
|
||
|
}
|
||
|
|
||
9 years ago
|
Log.d(Constants.TAG, "deleted tab");
|
||
10 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
|
||
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||
9 years ago
|
showCloseDialog(mDrawerListLeft.getCheckedItemPosition());
|
||
10 years ago
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
9 years ago
|
private void closeBrowser() {
|
||
9 years ago
|
mBrowserFrame.setBackgroundColor(mBackgroundColor);
|
||
9 years ago
|
if (mPreferences.getClearCacheExit() && mCurrentView != null && !isIncognito()) {
|
||
9 years ago
|
mCurrentView.clearCache(true);
|
||
9 years ago
|
Log.d(Constants.TAG, "Cache Cleared");
|
||
9 years ago
|
|
||
|
}
|
||
9 years ago
|
if (mPreferences.getClearHistoryExitEnabled() && !isIncognito()) {
|
||
9 years ago
|
clearHistory();
|
||
9 years ago
|
Log.d(Constants.TAG, "History Cleared");
|
||
9 years ago
|
|
||
|
}
|
||
9 years ago
|
if (mPreferences.getClearCookiesExitEnabled() && !isIncognito()) {
|
||
9 years ago
|
clearCookies();
|
||
9 years ago
|
Log.d(Constants.TAG, "Cookies Cleared");
|
||
9 years ago
|
|
||
|
}
|
||
|
mCurrentView = null;
|
||
|
for (int n = 0; n < mWebViews.size(); n++) {
|
||
|
if (mWebViews.get(n) != null) {
|
||
|
mWebViews.get(n).onDestroy();
|
||
|
}
|
||
|
}
|
||
|
mWebViews.clear();
|
||
|
mTitleAdapter.notifyDataSetChanged();
|
||
|
finish();
|
||
|
}
|
||
|
|
||
10 years ago
|
@SuppressWarnings("deprecation")
|
||
|
public void clearHistory() {
|
||
9 years ago
|
this.deleteDatabase(HistoryDatabase.DATABASE_NAME);
|
||
10 years ago
|
WebViewDatabase m = WebViewDatabase.getInstance(this);
|
||
|
m.clearFormData();
|
||
|
m.clearHttpAuthUsernamePassword();
|
||
|
if (API < 18) {
|
||
|
m.clearUsernamePassword();
|
||
|
WebIconDatabase.getInstance().removeAllIcons();
|
||
|
}
|
||
|
if (mSystemBrowser) {
|
||
|
try {
|
||
|
Browser.clearHistory(getContentResolver());
|
||
|
} catch (NullPointerException ignored) {
|
||
|
}
|
||
|
}
|
||
|
Utils.trimCache(this);
|
||
|
}
|
||
|
|
||
9 years ago
|
@SuppressLint("NewApi")
|
||
9 years ago
|
@SuppressWarnings("deprecation")
|
||
10 years ago
|
public void clearCookies() {
|
||
9 years ago
|
// TODO Break out web storage deletion into its own option/action
|
||
|
// TODO clear web storage for all sites that are visited in Incognito mode
|
||
|
WebStorage storage = WebStorage.getInstance();
|
||
|
storage.deleteAllData();
|
||
10 years ago
|
CookieManager c = CookieManager.getInstance();
|
||
9 years ago
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||
|
c.removeAllCookies(null);
|
||
|
} else {
|
||
|
CookieSyncManager.createInstance(this);
|
||
|
c.removeAllCookie();
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onBackPressed() {
|
||
10 years ago
|
if (mDrawerLayout.isDrawerOpen(mDrawerLeft)) {
|
||
|
mDrawerLayout.closeDrawer(mDrawerLeft);
|
||
10 years ago
|
} else if (mDrawerLayout.isDrawerOpen(mDrawerRight)) {
|
||
|
mDrawerLayout.closeDrawer(mDrawerRight);
|
||
|
} else {
|
||
|
if (mCurrentView != null) {
|
||
9 years ago
|
Log.d(Constants.TAG, "onBackPressed");
|
||
9 years ago
|
if (mSearch.hasFocus()) {
|
||
9 years ago
|
mCurrentView.requestFocus();
|
||
|
} else if (mCurrentView.canGoBack()) {
|
||
10 years ago
|
if (!mCurrentView.isShown()) {
|
||
|
onHideCustomView();
|
||
|
} else {
|
||
|
mCurrentView.goBack();
|
||
|
}
|
||
|
} else {
|
||
10 years ago
|
deleteTab(mDrawerListLeft.getCheckedItemPosition());
|
||
10 years ago
|
}
|
||
|
} else {
|
||
9 years ago
|
Log.e(Constants.TAG, "This shouldn't happen ever");
|
||
10 years ago
|
super.onBackPressed();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected void onPause() {
|
||
|
super.onPause();
|
||
9 years ago
|
Log.d(Constants.TAG, "onPause");
|
||
10 years ago
|
if (mCurrentView != null) {
|
||
|
mCurrentView.pauseTimers();
|
||
|
mCurrentView.onPause();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void saveOpenTabs() {
|
||
9 years ago
|
if (mPreferences.getRestoreLostTabsEnabled()) {
|
||
10 years ago
|
String s = "";
|
||
|
for (int n = 0; n < mWebViews.size(); n++) {
|
||
|
if (mWebViews.get(n).getUrl() != null) {
|
||
|
s = s + mWebViews.get(n).getUrl() + "|$|SEPARATOR|$|";
|
||
|
}
|
||
|
}
|
||
9 years ago
|
mPreferences.setMemoryUrl(s);
|
||
10 years ago
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected void onDestroy() {
|
||
9 years ago
|
Log.d(Constants.TAG, "onDestroy");
|
||
9 years ago
|
if (mHistoryDatabase != null) {
|
||
|
mHistoryDatabase.close();
|
||
10 years ago
|
}
|
||
|
super.onDestroy();
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected void onResume() {
|
||
|
super.onResume();
|
||
9 years ago
|
Log.d(Constants.TAG, "onResume");
|
||
10 years ago
|
if (mSearchAdapter != null) {
|
||
|
mSearchAdapter.refreshPreferences();
|
||
|
mSearchAdapter.refreshBookmarks();
|
||
|
}
|
||
|
if (mCurrentView != null) {
|
||
|
mCurrentView.resumeTimers();
|
||
|
mCurrentView.onResume();
|
||
|
|
||
9 years ago
|
mHistoryDatabase = HistoryDatabase.getInstance(getApplicationContext());
|
||
10 years ago
|
mBookmarkList = mBookmarkManager.getBookmarks(true);
|
||
10 years ago
|
notifyBookmarkDataSetChanged();
|
||
|
}
|
||
|
initializePreferences();
|
||
|
if (mWebViews != null) {
|
||
|
for (int n = 0; n < mWebViews.size(); n++) {
|
||
|
if (mWebViews.get(n) != null) {
|
||
|
mWebViews.get(n).initializePreferences(this);
|
||
|
} else {
|
||
|
mWebViews.remove(n);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
supportInvalidateOptionsMenu();
|
||
10 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* searches the web for the query fixing any and all problems with the input
|
||
|
* checks if it is a search, url, etc.
|
||
|
*/
|
||
|
void searchTheWeb(String query) {
|
||
|
if (query.equals("")) {
|
||
|
return;
|
||
|
}
|
||
|
String SEARCH = mSearchText;
|
||
|
query = query.trim();
|
||
|
mCurrentView.stopLoading();
|
||
|
|
||
|
if (query.startsWith("www.")) {
|
||
|
query = Constants.HTTP + query;
|
||
|
} else if (query.startsWith("ftp.")) {
|
||
|
query = "ftp://" + query;
|
||
|
}
|
||
|
|
||
|
boolean containsPeriod = query.contains(".");
|
||
|
boolean isIPAddress = (TextUtils.isDigitsOnly(query.replace(".", ""))
|
||
|
&& (query.replace(".", "").length() >= 4) && query.contains("."));
|
||
|
boolean aboutScheme = query.contains("about:");
|
||
|
boolean validURL = (query.startsWith("ftp://") || query.startsWith(Constants.HTTP)
|
||
|
|| query.startsWith(Constants.FILE) || query.startsWith(Constants.HTTPS))
|
||
|
|| isIPAddress;
|
||
|
boolean isSearch = ((query.contains(" ") || !containsPeriod) && !aboutScheme);
|
||
|
|
||
|
if (isIPAddress
|
||
|
&& (!query.startsWith(Constants.HTTP) || !query.startsWith(Constants.HTTPS))) {
|
||
|
query = Constants.HTTP + query;
|
||
|
}
|
||
|
|
||
|
if (isSearch) {
|
||
|
try {
|
||
|
query = URLEncoder.encode(query, "UTF-8");
|
||
|
} catch (UnsupportedEncodingException e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
mCurrentView.loadUrl(SEARCH + query);
|
||
|
} else if (!validURL) {
|
||
|
mCurrentView.loadUrl(Constants.HTTP + query);
|
||
|
} else {
|
||
|
mCurrentView.loadUrl(query);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public class LightningViewAdapter extends ArrayAdapter<LightningView> {
|
||
|
|
||
|
Context context;
|
||
9 years ago
|
ColorMatrix colorMatrix;
|
||
|
ColorMatrixColorFilter filter;
|
||
|
Paint paint;
|
||
10 years ago
|
int layoutResourceId;
|
||
|
List<LightningView> data = null;
|
||
9 years ago
|
CloseTabListener mExitListener;
|
||
10 years ago
|
|
||
|
public LightningViewAdapter(Context context, int layoutResourceId, List<LightningView> data) {
|
||
|
super(context, layoutResourceId, data);
|
||
|
this.layoutResourceId = layoutResourceId;
|
||
|
this.context = context;
|
||
|
this.data = data;
|
||
9 years ago
|
this.mExitListener = new CloseTabListener();
|
||
10 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public View getView(final int position, View convertView, ViewGroup parent) {
|
||
|
View row = convertView;
|
||
|
LightningViewHolder holder = null;
|
||
|
if (row == null) {
|
||
|
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
|
||
|
row = inflater.inflate(layoutResourceId, parent, false);
|
||
|
|
||
|
holder = new LightningViewHolder();
|
||
9 years ago
|
holder.txtTitle = (TextView) row.findViewById(R.id.textTab);
|
||
|
holder.favicon = (ImageView) row.findViewById(R.id.faviconTab);
|
||
|
holder.exit = (ImageView) row.findViewById(R.id.deleteButton);
|
||
10 years ago
|
holder.exit.setTag(position);
|
||
|
row.setTag(holder);
|
||
|
} else {
|
||
|
holder = (LightningViewHolder) row.getTag();
|
||
|
}
|
||
|
|
||
9 years ago
|
holder.exit.setTag(position);
|
||
|
holder.exit.setOnClickListener(mExitListener);
|
||
9 years ago
|
|
||
9 years ago
|
ViewCompat.jumpDrawablesToCurrentState(holder.exit);
|
||
10 years ago
|
|
||
|
LightningView web = data.get(position);
|
||
|
holder.txtTitle.setText(web.getTitle());
|
||
|
if (web.isForegroundTab()) {
|
||
|
holder.txtTitle.setTextAppearance(context, R.style.boldText);
|
||
|
} else {
|
||
|
holder.txtTitle.setTextAppearance(context, R.style.normalText);
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
Bitmap favicon = web.getFavicon();
|
||
10 years ago
|
if (web.isForegroundTab()) {
|
||
|
|
||
|
holder.favicon.setImageBitmap(favicon);
|
||
9 years ago
|
if (!isIncognito() && mColorMode)
|
||
9 years ago
|
changeToolbarBackground(favicon);
|
||
10 years ago
|
} else {
|
||
|
Bitmap grayscaleBitmap = Bitmap.createBitmap(favicon.getWidth(),
|
||
|
favicon.getHeight(), Bitmap.Config.ARGB_8888);
|
||
|
|
||
|
Canvas c = new Canvas(grayscaleBitmap);
|
||
9 years ago
|
if (colorMatrix == null || filter == null || paint == null) {
|
||
|
paint = new Paint();
|
||
|
colorMatrix = new ColorMatrix();
|
||
|
colorMatrix.setSaturation(0);
|
||
|
filter = new ColorMatrixColorFilter(colorMatrix);
|
||
|
paint.setColorFilter(filter);
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
c.drawBitmap(favicon, 0, 0, paint);
|
||
10 years ago
|
holder.favicon.setImageBitmap(grayscaleBitmap);
|
||
|
}
|
||
10 years ago
|
return row;
|
||
|
}
|
||
|
|
||
|
class LightningViewHolder {
|
||
|
TextView txtTitle;
|
||
|
ImageView favicon;
|
||
|
ImageView exit;
|
||
|
}
|
||
10 years ago
|
}
|
||
9 years ago
|
|
||
|
private class CloseTabListener implements OnClickListener {
|
||
9 years ago
|
|
||
|
@Override
|
||
|
public void onClick(View v) {
|
||
|
deleteTab((int) v.getTag());
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
}
|
||
10 years ago
|
|
||
9 years ago
|
private void changeToolbarBackground(Bitmap favicon) {
|
||
9 years ago
|
Palette.from(favicon).generate(new Palette.PaletteAsyncListener() {
|
||
|
@Override
|
||
|
public void onGenerated(Palette palette) {
|
||
|
|
||
|
// OR with opaque black to remove transparency glitches
|
||
|
int color = 0xff000000 | palette.getVibrantColor(mActivity.getResources()
|
||
|
.getColor(R.color.primary_color));
|
||
|
|
||
|
int finalColor; // Lighten up the dark color if it is
|
||
|
// too dark
|
||
|
if (isColorTooDark(color)) {
|
||
|
finalColor = mixTwoColors(
|
||
|
mActivity.getResources().getColor(R.color.primary_color),
|
||
|
color, 0.25f);
|
||
|
} else {
|
||
|
finalColor = color;
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
ValueAnimator anim = ValueAnimator.ofObject(new ArgbEvaluator(),
|
||
|
mBackground.getColor(), finalColor);
|
||
9 years ago
|
|
||
9 years ago
|
anim.addUpdateListener(new AnimatorUpdateListener() {
|
||
9 years ago
|
|
||
9 years ago
|
@Override
|
||
|
public void onAnimationUpdate(ValueAnimator animation) {
|
||
|
int color = (Integer) animation.getAnimatedValue();
|
||
|
mBackground.setColor(color);
|
||
|
getWindow().setBackgroundDrawable(mBackground);
|
||
|
mToolbarLayout.setBackgroundColor(color);
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
});
|
||
9 years ago
|
|
||
9 years ago
|
anim.setDuration(300);
|
||
|
anim.start();
|
||
9 years ago
|
|
||
9 years ago
|
}
|
||
|
});
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
public static boolean isColorTooDark(int color) {
|
||
|
final byte RED_CHANNEL = 16;
|
||
|
final byte GREEN_CHANNEL = 8;
|
||
|
final byte BLUE_CHANNEL = 0;
|
||
|
|
||
|
int r = ((int) ((float) (color >> RED_CHANNEL & 0xff) * 0.3f)) & 0xff;
|
||
|
int g = ((int) ((float) (color >> GREEN_CHANNEL & 0xff) * 0.59)) & 0xff;
|
||
|
int b = ((int) ((float) (color >> BLUE_CHANNEL & 0xff) * 0.11)) & 0xff;
|
||
|
int gr = (r + g + b) & 0xff;
|
||
|
int gray = gr + (gr << GREEN_CHANNEL) + (gr << RED_CHANNEL);
|
||
|
|
||
|
return gray < 0x727272;
|
||
|
}
|
||
|
|
||
|
public static int mixTwoColors(int color1, int color2, float amount) {
|
||
|
final byte ALPHA_CHANNEL = 24;
|
||
|
final byte RED_CHANNEL = 16;
|
||
|
final byte GREEN_CHANNEL = 8;
|
||
|
final byte BLUE_CHANNEL = 0;
|
||
|
|
||
|
final float inverseAmount = 1.0f - amount;
|
||
|
|
||
|
int r = ((int) (((float) (color1 >> RED_CHANNEL & 0xff) * amount) + ((float) (color2 >> RED_CHANNEL & 0xff) * inverseAmount))) & 0xff;
|
||
|
int g = ((int) (((float) (color1 >> GREEN_CHANNEL & 0xff) * amount) + ((float) (color2 >> GREEN_CHANNEL & 0xff) * inverseAmount))) & 0xff;
|
||
|
int b = ((int) (((float) (color1 & 0xff) * amount) + ((float) (color2 & 0xff) * inverseAmount))) & 0xff;
|
||
|
|
||
|
return 0xff << ALPHA_CHANNEL | r << RED_CHANNEL | g << GREEN_CHANNEL | b << BLUE_CHANNEL;
|
||
|
}
|
||
|
|
||
10 years ago
|
public class BookmarkViewAdapter extends ArrayAdapter<HistoryItem> {
|
||
10 years ago
|
|
||
10 years ago
|
Context context;
|
||
9 years ago
|
List<HistoryItem> data = null;
|
||
9 years ago
|
int layoutResourceId;
|
||
9 years ago
|
|
||
10 years ago
|
public BookmarkViewAdapter(Context context, int layoutResourceId, List<HistoryItem> data) {
|
||
|
super(context, layoutResourceId, data);
|
||
|
this.layoutResourceId = layoutResourceId;
|
||
|
this.context = context;
|
||
|
this.data = data;
|
||
|
}
|
||
10 years ago
|
|
||
|
@Override
|
||
10 years ago
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||
|
View row = convertView;
|
||
|
BookmarkViewHolder holder = null;
|
||
|
|
||
|
if (row == null) {
|
||
|
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
|
||
|
row = inflater.inflate(layoutResourceId, parent, false);
|
||
|
|
||
|
holder = new BookmarkViewHolder();
|
||
9 years ago
|
holder.txtTitle = (TextView) row.findViewById(R.id.textBookmark);
|
||
|
holder.favicon = (ImageView) row.findViewById(R.id.faviconBookmark);
|
||
10 years ago
|
row.setTag(holder);
|
||
10 years ago
|
} else {
|
||
10 years ago
|
holder = (BookmarkViewHolder) row.getTag();
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
|
HistoryItem web = data.get(position);
|
||
|
holder.txtTitle.setText(web.getTitle());
|
||
|
holder.favicon.setImageBitmap(mWebpageBitmap);
|
||
|
if (web.getBitmap() == null) {
|
||
|
getImage(holder.favicon, web);
|
||
|
} else {
|
||
|
holder.favicon.setImageBitmap(web.getBitmap());
|
||
|
}
|
||
|
return row;
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
class BookmarkViewHolder {
|
||
|
TextView txtTitle;
|
||
|
ImageView favicon;
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
private void getImage(ImageView image, HistoryItem web) {
|
||
9 years ago
|
new DownloadImageTask(image, web).execute(web.getUrl());
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
|
||
10 years ago
|
|
||
10 years ago
|
ImageView bmImage;
|
||
|
HistoryItem mWeb;
|
||
|
|
||
|
public DownloadImageTask(ImageView bmImage, HistoryItem web) {
|
||
|
this.bmImage = bmImage;
|
||
|
this.mWeb = web;
|
||
|
}
|
||
|
|
||
|
protected Bitmap doInBackground(String... urls) {
|
||
9 years ago
|
String url = urls[0];
|
||
10 years ago
|
Bitmap mIcon = null;
|
||
|
// unique path for each url that is bookmarked.
|
||
9 years ago
|
String hash = String.valueOf(Utils.getDomainName(url).hashCode());
|
||
9 years ago
|
File image = new File(mActivity.getCacheDir(), hash + ".png");
|
||
9 years ago
|
String urldisplay;
|
||
|
try {
|
||
|
urldisplay = Utils.getProtocol(url) + getDomainName(url) + "/favicon.ico";
|
||
|
} catch (URISyntaxException e) {
|
||
|
e.printStackTrace();
|
||
|
urldisplay = "https://www.google.com/s2/favicons?domain_url=" + url;
|
||
|
}
|
||
10 years ago
|
// checks to see if the image exists
|
||
|
if (!image.exists()) {
|
||
|
try {
|
||
|
// if not, download it...
|
||
9 years ago
|
URL urlDownload = new URL(urldisplay);
|
||
|
HttpURLConnection connection = (HttpURLConnection) urlDownload.openConnection();
|
||
10 years ago
|
connection.setDoInput(true);
|
||
|
connection.connect();
|
||
|
InputStream in = connection.getInputStream();
|
||
10 years ago
|
|
||
|
if (in != null) {
|
||
|
mIcon = BitmapFactory.decodeStream(in);
|
||
|
}
|
||
|
// ...and cache it
|
||
|
if (mIcon != null) {
|
||
|
FileOutputStream fos = new FileOutputStream(image);
|
||
10 years ago
|
mIcon.compress(Bitmap.CompressFormat.PNG, 100, fos);
|
||
10 years ago
|
fos.flush();
|
||
|
fos.close();
|
||
9 years ago
|
Log.d(Constants.TAG, "Downloaded: " + urldisplay);
|
||
10 years ago
|
}
|
||
|
|
||
|
} catch (Exception e) {
|
||
9 years ago
|
e.printStackTrace();
|
||
10 years ago
|
}
|
||
10 years ago
|
} else {
|
||
10 years ago
|
// if it exists, retrieve it from the cache
|
||
|
mIcon = BitmapFactory.decodeFile(image.getPath());
|
||
10 years ago
|
}
|
||
10 years ago
|
if (mIcon == null) {
|
||
|
try {
|
||
|
// if not, download it...
|
||
9 years ago
|
URL urlDownload = new URL("https://www.google.com/s2/favicons?domain_url="
|
||
|
+ url);
|
||
|
HttpURLConnection connection = (HttpURLConnection) urlDownload.openConnection();
|
||
9 years ago
|
connection.setDoInput(true);
|
||
|
connection.connect();
|
||
|
InputStream in = connection.getInputStream();
|
||
10 years ago
|
|
||
|
if (in != null) {
|
||
|
mIcon = BitmapFactory.decodeStream(in);
|
||
|
}
|
||
|
// ...and cache it
|
||
|
if (mIcon != null) {
|
||
|
FileOutputStream fos = new FileOutputStream(image);
|
||
10 years ago
|
mIcon.compress(Bitmap.CompressFormat.PNG, 100, fos);
|
||
10 years ago
|
fos.flush();
|
||
|
fos.close();
|
||
|
}
|
||
|
|
||
|
} catch (Exception e) {
|
||
9 years ago
|
e.printStackTrace();
|
||
10 years ago
|
}
|
||
|
}
|
||
|
if (mIcon == null) {
|
||
|
return mWebpageBitmap;
|
||
|
} else {
|
||
|
return mIcon;
|
||
10 years ago
|
}
|
||
|
}
|
||
10 years ago
|
|
||
|
protected void onPostExecute(Bitmap result) {
|
||
9 years ago
|
Bitmap fav = Utils.padFavicon(result);
|
||
9 years ago
|
bmImage.setImageBitmap(fav);
|
||
|
mWeb.setBitmap(fav);
|
||
10 years ago
|
notifyBookmarkDataSetChanged();
|
||
10 years ago
|
}
|
||
10 years ago
|
}
|
||
|
|
||
|
static String getDomainName(String url) throws URISyntaxException {
|
||
|
URI uri = new URI(url);
|
||
|
String domain = uri.getHost();
|
||
|
if (domain == null) {
|
||
|
return url;
|
||
10 years ago
|
}
|
||
10 years ago
|
return domain.startsWith("www.") ? domain.substring(4) : domain;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
9 years ago
|
public void updateUrl(String url, boolean shortUrl) {
|
||
9 years ago
|
if (url == null || mSearch == null || mSearch.hasFocus()) {
|
||
10 years ago
|
return;
|
||
10 years ago
|
}
|
||
9 years ago
|
if (shortUrl && !url.startsWith(Constants.FILE)) {
|
||
9 years ago
|
switch (mPreferences.getUrlBoxContentChoice()) {
|
||
9 years ago
|
case 0: // Default, show only the domain
|
||
|
url = url.replaceFirst(Constants.HTTP, "");
|
||
|
url = Utils.getDomainName(url);
|
||
|
mSearch.setText(url);
|
||
|
break;
|
||
|
case 1: // URL, show the entire URL
|
||
|
mSearch.setText(url);
|
||
|
break;
|
||
|
case 2: // Title, show the page's title
|
||
|
if (mCurrentView != null && !mCurrentView.getTitle().isEmpty()) {
|
||
|
mSearch.setText(mCurrentView.getTitle());
|
||
|
} else {
|
||
|
mSearch.setText(mUntitledTitle);
|
||
|
}
|
||
|
break;
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
9 years ago
|
} else {
|
||
|
if (url.startsWith(Constants.FILE)) {
|
||
|
url = "";
|
||
|
}
|
||
|
mSearch.setText(url);
|
||
10 years ago
|
}
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
10 years ago
|
public void updateProgress(int n) {
|
||
|
if (n >= 100) {
|
||
9 years ago
|
setIsFinishedLoading();
|
||
10 years ago
|
} else {
|
||
|
setIsLoading();
|
||
10 years ago
|
}
|
||
9 years ago
|
mProgressBar.setProgress(n);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
@Override
|
||
10 years ago
|
public void updateHistory(final String title, final String url) {
|
||
10 years ago
|
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public void addItemToHistory(final String title, final String url) {
|
||
|
Runnable update = new Runnable() {
|
||
|
@Override
|
||
|
public void run() {
|
||
9 years ago
|
if (isSystemBrowserAvailable() && mPreferences.getSyncHistoryEnabled()) {
|
||
10 years ago
|
try {
|
||
|
Browser.updateVisitedHistory(getContentResolver(), url, true);
|
||
|
} catch (NullPointerException ignored) {
|
||
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
try {
|
||
9 years ago
|
if (mHistoryDatabase == null) {
|
||
9 years ago
|
mHistoryDatabase = HistoryDatabase.getInstance(mActivity);
|
||
10 years ago
|
}
|
||
9 years ago
|
mHistoryDatabase.visitHistoryItem(url, title);
|
||
10 years ago
|
} catch (IllegalStateException e) {
|
||
|
Log.e(Constants.TAG, "IllegalStateException in updateHistory");
|
||
|
} catch (NullPointerException e) {
|
||
|
Log.e(Constants.TAG, "NullPointerException in updateHistory");
|
||
|
} catch (SQLiteException e) {
|
||
|
Log.e(Constants.TAG, "SQLiteException in updateHistory");
|
||
|
}
|
||
|
}
|
||
|
};
|
||
10 years ago
|
if (url != null && !url.startsWith(Constants.FILE)) {
|
||
|
new Thread(update).start();
|
||
10 years ago
|
}
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public boolean isSystemBrowserAvailable() {
|
||
|
return mSystemBrowser;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public boolean getSystemBrowser() {
|
||
|
Cursor c = null;
|
||
|
String[] columns = new String[] { "url", "title" };
|
||
|
boolean browserFlag = false;
|
||
|
try {
|
||
10 years ago
|
|
||
10 years ago
|
Uri bookmarks = Browser.BOOKMARKS_URI;
|
||
|
c = getContentResolver().query(bookmarks, columns, null, null, null);
|
||
|
} catch (SQLiteException ignored) {
|
||
|
} catch (IllegalStateException ignored) {
|
||
|
} catch (NullPointerException ignored) {
|
||
|
}
|
||
|
|
||
|
if (c != null) {
|
||
9 years ago
|
Log.d("Browser", "System Browser Available");
|
||
10 years ago
|
browserFlag = true;
|
||
10 years ago
|
} else {
|
||
10 years ago
|
Log.e("Browser", "System Browser Unavailable");
|
||
|
browserFlag = false;
|
||
|
}
|
||
|
if (c != null) {
|
||
|
c.close();
|
||
|
c = null;
|
||
|
}
|
||
9 years ago
|
mPreferences.setSystemBrowserPresent(browserFlag);
|
||
10 years ago
|
return browserFlag;
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
/**
|
||
|
* method to generate search suggestions for the AutoCompleteTextView from
|
||
|
* previously searched URLs
|
||
|
*/
|
||
|
private void initializeSearchSuggestions(final AutoCompleteTextView getUrl) {
|
||
10 years ago
|
|
||
10 years ago
|
getUrl.setThreshold(1);
|
||
|
getUrl.setDropDownWidth(-1);
|
||
9 years ago
|
getUrl.setDropDownAnchor(R.id.toolbar_layout);
|
||
10 years ago
|
getUrl.setOnItemClickListener(new OnItemClickListener() {
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
|
||
|
try {
|
||
|
String url;
|
||
|
url = ((TextView) arg1.findViewById(R.id.url)).getText().toString();
|
||
9 years ago
|
if (url.startsWith(mActivity.getString(R.string.suggestion))) {
|
||
10 years ago
|
url = ((TextView) arg1.findViewById(R.id.title)).getText().toString();
|
||
|
} else {
|
||
|
getUrl.setText(url);
|
||
|
}
|
||
|
searchTheWeb(url);
|
||
|
url = null;
|
||
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||
|
imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0);
|
||
|
if (mCurrentView != null) {
|
||
|
mCurrentView.requestFocus();
|
||
|
}
|
||
|
} catch (NullPointerException e) {
|
||
|
Log.e("Browser Error: ", "NullPointerException on item click");
|
||
|
}
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
});
|
||
10 years ago
|
|
||
10 years ago
|
getUrl.setSelectAllOnFocus(true);
|
||
9 years ago
|
mSearchAdapter = new SearchAdapter(mActivity, mDarkTheme, isIncognito());
|
||
10 years ago
|
getUrl.setAdapter(mSearchAdapter);
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
10 years ago
|
public boolean isIncognito() {
|
||
|
return false;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
/**
|
||
|
* function that opens the HTML history page in the browser
|
||
|
*/
|
||
|
private void openHistory() {
|
||
10 years ago
|
// use a thread so that history retrieval doesn't block the UI
|
||
10 years ago
|
Thread history = new Thread(new Runnable() {
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
public void run() {
|
||
9 years ago
|
mCurrentView.loadUrl(HistoryPage.getHistoryPage(mActivity));
|
||
10 years ago
|
mSearch.setText("");
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
});
|
||
|
history.run();
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
/**
|
||
|
* helper function that opens the bookmark drawer
|
||
|
*/
|
||
|
private void openBookmarks() {
|
||
10 years ago
|
if (mDrawerLayout.isDrawerOpen(mDrawerLeft)) {
|
||
10 years ago
|
mDrawerLayout.closeDrawers();
|
||
|
}
|
||
|
mDrawerLayout.openDrawer(mDrawerRight);
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public void closeDrawers() {
|
||
|
mDrawerLayout.closeDrawers();
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
/**
|
||
|
* open the HTML bookmarks page, parameter view is the WebView that should show the page
|
||
|
*/
|
||
|
public void openBookmarkPage(WebView view) {
|
||
9 years ago
|
StringBuilder bookmarkBuilder = new StringBuilder();
|
||
|
bookmarkBuilder.append(BookmarkPage.HEADING);
|
||
10 years ago
|
Iterator<HistoryItem> iter = mBookmarkList.iterator();
|
||
|
HistoryItem helper;
|
||
|
while (iter.hasNext()) {
|
||
|
helper = iter.next();
|
||
9 years ago
|
bookmarkBuilder.append(BookmarkPage.PART1);
|
||
|
bookmarkBuilder.append(helper.getUrl());
|
||
|
bookmarkBuilder.append(BookmarkPage.PART2);
|
||
|
bookmarkBuilder.append(helper.getUrl());
|
||
|
bookmarkBuilder.append(BookmarkPage.PART3);
|
||
|
bookmarkBuilder.append(helper.getTitle());
|
||
|
bookmarkBuilder.append(BookmarkPage.PART4);
|
||
|
}
|
||
|
bookmarkBuilder.append(BookmarkPage.END);
|
||
9 years ago
|
File bookmarkWebPage = new File(mActivity.getFilesDir(), BookmarkPage.FILENAME);
|
||
10 years ago
|
try {
|
||
|
FileWriter bookWriter = new FileWriter(bookmarkWebPage, false);
|
||
9 years ago
|
bookWriter.write(bookmarkBuilder.toString());
|
||
10 years ago
|
bookWriter.close();
|
||
|
} catch (IOException e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
view.loadUrl(Constants.FILE + bookmarkWebPage);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
@Override
|
||
|
public void update() {
|
||
|
mTitleAdapter.notifyDataSetChanged();
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
@Override
|
||
|
/**
|
||
|
* opens a file chooser
|
||
|
* param ValueCallback is the message from the WebView indicating a file chooser
|
||
|
* should be opened
|
||
|
*/
|
||
|
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
|
||
|
mUploadMessage = uploadMsg;
|
||
|
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
|
||
|
i.addCategory(Intent.CATEGORY_OPENABLE);
|
||
|
i.setType("*/*");
|
||
10 years ago
|
startActivityForResult(Intent.createChooser(i, getString(R.string.title_file_chooser)), 1);
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
/**
|
||
10 years ago
|
* used to allow uploading into the browser
|
||
10 years ago
|
*/
|
||
|
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||
9 years ago
|
if (API < Build.VERSION_CODES.LOLLIPOP) {
|
||
|
if (requestCode == 1) {
|
||
|
if (null == mUploadMessage) {
|
||
|
return;
|
||
|
}
|
||
|
Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData();
|
||
|
mUploadMessage.onReceiveValue(result);
|
||
|
mUploadMessage = null;
|
||
|
|
||
10 years ago
|
}
|
||
9 years ago
|
}
|
||
|
|
||
|
if (requestCode != 1 || mFilePathCallback == null) {
|
||
|
super.onActivityResult(requestCode, resultCode, intent);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
Uri[] results = null;
|
||
10 years ago
|
|
||
9 years ago
|
// Check that the response is a good one
|
||
|
if (resultCode == Activity.RESULT_OK) {
|
||
|
if (intent == null) {
|
||
|
// If there is not data, then we may have taken a photo
|
||
|
if (mCameraPhotoPath != null) {
|
||
|
results = new Uri[] { Uri.parse(mCameraPhotoPath) };
|
||
|
}
|
||
|
} else {
|
||
|
String dataString = intent.getDataString();
|
||
|
if (dataString != null) {
|
||
|
results = new Uri[] { Uri.parse(dataString) };
|
||
|
}
|
||
|
}
|
||
10 years ago
|
}
|
||
9 years ago
|
|
||
|
mFilePathCallback.onReceiveValue(results);
|
||
|
mFilePathCallback = null;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void showFileChooser(ValueCallback<Uri[]> filePathCallback) {
|
||
|
if (mFilePathCallback != null) {
|
||
|
mFilePathCallback.onReceiveValue(null);
|
||
|
}
|
||
|
mFilePathCallback = filePathCallback;
|
||
|
|
||
|
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||
|
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
|
||
|
// Create the File where the photo should go
|
||
|
File photoFile = null;
|
||
|
try {
|
||
|
photoFile = Utils.createImageFile();
|
||
|
takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
|
||
|
} catch (IOException ex) {
|
||
|
// Error occurred while creating the File
|
||
|
Log.e(Constants.TAG, "Unable to create Image File", ex);
|
||
|
}
|
||
|
|
||
|
// Continue only if the File was successfully created
|
||
|
if (photoFile != null) {
|
||
|
mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
|
||
|
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
|
||
|
} else {
|
||
|
takePictureIntent = null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
||
|
contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
|
||
|
contentSelectionIntent.setType("image/*");
|
||
|
|
||
|
Intent[] intentArray;
|
||
|
if (takePictureIntent != null) {
|
||
|
intentArray = new Intent[] { takePictureIntent };
|
||
|
} else {
|
||
|
intentArray = new Intent[0];
|
||
|
}
|
||
|
|
||
|
Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
|
||
|
chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
|
||
|
chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
|
||
|
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
|
||
|
|
||
|
mActivity.startActivityForResult(chooserIntent, 1);
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
/**
|
||
|
* handles long presses for the browser, tries to get the
|
||
|
* url of the item that was clicked and sends it (it can be null)
|
||
|
* to the click handler that does cool stuff with it
|
||
|
*/
|
||
|
public void onLongPress() {
|
||
|
if (mClickHandler == null) {
|
||
9 years ago
|
mClickHandler = new ClickHandler(mActivity);
|
||
10 years ago
|
}
|
||
|
Message click = mClickHandler.obtainMessage();
|
||
|
if (click != null) {
|
||
|
click.setTarget(mClickHandler);
|
||
9 years ago
|
mCurrentView.getWebView().requestFocusNodeHref(click);
|
||
10 years ago
|
}
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
@Override
|
||
|
public void onShowCustomView(View view, int requestedOrientation, CustomViewCallback callback) {
|
||
|
if (view == null) {
|
||
|
return;
|
||
|
}
|
||
|
if (mCustomView != null && callback != null) {
|
||
|
callback.onCustomViewHidden();
|
||
|
return;
|
||
|
}
|
||
9 years ago
|
try {
|
||
9 years ago
|
view.setKeepScreenOn(true);
|
||
9 years ago
|
} catch (SecurityException e) {
|
||
9 years ago
|
Log.e(Constants.TAG, "WebView is not allowed to keep the screen on");
|
||
|
}
|
||
10 years ago
|
mOriginalOrientation = getRequestedOrientation();
|
||
|
FrameLayout decor = (FrameLayout) getWindow().getDecorView();
|
||
|
mFullscreenContainer = new FullscreenHolder(this);
|
||
|
mCustomView = view;
|
||
|
mFullscreenContainer.addView(mCustomView, COVER_SCREEN_PARAMS);
|
||
|
decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS);
|
||
|
setFullscreen(true);
|
||
|
mCurrentView.setVisibility(View.GONE);
|
||
|
if (view instanceof FrameLayout) {
|
||
|
if (((FrameLayout) view).getFocusedChild() instanceof VideoView) {
|
||
|
mVideoView = (VideoView) ((FrameLayout) view).getFocusedChild();
|
||
|
mVideoView.setOnErrorListener(new VideoCompletionListener());
|
||
|
mVideoView.setOnCompletionListener(new VideoCompletionListener());
|
||
|
}
|
||
|
}
|
||
|
mCustomViewCallback = callback;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
public void onHideCustomView() {
|
||
|
if (mCustomView == null || mCustomViewCallback == null || mCurrentView == null) {
|
||
|
return;
|
||
|
}
|
||
9 years ago
|
Log.d(Constants.TAG, "onHideCustomView");
|
||
10 years ago
|
mCurrentView.setVisibility(View.VISIBLE);
|
||
9 years ago
|
try {
|
||
9 years ago
|
mCustomView.setKeepScreenOn(false);
|
||
9 years ago
|
} catch (SecurityException e) {
|
||
9 years ago
|
Log.e(Constants.TAG, "WebView is not allowed to keep the screen on");
|
||
|
}
|
||
9 years ago
|
setFullscreen(mPreferences.getHideStatusBarEnabled());
|
||
10 years ago
|
FrameLayout decor = (FrameLayout) getWindow().getDecorView();
|
||
|
if (decor != null) {
|
||
|
decor.removeView(mFullscreenContainer);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
if (API < 19) {
|
||
|
try {
|
||
|
mCustomViewCallback.onCustomViewHidden();
|
||
|
} catch (Throwable ignored) {
|
||
|
|
||
|
}
|
||
|
}
|
||
|
mFullscreenContainer = null;
|
||
|
mCustomView = null;
|
||
|
if (mVideoView != null) {
|
||
|
mVideoView.setOnErrorListener(null);
|
||
|
mVideoView.setOnCompletionListener(null);
|
||
|
mVideoView = null;
|
||
10 years ago
|
}
|
||
10 years ago
|
setRequestedOrientation(mOriginalOrientation);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
private class VideoCompletionListener implements MediaPlayer.OnCompletionListener,
|
||
|
MediaPlayer.OnErrorListener {
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
public boolean onError(MediaPlayer mp, int what, int extra) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onCompletion(MediaPlayer mp) {
|
||
|
onHideCustomView();
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
|
/**
|
||
|
* turns on fullscreen mode in the app
|
||
|
*
|
||
|
* @param enabled
|
||
|
* whether to enable fullscreen or not
|
||
|
*/
|
||
|
public void setFullscreen(boolean enabled) {
|
||
|
Window win = getWindow();
|
||
|
WindowManager.LayoutParams winParams = win.getAttributes();
|
||
|
final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
||
|
if (enabled) {
|
||
|
winParams.flags |= bits;
|
||
|
} else {
|
||
|
winParams.flags &= ~bits;
|
||
|
if (mCustomView != null) {
|
||
|
mCustomView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
||
|
} else {
|
||
|
mBrowserFrame.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
||
|
}
|
||
|
}
|
||
|
win.setAttributes(winParams);
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
/**
|
||
|
* a class extending FramLayout used to display fullscreen videos
|
||
|
*/
|
||
|
static class FullscreenHolder extends FrameLayout {
|
||
10 years ago
|
|
||
10 years ago
|
public FullscreenHolder(Context ctx) {
|
||
|
super(ctx);
|
||
|
setBackgroundColor(ctx.getResources().getColor(android.R.color.black));
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@SuppressLint("ClickableViewAccessibility")
|
||
10 years ago
|
@Override
|
||
10 years ago
|
public boolean onTouchEvent(MotionEvent evt) {
|
||
|
return true;
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
@Override
|
||
|
/**
|
||
|
* a stupid method that returns the bitmap image to display in place of
|
||
|
* a loading video
|
||
|
*/
|
||
|
public Bitmap getDefaultVideoPoster() {
|
||
|
if (mDefaultVideoPoster == null) {
|
||
|
mDefaultVideoPoster = BitmapFactory.decodeResource(getResources(),
|
||
|
android.R.drawable.ic_media_play);
|
||
|
}
|
||
|
return mDefaultVideoPoster;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@SuppressLint("InflateParams")
|
||
|
@Override
|
||
|
/**
|
||
|
* dumb method that returns the loading progress for a video
|
||
|
*/
|
||
|
public View getVideoLoadingProgressView() {
|
||
|
if (mVideoProgressView == null) {
|
||
|
LayoutInflater inflater = LayoutInflater.from(this);
|
||
|
mVideoProgressView = inflater.inflate(R.layout.video_loading_progress, null);
|
||
10 years ago
|
}
|
||
10 years ago
|
return mVideoProgressView;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
/**
|
||
|
* handles javascript requests to create a new window in the browser
|
||
|
*/
|
||
|
public void onCreateWindow(boolean isUserGesture, Message resultMsg) {
|
||
|
if (resultMsg == null) {
|
||
|
return;
|
||
10 years ago
|
}
|
||
9 years ago
|
if (newTab("", true)) {
|
||
|
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
|
||
|
transport.setWebView(mCurrentView.getWebView());
|
||
|
resultMsg.sendToTarget();
|
||
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
/**
|
||
|
* returns the Activity instance for this activity,
|
||
|
* very helpful when creating things in other classes... I think
|
||
|
*/
|
||
|
public Activity getActivity() {
|
||
|
return mActivity;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
/**
|
||
|
* it hides the action bar, seriously what else were you expecting
|
||
|
*/
|
||
10 years ago
|
@Override
|
||
10 years ago
|
public void hideActionBar() {
|
||
9 years ago
|
if (mFullScreen) {
|
||
|
if (mBrowserFrame.findViewById(R.id.toolbar_layout) == null) {
|
||
|
mUiLayout.removeView(mToolbarLayout);
|
||
|
mBrowserFrame.addView(mToolbarLayout);
|
||
|
mToolbarLayout.bringToFront();
|
||
9 years ago
|
Log.d(Constants.TAG, "Move view to browser frame");
|
||
9 years ago
|
}
|
||
|
if (mToolbarLayout.getVisibility() != View.GONE) {
|
||
9 years ago
|
|
||
9 years ago
|
Animation hide = AnimationUtils.loadAnimation(mActivity, R.anim.slide_up);
|
||
9 years ago
|
hide.setAnimationListener(new AnimationListener() {
|
||
9 years ago
|
|
||
|
@Override
|
||
|
public void onAnimationStart(Animation animation) {
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onAnimationEnd(Animation animation) {
|
||
|
mToolbarLayout.setVisibility(View.GONE);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onAnimationRepeat(Animation animation) {
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
});
|
||
|
mToolbarLayout.startAnimation(hide);
|
||
9 years ago
|
Log.d(Constants.TAG, "Hide");
|
||
9 years ago
|
}
|
||
|
}
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
@Override
|
||
9 years ago
|
public void toggleActionBar() {
|
||
9 years ago
|
if (mFullScreen) {
|
||
|
if (mToolbarLayout.getVisibility() != View.VISIBLE) {
|
||
|
showActionBar();
|
||
|
} else {
|
||
|
hideActionBar();
|
||
|
}
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
|
@Override
|
||
10 years ago
|
/**
|
||
|
* obviously it shows the action bar if it's hidden
|
||
|
*/
|
||
|
public void showActionBar() {
|
||
9 years ago
|
if (mFullScreen) {
|
||
|
if (mBrowserFrame.findViewById(R.id.toolbar_layout) == null) {
|
||
|
mUiLayout.removeView(mToolbarLayout);
|
||
|
mBrowserFrame.addView(mToolbarLayout);
|
||
|
mToolbarLayout.bringToFront();
|
||
9 years ago
|
Log.d(Constants.TAG, "Move view to browser frame");
|
||
9 years ago
|
}
|
||
|
if (mToolbarLayout.getVisibility() != View.VISIBLE) {
|
||
9 years ago
|
Animation show = AnimationUtils.loadAnimation(mActivity, R.anim.slide_down);
|
||
9 years ago
|
show.setAnimationListener(new AnimationListener() {
|
||
9 years ago
|
|
||
|
@Override
|
||
|
public void onAnimationStart(Animation animation) {
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onAnimationEnd(Animation animation) {
|
||
|
mToolbarLayout.setVisibility(View.VISIBLE);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onAnimationRepeat(Animation animation) {
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
});
|
||
|
mToolbarLayout.startAnimation(show);
|
||
9 years ago
|
Log.d(Constants.TAG, "Show");
|
||
9 years ago
|
}
|
||
|
|
||
|
}
|
||
|
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
@Override
|
||
10 years ago
|
/**
|
||
|
* handles a long click on the page, parameter String url
|
||
|
* is the url that should have been obtained from the WebView touch node
|
||
|
* thingy, if it is null, this method tries to deal with it and find a workaround
|
||
|
*/
|
||
|
public void longClickPage(final String url) {
|
||
|
HitTestResult result = null;
|
||
|
if (mCurrentView.getWebView() != null) {
|
||
|
result = mCurrentView.getWebView().getHitTestResult();
|
||
|
}
|
||
|
if (url != null) {
|
||
|
if (result != null) {
|
||
|
if (result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE
|
||
|
|| result.getType() == HitTestResult.IMAGE_TYPE) {
|
||
|
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int which) {
|
||
|
switch (which) {
|
||
10 years ago
|
case DialogInterface.BUTTON_POSITIVE:
|
||
|
newTab(url, false);
|
||
|
break;
|
||
|
|
||
|
case DialogInterface.BUTTON_NEGATIVE:
|
||
|
mCurrentView.loadUrl(url);
|
||
|
break;
|
||
|
|
||
|
case DialogInterface.BUTTON_NEUTRAL:
|
||
|
if (API > 8) {
|
||
|
Utils.downloadFile(mActivity, url,
|
||
|
mCurrentView.getUserAgent(), "attachment", false);
|
||
|
}
|
||
|
break;
|
||
10 years ago
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); // dialog
|
||
|
builder.setTitle(url.replace(Constants.HTTP, ""))
|
||
|
.setMessage(getResources().getString(R.string.dialog_image))
|
||
|
.setPositiveButton(getResources().getString(R.string.action_new_tab),
|
||
|
dialogClickListener)
|
||
|
.setNegativeButton(getResources().getString(R.string.action_open),
|
||
|
dialogClickListener)
|
||
|
.setNeutralButton(getResources().getString(R.string.action_download),
|
||
|
dialogClickListener).show();
|
||
|
|
||
|
} else {
|
||
|
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int which) {
|
||
|
switch (which) {
|
||
10 years ago
|
case DialogInterface.BUTTON_POSITIVE:
|
||
|
newTab(url, false);
|
||
|
break;
|
||
|
|
||
|
case DialogInterface.BUTTON_NEGATIVE:
|
||
|
mCurrentView.loadUrl(url);
|
||
|
break;
|
||
|
|
||
|
case DialogInterface.BUTTON_NEUTRAL:
|
||
|
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||
|
ClipData clip = ClipData.newPlainText("label", url);
|
||
|
clipboard.setPrimaryClip(clip);
|
||
|
break;
|
||
10 years ago
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); // dialog
|
||
|
builder.setTitle(url)
|
||
|
.setMessage(getResources().getString(R.string.dialog_link))
|
||
|
.setPositiveButton(getResources().getString(R.string.action_new_tab),
|
||
|
dialogClickListener)
|
||
|
.setNegativeButton(getResources().getString(R.string.action_open),
|
||
|
dialogClickListener)
|
||
|
.setNeutralButton(getResources().getString(R.string.action_copy),
|
||
|
dialogClickListener).show();
|
||
|
}
|
||
|
} else {
|
||
|
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int which) {
|
||
|
switch (which) {
|
||
10 years ago
|
case DialogInterface.BUTTON_POSITIVE:
|
||
|
newTab(url, false);
|
||
|
break;
|
||
10 years ago
|
|
||
10 years ago
|
case DialogInterface.BUTTON_NEGATIVE:
|
||
|
mCurrentView.loadUrl(url);
|
||
|
break;
|
||
10 years ago
|
|
||
10 years ago
|
case DialogInterface.BUTTON_NEUTRAL:
|
||
|
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||
|
ClipData clip = ClipData.newPlainText("label", url);
|
||
|
clipboard.setPrimaryClip(clip);
|
||
10 years ago
|
|
||
10 years ago
|
break;
|
||
10 years ago
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); // dialog
|
||
|
builder.setTitle(url)
|
||
|
.setMessage(getResources().getString(R.string.dialog_link))
|
||
|
.setPositiveButton(getResources().getString(R.string.action_new_tab),
|
||
|
dialogClickListener)
|
||
|
.setNegativeButton(getResources().getString(R.string.action_open),
|
||
|
dialogClickListener)
|
||
|
.setNeutralButton(getResources().getString(R.string.action_copy),
|
||
|
dialogClickListener).show();
|
||
10 years ago
|
}
|
||
10 years ago
|
} else if (result != null) {
|
||
|
if (result.getExtra() != null) {
|
||
|
final String newUrl = result.getExtra();
|
||
|
if (result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE
|
||
|
|| result.getType() == HitTestResult.IMAGE_TYPE) {
|
||
|
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int which) {
|
||
|
switch (which) {
|
||
10 years ago
|
case DialogInterface.BUTTON_POSITIVE:
|
||
|
newTab(newUrl, false);
|
||
|
break;
|
||
|
|
||
|
case DialogInterface.BUTTON_NEGATIVE:
|
||
|
mCurrentView.loadUrl(newUrl);
|
||
|
break;
|
||
|
|
||
|
case DialogInterface.BUTTON_NEUTRAL:
|
||
|
if (API > 8) {
|
||
|
Utils.downloadFile(mActivity, newUrl,
|
||
|
mCurrentView.getUserAgent(), "attachment", false);
|
||
|
}
|
||
|
break;
|
||
10 years ago
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); // dialog
|
||
|
builder.setTitle(newUrl.replace(Constants.HTTP, ""))
|
||
|
.setMessage(getResources().getString(R.string.dialog_image))
|
||
|
.setPositiveButton(getResources().getString(R.string.action_new_tab),
|
||
|
dialogClickListener)
|
||
|
.setNegativeButton(getResources().getString(R.string.action_open),
|
||
|
dialogClickListener)
|
||
|
.setNeutralButton(getResources().getString(R.string.action_download),
|
||
|
dialogClickListener).show();
|
||
|
|
||
|
} else {
|
||
|
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int which) {
|
||
|
switch (which) {
|
||
10 years ago
|
case DialogInterface.BUTTON_POSITIVE:
|
||
|
newTab(newUrl, false);
|
||
|
break;
|
||
10 years ago
|
|
||
10 years ago
|
case DialogInterface.BUTTON_NEGATIVE:
|
||
|
mCurrentView.loadUrl(newUrl);
|
||
|
break;
|
||
10 years ago
|
|
||
10 years ago
|
case DialogInterface.BUTTON_NEUTRAL:
|
||
|
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||
|
ClipData clip = ClipData.newPlainText("label", newUrl);
|
||
|
clipboard.setPrimaryClip(clip);
|
||
10 years ago
|
|
||
10 years ago
|
break;
|
||
10 years ago
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); // dialog
|
||
|
builder.setTitle(newUrl)
|
||
|
.setMessage(getResources().getString(R.string.dialog_link))
|
||
|
.setPositiveButton(getResources().getString(R.string.action_new_tab),
|
||
|
dialogClickListener)
|
||
|
.setNegativeButton(getResources().getString(R.string.action_open),
|
||
|
dialogClickListener)
|
||
|
.setNeutralButton(getResources().getString(R.string.action_copy),
|
||
|
dialogClickListener).show();
|
||
|
}
|
||
10 years ago
|
|
||
|
}
|
||
|
|
||
10 years ago
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* This method lets the search bar know that the page is currently loading
|
||
|
* and that it should display the stop icon to indicate to the user that
|
||
|
* pressing it stops the page from loading
|
||
|
*/
|
||
|
public void setIsLoading() {
|
||
|
if (!mSearch.hasFocus()) {
|
||
|
mIcon = mDeleteIcon;
|
||
|
mSearch.setCompoundDrawables(null, null, mDeleteIcon, null);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* This tells the search bar that the page is finished loading and it should
|
||
|
* display the refresh icon
|
||
|
*/
|
||
|
public void setIsFinishedLoading() {
|
||
|
if (!mSearch.hasFocus()) {
|
||
|
mIcon = mRefreshIcon;
|
||
|
mSearch.setCompoundDrawables(null, null, mRefreshIcon, null);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* handle presses on the refresh icon in the search bar, if the page is
|
||
|
* loading, stop the page, if it is done loading refresh the page.
|
||
|
*
|
||
|
* See setIsFinishedLoading and setIsLoading for displaying the correct icon
|
||
|
*/
|
||
|
public void refreshOrStop() {
|
||
|
if (mCurrentView != null) {
|
||
|
if (mCurrentView.getProgress() < 100) {
|
||
|
mCurrentView.stopLoading();
|
||
|
} else {
|
||
|
mCurrentView.reload();
|
||
10 years ago
|
}
|
||
10 years ago
|
}
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
// Override this, use finish() for Incognito, moveTaskToBack for Main
|
||
|
public void closeActivity() {
|
||
|
finish();
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public class SortIgnoreCase implements Comparator<HistoryItem> {
|
||
10 years ago
|
|
||
10 years ago
|
public int compare(HistoryItem o1, HistoryItem o2) {
|
||
|
return o1.getTitle().toLowerCase(Locale.getDefault())
|
||
|
.compareTo(o2.getTitle().toLowerCase(Locale.getDefault()));
|
||
|
}
|
||
10 years ago
|
|
||
|
}
|
||
9 years ago
|
|
||
|
@Override
|
||
|
public int getMenu() {
|
||
|
return R.menu.main;
|
||
|
}
|
||
9 years ago
|
|
||
|
@Override
|
||
|
public void onClick(View v) {
|
||
|
switch (v.getId()) {
|
||
9 years ago
|
case R.id.action_back:
|
||
|
if (mCurrentView != null) {
|
||
|
if (mCurrentView.canGoBack()) {
|
||
|
mCurrentView.goBack();
|
||
|
} else {
|
||
|
deleteTab(mDrawerListLeft.getCheckedItemPosition());
|
||
|
}
|
||
9 years ago
|
}
|
||
9 years ago
|
break;
|
||
|
case R.id.action_forward:
|
||
|
if (mCurrentView != null) {
|
||
|
if (mCurrentView.canGoForward()) {
|
||
|
mCurrentView.goForward();
|
||
|
}
|
||
9 years ago
|
}
|
||
9 years ago
|
break;
|
||
|
case R.id.arrow_button:
|
||
|
if (mSearch != null && mSearch.hasFocus()) {
|
||
|
mCurrentView.requestFocus();
|
||
|
} else {
|
||
|
mDrawerLayout.openDrawer(mDrawerLeft);
|
||
|
}
|
||
|
break;
|
||
|
case R.id.new_tab_button:
|
||
|
newTab(null, true);
|
||
|
break;
|
||
|
case R.id.button_next:
|
||
|
mCurrentView.getWebView().findNext(false);
|
||
|
break;
|
||
|
case R.id.button_back:
|
||
|
mCurrentView.getWebView().findNext(true);
|
||
|
break;
|
||
|
case R.id.button_quit:
|
||
|
mCurrentView.getWebView().clearMatches();
|
||
|
mSearchBar.setVisibility(View.GONE);
|
||
|
break;
|
||
9 years ago
|
}
|
||
|
}
|
||
10 years ago
|
}
|