Browse Source

Activities Restructure - Incognito and Main now extend a single BrowserActivity

master
Anthony Restaino 11 years ago
parent
commit
95110d9be9
  1. 4
      AndroidManifest.xml
  2. BIN
      libs/android-support-v4.jar
  3. 3
      lint.xml
  4. 247
      src/acr/browser/lightning/BrowserActivity.java
  5. 1
      src/acr/browser/lightning/Constants.java
  6. 2200
      src/acr/browser/lightning/IncognitoActivity.java
  7. 2
      src/acr/browser/lightning/LightningDownloadListener.java
  8. 116
      src/acr/browser/lightning/LightningView.java
  9. 77
      src/acr/browser/lightning/MainActivity.java
  10. 2
      src/acr/browser/lightning/Utils.java

4
AndroidManifest.xml

@ -28,7 +28,7 @@ @@ -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 @@ @@ -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"

BIN
libs/android-support-v4.jar

Binary file not shown.

3
lint.xml

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
</lint>

247
src/acr/browser/lightning/BrowserActivity.java

@ -77,7 +77,6 @@ import android.view.WindowManager; @@ -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; @@ -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
@ -443,45 +442,54 @@ public class BrowserActivity extends Activity implements BrowserController { @@ -443,45 +442,54 @@ public class BrowserActivity extends Activity implements BrowserController {
getDir("icons", MODE_PRIVATE).getPath());
}
boolean useProxy = mPreferences.getBoolean(PreferenceConstants.USE_PROXY, false);
//boolean useProxy = mPreferences.getBoolean(
// PreferenceConstants.USE_PROXY, false);
if (useProxy)
initializeTor();
else
// 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){
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
mPreferences.edit().putBoolean(PreferenceConstants.USE_PROXY, true).apply();
mPreferences
.edit()
.putBoolean(PreferenceConstants.USE_PROXY, true)
.apply();
initializeTor ();
initializeTor();
break;
case DialogInterface.BUTTON_NEGATIVE:
mPreferences.edit().putBoolean(PreferenceConstants.USE_PROXY, false).apply();
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;
}
@ -500,15 +508,25 @@ public class BrowserActivity extends Activity implements BrowserController { @@ -500,15 +508,25 @@ public class BrowserActivity extends Activity implements BrowserController {
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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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(
@ -2133,15 +2172,13 @@ public class BrowserActivity extends Activity implements BrowserController { @@ -2133,15 +2172,13 @@ public class BrowserActivity extends Activity implements BrowserController {
if (mCurrentView.getWebView() != null) {
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) {
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE: {
newTab(url, false);
@ -2185,8 +2222,7 @@ public class BrowserActivity extends Activity implements BrowserController { @@ -2185,8 +2222,7 @@ public class BrowserActivity extends Activity implements BrowserController {
} else {
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE: {
newTab(url, false);
@ -2198,8 +2234,8 @@ public class BrowserActivity extends Activity implements BrowserController { @@ -2198,8 +2234,8 @@ public class BrowserActivity extends Activity implements BrowserController {
}
case DialogInterface.BUTTON_NEUTRAL: {
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText(
"label", url);
ClipData clip = ClipData.newPlainText("label",
url);
clipboard.setPrimaryClip(clip);
break;
@ -2242,8 +2278,7 @@ public class BrowserActivity extends Activity implements BrowserController { @@ -2242,8 +2278,7 @@ public class BrowserActivity extends Activity implements BrowserController {
}
case DialogInterface.BUTTON_NEUTRAL: {
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("label",
url);
ClipData clip = ClipData.newPlainText("label", url);
clipboard.setPrimaryClip(clip);
break;
@ -2252,26 +2287,21 @@ public class BrowserActivity extends Activity implements BrowserController { @@ -2252,26 +2287,21 @@ public class BrowserActivity extends Activity implements BrowserController {
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(
mActivity); // dialog
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); // dialog
builder.setTitle(url)
.setMessage(
getResources().getString(
R.string.dialog_link))
getResources().getString(R.string.dialog_link))
.setPositiveButton(
getResources().getString(
R.string.action_new_tab),
dialogClickListener)
.setNegativeButton(
getResources().getString(
R.string.action_open),
getResources().getString(R.string.action_open),
dialogClickListener)
.setNeutralButton(
getResources().getString(
R.string.action_copy),
getResources().getString(R.string.action_copy),
dialogClickListener).show();
}
}
} else if (result != null) {
if (result.getExtra() != null) {
final String newUrl = result.getExtra();
@ -2419,6 +2449,11 @@ public class BrowserActivity extends Activity implements BrowserController { @@ -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) {

1
src/acr/browser/lightning/Constants.java

@ -34,5 +34,6 @@ public class Constants { @@ -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;
}

2200
src/acr/browser/lightning/IncognitoActivity.java

File diff suppressed because it is too large Load Diff

2
src/acr/browser/lightning/LightningDownloadListener.java

@ -44,7 +44,7 @@ public class LightningDownloadListener implements DownloadListener { @@ -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);
}

116
src/acr/browser/lightning/LightningView.java

@ -21,6 +21,7 @@ import org.apache.http.util.ByteArrayBuffer; @@ -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;
@ -76,7 +77,8 @@ public class LightningView { @@ -76,7 +77,8 @@ public class LightningView {
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);
@ -552,7 +554,6 @@ public class LightningView { @@ -552,7 +554,6 @@ public class LightningView {
return "";
}
public class LightningWebClient extends WebViewClient {
Context mActivity;
@ -572,7 +573,8 @@ public class LightningView { @@ -572,7 +573,8 @@ public class LightningView {
return response;
}
boolean useProxy = mPreferences.getBoolean(PreferenceConstants.USE_PROXY, false);
boolean useProxy = mPreferences.getBoolean(
PreferenceConstants.USE_PROXY, false);
boolean mDoLeakHardening = false;
if (!useProxy)
@ -581,26 +583,29 @@ public class LightningView { @@ -581,26 +583,29 @@ public class LightningView {
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("User-Agent",
mSettings.getUserAgentString());
//conn.setRequestProperty("Transfer-Encoding", "chunked");
//conn.setUseCaches(false);
// conn.setRequestProperty("Transfer-Encoding", "chunked");
// conn.setUseCaches(false);
final int bufferSize = 1024 * 32;
conn.setChunkedStreamingMode(bufferSize);
@ -609,16 +614,13 @@ public class LightningView { @@ -609,16 +614,13 @@ public class LightningView {
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();
}
}
@ -626,18 +628,18 @@ public class LightningView { @@ -626,18 +628,18 @@ public class LightningView {
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());
BufferedInputStream bis = new BufferedInputStream(
conn.getInputStream());
ByteArrayBuffer baf = new ByteArrayBuffer(connLen);
int read = 0;
int bufSize = 2048;
byte[] buffer = new byte[bufSize];
while(true){
while (true) {
read = bis.read(buffer);
if(read==-1){
if (read == -1) {
break;
}
baf.append(buffer, 0, read);
@ -646,33 +648,35 @@ public class LightningView { @@ -646,33 +648,35 @@ public class LightningView {
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(
@ -734,7 +738,7 @@ public class LightningView { @@ -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 { @@ -876,7 +880,11 @@ public class LightningView {
return false;
}
if (intent != null) {
try {
mActivity.startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.e(Constants.LOGTAG, "ActivityNotFoundException");
}
return true;
}
}
@ -996,17 +1004,15 @@ public class LightningView { @@ -996,17 +1004,15 @@ public class LightningView {
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
if (view instanceof FrameLayout){
if (view instanceof FrameLayout) {
FrameLayout frame = (FrameLayout) view;
if (frame.getFocusedChild() instanceof VideoView){
if (frame.getFocusedChild() instanceof VideoView) {
VideoView video = (VideoView) frame.getFocusedChild();
video.stopPlayback();
frame.removeView(video);
video.setVisibility(View.GONE);
}
}
else
{
} else {
Activity activity = mBrowserController.getActivity();
mBrowserController.onShowCustomView(view,
activity.getRequestedOrientation(), callback);
@ -1021,17 +1027,15 @@ public class LightningView { @@ -1021,17 +1027,15 @@ public class LightningView {
public void onShowCustomView(View view, int requestedOrientation,
CustomViewCallback callback) {
if (view instanceof FrameLayout){
if (view instanceof FrameLayout) {
FrameLayout frame = (FrameLayout) view;
if (frame.getFocusedChild() instanceof VideoView){
if (frame.getFocusedChild() instanceof VideoView) {
VideoView video = (VideoView) frame.getFocusedChild();
video.stopPlayback();
frame.removeView(video);
video.setVisibility(View.GONE);
}
}
else
{
} else {
mBrowserController.onShowCustomView(view, requestedOrientation,
callback);

77
src/acr/browser/lightning/MainActivity.java

@ -0,0 +1,77 @@ @@ -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);
}
}

2
src/acr/browser/lightning/Utils.java

@ -30,7 +30,7 @@ public class Utils { @@ -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…
Cancel
Save