diff --git a/res/anim/left.xml b/res/anim/left.xml new file mode 100644 index 0000000..11d3cf9 --- /dev/null +++ b/res/anim/left.xml @@ -0,0 +1,11 @@ + + + + + + + + \ No newline at end of file diff --git a/res/anim/right.xml b/res/anim/right.xml new file mode 100644 index 0000000..6c3fbf0 --- /dev/null +++ b/res/anim/right.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/res/drawable-xhdpi/ic_launcher.png b/res/drawable-xhdpi/ic_launcher.png index 8a6168a..81a92c6 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 index b02e89b..27f5168 100644 Binary files a/res/drawable-xhdpi/progress_bar.9.png and b/res/drawable-xhdpi/progress_bar.9.png differ diff --git a/res/layout/two_line_autocomplete.xml b/res/layout/two_line_autocomplete.xml index 209ec3e..526dacd 100644 --- a/res/layout/two_line_autocomplete.xml +++ b/res/layout/two_line_autocomplete.xml @@ -16,7 +16,7 @@ android:textColor="#000000" android:textAppearance="?android:attr/textAppearanceMedium" android:paddingLeft="6dip" - android:paddingTop="10dip"/> + android:paddingTop="2dip"/> + android:paddingBottom="2dip"/> \ No newline at end of file diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml index b67367d..bc61999 100644 --- a/res/values-zh-rCN/strings.xml +++ b/res/values-zh-rCN/strings.xml @@ -53,7 +53,5 @@ 新建标签 (没有检测到系统自带浏览器) (检测到系统自带浏览器) - 浏览网页时隐藏状态栏 - 清除 cookies - + \ No newline at end of file diff --git a/src/acr/browser/barebones/activities/BrowserActivity.java b/src/acr/browser/barebones/activities/BrowserActivity.java index d367499..8d9f675 100644 --- a/src/acr/browser/barebones/activities/BrowserActivity.java +++ b/src/acr/browser/barebones/activities/BrowserActivity.java @@ -11,6 +11,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Random; import acr.browser.barebones.R; import acr.browser.barebones.customwebview.CustomWebView; @@ -23,7 +24,6 @@ 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; @@ -74,12 +74,11 @@ 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.EditText; import android.widget.FrameLayout; import android.widget.HorizontalScrollView; import android.widget.ImageView; @@ -92,7 +91,6 @@ 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 { @@ -124,13 +122,13 @@ public class BrowserActivity extends Activity implements OnTouchListener { } 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"); + int urlColumn = historyCursor.getColumnIndex("url"); + int titleColumn = historyCursor + .getColumnIndex("title"); // Reference to the the column containing the URL int n = 0; do { @@ -164,7 +162,7 @@ public class BrowserActivity extends Activity implements OnTouchListener { e.printStackTrace(); } if (uBar.isShown()) { - urlTitle[pageId].setText("History"); + currentTabTitle.setText("History"); setUrlText(""); getUrl.setPadding(tenPad, 0, tenPad, 0); } @@ -186,7 +184,7 @@ public class BrowserActivity extends Activity implements OnTouchListener { } } - public static void removeView(WebView view) { + public static void removeView(CustomWebView view) { if (!showFullScreen) { view.startAnimation(fadeOut); } @@ -195,7 +193,80 @@ public class BrowserActivity extends Activity implements OnTouchListener { } private static BrowserActivity ACTIVITY; + + + private static int index = 0; + public static void renameBookmark(String url){ + index = 0; + for(int n = 0; n tabList; - public static SimpleAdapter adapter; + // variables + public static CustomWebView currentTab; + public static TextView currentTabTitle; public static MultiAutoCompleteTextView getUrl; - public static TextView[] urlTitle = new TextView[MAX_TABS]; + public static TextView[] urlTitle; public static ProgressBar browserProgress; - public static final CustomWebView[] main = new CustomWebView[MAX_TABS]; + public static CustomWebView[] main; public static Rect bounds; public static long timeTabPressed; + public static boolean fullScreen; public static int[] tabOrder = new int[MAX_TABS]; public static ValueCallback mUploadMessage; public static ImageView refresh; @@ -266,82 +345,61 @@ public class BrowserActivity extends Activity implements OnTouchListener { 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 currentId = 0; 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 showFullScreen = false; 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[] memoryURL; + public static String[] bUrl; + public static String[] bTitle; 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 String[][] urlToLoad; public static FrameLayout background; public static RelativeLayout uBar; + public static RelativeLayout screen; 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\\|\\$\\|"); + public static String[] getArray(String input) { + return input.split(SEPARATOR); + } + + public static int newId() { + + Random n = new Random(); + int id = n.nextInt(); + + while (tabList.contains(id)) { + id = n.nextInt(); + } + return id; } @SuppressWarnings("unused") public static void setFavicon(int id, Bitmap favicon) { - Drawable icon = null; + Drawable icon; icon = new BitmapDrawable(null, favicon); icon.setBounds(0, 0, width / 2, height / 2); if (icon != null) { @@ -350,104 +408,6 @@ public class BrowserActivity extends Activity implements OnTouchListener { 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); } @@ -473,7 +433,15 @@ public class BrowserActivity extends Activity implements OnTouchListener { @Override public void onAnimationEnd(Animation animation) { - urlTitle[del].setVisibility(View.GONE); + // urlTitle[del].setVisibility(View.GONE); + tabLayout.post(new Runnable() { + + @Override + public void run() { + tabLayout.removeView(urlTitle[del]); + } + + }); findNewView(del); main[del] = null; } @@ -492,15 +460,17 @@ public class BrowserActivity extends Activity implements OnTouchListener { } void findNewView(int id) { + int delete = tabList.indexOf(id); int leftId = id; boolean right = false, left = false; - if (id == pageId) { + if (id == currentId) { if (main[id].isShown()) { - // background.removeView(main[id]); removeView(main[id]); } - for (; id <= (number - 1); id++) { + + if (tabList.size() > delete + 1) { + id = tabList.get(delete + 1); if (urlTitle[id].isShown()) { background.addView(main[id]); main[id].setVisibility(View.VISIBLE); @@ -511,8 +481,10 @@ public class BrowserActivity extends Activity implements OnTouchListener { urlTitle[id].setBackground(active); } urlTitle[id].setPadding(leftPad, 0, rightPad, 0); - pageId = id; - setUrlText(urlToLoad[pageId][0]); + currentId = id; + currentTab = main[id]; + currentTabTitle = urlTitle[id]; + setUrlText(urlToLoad[currentId][0]); getUrl.setPadding(tenPad, 0, tenPad, 0); right = true; if (main[id].getProgress() < 100) { @@ -524,13 +496,13 @@ public class BrowserActivity extends Activity implements OnTouchListener { progressBar.setVisibility(View.GONE); refresh.setVisibility(View.VISIBLE); } - break; + // break; } } if (!right) { - for (; leftId >= 0; leftId--) { - + if (delete > 0) { + leftId = tabList.get(delete - 1); if (urlTitle[leftId].isShown()) { background.addView(main[leftId]); main[leftId].setVisibility(View.VISIBLE); @@ -541,20 +513,24 @@ public class BrowserActivity extends Activity implements OnTouchListener { urlTitle[leftId].setBackground(active); } urlTitle[leftId].setPadding(leftPad, 0, rightPad, 0); - pageId = leftId; - setUrlText(urlToLoad[pageId][0]); + currentId = leftId; + currentTab = main[leftId]; + currentTabTitle = urlTitle[leftId]; + setUrlText(urlToLoad[currentId][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()); + onProgressChanged(leftId, + main[leftId].getProgress()); } else { progressBar.setVisibility(View.GONE); refresh.setVisibility(View.VISIBLE); - onProgressChanged(leftId, main[leftId].getProgress()); + onProgressChanged(leftId, + main[leftId].getProgress()); } - break; + // break; } } @@ -564,18 +540,18 @@ public class BrowserActivity extends Activity implements OnTouchListener { } else { right = left = true; } - + tabList.remove(delete); if (!(right || left)) { finish(); } uBar.bringToFront(); - tabScroll.smoothScrollTo(urlTitle[pageId].getLeft(), 0); + tabScroll.smoothScrollTo(currentTabTitle.getLeft(), 0); } @Override public void onLowMemory() { for (int n = 0; n < MAX_TABS; n++) { - if (n != pageId && main[n] != null) { + if (n != currentId && main[n] != null) { main[n].freeMemory(); } } @@ -631,6 +607,7 @@ public class BrowserActivity extends Activity implements OnTouchListener { getUrl.setPadding(tenPad, 0, tenPad, 0); getUrl.setBackgroundResource(R.drawable.book); getUrl.setPadding(tenPad, 0, tenPad, 0); + final List> list = new ArrayList>(); handler = new Handler() { @Override @@ -638,7 +615,7 @@ public class BrowserActivity extends Activity implements OnTouchListener { switch (msg.what) { case 1: { - adapter = new SimpleAdapter(CONTEXT, list, + SimpleAdapter adapter = new SimpleAdapter(CONTEXT, list, R.layout.two_line_autocomplete, new String[] { "title", "url" }, new int[] { R.id.title, R.id.url }); @@ -699,7 +676,6 @@ public class BrowserActivity extends Activity implements OnTouchListener { } catch (IllegalStateException ignored) { } - list = new ArrayList>(); try { if (managedCursor != null) { @@ -707,13 +683,16 @@ public class BrowserActivity extends Activity implements OnTouchListener { // Variable for holding the retrieved URL - urlColumn = managedCursor.getColumnIndex("url"); - titleColumn = managedCursor.getColumnIndex("title"); + int urlColumn = managedCursor.getColumnIndex("url"); + int titleColumn = managedCursor + .getColumnIndex("title"); // Reference to the the column containing the URL do { - urlA = managedCursor.getString(urlColumn); - title = managedCursor.getString(titleColumn); - map = new HashMap(); + String urlA = managedCursor + .getString(urlColumn); + String title = managedCursor + .getString(titleColumn); + Map map = new HashMap(); map.put("title", title); map.put("url", urlA); list.add(map); @@ -777,10 +756,10 @@ public class BrowserActivity extends Activity implements OnTouchListener { @Override public void onClick(View v) { - if (main[pageId].canGoBack()) { - main[pageId].goBack(); + if (currentTab.canGoBack()) { + currentTab.goBack(); } else { - deleteTab(pageId); + deleteTab(currentId); } } @@ -801,9 +780,10 @@ public class BrowserActivity extends Activity implements OnTouchListener { @Override public void finish() { background.clearDisappearingChildren(); + background.removeView(currentTab); tabScroll.clearDisappearingChildren(); if (settings.getBoolean("cache", false)) { - main[pageId].clearCache(true); + currentTab.clearCache(true); Log.i("Lightning", "Cache Cleared"); } super.finish(); @@ -820,8 +800,8 @@ public class BrowserActivity extends Activity implements OnTouchListener { @Override public void onClick(View v) { - if (main[pageId].canGoForward()) { - main[pageId].goForward(); + if (currentTab.canGoForward()) { + currentTab.goForward(); } } @@ -854,6 +834,13 @@ public class BrowserActivity extends Activity implements OnTouchListener { @SuppressLint("InlinedApi") private void initialize() { + tabList = new ArrayList(); + bUrl = new String[MAX_BOOKMARKS]; + bTitle = new String[MAX_BOOKMARKS]; + main = new CustomWebView[MAX_TABS]; + urlTitle = new TextView[MAX_TABS]; + urlToLoad = new String[MAX_TABS][2]; + fullScreen = false; DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); historyHandler = new DatabaseHandler(this); @@ -875,7 +862,7 @@ public class BrowserActivity extends Activity implements OnTouchListener { showFullScreen = settings.getBoolean("fullscreen", false); uBar = (RelativeLayout) findViewById(R.id.urlBar); - RelativeLayout bg = (RelativeLayout) findViewById(R.id.background); + screen = (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); @@ -883,12 +870,10 @@ public class BrowserActivity extends Activity implements OnTouchListener { 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); } @@ -917,7 +902,6 @@ public class BrowserActivity extends Activity implements OnTouchListener { @Override public void onAnimationStart(Animation animation) { - uBar.setVisibility(View.VISIBLE); } @@ -936,10 +920,6 @@ public class BrowserActivity extends Activity implements OnTouchListener { 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; @@ -962,6 +942,9 @@ public class BrowserActivity extends Activity implements OnTouchListener { case 7: SEARCH = FinalVariables.YANDEX_SEARCH; break; + case 8: + SEARCH = FinalVariables.DUCK_LITE_SEARCH; + break; } exitTab = getResources().getDrawable(R.drawable.stop); // user @@ -971,23 +954,7 @@ public class BrowserActivity extends Activity implements OnTouchListener { // 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) @@ -1022,7 +989,6 @@ public class BrowserActivity extends Activity implements OnTouchListener { 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); @@ -1046,11 +1012,11 @@ public class BrowserActivity extends Activity implements OnTouchListener { newTab.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - newTab(number, homepage, true); + newTab(homepage, true); tabScroll.postDelayed(new Runnable() { @Override public void run() { - tabScroll.smoothScrollTo(urlTitle[pageId].getLeft(), 0); + tabScroll.smoothScrollTo(currentTabTitle.getLeft(), 0); } }, 100L); @@ -1061,14 +1027,14 @@ public class BrowserActivity extends Activity implements OnTouchListener { @Override public boolean onLongClick(View v) { if (settings.getString("oldPage", "").length() > 0) { - newTab(number, settings.getString("oldPage", ""), true); + newTab(settings.getString("oldPage", ""), true); edit.putString("oldPage", ""); edit.commit(); tabScroll.postDelayed(new Runnable() { @Override public void run() { - tabScroll.smoothScrollTo( - urlTitle[pageId].getLeft(), 0); + tabScroll.smoothScrollTo(currentTabTitle.getLeft(), + 0); } }, 100L); } @@ -1082,10 +1048,10 @@ public class BrowserActivity extends Activity implements OnTouchListener { @Override public void onClick(View arg0) { - if (main[pageId].getProgress() < 100) { - main[pageId].stopLoading(); + if (currentTab.getProgress() < 100) { + currentTab.stopLoading(); } else { - main[pageId].reload(); + currentTab.reload(); } } @@ -1093,8 +1059,7 @@ public class BrowserActivity extends Activity implements OnTouchListener { enterUrl(); if (showFullScreen) { - bg.removeView(uBar); - background.addView(uBar); + toggleFullScreen(); } browserHandler = new Handle(); @@ -1106,7 +1071,7 @@ public class BrowserActivity extends Activity implements OnTouchListener { public void handleMessage(Message msg) { switch (msg.what) { case 1: { - main[pageId].loadUrl(getUrl.getText().toString()); + currentTab.loadUrl(getUrl.getText().toString()); break; } case 2: { @@ -1114,7 +1079,7 @@ public class BrowserActivity extends Activity implements OnTouchListener { break; } case 3: { - main[pageId].invalidate(); + currentTab.invalidate(); break; } } @@ -1128,27 +1093,28 @@ public class BrowserActivity extends Activity implements OnTouchListener { String URL = url.getDataString(); boolean oldTabs = false; - if (saveTabs) { + if (settings.getBoolean("savetabs", true)) { if (URL != null) { // opens a new tab with the url if its there - newTab(number, URL, true); - main[number - 1].resumeTimers(); + int n = newTab(URL, true); + main[n].resumeTimers(); oldTabs = true; } + boolean first = false; for (String aMemoryURL : memoryURL) { if (aMemoryURL.length() > 0) { - if (number == 0) { - newTab(number, "", !oldTabs); - main[pageId].resumeTimers(); - main[pageId].getSettings().setCacheMode( + if (!first) { + int n = newTab("", !oldTabs); + main[n].resumeTimers(); + main[n].getSettings().setCacheMode( WebSettings.LOAD_CACHE_ELSE_NETWORK); - main[pageId].loadUrl(aMemoryURL); + main[n].loadUrl(aMemoryURL); } else { - newTab(number, "", false); - main[number - 1].getSettings().setCacheMode( + int n = newTab("", false); + main[n].getSettings().setCacheMode( WebSettings.LOAD_CACHE_ELSE_NETWORK); - main[number - 1].loadUrl(aMemoryURL); + main[n].loadUrl(aMemoryURL); } oldTabs = true; } @@ -1156,59 +1122,43 @@ public class BrowserActivity extends Activity implements OnTouchListener { } if (!oldTabs) { - newTab(number, homepage, true); - main[number - 1].resumeTimers(); + int n = newTab(homepage, true); + main[n].resumeTimers(); } } else { if (URL != null) { // opens a new tab with the URL if its there - newTab(number, URL, true); - main[number - 1].resumeTimers(); + int n = newTab(URL, true); + main[n].resumeTimers(); } else { // otherwise it opens the home-page - newTab(number, homepage, true); - main[number - 1].resumeTimers(); + int n = newTab(homepage, true); + main[n].resumeTimers(); } } } - public static CustomWebView makeTab(final int pageToView, String Url, + public static CustomWebView generateTab(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]); + if (currentId != -1) { + background.removeView(currentTab); + } background.addView(view); view.requestFocus(); - pageId = pageToView; + currentId = pageToView; + currentTab = main[pageToView]; + currentTabTitle = urlTitle[pageToView]; } uBar.bringToFront(); if (Url.contains("about:home")) { @@ -1231,159 +1181,106 @@ public class BrowserActivity extends Activity implements OnTouchListener { } // 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) { + public static int newTab(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(); + int finalID = createTab(theUrl, display); + if (finalID != -1) { + tabList.add(finalID); + if (display) { + currentId = finalID; + currentTab = main[finalID]; + currentTabTitle = urlTitle[finalID]; + } - if (API >= 11) { - main[num].onResume(); - } + return finalID; + } else { + return 0; + } + } - reuseWebView = true; + // creates the tab and returns the ID of the view + public static int createTab(String theUrl, boolean display) { + int id = -1; + for (int n = 0; n < MAX_TABS; n++) { + if (main[n] == null) { + id = n; 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 (id != -1) { + if (id > 0) { if (display) { if (API < 16) { - title.setBackgroundDrawable(active); + currentTabTitle.setBackgroundDrawable(inactive); } else { - title.setBackground(active); + currentTabTitle.setBackground(inactive); } + currentTabTitle.setPadding(leftPad, 0, rightPad, 0); + } + } + final TextView title = new TextView(CONTEXT); + title.setText("New Tab"); + if (display) { + if (API < 16) { + title.setBackgroundDrawable(active); } else { - if (API < 16) { - title.setBackgroundDrawable(inactive); - } else { - title.setBackground(inactive); - } + title.setBackground(active); } - 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() { + } 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(id); + 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 onAnimationEnd(Animation animation) { + } - @Override - public void onAnimationRepeat(Animation animation) { - } + @Override + public void onAnimationRepeat(Animation animation) { + } - @Override - public void onAnimationStart(Animation animation) { - title.setVisibility(View.VISIBLE); - } + @Override + public void onAnimationStart(Animation animation) { + title.setVisibility(View.VISIBLE); + } - }); - title.startAnimation(holo); - urlTitle[number] = title; + }); + title.startAnimation(holo); + urlTitle[id] = title; - urlTitle[number].setText("New Tab"); + urlTitle[id].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 (theUrl != null) { + main[id] = generateTab(id, theUrl, display); + } else { + main[id] = generateTab(id, homepage, display); } - } - if (!reuseWebView && number >= MAX_TABS) { - Toast.makeText(CONTEXT, "Maximum number of tabs reached...", - Toast.LENGTH_SHORT).show(); - } - return finalID; + } else { + Utils.showToast(CONTEXT, "Max number of tabs reached"); + } + return id; } @Override @@ -1406,10 +1303,10 @@ public class BrowserActivity extends Activity implements OnTouchListener { if (showFullScreen && !uBar.isShown()) { uBar.startAnimation(slideDown); } - if (main[pageId].isShown() && main[pageId].canGoBack()) { - main[pageId].goBack(); + if (currentTab.isShown() && currentTab.canGoBack()) { + currentTab.goBack(); } else { - deleteTab(pageId); + deleteTab(currentId); uBar.bringToFront(); } } catch (NullPointerException ignored) { @@ -1421,11 +1318,10 @@ public class BrowserActivity extends Activity implements OnTouchListener { public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (settings.getBoolean("textreflow", false)) { - main[pageId].getSettings().setLayoutAlgorithm( + currentTab.getSettings().setLayoutAlgorithm( LayoutAlgorithm.NARROW_COLUMNS); } else { - main[pageId].getSettings().setLayoutAlgorithm( - LayoutAlgorithm.NORMAL); + currentTab.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NORMAL); } } @@ -1436,18 +1332,18 @@ public class BrowserActivity extends Activity implements OnTouchListener { setContentView(R.layout.activity_main); // displays main xml layout CONTEXT = this; ACTIVITY = this; - settings = getSharedPreferences(preferences, 0); + settings = getSharedPreferences("settings", 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) { + if (settings.getBoolean("savetabs", true)) { String mem = settings.getString("memory", ""); edit.putString("memory", ""); - memoryURL = GetArray(mem); + memoryURL = new String[MAX_TABS]; + memoryURL = getArray(mem); } inactive = getResources().getDrawable(R.drawable.bg_inactive); @@ -1472,13 +1368,10 @@ public class BrowserActivity extends Activity implements OnTouchListener { 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"; + + "4. Visit settings and advanced settings to change options\n\n" + + "5. Long-press on the new tab button to open the last closed tab"; 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(); } @@ -1501,10 +1394,45 @@ public class BrowserActivity extends Activity implements OnTouchListener { */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_SEARCH) { + switch (keyCode) { + case KeyEvent.KEYCODE_SEARCH: { getUrl.requestFocus(); InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); manager.showSoftInput(getUrl, 0); + + break; + } + case KeyEvent.KEYCODE_F5: { + currentTab.reload(); + } + case KeyEvent.KEYCODE_ESCAPE: { + currentTab.stopLoading(); + } + case KeyEvent.KEYCODE_TAB: { + InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if (!manager.isActive()) { + newTab(homepage, true); + } + + } + case KeyEvent.KEYCODE_F12: { + finish(); + } + case KeyEvent.KEYCODE_F6: { + getUrl.selectAll(); + } + case KeyEvent.KEYCODE_F10: { + startActivity(new Intent(FinalVariables.SETTINGS_INTENT)); + } + case KeyEvent.KEYCODE_F11: { + toggleFullScreen(); + } + case KeyEvent.KEYCODE_DEL: { + InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if (!manager.isActive()) { + currentTab.goBack(); + } + } } return super.onKeyDown(keyCode, event); } @@ -1546,7 +1474,7 @@ public class BrowserActivity extends Activity implements OnTouchListener { } else if (download == 1) { Utils.downloadFile(CONTEXT, url, null, null); } else if (url != null) { - newTab(number, url, true); + newTab(url, true); } super.onNewIntent(intent); @@ -1557,13 +1485,13 @@ public class BrowserActivity extends Activity implements OnTouchListener { switch (item.getItemId()) { case R.id.history: - generateHistory(main[pageId], CONTEXT); + generateHistory(currentTab, 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]); + if (urlToLoad[currentId][1] != null) { + if (!urlToLoad[currentId][1].equals("Bookmarks")) { + Utils.addBookmark(CONTEXT, urlToLoad[currentId][1], + urlToLoad[currentId][0]); } } return true; @@ -1571,10 +1499,10 @@ public class BrowserActivity extends Activity implements OnTouchListener { 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]); + if (urlToLoad[currentId][1] == null) { + goBookmarks(CONTEXT, currentTab); + } else if (!urlToLoad[currentId][1].equals("Bookmarks")) { + goBookmarks(CONTEXT, currentTab); } return true; @@ -1593,11 +1521,11 @@ public class BrowserActivity extends Activity implements OnTouchListener { @Override protected void onPause() { - if (main[pageId] != null) { + if (currentTab != null) { if (API >= 11) { - main[pageId].onPause(); + currentTab.onPause(); } - main[pageId].pauseTimers(); + currentTab.pauseTimers(); } Thread remember = new Thread(new Runnable() { @@ -1619,16 +1547,20 @@ public class BrowserActivity extends Activity implements OnTouchListener { @Override protected void onResume() { - onProgressChanged(pageId, main[pageId].getProgress()); - if (main[pageId].getProgress() == 100) { + onProgressChanged(currentId, currentTab.getProgress()); + if (currentTab.getProgress() == 100) { progressBar.setVisibility(View.GONE); refresh.setVisibility(View.VISIBLE); - + } if (API >= 11) { - main[pageId].onResume(); + currentTab.onResume(); + } + reinitializeSettings(); + currentTab.resumeTimers(); + if (settings.getBoolean("fullscreen", false) != fullScreen) { + toggleFullScreen(); } - main[pageId].resumeTimers(); super.onResume(); } @@ -1654,7 +1586,7 @@ public class BrowserActivity extends Activity implements OnTouchListener { view.loadUrl("file://" + bookmarkWebPage); if (uBar.isShown()) { - urlTitle[pageId].setText("Bookmarks"); + currentTabTitle.setText("Bookmarks"); setUrlText(""); getUrl.setPadding(tenPad, 0, tenPad, 0); } @@ -1680,15 +1612,15 @@ public class BrowserActivity extends Activity implements OnTouchListener { switch (item.getItemId()) { case R.id.history: - generateHistory(main[pageId], CONTEXT); + generateHistory(currentTab, CONTEXT); return true; case R.id.bookmark: - if (urlToLoad[pageId][1] != null) { - if (!urlToLoad[pageId][1] + if (urlToLoad[currentId][1] != null) { + if (!urlToLoad[currentId][1] .equals("Bookmarks")) { Utils.addBookmark(CONTEXT, - urlToLoad[pageId][1], - urlToLoad[pageId][0]); + urlToLoad[currentId][1], + urlToLoad[currentId][0]); } } return true; @@ -1696,11 +1628,11 @@ public class BrowserActivity extends Activity implements OnTouchListener { newSettings(); return true; case R.id.allBookmarks: - if (urlToLoad[pageId][1] == null) { - goBookmarks(CONTEXT, main[pageId]); - } else if (!urlToLoad[pageId][1] + if (urlToLoad[currentId][1] == null) { + goBookmarks(CONTEXT, currentTab); + } else if (!urlToLoad[currentId][1] .equals("Bookmarks")) { - goBookmarks(CONTEXT, main[pageId]); + goBookmarks(CONTEXT, currentTab); } return true; case R.id.share: @@ -1726,14 +1658,6 @@ public class BrowserActivity extends Activity implements OnTouchListener { } }); - options.setOnLongClickListener(new OnLongClickListener() { - - @Override - public boolean onLongClick(View arg0) { - return true; - } - - }); } static void share() { @@ -1744,10 +1668,10 @@ public class BrowserActivity extends Activity implements OnTouchListener { // add a subject shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, - urlToLoad[pageId][1]); + urlToLoad[currentId][1]); // build the body of the message to be shared - String shareMessage = urlToLoad[pageId][0]; + String shareMessage = urlToLoad[currentId][0]; // add the message shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareMessage); @@ -1759,7 +1683,7 @@ public class BrowserActivity extends Activity implements OnTouchListener { static void searchTheWeb(String query, Context context) { query = query.trim(); - main[pageId].stopLoading(); + currentTab.stopLoading(); if (query.startsWith("www.")) { query = "http://" + query; @@ -1777,16 +1701,16 @@ public class BrowserActivity extends Activity implements OnTouchListener { boolean isSearch = ((query.contains(" ") || !containsPeriod) && !aboutScheme); if (query.contains("about:home") || query.contains("about:bookmarks")) { - goBookmarks(context, main[pageId]); + goBookmarks(context, currentTab); } else if (query.contains("about:history")) { - generateHistory(main[pageId], context); + generateHistory(currentTab, context); } else if (isSearch) { query.replaceAll(" ", "+"); - main[pageId].loadUrl(SEARCH + query); + currentTab.loadUrl(SEARCH + query); } else if (!validURL) { - main[pageId].loadUrl("http://" + query); + currentTab.loadUrl("http://" + query); } else { - main[pageId].loadUrl(query); + currentTab.loadUrl(query); } } @@ -1839,20 +1763,20 @@ public class BrowserActivity extends Activity implements OnTouchListener { } public static void onCreateWindow(Message resultMsg) { - newTab(number, "", true); + newTab("", true); WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj; - transport.setWebView(main[pageId]); + transport.setWebView(currentTab); resultMsg.sendToTarget(); browserHandler.postDelayed(new Runnable() { @Override public void run() { - main[pageId].loadUrl(getUrl.getText().toString()); + currentTab.loadUrl(getUrl.getText().toString()); } }, 500); } public static void onShowCustomView() { - background.removeView(main[pageId]); + background.removeView(currentTab); uBar.setVisibility(View.GONE); } @@ -1863,7 +1787,7 @@ public class BrowserActivity extends Activity implements OnTouchListener { fullScreenContainer = null; mCustomViewCallback.onCustomViewHidden(); ACTIVITY.setRequestedOrientation(orientation); - background.addView(main[pageId]); + background.addView(currentTab); uBar.setVisibility(View.VISIBLE); uBar.bringToFront(); } @@ -1888,91 +1812,97 @@ public class BrowserActivity extends Activity 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_DOWN) { - timeTabPressed = System.currentTimeMillis(); - } else if (event.getAction() == MotionEvent.ACTION_UP) { - - if ((System.currentTimeMillis() - timeTabPressed) > 1000) { - xPress = true; - } + try { + id = v.getId(); + background.clearDisappearingChildren(); + boolean xPress = false; + int x = (int) event.getX(); + int y = (int) event.getY(); + Rect edge = new Rect(); + v.getDrawingRect(edge); + currentTabTitle.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(); + 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; } - } 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]); + if (id == currentId) { + if (xPress) { + deleteTab(id); 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) { + } + } else if (id != currentId) { + if (xPress) { + deleteTab(id); + } else { + if (API < 16) { + currentTabTitle.setBackgroundDrawable(inactive); + } else if (API > 15) { + currentTabTitle.setBackground(inactive); + } + currentTabTitle.setPadding(leftPad, 0, rightPad, 0); + if (!showFullScreen) { + background.addView(main[id]); + main[id].startAnimation(fadeIn); + currentTab.startAnimation(fadeOut); + background.removeView(currentTab); + uBar.bringToFront(); + } else if (API >= 12) { + main[id].setAlpha(0f); + background.addView(main[id]); + try { + main[id].animate().alpha(1f).setDuration(250); + } catch (NullPointerException ignored) { + } + background.removeView(currentTab); + uBar.bringToFront(); + } else { + background.removeView(currentTab); + background.addView(main[id]); } - 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); + currentId = id; + currentTab = main[id]; + currentTabTitle = urlTitle[id]; + setUrlText(urlToLoad[currentId][0]); + getUrl.setPadding(tenPad, 0, tenPad, 0); + if (API < 16) { + currentTabTitle.setBackgroundDrawable(active); + } else if (API > 15) { + currentTabTitle.setBackground(active); + } + if (currentTab.getProgress() < 100) { + refresh.setVisibility(View.INVISIBLE); + + progressBar.setVisibility(View.VISIBLE); + + } else { + progressBar.setVisibility(View.GONE); + refresh.setVisibility(View.VISIBLE); + } + onProgressChanged(currentId, currentTab.getProgress()); + tabScroll.smoothScrollTo(currentTabTitle.getLeft(), 0); + currentTab.invalidate(); } - onProgressChanged(pageId, main[pageId].getProgress()); - tabScroll.smoothScrollTo(urlTitle[pageId].getLeft(), 0); - main[pageId].invalidate(); } - } + } + uBar.bringToFront(); + v.setPadding(leftPad, 0, rightPad, 0); + } catch (Exception e) { + e.printStackTrace(); + Log.e("Lightning Error", "Well we dun messed up"); } - uBar.bringToFront(); - v.setPadding(leftPad, 0, rightPad, 0); return true; } @@ -1993,99 +1923,113 @@ public class BrowserActivity extends Activity implements OnTouchListener { } - public static boolean onLongClick(final int n) { - final HitTestResult result = main[n].getHitTestResult(); + public static boolean onLongClick() { + int n = currentId; + final HitTestResult result = currentTab.getHitTestResult(); - if (main[n].getUrl().contains( + if (currentTab.getUrl().contains( "file://" + CONTEXT.getFilesDir() + "/bookmarks.html")) { - Message message = new Message(); message.arg1 = n; message.setTarget(new ClickHandler()); - main[n].requestFocusNodeHref(message); + currentTab.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(); + } else if (result != null) { + 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 = currentId; + newTab(result.getExtra(), false); + // urlTitle[num].performClick(); + currentId = num; + currentTab = main[num]; + currentTabTitle = urlTitle[num]; + break; + } + case DialogInterface.BUTTON_NEGATIVE: { + currentTab.loadUrl(result.getExtra()); + break; + } + case DialogInterface.BUTTON_NEUTRAL: { + if (API > 8) { + String url = result.getExtra(); - Utils.downloadFile(CONTEXT, url, null, null); + Utils.downloadFile(CONTEXT, url, null, null); + } + break; + } } - 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(); - 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); + } else { + DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + switch (which) { + case DialogInterface.BUTTON_POSITIVE: { + int num = currentId; + newTab(result.getExtra(), false); + currentId = num; + currentTab = main[num]; + currentTabTitle = urlTitle[num]; + break; + } + case DialogInterface.BUTTON_NEGATIVE: { + currentTab.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; + } } - 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(); + }; + + 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; } @@ -2100,9 +2044,7 @@ public class BrowserActivity extends Activity implements OnTouchListener { public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: { - int num = pageId; - newTab(number, clickedURL, false); - pageId = num; + renameBookmark(clickedURL); break; } case DialogInterface.BUTTON_NEGATIVE: { @@ -2119,26 +2061,31 @@ public class BrowserActivity extends Activity implements OnTouchListener { 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) + .setPositiveButton("Rename", dialogClickListener) + .setNegativeButton("Open", dialogClickListener) .setNeutralButton("Delete", dialogClickListener).show(); } } - public static void goBack() { - if (main[pageId].isShown() && main[pageId].canGoBack()) { - main[pageId].goBack(); + public static void goBack(CustomWebView view) { + if (view.isShown() && view.canGoBack()) { + view.goBack(); } + Animation left = AnimationUtils.loadAnimation(CONTEXT, R.anim.left); + background.startAnimation(left); + } - public static void goForward() { - if (main[pageId].isShown() && main[pageId].canGoForward()) { - main[pageId].goForward(); + public static void goForward(CustomWebView view) { + if (view.isShown() && view.canGoForward()) { + view.goForward(); } + Animation right = AnimationUtils.loadAnimation(CONTEXT, R.anim.right); + background.startAnimation(right); } public static void onProgressChanged(int id, int progress) { - if (id == pageId) { + if (id == currentId) { browserProgress.setProgress(progress); if (progress < 100) { browserProgress.setVisibility(View.VISIBLE); @@ -2147,4 +2094,25 @@ public class BrowserActivity extends Activity implements OnTouchListener { } } } + + public static void reinitializeSettings() { + int size = tabList.size(); + for (int n = 0; n < size; n++) { + main[tabList.get(n)].settingsInitialization(CONTEXT); + } + } + + public static void toggleFullScreen() { + showFullScreen = settings.getBoolean("fullscreen", false); + CustomWebView.showFullScreen = showFullScreen; + if (fullScreen) { + background.removeView(uBar); + screen.addView(uBar); + fullScreen = false; + } else { + screen.removeView(uBar); + background.addView(uBar); + fullScreen = true; + } + } } \ 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 db682e3..d4c4348 100644 --- a/src/acr/browser/barebones/activities/IncognitoModeActivity.java +++ b/src/acr/browser/barebones/activities/IncognitoModeActivity.java @@ -11,19 +11,19 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Random; 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; import acr.browser.barebones.utilities.Utils; +import acr.browser.barebones.incognitoclasses.IncognitoChromeClient; +import acr.browser.barebones.incognitoclasses.IncognitoDownloadListener; +import acr.browser.barebones.incognitoclasses.IncognitoWebViewClient; import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; @@ -74,8 +74,6 @@ 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; @@ -92,7 +90,6 @@ 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 IncognitoModeActivity extends Activity implements OnTouchListener { @@ -117,18 +114,20 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { 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"); + int urlColumn = historyCursor.getColumnIndex("url"); + int titleColumn = historyCursor + .getColumnIndex("title"); // Reference to the the column containing the URL int n = 0; do { @@ -146,7 +145,6 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { } while (n < 49 && historyCursor.moveToPrevious()); } } - handler.sendEmptyMessage(1); } catch (SQLiteException ignored) { } catch (NullPointerException ignored) { } catch (IllegalStateException ignored) { @@ -162,8 +160,8 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { } catch (IOException e) { e.printStackTrace(); } - if (urlBar.isShown()) { - urlTitle[pageId].setText("History"); + if (uBar.isShown()) { + currentTabTitle.setText("History"); setUrlText(""); getUrl.setPadding(tenPad, 0, tenPad, 0); } @@ -190,7 +188,7 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { view.startAnimation(fadeOut); } background.removeView(view); - urlBar.bringToFront(); + uBar.bringToFront(); } private static IncognitoModeActivity ACTIVITY; @@ -236,24 +234,35 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { readUrl.close(); } catch (IOException ignored) { } - openBookmarks(CONTEXT, main[pageId]); + openBookmarks(CONTEXT, currentTab); } - // variables to differentiate free from paid + // variables + + // constants 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 final String HOMEPAGE = FinalVariables.HOMEPAGE; + public static final int API = FinalVariables.API; + public static final String SEPARATOR = "\\|\\$\\|SEPARATOR\\|\\$\\|"; + // semi constants public static Context CONTEXT; - - public static final String HOMEPAGE = FinalVariables.HOMEPAGE; public static String SEARCH; + public static List tabList; - public static SimpleAdapter adapter; + // variables + public static IncognitoWebView currentTab; + public static TextView currentTabTitle; public static MultiAutoCompleteTextView getUrl; - public static TextView[] urlTitle = new TextView[MAX_TABS]; - public static final IncognitoWebView[] main = new IncognitoWebView[MAX_TABS]; + public static TextView[] urlTitle; + public static ProgressBar browserProgress; + public static IncognitoWebView[] main; public static Rect bounds; + public static long timeTabPressed; + public static boolean fullScreen; + public static int[] tabOrder = new int[MAX_TABS]; public static ValueCallback mUploadMessage; public static ImageView refresh; public static ProgressBar progressBar; @@ -262,185 +271,71 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { 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 currentId = 0; 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 ProgressBar browserProgress; - 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 showFullScreen = false; 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[] memoryURL; + public static String[] bUrl; + public static String[] bTitle; 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 String[][] urlToLoad; public static FrameLayout background; - public static RelativeLayout urlBar; + public static RelativeLayout uBar; + public static RelativeLayout screen; 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\\|\\$\\|"); + public static String[] getArray(String input) { + return input.split(SEPARATOR); } - + + public static int newId(){ + + Random n = new Random(); + int id = n.nextInt(); + + while(tabList.contains(id)){ + id = n.nextInt(); + } + return id; + } + + + @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); - - urlTitle[id].setCompoundDrawables(incognitoPage, null, exitTab, null); - - icon = null; - - } - - @SuppressLint("SetJavaScriptEnabled") - public static void browserSettings(Context context, IncognitoWebView 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; - } - + if (icon != null) { + urlTitle[id].setCompoundDrawables(incognitoPage, null, exitTab, null); } 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); + urlTitle[id] + .setCompoundDrawables(incognitoPage, null, exitTab, null); } - 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); + icon = null; } @@ -466,7 +361,15 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { @Override public void onAnimationEnd(Animation animation) { - urlTitle[del].setVisibility(View.GONE); + // urlTitle[del].setVisibility(View.GONE); + tabLayout.post(new Runnable() { + + @Override + public void run() { + tabLayout.removeView(urlTitle[del]); + } + + }); findNewView(del); main[del] = null; } @@ -481,31 +384,35 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { }); urlTitle[del].startAnimation(yolo); - urlBar.bringToFront(); + uBar.bringToFront(); } void findNewView(int id) { + int delete = tabList.indexOf(id); int leftId = id; boolean right = false, left = false; - if (id == pageId) { + if (id == currentId) { if (main[id].isShown()) { - // background.removeView(main[id]); removeView(main[id]); } - for (; id <= (number - 1); id++) { + + if (tabList.size() > delete + 1) { + id = tabList.get(delete + 1); if (urlTitle[id].isShown()) { background.addView(main[id]); main[id].setVisibility(View.VISIBLE); - urlBar.bringToFront(); + 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]); + currentId = id; + currentTab = main[id]; + currentTabTitle = urlTitle[id]; + setUrlText(urlToLoad[currentId][0]); getUrl.setPadding(tenPad, 0, tenPad, 0); right = true; if (main[id].getProgress() < 100) { @@ -517,37 +424,42 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { progressBar.setVisibility(View.GONE); refresh.setVisibility(View.VISIBLE); } - break; + // break; } } if (!right) { - for (; leftId >= 0; leftId--) { - + // for (; leftId >= 0; leftId--) { + if (delete > 0) { + leftId = tabList.get(delete - 1); if (urlTitle[leftId].isShown()) { background.addView(main[leftId]); main[leftId].setVisibility(View.VISIBLE); - // urlBar.bringToFront(); + // 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]); + currentId = leftId; + currentTab = main[leftId]; + currentTabTitle = urlTitle[leftId]; + setUrlText(urlToLoad[currentId][0]); 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); + onProgressChanged(leftId, + main[leftId].getProgress()); } else { - onProgressChanged(leftId, main[leftId].getProgress()); progressBar.setVisibility(View.GONE); refresh.setVisibility(View.VISIBLE); + onProgressChanged(leftId, + main[leftId].getProgress()); } - break; + // break; } } @@ -557,18 +469,18 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { } else { right = left = true; } - + tabList.remove(delete); if (!(right || left)) { finish(); } - urlBar.bringToFront(); - tabScroll.smoothScrollTo(urlTitle[pageId].getLeft(), 0); + uBar.bringToFront(); + tabScroll.smoothScrollTo(currentTabTitle.getLeft(), 0); } @Override public void onLowMemory() { for (int n = 0; n < MAX_TABS; n++) { - if (n != pageId && main[n] != null) { + if (n != currentId && main[n] != null) { main[n].freeMemory(); } } @@ -624,6 +536,7 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { getUrl.setPadding(tenPad, 0, tenPad, 0); getUrl.setBackgroundResource(R.drawable.book); getUrl.setPadding(tenPad, 0, tenPad, 0); + final List> list = new ArrayList>(); handler = new Handler() { @Override @@ -631,7 +544,7 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { switch (msg.what) { case 1: { - adapter = new SimpleAdapter(CONTEXT, list, + SimpleAdapter adapter = new SimpleAdapter(CONTEXT, list, R.layout.two_line_autocomplete, new String[] { "title", "url" }, new int[] { R.id.title, R.id.url }); @@ -687,14 +600,11 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { null, // Selection arguments (none) null, null, null); - handler.sendEmptyMessage(1); - } catch (SQLiteException ignored) { } catch (NullPointerException ignored) { } catch (IllegalStateException ignored) { } - list = new ArrayList>(); try { if (managedCursor != null) { @@ -702,19 +612,23 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { // Variable for holding the retrieved URL - urlColumn = managedCursor.getColumnIndex("url"); - titleColumn = managedCursor.getColumnIndex("title"); + int urlColumn = managedCursor.getColumnIndex("url"); + int titleColumn = managedCursor + .getColumnIndex("title"); // Reference to the the column containing the URL do { - urlA = managedCursor.getString(urlColumn); - title = managedCursor.getString(titleColumn); - map = new HashMap(); + String urlA = managedCursor + .getString(urlColumn); + String title = managedCursor + .getString(titleColumn); + Map 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) { @@ -771,10 +685,10 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { @Override public void onClick(View v) { - if (main[pageId].canGoBack()) { - main[pageId].goBack(); + if (currentTab.canGoBack()) { + currentTab.goBack(); } else { - deleteTab(pageId); + deleteTab(currentId); } } @@ -797,7 +711,7 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { background.clearDisappearingChildren(); tabScroll.clearDisappearingChildren(); if (settings.getBoolean("cache", false)) { - main[pageId].clearCache(true); + currentTab.clearCache(true); Log.i("Lightning", "Cache Cleared"); } super.finish(); @@ -814,8 +728,8 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { @Override public void onClick(View v) { - if (main[pageId].canGoForward()) { - main[pageId].goForward(); + if (currentTab.canGoForward()) { + currentTab.goForward(); } } @@ -847,6 +761,14 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { @SuppressLint("InlinedApi") private void initialize() { + + tabList = new ArrayList(); + bUrl = new String[MAX_BOOKMARKS]; + bTitle = new String[MAX_BOOKMARKS]; + main = new IncognitoWebView[MAX_TABS]; + urlTitle = new TextView[MAX_TABS]; + urlToLoad = new String[MAX_TABS][2]; + fullScreen = false; DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); historyHandler = new DatabaseHandler(this); @@ -867,8 +789,8 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { } showFullScreen = settings.getBoolean("fullscreen", false); - urlBar = (RelativeLayout) findViewById(R.id.urlBar); - RelativeLayout bg = (RelativeLayout) findViewById(R.id.background); + uBar = (RelativeLayout) findViewById(R.id.urlBar); + screen = (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); @@ -876,13 +798,11 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { 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) { - - urlBar.setVisibility(View.GONE); + uBar.setVisibility(View.GONE); } @Override @@ -910,8 +830,7 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { @Override public void onAnimationStart(Animation animation) { - - urlBar.setVisibility(View.VISIBLE); + uBar.setVisibility(View.VISIBLE); } }); @@ -929,10 +848,6 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { 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; @@ -955,6 +870,9 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { case 7: SEARCH = FinalVariables.YANDEX_SEARCH; break; + case 8: + SEARCH = FinalVariables.DUCK_LITE_SEARCH; + break; } exitTab = getResources().getDrawable(R.drawable.stop); // user @@ -964,23 +882,7 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { // 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) @@ -993,7 +895,6 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); // opens icondatabase so that favicons can be stored - WebIconDatabase.getInstance().open( getDir("icons", MODE_PRIVATE).getPath()); @@ -1016,7 +917,6 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { 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); @@ -1040,11 +940,11 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { newTab.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - newTab(number, homepage, true, false); + newTab(homepage, true); tabScroll.postDelayed(new Runnable() { @Override public void run() { - tabScroll.smoothScrollTo(urlTitle[pageId].getLeft(), 0); + tabScroll.smoothScrollTo(currentTabTitle.getLeft(), 0); } }, 100L); @@ -1055,15 +955,14 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { @Override public boolean onLongClick(View v) { if (settings.getString("oldPage", "").length() > 0) { - newTab(number, settings.getString("oldPage", ""), true, - false); + newTab(settings.getString("oldPage", ""), true); edit.putString("oldPage", ""); edit.commit(); tabScroll.postDelayed(new Runnable() { @Override public void run() { tabScroll.smoothScrollTo( - urlTitle[pageId].getLeft(), 0); + currentTabTitle.getLeft(), 0); } }, 100L); } @@ -1077,10 +976,10 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { @Override public void onClick(View arg0) { - if (main[pageId].getProgress() < 100) { - main[pageId].stopLoading(); + if (currentTab.getProgress() < 100) { + currentTab.stopLoading(); } else { - main[pageId].reload(); + currentTab.reload(); } } @@ -1088,9 +987,8 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { enterUrl(); if (showFullScreen) { - bg.removeView(urlBar); - background.addView(urlBar); - } + toggleFullScreen(); + } browserHandler = new Handle(); } @@ -1101,7 +999,7 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { public void handleMessage(Message msg) { switch (msg.what) { case 1: { - main[pageId].loadUrl(getUrl.getText().toString()); + currentTab.loadUrl(getUrl.getText().toString()); break; } case 2: { @@ -1109,7 +1007,7 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { break; } case 3: { - main[pageId].invalidate(); + currentTab.invalidate(); break; } } @@ -1121,57 +1019,76 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { void reopenOldTabs() { Intent url = getIntent(); String URL = url.getDataString(); + boolean oldTabs = false; + + if (settings.getBoolean("savetabs", true)) { + if (URL != null) { + // opens a new tab with the url if its there + int n = newTab(URL, true); + main[n].resumeTimers(); + oldTabs = true; - if (URL != null) { - // opens a new tab with the URL if its there - newTab(number, URL, true, false); - main[number - 1].resumeTimers(); + } + boolean first = false; + for (String aMemoryURL : memoryURL) { + if (aMemoryURL.length() > 0) { + if (!first) { + int n = newTab("", !oldTabs); + main[n].resumeTimers(); + main[n].getSettings().setCacheMode( + WebSettings.LOAD_CACHE_ELSE_NETWORK); + main[n].loadUrl(aMemoryURL); + } else { + int n = newTab("", false); + main[n].getSettings().setCacheMode( + WebSettings.LOAD_CACHE_ELSE_NETWORK); + main[n].loadUrl(aMemoryURL); + } + oldTabs = true; + } + } + + if (!oldTabs) { + int n = newTab(homepage, true); + main[n].resumeTimers(); + } } else { - // otherwise it opens the home-page - newTab(number, homepage, true, false); - main[number - 1].resumeTimers(); + if (URL != null) { + // opens a new tab with the URL if its there + int n = newTab(URL, true); + main[n].resumeTimers(); - } + } else { + // otherwise it opens the home-page + int n = newTab(homepage, true); + main[n].resumeTimers(); + } + } } - public static IncognitoWebView makeTab(final int pageToView, String Url, + public static IncognitoWebView generateTab(final int pageToView, String Url, final boolean display) { IncognitoWebView view = new IncognitoWebView(CONTEXT); view.setId(pageToView); - allowLocation = settings.getBoolean("location", false); - browserSettings(CONTEXT, view); view.setWebViewClient(new IncognitoWebViewClient(ACTIVITY)); view.setWebChromeClient(new IncognitoChromeClient(ACTIVITY)); if (API > 8) { view.setDownloadListener(new IncognitoDownloadListener(ACTIVITY)); } - view.setOnLongClickListener(new IncognitoLongClickListener()); - - 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]); + if (currentId != -1) { + background.removeView(currentTab); + } background.addView(view); view.requestFocus(); - pageId = pageToView; + currentId = pageToView; + currentTab = main[pageToView]; + currentTabTitle = urlTitle[pageToView]; } - urlBar.bringToFront(); + uBar.bringToFront(); if (Url.contains("about:home")) { goBookmarks(CONTEXT, view); } else if (Url.contains("about:blank")) { @@ -1192,161 +1109,106 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { } // 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, final boolean incognito_mode) { + public static int newTab(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(incognitoPage, 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; - - urlBar.bringToFront(); - - if (API >= 11) { - main[num].onResume(); - } + int finalID = createTab(theUrl, display); + if (finalID != -1) { + tabList.add(finalID); + if (display) { + currentId = finalID; + currentTab = main[finalID]; + currentTabTitle = urlTitle[finalID]; + } - reuseWebView = true; + return finalID; + } else { + return 0; + } + } + + //creates the tab and returns the ID of the view + public static int createTab(String theUrl, boolean display) { + int id = -1; + for (int n = 0; n < MAX_TABS; n++) { + if (main[n] == null) { + id = n; 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 (id != -1) { + if (id > 0) { if (display) { if (API < 16) { - title.setBackgroundDrawable(active); + currentTabTitle.setBackgroundDrawable(inactive); } else { - title.setBackground(active); + currentTabTitle.setBackground(inactive); } + currentTabTitle.setPadding(leftPad, 0, rightPad, 0); + } + } + final TextView title = new TextView(CONTEXT); + title.setText("New Tab"); + if (display) { + if (API < 16) { + title.setBackgroundDrawable(active); } else { - if (API < 16) { - title.setBackgroundDrawable(inactive); - } else { - title.setBackground(inactive); - } + 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() { + } + title.setSingleLine(true); + title.setGravity(Gravity.CENTER_VERTICAL); + title.setHeight(height32); + title.setWidth(pixels); + title.setPadding(leftPad, 0, rightPad, 0); + title.setId(id); + title.setGravity(Gravity.CENTER_VERTICAL); + + title.setCompoundDrawables(incognitoPage, 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 onAnimationEnd(Animation animation) { + } - @Override - public void onAnimationRepeat(Animation animation) { - } + @Override + public void onAnimationRepeat(Animation animation) { + } - @Override - public void onAnimationStart(Animation animation) { - title.setVisibility(View.VISIBLE); - } + @Override + public void onAnimationStart(Animation animation) { + title.setVisibility(View.VISIBLE); + } - }); - title.startAnimation(holo); - urlTitle[number] = title; + }); + title.startAnimation(holo); + urlTitle[id] = title; - urlTitle[number].setText("New Tab"); + urlTitle[id].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 (theUrl != null) { + main[id] = generateTab(id, theUrl, display); + } else { + main[id] = generateTab(id, homepage, display); } - } - if (!reuseWebView && number >= MAX_TABS) { - Toast.makeText(CONTEXT, "Maximum number of tabs reached...", - Toast.LENGTH_SHORT).show(); - } - return finalID; + } else { + Utils.showToast(CONTEXT, "Max number of tabs reached"); + } + return id; } @Override @@ -1366,27 +1228,28 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { @Override public void onBackPressed() { try { - if (showFullScreen && !urlBar.isShown()) { - urlBar.startAnimation(slideDown); + if (showFullScreen && !uBar.isShown()) { + uBar.startAnimation(slideDown); } - if (main[pageId].isShown() && main[pageId].canGoBack()) { - main[pageId].goBack(); + if (currentTab.isShown() && currentTab.canGoBack()) { + currentTab.goBack(); } else { - deleteTab(pageId); - urlBar.bringToFront(); + deleteTab(currentId); + uBar.bringToFront(); } } catch (NullPointerException ignored) { } + return; } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (settings.getBoolean("textreflow", false)) { - main[pageId].getSettings().setLayoutAlgorithm( + currentTab.getSettings().setLayoutAlgorithm( LayoutAlgorithm.NARROW_COLUMNS); } else { - main[pageId].getSettings().setLayoutAlgorithm( + currentTab.getSettings().setLayoutAlgorithm( LayoutAlgorithm.NORMAL); } @@ -1398,19 +1261,18 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { setContentView(R.layout.activity_main); // displays main xml layout CONTEXT = this; ACTIVITY = this; - settings = getSharedPreferences(preferences, 0); + settings = getSharedPreferences("settings", 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) { + if (settings.getBoolean("savetabs", true)) { String mem = settings.getString("memory", ""); edit.putString("memory", ""); - memoryURL = GetArray(mem); + memoryURL = new String[MAX_TABS]; + memoryURL = getArray(mem); } inactive = getResources().getDrawable(R.drawable.bg_inactive); @@ -1429,17 +1291,20 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { 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); + 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\n\n" + + "5. Long-press on the new tab button to open the last closed tab"; + + Utils.createInformativeDialog(CONTEXT, "Browser Tips", message); + edit.putInt("first", 1); edit.commit(); } + } @Override @@ -1458,10 +1323,45 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_SEARCH) { + switch (keyCode) { + case KeyEvent.KEYCODE_SEARCH: { getUrl.requestFocus(); InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); manager.showSoftInput(getUrl, 0); + + break; + } + case KeyEvent.KEYCODE_F5: { + currentTab.reload(); + } + case KeyEvent.KEYCODE_ESCAPE: { + currentTab.stopLoading(); + } + case KeyEvent.KEYCODE_TAB: { + InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if(!manager.isActive()){ + newTab(homepage, true); + } + + } + case KeyEvent.KEYCODE_F12: { + finish(); + } + case KeyEvent.KEYCODE_F6:{ + getUrl.selectAll(); + } + case KeyEvent.KEYCODE_F10: { + startActivity(new Intent(FinalVariables.SETTINGS_INTENT)); + } + case KeyEvent.KEYCODE_F11:{ + toggleFullScreen(); + } + case KeyEvent.KEYCODE_DEL:{ + InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if(!manager.isActive()){ + currentTab.goBack(); + } + } } return super.onKeyDown(keyCode, event); } @@ -1503,7 +1403,7 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { } else if (download == 1) { Utils.downloadFile(CONTEXT, url, null, null); } else if (url != null) { - newTab(number, url, true, false); + newTab(url, true); } super.onNewIntent(intent); @@ -1514,13 +1414,13 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { switch (item.getItemId()) { case R.id.history: - generateHistory(main[pageId], CONTEXT); + generateHistory(currentTab, 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]); + if (urlToLoad[currentId][1] != null) { + if (!urlToLoad[currentId][1].equals("Bookmarks")) { + Utils.addBookmark(CONTEXT, urlToLoad[currentId][1], + urlToLoad[currentId][0]); } } return true; @@ -1528,16 +1428,18 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { 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]); + if (urlToLoad[currentId][1] == null) { + goBookmarks(CONTEXT, currentTab); + } else if (!urlToLoad[currentId][1].equals("Bookmarks")) { + goBookmarks(CONTEXT, currentTab); } return true; - + case R.id.share: + share(); + return true; case R.id.incognito: - newTab(number, homepage, true, true); + newTab(homepage, true); return true; default: return super.onOptionsItemSelected(item); @@ -1547,11 +1449,11 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { @Override protected void onPause() { - if (main[pageId] != null) { + if (currentTab != null) { if (API >= 11) { - main[pageId].onPause(); + currentTab.onPause(); } - main[pageId].pauseTimers(); + currentTab.pauseTimers(); } Thread remember = new Thread(new Runnable() { @@ -1573,15 +1475,20 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { @Override protected void onResume() { - onProgressChanged(pageId, main[pageId].getProgress()); - if (main[pageId].getProgress() == 100) { + onProgressChanged(currentId, currentTab.getProgress()); + if (currentTab.getProgress() == 100) { progressBar.setVisibility(View.GONE); refresh.setVisibility(View.VISIBLE); + } if (API >= 11) { - main[pageId].onResume(); + currentTab.onResume(); + } + reinitializeSettings(); + currentTab.resumeTimers(); + if(settings.getBoolean("fullscreen", false)!=fullScreen){ + toggleFullScreen(); } - main[pageId].resumeTimers(); super.onResume(); } @@ -1606,8 +1513,8 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { } view.loadUrl("file://" + bookmarkWebPage); - if (urlBar.isShown()) { - urlTitle[pageId].setText("Bookmarks"); + if (uBar.isShown()) { + currentTabTitle.setText("Bookmarks"); setUrlText(""); getUrl.setPadding(tenPad, 0, tenPad, 0); } @@ -1633,15 +1540,15 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { switch (item.getItemId()) { case R.id.history: - generateHistory(main[pageId], CONTEXT); + generateHistory(currentTab, CONTEXT); return true; case R.id.bookmark: - if (urlToLoad[pageId][1] != null) { - if (!urlToLoad[pageId][1] + if (urlToLoad[currentId][1] != null) { + if (!urlToLoad[currentId][1] .equals("Bookmarks")) { Utils.addBookmark(CONTEXT, - urlToLoad[pageId][1], - urlToLoad[pageId][0]); + urlToLoad[currentId][1], + urlToLoad[currentId][0]); } } return true; @@ -1649,16 +1556,18 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { newSettings(); return true; case R.id.allBookmarks: - if (urlToLoad[pageId][1] == null) { - goBookmarks(CONTEXT, main[pageId]); - } else if (!urlToLoad[pageId][1] + if (urlToLoad[currentId][1] == null) { + goBookmarks(CONTEXT, currentTab); + } else if (!urlToLoad[currentId][1] .equals("Bookmarks")) { - goBookmarks(CONTEXT, main[pageId]); + goBookmarks(CONTEXT, currentTab); } return true; - + case R.id.share: + share(); + return true; case R.id.incognito: - newTab(number, homepage, true, true); + newTab(homepage,true); return true; default: return false; @@ -1675,19 +1584,32 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { } }); - 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[currentId][1]); + + // build the body of the message to be shared + String shareMessage = urlToLoad[currentId][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(); + currentTab.stopLoading(); if (query.startsWith("www.")) { query = "http://" + query; @@ -1705,16 +1627,16 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { boolean isSearch = ((query.contains(" ") || !containsPeriod) && !aboutScheme); if (query.contains("about:home") || query.contains("about:bookmarks")) { - goBookmarks(context, main[pageId]); + goBookmarks(context, currentTab); } else if (query.contains("about:history")) { - generateHistory(main[pageId], context); + generateHistory(currentTab, context); } else if (isSearch) { query.replaceAll(" ", "+"); - main[pageId].loadUrl(SEARCH + query); + currentTab.loadUrl(SEARCH + query); } else if (!validURL) { - main[pageId].loadUrl("http://" + query); + currentTab.loadUrl("http://" + query); } else { - main[pageId].loadUrl(query); + currentTab.loadUrl(query); } } @@ -1724,8 +1646,8 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { progressBar.setVisibility(View.GONE); refresh.setVisibility(View.VISIBLE); - if (showFullScreen && urlBar.isShown()) { - urlBar.startAnimation(slideUp); + if (showFullScreen && uBar.isShown()) { + uBar.startAnimation(slideUp); } } view.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); @@ -1733,7 +1655,8 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { 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(); @@ -1754,43 +1677,46 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { 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 (!urlBar.isShown() && showFullScreen) { - urlBar.startAnimation(slideDown); + if (!uBar.isShown() && showFullScreen) { + uBar.startAnimation(slideDown); } } public static void onCreateWindow(Message resultMsg) { - newTab(number, "", true, false); + newTab("", true); WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj; - transport.setWebView(main[pageId]); + transport.setWebView(currentTab); resultMsg.sendToTarget(); browserHandler.postDelayed(new Runnable() { @Override public void run() { - main[pageId].loadUrl(getUrl.getText().toString()); + currentTab.loadUrl(getUrl.getText().toString()); } }, 500); } public static void onShowCustomView() { - background.removeView(main[pageId]); - urlBar.setVisibility(View.GONE); + background.removeView(currentTab); + uBar.setVisibility(View.GONE); } public static void onHideCustomView(FrameLayout fullScreenContainer, - CustomViewCallback mCustomViewCallback, int orientation) { + CustomViewCallback mIncognitoViewCallback, int orientation) { FrameLayout screen = (FrameLayout) ACTIVITY.getWindow().getDecorView(); screen.removeView(fullScreenContainer); fullScreenContainer = null; - mCustomViewCallback.onCustomViewHidden(); + mIncognitoViewCallback.onCustomViewHidden(); ACTIVITY.setRequestedOrientation(orientation); - background.addView(main[pageId]); - urlBar.setVisibility(View.VISIBLE); - urlBar.bringToFront(); + background.addView(currentTab); + uBar.setVisibility(View.VISIBLE); + uBar.bringToFront(); } public static void onReceivedTitle(int numberPage, String title) { @@ -1811,88 +1737,108 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { @Override public boolean onTouch(View v, MotionEvent event) { + try{ 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); + v.getDrawingRect(edge); + currentTabTitle.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; + } - 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 (id == currentId) { if (xPress) { deleteTab(id); - urlBar.bringToFront(); + uBar.bringToFront(); } - } else if (id != pageId) { + } else if (id != currentId) { if (xPress) { deleteTab(id); } else { if (API < 16) { - urlTitle[pageId].setBackgroundDrawable(inactive); + currentTabTitle.setBackgroundDrawable(inactive); } else if (API > 15) { - urlTitle[pageId].setBackground(inactive); + currentTabTitle.setBackground(inactive); } - urlTitle[pageId].setPadding(leftPad, 0, rightPad, 0); + currentTabTitle.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(); + currentTab.startAnimation(fadeOut); + background.removeView(currentTab); + uBar.bringToFront(); } else if (API >= 12) { main[id].setAlpha(0f); background.addView(main[id]); try { - main[id].animate().alpha(1f) - .setDuration(mShortAnimationDuration); + main[id].animate().alpha(1f).setDuration(250); } catch (NullPointerException ignored) { } - background.removeView(main[pageId]); - urlBar.bringToFront(); + background.removeView(currentTab); + uBar.bringToFront(); } else { - background.removeView(main[pageId]); + background.removeView(currentTab); background.addView(main[id]); } - urlBar.bringToFront(); + uBar.bringToFront(); - pageId = id; - setUrlText(urlToLoad[pageId][0]); + currentId = id; + currentTab = main[id]; + currentTabTitle = urlTitle[id]; + setUrlText(urlToLoad[currentId][0]); getUrl.setPadding(tenPad, 0, tenPad, 0); if (API < 16) { - urlTitle[pageId].setBackgroundDrawable(active); + currentTabTitle.setBackgroundDrawable(active); } else if (API > 15) { - urlTitle[pageId].setBackground(active); + currentTabTitle.setBackground(active); } - if (main[pageId].getProgress() < 100) { + if (currentTab.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(); + onProgressChanged(currentId, currentTab.getProgress()); + tabScroll.smoothScrollTo(currentTabTitle.getLeft(), 0); + currentTab.invalidate(); } } } - urlBar.bringToFront(); + uBar.bringToFront(); v.setPadding(leftPad, 0, rightPad, 0); + } + catch(Exception e){ + e.printStackTrace(); + Log.e("Lightning Error", "Well we dun messed up"); + } 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); @@ -1903,7 +1849,8 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { } - public static boolean onLongClick(final int n) { + public static boolean onLongClick() { + final int n = currentId; final HitTestResult result = main[n].getHitTestResult(); if (main[n].getUrl().contains( @@ -1915,17 +1862,20 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { main[n].requestFocusNodeHref(message); return true; - } else if (result.getExtra() != null) { + } else if (result != null) { + 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); + int num = currentId; + newTab(result.getExtra(), false); // urlTitle[num].performClick(); - pageId = num; + currentId = num; + currentTab = main[num]; + currentTabTitle = urlTitle[num]; break; } case DialogInterface.BUTTON_NEGATIVE: { @@ -1959,9 +1909,11 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: { - int num = pageId; - newTab(number, result.getExtra(), false, false); - pageId = num; + int num = currentId; + newTab(result.getExtra(), false); + currentId = num; + currentTab = main[num]; + currentTabTitle = urlTitle[num]; break; } case DialogInterface.BUTTON_NEGATIVE: { @@ -1988,14 +1940,17 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { }; AlertDialog.Builder builder = new AlertDialog.Builder(CONTEXT); // dialog - builder.setTitle(result.getExtra()).setMessage("What do you want to do with this link?") + 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; } @@ -2010,10 +1965,11 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { 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; + int num = currentId; + newTab(clickedURL, false); + currentId = num; + currentTab = main[num]; + currentTabTitle = urlTitle[num]; break; } case DialogInterface.BUTTON_NEGATIVE: { @@ -2036,19 +1992,25 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { } } - public static void goBack() { - if (main[pageId].isShown() && main[pageId].canGoBack()) { - main[pageId].goBack(); + public static void goBack(IncognitoWebView view) { + if (view.isShown() && view.canGoBack()) { + view.goBack(); } + Animation left = AnimationUtils.loadAnimation(CONTEXT, R.anim.left); + background.startAnimation(left); + } - public static void goForward() { - if (main[pageId].isShown() && main[pageId].canGoForward()) { - main[pageId].goForward(); + public static void goForward(IncognitoWebView view) { + if (view.isShown() && view.canGoForward()) { + view.goForward(); } + Animation right = AnimationUtils.loadAnimation(CONTEXT, R.anim.right); + background.startAnimation(right); } + public static void onProgressChanged(int id, int progress) { - if (id == pageId) { + if (id == currentId) { browserProgress.setProgress(progress); if (progress < 100) { browserProgress.setVisibility(View.VISIBLE); @@ -2057,4 +2019,24 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { } } } + + public static void reinitializeSettings(){ + for(int n = 0; n < tabList.size(); n++){ + main[tabList.get(n)].settingsInitialization(CONTEXT); + } + } + + public static void toggleFullScreen(){ + showFullScreen = settings.getBoolean("fullscreen", false); + IncognitoWebView.showFullScreen = showFullScreen; + if(fullScreen){ + background.removeView(uBar); + screen.addView(uBar); + fullScreen = false; + }else{ + screen.removeView(uBar); + background.addView(uBar); + fullScreen = true; + } + } } \ 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 fe02977..79259a8 100644 --- a/src/acr/browser/barebones/activities/SettingsActivity.java +++ b/src/acr/browser/barebones/activities/SettingsActivity.java @@ -95,6 +95,9 @@ public class SettingsActivity extends Activity { case 7: searchText.setText("Yandex"); break; + case 8: + searchText.setText("DuckDuckGo Lite"); + break; } back.setBackgroundResource(R.drawable.button); @@ -224,8 +227,8 @@ public class SettingsActivity extends Activity { AlertDialog.Builder picker = new AlertDialog.Builder( SettingsActivity.this); picker.setTitle("Search Engine"); - CharSequence[] chars = { "Google (Suggested)", "Bing", "Yahoo", - "StartPage", "DuckDuckGo (Privacy)" , "Baidu (Chinese)", "Yandex (Russian)"}; + CharSequence[] chars = { "Google", "Bing", "Yahoo", + "StartPage", "DuckDuckGo (Privacy)" , "Baidu (Chinese)", "Yandex (Russian)", "DuckDuckGo Lite (Privacy)"}; int n = settings.getInt("search", 1); @@ -259,6 +262,9 @@ public class SettingsActivity extends Activity { case 7: searchText.setText("Yandex"); break; + case 8: + searchText.setText("DuckDuckGo Lite"); + break; } } }); @@ -463,10 +469,9 @@ public class SettingsActivity extends Activity { Utils.createInformativeDialog( SettingsActivity.this, "Warning", - "Adobe Flash does not support Android 4.3 and will" + "Adobe Flash does not support Android 4.3 and will " + "crash the browser, please do not report crashes that occur if you enable flash."); } - } }); diff --git a/src/acr/browser/barebones/customwebview/CustomWebView.java b/src/acr/browser/barebones/customwebview/CustomWebView.java index bbea647..bf81a4d 100644 --- a/src/acr/browser/barebones/customwebview/CustomWebView.java +++ b/src/acr/browser/barebones/customwebview/CustomWebView.java @@ -2,7 +2,9 @@ package acr.browser.barebones.customwebview; import acr.browser.barebones.activities.BrowserActivity; import acr.browser.barebones.utilities.FinalVariables; +import android.annotation.SuppressLint; import android.content.Context; +import android.content.SharedPreferences; import android.graphics.Point; import android.util.DisplayMetrics; import android.view.Display; @@ -14,50 +16,63 @@ import android.view.WindowManager; import android.view.animation.Animation; import android.webkit.WebSettings; import android.webkit.WebView; +import android.webkit.WebSettings.LayoutAlgorithm; +import android.webkit.WebSettings.PluginState; +import android.webkit.WebSettings.RenderPriority; public final class CustomWebView extends WebView { - private float location; private boolean first = false; - final int API = FinalVariables.API; - final boolean showFullScreen = BrowserActivity.showFullScreen; + static final int API = FinalVariables.API; + public static boolean showFullScreen;; final View uBar = BrowserActivity.uBar; final Animation slideUp = BrowserActivity.slideUp; final Animation slideDown = BrowserActivity.slideDown; static Context CONTEXT; + static String defaultUser; + public WebSettings settings; public CustomWebView(Context context) { + super(context); + defaultUser = BrowserActivity.defaultUser; + showFullScreen = BrowserActivity.showFullScreen; mGestureDetector = new GestureDetector(context, new CustomGestureListener()); CONTEXT = context; - WebSettings settings = this.getSettings(); + settings = getSettings(); browserInitialization(context); - settingsInitialization(context, settings); + settingsInitialization(context); } + @SuppressWarnings("deprecation") 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( + setDrawingCacheBackgroundColor(0x00000000); + setFocusableInTouchMode(true); + setFocusable(true); + setAnimationCacheEnabled(false); + setDrawingCacheEnabled(true); + setBackgroundColor(context.getResources().getColor( android.R.color.white)); - this.setWillNotCacheDrawing(false); - this.setAlwaysDrawnWithCacheEnabled(true); - this.setScrollbarFadingEnabled(true); - this.setSaveEnabled(true); + if (API >= 16) { + getRootView().setBackground(null); + } else { + getRootView().setBackgroundDrawable(null); + } + setWillNotCacheDrawing(false); + setAlwaysDrawnWithCacheEnabled(true); + setScrollbarFadingEnabled(true); + setSaveEnabled(true); } + @SuppressLint("SetJavaScriptEnabled") @SuppressWarnings("deprecation") - public void settingsInitialization(Context context, WebSettings settings) { + public void settingsInitialization(Context context) { + SharedPreferences preferences = context.getSharedPreferences( + "settings", 0); 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() @@ -68,54 +83,168 @@ public final class CustomWebView extends WebView { settings.setDisplayZoomControls(false); settings.setAllowContentAccess(true); } - } - @Override - public boolean onTouchEvent(MotionEvent event) { + if (preferences.getBoolean("java", true)) { + settings.setJavaScriptEnabled(true); + settings.setJavaScriptCanOpenWindowsAutomatically(true); + } - switch (event.getAction()) { - case MotionEvent.ACTION_DOWN: { - first = true; - if (API <= 10 && !hasFocus()) { - requestFocus(); + if (API < 14) { + switch (preferences.getInt("textsize", 3)) { + case 1: + settings.setTextSize(WebSettings.TextSize.LARGEST); + break; + case 2: + settings.setTextSize(WebSettings.TextSize.LARGER); + break; + case 3: + settings.setTextSize(WebSettings.TextSize.NORMAL); + break; + case 4: + settings.setTextSize(WebSettings.TextSize.SMALLER); + break; + case 5: + settings.setTextSize(WebSettings.TextSize.SMALLEST); + break; + } + + } else { + switch (preferences.getInt("textsize", 3)) { + case 1: + settings.setTextZoom(200); + break; + case 2: + settings.setTextZoom(150); + break; + case 3: + settings.setTextZoom(100); + break; + case 4: + settings.setTextZoom(75); + break; + case 5: + settings.setTextZoom(50); + break; } - location = event.getY(); + } + settings.setSupportMultipleWindows(preferences.getBoolean("newwindow", + true)); + + switch (preferences.getInt("enableflash", 0)) { + case 0: + break; + case 1: { + settings.setPluginState(PluginState.ON_DEMAND); break; } - case MotionEvent.ACTION_UP: { + case 2: { + settings.setPluginState(PluginState.ON); + break; + } + default: + break; + } + if (preferences.getBoolean("passwords", false)) { + if (API < 18) { + settings.setSavePassword(true); + } + settings.setSaveFormData(true); + } + if (API < 18) { + try { + settings.setRenderPriority(RenderPriority.HIGH); + } catch (SecurityException ignored) { - if (showFullScreen && first) { - if (uBar.isShown() && getScrollY() < 5) { - uBar.startAnimation(slideUp); - } else if ((event.getY() - location) > 20.0 && !uBar.isShown()) { - uBar.startAnimation(slideDown); - } else if ((event.getY() - location) < -20.0 && uBar.isShown()) { - uBar.startAnimation(slideUp); - } - first = false; } - break; } + settings.setGeolocationEnabled(preferences + .getBoolean("location", false)); + settings.setGeolocationDatabasePath(context.getFilesDir() + .getAbsolutePath()); + settings.setUseWideViewPort(preferences + .getBoolean("wideviewport", true)); + settings.setLoadWithOverviewMode(preferences.getBoolean("overviewmode", + true)); + + if (preferences.getBoolean("textreflow", false)) { + settings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS); + } else { + settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); + } + + settings.setBlockNetworkImage(preferences.getBoolean("blockimages", + false)); + settings.setLoadsImagesAutomatically(true); + + switch (preferences.getInt("agentchoose", 1)) { + case 1: + getSettings().setUserAgentString(defaultUser); + break; + case 2: + getSettings().setUserAgentString( + FinalVariables.DESKTOP_USER_AGENT); + break; + case 3: + getSettings().setUserAgentString( + FinalVariables.MOBILE_USER_AGENT); + break; + case 4: + getSettings().setUserAgentString( + preferences.getString("userAgentString", defaultUser)); + break; } + } + + @Override + public boolean onTouchEvent(MotionEvent event) { mGestureDetector.onTouchEvent(event); return super.onTouchEvent(event); - } @Override protected void onWindowVisibilityChanged(int visibility) { if (API >= 11) { - this.setActivated(visibility == View.VISIBLE); + setActivated(visibility == View.VISIBLE); } - this.setEnabled(visibility == View.VISIBLE); + 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; + final int SWIPE_THRESHOLD = 100; + final int SWIPE_VELOCITY_THRESHOLD = 100; + + @Override + public boolean onDown(MotionEvent e) { + first = true; + return super.onDown(e); + } + + @Override + public void onLongPress(MotionEvent e) { + if (BrowserActivity.currentId != -1) { + BrowserActivity.onLongClick(); + } + super.onLongPress(e); + } + + @Override + public boolean onScroll(MotionEvent e1, MotionEvent e2, + float distanceX, float distanceY) { + if (showFullScreen && first) { + if (uBar.isShown() && getScrollY() < 5) { + uBar.startAnimation(slideUp); + } else if (distanceY < -5 && !uBar.isShown()) { + uBar.startAnimation(slideDown); + } else if (distanceY > 5 && uBar.isShown()) { + uBar.startAnimation(slideUp); + } + first = false; + } + return super.onScroll(e1, e2, distanceX, distanceY); + } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, @@ -136,18 +265,17 @@ public final class CustomWebView extends WebView { width = size.x; } - if ((width - e1.getX() < width/12) || (e1.getX() < width/12)) { + 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; + BrowserActivity.goBack(CustomWebView.this); } else { - BrowserActivity.goForward(); - return false; + BrowserActivity.goForward(CustomWebView.this); } } } @@ -156,7 +284,7 @@ public final class CustomWebView extends WebView { } catch (Exception exception) { exception.printStackTrace(); } - return false; + return super.onFling(e1, e2, velocityX, velocityY); } } diff --git a/src/acr/browser/barebones/customwebview/IncognitoWebView.java b/src/acr/browser/barebones/customwebview/IncognitoWebView.java index 57342d0..6e6d931 100644 --- a/src/acr/browser/barebones/customwebview/IncognitoWebView.java +++ b/src/acr/browser/barebones/customwebview/IncognitoWebView.java @@ -2,7 +2,9 @@ package acr.browser.barebones.customwebview; import acr.browser.barebones.activities.IncognitoModeActivity; import acr.browser.barebones.utilities.FinalVariables; +import android.annotation.SuppressLint; import android.content.Context; +import android.content.SharedPreferences; import android.graphics.Point; import android.util.DisplayMetrics; import android.view.Display; @@ -14,50 +16,63 @@ import android.view.WindowManager; import android.view.animation.Animation; import android.webkit.WebSettings; import android.webkit.WebView; +import android.webkit.WebSettings.LayoutAlgorithm; +import android.webkit.WebSettings.PluginState; +import android.webkit.WebSettings.RenderPriority; public final class IncognitoWebView extends WebView { - private float location; private boolean first = false; - final int API = FinalVariables.API; - final boolean showFullScreen = IncognitoModeActivity.showFullScreen; - final View uBar = IncognitoModeActivity.urlBar; + static final int API = FinalVariables.API; + public static boolean showFullScreen;; + final View uBar = IncognitoModeActivity.uBar; final Animation slideUp = IncognitoModeActivity.slideUp; final Animation slideDown = IncognitoModeActivity.slideDown; static Context CONTEXT; + static String defaultUser; + public WebSettings settings; public IncognitoWebView(Context context) { + super(context); + defaultUser = IncognitoModeActivity.defaultUser; + showFullScreen = IncognitoModeActivity.showFullScreen; mGestureDetector = new GestureDetector(context, new CustomGestureListener()); CONTEXT = context; - WebSettings settings = this.getSettings(); + settings = getSettings(); browserInitialization(context); - settingsInitialization(context, settings); + settingsInitialization(context); } + @SuppressWarnings("deprecation") 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( + setDrawingCacheBackgroundColor(0x00000000); + setFocusableInTouchMode(true); + setFocusable(true); + setAnimationCacheEnabled(false); + setDrawingCacheEnabled(true); + setBackgroundColor(context.getResources().getColor( android.R.color.white)); - this.setWillNotCacheDrawing(false); - this.setAlwaysDrawnWithCacheEnabled(true); - this.setScrollbarFadingEnabled(true); - this.setSaveEnabled(true); + if (API >= 16) { + getRootView().setBackground(null); + } else { + getRootView().setBackgroundDrawable(null); + } + setWillNotCacheDrawing(false); + setAlwaysDrawnWithCacheEnabled(true); + setScrollbarFadingEnabled(true); + setSaveEnabled(true); } + @SuppressLint("SetJavaScriptEnabled") @SuppressWarnings("deprecation") - public void settingsInitialization(Context context, WebSettings settings) { + public void settingsInitialization(Context context) { + SharedPreferences preferences = context.getSharedPreferences( + "settings", 0); 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() @@ -68,54 +83,168 @@ public final class IncognitoWebView extends WebView { settings.setDisplayZoomControls(false); settings.setAllowContentAccess(true); } - } - @Override - public boolean onTouchEvent(MotionEvent event) { + if (preferences.getBoolean("java", true)) { + settings.setJavaScriptEnabled(true); + settings.setJavaScriptCanOpenWindowsAutomatically(true); + } - switch (event.getAction()) { - case MotionEvent.ACTION_DOWN: { - first = true; - if (API <= 10 && !hasFocus()) { - requestFocus(); + if (API < 14) { + switch (preferences.getInt("textsize", 3)) { + case 1: + settings.setTextSize(WebSettings.TextSize.LARGEST); + break; + case 2: + settings.setTextSize(WebSettings.TextSize.LARGER); + break; + case 3: + settings.setTextSize(WebSettings.TextSize.NORMAL); + break; + case 4: + settings.setTextSize(WebSettings.TextSize.SMALLER); + break; + case 5: + settings.setTextSize(WebSettings.TextSize.SMALLEST); + break; + } + + } else { + switch (preferences.getInt("textsize", 3)) { + case 1: + settings.setTextZoom(200); + break; + case 2: + settings.setTextZoom(150); + break; + case 3: + settings.setTextZoom(100); + break; + case 4: + settings.setTextZoom(75); + break; + case 5: + settings.setTextZoom(50); + break; } - location = event.getY(); + } + settings.setSupportMultipleWindows(preferences.getBoolean("newwindow", + true)); + + switch (preferences.getInt("enableflash", 0)) { + case 0: + break; + case 1: { + settings.setPluginState(PluginState.ON_DEMAND); break; } - case MotionEvent.ACTION_UP: { + case 2: { + settings.setPluginState(PluginState.ON); + break; + } + default: + break; + } + if (preferences.getBoolean("passwords", false)) { + if (API < 18) { + settings.setSavePassword(true); + } + settings.setSaveFormData(true); + } + if (API < 18) { + try { + settings.setRenderPriority(RenderPriority.HIGH); + } catch (SecurityException ignored) { - if (showFullScreen && first) { - if (uBar.isShown() && getScrollY() < 5) { - uBar.startAnimation(slideUp); - } else if ((event.getY() - location) > 20.0 && !uBar.isShown()) { - uBar.startAnimation(slideDown); - } else if ((event.getY() - location) < -20.0 && uBar.isShown()) { - uBar.startAnimation(slideUp); - } - first = false; } - break; } + settings.setGeolocationEnabled(preferences + .getBoolean("location", false)); + settings.setGeolocationDatabasePath(context.getFilesDir() + .getAbsolutePath()); + settings.setUseWideViewPort(preferences + .getBoolean("wideviewport", true)); + settings.setLoadWithOverviewMode(preferences.getBoolean("overviewmode", + true)); + + if (preferences.getBoolean("textreflow", false)) { + settings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS); + } else { + settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); } - return mGestureDetector.onTouchEvent(event) - || super.onTouchEvent(event); + settings.setBlockNetworkImage(preferences.getBoolean("blockimages", + false)); + settings.setLoadsImagesAutomatically(true); + + switch (preferences.getInt("agentchoose", 1)) { + case 1: + getSettings().setUserAgentString(defaultUser); + break; + case 2: + getSettings().setUserAgentString( + FinalVariables.DESKTOP_USER_AGENT); + break; + case 3: + getSettings().setUserAgentString( + FinalVariables.MOBILE_USER_AGENT); + break; + case 4: + getSettings().setUserAgentString( + preferences.getString("userAgentString", defaultUser)); + break; + } + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + mGestureDetector.onTouchEvent(event); + return super.onTouchEvent(event); } @Override protected void onWindowVisibilityChanged(int visibility) { if (API >= 11) { - this.setActivated(visibility == View.VISIBLE); + setActivated(visibility == View.VISIBLE); } - this.setEnabled(visibility == View.VISIBLE); + 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; + final int SWIPE_THRESHOLD = 100; + final int SWIPE_VELOCITY_THRESHOLD = 100; + + @Override + public boolean onDown(MotionEvent e) { + first = true; + return super.onDown(e); + } + + @Override + public void onLongPress(MotionEvent e) { + if (IncognitoModeActivity.currentId != -1) { + IncognitoModeActivity.onLongClick(); + } + super.onLongPress(e); + } + + @Override + public boolean onScroll(MotionEvent e1, MotionEvent e2, + float distanceX, float distanceY) { + if (showFullScreen && first) { + if (uBar.isShown() && getScrollY() < 5) { + uBar.startAnimation(slideUp); + } else if (distanceY < -5 && !uBar.isShown()) { + uBar.startAnimation(slideDown); + } else if (distanceY > 5 && uBar.isShown()) { + uBar.startAnimation(slideUp); + } + first = false; + } + return super.onScroll(e1, e2, distanceX, distanceY); + } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, @@ -136,18 +265,17 @@ public final class IncognitoWebView extends WebView { width = size.x; } - if ((width - e1.getX() < width/12) || (e1.getX() < width/12)) { + 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; + IncognitoModeActivity.goBack(IncognitoWebView.this); } else { - IncognitoModeActivity.goForward(); - return false; + IncognitoModeActivity.goForward(IncognitoWebView.this); } } } @@ -156,7 +284,7 @@ public final class IncognitoWebView extends WebView { } catch (Exception exception) { exception.printStackTrace(); } - return false; + return super.onFling(e1, e2, velocityX, velocityY); } } diff --git a/src/acr/browser/barebones/incognitoclasses/IncognitoChromeClient.java b/src/acr/browser/barebones/incognitoclasses/IncognitoChromeClient.java index 36e28e2..9e025c2 100644 --- a/src/acr/browser/barebones/incognitoclasses/IncognitoChromeClient.java +++ b/src/acr/browser/barebones/incognitoclasses/IncognitoChromeClient.java @@ -136,8 +136,9 @@ public class IncognitoChromeClient extends WebChromeClient { if (mCustomView == null && mCustomViewCallback == null) { return; } - mCustomView = null; + mCustomView.setKeepScreenOn(false); + mCustomView = null; IncognitoModeActivity.onHideCustomView(fullScreenContainer, mCustomViewCallback, orientation); } diff --git a/src/acr/browser/barebones/incognitoclasses/IncognitoLongClickListener.java b/src/acr/browser/barebones/incognitoclasses/IncognitoLongClickListener.java index 5e1798e..6f8855f 100644 --- a/src/acr/browser/barebones/incognitoclasses/IncognitoLongClickListener.java +++ b/src/acr/browser/barebones/incognitoclasses/IncognitoLongClickListener.java @@ -8,7 +8,7 @@ public class IncognitoLongClickListener implements OnLongClickListener{ @Override public boolean onLongClick(View v) { - return IncognitoModeActivity.onLongClick(v.getId()); + return IncognitoModeActivity.onLongClick(); } } diff --git a/src/acr/browser/barebones/utilities/FinalVariables.java b/src/acr/browser/barebones/utilities/FinalVariables.java index 0edc8d7..e59417c 100644 --- a/src/acr/browser/barebones/utilities/FinalVariables.java +++ b/src/acr/browser/barebones/utilities/FinalVariables.java @@ -15,6 +15,7 @@ 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 DUCK_LITE_SEARCH = "https://duckduckgo.com/lite/?q="; public static final String STARTPAGE_SEARCH = "https://startpage.com/do/metasearch.pl?language=english&cat=web&query="; public static final String HOMEPAGE = "https://www.google.com/"; public static final String BAIDU_SEARCH = "http://www.baidu.com/s?wd="; diff --git a/src/acr/browser/barebones/utilities/Utils.java b/src/acr/browser/barebones/utilities/Utils.java index 0d40dfe..86797b8 100644 --- a/src/acr/browser/barebones/utilities/Utils.java +++ b/src/acr/browser/barebones/utilities/Utils.java @@ -7,6 +7,7 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; + import acr.browser.barebones.databases.DatabaseHandler; import acr.browser.barebones.databases.HistoryItem; import android.annotation.SuppressLint; @@ -27,6 +28,7 @@ import android.os.Environment; import android.provider.Browser; import android.util.Log; import android.webkit.URLUtil; +import android.widget.EditText; import android.widget.Toast; public class Utils { diff --git a/src/acr/browser/barebones/webviewclasses/CustomChromeClient.java b/src/acr/browser/barebones/webviewclasses/CustomChromeClient.java index 72c68d2..b816588 100644 --- a/src/acr/browser/barebones/webviewclasses/CustomChromeClient.java +++ b/src/acr/browser/barebones/webviewclasses/CustomChromeClient.java @@ -136,8 +136,9 @@ public class CustomChromeClient extends WebChromeClient { if (mCustomView == null && mCustomViewCallback == null) { return; } - mCustomView = null; + mCustomView.setKeepScreenOn(false); + mCustomView = null; BrowserActivity.onHideCustomView(fullScreenContainer, mCustomViewCallback, orientation); } diff --git a/src/acr/browser/barebones/webviewclasses/WebPageLongClickListener.java b/src/acr/browser/barebones/webviewclasses/WebPageLongClickListener.java index 959d446..1313fed 100644 --- a/src/acr/browser/barebones/webviewclasses/WebPageLongClickListener.java +++ b/src/acr/browser/barebones/webviewclasses/WebPageLongClickListener.java @@ -8,7 +8,7 @@ public class WebPageLongClickListener implements OnLongClickListener{ @Override public boolean onLongClick(View v) { - return BrowserActivity.onLongClick(v.getId()); + return BrowserActivity.onLongClick(); } }