diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 26b1f06..1d91984 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,103 +1,124 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Barebones.apk b/Barebones.apk index 95fa1ea..367b556 100644 Binary files a/Barebones.apk and b/Barebones.apk differ diff --git a/README b/README deleted file mode 100644 index cf8ef51..0000000 --- a/README +++ /dev/null @@ -1,4 +0,0 @@ -This is an open source webkit based browser. - -I make money off a similar paid version which currently has unlimited tabs and unlimited bookmarks. Modifiying two values at the top of the main activity "barebones" will turn this into the paid version. -Change static public int MAX_TABS and MAX_BOOKMARKS from 5 to 50 and you have the paid version. diff --git a/README.md b/README.md new file mode 100644 index 0000000..b8cdd9f --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +#Lightning Browser +#![](https://lh3.ggpht.com/HLSuHvg80_HMmgZ8GkmxMkHvovFu0_QcBqK-omS-JLGe8s-ChPQPYZZFXBRHEtHoQZQ=w150-rw) +####Download +* [APK File](https://github.com/anthonycr/Lightning-Browser/blob/master/Barebones.apk?raw=true) + +* [Google Play](https://play.google.com/store/apps/details?id=acr.browser.barebones) + + +####Features +* Bookmarks + +* History + +* Multiple Search Engines (Google, Bing, Yahoo, StartPage, DuckDuckGo + +* Incognito Mode + +* Flash Support + +* Privacy Aware + +* ````#YOLOHOLO```` + +####Permissions Requested and Explained + +* INTERNET: For accessing the web + +* ````WRITE_EXTERNAL_STORAGE````: For downloading files from the browser + +* ````READ_EXTERNAL_STORAGE````: For downloading files from the browser + +* ````ACCESS_FINE_LOCATION````: For sites like Google Maps, it is disabled by default in settings and displays a pop-up asking if a site may use your location when it is enabled + +* ````READ_HISTORY_BOOKMARKS````: To synchronize history and bookmarks between the stock browser and Lightning + +* ````WRITE_HISTORY_BOOKMARKS````: To synchronize history and bookmarks between the stock browser and Lightning + +####The Code +* Code additions are always welcome +* Please add translations/translation fixes as you see need +* Change ````FinalVariables.MAX_TABS```` from 5 to 50 to change the Lightning to the paid version \ No newline at end of file diff --git a/zap1.png b/ic_launcher.png similarity index 100% rename from zap1.png rename to ic_launcher.png diff --git a/res/drawable-mdpi/ic_launcher.png b/res/drawable-mdpi/ic_launcher.png deleted file mode 100644 index 9cfeb00..0000000 Binary files a/res/drawable-mdpi/ic_launcher.png and /dev/null differ diff --git a/res/drawable-xhdpi/clearbg.9.png b/res/drawable-xhdpi/clearbg.9.png index c8c2052..54ef4d7 100644 Binary files a/res/drawable-xhdpi/clearbg.9.png and b/res/drawable-xhdpi/clearbg.9.png differ diff --git a/res/drawable-xxhdpi/ic_launcher.png b/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..75728fd Binary files /dev/null and b/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/res/layout/activity_main.xml b/res/layout/activity_main.xml index 4aecd7f..7137aa5 100644 --- a/res/layout/activity_main.xml +++ b/res/layout/activity_main.xml @@ -132,12 +132,13 @@ android:layout_toRightOf="@+id/refreshLayout" android:background="@drawable/book" android:ems="10" - android:hint="@string/google" + android:hint="@string/search_hint" android:imeOptions="actionGo" android:inputType="textUri" android:paddingLeft="10dp" android:paddingRight="10dp" - android:singleLine="true" /> + android:singleLine="true" + android:textColor="@color/dark" /> diff --git a/res/layout/advanced_settings.xml b/res/layout/advanced_settings.xml new file mode 100644 index 0000000..932064b --- /dev/null +++ b/res/layout/advanced_settings.xml @@ -0,0 +1,328 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/layout/settings.xml b/res/layout/settings.xml index f8bc446..8c1f4d4 100644 --- a/res/layout/settings.xml +++ b/res/layout/settings.xml @@ -1,162 +1,347 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - + android:background="@drawable/blueback" + android:paddingRight="10dp"> - + + + + + - - - - - - - - - - + android:background="@drawable/blueback" + android:paddingRight="10dp"> - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - \ No newline at end of file + diff --git a/res/menu-it/incognito_menu.xml b/res/menu-it/incognito_menu.xml deleted file mode 100644 index 5cc79f8..0000000 --- a/res/menu-it/incognito_menu.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/res/menu-it/menu.xml b/res/menu-it/menu.xml index 16c926b..598c1d7 100644 --- a/res/menu-it/menu.xml +++ b/res/menu-it/menu.xml @@ -1,11 +1,11 @@ - - - - - - - + + + + + + + - + \ No newline at end of file diff --git a/res/menu/advanced_settings.xml b/res/menu/advanced_settings.xml new file mode 100644 index 0000000..c002028 --- /dev/null +++ b/res/menu/advanced_settings.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/res/menu/menu.xml b/res/menu/menu.xml index 9c3a554..56f6c43 100644 --- a/res/menu/menu.xml +++ b/res/menu/menu.xml @@ -1,12 +1,11 @@ - - - - - - - + + + + + + - + \ No newline at end of file diff --git a/res/menu/new_settings.xml b/res/menu/new_settings.xml new file mode 100644 index 0000000..c002028 --- /dev/null +++ b/res/menu/new_settings.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/res/values-in/strings.xml b/res/values-in/strings.xml deleted file mode 100644 index 9d27b77..0000000 --- a/res/values-in/strings.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - Lightning - Google - Pengaturan Browser - Izinkan situs untuk mendeteksi lokasi anda - Simpan kata sandi - Nama Perangkat - Hapus riwayat jika keluar - Kirim email - Aktifkan Adobe Flash (jika terpasang) - Lihat dengan tampilan telpon - Lihat dengan tampilan komputer - Lihat dengan tampilan perangkat - Halaman Utama - Pengaturan hanya berlaku untuk TAB baru - Tampilan penuh - Aktifkan JavaScript - Kembalikan TAB saat kembali - - \ No newline at end of file diff --git a/res/values-it/strings.xml b/res/values-it/strings.xml index e5ac61f..6f5be6c 100644 --- a/res/values-it/strings.xml +++ b/res/values-it/strings.xml @@ -7,16 +7,15 @@ Consenti ai siti di accedere alla tua posizione Salva le tue password User Agent - Cancella cronologia all\'uscita - Scrivi allo sviluppatore + Clear history on exit + Email me Abilita Adobe Flash - Visualizza come Mobile - Visualizza come Desktop - Visualizza come User Agent personalizzato + Visualizza come mobile + Visualizza come desktop + Visualizza come agente utente personalizzata Homepage - Le impostazioni saranno valide solo per le nuove Tabs - Abilita schermo intero - Abilita JavaScript - Recupera le Tabs in caso di chiusura imprevista - - + Impostazioni valgono solo per le nuove schede + Enable fullscreen mode + Enable JavaScript + + \ No newline at end of file diff --git a/res/values-sw600dp/dimens.xml b/res/values-sw600dp/dimens.xml new file mode 100644 index 0000000..44f01db --- /dev/null +++ b/res/values-sw600dp/dimens.xml @@ -0,0 +1,8 @@ + + + + + diff --git a/res/values-sw720dp-land/dimens.xml b/res/values-sw720dp-land/dimens.xml new file mode 100644 index 0000000..61e3fa8 --- /dev/null +++ b/res/values-sw720dp-land/dimens.xml @@ -0,0 +1,9 @@ + + + + 128dp + + diff --git a/res/values/colors.xml b/res/values/colors.xml index 0026e66..1f77ce6 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -5,5 +5,6 @@ #3333b5e5 #ff000000 #ff3f3f3f + #ffa0a0a0 \ No newline at end of file diff --git a/res/values/dimens.xml b/res/values/dimens.xml new file mode 100644 index 0000000..55c1e59 --- /dev/null +++ b/res/values/dimens.xml @@ -0,0 +1,7 @@ + + + + 16dp + 16dp + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 192b4c6..328c91d 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -4,19 +4,42 @@ Lightning Google Browser Settings - Allow sites to access your location + Location Access Save your passwords User Agent - Clear history on exit + Clear history Email me - Enable Adobe Flash (if it\'s installed) + Enable Adobe Flash View as Mobile View as Desktop View as custom user agent Homepage Settings only apply to new tabs - Enable fullscreen mode + Full-screen Mode Enable JavaScript Restore your tabs if they\'re lost + Settings + Download Location + Advanced Settings + Source Code + License + github.com/anthonycr/Lightning-Browser + Apache License 2.0 + NewSettings + Settings + Application Version + Clear cache on exit + Enable text reflow + Block Images + Allow sites to open new windows + Incognito always on + Import bookmarks from Stock Browser (if available) + Text size + AdvancedSettings + Hello world! + (Recommended) + (Websites may look weird) + Search Engine + Search \ No newline at end of file diff --git a/src/acr/browser/barebones/AnthonyWebView.java b/src/acr/browser/barebones/AnthonyWebView.java deleted file mode 100644 index cc208bd..0000000 --- a/src/acr/browser/barebones/AnthonyWebView.java +++ /dev/null @@ -1,58 +0,0 @@ -package acr.browser.barebones; - -import android.content.Context; -import android.view.MotionEvent; -import android.view.View; -import android.view.animation.Animation; -import android.webkit.WebView; - -public final class AnthonyWebView extends WebView { - - boolean move; - int API = FinalVars.API; - int hitTest; - boolean showFullScreen = Barebones.showFullScreen; - View uBar = Barebones.uBar; - boolean uBarShows = Barebones.uBarShows; - Animation slideUp = Barebones.slideUp; - Animation slideDown = Barebones.slideDown; - - public AnthonyWebView(Context context) { - super(context); - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - - switch (event.getAction()) { - case MotionEvent.ACTION_DOWN: { - try { - hitTest = getHitTestResult().getType(); - } catch (NullPointerException e) { - } - if (API <= 10 && !Barebones.main[Barebones.pageId].hasFocus()) { - Barebones.main[Barebones.pageId].requestFocus(); - } - if (showFullScreen) { - if (uBarShows) { - uBar.startAnimation(slideUp); - uBarShows = false; - - } else if (Barebones.main[Barebones.pageId].getScrollY() <= 5 - && !uBarShows && hitTest != 9) { - - uBar.startAnimation(slideDown); - uBarShows = true; - - } - } - break; - } - default: - break; - } - - return super.onTouchEvent(event); - } - -} diff --git a/src/acr/browser/barebones/CustomWebView.java b/src/acr/browser/barebones/CustomWebView.java deleted file mode 100644 index 773468d..0000000 --- a/src/acr/browser/barebones/CustomWebView.java +++ /dev/null @@ -1,68 +0,0 @@ -package acr.browser.barebones; - -import java.lang.reflect.Method; - -import android.content.Context; -import android.view.MotionEvent; -import android.view.View; -import android.view.animation.Animation; -import android.webkit.WebView; -import android.widget.ZoomButtonsController; - -public final class CustomWebView extends WebView { - private float location; - private boolean first = false; - final int API = FinalVars.API; - final boolean showFullScreen = Barebones.showFullScreen; - final View uBar = Barebones.uBar; - final Animation slideUp = Barebones.slideUp; - final Animation slideDown = Barebones.slideDown; - private ZoomButtonsController zoomControl; - public CustomWebView(Context context) { - super(context); - getControls(); - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - if(API<11&&zoomControl!=null){ - zoomControl.getZoomControls().setVisibility(View.INVISIBLE); - } - switch (event.getAction()) { - case MotionEvent.ACTION_DOWN: { - first = true; - if (API <= 10 && !this.hasFocus()) { - this.requestFocus(); - } - location = event.getY(); - break; - } - case MotionEvent.ACTION_UP:{ - if (showFullScreen&&first) { - if (uBar.isShown()&&this.getScrollY()<5) { - uBar.startAnimation(slideUp); - } else if (event.getY()>location && !uBar.isShown()) { - uBar.startAnimation(slideDown); - } else if (event.getY() webview = Class.forName("android.webkit.WebView"); - Method method = webview.getMethod("getZoomButtonsController"); - zoomControl = (ZoomButtonsController) method.invoke(this, null); - } catch (Exception e) { - e.printStackTrace(); - } - } - } -} diff --git a/src/acr/browser/barebones/IncognitoWebView.java b/src/acr/browser/barebones/IncognitoWebView.java deleted file mode 100644 index bb9fbfe..0000000 --- a/src/acr/browser/barebones/IncognitoWebView.java +++ /dev/null @@ -1,68 +0,0 @@ -package acr.browser.barebones; - -import java.lang.reflect.Method; - -import android.content.Context; -import android.view.MotionEvent; -import android.view.View; -import android.view.animation.Animation; -import android.webkit.WebView; -import android.widget.ZoomButtonsController; - -public final class IncognitoWebView extends WebView { - private float location; - private boolean first = false; - final int API = FinalVars.API; - final boolean showFullScreen = IncognitoMode.showFullScreen; - final View uBar = IncognitoMode.uBar; - final Animation slideUp = IncognitoMode.slideUp; - final Animation slideDown = IncognitoMode.slideDown; - private ZoomButtonsController zoomControl; - public IncognitoWebView(Context context) { - super(context); - getControls(); - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - if(API<11&&zoomControl!=null){ - zoomControl.getZoomControls().setVisibility(View.INVISIBLE); - } - switch (event.getAction()) { - case MotionEvent.ACTION_DOWN: { - first = true; - if (API <= 10 && !this.hasFocus()) { - this.requestFocus(); - } - location = event.getY(); - break; - } - case MotionEvent.ACTION_UP:{ - if (showFullScreen&&first) { - if (uBar.isShown()&&this.getScrollY()<5) { - uBar.startAnimation(slideUp); - } else if (event.getY()>location && !uBar.isShown()) { - uBar.startAnimation(slideDown); - } else if (event.getY() webview = Class.forName("android.webkit.WebView"); - Method method = webview.getMethod("getZoomButtonsController"); - zoomControl = (ZoomButtonsController) method.invoke(this, null); - } catch (Exception e) { - e.printStackTrace(); - } - } - } -} diff --git a/src/acr/browser/barebones/Settings.java b/src/acr/browser/barebones/Settings.java deleted file mode 100644 index 9ff720a..0000000 --- a/src/acr/browser/barebones/Settings.java +++ /dev/null @@ -1,527 +0,0 @@ -package acr.browser.barebones; - -import android.app.Activity; -import android.app.AlertDialog; -import android.content.Context; -import android.content.DialogInterface; -import android.content.DialogInterface.OnCancelListener; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.view.KeyEvent; -import android.view.View; -import android.view.WindowManager; -import android.view.View.OnClickListener; -import android.view.View.OnKeyListener; -import android.view.inputmethod.EditorInfo; -import android.view.inputmethod.InputMethodManager; -import android.webkit.WebView; -import android.widget.CheckBox; -import android.widget.CompoundButton; -import android.widget.CompoundButton.OnCheckedChangeListener; -import android.widget.EditText; -import android.widget.ImageView; -import android.widget.RadioButton; -import android.widget.TextView; -import android.widget.TextView.OnEditorActionListener; - -public class Settings extends Activity { - private static final String preferences = "settings"; - private static boolean allowLocation; - private static boolean deleteHistory; - private static int enableFlash; - private static boolean savePasswords; - private static boolean fullScreen; - private static boolean java; - private static boolean saveTabs; - private static String userAgent; - private static String homepage; - private static EditText agent; - private static EditText h; - private static SharedPreferences.Editor edit; - private static int agentPicker; - - @Override - public void onCreate(Bundle savedInstanceState) { - // TODO Auto-generated method stub - super.onCreate(savedInstanceState); - setContentView(R.layout.settings); - TextView it = (TextView) findViewById(R.id.textView1); - - agent = (EditText) findViewById(R.id.agent); - agent.setSelectAllOnFocus(true); - this.getWindow().setSoftInputMode( - WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); - SharedPreferences settings = getSharedPreferences(preferences, 0); - WebView test = new WebView(Settings.this); - String user = test.getSettings().getUserAgentString(); - test.destroy(); - it.requestFocus(); - allowLocation = settings.getBoolean("location", false); - saveTabs = settings.getBoolean("savetabs", true); - savePasswords = settings.getBoolean("passwords", true); - deleteHistory = settings.getBoolean("history", false); - fullScreen = settings.getBoolean("fullscreen", false); - enableFlash = settings.getInt("enableflash", 0); - agentPicker = settings.getInt("agentchoose", 1); - userAgent = settings.getString("agent", user); - java = settings.getBoolean("java", true); - homepage = settings.getString("home", FinalVars.HOMEPAGE); - - agent.setText(userAgent); - edit = settings.edit(); - final RadioButton m = (RadioButton) findViewById(R.id.radioMobile); - final RadioButton d = (RadioButton) findViewById(R.id.radioDesktop); - final RadioButton c = (RadioButton) findViewById(R.id.radioCustom); - m.setOnClickListener(new OnClickListener(){ - - @Override - public void onClick(View arg0) { - // TODO Auto-generated method stub - d.setChecked(false); - c.setChecked(false); - edit.putInt("agentchoose", 1); - edit.commit(); - } - - }); - d.setOnClickListener(new OnClickListener(){ - - @Override - public void onClick(View arg0) { - // TODO Auto-generated method stub - m.setChecked(false); - c.setChecked(false); - edit.putInt("agentchoose", 2); - edit.commit(); - } - - }); - c.setOnClickListener(new OnClickListener(){ - - @Override - public void onClick(View arg0) { - // TODO Auto-generated method stub - m.setChecked(false); - d.setChecked(false); - edit.putInt("agentchoose", 3); - edit.commit(); - } - - }); - switch (agentPicker) { - case 1: - m.setChecked(true); - d.setChecked(false); - c.setChecked(false); - break; - case 2: - m.setChecked(false); - d.setChecked(true); - c.setChecked(false); - break; - case 3: - - m.setChecked(false); - d.setChecked(false); - c.setChecked(true); - break; - } - back(); - location(); - passwords(); - clearHistory(); - saveTabs(); - getText(); - flash(); - getHome(); - full(); - java(); - } - - void saveTabs(){ - final CheckBox tab = (CheckBox)findViewById(R.id.saveTabs); - if(saveTabs){ - tab.setChecked(true); - - }else{ - tab.setChecked(false); - } - tab.setOnCheckedChangeListener(new OnCheckedChangeListener(){ - - @Override - public void onCheckedChanged(CompoundButton arg0, boolean arg1) { - // TODO Auto-generated method stub - if(arg1){ - edit.putBoolean("savetabs", true); - edit.commit(); - }else{ - edit.putBoolean("savetabs", false); - edit.commit(); - } - } - - }); - } - - void getHome() { - h = (EditText) findViewById(R.id.homePage); - - TextView t = (TextView) findViewById(R.id.textView3); - t.setBackgroundResource(R.drawable.button); - TextView a = (TextView) findViewById(R.id.textView2); - a.setBackgroundResource(R.drawable.button); - h.setSelectAllOnFocus(true); - h.setText(homepage); - h.setSingleLine(true); - h.setOnKeyListener(new OnKeyListener(){ - - @Override - public boolean onKey(View arg0, int arg1, KeyEvent arg2) { - // TODO Auto-generated method stub - switch(arg1){ - case KeyEvent.KEYCODE_ENTER: - String home; - home = h.getText().toString(); - if(!home.contains("about:blank")&&!home.contains("about:home")){ - if(!home.contains("http://") && !home.contains("https://")){ - home = "http://"+home; - }} - edit.putString("home", home); - edit.commit(); - return true; - default: break; - } - return false; - } - - }); - h.setOnEditorActionListener(new OnEditorActionListener() { - - @Override - public boolean onEditorAction(TextView v, int actionId, - KeyEvent event) { - // TODO Auto-generated method stub - if (actionId == EditorInfo.IME_ACTION_GO - || actionId == EditorInfo.IME_ACTION_DONE - || actionId == EditorInfo.IME_ACTION_NEXT - || actionId == EditorInfo.IME_ACTION_SEND||actionId==EditorInfo.IME_ACTION_SEARCH||event.getAction()==KeyEvent.KEYCODE_ENTER) { - String home = h.getText().toString(); - if(!h.getText().toString().contains("about:blank")&&!h.getText().toString().contains("about:home")){ - if(!h.getText().toString().contains("http://") && !h.getText().toString().contains("https://")){ - home = "http://"+h.getText().toString(); - }} - edit.putString("home", home); - edit.commit(); - InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - imm.hideSoftInputFromWindow(agent.getWindowToken(), 0); - return true; - } - return false; - } - - }); - } - - public void radioAgent(View v) { - - boolean checked = ((RadioButton) v).isChecked(); - switch (v.getId()) { - case (R.id.radioMobile): - if (checked) { - edit.putInt("agentchoose", 1); - edit.commit(); - - } - break; - case (R.id.radioDesktop): - if (checked) { - edit.putInt("agentchoose", 2); - edit.commit(); - - } - break; - case (R.id.radioCustom): - if (checked) { - edit.putInt("agentchoose", 3); - edit.commit(); - - } - break; - } - - } - - void back() { - ImageView back = (ImageView) findViewById(R.id.back); - back.setBackgroundResource(R.drawable.button); - back.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - // TODO Auto-generated method stub - if (agentPicker == 3) { - userAgent = agent.getText().toString(); - edit.putString("agent", userAgent); - edit.commit(); - } - String home = h.getText().toString(); - if(!h.getText().toString().contains("about:blank")&&!h.getText().toString().contains("about:home")){ - if(!h.getText().toString().contains("http://") && !h.getText().toString().contains("https://")){ - home = "http://"+h.getText().toString(); - }} - edit.putString("home", home); - edit.commit(); - finish(); - } - - }); - } - void java(){ - final CheckBox full = (CheckBox)findViewById(R.id.java); - if(java){ - full.setChecked(true); - - }else{ - full.setChecked(false); - } - full.setOnCheckedChangeListener(new OnCheckedChangeListener(){ - - @Override - public void onCheckedChanged(CompoundButton arg0, boolean arg1) { - // TODO Auto-generated method stub - if(arg1){ - edit.putBoolean("java", true); - edit.commit(); - }else{ - edit.putBoolean("java", false); - edit.commit(); - } - } - - }); - } -void full(){ - final CheckBox full = (CheckBox)findViewById(R.id.fullScreen); - if(fullScreen){ - full.setChecked(true); - - }else{ - full.setChecked(false); - } - full.setOnCheckedChangeListener(new OnCheckedChangeListener(){ - - @Override - public void onCheckedChanged(CompoundButton arg0, boolean arg1) { - // TODO Auto-generated method stub - if(arg1){ - edit.putBoolean("fullscreen", true); - edit.commit(); - }else{ - edit.putBoolean("fullscreen", false); - edit.commit(); - } - } - - }); -} - void flash() { - final CheckBox fla = (CheckBox) findViewById(R.id.flash); - if (enableFlash == 1||enableFlash==2) { - fla.setChecked(true); - } else { - fla.setChecked(false); - } - fla.setOnCheckedChangeListener(new OnCheckedChangeListener() { - - @Override - public void onCheckedChanged(CompoundButton arg0, boolean isChecked) { - // TODO Auto-generated method stub - if (isChecked) { - - DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, - int which) { - switch (which) { - case DialogInterface.BUTTON_POSITIVE: { - edit.putInt("enableflash", 1); - edit.commit(); - break; - } - case DialogInterface.BUTTON_NEGATIVE: { - edit.putInt("enableflash", 2); - edit.commit(); - break; - } - default: - fla.setChecked(false); - edit.putInt("enableflash", 0); - break; - } - } - }; - - AlertDialog.Builder builder = new AlertDialog.Builder( - Settings.this); // dialog - builder.setMessage( - "How do you want Flash enabled?") - .setPositiveButton("Load on-demand", - dialogClickListener) - .setNegativeButton("Always load", - dialogClickListener).show(); - builder.setOnCancelListener(new OnCancelListener(){ - - @Override - public void onCancel(DialogInterface arg0) { - // TODO Auto-generated method stub - edit.putInt("enableflash", 0); - edit.commit(); - fla.setChecked(false); - } - - }); - - - } else { - edit.putInt("enableflash", 0); - edit.commit(); - } - } - - }); - } - - void location() { - CheckBox loc = (CheckBox) findViewById(R.id.location); - if (allowLocation) { - loc.setChecked(true); - } else { - loc.setChecked(false); - } - loc.setOnCheckedChangeListener(new OnCheckedChangeListener() { - - @Override - public void onCheckedChanged(CompoundButton arg0, boolean isChecked) { - // TODO Auto-generated method stub - if (isChecked) { - edit.putBoolean("location", true); - edit.commit(); - } else { - edit.putBoolean("location", false); - edit.commit(); - } - } - - }); - } - - - void getText() { - agent.setOnKeyListener(new OnKeyListener(){ - - @Override - public boolean onKey(View arg0, int arg1, KeyEvent arg2) { - // TODO Auto-generated method stub - switch(arg1){ - case KeyEvent.KEYCODE_ENTER: - userAgent = agent.getText().toString(); - InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - imm.hideSoftInputFromWindow(agent.getWindowToken(), 0); - edit.putString("agent", userAgent); - edit.commit(); - return true; - default: break; - } - return false; - } - - }); - agent.setOnEditorActionListener(new OnEditorActionListener() { - - @Override - public boolean onEditorAction(TextView v, int actionId, - KeyEvent event) { - // TODO Auto-generated method stub - if (actionId == EditorInfo.IME_ACTION_GO - || actionId == EditorInfo.IME_ACTION_DONE - || actionId == EditorInfo.IME_ACTION_NEXT - || actionId == EditorInfo.IME_ACTION_SEND||actionId==EditorInfo.IME_ACTION_SEARCH||event.getAction()==KeyEvent.KEYCODE_ENTER) { - userAgent = agent.getText().toString(); - InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - imm.hideSoftInputFromWindow(agent.getWindowToken(), 0); - edit.putString("agent", userAgent); - edit.commit(); - return true; - } - return false; - } - - }); - } - - void passwords() { - CheckBox pass = (CheckBox) findViewById(R.id.password); - if (savePasswords) { - pass.setChecked(true); - } else { - pass.setChecked(false); - } - pass.setOnCheckedChangeListener(new OnCheckedChangeListener() { - - @Override - public void onCheckedChanged(CompoundButton arg0, boolean isChecked) { - // TODO Auto-generated method stub - if (isChecked) { - edit.putBoolean("passwords", true); - edit.commit(); - } else { - edit.putBoolean("passwords", false); - edit.commit(); - } - } - - }); - } - - void clearHistory() { - CheckBox clearHist = (CheckBox) findViewById(R.id.historyClear); - if (deleteHistory) { - clearHist.setChecked(true); - } else { - clearHist.setChecked(false); - } - clearHist.setOnCheckedChangeListener(new OnCheckedChangeListener() { - - @Override - public void onCheckedChanged(CompoundButton arg0, boolean isChecked) { - // TODO Auto-generated method stub - if (isChecked) { - edit.putBoolean("history", true); - edit.commit(); - } else { - edit.putBoolean("history", false); - edit.commit(); - } - } - - }); - } - - - @Override - public void onBackPressed() { - // TODO Auto-generated method stub - if (agentPicker == 3) { - userAgent = agent.getText().toString(); - edit.putString("agent", userAgent); - edit.commit(); - } - String home = h.getText().toString(); - if(!h.getText().toString().contains("about:blank")&&!h.getText().toString().contains("about:home")){ - if(!h.getText().toString().contains("http://") && !h.getText().toString().contains("https://")){ - home = "http://"+h.getText().toString(); - }} - edit.putString("home", home); - edit.commit(); - super.onBackPressed(); - } -} diff --git a/src/acr/browser/barebones/activities/AdvancedSettingsActivity.java b/src/acr/browser/barebones/activities/AdvancedSettingsActivity.java new file mode 100644 index 0000000..1a93608 --- /dev/null +++ b/src/acr/browser/barebones/activities/AdvancedSettingsActivity.java @@ -0,0 +1,469 @@ +package acr.browser.barebones.activities; + +import java.io.File; + +import acr.browser.barebones.R; +import acr.browser.barebones.variables.BookmarkPageVariables; +import acr.browser.barebones.variables.FinalVariables; +import acr.browser.barebones.variables.Utils; +import acr.browser.barebones.activities.BarebonesActivity; +import android.os.Bundle; +import android.provider.Browser; +import android.app.Activity; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.SharedPreferences; +import android.database.Cursor; +import android.view.Menu; +import android.view.View; +import android.view.View.OnClickListener; +import android.webkit.CookieManager; +import android.webkit.CookieSyncManager; +import android.webkit.WebIconDatabase; +import android.webkit.WebViewDatabase; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.CompoundButton.OnCheckedChangeListener; +import android.widget.ImageView; +import android.widget.RelativeLayout; + +public class AdvancedSettingsActivity extends Activity { + + // settings variables + static boolean savePasswords, clearCache, enableJavaScript, + enableTextReflow, blockImages, newWindow, incognitoAlways; + static int defaultZoom, textSize; + static final int API = FinalVariables.API; + static final String preferences = "settings"; + static SharedPreferences settings; + static SharedPreferences.Editor edit; + static RelativeLayout r1, r2, r3, r4, r5, r6, r7, r8, r9, r10; + static CheckBox cb1, cb2, cb3, cb4, cb5, cb6, cb7; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.advanced_settings); + settings = getSharedPreferences(preferences, 0); + edit = settings.edit(); + initialize(); + } + + void initialize() { + + r1 = (RelativeLayout) findViewById(R.id.r1); + r2 = (RelativeLayout) findViewById(R.id.r2); + r3 = (RelativeLayout) findViewById(R.id.r3); + r4 = (RelativeLayout) findViewById(R.id.r4); + r5 = (RelativeLayout) findViewById(R.id.r5); + r6 = (RelativeLayout) findViewById(R.id.r6); + r7 = (RelativeLayout) findViewById(R.id.r7); + r8 = (RelativeLayout) findViewById(R.id.r8); + r9 = (RelativeLayout) findViewById(R.id.r9); + r10 = (RelativeLayout) findViewById(R.id.r10); + + cb1 = (CheckBox) findViewById(R.id.cb1); + cb2 = (CheckBox) findViewById(R.id.cb2); + cb3 = (CheckBox) findViewById(R.id.cb3); + cb4 = (CheckBox) findViewById(R.id.cb4); + cb5 = (CheckBox) findViewById(R.id.cb5); + cb6 = (CheckBox) findViewById(R.id.cb6); + cb7 = (CheckBox) findViewById(R.id.cb7); + + cb1.setChecked(settings.getBoolean("passwords", true)); + cb2.setChecked(settings.getBoolean("cache", false)); + cb3.setChecked(settings.getBoolean("java", true)); + cb4.setChecked(settings.getBoolean("textreflow", false)); + cb5.setChecked(settings.getBoolean("blockimages", false)); + cb6.setChecked(settings.getBoolean("newwindows", true)); + cb7.setChecked(settings.getBoolean("alwaysincognito", false)); + + r1(r1); + r2(r2); + r3(r3); + r4(r4); + r5(r5); + r6(r6); + r7(r7); + r8(r8); + r9(r9); + r10(r10); + cb1(cb1); + cb2(cb2); + cb3(cb3); + cb4(cb4); + cb5(cb5); + cb6(cb6); + cb7(cb7); + back(); + } + + void back() { + ImageView back = (ImageView) findViewById(R.id.advanced_back); + back.setBackgroundResource(R.drawable.button); + back.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View arg0) { + finish(); + } + + }); + } + + static void cb1(CheckBox view) { + view.setOnCheckedChangeListener(new OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, + boolean isChecked) { + edit.putBoolean("passwords", isChecked); + edit.commit(); + } + + }); + } + + void cb2(CheckBox view) { + view.setOnCheckedChangeListener(new OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, + boolean isChecked) { + edit.putBoolean("cache", isChecked); + edit.commit(); + } + + }); + } + + void cb3(CheckBox view) { + view.setOnCheckedChangeListener(new OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, + boolean isChecked) { + edit.putBoolean("java", isChecked); + edit.commit(); + } + + }); + } + + void cb4(CheckBox view) { + view.setOnCheckedChangeListener(new OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, + boolean isChecked) { + edit.putBoolean("textreflow", isChecked); + edit.commit(); + } + }); + } + + void cb5(CheckBox view) { + view.setOnCheckedChangeListener(new OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, + boolean isChecked) { + edit.putBoolean("blockimages", isChecked); + edit.commit(); + } + + }); + } + + void cb6(CheckBox view) { + view.setOnCheckedChangeListener(new OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, + boolean isChecked) { + edit.putBoolean("newwindows", isChecked); + edit.commit(); + } + + }); + } + + void cb7(CheckBox view) { + view.setOnCheckedChangeListener(new OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, + boolean isChecked) { + edit.putBoolean("alwaysincognito", isChecked); + edit.commit(); + } + + }); + } + + void r1(RelativeLayout view) { + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + // TODO Auto-generated method stub + cb1.setChecked(!cb1.isChecked()); + } + + }); + } + + void r2(RelativeLayout view) { + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + // TODO Auto-generated method stub + cb2.setChecked(!cb2.isChecked()); + } + + }); + } + + void r3(RelativeLayout view) { + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + // TODO Auto-generated method stub + cb3.setChecked(!cb3.isChecked()); + } + + }); + } + + void r4(RelativeLayout view) { + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + // TODO Auto-generated method stub + cb4.setChecked(!cb4.isChecked()); + } + + }); + } + + void r5(RelativeLayout view) { + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + // TODO Auto-generated method stub + cb5.setChecked(!cb5.isChecked()); + } + + }); + } + + void r6(RelativeLayout view) { + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + // TODO Auto-generated method stub + cb6.setChecked(!cb6.isChecked()); + } + + }); + } + + void r7(RelativeLayout view) { + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + // TODO Auto-generated method stub + cb7.setChecked(!cb7.isChecked()); + } + + }); + } + + void r8(RelativeLayout view) { + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + AlertDialog.Builder builder = new AlertDialog.Builder( + AdvancedSettingsActivity.this); // dialog + builder.setTitle("Clear History"); + builder.setMessage( + "Would you like to clear all browser history?") + .setPositiveButton("Yes", + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface arg0, + int arg1) { + Thread clear = new Thread( + new Runnable() { + + @Override + public void run() { + clearHistory(); + } + + }); + clear.start(); + } + + }) + .setNegativeButton("No", + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface arg0, + int arg1) { + // TODO Auto-generated method stub + + } + + }).show(); + } + + }); + } + + @SuppressWarnings("deprecation") + public void clearHistory() { + CookieManager c = CookieManager.getInstance(); + CookieSyncManager.createInstance(this); + c.removeAllCookie(); + AdvancedSettingsActivity.this.deleteDatabase("historyManager"); + BarebonesActivity.main[0].clearCache(true); + WebViewDatabase m = WebViewDatabase + .getInstance(AdvancedSettingsActivity.this); + m.clearFormData(); + m.clearHttpAuthUsernamePassword(); + if (API < 18) { + m.clearUsernamePassword(); + WebIconDatabase.getInstance().removeAllIcons(); + } + if (!BarebonesActivity.noStockBrowser) { + try { + Browser.clearHistory(getContentResolver()); + } catch (NullPointerException ignored) { + } + } + trimCache(AdvancedSettingsActivity.this); + } + + void r9(RelativeLayout view) { + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + importFromStockBrowser(); + } + + }); + } + + void r10(RelativeLayout view) { + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + AlertDialog.Builder picker = new AlertDialog.Builder( + AdvancedSettingsActivity.this); + picker.setTitle("Search Engine"); + CharSequence[] chars = { "Largest", "Large", "Normal", "Small", "Smallest"}; + + int n = settings.getInt("textsize", 3); + + picker.setSingleChoiceItems(chars, n - 1, + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, + int which) { + edit.putInt("textsize", which+1); + edit.commit(); + + } + }); + picker.setNeutralButton("OK", + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, + int which) { + + } + }); + picker.show(); + } + + }); + } + + void trimCache(Context context) { + try { + File dir = context.getCacheDir(); + + if (dir != null && dir.isDirectory()) { + deleteDir(dir); + } + } catch (Exception ignored) { + + } + } + + boolean deleteDir(File dir) { + if (dir != null && dir.isDirectory()) { + String[] children = dir.list(); + for (String aChildren : children) { + boolean success = deleteDir(new File(dir, aChildren)); + if (!success) { + return false; + } + } + } + // The directory is now empty so delete it + return dir.delete(); + } + + public void importFromStockBrowser() { + if (!BarebonesActivity.noStockBrowser) { + try { + String[] proj = new String[] { Browser.BookmarkColumns.TITLE, + Browser.BookmarkColumns.URL }; + String sel = Browser.BookmarkColumns.BOOKMARK + " = 1"; // 0 = + // history, + // 1 = + // bookmark + Cursor mCur; + mCur = getContentResolver().query(Browser.BOOKMARKS_URI, proj, + sel, null, null); + mCur.moveToFirst(); + + String title = ""; + String url = ""; + + if (mCur.moveToFirst() && mCur.getCount() > 0) { + while (mCur.isAfterLast() == false) { + + title = mCur.getString(mCur + .getColumnIndex(Browser.BookmarkColumns.TITLE)); + url = mCur.getString(mCur + .getColumnIndex(Browser.BookmarkColumns.URL)); + Utils.addBookmark(getBaseContext(),title,url); + mCur.moveToNext(); + } + } + } catch (NullPointerException ignored) { + } + } + else{ + Utils.createInformativeDialog(getBaseContext(), "Error", "No browser was detected to import bookmarks from."); + } + } + +} \ No newline at end of file diff --git a/src/acr/browser/barebones/Barebones.java b/src/acr/browser/barebones/activities/BarebonesActivity.java similarity index 78% rename from src/acr/browser/barebones/Barebones.java rename to src/acr/browser/barebones/activities/BarebonesActivity.java index 1148846..226f08c 100644 --- a/src/acr/browser/barebones/Barebones.java +++ b/src/acr/browser/barebones/activities/BarebonesActivity.java @@ -1,4 +1,4 @@ -package acr.browser.barebones; +package acr.browser.barebones.activities; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -12,10 +12,17 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import acr.browser.barebones.R; +import acr.browser.barebones.customwebview.CustomWebView; +import acr.browser.barebones.databases.DatabaseHandler; +import acr.browser.barebones.databases.SpaceTokenizer; +import acr.browser.barebones.variables.BookmarkPageVariables; +import acr.browser.barebones.variables.FinalVariables; +import acr.browser.barebones.variables.HistoryPageVariables; +import acr.browser.barebones.variables.Utils; import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; -import android.app.DownloadManager; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; @@ -24,7 +31,6 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; import android.database.Cursor; -import android.database.DatabaseUtils; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteMisuseException; @@ -36,10 +42,12 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.net.http.SslError; import android.os.Bundle; -import android.os.Environment; import android.os.Handler; import android.os.Message; import android.provider.Browser; +import android.text.InputType; +import android.text.TextUtils; +import android.text.method.PasswordTransformationMethod; import android.util.DisplayMetrics; import android.util.Log; import android.view.Gravity; @@ -62,10 +70,11 @@ import android.view.animation.AnimationUtils; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; import android.webkit.CookieManager; +import android.webkit.CookieSyncManager; import android.webkit.DownloadListener; import android.webkit.GeolocationPermissions; +import android.webkit.HttpAuthHandler; import android.webkit.SslErrorHandler; -import android.webkit.URLUtil; import android.webkit.ValueCallback; import android.webkit.WebChromeClient; import android.webkit.WebChromeClient.CustomViewCallback; @@ -78,9 +87,9 @@ import android.webkit.WebStorage.QuotaUpdater; import android.webkit.WebView; import android.webkit.WebView.HitTestResult; import android.webkit.WebViewClient; -import android.webkit.WebViewDatabase; 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; @@ -95,7 +104,8 @@ import android.widget.TextView; import android.widget.TextView.OnEditorActionListener; import android.widget.Toast; -public class Barebones extends Activity { +@SuppressWarnings("deprecation") +public class BarebonesActivity extends Activity { @SuppressLint("SetJavaScriptEnabled") public class CustomChromeClient extends WebChromeClient { @@ -110,24 +120,15 @@ public class Barebones extends Activity { long estimatedDatabaseSize, long totalQuota, QuotaUpdater quotaUpdater) { quotaUpdater.updateQuota(totalQuota + estimatedDatabaseSize); - super.onExceededDatabaseQuota(url, databaseIdentifier, quota, - estimatedDatabaseSize, totalQuota, quotaUpdater); + } @Override public void onReachedMaxAppCacheSize(long requiredStorage, long quota, QuotaUpdater quotaUpdater) { quotaUpdater.updateQuota(quota + requiredStorage); - super.onReachedMaxAppCacheSize(requiredStorage, quota, quotaUpdater); } - - @Override - public void onCloseWindow(WebView window) { - closeWindow = window.getId(); - browserHandler.sendEmptyMessage(2); - super.onCloseWindow(window); - } - + @Override public Bitmap getDefaultVideoPoster() { if (mDefaultVideoPoster == null) { @@ -147,20 +148,31 @@ public class Barebones extends Activity { return mVideoProgressView; } + @Override + public void onCloseWindow(WebView window) { + Message msg = Message.obtain(); + msg.what = 3; + msg.arg1 = window.getId(); + browserHandler.sendMessage(msg); + super.onCloseWindow(window); + } + @Override public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, final Message resultMsg) { - newTab(number, "", true, false); - WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj; - transport.setWebView(main[pageId]); - resultMsg.sendToTarget(); - browserHandler.postDelayed(new Runnable() { - @Override - public void run() { - main[pageId].loadUrl(getUrl.getText().toString()); - } - }, 500); + if (isUserGesture) { + newTab(number, "", true, false); + WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj; + transport.setWebView(main[pageId]); + resultMsg.sendToTarget(); + browserHandler.postDelayed(new Runnable() { + @Override + public void run() { + main[pageId].loadUrl(getUrl.getText().toString()); + } + }, 500); + } return true; } @@ -174,10 +186,14 @@ public class Barebones extends Activity { if (allowLocation) { final boolean remember = true; AlertDialog.Builder builder = new AlertDialog.Builder(CONTEXT); - builder.setTitle("Locations"); - String org = (String) origin.subSequence(0, 50); - builder.setMessage( - org + " Would like to use your Current Location ") + builder.setTitle("Location Access"); + String org = null; + if (origin.length() > 50) { + org = (String) origin.subSequence(0, 50) + "..."; + } else { + org = origin; + } + builder.setMessage(org + "\nWould like to use your Location ") .setCancelable(true) .setPositiveButton("Allow", new DialogInterface.OnClickListener() { @@ -219,19 +235,16 @@ public class Barebones extends Activity { @Override public void onReceivedIcon(WebView view, Bitmap favicon) { - if (!incognito[view.getId()]) { - setFavicon(view.getId(), favicon); - } - super.onReceivedIcon(view, favicon); + setFavicon(view.getId(), favicon); } @Override public void onReceivedTitle(final WebView view, final String title) { numberPage = view.getId(); - urlTitle[numberPage].setText(title); - urlToLoad[numberPage][1] = title; - if (title != null && !incognito[numberPage]) { - updateHistory(urlToLoad[numberPage][0], title); + if (title != null && title.length() != 0) { + urlTitle[numberPage].setText(title); + urlToLoad[numberPage][1] = title; + Utils.updateHistory(CONTEXT, getContentResolver(), noStockBrowser, urlToLoad[numberPage][0], title); } super.onReceivedTitle(view, title); } @@ -291,7 +304,7 @@ public class Barebones extends Activity { Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); - Barebones.this.startActivityForResult( + BarebonesActivity.this.startActivityForResult( Intent.createChooser(i, "File Browser"), 1); } @@ -301,7 +314,7 @@ public class Barebones extends Activity { Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); - Barebones.this.startActivityForResult( + BarebonesActivity.this.startActivityForResult( Intent.createChooser(i, "File Browser"), 1); } @@ -311,7 +324,7 @@ public class Barebones extends Activity { Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); - Barebones.this.startActivityForResult( + BarebonesActivity.this.startActivityForResult( Intent.createChooser(i, "File Browser"), 1); } } @@ -322,67 +335,91 @@ public class Barebones extends Activity { public void onDownloadStart(final String url, String userAgent, final String contentDisposition, final String mimetype, long contentLength) { - try { - Thread downloader = new Thread(new Runnable() { - @SuppressLint("InlinedApi") - @Override - public void run() { - DownloadManager download = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); - Uri nice = Uri.parse(url); - DownloadManager.Request it = new DownloadManager.Request( - nice); - String fileName = URLUtil.guessFileName(url, - contentDisposition, mimetype); - if (API >= 11) { - it.allowScanningByMediaScanner(); - it.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); - } - - it.setDestinationInExternalPublicDir( - Environment.DIRECTORY_DOWNLOADS, fileName); - Log.i("Barebones", "Downloading" + fileName); - download.enqueue(it); - } - }); - downloader.run(); - } catch (NullPointerException e) { - Log.e("Barebones", "Problem downloading"); - Toast.makeText(CONTEXT, "Error Downloading File", - Toast.LENGTH_SHORT).show(); - } catch (IllegalArgumentException e) { - Log.e("Barebones", "Problem downloading"); - Toast.makeText(CONTEXT, "Error Downloading File", - Toast.LENGTH_SHORT).show(); - } catch (SecurityException ignored) { - - } + Utils.downloadFile(CONTEXT, url, contentDisposition, mimetype); } - // } - } public class CustomWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { - - if (url.contains("market://") || url.contains("play.google.com")) { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); + Intent urlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + urlIntent + .putExtra("acr.browser.barebones.Origin", view.getId() + 1); + if (url.startsWith("market://") + || url.startsWith("http://play.google.com") + || url.startsWith("https://play.google.com")) { + startActivity(urlIntent); + return true; + } else if (url.startsWith("http://www.youtube.com") + || url.startsWith("https://www.youtube.com")) { + startActivity(urlIntent); + return true; + } else if (url.startsWith("http://maps.google.com") + || url.startsWith("https://maps.google.com")) { + startActivity(urlIntent); return true; - } else if (url.contains("youtube.com")) { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); + } else if (url.contains("tel:") || TextUtils.isDigitsOnly(url)) { + startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(url))); return true; - } else if (url.contains("maps.google.com")) { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); + } else if (url.contains("mailto:")) { + startActivity(new Intent(Intent.ACTION_SEND, Uri.parse(url))); return true; } return false; } + @Override + public void onReceivedHttpAuthRequest(final WebView view, + final HttpAuthHandler handler, final String host, + final String realm) { + + AlertDialog.Builder builder = new AlertDialog.Builder(CONTEXT); + final EditText name = new EditText(CONTEXT); + final EditText password = new EditText(CONTEXT); + LinearLayout passLayout = new LinearLayout(CONTEXT); + passLayout.setOrientation(LinearLayout.VERTICAL); + + passLayout.addView(name); + passLayout.addView(password); + + name.setHint("Username"); + password.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); + password.setTransformationMethod(new PasswordTransformationMethod()); + password.setHint("Password"); + builder.setTitle("Sign in"); + builder.setView(passLayout); + builder.setCancelable(true) + .setPositiveButton("Sign in", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + String user = name.getText().toString(); + String pass = password.getText().toString(); + handler.proceed(user.trim(), pass.trim()); + Log.i("Lightning", "Request Login"); + + } + }) + .setNegativeButton("Cancel", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + handler.cancel(); + + } + }); + AlertDialog alert = builder.create(); + alert.show(); + + } + @Override public void onScaleChanged(WebView view, float oldScale, float newScale) { - if (view != null) { + if (view.isShown()) { view.invalidate(); } super.onScaleChanged(view, oldScale, newScale); @@ -390,10 +427,8 @@ public class Barebones extends Activity { @Override public void onPageFinished(WebView view, final String url) { - if (view != null) { - view.invalidate(); - } if (view.isShown()) { + view.invalidate(); progressBar.setVisibility(View.GONE); refresh.setVisibility(View.VISIBLE); if (showFullScreen && uBar.isShown()) { @@ -401,37 +436,44 @@ public class Barebones extends Activity { } } view.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); - - pageIsLoading = false; - + Log.i("Lightning", "Page Finished"); + loadTime = System.currentTimeMillis() - loadTime; + Log.i("Lightning", "Load Time: " + loadTime); + super.onPageFinished(view, url); } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { - + Log.i("Lightning", "Page Started"); + loadTime = System.currentTimeMillis(); numberPage = view.getId(); + + if (url.startsWith("file:///")) { + view.getSettings().setUseWideViewPort(false); + } else { + view.getSettings().setUseWideViewPort(true); + } + if (view.isShown()) { refresh.setVisibility(View.INVISIBLE); progressBar.setVisibility(View.VISIBLE); + setUrlText(url); - pageIsLoading = true; } - if (incognito[numberPage]) { - urlTitle[numberPage].setCompoundDrawables(incognitoPage, null, - exitTab, null); - } else { - urlTitle[numberPage].setCompoundDrawables(webpageOther, null, - exitTab, null); - if (favicon != null) { - setFavicon(view.getId(), favicon); - } + + urlTitle[numberPage].setCompoundDrawables(webpageOther, null, + exitTab, null); + if (favicon != null) { + setFavicon(view.getId(), favicon); } + getUrl.setPadding(tenPad, 0, tenPad, 0); urlToLoad[numberPage][0] = url; if (!uBar.isShown() && showFullScreen) { uBar.startAnimation(slideDown); } + super.onPageStarted(view, url, favicon); } @Override @@ -459,8 +501,12 @@ public class Barebones extends Activity { } }); AlertDialog alert = builder.create(); - alert.show(); - super.onReceivedSslError(view, handler, error); + if (error.getPrimaryError() == SslError.SSL_UNTRUSTED) { + alert.show(); + } else { + handler.proceed(); + } + } @Override @@ -500,7 +546,7 @@ public class Barebones extends Activity { @Override public void run() { - String historyHtml = HistoryPage.Heading; + String historyHtml = HistoryPageVariables.Heading; Cursor historyCursor = null; String[][] h = new String[50][3]; @@ -536,9 +582,10 @@ public class Barebones extends Activity { Math.min(100, h[n][0].length())) + "..."; h[n][1] = historyCursor.getString(titleColumn); - historyHtml += (HistoryPage.Part1 + h[n][0] - + HistoryPage.Part2 + h[n][1] - + HistoryPage.Part3 + h[n][2] + HistoryPage.Part4); + historyHtml += (HistoryPageVariables.Part1 + + h[n][0] + HistoryPageVariables.Part2 + + h[n][1] + HistoryPageVariables.Part3 + + h[n][2] + HistoryPageVariables.Part4); n++; } while (n < 49 && historyCursor.moveToPrevious()); } @@ -548,7 +595,7 @@ public class Barebones extends Activity { } catch (IllegalStateException ignored) { } - historyHtml += BookmarkPage.End; + historyHtml += BookmarkPageVariables.End; File historyWebPage = new File(getBaseContext().getFilesDir(), "history.html"); try { @@ -572,10 +619,7 @@ public class Barebones extends Activity { } public void setUrlText(String url) { - if (!url.contains("file:///" + getBaseContext().getFilesDir() - + "/bookmarks.html") - && !url.contains("file:///" + getBaseContext().getFilesDir() - + "/history.html")) { + if (!url.startsWith("file://")) { getUrl.setText(url); } else { getUrl.setText(""); @@ -584,7 +628,6 @@ public class Barebones extends Activity { public class TabTouchListener implements OnTouchListener { - @SuppressWarnings("deprecation") @Override public boolean onTouch(View v, MotionEvent event) { id = v.getId(); @@ -597,10 +640,10 @@ public class Barebones extends Activity { urlTitle[pageId].setPadding(leftPad, 0, rightPad, 0); if (event.getAction() == MotionEvent.ACTION_UP) { - if (x >= (edge.right - bounds.width() - v.getPaddingRight() - fuzz * 3 / 2) - && x <= (edge.right - v.getPaddingRight() + fuzz * 3 / 2) - && y >= (v.getPaddingTop() - fuzz / 2) - && y <= (v.getHeight() - v.getPaddingBottom() + fuzz / 2)) { + 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) { @@ -784,52 +827,10 @@ public class Barebones extends Activity { } case DialogInterface.BUTTON_NEUTRAL: { if (API > 8) { - try { - Thread down = new Thread( - new Runnable() { - @SuppressLint("InlinedApi") - @Override - public void run() { - - DownloadManager download = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); - Uri nice = Uri.parse(result - .getExtra()); - DownloadManager.Request it = new DownloadManager.Request( - nice); - String fileName = URLUtil.guessFileName( - result.getExtra(), - null, null); - - if (API >= 11) { - it.allowScanningByMediaScanner(); - it.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); - } - - it.setDestinationInExternalPublicDir( - Environment.DIRECTORY_DOWNLOADS, - fileName); - Log.i("Barebones", - "Downloading" - + fileName); - download.enqueue(it); - } - }); - down.run(); - } catch (NullPointerException e) { - Log.e("Barebones", - "Problem downloading"); - Toast.makeText(CONTEXT, - "Error Downloading File", - Toast.LENGTH_SHORT).show(); - } catch (IllegalArgumentException e) { - Log.e("Barebones", - "Problem downloading"); - Toast.makeText(CONTEXT, - "Error Downloading File", - Toast.LENGTH_SHORT).show(); - } catch (SecurityException ignored) { - - } + String url = result.getExtra(); + + Utils.downloadFile(CONTEXT, url, null, null); + } break; } @@ -850,14 +851,12 @@ public class Barebones extends Activity { } else { DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { - @SuppressWarnings("deprecation") @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: { int num = pageId; newTab(number, result.getExtra(), false, false); - // urlTitle[num].performClick(); pageId = num; break; } @@ -902,25 +901,29 @@ public class Barebones extends Activity { } // variables to differentiate free from paid - public static final int MAX_TABS = FinalVars.MAX_TABS; - public static final int MAX_BOOKMARKS = FinalVars.MAX_BOOKMARKS; - public static final boolean PAID_VERSION = FinalVars.PAID_VERSION; - public final Context CONTEXT = Barebones.this; - public static final String HOMEPAGE = FinalVars.HOMEPAGE; - public static final String SEARCH = FinalVars.GOOGLE_SEARCH; + 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 final Context CONTEXT = BarebonesActivity.this; + + public static final String HOMEPAGE = FinalVariables.HOMEPAGE; + public static String SEARCH; + public static SimpleAdapter adapter; public static MultiAutoCompleteTextView getUrl; public static final TextView[] urlTitle = new TextView[MAX_TABS]; - public static final CustomWebView[] main = new CustomWebView[MAX_TABS]; + public final static CustomWebView[] main = new CustomWebView[MAX_TABS]; public static Rect bounds; public static ValueCallback mUploadMessage; public static ImageView refresh; public static ProgressBar progressBar; + public static String defaultUser; public static Drawable webpageOther; public static Drawable incognitoPage; public static Drawable exitTab; public static int numberPage; - public static final int fuzz = 10; + public static long loadTime = 0; public static int number; public static int pageId = 0; public static int agentPicker; @@ -931,7 +934,7 @@ public class Barebones extends Activity { public static int pixels; public static int leftPad; public static int rightPad; - public static final int API = FinalVars.API; + public static final int API = FinalVariables.API; public static int mShortAnimationDuration; public static int id; public static int tenPad; @@ -940,14 +943,12 @@ public class Barebones extends Activity { public static int closeWindow; public static View mCustomView = null; public static CustomViewCallback mCustomViewCallback; - public static final boolean[] incognito = new boolean[MAX_TABS]; public static boolean isPhone = false; - public static boolean pageIsLoading = false; public static boolean allowLocation; public static boolean savePasswords; public static boolean deleteHistory; public static boolean saveTabs; - static boolean showFullScreen; + public static boolean showFullScreen; public static boolean noStockBrowser = true; public static SharedPreferences settings; public static SharedPreferences.Editor edit; @@ -961,19 +962,16 @@ public class Barebones extends Activity { public static final String[] bTitle = new String[MAX_BOOKMARKS]; public static String[] columns; public static String homepage; - public static String str; public static final String preferences = "settings"; - public static String query; public static String userAgent; public static final String[][] urlToLoad = new String[MAX_TABS][2]; public static FrameLayout background; - static RelativeLayout uBar; + public static RelativeLayout uBar; public static HorizontalScrollView tabScroll; - static Animation slideUp; - static Animation slideDown; + public static Animation slideUp; + public static Animation slideDown; public static Animation fadeOut; public static Animation fadeIn; - public static TextView txt; public static CookieManager cookieManager; @@ -1012,82 +1010,89 @@ public class Barebones extends Activity { urlTitle[id] .setCompoundDrawables(webpageOther, null, exitTab, null); } - } + icon = null; - void addBookmark() { - File book = new File(getBaseContext().getFilesDir(), "bookmarks"); - File bookUrl = new File(getBaseContext().getFilesDir(), "bookurl"); - try { - BufferedReader readUrlRead = new BufferedReader(new FileReader( - bookUrl)); - String u; - int n = 0; - while ((u = readUrlRead.readLine()) != null && n < MAX_BOOKMARKS) { - if (u.contentEquals(urlToLoad[pageId][0])) { - - readUrlRead.close(); - return; - } - n++; - } - readUrlRead.close(); - } catch (FileNotFoundException ignored) { - } catch (IOException ignored) { - } - try { - BufferedWriter bookWriter = new BufferedWriter(new FileWriter(book, - true)); - BufferedWriter urlWriter = new BufferedWriter(new FileWriter( - bookUrl, true)); - bookWriter.write(urlToLoad[pageId][1]); - urlWriter.write(urlToLoad[pageId][0]); - bookWriter.newLine(); - urlWriter.newLine(); - bookWriter.close(); - urlWriter.close(); - } catch (FileNotFoundException ignored) { - } catch (IOException ignored) { - } catch (NullPointerException ignored) { - } } + + @SuppressLint("SetJavaScriptEnabled") CustomWebView browserSettings(CustomWebView view) { view.setAnimationCacheEnabled(false); - view.setDrawingCacheEnabled(false); - view.setDrawingCacheBackgroundColor(getResources().getColor( - android.R.color.background_light)); - // view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); + view.setDrawingCacheEnabled(true); - view.setWillNotCacheDrawing(true); + view.setBackgroundColor(getResources().getColor(android.R.color.white)); + view.setDrawingCacheBackgroundColor(getResources().getColor( + android.R.color.white)); + view.setWillNotCacheDrawing(false); + view.setLongClickable(true); + view.setAlwaysDrawnWithCacheEnabled(true); + view.setScrollbarFadingEnabled(true); view.setFocusable(true); view.setFocusableInTouchMode(true); view.setSaveEnabled(true); - + view.setBackgroundColor(0xFFFFFFFF); WebSettings webViewSettings = view.getSettings(); - - boolean java = settings.getBoolean("java", true); - if (java) { + if (settings.getBoolean("java", true)) { webViewSettings.setJavaScriptEnabled(true); - webViewSettings.setJavaScriptCanOpenWindowsAutomatically(false); - } - webViewSettings.setBlockNetworkImage(false); + webViewSettings.setJavaScriptCanOpenWindowsAutomatically(true); // TODO + // not + // sure + // whether + // to + // enable + // or + // disable + } + webViewSettings.setAllowFileAccess(true); - webViewSettings.setLightTouchEnabled(true); - webViewSettings.setSupportMultipleWindows(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)); webViewSettings.setDomStorageEnabled(true); webViewSettings.setAppCacheEnabled(true); webViewSettings.setAppCachePath(getApplicationContext().getFilesDir() .getAbsolutePath() + "/cache"); - webViewSettings.setRenderPriority(RenderPriority.HIGH); - webViewSettings.setGeolocationEnabled(true); - webViewSettings.setGeolocationDatabasePath(getApplicationContext() - .getFilesDir().getAbsolutePath()); - webViewSettings.setDatabaseEnabled(true); - webViewSettings.setDatabasePath(getApplicationContext().getFilesDir() - .getAbsolutePath() + "/databases"); - enableFlash = settings.getInt("enableflash", 0); - switch (enableFlash) { + + switch (settings.getInt("enableflash", 0)) { case 0: break; case 1: { @@ -1101,24 +1106,49 @@ public class Barebones extends Activity { default: break; } + - webViewSettings.setUserAgentString(userAgent); - savePasswords = settings.getBoolean("passwords", false); - if (savePasswords) { - webViewSettings.setSavePassword(true); - webViewSettings.setSaveFormData(true); + if (API < 18) { + if (settings.getBoolean("passwords", false)) { + webViewSettings.setSavePassword(true); + webViewSettings.setSaveFormData(true); + } + try { + webViewSettings.setLightTouchEnabled(true); + webViewSettings.setRenderPriority(RenderPriority.HIGH); + + } catch (SecurityException ignored) { + + } + } else { + if (settings.getBoolean("passwords", false)) { + webViewSettings.setSaveFormData(true); + } } + webViewSettings.setGeolocationEnabled(true); + webViewSettings.setGeolocationDatabasePath(getApplicationContext() + .getFilesDir().getAbsolutePath()); + webViewSettings.setDatabaseEnabled(true); + webViewSettings.setDatabasePath(getApplicationContext().getFilesDir() + .getAbsolutePath() + "/databases"); + + webViewSettings.setUserAgentString(userAgent); + webViewSettings.setBuiltInZoomControls(true); webViewSettings.setSupportZoom(true); webViewSettings.setUseWideViewPort(true); - webViewSettings.setLoadWithOverviewMode(true); // Seems to be causing - // the performance - // to drop + webViewSettings.setLoadWithOverviewMode(true); if (API >= 11) { webViewSettings.setDisplayZoomControls(false); webViewSettings.setAllowContentAccess(true); } - webViewSettings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); + if (settings.getBoolean("textreflow", false)) { + webViewSettings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS); + } else { + webViewSettings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); + } + + webViewSettings.setBlockNetworkImage(settings.getBoolean("blockimages", false)); webViewSettings.setLoadsImagesAutomatically(true); return view; } @@ -1138,23 +1168,20 @@ public class Barebones extends Activity { return dir.delete(); } - @SuppressWarnings("deprecation") void deleteTab(final int del) { + if (API >= 11) { + main[del].onPause(); + } main[del].stopLoading(); main[del].clearHistory(); - // main[del].clearView(); urlToLoad[del][0] = null; urlToLoad[del][1] = null; - if (API >= 11) { - main[del].onPause(); - } - - // background.clearDisappearingChildren(); if (API < 16) { urlTitle[del].setBackgroundDrawable(active); } else { urlTitle[del].setBackground(active); } + urlTitle[del].setPadding(leftPad, 0, rightPad, 0); Animation yolo = AnimationUtils.loadAnimation(this, R.anim.down); yolo.setAnimationListener(new AnimationListener() { @@ -1179,7 +1206,6 @@ public class Barebones extends Activity { uBar.bringToFront(); } - @SuppressWarnings("deprecation") void findNewView(int id) { int leftId = id; boolean right = false, left = false; @@ -1257,6 +1283,16 @@ public class Barebones extends Activity { tabScroll.smoothScrollTo(urlTitle[pageId].getLeft(), 0); } + @Override + public void onLowMemory() { + for (int n = 0; n < MAX_TABS; n++) { + if (n != pageId && main[n] != null) { + main[n].freeMemory(); + } + } + super.onLowMemory(); + } + void enter() { getUrl.setOnKeyListener(new OnKeyListener() { @@ -1265,10 +1301,9 @@ public class Barebones extends Activity { switch (arg1) { case KeyEvent.KEYCODE_ENTER: - query = getUrl.getText().toString(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0); - testForSearch(); + searchTheWeb(getUrl.getText().toString()); return true; default: break; @@ -1288,10 +1323,9 @@ public class Barebones extends Activity { || actionId == EditorInfo.IME_ACTION_SEND || actionId == EditorInfo.IME_ACTION_SEARCH || (arg2.getAction() == KeyEvent.KEYCODE_ENTER)) { - query = getUrl.getText().toString(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0); - testForSearch(); + searchTheWeb(getUrl.getText().toString()); return true; } return false; @@ -1312,6 +1346,7 @@ public class Barebones extends Activity { @Override public void handleMessage(Message msg) { + switch (msg.what) { case 1: { adapter = new SimpleAdapter(CONTEXT, list, @@ -1422,10 +1457,11 @@ public class Barebones extends Activity { public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) { try { - txt = (TextView) arg1.findViewById(R.id.url); - str = txt.getText().toString(); - main[pageId].loadUrl(str); - setUrlText(str); + String url; + url = ((TextView) arg1.findViewById(R.id.url)).getText() + .toString(); + searchTheWeb(url); + url = null; getUrl.setPadding(tenPad, 0, tenPad, 0); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0); @@ -1478,29 +1514,10 @@ public class Barebones extends Activity { public void finish() { background.clearDisappearingChildren(); tabScroll.clearDisappearingChildren(); - try { - deleteHistory = settings.getBoolean("history", false); - if (deleteHistory) { - cookieManager.removeAllCookie(); - main[0].clearCache(true); - WebViewDatabase m = WebViewDatabase.getInstance(this); - m.clearFormData(); - m.clearHttpAuthUsernamePassword(); - m.clearUsernamePassword(); - CONTEXT.deleteDatabase("historyManager"); - if (!noStockBrowser) { - try { - Browser.clearHistory(getContentResolver()); - } catch (NullPointerException ignored) { - } - } - trimCache(CONTEXT); - } - - } catch (Exception e) { - Log.e("Lightning", "Error Clearing data"); + if (settings.getBoolean("cache", false)) { + main[pageId].clearCache(true); + Log.i("Lightning", "Cache Cleared"); } - super.finish(); } @@ -1547,11 +1564,13 @@ public class Barebones extends Activity { } @SuppressLint("InlinedApi") - void init() { + void initialize() { DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); historyHandler = new DatabaseHandler(this); cookieManager = CookieManager.getInstance(); + CookieSyncManager.createInstance(CONTEXT); + cookieManager.setAcceptCookie(true); progressBar = (ProgressBar) findViewById(R.id.progressBar1); if (API >= 11) { @@ -1614,13 +1633,37 @@ public class Barebones extends Activity { refreshLayout.setBackgroundResource(R.drawable.button); // user agent - user = new WebView(CONTEXT).getSettings().getUserAgentString(); + if (API < 17) { + user = new WebView(CONTEXT).getSettings().getUserAgentString(); + } else { + user = WebSettings.getDefaultUserAgent(this); + } background = (FrameLayout) findViewById(R.id.holder); - mobile = user; // setting mobile user - // agent - desktop = FinalVars.DESKTOP_USER_AGENT; // setting + defaultUser = user; // setting mobile user + // agent + mobile = FinalVariables.MOBILE_USER_AGENT; + desktop = FinalVariables.DESKTOP_USER_AGENT; // setting // desktop user agent + + switch (settings.getInt("search", 1)) { + case 1: + SEARCH = FinalVariables.GOOGLE_SEARCH; + break; + case 2: + SEARCH = FinalVariables.BING_SEARCH; + break; + case 3: + SEARCH = FinalVariables.YAHOO_SEARCH; + break; + case 4: + SEARCH = FinalVariables.STARTPAGE_SEARCH; + break; + case 5: + SEARCH = FinalVariables.DUCK_SEARCH; + break; + } + exitTab = getResources().getDrawable(R.drawable.stop); // user // agent homepage = settings.getString("home", HOMEPAGE); // initializing @@ -1660,6 +1703,7 @@ public class Barebones extends Activity { WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); // opens icondatabase so that favicons can be stored + WebIconDatabase.getInstance().open( getDir("icons", MODE_PRIVATE).getPath()); @@ -1694,7 +1738,7 @@ public class Barebones extends Activity { @Override public void run() { - initializeTabs(); // restores old tabs or creates a new one + reopenOldTabs(); // restores old tabs or creates a new one } @@ -1723,7 +1767,7 @@ public class Barebones extends Activity { @Override public void onClick(View arg0) { - if (pageIsLoading) { + if (main[pageId].getProgress() < 100) { main[pageId].stopLoading(); } else { main[pageId].reload(); @@ -1737,28 +1781,34 @@ public class Barebones extends Activity { bg.removeView(uBar); background.addView(uBar); } - browserHandler = new Handler() { - @Override - public void handleMessage(Message msg) { - switch (msg.what) { - case 1: { - main[pageId].loadUrl(getUrl.getText().toString()); - break; - } - case 2: { - deleteTab(closeWindow); - break; - } - case 3: { - main[pageId].invalidate(); - break; - } - } + browserHandler = new Handle(); + + } + + class Handle extends Handler { + + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + case 1: { + main[pageId].loadUrl(getUrl.getText().toString()); + break; } - }; + case 2: { + deleteTab(msg.arg1); + break; + } + case 3: { + main[pageId].invalidate(); + break; + } + } + super.handleMessage(msg); + } + } - void initializeTabs() { + void reopenOldTabs() { Intent url = getIntent(); String URL = url.getDataString(); boolean oldTabs = false; @@ -1775,10 +1825,10 @@ public class Barebones extends Activity { if (aMemoryURL.length() > 0) { if (number == 0) { newTab(number, "", !oldTabs, false); - main[number - 1].resumeTimers(); - main[number - 1].getSettings().setCacheMode( + main[pageId].resumeTimers(); + main[pageId].getSettings().setCacheMode( WebSettings.LOAD_CACHE_ELSE_NETWORK); - main[number - 1].loadUrl(aMemoryURL); + main[pageId].loadUrl(aMemoryURL); } else { newTab(number, "", false, false); main[number - 1].getSettings().setCacheMode( @@ -1796,12 +1846,12 @@ public class Barebones extends Activity { } } else { if (URL != null) { - // opens a new tab with the url if its there + // opens a new tab with the URL if its there newTab(number, URL, true, false); main[number - 1].resumeTimers(); } else { - // otherwise it opens the homepage + // otherwise it opens the home-page newTab(number, homepage, true, false); main[number - 1].resumeTimers(); @@ -1809,7 +1859,7 @@ public class Barebones extends Activity { } } - public CustomWebView makeTab(final int pageToView, final String Url, + public CustomWebView makeTab(final int pageToView, String Url, final boolean display) { CustomWebView view = new CustomWebView(CONTEXT); view.setId(pageToView); @@ -1825,14 +1875,13 @@ public class Barebones extends Activity { agentPicker = settings.getInt("agentchoose", 1); switch (agentPicker) { case 1: - view.getSettings().setUserAgentString(mobile); + view.getSettings().setUserAgentString(defaultUser); break; case 2: view.getSettings().setUserAgentString(desktop); break; case 3: - userAgent = settings.getString("agent", user); - view.getSettings().setUserAgentString(userAgent); + view.getSettings().setUserAgentString(mobile); break; } if (display) { @@ -1845,11 +1894,11 @@ public class Barebones extends Activity { if (Url.contains("about:home")) { goBookmarks(view); } else if (Url.contains("about:blank")) { - - view.loadUrl("about:blank"); - + view.loadUrl(""); } else { - + if (!Url.startsWith("http") && Url != "") { + Url = "http://" + Url; + } view.loadUrl(Url); } @@ -1858,12 +1907,10 @@ public class Barebones extends Activity { } void newSettings() { - Intent set = new Intent(FinalVars.SETTINGS_INTENT); - startActivity(set); + startActivity(new Intent(FinalVariables.SETTINGS_INTENT)); } // new tab method, takes the id of the tab to be created and the url to load - @SuppressWarnings("deprecation") int newTab(int theId, final String theUrl, final boolean display, final boolean incognito_mode) { Log.i("Barebones", "making tab"); @@ -1871,7 +1918,7 @@ public class Barebones extends Activity { int finalID = 0; homepage = settings.getString("home", HOMEPAGE); allowLocation = settings.getBoolean("location", false); - boolean isEmptyWebViewAvailable = false; + boolean reuseWebView = false; for (int num = 0; num < number; num++) { if (urlTitle[num].getVisibility() == View.GONE) { @@ -1896,7 +1943,7 @@ public class Barebones extends Activity { }); urlTitle[n].startAnimation(holo); urlTitle[num].setText("New Tab"); - incognito[num] = incognito_mode; + if (display) { if (API < 16) { urlTitle[num].setBackgroundDrawable(active); @@ -1918,8 +1965,9 @@ public class Barebones extends Activity { urlTitle[pageId].setBackground(inactive); } } - urlTitle[pageId].setCompoundDrawables(webpageOther, null, - exitTab, null); + 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; @@ -1931,13 +1979,12 @@ public class Barebones extends Activity { main[num].onResume(); } - isEmptyWebViewAvailable = true; + reuseWebView = true; break; } } - if (!isEmptyWebViewAvailable) { + if (!reuseWebView) { if (number < MAX_TABS) { - incognito[number] = incognito_mode; if (number > 0) { if (display) { if (API < 16) { @@ -1971,13 +2018,9 @@ public class Barebones extends Activity { title.setPadding(leftPad, 0, rightPad, 0); title.setId(number); title.setGravity(Gravity.CENTER_VERTICAL); - if (incognito[number]) { - title.setCompoundDrawables(incognitoPage, null, exitTab, - null); - } else { - title.setCompoundDrawables(webpageOther, null, exitTab, - null); - } + + title.setCompoundDrawables(webpageOther, null, exitTab, null); + Drawable[] drawables = title.getCompoundDrawables(); bounds = drawables[2].getBounds(); title.setOnTouchListener(new TabTouchListener()); @@ -2002,10 +2045,9 @@ public class Barebones extends Activity { }); title.startAnimation(holo); urlTitle[number] = title; - if (incognito[number]) { - urlTitle[number].setText("Incognito"); - } + urlTitle[number].setText("New Tab"); + if (theUrl != null) { main[number] = makeTab(number, theUrl, display); } else { @@ -2015,7 +2057,7 @@ public class Barebones extends Activity { number = number + 1; } } - if (!isEmptyWebViewAvailable && number >= MAX_TABS) { + if (!reuseWebView && number >= MAX_TABS) { Toast.makeText(CONTEXT, "Maximum number of tabs reached...", Toast.LENGTH_SHORT).show(); } @@ -2040,26 +2082,31 @@ public class Barebones extends Activity { @Override public void onBackPressed() { - if (main[pageId] != null) { + if (main[pageId] != null && main[pageId].canGoBack()) { main[pageId].stopLoading(); - + main[pageId].goBack(); if (showFullScreen && !uBar.isShown()) { uBar.startAnimation(slideDown); } - if (main[pageId].canGoBack()) { - main[pageId].goBack(); - } else { - deleteTab(pageId); - uBar.bringToFront(); - } + } else { + deleteTab(pageId); + uBar.bringToFront(); } } @Override public void onConfigurationChanged(Configuration newConfig) { + // TODO super.onConfigurationChanged(newConfig); - main[pageId].getSettings().setLayoutAlgorithm(LayoutAlgorithm.NORMAL); + if (settings.getBoolean("textreflow", false)) { + main[pageId].getSettings().setLayoutAlgorithm( + LayoutAlgorithm.NARROW_COLUMNS); + } else { + main[pageId].getSettings().setLayoutAlgorithm( + LayoutAlgorithm.NORMAL); + } + } @Override @@ -2068,20 +2115,22 @@ public class Barebones extends Activity { setContentView(R.layout.activity_main); // displays main xml layout settings = getSharedPreferences(preferences, 0); edit = settings.edit(); + saveTabs = settings.getBoolean("savetabs", true); if (saveTabs) { String mem = settings.getString("memory", ""); - memoryURL = null; + edit.putString("memory", ""); memoryURL = GetArray(mem); } inactive = getResources().getDrawable(R.drawable.bg_inactive); active = getResources().getDrawable(R.drawable.bg_press); - init(); // sets up random stuff + initialize(); // sets up random stuff options(); // allows options to be opened enter();// enter url bar DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); + float widthInInches = metrics.widthPixels / metrics.xdpi; float heightInInches = metrics.heightPixels / metrics.ydpi; double sizeInInches = Math.sqrt(Math.pow(widthInInches, 2) @@ -2094,26 +2143,13 @@ public class Barebones extends Activity { if (first == 0) { // This dialog alerts the user to some navigation // techniques - DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - switch (which) { - case DialogInterface.BUTTON_POSITIVE: - break; - - } - } - }; - - AlertDialog.Builder builder = new AlertDialog.Builder(CONTEXT); // dialog - builder.setTitle("Browser Tips"); - builder.setMessage( - "\nLong-press back button to exit browser" - + "\n\nSet your homepage in settings to about:blank to set a blank page as your default" - + "\n\nSet the homepage to about:home to set bookmarks as your homepage" - + "\n\nLong-press a link to open in a new tab" - + "\n\nCheck out the settings for more stuff!") - .setPositiveButton("Ok", dialogClickListener).show(); + String message = "\nLong-press back button to exit browser" + + "\n\nSet your homepage in settings" + + "\n\nTurn on Flash in settings" + + "\n\nTurn on Full-Screen mode in settings" + + "\n\nLong-press a link for more options" + + "\n\nCheck out advanced settings for more stuff!"; + Utils.createInformativeDialog(CONTEXT, "Browser Tips", message); edit.putInt("first", 1); edit.commit(); } @@ -2134,17 +2170,26 @@ public class Barebones extends Activity { if (keyCode == KeyEvent.KEYCODE_BACK) { finish(); return true; - } - return super.onKeyLongPress(keyCode, event); + } else + return super.onKeyLongPress(keyCode, event); } @Override protected void onNewIntent(Intent intent) { String url = intent.getDataString(); - if (url != null) { + int id = -1; + try { + id = intent.getExtras().getInt("acr.browser.barebones.Origin") - 1; + } catch (NullPointerException e) { + id = -1; + } + if (id >= 0) { + main[id].loadUrl(url); + } else if (url != null) { newTab(number, url, true, false); } + super.onNewIntent(intent); } @@ -2156,23 +2201,28 @@ public class Barebones extends Activity { generateHistory(main[pageId]); return true; case R.id.bookmark: - if (!urlToLoad[pageId][1].equals("Bookmarks")) { - addBookmark(); + if (urlToLoad[pageId][1] != null) { + if (!urlToLoad[pageId][1].equals("Bookmarks")) { + Utils.addBookmark(CONTEXT, urlToLoad[pageId][1],urlToLoad[pageId][0]); + } } return true; case R.id.settings: newSettings(); return true; case R.id.allBookmarks: - if (!urlToLoad[pageId][1].equals("Bookmarks")) { + if (urlToLoad[pageId][1] == null) { + goBookmarks(main[pageId]); + } else if (!urlToLoad[pageId][1].equals("Bookmarks")) { goBookmarks(main[pageId]); } + return true; case R.id.share: share(); return true; case R.id.incognito: - startActivity(new Intent(FinalVars.INCOGNITO_INTENT)); + startActivity(new Intent(FinalVariables.INCOGNITO_INTENT)); // newTab(number, homepage, true, true); return true; default: @@ -2182,6 +2232,7 @@ public class Barebones extends Activity { @Override protected void onPause() { + super.onPause(); if (main[pageId] != null) { if (API >= 11) { main[pageId].onPause(); @@ -2202,31 +2253,37 @@ public class Barebones extends Activity { edit.commit(); } }); - // remember.setPriority(10); remember.start(); - super.onPause(); + } @Override protected void onResume() { super.onResume(); + if (main[pageId].getProgress() == 100) { + progressBar.setVisibility(View.GONE); + refresh.setVisibility(View.VISIBLE); + } if (API >= 11) { main[pageId].onResume(); } - main[0].resumeTimers(); + main[pageId].resumeTimers(); } void openBookmarks(CustomWebView view) { - String bookmarkHtml = BookmarkPage.Heading; + String bookmarkHtml = BookmarkPageVariables.Heading; + + + for (int n = 0; n < MAX_BOOKMARKS; n++) { if (bUrl[n] != null) { - bookmarkHtml += (BookmarkPage.Part1 + bUrl[n] - + BookmarkPage.Part2 + bUrl[n] + BookmarkPage.Part3 - + bTitle[n] + BookmarkPage.Part4); + bookmarkHtml += (BookmarkPageVariables.Part1 + bUrl[n] + + BookmarkPageVariables.Part2 + bUrl[n] + + BookmarkPageVariables.Part3 + bTitle[n] + BookmarkPageVariables.Part4); } } - bookmarkHtml += BookmarkPage.End; + bookmarkHtml += BookmarkPageVariables.End; File bookmarkWebPage = new File(getBaseContext().getFilesDir(), "bookmarks.html"); try { @@ -2268,15 +2325,21 @@ public class Barebones extends Activity { generateHistory(main[pageId]); return true; case R.id.bookmark: - if (!urlToLoad[pageId][1].equals("Bookmarks")) { - addBookmark(); + if (urlToLoad[pageId][1] != null) { + if (!urlToLoad[pageId][1] + .equals("Bookmarks")) { + Utils.addBookmark(CONTEXT, urlToLoad[pageId][1],urlToLoad[pageId][0]); + } } return true; case R.id.settings: newSettings(); return true; case R.id.allBookmarks: - if (!urlToLoad[pageId][1].equals("Bookmarks")) { + if (urlToLoad[pageId][1] == null) { + goBookmarks(main[pageId]); + } else if (!urlToLoad[pageId][1] + .equals("Bookmarks")) { goBookmarks(main[pageId]); } return true; @@ -2285,7 +2348,7 @@ public class Barebones extends Activity { return true; case R.id.incognito: startActivity(new Intent( - FinalVars.INCOGNITO_INTENT)); + FinalVariables.INCOGNITO_INTENT)); // newTab(number, homepage, true, true); return true; default: @@ -2333,29 +2396,36 @@ public class Barebones extends Activity { startActivity(Intent.createChooser(shareIntent, "Share this page")); } - void testForSearch() { - String fixedQuery = query.trim(); + void searchTheWeb(String query) { + query = query.trim(); main[pageId].stopLoading(); - boolean period = fixedQuery.contains("."); - if (fixedQuery.contains("about:home") - || fixedQuery.contains("about:bookmarks")) { + if (query.startsWith("www.")) { + query = "http://" + query; + } else if (query.startsWith("ftp.")) { + query = "ftp://" + query; + } + + boolean containsPeriod = query.contains("."); + boolean isIPAddress = (TextUtils.isDigitsOnly(query.replace(".", "")) && (query + .replace(".", "").length() >= 4)); + boolean aboutScheme = query.contains("about:"); + boolean validURL = (query.startsWith("ftp://") + || query.startsWith("http://") || query.startsWith("file://") || query + .startsWith("https://")) || isIPAddress; + boolean isSearch = ((query.contains(" ") || !containsPeriod) && !aboutScheme); + + if (query.contains("about:home") || query.contains("about:bookmarks")) { goBookmarks(main[pageId]); - } else if (fixedQuery.contains("about:history")) { + } else if (query.contains("about:history")) { generateHistory(main[pageId]); - } else if (fixedQuery.contains(" ") || !period) { - fixedQuery.replaceAll(" ", "+"); - main[pageId].loadUrl(SEARCH + fixedQuery); - } else if (!fixedQuery.contains("http//") - && !fixedQuery.contains("https//") - && !fixedQuery.contains("http://") - && !fixedQuery.contains("https://")) { - fixedQuery = "http://" + fixedQuery; - main[pageId].loadUrl(fixedQuery); + } else if (isSearch) { + query.replaceAll(" ", "+"); + main[pageId].loadUrl(SEARCH + query); + } else if (!validURL) { + main[pageId].loadUrl("http://" + query); } else { - fixedQuery = fixedQuery.replaceAll("http//", "http://"); - fixedQuery = fixedQuery.replaceAll("https//", "https://"); - main[pageId].loadUrl(fixedQuery); + main[pageId].loadUrl(query); } } @@ -2370,46 +2440,4 @@ public class Barebones extends Activity { } } - - void updateHistory(final String url, final String pageTitle) { - update = new Runnable() { - @Override - public void run() { - if (!noStockBrowser) { - try { - Browser.updateVisitedHistory(getContentResolver(), url, - false); - } catch (NullPointerException ignored) { - } - } - try { - sb = new StringBuilder("url" + " = "); - DatabaseUtils.appendEscapedSQLString(sb, url); - s = historyHandler.getReadableDatabase(); - Cursor cursor = s.query("history", new String[] { "id", - "url", "title" }, sb.toString(), null, null, null, - null); - if (!cursor.moveToFirst()) { - historyHandler.addHistoryItem(new HistoryItem(url, - pageTitle)); - } - cursor.close(); - s.close(); - } catch (IllegalStateException e) { - Log.e("Barebones", "ERRRRROOORRRR 1"); - } catch (NullPointerException e) { - Log.e("Barebones", "ERRRRROOORRRR 2"); - } catch (SQLiteException e) { - Log.e("Barebones", "SQLiteException"); - } - } - }; - if (!url.contains("file:///" + getBaseContext().getFilesDir() - + "/bookmarks.html") - && !url.contains("file:///" + getBaseContext().getFilesDir() - + "/history.html")) { - - new Thread(update).start(); - } - } } \ No newline at end of file diff --git a/src/acr/browser/barebones/IncognitoMode.java b/src/acr/browser/barebones/activities/IncognitoModeActivity.java similarity index 82% rename from src/acr/browser/barebones/IncognitoMode.java rename to src/acr/browser/barebones/activities/IncognitoModeActivity.java index e64e716..7c59175 100644 --- a/src/acr/browser/barebones/IncognitoMode.java +++ b/src/acr/browser/barebones/activities/IncognitoModeActivity.java @@ -1,4 +1,4 @@ -package acr.browser.barebones; +package acr.browser.barebones.activities; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -12,6 +12,13 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +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.variables.BookmarkPageVariables; +import acr.browser.barebones.variables.FinalVariables; +import acr.browser.barebones.variables.HistoryPageVariables; import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; @@ -38,6 +45,9 @@ import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.Message; +import android.text.InputType; +import android.text.TextUtils; +import android.text.method.PasswordTransformationMethod; import android.util.DisplayMetrics; import android.util.Log; import android.view.Gravity; @@ -63,6 +73,7 @@ import android.webkit.CookieManager; import android.webkit.CookieSyncManager; import android.webkit.DownloadListener; import android.webkit.GeolocationPermissions; +import android.webkit.HttpAuthHandler; import android.webkit.SslErrorHandler; import android.webkit.URLUtil; import android.webkit.ValueCallback; @@ -79,6 +90,7 @@ import android.webkit.WebView.HitTestResult; import android.webkit.WebViewClient; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; +import android.widget.EditText; import android.widget.FrameLayout; import android.widget.HorizontalScrollView; import android.widget.ImageView; @@ -93,7 +105,7 @@ import android.widget.TextView; import android.widget.TextView.OnEditorActionListener; import android.widget.Toast; -public class IncognitoMode extends Activity { +public class IncognitoModeActivity extends Activity { @SuppressLint("SetJavaScriptEnabled") public class CustomChromeClient extends WebChromeClient { @@ -149,16 +161,18 @@ public class IncognitoMode extends Activity { public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, final Message resultMsg) { - newTab(number, "", true); - WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj; - transport.setWebView(main[pageId]); - resultMsg.sendToTarget(); - browserHandler.postDelayed(new Runnable() { - @Override - public void run() { - main[pageId].loadUrl(getUrl.getText().toString()); - } - }, 500); + if (isUserGesture) { + newTab(number, "", true, false); + WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj; + transport.setWebView(main[pageId]); + resultMsg.sendToTarget(); + browserHandler.postDelayed(new Runnable() { + @Override + public void run() { + main[pageId].loadUrl(getUrl.getText().toString()); + } + }, 500); + } return true; } @@ -172,10 +186,14 @@ public class IncognitoMode extends Activity { if (allowLocation) { final boolean remember = true; AlertDialog.Builder builder = new AlertDialog.Builder(CONTEXT); - builder.setTitle("Locations"); - String org = (String) origin.subSequence(0, 50); - builder.setMessage( - org + " Would like to use your Current Location ") + builder.setTitle("Location Access"); + String org = null; + if (origin.length() > 50) { + org = (String) origin.subSequence(0, 50) + "..."; + } else { + org = origin; + } + builder.setMessage(org + "\nWould like to use your Location ") .setCancelable(true) .setPositiveButton("Allow", new DialogInterface.OnClickListener() { @@ -215,11 +233,19 @@ public class IncognitoMode extends Activity { uBar.bringToFront(); } + @Override + public void onReceivedIcon(WebView view, Bitmap favicon) { + setFavicon(view.getId(), favicon); + } + @Override public void onReceivedTitle(final WebView view, final String title) { numberPage = view.getId(); - urlTitle[numberPage].setText(title); - urlToLoad[numberPage][1] = title; + + if (title != null && title.length() != 0) { + urlTitle[numberPage].setText(title); + urlToLoad[numberPage][1] = title; + } super.onReceivedTitle(view, title); } @@ -278,7 +304,7 @@ public class IncognitoMode extends Activity { Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); - IncognitoMode.this.startActivityForResult( + IncognitoModeActivity.this.startActivityForResult( Intent.createChooser(i, "File Browser"), 1); } @@ -288,7 +314,7 @@ public class IncognitoMode extends Activity { Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); - IncognitoMode.this.startActivityForResult( + IncognitoModeActivity.this.startActivityForResult( Intent.createChooser(i, "File Browser"), 1); } @@ -298,7 +324,7 @@ public class IncognitoMode extends Activity { Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); - IncognitoMode.this.startActivityForResult( + IncognitoModeActivity.this.startActivityForResult( Intent.createChooser(i, "File Browser"), 1); } } @@ -345,31 +371,60 @@ public class IncognitoMode extends Activity { } } - // } - } - public class IncognitoWebViewClient extends WebViewClient { + public class CustomWebViewClient extends WebViewClient { @Override - public boolean shouldOverrideUrlLoading(WebView view, String url) { + public void onReceivedHttpAuthRequest(final WebView view, + final HttpAuthHandler handler, final String host, + final String realm) { + + AlertDialog.Builder builder = new AlertDialog.Builder(CONTEXT); + final EditText name = new EditText(CONTEXT); + final EditText password = new EditText(CONTEXT); + LinearLayout passLayout = new LinearLayout(CONTEXT); + passLayout.setOrientation(LinearLayout.VERTICAL); + + passLayout.addView(name); + passLayout.addView(password); + + name.setHint("Username"); + password.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); + password.setTransformationMethod(new PasswordTransformationMethod()); + password.setHint("Password"); + builder.setTitle("Sign in"); + builder.setView(passLayout); + builder.setCancelable(true) + .setPositiveButton("Sign in", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + String user = name.getText().toString(); + String pass = password.getText().toString(); + handler.proceed(user.trim(), pass.trim()); + Log.i("Lightning", "Request Login"); + + } + }) + .setNegativeButton("Cancel", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int id) { + handler.cancel(); + + } + }); + AlertDialog alert = builder.create(); + alert.show(); - if (url.contains("market://") || url.contains("play.google.com")) { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); - return true; - } else if (url.contains("youtube.com")) { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); - return true; - } else if (url.contains("maps.google.com")) { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); - return true; - } - return false; } @Override public void onScaleChanged(WebView view, float oldScale, float newScale) { - if (view != null) { + if (view.isShown()) { view.invalidate(); } super.onScaleChanged(view, oldScale, newScale); @@ -377,35 +432,47 @@ public class IncognitoMode extends Activity { @Override public void onPageFinished(WebView view, final String url) { - if (view != null) { - view.invalidate(); - } + if (view.isShown()) { + view.invalidate(); progressBar.setVisibility(View.GONE); refresh.setVisibility(View.VISIBLE); if (showFullScreen && uBar.isShown()) { uBar.startAnimation(slideUp); } } - view.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); - - pageIsLoading = false; - + view.getSettings() + .setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); + Log.i("Lightning", "Page Finished"); + loadTime = System.currentTimeMillis() - loadTime; + Log.i("Lightning", "Load Time: "+loadTime); + super.onPageFinished(view, url); } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { - + Log.i("Lightning", "Page Started"); + loadTime = System.currentTimeMillis(); numberPage = view.getId(); + + if (url.startsWith("file:///")) { + view.getSettings().setUseWideViewPort(false); + } else { + view.getSettings().setUseWideViewPort(true); + } + if (view.isShown()) { refresh.setVisibility(View.INVISIBLE); progressBar.setVisibility(View.VISIBLE); + setUrlText(url); - pageIsLoading = true; } urlTitle[numberPage].setCompoundDrawables(incognitoPage, null, exitTab, null); + if (favicon != null) { + setFavicon(view.getId(), favicon); + } getUrl.setPadding(tenPad, 0, tenPad, 0); urlToLoad[numberPage][0] = url; @@ -413,6 +480,7 @@ public class IncognitoMode extends Activity { if (!uBar.isShown() && showFullScreen) { uBar.startAnimation(slideDown); } + super.onPageStarted(view, url, favicon); } @Override @@ -440,8 +508,12 @@ public class IncognitoMode extends Activity { } }); AlertDialog alert = builder.create(); - alert.show(); - super.onReceivedSslError(view, handler, error); + if (error.getPrimaryError() == SslError.SSL_UNTRUSTED) { + alert.show(); + } else { + handler.proceed(); + } + } @Override @@ -481,7 +553,7 @@ public class IncognitoMode extends Activity { @Override public void run() { - String historyHtml = HistoryPage.Heading; + String historyHtml = HistoryPageVariables.Heading; Cursor historyCursor = null; String[][] h = new String[50][3]; @@ -517,9 +589,10 @@ public class IncognitoMode extends Activity { Math.min(100, h[n][0].length())) + "..."; h[n][1] = historyCursor.getString(titleColumn); - historyHtml += (HistoryPage.Part1 + h[n][0] - + HistoryPage.Part2 + h[n][1] - + HistoryPage.Part3 + h[n][2] + HistoryPage.Part4); + historyHtml += (HistoryPageVariables.Part1 + + h[n][0] + HistoryPageVariables.Part2 + + h[n][1] + HistoryPageVariables.Part3 + + h[n][2] + HistoryPageVariables.Part4); n++; } while (n < 49 && historyCursor.moveToPrevious()); } @@ -529,7 +602,7 @@ public class IncognitoMode extends Activity { } catch (IllegalStateException ignored) { } - historyHtml += BookmarkPage.End; + historyHtml += BookmarkPageVariables.End; File historyWebPage = new File(getBaseContext().getFilesDir(), "history.html"); try { @@ -553,10 +626,7 @@ public class IncognitoMode extends Activity { } public void setUrlText(String url) { - if (!url.contains("file:///" + getBaseContext().getFilesDir() - + "/bookmarks.html") - && !url.contains("file:///" + getBaseContext().getFilesDir() - + "/history.html")) { + if (!url.startsWith("file:///")) { getUrl.setText(url); } else { getUrl.setText(""); @@ -578,10 +648,10 @@ public class IncognitoMode extends Activity { urlTitle[pageId].setPadding(leftPad, 0, rightPad, 0); if (event.getAction() == MotionEvent.ACTION_UP) { - if (x >= (edge.right - bounds.width() - v.getPaddingRight() - fuzz * 3 / 2) - && x <= (edge.right - v.getPaddingRight() + fuzz * 3 / 2) - && y >= (v.getPaddingTop() - fuzz / 2) - && y <= (v.getHeight() - v.getPaddingBottom() + fuzz / 2)) { + 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) { @@ -716,7 +786,7 @@ public class IncognitoMode extends Activity { switch (which) { case DialogInterface.BUTTON_POSITIVE: { int num = pageId; - newTab(number, result.getExtra(), false); + newTab(number, result.getExtra(), false, false); // urlTitle[num].performClick(); pageId = num; break; @@ -754,7 +824,7 @@ public class IncognitoMode extends Activity { switch (which) { case DialogInterface.BUTTON_POSITIVE: { int num = pageId; - newTab(number, result.getExtra(), false); + newTab(number, result.getExtra(), false, false); // urlTitle[num].performClick(); pageId = num; break; @@ -837,8 +907,7 @@ public class IncognitoMode extends Activity { switch (which) { case DialogInterface.BUTTON_POSITIVE: { int num = pageId; - newTab(number, result.getExtra(), false); - // urlTitle[num].performClick(); + newTab(number, result.getExtra(), false, false); pageId = num; break; } @@ -883,25 +952,27 @@ public class IncognitoMode extends Activity { } // variables to differentiate free from paid - public static final int MAX_TABS = FinalVars.MAX_TABS; - public static final int MAX_BOOKMARKS = FinalVars.MAX_BOOKMARKS; - public static final boolean PAID_VERSION = FinalVars.PAID_VERSION; - public final Context CONTEXT = IncognitoMode.this; - public static final String HOMEPAGE = FinalVars.HOMEPAGE; - public static final String SEARCH = FinalVars.GOOGLE_SEARCH; + 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 final Context CONTEXT = IncognitoModeActivity.this; + + public static final String HOMEPAGE = FinalVariables.HOMEPAGE; + public static String SEARCH; + public static SimpleAdapter adapter; public static MultiAutoCompleteTextView getUrl; public static final TextView[] urlTitle = new TextView[MAX_TABS]; - public static final IncognitoWebView[] main = new IncognitoWebView[MAX_TABS]; + public final static IncognitoWebView[] main = new IncognitoWebView[MAX_TABS]; public static Rect bounds; public static ValueCallback mUploadMessage; public static ImageView refresh; public static ProgressBar progressBar; - public static Drawable webpageOther; + public static String defaultUser; public static Drawable incognitoPage; public static Drawable exitTab; public static int numberPage; - public static final int fuzz = 10; public static int number; public static int pageId = 0; public static int agentPicker; @@ -912,19 +983,22 @@ public class IncognitoMode extends Activity { public static int pixels; public static int leftPad; public static int rightPad; - public static final int API = FinalVars.API; + 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 long loadTime = 0; public static View mCustomView = null; public static CustomViewCallback mCustomViewCallback; public static boolean isPhone = false; - public static boolean pageIsLoading = false; public static boolean allowLocation; - static boolean showFullScreen; + public static boolean savePasswords; + public static boolean deleteHistory; + public static boolean saveTabs; + public static boolean showFullScreen; public static SharedPreferences settings; public static SharedPreferences.Editor edit; public static String desktop; @@ -936,22 +1010,20 @@ public class IncognitoMode extends Activity { public static final String[] bTitle = new String[MAX_BOOKMARKS]; public static String[] columns; public static String homepage; - public static String str; public static final String preferences = "settings"; - public static String query; public static String userAgent; public static final String[][] urlToLoad = new String[MAX_TABS][2]; public static FrameLayout background; - static RelativeLayout uBar; + public static RelativeLayout uBar; public static HorizontalScrollView tabScroll; - static Animation slideUp; - static Animation slideDown; + public static Animation slideUp; + public static Animation slideDown; public static Animation fadeOut; public static Animation fadeIn; - public static TextView txt; public static CookieManager cookieManager; + public static Uri bookmarks; public static List> list; public static Map map; @@ -959,99 +1031,86 @@ public class IncognitoMode extends Activity { public static DatabaseHandler historyHandler; + public static StringBuilder sb; + + public static Runnable update; + + public static SQLiteDatabase s; + public static Drawable inactive; public static Drawable active; public static LinearLayout tabLayout; + public static String[] GetArray(String input) { + return input.split("\\|\\$\\|SEPARATOR\\|\\$\\|"); + } + @SuppressWarnings("unused") public static void setFavicon(int id, Bitmap favicon) { Drawable icon = null; icon = new BitmapDrawable(null, favicon); icon.setBounds(0, 0, width / 2, height / 2); - if (icon != null) { - urlTitle[id].setCompoundDrawables(icon, null, exitTab, null); - } else { - urlTitle[id] - .setCompoundDrawables(webpageOther, null, exitTab, null); - } - } - void addBookmark() { - File book = new File(getBaseContext().getFilesDir(), "bookmarks"); - File bookUrl = new File(getBaseContext().getFilesDir(), "bookurl"); - try { - BufferedReader readUrlRead = new BufferedReader(new FileReader( - bookUrl)); - String u; - int n = 0; - while ((u = readUrlRead.readLine()) != null && n < MAX_BOOKMARKS) { - if (u.contentEquals(urlToLoad[pageId][0])) { + urlTitle[id].setCompoundDrawables(incognitoPage, null, exitTab, null); + + icon = null; - readUrlRead.close(); - return; - } - n++; - } - readUrlRead.close(); - } catch (FileNotFoundException ignored) { - } catch (IOException ignored) { - } - try { - BufferedWriter bookWriter = new BufferedWriter(new FileWriter(book, - true)); - BufferedWriter urlWriter = new BufferedWriter(new FileWriter( - bookUrl, true)); - bookWriter.write(urlToLoad[pageId][1]); - urlWriter.write(urlToLoad[pageId][0]); - bookWriter.newLine(); - urlWriter.newLine(); - bookWriter.close(); - urlWriter.close(); - } catch (FileNotFoundException ignored) { - } catch (IOException ignored) { - } catch (NullPointerException ignored) { - } } @SuppressLint("SetJavaScriptEnabled") IncognitoWebView browserSettings(IncognitoWebView view) { view.setAnimationCacheEnabled(false); - view.setDrawingCacheEnabled(false); + view.setDrawingCacheEnabled(true); + view.setBackgroundColor(getResources().getColor(android.R.color.white)); view.setDrawingCacheBackgroundColor(getResources().getColor( - android.R.color.background_light)); - // view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); - - view.setWillNotCacheDrawing(true); + android.R.color.white)); + view.setWillNotCacheDrawing(false); + view.setLongClickable(true); + view.setScrollbarFadingEnabled(true); view.setFocusable(true); view.setFocusableInTouchMode(true); view.setSaveEnabled(true); - + view.setBackgroundColor(0xFFFFFFFF); WebSettings webViewSettings = view.getSettings(); - - boolean java = settings.getBoolean("java", true); - if (java) { + + if (settings.getBoolean("java", true)) { webViewSettings.setJavaScriptEnabled(true); - webViewSettings.setJavaScriptCanOpenWindowsAutomatically(false); + webViewSettings.setJavaScriptCanOpenWindowsAutomatically(true); // TODO + // not + // sure + // whether + // to + // enable + // or + // disable } webViewSettings.setBlockNetworkImage(false); webViewSettings.setAllowFileAccess(true); webViewSettings.setLightTouchEnabled(true); - webViewSettings.setSupportMultipleWindows(true); + webViewSettings.setSupportMultipleWindows(settings.getBoolean( + "newwindow", true)); webViewSettings.setDomStorageEnabled(true); webViewSettings.setAppCacheEnabled(true); webViewSettings.setAppCachePath(getApplicationContext().getFilesDir() - .getAbsolutePath() + "/cache"); - webViewSettings.setRenderPriority(RenderPriority.HIGH); - webViewSettings.setGeolocationEnabled(true); + .getAbsolutePath() + "/incognito_cache"); + try { + webViewSettings.setRenderPriority(RenderPriority.HIGH); // TODO do I + // want this + // here or + // at normal + } catch (SecurityException ignored) { + + } + webViewSettings.setGeolocationEnabled(false); webViewSettings.setGeolocationDatabasePath(getApplicationContext() .getFilesDir().getAbsolutePath()); webViewSettings.setDatabaseEnabled(true); webViewSettings.setDatabasePath(getApplicationContext().getFilesDir() .getAbsolutePath() + "/databases"); - enableFlash = settings.getInt("enableflash", 0); - switch (enableFlash) { + + switch (settings.getInt("enableflash", 0)) { case 0: break; case 1: { @@ -1067,19 +1126,24 @@ public class IncognitoMode extends Activity { } webViewSettings.setUserAgentString(userAgent); - webViewSettings.setSavePassword(false); - webViewSettings.setSaveFormData(false); + + webViewSettings.setSavePassword(false); + webViewSettings.setSaveFormData(false); + webViewSettings.setBuiltInZoomControls(true); webViewSettings.setSupportZoom(true); webViewSettings.setUseWideViewPort(true); - webViewSettings.setLoadWithOverviewMode(true); // Seems to be causing - // the performance - // to drop + webViewSettings.setLoadWithOverviewMode(true); if (API >= 11) { webViewSettings.setDisplayZoomControls(false); webViewSettings.setAllowContentAccess(true); } - webViewSettings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); + if (settings.getBoolean("textreflow", false)) { + webViewSettings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS); + } else { + webViewSettings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); + } + webViewSettings.setLoadsImagesAutomatically(true); return view; } @@ -1101,16 +1165,15 @@ public class IncognitoMode extends Activity { @SuppressWarnings("deprecation") void deleteTab(final int del) { + if (API >= 11) { + main[del].onPause(); + } main[del].stopLoading(); main[del].clearHistory(); - // main[del].clearView(); + main[del].freeMemory(); urlToLoad[del][0] = null; urlToLoad[del][1] = null; - if (API >= 11) { - main[del].onPause(); - } - // background.clearDisappearingChildren(); if (API < 16) { urlTitle[del].setBackgroundDrawable(active); } else { @@ -1218,6 +1281,16 @@ public class IncognitoMode extends Activity { tabScroll.smoothScrollTo(urlTitle[pageId].getLeft(), 0); } + @Override + public void onLowMemory() { + for (int n = 0; n < MAX_TABS; n++) { + if (n != pageId && main[n] != null) { + main[n].freeMemory(); + } + } + super.onLowMemory(); + } + void enter() { getUrl.setOnKeyListener(new OnKeyListener() { @@ -1226,10 +1299,9 @@ public class IncognitoMode extends Activity { switch (arg1) { case KeyEvent.KEYCODE_ENTER: - query = getUrl.getText().toString(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0); - testForSearch(); + searchTheWeb(getUrl.getText().toString()); return true; default: break; @@ -1249,10 +1321,9 @@ public class IncognitoMode extends Activity { || actionId == EditorInfo.IME_ACTION_SEND || actionId == EditorInfo.IME_ACTION_SEARCH || (arg2.getAction() == KeyEvent.KEYCODE_ENTER)) { - query = getUrl.getText().toString(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0); - testForSearch(); + searchTheWeb(getUrl.getText().toString()); return true; } return false; @@ -1273,6 +1344,7 @@ public class IncognitoMode extends Activity { @Override public void handleMessage(Message msg) { + switch (msg.what) { case 1: { adapter = new SimpleAdapter(CONTEXT, list, @@ -1297,6 +1369,7 @@ public class IncognitoMode extends Activity { @Override public void run() { + Cursor managedCursor = null; columns = new String[] { "url", "title" }; try { @@ -1362,10 +1435,12 @@ public class IncognitoMode extends Activity { public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) { try { - txt = (TextView) arg1.findViewById(R.id.url); - str = txt.getText().toString(); - main[pageId].loadUrl(str); - setUrlText(str); + String url; + url = ((TextView) arg1.findViewById(R.id.url)).getText() + .toString(); + main[pageId].loadUrl(url); + setUrlText(url); + url = null; getUrl.setPadding(tenPad, 0, tenPad, 0); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0); @@ -1419,6 +1494,8 @@ public class IncognitoMode extends Activity { background.clearDisappearingChildren(); tabScroll.clearDisappearingChildren(); super.finish(); + main[0].clearCache(true); + } void forward() { @@ -1464,10 +1541,13 @@ public class IncognitoMode extends Activity { } @SuppressLint("InlinedApi") - void init() { + void initialize() { DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); historyHandler = new DatabaseHandler(this); + cookieManager = CookieManager.getInstance(); + CookieSyncManager.createInstance(CONTEXT); + cookieManager.setAcceptCookie(false); progressBar = (ProgressBar) findViewById(R.id.progressBar1); if (API >= 11) { @@ -1533,10 +1613,30 @@ public class IncognitoMode extends Activity { user = new WebView(CONTEXT).getSettings().getUserAgentString(); background = (FrameLayout) findViewById(R.id.holder); - mobile = user; // setting mobile user - // agent - desktop = FinalVars.DESKTOP_USER_AGENT; // setting + defaultUser = user; // setting mobile user + // agent + mobile = FinalVariables.MOBILE_USER_AGENT; + desktop = FinalVariables.DESKTOP_USER_AGENT; // setting // desktop user agent + + switch (settings.getInt("search", 1)) { + case 1: + SEARCH = FinalVariables.GOOGLE_SEARCH; + break; + case 2: + SEARCH = FinalVariables.BING_SEARCH; + break; + case 3: + SEARCH = FinalVariables.YAHOO_SEARCH; + break; + case 4: + SEARCH = FinalVariables.STARTPAGE_SEARCH; + break; + case 5: + SEARCH = FinalVariables.DUCK_SEARCH; + break; + } + exitTab = getResources().getDrawable(R.drawable.stop); // user // agent homepage = settings.getString("home", HOMEPAGE); // initializing @@ -1550,6 +1650,10 @@ public class IncognitoMode extends Activity { 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 @@ -1557,6 +1661,9 @@ public class IncognitoMode extends Activity { // 2=desktop, // 3=custom + deleteHistory = settings.getBoolean("history", false); // delete history + // on exit + // boolean // initializing variables declared height = getResources().getDrawable(R.drawable.loading) @@ -1593,9 +1700,9 @@ public class IncognitoMode extends Activity { tenPad = (int) (10 * scale + 0.5f); number = 0; - webpageOther = getResources().getDrawable(R.drawable.webpage); + incognitoPage = getResources().getDrawable(R.drawable.incognito); - webpageOther.setBounds(0, 0, width / 2, height / 2); + incognitoPage.setBounds(0, 0, width / 2, height / 2); exitTab.setBounds(0, 0, width * 2 / 3, height * 2 / 3); @@ -1616,7 +1723,7 @@ public class IncognitoMode extends Activity { newTab.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - newTab(number, homepage, true); + newTab(number, homepage, true, false); tabScroll.postDelayed(new Runnable() { @Override public void run() { @@ -1632,7 +1739,7 @@ public class IncognitoMode extends Activity { @Override public void onClick(View arg0) { - if (pageIsLoading) { + if (main[pageId].getProgress() < 100) { main[pageId].stopLoading(); } else { main[pageId].reload(); @@ -1671,25 +1778,24 @@ public class IncognitoMode extends Activity { Intent url = getIntent(); String URL = url.getDataString(); if (URL != null) { - // opens a new tab with the url if its there - newTab(number, URL, true); + // opens a new tab with the URL if its there + newTab(number, URL, true, false); main[number - 1].resumeTimers(); } else { - // otherwise it opens the homepage - newTab(number, homepage, true); + // otherwise it opens the home-page + newTab(number, homepage, true, false); main[number - 1].resumeTimers(); } - } - public IncognitoWebView makeTab(final int pageToView, final String Url, + public IncognitoWebView makeTab(final int pageToView, String Url, final boolean display) { IncognitoWebView view = new IncognitoWebView(CONTEXT); view.setId(pageToView); allowLocation = settings.getBoolean("location", false); - view.setWebViewClient(new IncognitoWebViewClient()); + view.setWebViewClient(new CustomWebViewClient()); view.setWebChromeClient(new CustomChromeClient()); if (API > 8) { view.setDownloadListener(new CustomDownloadListener()); @@ -1700,14 +1806,13 @@ public class IncognitoMode extends Activity { agentPicker = settings.getInt("agentchoose", 1); switch (agentPicker) { case 1: - view.getSettings().setUserAgentString(mobile); + view.getSettings().setUserAgentString(defaultUser); break; case 2: view.getSettings().setUserAgentString(desktop); break; case 3: - userAgent = settings.getString("agent", user); - view.getSettings().setUserAgentString(userAgent); + view.getSettings().setUserAgentString(mobile); break; } if (display) { @@ -1720,11 +1825,11 @@ public class IncognitoMode extends Activity { if (Url.contains("about:home")) { goBookmarks(view); } else if (Url.contains("about:blank")) { - - view.loadUrl("about:blank"); - + view.loadUrl(""); } else { - + if (!Url.startsWith("http") && Url != "") { + Url = "http://" + Url; + } view.loadUrl(Url); } @@ -1733,19 +1838,19 @@ public class IncognitoMode extends Activity { } void newSettings() { - Intent set = new Intent(FinalVars.SETTINGS_INTENT); - startActivity(set); + startActivity(new Intent(FinalVariables.SETTINGS_INTENT)); } // new tab method, takes the id of the tab to be created and the url to load @SuppressWarnings("deprecation") - int newTab(int theId, final String theUrl, final boolean display) { + int newTab(int theId, final String theUrl, final boolean display, + final boolean incognito_mode) { Log.i("IncognitoMode", "making tab"); int finalID = 0; homepage = settings.getString("home", HOMEPAGE); allowLocation = settings.getBoolean("location", false); - boolean isEmptyWebViewAvailable = false; + boolean reuseWebView = false; for (int num = 0; num < number; num++) { if (urlTitle[num].getVisibility() == View.GONE) { @@ -1792,8 +1897,9 @@ public class IncognitoMode extends Activity { urlTitle[pageId].setBackground(inactive); } } - urlTitle[pageId].setCompoundDrawables(webpageOther, null, - exitTab, null); + 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; @@ -1805,11 +1911,11 @@ public class IncognitoMode extends Activity { main[num].onResume(); } - isEmptyWebViewAvailable = true; + reuseWebView = true; break; } } - if (!isEmptyWebViewAvailable) { + if (!reuseWebView) { if (number < MAX_TABS) { if (number > 0) { if (display) { @@ -1872,7 +1978,7 @@ public class IncognitoMode extends Activity { title.startAnimation(holo); urlTitle[number] = title; - urlTitle[number].setText("Incognito"); + urlTitle[number].setText("New Tab"); if (theUrl != null) { main[number] = makeTab(number, theUrl, display); @@ -1883,7 +1989,7 @@ public class IncognitoMode extends Activity { number = number + 1; } } - if (!isEmptyWebViewAvailable && number >= MAX_TABS) { + if (!reuseWebView && number >= MAX_TABS) { Toast.makeText(CONTEXT, "Maximum number of tabs reached...", Toast.LENGTH_SHORT).show(); } @@ -1908,26 +2014,32 @@ public class IncognitoMode extends Activity { @Override public void onBackPressed() { - if (main[pageId] != null) { + if (main[pageId] != null && main[pageId].canGoBack()) { main[pageId].stopLoading(); - + main[pageId].goBack(); if (showFullScreen && !uBar.isShown()) { uBar.startAnimation(slideDown); } - if (main[pageId].canGoBack()) { - main[pageId].goBack(); - } else { - deleteTab(pageId); - uBar.bringToFront(); - } + } else { + deleteTab(pageId); + uBar.bringToFront(); } } @Override public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); + // TODO + main[pageId].getSettings().setLayoutAlgorithm(LayoutAlgorithm.NORMAL); + if (settings.getBoolean("textreflow", false)) { + main[pageId].getSettings().setLayoutAlgorithm( + LayoutAlgorithm.NARROW_COLUMNS); + } else { + main[pageId].getSettings().setLayoutAlgorithm( + LayoutAlgorithm.NORMAL); + } + super.onConfigurationChanged(newConfig); } @Override @@ -1936,16 +2048,15 @@ public class IncognitoMode extends Activity { setContentView(R.layout.activity_main); // displays main xml layout settings = getSharedPreferences(preferences, 0); edit = settings.edit(); - CookieSyncManager.createInstance(CONTEXT); - cookieManager = CookieManager.getInstance(); - cookieManager.setAcceptCookie(false); + inactive = getResources().getDrawable(R.drawable.bg_inactive); active = getResources().getDrawable(R.drawable.bg_press); - init(); // sets up random stuff + initialize(); // sets up random stuff options(); // allows options to be opened enter();// enter url bar DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); + float widthInInches = metrics.widthPixels / metrics.xdpi; float heightInInches = metrics.heightPixels / metrics.ydpi; double sizeInInches = Math.sqrt(Math.pow(widthInInches, 2) @@ -1998,18 +2109,8 @@ public class IncognitoMode extends Activity { if (keyCode == KeyEvent.KEYCODE_BACK) { finish(); return true; - } - return super.onKeyLongPress(keyCode, event); - } - - @Override - protected void onNewIntent(Intent intent) { - - String url = intent.getDataString(); - if (url != null) { - newTab(number, url, true); - } - super.onNewIntent(intent); + } else + return super.onKeyLongPress(keyCode, event); } @Override @@ -2025,7 +2126,8 @@ public class IncognitoMode extends Activity { } return true; case R.id.incognito: - newTab(number, homepage, true); + newTab(number,homepage,true,true); + // newTab(number, homepage, true, true); return true; default: return false; @@ -2034,13 +2136,13 @@ public class IncognitoMode extends Activity { @Override protected void onPause() { + super.onPause(); if (main[pageId] != null) { if (API >= 11) { main[pageId].onPause(); } main[pageId].pauseTimers(); } - super.onPause(); } @Override @@ -2054,15 +2156,15 @@ public class IncognitoMode extends Activity { } void openBookmarks(IncognitoWebView view) { - String bookmarkHtml = BookmarkPage.Heading; + String bookmarkHtml = BookmarkPageVariables.Heading; for (int n = 0; n < MAX_BOOKMARKS; n++) { if (bUrl[n] != null) { - bookmarkHtml += (BookmarkPage.Part1 + bUrl[n] - + BookmarkPage.Part2 + bUrl[n] + BookmarkPage.Part3 - + bTitle[n] + BookmarkPage.Part4); + bookmarkHtml += (BookmarkPageVariables.Part1 + bUrl[n] + + BookmarkPageVariables.Part2 + bUrl[n] + + BookmarkPageVariables.Part3 + bTitle[n] + BookmarkPageVariables.Part4); } } - bookmarkHtml += BookmarkPage.End; + bookmarkHtml += BookmarkPageVariables.End; File bookmarkWebPage = new File(getBaseContext().getFilesDir(), "bookmarks.html"); try { @@ -2109,7 +2211,8 @@ public class IncognitoMode extends Activity { } return true; case R.id.incognito: - newTab(number, homepage, true); + newTab(number,homepage,true,true); + // newTab(number, homepage, true, true); return true; default: return false; @@ -2136,49 +2239,39 @@ public class IncognitoMode extends Activity { }); } - void share() { - Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); - - // set the type - shareIntent.setType("text/plain"); - - // add a subject - shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, - urlToLoad[pageId][1]); - - // build the body of the message to be shared - String shareMessage = urlToLoad[pageId][0]; - - // add the message - shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareMessage); - - // start the chooser for sharing - startActivity(Intent.createChooser(shareIntent, "Share this page")); - } - - void testForSearch() { - String fixedQuery = query.trim(); + void searchTheWeb(String query) { + query = query.trim(); main[pageId].stopLoading(); - boolean period = fixedQuery.contains("."); - - if (fixedQuery.contains("about:home") - || fixedQuery.contains("about:bookmarks")) { + + if(query.startsWith("www.")){ + query = "http://" + query; + } + else if(query.startsWith("ftp.")){ + query = "ftp://" + query; + } + + boolean containsPeriod = query.contains("."); + boolean isIPAddress = (TextUtils.isDigitsOnly(query.replace(".", ""))&&(query.replace(".", "").length()>=4)); + boolean aboutScheme = query.contains("about:"); + boolean validURL = (query.startsWith("ftp://")|| + query.startsWith("http://")|| + query.startsWith("file://")|| + query.startsWith("https://"))|| + isIPAddress; + boolean isSearch = ((query.contains(" ") || !containsPeriod) && !aboutScheme); + + if (query.contains("about:home") + || query.contains("about:bookmarks")) { goBookmarks(main[pageId]); - } else if (fixedQuery.contains("about:history")) { + } else if (query.contains("about:history")) { generateHistory(main[pageId]); - } else if (fixedQuery.contains(" ") || !period) { - fixedQuery.replaceAll(" ", "+"); - main[pageId].loadUrl(SEARCH + fixedQuery); - } else if (!fixedQuery.contains("http//") - && !fixedQuery.contains("https//") - && !fixedQuery.contains("http://") - && !fixedQuery.contains("https://")) { - fixedQuery = "http://" + fixedQuery; - main[pageId].loadUrl(fixedQuery); + } else if (isSearch) { + query.replaceAll(" ", "+"); + main[pageId].loadUrl(SEARCH + query); + } else if (!validURL) { + main[pageId].loadUrl("http://" + query); } else { - fixedQuery = fixedQuery.replaceAll("http//", "http://"); - fixedQuery = fixedQuery.replaceAll("https//", "https://"); - main[pageId].loadUrl(fixedQuery); + main[pageId].loadUrl(query); } } diff --git a/src/acr/browser/barebones/activities/SettingsActivity.java b/src/acr/browser/barebones/activities/SettingsActivity.java new file mode 100644 index 0000000..185e9c1 --- /dev/null +++ b/src/acr/browser/barebones/activities/SettingsActivity.java @@ -0,0 +1,684 @@ +package acr.browser.barebones.activities; + +import acr.browser.barebones.R; +import acr.browser.barebones.R.drawable; +import acr.browser.barebones.R.id; +import acr.browser.barebones.R.layout; +import acr.browser.barebones.variables.FinalVariables; +import android.net.Uri; +import android.os.Bundle; +import android.os.Environment; +import android.annotation.SuppressLint; +import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager.NameNotFoundException; +import android.util.Log; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.CompoundButton.OnCheckedChangeListener; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.RelativeLayout; +import android.widget.Switch; +import android.widget.TextView; +import android.widget.Toast; + +public class SettingsActivity extends Activity { + static int API = FinalVariables.API; + static final String preferences = "settings"; + static SharedPreferences.Editor edit; + static int agentChoice; + static String homepage; + static TextView agentText; + static TextView download; + static int egg = 0; + static String downloadLocation; + static TextView homepageText; + static SharedPreferences settings; + static TextView searchText; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.settings); + init(); + } + + @SuppressLint("NewApi") + public void init() { + // settings storage + settings = getSharedPreferences(preferences, 0); + edit = settings.edit(); + + // initialize UI + RelativeLayout layoutLocation = (RelativeLayout) findViewById(R.id.layoutLocation); + RelativeLayout layoutFullScreen = (RelativeLayout) findViewById(R.id.layoutFullScreen); + RelativeLayout layoutFlash = (RelativeLayout) findViewById(R.id.layoutFlash); + ImageView back = (ImageView) findViewById(R.id.back); + + searchText = (TextView) findViewById(R.id.searchText); + + switch (settings.getInt("search", 1)) { + case 1: + searchText.setText("Google"); + break; + case 2: + searchText.setText("Bing"); + break; + case 3: + searchText.setText("Yahoo"); + break; + case 4: + searchText.setText("StartPage"); + break; + case 5: + searchText.setText("DuckDuckGo"); + break; + } + + back.setBackgroundResource(R.drawable.button); + agentText = (TextView) findViewById(R.id.agentText); + homepageText = (TextView) findViewById(R.id.homepageText); + download = (TextView) findViewById(R.id.downloadText); + + boolean locationBool = settings.getBoolean("location", false); + int flashNum = settings.getInt("enableflash", 0); + boolean fullScreenBool = settings.getBoolean("fullscreen", false); + agentChoice = settings.getInt("agentchoose", 1); + homepage = settings.getString("home", FinalVariables.HOMEPAGE); + downloadLocation = settings.getString("download", + FinalVariables.DOWNLOAD_LOCATION); + + download.setText(downloadLocation); + + int code = 0; + + try { + PackageInfo p = getPackageManager().getPackageInfo( + getPackageName(), 0); + code = p.versionCode; + } catch (NameNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + TextView version = (TextView) findViewById(R.id.versionCode); + version.setText(code + ""); + + if (homepage.contains("about:home")) { + homepageText.setText("Bookmarks"); + } else if (homepage.contains("about:blank")) { + homepageText.setText("Blank Page"); + } else { + homepageText.setText(homepage); + } + + switch (agentChoice) { + case 1: + agentText.setText("Default"); + break; + case 2: + agentText.setText("Desktop"); + break; + case 3: + agentText.setText("Mobile"); + break; + } + RelativeLayout r1, r2, r3; + r1 = (RelativeLayout)findViewById(R.id.setR1); + r2 = (RelativeLayout)findViewById(R.id.setR2); + r3 = (RelativeLayout)findViewById(R.id.setR3); + if (API >= 14) { + Switch location = new Switch(this); + Switch fullScreen = new Switch(this); + Switch flash = new Switch(this); + + + r1.addView(location); + r2.addView(fullScreen); + r3.addView(flash); + location.setChecked(locationBool); + fullScreen.setChecked(fullScreenBool); + if (flashNum > 0) { + flash.setChecked(true); + } else { + flash.setChecked(false); + } + + initSwitch(location, fullScreen, flash); + clickListenerForSwitches( + layoutLocation, layoutFullScreen, layoutFlash, location, fullScreen, flash); + + } else { + CheckBox location = new CheckBox(this); + CheckBox fullScreen = new CheckBox(this); + CheckBox flash = new CheckBox(this); + + r1.addView(location); + r2.addView(fullScreen); + r3.addView(flash); + + location.setChecked(locationBool); + fullScreen.setChecked(fullScreenBool); + if (flashNum > 0) { + flash.setChecked(true); + } else { + flash.setChecked(false); + } + initCheckBox(location, fullScreen, flash); + clickListenerForCheckBoxes( + layoutLocation, layoutFullScreen, layoutFlash, location, fullScreen, flash); + } + + RelativeLayout agent = (RelativeLayout) findViewById(R.id.layoutUserAgent); + RelativeLayout download = (RelativeLayout) findViewById(R.id.layoutDownload); + RelativeLayout homepage = (RelativeLayout) findViewById(R.id.layoutHomepage); + RelativeLayout advanced = (RelativeLayout) findViewById(R.id.layoutAdvanced); + RelativeLayout source = (RelativeLayout) findViewById(R.id.layoutSource); + RelativeLayout license = (RelativeLayout) findViewById(R.id.layoutLicense); + + back(back); + agent(agent); + download(download); + homepage(homepage); + advanced(advanced); + source(source); + license(license); + search(); + easterEgg(); + } + + public void search(){ + RelativeLayout search = (RelativeLayout)findViewById(R.id.layoutSearch); + search.setOnClickListener(new OnClickListener(){ + + @Override + public void onClick(View v) { + AlertDialog.Builder picker = new AlertDialog.Builder( + SettingsActivity.this); + picker.setTitle("Search Engine"); + CharSequence[] chars = { "Google (Suggested)", "Bing", "Yahoo", "StartPage", "DuckDuckGo (Privacy)" }; + + int n = settings.getInt("search", 1); + + picker.setSingleChoiceItems(chars, n - 1, + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, + int which) { + edit.putInt("search", which+1); + edit.commit(); + switch (which+1) { + case 1: + searchText.setText("Google"); + break; + case 2: + searchText.setText("Bing"); + break; + case 3: + searchText.setText("Yahoo"); + break; + case 4: + searchText.setText("StartPage"); + break; + case 5: + searchText.setText("DuckDuckGo"); + break; + } + } + }); + picker.setNeutralButton("OK", + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, + int which) { + + } + }); + picker.show(); + } + + }); + } + + public void clickListenerForCheckBoxes( + RelativeLayout one, RelativeLayout two, RelativeLayout three, final CheckBox loc, + final CheckBox full, final CheckBox flash) { + one.setOnClickListener(new OnClickListener(){ + + @Override + public void onClick(View v) { + loc.setChecked(!loc.isChecked()); + } + + }); + two.setOnClickListener(new OnClickListener(){ + + @Override + public void onClick(View v) { + full.setChecked(!full.isChecked()); + } + + }); + three.setOnClickListener(new OnClickListener(){ + + @Override + public void onClick(View v) { + flash.setChecked(!flash.isChecked()); + } + + }); + } + + public void clickListenerForSwitches( + RelativeLayout one, RelativeLayout two, RelativeLayout three, final Switch loc, + final Switch full, final Switch flash) { + one.setOnClickListener(new OnClickListener(){ + + @Override + public void onClick(View v) { + loc.setChecked(!loc.isChecked()); + } + + }); + two.setOnClickListener(new OnClickListener(){ + + @Override + public void onClick(View v) { + full.setChecked(!full.isChecked()); + } + + }); + three.setOnClickListener(new OnClickListener(){ + + @Override + public void onClick(View v) { + flash.setChecked(!flash.isChecked()); + } + + }); + } + + public void easterEgg() { + RelativeLayout easter = (RelativeLayout) findViewById(R.id.layoutVersion); + easter.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + egg++; + if (egg == 10) { + Toast.makeText(SettingsActivity.this, "Almost There", + Toast.LENGTH_SHORT).show(); + } + if (egg == 15) { + Toast.makeText(SettingsActivity.this, "Easter Egg", + Toast.LENGTH_SHORT).show(); + egg = 0; + } + + } + + }); + } + + public void initSwitch(Switch location, Switch fullscreen, Switch flash) { + location.setOnCheckedChangeListener(new OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, + boolean isChecked) { + edit.putBoolean("location", isChecked); + edit.commit(); + + } + + }); + flash.setOnCheckedChangeListener(new OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, + boolean isChecked) { + int n = 0; + if (isChecked) { + n = 1; + } + edit.putInt("enableflash", n); + edit.commit(); + + } + + }); + fullscreen.setOnCheckedChangeListener(new OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, + boolean isChecked) { + edit.putBoolean("fullscreen", isChecked); + edit.commit(); + + } + + }); + } + + public void initCheckBox(CheckBox location, CheckBox fullscreen, CheckBox flash) { + location.setOnCheckedChangeListener(new OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, + boolean isChecked) { + edit.putBoolean("location", isChecked); + edit.commit(); + + } + + }); + flash.setOnCheckedChangeListener(new OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, + boolean isChecked) { + int n = 0; + if (isChecked) { + n = 1; + } + edit.putInt("enableflash", n); + edit.commit(); + + } + + }); + fullscreen.setOnCheckedChangeListener(new OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, + boolean isChecked) { + edit.putBoolean("fullscreen", isChecked); + edit.commit(); + + } + + }); + } + + public void back(ImageView view) { + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + finish(); + } + + }); + } + + public void agent(RelativeLayout view) { + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + AlertDialog.Builder agentPicker = new AlertDialog.Builder( + SettingsActivity.this); + agentPicker.setTitle("User Agent"); + CharSequence[] chars = { "Default", "Desktop", "Mobile" }; + agentChoice = settings.getInt("agentchoose", 1); + agentPicker.setSingleChoiceItems(chars, agentChoice - 1, + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, + int which) { + edit.putInt("agentchoose", which + 1); + edit.commit(); + switch (which + 1) { + case 1: + agentText.setText("Default"); + break; + case 2: + agentText.setText("Desktop"); + break; + case 3: + agentText.setText("Mobile"); + break; + } + } + }); + agentPicker.setNeutralButton("OK", + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, + int which) { + // TODO Auto-generated method stub + + } + + }); + agentPicker + .setOnCancelListener(new DialogInterface.OnCancelListener() { + + @Override + public void onCancel(DialogInterface dialog) { + // TODO Auto-generated method stub + Log.i("Cancelled", ""); + } + }); + agentPicker.show(); + + } + + }); + } + + public void download(RelativeLayout view) { + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + + AlertDialog.Builder picker = new AlertDialog.Builder( + SettingsActivity.this); + picker.setTitle("Download Location"); + CharSequence[] chars = { "Default", "Custom" }; + downloadLocation = settings.getString("download", + FinalVariables.DOWNLOAD_LOCATION); + int n = -1; + if (downloadLocation.contains(FinalVariables.DOWNLOAD_LOCATION)) { + n = 1; + } else { + n = 2; + } + + picker.setSingleChoiceItems(chars, n - 1, + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, + int which) { + + switch (which + 1) { + case 1: + edit.putString("download", + FinalVariables.DOWNLOAD_LOCATION); + edit.commit(); + download.setText(FinalVariables.DOWNLOAD_LOCATION); + break; + case 2: + downPicker(); + + break; + } + } + }); + picker.setNeutralButton("OK", + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, + int which) { + + } + }); + picker.show(); + } + + }); + } + + public void homePicker() { + final AlertDialog.Builder homePicker = new AlertDialog.Builder( + SettingsActivity.this); + homePicker.setTitle("Custom Homepage"); + final EditText getHome = new EditText(SettingsActivity.this); + homepage = settings.getString("home", FinalVariables.HOMEPAGE); + if (!homepage.startsWith("about:")) { + getHome.setText(homepage); + } else { + getHome.setText("http://www.google.com"); + } + homePicker.setView(getHome); + homePicker.setPositiveButton("OK", + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + String text = getHome.getText().toString(); + edit.putString("home", text); + edit.commit(); + homepageText.setText(text); + } + }); + homePicker.show(); + } + + public void downPicker() { + final AlertDialog.Builder downLocationPicker = new AlertDialog.Builder( + SettingsActivity.this); + downLocationPicker.setTitle("Custom Location"); + final EditText getDownload = new EditText(SettingsActivity.this); + downloadLocation = settings.getString("download", + FinalVariables.DOWNLOAD_LOCATION); + getDownload.setText(downloadLocation); + downLocationPicker.setView(getDownload); + downLocationPicker.setPositiveButton("OK", + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + String text = getDownload.getText().toString(); + edit.putString("download", text); + edit.commit(); + download.setText(text); + } + }); + downLocationPicker.show(); + } + + public void homepage(RelativeLayout view) { + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + AlertDialog.Builder picker = new AlertDialog.Builder( + SettingsActivity.this); + picker.setTitle("Homepage"); + CharSequence[] chars = { "Bookmarks", "Blank Page", "Webpage" }; + homepage = settings.getString("home", FinalVariables.HOMEPAGE); + int n = -1; + if (homepage.contains("about:home")) { + n = 1; + } else if (homepage.contains("about:blank")) { + n = 2; + } else { + n = 3; + } + + picker.setSingleChoiceItems(chars, n - 1, + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, + int which) { + + switch (which + 1) { + case 1: + edit.putString("home", "about:home"); + edit.commit(); + homepageText.setText("Bookmarks"); + break; + case 2: + edit.putString("home", "about:blank"); + edit.commit(); + homepageText.setText("Blank Page"); + break; + case 3: + homePicker(); + + break; + } + } + }); + picker.setNeutralButton("OK", + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, + int which) { + + } + }); + picker.show(); + } + + }); + } + + public void advanced(RelativeLayout view) { + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + startActivity(new Intent( + "android.intent.action.ADVANCEDSETTINGS")); + } + + }); + } + + public void source(RelativeLayout view) { + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + startActivity(new Intent( + Intent.ACTION_VIEW, + Uri.parse("https://github.com/anthonycr/Lightning-Browser"))); + finish(); + } + + }); + } + + public void license(RelativeLayout view) { + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + startActivity(new Intent(Intent.ACTION_VIEW, Uri + .parse("http://www.apache.org/licenses/LICENSE-2.0"))); + finish(); + } + + }); + } +} diff --git a/src/acr/browser/barebones/customwebview/CustomWebView.java b/src/acr/browser/barebones/customwebview/CustomWebView.java new file mode 100644 index 0000000..62ef0ef --- /dev/null +++ b/src/acr/browser/barebones/customwebview/CustomWebView.java @@ -0,0 +1,92 @@ +package acr.browser.barebones.customwebview; + +import java.lang.reflect.Method; +import acr.browser.barebones.activities.BarebonesActivity; +import acr.browser.barebones.variables.FinalVariables; +import android.content.Context; +import android.util.Log; +import android.view.MotionEvent; +import android.view.View; +import android.view.animation.Animation; +import android.webkit.WebView; +import android.widget.ZoomButtonsController; + +public final class CustomWebView extends WebView { + private float location; + private boolean first = false; + final int API = FinalVariables.API; + final boolean showFullScreen = BarebonesActivity.showFullScreen; + final View uBar = BarebonesActivity.uBar; + final Animation slideUp = BarebonesActivity.slideUp; + final Animation slideDown = BarebonesActivity.slideDown; + private ZoomButtonsController zoomControl; + private boolean zoomShouldDie = false; + + public CustomWebView(Context context) { + super(context); + this.setBackgroundResource(0); + + getControls(); + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + + if (zoomShouldDie) { + try { + zoomControl.getZoomControls().setVisibility(View.INVISIBLE); + } catch (IllegalArgumentException ignored) { + } + } + switch (event.getAction()) { + case MotionEvent.ACTION_DOWN: { + first = true; + if (API <= 10 && !this.hasFocus()) { + this.requestFocus(); + } + location = event.getY(); + break; + } + case MotionEvent.ACTION_UP: { + if (showFullScreen && first) { + if (uBar.isShown() && this.getScrollY() < 5) { + uBar.startAnimation(slideUp); + } else if (event.getY() > location && !uBar.isShown()) { + uBar.startAnimation(slideDown); + } else if (event.getY() < location && uBar.isShown()) { + uBar.startAnimation(slideUp); + } + first = false; + } + break; + } + } + + return super.onTouchEvent(event); + + } + + @Override + protected void onWindowVisibilityChanged(int visibility) { + if(API >= 11){ + this.setActivated(visibility == View.VISIBLE); + } + super.onWindowVisibilityChanged(visibility); + } + + private void getControls() { + if (API < 11) { + try { + Class webview = Class.forName("android.webkit.WebView"); + Method method = webview.getMethod("getZoomButtonsController"); + zoomControl = (ZoomButtonsController) method.invoke(this, (Object) null); + if (zoomControl != null) { + zoomShouldDie = true; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + +} diff --git a/src/acr/browser/barebones/customwebview/IncognitoWebView.java b/src/acr/browser/barebones/customwebview/IncognitoWebView.java new file mode 100644 index 0000000..e56b2f2 --- /dev/null +++ b/src/acr/browser/barebones/customwebview/IncognitoWebView.java @@ -0,0 +1,76 @@ +package acr.browser.barebones.customwebview; + +import java.lang.reflect.Method; + +import acr.browser.barebones.activities.IncognitoModeActivity; +import acr.browser.barebones.variables.FinalVariables; +import android.content.Context; +import android.view.MotionEvent; +import android.view.View; +import android.view.animation.Animation; +import android.webkit.WebView; +import android.widget.ZoomButtonsController; + +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.uBar; + final Animation slideUp = IncognitoModeActivity.slideUp; + final Animation slideDown = IncognitoModeActivity.slideDown; + private ZoomButtonsController zoomControl; + + public IncognitoWebView(Context context) { + super(context); + getControls(); + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + if (API < 11 && zoomControl != null) { + try { + zoomControl.getZoomControls().setVisibility(View.INVISIBLE); + } catch (IllegalArgumentException ignored) { + + } + } + switch (event.getAction()) { + case MotionEvent.ACTION_DOWN: { + first = true; + if (API <= 10 && !this.hasFocus()) { + this.requestFocus(); + } + location = event.getY(); + break; + } + case MotionEvent.ACTION_UP: { + if (showFullScreen && first) { + if (uBar.isShown() && this.getScrollY() < 5) { + uBar.startAnimation(slideUp); + } else if (event.getY() > location && !uBar.isShown()) { + uBar.startAnimation(slideDown); + } else if (event.getY() < location && uBar.isShown()) { + uBar.startAnimation(slideUp); + } + first = false; + } + break; + } + } + + return super.onTouchEvent(event); + } + + private void getControls() { + if (API < 11) { + try { + Class webview = Class.forName("android.webkit.WebView"); + Method method = webview.getMethod("getZoomButtonsController"); + zoomControl = (ZoomButtonsController) method.invoke(this, null); + } catch (Exception e) { + e.printStackTrace(); + } + } + } +} diff --git a/src/acr/browser/barebones/DatabaseHandler.java b/src/acr/browser/barebones/databases/DatabaseHandler.java similarity index 86% rename from src/acr/browser/barebones/DatabaseHandler.java rename to src/acr/browser/barebones/databases/DatabaseHandler.java index 522692d..c04543a 100644 --- a/src/acr/browser/barebones/DatabaseHandler.java +++ b/src/acr/browser/barebones/databases/DatabaseHandler.java @@ -1,4 +1,4 @@ -package acr.browser.barebones; +package acr.browser.barebones.databases; import java.util.ArrayList; import java.util.List; @@ -9,7 +9,7 @@ import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; -class DatabaseHandler extends SQLiteOpenHelper { +public class DatabaseHandler extends SQLiteOpenHelper { // All Static variables // Database Version @@ -52,9 +52,14 @@ class DatabaseHandler extends SQLiteOpenHelper { /** * All CRUD(Create, Read, Update, Delete) Operations */ + + public void delete(String url){ + String n = getHistoryItem(url); + deleteHistoryItem(n); + } // Adding new item - void addHistoryItem(HistoryItem item) { + public void addHistoryItem(HistoryItem item) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); @@ -66,19 +71,18 @@ class DatabaseHandler extends SQLiteOpenHelper { } // Getting single item - HistoryItem getHistoryItem(int id) { + String getHistoryItem(String url) { SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.query(TABLE_HISTORY, new String[] { KEY_ID, - KEY_URL, KEY_TITLE}, KEY_ID + "=?", - new String[] { String.valueOf(id) }, null, null, null, null); + KEY_URL, KEY_TITLE}, KEY_URL + "=?", + new String[] { url }, null, null, null, null); if (cursor != null) cursor.moveToFirst(); - - + String m = cursor.getString(0); + cursor.close(); // return item - return new HistoryItem(Integer.parseInt(cursor.getString(0)), - cursor.getString(1), cursor.getString(2)); + return m; } // Getting All HistoryItems @@ -101,7 +105,7 @@ class DatabaseHandler extends SQLiteOpenHelper { itemList.add(item); } while (cursor.moveToNext()); } - + cursor.close(); // return item list return itemList; } @@ -120,10 +124,10 @@ class DatabaseHandler extends SQLiteOpenHelper { } // Deleting single item - public void deleteHistoryItem(HistoryItem item) { + public void deleteHistoryItem(String id) { SQLiteDatabase db = this.getWritableDatabase(); db.delete(TABLE_HISTORY, KEY_ID + " = ?", - new String[] { String.valueOf(item.getID()) }); + new String[] { String.valueOf(id) }); db.close(); } diff --git a/src/acr/browser/barebones/HistoryItem.java b/src/acr/browser/barebones/databases/HistoryItem.java similarity index 92% rename from src/acr/browser/barebones/HistoryItem.java rename to src/acr/browser/barebones/databases/HistoryItem.java index e7120b5..03ef83b 100644 --- a/src/acr/browser/barebones/HistoryItem.java +++ b/src/acr/browser/barebones/databases/HistoryItem.java @@ -1,6 +1,6 @@ -package acr.browser.barebones; +package acr.browser.barebones.databases; -class HistoryItem { +public class HistoryItem { //private variables diff --git a/src/acr/browser/barebones/SpaceTokenizer.java b/src/acr/browser/barebones/databases/SpaceTokenizer.java similarity index 82% rename from src/acr/browser/barebones/SpaceTokenizer.java rename to src/acr/browser/barebones/databases/SpaceTokenizer.java index f738956..a5cc3ea 100644 --- a/src/acr/browser/barebones/SpaceTokenizer.java +++ b/src/acr/browser/barebones/databases/SpaceTokenizer.java @@ -1,16 +1,13 @@ -package acr.browser.barebones; +package acr.browser.barebones.databases; -import android.text.SpannableString; -import android.text.Spanned; -import android.text.TextUtils; import android.widget.MultiAutoCompleteTextView.Tokenizer; public class SpaceTokenizer implements Tokenizer { @Override public int findTokenEnd(CharSequence text, int cursor) { - int i = cursor; - int len = text.length(); + //int i = cursor; + //int len = text.length(); /*while (i < len) { if (text.charAt(i) == ' ') { @@ -20,7 +17,7 @@ public class SpaceTokenizer implements Tokenizer { } } */ - return len; + return text.length(); } @Override @@ -39,7 +36,10 @@ public class SpaceTokenizer implements Tokenizer { @Override public CharSequence terminateToken(CharSequence text) { - int i = text.length(); + //int i = text.length(); + if(text.charAt(text.length()-1) != ' '){ + text = text + " "; + } return text; /*while (i > 0 && text.charAt(i - 1) == ' ') { i--; diff --git a/src/acr/browser/barebones/BookmarkPage.java b/src/acr/browser/barebones/variables/BookmarkPageVariables.java similarity index 70% rename from src/acr/browser/barebones/BookmarkPage.java rename to src/acr/browser/barebones/variables/BookmarkPageVariables.java index 92688d0..5dd24d9 100644 --- a/src/acr/browser/barebones/BookmarkPage.java +++ b/src/acr/browser/barebones/variables/BookmarkPageVariables.java @@ -1,23 +1,23 @@ -package acr.browser.barebones; +package acr.browser.barebones.variables; -class BookmarkPage { +public class BookmarkPageVariables { public static final String Heading = "" + "" + "Bookmarks"; public static final String Part1 = "
" + "
" + "

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

