blob: c1a2493d2a6fbed392107fa758ae8d275a8c7722 [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;
Daisuke Miyakawa8c108072009-08-24 10:51:58 +090019import android.content.Context;
Daisuke Miyakawadcc2a9e2009-07-17 12:28:26 -070020import android.os.Handler;
21import android.pim.vcard.ContactStruct;
22import android.pim.vcard.EntryHandler;
23import android.pim.vcard.VCardConfig;
24import android.util.Log;
25
26public class ProgressShower implements EntryHandler {
27 public static final String LOG_TAG = "vcard.ProgressShower";
28
Daisuke Miyakawa8c108072009-08-24 10:51:58 +090029 private final Context mContext;
Daisuke Miyakawadcc2a9e2009-07-17 12:28:26 -070030 private final Handler mHandler;
31 private final ProgressDialog mProgressDialog;
32 private final String mProgressMessage;
Daisuke Miyakawadcc2a9e2009-07-17 12:28:26 -070033
34 private long mTime;
35
36 private class ShowProgressRunnable implements Runnable {
37 private ContactStruct mContact;
38
39 public ShowProgressRunnable(ContactStruct contact) {
40 mContact = contact;
41 }
42
43 public void run() {
Daisuke Miyakawa8c108072009-08-24 10:51:58 +090044 mProgressDialog.setMessage( mProgressMessage + "\n" +
45 mContact.getDisplayName());
46 mProgressDialog.incrementProgressBy(1);
Daisuke Miyakawadcc2a9e2009-07-17 12:28:26 -070047 }
48 }
49
50 public ProgressShower(ProgressDialog progressDialog,
51 String progressMessage,
Daisuke Miyakawa8c108072009-08-24 10:51:58 +090052 Context context,
53 Handler handler) {
54 mContext = context;
Daisuke Miyakawadcc2a9e2009-07-17 12:28:26 -070055 mHandler = handler;
56 mProgressDialog = progressDialog;
57 mProgressMessage = progressMessage;
Daisuke Miyakawadcc2a9e2009-07-17 12:28:26 -070058 }
Daisuke Miyakawa8c108072009-08-24 10:51:58 +090059
60 public void onParsingStart() {
61 }
62
Daisuke Miyakawadcc2a9e2009-07-17 12:28:26 -070063 public void onEntryCreated(ContactStruct contactStruct) {
64 long start = System.currentTimeMillis();
65
66 if (!contactStruct.isIgnorable()) {
67 if (mProgressDialog != null && mProgressMessage != null) {
68 if (mHandler != null) {
69 mHandler.post(new ShowProgressRunnable(contactStruct));
70 } else {
Daisuke Miyakawa8c108072009-08-24 10:51:58 +090071 mProgressDialog.setMessage(mContext.getString(R.string.progress_shower_message,
72 mProgressMessage,
73 contactStruct.getDisplayName()));
Daisuke Miyakawadcc2a9e2009-07-17 12:28:26 -070074 }
75 }
76 }
77
78 mTime += System.currentTimeMillis() - start;
79 }
80
Daisuke Miyakawa8c108072009-08-24 10:51:58 +090081 public void onParsingEnd() {
Daisuke Miyakawadcc2a9e2009-07-17 12:28:26 -070082 if (VCardConfig.showPerformanceLog()) {
83 Log.d(LOG_TAG,
Daisuke Miyakawa8c108072009-08-24 10:51:58 +090084 String.format("Time to progress a dialog: %d ms", mTime));
Daisuke Miyakawadcc2a9e2009-07-17 12:28:26 -070085 }
86 }
Daisuke Miyakawa8c108072009-08-24 10:51:58 +090087}