1 /* 2 * Copyright (C) 2017 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.bips.ui; 18 19 import android.content.Context; 20 import android.preference.Preference; 21 22 import com.android.bips.BuiltInPrintService; 23 import com.android.bips.R; 24 import com.android.bips.discovery.DiscoveredPrinter; 25 26 class PrinterPreference extends Preference { 27 private final BuiltInPrintService mPrintService; 28 private DiscoveredPrinter mPrinter; 29 private boolean mAdding = false; 30 PrinterPreference(Context context, BuiltInPrintService printService, DiscoveredPrinter printer, boolean adding)31 PrinterPreference(Context context, BuiltInPrintService printService, 32 DiscoveredPrinter printer, boolean adding) { 33 super(context); 34 mPrintService = printService; 35 mPrinter = printer; 36 mAdding = adding; 37 updatePrinter(printer); 38 } 39 updatePrinter(DiscoveredPrinter printer)40 void updatePrinter(DiscoveredPrinter printer) { 41 mPrinter = printer; 42 setLayoutResource(R.layout.printer_item); 43 if (mAdding) { 44 setTitle(getContext().getString(R.string.add_named, printer.name)); 45 } else { 46 setTitle(printer.name); 47 } 48 49 setSummary(mPrintService.getDescription(printer)); 50 setIcon(R.drawable.ic_printer); 51 } 52 getPrinter()53 DiscoveredPrinter getPrinter() { 54 return mPrinter; 55 } 56 } 57