diff options
Diffstat (limited to 'core')
6 files changed, 64 insertions, 153 deletions
diff --git a/core/java/android/print/PrintAttributes.java b/core/java/android/print/PrintAttributes.java index a1ffa8c..d889353 100644 --- a/core/java/android/print/PrintAttributes.java +++ b/core/java/android/print/PrintAttributes.java @@ -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,64 +651,12 @@ 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. * * @param id The unique resolution id. @@ -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; } } diff --git a/core/java/android/print/PrintDocumentInfo.java b/core/java/android/print/PrintDocumentInfo.java index 7a96e69..f094962 100644 --- a/core/java/android/print/PrintDocumentInfo.java +++ b/core/java/android/print/PrintDocumentInfo.java @@ -277,7 +277,7 @@ public final class PrintDocumentInfo implements Parcelable { * * @return The new instance. */ - public PrintDocumentInfo create() { + public PrintDocumentInfo build() { return new PrintDocumentInfo(mPrototype); } } diff --git a/core/java/android/print/PrinterCapabilitiesInfo.java b/core/java/android/print/PrinterCapabilitiesInfo.java index ea44c87..df51ec1 100644 --- a/core/java/android/print/PrinterCapabilitiesInfo.java +++ b/core/java/android/print/PrinterCapabilitiesInfo.java @@ -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); } diff --git a/core/java/android/print/PrinterInfo.java b/core/java/android/print/PrinterInfo.java index 0ea319b..a51e28b 100644 --- a/core/java/android/print/PrinterInfo.java +++ b/core/java/android/print/PrinterInfo.java @@ -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); } diff --git a/core/java/android/print/pdf/PrintedPdfDocument.java b/core/java/android/print/pdf/PrintedPdfDocument.java index bee17ef..1fd4646 100644 --- a/core/java/android/print/pdf/PrintedPdfDocument.java +++ b/core/java/android/print/pdf/PrintedPdfDocument.java @@ -77,14 +77,14 @@ public final class PrintedPdfDocument { mPageSize.set(0, 0, pageWidth, pageHeight); // Compute the content size from the attributes. - Margins margins = attributes.getMargins(); - final int marginLeft = (int) (((float) margins.getLeftMils() /MILS_PER_INCH) + Margins minMargins = attributes.getMinMargins(); + final int marginLeft = (int) (((float) minMargins.getLeftMils() /MILS_PER_INCH) * POINTS_IN_INCH); - final int marginTop = (int) (((float) margins.getTopMils() / MILS_PER_INCH) + final int marginTop = (int) (((float) minMargins.getTopMils() / MILS_PER_INCH) * POINTS_IN_INCH); - final int marginRight = (int) (((float) margins.getRightMils() / MILS_PER_INCH) + final int marginRight = (int) (((float) minMargins.getRightMils() / MILS_PER_INCH) * POINTS_IN_INCH); - final int marginBottom = (int) (((float) margins.getBottomMils() / MILS_PER_INCH) + final int marginBottom = (int) (((float) minMargins.getBottomMils() / MILS_PER_INCH) * POINTS_IN_INCH); mContentSize.set(mPageSize.left + marginLeft, mPageSize.top + marginTop, mPageSize.right - marginRight, mPageSize.bottom - marginBottom); diff --git a/core/java/android/view/accessibility/AccessibilityNodeInfoCache.java b/core/java/android/view/accessibility/AccessibilityNodeInfoCache.java index 1fde2fa..02d4c8d 100644 --- a/core/java/android/view/accessibility/AccessibilityNodeInfoCache.java +++ b/core/java/android/view/accessibility/AccessibilityNodeInfoCache.java @@ -100,7 +100,7 @@ public class AccessibilityNodeInfoCache { } } break; } - if (Build.IS_DEBUGGABLE && CHECK_INTEGRITY_IF_DEBUGGABLE_BUILD) { + if (CHECK_INTEGRITY_IF_DEBUGGABLE_BUILD && Build.IS_DEBUGGABLE) { checkIntegrity(); } } |