Home | History | Annotate | Download | only in vcard
      1 /*
      2  * Copyright (C) 2009 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 android.pim.vcard;
     17 
     18 import android.content.ContentResolver;
     19 import android.net.Uri;
     20 import android.util.Log;
     21 
     22 import java.util.ArrayList;
     23 
     24 /**
     25  * <P>
     26  * {@link VCardEntryHandler} implementation which commits the entry to ContentResolver.
     27  * </P>
     28  * <P>
     29  * Note:<BR />
     30  * Each vCard may contain big photo images encoded by BASE64,
     31  * If we store all vCard entries in memory, OutOfMemoryError may be thrown.
     32  * Thus, this class push each VCard entry into ContentResolver immediately.
     33  * </P>
     34  */
     35 public class VCardEntryCommitter implements VCardEntryHandler {
     36     public static String LOG_TAG = "VCardEntryComitter";
     37 
     38     private final ContentResolver mContentResolver;
     39     private long mTimeToCommit;
     40     private ArrayList<Uri> mCreatedUris = new ArrayList<Uri>();
     41 
     42     public VCardEntryCommitter(ContentResolver resolver) {
     43         mContentResolver = resolver;
     44     }
     45 
     46     public void onStart() {
     47     }
     48 
     49     public void onEnd() {
     50         if (VCardConfig.showPerformanceLog()) {
     51             Log.d(LOG_TAG, String.format("time to commit entries: %d ms", mTimeToCommit));
     52         }
     53     }
     54 
     55     public void onEntryCreated(final VCardEntry vcardEntry) {
     56         long start = System.currentTimeMillis();
     57         mCreatedUris.add(vcardEntry.pushIntoContentResolver(mContentResolver));
     58         mTimeToCommit += System.currentTimeMillis() - start;
     59     }
     60 
     61     /**
     62      * Returns the list of created Uris. This list should not be modified by the caller as it is
     63      * not a clone.
     64      */
     65    public ArrayList<Uri> getCreatedUris() {
     66         return mCreatedUris;
     67     }
     68 }