diff options
| author | Svetoslav Ganov <svetoslavganov@google.com> | 2013-07-24 17:00:06 -0700 | 
|---|---|---|
| committer | Svetoslav Ganov <svetoslavganov@google.com> | 2013-07-30 17:15:11 -0700 | 
| commit | 85b1f883056a1d74473fd9ce774948878f389ab6 (patch) | |
| tree | 7417d396a98766611636e0123102154f60726737 /core/java/android/print/PrintAttributes.java | |
| parent | 0d1daa50f6d180c57f92596501e2e5c0b5ef9997 (diff) | |
| download | frameworks_base-85b1f883056a1d74473fd9ce774948878f389ab6.zip frameworks_base-85b1f883056a1d74473fd9ce774948878f389ab6.tar.gz frameworks_base-85b1f883056a1d74473fd9ce774948878f389ab6.tar.bz2  | |
Iteration on the print sub-system.
1.  API changes: Moved copies API from PrintAttributes to PrintJobInfo;
    Changed the PageRange list to an array in PrintDocumentAdapter#onWrite;
    Added onCancelled method to the layout and write callbacks.
2.  Refactored the serialization of remote layout and write commands. Now
    the commands are serialized by the code in the client instead in the spooler.
    The benefit is simple code since the client has to do a serialization to delegate
    to the main thread anyway. The increased IPC found is fine since these calls
    are quite unfrequent.
3.  Removed an unused file: IPrintSpoolerObserver.aidl
4.  Added equals and hasCode implementation to PageRange, PrintAttributes,
    MediaSize, Resolution, Margins, Tray, PrintDocumentInfo.
5.  Added shortcut path for query APIs on PrintJob that return cached values
    if the print job is in a uncuttable state, i.e. completed or cancelled. Failed
    print jobs can be restarted.
6.  PrintJobInfo was not properly serialized.
7.  Updated the look of the print dialog to be stable if there is and there isn't
    currently selected printer.
8.  PrintJobCOnfigActivity now calls onLayout on every print attributes change
    but requests a write only on print preview or print button press. Also if the
    layout did not change the content and it is already written no subsequent
    call is made. Also if the selected pages change and we already have them
    no subsequent call to write is made. Also the app is called with print preview
    attribute set when performing layout and with it cleared after the print button
    is pressed. A lot of changes making sure that only valid actions are enabled
    in the activity (looks like a dialog) at a given time frame. The print job config
    activity is also hidden after we got all the data, i.e. layout and write are done.
9.  The callback from the print spooler to the system are scheduled via messages
    to avoid lock being held during the call. It was hard to guarantee that since a
    method holding a lock may be calling one that would like to release the lock
    at some point to make the callbacks.
10. Print spooler state is persisted only if something changes in a completed
    print job, i.e. not one that is being constructed due the print job config dialog.
11. Fixed a potential race in the RemotePrintSpooler where it was possible that
    a client that got a handle to the remote spooler calls into an unbound spooler.
    E.g: the client gets the remote interface with a lock held, now the client releases
    the lock to avoid IPC with a lock, during the IPC scheduling the spooler has
    notified the system that it is done and the system unbinds from it, now the
    client's IPC is made to a spooler that is disconnected.
