1 /* 2 * Copyright (C) 2014 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.print.test.services; 18 19 import android.app.Activity; 20 import android.content.Intent; 21 import android.os.Bundle; 22 import android.print.PrintJobInfo; 23 import android.print.PrinterInfo; 24 import android.printservice.PrintService; 25 26 /** 27 * Custom print options activity for both print services 28 */ 29 public class CustomPrintOptionsActivity extends Activity { 30 /** Lock for {@link #sCallback} */ 31 private static final Object sLock = new Object(); 32 33 /** Currently registered callback for _both_ first and second print service. */ 34 private static CustomPrintOptionsCallback sCallback = null; 35 36 /** 37 * Set a new callback called when the custom options activity is launched. 38 * 39 * @param callback The new callback or null, if the callback should be unregistered. 40 */ setCallBack(CustomPrintOptionsCallback callback)41 public static void setCallBack(CustomPrintOptionsCallback callback) { 42 synchronized (sLock) { 43 sCallback = callback; 44 } 45 } 46 47 /** 48 * Callback executed for this activity. Set via {@link #setCallBack}. 49 */ 50 public interface CustomPrintOptionsCallback { executeCustomPrintOptionsActivity(PrintJobInfo printJob, PrinterInfo printer)51 PrintJobInfo executeCustomPrintOptionsActivity(PrintJobInfo printJob, 52 PrinterInfo printer); 53 } 54 55 @Override onCreate(Bundle savedInstanceState)56 protected void onCreate(Bundle savedInstanceState) { 57 super.onCreate(savedInstanceState); 58 59 Intent result = new Intent(); 60 61 synchronized (sLock) { 62 if (sCallback != null) { 63 PrintJobInfo printJobInfo = getIntent().getParcelableExtra( 64 PrintService.EXTRA_PRINT_JOB_INFO); 65 PrinterInfo printerInfo = getIntent().getParcelableExtra( 66 "android.intent.extra.print.EXTRA_PRINTER_INFO"); 67 68 result.putExtra(PrintService.EXTRA_PRINT_JOB_INFO, 69 sCallback.executeCustomPrintOptionsActivity(printJobInfo, printerInfo)); 70 } 71 } 72 73 setResult(Activity.RESULT_OK, result); 74 finish(); 75 } 76 } 77