Browse Source

2.3.10

- fixed all issues with rendering, performance has increased
dramatically on not-fullscreen and has increased a little in fullscreen
- battery life improved as a result
- added hebrew language
- changed the way history works (now uses SQLite database, it's way
better than the android.provider.Browser way)
- fixed a couple crashes related to bookmarks and downloads
- formatted the code a little better (thanks to Aeefire for the tips,
just know I'm taking your advice LOL)
master
Anthony Restaino 12 years ago
parent
commit
c68e856741
  1. 5
      AndroidManifest.xml
  2. BIN
      res/drawable-xhdpi/spinner.png
  3. 24
      res/drawable/ginger_animation.xml
  4. 26
      res/drawable/ics_animation.xml
  5. 10
      res/layout/activity_main.xml
  6. 77
      src/acr/browser/barebones/AnthonyWebView.java
  7. 347
      src/acr/browser/barebones/Barebones.java
  8. 141
      src/acr/browser/barebones/DatabaseHandler.java
  9. 57
      src/acr/browser/barebones/HistoryItem.java

5
AndroidManifest.xml

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="acr.browser.barebones" package="acr.browser.barebones"
android:versionCode="30" android:versionCode="32"
android:versionName="2.3.7" > android:versionName="2.3.9" >
<uses-sdk <uses-sdk
android:minSdkVersion="8" android:minSdkVersion="8"
@ -26,6 +26,7 @@
android:launchMode="singleTask" android:launchMode="singleTask"
android:allowTaskReparenting="true" android:allowTaskReparenting="true"
android:multiprocess="false" android:multiprocess="false"
android:hardwareAccelerated="true"
> >
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />

BIN
res/drawable-xhdpi/spinner.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

24
res/drawable/ginger_animation.xml

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2009, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/spinner"
android:pivotX="50%"
android:pivotY="50%"
/>

26
res/drawable/ics_animation.xml

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2010, The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<rotate
android:drawable="@drawable/spinner"
android:fromDegrees="720"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="0" />
</item>
</layer-list>

10
res/layout/activity_main.xml

@ -109,6 +109,16 @@
android:paddingRight="10dp" android:paddingRight="10dp"
android:paddingTop="10dp" android:paddingTop="10dp"
android:src="@drawable/refresh" /> android:src="@drawable/refresh" />
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminate="true"
/>
</RelativeLayout> </RelativeLayout>
<MultiAutoCompleteTextView <MultiAutoCompleteTextView

77
src/acr/browser/barebones/AnthonyWebView.java

@ -0,0 +1,77 @@
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 = Barebones.API;
long timeBetweenDownPress = 0;
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: {
move = false;
if (API <= 10 && !Barebones.main[Barebones.pageId].hasFocus()) {
Barebones.main[Barebones.pageId].requestFocus();
}
timeBetweenDownPress = System.currentTimeMillis();
break;
}
case MotionEvent.ACTION_MOVE: {
move = true;
}
case MotionEvent.ACTION_UP: {
try {
hitTest = getHitTestResult().getType();
} catch (NullPointerException e) {
}
if (showFullScreen && hitTest != 9) {
if (System.currentTimeMillis() - timeBetweenDownPress < 500
&& !move) {
if (!uBarShows) {
uBar.startAnimation(slideDown);
uBarShows = true;
} else if (uBarShows) {
uBar.startAnimation(slideUp);
uBarShows = false;
}
break;
} else if (Barebones.main[Barebones.pageId].getScrollY() > 5 && uBarShows) {
uBar.startAnimation(slideUp);
uBarShows = false;
break;
} else if (Barebones.main[Barebones.pageId].getScrollY() < 5 && !uBarShows) {
uBar.startAnimation(slideDown);
uBarShows = true;
break;
}
}
}
default:
break;
}
return super.onTouchEvent(event);
}
}

347
src/acr/browser/barebones/Barebones.java

