Printers in the list of printers change position.
1. The printers in the printers list of settings change position if they are updated. The settings app is using hidden platform APIs the this change fixes. 2. Enable ProGuard for the PrintSpooler. 3. Added icons on the list of printers so the user knows which print service used the printer. Now the user can know when he is using cloud print and maybe incurring data costs vs local printer discovered by a vendor plug in. bug:10955751 Change-Id: I292f48b424cb561218fdb424d0388f4d786d8339
This commit is contained in:
@@ -192,22 +192,46 @@ public final class PrinterDiscoverySession {
|
||||
}
|
||||
}
|
||||
|
||||
private void handlePrintersAdded(List<PrinterInfo> printers) {
|
||||
private void handlePrintersAdded(List<PrinterInfo> addedPrinters) {
|
||||
if (isDestroyed()) {
|
||||
return;
|
||||
}
|
||||
boolean printersChanged = false;
|
||||
final int addedPrinterCount = printers.size();
|
||||
for (int i = 0; i < addedPrinterCount; i++) {
|
||||
PrinterInfo addedPrinter = printers.get(i);
|
||||
PrinterInfo oldPrinter = mPrinters.put(addedPrinter.getId(), addedPrinter);
|
||||
if (oldPrinter == null || !oldPrinter.equals(addedPrinter)) {
|
||||
printersChanged = true;
|
||||
|
||||
// No old printers - do not bother keeping their position.
|
||||
if (mPrinters.isEmpty()) {
|
||||
final int printerCount = addedPrinters.size();
|
||||
for (int i = 0; i < printerCount; i++) {
|
||||
PrinterInfo printer = addedPrinters.get(i);
|
||||
mPrinters.put(printer.getId(), printer);
|
||||
}
|
||||
notifyOnPrintersChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
// Add the printers to a map.
|
||||
ArrayMap<PrinterId, PrinterInfo> addedPrintersMap =
|
||||
new ArrayMap<PrinterId, PrinterInfo>();
|
||||
final int printerCount = addedPrinters.size();
|
||||
for (int i = 0; i < printerCount; i++) {
|
||||
PrinterInfo printer = addedPrinters.get(i);
|
||||
addedPrintersMap.put(printer.getId(), printer);
|
||||
}
|
||||
|
||||
// Update printers we already have.
|
||||
final int oldPrinterCount = mPrinters.size();
|
||||
for (int i = 0; i < oldPrinterCount; i++) {
|
||||
PrinterId oldPrinterId = mPrinters.keyAt(i);
|
||||
PrinterInfo updatedPrinter = addedPrintersMap.remove(oldPrinterId);
|
||||
if (updatedPrinter != null) {
|
||||
mPrinters.put(oldPrinterId, updatedPrinter);
|
||||
}
|
||||
}
|
||||
if (printersChanged) {
|
||||
notifyOnPrintersChanged();
|
||||
}
|
||||
|
||||
// Add the new printers, i.e. what is left.
|
||||
mPrinters.putAll(addedPrintersMap);
|
||||
|
||||
// Announce the change.
|
||||
notifyOnPrintersChanged();
|
||||
}
|
||||
|
||||
private void handlePrintersRemoved(List<PrinterId> printerIds) {
|
||||
|
||||
@@ -24,7 +24,4 @@ LOCAL_PACKAGE_NAME := PrintSpooler
|
||||
|
||||
LOCAL_JAVA_LIBRARIES := framework-base
|
||||
|
||||
LOCAL_PROGUARD_ENABLED := disabled
|
||||
|
||||
include $(BUILD_PACKAGE)
|
||||
|
||||
|
||||
70
packages/PrintSpooler/res/layout/printer_dropdown_item.xml
Normal file
70
packages/PrintSpooler/res/layout/printer_dropdown_item.xml
Normal file
@@ -0,0 +1,70 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2013 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="16dip"
|
||||
android:paddingEnd="16dip"
|
||||
android:minHeight="?android:attr/listPreferredItemHeightSmall"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="start|center_vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="32dip"
|
||||
android:layout_height="32dip"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginEnd="8dip"
|
||||
android:duplicateParentState="true"
|
||||
android:contentDescription="@null"
|
||||
android:visibility="gone">
|
||||
</ImageView>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="end"
|
||||
android:textIsSelectable="false"
|
||||
android:gravity="top|start"
|
||||
android:textColor="@color/item_text_color"
|
||||
android:duplicateParentState="true">
|
||||
</TextView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/subtitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="end"
|
||||
android:textIsSelectable="false"
|
||||
android:visibility="gone"
|
||||
android:textColor="@color/print_option_title"
|
||||
android:duplicateParentState="true">
|
||||
</TextView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -75,11 +75,10 @@ import android.widget.ArrayAdapter;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import libcore.io.IoUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -96,6 +95,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import libcore.io.IoUtils;
|
||||
|
||||
/**
|
||||
* Activity for configuring a print job.
|
||||
*/
|
||||
@@ -2066,11 +2067,12 @@ public class PrintJobConfigActivity extends Activity {
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
if (convertView == null) {
|
||||
convertView = getLayoutInflater().inflate(
|
||||
R.layout.spinner_dropdown_item, parent, false);
|
||||
R.layout.printer_dropdown_item, parent, false);
|
||||
}
|
||||
|
||||
CharSequence title = null;
|
||||
CharSequence subtitle = null;
|
||||
Drawable icon = null;
|
||||
|
||||
if (mPrinters.isEmpty()) {
|
||||
if (position == 0) {
|
||||
@@ -2092,6 +2094,7 @@ public class PrintJobConfigActivity extends Activity {
|
||||
PackageInfo packageInfo = getPackageManager().getPackageInfo(
|
||||
printer.getId().getServiceName().getPackageName(), 0);
|
||||
subtitle = packageInfo.applicationInfo.loadLabel(getPackageManager());
|
||||
icon = packageInfo.applicationInfo.loadIcon(getPackageManager());
|
||||
} catch (NameNotFoundException nnfe) {
|
||||
/* ignore */
|
||||
}
|
||||
@@ -2110,6 +2113,14 @@ public class PrintJobConfigActivity extends Activity {
|
||||
subtitleView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
ImageView iconView = (ImageView) convertView.findViewById(R.id.icon);
|
||||
if (icon != null) {
|
||||
iconView.setImageDrawable(icon);
|
||||
iconView.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
iconView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user