Change-Id: Ie9c42255940a27ecaed21a4d326a663a4788ac9d
Diffstat (limited to 'core/java/android/print/PrintAttributes.java')
| -rw-r--r-- | core/java/android/print/PrintAttributes.java | 295 | 
1 files changed, 240 insertions, 55 deletions
diff --git a/core/java/android/print/PrintAttributes.java b/core/java/android/print/PrintAttributes.java index 87d75c0..911e380 100644 --- a/core/java/android/print/PrintAttributes.java +++ b/core/java/android/print/PrintAttributes.java @@ -77,7 +77,6 @@ public final class PrintAttributes implements Parcelable {      private int mColorMode;      private int mFittingMode;      private int mOrientation; -    private int mCopies;      PrintAttributes() {          /* hide constructor */ @@ -93,7 +92,6 @@ public final class PrintAttributes implements Parcelable {          mColorMode = parcel.readInt();          mFittingMode = parcel.readInt();          mOrientation = parcel.readInt(); -        mCopies = parcel.readInt();      }      /** @@ -302,29 +300,6 @@ public final class PrintAttributes implements Parcelable {          mOrientation = orientation;      } -    /** -     * Gets the number of copies. -     * -     * @return The number of copies or zero if not set. -     */ -    public int getCopies() { -        return mCopies; -    } - -    /** -     * Sets the number of copies. -     * -     * @param copyCount The number of copies. -     * -     * @hide -     */ -    public void setCopies(int copyCount) { -        if (copyCount < 1) { -            throw new IllegalArgumentException("Copies must be more than one."); -        } -        mCopies = copyCount; -    } -      @Override      public void writeToParcel(Parcel parcel, int flags) {          if (mMediaSize != null) { @@ -361,7 +336,6 @@ public final class PrintAttributes implements Parcelable {          parcel.writeInt(mColorMode);          parcel.writeInt(mFittingMode);          parcel.writeInt(mOrientation); -        parcel.writeInt(mCopies);      }      @Override @@ -369,6 +343,101 @@ public final class PrintAttributes implements Parcelable {          return 0;      } +    @Override +    public int hashCode() { +        final int prime = 31; +        int result = 1; +        result = prime * result + mColorMode; +        result = prime * result + mDuplexMode; +        result = prime * result + mFittingMode; +        result = prime * result + mOrientation; +        result = prime * result + ((mInputTray == null) ? 0 : mInputTray.hashCode()); +        result = prime * result + ((mMargins == null) ? 0 : mMargins.hashCode()); +        result = prime * result + ((mMediaSize == null) ? 0 : mMediaSize.hashCode()); +        result = prime * result + ((mOutputTray == null) ? 0 : mOutputTray.hashCode()); +        result = prime * result + ((mResolution == null) ? 0 : mResolution.hashCode()); +        return result; +    } + +    @Override +    public boolean equals(Object obj) { +        if (this == obj) { +            return true; +        } +        if (obj == null) { +            return false; +        } +        if (getClass() != obj.getClass()) { +            return false; +        } +        PrintAttributes other = (PrintAttributes) obj; +        if (mColorMode != other.mColorMode) { +            return false; +        } +        if (mDuplexMode != other.mDuplexMode) { +            return false; +        } +        if (mFittingMode != other.mFittingMode) { +            return false; +        } +        if (mOrientation != other.mOrientation) { +            return false; +        } +        if (mInputTray == null) { +            if (other.mInputTray != null) { +                return false; +            } +        } else if (!mInputTray.equals(other.mInputTray)) { +            return false; +        } +        if (mOutputTray == null) { +            if (other.mOutputTray != null) { +                return false; +            } +        } else if (!mOutputTray.equals(other.mOutputTray)) { +            return false; +        } +        if (mMargins == null) { +            if (other.mMargins != null) { +                return false; +            } +        } else if (!mMargins.equals(other.mMargins)) { +            return false; +        } +        if (mMediaSize == null) { +            if (other.mMediaSize != null) { +                return false; +            } +        } else if (!mMediaSize.equals(other.mMediaSize)) { +            return false; +        } +        if (mResolution == null) { +            if (other.mResolution != null) { +                return false; +            } +        } else if (!mResolution.equals(other.mResolution)) { +            return false; +        } +        return true; +    } + +    @Override +    public String toString() { +        StringBuilder builder = new StringBuilder(); +        builder.append("PrintAttributes{"); +        builder.append("mediaSize: ").append(mMediaSize); +        builder.append(", resolution: ").append(mResolution); +        builder.append(", margins: ").append(mMargins); +        builder.append(", inputTray: ").append(mInputTray); +        builder.append(", outputTray: ").append(mOutputTray); +        builder.append(", colorMode: ").append(colorModeToString(mColorMode)); +        builder.append(", duplexMode: ").append(duplexModeToString(mDuplexMode)); +        builder.append(", fittingMode: ").append(fittingModeToString(mFittingMode)); +        builder.append(", orientation: ").append(orientationToString(mOrientation)); +        builder.append("}"); +        return builder.toString(); +    } +      /** hide */      public void clear() {          mMediaSize = null; @@ -380,7 +449,6 @@ public final class PrintAttributes implements Parcelable {          mColorMode = 0;          mFittingMode = 0;          mOrientation = 0; -        mCopies = 0;      }      /** @@ -396,7 +464,6 @@ public final class PrintAttributes implements Parcelable {          mColorMode = other.mColorMode;          mFittingMode = other.mFittingMode;          mOrientation = other.mOrientation; -        mCopies = other.mCopies;      }      /** @@ -954,6 +1021,44 @@ public final class PrintAttributes implements Parcelable {          }          @Override +        public int hashCode() { +            final int prime = 31; +            int result = 1; +            result = prime * result + ((mId == null) ? 0 : mId.hashCode()); +            result = prime * result + ((mLabel == null) ? 0 : mLabel.hashCode()); +            result = prime * result + mWidthMils; +            result = prime * result + mHeightMils; +            return result; +        } + +        @Override +        public boolean equals(Object obj) { +            if (this == obj) { +                return true; +            } +            if (obj == null) { +                return false; +            } +            if (getClass() != obj.getClass()) { +                return false; +            } +            MediaSize other = (MediaSize) obj; +            if (!TextUtils.equals(mId, other.mId)) { +                return false; +            } +            if (!TextUtils.equals(mLabel, other.mLabel)) { +                return false; +            } +            if (mWidthMils != other.mWidthMils) { +                return false; +            } +            if (mHeightMils != other.mHeightMils) { +                return false; +            } +            return true; +        } + +        @Override          public String toString() {              StringBuilder builder = new StringBuilder();              builder.append("MediaSize{"); @@ -1061,6 +1166,44 @@ public final class PrintAttributes implements Parcelable {          }          @Override +        public int hashCode() { +            final int prime = 31; +            int result = 1; +            result = prime * result + ((mId == null) ? 0 : mId.hashCode()); +            result = prime * result + ((mLabel == null) ? 0 : mLabel.hashCode()); +            result = prime * result + mHorizontalDpi; +            result = prime * result + mVerticalDpi; +            return result; +        } + +        @Override +        public boolean equals(Object obj) { +            if (this == obj) { +                return true; +            } +            if (obj == null) { +                return false; +            } +            if (getClass() != obj.getClass()) { +                return false; +            } +            Resolution other = (Resolution) obj; +            if (!TextUtils.equals(mId, other.mId)) { +                return false; +            } +            if (!TextUtils.equals(mLabel, other.mLabel)) { +                return false; +            } +            if (mHorizontalDpi != other.mHorizontalDpi) { +                return false; +            } +            if (mVerticalDpi != other.mVerticalDpi) { +                return false; +            } +            return true; +        } + +        @Override          public String toString() {              StringBuilder builder = new StringBuilder();              builder.append("Resolution{"); @@ -1166,6 +1309,44 @@ public final class PrintAttributes implements Parcelable {          }          @Override +        public int hashCode() { +            final int prime = 31; +            int result = 1; +            result = prime * result + mBottomMils; +            result = prime * result + mLeftMils; +            result = prime * result + mRightMils; +            result = prime * result + mTopMils; +            return result; +        } + +        @Override +        public boolean equals(Object obj) { +            if (this == obj) { +                return true; +            } +            if (obj == null) { +                return false; +            } +            if (getClass() != obj.getClass()) { +                return false; +            } +            Margins other = (Margins) obj; +            if (mBottomMils != other.mBottomMils) { +                return false; +            } +            if (mLeftMils != other.mLeftMils) { +                return false; +            } +            if (mRightMils != other.mRightMils) { +                return false; +            } +            if (mTopMils != other.mTopMils) { +                return false; +            } +            return true; +        } + +        @Override          public String toString() {              StringBuilder builder = new StringBuilder();              builder.append("Margins{"); @@ -1235,6 +1416,36 @@ public final class PrintAttributes implements Parcelable {          }          @Override +        public int hashCode() { +            final int prime = 31; +            int result = 1; +            result = prime * result + ((mId == null) ? 0 : mId.hashCode()); +            result = prime * result + ((mLabel == null) ? 0 : mLabel.hashCode()); +            return result; +        } + +        @Override +        public boolean equals(Object obj) { +            if (this == obj) { +                return true; +            } +            if (obj == null) { +                return false; +            } +            if (getClass() != obj.getClass()) { +                return false; +            } +            Tray other = (Tray) obj; +            if (!TextUtils.equals(mId, other.mId)) { +                return false; +            } +            if (!TextUtils.equals(mLabel, other.mLabel)) { +                return false; +            } +            return true; +        } + +        @Override          public String toString() {              StringBuilder builder = new StringBuilder();              builder.append("Tray{"); @@ -1246,21 +1457,6 @@ public final class PrintAttributes implements Parcelable {          }      } -    @Override -    public String toString() { -        StringBuilder builder = new StringBuilder(); -        builder.append("PrintAttributes{"); -        builder.append("mediaSize: ").append(mMediaSize); -        builder.append(", resolution: ").append(mResolution); -        builder.append(", margins: ").append(mMargins); -        builder.append(", duplexMode: ").append(duplexModeToString(mDuplexMode)); -        builder.append(", colorMode: ").append(colorModeToString(mColorMode)); -        builder.append(", fittingMode: ").append(fittingModeToString(mFittingMode)); -        builder.append(", orientation: ").append(orientationToString(mOrientation)); -        builder.append(", copies: ").append(mCopies); -        return builder.toString(); -    } -      private static String duplexModeToString(int duplexMode) {          switch (duplexMode) {              case DUPLEX_MODE_NONE: { @@ -1412,7 +1608,7 @@ public final class PrintAttributes implements Parcelable {           * @see PrintAttributes#DUPLEX_MODE_LONG_EDGE           */          public Builder setDuplexMode(int duplexMode) { -            if (Integer.bitCount(duplexMode) != 1) { +            if (Integer.bitCount(duplexMode) > 1) {                  throw new IllegalArgumentException("can specify at most one duplexMode bit.");              }              mAttributes.setDuplexMode(duplexMode); @@ -1471,17 +1667,6 @@ public final class PrintAttributes implements Parcelable {          }          /** -         * Sets the number of copies. -         * -         * @param copyCount A greater or equal to zero copy count. -         * @return This builder. -         */ -        public Builder setCopyCount(int copyCount) { -            mAttributes.setCopies(copyCount); -            return this; -        } - -        /**           * Creates a new {@link PrintAttributes} instance.           *           * @return The new instance.  | 
