blob: c8f848a76116652d164d5b153a7486e8f367c28e [file] [log] [blame]
The Android Open Source Project0c908882009-03-03 19:32:16 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.browser;
18
The Android Open Source Project0c908882009-03-03 19:32:16 -080019import android.app.AlertDialog;
Leon Scroggins24837452010-01-13 13:43:35 -050020import android.app.ExpandableListActivity;
The Android Open Source Project0c908882009-03-03 19:32:16 -080021import android.content.ActivityNotFoundException;
22import android.content.ContentValues;
23import android.content.DialogInterface;
24import android.content.Intent;
25import android.content.ContentUris;
26import android.content.pm.PackageManager;
27import android.content.pm.ResolveInfo;
Leon Scrogginsd080b182010-02-26 14:16:41 -050028import android.database.ContentObserver;
The Android Open Source Project0c908882009-03-03 19:32:16 -080029import android.database.Cursor;
30import android.net.Uri;
31import android.os.Bundle;
Leon Scrogginsd080b182010-02-26 14:16:41 -050032import android.os.Handler;
The Android Open Source Project0c908882009-03-03 19:32:16 -080033import android.provider.Downloads;
34import android.view.ContextMenu;
35import android.view.ContextMenu.ContextMenuInfo;
36import android.view.LayoutInflater;
37import android.view.Menu;
38import android.view.MenuItem;
39import android.view.MenuInflater;
40import android.view.View;
41import android.view.ViewGroup.LayoutParams;
42import android.widget.AdapterView;
Leon Scroggins24837452010-01-13 13:43:35 -050043import android.widget.ExpandableListView;
The Android Open Source Project0c908882009-03-03 19:32:16 -080044
45import java.io.File;
46import java.util.List;
47
48/**
49 * View showing the user's current browser downloads
50 */
Leon Scroggins24837452010-01-13 13:43:35 -050051public class BrowserDownloadPage extends ExpandableListActivity {
Leon Scroggins24837452010-01-13 13:43:35 -050052 private ExpandableListView mListView;
The Android Open Source Project0c908882009-03-03 19:32:16 -080053 private Cursor mDownloadCursor;
54 private BrowserDownloadAdapter mDownloadAdapter;
55 private int mStatusColumnId;
56 private int mIdColumnId;
57 private int mTitleColumnId;
Leon Scroggins24837452010-01-13 13:43:35 -050058 private long mContextMenuPosition;
Leon Scrogginsd080b182010-02-26 14:16:41 -050059 // Used to update the ContextMenu if an item is being downloaded and the
60 // user opens the ContextMenu.
61 private ContentObserver mContentObserver;
62 // Only meaningful while a ContentObserver is registered. The ContextMenu
63 // will be reopened on this View.
64 private View mSelectedView;
65
The Android Open Source Project0c908882009-03-03 19:32:16 -080066 @Override
67 public void onCreate(Bundle icicle) {
68 super.onCreate(icicle);
69 setContentView(R.layout.browser_downloads_page);
70
71 setTitle(getText(R.string.download_title));
72
Leon Scroggins24837452010-01-13 13:43:35 -050073 mListView = (ExpandableListView) findViewById(android.R.id.list);
Mihai Preda83817df2009-04-28 14:24:47 +020074 mListView.setEmptyView(findViewById(R.id.empty));
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -080075 mDownloadCursor = managedQuery(Downloads.Impl.CONTENT_URI,
Leon Scrogginsfedc4932010-01-26 14:15:01 -050076 new String [] {Downloads.Impl._ID, Downloads.Impl.COLUMN_TITLE,
77 Downloads.Impl.COLUMN_STATUS, Downloads.Impl.COLUMN_TOTAL_BYTES,
78 Downloads.Impl.COLUMN_CURRENT_BYTES,
79 Downloads.Impl.COLUMN_DESCRIPTION,
80 Downloads.Impl.COLUMN_NOTIFICATION_PACKAGE,
81 Downloads.Impl.COLUMN_LAST_MODIFICATION,
82 Downloads.Impl.COLUMN_VISIBILITY,
Leon Scrogginsb67db6b2010-02-26 17:58:31 -050083 Downloads.Impl._DATA,
Leon Scrogginsfedc4932010-01-26 14:15:01 -050084 Downloads.Impl.COLUMN_MIME_TYPE},
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -080085 null, Downloads.Impl.COLUMN_LAST_MODIFICATION + " DESC");
The Android Open Source Project0c908882009-03-03 19:32:16 -080086
87 // only attach everything to the listbox if we can access
88 // the download database. Otherwise, just show it empty
89 if (mDownloadCursor != null) {
90 mStatusColumnId =
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -080091 mDownloadCursor.getColumnIndexOrThrow(Downloads.Impl.COLUMN_STATUS);
The Android Open Source Project0c908882009-03-03 19:32:16 -080092 mIdColumnId =
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -080093 mDownloadCursor.getColumnIndexOrThrow(Downloads.Impl._ID);
The Android Open Source Project0c908882009-03-03 19:32:16 -080094 mTitleColumnId =
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -080095 mDownloadCursor.getColumnIndexOrThrow(Downloads.Impl.COLUMN_TITLE);
The Android Open Source Project0c908882009-03-03 19:32:16 -080096
97 // Create a list "controller" for the data
98 mDownloadAdapter = new BrowserDownloadAdapter(this,
Leon Scroggins24837452010-01-13 13:43:35 -050099 mDownloadCursor, mDownloadCursor.getColumnIndexOrThrow(
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -0800100 Downloads.Impl.COLUMN_LAST_MODIFICATION));
Mihai Preda83817df2009-04-28 14:24:47 +0200101
Leon Scroggins24837452010-01-13 13:43:35 -0500102 setListAdapter(mDownloadAdapter);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800103 mListView.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
104 mListView.setOnCreateContextMenuListener(this);
Leon Scroggins24837452010-01-13 13:43:35 -0500105
The Android Open Source Project0c908882009-03-03 19:32:16 -0800106 Intent intent = getIntent();
Leon Scroggins24837452010-01-13 13:43:35 -0500107 final int groupToShow = intent == null || intent.getData() == null
108 ? 0 : checkStatus(ContentUris.parseId(intent.getData()));
109 if (mDownloadAdapter.getGroupCount() > groupToShow) {
110 mListView.post(new Runnable() {
111 public void run() {
112 if (mDownloadAdapter.getGroupCount() > groupToShow) {
113 mListView.expandGroup(groupToShow);
114 }
115 }
116 });
The Android Open Source Project0c908882009-03-03 19:32:16 -0800117 }
118 }
119 }
Leon Scrogginsfedc4932010-01-26 14:15:01 -0500120
The Android Open Source Project0c908882009-03-03 19:32:16 -0800121 @Override
Leon Scrogginsb67db6b2010-02-26 17:58:31 -0500122 protected void onResume() {
123 super.onResume();
124 if (mDownloadCursor != null) {
125 String where = null;
126 for (mDownloadCursor.moveToFirst(); !mDownloadCursor.isAfterLast();
127 mDownloadCursor.moveToNext()) {
128 if (!Downloads.Impl.isStatusCompleted(
129 mDownloadCursor.getInt(mStatusColumnId))) {
130 // Only want to check files that have completed.
131 continue;
132 }
133 int filenameColumnId = mDownloadCursor.getColumnIndexOrThrow(
134 Downloads.Impl._DATA);
135 String filename = mDownloadCursor.getString(filenameColumnId);
136 File file = new File(filename);
137 if (!file.exists()) {
138 long id = mDownloadCursor.getLong(mIdColumnId);
139 if (where == null) {
140 where = Downloads.Impl._ID + " = '" + id + "'";
141 } else {
142 where += " OR " + Downloads.Impl._ID + " = '" + id + "'";
143 }
144 }
145 }
146 if (where != null) {
147 getContentResolver().delete(Downloads.Impl.CONTENT_URI, where,
148 null);
149 }
150 }
151 }
152
153 @Override
The Android Open Source Project0c908882009-03-03 19:32:16 -0800154 public boolean onCreateOptionsMenu(Menu menu) {
155 if (mDownloadCursor != null) {
156 MenuInflater inflater = getMenuInflater();
157 inflater.inflate(R.menu.downloadhistory, menu);
158 }
159 return true;
160 }
161
162 @Override
163 public boolean onPrepareOptionsMenu(Menu menu) {
164 boolean showCancel = getCancelableCount() > 0;
165 menu.findItem(R.id.download_menu_cancel_all).setEnabled(showCancel);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800166 return super.onPrepareOptionsMenu(menu);
167 }
168
169 @Override
170 public boolean onOptionsItemSelected(MenuItem item) {
171 switch (item.getItemId()) {
172 case R.id.download_menu_cancel_all:
173 promptCancelAll();
174 return true;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800175 }
176 return false;
177 }
178
Leon Scroggins9be17332010-01-14 15:44:06 -0500179 /**
180 * Remove the file from the list of downloads.
181 * @param id Unique ID of the download to remove.
182 */
183 private void clearFromDownloads(long id) {
184 getContentResolver().delete(ContentUris.withAppendedId(
185 Downloads.Impl.CONTENT_URI, id), null, null);
186 }
187
The Android Open Source Project0c908882009-03-03 19:32:16 -0800188 @Override
189 public boolean onContextItemSelected(MenuItem item) {
Leon Scroggins24837452010-01-13 13:43:35 -0500190 if (!mDownloadAdapter.moveCursorToPackedChildPosition(
191 mContextMenuPosition)) {
192 return false;
193 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800194 switch (item.getItemId()) {
195 case R.id.download_menu_open:
196 hideCompletedDownload();
Leon Scrogginsfedc4932010-01-26 14:15:01 -0500197 openOrDeleteCurrentDownload(false);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800198 return true;
Leon Scroggins9be17332010-01-14 15:44:06 -0500199
200 case R.id.download_menu_delete:
Leon Scroggins9be17332010-01-14 15:44:06 -0500201 new AlertDialog.Builder(this)
202 .setTitle(R.string.download_delete_file)
203 .setIcon(android.R.drawable.ic_dialog_alert)
Leon Scrogginsfedc4932010-01-26 14:15:01 -0500204 .setMessage(mDownloadCursor.getString(mTitleColumnId))
Leon Scroggins9be17332010-01-14 15:44:06 -0500205 .setNegativeButton(R.string.cancel, null)
206 .setPositiveButton(R.string.ok,
207 new DialogInterface.OnClickListener() {
208 public void onClick(DialogInterface dialog,
209 int whichButton) {
Leon Scrogginsfedc4932010-01-26 14:15:01 -0500210 openOrDeleteCurrentDownload(true);
Leon Scroggins9be17332010-01-14 15:44:06 -0500211 }
212 })
213 .show();
214 break;
215
The Android Open Source Project0c908882009-03-03 19:32:16 -0800216 case R.id.download_menu_clear:
217 case R.id.download_menu_cancel:
Leon Scroggins9be17332010-01-14 15:44:06 -0500218 clearFromDownloads(mDownloadCursor.getLong(mIdColumnId));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800219 return true;
220 }
221 return false;
222 }
223
224 @Override
Leon Scrogginsd080b182010-02-26 14:16:41 -0500225 protected void onPause() {
226 super.onPause();
227 if (mContentObserver != null) {
228 getContentResolver().unregisterContentObserver(mContentObserver);
229 // Note that we do not need to undo this in onResume, because the
230 // ContextMenu does not get reinvoked when the Activity resumes.
231 }
232 }
233
234 /*
235 * ContentObserver to update the ContextMenu if it is open when the
236 * corresponding download completes.
237 */
238 private class ChangeObserver extends ContentObserver {
239 private final Uri mTrack;
240 public ChangeObserver(Uri track) {
241 super(new Handler());
242 mTrack = track;
243 }
244
245 @Override
246 public boolean deliverSelfNotifications() {
247 return false;
248 }
249
250 @Override
251 public void onChange(boolean selfChange) {
252 Cursor cursor = getContentResolver().query(mTrack,
253 new String[] { Downloads.Impl.COLUMN_STATUS }, null, null,
254 null);
255 if (cursor.moveToFirst() && Downloads.Impl.isStatusSuccess(
256 cursor.getInt(0))) {
257 // Do this right away, so we get no more updates.
258 getContentResolver().unregisterContentObserver(
259 mContentObserver);
260 // Post a runnable in case this ContentObserver gets notified
261 // before the one that updates the ListView.
262 mListView.post(new Runnable() {
263 public void run() {
264 // Close the context menu, reopen with up to date data.
265 closeContextMenu();
266 openContextMenu(mSelectedView);
267 }
268 });
269 }
270 cursor.deactivate();
271 }
272 }
273
274 @Override
The Android Open Source Project0c908882009-03-03 19:32:16 -0800275 public void onCreateContextMenu(ContextMenu menu, View v,
276 ContextMenuInfo menuInfo) {
277 if (mDownloadCursor != null) {
Leon Scroggins24837452010-01-13 13:43:35 -0500278 ExpandableListView.ExpandableListContextMenuInfo info
279 = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
280 long packedPosition = info.packedPosition;
281 // Only show a context menu for the child views
282 if (!mDownloadAdapter.moveCursorToPackedChildPosition(
283 packedPosition)) {
284 return;
285 }
286 mContextMenuPosition = packedPosition;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800287 menu.setHeaderTitle(mDownloadCursor.getString(mTitleColumnId));
288
289 MenuInflater inflater = getMenuInflater();
290 int status = mDownloadCursor.getInt(mStatusColumnId);
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -0800291 if (Downloads.Impl.isStatusSuccess(status)) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800292 inflater.inflate(R.menu.downloadhistorycontextfinished, menu);
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -0800293 } else if (Downloads.Impl.isStatusError(status)) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800294 inflater.inflate(R.menu.downloadhistorycontextfailed, menu);
295 } else {
Leon Scrogginsd080b182010-02-26 14:16:41 -0500296 // In this case, the download is in progress. Set a
297 // ContentObserver so that we can know when it completes,
298 // and if it does, we can then update the context menu
299 Uri track = ContentUris.withAppendedId(
300 Downloads.Impl.CONTENT_URI,
301 mDownloadCursor.getLong(mIdColumnId));
302 if (mContentObserver != null) {
303 getContentResolver().unregisterContentObserver(
304 mContentObserver);
305 }
306 mContentObserver = new ChangeObserver(track);
307 mSelectedView = v;
308 getContentResolver().registerContentObserver(track, false,
309 mContentObserver);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800310 inflater.inflate(R.menu.downloadhistorycontextrunning, menu);
311 }
312 }
Leon Scroggins24837452010-01-13 13:43:35 -0500313 super.onCreateContextMenu(menu, v, menuInfo);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800314 }
315
316 /**
317 * This function is called to check the status of the download and if it
318 * has an error show an error dialog.
319 * @param id Row id of the download to check
Leon Scroggins24837452010-01-13 13:43:35 -0500320 * @return Group which contains the download
The Android Open Source Project0c908882009-03-03 19:32:16 -0800321 */
Leon Scroggins24837452010-01-13 13:43:35 -0500322 private int checkStatus(final long id) {
323 int groupToShow = mDownloadAdapter.groupFromChildId(id);
324 if (-1 == groupToShow) return 0;
325 int status = mDownloadCursor.getInt(mStatusColumnId);
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -0800326 if (!Downloads.Impl.isStatusError(status)) {
Leon Scroggins24837452010-01-13 13:43:35 -0500327 return groupToShow;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800328 }
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -0800329 if (status == Downloads.Impl.STATUS_FILE_ERROR) {
Leon Scroggins24837452010-01-13 13:43:35 -0500330 String title = mDownloadCursor.getString(mTitleColumnId);
331 if (title == null || title.length() == 0) {
332 title = getString(R.string.download_unknown_filename);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800333 }
Leon Scroggins24837452010-01-13 13:43:35 -0500334 String msg = getString(R.string.download_file_error_dlg_msg, title);
335 new AlertDialog.Builder(this)
336 .setTitle(R.string.download_file_error_dlg_title)
337 .setIcon(android.R.drawable.ic_popup_disk_full)
338 .setMessage(msg)
339 .setPositiveButton(R.string.ok, null)
340 .setNegativeButton(R.string.retry,
341 new DialogInterface.OnClickListener() {
342 public void onClick(DialogInterface dialog,
343 int whichButton) {
344 resumeDownload(id);
345 }
346 })
347 .show();
348 } else {
349 new AlertDialog.Builder(this)
350 .setTitle(R.string.download_failed_generic_dlg_title)
351 .setIcon(R.drawable.ssl_icon)
352 .setMessage(BrowserDownloadAdapter.getErrorText(status))
353 .setPositiveButton(R.string.ok, null)
354 .show();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800355 }
Leon Scroggins24837452010-01-13 13:43:35 -0500356 return groupToShow;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800357 }
358
359 /**
360 * Resume a given download
361 * @param id Row id of the download to resume
362 */
363 private void resumeDownload(final long id) {
364 // the relevant functionality doesn't exist in the download manager
365 }
366
367 /**
The Android Open Source Project0c908882009-03-03 19:32:16 -0800368 * Return the number of items in the list that can be canceled.
369 * @return count
370 */
371 private int getCancelableCount() {
372 // Count the number of items that will be canceled.
373 int count = 0;
374 if (mDownloadCursor != null) {
Leon Scrogginsb67db6b2010-02-26 17:58:31 -0500375 for (mDownloadCursor.moveToFirst(); !mDownloadCursor.isAfterLast();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800376 mDownloadCursor.moveToNext()) {
377 int status = mDownloadCursor.getInt(mStatusColumnId);
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -0800378 if (!Downloads.Impl.isStatusCompleted(status)) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800379 count++;
380 }
381 }
382 }
383
384 return count;
385 }
386
387 /**
388 * Prompt the user if they would like to clear the download history
389 */
390 private void promptCancelAll() {
391 int count = getCancelableCount();
392
393 // If there is nothing to do, just return
394 if (count == 0) {
395 return;
396 }
397
398 // Don't show the dialog if there is only one download
399 if (count == 1) {
400 cancelAllDownloads();
401 return;
402 }
403 String msg =
404 getString(R.string.download_cancel_dlg_msg, count);
405 new AlertDialog.Builder(this)
406 .setTitle(R.string.download_cancel_dlg_title)
407 .setIcon(R.drawable.ssl_icon)
408 .setMessage(msg)
409 .setPositiveButton(R.string.ok,
410 new DialogInterface.OnClickListener() {
411 public void onClick(DialogInterface dialog,
412 int whichButton) {
413 cancelAllDownloads();
414 }
415 })
416 .setNegativeButton(R.string.cancel, null)
417 .show();
418 }
419
420 /**
421 * Cancel all downloads. As canceled downloads are not
422 * listed, we removed them from the db. Removing a download
423 * record, cancels the download.
424 */
425 private void cancelAllDownloads() {
426 if (mDownloadCursor.moveToFirst()) {
427 StringBuilder where = new StringBuilder();
428 boolean firstTime = true;
429 while (!mDownloadCursor.isAfterLast()) {
430 int status = mDownloadCursor.getInt(mStatusColumnId);
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -0800431 if (!Downloads.Impl.isStatusCompleted(status)) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800432 if (firstTime) {
433 firstTime = false;
434 } else {
435 where.append(" OR ");
436 }
437 where.append("( ");
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -0800438 where.append(Downloads.Impl._ID);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800439 where.append(" = '");
440 where.append(mDownloadCursor.getLong(mIdColumnId));
441 where.append("' )");
442 }
443 mDownloadCursor.moveToNext();
444 }
445 if (!firstTime) {
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -0800446 getContentResolver().delete(Downloads.Impl.CONTENT_URI,
The Android Open Source Project0c908882009-03-03 19:32:16 -0800447 where.toString(), null);
448 }
449 }
450 }
451
452 private int getClearableCount() {
453 int count = 0;
454 if (mDownloadCursor.moveToFirst()) {
455 while (!mDownloadCursor.isAfterLast()) {
456 int status = mDownloadCursor.getInt(mStatusColumnId);
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -0800457 if (Downloads.Impl.isStatusCompleted(status)) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800458 count++;
459 }
460 mDownloadCursor.moveToNext();
461 }
462 }
463 return count;
464 }
Leon Scroggins4cf7de02010-01-21 10:05:59 -0500465
The Android Open Source Project0c908882009-03-03 19:32:16 -0800466 /**
Leon Scrogginsfedc4932010-01-26 14:15:01 -0500467 * Open or delete content where the download db cursor currently is. Sends
468 * an Intent to perform the action.
469 * @param delete If true, delete the content. Otherwise open it.
The Android Open Source Project0c908882009-03-03 19:32:16 -0800470 */
Leon Scrogginsfedc4932010-01-26 14:15:01 -0500471 private void openOrDeleteCurrentDownload(boolean delete) {
472 int packageColumnId = mDownloadCursor.getColumnIndexOrThrow(
473 Downloads.Impl.COLUMN_NOTIFICATION_PACKAGE);
474 String packageName = mDownloadCursor.getString(packageColumnId);
475 Intent intent = new Intent(delete ? Intent.ACTION_DELETE
476 : Downloads.Impl.ACTION_NOTIFICATION_CLICKED);
477 Uri contentUri = ContentUris.withAppendedId(
478 Downloads.Impl.CONTENT_URI,
479 mDownloadCursor.getLong(mIdColumnId));
480 intent.setData(contentUri);
481 intent.setPackage(packageName);
482 sendBroadcast(intent);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800483 }
484
Leon Scroggins24837452010-01-13 13:43:35 -0500485 @Override
486 public boolean onChildClick(ExpandableListView parent, View v,
487 int groupPosition, int childPosition, long id) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800488 // Open the selected item
Leon Scroggins24837452010-01-13 13:43:35 -0500489 mDownloadAdapter.moveCursorToChildPosition(groupPosition,
490 childPosition);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800491
492 hideCompletedDownload();
493
494 int status = mDownloadCursor.getInt(mStatusColumnId);
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -0800495 if (Downloads.Impl.isStatusSuccess(status)) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800496 // Open it if it downloaded successfully
Leon Scrogginsfedc4932010-01-26 14:15:01 -0500497 openOrDeleteCurrentDownload(false);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800498 } else {
499 // Check to see if there is an error.
500 checkStatus(id);
501 }
Leon Scroggins24837452010-01-13 13:43:35 -0500502 return true;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800503 }
504
505 /**
506 * hides the notification for the download pointed by mDownloadCursor
507 * if the download has completed.
508 */
509 private void hideCompletedDownload() {
510 int status = mDownloadCursor.getInt(mStatusColumnId);
511
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -0800512 int visibilityColumn = mDownloadCursor.getColumnIndexOrThrow(
513 Downloads.Impl.COLUMN_VISIBILITY);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800514 int visibility = mDownloadCursor.getInt(visibilityColumn);
515
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -0800516 if (Downloads.Impl.isStatusCompleted(status) &&
517 visibility == Downloads.Impl.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800518 ContentValues values = new ContentValues();
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -0800519 values.put(Downloads.Impl.COLUMN_VISIBILITY, Downloads.Impl.VISIBILITY_VISIBLE);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800520 getContentResolver().update(
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -0800521 ContentUris.withAppendedId(Downloads.Impl.CONTENT_URI,
The Android Open Source Project0c908882009-03-03 19:32:16 -0800522 mDownloadCursor.getLong(mIdColumnId)), values, null, null);
523 }
524 }
525}