summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Svetoslav <svetoslavganov@google.com> 2013-09-27 02:24:38 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2013-09-27 02:24:38 +0000
commit25b0151a570ff6fb7a6acd9c788b9c3cc9f76be9 (patch)
treeec805896a47dd36a53fd03a025b4aa69d9c21321
parent231bd6c514f15cb0b42a04d4fc7fc9631c743686 (diff)
parentc335eb411503154cf475903eb6c5c67575769112 (diff)
Merge "Printers in the list of printers change position." into klp-dev
-rw-r--r--core/java/android/print/PrinterDiscoverySession.java44
-rw-r--r--packages/PrintSpooler/Android.mk3
-rw-r--r--packages/PrintSpooler/res/layout/printer_dropdown_item.xml70
-rw-r--r--packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java17
4 files changed, 118 insertions, 16 deletions
diff --git a/core/java/android/print/PrinterDiscoverySession.java b/core/java/android/print/PrinterDiscoverySession.java
index c6dbc1664b30..6432a376d8ca 100644
--- a/core/java/android/print/PrinterDiscoverySession.java
+++ b/core/java/android/print/PrinterDiscoverySession.java
@@ -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);
}
- }
- if (printersChanged) {
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);
+ }
+ }
+
+ // Add the new printers, i.e. what is left.
+ mPrinters.putAll(addedPrintersMap);
+
+ // Announce the change.
+ notifyOnPrintersChanged();
}
private void handlePrintersRemoved(List<PrinterId> printerIds) {
diff --git a/packages/PrintSpooler/Android.mk b/packages/PrintSpooler/Android.mk
index f65fe4b7c64b..9e7b969ce1b3 100644
--- a/packages/PrintSpooler/Android.mk
+++ b/packages/PrintSpooler/Android.mk
@@ -24,7 +24,4 @@ LOCAL_PACKAGE_NAME := PrintSpooler
LOCAL_JAVA_LIBRARIES := framework-base
-LOCAL_PROGUARD_ENABLED := disabled
-
include $(BUILD_PACKAGE)
-
diff --git a/packages/PrintSpooler/res/layout/printer_dropdown_item.xml b/packages/PrintSpooler/res/layout/printer_dropdown_item.xml
new file mode 100644
index 000000000000..6439b49acc9d
--- /dev/null
+++ b/packages/PrintSpooler/res/layout/printer_dropdown_item.xml
@@ -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>
diff --git a/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java b/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java
index 8d11a9392d0f..b6ef7b1a2756 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java
@@ -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;
}