Activities Restructure - Incognito and Main now extend a single BrowserActivity
This commit is contained in:
parent
7e6a2cbcdd
commit
95110d9be9
@ -28,7 +28,7 @@
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="14"
|
||||
android:targetSdkVersion="19" />
|
||||
android:targetSdkVersion="20" />
|
||||
|
||||
<application
|
||||
android:name="acr.browser.lightning.BrowserApp"
|
||||
@ -37,7 +37,7 @@
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name" >
|
||||
<activity
|
||||
android:name="acr.browser.lightning.BrowserActivity"
|
||||
android:name="acr.browser.lightning.MainActivity"
|
||||
android:alwaysRetainTaskState="true"
|
||||
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
|
||||
android:label="@string/app_name"
|
||||
|
Binary file not shown.
3
lint.xml
Normal file
3
lint.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<lint>
|
||||
</lint>
|
@ -77,7 +77,6 @@ import android.view.WindowManager;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.webkit.CookieManager;
|
||||
import android.webkit.CookieSyncManager;
|
||||
import android.webkit.ValueCallback;
|
||||
import android.webkit.WebChromeClient.CustomViewCallback;
|
||||
import android.webkit.WebIconDatabase;
|
||||
@ -99,57 +98,57 @@ import android.widget.TextView.OnEditorActionListener;
|
||||
import android.widget.VideoView;
|
||||
|
||||
public class BrowserActivity extends Activity implements BrowserController {
|
||||
private static DrawerLayout mDrawerLayout;
|
||||
private static ListView mDrawerList;
|
||||
private static RelativeLayout mDrawer;
|
||||
private static LinearLayout mDrawerRight;
|
||||
private static ListView mDrawerListRight;
|
||||
private static TextView mNewTab;
|
||||
private static ActionBarDrawerToggle mDrawerToggle;
|
||||
private DrawerLayout mDrawerLayout;
|
||||
private ListView mDrawerList;
|
||||
private RelativeLayout mDrawer;
|
||||
private LinearLayout mDrawerRight;
|
||||
private ListView mDrawerListRight;
|
||||
private TextView mNewTab;
|
||||
private ActionBarDrawerToggle mDrawerToggle;
|
||||
private List<LightningView> mWebViews = new ArrayList<LightningView>();
|
||||
private static List<Integer> mIdList = new ArrayList<Integer>();
|
||||
private List<Integer> mIdList = new ArrayList<Integer>();
|
||||
private LightningView mCurrentView;
|
||||
private static int mIdGenerator;
|
||||
private static LightningViewAdapter mTitleAdapter;
|
||||
private static List<HistoryItem> mBookmarkList;
|
||||
private static BookmarkViewAdapter mBookmarkAdapter;
|
||||
private static AutoCompleteTextView mSearch;
|
||||
private static ClickHandler mClickHandler;
|
||||
private static ProgressBar mProgress;
|
||||
private static boolean mSystemBrowser = false;
|
||||
private static ValueCallback<Uri> mUploadMessage;
|
||||
private static View mCustomView;
|
||||
private static int mOriginalOrientation;
|
||||
private static int mActionBarSize;
|
||||
private static ActionBar mActionBar;
|
||||
private static boolean mFullScreen;
|
||||
private static FrameLayout mBrowserFrame;
|
||||
private static FullscreenHolder mFullscreenContainer;
|
||||
private static CustomViewCallback mCustomViewCallback;
|
||||
private static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = new FrameLayout.LayoutParams(
|
||||
private int mIdGenerator;
|
||||
private LightningViewAdapter mTitleAdapter;
|
||||
private List<HistoryItem> mBookmarkList;
|
||||
private BookmarkViewAdapter mBookmarkAdapter;
|
||||
private AutoCompleteTextView mSearch;
|
||||
private ClickHandler mClickHandler;
|
||||
private ProgressBar mProgress;
|
||||
private boolean mSystemBrowser = false;
|
||||
private ValueCallback<Uri> mUploadMessage;
|
||||
private View mCustomView;
|
||||
private int mOriginalOrientation;
|
||||
private int mActionBarSize;
|
||||
private ActionBar mActionBar;
|
||||
private boolean mFullScreen;
|
||||
private FrameLayout mBrowserFrame;
|
||||
private FullscreenHolder mFullscreenContainer;
|
||||
private CustomViewCallback mCustomViewCallback;
|
||||
private final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = new FrameLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
private static Bitmap mDefaultVideoPoster;
|
||||
private static View mVideoProgressView;
|
||||
private static DatabaseHandler mHistoryHandler;
|
||||
private static SQLiteDatabase mHistoryDatabase;
|
||||
private static SharedPreferences mPreferences;
|
||||
private static SharedPreferences.Editor mEditPrefs;
|
||||
private static Context mContext;
|
||||
private static Bitmap mWebpageBitmap;
|
||||
private static String mSearchText;
|
||||
private static Activity mActivity;
|
||||
private static CookieManager mCookieManager;
|
||||
private static final int API = android.os.Build.VERSION.SDK_INT;
|
||||
private static Drawable mDeleteIcon;
|
||||
private static Drawable mRefreshIcon;
|
||||
private static Drawable mCopyIcon;
|
||||
private static Drawable mIcon;
|
||||
private static int mActionBarSizeDp;
|
||||
private static int mNumberIconColor;
|
||||
private static String mHomepage;
|
||||
private static boolean mIsNewIntent = false;
|
||||
private static VideoView mVideoView;
|
||||
private Bitmap mDefaultVideoPoster;
|
||||
private View mVideoProgressView;
|
||||
private DatabaseHandler mHistoryHandler;
|
||||
private SQLiteDatabase mHistoryDatabase;
|
||||
private SharedPreferences mPreferences;
|
||||
private SharedPreferences.Editor mEditPrefs;
|
||||
private Context mContext;
|
||||
private Bitmap mWebpageBitmap;
|
||||
private String mSearchText;
|
||||
private Activity mActivity;
|
||||
private CookieManager mCookieManager;
|
||||
private final int API = android.os.Build.VERSION.SDK_INT;
|
||||
private Drawable mDeleteIcon;
|
||||
private Drawable mRefreshIcon;
|
||||
private Drawable mCopyIcon;
|
||||
private Drawable mIcon;
|
||||
private int mActionBarSizeDp;
|
||||
private int mNumberIconColor;
|
||||
private String mHomepage;
|
||||
private boolean mIsNewIntent = false;
|
||||
private VideoView mVideoView;
|
||||
private static SearchAdapter mSearchAdapter;
|
||||
|
||||
@Override
|
||||
@ -442,73 +441,92 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
WebIconDatabase.getInstance().open(
|
||||
getDir("icons", MODE_PRIVATE).getPath());
|
||||
}
|
||||
|
||||
boolean useProxy = mPreferences.getBoolean(PreferenceConstants.USE_PROXY, false);
|
||||
|
||||
if (useProxy)
|
||||
initializeTor();
|
||||
else
|
||||
checkForTor();
|
||||
|
||||
|
||||
//boolean useProxy = mPreferences.getBoolean(
|
||||
// PreferenceConstants.USE_PROXY, false);
|
||||
|
||||
// if (useProxy)
|
||||
// initializeTor();
|
||||
// else
|
||||
checkForTor();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* If Orbot/Tor is installed, prompt the user if they want to enable proxying for this session
|
||||
* If Orbot/Tor is installed, prompt the user if they want to enable
|
||||
* proxying for this session
|
||||
*/
|
||||
public boolean checkForTor () {
|
||||
public boolean checkForTor() {
|
||||
|
||||
OrbotHelper oh = new OrbotHelper(this);
|
||||
if (oh.isOrbotInstalled()) {
|
||||
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which){
|
||||
case DialogInterface.BUTTON_POSITIVE:
|
||||
|
||||
mPreferences.edit().putBoolean(PreferenceConstants.USE_PROXY, true).apply();
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_POSITIVE:
|
||||
|
||||
initializeTor ();
|
||||
|
||||
break;
|
||||
mPreferences
|
||||
.edit()
|
||||
.putBoolean(PreferenceConstants.USE_PROXY, true)
|
||||
.apply();
|
||||
|
||||
case DialogInterface.BUTTON_NEGATIVE:
|
||||
|
||||
mPreferences.edit().putBoolean(PreferenceConstants.USE_PROXY, false).apply();
|
||||
break;
|
||||
}
|
||||
}
|
||||
initializeTor();
|
||||
|
||||
break;
|
||||
|
||||
case DialogInterface.BUTTON_NEGATIVE:
|
||||
|
||||
mPreferences
|
||||
.edit()
|
||||
.putBoolean(PreferenceConstants.USE_PROXY,
|
||||
false).apply();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(R.string.use_tor_prompt).setPositiveButton(android.R.string.yes, dialogClickListener)
|
||||
.setNegativeButton(android.R.string.no, dialogClickListener).show();
|
||||
|
||||
builder.setMessage(R.string.use_tor_prompt)
|
||||
.setPositiveButton(R.string.yes, dialogClickListener)
|
||||
.setNegativeButton(R.string.no, dialogClickListener).show();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialize WebKit Proxying for Tor
|
||||
*/
|
||||
public void initializeTor() {
|
||||
|
||||
|
||||
OrbotHelper oh = new OrbotHelper(this);
|
||||
if (!oh.isOrbotRunning())
|
||||
oh.requestOrbotStart(this);
|
||||
|
||||
WebkitProxy wkp = new WebkitProxy();
|
||||
|
||||
WebkitProxy wkp = new WebkitProxy();
|
||||
try {
|
||||
String host = mPreferences.getString(PreferenceConstants.USE_PROXY_HOST, "localhost");
|
||||
int port = mPreferences.getInt(PreferenceConstants.USE_PROXY_PORT, 8118);
|
||||
wkp.setProxy("acr.browser.lightning.BrowserApp", getApplicationContext(), host, port);
|
||||
String host = mPreferences.getString(
|
||||
PreferenceConstants.USE_PROXY_HOST, "localhost");
|
||||
int port = mPreferences.getInt(PreferenceConstants.USE_PROXY_PORT,
|
||||
8118);
|
||||
wkp.setProxy("acr.browser.lightning.BrowserApp",
|
||||
getApplicationContext(), host, port);
|
||||
} catch (Exception e) {
|
||||
Log.d("Lightning","error enabling web proxying",e);
|
||||
}
|
||||
Log.d(Constants.LOGTAG, "error enabling web proxying", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Override this class
|
||||
*/
|
||||
public synchronized void initializeTabs() {
|
||||
|
||||
}
|
||||
|
||||
public void restoreOrNewTab() {
|
||||
mIdGenerator = 0;
|
||||
|
||||
String url = null;
|
||||
@ -545,7 +563,6 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
} else {
|
||||
newTab(url, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void initializePreferences() {
|
||||
@ -603,10 +620,14 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
break;
|
||||
}
|
||||
|
||||
mCookieManager = CookieManager.getInstance();
|
||||
CookieSyncManager.createInstance(this);
|
||||
mCookieManager.setAcceptCookie(mPreferences.getBoolean(
|
||||
PreferenceConstants.COOKIES, true));
|
||||
updateCookiePreference();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Override this if class overrides BrowserActivity
|
||||
*/
|
||||
public void updateCookiePreference() {
|
||||
|
||||
}
|
||||
|
||||
@ -622,7 +643,6 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@ -938,6 +958,9 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
}
|
||||
|
||||
public void handleNewIntent(Intent intent) {
|
||||
if (mCurrentView == null) {
|
||||
initialize();
|
||||
}
|
||||
@ -991,9 +1014,10 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
mDrawerToggle.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
private synchronized void newTab(String url, boolean show) {
|
||||
protected synchronized void newTab(String url, boolean show) {
|
||||
mIsNewIntent = false;
|
||||
LightningView startingTab = new LightningView(mActivity, url, mCookieManager);
|
||||
LightningView startingTab = new LightningView(mActivity, url,
|
||||
mCookieManager);
|
||||
if (mIdGenerator == 0) {
|
||||
startingTab.resumeTimers();
|
||||
}
|
||||
@ -1041,7 +1065,7 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
} else {
|
||||
if (mCurrentView.getUrl().startsWith(Constants.FILE)
|
||||
|| mCurrentView.getUrl().equals(mHomepage)) {
|
||||
moveTaskToBack(true);
|
||||
closeActivity();
|
||||
} else {
|
||||
mIdList.remove(position);
|
||||
mWebViews.remove(position);
|
||||
@ -1049,7 +1073,7 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
PreferenceConstants.CLEAR_CACHE_EXIT, false)
|
||||
&& mCurrentView != null) {
|
||||
mCurrentView.clearCache(true);
|
||||
Log.i("Lightning", "Cache Cleared");
|
||||
Log.i(Constants.LOGTAG, "Cache Cleared");
|
||||
|
||||
}
|
||||
if (reference != null) {
|
||||
@ -1068,10 +1092,10 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
|
||||
if (mIsNewIntent && isShown) {
|
||||
mIsNewIntent = false;
|
||||
moveTaskToBack(true);
|
||||
closeActivity();
|
||||
}
|
||||
|
||||
Log.i("Lightning", "deleted tab");
|
||||
Log.i(Constants.LOGTAG, "deleted tab");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1080,7 +1104,7 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
if (mPreferences.getBoolean(PreferenceConstants.CLEAR_CACHE_EXIT,
|
||||
false) && mCurrentView != null) {
|
||||
mCurrentView.clearCache(true);
|
||||
Log.i("Lightning", "Cache Cleared");
|
||||
Log.i(Constants.LOGTAG, "Cache Cleared");
|
||||
|
||||
}
|
||||
mCurrentView = null;
|
||||
@ -1106,7 +1130,7 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
mDrawerLayout.closeDrawer(mDrawerRight);
|
||||
} else {
|
||||
if (mCurrentView != null) {
|
||||
Log.i("Lightning", "onBackPressed");
|
||||
Log.i(Constants.LOGTAG, "onBackPressed");
|
||||
if (mCurrentView.canGoBack()) {
|
||||
if (!mCurrentView.isShown()) {
|
||||
onHideCustomView();
|
||||
@ -1117,7 +1141,7 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
deleteTab(mDrawerList.getCheckedItemPosition());
|
||||
}
|
||||
} else {
|
||||
Log.e("Lightning Browser",
|
||||
Log.e(Constants.LOGTAG,
|
||||
"So madness. Much confusion. Why happen.");
|
||||
super.onBackPressed();
|
||||
}
|
||||
@ -1127,7 +1151,7 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
Log.i("Lightning", "onPause");
|
||||
Log.i(Constants.LOGTAG, "onPause");
|
||||
if (mCurrentView != null) {
|
||||
mCurrentView.pauseTimers();
|
||||
mCurrentView.onPause();
|
||||
@ -1140,6 +1164,10 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
if (mHistoryHandler.isOpen())
|
||||
mHistoryHandler.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void saveOpenTabs() {
|
||||
if (mPreferences
|
||||
.getBoolean(PreferenceConstants.RESTORE_LOST_TABS, true)) {
|
||||
String s = "";
|
||||
@ -1155,7 +1183,7 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
Log.i("Lightning", "onDestroy");
|
||||
Log.i(Constants.LOGTAG, "onDestroy");
|
||||
if (mHistoryDatabase != null) {
|
||||
if (mHistoryDatabase.isOpen())
|
||||
mHistoryDatabase.close();
|
||||
@ -1170,7 +1198,7 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
Log.i("Lightning", "onResume");
|
||||
Log.i(Constants.LOGTAG, "onResume");
|
||||
if (SettingsController.getClearHistory()) {
|
||||
}
|
||||
if (mSearchAdapter != null) {
|
||||
@ -1544,7 +1572,7 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getDomainName(String url) throws URISyntaxException {
|
||||
static String getDomainName(String url) throws URISyntaxException {
|
||||
URI uri = new URI(url);
|
||||
String domain = uri.getHost();
|
||||
if (domain == null) {
|
||||
@ -1580,6 +1608,10 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
|
||||
@Override
|
||||
public void updateHistory(final String title, final String url) {
|
||||
|
||||
}
|
||||
|
||||
public void addItemToHistory(final String title, final String url) {
|
||||
Runnable update = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -1624,11 +1656,13 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
cursor.close();
|
||||
cursor = null;
|
||||
} catch (IllegalStateException e) {
|
||||
Log.e("Lightning", "IllegalStateException in updateHistory");
|
||||
Log.e(Constants.LOGTAG,
|
||||
"IllegalStateException in updateHistory");
|
||||
} catch (NullPointerException e) {
|
||||
Log.e("Lightning", "NullPointerException in updateHistory");
|
||||
Log.e(Constants.LOGTAG,
|
||||
"NullPointerException in updateHistory");
|
||||
} catch (SQLiteException e) {
|
||||
Log.e("Lightning", "SQLiteException in updateHistory");
|
||||
Log.e(Constants.LOGTAG, "SQLiteException in updateHistory");
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -1722,10 +1756,15 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
});
|
||||
|
||||
getUrl.setSelectAllOnFocus(true);
|
||||
mSearchAdapter = new SearchAdapter(mContext, false);
|
||||
mSearchAdapter = new SearchAdapter(mContext, isIncognito());
|
||||
getUrl.setAdapter(mSearchAdapter);
|
||||
}
|
||||
|
||||
public boolean isIncognito() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Damn it, I regret not using SQLite in the first place for this
|
||||
private List<HistoryItem> getBookmarks() {
|
||||
List<HistoryItem> bookmarks = new ArrayList<HistoryItem>();
|
||||
File bookUrl = new File(getApplicationContext().getFilesDir(),
|
||||
@ -1969,7 +2008,7 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
if (mCustomView == null || mCustomViewCallback == null
|
||||
|| mCurrentView == null)
|
||||
return;
|
||||
Log.i("Lightning", "onHideCustomView");
|
||||
Log.i(Constants.LOGTAG, "onHideCustomView");
|
||||
mCurrentView.setVisibility(View.VISIBLE);
|
||||
mCustomView.setKeepScreenOn(false);
|
||||
setFullscreen(mPreferences.getBoolean(
|
||||
@ -2134,99 +2173,52 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
result = mCurrentView.getWebView().getHitTestResult();
|
||||
}
|
||||
if (url != null) {
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
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) {
|
||||
case DialogInterface.BUTTON_POSITIVE: {
|
||||
newTab(url, false);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
case DialogInterface.BUTTON_NEGATIVE: {
|
||||
mCurrentView.loadUrl(url);
|
||||
break;
|
||||
}
|
||||
};
|
||||
case DialogInterface.BUTTON_NEUTRAL: {
|
||||
if (API > 8) {
|
||||
Utils.downloadFile(mActivity, url,
|
||||
mCurrentView.getUserAgent(),
|
||||
"attachment", false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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();
|
||||
|
||||
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
|
||||
@ -2271,6 +2263,44 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
R.string.action_copy),
|
||||
dialogClickListener).show();
|
||||
}
|
||||
} else {
|
||||
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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 if (result != null) {
|
||||
if (result.getExtra() != null) {
|
||||
@ -2419,6 +2449,11 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
}
|
||||
}
|
||||
|
||||
//Override this, use finish() for Incognito, moveTaskToBack for Main
|
||||
public void closeActivity() {
|
||||
finish();
|
||||
}
|
||||
|
||||
public class SortIgnoreCase implements Comparator<HistoryItem> {
|
||||
|
||||
public int compare(HistoryItem o1, HistoryItem o2) {
|
||||
|
@ -34,5 +34,6 @@ public class Constants {
|
||||
public static final String HTTP = "http://";
|
||||
public static final String HTTPS = "https://";
|
||||
public static final String FILE = "file://";
|
||||
public static final String LOGTAG = Constants.LOGTAG;
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -44,7 +44,7 @@ public class LightningDownloadListener implements DownloadListener {
|
||||
dialogClickListener)
|
||||
.setNegativeButton(mActivity.getResources().getString(R.string.action_cancel), dialogClickListener)
|
||||
.show();
|
||||
Log.i("Lightning", "Downloading" + fileName);
|
||||
Log.i(Constants.LOGTAG, "Downloading" + fileName);
|
||||
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ import org.apache.http.util.ByteArrayBuffer;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
@ -74,9 +75,10 @@ public class LightningView {
|
||||
private static boolean mWideViewPort;
|
||||
private static AdBlock mAdBlock;
|
||||
private CookieManager mCookieManager;
|
||||
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public LightningView(Activity activity, String url, CookieManager cookieManager) {
|
||||
public LightningView(Activity activity, String url,
|
||||
CookieManager cookieManager) {
|
||||
mActivity = activity;
|
||||
mCookieManager = cookieManager;
|
||||
mWebView = new WebView(activity);
|
||||
@ -372,7 +374,7 @@ public class LightningView {
|
||||
settings.setEnableSmoothTransition(true);
|
||||
}
|
||||
if (API > 16) {
|
||||
settings.setMediaPlaybackRequiresUserGesture(true);
|
||||
settings.setMediaPlaybackRequiresUserGesture(true);
|
||||
}
|
||||
if (API < 19) {
|
||||
settings.setDatabasePath(context.getFilesDir().getAbsolutePath()
|
||||
@ -552,7 +554,6 @@ public class LightningView {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
public class LightningWebClient extends WebViewClient {
|
||||
|
||||
Context mActivity;
|
||||
@ -571,115 +572,118 @@ public class LightningView {
|
||||
"text/plain", "utf-8", EMPTY);
|
||||
return response;
|
||||
}
|
||||
|
||||
boolean useProxy = mPreferences.getBoolean(PreferenceConstants.USE_PROXY, false);
|
||||
|
||||
boolean useProxy = mPreferences.getBoolean(
|
||||
PreferenceConstants.USE_PROXY, false);
|
||||
boolean mDoLeakHardening = false;
|
||||
|
||||
|
||||
if (!useProxy)
|
||||
return null;
|
||||
|
||||
|
||||
if (!mDoLeakHardening)
|
||||
return null;
|
||||
|
||||
//now we are going to proxy!
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
// now we are going to proxy!
|
||||
try {
|
||||
|
||||
URL uURl = new URL(url);
|
||||
|
||||
|
||||
Proxy proxy = null;
|
||||
|
||||
String host = mPreferences.getString(PreferenceConstants.USE_PROXY_HOST, "localhost");
|
||||
int port = mPreferences.getInt(PreferenceConstants.USE_PROXY_PORT, 8118);
|
||||
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port));
|
||||
|
||||
|
||||
String host = mPreferences.getString(
|
||||
PreferenceConstants.USE_PROXY_HOST, "localhost");
|
||||
int port = mPreferences.getInt(
|
||||
PreferenceConstants.USE_PROXY_PORT, 8118);
|
||||
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host,
|
||||
port));
|
||||
|
||||
HttpURLConnection.setFollowRedirects(true);
|
||||
HttpURLConnection conn = (HttpURLConnection)uURl.openConnection(proxy);
|
||||
HttpURLConnection conn = (HttpURLConnection) uURl
|
||||
.openConnection(proxy);
|
||||
conn.setInstanceFollowRedirects(true);
|
||||
conn.setRequestProperty("User-Agent", mSettings.getUserAgentString());
|
||||
|
||||
//conn.setRequestProperty("Transfer-Encoding", "chunked");
|
||||
//conn.setUseCaches(false);
|
||||
|
||||
conn.setRequestProperty("User-Agent",
|
||||
mSettings.getUserAgentString());
|
||||
|
||||
// conn.setRequestProperty("Transfer-Encoding", "chunked");
|
||||
// conn.setUseCaches(false);
|
||||
|
||||
final int bufferSize = 1024 * 32;
|
||||
conn.setChunkedStreamingMode(bufferSize);
|
||||
|
||||
String cType = conn.getContentType();
|
||||
String cEnc = conn.getContentEncoding();
|
||||
String cEnc = conn.getContentEncoding();
|
||||
int connLen = conn.getContentLength();
|
||||
|
||||
|
||||
if (cType != null)
|
||||
{
|
||||
|
||||
if (cType != null) {
|
||||
String[] ctArray = cType.split(";");
|
||||
cType = ctArray[0].trim();
|
||||
|
||||
if (cEnc == null && ctArray.length > 1)
|
||||
{
|
||||
|
||||
if (cEnc == null && ctArray.length > 1) {
|
||||
cEnc = ctArray[1];
|
||||
if (cEnc.indexOf('=')!=-1)
|
||||
if (cEnc.indexOf('=') != -1)
|
||||
cEnc = cEnc.split("=")[1].trim();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (connLen <= 0)
|
||||
connLen = 2048;
|
||||
|
||||
if (cType != null && cType.startsWith("text"))
|
||||
{
|
||||
|
||||
if (cType != null && cType.startsWith("text")) {
|
||||
InputStream fStream = null;
|
||||
|
||||
BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
|
||||
ByteArrayBuffer baf = new ByteArrayBuffer(connLen);
|
||||
int read = 0;
|
||||
int bufSize = 2048;
|
||||
byte[] buffer = new byte[bufSize];
|
||||
while(true){
|
||||
read = bis.read(buffer);
|
||||
if(read==-1){
|
||||
break;
|
||||
}
|
||||
baf.append(buffer, 0, read);
|
||||
}
|
||||
byte[] plainText = baf.toByteArray();
|
||||
|
||||
|
||||
BufferedInputStream bis = new BufferedInputStream(
|
||||
conn.getInputStream());
|
||||
ByteArrayBuffer baf = new ByteArrayBuffer(connLen);
|
||||
int read = 0;
|
||||
int bufSize = 2048;
|
||||
byte[] buffer = new byte[bufSize];
|
||||
while (true) {
|
||||
read = bis.read(buffer);
|
||||
if (read == -1) {
|
||||
break;
|
||||
}
|
||||
baf.append(buffer, 0, read);
|
||||
}
|
||||
byte[] plainText = baf.toByteArray();
|
||||
|
||||
fStream = new ByteArrayInputStream(plainText);
|
||||
|
||||
fStream = new ReplacingInputStream(new ByteArrayInputStream(plainText),"poster=".getBytes(),"foo=".getBytes());
|
||||
fStream = new ReplacingInputStream(fStream,"Poster=".getBytes(),"foo=".getBytes());
|
||||
fStream = new ReplacingInputStream(fStream,"Poster=".getBytes(),"foo=".getBytes());
|
||||
fStream = new ReplacingInputStream(fStream,".poster".getBytes(),".foo".getBytes());
|
||||
fStream = new ReplacingInputStream(fStream,"\"poster\"".getBytes(),"\"foo\"".getBytes());
|
||||
|
||||
|
||||
fStream = new ReplacingInputStream(
|
||||
new ByteArrayInputStream(plainText),
|
||||
"poster=".getBytes(), "foo=".getBytes());
|
||||
fStream = new ReplacingInputStream(fStream,
|
||||
"Poster=".getBytes(), "foo=".getBytes());
|
||||
fStream = new ReplacingInputStream(fStream,
|
||||
"Poster=".getBytes(), "foo=".getBytes());
|
||||
fStream = new ReplacingInputStream(fStream,
|
||||
".poster".getBytes(), ".foo".getBytes());
|
||||
fStream = new ReplacingInputStream(fStream,
|
||||
"\"poster\"".getBytes(), "\"foo\"".getBytes());
|
||||
|
||||
WebResourceResponse response = new WebResourceResponse(
|
||||
cType, cEnc, fStream);
|
||||
|
||||
|
||||
return response;
|
||||
}/**
|
||||
else if (mDoLeakHardening)
|
||||
{
|
||||
WebResourceResponse response = new WebResourceResponse(
|
||||
cType, cEnc, conn.getInputStream());
|
||||
|
||||
return response;
|
||||
|
||||
}*/
|
||||
else
|
||||
{
|
||||
return null; //let webkit handle it
|
||||
* else if (mDoLeakHardening) { WebResourceResponse response =
|
||||
* new WebResourceResponse( cType, cEnc, conn.getInputStream());
|
||||
*
|
||||
* return response;
|
||||
*
|
||||
* }
|
||||
*/
|
||||
else {
|
||||
return null; // let webkit handle it
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.e("Lightning","Error filtering stream",e);
|
||||
} catch (Exception e) {
|
||||
Log.e(Constants.LOGTAG, "Error filtering stream", e);
|
||||
ByteArrayInputStream EMPTY = new ByteArrayInputStream(
|
||||
"".getBytes());
|
||||
WebResourceResponse response = new WebResourceResponse(
|
||||
"text/plain", "utf-8", EMPTY);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -734,7 +738,7 @@ public class LightningView {
|
||||
String user = name.getText().toString();
|
||||
String pass = password.getText().toString();
|
||||
handler.proceed(user.trim(), pass.trim());
|
||||
Log.i("Lightning", "Request Login");
|
||||
Log.i(Constants.LOGTAG, "Request Login");
|
||||
|
||||
}
|
||||
})
|
||||
@ -876,7 +880,11 @@ public class LightningView {
|
||||
return false;
|
||||
}
|
||||
if (intent != null) {
|
||||
mActivity.startActivity(intent);
|
||||
try {
|
||||
mActivity.startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Log.e(Constants.LOGTAG, "ActivityNotFoundException");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -995,24 +1003,22 @@ public class LightningView {
|
||||
|
||||
@Override
|
||||
public void onShowCustomView(View view, CustomViewCallback callback) {
|
||||
|
||||
if (view instanceof FrameLayout){
|
||||
FrameLayout frame = (FrameLayout) view;
|
||||
if (frame.getFocusedChild() instanceof VideoView){
|
||||
VideoView video = (VideoView) frame.getFocusedChild();
|
||||
video.stopPlayback();
|
||||
frame.removeView(video);
|
||||
video.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (view instanceof FrameLayout) {
|
||||
FrameLayout frame = (FrameLayout) view;
|
||||
if (frame.getFocusedChild() instanceof VideoView) {
|
||||
VideoView video = (VideoView) frame.getFocusedChild();
|
||||
video.stopPlayback();
|
||||
frame.removeView(video);
|
||||
video.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
Activity activity = mBrowserController.getActivity();
|
||||
mBrowserController.onShowCustomView(view,
|
||||
activity.getRequestedOrientation(), callback);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
super.onShowCustomView(view, callback);
|
||||
}
|
||||
|
||||
@ -1020,23 +1026,21 @@ public class LightningView {
|
||||
@Deprecated
|
||||
public void onShowCustomView(View view, int requestedOrientation,
|
||||
CustomViewCallback callback) {
|
||||
|
||||
if (view instanceof FrameLayout){
|
||||
FrameLayout frame = (FrameLayout) view;
|
||||
if (frame.getFocusedChild() instanceof VideoView){
|
||||
VideoView video = (VideoView) frame.getFocusedChild();
|
||||
video.stopPlayback();
|
||||
frame.removeView(video);
|
||||
video.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (view instanceof FrameLayout) {
|
||||
FrameLayout frame = (FrameLayout) view;
|
||||
if (frame.getFocusedChild() instanceof VideoView) {
|
||||
VideoView video = (VideoView) frame.getFocusedChild();
|
||||
video.stopPlayback();
|
||||
frame.removeView(video);
|
||||
video.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
mBrowserController.onShowCustomView(view, requestedOrientation,
|
||||
callback);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
super.onShowCustomView(view, requestedOrientation, callback);
|
||||
}
|
||||
|
||||
|
77
src/acr/browser/lightning/MainActivity.java
Normal file
77
src/acr/browser/lightning/MainActivity.java
Normal file
@ -0,0 +1,77 @@
|
||||
package acr.browser.lightning;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.webkit.CookieManager;
|
||||
import android.webkit.CookieSyncManager;
|
||||
|
||||
public class MainActivity extends BrowserActivity {
|
||||
|
||||
SharedPreferences mPreferences;
|
||||
CookieManager mCookieManager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCookiePreference() {
|
||||
if (mPreferences == null) {
|
||||
mPreferences = getSharedPreferences(
|
||||
PreferenceConstants.PREFERENCES, 0);
|
||||
}
|
||||
mCookieManager = CookieManager.getInstance();
|
||||
CookieSyncManager.createInstance(this);
|
||||
mCookieManager.setAcceptCookie(mPreferences.getBoolean(
|
||||
PreferenceConstants.COOKIES, true));
|
||||
super.updateCookiePreference();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void initializeTabs() {
|
||||
super.initializeTabs();
|
||||
restoreOrNewTab();
|
||||
//if incognito mode use newTab(null, true); instead
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
handleNewIntent(intent);
|
||||
super.onNewIntent(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
saveOpenTabs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateHistory(String title, String url) {
|
||||
super.updateHistory(title, url);
|
||||
addItemToHistory(title, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncognito() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeActivity() {
|
||||
moveTaskToBack(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -30,7 +30,7 @@ public class Utils {
|
||||
String fileName = URLUtil.guessFileName(url, null,
|
||||
null);
|
||||
DownloadHandler.onDownloadStart(activity, url, userAgent, contentDisposition, null, privateBrowsing);
|
||||
Log.i("Lightning", "Downloading" + fileName);
|
||||
Log.i(Constants.LOGTAG, "Downloading" + fileName);
|
||||
}
|
||||
|
||||
public static synchronized void addBookmark(Context context, String title, String url) {
|
||||
|
Loading…
Reference in New Issue
Block a user