@ -15,15 +15,17 @@ import java.util.Map;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.DownloadManager; import android.app.DownloadManager;
import android.content.ActivityNotFoundException;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.ComponentName;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.database.Cursor; import android.database.Cursor;
import android.database.DatabaseUtils; import android.database.DatabaseUtils;
@ -40,16 +42,13 @@ import android.net.http.SslError;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.os.Handler; import android.os.Handler;
import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.provider.Browser; import android.provider.Browser;
import android.provider.Browser.BookmarkColumns;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.view.Display;
import android.view.Gravity; import android.view.Gravity;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -73,6 +72,7 @@ import android.webkit.DownloadListener;
import android.webkit.GeolocationPermissions; import android.webkit.GeolocationPermissions;
import android.webkit.HttpAuthHandler; import android.webkit.HttpAuthHandler;
import android.webkit.SslErrorHandler; import android.webkit.SslErrorHandler;
import android.webkit.URLUtil;
import android.webkit.ValueCallback; import android.webkit.ValueCallback;
import android.webkit.WebChromeClient; import android.webkit.WebChromeClient;
import android.webkit.WebSettings; import android.webkit.WebSettings;
@ -94,7 +94,6 @@ import android.widget.LinearLayout;
import android.widget.MultiAutoCompleteTextView.Tokenizer; import android.widget.MultiAutoCompleteTextView.Tokenizer;
import android.widget.PopupMenu; import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener; import android.widget.PopupMenu.OnMenuItemClickListener;
import android.widget.PopupWindow;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.ScrollView; import android.widget.ScrollView;
@ -168,7 +167,6 @@ public class Barebones extends Activity implements OnLongClickListener,
static HorizontalScrollView tabScroll; static HorizontalScrollView tabScroll;
static Animation slideUp; static Animation slideUp;
static Animation slideDown; static Animation slideDown;
static Animation anim;
static Animation fadeOut, fadeIn; static Animation fadeOut, fadeIn;
static long clock = 0; static long clock = 0;
static long timeBetweenDownPress = System.currentTimeMillis(); static long timeBetweenDownPress = System.currentTimeMillis();
@ -178,6 +176,7 @@ public class Barebones extends Activity implements OnLongClickListener,
static List<Map<String, String>> list; static List<Map<String, String>> list;
static Map<String, String> map; static Map<String, String> map;
static Handler handler; static Handler handler;
static DatabaseHandler historyHandler;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -230,7 +229,17 @@ public class Barebones extends Activity implements OnLongClickListener,
public void init() { public void init() {
DisplayMetrics metrics = new DisplayMetrics(); DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics); getWindowManager().getDefaultDisplay().getMetrics(metrics);
historyHandler = new DatabaseHandler(this);
API = Integer.valueOf(android.os.Build.VERSION.SDK_INT); // gets the sdk
// level
progressBar = (ProgressBar) findViewById(R.id.progressBar1);
if (API >= 11) {
progressBar.setIndeterminateDrawable(getResources().getDrawable(
R.drawable.ics_animation));
} else {
progressBar.setIndeterminateDrawable(getResources().getDrawable(
R.drawable.ginger_animation));
}
showFullScreen = settings.getBoolean("fullscreen", false); showFullScreen = settings.getBoolean("fullscreen", false);
uBar = (RelativeLayout) findViewById(R.id.urlBar); uBar = (RelativeLayout) findViewById(R.id.urlBar);
bg = (RelativeLayout) findViewById(R.id.background); bg = (RelativeLayout) findViewById(R.id.background);
@ -282,7 +291,6 @@ public class Barebones extends Activity implements OnLongClickListener,
barLayout = (RelativeLayout) findViewById(R.id.relativeLayout1); barLayout = (RelativeLayout) findViewById(R.id.relativeLayout1);
refreshLayout = (RelativeLayout) findViewById(R.id.refreshLayout); refreshLayout = (RelativeLayout) findViewById(R.id.refreshLayout);
refreshLayout.setBackgroundResource(R.drawable.button); refreshLayout.setBackgroundResource(R.drawable.button);
anim = AnimationUtils.loadAnimation(Barebones.this, R.anim.rotate);
// get settings // get settings
WebView test = new WebView(Barebones.this); // getting default webview WebView test = new WebView(Barebones.this); // getting default webview
// user agent // user agent
@ -299,8 +307,7 @@ public class Barebones extends Activity implements OnLongClickListener,
// stored // stored
// homepage // homepage
// variable // variable
API = Integer.valueOf(android.os.Build.VERSION.SDK_INT); // gets the sdk
// level
test.destroy(); test.destroy();
userAgent = settings.getString("agent", mobile); // initializing userAgent = settings.getString("agent", mobile); // initializing
// useragent string // useragent string
@ -407,7 +414,6 @@ public class Barebones extends Activity implements OnLongClickListener,
}); });
enterUrl(); enterUrl();
updateUI();
if (showFullScreen) { if (showFullScreen) {
bg.removeView(uBar); bg.removeView(uBar);
background.addView(uBar); background.addView(uBar);
@ -415,30 +421,6 @@ public class Barebones extends Activity implements OnLongClickListener,
} }
public static void updateUI() {
clock = System.currentTimeMillis();
Thread uiUpdate = new Thread(new Runnable() {
@Override
public void run() {
long clock = System.currentTimeMillis();
while (true) {
while (!(System.currentTimeMillis() - clock > 20 && pageIdIsVisible))
;
main[pageId].postInvalidate();
clock = System.currentTimeMillis();
}
}
});
if (API == 17 && !showFullScreen) {
pageIdIsVisible = true;
uiUpdate.setDaemon(true);
uiUpdate.setPriority(Thread.MIN_PRIORITY);
// uiUpdate.start();
}
}
public class SpaceTokenizer implements Tokenizer { public class SpaceTokenizer implements Tokenizer {
public int findTokenStart(CharSequence text, int cursor) { public int findTokenStart(CharSequence text, int cursor) {
@ -525,23 +507,21 @@ public class Barebones extends Activity implements OnLongClickListener,
@Override @Override
public void run() { public void run() {
bookmarks = Browser.BOOKMARKS_URI; // bookmarks = Browser.BOOKMARKS_URI;
columns = new String[] { Browser.BookmarkColumns.URL, columns = new String[] { "url", "title" };
Browser.BookmarkColumns.TITLE };
try { try {
managedCursor = null; managedCursor = null;
managedCursor = getContentResolver().query(bookmarks, // URI SQLiteDatabase s = historyHandler.getReadableDatabase();
// of managedCursor = s.query("history", // URI
// of
columns, // Which columns to return columns, // Which columns to return
null, // Which rows to return (all rows) null, // Which rows to return (all rows)
null, // Selection arguments (none) null, // Selection arguments (none)
null); null, null, null);
Log.i("Barebones: ", "SQLite success!!!");
handler.sendEmptyMessage(1); handler.sendEmptyMessage(1);
Log.i("Barebones: ", "SQLite success!!!");
} catch (SQLiteException e) { } catch (SQLiteException e) {
handler.sendEmptyMessage(2); handler.sendEmptyMessage(2);
@ -557,10 +537,8 @@ public class Barebones extends Activity implements OnLongClickListener,
// Variable for holding the retrieved URL // Variable for holding the retrieved URL
urlColumn = managedCursor urlColumn = managedCursor.getColumnIndex("url");
.getColumnIndex(Browser.BookmarkColumns.URL); titleColumn = managedCursor.getColumnIndex("title");
titleColumn = managedCursor
.getColumnIndex(Browser.BookmarkColumns.TITLE);
// Reference to the the column containing the URL // Reference to the the column containing the URL
do { do {
urlA = managedCursor.getString(urlColumn); urlA = managedCursor.getString(urlColumn);
@ -587,25 +565,25 @@ public class Barebones extends Activity implements OnLongClickListener,
@Override @Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) { long arg3) {
try{ try {
txt = (TextView) arg1.findViewById(R.id.url); txt = (TextView) arg1.findViewById(R.id.url);
str = txt.getText().toString(); str = txt.getText().toString();
if (!pageIdIsVisible && isBookmarkShowing) { if (!pageIdIsVisible && isBookmarkShowing) {
scrollBookmarks.startAnimation(fadeOut); scrollBookmarks.startAnimation(fadeOut);
background.removeView(scrollBookmarks); background.removeView(scrollBookmarks);
background.addView(main[pageId]); background.addView(main[pageId]);
pageIdIsVisible = true; pageIdIsVisible = true;
isBookmarkShowing = false; isBookmarkShowing = false;
} }
main[pageId].loadUrl(str); main[pageId].loadUrl(str);
getUrl.setText(str); getUrl.setText(str);
getUrl.setPadding(tenPad, 0, tenPad, 0); getUrl.setPadding(tenPad, 0, tenPad, 0);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0); imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0);
} } catch (NullPointerException e) {
catch(NullPointerException e){
Log.e("Barebones Error: ","NullPointerException on item click"); Log.e("Barebones Error: ",
"NullPointerException on item click");
} }
} }
@ -790,9 +768,10 @@ public class Barebones extends Activity implements OnLongClickListener,
@Override @Override
public void onConfigurationChanged(Configuration newConfig) { public void onConfigurationChanged(Configuration newConfig) {
main[pageId].invalidate();
main[pageId].getSettings().setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
main[pageId].getSettings().setLayoutAlgorithm(
LayoutAlgorithm.NARROW_COLUMNS);
main[pageId].invalidate();
} }
public void makeTab(final int pageToView, String Url) { public void makeTab(final int pageToView, String Url) {
@ -807,7 +786,7 @@ public class Barebones extends Activity implements OnLongClickListener,
main[pageToView].setDownloadListener(new AnthonyDownload()); main[pageToView].setDownloadListener(new AnthonyDownload());
} }
main[pageToView].requestFocus(); main[pageToView].requestFocus();
main[pageToView].setFocusable(true); // main[pageToView].setFocusable(true);
main[pageToView].setOnLongClickListener(new OnLongClickListener() { main[pageToView].setOnLongClickListener(new OnLongClickListener() {
@Override @Override
@ -976,75 +955,6 @@ public class Barebones extends Activity implements OnLongClickListener,
} }
public static final class AnthonyWebView extends WebView {
public AnthonyWebView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
if (!showFullScreen) {
main[pageId].invalidate();
}
super.onDraw(canvas);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// final HitTestResult poop;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
move = false;
if (API <= 10 && !main[pageId].hasFocus()) {
main[pageId].requestFocus();
}
timeBetweenDownPress = System.currentTimeMillis();
break;
}
case MotionEvent.ACTION_MOVE: {
move = true;
}
case MotionEvent.ACTION_UP: {
try {
hitTest = getHitTestResult().getType();
} catch (NullPointerException e) {
}
if (showFullScreen && hitTest != 9) {
if (System.currentTimeMillis() - timeBetweenDownPress < 500
&& !move) {
if (!uBarShows) {
uBar.startAnimation(slideDown);
uBarShows = true;
} else if (uBarShows) {
uBar.startAnimation(slideUp);
uBarShows = false;
}
break;
} else if (main[pageId].getScrollY() > 5 && uBarShows) {
uBar.startAnimation(slideUp);
uBarShows = false;
break;
} else if (main[pageId].getScrollY() < 5 && !uBarShows) {
uBar.startAnimation(slideDown);
uBarShows = true;
break;
}
}
}
default:
break;
}
return super.onTouchEvent(event);
}
}
private class AnthonyWebViewClient extends WebViewClient { private class AnthonyWebViewClient extends WebViewClient {
@Override @Override
@ -1098,8 +1008,9 @@ public class Barebones extends Activity implements OnLongClickListener,
int num = view.getId(); int num = view.getId();
pageIsLoading = true; pageIsLoading = true;
refresh.startAnimation(anim);
getUrl.setText(url); getUrl.setText(url);
refresh.setVisibility(View.INVISIBLE);
progressBar.setVisibility(View.VISIBLE);
getUrl.setPadding(tenPad, 0, tenPad, 0); getUrl.setPadding(tenPad, 0, tenPad, 0);
urlToLoad[num][0] = url; urlToLoad[num][0] = url;
urlTitle[num].setCompoundDrawables(webpageOther, null, exitTab, urlTitle[num].setCompoundDrawables(webpageOther, null, exitTab,
@ -1113,21 +1024,20 @@ public class Barebones extends Activity implements OnLongClickListener,
@Override @Override
public void onPageFinished(WebView view, final String url) { public void onPageFinished(WebView view, final String url) {
progressBar.setVisibility(View.GONE);
refresh.setVisibility(View.VISIBLE);
if (!noStockBrowser) { if (!noStockBrowser) {
Thread history = new Thread(new Runnable() { Thread history = new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
Browser.updateVisitedHistory(getContentResolver(), url, Browser.updateVisitedHistory(getContentResolver(), url,
true); true);
// Log.i("Barebones",view.getTitle()+" "+url);
} }
}); });
history.start(); history.start();
} }
pageIsLoading = false; pageIsLoading = false;
anim.cancel();
anim.reset();
} }
} }
@ -1137,15 +1047,61 @@ public class Barebones extends Activity implements OnLongClickListener,
@Override @Override
public void onDownloadStart(String url, String userAgent, public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype, long contentLength) { String contentDisposition, String mimetype, long contentLength) {
DownloadManager download = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); if (contentDisposition == null
Uri nice = Uri.parse(url); || !contentDisposition.regionMatches(
DownloadManager.Request it = new DownloadManager.Request(nice); true, 0, "attachment", 0, 10)) {
String fileName = url.substring(url.lastIndexOf('/') + 1, // query the package manager to see if there's a registered handler
url.length()); // that matches.
it.setDestinationInExternalPublicDir( Intent intent = new Intent(Intent.ACTION_VIEW);
Environment.DIRECTORY_DOWNLOADS, fileName); intent.setDataAndType(Uri.parse(url), mimetype);
Log.i("Barebones", "Downloading" + fileName); ResolveInfo info = getPackageManager().resolveActivity(intent,
download.enqueue(it); PackageManager.MATCH_DEFAULT_ONLY);
if (info != null) {
ComponentName myName = getComponentName();
// If we resolved to ourselves, we don't want to attempt to
// load the url only to try and download it again.
if (!myName.getPackageName().equals(
info.activityInfo.packageName)
|| !myName.getClassName().equals(
info.activityInfo.name)) {
// someone (other than us) knows how to handle this mime
// type with this scheme, don't download.
try {
startActivity(intent);
return;
} catch (ActivityNotFoundException ex) {
Log.d("Barebones", "activity not found for " + mimetype
+ " over " + Uri.parse(url).getScheme(),
ex);
// Best behavior is to fall back to a download in this
// case
try {
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);
it.setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOWNLOADS, fileName);
Log.i("Barebones", "Downloading" + fileName);
download.enqueue(it);
} catch (NullPointerException e) {
Log.e("Barebones", "Problem downloading");
Toast.makeText(Barebones.this, "Error Downloading File",
Toast.LENGTH_SHORT).show();
}
catch (IllegalArgumentException e){
Log.e("Barebones", "Problem downloading");
Toast.makeText(Barebones.this, "Error Downloading File",
Toast.LENGTH_SHORT).show();
}
}
}
}
}
} }
} }
@ -1257,11 +1213,36 @@ public class Barebones extends Activity implements OnLongClickListener,
} }
@Override @Override
public void onReceivedTitle(WebView view, String title) { public void onReceivedTitle(final WebView view, final String title) {
int num = view.getId(); int num = view.getId();
urlTitle[num].setText(title); urlTitle[num].setText(title);
urlToLoad[num][1] = title; urlToLoad[num][1] = title;
Thread up = new Thread(new Runnable() {
@Override
public void run() {
try {
StringBuilder sb = new StringBuilder("url" + " = ");
DatabaseUtils.appendEscapedSQLString(sb, view.getUrl());
SQLiteDatabase s = historyHandler.getReadableDatabase();
Cursor c = s.query("history", new String[] { "id",
"url", "title" }, sb.toString(), null, null,
null, null);
if (c.moveToFirst()) {
} else {
historyHandler.addHistoryItem(new HistoryItem(view
.getUrl(), title));
}
} catch (IllegalStateException e) {
Log.e("Barebones", "ERRRRROOORRRR 1");
} catch (NullPointerException e) {
Log.e("Barebones", "ERRRRROOORRRR 2");
}
}
});
up.run();
super.onReceivedTitle(view, title); super.onReceivedTitle(view, title);
} }
@ -1340,8 +1321,10 @@ public class Barebones extends Activity implements OnLongClickListener,
// view.setDrawingCacheEnabled(true); // view.setDrawingCacheEnabled(true);
view.setDrawingCacheBackgroundColor(getResources().getColor( view.setDrawingCacheBackgroundColor(getResources().getColor(
android.R.color.background_light)); android.R.color.background_light));
view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); // view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
view.setAlwaysDrawnWithCacheEnabled(true); // view.setAlwaysDrawnWithCacheEnabled(true);
view.setWillNotCacheDrawing(true);
// view.setPersistentDrawingCache(ViewGroup.PERSISTENT_ALL_CACHES);
view.setFocusable(true); view.setFocusable(true);
view.setFocusableInTouchMode(true); view.setFocusableInTouchMode(true);
view.setSaveEnabled(true); view.setSaveEnabled(true);
@ -1392,6 +1375,7 @@ public class Barebones extends Activity implements OnLongClickListener,
webViewSettings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS); webViewSettings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
webViewSettings.setLoadsImagesAutomatically(true); webViewSettings.setLoadsImagesAutomatically(true);
// webViewSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); // webViewSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
return view; return view;
} }
@ -1477,9 +1461,7 @@ public class Barebones extends Activity implements OnLongClickListener,
new FileWriter(book)); new FileWriter(book));
BufferedWriter urlWriter = new BufferedWriter( BufferedWriter urlWriter = new BufferedWriter(
new FileWriter(bookUrl)); new FileWriter(bookUrl));
Log.i("barebones", "makes to here");
while (bUrl[n] != null && n < (MAX_BOOKMARKS - 1)) { while (bUrl[n] != null && n < (MAX_BOOKMARKS - 1)) {
Log.i("barebones", "makes to here " + n);
if (delete != n) { if (delete != n) {
bookWriter.write(bTitle[n]); bookWriter.write(bTitle[n]);
urlWriter.write(bUrl[n]); urlWriter.write(bUrl[n]);
@ -1487,7 +1469,6 @@ public class Barebones extends Activity implements OnLongClickListener,
urlWriter.newLine(); urlWriter.newLine();
} }
n++; n++;
Log.i("barebones", "makes to here " + n);
} }
bookWriter.close(); bookWriter.close();
urlWriter.close(); urlWriter.close();
@ -1577,7 +1558,6 @@ public class Barebones extends Activity implements OnLongClickListener,
} }
} }
public void addBookmark() { public void addBookmark() {
File book = new File(getBaseContext().getFilesDir(), "bookmarks"); File book = new File(getBaseContext().getFilesDir(), "bookmarks");
File bookUrl = new File(getBaseContext().getFilesDir(), "bookurl"); File bookUrl = new File(getBaseContext().getFilesDir(), "bookurl");
@ -1598,7 +1578,7 @@ public class Barebones extends Activity implements OnLongClickListener,
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} catch (NullPointerException e){ } catch (NullPointerException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -1657,6 +1637,9 @@ public class Barebones extends Activity implements OnLongClickListener,
int leftId = id; int leftId = id;
pageIdIsVisible = false; pageIdIsVisible = false;
main[id].stopLoading(); main[id].stopLoading();
if (API >= 11) {
main[id].onPause();
}
main[id].clearView(); main[id].clearView();
boolean right = false, left = false; boolean right = false, left = false;
// background.clearDisappearingChildren(); // background.clearDisappearingChildren();
@ -1886,19 +1869,24 @@ public class Barebones extends Activity implements OnLongClickListener,
menu.show(); menu.show();
} else if (API < 11) { } else if (API < 11) {
/* /*
LayoutInflater inflater=(LayoutInflater)Barebones.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); * LayoutInflater
Display display=getWindowManager().getDefaultDisplay(); * inflater=(LayoutInflater)Barebones.this.getSystemService
* (Context.LAYOUT_INFLATER_SERVICE); Display
int width=display.getWidth()/2; * display=getWindowManager().getDefaultDisplay();
int height=display.getHeight()/2; *
* int width=display.getWidth()/2; int
View pop = inflater.inflate(R.layout.menu,null,false); * height=display.getHeight()/2;
pop.measure(View.MeasureSpec.UNSPECIFIED,View.MeasureSpec.UNSPECIFIED); *
height=pop.getMeasuredHeight(); * View pop = inflater.inflate(R.layout.menu,null,false);
width=pop.getMeasuredWidth(); * pop
PopupWindow pu = new PopupWindow(pop,width,height,true); * .measure(View.MeasureSpec.UNSPECIFIED,View.MeasureSpec.
pu.showAtLocation(findViewById(v.getId()),Gravity.NO_GRAVITY,v.getRight(),v.getBottom()+80); * UNSPECIFIED); height=pop.getMeasuredHeight();
*/ * width=pop.getMeasuredWidth(); PopupWindow pu = new
* PopupWindow(pop,width,height,true);
* pu.showAtLocation(findViewById
* (v.getId()),Gravity.NO_GRAVITY
* ,v.getRight(),v.getBottom()+80);
*/
openOptionsMenu(); openOptionsMenu();
} }
@ -1963,7 +1951,6 @@ public class Barebones extends Activity implements OnLongClickListener,
String fixedQuery = query.trim(); String fixedQuery = query.trim();
boolean period = fixedQuery.contains("."); boolean period = fixedQuery.contains(".");
if (isBookmarkShowing) { if (isBookmarkShowing) {
Log.i("Barebones", " is executing");
scrollBookmarks.startAnimation(fadeOut); scrollBookmarks.startAnimation(fadeOut);
background.removeView(scrollBookmarks); background.removeView(scrollBookmarks);
isBookmarkShowing = false; isBookmarkShowing = false;
@ -2098,16 +2085,11 @@ public class Barebones extends Activity implements OnLongClickListener,
@Override @Override
public void finish() { public void finish() {
pageIdIsVisible = false; pageIdIsVisible = false;
this.onPause();
super.finish();
}
@Override
protected void onDestroy() {
try { try {
deleteHistory = settings.getBoolean("history", false); deleteHistory = settings.getBoolean("history", false);
if (deleteHistory == true) { if (deleteHistory == true) {
this.deleteDatabase("historyManager");
if (!noStockBrowser) { if (!noStockBrowser) {
Browser.clearHistory(getContentResolver()); Browser.clearHistory(getContentResolver());
} }
@ -2117,6 +2099,13 @@ public class Barebones extends Activity implements OnLongClickListener,
e.printStackTrace(); e.printStackTrace();
} }
this.onPause();
super.finish();
}
@Override
protected void onDestroy() {
super.onDestroy(); super.onDestroy();
} }

141
src/acr/browser/barebones/DatabaseHandler.java

@ -0,0 +1,141 @@
package acr.browser.barebones;
import java.util.ArrayList;
import java.util.List;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHandler extends SQLiteOpenHelper {
// All Static variables
// Database Version
private static final int DATABASE_VERSION = 1;
// Database Name
private static final String DATABASE_NAME = "historyManager";
// HistoryItems table name
private static final String TABLE_HISTORY = "history";
// HistoryItems Table Columns names
private static final String KEY_ID = "id";
private static final String KEY_URL = "url";
private static final String KEY_TITLE = "title";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_HISTORY + "("
+ KEY_ID + " INTEGER PRIMARY KEY," + KEY_URL + " TEXT,"
+ KEY_TITLE + " TEXT" +")";
db.execSQL(CREATE_CONTACTS_TABLE);
}
// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_HISTORY);
// Create tables again
onCreate(db);
}
/**
* All CRUD(Create, Read, Update, Delete) Operations
*/
// Adding new item
void addHistoryItem(HistoryItem item) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_URL, item.getUrl()); // HistoryItem Name
values.put(KEY_TITLE, item.getTitle()); // HistoryItem Phone
// Inserting Row
db.insert(TABLE_HISTORY, null, values);
db.close(); // Closing database connection
}
// Getting single item
HistoryItem getHistoryItem(int id) {
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);
if (cursor != null)
cursor.moveToFirst();
HistoryItem item = new HistoryItem(Integer.parseInt(cursor.getString(0)),
cursor.getString(1), cursor.getString(2));
// return item
return item;
}
// Getting All HistoryItems
public List<HistoryItem> getAllHistoryItems() {
List<HistoryItem> itemList = new ArrayList<HistoryItem>();
// Select All Query
String selectQuery = "SELECT * FROM " + TABLE_HISTORY;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
HistoryItem item = new HistoryItem();
item.setID(Integer.parseInt(cursor.getString(0)));
item.setUrl(cursor.getString(1));
item.setTitle(cursor.getString(2));
// Adding item to list
itemList.add(item);
} while (cursor.moveToNext());
}
// return item list
return itemList;
}
// Updating single item
public int updateHistoryItem(HistoryItem item) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_URL, item.getUrl());
values.put(KEY_TITLE, item.getTitle());
// updating row
return db.update(TABLE_HISTORY, values, KEY_ID + " = ?",
new String[] { String.valueOf(item.getID()) });
}
// Deleting single item
public void deleteHistoryItem(HistoryItem item) {
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_HISTORY, KEY_ID + " = ?",
new String[] { String.valueOf(item.getID()) });
db.close();
}
// Getting items Count
public int getHistoryItemsCount() {
String countQuery = "SELECT * FROM " + TABLE_HISTORY;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
cursor.close();
// return count
return cursor.getCount();
}
}

57
src/acr/browser/barebones/HistoryItem.java

@ -0,0 +1,57 @@
package acr.browser.barebones;
public class HistoryItem {
//private variables
int _id;
String _url;
String _title;
// Empty constructor
public HistoryItem(){
}
// constructor
public HistoryItem(int id, String url, String title){
this._id = id;
this._url = url;
this._title = title;
}
// constructor
public HistoryItem(String url, String title){
this._url = url;
this._title = title;
}
// getting ID
public int getID(){
return this._id;
}
// setting id
public void setID(int id){
this._id = id;
}
// getting name
public String getUrl(){
return this._url;
}
// setting name
public void setUrl(String url){
this._url = url;
}
// getting phone number
public String getTitle(){
return this._title;
}
// setting phone number
public void setTitle(String title){
this._title = title;
}
}
Loading…
Cancel
Save