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

Commit b72ff5aa authored by Svetoslav's avatar Svetoslav Committed by Android (Google) Code Review
Browse files

Merge "Remove unneeded print APIs and update the min margins APIs." into klp-dev

parents 4801a4f9 651dd4e6
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -19037,8 +19037,8 @@ package android.print {
    method public void clear();
    method public int describeContents();
    method public int getColorMode();
    method public android.print.PrintAttributes.Margins getMargins();
    method public android.print.PrintAttributes.MediaSize getMediaSize();
    method public android.print.PrintAttributes.Margins getMinMargins();
    method public android.print.PrintAttributes.Resolution getResolution();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final int COLOR_MODE_COLOR = 2; // 0x2
@@ -19048,10 +19048,10 @@ package android.print {
  public static final class PrintAttributes.Builder {
    ctor public PrintAttributes.Builder();
    method public android.print.PrintAttributes create();
    method public android.print.PrintAttributes build();
    method public android.print.PrintAttributes.Builder setColorMode(int);
    method public android.print.PrintAttributes.Builder setMargins(android.print.PrintAttributes.Margins);
    method public android.print.PrintAttributes.Builder setMediaSize(android.print.PrintAttributes.MediaSize);
    method public android.print.PrintAttributes.Builder setMinMargins(android.print.PrintAttributes.Margins);
    method public android.print.PrintAttributes.Builder setResolution(android.print.PrintAttributes.Resolution);
  }
@@ -19118,7 +19118,7 @@ package android.print {
    ctor public PrintAttributes.Resolution(java.lang.String, java.lang.String, int, int);
    method public int getHorizontalDpi();
    method public java.lang.String getId();
    method public java.lang.String getLabel(android.content.pm.PackageManager);
    method public java.lang.String getLabel();
    method public int getVerticalDpi();
  }
@@ -19159,7 +19159,7 @@ package android.print {
  public static final class PrintDocumentInfo.Builder {
    ctor public PrintDocumentInfo.Builder(java.lang.String);
    method public android.print.PrintDocumentInfo create();
    method public android.print.PrintDocumentInfo build();
    method public android.print.PrintDocumentInfo.Builder setContentType(int);
    method public android.print.PrintDocumentInfo.Builder setPageCount(int);
  }
@@ -19206,7 +19206,7 @@ package android.print {
  public final class PrinterCapabilitiesInfo implements android.os.Parcelable {
    method public int describeContents();
    method public int getColorModes();
    method public void getDefaults(android.print.PrintAttributes);
    method public android.print.PrintAttributes getDefaults();
    method public java.util.List<android.print.PrintAttributes.MediaSize> getMediaSizes();
    method public android.print.PrintAttributes.Margins getMinMargins();
    method public java.util.List<android.print.PrintAttributes.Resolution> getResolutions();
@@ -19218,9 +19218,9 @@ package android.print {
    ctor public PrinterCapabilitiesInfo.Builder(android.print.PrinterId);
    method public android.print.PrinterCapabilitiesInfo.Builder addMediaSize(android.print.PrintAttributes.MediaSize, boolean);
    method public android.print.PrinterCapabilitiesInfo.Builder addResolution(android.print.PrintAttributes.Resolution, boolean);
    method public android.print.PrinterCapabilitiesInfo create();
    method public android.print.PrinterCapabilitiesInfo build();
    method public android.print.PrinterCapabilitiesInfo.Builder setColorModes(int, int);
    method public android.print.PrinterCapabilitiesInfo.Builder setMinMargins(android.print.PrintAttributes.Margins, android.print.PrintAttributes.Margins);
    method public android.print.PrinterCapabilitiesInfo.Builder setMinMargins(android.print.PrintAttributes.Margins);
  }
  public final class PrinterId implements android.os.Parcelable {
@@ -19247,7 +19247,7 @@ package android.print {
  public static final class PrinterInfo.Builder {
    ctor public PrinterInfo.Builder(android.print.PrinterId, java.lang.String, int);
    ctor public PrinterInfo.Builder(android.print.PrinterInfo);
    method public android.print.PrinterInfo create();
    method public android.print.PrinterInfo build();
    method public android.print.PrinterInfo.Builder setCapabilities(android.print.PrinterCapabilitiesInfo);
    method public android.print.PrinterInfo.Builder setDescription(java.lang.String);
    method public android.print.PrinterInfo.Builder setName(java.lang.String);
+26 −107
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ public final class PrintAttributes implements Parcelable {

    private MediaSize mMediaSize;
    private Resolution mResolution;
    private Margins mMargins;
    private Margins mMinMargins;

    private int mColorMode;

@@ -52,7 +52,7 @@ public final class PrintAttributes implements Parcelable {
    private PrintAttributes(Parcel parcel) {
        mMediaSize = (parcel.readInt() ==  1) ? MediaSize.createFromParcel(parcel) : null;
        mResolution = (parcel.readInt() ==  1) ? Resolution.createFromParcel(parcel) : null;
        mMargins = (parcel.readInt() ==  1) ? Margins.createFromParcel(parcel) : null;
        mMinMargins = (parcel.readInt() ==  1) ? Margins.createFromParcel(parcel) : null;
        mColorMode = parcel.readInt();
    }

@@ -97,23 +97,25 @@ public final class PrintAttributes implements Parcelable {
    }

    /**
     * Gets the margins.
     * Gets the minimal margins. If the content does not fit
     * these margins it will be clipped.
     *
     * @return The margins or <code>null</code> if not set.
     */
    public Margins getMargins() {
        return mMargins;
    public Margins getMinMargins() {
        return mMinMargins;
    }

    /**
     * Sets the margins.
     * Sets the minimal margins. If the content does not fit
     * these margins it will be clipped.
     *
     * @param The margins.
     *
     * @hide
     */
    public void setMargins(Margins margins) {
        mMargins = margins;
    public void setMinMargins(Margins margins) {
        mMinMargins = margins;
    }

    /**
@@ -157,9 +159,9 @@ public final class PrintAttributes implements Parcelable {
        } else {
            parcel.writeInt(0);
        }
        if (mMargins != null) {
        if (mMinMargins != null) {
            parcel.writeInt(1);
            mMargins.writeToParcel(parcel);
            mMinMargins.writeToParcel(parcel);
        } else {
            parcel.writeInt(0);
        }
@@ -176,7 +178,7 @@ public final class PrintAttributes implements Parcelable {
        final int prime = 31;
        int result = 1;
        result = prime * result + mColorMode;
        result = prime * result + ((mMargins == null) ? 0 : mMargins.hashCode());
        result = prime * result + ((mMinMargins == null) ? 0 : mMinMargins.hashCode());
        result = prime * result + ((mMediaSize == null) ? 0 : mMediaSize.hashCode());
        result = prime * result + ((mResolution == null) ? 0 : mResolution.hashCode());
        return result;
@@ -197,11 +199,11 @@ public final class PrintAttributes implements Parcelable {
        if (mColorMode != other.mColorMode) {
            return false;
        }
        if (mMargins == null) {
            if (other.mMargins != null) {
        if (mMinMargins == null) {
            if (other.mMinMargins != null) {
                return false;
            }
        } else if (!mMargins.equals(other.mMargins)) {
        } else if (!mMinMargins.equals(other.mMinMargins)) {
            return false;
        }
        if (mMediaSize == null) {
@@ -233,7 +235,7 @@ public final class PrintAttributes implements Parcelable {
            builder.append(", orientation: ").append("null");
        }
        builder.append(", resolution: ").append(mResolution);
        builder.append(", margins: ").append(mMargins);
        builder.append(", minMargins: ").append(mMinMargins);
        builder.append(", colorMode: ").append(colorModeToString(mColorMode));
        builder.append("}");
        return builder.toString();
@@ -243,7 +245,7 @@ public final class PrintAttributes implements Parcelable {
    public void clear() {
        mMediaSize = null;
        mResolution = null;
        mMargins = null;
        mMinMargins = null;
        mColorMode = 0;
    }

@@ -253,7 +255,7 @@ public final class PrintAttributes implements Parcelable {
    public void copyFrom(PrintAttributes other) {
        mMediaSize = other.mMediaSize;
        mResolution = other.mResolution;
        mMargins = other.mMargins;
        mMinMargins = other.mMinMargins;
        mColorMode = other.mColorMode;
    }

@@ -649,63 +651,11 @@ public final class PrintAttributes implements Parcelable {
     * This class specifies a supported resolution in dpi (dots per inch).
     */
    public static final class Resolution {
        private static final String LOG_TAG = "Resolution";

        private final String mId;
        /**@hide */
        public final String mLabel;
        /**@hide */
        public final String mPackageName;
        /**@hide */
        public final int mLabelResId;
        private final String mLabel;
        private final int mHorizontalDpi;
        private final int mVerticalDpi;

        /**
         * Creates a new instance. This is the preferred constructor since
         * it enables the resolution label to be shown in a localized fashion
         * on a locale change.
         *
         * @param id The unique resolution id.
         * @param packageName The name of the creating package.
         * @param labelResId The resource id of a human readable label.
         * @param horizontalDpi The horizontal resolution in dpi.
         * @param verticalDpi The vertical resolution in dpi.
         *
         * @throws IllegalArgumentException If the id is empty.
         * @throws IllegalArgumentException If the label is empty.
         * @throws IllegalArgumentException If the horizontalDpi is less than or equal to zero.
         * @throws IllegalArgumentException If the verticalDpi is less than or equal to zero.
         *
         * @hide
         */
        public Resolution(String id, String packageName, int labelResId,
                int horizontalDpi, int verticalDpi) {
            if (TextUtils.isEmpty(id)) {
                throw new IllegalArgumentException("id cannot be empty.");
            }
            if (TextUtils.isEmpty(packageName)) {
                throw new IllegalArgumentException("packageName cannot be empty.");
            }
            if (labelResId <= 0) {
                throw new IllegalArgumentException("labelResId must be greater than zero.");
            }
            if (horizontalDpi <= 0) {
                throw new IllegalArgumentException("horizontalDpi "
                        + "cannot be less than or equal to zero.");
            }
            if (verticalDpi <= 0) {
                throw new IllegalArgumentException("verticalDpi"
                       + " cannot be less than or equal to zero.");
            }
            mId = id;
            mPackageName = packageName;
            mLabelResId = labelResId;
            mHorizontalDpi = horizontalDpi;
            mVerticalDpi = verticalDpi;
            mLabel = null;
        }

        /**
         * Creates a new instance.
         *
@@ -738,19 +688,6 @@ public final class PrintAttributes implements Parcelable {
            mLabel = label;
            mHorizontalDpi = horizontalDpi;
            mVerticalDpi = verticalDpi;
            mPackageName = null;
            mLabelResId = 0;
        }

        /** @hide */
        public Resolution(String id, String label, String packageName,
                int horizontalDpi, int verticalDpi, int labelResId) {
            mId = id;
            mPackageName = packageName;
            mLabelResId = labelResId;
            mHorizontalDpi = horizontalDpi;
            mVerticalDpi = verticalDpi;
            mLabel = label;
        }

        /**
@@ -765,22 +702,9 @@ public final class PrintAttributes implements Parcelable {
        /**
         * Gets the resolution human readable label.
         *
         * @param packageManager The package manager for loading the label.
         * @return The human readable label.
         */
        public String getLabel(PackageManager packageManager) {
            if (!TextUtils.isEmpty(mPackageName) && mLabelResId > 0) {
                try {
                    return packageManager.getResourcesForApplication(
                            mPackageName).getString(mLabelResId);
                } catch (NotFoundException nfe) {
                    Log.w(LOG_TAG, "Could not load resouce" + mLabelResId
                            + " from package " + mPackageName);
                } catch (NameNotFoundException nnfee) {
                    Log.w(LOG_TAG, "Could not load resouce" + mLabelResId
                            + " from package " + mPackageName);
                }
            }
        public String getLabel() {
            return mLabel;
        }

@@ -805,18 +729,14 @@ public final class PrintAttributes implements Parcelable {
        void writeToParcel(Parcel parcel) {
            parcel.writeString(mId);
            parcel.writeString(mLabel);
            parcel.writeString(mPackageName);
            parcel.writeInt(mHorizontalDpi);
            parcel.writeInt(mVerticalDpi);
            parcel.writeInt(mLabelResId);
        }

        static Resolution createFromParcel(Parcel parcel) {
            return new Resolution(
                    parcel.readString(),
                    parcel.readString(),
                    parcel.readString(),
                    parcel.readInt(),
                    parcel.readInt(),
                    parcel.readInt());
        }
@@ -857,10 +777,8 @@ public final class PrintAttributes implements Parcelable {
            builder.append("Resolution{");
            builder.append("id: ").append(mId);
            builder.append(", label: ").append(mLabel);
            builder.append(", packageName: ").append(mPackageName);
            builder.append(", horizontalDpi: ").append(mHorizontalDpi);
            builder.append(", verticalDpi: ").append(mVerticalDpi);
            builder.append(", labelResId: ").append(mLabelResId);
            builder.append("}");
            return builder.toString();
        }
@@ -1042,13 +960,14 @@ public final class PrintAttributes implements Parcelable {
        }

        /**
         * Sets the margins.
         * Sets the minimal margins. If the content does not fit
         * these margins it will be clipped.
         *
         * @param margins The margins.
         * @return This builder.
         */
        public Builder setMargins(Margins margins) {
            mAttributes.setMargins(margins);
        public Builder setMinMargins(Margins margins) {
            mAttributes.setMinMargins(margins);
            return this;
        }

@@ -1074,7 +993,7 @@ public final class PrintAttributes implements Parcelable {
         *
         * @return The new instance.
         */
        public PrintAttributes create() {
        public PrintAttributes build() {
            return mAttributes;
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -277,7 +277,7 @@ public final class PrintDocumentInfo implements Parcelable {
         *
         * @return The new instance.
         */
        public PrintDocumentInfo create() {
        public PrintDocumentInfo build() {
            return new PrintDocumentInfo(mPrototype);
        }
    }
+27 −38
Original line number Diff line number Diff line
@@ -51,7 +51,6 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
    private int mColorModes;

    private final int[] mDefaults = new int[PROPERTY_COUNT];
    private Margins mDefaultMargins = DEFAULT_MARGINS;

    /**
     * @hide
@@ -71,6 +70,10 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
     * @hide
     */
    public void copyFrom(PrinterCapabilitiesInfo other) {
        if (this == other) {
            return;
        }

        mMinMargins = other.mMinMargins;

        if (other.mMediaSizes != null) {
@@ -101,8 +104,6 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
        for (int i = 0; i < defaultCount; i++) {
            mDefaults[i] = other.mDefaults[i];
        }

        mDefaultMargins = other.mDefaultMargins;
    }

    /**
@@ -124,7 +125,8 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
    }

    /**
     * Gets the minimal supported margins.
     * Gets the minimal margins. These are the minimal margins
     * the printer physically supports.
     *
     * @return The minimal margins.
     */
@@ -147,27 +149,29 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
    /**
     * Gets the default print attributes.
     *
     * @param outAttributes The attributes to populated.
     * @return The default attributes.
     */
    public void getDefaults(PrintAttributes outAttributes) {
        outAttributes.clear();
    public PrintAttributes getDefaults() {
        PrintAttributes.Builder builder = new PrintAttributes.Builder();

        outAttributes.setMargins(mDefaultMargins);
        builder.setMinMargins(mMinMargins);

        final int mediaSizeIndex = mDefaults[PROPERTY_MEDIA_SIZE];
        if (mediaSizeIndex >= 0) {
            outAttributes.setMediaSize(mMediaSizes.get(mediaSizeIndex));
            builder.setMediaSize(mMediaSizes.get(mediaSizeIndex));
        }

        final int resolutionIndex = mDefaults[PROPERTY_RESOLUTION];
        if (resolutionIndex >= 0) {
            outAttributes.setResolution(mResolutions.get(resolutionIndex));
            builder.setResolution(mResolutions.get(resolutionIndex));
        }

        final int colorMode = mDefaults[PROPERTY_COLOR_MODE];
        if (colorMode > 0) {
            outAttributes.setColorMode(colorMode);
            builder.setColorMode(colorMode);
        }

        return builder.build();
    }

    private PrinterCapabilitiesInfo(Parcel parcel) {
@@ -178,7 +182,6 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
        mColorModes = parcel.readInt();

        readDefaults(parcel);
        mDefaultMargins = readMargins(parcel);
    }

    @Override
@@ -195,7 +198,6 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
        parcel.writeInt(mColorModes);

        writeDefaults(parcel);
        writeMargins(mDefaultMargins, parcel);
    }

    @Override
@@ -207,7 +209,6 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
        result = prime * result + ((mResolutions == null) ? 0 : mResolutions.hashCode());
        result = prime * result + mColorModes;
        result = prime * result + Arrays.hashCode(mDefaults);
        result = prime * result + ((mDefaultMargins == null) ? 0 : mDefaultMargins.hashCode());
        return result;
    }

@@ -250,13 +251,6 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
        if (!Arrays.equals(mDefaults, other.mDefaults)) {
            return false;
        }
        if (mDefaultMargins == null) {
            if (other.mDefaultMargins != null) {
                return false;
            }
        } else if (!mDefaultMargins.equals(other.mDefaultMargins)) {
            return false;
        }
        return true;
    }

@@ -279,7 +273,7 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
        while (colorModes != 0) {
            final int colorMode = 1 << Integer.numberOfTrailingZeros(colorModes);
            colorModes &= ~colorMode;
            if (builder.length() > 0) {
            if (builder.length() > 1) {
                builder.append(", ");
            }
            builder.append(PrintAttributes.colorModeToString(colorMode));
@@ -442,27 +436,25 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
        }

        /**
         * Sets the minimal margins.
         * Sets the minimal margins. These are the minimal margins
         * the printer physically supports.
         *
         * <p>
         * <strong>Required:</strong> No
         * <strong>Required:</strong> Yes
         * </p>
         *
         * @param margins The margins.
         * @param defaultMargins The default margins.
         * @return This builder.
         *
         * @throws IllegalArgumentException If margins are <code>null</code>.
         *
         * @see PrintAttributes.Margins
         */
        public Builder setMinMargins(Margins margins, Margins defaultMargins) {
            if (margins.getLeftMils() > defaultMargins.getLeftMils()
                    || margins.getTopMils() > defaultMargins.getTopMils()
                    || margins.getRightMils() < defaultMargins.getRightMils()
                    || margins.getBottomMils() < defaultMargins.getBottomMils()) {
                throw new IllegalArgumentException("Default margins"
                    + " cannot be outside of the min margins.");
        public Builder setMinMargins(Margins margins) {
            if (margins == null) {
                throw new IllegalArgumentException("margins cannot be null");
            }
            mPrototype.mMinMargins = margins;
            mPrototype.mDefaultMargins = defaultMargins;
            return this;
        }

@@ -507,7 +499,7 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
         *
         * @throws IllegalStateException If a required attribute was not specified.
         */
        public PrinterCapabilitiesInfo create() {
        public PrinterCapabilitiesInfo build() {
            if (mPrototype.mMediaSizes == null || mPrototype.mMediaSizes.isEmpty()) {
                throw new IllegalStateException("No media size specified.");
            }
@@ -527,10 +519,7 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
                throw new IllegalStateException("No default color mode specified.");
            }
            if (mPrototype.mMinMargins == null) {
                mPrototype.mMinMargins  = new Margins(0, 0, 0, 0);
            }
            if (mPrototype.mDefaultMargins == null) {
                mPrototype.mDefaultMargins = mPrototype.mMinMargins;
                throw new IllegalArgumentException("margins cannot be null");
            }
            return new PrinterCapabilitiesInfo(mPrototype);
        }
+4 −1
Original line number Diff line number Diff line
@@ -56,6 +56,9 @@ public final class PrinterInfo implements Parcelable {
     * @hide
     */
    public void copyFrom(PrinterInfo other) {
        if (this == other) {
            return;
        }
        mId = other.mId;
        mName = other.mName;
        mStatus = other.mStatus;
@@ -293,7 +296,7 @@ public final class PrinterInfo implements Parcelable {
         *
         * @return A new {@link PrinterInfo}.
         */
        public PrinterInfo create() {
        public PrinterInfo build() {
            return new PrinterInfo(mPrototype);
        }

Loading