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