blob: 94985692bc0c1211f3bdec851f3045b558f8dce1 [file] [log] [blame]
Daisuke Miyakawadcc2a9e2009-07-17 12:28:26 -07001/*
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 */
16package com.android.contacts;
17
18import android.app.ProgressDialog;
19import android.os.Handler;
20import android.pim.vcard.ContactStruct;
21import android.pim.vcard.EntryHandler;
22import android.pim.vcard.VCardConfig;
23import android.util.Log;
24
25public class ProgressShower implements EntryHandler {
26 public static final String LOG_TAG = "vcard.ProgressShower";
27
28 private final Handler mHandler;
29 private final ProgressDialog mProgressDialog;
30 private final String mProgressMessage;
31 private final boolean mIncrementProgress;
32
33 private long mTime;
34
35 private class ShowProgressRunnable implements Runnable {
36 private ContactStruct mContact;
37
38 public ShowProgressRunnable(ContactStruct contact) {
39 mContact = contact;
40 }
41
42 public void run() {
43 mProgressDialog.setMessage(mProgressMessage + "\n" +
44 mContact.displayString());
45 if (mIncrementProgress) {
46 mProgressDialog.incrementProgressBy(1);
47 }
48 }
49 }
50
51 public ProgressShower(ProgressDialog progressDialog,
52 String progressMessage,
53 Handler handler,
54 boolean incrementProgress) {
55 mHandler = handler;
56 mProgressDialog = progressDialog;
57 mProgressMessage = progressMessage;
58 mIncrementProgress = incrementProgress;
59 }
60
61 public void onEntryCreated(ContactStruct contactStruct) {
62 long start = System.currentTimeMillis();
63
64 if (!contactStruct.isIgnorable()) {
65 if (mProgressDialog != null && mProgressMessage != null) {
66 if (mHandler != null) {
67 mHandler.post(new ShowProgressRunnable(contactStruct));
68 } else {
69 mProgressDialog.setMessage(mProgressMessage + "\n" +
70 contactStruct.displayString());
71 }
72 }
73 }
74
75 mTime += System.currentTimeMillis() - start;
76 }
77
78 public void onFinal() {
79 if (VCardConfig.showPerformanceLog()) {
80 Log.d(LOG_TAG,
81 String.format("Time to progress a dialog: %ld ms", mTime));
82 }
83 }
84}