16fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslavpackage foo.bar.printservice;
26fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav
36fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslavimport android.app.ListActivity;
46fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslavimport android.os.Bundle;
5f11598332008fd706ed17be975a0ff73ba7f6a21Svetoslav Ganovimport android.print.PrintJobId;
66fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslavimport android.view.View;
76fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslavimport android.widget.AdapterView;
86fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslavimport android.widget.ArrayAdapter;
96fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav
106fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslavpublic class MyDialogActivity extends ListActivity {
116fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav
126fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav    private static final int ITEM_INDEX_PRINT_NOW = 0;
136fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav    private static final int ITEM_INDEX_PRINT_DELAYED = 1;
146fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav    private static final int ITEM_INDEX_FAIL_NOW = 2;
156fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav    private static final int ITEM_INDEX_FAIL_DELAYED = 3;
163bb4d60425207dad4241d0565ff0c4a20dca119dSvetoslav Ganov    private static final int ITEM_INDEX_BLOCK_NOW = 4;
173bb4d60425207dad4241d0565ff0c4a20dca119dSvetoslav Ganov    private static final int ITEM_INDEX_BLOCK_DELAYED = 5;
183bb4d60425207dad4241d0565ff0c4a20dca119dSvetoslav Ganov    private static final int ITEM_INDEX_BLOCK_AND_DELAYED_UNBLOCK = 6;
199981caa9c40383230c2e08fade7cbe03e2d96125Philip P. Moltmann    private static final int ITEM_INDEX_PRINT_SLOWLY = 7;
206fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav
216fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav    private static final int ITEM_INDEX_CANCEL_YES = 0;
226fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav
236fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav    @Override
246fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav    protected void onCreate(Bundle savedInstanceState) {
256fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav        super.onCreate(savedInstanceState);
266fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav
27f11598332008fd706ed17be975a0ff73ba7f6a21Svetoslav Ganov        PrintJobId printJobId = getIntent().getParcelableExtra(
28f11598332008fd706ed17be975a0ff73ba7f6a21Svetoslav Ganov                MyPrintService.INTENT_EXTRA_PRINT_JOB_ID);
296fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav        final int actionType = getIntent().getIntExtra(MyPrintService.INTENT_EXTRA_ACTION_TYPE,
306fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav                MyPrintService.ACTION_TYPE_ON_PRINT_JOB_PENDING);
316fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav
326fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav        if (actionType == MyPrintService.ACTION_TYPE_ON_PRINT_JOB_PENDING) {
336fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav            createActionTypeOnPrintJobPendingUi(printJobId);
346fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav        } else {
356fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav            createActionTypeOnReqeustCancelPrintJobUi(printJobId);
366fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav        }
376fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav    }
386fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav
39f11598332008fd706ed17be975a0ff73ba7f6a21Svetoslav Ganov    private void createActionTypeOnPrintJobPendingUi(final PrintJobId printJobId) {
406fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav        setTitle(getString(R.string.on_print_job_pending_activity_title));
416fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav
42002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann        setListAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,
436fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav                getResources().getStringArray(R.array.on_print_job_queued_actions)));
44002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann        getListView().setOnItemClickListener((parent, view, position, id) -> {
45002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann            switch (position) {
46002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                case ITEM_INDEX_PRINT_NOW: {
47002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                    MyPrintService.peekInstance().handleQueuedPrintJob(printJobId);
48002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                } break;
49002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann
50002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                case ITEM_INDEX_PRINT_DELAYED: {
51002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                    MyPrintService.peekInstance().handleQueuedPrintJobDelayed(printJobId);
52002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                } break;
53002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann
54002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                case ITEM_INDEX_FAIL_NOW: {
55002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                    MyPrintService.peekInstance().handleFailPrintJob(printJobId);
56002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                } break;
57002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann
58002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                case ITEM_INDEX_FAIL_DELAYED: {
59002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                    MyPrintService.peekInstance().handleFailPrintJobDelayed(printJobId);
60002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                } break;
61002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann
62002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                case ITEM_INDEX_BLOCK_NOW: {
63002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                    MyPrintService.peekInstance().handleBlockPrintJob(printJobId);
64002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                } break;
65002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann
66002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                case ITEM_INDEX_BLOCK_DELAYED: {
67002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                    MyPrintService.peekInstance().handleBlockPrintJobDelayed(printJobId);
68002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                } break;
69002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann
70002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                case ITEM_INDEX_BLOCK_AND_DELAYED_UNBLOCK: {
71002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                    MyPrintService.peekInstance().handleBlockAndDelayedUnblockPrintJob(
72002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                            printJobId);
73002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                } break;
74002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann
75002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                case ITEM_INDEX_PRINT_SLOWLY: {
76002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                    MyPrintService.peekInstance().handlePrintJobProgress(printJobId, 0);
77002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                } break;
786fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav            }
79002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann            finishAndRemoveTask();
806fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav        });
816fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav    }
826fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav
83f11598332008fd706ed17be975a0ff73ba7f6a21Svetoslav Ganov    private void createActionTypeOnReqeustCancelPrintJobUi(final PrintJobId printJobId) {
846fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav        setTitle(getString(R.string.on_cancle_print_job_requested_activity_title));
856fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav
86002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann        setListAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,
876fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav                getResources().getStringArray(R.array.on_request_cancel_print_job_actions)));
88002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann        getListView().setOnItemClickListener((parent, view, position, id) -> {
89002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann            switch (position) {
90002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                case ITEM_INDEX_CANCEL_YES: {
91002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                    MyPrintService.peekInstance().handleRequestCancelPrintJob(printJobId);
92002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann                } break;
936fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav            }
94002df26c21a78353d33705bb076ac61a09400095Philip P. Moltmann            finishAndRemoveTask();
956fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav        });
966fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav    }
976fc52023a04fe45b6f59212fc716cbbcf76f35fcSvetoslav}
98