1 /* 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 */ 16 package com.android.contacts.common.vcard; 17 18 import android.accounts.Account; 19 import android.net.Uri; 20 21 import com.android.vcard.VCardSourceDetector; 22 23 /** 24 * Class representing one request for importing vCard (given as a Uri). 25 * 26 * Mainly used when {@link ImportVCardActivity} requests {@link VCardService} 27 * to import some specific Uri. 28 * 29 * Note: This object's accepting only One Uri does NOT mean that 30 * there's only one vCard entry inside the instance, as one Uri often has multiple 31 * vCard entries inside it. 32 */ 33 public class ImportRequest { 34 /** 35 * Can be null (typically when there's no Account available in the system). 36 */ 37 public final Account account; 38 39 /** 40 * Uri to be imported. May have different content than originally given from users, so 41 * when displaying user-friendly information (e.g. "importing xxx.vcf"), use 42 * {@link #displayName} instead. 43 * 44 * If this is null {@link #data} contains the byte stream of the vcard. 45 */ 46 public final Uri uri; 47 48 /** 49 * Holds the byte stream of the vcard, if {@link #uri} is null. 50 */ 51 public final byte[] data; 52 53 /** 54 * String to be displayed to the user to indicate the source of the VCARD. 55 */ 56 public final String displayName; 57 58 /** 59 * Can be {@link VCardSourceDetector#PARSE_TYPE_UNKNOWN}. 60 */ 61 public final int estimatedVCardType; 62 63 /** 64 * Can be null, meaning no preferable charset is available. 65 */ 66 public final String estimatedCharset; 67 68 /** 69 * Assumes that one Uri contains only one version, while there's a (tiny) possibility 70 * we may have two types in one vCard. 71 * 72 * e.g. 73 * BEGIN:VCARD 74 * VERSION:2.1 75 * ... 76 * END:VCARD 77 * BEGIN:VCARD 78 * VERSION:3.0 79 * ... 80 * END:VCARD 81 * 82 * We've never seen this kind of a file, but we may have to cope with it in the future. 83 */ 84 public final int vcardVersion; 85 86 /** 87 * The count of vCard entries in {@link #uri}. A receiver of this object can use it 88 * when showing the progress of import. Thus a receiver must be able to torelate this 89 * variable being invalid because of vCard's limitation. 90 * 91 * vCard does not let us know this count without looking over a whole file content, 92 * which means we have to open and scan over {@link #uri} to know this value, while 93 * it may not be opened more than once (Uri does not require it to be opened multiple times 94 * and may become invalid after its close() request). 95 */ 96 public final int entryCount; 97 98 public ImportRequest(Account account, 99 byte[] data, Uri uri, String displayName, int estimatedType, String estimatedCharset, 100 int vcardVersion, int entryCount) { 101 this.account = account; 102 this.data = data; 103 this.uri = uri; 104 this.displayName = displayName; 105 this.estimatedVCardType = estimatedType; 106 this.estimatedCharset = estimatedCharset; 107 this.vcardVersion = vcardVersion; 108 this.entryCount = entryCount; 109 } 110 } 111