Merge "Allow the PDF Printer to "print" non-locale-default paper sizes."

This commit is contained in:
Philip P. Moltmann
2016-02-02 16:34:49 +00:00
committed by Android (Google) Code Review
8 changed files with 23 additions and 212 deletions

View File

@@ -27,6 +27,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Log;
import com.android.internal.R;
@@ -872,6 +873,23 @@ public final class PrintAttributes implements Parcelable {
mPackageName = null;
}
/**
* Get the Id of all predefined media sizes beside the {@link #UNKNOWN_PORTRAIT} and
* {@link #UNKNOWN_LANDSCAPE}.
*
* @return List of all predefined media sizes
*
* @hide
*/
public static @NonNull ArraySet<MediaSize> getAllPredefinedSizes() {
ArraySet<MediaSize> definedMediaSizes = new ArraySet<>(sIdToMediaSizeMap.values());
definedMediaSizes.remove(UNKNOWN_PORTRAIT);
definedMediaSizes.remove(UNKNOWN_LANDSCAPE);
return definedMediaSizes;
}
/** @hide */
public MediaSize(String id, String label, String packageName,
int widthMils, int heightMils, int labelResId) {

View File

@@ -1,33 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 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.
-->
<resources>
<string-array name="pdf_printer_media_sizes" translatable="false">
<item>NA_LETTER</item>
<item>NA_GOVT_LETTER</item>
<item>NA_LEGAL</item>
<item>NA_JUNIOR_LEGAL</item>
<item>NA_LEDGER</item>
<item>NA_TABLOID</item>
<item>NA_INDEX_3X5</item>
<item>NA_INDEX_4X6</item>
<item>NA_INDEX_5X8</item>
<item>NA_MONARCH</item>
<item>NA_QUARTO</item>
<item>NA_FOOLSCAP</item>
</string-array>
</resources>

View File

@@ -1,33 +0,0 @@
<?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.
-->
<resources>
<string-array name="pdf_printer_media_sizes" translatable="false">
<item>NA_LETTER</item>
<item>NA_GOVT_LETTER</item>
<item>NA_LEGAL</item>
<item>NA_JUNIOR_LEGAL</item>
<item>NA_LEDGER</item>
<item>NA_TABLOID</item>
<item>NA_INDEX_3X5</item>
<item>NA_INDEX_4X6</item>
<item>NA_INDEX_5X8</item>
<item>NA_MONARCH</item>
<item>NA_QUARTO</item>
<item>NA_FOOLSCAP</item>
</string-array>
</resources>

View File

@@ -1,33 +0,0 @@
<?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.
-->
<resources>
<string-array name="pdf_printer_media_sizes" translatable="false">
<item>NA_LETTER</item>
<item>NA_GOVT_LETTER</item>
<item>NA_LEGAL</item>
<item>NA_JUNIOR_LEGAL</item>
<item>NA_LEDGER</item>
<item>NA_TABLOID</item>
<item>NA_INDEX_3X5</item>
<item>NA_INDEX_4X6</item>
<item>NA_INDEX_5X8</item>
<item>NA_MONARCH</item>
<item>NA_QUARTO</item>
<item>NA_FOOLSCAP</item>
</string-array>
</resources>

View File

@@ -1,33 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 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.
-->
<resources>
<string-array name="pdf_printer_media_sizes" translatable="false">
<item>NA_LETTER</item>
<item>NA_GOVT_LETTER</item>
<item>NA_LEGAL</item>
<item>NA_JUNIOR_LEGAL</item>
<item>NA_LEDGER</item>
<item>NA_TABLOID</item>
<item>NA_INDEX_3X5</item>
<item>NA_INDEX_4X6</item>
<item>NA_INDEX_5X8</item>
<item>NA_MONARCH</item>
<item>NA_QUARTO</item>
<item>NA_FOOLSCAP</item>
</string-array>
</resources>

View File

@@ -1,41 +0,0 @@
<?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.
-->
<resources>
<string-array name="pdf_printer_media_sizes" translatable="false">
<item>JIS_B10</item>
<item>JIS_B9</item>
<item>JIS_B8</item>
<item>JIS_B7</item>
<item>JIS_B6</item>
<item>JIS_B5</item>
<item>JIS_B4</item>
<item>JIS_B3</item>
<item>JIS_B2</item>
<item>JIS_B1</item>
<item>JIS_B0</item>
<item>JIS_EXEC</item>
<item>JPN_CHOU4</item>
<item>JPN_CHOU3</item>
<item>JPN_CHOU2</item>
<item>JPN_HAGAKI</item>
<item>JPN_OUFUKU</item>
<item>JPN_KAHU</item>
<item>JPN_KAKU2</item>
<item>JPN_YOU4</item>
</string-array>
</resources>

View File

@@ -121,38 +121,4 @@
<!-- Everything else is ISO -->
</string-array>
<string-array name="pdf_printer_media_sizes" translatable="false">
<item>ISO_A0</item>
<item>ISO_A1</item>
<item>ISO_A2</item>
<item>ISO_A3</item>
<item>ISO_A4</item>
<item>ISO_A5</item>
<item>ISO_A6</item>
<item>ISO_A7</item>
<item>ISO_A8</item>
<item>ISO_A9</item>
<item>ISO_A10</item>
<item>ISO_B1</item>
<item>ISO_B2</item>
<item>ISO_B3</item>
<item>ISO_B4</item>
<item>ISO_B5</item>
<item>ISO_B6</item>
<item>ISO_B7</item>
<item>ISO_B8</item>
<item>ISO_B9</item>
<item>ISO_B10</item>
<item>ISO_C1</item>
<item>ISO_C2</item>
<item>ISO_C3</item>
<item>ISO_C4</item>
<item>ISO_C5</item>
<item>ISO_C6</item>
<item>ISO_C7</item>
<item>ISO_C8</item>
<item>ISO_C9</item>
<item>ISO_C10</item>
</string-array>
</resources>

View File

@@ -61,6 +61,7 @@ import android.text.TextUtils;
import android.text.TextUtils.SimpleStringSplitter;
import android.text.TextWatcher;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Log;
import android.util.TypedValue;
import android.view.KeyEvent;
@@ -2361,6 +2362,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
}
private PrinterInfo createFakePdfPrinter() {
ArraySet<MediaSize> allMediaSizes = MediaSize.getAllPredefinedSizes();
MediaSize defaultMediaSize = MediaSizeUtils.getDefault(PrintActivity.this);
PrinterId printerId = new PrinterId(getComponentName(), "PDF printer");
@@ -2368,11 +2370,9 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
PrinterCapabilitiesInfo.Builder builder =
new PrinterCapabilitiesInfo.Builder(printerId);
String[] mediaSizeIds = getResources().getStringArray(R.array.pdf_printer_media_sizes);
final int mediaSizeIdCount = mediaSizeIds.length;
for (int i = 0; i < mediaSizeIdCount; i++) {
String id = mediaSizeIds[i];
MediaSize mediaSize = MediaSize.getStandardMediaSizeById(id);
final int mediaSizeCount = allMediaSizes.size();
for (int i = 0; i < mediaSizeCount; i++) {
MediaSize mediaSize = allMediaSizes.valueAt(i);
builder.addMediaSize(mediaSize, mediaSize.equals(defaultMediaSize));
}