OSDN Git Service

Use the new download manager APIs introduced in change 7400
authorJean-Baptiste Queru <jbq@google.com>
Tue, 31 Mar 2009 23:49:44 +0000 (16:49 -0700)
committerJean-Baptiste Queru <jbq@google.com>
Tue, 31 Mar 2009 23:49:44 +0000 (16:49 -0700)
Conflicts:

src/com/android/browser/BrowserActivity.java

src/com/android/browser/BrowserActivity.java
src/com/android/browser/BrowserDownloadAdapter.java
src/com/android/browser/BrowserDownloadPage.java
src/com/android/browser/FetchUrlMimeType.java

index 1c89640..c9bbb35 100644 (file)
@@ -3525,19 +3525,19 @@ public class BrowserActivity extends Activity
         String cookies = CookieManager.getInstance().getCookie(url);
 
         ContentValues values = new ContentValues();
-        values.put(Downloads.URI, uri.toString());
-        values.put(Downloads.COOKIE_DATA, cookies);
-        values.put(Downloads.USER_AGENT, userAgent);
-        values.put(Downloads.NOTIFICATION_PACKAGE,
+        values.put(Downloads.COLUMN_URI, uri.toString());
+        values.put(Downloads.COLUMN_COOKIE_DATA, cookies);
+        values.put(Downloads.COLUMN_USER_AGENT, userAgent);
+        values.put(Downloads.COLUMN_NOTIFICATION_PACKAGE,
                 getPackageName());
-        values.put(Downloads.NOTIFICATION_CLASS,
+        values.put(Downloads.COLUMN_NOTIFICATION_CLASS,
                 BrowserDownloadPage.class.getCanonicalName());
-        values.put(Downloads.VISIBILITY, Downloads.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
-        values.put(Downloads.MIMETYPE, mimetype);
-        values.put(Downloads.FILENAME_HINT, filename);
-        values.put(Downloads.DESCRIPTION, uri.getHost());
+        values.put(Downloads.COLUMN_VISIBILITY, Downloads.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
+        values.put(Downloads.COLUMN_MIME_TYPE, mimetype);
+        values.put(Downloads.COLUMN_FILE_NAME_HINT, filename);
+        values.put(Downloads.COLUMN_DESCRIPTION, uri.getHost());
         if (contentLength > 0) {
-            values.put(Downloads.TOTAL_BYTES, contentLength);
+            values.put(Downloads.COLUMN_TOTAL_BYTES, contentLength);
         }
         if (mimetype == null) {
             // We must have long pressed on a link or image to download it. We
index 38b83fe..16cb982 100644 (file)
@@ -60,14 +60,14 @@ public class BrowserDownloadAdapter extends ResourceCursorAdapter {
     public BrowserDownloadAdapter(Context context, int layout, Cursor c) {
         super(context, layout, c);
         mFilenameColumnId = c.getColumnIndexOrThrow(Downloads._DATA);
-        mTitleColumnId = c.getColumnIndexOrThrow(Downloads.TITLE);
-        mDescColumnId = c.getColumnIndexOrThrow(Downloads.DESCRIPTION);
-        mStatusColumnId = c.getColumnIndexOrThrow(Downloads.STATUS);
-        mTotalBytesColumnId = c.getColumnIndexOrThrow(Downloads.TOTAL_BYTES);
+        mTitleColumnId = c.getColumnIndexOrThrow(Downloads.COLUMN_TITLE);
+        mDescColumnId = c.getColumnIndexOrThrow(Downloads.COLUMN_DESCRIPTION);
+        mStatusColumnId = c.getColumnIndexOrThrow(Downloads.COLUMN_STATUS);
+        mTotalBytesColumnId = c.getColumnIndexOrThrow(Downloads.COLUMN_TOTAL_BYTES);
         mCurrentBytesColumnId = 
-            c.getColumnIndexOrThrow(Downloads.CURRENT_BYTES);
-        mMimetypeColumnId = c.getColumnIndexOrThrow(Downloads.MIMETYPE);
-        mDateColumnId = c.getColumnIndexOrThrow(Downloads.LAST_MODIFICATION);
+            c.getColumnIndexOrThrow(Downloads.COLUMN_CURRENT_BYTES);
+        mMimetypeColumnId = c.getColumnIndexOrThrow(Downloads.COLUMN_MIME_TYPE);
+        mDateColumnId = c.getColumnIndexOrThrow(Downloads.COLUMN_LAST_MODIFICATION);
     }
 
     @Override
@@ -106,7 +106,7 @@ public class BrowserDownloadAdapter extends ResourceCursorAdapter {
                 // We have a filename, so we can build a title from that
                 title = new File(fullFilename).getName();
                 ContentValues values = new ContentValues();
-                values.put(Downloads.TITLE, title);
+                values.put(Downloads.COLUMN_TITLE, title);
                 // assume "_id" is the first column for the cursor 
                 context.getContentResolver().update(
                         ContentUris.withAppendedId(Downloads.CONTENT_URI,
index 4397337..9776834 100644 (file)
@@ -73,22 +73,22 @@ public class BrowserDownloadPage extends Activity
         mListView.setEmptyView(v);
         
         mDownloadCursor = managedQuery(Downloads.CONTENT_URI, 
-                new String [] {"_id", Downloads.TITLE, Downloads.STATUS,
-                Downloads.TOTAL_BYTES, Downloads.CURRENT_BYTES, 
-                Downloads._DATA, Downloads.DESCRIPTION, 
-                Downloads.MIMETYPE, Downloads.LAST_MODIFICATION,
-                Downloads.VISIBILITY}, 
+                new String [] {"_id", Downloads.COLUMN_TITLE, Downloads.COLUMN_STATUS,
+                Downloads.COLUMN_TOTAL_BYTES, Downloads.COLUMN_CURRENT_BYTES, 
+                Downloads._DATA, Downloads.COLUMN_DESCRIPTION, 
+                Downloads.COLUMN_MIME_TYPE, Downloads.COLUMN_LAST_MODIFICATION,
+                Downloads.COLUMN_VISIBILITY}, 
                 null, null);
         
         // only attach everything to the listbox if we can access
         // the download database. Otherwise, just show it empty
         if (mDownloadCursor != null) {
             mStatusColumnId = 
-                    mDownloadCursor.getColumnIndexOrThrow(Downloads.STATUS);
+                    mDownloadCursor.getColumnIndexOrThrow(Downloads.COLUMN_STATUS);
             mIdColumnId =
                     mDownloadCursor.getColumnIndexOrThrow(Downloads._ID);
             mTitleColumnId = 
-                    mDownloadCursor.getColumnIndexOrThrow(Downloads.TITLE);
+                    mDownloadCursor.getColumnIndexOrThrow(Downloads.COLUMN_TITLE);
             
             // Create a list "controller" for the data
             mDownloadAdapter = new BrowserDownloadAdapter(this, 
@@ -403,7 +403,7 @@ public class BrowserDownloadPage extends Activity
                 mDownloadCursor.getColumnIndexOrThrow(Downloads._DATA);
         String filename = mDownloadCursor.getString(filenameColumnId);
         int mimetypeColumnId =
-                mDownloadCursor.getColumnIndexOrThrow(Downloads.MIMETYPE);
+                mDownloadCursor.getColumnIndexOrThrow(Downloads.COLUMN_MIME_TYPE);
         String mimetype = mDownloadCursor.getString(mimetypeColumnId);
         Uri path = Uri.parse(filename);
         // If there is no scheme, then it must be a file
@@ -453,13 +453,13 @@ public class BrowserDownloadPage extends Activity
     private void hideCompletedDownload() {
         int status = mDownloadCursor.getInt(mStatusColumnId);
 
-        int visibilityColumn = mDownloadCursor.getColumnIndexOrThrow(Downloads.VISIBILITY);
+        int visibilityColumn = mDownloadCursor.getColumnIndexOrThrow(Downloads.COLUMN_VISIBILITY);
         int visibility = mDownloadCursor.getInt(visibilityColumn);
 
         if (Downloads.isStatusCompleted(status) &&
                 visibility == Downloads.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) {
             ContentValues values = new ContentValues();
-            values.put(Downloads.VISIBILITY, Downloads.VISIBILITY_VISIBLE);
+            values.put(Downloads.COLUMN_VISIBILITY, Downloads.VISIBILITY_VISIBLE);
             getContentResolver().update(
                     ContentUris.withAppendedId(Downloads.CONTENT_URI,
                     mDownloadCursor.getLong(mIdColumnId)), values, null, null);
index 8578643..c585dbb 100644 (file)
@@ -58,7 +58,7 @@ class FetchUrlMimeType extends AsyncTask<ContentValues, String, String> {
         mValues = values[0];
 
         // Check to make sure we have a URI to download
-        String uri = mValues.getAsString(Downloads.URI);
+        String uri = mValues.getAsString(Downloads.COLUMN_URI);
         if (uri == null || uri.length() == 0) {
             return null;
         }
@@ -66,15 +66,15 @@ class FetchUrlMimeType extends AsyncTask<ContentValues, String, String> {
         // User agent is likely to be null, though the AndroidHttpClient
         // seems ok with that.
         AndroidHttpClient client = AndroidHttpClient.newInstance(
-                mValues.getAsString(Downloads.USER_AGENT));
+                mValues.getAsString(Downloads.COLUMN_USER_AGENT));
         HttpHead request = new HttpHead(uri);
 
-        String cookie = mValues.getAsString(Downloads.COOKIE_DATA);
+        String cookie = mValues.getAsString(Downloads.COLUMN_COOKIE_DATA);
         if (cookie != null && cookie.length() > 0) {
             request.addHeader("Cookie", cookie);
         }
 
-        String referer = mValues.getAsString(Downloads.REFERER);
+        String referer = mValues.getAsString(Downloads.COLUMN_REFERER);
         if (referer != null && referer.length() > 0) {
             request.addHeader("Referer", referer);
         }
@@ -111,19 +111,19 @@ class FetchUrlMimeType extends AsyncTask<ContentValues, String, String> {
    @Override
     public void onPostExecute(String mimeType) {
        if (mimeType != null) {
-           String url = mValues.getAsString(Downloads.URI);
+           String url = mValues.getAsString(Downloads.COLUMN_URI);
            if (mimeType.equalsIgnoreCase("text/plain") ||
                    mimeType.equalsIgnoreCase("application/octet-stream")) {
                String newMimeType =
                        MimeTypeMap.getSingleton().getMimeTypeFromExtension(
                            MimeTypeMap.getFileExtensionFromUrl(url));
                if (newMimeType != null) {
-                   mValues.put(Downloads.MIMETYPE, newMimeType);
+                   mValues.put(Downloads.COLUMN_MIME_TYPE, newMimeType);
                }
            }
            String filename = URLUtil.guessFileName(url,
                    null, mimeType);
-           mValues.put(Downloads.FILENAME_HINT, filename);
+           mValues.put(Downloads.COLUMN_FILE_NAME_HINT, filename);
        }
 
        // Start the download