Browse Source
- added ability to have the browser ignore old tabs you closed when long-pressing the back button - layout tweaksmaster
Anthony Restaino
12 years ago
16 changed files with 359 additions and 42 deletions
Before Width: | Height: | Size: 987 B After Width: | Height: | Size: 976 B |
Before Width: | Height: | Size: 943 B After Width: | Height: | Size: 936 B |
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
package acr.browser.barebones.utilities; |
||||
|
||||
public class BookmarkPageVariables { |
||||
public static final String Heading = "<!DOCTYPE html><html xmlns=\"http://www.w3.org/1999/xhtml\">" |
||||
+ "<head><meta content=\"en-us\" http-equiv=\"Content-Language\" /><meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\" />" |
||||
+ "<title>Bookmarks</title></head><style>" |
||||
+ "div.shadow{-moz-box-shadow: 0px 0px 6px #111;-webkit-box-shadow: 0px 0px 6px #111;box-shadow: 0px 0px 6px #111;}" |
||||
+ "body{color: gray;text-size: 10px}" |
||||
+ "div {vertical-align: middle;background-color: #ffffff;}" |
||||
+ "div.clickable {position:relative;}" |
||||
+ "p.font{font-size: 1em;font-family: \"Lucida Console\"}" |
||||
+ "div.clickable a {position:absolute;width:100%;height:100%;top:0;left:0;text-decoration:none; z-index:10; background-color:white;opacity: 0; filter: alpha(opacity=1);}" |
||||
+ "div.space {height: 0.7em;}" |
||||
+ "p{padding-top: 0.5em;padding-bottom: 0.5em;padding-right: 0.5em;padding-left: 0.5em;}" |
||||
+ "img{padding-left: 0em;padding-right: 0.5em;}" |
||||
+ "</style><body bgcolor = #f2f2f2>"; |
||||
public static final String Part1 = "<div class=\"clickable\">" |
||||
+ "<div class=\"shadow\">" + "<p class=\"font\">" + "<a href=\""; |
||||
public static final String Part2 = "\"></a>"+ |
||||
"<img height=\"15px\" width=\"15px\" src='https://www.google.com/s2/favicons?domain="; |
||||
public static final String Part3 = "'/>"; |
||||
public static final String Part4 = "</p></div></div>"; |
||||
public static final String End = "</body></html>"; |
||||
} |
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
package acr.browser.barebones.utilities; |
||||
|
||||
import android.os.Environment; |
||||
|
||||
|
||||
public class FinalVariables { |
||||
|
||||
public static final int MAX_TABS = 5; |
||||
public static final int MAX_BOOKMARKS = 50; |
||||
public static final boolean PAID_VERSION = false; |
||||
public static final String DESKTOP_USER_AGENT = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/20 Safari/537.17"; |
||||
public static final String MOBILE_USER_AGENT = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7"; |
||||
public static final int API = android.os.Build.VERSION.SDK_INT; |
||||
public static final String YAHOO_SEARCH = "http://search.yahoo.com/search?p="; |
||||
public static final String GOOGLE_SEARCH = "https://www.google.com/search?client=lightning&q="; |
||||
public static final String BING_SEARCH = "http://www.bing.com/search?q="; |
||||
public static final String DUCK_SEARCH = "https://duckduckgo.com/?t=lightning&q="; |
||||
public static final String STARTPAGE_SEARCH = "https://startpage.com/do/metasearch.pl?language=english&cat=web&query="; |
||||
public static final String HOMEPAGE = "https://www.google.com/"; |
||||
public static final String SETTINGS_INTENT = "android.intent.action.SETTINGS"; |
||||
public static final String INCOGNITO_INTENT = "android.intent.action.BAREBONESINCOGNITO"; |
||||
public static final String DOWNLOAD_LOCATION = Environment.getExternalStorageDirectory().toString()+Environment.DIRECTORY_DOWNLOADS; |
||||
|
||||
|
||||
|
||||
} |
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
package acr.browser.barebones.utilities; |
||||
|
||||
public class HistoryPageVariables { |
||||
public static final String Heading = "<!DOCTYPE html><html xmlns=\"http://www.w3.org/1999/xhtml\">" |
||||
+ "<head><meta content=\"en-us\" http-equiv=\"Content-Language\" /><meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\" /><title>History</title></head><style>" |
||||
+ "div.shadow {-moz-box-shadow: 0px 0px 6px #111;-webkit-box-shadow: 0px 0px 6px #111;box-shadow: 0px 0px 6px #111;}" |
||||
+ "body{color: gray;text-size: 10px}div.space {height: 0.7em;} div.extra{text-align: center;}div {vertical-align: middle;}" |
||||
+ "div {background-color: #ffffff;}div.clickable {position:relative;}p.black{color: black;font-size: 1em;font-family: \"Lucida Console\"}" |
||||
+ "p.font{font-size: 1em;font-family: \"Lucida Console\"}p.black{padding-left: 0.5em;padding-right: 0.5em;padding-top: 0.5em;padding-bottom: 0em;}" |
||||
+ "p.font{padding-left: 0.5em;padding-right: 0.5em;padding-top: 0em;padding-bottom: 0.5em;}" |
||||
+ "div.clickable a {position:absolute; width:100%;height:100%;top:0;left:0;text-decoration:none; z-index:10; background-color:white;opacity: 0;filter: alpha(opacity=1);}" |
||||
+ "</style><body bgcolor = #f2f2f2>"; |
||||
|
||||
public static final String Part1 = "<div class=\"clickable\"><div class=\"shadow\"><a href=\""; |
||||
public static final String Part2 = "\"></a><p class=\"black\">"; |
||||
public static final String Part3 = "</p><p class=\"font\">"; |
||||
public static final String Part4 = "</p></div></div>"; |
||||
public static final String End = "</body></html>"; |
||||
} |
@ -0,0 +1,180 @@
@@ -0,0 +1,180 @@
|
||||
package acr.browser.barebones.utilities; |
||||
|
||||
import java.io.BufferedReader; |
||||
import java.io.BufferedWriter; |
||||
import java.io.File; |
||||
import java.io.FileNotFoundException; |
||||
import java.io.FileReader; |
||||
import java.io.FileWriter; |
||||
import java.io.IOException; |
||||
|
||||
import acr.browser.barebones.databases.DatabaseHandler; |
||||
import acr.browser.barebones.databases.HistoryItem; |
||||
import android.annotation.SuppressLint; |
||||
import android.annotation.TargetApi; |
||||
import android.app.AlertDialog; |
||||
import android.app.DownloadManager; |
||||
import android.content.ContentResolver; |
||||
import android.content.Context; |
||||
import android.content.DialogInterface; |
||||
import android.database.Cursor; |
||||
import android.database.DatabaseUtils; |
||||
import android.database.sqlite.SQLiteDatabase; |
||||
import android.database.sqlite.SQLiteException; |
||||
import android.net.Uri; |
||||
import android.os.Build; |
||||
import android.os.Environment; |
||||
import android.provider.Browser; |
||||
import android.util.Log; |
||||
import android.webkit.URLUtil; |
||||
import android.widget.Toast; |
||||
|
||||
|
||||
|
||||
public class Utils { |
||||
|
||||
public static DatabaseHandler historyHandler; |
||||
public static SQLiteDatabase history; |
||||
|
||||
public static void createInformativeDialog(Context context, String title, |
||||
String message) { |
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context); |
||||
builder.setTitle(title); |
||||
builder.setMessage(message) |
||||
.setCancelable(true) |
||||
.setPositiveButton("Ok", |
||||
new DialogInterface.OnClickListener() { |
||||
@Override |
||||
public void onClick(DialogInterface dialog, int id) { |
||||
} |
||||
}); |
||||
AlertDialog alert = builder.create(); |
||||
alert.show(); |
||||
} |
||||
|
||||
public static void addBookmark(Context context, String title, String url) { |
||||
File book = new File(context.getFilesDir(), "bookmarks"); |
||||
File bookUrl = new File(context.getFilesDir(), "bookurl"); |
||||
try { |
||||
BufferedReader readUrlRead = new BufferedReader(new FileReader( |
||||
bookUrl)); |
||||
String u; |
||||
int n = 0; |
||||
while ((u = readUrlRead.readLine()) != null |
||||
&& n < FinalVariables.MAX_BOOKMARKS) { |
||||
if (u.contentEquals(url)) { |
||||
readUrlRead.close(); |
||||
return; |
||||
} |
||||
n++; |
||||
} |
||||
readUrlRead.close(); |
||||
|
||||
} catch (FileNotFoundException ignored) { |
||||
} catch (IOException ignored) { |
||||
} catch (NullPointerException ignored) { |
||||
} |
||||
try { |
||||
BufferedWriter bookWriter = new BufferedWriter(new FileWriter(book, |
||||
true)); |
||||
BufferedWriter urlWriter = new BufferedWriter(new FileWriter( |
||||
bookUrl, true)); |
||||
bookWriter.write(title); |
||||
urlWriter.write(url); |
||||
bookWriter.newLine(); |
||||
urlWriter.newLine(); |
||||
bookWriter.close(); |
||||
urlWriter.close(); |
||||
} catch (FileNotFoundException ignored) { |
||||
} catch (IOException ignored) { |
||||
} catch (NullPointerException ignored) { |
||||
} |
||||
} |
||||
|
||||
public static void updateHistory(final Context context, |
||||
final ContentResolver content, final boolean noStockBrowser, |
||||
final String url, final String title) { |
||||
Runnable update = new Runnable() { |
||||
@Override |
||||
public void run() { |
||||
if (!noStockBrowser) { |
||||
try { |
||||
Browser.updateVisitedHistory(content, url, true); |
||||
} catch (NullPointerException ignored) { |
||||
} |
||||
} |
||||
try { |
||||
StringBuilder sb = new StringBuilder("url" + " = "); |
||||
DatabaseUtils.appendEscapedSQLString(sb, url); |
||||
historyHandler = new DatabaseHandler( |
||||
context); |
||||
history = historyHandler.getReadableDatabase(); |
||||
Cursor cursor = history.query("history", new String[] { "id", |
||||
"url", "title" }, sb.toString(), null, null, null, |
||||
null); |
||||
if (!cursor.moveToFirst()) { |
||||
historyHandler.addHistoryItem(new HistoryItem(url, |
||||
title)); |
||||
} else { |
||||
historyHandler.delete(url); |
||||
historyHandler.addHistoryItem(new HistoryItem(url, |
||||
title)); |
||||
} |
||||
historyHandler.close(); |
||||
cursor.close(); |
||||
history.close(); |
||||
} catch (IllegalStateException e) { |
||||
Log.e("Barebones", "IllegalStateException in updateHistory"); |
||||
} catch (NullPointerException e) { |
||||
Log.e("Barebones", "NullPointerException in updateHistory"); |
||||
} catch (SQLiteException e) { |
||||
Log.e("Barebones", "SQLiteException in updateHistory"); |
||||
} |
||||
} |
||||
}; |
||||
if (url != null) { |
||||
if (!url.startsWith("file://")) { |
||||
new Thread(update).start(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@TargetApi(Build.VERSION_CODES.GINGERBREAD) |
||||
public static void downloadFile(final Context context, final String url, final String contentDisposition, final String mimetype){ |
||||
try { |
||||
Thread downloader = new Thread(new Runnable() { |
||||
@SuppressLint("InlinedApi") |
||||
@Override |
||||
public void run() { |
||||
DownloadManager download = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); |
||||
Uri nice = Uri.parse(url); |
||||
DownloadManager.Request it = new DownloadManager.Request( |
||||
nice); |
||||
String fileName = URLUtil.guessFileName(url, |
||||
contentDisposition, mimetype); |
||||
if (FinalVariables.API >= 11) { |
||||
it.allowScanningByMediaScanner(); |
||||
it.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); |
||||
} |
||||
|
||||
it.setDestinationInExternalPublicDir( |
||||
Environment.DIRECTORY_DOWNLOADS, fileName); |
||||
Log.i("Barebones", "Downloading" + fileName); |
||||
download.enqueue(it); |
||||
} |
||||
}); |
||||
downloader.run(); |
||||
} catch (NullPointerException e) { |
||||
Log.e("Barebones", "Problem downloading"); |
||||
Toast.makeText(context, "Error Downloading File", |
||||
Toast.LENGTH_SHORT).show(); |
||||
} catch (IllegalArgumentException e) { |
||||
Log.e("Barebones", "Problem downloading"); |
||||
Toast.makeText(context, "Error Downloading File", |
||||
Toast.LENGTH_SHORT).show(); |
||||
} catch (SecurityException ignored) { |
||||
|
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue