blob: 32efb9936edd93d0b22825cc867dd70bc7b70412 [file] [log] [blame]
Chiao Chengd80c4342012-12-03 17:15:58 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.android.contacts.common.vcard;
17
18import android.accounts.Account;
19import android.net.Uri;
20
Jay Shrauner2ae200d2015-01-09 11:36:20 -080021import com.android.contacts.common.model.account.AccountWithDataSet;
Chiao Chengd80c4342012-12-03 17:15:58 -080022import com.android.vcard.VCardSourceDetector;
23
24/**
25 * Class representing one request for importing vCard (given as a Uri).
26 *
27 * Mainly used when {@link ImportVCardActivity} requests {@link VCardService}
28 * to import some specific Uri.
29 *
30 * Note: This object's accepting only One Uri does NOT mean that
31 * there's only one vCard entry inside the instance, as one Uri often has multiple
32 * vCard entries inside it.
33 */
34public class ImportRequest {
35 /**
36 * Can be null (typically when there's no Account available in the system).
37 */
38 public final Account account;
39
40 /**
41 * Uri to be imported. May have different content than originally given from users, so
42 * when displaying user-friendly information (e.g. "importing xxx.vcf"), use
43 * {@link #displayName} instead.
44 *
45 * If this is null {@link #data} contains the byte stream of the vcard.
46 */
47 public final Uri uri;
48
49 /**
50 * Holds the byte stream of the vcard, if {@link #uri} is null.
51 */
52 public final byte[] data;
53
54 /**
55 * String to be displayed to the user to indicate the source of the VCARD.
56 */
57 public final String displayName;
58
59 /**
60 * Can be {@link VCardSourceDetector#PARSE_TYPE_UNKNOWN}.
61 */
62 public final int estimatedVCardType;
63
64 /**
65 * Can be null, meaning no preferable charset is available.
66 */
67 public final String estimatedCharset;
68
69 /**
70 * Assumes that one Uri contains only one version, while there's a (tiny) possibility
71 * we may have two types in one vCard.
72 *
73 * e.g.
74 * BEGIN:VCARD
75 * VERSION:2.1
76 * ...
77 * END:VCARD
78 * BEGIN:VCARD
79 * VERSION:3.0
80 * ...
81 * END:VCARD
82 *
83 * We've never seen this kind of a file, but we may have to cope with it in the future.
84 */
85 public final int vcardVersion;
86
87 /**
88 * The count of vCard entries in {@link #uri}. A receiver of this object can use it
89 * when showing the progress of import. Thus a receiver must be able to torelate this
90 * variable being invalid because of vCard's limitation.
91 *
92 * vCard does not let us know this count without looking over a whole file content,
93 * which means we have to open and scan over {@link #uri} to know this value, while
94 * it may not be opened more than once (Uri does not require it to be opened multiple times
95 * and may become invalid after its close() request).
96 */
97 public final int entryCount;
98
Jay Shrauner2ae200d2015-01-09 11:36:20 -080099 public ImportRequest(AccountWithDataSet account,
Chiao Chengd80c4342012-12-03 17:15:58 -0800100 byte[] data, Uri uri, String displayName, int estimatedType, String estimatedCharset,
101 int vcardVersion, int entryCount) {
Jay Shrauner2ae200d2015-01-09 11:36:20 -0800102 this.account = account != null ? account.getAccountOrNull() : null;
Chiao Chengd80c4342012-12-03 17:15:58 -0800103 this.data = data;
104 this.uri = uri;
105 this.displayName = displayName;
106 this.estimatedVCardType = estimatedType;
107 this.estimatedCharset = estimatedCharset;
108 this.vcardVersion = vcardVersion;
109 this.entryCount = entryCount;
110 }
111}