blob: 3a134662dc8d7679fc5ec361a37f9abcb1bdefcd [file] [log] [blame]
Chih-Chung Chang0e48fe62009-06-26 19:23:56 +08001/*
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
17package com.android.camera;
18
19import android.app.Activity;
Chih-Chung Chang0e48fe62009-06-26 19:23:56 +080020import android.content.ContentResolver;
21import android.content.Intent;
22import android.net.Uri;
23import android.os.Bundle;
24import android.os.Handler;
Chih-Chung Chang0e48fe62009-06-26 19:23:56 +080025import android.widget.ProgressBar;
26
27import java.util.ArrayList;
28
29public class DeleteImage extends Activity {
Owen Lin52aae702009-07-01 17:03:33 -070030
31 @SuppressWarnings("unused")
Chih-Chung Chang0e48fe62009-06-26 19:23:56 +080032 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 Lin52aae702009-07-01 17:03:33 -070036 private final Handler mHandler = new Handler();
37 private final Runnable mDeleteNextRunnable = new Runnable() {
Chih-Chung Chang0e48fe62009-06-26 19:23:56 +080038 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}