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