1 /* 2 * Copyright (C) 2011 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 android.holo.cts; 18 19 import com.android.cts.holo.R; 20 21 import android.app.Activity; 22 import android.app.AlertDialog; 23 import android.app.Dialog; 24 import android.app.ProgressDialog; 25 import android.content.DialogInterface; 26 import android.os.AsyncTask; 27 import android.os.Bundle; 28 29 /** 30 * {@link Activity} that iterates over all the test layouts for a single theme 31 * and either compares or generates bitmaps. 32 */ 33 public class BitmapDeletionActivity extends Activity { 34 35 static final String EXTRA_BITMAP_TYPE = "bitmapType"; 36 37 private static final int DIALOG_DELETING_ID = 1; 38 private static final int DIALOG_FINISHED_DELETING_ID = 2; 39 private static final int DIALOG_ERROR_DELETING_ID = 3; 40 41 private int mBitmapType; 42 43 @Override 44 protected void onCreate(Bundle savedInstanceState) { 45 super.onCreate(savedInstanceState); 46 mBitmapType = getIntent().getIntExtra(EXTRA_BITMAP_TYPE, -1); 47 new DeleteBitmapsTask().execute(); 48 } 49 50 class DeleteBitmapsTask extends AsyncTask<Void, Void, Boolean> { 51 52 @Override 53 protected void onPreExecute() { 54 super.onPreExecute(); 55 showDialog(DIALOG_DELETING_ID); 56 } 57 58 @Override 59 protected Boolean doInBackground(Void... darthVoider) { 60 return BitmapAssets.clearDirectory(mBitmapType); 61 } 62 63 @Override 64 protected void onPostExecute(Boolean success) { 65 dismissDialog(DIALOG_DELETING_ID); 66 showDialog(success ? DIALOG_FINISHED_DELETING_ID : DIALOG_ERROR_DELETING_ID); 67 } 68 } 69 70 @Override 71 protected Dialog onCreateDialog(int id, Bundle args) { 72 switch (id) { 73 case DIALOG_DELETING_ID: 74 ProgressDialog dialog = new ProgressDialog(BitmapDeletionActivity.this); 75 dialog.setMessage(getString(R.string.deleting_bitmaps)); 76 return dialog; 77 78 case DIALOG_FINISHED_DELETING_ID: 79 return createFinishingDialog(R.string.deleting_bitmaps_finished); 80 81 case DIALOG_ERROR_DELETING_ID: 82 return createFinishingDialog(R.string.deleting_bitmaps_error); 83 84 default: 85 return super.onCreateDialog(id, args); 86 } 87 } 88 89 private AlertDialog createFinishingDialog(int message) { 90 DialogInterface.OnClickListener finishListener = 91 new DialogInterface.OnClickListener() { 92 @Override 93 public void onClick(DialogInterface dialog, int which) { 94 finish(); 95 } 96 }; 97 return new AlertDialog.Builder(BitmapDeletionActivity.this) 98 .setMessage(message) 99 .setCancelable(false) 100 .setPositiveButton(android.R.string.ok, finishListener) 101 .create(); 102 } 103 } 104