"; public static final String End = ""; diff --git a/src/acr/browser/barebones/FinalVars.java b/src/acr/browser/barebones/variables/FinalVariables.java similarity index 56% rename from src/acr/browser/barebones/FinalVars.java rename to src/acr/browser/barebones/variables/FinalVariables.java index 8365f08..00148d0 100644 --- a/src/acr/browser/barebones/FinalVars.java +++ b/src/acr/browser/barebones/variables/FinalVariables.java @@ -1,21 +1,25 @@ -package acr.browser.barebones; +package acr.browser.barebones.variables; +import android.os.Environment; -class FinalVars { + +public class FinalVariables { public static final int MAX_TABS = 5; - public static final int MAX_BOOKMARKS = 5; + public static final int MAX_BOOKMARKS = 50; public static final boolean PAID_VERSION = false; public static final String DESKTOP_USER_AGENT = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/20 Safari/537.17"; + public static final String MOBILE_USER_AGENT = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7"; public static final int API = android.os.Build.VERSION.SDK_INT; - public static final String YAHOO_SEARCH = "search.yahoo.com/search?p="; + public static final String YAHOO_SEARCH = "http://search.yahoo.com/search?p="; public static final String GOOGLE_SEARCH = "https://www.google.com/search?client=lightning&q="; - public static final String BING_SEARCH = "www.bing.com/search?q="; + public static final String BING_SEARCH = "http://www.bing.com/search?q="; public static final String DUCK_SEARCH = "https://duckduckgo.com/?t=lightning&q="; public static final String STARTPAGE_SEARCH = "https://startpage.com/do/metasearch.pl?language=english&cat=web&query="; public static final String HOMEPAGE = "https://www.google.com/"; - public static final String SETTINGS_INTENT = "android.intent.action.BAREBONESSETTINGS"; + public static final String SETTINGS_INTENT = "android.intent.action.SETTINGS"; public static final String INCOGNITO_INTENT = "android.intent.action.BAREBONESINCOGNITO"; + public static final String DOWNLOAD_LOCATION = Environment.getExternalStorageDirectory().toString()+Environment.DIRECTORY_DOWNLOADS; diff --git a/src/acr/browser/barebones/HistoryPage.java b/src/acr/browser/barebones/variables/HistoryPageVariables.java similarity index 65% rename from src/acr/browser/barebones/HistoryPage.java rename to src/acr/browser/barebones/variables/HistoryPageVariables.java index 23dc5de..7cd1759 100644 --- a/src/acr/browser/barebones/HistoryPage.java +++ b/src/acr/browser/barebones/variables/HistoryPageVariables.java @@ -1,12 +1,13 @@ -package acr.browser.barebones; +package acr.browser.barebones.variables; -public class HistoryPage { +public class HistoryPageVariables { public static final String Heading = "" + "History"; diff --git a/src/acr/browser/barebones/variables/Utils.java b/src/acr/browser/barebones/variables/Utils.java new file mode 100644 index 0000000..0b02460 --- /dev/null +++ b/src/acr/browser/barebones/variables/Utils.java @@ -0,0 +1,174 @@ +package acr.browser.barebones.variables; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +import acr.browser.barebones.databases.DatabaseHandler; +import acr.browser.barebones.databases.HistoryItem; +import android.annotation.SuppressLint; +import android.annotation.TargetApi; +import android.app.AlertDialog; +import android.app.DownloadManager; +import android.content.ContentResolver; +import android.content.Context; +import android.content.DialogInterface; +import android.database.Cursor; +import android.database.DatabaseUtils; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteException; +import android.net.Uri; +import android.os.Build; +import android.os.Environment; +import android.provider.Browser; +import android.util.Log; +import android.webkit.URLUtil; +import android.widget.Toast; + +public class Utils { + public static void createInformativeDialog(Context context, String title, + String message) { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(title); + builder.setMessage(message) + .setCancelable(true) + .setPositiveButton("Ok", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + } + }); + AlertDialog alert = builder.create(); + alert.show(); + } + + public static void addBookmark(Context context, String title, String url) { + File book = new File(context.getFilesDir(), "bookmarks"); + File bookUrl = new File(context.getFilesDir(), "bookurl"); + try { + BufferedReader readUrlRead = new BufferedReader(new FileReader( + bookUrl)); + String u; + int n = 0; + while ((u = readUrlRead.readLine()) != null + && n < FinalVariables.MAX_BOOKMARKS) { + if (u.contentEquals(url)) { + readUrlRead.close(); + return; + } + n++; + } + readUrlRead.close(); + + } catch (FileNotFoundException ignored) { + } catch (IOException ignored) { + } catch (NullPointerException ignored) { + } + try { + BufferedWriter bookWriter = new BufferedWriter(new FileWriter(book, + true)); + BufferedWriter urlWriter = new BufferedWriter(new FileWriter( + bookUrl, true)); + bookWriter.write(title); + urlWriter.write(url); + bookWriter.newLine(); + urlWriter.newLine(); + bookWriter.close(); + urlWriter.close(); + } catch (FileNotFoundException ignored) { + } catch (IOException ignored) { + } catch (NullPointerException ignored) { + } + } + + public static void updateHistory(final Context context, + final ContentResolver content, final boolean noStockBrowser, + final String url, final String title) { + Runnable update = new Runnable() { + @Override + public void run() { + if (!noStockBrowser) { + try { + Browser.updateVisitedHistory(content, url, true); + } catch (NullPointerException ignored) { + } + } + try { + StringBuilder sb = new StringBuilder("url" + " = "); + DatabaseUtils.appendEscapedSQLString(sb, url); + DatabaseHandler historyHandler = new DatabaseHandler( + context); + SQLiteDatabase history = historyHandler.getReadableDatabase(); + Cursor cursor = history.query("history", new String[] { "id", + "url", "title" }, sb.toString(), null, null, null, + null); + if (!cursor.moveToFirst()) { + historyHandler.addHistoryItem(new HistoryItem(url, + title)); + } else { + historyHandler.delete(url); + historyHandler.addHistoryItem(new HistoryItem(url, + title)); + } + historyHandler.close(); + cursor.close(); + history.close(); + } catch (IllegalStateException e) { + Log.e("Barebones", "IllegalStateException in updateHistory"); + } catch (NullPointerException e) { + Log.e("Barebones", "NullPointerException in updateHistory"); + } catch (SQLiteException e) { + Log.e("Barebones", "SQLiteException in updateHistory"); + } + } + }; + if (url != null) { + if (!url.startsWith("file://")) { + new Thread(update).start(); + } + } + } + + @TargetApi(Build.VERSION_CODES.GINGERBREAD) + public static void downloadFile(final Context context, final String url, final String contentDisposition, final String mimetype){ + try { + Thread downloader = new Thread(new Runnable() { + @SuppressLint("InlinedApi") + @Override + public void run() { + DownloadManager download = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); + Uri nice = Uri.parse(url); + DownloadManager.Request it = new DownloadManager.Request( + nice); + String fileName = URLUtil.guessFileName(url, + contentDisposition, mimetype); + if (FinalVariables.API >= 11) { + it.allowScanningByMediaScanner(); + it.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); + } + + it.setDestinationInExternalPublicDir( + Environment.DIRECTORY_DOWNLOADS, fileName); + Log.i("Barebones", "Downloading" + fileName); + download.enqueue(it); + } + }); + downloader.run(); + } catch (NullPointerException e) { + Log.e("Barebones", "Problem downloading"); + Toast.makeText(context, "Error Downloading File", + Toast.LENGTH_SHORT).show(); + } catch (IllegalArgumentException e) { + Log.e("Barebones", "Problem downloading"); + Toast.makeText(context, "Error Downloading File", + Toast.LENGTH_SHORT).show(); + } catch (SecurityException ignored) { + + } + } + +}