@ -10,7 +10,6 @@ import java.io.IOException;
import acr.browser.barebones.databases.DatabaseHandler ;
import acr.browser.barebones.databases.DatabaseHandler ;
import acr.browser.barebones.databases.HistoryItem ;
import acr.browser.barebones.databases.HistoryItem ;
import android.annotation.SuppressLint ;
import android.annotation.TargetApi ;
import android.annotation.TargetApi ;
import android.app.AlertDialog ;
import android.app.AlertDialog ;
import android.app.DownloadManager ;
import android.app.DownloadManager ;
@ -28,13 +27,15 @@ import android.os.Environment;
import android.provider.Browser ;
import android.provider.Browser ;
import android.util.Log ;
import android.util.Log ;
import android.webkit.URLUtil ;
import android.webkit.URLUtil ;
import android.widget.EditText ;
import android.widget.Toast ;
import android.widget.Toast ;
public class Utils {
public class Utils {
public static DatabaseHandler historyHandler ;
public static DatabaseHandler historyHandler ;
public static SQLiteDatabase history ;
public static SQLiteDatabase history ;
public static Cursor cursor ;
public static StringBuilder sb ;
public static Runnable update ;
public static void createInformativeDialog ( Context context , String title ,
public static void createInformativeDialog ( Context context , String title ,
String message ) {
String message ) {
@ -92,7 +93,7 @@ public class Utils {
public static void updateHistory ( final Context context ,
public static void updateHistory ( final Context context ,
final ContentResolver content , final boolean noStockBrowser ,
final ContentResolver content , final boolean noStockBrowser ,
final String url , final String title ) {
final String url , final String title ) {
Runnable update = new Runnable ( ) {
update = new Runnable ( ) {
@Override
@Override
public void run ( ) {
public void run ( ) {
if ( ! noStockBrowser ) {
if ( ! noStockBrowser ) {
@ -102,11 +103,11 @@ public class Utils {
}
}
}
}
try {
try {
StringBuilder sb = new StringBuilder ( "url" + " = " ) ;
sb = new StringBuilder ( "url" + " = " ) ;
DatabaseUtils . appendEscapedSQLString ( sb , url ) ;
DatabaseUtils . appendEscapedSQLString ( sb , url ) ;
historyHandler = new DatabaseHandler ( context ) ;
historyHandler = new DatabaseHandler ( context ) ;
history = historyHandler . getReadableDatabase ( ) ;
history = historyHandler . getReadableDatabase ( ) ;
Cursor cursor = history . query ( "history" , new String [ ] {
cursor = history . query ( "history" , new String [ ] {
"id" , "url" , "title" } , sb . toString ( ) , null , null ,
"id" , "url" , "title" } , sb . toString ( ) , null , null ,
null , null ) ;
null , null ) ;
if ( ! cursor . moveToFirst ( ) ) {
if ( ! cursor . moveToFirst ( ) ) {
@ -140,10 +141,6 @@ public class Utils {
public static void downloadFile ( final Context context , final String url ,
public static void downloadFile ( final Context context , final String url ,
final String contentDisposition , final String mimetype ) {
final String contentDisposition , final String mimetype ) {
try {
try {
Thread downloader = new Thread ( new Runnable ( ) {
@SuppressLint ( "InlinedApi" )
@Override
public void run ( ) {
DownloadManager download = ( DownloadManager ) context
DownloadManager download = ( DownloadManager ) context
. getSystemService ( Context . DOWNLOAD_SERVICE ) ;
. getSystemService ( Context . DOWNLOAD_SERVICE ) ;
Uri nice = Uri . parse ( url ) ;
Uri nice = Uri . parse ( url ) ;
@ -151,6 +148,8 @@ public class Utils {
nice ) ;
nice ) ;
String fileName = URLUtil . guessFileName ( url ,
String fileName = URLUtil . guessFileName ( url ,
contentDisposition , mimetype ) ;
contentDisposition , mimetype ) ;
it . setTitle ( fileName ) ;
it . setDescription ( url ) ;
if ( FinalVariables . API > = 11 ) {
if ( FinalVariables . API > = 11 ) {
it . allowScanningByMediaScanner ( ) ;
it . allowScanningByMediaScanner ( ) ;
it . setNotificationVisibility ( DownloadManager . Request . VISIBILITY_VISIBLE_NOTIFY_COMPLETED ) ;
it . setNotificationVisibility ( DownloadManager . Request . VISIBILITY_VISIBLE_NOTIFY_COMPLETED ) ;
@ -161,9 +160,7 @@ public class Utils {
it . setDestinationInExternalPublicDir ( location , fileName ) ;
it . setDestinationInExternalPublicDir ( location , fileName ) ;
Log . i ( "Barebones" , "Downloading" + fileName ) ;
Log . i ( "Barebones" , "Downloading" + fileName ) ;
download . enqueue ( it ) ;
download . enqueue ( it ) ;
}
} ) ;
downloader . run ( ) ;
} catch ( NullPointerException e ) {
} catch ( NullPointerException e ) {
Log . e ( "Barebones" , "Problem downloading" ) ;
Log . e ( "Barebones" , "Problem downloading" ) ;
Toast . makeText ( context , "Error Downloading File" ,
Toast . makeText ( context , "Error Downloading File" ,