1package foo.bar.printservice; 2 3import android.app.ListActivity; 4import android.os.Bundle; 5import android.print.PrintJobId; 6import android.view.View; 7import android.widget.AdapterView; 8import android.widget.ArrayAdapter; 9 10public class MyDialogActivity extends ListActivity { 11 12 private static final int ITEM_INDEX_PRINT_NOW = 0; 13 private static final int ITEM_INDEX_PRINT_DELAYED = 1; 14 private static final int ITEM_INDEX_FAIL_NOW = 2; 15 private static final int ITEM_INDEX_FAIL_DELAYED = 3; 16 private static final int ITEM_INDEX_BLOCK_NOW = 4; 17 private static final int ITEM_INDEX_BLOCK_DELAYED = 5; 18 private static final int ITEM_INDEX_BLOCK_AND_DELAYED_UNBLOCK = 6; 19 private static final int ITEM_INDEX_PRINT_SLOWLY = 7; 20 21 private static final int ITEM_INDEX_CANCEL_YES = 0; 22 23 @Override 24 protected void onCreate(Bundle savedInstanceState) { 25 super.onCreate(savedInstanceState); 26 27 PrintJobId printJobId = getIntent().getParcelableExtra( 28 MyPrintService.INTENT_EXTRA_PRINT_JOB_ID); 29 final int actionType = getIntent().getIntExtra(MyPrintService.INTENT_EXTRA_ACTION_TYPE, 30 MyPrintService.ACTION_TYPE_ON_PRINT_JOB_PENDING); 31 32 if (actionType == MyPrintService.ACTION_TYPE_ON_PRINT_JOB_PENDING) { 33 createActionTypeOnPrintJobPendingUi(printJobId); 34 } else { 35 createActionTypeOnReqeustCancelPrintJobUi(printJobId); 36 } 37 } 38 39 private void createActionTypeOnPrintJobPendingUi(final PrintJobId printJobId) { 40 setTitle(getString(R.string.on_print_job_pending_activity_title)); 41 42 setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, 43 getResources().getStringArray(R.array.on_print_job_queued_actions))); 44 getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() { 45 @Override 46 public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 47 switch (position) { 48 case ITEM_INDEX_PRINT_NOW: { 49 MyPrintService.peekInstance().handleQueuedPrintJob(printJobId); 50 } break; 51 52 case ITEM_INDEX_PRINT_DELAYED: { 53 MyPrintService.peekInstance().handleQueuedPrintJobDelayed(printJobId); 54 } break; 55 56 case ITEM_INDEX_FAIL_NOW: { 57 MyPrintService.peekInstance().handleFailPrintJob(printJobId); 58 } break; 59 60 case ITEM_INDEX_FAIL_DELAYED: { 61 MyPrintService.peekInstance().handleFailPrintJobDelayed(printJobId); 62 } break; 63 64 case ITEM_INDEX_BLOCK_NOW: { 65 MyPrintService.peekInstance().handleBlockPrintJob(printJobId); 66 } break; 67 68 case ITEM_INDEX_BLOCK_DELAYED: { 69 MyPrintService.peekInstance().handleBlockPrintJobDelayed(printJobId); 70 } break; 71 72 case ITEM_INDEX_BLOCK_AND_DELAYED_UNBLOCK: { 73 MyPrintService.peekInstance().handleBlockAndDelayedUnblockPrintJob( 74 printJobId); 75 } break; 76 77 case ITEM_INDEX_PRINT_SLOWLY: { 78 MyPrintService.peekInstance().handlePrintJobProgress(printJobId, 0); 79 } break; 80 } 81 finishAndRemoveTask(); 82 } 83 }); 84 } 85 86 private void createActionTypeOnReqeustCancelPrintJobUi(final PrintJobId printJobId) { 87 setTitle(getString(R.string.on_cancle_print_job_requested_activity_title)); 88 89 setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, 90 getResources().getStringArray(R.array.on_request_cancel_print_job_actions))); 91 getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() { 92 @Override 93 public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 94 switch (position) { 95 case ITEM_INDEX_CANCEL_YES: { 96 MyPrintService.peekInstance().handleRequestCancelPrintJob(printJobId); 97 } break; 98 } 99 finishAndRemoveTask(); 100 } 101 }); 102 } 103} 104