clean BrowserActivity

This commit is contained in:
DF1E 2015-04-01 20:36:10 +02:00
parent 763524555b
commit c75ca89775

View File

@ -72,14 +72,12 @@ import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.*; import java.util.*;
public class BrowserActivity extends ActionBarActivity implements BrowserController { public class BrowserActivity extends ActionBarActivity implements BrowserController, OnClickListener {
private DrawerLayout mDrawerLayout; private DrawerLayout mDrawerLayout;
private ListView mDrawerListLeft; private ListView mDrawerListLeft, mDrawerListRight;
private LinearLayout mDrawerLeft; private LinearLayout mDrawerLeft, mDrawerRight, mPageLayout, mUiLayout, mToolbarLayout;
private LinearLayout mDrawerRight; private RelativeLayout mNewTab, mSearchBar;
private ListView mDrawerListRight;
private RelativeLayout mNewTab;
private List<LightningView> mWebViews = new ArrayList<LightningView>(); private List<LightningView> mWebViews = new ArrayList<LightningView>();
private LightningView mCurrentView; private LightningView mCurrentView;
private int mIdGenerator; private int mIdGenerator;
@ -94,42 +92,29 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
private AnimatedProgressBar mProgressBar; private AnimatedProgressBar mProgressBar;
private boolean mSystemBrowser = false; private boolean mSystemBrowser = false;
private ValueCallback<Uri> mUploadMessage; private ValueCallback<Uri> mUploadMessage;
private View mCustomView; private View mCustomView, mVideoProgressView;
private int mOriginalOrientation; private int mOriginalOrientation, mBackgroundColor;
private int mBackgroundColor;
private ActionBar mActionBar; private ActionBar mActionBar;
private boolean mFullScreen; private boolean mFullScreen, mColorMode, mDarkTheme;
private boolean mColorMode;
private FrameLayout mBrowserFrame; private FrameLayout mBrowserFrame;
private LinearLayout mPageLayout;
private LinearLayout mUiLayout;
private FullscreenHolder mFullscreenContainer; private FullscreenHolder mFullscreenContainer;
private CustomViewCallback mCustomViewCallback; private CustomViewCallback mCustomViewCallback;
private final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = new FrameLayout.LayoutParams( private final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
private Bitmap mDefaultVideoPoster; private Bitmap mDefaultVideoPoster, mWebpageBitmap;
private View mVideoProgressView;
private LinearLayout mToolbarLayout;
private HistoryDatabase mHistoryDatabase; private HistoryDatabase mHistoryDatabase;
private SharedPreferences mPreferences; private SharedPreferences mPreferences;
private Context mContext; private Context mContext;
private Bitmap mWebpageBitmap; private String mSearchText, mUntitledTitle, mHomepage;
private String mSearchText;
private String mUntitledTitle;
private Activity mActivity; private Activity mActivity;
private final int API = android.os.Build.VERSION.SDK_INT; private final int API = android.os.Build.VERSION.SDK_INT;
private Drawable mDeleteIcon; private Drawable mDeleteIcon, mRefreshIcon, mCopyIcon, mIcon;
private Drawable mRefreshIcon;
private Drawable mCopyIcon;
private Drawable mIcon;
private String mHomepage;
private boolean mIsNewIntent = false; private boolean mIsNewIntent = false;
private VideoView mVideoView; private VideoView mVideoView;
private static SearchAdapter mSearchAdapter; private static SearchAdapter mSearchAdapter;
private static LayoutParams mMatchParent = new LayoutParams(LayoutParams.MATCH_PARENT, private static LayoutParams mMatchParent = new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT); LayoutParams.MATCH_PARENT);
private BookmarkManager mBookmarkManager; private BookmarkManager mBookmarkManager;
private boolean mDarkTheme;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -211,7 +196,6 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
mHistoryDatabase = HistoryDatabase.getInstance(this); mHistoryDatabase = HistoryDatabase.getInstance(this);
// set display options of the ActionBar // set display options of the ActionBar
mActionBar.setDisplayShowTitleEnabled(false); mActionBar.setDisplayShowTitleEnabled(false);
mActionBar.setHomeButtonEnabled(false); mActionBar.setHomeButtonEnabled(false);
mActionBar.setDisplayShowHomeEnabled(false); mActionBar.setDisplayShowHomeEnabled(false);
@ -233,51 +217,13 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
mArrowImage.setImageDrawable(mArrowDrawable); mArrowImage.setImageDrawable(mArrowDrawable);
LinearLayout arrowButton = (LinearLayout) mActionBar.getCustomView().findViewById( LinearLayout arrowButton = (LinearLayout) mActionBar.getCustomView().findViewById(
R.id.arrow_button); R.id.arrow_button);
arrowButton.setOnClickListener(new OnClickListener() { arrowButton.setOnClickListener(this);
@Override
public void onClick(View v) {
if (mSearch != null && mSearch.hasFocus()) {
mCurrentView.requestFocus();
} else {
mDrawerLayout.openDrawer(mDrawerLeft);
}
}
});
RelativeLayout back = (RelativeLayout) findViewById(R.id.action_back); RelativeLayout back = (RelativeLayout) findViewById(R.id.action_back);
back.setOnClickListener(this);
RelativeLayout forward = (RelativeLayout) findViewById(R.id.action_forward); RelativeLayout forward = (RelativeLayout) findViewById(R.id.action_forward);
if (back != null) { forward.setOnClickListener(this);
back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mCurrentView != null) {
if (mCurrentView.canGoBack()) {
mCurrentView.goBack();
} else {
deleteTab(mDrawerListLeft.getCheckedItemPosition());
}
}
}
});
}
if (forward != null) {
forward.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mCurrentView != null) {
if (mCurrentView.canGoForward()) {
mCurrentView.goForward();
}
}
}
});
}
// create the search EditText in the ToolBar // create the search EditText in the ToolBar
mSearch = (AutoCompleteTextView) mActionBar.getCustomView().findViewById(R.id.search); mSearch = (AutoCompleteTextView) mActionBar.getCustomView().findViewById(R.id.search);
@ -316,15 +262,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
}); });
initialize.run(); initialize.run();
mNewTab.setOnClickListener(new OnClickListener() { mNewTab.setOnClickListener(this);
@Override
public void onClick(View arg0) {
newTab(null, true);
}
});
mNewTab.setOnLongClickListener(new OnLongClickListener() { mNewTab.setOnLongClickListener(new OnLongClickListener() {
@Override @Override
@ -351,7 +289,6 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
} }
checkForTor(); checkForTor();
} }
private class SearchClass { private class SearchClass {
@ -540,92 +477,6 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
} }
public boolean handleMenuItemClick(MenuItem item) {
// Handle action buttons
switch (item.getItemId()) {
case android.R.id.home:
if (mDrawerLayout.isDrawerOpen(mDrawerRight)) {
mDrawerLayout.closeDrawer(mDrawerRight);
}
// mDrawerToggle.syncState();
return true;
case R.id.action_back:
if (mCurrentView != null) {
if (mCurrentView.canGoBack()) {
mCurrentView.goBack();
}
}
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:
if (!mCurrentView.getUrl().startsWith(Constants.FILE)) {
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)));
}
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);
ClipData clip = ClipData.newPlainText("label", mCurrentView.getUrl());
clipboard.setPrimaryClip(clip);
Utils.showToast(mContext,
mContext.getResources().getString(R.string.message_link_copied));
}
}
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)) {
HistoryItem bookmark = new HistoryItem(mCurrentView.getUrl(),
mCurrentView.getTitle());
if (mBookmarkManager.addBookmark(bookmark)) {
mBookmarkList.add(bookmark);
Collections.sort(mBookmarkList, new SortIgnoreCase());
notifyBookmarkDataSetChanged();
mSearchAdapter.refreshBookmarks();
}
}
return true;
case R.id.action_find:
findInPage();
return true;
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;
default:
return super.onOptionsItemSelected(item);
}
}
/* /*
* If Orbot/Tor is installed, prompt the user if they want to enable * If Orbot/Tor is installed, prompt the user if they want to enable
* proxying for this session * proxying for this session
@ -997,35 +848,20 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
if (mCurrentView != null) { if (mCurrentView != null) {
mCurrentView.find(text); mCurrentView.find(text);
} }
final RelativeLayout bar = (RelativeLayout) findViewById(R.id.search_bar); mSearchBar = (RelativeLayout) findViewById(R.id.search_bar);
bar.setVisibility(View.VISIBLE); mSearchBar.setVisibility(View.VISIBLE);
TextView tw = (TextView) findViewById(R.id.search_query); TextView tw = (TextView) findViewById(R.id.search_query);
tw.setText("'" + text + "'"); tw.setText("'" + text + "'");
ImageButton up = (ImageButton) findViewById(R.id.button_next); ImageButton up = (ImageButton) findViewById(R.id.button_next);
up.setOnClickListener(new View.OnClickListener() { up.setOnClickListener(this);
@Override
public void onClick(View v) {
mCurrentView.getWebView().findNext(false);
}
});
ImageButton down = (ImageButton) findViewById(R.id.button_back); ImageButton down = (ImageButton) findViewById(R.id.button_back);
down.setOnClickListener(new View.OnClickListener() { down.setOnClickListener(this);
@Override
public void onClick(View v) {
mCurrentView.getWebView().findNext(true);
}
});
ImageButton quit = (ImageButton) findViewById(R.id.button_quit); ImageButton quit = (ImageButton) findViewById(R.id.button_quit);
quit.setOnClickListener(new View.OnClickListener() { quit.setOnClickListener(this);
@Override
public void onClick(View v) {
mCurrentView.getWebView().clearMatches();
bar.setVisibility(View.GONE);
}
});
} }
private void showCloseDialog(final int position) { private void showCloseDialog(final int position) {
@ -2693,4 +2529,46 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
public int getMenu() { public int getMenu() {
return R.menu.main; return R.menu.main;
} }
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.action_back:
if (mCurrentView != null) {
if (mCurrentView.canGoBack()) {
mCurrentView.goBack();
} else {
deleteTab(mDrawerListLeft.getCheckedItemPosition());
}
}
break;
case R.id.action_forward:
if (mCurrentView != null) {
if (mCurrentView.canGoForward()) {
mCurrentView.goForward();
}
}
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;
}
}
} }