/android/import-contacts

To get this branch, use:
bzr branch http://bzr.ed.am/android/import-contacts

« back to all changes in this revision

Viewing changes to src/org/waxworlds/importcontacts/Doit.java

  • Committer: edam
  • Date: 2009-01-10 16:14:11 UTC
  • Revision ID: edam@waxworlds.org-20090110161411-4d17l9hs9d6j277q
Initial import

Show diffs side-by-side

added added

removed removed

1
 
/*
2
 
 * Doit.java
3
 
 *
4
 
 * Copyright (C) 2009 Tim Marston <tim@ed.am>
5
 
 *
6
 
 * This file is part of the Import Contacts program (hereafter referred
7
 
 * to as "this program").  For more information, see
8
 
 * http://ed.am/dev/android/import-contacts
9
 
 *
10
 
 * This program is free software: you can redistribute it and/or modify
11
 
 * it under the terms of the GNU General Public License as published by
12
 
 * the Free Software Foundation, either version 3 of the License, or
13
 
 * (at your option) any later version.
14
 
 *
15
 
 * This program is distributed in the hope that it will be useful,
16
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 
 * GNU General Public License for more details.
19
 
 *
20
 
 * You should have received a copy of the GNU General Public License
21
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 
 */
23
 
 
24
 
package am.ed.importcontacts;
 
1
package org.waxworlds.importcontacts;
25
2
 
26
3
import android.app.AlertDialog;
27
4
import android.app.Dialog;
36
13
import android.widget.Button;
37
14
import android.widget.CheckBox;
38
15
import android.widget.CompoundButton;
 
16
import android.widget.LinearLayout;
39
17
import android.widget.ProgressBar;
40
18
import android.widget.TextView;
41
 
import android.widget.Toast;
42
19
 
