Daisuke Miyakawa | dcc2a9e | 2009-07-17 12:28:26 -0700 | [diff] [blame] | 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 com.android.contacts; |
| 17 | |
| 18 | import android.app.ProgressDialog; |
Daisuke Miyakawa | 8c10807 | 2009-08-24 10:51:58 +0900 | [diff] [blame^] | 19 | import android.content.Context; |
Daisuke Miyakawa | dcc2a9e | 2009-07-17 12:28:26 -0700 | [diff] [blame] | 20 | import android.os.Handler; |
| 21 | import android.pim.vcard.ContactStruct; |
| 22 | import android.pim.vcard.EntryHandler; |
| 23 | import android.pim.vcard.VCardConfig; |
| 24 | import android.util.Log; |
| 25 | |
| 26 | public class ProgressShower implements EntryHandler { |
| 27 | public static final String LOG_TAG = "vcard.ProgressShower"; |
| 28 | |
Daisuke Miyakawa | 8c10807 | 2009-08-24 10:51:58 +0900 | [diff] [blame^] | 29 | private final Context mContext; |
Daisuke Miyakawa | dcc2a9e | 2009-07-17 12:28:26 -0700 | [diff] [blame] | 30 | private final Handler mHandler; |
| 31 | private final ProgressDialog mProgressDialog; |
| 32 | private final String mProgressMessage; |
Daisuke Miyakawa | dcc2a9e | 2009-07-17 12:28:26 -0700 | [diff] [blame] | 33 | |
| 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 Miyakawa | 8c10807 | 2009-08-24 10:51:58 +0900 | [diff] [blame^] | 44 | mProgressDialog.setMessage( mProgressMessage + "\n" + |
| 45 | mContact.getDisplayName()); |
| 46 | mProgressDialog.incrementProgressBy(1); |
Daisuke Miyakawa | dcc2a9e | 2009-07-17 12:28:26 -0700 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | |
| 50 | public ProgressShower(ProgressDialog progressDialog, |
| 51 | String progressMessage, |
Daisuke Miyakawa | 8c10807 | 2009-08-24 10:51:58 +0900 | [diff] [blame^] | 52 | Context context, |
| 53 | Handler handler) { |
| 54 | mContext = context; |
Daisuke Miyakawa | dcc2a9e | 2009-07-17 12:28:26 -0700 | [diff] [blame] | 55 | mHandler = handler; |
| 56 | mProgressDialog = progressDialog; |
| 57 | mProgressMessage = progressMessage; |
Daisuke Miyakawa | dcc2a9e | 2009-07-17 12:28:26 -0700 | [diff] [blame] | 58 | } |
Daisuke Miyakawa | 8c10807 | 2009-08-24 10:51:58 +0900 | [diff] [blame^] | 59 | |
| 60 | public void onParsingStart() { |
| 61 | } |
| 62 | |
Daisuke Miyakawa | dcc2a9e | 2009-07-17 12:28:26 -0700 | [diff] [blame] | 63 | 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 Miyakawa | 8c10807 | 2009-08-24 10:51:58 +0900 | [diff] [blame^] | 71 | mProgressDialog.setMessage(mContext.getString(R.string.progress_shower_message, |
| 72 | mProgressMessage, |
| 73 | contactStruct.getDisplayName())); |
Daisuke Miyakawa | dcc2a9e | 2009-07-17 12:28:26 -0700 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | mTime += System.currentTimeMillis() - start; |
| 79 | } |
| 80 | |
Daisuke Miyakawa | 8c10807 | 2009-08-24 10:51:58 +0900 | [diff] [blame^] | 81 | public void onParsingEnd() { |
Daisuke Miyakawa | dcc2a9e | 2009-07-17 12:28:26 -0700 | [diff] [blame] | 82 | if (VCardConfig.showPerformanceLog()) { |
| 83 | Log.d(LOG_TAG, |
Daisuke Miyakawa | 8c10807 | 2009-08-24 10:51:58 +0900 | [diff] [blame^] | 84 | String.format("Time to progress a dialog: %d ms", mTime)); |
Daisuke Miyakawa | dcc2a9e | 2009-07-17 12:28:26 -0700 | [diff] [blame] | 85 | } |
| 86 | } |
Daisuke Miyakawa | 8c10807 | 2009-08-24 10:51:58 +0900 | [diff] [blame^] | 87 | } |