• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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.settings.print;
18 
19 import android.app.settings.SettingsEnums;
20 import android.content.Context;
21 import android.os.Bundle;
22 import android.print.PrintJob;
23 import android.view.Menu;
24 import android.view.MenuInflater;
25 import android.view.MenuItem;
26 import android.view.View;
27 
28 import com.android.settings.R;
29 import com.android.settings.dashboard.DashboardFragment;
30 
31 /**
32  * Fragment for management of a print job.
33  */
34 public class PrintJobSettingsFragment extends DashboardFragment {
35     private static final String TAG = "PrintJobSettingsFragment";
36 
37     private static final int MENU_ITEM_ID_CANCEL = 1;
38     private static final int MENU_ITEM_ID_RESTART = 2;
39 
40     @Override
getPreferenceScreenResId()41     protected int getPreferenceScreenResId() {
42         return R.xml.print_job_settings;
43     }
44 
45     @Override
getLogTag()46     protected String getLogTag() {
47         return TAG;
48     }
49 
50     @Override
onAttach(Context context)51     public void onAttach(Context context) {
52         super.onAttach(context);
53         use(PrintJobPreferenceController.class).init(this);
54         use(PrintJobMessagePreferenceController.class).init(this);
55     }
56 
57     @Override
getMetricsCategory()58     public int getMetricsCategory() {
59         return SettingsEnums.PRINT_JOB_SETTINGS;
60     }
61 
62     @Override
onViewCreated(View view, Bundle savedInstanceState)63     public void onViewCreated(View view, Bundle savedInstanceState) {
64         super.onViewCreated(view, savedInstanceState);
65         getListView().setEnabled(false);
66     }
67 
68     @Override
onCreateOptionsMenu(Menu menu, MenuInflater inflater)69     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
70         super.onCreateOptionsMenu(menu, inflater);
71 
72         final PrintJob printJob = use(PrintJobPreferenceController.class).getPrintJob();
73         if (printJob == null) {
74             return;
75         }
76 
77         if (!printJob.getInfo().isCancelling()) {
78             MenuItem cancel = menu.add(0, MENU_ITEM_ID_CANCEL, Menu.NONE,
79                     getString(R.string.print_cancel));
80             cancel.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
81         }
82 
83         if (printJob.isFailed()) {
84             MenuItem restart = menu.add(0, MENU_ITEM_ID_RESTART, Menu.NONE,
85                     getString(R.string.print_restart));
86             restart.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
87         }
88     }
89 
90     @Override
onOptionsItemSelected(MenuItem item)91     public boolean onOptionsItemSelected(MenuItem item) {
92         final PrintJob printJob = use(PrintJobPreferenceController.class).getPrintJob();
93 
94         if (printJob != null) {
95             switch (item.getItemId()) {
96                 case MENU_ITEM_ID_CANCEL: {
97                     printJob.cancel();
98                     finish();
99                     return true;
100                 }
101 
102                 case MENU_ITEM_ID_RESTART: {
103                     printJob.restart();
104                     finish();
105                     return true;
106                 }
107             }
108         }
109 
110         return super.onOptionsItemSelected(item);
111     }
112 }
113