@ -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,30 +141,26 @@ 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 ( ) {
DownloadManager download = ( DownloadManager ) context
@SuppressLint ( "InlinedApi" )
. getSystemService ( Context . DOWNLOAD_SERVICE ) ;
@Override
Uri nice = Uri . parse ( url ) ;
public void run ( ) {
DownloadManager . Request it = new DownloadManager . Request (
DownloadManager download = ( DownloadManager ) context
nice ) ;
. getSystemService ( Context . DOWNLOAD_SERVICE ) ;
String fileName = URLUtil . guessFileName ( url ,
Uri nice = Uri . parse ( url ) ;
contentDisposition , mimetype ) ;
DownloadManager . Request it = new DownloadManager . Request (
it . setTitle ( fileName ) ;
nice ) ;
it . setDescription ( url ) ;
String fileName = URLUtil . guessFileName ( url ,
if ( FinalVariables . API > = 11 ) {
contentDisposition , mimetype ) ;
it . allowScanningByMediaScanner ( ) ;
if ( FinalVariables . API > = 11 ) {
it . setNotificationVisibility ( DownloadManager . Request . VISIBILITY_VISIBLE_NOTIFY_COMPLETED ) ;
it . allowScanningByMediaScanner ( ) ;
}
it . setNotificationVisibility ( DownloadManager . Request . VISIBILITY_VISIBLE_NOTIFY_COMPLETED ) ;
String location = context . getSharedPreferences ( "settings" ,
}
0 ) . getString ( "download" ,
String location = context . getSharedPreferences ( "settings" ,
Environment . DIRECTORY_DOWNLOADS ) ;
0 ) . getString ( "download" ,
it . setDestinationInExternalPublicDir ( location , fileName ) ;
Environment . DIRECTORY_DOWNLOADS ) ;
Log . i ( "Barebones" , "Downloading" + fileName ) ;
it . setDestinationInExternalPublicDir ( location , fileName ) ;
download . enqueue ( it ) ;
Log . i ( "Barebones" , "Downloading" + fileName ) ;
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" ,