43
20
public class Doit extends WizardActivity
44
21
{
46
23
        private final static int DIALOG_CONTINUEORABORT = 1;
47
24
        private final static int DIALOG_MERGEPROMPT = 2;
48
25
 
49
 
        public final static int MESSAGE_ALLDONE = 0;
50
 
        public final static int MESSAGE_ABORT = 1;
51
 
        public final static int MESSAGE_ERROR = 3;
52
 
        public final static int MESSAGE_CONTINUEORABORT = 4;
53
 
        public final static int MESSAGE_SETPROGRESSMESSAGE = 5;
54
 
        public final static int MESSAGE_SETMAXPROGRESS = 6;
55
 
        public final static int MESSAGE_SETTMPPROGRESS = 7;
56
 
        public final static int MESSAGE_SETPROGRESS = 8;
57
 
        public final static int MESSAGE_MERGEPROMPT = 9;
58
 
        public final static int MESSAGE_CONTACTOVERWRITTEN = 10;
59
 
        public final static int MESSAGE_CONTACTCREATED = 11;
60
 
        public final static int MESSAGE_CONTACTMERGED = 12;
61
 
        public final static int MESSAGE_CONTACTSKIPPED = 13;
62
 
 
63
 
        public final static int ACTION_PROMPT = 0;
64
 
        public final static int ACTION_KEEP = 1;
65
 
        public final static int ACTION_MERGE_MERGE = 2;
66
 
        public final static int ACTION_OVERWRITE = 3;
67
 
 
68
 
        public final static int NEXT_BEGIN = 0;
69
 
        public final static int NEXT_CLOSE = 1;
70
 
 
71
 
        private boolean _started_progress;
72
 
        private int _max_progress;
73
 
        private int _tmp_progress;
 
26
        private boolean _startedProgress;
 
27
        private int _maxProgress;
 
28
        private int _tmpProgress;
74
29
        private int _progress;
75
 
        protected String _dialog_message;
76
 
        private Dialog _merge_prompt_dialog;
77
 
        private boolean _merge_prompt_always_selected;
78
 
        private int _next_action;
79
 
        private int _current_dialog_id;
80
 
 
81
 
        private int _count_overwrites;
82
 
        private int _count_creates;
83
 
        private int _count_merges;
84
 
        private int _count_skips;
85
 
 
86
 
        protected Importer _importer = null;
 
30
        protected String _dialogMessage;
 
31
        private Dialog _mergePromptDialog;
 
32
        private boolean _mergePromptAlwaysSelected;
 
33
 
 
34
        private int _countOverwrites;
 
35
        private int _countCreates;
 
36
        private int _countMerges;
 
37
        private int _countSkips;
 
38
 
 
39
        protected Importer _importer;
87
40
 
88
41
        public Handler _handler;
89
42
 
93
46
                public void handleMessage( Message msg ) {
94
47
                        switch( msg.what )
95
48
                        {
96
 
                        case MESSAGE_ALLDONE:
97
 
                                ( (TextView)findViewById( R.id.doit_alldone ) ).
98
 
                                        setVisibility( View.VISIBLE );
99
 
                                ( (Button)findViewById( R.id.back ) ).setEnabled( false );
100
 
                                updateNext( NEXT_CLOSE );
101
 
                                findViewById( R.id.doit_abort_disp ).setVisibility(
102
 
                                        View.GONE );
103
 
                                break;
104
 
                        case MESSAGE_ABORT:
105
 
                                manualAbort();
106
 
                                break;
107
 
                        case MESSAGE_ERROR:
108
 
                                _dialog_message = (String)msg.obj;
 
49
                        case Importer.MESSAGE_FINISHED:
 
50
                                ( (LinearLayout)findViewById( R.id.doit_closedisplay ) ).
 
51
                                                setVisibility( View.VISIBLE );
 
52
                                break;
 
53
                        case Importer.MESSAGE_FINISHED_BACK:
 
54
                                ( (Button)findViewById( R.id.back ) ).setEnabled( true );
 
55
                                break;
 
56
                        case Importer.MESSAGE_ERROR:
 
57
                                Doit.this._dialogMessage = (String)msg.obj;
109
58
                                showDialog( DIALOG_ERROR );
110
59
                                break;
111
 
                        case MESSAGE_CONTINUEORABORT:
112
 
                                _dialog_message = (String)msg.obj;
 
60
                        case Importer.MESSAGE_CONTINUEORABORT:
 
61
                                Doit.this._dialogMessage = (String)msg.obj;
113
62
                                showDialog( DIALOG_CONTINUEORABORT );
114
63
                                break;
115
 
                        case MESSAGE_SETPROGRESSMESSAGE:
 
64
                        case Importer.MESSAGE_SETPROGRESSMESSAGE:
116
65
                                ( (TextView)findViewById( R.id.doit_percentage ) ).
117
 
                                        setText( (String)msg.obj );
 
66
                                                setText( (String)msg.obj );
118
67
                                break;
119
 
                        case MESSAGE_SETMAXPROGRESS:
120
 
                                if( _max_progress > 0 ) {
121
 
                                        if( _tmp_progress == _max_progress - 1 )
122
 
                                                _tmp_progress = (Integer)msg.obj;
123
 
                                        if( _progress == _max_progress - 1 )
 
68
                        case Importer.MESSAGE_SETMAXPROGRESS:
 
69
                                if( _maxProgress > 0 ) {
 
70
                                        if( _tmpProgress == _maxProgress )
 
71
                                                _tmpProgress = (Integer)msg.obj;
 
72
                                        if( _progress == _maxProgress )
124
73
                                                _progress = (Integer)msg.obj;
125
74
                                }
126
 
                                _max_progress = (Integer)msg.obj;
127
 
                                updateProgress();
128
 
                                break;
129
 
                        case MESSAGE_SETTMPPROGRESS:
130
 
                                _tmp_progress = (Integer)msg.obj;
131
 
                                updateProgress();
132
 
                                break;
133
 
                        case MESSAGE_SETPROGRESS:
134
 
                                _started_progress = true;
 
75
                                _maxProgress = (Integer)msg.obj;
 
76
                                updateProgress();
 
77
                                break;
 
78
                        case Importer.MESSAGE_SETTMPPROGRESS:
 
79
                                _tmpProgress = (Integer)msg.obj;
 
80
                                updateProgress();
 
81
                                break;
 
82
                        case Importer.MESSAGE_SETPROGRESS:
 
83
                                _startedProgress = true;
135
84
                                _progress = (Integer)msg.obj;
136
85
                                updateProgress();
137
86
                                break;
138
 
                        case MESSAGE_MERGEPROMPT:
139
 
                                _dialog_message = (String)msg.obj;
 
87
                        case Importer.MESSAGE_MERGEPROMPT:
 
88
                                _dialogMessage = (String)msg.obj;
140
89
                                showDialog( DIALOG_MERGEPROMPT );
141
90
                                break;
142
 
                        case MESSAGE_CONTACTOVERWRITTEN:
143
 
                                _count_overwrites++;
144
 
                                updateStats();
145
 
                                break;
146
 
                        case MESSAGE_CONTACTCREATED:
147
 
                                _count_creates++;
148
 
                                updateStats();
149
 
                                break;
150
 
                        case MESSAGE_CONTACTMERGED:
151
 
                                _count_merges++;
152
 
                                updateStats();
153
 
                                break;
154
 
                        case MESSAGE_CONTACTSKIPPED:
155
 
                                _count_skips++;
 
91
                        case Importer.MESSAGE_CONTACTOVERWRITTEN:
 
92
                                _countOverwrites++;
 
93
                                updateStats();
 
94
                                break;
 
95
                        case Importer.MESSAGE_CONTACTCREATED:
 
96
                                _countCreates++;
 
97
                                updateStats();
 
98
                                break;
 
99
                        case Importer.MESSAGE_CONTACTMERGED:
 
100
                                _countMerges++;
 
101
                                updateStats();
 
102
                                break;
 
103
                        case Importer.MESSAGE_CONTACTSKIPPED:
 
104
                                _countSkips++;
156
105
                                updateStats();
157
106
                                break;
158
107
                        default:
162
111
        }
163
112
 
164
113
        @Override
165
 
        protected void onCreate(Bundle saved_instance_state)
 
114
        protected void onCreate(Bundle savedInstanceState)
166
115
        {
167
116
                setContentView( R.layout.doit );
168
 
                super.onCreate( saved_instance_state );
 
117
                super.onCreate( savedInstanceState );
169
118
 
170
119
                // hide page 2
171
120
                ( findViewById( R.id.doit_page_2 ) ).setVisibility( View.GONE );
172
121
 
173
 
                // set up abort button
174
 
                Button begin = (Button)findViewById( R.id.abort );
 
122
                // set up begin button
 
123
                Button begin = (Button)findViewById( R.id.doit_begin );
175
124
                begin.setOnClickListener( new View.OnClickListener() {
176
125
                        public void onClick( View view ) {
177
 
                                manualAbort();
178
 
                        }
179
 
                } );
180
 
 
181
 
                _started_progress = false;
182
 
                _max_progress = 0;
183
 
                _tmp_progress = 0;
 
126
                                importContacts();
 
127
                        }
 
128
                } );
 
129
 
 
130
                // set up close button
 
131
                Button close = (Button)findViewById( R.id.doit_close );
 
132
                close.setOnClickListener( new View.OnClickListener() {
 
133
                        public void onClick( View view ) {
 
134
                                setResult( RESULT_CANCELED );
 
135
                                finish();
 
136
                        }
 
137
                } );
 
138
 
 
139
 
 
140
 
 
141
                _startedProgress = false;
 
142
                _maxProgress = 0;
 
143
                _tmpProgress = 0;
184
144
                _progress = 0;
185
145
                _handler = new DoitHandler();
186
146
 
187
 
                _count_overwrites = 0;
188
 
                _count_creates = 0;
189
 
                _count_merges = 0;
190
 
                _count_skips = 0;
191
 
 
192
 
                updateNext( NEXT_BEGIN );
 
147
                _countOverwrites = 0;
 
148
                _countCreates = 0;
 
149
                _countMerges = 0;
 
150
                _countSkips = 0;
193
151
 
194
152
                updateProgress();
195
153
                updateStats();
200
158
        {
201
159
                super.onPause();
202
160
 
203
 
                // saving the state of an import sounds complicated! Lets just abort!
204
 
                if( _next_action != NEXT_CLOSE )
205
 
                        manualAbort( true );
 
161
                abortImport();
 
162
 
 
163
                // notify the user
 
164
 
 
165
 
206
166
        }
207
167
 
208
168
        @Override
209
 
        protected Dialog onCreateDialog( int id )
 
169
        protected Dialog onCreateDialog(int id)
210
170
        {
211
171
                switch( id )
212
172
                {
213
173
                case DIALOG_ERROR:
214
174
                        return new AlertDialog.Builder( this )
215
 
                                .setIcon( R.drawable.alert_dialog_icon )
216
 
                                .setTitle( R.string.error_title )
217
 
                                .setMessage( "" )
218
 
                                .setPositiveButton( R.string.error_ok,
219
 
                                        new DialogInterface.OnClickListener() {
220
 
                                                public void onClick( DialogInterface dialog,
221
 
                                                        int whichButton )
222
 
                                                {
223
 
                                                        if( Doit.this != null )
224
 
                                                                Doit.this._importer.wake();
 
175
                                        .setIcon( R.drawable.alert_dialog_icon )
 
176
                                        .setTitle( R.string.error_title )
 
177
                                        .setMessage( "" )
 
178
                                        .setPositiveButton( R.string.error_ok,
 
179
                                                        new DialogInterface.OnClickListener() {
 
180
                                                public void onClick(DialogInterface dialog,
 
181
                                                                int whichButton) {
 
182
                                                        Doit.this._importer.wake();
225
183
                                                }
226
184
                                        } )
227
 
                                .setOnCancelListener( _dialog_on_cancel_listener )
228
 
                                .create();
 
185
                                        .setOnCancelListener( _dialogOnCancelListener )
 
186
                                        .create();
229
187
                case DIALOG_CONTINUEORABORT:
230
188
                        return new AlertDialog.Builder( this )
231
 
                                .setIcon( R.drawable.alert_dialog_icon )
232
 
                                .setTitle( R.string.error_title )
233
 
                                .setMessage( "" )
234
 
                                .setPositiveButton( R.string.error_continue,
235
 
                                        new DialogInterface.OnClickListener() {
236
 
                                                public void onClick( DialogInterface dialog,
237
 
                                                        int which_button )
238
 
                                                {
239
 
                                                        if( Doit.this != null )
240
 
                                                                Doit.this._importer.wake(
 
189
                                        .setIcon( R.drawable.alert_dialog_icon )
 
190
                                        .setTitle( R.string.error_title )
 
191
                                        .setMessage( "" )
 
192
                                        .setPositiveButton( R.string.error_continue,
 
193
                                                        new DialogInterface.OnClickListener() {
 
194
                                                public void onClick(DialogInterface dialog,
 
195
                                                                int whichButton) {
 
196
                                                        Doit.this._importer.wake(
241
197
                                                                        Importer.RESPONSE_POSITIVE );
242
198
                                                }
243
199
                                        } )
244
 
                                .setNegativeButton( R.string.error_abort,
245
 
                                        new DialogInterface.OnClickListener() {
246
 
                                                public void onClick( DialogInterface dialog,
247
 
                                                        int which_button )
248
 
                                                {
249
 
                                                        if( Doit.this != null )
250
 
                                                                Doit.this._importer.wake(
 
200
                                        .setNegativeButton( R.string.error_abort,
 
201
                                                        new DialogInterface.OnClickListener() {
 
202
                                                public void onClick(DialogInterface dialog,
 
203
                                                                int whichButton) {
 
204
                                                        Doit.this._importer.wake(
251
205
                                                                        Importer.RESPONSE_NEGATIVE );
252
206
                                                }
253
207
                                        } )
254
 
                                .setOnCancelListener( _dialog_on_cancel_listener )
255
 
                                .create();
 
208
                                        .setOnCancelListener( _dialogOnCancelListener )
 
209
                                        .create();
256
210
                case DIALOG_MERGEPROMPT:
257
211
                        // custom layout in an AlertDialog
258
212
                        LayoutInflater factory = LayoutInflater.from( this );
259
 
                        final View dialog_view = factory.inflate(
260
 
                                R.layout.mergeprompt, null );
261
 
                        ( (CheckBox)dialog_view.findViewById( R.id.mergeprompt_always ) ).
262
 
                                setOnCheckedChangeListener(
263
 
                                        new CompoundButton.OnCheckedChangeListener() {
264
 
                                                public void onCheckedChanged(
265
 
                                                        CompoundButton button_view, boolean is_checked )
266
 
                                                {
267
 
                                                        if( Doit.this != null )
268
 
                                                                Doit.this._merge_prompt_always_selected =
269
 
                                                                        is_checked;
270
 
                                                }
271
 
                                        } );
272
 
                        ( (Button)dialog_view.findViewById( R.id.merge_keep ) ).
273
 
                                setOnClickListener( _merge_prompt_button_listener );
274
 
                        ( (Button)dialog_view.findViewById( R.id.merge_overwrite ) ).
275
 
                                setOnClickListener( _merge_prompt_button_listener );
276
 
                        ( (Button)dialog_view.findViewById( R.id.merge_merge ) ).
277
 
                                setOnClickListener( _merge_prompt_button_listener );
278
 
                        ( (Button)dialog_view.findViewById( R.id.abort ) ).
279
 
                                setOnClickListener( _merge_prompt_button_listener );
280
 
                        _merge_prompt_always_selected = false;
 
213
                        final View dialogView = factory.inflate(
 
214
                                        R.layout.mergeprompt, null );
 
215
                        ( (CheckBox)dialogView.findViewById( R.id.mergeprompt_always ) ).
 
216
                                        setOnCheckedChangeListener(
 
217
                                                        new CompoundButton.OnCheckedChangeListener() {
 
218
                                public void onCheckedChanged( CompoundButton buttonView,
 
219
                                                boolean isChecked ) {
 
220
                                        Doit.this._mergePromptAlwaysSelected = isChecked;
 
221
                                }
 
222
                        } );
 
223
                        ( (Button)dialogView.findViewById( R.id.merge_keep ) ).
 
224
                                        setOnClickListener( _mergePromptButtonListener );
 
225
                        ( (Button)dialogView.findViewById( R.id.merge_overwrite ) ).
 
226
                                        setOnClickListener( _mergePromptButtonListener );
 
227
                        ( (Button)dialogView.findViewById( R.id.merge_merge ) ).
 
228
                                        setOnClickListener( _mergePromptButtonListener );
 
229
                        _mergePromptAlwaysSelected = false;
281
230
                        return new AlertDialog.Builder( this )
282
 
                                .setIcon( R.drawable.alert_dialog_icon )
283
 
                                .setTitle( R.string.mergeprompt_title )
284
 
                                .setView( dialog_view )
285
 
                                .setOnCancelListener( _dialog_on_cancel_listener )
286
 
                                .create();
 
231
                                        .setIcon( R.drawable.alert_dialog_icon )
 
232
                                        .setTitle( R.string.mergeprompt_title )
 
233
                                        .setView( dialogView )
 
234
                                        .setOnCancelListener( _dialogOnCancelListener )
 
235
                                        .create();
287
236
                }
288
237
                return null;
289
238
        }
290
239
 
291
 
        private OnClickListener _merge_prompt_button_listener =
292
 
                new OnClickListener()
293
 
        {
294
 
                public void onClick( View view )
295
 
                {
296
 
                        if( Doit.this == null ) return;
297
 
 
298
 
                        // handle abort
299
 
                        if( view.getId() == R.id.abort )
300
 
                                manualAbort();
301
 
 
302
 
                        // else, response (just check we haven't aborted already!)
303
 
                        else if( Doit.this._importer != null ) {
304
 
                                int response_extra = _merge_prompt_always_selected?
 
240
    private OnClickListener _mergePromptButtonListener = new OnClickListener() {
 
241
                public void onClick( View view ) {
 
242
                        int responseExtra = _mergePromptAlwaysSelected?
305
243
                                        Importer.RESPONSEEXTRA_ALWAYS : Importer.RESPONSEEXTRA_NONE;
306
 
                                Doit.this._importer.wake( convertIdToAction( view.getId() ),
307
 
                                        response_extra );
308
 
                        }
309
 
 
310
 
                        // close dialog and free (don't keep a reference)
311
 
                        Doit.this._merge_prompt_dialog.dismiss();
312
 
                        Doit.this._merge_prompt_dialog = null;
 
244
                        Doit.this._mergePromptDialog.dismiss();
 
245
                        Doit.this._mergePromptDialog = null;    // dont keep a reference!
 
246
                        Doit.this._importer.wake( view.getId(), responseExtra );
313
247
                }
314
248
        };
315
249
 
316
 
        @Override
317
 
        protected void onNext()
318
 
        {
319
 
                Button next = (Button)findViewById( R.id.next );
320
 
                next.setEnabled( false );
321
 
 
322
 
                switch( _next_action )
323
 
                {
324
 
                case NEXT_BEGIN:
325
 
                        importContacts();
326
 
                        break;
327
 
                case NEXT_CLOSE:
328
 
                        setResult( RESULT_OK );
 
250
        private DialogInterface.OnCancelListener _dialogOnCancelListener =
 
251
                        new DialogInterface.OnCancelListener() {
 
252
                public void onCancel( DialogInterface dialog ) {
 
253
                        setResult( RESULT_CANCELED );
329
254
                        finish();
330
 
                        break;
331
 
                }
332
 
        }
333
 
 
334
 
        private void manualAbort()
335
 
        {
336
 
                manualAbort( false );
337
 
        }
338
 
 
339
 
        private void manualAbort( boolean show_toaster_popup )
340
 
        {
341
 
                abortImport( show_toaster_popup );
342
 
 
343
 
                updateNext( NEXT_CLOSE );
344
 
                ( (Button)findViewById( R.id.back ) ).setEnabled( true );
345
 
                findViewById( R.id.doit_abort_disp ).setVisibility( View.GONE );
346
 
                ( (TextView)findViewById( R.id.doit_aborted ) ).
347
 
                        setVisibility( View.VISIBLE );
348
 
                ( (TextView)findViewById( R.id.doit_alldone ) ).
349
 
                        setVisibility( View.GONE );
350
 
 
351
 
                // close any open dialogs
352
 
                try {
353
 
                        dismissDialog( _current_dialog_id );
354
 
                }
355
 
                catch( Exception e ) {
356
 
                        // ignore errors
357
 
                }
358
 
        }
359
 
 
360
 
        private void updateNext( int next_action )
361
 
        {
362
 
                Button next = (Button)findViewById( R.id.next );
363
 
                switch( next_action ) {
364
 
                case NEXT_BEGIN:        next.setText( R.string.doit_begin ); break;
365
 
                case NEXT_CLOSE:        next.setText( R.string.doit_close ); break;
366
 
                }
367
 
                next.setEnabled( true );
368
 
                _next_action = next_action;
369
 
        }
370
 
 
371
 
        public static int convertIdToAction( int id ) {
372
 
                switch( id ) {
373
 
                case R.id.merge_keep:           return ACTION_KEEP;
374
 
                case R.id.merge_merge:          return ACTION_MERGE_MERGE;
375
 
                case R.id.merge_overwrite:      return ACTION_OVERWRITE;
376
 
                default: return ACTION_PROMPT;
377
 
                }
378
 
        }
379
 
 
380
 
        public static int convertActionToId( int action ) {
381
 
                switch( action ) {
382
 
                case ACTION_KEEP:               return R.id.merge_keep;
383
 
                case ACTION_MERGE_MERGE:return R.id.merge_merge;
384
 
                case ACTION_OVERWRITE:  return R.id.merge_overwrite;
385
 
                default: return R.id.merge_prompt;
386
 
                }
387
 
        }
388
 
 
389
 
        private DialogInterface.OnCancelListener _dialog_on_cancel_listener =
390
 
                new DialogInterface.OnCancelListener()
391
 
        {
392
 
                public void onCancel( DialogInterface dialog ) {
393
 
                        manualAbort();
394
255
                }
395
256
        };
396
257
 
397
 
 
398
258
        @Override
399
 
        protected void onActivityResult( int request_code, int result_code,
400
 
                Intent data )
 
259
        protected void onActivityResult( int requestCode, int resultCode,
 
260
                        Intent data )
401
261
        {
402
 
                // if we're cancelling, abort any import
403
 
                if( result_code == RESULT_CANCELED )
404
 
                        abortImport( true );
 
262
                if( resultCode == RESULT_CANCELED )
 
263
                        abortImport();
405
264
        }
406
265
 
407
266
        @Override
408
 
        protected void onPrepareDialog( int id, Dialog dialog )
 
267
        protected void onPrepareDialog(int id, Dialog dialog)
409
268
        {
410
 
                _current_dialog_id = id;
411
 
 
412
269
                switch( id )
413
270
                {
414
271
                case DIALOG_ERROR:      // fall through
415
272
                case DIALOG_CONTINUEORABORT:
416
273
                        // set dialog message
417
 
                        ( (AlertDialog)dialog ).setMessage( _dialog_message );
 
274
                        ( (AlertDialog)dialog ).setMessage( _dialogMessage );
418
275
                        break;
419
276
                case DIALOG_MERGEPROMPT:
420
277
                        // set contact's name
421
 
                        ( (TextView)dialog.findViewById( R.id.mergeprompt_name ) )
422
 
                                .setText( _dialog_message );
 
278
                        ( (TextView)dialog.findViewById( R.id.mergeprompt_name ) ).setText(
 
279
                                        _dialogMessage );
423
280
                        // and set up reference to dialog
424
 
                        _merge_prompt_dialog = dialog;
 
281
                        _mergePromptDialog = dialog;
425
282
                        break;
426
283
                }
427
284
 
438
295
                ( (Button)findViewById( R.id.back ) ).setEnabled( false );
439
296
 
440
297
                // create importer
441
 
                _importer = new VcardImporter( this );
 
298
                _importer = new VCFImporter( this );
442
299
 
443
300
                // start the service's thread
444
301
                _importer.start();
447
304
        private void updateProgress()
448
305
        {
449
306
                ProgressBar bar = (ProgressBar)findViewById( R.id.doit_progress );
450
 
                TextView out_of = (TextView)findViewById( R.id.doit_outof );
 
307
                TextView outOf = (TextView)findViewById( R.id.doit_outof );
451
308
 
452
 
                if( _max_progress > 0 )
 
309
                if( _maxProgress > 0 )
453
310
                {
454
 
                        bar.setMax( _max_progress );
455
 
                        bar.setSecondaryProgress( _tmp_progress );
 
311
                        bar.setMax( _maxProgress );
 
312
                        bar.setSecondaryProgress( _tmpProgress );
456
313
 
457
 
                        if( _started_progress )
 
314
                        if( _startedProgress )
458
315
                        {
459
316
                                ( (TextView)findViewById( R.id.doit_percentage ) ).setText(
460
 
                                        (int)Math.round( 100 * _progress / _max_progress ) + "%" );
461
 
                                out_of.setText( _progress + "/" + _max_progress );
 
317
                                                (int)Math.round( 100 * _progress / _maxProgress ) + "%" );
 
318
                                outOf.setText( _progress + "/" + _maxProgress );
462
319
                                bar.setProgress( _progress );
463
320
                        }
464
321
                }
467
324
        private void updateStats()
468
325
        {
469
326
                ( (TextView)findViewById( R.id.doit_overwrites ) ).setText(
470
 
                        "" + _count_overwrites );
 
327
                                "" + _countOverwrites );
471
328
                ( (TextView)findViewById( R.id.doit_creates ) ).setText(
472
 
                        "" + _count_creates );
 
329
                                "" + _countCreates );
473
330
                ( (TextView)findViewById( R.id.doit_merges ) ).setText(
474
 
                        "" + _count_merges );
 
331
                                "" + _countMerges );
475
332
                ( (TextView)findViewById( R.id.doit_skips ) ).setText(
476
 
                        "" + _count_skips );
 
333
                                "" + _countSkips );
477
334
        }
478
335
 
479
 
        private void abortImport( boolean show_toaster_popup )
 
336
        private void abortImport()
480
337
        {
481
338
                if( _importer != null )
482
339
                {
483
 
                        // try and flag worker thread - did we need to?
484
 
                        if( _importer.setAbort() )
485
 
                        {
486
 
                                // wait for worker thread to end
487
 
                                while( true ) {
488
 
                                        try {
489
 
                                                _importer.join();
490
 
                                                break;
491
 
                                        }
492
 
                                        catch( InterruptedException e ) {}
 
340
                        _importer.setAbort();
 
341
                        while( true ) {
 
342
                                try {
 
343
                                        _importer.join();
 
344
                                        break;
493
345
                                }
494
 
 
495
 
                                // notify the user
496
 
                                if( show_toaster_popup )
497
 
                                        Toast.makeText( this, R.string.doit_importaborted,
498
 
                                                Toast.LENGTH_LONG ).show();
 
346
                                catch( InterruptedException e ) {}
499
347
                        }
500
348
                }
501
 
 
502
 
                // destroy some stuff
503
 
                _importer = null;
504
 
                _handler = null;
505
349
        }
506
350
}