Chih-Chung Chang | 0e48fe6 | 2009-06-26 19:23:56 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | |
| 17 | package com.android.camera; |
| 18 | |
| 19 | import android.app.Activity; |
Chih-Chung Chang | 0e48fe6 | 2009-06-26 19:23:56 +0800 | [diff] [blame] | 20 | import android.content.ContentResolver; |
| 21 | import android.content.Intent; |
| 22 | import android.net.Uri; |
| 23 | import android.os.Bundle; |
| 24 | import android.os.Handler; |
Chih-Chung Chang | 0e48fe6 | 2009-06-26 19:23:56 +0800 | [diff] [blame] | 25 | import android.widget.ProgressBar; |
| 26 | |
| 27 | import java.util.ArrayList; |
| 28 | |
| 29 | public class DeleteImage extends Activity { |
Owen Lin | 52aae70 | 2009-07-01 17:03:33 -0700 | [diff] [blame] | 30 | |
| 31 | @SuppressWarnings("unused") |
Chih-Chung Chang | 0e48fe6 | 2009-06-26 19:23:56 +0800 | [diff] [blame] | 32 | private static final String TAG = "DeleteImage"; |
| 33 | private ProgressBar mProgressBar; |
| 34 | private ArrayList<Uri> mUriList; // a list of image uri |
| 35 | private int mIndex = 0; // next image to delete |
Owen Lin | 52aae70 | 2009-07-01 17:03:33 -0700 | [diff] [blame] | 36 | private final Handler mHandler = new Handler(); |
| 37 | private final Runnable mDeleteNextRunnable = new Runnable() { |
Chih-Chung Chang | 0e48fe6 | 2009-06-26 19:23:56 +0800 | [diff] [blame] | 38 | public void run() { |
| 39 | deleteNext(); |
| 40 | } |
| 41 | }; |
| 42 | private ContentResolver mContentResolver; |
| 43 | private boolean mPausing; |
| 44 | |
| 45 | @Override |
| 46 | protected void onCreate(Bundle savedInstanceState) { |
| 47 | super.onCreate(savedInstanceState); |
| 48 | Intent intent = getIntent(); |
| 49 | mUriList = intent.getParcelableArrayListExtra("delete-uris"); |
| 50 | if (mUriList == null) { |
| 51 | finish(); |
| 52 | } |
| 53 | setContentView(R.layout.delete_image); |
| 54 | mProgressBar = (ProgressBar) findViewById(R.id.delete_progress); |
| 55 | mContentResolver = getContentResolver(); |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | protected void onResume() { |
| 60 | super.onResume(); |
| 61 | mPausing = false; |
| 62 | mHandler.post(mDeleteNextRunnable); |
| 63 | } |
| 64 | |
| 65 | private void deleteNext() { |
| 66 | if (mPausing) return; |
| 67 | if (mIndex >= mUriList.size()) { |
| 68 | finish(); |
| 69 | return; |
| 70 | } |
| 71 | Uri uri = mUriList.get(mIndex++); |
| 72 | // The max progress value of the bar is set to 10000 in the xml file. |
| 73 | mProgressBar.setProgress(mIndex * 10000 / mUriList.size()); |
| 74 | mContentResolver.delete(uri, null, null); |
| 75 | mHandler.post(mDeleteNextRunnable); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | protected void onPause() { |
| 80 | super.onPause(); |
| 81 | mPausing = true; |
| 82 | } |
| 83 | } |