• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
19 import android.content.Context;
20 import android.os.Handler;
21 import android.pim.vcard.VCardEntry;
22 import android.pim.vcard.VCardEntryHandler;
23 import android.pim.vcard.VCardConfig;
24 import android.util.Log;
25 
26 public class ProgressShower implements VCardEntryHandler {
27     public static final String LOG_TAG = "vcard.ProgressShower";
28 
29     private final Context mContext;
30     private final Handler mHandler;
31     private final ProgressDialog mProgressDialog;
32     private final String mProgressMessage;
33 
34     private long mTime;
35 
36     private class ShowProgressRunnable implements Runnable {
37         private VCardEntry mContact;
38 
ShowProgressRunnable(VCardEntry contact)39         public ShowProgressRunnable(VCardEntry contact) {
40             mContact = contact;
41         }
42 
run()43         public void run() {
44             mProgressDialog.setMessage( mProgressMessage + "\n" +
45                     mContact.getDisplayName());
46             mProgressDialog.incrementProgressBy(1);
47         }
48     }
49 
ProgressShower(ProgressDialog progressDialog, String progressMessage, Context context, Handler handler)50     public ProgressShower(ProgressDialog progressDialog,
51             String progressMessage,
52             Context context,
53             Handler handler) {
54         mContext = context;
55         mHandler = handler;
56         mProgressDialog = progressDialog;
57         mProgressMessage = progressMessage;
58     }
59 
onStart()60     public void onStart() {
61     }
62 
onEntryCreated(VCardEntry contactStruct)63     public void onEntryCreated(VCardEntry 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 {
71                     mProgressDialog.setMessage(mContext.getString(R.string.progress_shower_message,
72                             mProgressMessage,
73                             contactStruct.getDisplayName()));
74                 }
75             }
76         }
77 
78         mTime += System.currentTimeMillis() - start;
79     }
80 
onEnd()81     public void onEnd() {
82         if (VCardConfig.showPerformanceLog()) {
83             Log.d(LOG_TAG,
84                     String.format("Time to progress a dialog: %d ms", mTime));
85         }
86     }
87 }
88