diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 68b9224..43ad229 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="53" + android:versionName="2.5.0.11" > - + @@ -114,7 +114,7 @@ android:configChanges="orientation|screenSize|keyboardHidden|keyboard" android:label="@string/title_activity_advanced_settings" > - + diff --git a/ic_launcher.png b/ic_launcher.png index 52fa9d0..5ef2ab5 100644 Binary files a/ic_launcher.png and b/ic_launcher.png differ diff --git a/ic_launcher_small.png b/ic_launcher_small.png index 8404e38..89b702f 100644 Binary files a/ic_launcher_small.png and b/ic_launcher_small.png differ diff --git a/proguard-project.txt b/proguard-project.txt new file mode 100644 index 0000000..39a2e09 --- /dev/null +++ b/proguard-project.txt @@ -0,0 +1,69 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +-keepclassmembers class fqcn.of.javascript.interface.for.webview { + public *; +} + +-keep class acr.browser.barebones.webviewclasses.CustomChromeClient{ + public *; + private *; + protected *; +} + +-keep class acr.browser.barebones.webviewclasses.CustomWebViewClient{ + public *; + private *; + protected *; +} + +-keep class acr.browser.barebones.customwebview.CustomWebView{ + public *; + private *; + protected *; +} + +-keep class acr.browser.barebones.activities.BrowserActivity{ + public void browserSettings(...); + public void makeTab(...); + public void newTab(...); + public void onLongClick(...); +} + +-keep class acr.browser.barebones.incognitoclasses.IncognitoChromeClient{ + public *; + private *; + protected *; +} + +-keep class acr.browser.barebones.incognitoclasses.IncognitoWebViewClient{ + public *; + private *; + protected *; +} + +-keep class acr.browser.barebones.customwebview.IncognitoWebView{ + public *; + private *; + protected *; +} + +-keep class acr.browser.barebones.activities.IncognitoModeActivity{ + public void browserSettings(...); + public void makeTab(...); + public void newTab(...); +} diff --git a/res/drawable-hdpi/ic_launcher.png b/res/drawable-hdpi/ic_launcher.png index 4854953..b7a46c4 100644 Binary files a/res/drawable-hdpi/ic_launcher.png and b/res/drawable-hdpi/ic_launcher.png differ diff --git a/res/drawable-xhdpi/ic_launcher.png b/res/drawable-xhdpi/ic_launcher.png index 445b370..8a6168a 100644 Binary files a/res/drawable-xhdpi/ic_launcher.png and b/res/drawable-xhdpi/ic_launcher.png differ diff --git a/res/drawable-xhdpi/progress_bar.9.png b/res/drawable-xhdpi/progress_bar.9.png new file mode 100644 index 0000000..b02e89b Binary files /dev/null and b/res/drawable-xhdpi/progress_bar.9.png differ diff --git a/res/drawable-xhdpi/progress_bar_bg.9.png b/res/drawable-xhdpi/progress_bar_bg.9.png new file mode 100644 index 0000000..daca8b7 Binary files /dev/null and b/res/drawable-xhdpi/progress_bar_bg.9.png differ diff --git a/res/drawable-xxhdpi/ic_launcher.png b/res/drawable-xxhdpi/ic_launcher.png index 75728fd..7df2cf1 100644 Binary files a/res/drawable-xxhdpi/ic_launcher.png and b/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/res/drawable/progress.xml b/res/drawable/progress.xml new file mode 100644 index 0000000..a59c866 --- /dev/null +++ b/res/drawable/progress.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/activity_main.xml b/res/layout/activity_main.xml index 3dcf6f8..52a065c 100644 --- a/res/layout/activity_main.xml +++ b/res/layout/activity_main.xml @@ -151,5 +151,18 @@ android:layout_below="@+id/urlBar" > + + \ No newline at end of file diff --git a/res/layout/advanced_settings.xml b/res/layout/advanced_settings.xml index b9436c2..8d4afd2 100644 --- a/res/layout/advanced_settings.xml +++ b/res/layout/advanced_settings.xml @@ -370,6 +370,30 @@ android:layout_alignParentRight="true" android:layout_centerVertical="true"/> + + + + + + + + + + + + + + android:textAppearance="?android:attr/textAppearanceMedium" /> + + + Lightning + Google + Taray�c� ayarlar� + Konum eri�imi + Parolar�n�z� kaydetme + Kullan�c� aray�z� + Ge�mi�i temizle + Bana e-posta + Adobe Flash aktif + Mobil G�r�n�m + Masa�st� G�r�n�m + �zel kullan�c� arac�s� olarak g�r�nt�leme + Ana sayfa + Ayarlar sadece yeni sekmeler i�in ge�erli + Tam ekran modu + JavaScript aktif + Kaybedilen sekmeleri geri y�kle + Ayarlar + Y�kleme Yeri + Geli�mi� Ayarlar + Kaynak kodu + Lisans + github.com/anthonycr/Lightning-Browser + Apache License 2.0 + YeniAyarlar + Ayarlar + Uygulama Versiyonu + ��k��ta �nbelle�i temizleme + Metin ak���n� etkinle�tirme + Resimleri engelleme + Siteleri yeni pencerede a�ma + �erezleri etkinle�tirme + Taray�c� yer imlerini i�e aktarma + Metin boyutu + Geli�mi�Ayarlar + Hello world! + (�nerilen) + (Web siteleri garip g�r�nebilir) + Arama Motoru + Arama + Geni� g�r�n�m kullanma + Genel bak�� modunda sayfalar� y�kleme + Kaybolan pencereleri ba�lang��ta y�kleme + Ge�mi� + Yer imi ekle + Yer imleri + Payla� + Ayarlar + Gizli sekme + Yeni pencere + (Hi�bir stok taray�c� tespit edilemedi) + (Desteklenen stok taray�c� tespit edildi) + + \ No newline at end of file diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml index 092b80b..bc61999 100644 --- a/res/values-zh-rCN/strings.xml +++ b/res/values-zh-rCN/strings.xml @@ -54,4 +54,4 @@ (没有检测到系统自带浏览器) (检测到系统自带浏览器) - + \ No newline at end of file diff --git a/res/values-zh-rTW/strings.xml b/res/values-zh-rTW/strings.xml index 25a8334..9129861 100644 --- a/res/values-zh-rTW/strings.xml +++ b/res/values-zh-rTW/strings.xml @@ -1,26 +1,57 @@ + Lightning Google - 瀏覽器設定 - 允許網頁存取您的位置資訊 - 儲存密碼 - 使用者代理 - 退出時清除歷史記錄(自動清理緩存) - 電郵給開發者 - 啓用 Adobe Flash(若已安裝) - 以手機版檢視 - 以電腦桌面版檢視 - 自定義使用者代理 + 瀏覽器設置 + 允許站點訪問地理位置 + 保存密碼 + User Agent + 清空歷史記錄 + 郵件開發者 + 啟用 Adobe Flash + 作為移動設備訪問 + 作為桌面設備訪問 + 自定義 User Agent 首頁 - 設定僅套用於新的標簽頁 - 啓用全螢幕模式 - 啓用 JavaScript - History - 加入到書簽 - 我的書簽 + 設置僅將應用於新標簽頁 + 啟用全屏模式 + 啟用 JavaScript + 恢復丟失標簽 + 設置 + 下載位置 + 高級設置 + 源碼 + 許可證 + github.com/anthonycr/Lightning-Browser + Apache License 2.0 + NewSettings + 設置 + 應用版本 + 退出時清理緩存 + 啟用文本重排 + 屏蔽網頁圖像 + 允許站點打開新窗口 + 啟用 Cookies + 從瀏覽器中導入書簽 + 頁面文本尺寸 + AdvancedSettings + Hello world! + (推薦) + (部分網頁可能看起來很奇怪) + 搜索引擎 + 搜索 + 使用寬視圖 + 使用概覽模式載入頁面 + 啟動時恢復丟失頁面 + 歷史記錄 + 添加書簽 + 書簽列表 分享頁面 - 設定 - Incognito tab - New tab - + 應用設置 + 隱身標簽 + 新建標簽 + (尚未檢測到原生瀏覽器) + (檢測到已支持的原生瀏覽器) + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 974ccca..d775be7 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -53,5 +53,7 @@ New tab (No stock browser detected) (Supported stock browser detected) + Hide status bar while browsing + Clear browser cookies \ No newline at end of file diff --git a/src/acr/browser/barebones/activities/AdvancedSettingsActivity.java b/src/acr/browser/barebones/activities/AdvancedSettingsActivity.java index d73c24b..dfe5290 100644 --- a/src/acr/browser/barebones/activities/AdvancedSettingsActivity.java +++ b/src/acr/browser/barebones/activities/AdvancedSettingsActivity.java @@ -3,10 +3,9 @@ package acr.browser.barebones.activities; import java.io.File; import acr.browser.barebones.R; -import acr.browser.barebones.utilities.BookmarkPageVariables; import acr.browser.barebones.utilities.FinalVariables; import acr.browser.barebones.utilities.Utils; -import acr.browser.barebones.activities.BarebonesActivity; +import acr.browser.barebones.activities.BrowserActivity; import android.os.Bundle; import android.os.Handler; import android.os.Message; @@ -17,9 +16,8 @@ import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; import android.database.Cursor; -import android.util.Log; -import android.view.Menu; import android.view.View; +import android.view.WindowManager; import android.view.View.OnClickListener; import android.webkit.CookieManager; import android.webkit.CookieSyncManager; @@ -31,8 +29,8 @@ import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; -import android.widget.Toast; +@SuppressWarnings("deprecation") public class AdvancedSettingsActivity extends Activity { // settings variables @@ -41,8 +39,8 @@ public class AdvancedSettingsActivity extends Activity { static final String preferences = "settings"; static SharedPreferences settings; static SharedPreferences.Editor edit; - static RelativeLayout r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13; - static CheckBox cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, cb9, cb10; + static RelativeLayout r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15; + static CheckBox cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, cb9, cb10, cb11; static Context CONTEXT; Handler messageHandler; @@ -51,6 +49,10 @@ public class AdvancedSettingsActivity extends Activity { super.onCreate(savedInstanceState); setContentView(R.layout.advanced_settings); settings = getSharedPreferences(preferences, 0); + if (settings.getBoolean("hidestatus", false)) { + getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN); + } edit = settings.edit(); CONTEXT = this; initialize(); @@ -72,6 +74,8 @@ public class AdvancedSettingsActivity extends Activity { r11 = (RelativeLayout) findViewById(R.id.r11); r12 = (RelativeLayout) findViewById(R.id.r12); r13 = (RelativeLayout) findViewById(R.id.r13); + r14 = (RelativeLayout) findViewById(R.id.r14); + r15 = (RelativeLayout) findViewById(R.id.r15); cb1 = (CheckBox) findViewById(R.id.cb1); cb2 = (CheckBox) findViewById(R.id.cb2); @@ -83,6 +87,7 @@ public class AdvancedSettingsActivity extends Activity { cb8 = (CheckBox) findViewById(R.id.cb8); cb9 = (CheckBox) findViewById(R.id.cb9); cb10 = (CheckBox) findViewById(R.id.cb10); + cb11 = (CheckBox) findViewById(R.id.cb11); cb1.setChecked(settings.getBoolean("passwords", true)); cb2.setChecked(settings.getBoolean("cache", false)); @@ -94,6 +99,7 @@ public class AdvancedSettingsActivity extends Activity { cb8.setChecked(settings.getBoolean("wideviewport", true)); cb9.setChecked(settings.getBoolean("overviewmode", true)); cb10.setChecked(settings.getBoolean("restoreclosed", true)); + cb11.setChecked(settings.getBoolean("hidestatus", false)); r1(r1); r2(r2); @@ -108,6 +114,8 @@ public class AdvancedSettingsActivity extends Activity { r11(r11); r12(r12); r13(r13); + r14(r14); + r15(r15); cb1(cb1); cb2(cb2); cb3(cb3); @@ -118,11 +126,12 @@ public class AdvancedSettingsActivity extends Activity { cb8(cb8); cb9(cb9); cb10(cb10); + cb11(cb11); back(); TextView importBookmarks = (TextView)findViewById(R.id.isImportAvailable); - if(BarebonesActivity.noStockBrowser){ + if(BrowserActivity.noStockBrowser){ importBookmarks.setText(getResources().getString(R.string.stock_browser_unavailable)); } else{ @@ -140,6 +149,9 @@ public class AdvancedSettingsActivity extends Activity { case 1: Utils.showToast(CONTEXT, "History Cleared"); break; + case 2: + Utils.showToast(CONTEXT, "Cookies Cleared"); + break; } super.handleMessage(msg); } @@ -286,6 +298,19 @@ public class AdvancedSettingsActivity extends Activity { }); } + + void cb11(CheckBox view) { + view.setOnCheckedChangeListener(new OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, + boolean isChecked) { + edit.putBoolean("hidestatus", isChecked); + edit.commit(); + } + + }); + } void r1(RelativeLayout view) { view.setOnClickListener(new OnClickListener() { @@ -446,20 +471,71 @@ public class AdvancedSettingsActivity extends Activity { @Override public void onClick(View v) { - // TODO Auto-generated method stub cb10.setChecked(!cb10.isChecked()); } }); } + void r14(RelativeLayout view) { + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + cb11.setChecked(!cb11.isChecked()); + } + + }); + } + + void r15(RelativeLayout view) { + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + AlertDialog.Builder builder = new AlertDialog.Builder( + AdvancedSettingsActivity.this); // dialog + builder.setTitle("Clear Cookies"); + builder.setMessage( + "Would you like to clear all browser cookies?") + .setPositiveButton("Yes", + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface arg0, + int arg1) { + Thread clear = new Thread( + new Runnable() { + + @Override + public void run() { + clearCookies(); + } + + }); + clear.start(); + } + + }) + .setNegativeButton("No", + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface arg0, + int arg1) { + + } + + }).show(); + } + + }); + } - @SuppressWarnings("deprecation") public void clearHistory() { CookieManager c = CookieManager.getInstance(); CookieSyncManager.createInstance(this); c.removeAllCookie(); AdvancedSettingsActivity.this.deleteDatabase("historyManager"); - BarebonesActivity.main[0].clearCache(true); WebViewDatabase m = WebViewDatabase .getInstance(AdvancedSettingsActivity.this); m.clearFormData(); @@ -468,7 +544,7 @@ public class AdvancedSettingsActivity extends Activity { m.clearUsernamePassword(); WebIconDatabase.getInstance().removeAllIcons(); } - if (!BarebonesActivity.noStockBrowser) { + if (!BrowserActivity.noStockBrowser) { try { Browser.clearHistory(getContentResolver()); } catch (NullPointerException ignored) { @@ -478,7 +554,12 @@ public class AdvancedSettingsActivity extends Activity { messageHandler.sendEmptyMessage(1); } - + public void clearCookies(){ + CookieManager c = CookieManager.getInstance(); + CookieSyncManager.createInstance(this); + c.removeAllCookie(); + messageHandler.sendEmptyMessage(2); + } void r9(RelativeLayout view) { @@ -559,7 +640,7 @@ public class AdvancedSettingsActivity extends Activity { } public void importFromStockBrowser() { - if (!BarebonesActivity.noStockBrowser) { + if (!BrowserActivity.noStockBrowser) { try { String[] proj = new String[] { Browser.BookmarkColumns.TITLE, Browser.BookmarkColumns.URL }; diff --git a/src/acr/browser/barebones/activities/BrowserActivity.java b/src/acr/browser/barebones/activities/BrowserActivity.java new file mode 100644 index 0000000..d367499 --- /dev/null +++ b/src/acr/browser/barebones/activities/BrowserActivity.java @@ -0,0 +1,2150 @@ +package acr.browser.barebones.activities; + +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 java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import acr.browser.barebones.R; +import acr.browser.barebones.customwebview.CustomWebView; +import acr.browser.barebones.databases.DatabaseHandler; +import acr.browser.barebones.databases.SpaceTokenizer; +import acr.browser.barebones.utilities.BookmarkPageVariables; +import acr.browser.barebones.utilities.FinalVariables; +import acr.browser.barebones.utilities.HistoryPageVariables; +import acr.browser.barebones.utilities.Utils; +import acr.browser.barebones.webviewclasses.CustomChromeClient; +import acr.browser.barebones.webviewclasses.CustomDownloadListener; +import acr.browser.barebones.webviewclasses.CustomWebViewClient; +import acr.browser.barebones.webviewclasses.WebPageLongClickListener; +import android.annotation.SuppressLint; +import android.app.Activity; +import android.app.AlertDialog; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteException; +import android.database.sqlite.SQLiteMisuseException; +import android.graphics.Bitmap; +import android.graphics.Rect; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.provider.Browser; +import android.text.TextUtils; +import android.util.DisplayMetrics; +import android.util.Log; +import android.view.Gravity; +import android.view.KeyEvent; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.MotionEvent; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.View.OnKeyListener; +import android.view.View.OnLongClickListener; +import android.view.View.OnTouchListener; +import android.view.WindowManager; +import android.view.animation.Animation; +import android.view.animation.Animation.AnimationListener; +import android.view.animation.AnimationUtils; +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; +import android.webkit.WebSettings; +import android.webkit.WebSettings.LayoutAlgorithm; +import android.webkit.WebSettings.PluginState; +import android.webkit.WebSettings.RenderPriority; +import android.webkit.WebView; +import android.webkit.WebView.HitTestResult; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.FrameLayout; +import android.widget.HorizontalScrollView; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.MultiAutoCompleteTextView; +import android.widget.PopupMenu; +import android.widget.PopupMenu.OnMenuItemClickListener; +import android.widget.ProgressBar; +import android.widget.RelativeLayout; +import android.widget.SimpleAdapter; +import android.widget.TextView; +import android.widget.TextView.OnEditorActionListener; +import android.widget.Toast; + +@SuppressWarnings("deprecation") +public class BrowserActivity extends Activity implements OnTouchListener { + + public static void generateHistory(final CustomWebView view, + final Context context) { + + Thread history = new Thread(new Runnable() { + + @Override + public void run() { + String historyHtml = HistoryPageVariables.Heading; + Cursor historyCursor = null; + String[][] h = new String[50][3]; + + try { + SQLiteDatabase s = historyHandler.getReadableDatabase(); + historyCursor = s.query("history", // URI + // of + columns, // Which columns to return + null, // Which rows to return (all rows) + null, // Selection arguments (none) + null, null, null); + + handler.sendEmptyMessage(1); + + } catch (SQLiteException ignored) { + } catch (NullPointerException ignored) { + } catch (IllegalStateException ignored) { + } + + list = new ArrayList>(); + try { + if (historyCursor != null) { + if (historyCursor.moveToLast()) { + // Variable for holding the retrieved URL + urlColumn = historyCursor.getColumnIndex("url"); + titleColumn = historyCursor.getColumnIndex("title"); + // Reference to the the column containing the URL + int n = 0; + do { + + h[n][0] = historyCursor.getString(urlColumn); + h[n][2] = h[n][0].substring(0, + Math.min(100, h[n][0].length())) + + "..."; + h[n][1] = historyCursor.getString(titleColumn); + historyHtml += (HistoryPageVariables.Part1 + + h[n][0] + HistoryPageVariables.Part2 + + h[n][1] + HistoryPageVariables.Part3 + + h[n][2] + HistoryPageVariables.Part4); + n++; + } while (n < 49 && historyCursor.moveToPrevious()); + } + } + } catch (SQLiteException ignored) { + } catch (NullPointerException ignored) { + } catch (IllegalStateException ignored) { + } + + historyHtml += BookmarkPageVariables.End; + File historyWebPage = new File(context.getFilesDir(), + "history.html"); + try { + FileWriter hWriter = new FileWriter(historyWebPage, false); + hWriter.write(historyHtml); + hWriter.close(); + } catch (IOException e) { + e.printStackTrace(); + } + if (uBar.isShown()) { + urlTitle[pageId].setText("History"); + setUrlText(""); + getUrl.setPadding(tenPad, 0, tenPad, 0); + } + + view.loadUrl("file://" + historyWebPage); + } + + }); + history.run(); + } + + public static void setUrlText(String url) { + if (url != null) { + if (!url.startsWith("file://")) { + getUrl.setText(url); + } else { + getUrl.setText(""); + } + } + } + + public static void removeView(WebView view) { + if (!showFullScreen) { + view.startAnimation(fadeOut); + } + background.removeView(view); + uBar.bringToFront(); + } + + private static BrowserActivity ACTIVITY; + + public static void deleteBookmark(String url) { + File book = new File(CONTEXT.getFilesDir(), "bookmarks"); + File bookUrl = new File(CONTEXT.getFilesDir(), "bookurl"); + int n = 0; + try { + BufferedWriter bookWriter = new BufferedWriter(new FileWriter(book)); + BufferedWriter urlWriter = new BufferedWriter(new FileWriter( + bookUrl)); + while (bUrl[n] != null && n < (MAX_BOOKMARKS - 1)) { + if (!bUrl[n].equalsIgnoreCase(url)) { + bookWriter.write(bTitle[n]); + urlWriter.write(bUrl[n]); + bookWriter.newLine(); + urlWriter.newLine(); + } + n++; + } + bookWriter.close(); + urlWriter.close(); + } catch (FileNotFoundException e) { + } catch (IOException e) { + } + for (int p = 0; p < MAX_BOOKMARKS; p++) { + bUrl[p] = null; + bTitle[p] = null; + } + try { + BufferedReader readBook = new BufferedReader(new FileReader(book)); + BufferedReader readUrl = new BufferedReader(new FileReader(bookUrl)); + String t, u; + int z = 0; + while ((t = readBook.readLine()) != null + && (u = readUrl.readLine()) != null && z < MAX_BOOKMARKS) { + bUrl[z] = u; + bTitle[z] = t; + z++; + } + readBook.close(); + readUrl.close(); + } catch (IOException ignored) { + } + openBookmarks(CONTEXT, main[pageId]); + } + + // variables to differentiate free from paid + public static final int MAX_TABS = FinalVariables.MAX_TABS; + public static final int MAX_BOOKMARKS = FinalVariables.MAX_BOOKMARKS; + public static final boolean PAID_VERSION = FinalVariables.PAID_VERSION; + + public static Context CONTEXT; + + public static final String HOMEPAGE = FinalVariables.HOMEPAGE; + public static String SEARCH; + + public static SimpleAdapter adapter; + public static MultiAutoCompleteTextView getUrl; + public static TextView[] urlTitle = new TextView[MAX_TABS]; + public static ProgressBar browserProgress; + public static final CustomWebView[] main = new CustomWebView[MAX_TABS]; + public static Rect bounds; + public static long timeTabPressed; + public static int[] tabOrder = new int[MAX_TABS]; + public static ValueCallback mUploadMessage; + public static ImageView refresh; + public static ProgressBar progressBar; + public static String defaultUser; + public static Drawable webpageOther; + public static Drawable incognitoPage; + public static Drawable exitTab; + public static long loadTime = 0; + public static int number; + public static int pageId = 0; + public static int agentPicker; + public static int enableFlash; + public static int height32; + public static int height; + public static int width; + public static int pixels; + public static int leftPad; + public static int rightPad; + public static final int API = FinalVariables.API; + public static int mShortAnimationDuration; + public static int id; + public static int tenPad; + public static int urlColumn; + public static int titleColumn; + public static int closeWindow; + public static boolean isPhone = false; + public static boolean allowLocation; + public static boolean savePasswords; + public static boolean deleteHistory; + public static boolean saveTabs; + public static boolean showFullScreen; + public static boolean noStockBrowser = true; + public static SharedPreferences settings; + public static SharedPreferences.Editor edit; + public static String desktop; + public static String mobile; + public static String user; + public static String urlA; + public static String title; + public static String[] memoryURL = new String[MAX_TABS]; + public static String[] bUrl = new String[MAX_BOOKMARKS]; + public static String[] bTitle = new String[MAX_BOOKMARKS]; + public static String[] columns; + public static String homepage; + public static final String preferences = "settings"; + + public static String[][] urlToLoad = new String[MAX_TABS][2]; + public static FrameLayout background; + public static RelativeLayout uBar; + public static HorizontalScrollView tabScroll; + public static Animation slideUp; + public static Animation slideDown; + public static Animation fadeOut; + public static Animation fadeIn; + + public static CookieManager cookieManager; + + public static Uri bookmarks; + public static List> list; + public static Map map; + + public static Handler handler, browserHandler; + + public static DatabaseHandler historyHandler; + + public static StringBuilder sb; + + public static Runnable update; + + public static SQLiteDatabase s; + + public static Drawable inactive; + + public static Drawable active; + + public static LinearLayout tabLayout; + + public static String[] GetArray(String input) { + return input.split("\\|\\$\\|SEPARATOR\\|\\$\\|"); + } + + @SuppressWarnings("unused") + public static void setFavicon(int id, Bitmap favicon) { + Drawable icon = null; + icon = new BitmapDrawable(null, favicon); + icon.setBounds(0, 0, width / 2, height / 2); + if (icon != null) { + urlTitle[id].setCompoundDrawables(icon, null, exitTab, null); + } else { + urlTitle[id] + .setCompoundDrawables(webpageOther, null, exitTab, null); + } + icon = null; + + } + + @SuppressLint("SetJavaScriptEnabled") + public static void browserSettings(Context context, CustomWebView view) { + WebSettings webViewSettings = view.getSettings(); + if (settings.getBoolean("java", true)) { + webViewSettings.setJavaScriptEnabled(true); + webViewSettings.setJavaScriptCanOpenWindowsAutomatically(true); + } + + if (API < 14) { + switch (settings.getInt("textsize", 3)) { + case 1: + webViewSettings.setTextSize(WebSettings.TextSize.LARGEST); + break; + case 2: + webViewSettings.setTextSize(WebSettings.TextSize.LARGER); + break; + case 3: + webViewSettings.setTextSize(WebSettings.TextSize.NORMAL); + break; + case 4: + webViewSettings.setTextSize(WebSettings.TextSize.SMALLER); + break; + case 5: + webViewSettings.setTextSize(WebSettings.TextSize.SMALLEST); + break; + } + + } else { + switch (settings.getInt("textsize", 3)) { + case 1: + webViewSettings.setTextZoom(200); + break; + case 2: + webViewSettings.setTextZoom(150); + break; + case 3: + webViewSettings.setTextZoom(100); + break; + case 4: + webViewSettings.setTextZoom(75); + break; + case 5: + webViewSettings.setTextZoom(50); + break; + } + } + webViewSettings.setSupportMultipleWindows(settings.getBoolean( + "newwindow", true)); + + switch (settings.getInt("enableflash", 0)) { + case 0: + break; + case 1: { + webViewSettings.setPluginState(PluginState.ON_DEMAND); + break; + } + case 2: { + webViewSettings.setPluginState(PluginState.ON); + break; + } + default: + break; + } + if (settings.getBoolean("passwords", false)) { + if (API < 18) { + webViewSettings.setSavePassword(true); + } + webViewSettings.setSaveFormData(true); + } + if (API < 18) { + try { + webViewSettings.setRenderPriority(RenderPriority.HIGH); + } catch (SecurityException ignored) { + + } + } + webViewSettings.setGeolocationEnabled(settings.getBoolean("location", + false)); + webViewSettings.setGeolocationDatabasePath(context.getFilesDir() + .getAbsolutePath()); + webViewSettings.setUseWideViewPort(settings.getBoolean("wideviewport", + true)); + webViewSettings.setLoadWithOverviewMode(settings.getBoolean( + "overviewmode", true)); + + if (settings.getBoolean("textreflow", false)) { + webViewSettings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS); + } else { + webViewSettings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); + } + + webViewSettings.setBlockNetworkImage(settings.getBoolean("blockimages", + false)); + webViewSettings.setLoadsImagesAutomatically(true); + + } + + void deleteTab(final int del) { + if (API >= 11) { + main[del].onPause(); + } + main[del].stopLoading(); + main[del].clearHistory(); + edit.putString("oldPage", urlToLoad[del][0]); + edit.commit(); + urlToLoad[del][0] = null; + urlToLoad[del][1] = null; + if (API < 16) { + urlTitle[del].setBackgroundDrawable(active); + } else { + urlTitle[del].setBackground(active); + } + + urlTitle[del].setPadding(leftPad, 0, rightPad, 0); + Animation yolo = AnimationUtils.loadAnimation(this, R.anim.down); + yolo.setAnimationListener(new AnimationListener() { + + @Override + public void onAnimationEnd(Animation animation) { + urlTitle[del].setVisibility(View.GONE); + findNewView(del); + main[del] = null; + } + + @Override + public void onAnimationRepeat(Animation animation) { + } + + @Override + public void onAnimationStart(Animation animation) { + } + + }); + urlTitle[del].startAnimation(yolo); + uBar.bringToFront(); + } + + void findNewView(int id) { + int leftId = id; + boolean right = false, left = false; + if (id == pageId) { + + if (main[id].isShown()) { + // background.removeView(main[id]); + removeView(main[id]); + } + for (; id <= (number - 1); id++) { + if (urlTitle[id].isShown()) { + background.addView(main[id]); + main[id].setVisibility(View.VISIBLE); + uBar.bringToFront(); + if (API < 16) { + urlTitle[id].setBackgroundDrawable(active); + } else { + urlTitle[id].setBackground(active); + } + urlTitle[id].setPadding(leftPad, 0, rightPad, 0); + pageId = id; + setUrlText(urlToLoad[pageId][0]); + getUrl.setPadding(tenPad, 0, tenPad, 0); + right = true; + if (main[id].getProgress() < 100) { + onProgressChanged(id, main[id].getProgress()); + refresh.setVisibility(View.INVISIBLE); + progressBar.setVisibility(View.VISIBLE); + } else { + onProgressChanged(id, main[id].getProgress()); + progressBar.setVisibility(View.GONE); + refresh.setVisibility(View.VISIBLE); + } + break; + } + + } + if (!right) { + for (; leftId >= 0; leftId--) { + + if (urlTitle[leftId].isShown()) { + background.addView(main[leftId]); + main[leftId].setVisibility(View.VISIBLE); + // uBar.bringToFront(); + if (API < 16) { + urlTitle[leftId].setBackgroundDrawable(active); + } else { + urlTitle[leftId].setBackground(active); + } + urlTitle[leftId].setPadding(leftPad, 0, rightPad, 0); + pageId = leftId; + setUrlText(urlToLoad[pageId][0]); + getUrl.setPadding(tenPad, 0, tenPad, 0); + left = true; + if (main[leftId].getProgress() < 100) { + refresh.setVisibility(View.INVISIBLE); + progressBar.setVisibility(View.VISIBLE); + onProgressChanged(leftId, main[leftId].getProgress()); + } else { + progressBar.setVisibility(View.GONE); + refresh.setVisibility(View.VISIBLE); + onProgressChanged(leftId, main[leftId].getProgress()); + } + break; + } + + } + + } + + } else { + right = left = true; + } + + if (!(right || left)) { + finish(); + } + uBar.bringToFront(); + tabScroll.smoothScrollTo(urlTitle[pageId].getLeft(), 0); + } + + @Override + public void onLowMemory() { + for (int n = 0; n < MAX_TABS; n++) { + if (n != pageId && main[n] != null) { + main[n].freeMemory(); + } + } + super.onLowMemory(); + } + + void enter() { + getUrl.setOnKeyListener(new OnKeyListener() { + + @Override + public boolean onKey(View arg0, int arg1, KeyEvent arg2) { + + switch (arg1) { + case KeyEvent.KEYCODE_ENTER: + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0); + searchTheWeb(getUrl.getText().toString(), CONTEXT); + return true; + default: + break; + } + return false; + } + + }); + getUrl.setOnEditorActionListener(new OnEditorActionListener() { + + @Override + public boolean onEditorAction(TextView arg0, int actionId, + KeyEvent arg2) { + if (actionId == EditorInfo.IME_ACTION_GO + || actionId == EditorInfo.IME_ACTION_DONE + || actionId == EditorInfo.IME_ACTION_NEXT + || actionId == EditorInfo.IME_ACTION_SEND + || actionId == EditorInfo.IME_ACTION_SEARCH + || (arg2.getAction() == KeyEvent.KEYCODE_ENTER)) { + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0); + searchTheWeb(getUrl.getText().toString(), CONTEXT); + return true; + } + return false; + } + + }); + } + + @SuppressLint("HandlerLeak") + void enterUrl() { + getUrl = (MultiAutoCompleteTextView) findViewById(R.id.enterUrl); + getUrl.setPadding(tenPad, 0, tenPad, 0); + getUrl.setTextColor(getResources().getColor(android.R.color.black)); + getUrl.setPadding(tenPad, 0, tenPad, 0); + getUrl.setBackgroundResource(R.drawable.book); + getUrl.setPadding(tenPad, 0, tenPad, 0); + handler = new Handler() { + + @Override + public void handleMessage(Message msg) { + + switch (msg.what) { + case 1: { + adapter = new SimpleAdapter(CONTEXT, list, + R.layout.two_line_autocomplete, new String[] { + "title", "url" }, new int[] { R.id.title, + R.id.url }); + + getUrl.setAdapter(adapter); + + break; + } + case 2: { + + break; + } + } + } + }; + + Thread updateAutoComplete = new Thread(new Runnable() { + + @Override + public void run() { + + Cursor c = null; + Cursor managedCursor = null; + columns = new String[] { "url", "title" }; + try { + + bookmarks = Browser.BOOKMARKS_URI; + c = getContentResolver().query(bookmarks, columns, null, + null, null); + } catch (SQLiteException ignored) { + } catch (IllegalStateException ignored) { + } catch (NullPointerException ignored) { + } + + if (c != null) { + noStockBrowser = false; + Log.i("Browser", "detected AOSP browser"); + } else { + noStockBrowser = true; + Log.e("Browser", "did not detect AOSP browser"); + } + if (c != null) { + c.close(); + } + try { + + managedCursor = null; + SQLiteDatabase s = historyHandler.getReadableDatabase(); + managedCursor = s.query("history", // URI + // of + columns, // Which columns to return + null, // Which rows to return (all rows) + null, // Selection arguments (none) + null, null, null); + + } catch (SQLiteException ignored) { + } catch (NullPointerException ignored) { + } catch (IllegalStateException ignored) { + } + + list = new ArrayList>(); + try { + if (managedCursor != null) { + + if (managedCursor.moveToLast()) { + + // Variable for holding the retrieved URL + + urlColumn = managedCursor.getColumnIndex("url"); + titleColumn = managedCursor.getColumnIndex("title"); + // Reference to the the column containing the URL + do { + urlA = managedCursor.getString(urlColumn); + title = managedCursor.getString(titleColumn); + map = new HashMap(); + map.put("title", title); + map.put("url", urlA); + list.add(map); + } while (managedCursor.moveToPrevious()); + } + } + handler.sendEmptyMessage(1); + } catch (SQLiteException ignored) { + } catch (NullPointerException ignored) { + } catch (IllegalStateException ignored) { + } + managedCursor.close(); + } + + }); + try { + updateAutoComplete.start(); + } catch (NullPointerException ignored) { + } catch (SQLiteMisuseException ignored) { + } catch (IllegalStateException ignored) { + } + + getUrl.setThreshold(1); + getUrl.setTokenizer(new SpaceTokenizer()); + getUrl.setOnItemClickListener(new OnItemClickListener() { + + @Override + public void onItemClick(AdapterView arg0, View arg1, int arg2, + long arg3) { + try { + String url; + url = ((TextView) arg1.findViewById(R.id.url)).getText() + .toString(); + getUrl.setText(url); + searchTheWeb(url, CONTEXT); + url = null; + getUrl.setPadding(tenPad, 0, tenPad, 0); + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0); + } catch (NullPointerException e) { + Log.e("Browser Error: ", + "NullPointerException on item click"); + } + } + + }); + + getUrl.setSelectAllOnFocus(true); // allows edittext to select all when + // clicked + } + + void back() { + ImageView exit = (ImageView) findViewById(R.id.exit); + exit.setBackgroundResource(R.drawable.button); + if (isPhone) { + RelativeLayout relativeLayout1 = (RelativeLayout) findViewById(R.id.relativeLayout1); + relativeLayout1.removeView(exit); + } + exit.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + + if (main[pageId].canGoBack()) { + main[pageId].goBack(); + } else { + deleteTab(pageId); + } + + } + + }); + exit.setOnLongClickListener(new OnLongClickListener() { + + @Override + public boolean onLongClick(View v) { + finish(); + return true; + } + + }); + + } + + @Override + public void finish() { + background.clearDisappearingChildren(); + tabScroll.clearDisappearingChildren(); + if (settings.getBoolean("cache", false)) { + main[pageId].clearCache(true); + Log.i("Lightning", "Cache Cleared"); + } + super.finish(); + } + + void forward() { + ImageView forward = (ImageView) findViewById(R.id.forward); + forward.setBackgroundResource(R.drawable.button); + if (isPhone) { + RelativeLayout relativeLayout1 = (RelativeLayout) findViewById(R.id.relativeLayout1); + relativeLayout1.removeView(forward); + } + forward.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + if (main[pageId].canGoForward()) { + main[pageId].goForward(); + } + } + + }); + } + + static void goBookmarks(Context context, CustomWebView view) { + File book = new File(context.getFilesDir(), "bookmarks"); + File bookUrl = new File(context.getFilesDir(), "bookurl"); + try { + BufferedReader readBook = new BufferedReader(new FileReader(book)); + BufferedReader readUrl = new BufferedReader(new FileReader(bookUrl)); + String t, u; + int n = 0; + while ((t = readBook.readLine()) != null + && (u = readUrl.readLine()) != null && n < MAX_BOOKMARKS) { + bUrl[n] = u; + bTitle[n] = t; + + n++; + } + readBook.close(); + readUrl.close(); + } catch (FileNotFoundException ignored) { + } catch (IOException ignored) { + } + openBookmarks(context, view); + } + + @SuppressLint("InlinedApi") + private void initialize() { + + DisplayMetrics metrics = new DisplayMetrics(); + getWindowManager().getDefaultDisplay().getMetrics(metrics); + historyHandler = new DatabaseHandler(this); + cookieManager = CookieManager.getInstance(); + CookieSyncManager.createInstance(CONTEXT); + cookieManager.setAcceptCookie(settings.getBoolean("cookies", true)); + + progressBar = (ProgressBar) findViewById(R.id.progressBar1); + browserProgress = (ProgressBar) findViewById(R.id.progressBar); + browserProgress.setVisibility(View.GONE); + + if (API >= 11) { + progressBar.setIndeterminateDrawable(getResources().getDrawable( + R.drawable.ics_animation)); + } else { + progressBar.setIndeterminateDrawable(getResources().getDrawable( + R.drawable.ginger_animation)); + } + + showFullScreen = settings.getBoolean("fullscreen", false); + uBar = (RelativeLayout) findViewById(R.id.urlBar); + RelativeLayout bg = (RelativeLayout) findViewById(R.id.background); + slideUp = AnimationUtils.loadAnimation(this, R.anim.slide_up); + slideDown = AnimationUtils.loadAnimation(this, R.anim.slide_down); + fadeOut = AnimationUtils.loadAnimation(this, android.R.anim.fade_out); + fadeOut.setDuration(250); + fadeIn = AnimationUtils.loadAnimation(this, android.R.anim.fade_in); + // mShortAnimationDuration = getResources().getInteger( + // android.R.integer.config_mediumAnimTime); + mShortAnimationDuration = 250; + slideUp.setAnimationListener(new AnimationListener() { + + @Override + public void onAnimationEnd(Animation arg0) { + + uBar.setVisibility(View.GONE); + } + + @Override + public void onAnimationRepeat(Animation arg0) { + + } + + @Override + public void onAnimationStart(Animation arg0) { + + } + + }); + slideDown.setAnimationListener(new AnimationListener() { + + @Override + public void onAnimationEnd(Animation animation) { + + } + + @Override + public void onAnimationRepeat(Animation animation) { + + } + + @Override + public void onAnimationStart(Animation animation) { + + uBar.setVisibility(View.VISIBLE); + } + + }); + + RelativeLayout refreshLayout = (RelativeLayout) findViewById(R.id.refreshLayout); + refreshLayout.setBackgroundResource(R.drawable.button); + + // user agent + if (API < 17) { + user = new WebView(CONTEXT).getSettings().getUserAgentString(); + } else { + user = WebSettings.getDefaultUserAgent(this); + } + + background = (FrameLayout) findViewById(R.id.holder); + defaultUser = user; // setting mobile user + // agent + mobile = FinalVariables.MOBILE_USER_AGENT; + desktop = FinalVariables.DESKTOP_USER_AGENT; // setting + // desktop user agent + + switch (settings.getInt("search", 1)) { + case 1: + SEARCH = FinalVariables.GOOGLE_SEARCH; + break; + case 2: + SEARCH = FinalVariables.BING_SEARCH; + break; + case 3: + SEARCH = FinalVariables.YAHOO_SEARCH; + break; + case 4: + SEARCH = FinalVariables.STARTPAGE_SEARCH; + break; + case 5: + SEARCH = FinalVariables.DUCK_SEARCH; + break; + case 6: + SEARCH = FinalVariables.BAIDU_SEARCH; + break; + case 7: + SEARCH = FinalVariables.YANDEX_SEARCH; + break; + } + + exitTab = getResources().getDrawable(R.drawable.stop); // user + // agent + homepage = settings.getString("home", HOMEPAGE); // initializing + // the + // stored + // homepage + // variable + allowLocation = settings.getBoolean("location", false); // initializing + // location + // variable + savePasswords = settings.getBoolean("passwords", false); // initializing + // save + // passwords + // variable + enableFlash = settings.getInt("enableflash", 0); // enable flash + // boolean + agentPicker = settings.getInt("agentchoose", 1); // which user agent to + // use, 1=mobile, + // 2=desktop, + // 3=custom + + deleteHistory = settings.getBoolean("history", false); // delete history + // on exit + // boolean + // initializing variables declared + + height = getResources().getDrawable(R.drawable.loading) + .getMinimumHeight(); + width = getResources().getDrawable(R.drawable.loading) + .getMinimumWidth(); + + // hides keyboard so it doesn't default pop up + this.getWindow().setSoftInputMode( + WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); + + // opens icondatabase so that favicons can be stored + WebIconDatabase.getInstance().open( + getDir("icons", MODE_PRIVATE).getPath()); + + // scroll view containing tabs + tabLayout = (LinearLayout) findViewById(R.id.tabLayout); + tabScroll = (HorizontalScrollView) findViewById(R.id.tabScroll); + tabScroll.setBackgroundColor(getResources().getColor(R.color.black)); + tabScroll.setHorizontalScrollBarEnabled(false); + if (API > 8) { + tabScroll.setOverScrollMode(View.OVER_SCROLL_NEVER); // disallow + // overscroll + } + + // image dimensions and initialization + final int dps = 175; + final float scale = getApplicationContext().getResources() + .getDisplayMetrics().density; + pixels = (int) (dps * scale + 0.5f); + leftPad = (int) (17 * scale + 0.5f); + rightPad = (int) (15 * scale + 0.5f); + height32 = (int) (32 * scale + 0.5f); + tenPad = (int) (10 * scale + 0.5f); + number = 0; + + webpageOther = getResources().getDrawable(R.drawable.webpage); + incognitoPage = getResources().getDrawable(R.drawable.incognito); + webpageOther.setBounds(0, 0, width / 2, height / 2); + incognitoPage.setBounds(0, 0, width / 2, height / 2); + exitTab.setBounds(0, 0, width * 2 / 3, height * 2 / 3); + + Thread startup = new Thread(new Runnable() { + + @Override + public void run() { + reopenOldTabs(); // restores old tabs or creates a new one + } + + }); + startup.run(); + + // new tab button + ImageView newTab = (ImageView) findViewById(R.id.newTab); + newTab.setBackgroundResource(R.drawable.button); + newTab.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + newTab(number, homepage, true); + tabScroll.postDelayed(new Runnable() { + @Override + public void run() { + tabScroll.smoothScrollTo(urlTitle[pageId].getLeft(), 0); + } + }, 100L); + + } + }); + newTab.setOnLongClickListener(new OnLongClickListener() { + + @Override + public boolean onLongClick(View v) { + if (settings.getString("oldPage", "").length() > 0) { + newTab(number, settings.getString("oldPage", ""), true); + edit.putString("oldPage", ""); + edit.commit(); + tabScroll.postDelayed(new Runnable() { + @Override + public void run() { + tabScroll.smoothScrollTo( + urlTitle[pageId].getLeft(), 0); + } + }, 100L); + } + return true; + } + + }); + refresh = (ImageView) findViewById(R.id.refresh); + refreshLayout.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View arg0) { + + if (main[pageId].getProgress() < 100) { + main[pageId].stopLoading(); + } else { + main[pageId].reload(); + } + } + + }); + + enterUrl(); + if (showFullScreen) { + bg.removeView(uBar); + background.addView(uBar); + } + browserHandler = new Handle(); + + } + + static class Handle extends Handler { + + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + case 1: { + main[pageId].loadUrl(getUrl.getText().toString()); + break; + } + case 2: { + // deleteTab(msg.arg1); + break; + } + case 3: { + main[pageId].invalidate(); + break; + } + } + super.handleMessage(msg); + } + + } + + void reopenOldTabs() { + Intent url = getIntent(); + String URL = url.getDataString(); + boolean oldTabs = false; + + if (saveTabs) { + if (URL != null) { + // opens a new tab with the url if its there + newTab(number, URL, true); + main[number - 1].resumeTimers(); + oldTabs = true; + + } + for (String aMemoryURL : memoryURL) { + if (aMemoryURL.length() > 0) { + if (number == 0) { + newTab(number, "", !oldTabs); + main[pageId].resumeTimers(); + main[pageId].getSettings().setCacheMode( + WebSettings.LOAD_CACHE_ELSE_NETWORK); + main[pageId].loadUrl(aMemoryURL); + } else { + newTab(number, "", false); + main[number - 1].getSettings().setCacheMode( + WebSettings.LOAD_CACHE_ELSE_NETWORK); + main[number - 1].loadUrl(aMemoryURL); + } + oldTabs = true; + } + + } + + if (!oldTabs) { + newTab(number, homepage, true); + main[number - 1].resumeTimers(); + } + } else { + if (URL != null) { + // opens a new tab with the URL if its there + newTab(number, URL, true); + main[number - 1].resumeTimers(); + + } else { + // otherwise it opens the home-page + newTab(number, homepage, true); + main[number - 1].resumeTimers(); + + } + } + } + + public static CustomWebView makeTab(final int pageToView, String Url, + final boolean display) { + CustomWebView view = new CustomWebView(CONTEXT); + view.setId(pageToView); + allowLocation = settings.getBoolean("location", false); + browserSettings(CONTEXT, view); + view.setWebViewClient(new CustomWebViewClient(ACTIVITY)); + view.setWebChromeClient(new CustomChromeClient(ACTIVITY)); + if (API > 8) { + view.setDownloadListener(new CustomDownloadListener(ACTIVITY)); + } + + view.setOnLongClickListener(new WebPageLongClickListener()); + + agentPicker = settings.getInt("agentchoose", 1); + switch (agentPicker) { + case 1: + view.getSettings().setUserAgentString(defaultUser); + break; + case 2: + view.getSettings().setUserAgentString(desktop); + break; + case 3: + view.getSettings().setUserAgentString(mobile); + break; + case 4: + view.getSettings().setUserAgentString( + settings.getString("userAgentString", defaultUser)); + break; + } + if (display) { + background.removeView(main[pageId]); + background.addView(view); + view.requestFocus(); + pageId = pageToView; + } + uBar.bringToFront(); + if (Url.contains("about:home")) { + goBookmarks(CONTEXT, view); + } else if (Url.contains("about:blank")) { + view.loadUrl(""); + } else { + if (!Url.startsWith("http") && Url != "") { + Url = "http://" + Url; + } + view.loadUrl(Url); + + } + Log.i("Browser", "tab complete"); + return view; + } + + private void newSettings() { + startActivity(new Intent(FinalVariables.SETTINGS_INTENT)); + } + + // new tab method, takes the id of the tab to be created and the url to load + public static int newTab(int theId, final String theUrl, + final boolean display) { + Log.i("Browser", "making tab"); + int finalID = 0; + homepage = settings.getString("home", HOMEPAGE); + allowLocation = settings.getBoolean("location", false); + boolean reuseWebView = false; + + for (int num = 0; num < number; num++) { + if (urlTitle[num].getVisibility() == View.GONE) { + final int n = num; + Animation holo = AnimationUtils.loadAnimation(CONTEXT, + R.anim.up); + holo.setAnimationListener(new AnimationListener() { + + @Override + public void onAnimationEnd(Animation animation) { + } + + @Override + public void onAnimationRepeat(Animation animation) { + } + + @Override + public void onAnimationStart(Animation animation) { + urlTitle[n].setVisibility(View.VISIBLE); + } + + }); + urlTitle[n].startAnimation(holo); + urlTitle[num].setText("New Tab"); + + if (display) { + if (API < 16) { + urlTitle[num].setBackgroundDrawable(active); + } else { + urlTitle[num].setBackground(active); + } + } else { + if (API < 16) { + urlTitle[num].setBackgroundDrawable(inactive); + } else { + urlTitle[num].setBackground(inactive); + } + } + urlTitle[num].setPadding(leftPad, 0, rightPad, 0); + if (display) { + if (API < 16) { + urlTitle[pageId].setBackgroundDrawable(inactive); + } else { + urlTitle[pageId].setBackground(inactive); + } + } + urlTitle[num].setCompoundDrawables(webpageOther, null, exitTab, + null); + urlTitle[num].setPadding(leftPad, 0, rightPad, 0); + urlTitle[pageId].setPadding(leftPad, 0, rightPad, 0); + + main[num] = makeTab(num, theUrl, display); + finalID = num; + pageId = num; + + uBar.bringToFront(); + + if (API >= 11) { + main[num].onResume(); + } + + reuseWebView = true; + break; + } + } + if (!reuseWebView) { + if (number < MAX_TABS) { + if (number > 0) { + if (display) { + if (API < 16) { + urlTitle[pageId].setBackgroundDrawable(inactive); + } else { + urlTitle[pageId].setBackground(inactive); + } + + urlTitle[pageId].setPadding(leftPad, 0, rightPad, 0); + } + } + final TextView title = new TextView(CONTEXT); + title.setText("New Tab"); + if (display) { + if (API < 16) { + title.setBackgroundDrawable(active); + } else { + title.setBackground(active); + } + } else { + if (API < 16) { + title.setBackgroundDrawable(inactive); + } else { + title.setBackground(inactive); + } + } + title.setSingleLine(true); + title.setGravity(Gravity.CENTER_VERTICAL); + title.setHeight(height32); + title.setWidth(pixels); + title.setPadding(leftPad, 0, rightPad, 0); + title.setId(number); + title.setGravity(Gravity.CENTER_VERTICAL); + + title.setCompoundDrawables(webpageOther, null, exitTab, null); + + Drawable[] drawables = title.getCompoundDrawables(); + bounds = drawables[2].getBounds(); + title.setOnTouchListener(ACTIVITY); + Animation holo = AnimationUtils.loadAnimation(CONTEXT, + R.anim.up); + tabLayout.addView(title); + title.setVisibility(View.INVISIBLE); + holo.setAnimationListener(new AnimationListener() { + + @Override + public void onAnimationEnd(Animation animation) { + } + + @Override + public void onAnimationRepeat(Animation animation) { + } + + @Override + public void onAnimationStart(Animation animation) { + title.setVisibility(View.VISIBLE); + } + + }); + title.startAnimation(holo); + urlTitle[number] = title; + + urlTitle[number].setText("New Tab"); + + if (theUrl != null) { + main[number] = makeTab(number, theUrl, display); + } else { + main[number] = makeTab(number, homepage, display); + } + finalID = number; + number = number + 1; + } + } + if (!reuseWebView && number >= MAX_TABS) { + Toast.makeText(CONTEXT, "Maximum number of tabs reached...", + Toast.LENGTH_SHORT).show(); + } + return finalID; + + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, + Intent intent) { + if (requestCode == 1) { + if (null == mUploadMessage) + return; + Uri result = intent == null || resultCode != RESULT_OK ? null + : intent.getData(); + mUploadMessage.onReceiveValue(result); + mUploadMessage = null; + + } + } + + @Override + public void onBackPressed() { + try { + if (showFullScreen && !uBar.isShown()) { + uBar.startAnimation(slideDown); + } + if (main[pageId].isShown() && main[pageId].canGoBack()) { + main[pageId].goBack(); + } else { + deleteTab(pageId); + uBar.bringToFront(); + } + } catch (NullPointerException ignored) { + } + return; + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + if (settings.getBoolean("textreflow", false)) { + main[pageId].getSettings().setLayoutAlgorithm( + LayoutAlgorithm.NARROW_COLUMNS); + } else { + main[pageId].getSettings().setLayoutAlgorithm( + LayoutAlgorithm.NORMAL); + } + + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); // displays main xml layout + CONTEXT = this; + ACTIVITY = this; + settings = getSharedPreferences(preferences, 0); + edit = settings.edit(); + + if (settings.getBoolean("hidestatus", false)) { + getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN); + } + saveTabs = settings.getBoolean("savetabs", true); + if (saveTabs) { + String mem = settings.getString("memory", ""); + edit.putString("memory", ""); + memoryURL = GetArray(mem); + } + + inactive = getResources().getDrawable(R.drawable.bg_inactive); + active = getResources().getDrawable(R.drawable.bg_press); + initialize(); // sets up random stuff + options(); // allows options to be opened + enter();// enter url bar + DisplayMetrics metrics = new DisplayMetrics(); + getWindowManager().getDefaultDisplay().getMetrics(metrics); + + float widthInInches = metrics.widthPixels / metrics.xdpi; + float heightInInches = metrics.heightPixels / metrics.ydpi; + double sizeInInches = Math.sqrt(Math.pow(widthInInches, 2) + + Math.pow(heightInInches, 2)); + // 0.5" buffer for 7" devices + isPhone = sizeInInches < 6.5; + forward();// forward button + back(); + if (settings.getInt("first", 0) == 0) { // This dialog alerts the user + // to some navigation + // techniques + String message = "1. Long-press back button to exit browser\n\n" + + "2. Swipe from left edge toward the right (---->) to go back\n\n" + + "3. Swipe from right edge toward the left (<----)to go forward\n\n" + + "4. Visit settings and advanced settings to change options"; + + Utils.createInformativeDialog(CONTEXT, "Browser Tips", message); + String sorry = "I have changed back to the old icon because it has been" + + " brought to my attention that another app had a very similar icon to the new one." + + " I apologize if you liked the new one."; + Utils.createInformativeDialog(CONTEXT, "New Icon", sorry); + edit.putInt("first", 1); + edit.commit(); + } + + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.menu, menu); + + return true; + } + + /* + * (non-Javadoc) + * + * @see android.app.Activity#onKeyDown(int, android.view.KeyEvent) + */ + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_SEARCH) { + getUrl.requestFocus(); + InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + manager.showSoftInput(getUrl, 0); + } + return super.onKeyDown(keyCode, event); + } + + @Override + public boolean onKeyLongPress(int keyCode, KeyEvent event) { + + if (keyCode == KeyEvent.KEYCODE_BACK) { + if (!settings.getBoolean("restoreclosed", true)) { + for (int n = 0; n < MAX_TABS; n++) { + urlToLoad[n][0] = null; + } + } + finish(); + return true; + } else + return super.onKeyLongPress(keyCode, event); + } + + @Override + protected void onNewIntent(Intent intent) { + + String url = intent.getDataString(); + int id = -1; + int download = -1; + try { + id = intent.getExtras().getInt("acr.browser.barebones.Origin") - 1; + } catch (NullPointerException e) { + id = -1; + } + try { + download = intent.getExtras().getInt( + "acr.browser.barebones.Download"); + } catch (NullPointerException e) { + download = -1; + } + if (id >= 0) { + main[id].loadUrl(url); + } else if (download == 1) { + Utils.downloadFile(CONTEXT, url, null, null); + } else if (url != null) { + newTab(number, url, true); + } + + super.onNewIntent(intent); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + + switch (item.getItemId()) { + case R.id.history: + generateHistory(main[pageId], CONTEXT); + return true; + case R.id.bookmark: + if (urlToLoad[pageId][1] != null) { + if (!urlToLoad[pageId][1].equals("Bookmarks")) { + Utils.addBookmark(CONTEXT, urlToLoad[pageId][1], + urlToLoad[pageId][0]); + } + } + return true; + case R.id.settings: + newSettings(); + return true; + case R.id.allBookmarks: + if (urlToLoad[pageId][1] == null) { + goBookmarks(CONTEXT, main[pageId]); + } else if (!urlToLoad[pageId][1].equals("Bookmarks")) { + goBookmarks(CONTEXT, main[pageId]); + } + + return true; + case R.id.share: + share(); + return true; + case R.id.incognito: + startActivity(new Intent(FinalVariables.INCOGNITO_INTENT)); + // newTab(number, homepage, true, true); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + @Override + protected void onPause() { + + if (main[pageId] != null) { + if (API >= 11) { + main[pageId].onPause(); + } + main[pageId].pauseTimers(); + } + Thread remember = new Thread(new Runnable() { + + @Override + public void run() { + String s = ""; + for (int n = 0; n < MAX_TABS; n++) { + if (urlToLoad[n][0] != null) { + s = s + urlToLoad[n][0] + "|$|SEPARATOR|$|"; + } + } + edit.putString("memory", s); + edit.commit(); + } + }); + remember.start(); + super.onPause(); + } + + @Override + protected void onResume() { + onProgressChanged(pageId, main[pageId].getProgress()); + if (main[pageId].getProgress() == 100) { + progressBar.setVisibility(View.GONE); + refresh.setVisibility(View.VISIBLE); + + } + if (API >= 11) { + main[pageId].onResume(); + } + main[pageId].resumeTimers(); + super.onResume(); + } + + static void openBookmarks(Context context, CustomWebView view) { + String bookmarkHtml = BookmarkPageVariables.Heading; + + for (int n = 0; n < MAX_BOOKMARKS; n++) { + if (bUrl[n] != null) { + bookmarkHtml += (BookmarkPageVariables.Part1 + bUrl[n] + + BookmarkPageVariables.Part2 + bUrl[n] + + BookmarkPageVariables.Part3 + bTitle[n] + BookmarkPageVariables.Part4); + } + } + bookmarkHtml += BookmarkPageVariables.End; + File bookmarkWebPage = new File(context.getFilesDir(), "bookmarks.html"); + try { + FileWriter bookWriter = new FileWriter(bookmarkWebPage, false); + bookWriter.write(bookmarkHtml); + bookWriter.close(); + } catch (IOException e) { + e.printStackTrace(); + } + view.loadUrl("file://" + bookmarkWebPage); + + if (uBar.isShown()) { + urlTitle[pageId].setText("Bookmarks"); + setUrlText(""); + getUrl.setPadding(tenPad, 0, tenPad, 0); + } + + } + + void options() { + ImageView options = (ImageView) findViewById(R.id.options); + options.setBackgroundResource(R.drawable.button); + options.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + + if (API >= 11) { + PopupMenu menu = new PopupMenu(CONTEXT, v); + MenuInflater inflate = menu.getMenuInflater(); + inflate.inflate(R.menu.menu, menu.getMenu()); + menu.setOnMenuItemClickListener(new OnMenuItemClickListener() { + + @Override + public boolean onMenuItemClick(MenuItem item) { + + switch (item.getItemId()) { + case R.id.history: + generateHistory(main[pageId], CONTEXT); + return true; + case R.id.bookmark: + if (urlToLoad[pageId][1] != null) { + if (!urlToLoad[pageId][1] + .equals("Bookmarks")) { + Utils.addBookmark(CONTEXT, + urlToLoad[pageId][1], + urlToLoad[pageId][0]); + } + } + return true; + case R.id.settings: + newSettings(); + return true; + case R.id.allBookmarks: + if (urlToLoad[pageId][1] == null) { + goBookmarks(CONTEXT, main[pageId]); + } else if (!urlToLoad[pageId][1] + .equals("Bookmarks")) { + goBookmarks(CONTEXT, main[pageId]); + } + return true; + case R.id.share: + share(); + return true; + case R.id.incognito: + startActivity(new Intent( + FinalVariables.INCOGNITO_INTENT)); + // newTab(number, homepage, true, true); + return true; + default: + return false; + } + + } + + }); + menu.show(); + } else if (API < 11) { + + openOptionsMenu(); + } + } + + }); + options.setOnLongClickListener(new OnLongClickListener() { + + @Override + public boolean onLongClick(View arg0) { + return true; + } + + }); + } + + static void share() { + Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); + + // set the type + shareIntent.setType("text/plain"); + + // add a subject + shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, + urlToLoad[pageId][1]); + + // build the body of the message to be shared + String shareMessage = urlToLoad[pageId][0]; + + // add the message + shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareMessage); + + // start the chooser for sharing + CONTEXT.startActivity(Intent.createChooser(shareIntent, + "Share this page")); + } + + static void searchTheWeb(String query, Context context) { + query = query.trim(); + main[pageId].stopLoading(); + + if (query.startsWith("www.")) { + query = "http://" + query; + } else if (query.startsWith("ftp.")) { + query = "ftp://" + query; + } + + boolean containsPeriod = query.contains("."); + boolean isIPAddress = (TextUtils.isDigitsOnly(query.replace(".", "")) && (query + .replace(".", "").length() >= 4)); + boolean aboutScheme = query.contains("about:"); + boolean validURL = (query.startsWith("ftp://") + || query.startsWith("http://") || query.startsWith("file://") || query + .startsWith("https://")) || isIPAddress; + boolean isSearch = ((query.contains(" ") || !containsPeriod) && !aboutScheme); + + if (query.contains("about:home") || query.contains("about:bookmarks")) { + goBookmarks(context, main[pageId]); + } else if (query.contains("about:history")) { + generateHistory(main[pageId], context); + } else if (isSearch) { + query.replaceAll(" ", "+"); + main[pageId].loadUrl(SEARCH + query); + } else if (!validURL) { + main[pageId].loadUrl("http://" + query); + } else { + main[pageId].loadUrl(query); + } + } + + public static void onPageFinished(WebView view, String url) { + if (view.isShown()) { + view.invalidate(); + progressBar.setVisibility(View.GONE); + refresh.setVisibility(View.VISIBLE); + + if (showFullScreen && uBar.isShown()) { + uBar.startAnimation(slideUp); + } + } + view.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); + Log.i("Lightning", "Page Finished"); + loadTime = System.currentTimeMillis() - loadTime; + Log.i("Lightning", "Load Time: " + loadTime); + } + + public static void onPageStarted(WebView view, String url, Bitmap favicon) { + Log.i("Lightning", "Page Started"); + loadTime = System.currentTimeMillis(); + int numberPage = view.getId(); + + if (url.startsWith("file://")) { + view.getSettings().setUseWideViewPort(false); + } else { + view.getSettings().setUseWideViewPort( + settings.getBoolean("wideviewport", true)); + } + + if (view.isShown()) { + refresh.setVisibility(View.INVISIBLE); + progressBar.setVisibility(View.VISIBLE); + setUrlText(url); + } + + urlTitle[numberPage].setCompoundDrawables(webpageOther, null, exitTab, + null); + if (favicon != null) { + setFavicon(view.getId(), favicon); + } + + getUrl.setPadding(tenPad, 0, tenPad, 0); + urlToLoad[numberPage][0] = url; + + if (!uBar.isShown() && showFullScreen) { + uBar.startAnimation(slideDown); + } + } + + public static void onCreateWindow(Message resultMsg) { + newTab(number, "", true); + WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj; + transport.setWebView(main[pageId]); + resultMsg.sendToTarget(); + browserHandler.postDelayed(new Runnable() { + @Override + public void run() { + main[pageId].loadUrl(getUrl.getText().toString()); + } + }, 500); + } + + public static void onShowCustomView() { + background.removeView(main[pageId]); + uBar.setVisibility(View.GONE); + } + + public static void onHideCustomView(FrameLayout fullScreenContainer, + CustomViewCallback mCustomViewCallback, int orientation) { + FrameLayout screen = (FrameLayout) ACTIVITY.getWindow().getDecorView(); + screen.removeView(fullScreenContainer); + fullScreenContainer = null; + mCustomViewCallback.onCustomViewHidden(); + ACTIVITY.setRequestedOrientation(orientation); + background.addView(main[pageId]); + uBar.setVisibility(View.VISIBLE); + uBar.bringToFront(); + } + + public static void onReceivedTitle(int numberPage, String title) { + if (title != null && title.length() != 0) { + urlTitle[numberPage].setText(title); + urlToLoad[numberPage][1] = title; + Utils.updateHistory(CONTEXT, CONTEXT.getContentResolver(), + noStockBrowser, urlToLoad[numberPage][0], title); + } + } + + public static void openFileChooser(ValueCallback uploadMsg) { + mUploadMessage = uploadMsg; + Intent i = new Intent(Intent.ACTION_GET_CONTENT); + i.addCategory(Intent.CATEGORY_OPENABLE); + i.setType("*/*"); + ACTIVITY.startActivityForResult( + Intent.createChooser(i, "File Chooser"), 1); + } + + @Override + public boolean onTouch(View v, MotionEvent event) { + id = v.getId(); + background.clearDisappearingChildren(); + boolean xPress = false; + int x = (int) event.getX(); + int y = (int) event.getY(); + Rect edge = new Rect(); + v.getLocalVisibleRect(edge); + urlTitle[pageId].setPadding(leftPad, 0, rightPad, 0); + if (event.getAction() == MotionEvent.ACTION_DOWN) { + timeTabPressed = System.currentTimeMillis(); + } else if (event.getAction() == MotionEvent.ACTION_UP) { + + if ((System.currentTimeMillis() - timeTabPressed) > 1000) { + xPress = true; + } + + if (x >= (edge.right - bounds.width() - v.getPaddingRight() - 10 * 3 / 2) + && x <= (edge.right - v.getPaddingRight() + 10 * 3 / 2) + && y >= (v.getPaddingTop() - 10 / 2) + && y <= (v.getHeight() - v.getPaddingBottom() + 10 / 2)) { + xPress = true; + } + if (id == pageId) { + if (xPress) { + deleteTab(id); + uBar.bringToFront(); + } + } else if (id != pageId) { + if (xPress) { + deleteTab(id); + } else { + if (API < 16) { + urlTitle[pageId].setBackgroundDrawable(inactive); + } else if (API > 15) { + urlTitle[pageId].setBackground(inactive); + } + urlTitle[pageId].setPadding(leftPad, 0, rightPad, 0); + if (!showFullScreen) { + background.addView(main[id]); + main[id].startAnimation(fadeIn); + main[pageId].startAnimation(fadeOut); + background.removeView(main[pageId]); + uBar.bringToFront(); + } else if (API >= 12) { + main[id].setAlpha(0f); + background.addView(main[id]); + try { + main[id].animate().alpha(1f) + .setDuration(mShortAnimationDuration); + } catch (NullPointerException ignored) { + } + background.removeView(main[pageId]); + uBar.bringToFront(); + } else { + background.removeView(main[pageId]); + background.addView(main[id]); + } + uBar.bringToFront(); + + pageId = id; + setUrlText(urlToLoad[pageId][0]); + getUrl.setPadding(tenPad, 0, tenPad, 0); + if (API < 16) { + urlTitle[pageId].setBackgroundDrawable(active); + } else if (API > 15) { + urlTitle[pageId].setBackground(active); + } + if (main[pageId].getProgress() < 100) { + refresh.setVisibility(View.INVISIBLE); + + progressBar.setVisibility(View.VISIBLE); + + } else { + progressBar.setVisibility(View.GONE); + refresh.setVisibility(View.VISIBLE); + } + onProgressChanged(pageId, main[pageId].getProgress()); + tabScroll.smoothScrollTo(urlTitle[pageId].getLeft(), 0); + main[pageId].invalidate(); + } + } + + } + uBar.bringToFront(); + v.setPadding(leftPad, 0, rightPad, 0); + return true; + } + + public static class ClickHandler extends Handler { + + /* + * (non-Javadoc) + * + * @see android.os.Handler#handleMessage(android.os.Message) + */ + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + String url = null; + url = msg.getData().getString("url"); + handleLongClickOnBookmarks(url, msg.arg1); + } + + } + + public static boolean onLongClick(final int n) { + final HitTestResult result = main[n].getHitTestResult(); + + if (main[n].getUrl().contains( + "file://" + CONTEXT.getFilesDir() + "/bookmarks.html")) { + + Message message = new Message(); + message.arg1 = n; + message.setTarget(new ClickHandler()); + main[n].requestFocusNodeHref(message); + + return true; + } else if (result.getExtra() != null) { + if (result.getType() == 5 && API > 8) { + DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + switch (which) { + case DialogInterface.BUTTON_POSITIVE: { + int num = pageId; + newTab(number, result.getExtra(), false); + // urlTitle[num].performClick(); + pageId = num; + break; + } + case DialogInterface.BUTTON_NEGATIVE: { + main[n].loadUrl(result.getExtra()); + break; + } + case DialogInterface.BUTTON_NEUTRAL: { + if (API > 8) { + String url = result.getExtra(); + + Utils.downloadFile(CONTEXT, url, null, null); + + } + break; + } + } + } + }; + + AlertDialog.Builder builder = new AlertDialog.Builder(CONTEXT); // dialog + builder.setMessage("What would you like to do with this image?") + .setPositiveButton("Open in New Tab", + dialogClickListener) + .setNegativeButton("Open Normally", dialogClickListener) + .setNeutralButton("Download Image", dialogClickListener) + .show(); + + } else { + DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + switch (which) { + case DialogInterface.BUTTON_POSITIVE: { + int num = pageId; + newTab(number, result.getExtra(), false); + pageId = num; + break; + } + case DialogInterface.BUTTON_NEGATIVE: { + main[n].loadUrl(result.getExtra()); + break; + } + case DialogInterface.BUTTON_NEUTRAL: { + + if (API < 11) { + android.text.ClipboardManager clipboard = (android.text.ClipboardManager) ACTIVITY + .getSystemService(Context.CLIPBOARD_SERVICE); + clipboard.setText(result.getExtra()); + } else { + ClipboardManager clipboard = (ClipboardManager) ACTIVITY + .getSystemService(CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText("label", + result.getExtra()); + clipboard.setPrimaryClip(clip); + } + break; + } + } + } + }; + + AlertDialog.Builder builder = new AlertDialog.Builder(CONTEXT); // dialog + builder.setTitle(result.getExtra()).setMessage("What do you want to do with this link?") + .setPositiveButton("Open in New Tab", + dialogClickListener) + .setNegativeButton("Open Normally", dialogClickListener) + .setNeutralButton("Copy link", dialogClickListener) + .show(); + } + return true; + } else { + return false; + } + } + + public static void handleLongClickOnBookmarks(final String clickedURL, + final int n) { + if (clickedURL != null) { + + DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + switch (which) { + case DialogInterface.BUTTON_POSITIVE: { + int num = pageId; + newTab(number, clickedURL, false); + pageId = num; + break; + } + case DialogInterface.BUTTON_NEGATIVE: { + main[n].loadUrl(clickedURL); + break; + } + case DialogInterface.BUTTON_NEUTRAL: { + deleteBookmark(clickedURL); + break; + } + } + } + }; + + AlertDialog.Builder builder = new AlertDialog.Builder(CONTEXT); // dialog + builder.setMessage("What would you like to do with this bookmark?") + .setPositiveButton("Open in New Tab", dialogClickListener) + .setNegativeButton("Open Normally", dialogClickListener) + .setNeutralButton("Delete", dialogClickListener).show(); + } + } + + public static void goBack() { + if (main[pageId].isShown() && main[pageId].canGoBack()) { + main[pageId].goBack(); + } + } + + public static void goForward() { + if (main[pageId].isShown() && main[pageId].canGoForward()) { + main[pageId].goForward(); + } + } + + public static void onProgressChanged(int id, int progress) { + if (id == pageId) { + browserProgress.setProgress(progress); + if (progress < 100) { + browserProgress.setVisibility(View.VISIBLE); + } else { + browserProgress.setVisibility(View.GONE); + } + } + } +} \ No newline at end of file diff --git a/src/acr/browser/barebones/activities/IncognitoModeActivity.java b/src/acr/browser/barebones/activities/IncognitoModeActivity.java index 00d2bc1..db682e3 100644 --- a/src/acr/browser/barebones/activities/IncognitoModeActivity.java +++ b/src/acr/browser/barebones/activities/IncognitoModeActivity.java @@ -8,7 +8,6 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -17,6 +16,10 @@ import acr.browser.barebones.R; import acr.browser.barebones.customwebview.IncognitoWebView; import acr.browser.barebones.databases.DatabaseHandler; import acr.browser.barebones.databases.SpaceTokenizer; +import acr.browser.barebones.incognitoclasses.IncognitoChromeClient; +import acr.browser.barebones.incognitoclasses.IncognitoDownloadListener; +import acr.browser.barebones.incognitoclasses.IncognitoLongClickListener; +import acr.browser.barebones.incognitoclasses.IncognitoWebViewClient; import acr.browser.barebones.utilities.BookmarkPageVariables; import acr.browser.barebones.utilities.FinalVariables; import acr.browser.barebones.utilities.HistoryPageVariables; @@ -36,24 +39,19 @@ import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteMisuseException; import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; -import android.net.http.SslError; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.provider.Browser; -import android.text.InputType; import android.text.TextUtils; -import android.text.method.PasswordTransformationMethod; import android.util.DisplayMetrics; import android.util.Log; import android.view.Gravity; import android.view.KeyEvent; -import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -63,7 +61,6 @@ import android.view.View.OnClickListener; import android.view.View.OnKeyListener; import android.view.View.OnLongClickListener; import android.view.View.OnTouchListener; -import android.view.ViewGroup; import android.view.WindowManager; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; @@ -72,25 +69,17 @@ import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; import android.webkit.CookieManager; import android.webkit.CookieSyncManager; -import android.webkit.DownloadListener; -import android.webkit.GeolocationPermissions; -import android.webkit.HttpAuthHandler; -import android.webkit.SslErrorHandler; import android.webkit.ValueCallback; -import android.webkit.WebChromeClient; import android.webkit.WebChromeClient.CustomViewCallback; import android.webkit.WebIconDatabase; import android.webkit.WebSettings; import android.webkit.WebSettings.LayoutAlgorithm; import android.webkit.WebSettings.PluginState; import android.webkit.WebSettings.RenderPriority; -import android.webkit.WebStorage.QuotaUpdater; import android.webkit.WebView; import android.webkit.WebView.HitTestResult; -import android.webkit.WebViewClient; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; -import android.widget.EditText; import android.widget.FrameLayout; import android.widget.HorizontalScrollView; import android.widget.ImageView; @@ -106,453 +95,10 @@ import android.widget.TextView.OnEditorActionListener; import android.widget.Toast; @SuppressWarnings("deprecation") -public class IncognitoModeActivity extends Activity { +public class IncognitoModeActivity extends Activity implements OnTouchListener { - @SuppressLint("SetJavaScriptEnabled") - public class CustomChromeClient extends WebChromeClient { - public Bitmap mDefaultVideoPoster; - public View mVideoProgressView; - public FrameLayout fullScreenContainer; - public int orientation; - - @Override - public void onExceededDatabaseQuota(String url, - String databaseIdentifier, long quota, - long estimatedDatabaseSize, long totalQuota, - QuotaUpdater quotaUpdater) { - quotaUpdater.updateQuota(totalQuota + estimatedDatabaseSize); - - } - - @Override - public void onProgressChanged(WebView view, int newProgress) { - - super.onProgressChanged(view, newProgress); - } - - @Override - public void onReachedMaxAppCacheSize(long requiredStorage, long quota, - QuotaUpdater quotaUpdater) { - quotaUpdater.updateQuota(quota + requiredStorage); - } - - @Override - public Bitmap getDefaultVideoPoster() { - if (mDefaultVideoPoster == null) { - mDefaultVideoPoster = BitmapFactory.decodeResource( - getResources(), android.R.color.black); - } - return mDefaultVideoPoster; - } - - @Override - public View getVideoLoadingProgressView() { - if (mVideoProgressView == null) { - LayoutInflater inflater = LayoutInflater.from(getBaseContext()); - mVideoProgressView = inflater.inflate( - android.R.layout.simple_spinner_item, null); - } - return mVideoProgressView; - } - - @Override - public void onCloseWindow(WebView window) { - Message msg = Message.obtain(); - msg.what = 3; - msg.arg1 = window.getId(); - browserHandler.sendMessage(msg); - super.onCloseWindow(window); - } - - @Override - public boolean onCreateWindow(WebView view, boolean isDialog, - boolean isUserGesture, final Message resultMsg) { - - if (isUserGesture) { - newTab(number, "", true, false); - WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj; - transport.setWebView(main[pageId]); - resultMsg.sendToTarget(); - browserHandler.postDelayed(new Runnable() { - @Override - public void run() { - main[pageId].loadUrl(getUrl.getText().toString()); - } - }, 500); - } - return true; - } - - @Override - public void onGeolocationPermissionsShowPrompt(final String origin, - final GeolocationPermissions.Callback callback) { - - if (!allowLocation) { - callback.invoke(origin, false, false); - } - if (allowLocation) { - final boolean remember = true; - AlertDialog.Builder builder = new AlertDialog.Builder(CONTEXT); - builder.setTitle("Location Access"); - String org = null; - if (origin.length() > 50) { - org = (String) origin.subSequence(0, 50) + "..."; - } else { - org = origin; - } - builder.setMessage(org + "\nWould like to use your Location ") - .setCancelable(true) - .setPositiveButton("Allow", - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, - int id) { - callback.invoke(origin, true, remember); - } - }) - .setNegativeButton("Don't Allow", - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, - int id) { - callback.invoke(origin, false, remember); - } - }); - AlertDialog alert = builder.create(); - alert.show(); - } - } - - @Override - public void onHideCustomView() { - if (mCustomView == null && mCustomViewCallback == null) { - return; - } - mCustomView.setKeepScreenOn(false); - FrameLayout screen = (FrameLayout) getWindow().getDecorView(); - screen.removeView(fullScreenContainer); - fullScreenContainer = null; - mCustomView = null; - mCustomViewCallback.onCustomViewHidden(); - setRequestedOrientation(orientation); - background.addView(main[pageId]); - uBar.setVisibility(View.VISIBLE); - uBar.bringToFront(); - } - - @Override - public void onReceivedIcon(WebView view, Bitmap favicon) { - setFavicon(view.getId(), favicon); - } - - @Override - public void onReceivedTitle(final WebView view, final String title) { - numberPage = view.getId(); - if (title != null && title.length() != 0) { - urlTitle[numberPage].setText(title); - urlToLoad[numberPage][1] = title; - } - super.onReceivedTitle(view, title); - } - - @Override - public void onShowCustomView(View view, int requestedOrientation, - CustomViewCallback callback) { - if (mCustomView != null) { - callback.onCustomViewHidden(); - return; - } - view.setKeepScreenOn(true); - orientation = getRequestedOrientation(); - FrameLayout screen = (FrameLayout) getWindow().getDecorView(); - fullScreenContainer = new FrameLayout(getBaseContext()); - fullScreenContainer.setBackgroundColor(getResources().getColor( - R.color.black)); - background.removeView(main[pageId]); - uBar.setVisibility(View.GONE); - fullScreenContainer.addView(view, - ViewGroup.LayoutParams.MATCH_PARENT); - screen.addView(fullScreenContainer, - ViewGroup.LayoutParams.MATCH_PARENT); - mCustomView = view; - mCustomViewCallback = callback; - setRequestedOrientation(requestedOrientation); - - } - - @Override - public void onShowCustomView(View view, - WebChromeClient.CustomViewCallback callback) { - if (mCustomView != null) { - callback.onCustomViewHidden(); - return; - } - view.setKeepScreenOn(true); - orientation = getRequestedOrientation(); - FrameLayout screen = (FrameLayout) getWindow().getDecorView(); - fullScreenContainer = new FrameLayout(getBaseContext()); - fullScreenContainer.setBackgroundColor(getResources().getColor( - R.color.black)); - background.removeView(main[pageId]); - uBar.setVisibility(View.GONE); - fullScreenContainer.addView(view, - ViewGroup.LayoutParams.MATCH_PARENT); - screen.addView(fullScreenContainer, - ViewGroup.LayoutParams.MATCH_PARENT); - mCustomView = view; - mCustomViewCallback = callback; - setRequestedOrientation(getRequestedOrientation()); - } - - public void openFileChooser(ValueCallback uploadMsg) { - mUploadMessage = uploadMsg; - Intent i = new Intent(Intent.ACTION_GET_CONTENT); - i.addCategory(Intent.CATEGORY_OPENABLE); - i.setType("image/*"); - startActivityForResult(Intent.createChooser(i,"File Chooser"), 1); - } - - public void openFileChooser(ValueCallback uploadMsg, - String acceptType) { - mUploadMessage = uploadMsg; - Intent i = new Intent(Intent.ACTION_GET_CONTENT); - i.addCategory(Intent.CATEGORY_OPENABLE); - i.setType("*/*"); - startActivityForResult( - Intent.createChooser(i, "File Browser"),1); - } - - public void openFileChooser(ValueCallback uploadMsg, - String acceptType, String capture) { - openFileChooser(uploadMsg); - } - } - - public class CustomDownloadListener implements DownloadListener { - - @Override - public void onDownloadStart(final String url, String userAgent, - final String contentDisposition, final String mimetype, - long contentLength) { - if (url.endsWith(".mp4") || url.endsWith(".m4a")) { - - AlertDialog.Builder builder = new AlertDialog.Builder(CONTEXT); - builder.setTitle("Open as..."); - builder.setMessage( - "Do you want to download this video or watch it in an app?") - .setCancelable(true) - .setPositiveButton("Download", - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, - int id) { - Utils.downloadFile(CONTEXT, url, - contentDisposition, mimetype); - } - }) - .setNegativeButton("Watch", - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, - int id) { - Intent intent = new Intent( - Intent.ACTION_VIEW); - intent.setDataAndType(Uri.parse(url), - "video/mp4"); - intent.putExtra( - "acr.browser.barebones.Download", - 1); - startActivity(intent); - } - }); - AlertDialog alert = builder.create(); - alert.show(); - - } else { - Utils.downloadFile(CONTEXT, url, contentDisposition, mimetype); - } - } - - } - - public class IncognitoWebViewClient extends WebViewClient { - - @Override - public boolean shouldOverrideUrlLoading(WebView view, String url) { - return false; - } - - @Override - public void onReceivedHttpAuthRequest(final WebView view, - final HttpAuthHandler handler, final String host, - final String realm) { - - AlertDialog.Builder builder = new AlertDialog.Builder(CONTEXT); - final EditText name = new EditText(CONTEXT); - final EditText password = new EditText(CONTEXT); - LinearLayout passLayout = new LinearLayout(CONTEXT); - passLayout.setOrientation(LinearLayout.VERTICAL); - - passLayout.addView(name); - passLayout.addView(password); - - name.setHint("Username"); - password.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); - password.setTransformationMethod(new PasswordTransformationMethod()); - password.setHint("Password"); - builder.setTitle("Sign in"); - builder.setView(passLayout); - builder.setCancelable(true) - .setPositiveButton("Sign in", - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, - int id) { - String user = name.getText().toString(); - String pass = password.getText().toString(); - handler.proceed(user.trim(), pass.trim()); - Log.i("Lightning", "Request Login"); - - } - }) - .setNegativeButton("Cancel", - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, - int id) { - handler.cancel(); - - } - }); - AlertDialog alert = builder.create(); - alert.show(); - - } - - @Override - public void onScaleChanged(WebView view, float oldScale, float newScale) { - if (view.isShown()) { - view.invalidate(); - } - super.onScaleChanged(view, oldScale, newScale); - } - - @Override - public void onPageFinished(WebView view, final String url) { - if (view.isShown()) { - view.invalidate(); - progressBar.setVisibility(View.GONE); - refresh.setVisibility(View.VISIBLE); - - if (showFullScreen && uBar.isShown()) { - uBar.startAnimation(slideUp); - } - } - view.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); - Log.i("Lightning", "Page Finished"); - loadTime = System.currentTimeMillis() - loadTime; - Log.i("Lightning", "Load Time: " + loadTime); - super.onPageFinished(view, url); - } - - @Override - public void onPageStarted(WebView view, String url, Bitmap favicon) { - Log.i("Lightning", "Page Started"); - loadTime = System.currentTimeMillis(); - numberPage = view.getId(); - - if (url.startsWith("file:///")) { - view.getSettings().setUseWideViewPort(false); - } else { - view.getSettings().setUseWideViewPort(settings.getBoolean("wideviewport", true)); - } - - if (view.isShown()) { - refresh.setVisibility(View.INVISIBLE); - progressBar.setVisibility(View.VISIBLE); - setUrlText(url); - } - - urlTitle[numberPage].setCompoundDrawables(incognitoPage, null, - exitTab, null); - if (favicon != null) { - setFavicon(view.getId(), favicon); - } - - getUrl.setPadding(tenPad, 0, tenPad, 0); - urlToLoad[numberPage][0] = url; - - if (!uBar.isShown() && showFullScreen) { - uBar.startAnimation(slideDown); - } - super.onPageStarted(view, url, favicon); - } - - @Override - public void onReceivedSslError(WebView view, - final SslErrorHandler handler, SslError error) { - AlertDialog.Builder builder = new AlertDialog.Builder(CONTEXT); - builder.setTitle("Warning"); - builder.setMessage( - "The certificate of the site is not trusted. Proceed anyway?") - .setCancelable(true) - .setPositiveButton("Yes", - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, - int id) { - handler.proceed(); - } - }) - .setNegativeButton("No", - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, - int id) { - handler.cancel(); - } - }); - AlertDialog alert = builder.create(); - if (error.getPrimaryError() == SslError.SSL_UNTRUSTED) { - alert.show(); - } else { - handler.proceed(); - } - - } - - @Override - public void onFormResubmission(WebView view, final Message dontResend, - final Message resend) { - AlertDialog.Builder builder = new AlertDialog.Builder(CONTEXT); - builder.setTitle("Form Resubmission"); - builder.setMessage("Would you like to resend the data?") - .setCancelable(true) - .setPositiveButton("Yes", - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, - int id) { - - resend.sendToTarget(); - } - }) - .setNegativeButton("No", - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, - int id) { - - dontResend.sendToTarget(); - } - }); - AlertDialog alert = builder.create(); - alert.show(); - super.onFormResubmission(view, dontResend, resend); - } - } - - public void generateHistory(final IncognitoWebView view) { + public static void generateHistory(final IncognitoWebView view, + final Context context) { Thread history = new Thread(new Runnable() { @@ -571,8 +117,6 @@ public class IncognitoModeActivity extends Activity { null, // Selection arguments (none) null, null, null); - handler.sendEmptyMessage(1); - } catch (SQLiteException ignored) { } catch (NullPointerException ignored) { } catch (IllegalStateException ignored) { @@ -602,13 +146,14 @@ public class IncognitoModeActivity extends Activity { } while (n < 49 && historyCursor.moveToPrevious()); } } + handler.sendEmptyMessage(1); } catch (SQLiteException ignored) { } catch (NullPointerException ignored) { } catch (IllegalStateException ignored) { } historyHtml += BookmarkPageVariables.End; - File historyWebPage = new File(getBaseContext().getFilesDir(), + File historyWebPage = new File(context.getFilesDir(), "history.html"); try { FileWriter hWriter = new FileWriter(historyWebPage, false); @@ -617,20 +162,20 @@ public class IncognitoModeActivity extends Activity { } catch (IOException e) { e.printStackTrace(); } - if (uBar.isShown()) { + if (urlBar.isShown()) { urlTitle[pageId].setText("History"); setUrlText(""); getUrl.setPadding(tenPad, 0, tenPad, 0); } - view.loadUrl("file:///" + historyWebPage); + view.loadUrl("file://" + historyWebPage); } }); history.run(); } - public void setUrlText(String url) { + public static void setUrlText(String url) { if (url != null) { if (!url.startsWith("file://")) { getUrl.setText(url); @@ -640,102 +185,19 @@ public class IncognitoModeActivity extends Activity { } } - public class TabTouchListener implements OnTouchListener { - - @Override - public boolean onTouch(View v, MotionEvent event) { - id = v.getId(); - background.clearDisappearingChildren(); - boolean xPress = false; - int x = (int) event.getX(); - int y = (int) event.getY(); - Rect edge = new Rect(); - v.getLocalVisibleRect(edge); - - urlTitle[pageId].setPadding(leftPad, 0, rightPad, 0); - if (event.getAction() == MotionEvent.ACTION_UP) { - if (x >= (edge.right - bounds.width() - v.getPaddingRight() - 10 * 3 / 2) - && x <= (edge.right - v.getPaddingRight() + 10 * 3 / 2) - && y >= (v.getPaddingTop() - 10 / 2) - && y <= (v.getHeight() - v.getPaddingBottom() + 10 / 2)) { - xPress = true; - } - if (id == pageId) { - if (xPress) { - deleteTab(id); - uBar.bringToFront(); - } - } else if (id != pageId) { - if (xPress) { - deleteTab(id); - } else { - if (API < 16) { - urlTitle[pageId].setBackgroundDrawable(inactive); - } else if (API > 15) { - urlTitle[pageId].setBackground(inactive); - } - urlTitle[pageId].setPadding(leftPad, 0, rightPad, 0); - if (!showFullScreen) { - background.addView(main[id]); - main[id].startAnimation(fadeIn); - main[pageId].startAnimation(fadeOut); - background.removeView(main[pageId]); - uBar.bringToFront(); - } else if (API >= 12) { - main[id].setAlpha(0f); - background.addView(main[id]); - try { - main[id].animate().alpha(1f) - .setDuration(mShortAnimationDuration); - } catch (NullPointerException ignored) { - } - background.removeView(main[pageId]); - uBar.bringToFront(); - } else { - background.removeView(main[pageId]); - background.addView(main[id]); - } - uBar.bringToFront(); - - pageId = id; - setUrlText(urlToLoad[pageId][0]); - getUrl.setPadding(tenPad, 0, tenPad, 0); - if (API < 16) { - urlTitle[pageId].setBackgroundDrawable(active); - } else if (API > 15) { - urlTitle[pageId].setBackground(active); - } - if (main[pageId].getProgress() < 100) { - refresh.setVisibility(View.INVISIBLE); - progressBar.setVisibility(View.VISIBLE); - } else { - progressBar.setVisibility(View.GONE); - refresh.setVisibility(View.VISIBLE); - } - tabScroll.smoothScrollTo(urlTitle[pageId].getLeft(), 0); - main[pageId].invalidate(); - } - } - - } - uBar.bringToFront(); - urlTitle[pageId].setPadding(leftPad, 0, rightPad, 0); - return true; - } - - } - - public void removeView(WebView view) { + public static void removeView(WebView view) { if (!showFullScreen) { view.startAnimation(fadeOut); } background.removeView(view); - uBar.bringToFront(); + urlBar.bringToFront(); } - public void deleteBookmark(String url) { - File book = new File(getBaseContext().getFilesDir(), "bookmarks"); - File bookUrl = new File(getBaseContext().getFilesDir(), "bookurl"); + private static IncognitoModeActivity ACTIVITY; + + public static void deleteBookmark(String url) { + File book = new File(CONTEXT.getFilesDir(), "bookmarks"); + File bookUrl = new File(CONTEXT.getFilesDir(), "bookurl"); int n = 0; try { BufferedWriter bookWriter = new BufferedWriter(new FileWriter(book)); @@ -774,144 +236,7 @@ public class IncognitoModeActivity extends Activity { readUrl.close(); } catch (IOException ignored) { } - openBookmarks(main[pageId]); - } - - public class WebPageLongClickListener implements OnLongClickListener { - - @Override - public boolean onLongClick(View v) { - final HitTestResult result = main[pageId].getHitTestResult(); - if (main[pageId].getUrl().contains( - "file:///" + getBaseContext().getFilesDir() - + "/bookmarks.html")) { - if (result.getExtra() != null) { - DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - switch (which) { - case DialogInterface.BUTTON_POSITIVE: { - int num = pageId; - newTab(number, result.getExtra(), false, false); - // urlTitle[num].performClick(); - pageId = num; - break; - } - case DialogInterface.BUTTON_NEGATIVE: { - main[pageId].loadUrl(result.getExtra()); - break; - } - case DialogInterface.BUTTON_NEUTRAL: { - - deleteBookmark(result.getExtra()); - break; - } - } - } - }; - - AlertDialog.Builder builder = new AlertDialog.Builder( - CONTEXT); // dialog - builder.setMessage( - "What would you like to do with this link?") - .setPositiveButton("Open in New Tab", - dialogClickListener) - .setNegativeButton("Open Normally", - dialogClickListener) - .setNeutralButton("Delete", dialogClickListener) - .show(); - } - return true; - } else if (result.getExtra() != null) { - if (result.getType() == 5 && API > 8) { - DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - switch (which) { - case DialogInterface.BUTTON_POSITIVE: { - int num = pageId; - newTab(number, result.getExtra(), false, false); - // urlTitle[num].performClick(); - pageId = num; - break; - } - case DialogInterface.BUTTON_NEGATIVE: { - main[pageId].loadUrl(result.getExtra()); - break; - } - case DialogInterface.BUTTON_NEUTRAL: { - if (API > 8) { - String url = result.getExtra(); - - Utils.downloadFile(CONTEXT, url, null, null); - - } - break; - } - } - } - }; - - AlertDialog.Builder builder = new AlertDialog.Builder( - CONTEXT); // dialog - builder.setMessage( - "What would you like to do with this link?") - .setPositiveButton("Open in New Tab", - dialogClickListener) - .setNegativeButton("Open Normally", - dialogClickListener) - .setNeutralButton("Download Image", - dialogClickListener).show(); - - } else { - DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - switch (which) { - case DialogInterface.BUTTON_POSITIVE: { - int num = pageId; - newTab(number, result.getExtra(), false, false); - pageId = num; - break; - } - case DialogInterface.BUTTON_NEGATIVE: { - main[pageId].loadUrl(result.getExtra()); - break; - } - case DialogInterface.BUTTON_NEUTRAL: { - - if (API < 11) { - android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); - clipboard.setText(result.getExtra()); - } else { - ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText( - "label", result.getExtra()); - clipboard.setPrimaryClip(clip); - } - break; - } - } - } - }; - - AlertDialog.Builder builder = new AlertDialog.Builder( - CONTEXT); // dialog - builder.setMessage( - "What would you like to do with this link?") - .setPositiveButton("Open in New Tab", - dialogClickListener) - .setNegativeButton("Open Normally", - dialogClickListener) - .setNeutralButton("Copy link", dialogClickListener) - .show(); - } - return true; - } else { - return false; - } - } - + openBookmarks(CONTEXT, main[pageId]); } // variables to differentiate free from paid @@ -919,15 +244,15 @@ public class IncognitoModeActivity extends Activity { public static final int MAX_BOOKMARKS = FinalVariables.MAX_BOOKMARKS; public static final boolean PAID_VERSION = FinalVariables.PAID_VERSION; - public final Context CONTEXT = IncognitoModeActivity.this; + public static Context CONTEXT; public static final String HOMEPAGE = FinalVariables.HOMEPAGE; public static String SEARCH; public static SimpleAdapter adapter; public static MultiAutoCompleteTextView getUrl; - public static final TextView[] urlTitle = new TextView[MAX_TABS]; - public final static IncognitoWebView[] main = new IncognitoWebView[MAX_TABS]; + public static TextView[] urlTitle = new TextView[MAX_TABS]; + public static final IncognitoWebView[] main = new IncognitoWebView[MAX_TABS]; public static Rect bounds; public static ValueCallback mUploadMessage; public static ImageView refresh; @@ -936,7 +261,6 @@ public class IncognitoModeActivity extends Activity { public static Drawable webpageOther; public static Drawable incognitoPage; public static Drawable exitTab; - public static int numberPage; public static long loadTime = 0; public static int number; public static int pageId = 0; @@ -948,6 +272,7 @@ public class IncognitoModeActivity extends Activity { public static int pixels; public static int leftPad; public static int rightPad; + public static ProgressBar browserProgress; public static final int API = FinalVariables.API; public static int mShortAnimationDuration; public static int id; @@ -955,8 +280,6 @@ public class IncognitoModeActivity extends Activity { public static int urlColumn; public static int titleColumn; public static int closeWindow; - public static View mCustomView = null; - public static CustomViewCallback mCustomViewCallback; public static boolean isPhone = false; public static boolean allowLocation; public static boolean savePasswords; @@ -972,15 +295,14 @@ public class IncognitoModeActivity extends Activity { public static String urlA; public static String title; public static String[] memoryURL = new String[MAX_TABS]; - public static final String[] bUrl = new String[MAX_BOOKMARKS]; - public static final String[] bTitle = new String[MAX_BOOKMARKS]; + public static String[] bUrl = new String[MAX_BOOKMARKS]; + public static String[] bTitle = new String[MAX_BOOKMARKS]; public static String[] columns; public static String homepage; public static final String preferences = "settings"; - public static String userAgent; - public static final String[][] urlToLoad = new String[MAX_TABS][2]; + public static String[][] urlToLoad = new String[MAX_TABS][2]; public static FrameLayout background; - public static RelativeLayout uBar; + public static RelativeLayout urlBar; public static HorizontalScrollView tabScroll; public static Animation slideUp; public static Animation slideDown; @@ -1009,7 +331,10 @@ public class IncognitoModeActivity extends Activity { public static LinearLayout tabLayout; - @SuppressWarnings("unused") + public static String[] GetArray(String input) { + return input.split("\\|\\$\\|SEPARATOR\\|\\$\\|"); + } + public static void setFavicon(int id, Bitmap favicon) { Drawable icon = null; icon = new BitmapDrawable(null, favicon); @@ -1022,34 +347,13 @@ public class IncognitoModeActivity extends Activity { } @SuppressLint("SetJavaScriptEnabled") - IncognitoWebView browserSettings(IncognitoWebView view) { - view.setAnimationCacheEnabled(false); - view.setDrawingCacheEnabled(true); - view.setBackgroundColor(getResources().getColor(android.R.color.white)); - view.setDrawingCacheBackgroundColor(getResources().getColor( - android.R.color.white)); - view.setWillNotCacheDrawing(false); - view.setLongClickable(true); - view.setAlwaysDrawnWithCacheEnabled(true); - view.setScrollbarFadingEnabled(true); - view.setFocusable(true); - view.setFocusableInTouchMode(true); - view.setSaveEnabled(true); - view.setBackgroundColor(0xFFFFFFFF); + public static void browserSettings(Context context, IncognitoWebView view) { WebSettings webViewSettings = view.getSettings(); if (settings.getBoolean("java", true)) { webViewSettings.setJavaScriptEnabled(true); - webViewSettings.setJavaScriptCanOpenWindowsAutomatically(true); // TODO - // not - // sure - // whether - // to - // enable - // or - // disable + webViewSettings.setJavaScriptCanOpenWindowsAutomatically(true); } - webViewSettings.setAllowFileAccess(true); if (API < 14) { switch (settings.getInt("textsize", 3)) { case 1: @@ -1090,10 +394,6 @@ public class IncognitoModeActivity extends Activity { } webViewSettings.setSupportMultipleWindows(settings.getBoolean( "newwindow", true)); - webViewSettings.setDomStorageEnabled(true); - webViewSettings.setAppCacheEnabled(true); - webViewSettings.setAppCachePath(getApplicationContext().getFilesDir() - .getAbsolutePath() + "/cache"); switch (settings.getInt("enableflash", 0)) { case 0: @@ -1109,42 +409,29 @@ public class IncognitoModeActivity extends Activity { default: break; } - - if (API < 18) { - if (settings.getBoolean("passwords", false)) { + if (settings.getBoolean("passwords", false)) { + if (API < 18) { webViewSettings.setSavePassword(true); - webViewSettings.setSaveFormData(true); } + webViewSettings.setSaveFormData(true); + } + if (API < 18) { try { - webViewSettings.setLightTouchEnabled(true); webViewSettings.setRenderPriority(RenderPriority.HIGH); - } catch (SecurityException ignored) { } - } else { - if (settings.getBoolean("passwords", false)) { - webViewSettings.setSaveFormData(true); - } } - webViewSettings.setGeolocationEnabled(true); - webViewSettings.setGeolocationDatabasePath(getApplicationContext() - .getFilesDir().getAbsolutePath()); - webViewSettings.setDatabaseEnabled(true); - webViewSettings.setDatabasePath(getApplicationContext().getFilesDir() - .getAbsolutePath() + "/databases"); + webViewSettings.setGeolocationEnabled(settings.getBoolean("location", + false)); + webViewSettings.setGeolocationDatabasePath(context.getFilesDir() + .getAbsolutePath()); - webViewSettings.setUserAgentString(userAgent); - webViewSettings.setSupportZoom(true); - webViewSettings.setBuiltInZoomControls(true); webViewSettings.setUseWideViewPort(settings.getBoolean("wideviewport", true)); webViewSettings.setLoadWithOverviewMode(settings.getBoolean( "overviewmode", true)); - if (API >= 11) { - webViewSettings.setDisplayZoomControls(false); - webViewSettings.setAllowContentAccess(true); - } + if (settings.getBoolean("textreflow", false)) { webViewSettings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS); } else { @@ -1154,7 +441,7 @@ public class IncognitoModeActivity extends Activity { webViewSettings.setBlockNetworkImage(settings.getBoolean("blockimages", false)); webViewSettings.setLoadsImagesAutomatically(true); - return view; + } void deleteTab(final int del) { @@ -1194,7 +481,7 @@ public class IncognitoModeActivity extends Activity { }); urlTitle[del].startAnimation(yolo); - uBar.bringToFront(); + urlBar.bringToFront(); } void findNewView(int id) { @@ -1210,7 +497,7 @@ public class IncognitoModeActivity extends Activity { if (urlTitle[id].isShown()) { background.addView(main[id]); main[id].setVisibility(View.VISIBLE); - uBar.bringToFront(); + urlBar.bringToFront(); if (API < 16) { urlTitle[id].setBackgroundDrawable(active); } else { @@ -1222,9 +509,11 @@ public class IncognitoModeActivity extends Activity { getUrl.setPadding(tenPad, 0, tenPad, 0); right = true; if (main[id].getProgress() < 100) { + onProgressChanged(id, main[id].getProgress()); refresh.setVisibility(View.INVISIBLE); progressBar.setVisibility(View.VISIBLE); } else { + onProgressChanged(id, main[id].getProgress()); progressBar.setVisibility(View.GONE); refresh.setVisibility(View.VISIBLE); } @@ -1238,7 +527,7 @@ public class IncognitoModeActivity extends Activity { if (urlTitle[leftId].isShown()) { background.addView(main[leftId]); main[leftId].setVisibility(View.VISIBLE); - // uBar.bringToFront(); + // urlBar.bringToFront(); if (API < 16) { urlTitle[leftId].setBackgroundDrawable(active); } else { @@ -1250,9 +539,11 @@ public class IncognitoModeActivity extends Activity { getUrl.setPadding(tenPad, 0, tenPad, 0); left = true; if (main[leftId].getProgress() < 100) { + onProgressChanged(leftId, main[leftId].getProgress()); refresh.setVisibility(View.INVISIBLE); progressBar.setVisibility(View.VISIBLE); } else { + onProgressChanged(leftId, main[leftId].getProgress()); progressBar.setVisibility(View.GONE); refresh.setVisibility(View.VISIBLE); } @@ -1270,7 +561,7 @@ public class IncognitoModeActivity extends Activity { if (!(right || left)) { finish(); } - uBar.bringToFront(); + urlBar.bringToFront(); tabScroll.smoothScrollTo(urlTitle[pageId].getLeft(), 0); } @@ -1294,7 +585,7 @@ public class IncognitoModeActivity extends Activity { case KeyEvent.KEYCODE_ENTER: InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0); - searchTheWeb(getUrl.getText().toString()); + searchTheWeb(getUrl.getText().toString(), CONTEXT); return true; default: break; @@ -1316,7 +607,7 @@ public class IncognitoModeActivity extends Activity { || (arg2.getAction() == KeyEvent.KEYCODE_ENTER)) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0); - searchTheWeb(getUrl.getText().toString()); + searchTheWeb(getUrl.getText().toString(), CONTEXT); return true; } return false; @@ -1377,10 +668,10 @@ public class IncognitoModeActivity extends Activity { if (c != null) { noStockBrowser = false; - Log.i("Barebones", "detected AOSP browser"); + Log.i("Browser", "detected AOSP browser"); } else { noStockBrowser = true; - Log.e("Barebones", "did not detect AOSP browser"); + Log.e("Browser", "did not detect AOSP browser"); } if (c != null) { c.close(); @@ -1432,7 +723,6 @@ public class IncognitoModeActivity extends Activity { } }); - updateAutoComplete.setPriority(3); try { updateAutoComplete.start(); } catch (NullPointerException ignored) { @@ -1451,13 +741,14 @@ public class IncognitoModeActivity extends Activity { String url; url = ((TextView) arg1.findViewById(R.id.url)).getText() .toString(); - searchTheWeb(url); + getUrl.setText(url); + searchTheWeb(url, CONTEXT); url = null; getUrl.setPadding(tenPad, 0, tenPad, 0); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0); } catch (NullPointerException e) { - Log.e("Barebones Error: ", + Log.e("Browser Error: ", "NullPointerException on item click"); } } @@ -1505,8 +796,10 @@ public class IncognitoModeActivity extends Activity { public void finish() { background.clearDisappearingChildren(); tabScroll.clearDisappearingChildren(); - main[pageId].clearCache(true); - Log.i("Lightning", "Cache Cleared"); + if (settings.getBoolean("cache", false)) { + main[pageId].clearCache(true); + Log.i("Lightning", "Cache Cleared"); + } super.finish(); } @@ -1529,9 +822,9 @@ public class IncognitoModeActivity extends Activity { }); } - void goBookmarks(IncognitoWebView view) { - File book = new File(getBaseContext().getFilesDir(), "bookmarks"); - File bookUrl = new File(getBaseContext().getFilesDir(), "bookurl"); + static void goBookmarks(Context context, IncognitoWebView view) { + File book = new File(context.getFilesDir(), "bookmarks"); + File bookUrl = new File(context.getFilesDir(), "bookurl"); try { BufferedReader readBook = new BufferedReader(new FileReader(book)); BufferedReader readUrl = new BufferedReader(new FileReader(bookUrl)); @@ -1549,11 +842,11 @@ public class IncognitoModeActivity extends Activity { } catch (FileNotFoundException ignored) { } catch (IOException ignored) { } - openBookmarks(view); + openBookmarks(context, view); } @SuppressLint("InlinedApi") - void initialize() { + private void initialize() { DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); historyHandler = new DatabaseHandler(this); @@ -1562,6 +855,8 @@ public class IncognitoModeActivity extends Activity { cookieManager.setAcceptCookie(false); progressBar = (ProgressBar) findViewById(R.id.progressBar1); + browserProgress = (ProgressBar) findViewById(R.id.progressBar); + browserProgress.setVisibility(View.GONE); if (API >= 11) { progressBar.setIndeterminateDrawable(getResources().getDrawable( @@ -1572,7 +867,7 @@ public class IncognitoModeActivity extends Activity { } showFullScreen = settings.getBoolean("fullscreen", false); - uBar = (RelativeLayout) findViewById(R.id.urlBar); + urlBar = (RelativeLayout) findViewById(R.id.urlBar); RelativeLayout bg = (RelativeLayout) findViewById(R.id.background); slideUp = AnimationUtils.loadAnimation(this, R.anim.slide_up); slideDown = AnimationUtils.loadAnimation(this, R.anim.slide_down); @@ -1587,7 +882,7 @@ public class IncognitoModeActivity extends Activity { @Override public void onAnimationEnd(Animation arg0) { - uBar.setVisibility(View.GONE); + urlBar.setVisibility(View.GONE); } @Override @@ -1616,7 +911,7 @@ public class IncognitoModeActivity extends Activity { @Override public void onAnimationStart(Animation animation) { - uBar.setVisibility(View.VISIBLE); + urlBar.setVisibility(View.VISIBLE); } }); @@ -1657,6 +952,9 @@ public class IncognitoModeActivity extends Activity { case 6: SEARCH = FinalVariables.BAIDU_SEARCH; break; + case 7: + SEARCH = FinalVariables.YANDEX_SEARCH; + break; } exitTab = getResources().getDrawable(R.drawable.stop); // user @@ -1666,9 +964,6 @@ public class IncognitoModeActivity extends Activity { // stored // homepage // variable - - userAgent = settings.getString("agent", mobile); // initializing - // useragent string allowLocation = settings.getBoolean("location", false); // initializing // location // variable @@ -1734,7 +1029,6 @@ public class IncognitoModeActivity extends Activity { @Override public void run() { reopenOldTabs(); // restores old tabs or creates a new one - } }); @@ -1794,14 +1088,14 @@ public class IncognitoModeActivity extends Activity { enterUrl(); if (showFullScreen) { - bg.removeView(uBar); - background.addView(uBar); + bg.removeView(urlBar); + background.addView(urlBar); } browserHandler = new Handle(); } - class Handle extends Handler { + static class Handle extends Handler { @Override public void handleMessage(Message msg) { @@ -1811,7 +1105,7 @@ public class IncognitoModeActivity extends Activity { break; } case 2: { - deleteTab(msg.arg1); + // deleteTab(msg.arg1); break; } case 3: { @@ -1825,25 +1119,37 @@ public class IncognitoModeActivity extends Activity { } void reopenOldTabs() { - // it opens the home-page - newTab(number, homepage, true, false); - main[number - 1].resumeTimers(); + Intent url = getIntent(); + String URL = url.getDataString(); + + if (URL != null) { + // opens a new tab with the URL if its there + newTab(number, URL, true, false); + main[number - 1].resumeTimers(); + + } else { + // otherwise it opens the home-page + newTab(number, homepage, true, false); + main[number - 1].resumeTimers(); + + } } - public IncognitoWebView makeTab(final int pageToView, String Url, + public static IncognitoWebView makeTab(final int pageToView, String Url, final boolean display) { IncognitoWebView view = new IncognitoWebView(CONTEXT); view.setId(pageToView); allowLocation = settings.getBoolean("location", false); - view.setWebViewClient(new IncognitoWebViewClient()); - view.setWebChromeClient(new CustomChromeClient()); + browserSettings(CONTEXT, view); + view.setWebViewClient(new IncognitoWebViewClient(ACTIVITY)); + view.setWebChromeClient(new IncognitoChromeClient(ACTIVITY)); if (API > 8) { - view.setDownloadListener(new CustomDownloadListener()); + view.setDownloadListener(new IncognitoDownloadListener(ACTIVITY)); } - view.setOnLongClickListener(new WebPageLongClickListener()); - view = browserSettings(view); + view.setOnLongClickListener(new IncognitoLongClickListener()); + agentPicker = settings.getInt("agentchoose", 1); switch (agentPicker) { case 1: @@ -1855,6 +1161,9 @@ public class IncognitoModeActivity extends Activity { case 3: view.getSettings().setUserAgentString(mobile); break; + case 4: + view.getSettings().setUserAgentString(settings.getString("userAgentString", defaultUser)); + break; } if (display) { background.removeView(main[pageId]); @@ -1862,9 +1171,9 @@ public class IncognitoModeActivity extends Activity { view.requestFocus(); pageId = pageToView; } - uBar.bringToFront(); + urlBar.bringToFront(); if (Url.contains("about:home")) { - goBookmarks(view); + goBookmarks(CONTEXT, view); } else if (Url.contains("about:blank")) { view.loadUrl(""); } else { @@ -1874,18 +1183,18 @@ public class IncognitoModeActivity extends Activity { view.loadUrl(Url); } - Log.i("Barebones", "tab complete"); + Log.i("Browser", "tab complete"); return view; } - void newSettings() { + private void newSettings() { startActivity(new Intent(FinalVariables.SETTINGS_INTENT)); } // new tab method, takes the id of the tab to be created and the url to load - int newTab(int theId, final String theUrl, final boolean display, - final boolean incognito_mode) { - Log.i("Barebones", "making tab"); + public static int newTab(int theId, final String theUrl, + final boolean display, final boolean incognito_mode) { + Log.i("Browser", "making tab"); int finalID = 0; homepage = settings.getString("home", HOMEPAGE); @@ -1896,7 +1205,8 @@ public class IncognitoModeActivity extends Activity { if (urlTitle[num].getVisibility() == View.GONE) { final int n = num; - Animation holo = AnimationUtils.loadAnimation(this, R.anim.up); + Animation holo = AnimationUtils.loadAnimation(CONTEXT, + R.anim.up); holo.setAnimationListener(new AnimationListener() { @Override @@ -1941,11 +1251,12 @@ public class IncognitoModeActivity extends Activity { exitTab, null); urlTitle[num].setPadding(leftPad, 0, rightPad, 0); urlTitle[pageId].setPadding(leftPad, 0, rightPad, 0); + main[num] = makeTab(num, theUrl, display); finalID = num; pageId = num; - uBar.bringToFront(); + urlBar.bringToFront(); if (API >= 11) { main[num].onResume(); @@ -1995,8 +1306,9 @@ public class IncognitoModeActivity extends Activity { Drawable[] drawables = title.getCompoundDrawables(); bounds = drawables[2].getBounds(); - title.setOnTouchListener(new TabTouchListener()); - Animation holo = AnimationUtils.loadAnimation(this, R.anim.up); + title.setOnTouchListener(ACTIVITY); + Animation holo = AnimationUtils.loadAnimation(CONTEXT, + R.anim.up); tabLayout.addView(title); title.setVisibility(View.INVISIBLE); holo.setAnimationListener(new AnimationListener() { @@ -2053,21 +1365,22 @@ public class IncognitoModeActivity extends Activity { @Override public void onBackPressed() { - if (showFullScreen && !uBar.isShown()) { - uBar.startAnimation(slideDown); + try { + if (showFullScreen && !urlBar.isShown()) { + urlBar.startAnimation(slideDown); + } + if (main[pageId].isShown() && main[pageId].canGoBack()) { + main[pageId].goBack(); + } else { + deleteTab(pageId); + urlBar.bringToFront(); + } + } catch (NullPointerException ignored) { } - if (main[pageId].isShown() && main[pageId].canGoBack()) { - main[pageId].goBack(); - } else { - deleteTab(pageId); - uBar.bringToFront(); - } - } @Override public void onConfigurationChanged(Configuration newConfig) { - // TODO super.onConfigurationChanged(newConfig); if (settings.getBoolean("textreflow", false)) { main[pageId].getSettings().setLayoutAlgorithm( @@ -2083,9 +1396,23 @@ public class IncognitoModeActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // displays main xml layout + CONTEXT = this; + ACTIVITY = this; settings = getSharedPreferences(preferences, 0); edit = settings.edit(); + if (settings.getBoolean("hidestatus", false)) { + getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN); + } + + saveTabs = settings.getBoolean("savetabs", true); + if (saveTabs) { + String mem = settings.getString("memory", ""); + edit.putString("memory", ""); + memoryURL = GetArray(mem); + } + inactive = getResources().getDrawable(R.drawable.bg_inactive); active = getResources().getDrawable(R.drawable.bg_press); initialize(); // sets up random stuff @@ -2102,6 +1429,17 @@ public class IncognitoModeActivity extends Activity { isPhone = sizeInInches < 6.5; forward();// forward button back(); + int first = settings.getInt("second", 0); + + if (first == 0) { // This dialog alerts the user to some navigation + // techniques + String message = "Incognito mode does not add the pages you visit to your history," + + " so no one can see where you've been. For protection from tracking, Incognito also does" + + " not allow browser Cookies."; + Utils.createInformativeDialog(CONTEXT, "About Incognito", message); + edit.putInt("second", 1); + edit.commit(); + } } @Override @@ -2113,6 +1451,21 @@ public class IncognitoModeActivity extends Activity { return true; } + /* + * (non-Javadoc) + * + * @see android.app.Activity#onKeyDown(int, android.view.KeyEvent) + */ + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_SEARCH) { + getUrl.requestFocus(); + InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + manager.showSoftInput(getUrl, 0); + } + return super.onKeyDown(keyCode, event); + } + @Override public boolean onKeyLongPress(int keyCode, KeyEvent event) { @@ -2128,28 +1481,63 @@ public class IncognitoModeActivity extends Activity { return super.onKeyLongPress(keyCode, event); } + @Override + protected void onNewIntent(Intent intent) { + + String url = intent.getDataString(); + int id = -1; + int download = -1; + try { + id = intent.getExtras().getInt("acr.browser.barebones.Origin") - 1; + } catch (NullPointerException e) { + id = -1; + } + try { + download = intent.getExtras().getInt( + "acr.browser.barebones.Download"); + } catch (NullPointerException e) { + download = -1; + } + if (id >= 0) { + main[id].loadUrl(url); + } else if (download == 1) { + Utils.downloadFile(CONTEXT, url, null, null); + } else if (url != null) { + newTab(number, url, true, false); + } + + super.onNewIntent(intent); + } + @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.history: - generateHistory(main[pageId]); + generateHistory(main[pageId], CONTEXT); + return true; + case R.id.bookmark: + if (urlToLoad[pageId][1] != null) { + if (!urlToLoad[pageId][1].equals("Bookmarks")) { + Utils.addBookmark(CONTEXT, urlToLoad[pageId][1], + urlToLoad[pageId][0]); + } + } return true; case R.id.settings: newSettings(); return true; case R.id.allBookmarks: if (urlToLoad[pageId][1] == null) { - goBookmarks(main[pageId]); + goBookmarks(CONTEXT, main[pageId]); } else if (!urlToLoad[pageId][1].equals("Bookmarks")) { - goBookmarks(main[pageId]); + goBookmarks(CONTEXT, main[pageId]); } return true; case R.id.incognito: - startActivity(new Intent(FinalVariables.INCOGNITO_INTENT)); - // newTab(number, homepage, true, true); + newTab(number, homepage, true, true); return true; default: return super.onOptionsItemSelected(item); @@ -2158,19 +1546,34 @@ public class IncognitoModeActivity extends Activity { @Override protected void onPause() { - super.onPause(); + if (main[pageId] != null) { if (API >= 11) { main[pageId].onPause(); } main[pageId].pauseTimers(); } + Thread remember = new Thread(new Runnable() { + @Override + public void run() { + String s = ""; + for (int n = 0; n < MAX_TABS; n++) { + if (urlToLoad[n][0] != null) { + s = s + urlToLoad[n][0] + "|$|SEPARATOR|$|"; + } + } + edit.putString("memory", s); + edit.commit(); + } + }); + remember.start(); + super.onPause(); } @Override protected void onResume() { - super.onResume(); + onProgressChanged(pageId, main[pageId].getProgress()); if (main[pageId].getProgress() == 100) { progressBar.setVisibility(View.GONE); refresh.setVisibility(View.VISIBLE); @@ -2179,10 +1582,10 @@ public class IncognitoModeActivity extends Activity { main[pageId].onResume(); } main[pageId].resumeTimers(); - + super.onResume(); } - void openBookmarks(IncognitoWebView view) { + static void openBookmarks(Context context, IncognitoWebView view) { String bookmarkHtml = BookmarkPageVariables.Heading; for (int n = 0; n < MAX_BOOKMARKS; n++) { @@ -2193,8 +1596,7 @@ public class IncognitoModeActivity extends Activity { } } bookmarkHtml += BookmarkPageVariables.End; - File bookmarkWebPage = new File(getBaseContext().getFilesDir(), - "bookmarks.html"); + File bookmarkWebPage = new File(context.getFilesDir(), "bookmarks.html"); try { FileWriter bookWriter = new FileWriter(bookmarkWebPage, false); bookWriter.write(bookmarkHtml); @@ -2202,9 +1604,9 @@ public class IncognitoModeActivity extends Activity { } catch (IOException e) { e.printStackTrace(); } - view.loadUrl("file:///" + bookmarkWebPage); + view.loadUrl("file://" + bookmarkWebPage); - if (uBar.isShown()) { + if (urlBar.isShown()) { urlTitle[pageId].setText("Bookmarks"); setUrlText(""); getUrl.setPadding(tenPad, 0, tenPad, 0); @@ -2231,24 +1633,32 @@ public class IncognitoModeActivity extends Activity { switch (item.getItemId()) { case R.id.history: - generateHistory(main[pageId]); + generateHistory(main[pageId], CONTEXT); + return true; + case R.id.bookmark: + if (urlToLoad[pageId][1] != null) { + if (!urlToLoad[pageId][1] + .equals("Bookmarks")) { + Utils.addBookmark(CONTEXT, + urlToLoad[pageId][1], + urlToLoad[pageId][0]); + } + } return true; case R.id.settings: newSettings(); return true; case R.id.allBookmarks: if (urlToLoad[pageId][1] == null) { - goBookmarks(main[pageId]); + goBookmarks(CONTEXT, main[pageId]); } else if (!urlToLoad[pageId][1] .equals("Bookmarks")) { - goBookmarks(main[pageId]); + goBookmarks(CONTEXT, main[pageId]); } return true; case R.id.incognito: - startActivity(new Intent( - FinalVariables.INCOGNITO_INTENT)); - // newTab(number, homepage, true, true); + newTab(number, homepage, true, true); return true; default: return false; @@ -2275,7 +1685,7 @@ public class IncognitoModeActivity extends Activity { }); } - void searchTheWeb(String query) { + static void searchTheWeb(String query, Context context) { query = query.trim(); main[pageId].stopLoading(); @@ -2295,9 +1705,9 @@ public class IncognitoModeActivity extends Activity { boolean isSearch = ((query.contains(" ") || !containsPeriod) && !aboutScheme); if (query.contains("about:home") || query.contains("about:bookmarks")) { - goBookmarks(main[pageId]); + goBookmarks(context, main[pageId]); } else if (query.contains("about:history")) { - generateHistory(main[pageId]); + generateHistory(main[pageId], context); } else if (isSearch) { query.replaceAll(" ", "+"); main[pageId].loadUrl(SEARCH + query); @@ -2307,4 +1717,344 @@ public class IncognitoModeActivity extends Activity { main[pageId].loadUrl(query); } } + + public static void onPageFinished(WebView view, String url) { + if (view.isShown()) { + view.invalidate(); + progressBar.setVisibility(View.GONE); + refresh.setVisibility(View.VISIBLE); + + if (showFullScreen && urlBar.isShown()) { + urlBar.startAnimation(slideUp); + } + } + view.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); + Log.i("Lightning", "Page Finished"); + loadTime = System.currentTimeMillis() - loadTime; + Log.i("Lightning", "Load Time: " + loadTime); + } + + public static void onPageStarted(WebView view, String url, Bitmap favicon) { + Log.i("Lightning", "Page Started"); + loadTime = System.currentTimeMillis(); + int numberPage = view.getId(); + + if (url.startsWith("file://")) { + view.getSettings().setUseWideViewPort(false); + } else { + view.getSettings().setUseWideViewPort( + settings.getBoolean("wideviewport", true)); + } + + if (view.isShown()) { + refresh.setVisibility(View.INVISIBLE); + progressBar.setVisibility(View.VISIBLE); + setUrlText(url); + } + + urlTitle[numberPage].setCompoundDrawables(incognitoPage, null, exitTab, + null); + + getUrl.setPadding(tenPad, 0, tenPad, 0); + urlToLoad[numberPage][0] = url; + + if (!urlBar.isShown() && showFullScreen) { + urlBar.startAnimation(slideDown); + } + } + + public static void onCreateWindow(Message resultMsg) { + newTab(number, "", true, false); + WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj; + transport.setWebView(main[pageId]); + resultMsg.sendToTarget(); + browserHandler.postDelayed(new Runnable() { + @Override + public void run() { + main[pageId].loadUrl(getUrl.getText().toString()); + } + }, 500); + } + + public static void onShowCustomView() { + background.removeView(main[pageId]); + urlBar.setVisibility(View.GONE); + } + + public static void onHideCustomView(FrameLayout fullScreenContainer, + CustomViewCallback mCustomViewCallback, int orientation) { + FrameLayout screen = (FrameLayout) ACTIVITY.getWindow().getDecorView(); + screen.removeView(fullScreenContainer); + fullScreenContainer = null; + mCustomViewCallback.onCustomViewHidden(); + ACTIVITY.setRequestedOrientation(orientation); + background.addView(main[pageId]); + urlBar.setVisibility(View.VISIBLE); + urlBar.bringToFront(); + } + + public static void onReceivedTitle(int numberPage, String title) { + if (title != null && title.length() != 0) { + urlTitle[numberPage].setText(title); + urlToLoad[numberPage][1] = title; + } + } + + public static void openFileChooser(ValueCallback uploadMsg) { + mUploadMessage = uploadMsg; + Intent i = new Intent(Intent.ACTION_GET_CONTENT); + i.addCategory(Intent.CATEGORY_OPENABLE); + i.setType("*/*"); + ACTIVITY.startActivityForResult( + Intent.createChooser(i, "File Chooser"), 1); + } + + @Override + public boolean onTouch(View v, MotionEvent event) { + id = v.getId(); + background.clearDisappearingChildren(); + boolean xPress = false; + int x = (int) event.getX(); + int y = (int) event.getY(); + Rect edge = new Rect(); + v.getLocalVisibleRect(edge); + + urlTitle[pageId].setPadding(leftPad, 0, rightPad, 0); + if (event.getAction() == MotionEvent.ACTION_UP) { + if (x >= (edge.right - bounds.width() - v.getPaddingRight() - 10 * 3 / 2) + && x <= (edge.right - v.getPaddingRight() + 10 * 3 / 2) + && y >= (v.getPaddingTop() - 10 / 2) + && y <= (v.getHeight() - v.getPaddingBottom() + 10 / 2)) { + xPress = true; + } + if (id == pageId) { + if (xPress) { + deleteTab(id); + urlBar.bringToFront(); + } + } else if (id != pageId) { + if (xPress) { + deleteTab(id); + } else { + if (API < 16) { + urlTitle[pageId].setBackgroundDrawable(inactive); + } else if (API > 15) { + urlTitle[pageId].setBackground(inactive); + } + urlTitle[pageId].setPadding(leftPad, 0, rightPad, 0); + if (!showFullScreen) { + background.addView(main[id]); + main[id].startAnimation(fadeIn); + main[pageId].startAnimation(fadeOut); + background.removeView(main[pageId]); + urlBar.bringToFront(); + } else if (API >= 12) { + main[id].setAlpha(0f); + background.addView(main[id]); + try { + main[id].animate().alpha(1f) + .setDuration(mShortAnimationDuration); + } catch (NullPointerException ignored) { + } + background.removeView(main[pageId]); + urlBar.bringToFront(); + } else { + background.removeView(main[pageId]); + background.addView(main[id]); + } + urlBar.bringToFront(); + + pageId = id; + setUrlText(urlToLoad[pageId][0]); + getUrl.setPadding(tenPad, 0, tenPad, 0); + if (API < 16) { + urlTitle[pageId].setBackgroundDrawable(active); + } else if (API > 15) { + urlTitle[pageId].setBackground(active); + } + if (main[pageId].getProgress() < 100) { + refresh.setVisibility(View.INVISIBLE); + progressBar.setVisibility(View.VISIBLE); + } else { + progressBar.setVisibility(View.GONE); + refresh.setVisibility(View.VISIBLE); + } + onProgressChanged(pageId, main[pageId].getProgress()); + tabScroll.smoothScrollTo(urlTitle[pageId].getLeft(), 0); + main[pageId].invalidate(); + } + } + + } + urlBar.bringToFront(); + v.setPadding(leftPad, 0, rightPad, 0); + return true; + } + + public static class ClickHandler extends Handler { + + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + String url = null; + url = msg.getData().getString("url"); + handleLongClickOnBookmarks(url, msg.arg1); + } + + } + + public static boolean onLongClick(final int n) { + final HitTestResult result = main[n].getHitTestResult(); + + if (main[n].getUrl().contains( + "file://" + CONTEXT.getFilesDir() + "/bookmarks.html")) { + + Message message = new Message(); + message.arg1 = n; + message.setTarget(new ClickHandler()); + main[n].requestFocusNodeHref(message); + + return true; + } else if (result.getExtra() != null) { + if (result.getType() == 5 && API > 8) { + DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + switch (which) { + case DialogInterface.BUTTON_POSITIVE: { + int num = pageId; + newTab(number, result.getExtra(), false, false); + // urlTitle[num].performClick(); + pageId = num; + break; + } + case DialogInterface.BUTTON_NEGATIVE: { + main[n].loadUrl(result.getExtra()); + break; + } + case DialogInterface.BUTTON_NEUTRAL: { + if (API > 8) { + String url = result.getExtra(); + + Utils.downloadFile(CONTEXT, url, null, null); + + } + break; + } + } + } + }; + + AlertDialog.Builder builder = new AlertDialog.Builder(CONTEXT); // dialog + builder.setMessage("What would you like to do with this image?") + .setPositiveButton("Open in New Tab", + dialogClickListener) + .setNegativeButton("Open Normally", dialogClickListener) + .setNeutralButton("Download Image", dialogClickListener) + .show(); + + } else { + DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + switch (which) { + case DialogInterface.BUTTON_POSITIVE: { + int num = pageId; + newTab(number, result.getExtra(), false, false); + pageId = num; + break; + } + case DialogInterface.BUTTON_NEGATIVE: { + main[n].loadUrl(result.getExtra()); + break; + } + case DialogInterface.BUTTON_NEUTRAL: { + + if (API < 11) { + android.text.ClipboardManager clipboard = (android.text.ClipboardManager) ACTIVITY + .getSystemService(Context.CLIPBOARD_SERVICE); + clipboard.setText(result.getExtra()); + } else { + ClipboardManager clipboard = (ClipboardManager) ACTIVITY + .getSystemService(CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText("label", + result.getExtra()); + clipboard.setPrimaryClip(clip); + } + break; + } + } + } + }; + + AlertDialog.Builder builder = new AlertDialog.Builder(CONTEXT); // dialog + builder.setTitle(result.getExtra()).setMessage("What do you want to do with this link?") + .setPositiveButton("Open in New Tab", + dialogClickListener) + .setNegativeButton("Open Normally", dialogClickListener) + .setNeutralButton("Copy link", dialogClickListener) + .show(); + } + return true; + } else { + return false; + } + } + + public static void handleLongClickOnBookmarks(final String clickedURL, + final int n) { + if (clickedURL != null) { + + DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + switch (which) { + case DialogInterface.BUTTON_POSITIVE: { + int num = pageId; + newTab(number, clickedURL, false, false); + // urlTitle[num].performClick(); + pageId = num; + break; + } + case DialogInterface.BUTTON_NEGATIVE: { + main[n].loadUrl(clickedURL); + break; + } + case DialogInterface.BUTTON_NEUTRAL: { + deleteBookmark(clickedURL); + break; + } + } + } + }; + + AlertDialog.Builder builder = new AlertDialog.Builder(CONTEXT); // dialog + builder.setMessage("What would you like to do with this bookmark?") + .setPositiveButton("Open in New Tab", dialogClickListener) + .setNegativeButton("Open Normally", dialogClickListener) + .setNeutralButton("Delete", dialogClickListener).show(); + } + } + + public static void goBack() { + if (main[pageId].isShown() && main[pageId].canGoBack()) { + main[pageId].goBack(); + } + } + + public static void goForward() { + if (main[pageId].isShown() && main[pageId].canGoForward()) { + main[pageId].goForward(); + } + } + public static void onProgressChanged(int id, int progress) { + if (id == pageId) { + browserProgress.setProgress(progress); + if (progress < 100) { + browserProgress.setVisibility(View.VISIBLE); + } else { + browserProgress.setVisibility(View.GONE); + } + } + } } \ No newline at end of file diff --git a/src/acr/browser/barebones/activities/SettingsActivity.java b/src/acr/browser/barebones/activities/SettingsActivity.java index 03c2fd2..fe02977 100644 --- a/src/acr/browser/barebones/activities/SettingsActivity.java +++ b/src/acr/browser/barebones/activities/SettingsActivity.java @@ -1,9 +1,6 @@ package acr.browser.barebones.activities; import acr.browser.barebones.R; -import acr.browser.barebones.R.drawable; -import acr.browser.barebones.R.id; -import acr.browser.barebones.R.layout; import acr.browser.barebones.utilities.FinalVariables; import acr.browser.barebones.utilities.Utils; import android.net.Uri; @@ -19,23 +16,21 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; +import android.graphics.Color; import android.util.Log; +import android.util.TypedValue; import android.view.View; +import android.view.WindowManager; import android.view.View.OnClickListener; -import android.view.animation.Animation; -import android.view.animation.AnimationUtils; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.EditText; import android.widget.ImageView; -import android.widget.RadioButton; -import android.widget.RadioGroup; +import android.widget.LinearLayout; import android.widget.RelativeLayout; -import android.widget.ScrollView; import android.widget.Switch; import android.widget.TextView; -import android.widget.Toast; public class SettingsActivity extends Activity { static int API = FinalVariables.API; @@ -44,6 +39,7 @@ public class SettingsActivity extends Activity { static int agentChoice; static String homepage; static TextView agentText; + static String agent; static TextView download; static int egg = 0; static String downloadLocation; @@ -55,6 +51,7 @@ public class SettingsActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.settings); + init(); } @@ -62,6 +59,10 @@ public class SettingsActivity extends Activity { public void init() { // settings storage settings = getSharedPreferences(preferences, 0); + if (settings.getBoolean("hidestatus", false)) { + getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN); + } edit = settings.edit(); // initialize UI @@ -91,6 +92,9 @@ public class SettingsActivity extends Activity { case 6: searchText.setText("Baidu"); break; + case 7: + searchText.setText("Yandex"); + break; } back.setBackgroundResource(R.drawable.button); @@ -104,9 +108,10 @@ public class SettingsActivity extends Activity { agentChoice = settings.getInt("agentchoose", 1); homepage = settings.getString("home", FinalVariables.HOMEPAGE); downloadLocation = settings.getString("download", - FinalVariables.DOWNLOAD_LOCATION); + Environment.DIRECTORY_DOWNLOADS); - download.setText(downloadLocation); + download.setText(FinalVariables.EXTERNAL_STORAGE + "/" + + downloadLocation); String code = "HOLO"; @@ -133,13 +138,19 @@ public class SettingsActivity extends Activity { switch (agentChoice) { case 1: agentText.setText("Default"); + agent = BrowserActivity.defaultUser; break; case 2: agentText.setText("Desktop"); + agent = FinalVariables.DESKTOP_USER_AGENT; break; case 3: agentText.setText("Mobile"); + agent = FinalVariables.MOBILE_USER_AGENT; break; + case 4: + agentText.setText("Custom"); + agent = settings.getString("userAgentString", BrowserActivity.defaultUser); } RelativeLayout r1, r2, r3; r1 = (RelativeLayout) findViewById(R.id.setR1); @@ -214,7 +225,7 @@ public class SettingsActivity extends Activity { SettingsActivity.this); picker.setTitle("Search Engine"); CharSequence[] chars = { "Google (Suggested)", "Bing", "Yahoo", - "StartPage", "DuckDuckGo (Privacy)" ,"Baidu"}; + "StartPage", "DuckDuckGo (Privacy)" , "Baidu (Chinese)", "Yandex (Russian)"}; int n = settings.getInt("search", 1); @@ -245,6 +256,9 @@ public class SettingsActivity extends Activity { case 6: searchText.setText("Baidu"); break; + case 7: + searchText.setText("Yandex"); + break; } } }); @@ -329,9 +343,8 @@ public class SettingsActivity extends Activity { public void onClick(View v) { egg++; if (egg == 10) { - startActivity(new Intent( - Intent.ACTION_VIEW, - Uri.parse("http://imgs.xkcd.com/comics/compiling.png"))); + startActivity(new Intent(Intent.ACTION_VIEW, Uri + .parse("http://imgs.xkcd.com/comics/compiling.png"))); finish(); egg = 0; } @@ -502,12 +515,20 @@ public class SettingsActivity extends Activity { switch (which + 1) { case 1: agentText.setText("Default"); + agent = BrowserActivity.defaultUser; break; case 2: agentText.setText("Desktop"); + agent = FinalVariables.DESKTOP_USER_AGENT; break; case 3: agentText.setText("Mobile"); + agent = FinalVariables.MOBILE_USER_AGENT; + break; + case 4: + agentText.setText("Custom"); + agent = settings.getString("userAgentString", BrowserActivity.defaultUser); + agentPicker(); break; } } @@ -538,6 +559,27 @@ public class SettingsActivity extends Activity { }); } + + public void agentPicker() { + final AlertDialog.Builder agentStringPicker = new AlertDialog.Builder( + SettingsActivity.this); + + agentStringPicker.setTitle("Custom Agent"); + final EditText getAgent = new EditText(SettingsActivity.this); + agentStringPicker.setView(getAgent); + agentStringPicker.setPositiveButton("OK", + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + String text = getAgent.getText().toString(); + edit.putString("userAgentString", text); + edit.commit(); + agentText.setText("Custom"); + } + }); + agentStringPicker.show(); + } public void download(RelativeLayout view) { view.setOnClickListener(new OnClickListener() { @@ -550,9 +592,9 @@ public class SettingsActivity extends Activity { picker.setTitle("Download Location"); CharSequence[] chars = { "Default", "Custom" }; downloadLocation = settings.getString("download", - FinalVariables.DOWNLOAD_LOCATION); + Environment.DIRECTORY_DOWNLOADS); int n = -1; - if (downloadLocation.contains(FinalVariables.DOWNLOAD_LOCATION)) { + if (downloadLocation.contains(Environment.DIRECTORY_DOWNLOADS)) { n = 1; } else { n = 2; @@ -568,9 +610,11 @@ public class SettingsActivity extends Activity { switch (which + 1) { case 1: edit.putString("download", - FinalVariables.DOWNLOAD_LOCATION); + Environment.DIRECTORY_DOWNLOADS); edit.commit(); - download.setText(FinalVariables.DOWNLOAD_LOCATION); + download.setText(FinalVariables.EXTERNAL_STORAGE + + "/" + + Environment.DIRECTORY_DOWNLOADS); break; case 2: downPicker(); @@ -620,15 +664,42 @@ public class SettingsActivity extends Activity { homePicker.show(); } + @SuppressWarnings("deprecation") public void downPicker() { final AlertDialog.Builder downLocationPicker = new AlertDialog.Builder( SettingsActivity.this); + LinearLayout layout = new LinearLayout(this); downLocationPicker.setTitle("Custom Location"); final EditText getDownload = new EditText(SettingsActivity.this); + getDownload.setBackgroundResource(0); downloadLocation = settings.getString("download", - FinalVariables.DOWNLOAD_LOCATION); + Environment.DIRECTORY_DOWNLOADS); + int padding = Utils.convertDensityPixesl(this, 10); + + LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.MATCH_PARENT); + + getDownload.setLayoutParams(lparams); + getDownload.setTextColor(Color.DKGRAY); getDownload.setText(downloadLocation); - downLocationPicker.setView(getDownload); + getDownload.setPadding(0, padding, padding, padding); + + TextView v = new TextView(this); + v.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); + v.setTextColor(Color.DKGRAY); + v.setText(FinalVariables.EXTERNAL_STORAGE + "/"); + v.setPadding(padding, padding, 0, padding); + layout.addView(v); + layout.addView(getDownload); + if (API < 16) { + layout.setBackgroundDrawable(getResources().getDrawable( + android.R.drawable.edit_text)); + } else { + layout.setBackground(getResources().getDrawable( + android.R.drawable.edit_text)); + } + downLocationPicker.setView(layout); downLocationPicker.setPositiveButton("OK", new DialogInterface.OnClickListener() { @@ -637,7 +708,8 @@ public class SettingsActivity extends Activity { String text = getDownload.getText().toString(); edit.putString("download", text); edit.commit(); - download.setText(text); + download.setText(FinalVariables.EXTERNAL_STORAGE + "/" + + text); } }); downLocationPicker.show(); @@ -708,7 +780,7 @@ public class SettingsActivity extends Activity { @Override public void onClick(View v) { startActivity(new Intent( - "android.intent.action.ADVANCEDSETTINGS")); + FinalVariables.ADVANCED_SETTINGS_INTENT)); } }); diff --git a/src/acr/browser/barebones/customwebview/CustomWebView.java b/src/acr/browser/barebones/customwebview/CustomWebView.java index 9697edf..bbea647 100644 --- a/src/acr/browser/barebones/customwebview/CustomWebView.java +++ b/src/acr/browser/barebones/customwebview/CustomWebView.java @@ -1,59 +1,95 @@ package acr.browser.barebones.customwebview; -import java.lang.reflect.Method; -import acr.browser.barebones.activities.BarebonesActivity; +import acr.browser.barebones.activities.BrowserActivity; import acr.browser.barebones.utilities.FinalVariables; import android.content.Context; -import android.util.Log; +import android.graphics.Point; +import android.util.DisplayMetrics; +import android.view.Display; +import android.view.GestureDetector; +import android.view.GestureDetector.SimpleOnGestureListener; import android.view.MotionEvent; import android.view.View; +import android.view.WindowManager; import android.view.animation.Animation; +import android.webkit.WebSettings; import android.webkit.WebView; -import android.widget.ZoomButtonsController; public final class CustomWebView extends WebView { private float location; private boolean first = false; final int API = FinalVariables.API; - final boolean showFullScreen = BarebonesActivity.showFullScreen; - final View uBar = BarebonesActivity.uBar; - final Animation slideUp = BarebonesActivity.slideUp; - final Animation slideDown = BarebonesActivity.slideDown; - private ZoomButtonsController zoomControl; - private boolean zoomShouldDie = false; + final boolean showFullScreen = BrowserActivity.showFullScreen; + final View uBar = BrowserActivity.uBar; + final Animation slideUp = BrowserActivity.slideUp; + final Animation slideDown = BrowserActivity.slideDown; + static Context CONTEXT; public CustomWebView(Context context) { super(context); - this.setBackgroundResource(0); - - //getControls(); + mGestureDetector = new GestureDetector(context, + new CustomGestureListener()); + CONTEXT = context; + WebSettings settings = this.getSettings(); + browserInitialization(context); + settingsInitialization(context, settings); + } + + public void browserInitialization(Context context) { + this.setDrawingCacheBackgroundColor(0x00000000); + this.setFocusableInTouchMode(true); + this.setFocusable(true); + this.setAnimationCacheEnabled(false); + this.setDrawingCacheEnabled(true); + this.setBackgroundColor(context.getResources().getColor( + android.R.color.white)); + this.setWillNotCacheDrawing(false); + this.setAlwaysDrawnWithCacheEnabled(true); + this.setScrollbarFadingEnabled(true); + this.setSaveEnabled(true); + } + + @SuppressWarnings("deprecation") + public void settingsInitialization(Context context, WebSettings settings) { + settings.setDomStorageEnabled(true); + settings.setAppCacheEnabled(true); + settings.setAppCachePath(context.getFilesDir().getAbsolutePath() + + "/cache"); + if (API < 18) { + settings.setLightTouchEnabled(true); + } + settings.setAllowFileAccess(true); + settings.setDatabaseEnabled(true); + settings.setDatabasePath(context.getFilesDir().getAbsolutePath() + + "/databases"); + settings.setSupportZoom(true); + settings.setBuiltInZoomControls(true); + if (API >= 11) { + settings.setDisplayZoomControls(false); + settings.setAllowContentAccess(true); + } } @Override public boolean onTouchEvent(MotionEvent event) { - - /*if (zoomShouldDie) { - try { - zoomControl.getZoomControls().setVisibility(View.INVISIBLE); - } catch (IllegalArgumentException ignored) { - } - }*/ + switch (event.getAction()) { case MotionEvent.ACTION_DOWN: { first = true; - if (API <= 10 && !this.hasFocus()) { - this.requestFocus(); + if (API <= 10 && !hasFocus()) { + requestFocus(); } location = event.getY(); break; } case MotionEvent.ACTION_UP: { + if (showFullScreen && first) { - if (uBar.isShown() && this.getScrollY() < 5) { + if (uBar.isShown() && getScrollY() < 5) { uBar.startAnimation(slideUp); - } else if (event.getY() > location && !uBar.isShown()) { + } else if ((event.getY() - location) > 20.0 && !uBar.isShown()) { uBar.startAnimation(slideDown); - } else if (event.getY() < location && uBar.isShown()) { + } else if ((event.getY() - location) < -20.0 && uBar.isShown()) { uBar.startAnimation(slideUp); } first = false; @@ -61,33 +97,67 @@ public final class CustomWebView extends WebView { break; } } - + mGestureDetector.onTouchEvent(event); return super.onTouchEvent(event); } @Override protected void onWindowVisibilityChanged(int visibility) { - if(API >= 11){ + if (API >= 11) { this.setActivated(visibility == View.VISIBLE); } + this.setEnabled(visibility == View.VISIBLE); super.onWindowVisibilityChanged(visibility); } -/* - private void getControls() { - if (API < 11) { + + private final GestureDetector mGestureDetector; + + private class CustomGestureListener extends SimpleOnGestureListener { + private final int SWIPE_THRESHOLD = 100; + private final int SWIPE_VELOCITY_THRESHOLD = 100; + + @Override + public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, + float velocityY) { try { - Class webview = Class.forName("android.webkit.WebView"); - Method method = webview.getMethod("getZoomButtonsController"); - - zoomControl = (ZoomButtonsController) method.invoke(this, (Object[])null); - if (zoomControl != null) { - zoomShouldDie = true; + + int width; + if (API < 13) { + DisplayMetrics metrics = CONTEXT.getResources() + .getDisplayMetrics(); + width = metrics.widthPixels; + } else { + WindowManager wm = (WindowManager) CONTEXT + .getSystemService(Context.WINDOW_SERVICE); + Display display = wm.getDefaultDisplay(); + Point size = new Point(); + display.getSize(size); + width = size.x; } - } catch (Exception e) { - e.printStackTrace(); + + if ((width - e1.getX() < width/12) || (e1.getX() < width/12)) { + float diffY = e2.getY() - e1.getY(); + float diffX = e2.getX() - e1.getX(); + if (Math.abs(diffX) > Math.abs(diffY)) { + if (Math.abs(diffX) > SWIPE_THRESHOLD + && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) { + if (diffX > 0) { + BrowserActivity.goBack(); + return false; + } else { + BrowserActivity.goForward(); + return false; + } + } + } + } + + } catch (Exception exception) { + exception.printStackTrace(); } + return false; } } -*/ + } diff --git a/src/acr/browser/barebones/customwebview/IncognitoWebView.java b/src/acr/browser/barebones/customwebview/IncognitoWebView.java index 1b5cbfe..57342d0 100644 --- a/src/acr/browser/barebones/customwebview/IncognitoWebView.java +++ b/src/acr/browser/barebones/customwebview/IncognitoWebView.java @@ -3,9 +3,16 @@ package acr.browser.barebones.customwebview; import acr.browser.barebones.activities.IncognitoModeActivity; import acr.browser.barebones.utilities.FinalVariables; import android.content.Context; +import android.graphics.Point; +import android.util.DisplayMetrics; +import android.view.Display; +import android.view.GestureDetector; +import android.view.GestureDetector.SimpleOnGestureListener; import android.view.MotionEvent; import android.view.View; +import android.view.WindowManager; import android.view.animation.Animation; +import android.webkit.WebSettings; import android.webkit.WebView; public final class IncognitoWebView extends WebView { @@ -13,34 +20,76 @@ public final class IncognitoWebView extends WebView { private boolean first = false; final int API = FinalVariables.API; final boolean showFullScreen = IncognitoModeActivity.showFullScreen; - final View uBar = IncognitoModeActivity.uBar; + final View uBar = IncognitoModeActivity.urlBar; final Animation slideUp = IncognitoModeActivity.slideUp; final Animation slideDown = IncognitoModeActivity.slideDown; - + static Context CONTEXT; public IncognitoWebView(Context context) { super(context); + mGestureDetector = new GestureDetector(context, + new CustomGestureListener()); + CONTEXT = context; + WebSettings settings = this.getSettings(); + browserInitialization(context); + settingsInitialization(context, settings); + } + + public void browserInitialization(Context context) { + this.setDrawingCacheBackgroundColor(0x00000000); + this.setFocusableInTouchMode(true); + this.setFocusable(true); + this.setAnimationCacheEnabled(false); + this.setDrawingCacheEnabled(true); + this.setBackgroundColor(context.getResources().getColor( + android.R.color.white)); + this.setWillNotCacheDrawing(false); + this.setAlwaysDrawnWithCacheEnabled(true); + this.setScrollbarFadingEnabled(true); + this.setSaveEnabled(true); + } + + @SuppressWarnings("deprecation") + public void settingsInitialization(Context context, WebSettings settings) { + settings.setDomStorageEnabled(true); + settings.setAppCacheEnabled(true); + settings.setAppCachePath(context.getFilesDir().getAbsolutePath() + + "/cache"); + if (API < 18) { + settings.setLightTouchEnabled(true); + } + settings.setAllowFileAccess(true); + settings.setDatabaseEnabled(true); + settings.setDatabasePath(context.getFilesDir().getAbsolutePath() + + "/databases"); + settings.setSupportZoom(true); + settings.setBuiltInZoomControls(true); + if (API >= 11) { + settings.setDisplayZoomControls(false); + settings.setAllowContentAccess(true); + } } @Override public boolean onTouchEvent(MotionEvent event) { - + switch (event.getAction()) { case MotionEvent.ACTION_DOWN: { first = true; - if (API <= 10 && !this.hasFocus()) { - this.requestFocus(); + if (API <= 10 && !hasFocus()) { + requestFocus(); } location = event.getY(); break; } case MotionEvent.ACTION_UP: { + if (showFullScreen && first) { - if (uBar.isShown() && this.getScrollY() < 5) { + if (uBar.isShown() && getScrollY() < 5) { uBar.startAnimation(slideUp); - } else if (event.getY() > location && !uBar.isShown()) { + } else if ((event.getY() - location) > 20.0 && !uBar.isShown()) { uBar.startAnimation(slideDown); - } else if (event.getY() < location && uBar.isShown()) { + } else if ((event.getY() - location) < -20.0 && uBar.isShown()) { uBar.startAnimation(slideUp); } first = false; @@ -48,8 +97,67 @@ public final class IncognitoWebView extends WebView { break; } } + return mGestureDetector.onTouchEvent(event) + || super.onTouchEvent(event); - return super.onTouchEvent(event); + } + + @Override + protected void onWindowVisibilityChanged(int visibility) { + if (API >= 11) { + this.setActivated(visibility == View.VISIBLE); + } + this.setEnabled(visibility == View.VISIBLE); + super.onWindowVisibilityChanged(visibility); + } + + private final GestureDetector mGestureDetector; + + private class CustomGestureListener extends SimpleOnGestureListener { + private final int SWIPE_THRESHOLD = 100; + private final int SWIPE_VELOCITY_THRESHOLD = 100; + + @Override + public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, + float velocityY) { + try { + + int width; + if (API < 13) { + DisplayMetrics metrics = CONTEXT.getResources() + .getDisplayMetrics(); + width = metrics.widthPixels; + } else { + WindowManager wm = (WindowManager) CONTEXT + .getSystemService(Context.WINDOW_SERVICE); + Display display = wm.getDefaultDisplay(); + Point size = new Point(); + display.getSize(size); + width = size.x; + } + + if ((width - e1.getX() < width/12) || (e1.getX() < width/12)) { + float diffY = e2.getY() - e1.getY(); + float diffX = e2.getX() - e1.getX(); + if (Math.abs(diffX) > Math.abs(diffY)) { + if (Math.abs(diffX) > SWIPE_THRESHOLD + && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) { + if (diffX > 0) { + IncognitoModeActivity.goBack(); + return false; + } else { + IncognitoModeActivity.goForward(); + return false; + } + } + } + } + + } catch (Exception exception) { + exception.printStackTrace(); + } + return false; + } } } diff --git a/src/acr/browser/barebones/incognitoclasses/IncognitoChromeClient.java b/src/acr/browser/barebones/incognitoclasses/IncognitoChromeClient.java new file mode 100644 index 0000000..36e28e2 --- /dev/null +++ b/src/acr/browser/barebones/incognitoclasses/IncognitoChromeClient.java @@ -0,0 +1,216 @@ +package acr.browser.barebones.incognitoclasses; + +import acr.browser.barebones.R; +import acr.browser.barebones.activities.IncognitoModeActivity; +import android.annotation.SuppressLint; +import android.app.Activity; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.net.Uri; +import android.os.Message; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.webkit.GeolocationPermissions; +import android.webkit.ValueCallback; +import android.webkit.WebChromeClient; +import android.webkit.WebView; +import android.webkit.WebStorage.QuotaUpdater; +import android.widget.FrameLayout; + +@SuppressLint("SetJavaScriptEnabled") +public class IncognitoChromeClient extends WebChromeClient { + private static Context context; + private static Activity browserActivity; + private static View mCustomView; + private static CustomViewCallback mCustomViewCallback; + public IncognitoChromeClient(IncognitoModeActivity activity){ + context = activity; + browserActivity = activity; + } + public Bitmap mDefaultVideoPoster; + public View mVideoProgressView; + public FrameLayout fullScreenContainer; + public int orientation; + + @Override + public void onExceededDatabaseQuota(String url, + String databaseIdentifier, long quota, + long estimatedDatabaseSize, long totalQuota, + QuotaUpdater quotaUpdater) { + quotaUpdater.updateQuota(totalQuota + estimatedDatabaseSize); + + } + + @Override + public void onProgressChanged(WebView view, int newProgress) { + IncognitoModeActivity.onProgressChanged(view.getId(), newProgress); + super.onProgressChanged(view, newProgress); + } + + @Override + public void onReachedMaxAppCacheSize(long requiredStorage, long quota, + QuotaUpdater quotaUpdater) { + quotaUpdater.updateQuota(quota + requiredStorage); + } + + @Override + public Bitmap getDefaultVideoPoster() { + if (mDefaultVideoPoster == null) { + mDefaultVideoPoster = BitmapFactory.decodeResource( + context.getResources(), android.R.color.black); + } + return mDefaultVideoPoster; + } + + @Override + public View getVideoLoadingProgressView() { + if (mVideoProgressView == null) { + LayoutInflater inflater = LayoutInflater.from(context); + mVideoProgressView = inflater.inflate( + android.R.layout.simple_spinner_item, null); + } + return mVideoProgressView; + } + + @Override + public void onCloseWindow(WebView window) { + Message msg = Message.obtain(); + msg.what = 3; + msg.arg1 = window.getId(); + IncognitoModeActivity.browserHandler.sendMessage(msg); + super.onCloseWindow(window); + } + + @Override + public boolean onCreateWindow(WebView view, boolean isDialog, + boolean isUserGesture, final Message resultMsg) { + + if (isUserGesture) { + IncognitoModeActivity.onCreateWindow(resultMsg); + } + return true; + } + + + @Override + public void onGeolocationPermissionsShowPrompt(final String origin, + final GeolocationPermissions.Callback callback) { + final boolean remember = true; + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle("Location Access"); + String org = null; + if (origin.length() > 50) { + org = (String) origin.subSequence(0, 50) + "..."; + } else { + org = origin; + } + builder.setMessage(org + "\nWould like to use your Location ") + .setCancelable(true) + .setPositiveButton("Allow", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + callback.invoke(origin, true, remember); + } + }) + .setNegativeButton("Don't Allow", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + callback.invoke(origin, false, remember); + } + }); + AlertDialog alert = builder.create(); + alert.show(); + + } + + @Override + public void onHideCustomView() { + if (mCustomView == null && mCustomViewCallback == null) { + return; + } + mCustomView = null; + mCustomView.setKeepScreenOn(false); + IncognitoModeActivity.onHideCustomView(fullScreenContainer, mCustomViewCallback, orientation); + } + + @Override + public void onReceivedIcon(WebView view, Bitmap favicon) { + IncognitoModeActivity.setFavicon(view.getId(), favicon); + } + + @Override + public void onReceivedTitle(final WebView view, final String title) { + IncognitoModeActivity.onReceivedTitle(view.getId(), title); + super.onReceivedTitle(view, title); + } + + @Override + public void onShowCustomView(View view, int requestedOrientation, + CustomViewCallback callback) { + if (mCustomView != null) { + callback.onCustomViewHidden(); + return; + } + view.setKeepScreenOn(true); + orientation = browserActivity.getRequestedOrientation(); + FrameLayout screen = (FrameLayout) browserActivity.getWindow().getDecorView(); + fullScreenContainer = new FrameLayout(context); + fullScreenContainer.setBackgroundColor(context.getResources().getColor( + R.color.black)); + IncognitoModeActivity.onShowCustomView(); + fullScreenContainer.addView(view, + ViewGroup.LayoutParams.MATCH_PARENT); + screen.addView(fullScreenContainer, + ViewGroup.LayoutParams.MATCH_PARENT); + mCustomView = view; + mCustomViewCallback = callback; + browserActivity.setRequestedOrientation(requestedOrientation); + + } + + @Override + public void onShowCustomView(View view, + WebChromeClient.CustomViewCallback callback) { + if (mCustomView != null) { + callback.onCustomViewHidden(); + return; + } + view.setKeepScreenOn(true); + orientation = browserActivity.getRequestedOrientation(); + FrameLayout screen = (FrameLayout) browserActivity.getWindow().getDecorView(); + fullScreenContainer = new FrameLayout(context); + fullScreenContainer.setBackgroundColor(context.getResources().getColor( + R.color.black)); + IncognitoModeActivity.onShowCustomView(); + fullScreenContainer.addView(view, + ViewGroup.LayoutParams.MATCH_PARENT); + screen.addView(fullScreenContainer, + ViewGroup.LayoutParams.MATCH_PARENT); + mCustomView = view; + mCustomViewCallback = callback; + browserActivity.setRequestedOrientation(browserActivity.getRequestedOrientation()); + } + + public void openFileChooser(ValueCallback uploadMsg) { + IncognitoModeActivity.openFileChooser(uploadMsg); + } + + public void openFileChooser(ValueCallback uploadMsg, + String acceptType) { + IncognitoModeActivity.openFileChooser(uploadMsg); + } + + public void openFileChooser(ValueCallback uploadMsg, + String acceptType, String capture) { + IncognitoModeActivity.openFileChooser(uploadMsg); + } + +} diff --git a/src/acr/browser/barebones/incognitoclasses/IncognitoDownloadListener.java b/src/acr/browser/barebones/incognitoclasses/IncognitoDownloadListener.java new file mode 100644 index 0000000..459bf8f --- /dev/null +++ b/src/acr/browser/barebones/incognitoclasses/IncognitoDownloadListener.java @@ -0,0 +1,60 @@ +package acr.browser.barebones.incognitoclasses; + +import acr.browser.barebones.activities.IncognitoModeActivity; +import acr.browser.barebones.utilities.Utils; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.net.Uri; +import android.webkit.DownloadListener; + +public class IncognitoDownloadListener implements DownloadListener { + private static Context context; + public IncognitoDownloadListener(IncognitoModeActivity activity){ + context = activity; + } + @Override + public void onDownloadStart(final String url, String userAgent, + final String contentDisposition, final String mimetype, + long contentLength) { + if (url.endsWith(".mp4") || url.endsWith(".m4a")) { + + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle("Open as..."); + builder.setMessage( + "Do you want to download this video or watch it in an app?") + .setCancelable(true) + .setPositiveButton("Download", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + Utils.downloadFile(context, url, + contentDisposition, mimetype); + } + }) + .setNegativeButton("Watch", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + Intent intent = new Intent( + Intent.ACTION_VIEW); + intent.setDataAndType(Uri.parse(url), + "video/mp4"); + intent.putExtra( + "acr.browser.barebones.Download", + 1); + context.startActivity(intent); + } + }); + AlertDialog alert = builder.create(); + alert.show(); + + } else { + Utils.downloadFile(context, url, contentDisposition, mimetype); + } + } + +} diff --git a/src/acr/browser/barebones/incognitoclasses/IncognitoLongClickListener.java b/src/acr/browser/barebones/incognitoclasses/IncognitoLongClickListener.java new file mode 100644 index 0000000..5e1798e --- /dev/null +++ b/src/acr/browser/barebones/incognitoclasses/IncognitoLongClickListener.java @@ -0,0 +1,14 @@ +package acr.browser.barebones.incognitoclasses; + +import acr.browser.barebones.activities.IncognitoModeActivity; +import android.view.View; +import android.view.View.OnLongClickListener; + +public class IncognitoLongClickListener implements OnLongClickListener{ + + @Override + public boolean onLongClick(View v) { + return IncognitoModeActivity.onLongClick(v.getId()); + } + +} diff --git a/src/acr/browser/barebones/incognitoclasses/IncognitoWebViewClient.java b/src/acr/browser/barebones/incognitoclasses/IncognitoWebViewClient.java new file mode 100644 index 0000000..390fc14 --- /dev/null +++ b/src/acr/browser/barebones/incognitoclasses/IncognitoWebViewClient.java @@ -0,0 +1,202 @@ +package acr.browser.barebones.incognitoclasses; + +import acr.browser.barebones.activities.IncognitoModeActivity; +import acr.browser.barebones.utilities.Utils; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.graphics.Bitmap; +import android.net.MailTo; +import android.net.Uri; +import android.net.http.SslError; +import android.os.Message; +import android.text.InputType; +import android.text.TextUtils; +import android.text.method.PasswordTransformationMethod; +import android.util.Log; +import android.webkit.HttpAuthHandler; +import android.webkit.SslErrorHandler; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import android.widget.EditText; +import android.widget.LinearLayout; + +public class IncognitoWebViewClient extends WebViewClient { + private static Context context; + public IncognitoWebViewClient(IncognitoModeActivity browserActivity){ + context = browserActivity; + } + + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + if (url.startsWith("market://") + || url.startsWith("http://play.google.com") + || url.startsWith("https://play.google.com")) { + Intent urlIntent = new Intent(Intent.ACTION_VIEW, + Uri.parse(url)); + urlIntent.putExtra("acr.browser.barebones.Origin", + view.getId() + 1); + context.startActivity(urlIntent); + return true; + } else if (url.startsWith("http://www.youtube.com") + || url.startsWith("https://www.youtube.com")) { + Intent urlIntent = new Intent(Intent.ACTION_VIEW, + Uri.parse(url)); + urlIntent.putExtra("acr.browser.barebones.Origin", + view.getId() + 1); + context.startActivity(urlIntent); + return true; + } else if (url.startsWith("http://maps.google.com") + || url.startsWith("https://maps.google.com")) { + Intent urlIntent = new Intent(Intent.ACTION_VIEW, + Uri.parse(url)); + urlIntent.putExtra("acr.browser.barebones.Origin", + view.getId() + 1); + context.startActivity(urlIntent); + return true; + } else if (url.contains("tel:") || TextUtils.isDigitsOnly(url)) { + context.startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(url))); + return true; + } else if (url.contains("mailto:")) { + MailTo mailTo = MailTo.parse(url); + Intent i = Utils.newEmailIntent(context, + mailTo.getTo(), mailTo.getSubject(), mailTo.getBody(), + mailTo.getCc()); + context.startActivity(i); + view.reload(); + return true; + } + return super.shouldOverrideUrlLoading(view, url); + } + + @Override + public void onReceivedHttpAuthRequest(final WebView view, + final HttpAuthHandler handler, final String host, + final String realm) { + + AlertDialog.Builder builder = new AlertDialog.Builder(context); + final EditText name = new EditText(context); + final EditText password = new EditText(context); + LinearLayout passLayout = new LinearLayout(context); + passLayout.setOrientation(LinearLayout.VERTICAL); + + passLayout.addView(name); + passLayout.addView(password); + + name.setHint("Username"); + password.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); + password.setTransformationMethod(new PasswordTransformationMethod()); + password.setHint("Password"); + builder.setTitle("Sign in"); + builder.setView(passLayout); + builder.setCancelable(true) + .setPositiveButton("Sign in", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + String user = name.getText().toString(); + String pass = password.getText().toString(); + handler.proceed(user.trim(), pass.trim()); + Log.i("Lightning", "Request Login"); + + } + }) + .setNegativeButton("Cancel", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + handler.cancel(); + + } + }); + AlertDialog alert = builder.create(); + alert.show(); + + } + + @Override + public void onScaleChanged(WebView view, float oldScale, float newScale) { + if (view.isShown()) { + view.invalidate(); + } + super.onScaleChanged(view, oldScale, newScale); + } + + @Override + public void onPageFinished(WebView view, String url) { + IncognitoModeActivity.onPageFinished(view, url); + super.onPageFinished(view, url); + } + + @Override + public void onPageStarted(WebView view, String url, Bitmap favicon) { + IncognitoModeActivity.onPageStarted(view, url, favicon); + super.onPageStarted(view, url, favicon); + } + + @Override + public void onReceivedSslError(WebView view, + final SslErrorHandler handler, SslError error) { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle("Warning"); + builder.setMessage( + "The certificate of the site is not trusted. Proceed anyway?") + .setCancelable(true) + .setPositiveButton("Yes", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + handler.proceed(); + } + }) + .setNegativeButton("No", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + handler.cancel(); + } + }); + AlertDialog alert = builder.create(); + if (error.getPrimaryError() == SslError.SSL_UNTRUSTED) { + alert.show(); + } else { + handler.proceed(); + } + + } + + @Override + public void onFormResubmission(WebView view, final Message dontResend, + final Message resend) { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle("Form Resubmission"); + builder.setMessage("Would you like to resend the data?") + .setCancelable(true) + .setPositiveButton("Yes", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + + resend.sendToTarget(); + } + }) + .setNegativeButton("No", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + + dontResend.sendToTarget(); + } + }); + AlertDialog alert = builder.create(); + alert.show(); + super.onFormResubmission(view, dontResend, resend); + } +} diff --git a/src/acr/browser/barebones/utilities/BookmarkPageVariables.java b/src/acr/browser/barebones/utilities/BookmarkPageVariables.java index a029fe9..9acc39a 100644 --- a/src/acr/browser/barebones/utilities/BookmarkPageVariables.java +++ b/src/acr/browser/barebones/utilities/BookmarkPageVariables.java @@ -17,7 +17,7 @@ public class BookmarkPageVariables { public static final String Part1 = "
" + "
" + "

" + ""+ - ""; public static final String Part4 = "

"; public static final String End = ""; diff --git a/src/acr/browser/barebones/utilities/FinalVariables.java b/src/acr/browser/barebones/utilities/FinalVariables.java index b257308..0edc8d7 100644 --- a/src/acr/browser/barebones/utilities/FinalVariables.java +++ b/src/acr/browser/barebones/utilities/FinalVariables.java @@ -15,13 +15,13 @@ public class FinalVariables { 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 BAIDU_SEARCH = "http://www.baidu.com/s?wd="; 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 BAIDU_SEARCH = "http://www.baidu.com/s?wd="; + public static final String YANDEX_SEARCH = "http://yandex.ru/yandsearch?lr=21411&text="; + public static final String ADVANCED_SETTINGS_INTENT = "android.intent.action.ADVANCED_SETTINGS"; 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; - - + public static final String INCOGNITO_INTENT = "android.intent.action.BROWSER_INCOGNITO"; + public static final String EXTERNAL_STORAGE = Environment.getExternalStorageDirectory().toString(); } diff --git a/src/acr/browser/barebones/utilities/Utils.java b/src/acr/browser/barebones/utilities/Utils.java index 1d35313..0d40dfe 100644 --- a/src/acr/browser/barebones/utilities/Utils.java +++ b/src/acr/browser/barebones/utilities/Utils.java @@ -7,8 +7,6 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; - -import acr.browser.barebones.activities.AdvancedSettingsActivity; import acr.browser.barebones.databases.DatabaseHandler; import acr.browser.barebones.databases.HistoryItem; import android.annotation.SuppressLint; @@ -31,25 +29,21 @@ 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) { - } - }); + builder.setMessage(message).setCancelable(true) + .setPositiveButton("Ok", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + } + }); AlertDialog alert = builder.create(); alert.show(); } @@ -108,12 +102,11 @@ public class Utils { try { StringBuilder sb = new StringBuilder("url" + " = "); DatabaseUtils.appendEscapedSQLString(sb, url); - historyHandler = new DatabaseHandler( - context); + historyHandler = new DatabaseHandler(context); history = historyHandler.getReadableDatabase(); - Cursor cursor = history.query("history", new String[] { "id", - "url", "title" }, sb.toString(), null, null, null, - null); + 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)); @@ -140,15 +133,17 @@ public class Utils { } } } - + @TargetApi(Build.VERSION_CODES.GINGERBREAD) - public static void downloadFile(final Context context, final String url, final String contentDisposition, final String mimetype){ + 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); + DownloadManager download = (DownloadManager) context + .getSystemService(Context.DOWNLOAD_SERVICE); Uri nice = Uri.parse(url); DownloadManager.Request it = new DownloadManager.Request( nice); @@ -158,9 +153,10 @@ public class Utils { it.allowScanningByMediaScanner(); it.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); } - - it.setDestinationInExternalPublicDir( - Environment.DIRECTORY_DOWNLOADS, fileName); + String location = context.getSharedPreferences("settings", + 0).getString("download", + Environment.DIRECTORY_DOWNLOADS); + it.setDestinationInExternalPublicDir(location, fileName); Log.i("Barebones", "Downloading" + fileName); download.enqueue(it); } @@ -178,18 +174,26 @@ public class Utils { } } - - public static void showToast(Context context, String message){ + + public static void showToast(Context context, String message) { Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); } - - public static Intent newEmailIntent(Context context, String address, String subject, String body, String cc) { - Intent intent = new Intent(Intent.ACTION_SEND); - intent.putExtra(Intent.EXTRA_EMAIL, new String[] { address }); - intent.putExtra(Intent.EXTRA_TEXT, body); - intent.putExtra(Intent.EXTRA_SUBJECT, subject); - intent.putExtra(Intent.EXTRA_CC, cc); - intent.setType("message/rfc822"); - return intent; + + public static Intent newEmailIntent(Context context, String address, + String subject, String body, String cc) { + Intent intent = new Intent(Intent.ACTION_SEND); + intent.putExtra(Intent.EXTRA_EMAIL, new String[] { address }); + intent.putExtra(Intent.EXTRA_TEXT, body); + intent.putExtra(Intent.EXTRA_SUBJECT, subject); + intent.putExtra(Intent.EXTRA_CC, cc); + intent.setType("message/rfc822"); + return intent; } + + public static int convertDensityPixesl(Context context, int densityPixels) { + float scale = context.getResources().getDisplayMetrics().density; + int pixels = (int) (densityPixels * scale + 0.5f); + return pixels; + } + } diff --git a/src/acr/browser/barebones/webviewclasses/CustomChromeClient.java b/src/acr/browser/barebones/webviewclasses/CustomChromeClient.java new file mode 100644 index 0000000..72c68d2 --- /dev/null +++ b/src/acr/browser/barebones/webviewclasses/CustomChromeClient.java @@ -0,0 +1,216 @@ +package acr.browser.barebones.webviewclasses; + +import acr.browser.barebones.R; +import acr.browser.barebones.activities.BrowserActivity; +import android.annotation.SuppressLint; +import android.app.Activity; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.net.Uri; +import android.os.Message; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.webkit.GeolocationPermissions; +import android.webkit.ValueCallback; +import android.webkit.WebChromeClient; +import android.webkit.WebView; +import android.webkit.WebStorage.QuotaUpdater; +import android.widget.FrameLayout; + +@SuppressLint("SetJavaScriptEnabled") +public class CustomChromeClient extends WebChromeClient { + private static Context context; + private static Activity browserActivity; + private static View mCustomView; + private static CustomViewCallback mCustomViewCallback; + public CustomChromeClient(BrowserActivity activity){ + context = activity; + browserActivity = activity; + } + public Bitmap mDefaultVideoPoster; + public View mVideoProgressView; + public FrameLayout fullScreenContainer; + public int orientation; + + @Override + public void onExceededDatabaseQuota(String url, + String databaseIdentifier, long quota, + long estimatedDatabaseSize, long totalQuota, + QuotaUpdater quotaUpdater) { + quotaUpdater.updateQuota(totalQuota + estimatedDatabaseSize); + + } + + @Override + public void onProgressChanged(WebView view, int newProgress) { + BrowserActivity.onProgressChanged(view.getId(), newProgress); + super.onProgressChanged(view, newProgress); + } + + @Override + public void onReachedMaxAppCacheSize(long requiredStorage, long quota, + QuotaUpdater quotaUpdater) { + quotaUpdater.updateQuota(quota + requiredStorage); + } + + @Override + public Bitmap getDefaultVideoPoster() { + if (mDefaultVideoPoster == null) { + mDefaultVideoPoster = BitmapFactory.decodeResource( + context.getResources(), android.R.color.black); + } + return mDefaultVideoPoster; + } + + @Override + public View getVideoLoadingProgressView() { + if (mVideoProgressView == null) { + LayoutInflater inflater = LayoutInflater.from(context); + mVideoProgressView = inflater.inflate( + android.R.layout.simple_spinner_item, null); + } + return mVideoProgressView; + } + + @Override + public void onCloseWindow(WebView window) { + Message msg = Message.obtain(); + msg.what = 3; + msg.arg1 = window.getId(); + BrowserActivity.browserHandler.sendMessage(msg); + super.onCloseWindow(window); + } + + @Override + public boolean onCreateWindow(WebView view, boolean isDialog, + boolean isUserGesture, final Message resultMsg) { + + if (isUserGesture) { + BrowserActivity.onCreateWindow(resultMsg); + } + return true; + } + + + @Override + public void onGeolocationPermissionsShowPrompt(final String origin, + final GeolocationPermissions.Callback callback) { + final boolean remember = true; + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle("Location Access"); + String org = null; + if (origin.length() > 50) { + org = (String) origin.subSequence(0, 50) + "..."; + } else { + org = origin; + } + builder.setMessage(org + "\nWould like to use your Location ") + .setCancelable(true) + .setPositiveButton("Allow", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + callback.invoke(origin, true, remember); + } + }) + .setNegativeButton("Don't Allow", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + callback.invoke(origin, false, remember); + } + }); + AlertDialog alert = builder.create(); + alert.show(); + + } + + @Override + public void onHideCustomView() { + if (mCustomView == null && mCustomViewCallback == null) { + return; + } + mCustomView = null; + mCustomView.setKeepScreenOn(false); + BrowserActivity.onHideCustomView(fullScreenContainer, mCustomViewCallback, orientation); + } + + @Override + public void onReceivedIcon(WebView view, Bitmap favicon) { + BrowserActivity.setFavicon(view.getId(), favicon); + } + + @Override + public void onReceivedTitle(final WebView view, final String title) { + BrowserActivity.onReceivedTitle(view.getId(), title); + super.onReceivedTitle(view, title); + } + + @Override + public void onShowCustomView(View view, int requestedOrientation, + CustomViewCallback callback) { + if (mCustomView != null) { + callback.onCustomViewHidden(); + return; + } + view.setKeepScreenOn(true); + orientation = browserActivity.getRequestedOrientation(); + FrameLayout screen = (FrameLayout) browserActivity.getWindow().getDecorView(); + fullScreenContainer = new FrameLayout(context); + fullScreenContainer.setBackgroundColor(context.getResources().getColor( + R.color.black)); + BrowserActivity.onShowCustomView(); + fullScreenContainer.addView(view, + ViewGroup.LayoutParams.MATCH_PARENT); + screen.addView(fullScreenContainer, + ViewGroup.LayoutParams.MATCH_PARENT); + mCustomView = view; + mCustomViewCallback = callback; + browserActivity.setRequestedOrientation(requestedOrientation); + + } + + @Override + public void onShowCustomView(View view, + WebChromeClient.CustomViewCallback callback) { + if (mCustomView != null) { + callback.onCustomViewHidden(); + return; + } + view.setKeepScreenOn(true); + orientation = browserActivity.getRequestedOrientation(); + FrameLayout screen = (FrameLayout) browserActivity.getWindow().getDecorView(); + fullScreenContainer = new FrameLayout(context); + fullScreenContainer.setBackgroundColor(context.getResources().getColor( + R.color.black)); + BrowserActivity.onShowCustomView(); + fullScreenContainer.addView(view, + ViewGroup.LayoutParams.MATCH_PARENT); + screen.addView(fullScreenContainer, + ViewGroup.LayoutParams.MATCH_PARENT); + mCustomView = view; + mCustomViewCallback = callback; + browserActivity.setRequestedOrientation(browserActivity.getRequestedOrientation()); + } + + public void openFileChooser(ValueCallback uploadMsg) { + BrowserActivity.openFileChooser(uploadMsg); + } + + public void openFileChooser(ValueCallback uploadMsg, + String acceptType) { + BrowserActivity.openFileChooser(uploadMsg); + } + + public void openFileChooser(ValueCallback uploadMsg, + String acceptType, String capture) { + BrowserActivity.openFileChooser(uploadMsg); + } + +} diff --git a/src/acr/browser/barebones/webviewclasses/CustomDownloadListener.java b/src/acr/browser/barebones/webviewclasses/CustomDownloadListener.java new file mode 100644 index 0000000..e961d22 --- /dev/null +++ b/src/acr/browser/barebones/webviewclasses/CustomDownloadListener.java @@ -0,0 +1,62 @@ +package acr.browser.barebones.webviewclasses; + +import acr.browser.barebones.activities.BrowserActivity; +import acr.browser.barebones.utilities.Utils; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.net.Uri; +import android.webkit.DownloadListener; + +public class CustomDownloadListener implements DownloadListener { + private static Context context; + public CustomDownloadListener(BrowserActivity activity){ + context = activity; + } + + + @Override + public void onDownloadStart(final String url, String userAgent, + final String contentDisposition, final String mimetype, + long contentLength) { + if (url.endsWith(".mp4") || url.endsWith(".m4a")) { + + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle("Open as..."); + builder.setMessage( + "Do you want to download this video or watch it in an app?") + .setCancelable(true) + .setPositiveButton("Download", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + Utils.downloadFile(context, url, + contentDisposition, mimetype); + } + }) + .setNegativeButton("Watch", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + Intent intent = new Intent( + Intent.ACTION_VIEW); + intent.setDataAndType(Uri.parse(url), + "video/mp4"); + intent.putExtra( + "acr.browser.barebones.Download", + 1); + context.startActivity(intent); + } + }); + AlertDialog alert = builder.create(); + alert.show(); + + } else { + Utils.downloadFile(context, url, contentDisposition, mimetype); + } + } + +} diff --git a/src/acr/browser/barebones/webviewclasses/CustomWebViewClient.java b/src/acr/browser/barebones/webviewclasses/CustomWebViewClient.java new file mode 100644 index 0000000..61914b5 --- /dev/null +++ b/src/acr/browser/barebones/webviewclasses/CustomWebViewClient.java @@ -0,0 +1,202 @@ +package acr.browser.barebones.webviewclasses; + +import acr.browser.barebones.activities.BrowserActivity; +import acr.browser.barebones.utilities.Utils; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.graphics.Bitmap; +import android.net.MailTo; +import android.net.Uri; +import android.net.http.SslError; +import android.os.Message; +import android.text.InputType; +import android.text.TextUtils; +import android.text.method.PasswordTransformationMethod; +import android.util.Log; +import android.webkit.HttpAuthHandler; +import android.webkit.SslErrorHandler; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import android.widget.EditText; +import android.widget.LinearLayout; + +public class CustomWebViewClient extends WebViewClient { + private static Context context; + public CustomWebViewClient(BrowserActivity browserActivity){ + context = browserActivity; + } + + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + if (url.startsWith("market://") + || url.startsWith("http://play.google.com") + || url.startsWith("https://play.google.com")) { + Intent urlIntent = new Intent(Intent.ACTION_VIEW, + Uri.parse(url)); + urlIntent.putExtra("acr.browser.barebones.Origin", + view.getId() + 1); + context.startActivity(urlIntent); + return true; + } else if (url.startsWith("http://www.youtube.com") + || url.startsWith("https://www.youtube.com")) { + Intent urlIntent = new Intent(Intent.ACTION_VIEW, + Uri.parse(url)); + urlIntent.putExtra("acr.browser.barebones.Origin", + view.getId() + 1); + context.startActivity(urlIntent); + return true; + } else if (url.startsWith("http://maps.google.com") + || url.startsWith("https://maps.google.com")) { + Intent urlIntent = new Intent(Intent.ACTION_VIEW, + Uri.parse(url)); + urlIntent.putExtra("acr.browser.barebones.Origin", + view.getId() + 1); + context.startActivity(urlIntent); + return true; + } else if (url.contains("tel:") || TextUtils.isDigitsOnly(url)) { + context.startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(url))); + return true; + } else if (url.contains("mailto:")) { + MailTo mailTo = MailTo.parse(url); + Intent i = Utils.newEmailIntent(context, + mailTo.getTo(), mailTo.getSubject(), mailTo.getBody(), + mailTo.getCc()); + context.startActivity(i); + view.reload(); + return true; + } + return super.shouldOverrideUrlLoading(view, url); + } + + @Override + public void onReceivedHttpAuthRequest(final WebView view, + final HttpAuthHandler handler, final String host, + final String realm) { + + AlertDialog.Builder builder = new AlertDialog.Builder(context); + final EditText name = new EditText(context); + final EditText password = new EditText(context); + LinearLayout passLayout = new LinearLayout(context); + passLayout.setOrientation(LinearLayout.VERTICAL); + + passLayout.addView(name); + passLayout.addView(password); + + name.setHint("Username"); + password.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); + password.setTransformationMethod(new PasswordTransformationMethod()); + password.setHint("Password"); + builder.setTitle("Sign in"); + builder.setView(passLayout); + builder.setCancelable(true) + .setPositiveButton("Sign in", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + String user = name.getText().toString(); + String pass = password.getText().toString(); + handler.proceed(user.trim(), pass.trim()); + Log.i("Lightning", "Request Login"); + + } + }) + .setNegativeButton("Cancel", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + handler.cancel(); + + } + }); + AlertDialog alert = builder.create(); + alert.show(); + + } + + @Override + public void onScaleChanged(WebView view, float oldScale, float newScale) { + if (view.isShown()) { + view.invalidate(); + } + super.onScaleChanged(view, oldScale, newScale); + } + + @Override + public void onPageFinished(WebView view, String url) { + BrowserActivity.onPageFinished(view, url); + super.onPageFinished(view, url); + } + + @Override + public void onPageStarted(WebView view, String url, Bitmap favicon) { + BrowserActivity.onPageStarted(view, url, favicon); + super.onPageStarted(view, url, favicon); + } + + @Override + public void onReceivedSslError(WebView view, + final SslErrorHandler handler, SslError error) { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle("Warning"); + builder.setMessage( + "The certificate of the site is not trusted. Proceed anyway?") + .setCancelable(true) + .setPositiveButton("Yes", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + handler.proceed(); + } + }) + .setNegativeButton("No", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + handler.cancel(); + } + }); + AlertDialog alert = builder.create(); + if (error.getPrimaryError() == SslError.SSL_UNTRUSTED) { + alert.show(); + } else { + handler.proceed(); + } + + } + + @Override + public void onFormResubmission(WebView view, final Message dontResend, + final Message resend) { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle("Form Resubmission"); + builder.setMessage("Would you like to resend the data?") + .setCancelable(true) + .setPositiveButton("Yes", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + + resend.sendToTarget(); + } + }) + .setNegativeButton("No", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + + dontResend.sendToTarget(); + } + }); + AlertDialog alert = builder.create(); + alert.show(); + super.onFormResubmission(view, dontResend, resend); + } +} diff --git a/src/acr/browser/barebones/webviewclasses/WebPageLongClickListener.java b/src/acr/browser/barebones/webviewclasses/WebPageLongClickListener.java new file mode 100644 index 0000000..959d446 --- /dev/null +++ b/src/acr/browser/barebones/webviewclasses/WebPageLongClickListener.java @@ -0,0 +1,14 @@ +package acr.browser.barebones.webviewclasses; + +import acr.browser.barebones.activities.BrowserActivity; +import android.view.View; +import android.view.View.OnLongClickListener; + +public class WebPageLongClickListener implements OnLongClickListener{ + + @Override + public boolean onLongClick(View v) { + return BrowserActivity.onLongClick(v.getId()); + } + +}