Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b31aea5f authored by Svetoslav's avatar Svetoslav Committed by Android Git Automerger
Browse files

am 25b0151a: Merge "Printers in the list of printers change position." into klp-dev

* commit '25b0151a':
  Printers in the list of printers change position.
parents aeccbf77 25b0151a
Loading
Loading
Loading
Loading
+34 −10
Original line number Diff line number Diff line
@@ -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) {
+0 −3
Original line number Diff line number Diff line
@@ -24,7 +24,4 @@ LOCAL_PACKAGE_NAME := PrintSpooler

LOCAL_JAVA_LIBRARIES := framework-base

LOCAL_PROGUARD_ENABLED := disabled

include $(BUILD_PACKAGE)
+70 −0
Original line number Diff line number Diff line
<?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>
+14 −3
Original line number Diff line number Diff line
@@ -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;
            }