summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AndroidManifest.xml1
-rw-r--r--res/layout/browser_download_item.xml91
-rw-r--r--res/layout/browser_downloads_page.xml24
-rw-r--r--res/layout/no_downloads.xml25
-rw-r--r--src/com/android/browser/BrowserActivity.java13
-rw-r--r--src/com/android/browser/BrowserDownloadAdapter.java221
-rw-r--r--src/com/android/browser/BrowserDownloadPage.java535
-rw-r--r--src/com/android/browser/OpenDownloadReceiver.java42
8 files changed, 12 insertions, 940 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 36e2820..dc8f599 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -200,7 +200,6 @@
<receiver android:name=".OpenDownloadReceiver">
<intent-filter>
<action android:name="android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED"/>
- <action android:name="android.intent.action.DELETE"/>
<data android:scheme="content" android:mimeType="vnd.android.cursor.item/download"/>
</intent-filter>
</receiver>
diff --git a/res/layout/browser_download_item.xml b/res/layout/browser_download_item.xml
deleted file mode 100644
index 52f49c1..0000000
--- a/res/layout/browser_download_item.xml
+++ /dev/null
@@ -1,91 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-** assets/res/any/layout/browser_bookmark_item.xml
-**
-** Copyright 2006, 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.
-*/
--->
-
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingRight="?android:attr/scrollbarSize"
- >
-
- <ImageView android:id="@+id/download_icon"
- android:layout_width="@android:dimen/app_icon_size"
- android:layout_height="@android:dimen/app_icon_size"
- android:layout_alignParentTop="true"
- android:layout_alignParentLeft="true"
- android:scaleType="fitCenter"
- />
-
- <TextView android:id="@+id/download_title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:maxLines="1"
- android:layout_alignParentTop="true"
- android:layout_toRightOf="@id/download_icon"
- android:textAppearance="?android:attr/textAppearanceMedium"
- />
- <TextView android:id="@+id/domain"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toRightOf="@id/download_icon"
- android:layout_below="@id/download_title"
- android:maxLines="1"
- android:textAppearance="?android:attr/textAppearanceSmall"
- />
-
- <TextView android:id="@+id/complete_date"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:maxLines="1"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:layout_below="@id/domain"
- android:layout_alignParentRight="true"
- android:visibility="gone"
- />
-
- <TextView android:id="@+id/complete_text"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@id/domain"
- android:layout_toRightOf="@id/download_icon"
- android:layout_toLeftOf="@id/complete_date"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:visibility="gone"
- />
-
- <ProgressBar android:id="@+id/download_progress"
- style="?android:attr/progressBarStyleHorizontal"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_below="@id/download_icon"
- android:layout_alignParentLeft="true"
- android:layout_alignParentRight="true"
- android:max="100"
- />
- <TextView android:id="@+id/progress_text"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:maxLines="1"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:layout_centerHorizontal="true"
- android:layout_below="@id/download_progress"
- />
-</RelativeLayout>
-
diff --git a/res/layout/browser_downloads_page.xml b/res/layout/browser_downloads_page.xml
deleted file mode 100644
index 5cdf30c..0000000
--- a/res/layout/browser_downloads_page.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-** assets/res/any/layout/browser_bookmarks_page.xml
-**
-** Copyright 2006, 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.
-*/
--->
-<merge xmlns:android="http://schemas.android.com/apk/res/android">
- <ExpandableListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="match_parent"/>
- <ViewStub android:id="@+id/empty" android:layout="@layout/no_downloads" android:layout_width="match_parent" android:layout_height="match_parent"/>
-</merge>
diff --git a/res/layout/no_downloads.xml b/res/layout/no_downloads.xml
deleted file mode 100644
index 6918eab..0000000
--- a/res/layout/no_downloads.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2008 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.
--->
-
-<TextView xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:text="@string/no_downloads"
- android:background="@color/black"
- android:textColor="@color/white"
- android:gravity="center"
- android:textStyle="bold"
- />
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java
index 72ed2ec..101157c 100644
--- a/src/com/android/browser/BrowserActivity.java
+++ b/src/com/android/browser/BrowserActivity.java
@@ -47,6 +47,7 @@ import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
+import android.net.DownloadManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.net.WebAddress;
@@ -1447,7 +1448,7 @@ public class BrowserActivity extends Activity
break;
case R.id.view_downloads_menu_id:
- viewDownloads(null);
+ viewDownloads();
break;
case R.id.window_one_menu_id:
@@ -3566,12 +3567,9 @@ public class BrowserActivity extends Activity
* menu to see the download window. It shows the download window on top of
* the current window.
*/
- private void viewDownloads(Uri downloadRecord) {
- Intent intent = new Intent(this,
- BrowserDownloadPage.class);
- intent.setData(downloadRecord);
- startActivityForResult(intent, BrowserActivity.DOWNLOAD_PAGE);
-
+ private void viewDownloads() {
+ Intent intent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS);
+ startActivity(intent);
}
/**
@@ -3994,7 +3992,6 @@ public class BrowserActivity extends Activity
// activity requestCode
final static int COMBO_PAGE = 1;
- final static int DOWNLOAD_PAGE = 2;
final static int PREFERENCES_PAGE = 3;
final static int FILE_SELECTED = 4;
diff --git a/src/com/android/browser/BrowserDownloadAdapter.java b/src/com/android/browser/BrowserDownloadAdapter.java
deleted file mode 100644
index 0f8f721..0000000
--- a/src/com/android/browser/BrowserDownloadAdapter.java
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- * Copyright (C) 2007 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.
- */
-
-
-package com.android.browser;
-
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.res.Resources;
-import android.database.Cursor;
-import android.drm.mobile1.DrmRawContent;
-import android.graphics.drawable.Drawable;
-import android.net.Uri;
-import android.provider.Downloads;
-import android.text.format.Formatter;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ImageView;
-import android.widget.ProgressBar;
-import android.widget.RelativeLayout;
-import android.widget.TextView;
-
-import java.text.DateFormat;
-import java.util.Date;
-import java.util.List;
-
-/**
- * This class is used to represent the data for the download list box. The only
- * real work done by this class is to construct a custom view for the line
- * items.
- */
-public class BrowserDownloadAdapter extends DateSortedExpandableListAdapter {
-
- private int mTitleColumnId;
- private int mDescColumnId;
- private int mStatusColumnId;
- private int mTotalBytesColumnId;
- private int mCurrentBytesColumnId;
- private int mMimetypeColumnId;
- private int mDateColumnId;
-
- public BrowserDownloadAdapter(Context context, Cursor c, int index) {
- super(context, c, index);
- mTitleColumnId = c.getColumnIndexOrThrow(Downloads.Impl.COLUMN_TITLE);
- mDescColumnId = c.getColumnIndexOrThrow(Downloads.Impl.COLUMN_DESCRIPTION);
- mStatusColumnId = c.getColumnIndexOrThrow(Downloads.Impl.COLUMN_STATUS);
- mTotalBytesColumnId = c.getColumnIndexOrThrow(Downloads.Impl.COLUMN_TOTAL_BYTES);
- mCurrentBytesColumnId =
- c.getColumnIndexOrThrow(Downloads.Impl.COLUMN_CURRENT_BYTES);
- mMimetypeColumnId = c.getColumnIndexOrThrow(Downloads.Impl.COLUMN_MIME_TYPE);
- mDateColumnId = c.getColumnIndexOrThrow(Downloads.Impl.COLUMN_LAST_MODIFICATION);
- }
-
- @Override
- public View getChildView(int groupPosition, int childPosition,
- boolean isLastChild, View convertView, ViewGroup parent) {
- Context context = getContext();
- // The layout file uses a RelativeLayout, whereas the GroupViews use
- // TextView.
- if (null == convertView || !(convertView instanceof RelativeLayout)) {
- convertView = LayoutInflater.from(context).inflate(
- R.layout.browser_download_item, null);
- }
-
- // Bail early if the Cursor is closed.
- if (!moveCursorToChildPosition(groupPosition, childPosition)) {
- return convertView;
- }
-
- Resources r = context.getResources();
-
- // Retrieve the icon for this download
- String mimeType = getString(mMimetypeColumnId);
- ImageView iv = (ImageView) convertView.findViewById(R.id.download_icon);
- if (DrmRawContent.DRM_MIMETYPE_MESSAGE_STRING.equalsIgnoreCase(mimeType)) {
- iv.setImageResource(R.drawable.ic_launcher_drm_file);
- } else if (mimeType == null) {
- iv.setVisibility(View.INVISIBLE);
- } else {
- Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setDataAndType(Uri.fromParts("file", "", null), mimeType);
- PackageManager pm = context.getPackageManager();
- List<ResolveInfo> list = pm.queryIntentActivities(intent,
- PackageManager.MATCH_DEFAULT_ONLY);
- if (list.size() > 0) {
- Drawable icon = list.get(0).activityInfo.loadIcon(pm);
- iv.setImageDrawable(icon);
- iv.setVisibility(View.VISIBLE);
- } else {
- iv.setVisibility(View.INVISIBLE);
- }
- }
-
- TextView tv = (TextView) convertView.findViewById(R.id.download_title);
- String title = getString(mTitleColumnId);
- if (title == null) {
- title = r.getString(R.string.download_unknown_filename);
- }
- tv.setText(title);
-
- tv = (TextView) convertView.findViewById(R.id.domain);
- tv.setText(getString(mDescColumnId));
-
- long totalBytes = getLong(mTotalBytesColumnId);
-
- int status = getInt(mStatusColumnId);
- if (Downloads.Impl.isStatusCompleted(status)) { // Download stopped
- View v = convertView.findViewById(R.id.progress_text);
- v.setVisibility(View.GONE);
-
- v = convertView.findViewById(R.id.download_progress);
- v.setVisibility(View.GONE);
-
- tv = (TextView) convertView.findViewById(R.id.complete_text);
- tv.setVisibility(View.VISIBLE);
- if (Downloads.Impl.isStatusError(status)) {
- tv.setText(getErrorText(status));
- } else {
- tv.setText(r.getString(R.string.download_success,
- Formatter.formatFileSize(context, totalBytes)));
- }
-
- long time = getLong(mDateColumnId);
- Date d = new Date(time);
- DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
- tv = (TextView) convertView.findViewById(R.id.complete_date);
- tv.setVisibility(View.VISIBLE);
- tv.setText(df.format(d));
-
- } else { // Download is still running
- tv = (TextView) convertView.findViewById(R.id.progress_text);
- tv.setVisibility(View.VISIBLE);
-
- View progress = convertView.findViewById(R.id.download_progress);
- progress.setVisibility(View.VISIBLE);
-
- View v = convertView.findViewById(R.id.complete_date);
- v.setVisibility(View.GONE);
-
- v = convertView.findViewById(R.id.complete_text);
- v.setVisibility(View.GONE);
-
- if (status == Downloads.Impl.STATUS_PENDING) {
- tv.setText(r.getText(R.string.download_pending));
- } else if (status == Downloads.Impl.STATUS_PENDING_PAUSED) {
- tv.setText(r.getText(R.string.download_pending_network));
- } else {
- ProgressBar pb = (ProgressBar) progress;
-
- StringBuilder sb = new StringBuilder();
- if (status == Downloads.Impl.STATUS_RUNNING) {
- sb.append(r.getText(R.string.download_running));
- } else {
- sb.append(r.getText(R.string.download_running_paused));
- }
- if (totalBytes > 0) {
- long currentBytes = getLong(mCurrentBytesColumnId);
- int progressAmount = (int)(currentBytes * 100 / totalBytes);
- sb.append(' ');
- sb.append(progressAmount);
- sb.append("% (");
- sb.append(Formatter.formatFileSize(context, currentBytes));
- sb.append("/");
- sb.append(Formatter.formatFileSize(context, totalBytes));
- sb.append(")");
- pb.setIndeterminate(false);
- pb.setProgress(progressAmount);
- } else {
- pb.setIndeterminate(true);
- }
- tv.setText(sb.toString());
- }
- }
- return convertView;
- }
-
- /**
- * Provide the resource id for the error string.
- * @param status status of the download item
- * @return resource id for the error string.
- */
- public static int getErrorText(int status) {
- switch (status) {
- case Downloads.Impl.STATUS_NOT_ACCEPTABLE:
- return R.string.download_not_acceptable;
-
- case Downloads.Impl.STATUS_LENGTH_REQUIRED:
- return R.string.download_length_required;
-
- case Downloads.Impl.STATUS_PRECONDITION_FAILED:
- return R.string.download_precondition_failed;
-
- case Downloads.Impl.STATUS_CANCELED:
- return R.string.download_canceled;
-
- case Downloads.Impl.STATUS_FILE_ERROR:
- return R.string.download_file_error;
-
- case Downloads.Impl.STATUS_BAD_REQUEST:
- case Downloads.Impl.STATUS_UNKNOWN_ERROR:
- default:
- return R.string.download_error;
- }
- }
-}
diff --git a/src/com/android/browser/BrowserDownloadPage.java b/src/com/android/browser/BrowserDownloadPage.java
deleted file mode 100644
index 18faf8b..0000000
--- a/src/com/android/browser/BrowserDownloadPage.java
+++ /dev/null
@@ -1,535 +0,0 @@
-/*
- * Copyright (C) 2007 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.
- */
-
-package com.android.browser;
-
-import android.app.AlertDialog;
-import android.app.ExpandableListActivity;
-import android.content.ActivityNotFoundException;
-import android.content.ContentValues;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.ContentUris;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.database.ContentObserver;
-import android.database.Cursor;
-import android.net.Uri;
-import android.os.Bundle;
-import android.os.Handler;
-import android.provider.Downloads;
-import android.util.Log;
-import android.view.ContextMenu;
-import android.view.ContextMenu.ContextMenuInfo;
-import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.MenuInflater;
-import android.view.View;
-import android.view.ViewGroup.LayoutParams;
-import android.widget.AdapterView;
-import android.widget.ExpandableListView;
-
-import java.io.File;
-import java.util.List;
-
-/**
- * View showing the user's current browser downloads
- */
-public class BrowserDownloadPage extends ExpandableListActivity {
- private ExpandableListView mListView;
- private Cursor mDownloadCursor;
- private BrowserDownloadAdapter mDownloadAdapter;
- private int mStatusColumnId;
- private int mIdColumnId;
- private int mTitleColumnId;
- private long mContextMenuPosition;
- // Used to update the ContextMenu if an item is being downloaded and the
- // user opens the ContextMenu.
- private ContentObserver mContentObserver;
- // Only meaningful while a ContentObserver is registered. The ContextMenu
- // will be reopened on this View.
- private View mSelectedView;
-
- private final static String LOGTAG = "BrowserDownloadPage";
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- setContentView(R.layout.browser_downloads_page);
-
- setTitle(getText(R.string.download_title));
-
- mListView = (ExpandableListView) findViewById(android.R.id.list);
- mListView.setEmptyView(findViewById(R.id.empty));
- mDownloadCursor = managedQuery(Downloads.Impl.CONTENT_URI,
- new String [] {Downloads.Impl._ID, Downloads.Impl.COLUMN_TITLE,
- Downloads.Impl.COLUMN_STATUS, Downloads.Impl.COLUMN_TOTAL_BYTES,
- Downloads.Impl.COLUMN_CURRENT_BYTES,
- Downloads.Impl.COLUMN_DESCRIPTION,
- Downloads.Impl.COLUMN_NOTIFICATION_PACKAGE,
- Downloads.Impl.COLUMN_LAST_MODIFICATION,
- Downloads.Impl.COLUMN_VISIBILITY,
- Downloads.Impl._DATA,
- Downloads.Impl.COLUMN_MIME_TYPE},
- null, Downloads.Impl.COLUMN_LAST_MODIFICATION + " DESC");
-
- // 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.Impl.COLUMN_STATUS);
- mIdColumnId =
- mDownloadCursor.getColumnIndexOrThrow(Downloads.Impl._ID);
- mTitleColumnId =
- mDownloadCursor.getColumnIndexOrThrow(Downloads.Impl.COLUMN_TITLE);
-
- // Create a list "controller" for the data
- mDownloadAdapter = new BrowserDownloadAdapter(this,
- mDownloadCursor, mDownloadCursor.getColumnIndexOrThrow(
- Downloads.Impl.COLUMN_LAST_MODIFICATION));
-
- setListAdapter(mDownloadAdapter);
- mListView.setOnCreateContextMenuListener(this);
-
- Intent intent = getIntent();
- final int groupToShow = intent == null || intent.getData() == null
- ? 0 : checkStatus(ContentUris.parseId(intent.getData()));
- if (mDownloadAdapter.getGroupCount() > groupToShow) {
- mListView.post(new Runnable() {
- public void run() {
- if (mDownloadAdapter.getGroupCount() > groupToShow) {
- mListView.expandGroup(groupToShow);
- }
- }
- });
- }
- }
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- if (mDownloadCursor != null) {
- String where = null;
- for (mDownloadCursor.moveToFirst(); !mDownloadCursor.isAfterLast();
- mDownloadCursor.moveToNext()) {
- if (!Downloads.Impl.isStatusCompleted(
- mDownloadCursor.getInt(mStatusColumnId))) {
- // Only want to check files that have completed.
- continue;
- }
- int filenameColumnId = mDownloadCursor.getColumnIndexOrThrow(
- Downloads.Impl._DATA);
- String filename = mDownloadCursor.getString(filenameColumnId);
- if (filename != null) {
- File file = new File(filename);
- if (!file.exists()) {
- long id = mDownloadCursor.getLong(mIdColumnId);
- if (where == null) {
- where = Downloads.Impl._ID + " = '" + id + "'";
- } else {
- where += " OR " + Downloads.Impl._ID + " = '" + id
- + "'";
- }
- }
- }
- }
- if (where != null) {
- getContentResolver().delete(Downloads.Impl.CONTENT_URI, where,
- null);
- }
- }
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- if (mDownloadCursor != null) {
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.downloadhistory, menu);
- }
- return true;
- }
-
- @Override
- public boolean onPrepareOptionsMenu(Menu menu) {
- boolean showCancel = getCancelableCount() > 0;
- menu.findItem(R.id.download_menu_cancel_all).setEnabled(showCancel);
- return super.onPrepareOptionsMenu(menu);
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.download_menu_cancel_all:
- promptCancelAll();
- return true;
- }
- return false;
- }
-
- /**
- * Remove the file from the list of downloads.
- * @param id Unique ID of the download to remove.
- */
- private void clearFromDownloads(long id) {
- getContentResolver().delete(ContentUris.withAppendedId(
- Downloads.Impl.CONTENT_URI, id), null, null);
- }
-
- @Override
- public boolean onContextItemSelected(MenuItem item) {
- if (!mDownloadAdapter.moveCursorToPackedChildPosition(
- mContextMenuPosition)) {
- return false;
- }
- switch (item.getItemId()) {
- case R.id.download_menu_open:
- hideCompletedDownload();
- openOrDeleteCurrentDownload(false);
- return true;
-
- case R.id.download_menu_delete:
- new AlertDialog.Builder(this)
- .setTitle(R.string.download_delete_file)
- .setIcon(android.R.drawable.ic_dialog_alert)
- .setMessage(mDownloadCursor.getString(mTitleColumnId))
- .setNegativeButton(R.string.cancel, null)
- .setPositiveButton(R.string.ok,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog,
- int whichButton) {
- openOrDeleteCurrentDownload(true);
- }
- })
- .show();
- break;
-
- case R.id.download_menu_clear:
- case R.id.download_menu_cancel:
- clearFromDownloads(mDownloadCursor.getLong(mIdColumnId));
- return true;
- }
- return false;
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- if (mContentObserver != null) {
- getContentResolver().unregisterContentObserver(mContentObserver);
- // Note that we do not need to undo this in onResume, because the
- // ContextMenu does not get reinvoked when the Activity resumes.
- }
- }
-
- /*
- * ContentObserver to update the ContextMenu if it is open when the
- * corresponding download completes.
- */
- private class ChangeObserver extends ContentObserver {
- private final Uri mTrack;
- public ChangeObserver(Uri track) {
- super(new Handler());
- mTrack = track;
- }
-
- @Override
- public boolean deliverSelfNotifications() {
- return false;
- }
-
- @Override
- public void onChange(boolean selfChange) {
- Cursor cursor = null;
- try {
- cursor = getContentResolver().query(mTrack,
- new String[] { Downloads.Impl.COLUMN_STATUS }, null, null,
- null);
- if (cursor.moveToFirst() && Downloads.Impl.isStatusSuccess(
- cursor.getInt(0))) {
- // Do this right away, so we get no more updates.
- getContentResolver().unregisterContentObserver(
- mContentObserver);
- // Post a runnable in case this ContentObserver gets notified
- // before the one that updates the ListView.
- mListView.post(new Runnable() {
- public void run() {
- // Close the context menu, reopen with up to date data.
- closeContextMenu();
- openContextMenu(mSelectedView);
- }
- });
- }
- } catch (IllegalStateException e) {
- Log.e(LOGTAG, "onChange", e);
- } finally {
- if (cursor != null) cursor.close();
- }
- }
- }
-
- @Override
- public void onCreateContextMenu(ContextMenu menu, View v,
- ContextMenuInfo menuInfo) {
- if (mDownloadCursor != null) {
- ExpandableListView.ExpandableListContextMenuInfo info
- = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
- long packedPosition = info.packedPosition;
- // Only show a context menu for the child views
- if (!mDownloadAdapter.moveCursorToPackedChildPosition(
- packedPosition)) {
- return;
- }
- mContextMenuPosition = packedPosition;
- menu.setHeaderTitle(mDownloadCursor.getString(mTitleColumnId));
-
- MenuInflater inflater = getMenuInflater();
- int status = mDownloadCursor.getInt(mStatusColumnId);
- if (Downloads.Impl.isStatusSuccess(status)) {
- inflater.inflate(R.menu.downloadhistorycontextfinished, menu);
- } else if (Downloads.Impl.isStatusError(status)) {
- inflater.inflate(R.menu.downloadhistorycontextfailed, menu);
- } else {
- // In this case, the download is in progress. Set a
- // ContentObserver so that we can know when it completes,
- // and if it does, we can then update the context menu
- Uri track = ContentUris.withAppendedId(
- Downloads.Impl.CONTENT_URI,
- mDownloadCursor.getLong(mIdColumnId));
- if (mContentObserver != null) {
- getContentResolver().unregisterContentObserver(
- mContentObserver);
- }
- mContentObserver = new ChangeObserver(track);
- mSelectedView = v;
- getContentResolver().registerContentObserver(track, false,
- mContentObserver);
- inflater.inflate(R.menu.downloadhistorycontextrunning, menu);
- }
- }
- super.onCreateContextMenu(menu, v, menuInfo);
- }
-
- /**
- * This function is called to check the status of the download and if it
- * has an error show an error dialog.
- * @param id Row id of the download to check
- * @return Group which contains the download
- */
- private int checkStatus(final long id) {
- int groupToShow = mDownloadAdapter.groupFromChildId(id);
- if (-1 == groupToShow) return 0;
- int status = mDownloadCursor.getInt(mStatusColumnId);
- if (!Downloads.Impl.isStatusError(status)) {
- return groupToShow;
- }
- if (status == Downloads.Impl.STATUS_FILE_ERROR) {
- String title = mDownloadCursor.getString(mTitleColumnId);
- if (title == null || title.length() == 0) {
- title = getString(R.string.download_unknown_filename);
- }
- String msg = getString(R.string.download_file_error_dlg_msg, title);
- new AlertDialog.Builder(this)
- .setTitle(R.string.download_file_error_dlg_title)
- .setIcon(android.R.drawable.ic_popup_disk_full)
- .setMessage(msg)
- .setPositiveButton(R.string.ok, null)
- .setNegativeButton(R.string.retry,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog,
- int whichButton) {
- resumeDownload(id);
- }
- })
- .show();
- } else {
- new AlertDialog.Builder(this)
- .setTitle(R.string.download_failed_generic_dlg_title)
- .setIcon(R.drawable.ssl_icon)
- .setMessage(BrowserDownloadAdapter.getErrorText(status))
- .setPositiveButton(R.string.ok, null)
- .show();
- }
- return groupToShow;
- }
-
- /**
- * Resume a given download
- * @param id Row id of the download to resume
- */
- private void resumeDownload(final long id) {
- // the relevant functionality doesn't exist in the download manager
- }
-
- /**
- * Return the number of items in the list that can be canceled.
- * @return count
- */
- private int getCancelableCount() {
- // Count the number of items that will be canceled.
- int count = 0;
- if (mDownloadCursor != null) {
- for (mDownloadCursor.moveToFirst(); !mDownloadCursor.isAfterLast();
- mDownloadCursor.moveToNext()) {
- int status = mDownloadCursor.getInt(mStatusColumnId);
- if (!Downloads.Impl.isStatusCompleted(status)) {
- count++;
- }
- }
- }
-
- return count;
- }
-
- /**
- * Prompt the user if they would like to clear the download history
- */
- private void promptCancelAll() {
- int count = getCancelableCount();
-
- // If there is nothing to do, just return
- if (count == 0) {
- return;
- }
-
- // Don't show the dialog if there is only one download
- if (count == 1) {
- cancelAllDownloads();
- return;
- }
- String msg =
- getString(R.string.download_cancel_dlg_msg, count);
- new AlertDialog.Builder(this)
- .setTitle(R.string.download_cancel_dlg_title)
- .setIcon(R.drawable.ssl_icon)
- .setMessage(msg)
- .setPositiveButton(R.string.ok,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog,
- int whichButton) {
- cancelAllDownloads();
- }
- })
- .setNegativeButton(R.string.cancel, null)
- .show();
- }
-
- /**
- * Cancel all downloads. As canceled downloads are not
- * listed, we removed them from the db. Removing a download
- * record, cancels the download.
- */
- private void cancelAllDownloads() {
- if (mDownloadCursor.moveToFirst()) {
- StringBuilder where = new StringBuilder();
- boolean firstTime = true;
- while (!mDownloadCursor.isAfterLast()) {
- int status = mDownloadCursor.getInt(mStatusColumnId);
- if (!Downloads.Impl.isStatusCompleted(status)) {
- if (firstTime) {
- firstTime = false;
- } else {
- where.append(" OR ");
- }
- where.append("( ");
- where.append(Downloads.Impl._ID);
- where.append(" = '");
- where.append(mDownloadCursor.getLong(mIdColumnId));
- where.append("' )");
- }
- mDownloadCursor.moveToNext();
- }
- if (!firstTime) {
- getContentResolver().delete(Downloads.Impl.CONTENT_URI,
- where.toString(), null);
- }
- }
- }
-
- private int getClearableCount() {
- int count = 0;
- if (mDownloadCursor.moveToFirst()) {
- while (!mDownloadCursor.isAfterLast()) {
- int status = mDownloadCursor.getInt(mStatusColumnId);
- if (Downloads.Impl.isStatusCompleted(status)) {
- count++;
- }
- mDownloadCursor.moveToNext();
- }
- }
- return count;
- }
-
- /**
- * Open or delete content where the download db cursor currently is. Sends
- * an Intent to perform the action.
- * @param delete If true, delete the content. Otherwise open it.
- */
- private void openOrDeleteCurrentDownload(boolean delete) {
- int packageColumnId = mDownloadCursor.getColumnIndexOrThrow(
- Downloads.Impl.COLUMN_NOTIFICATION_PACKAGE);
- String packageName = mDownloadCursor.getString(packageColumnId);
- Intent intent = new Intent(delete ? Intent.ACTION_DELETE
- : Downloads.Impl.ACTION_NOTIFICATION_CLICKED);
- Uri contentUri = ContentUris.withAppendedId(
- Downloads.Impl.CONTENT_URI,
- mDownloadCursor.getLong(mIdColumnId));
- intent.setData(contentUri);
- intent.setPackage(packageName);
- sendBroadcast(intent);
- }
-
- @Override
- public boolean onChildClick(ExpandableListView parent, View v,
- int groupPosition, int childPosition, long id) {
- // Open the selected item
- mDownloadAdapter.moveCursorToChildPosition(groupPosition,
- childPosition);
-
- hideCompletedDownload();
-
- int status = mDownloadCursor.getInt(mStatusColumnId);
- if (Downloads.Impl.isStatusSuccess(status)) {
- // Open it if it downloaded successfully
- openOrDeleteCurrentDownload(false);
- } else {
- // Check to see if there is an error.
- checkStatus(id);
- }
- return true;
- }
-
- /**
- * hides the notification for the download pointed by mDownloadCursor
- * if the download has completed.
- */
- private void hideCompletedDownload() {
- int status = mDownloadCursor.getInt(mStatusColumnId);
-
- int visibilityColumn = mDownloadCursor.getColumnIndexOrThrow(
- Downloads.Impl.COLUMN_VISIBILITY);
- int visibility = mDownloadCursor.getInt(visibilityColumn);
-
- if (Downloads.Impl.isStatusCompleted(status) &&
- visibility == Downloads.Impl.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) {
- ContentValues values = new ContentValues();
- values.put(Downloads.Impl.COLUMN_VISIBILITY, Downloads.Impl.VISIBILITY_VISIBLE);
- getContentResolver().update(
- ContentUris.withAppendedId(Downloads.Impl.CONTENT_URI,
- mDownloadCursor.getLong(mIdColumnId)), values, null, null);
- }
- }
-}
diff --git a/src/com/android/browser/OpenDownloadReceiver.java b/src/com/android/browser/OpenDownloadReceiver.java
index 814aa9c..26bf51e 100644
--- a/src/com/android/browser/OpenDownloadReceiver.java
+++ b/src/com/android/browser/OpenDownloadReceiver.java
@@ -22,17 +22,18 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
-import android.database.DatabaseUtils;
+import android.net.DownloadManager;
import android.net.Uri;
import android.provider.Downloads;
-import android.provider.MediaStore;
import android.widget.Toast;
import java.io.File;
/**
- * This {@link BroadcastReceiver} handles {@link Intent}s to open and delete
- * files downloaded by the Browser.
+ * This {@link BroadcastReceiver} handles clicks to notifications that
+ * downloads from the browser are in progress/complete. Clicking on an
+ * in-progress or failed download will open the download manager. Clicking on
+ * a complete, successful download will open the file.
*/
public class OpenDownloadReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
@@ -69,44 +70,15 @@ public class OpenDownloadReceiver extends BroadcastReceiver {
}
} else {
// Open the downloads page
- Intent pageView = new Intent(context,
- BrowserDownloadPage.class);
- pageView.setData(data);
+ Intent pageView = new Intent(
+ DownloadManager.ACTION_VIEW_DOWNLOADS);
pageView.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(pageView);
}
- } else if (Intent.ACTION_DELETE.equals(action)) {
- if (deleteFile(cr, filename, mimetype)) {
- cr.delete(data, null, null);
- }
}
}
} finally {
if (cursor != null) cursor.close();
}
}
-
- /**
- * Remove the file from the SD card
- * @param cr ContentResolver used to delete the file.
- * @param filename Name of the file to delete.
- * @param mimetype Mimetype of the file to delete.
- * @return boolean True on success, false on failure.
- */
- private boolean deleteFile(ContentResolver cr, String filename,
- String mimetype) {
- Uri uri;
- if (mimetype.startsWith("image")) {
- uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
- } else if (mimetype.startsWith("audio")) {
- uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
- } else if (mimetype.startsWith("video")) {
- uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
- } else {
- uri = null;
- }
- return (uri != null && cr.delete(uri, MediaStore.MediaColumns.DATA
- + " = " + DatabaseUtils.sqlEscapeString(filename), null) > 0)
- || new File(filename).delete();
- }
}