summaryrefslogtreecommitdiffstats
path: root/core/java/android/printservice/PrintServiceInfo.java
diff options
context:
space:
mode:
authorSvetoslav Ganov <svetoslavganov@google.com>2013-06-11 15:20:06 -0700
committerSvetoslav Ganov <svetoslavganov@google.com>2013-06-21 18:43:17 -0700
commit4b9a4d16872bbb50712e007b419ac0b35ff1582d (patch)
tree5799cec302adb4db9311bd7a9a889cbd217553a5 /core/java/android/printservice/PrintServiceInfo.java
parent142dd91583f429db43017ada2497d0ecfdc2b392 (diff)
downloadframeworks_base-4b9a4d16872bbb50712e007b419ac0b35ff1582d.zip
frameworks_base-4b9a4d16872bbb50712e007b419ac0b35ff1582d.tar.gz
frameworks_base-4b9a4d16872bbb50712e007b419ac0b35ff1582d.tar.bz2
Print - platform APIs
Related changes: Skia (inlcude PDF APIs): https://googleplex-android-review.googlesource.com/#/c/305814/ Canvas to PDF: https://googleplex-android-review.googlesource.com/#/c/319367/ Settings (initial version): https://googleplex-android-review.googlesource.com/#/c/306077/ Build: https://googleplex-android-review.googlesource.com/#/c/292437/ Sample print services: https://googleplex-android-review.googlesource.com/#/c/281785/ Change-Id: I104d12efd12577f05c7b9b2a5e5e49125c0f09da
Diffstat (limited to 'core/java/android/printservice/PrintServiceInfo.java')
-rw-r--r--core/java/android/printservice/PrintServiceInfo.java267
1 files changed, 267 insertions, 0 deletions
diff --git a/core/java/android/printservice/PrintServiceInfo.java b/core/java/android/printservice/PrintServiceInfo.java
new file mode 100644
index 0000000..0370a25
--- /dev/null
+++ b/core/java/android/printservice/PrintServiceInfo.java
@@ -0,0 +1,267 @@
+/*
+ * 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.
+ */
+
+package android.printservice;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.ResolveInfo;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+import android.content.res.XmlResourceParser;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.util.Xml;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+import java.io.IOException;
+
+/**
+ * This class describes a {@link PrintService}. A print service knows
+ * how to communicate with one or more printers over one or more protocols
+ * and exposes printers for use by the applications via the platform print
+ * APIs.
+ *
+ * @see PrintService
+ * @see android.print.PrintManager
+ *
+ * @hide
+ */
+public final class PrintServiceInfo implements Parcelable {
+
+ private static final boolean DEBUG = false;
+
+ private static final String LOG_TAG = PrintServiceInfo.class.getSimpleName();
+
+ private static final String TAG_PRINT_SERVICE = "print-service";
+
+ private final String mId;
+
+ private final ResolveInfo mResolveInfo;
+
+ private final String mSettingsActivityName;
+
+ private final String mAddPrintersActivityName;
+
+ /**
+ * Creates a new instance.
+ *
+ * @hide
+ */
+ public PrintServiceInfo(Parcel parcel) {
+ mId = parcel.readString();
+ mResolveInfo = parcel.readParcelable(null);
+ mSettingsActivityName = parcel.readString();
+ mAddPrintersActivityName = parcel.readString();
+ }
+
+ /**
+ * Creates a new instance.
+ *
+ * @param resolveInfo The service resolve info.
+ * @param settingsActivityName Optional settings activity name.
+ * @param addPrintersActivityName Optional add printers activity name.
+ */
+ public PrintServiceInfo(ResolveInfo resolveInfo, String settingsActivityName,
+ String addPrintersActivityName) {
+ mId = new ComponentName(resolveInfo.serviceInfo.packageName,
+ resolveInfo.serviceInfo.name).flattenToString();
+ mResolveInfo = resolveInfo;
+ mSettingsActivityName = settingsActivityName;
+ mAddPrintersActivityName = addPrintersActivityName;
+ }
+
+ /**
+ * Creates a new instance.
+ *
+ * @param resolveInfo The service resolve info.
+ * @param context Context for accessing resources.
+ * @throws XmlPullParserException If a XML parsing error occurs.
+ * @throws IOException If a I/O error occurs.
+ * @hide
+ */
+ public static PrintServiceInfo create(ResolveInfo resolveInfo, Context context) {
+ String settingsActivityName = null;
+ String addPrintersActivityName = null;
+
+ XmlResourceParser parser = null;
+ PackageManager packageManager = context.getPackageManager();
+ parser = resolveInfo.serviceInfo.loadXmlMetaData(packageManager,
+ PrintService.SERVICE_META_DATA);
+ if (parser != null) {
+ try {
+ int type = 0;
+ while (type != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
+ type = parser.next();
+ }
+
+ String nodeName = parser.getName();
+ if (!TAG_PRINT_SERVICE.equals(nodeName)) {
+ throw new XmlPullParserException(
+ "Meta-data does not start with" + TAG_PRINT_SERVICE + " tag");
+ }
+
+ Resources resources = packageManager.getResourcesForApplication(
+ resolveInfo.serviceInfo.applicationInfo);
+ AttributeSet allAttributes = Xml.asAttributeSet(parser);
+ TypedArray attributes = resources.obtainAttributes(allAttributes,
+ com.android.internal.R.styleable.PrintService);
+
+ settingsActivityName = attributes.getString(
+ com.android.internal.R.styleable.PrintService_settingsActivity);
+
+ addPrintersActivityName = attributes.getString(
+ com.android.internal.R.styleable.PrintService_addPrintersActivity);
+
+ attributes.recycle();
+ } catch (IOException ioe) {
+ Log.w(LOG_TAG, "Error reading meta-data:" + ioe);
+ } catch (XmlPullParserException xppe) {
+ Log.w(LOG_TAG, "Error reading meta-data:" + xppe);
+ } catch (NameNotFoundException e) {
+ Log.e(LOG_TAG, "Unable to load resources for: "
+ + resolveInfo.serviceInfo.packageName);
+ } finally {
+ if (parser != null) {
+ parser.close();
+ }
+ }
+ }
+
+ return new PrintServiceInfo(resolveInfo, settingsActivityName, addPrintersActivityName);
+ }
+
+ /**
+ * The accessibility service id.
+ * <p>
+ * <strong>Generated by the system.</strong>
+ * </p>
+ *
+ * @return The id.
+ */
+ public String getId() {
+ return mId;
+ }
+
+ /**
+ * The service {@link ResolveInfo}.
+ *
+ * @return The info.
+ */
+ public ResolveInfo getResolveInfo() {
+ return mResolveInfo;
+ }
+
+ /**
+ * The settings activity name.
+ * <p>
+ * <strong>Statically set from
+ * {@link PrintService#SERVICE_META_DATA meta-data}.</strong>
+ * </p>
+ *
+ * @return The settings activity name.
+ */
+ public String getSettingsActivityName() {
+ return mSettingsActivityName;
+ }
+
+ /**
+ * The add printers activity name.
+ * <p>
+ * <strong>Statically set from
+ * {@link PrintService#SERVICE_META_DATA meta-data}.</strong>
+ * </p>
+ *
+ * @return The add printers activity name.
+ */
+ public String getAddPrintersActivityName() {
+ return mAddPrintersActivityName;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int describeContents() {
+ return 0;
+ }
+
+ public void writeToParcel(Parcel parcel, int flagz) {
+ parcel.writeString(mId);
+ parcel.writeParcelable(mResolveInfo, 0);
+ parcel.writeString(mSettingsActivityName);
+ parcel.writeString(mAddPrintersActivityName);
+ }
+
+ @Override
+ public int hashCode() {
+ return 31 * 1 + ((mId == null) ? 0 : mId.hashCode());
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ PrintServiceInfo other = (PrintServiceInfo) obj;
+ if (mId == null) {
+ if (other.mId != null) {
+ return false;
+ }
+ } else if (!mId.equals(other.mId)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("PrintServiceInfo{");
+ builder.append("id:").append(mId).append(", ");
+ builder.append("resolveInfo:").append(mResolveInfo).append(", ");
+ if (DEBUG) {
+ builder.append("settingsActivityName:").append(mSettingsActivityName);
+ builder.append("addPrintersActivityName:").append(mAddPrintersActivityName);
+ } else if (mSettingsActivityName != null || mAddPrintersActivityName != null) {
+ builder.append("<has meta-data>");
+ }
+ builder.append("}");
+ return builder.toString();
+ }
+
+ public static final Parcelable.Creator<PrintServiceInfo> CREATOR =
+ new Parcelable.Creator<PrintServiceInfo>() {
+ public PrintServiceInfo createFromParcel(Parcel parcel) {
+ return new PrintServiceInfo(parcel);
+ }
+
+ public PrintServiceInfo[] newArray(int size) {
+ return new PrintServiceInfo[size];
+ }
+ };
+}