/android/import-contacts

To get this branch, use:
bzr branch http://bzr.ed.am/android/import-contacts
6 by edam
- added GPL header comments to all files
1
/*
2
 * Doit.java
3
 *
50 by edam
updated all URLs, email addresses and package names to ed.am
4
 * Copyright (C) 2009 Tim Marston <tim@ed.am>
6 by edam
- added GPL header comments to all files
5
 *
6
 * This file is part of the Import Contacts program (hereafter referred
7
 * to as "this program"). For more information, see
50 by edam
updated all URLs, email addresses and package names to ed.am
8
 * http://ed.am/dev/android/import-contacts
6 by edam
- added GPL header comments to all files
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
50 by edam
updated all URLs, email addresses and package names to ed.am
24
package am.ed.importcontacts;
1 by edam
Initial import
25
26
import android.app.AlertDialog;
27
import android.app.Dialog;
28
import android.content.DialogInterface;
29
import android.content.Intent;
30
import android.os.Bundle;
31
import android.os.Handler;
32
import android.os.Message;
33
import android.view.LayoutInflater;
34
import android.view.View;
35
import android.view.View.OnClickListener;
36
import android.widget.Button;
37
import android.widget.CheckBox;
38
import android.widget.CompoundButton;
39
import android.widget.ProgressBar;
40
import android.widget.TextView;
2 by edam
- added toaster message about import abortion in onPause()
41
import android.widget.Toast;
1 by edam
Initial import
42
43
public class Doit extends WizardActivity
44
{
45
	private final static int DIALOG_ERROR = 0;
46
	private final static int DIALOG_CONTINUEORABORT = 1;
47
	private final static int DIALOG_MERGEPROMPT = 2;
48
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
49
	public final static int MESSAGE_ALLDONE = 0;
50
	public final static int MESSAGE_ABORT = 1;
3 by edam
- added "all done" message
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
9 by edam
- added scroll view to all layouts
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
10 by edam
- made behaviour of next button overridable
68
	public final static int NEXT_BEGIN = 0;
69
	public final static int NEXT_CLOSE = 1;
70
41 by edam
- updated TODO
71
	private boolean _started_progress;
72
	private int _max_progress;
73
	private int _tmp_progress;
1 by edam
Initial import
74
	private int _progress;
41 by edam
- updated TODO
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;
1 by edam
Initial import
80
41 by edam
- updated TODO
81
	private int _count_overwrites;
82
	private int _count_creates;
83
	private int _count_merges;
84
	private int _count_skips;
1 by edam
Initial import
85
3 by edam
- added "all done" message
86
	protected Importer _importer = null;
1 by edam
Initial import
87
88
	public Handler _handler;
89
90
	public class DoitHandler extends Handler
91
	{
92
		@Override
93
		public void handleMessage( Message msg ) {
94
			switch( msg.what )
95
			{
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
96
			case MESSAGE_ALLDONE:
3 by edam
- added "all done" message
97
				( (TextView)findViewById( R.id.doit_alldone ) ).
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
98
					setVisibility( View.VISIBLE );
99
				( (Button)findViewById( R.id.back ) ).setEnabled( false );
10 by edam
- made behaviour of next button overridable
100
				updateNext( NEXT_CLOSE );
101
				findViewById( R.id.doit_abort_disp ).setVisibility(
36 by edam
- formatting: removed some double-indents on overrunning lines
102
					View.GONE );
1 by edam
Initial import
103
				break;
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
104
			case MESSAGE_ABORT:
105
				manualAbort();
1 by edam
Initial import
106
				break;
3 by edam
- added "all done" message
107
			case MESSAGE_ERROR:
41 by edam
- updated TODO
108
				_dialog_message = (String)msg.obj;
1 by edam
Initial import
109
				showDialog( DIALOG_ERROR );
110
				break;
3 by edam
- added "all done" message
111
			case MESSAGE_CONTINUEORABORT:
41 by edam
- updated TODO
112
				_dialog_message = (String)msg.obj;
1 by edam
Initial import
113
				showDialog( DIALOG_CONTINUEORABORT );
114
				break;
3 by edam
- added "all done" message
115
			case MESSAGE_SETPROGRESSMESSAGE:
1 by edam
Initial import
116
				( (TextView)findViewById( R.id.doit_percentage ) ).
36 by edam
- formatting: removed some double-indents on overrunning lines
117
					setText( (String)msg.obj );
1 by edam
Initial import
118
				break;
3 by edam
- added "all done" message
119
			case MESSAGE_SETMAXPROGRESS:
41 by edam
- updated TODO
120
				if( _max_progress > 0 ) {
121
					if( _tmp_progress == _max_progress - 1 )
122
						_tmp_progress = (Integer)msg.obj;
123
					if( _progress == _max_progress - 1 )
1 by edam
Initial import
124
						_progress = (Integer)msg.obj;
125
				}
41 by edam
- updated TODO
126
				_max_progress = (Integer)msg.obj;
1 by edam
Initial import
127
				updateProgress();
128
				break;
3 by edam
- added "all done" message
129
			case MESSAGE_SETTMPPROGRESS:
41 by edam
- updated TODO
130
				_tmp_progress = (Integer)msg.obj;
1 by edam
Initial import
131
				updateProgress();
132
				break;
3 by edam
- added "all done" message
133
			case MESSAGE_SETPROGRESS:
41 by edam
- updated TODO
134
				_started_progress = true;
1 by edam
Initial import
135
				_progress = (Integer)msg.obj;
136
				updateProgress();
137
				break;
3 by edam
- added "all done" message
138
			case MESSAGE_MERGEPROMPT:
41 by edam
- updated TODO
139
				_dialog_message = (String)msg.obj;
1 by edam
Initial import
140
				showDialog( DIALOG_MERGEPROMPT );
141
				break;
3 by edam
- added "all done" message
142
			case MESSAGE_CONTACTOVERWRITTEN:
41 by edam
- updated TODO
143
				_count_overwrites++;
1 by edam
Initial import
144
				updateStats();
145
				break;
3 by edam
- added "all done" message
146
			case MESSAGE_CONTACTCREATED:
41 by edam
- updated TODO
147
				_count_creates++;
1 by edam
Initial import
148
				updateStats();
149
				break;
3 by edam
- added "all done" message
150
			case MESSAGE_CONTACTMERGED:
41 by edam
- updated TODO
151
				_count_merges++;
1 by edam
Initial import
152
				updateStats();
153
				break;
3 by edam
- added "all done" message
154
			case MESSAGE_CONTACTSKIPPED:
41 by edam
- updated TODO
155
				_count_skips++;
1 by edam
Initial import
156
				updateStats();
157
				break;
158
			default:
159
				super.handleMessage( msg );
160
			}
161
		}
162
	}
163
164
	@Override
41 by edam
- updated TODO
165
	protected void onCreate(Bundle saved_instance_state)
1 by edam
Initial import
166
	{
167
		setContentView( R.layout.doit );
41 by edam
- updated TODO
168
		super.onCreate( saved_instance_state );
1 by edam
Initial import
169
170
		// hide page 2
171
		( findViewById( R.id.doit_page_2 ) ).setVisibility( View.GONE );
172
10 by edam
- made behaviour of next button overridable
173
		// set up abort button
174
		Button begin = (Button)findViewById( R.id.abort );
1 by edam
Initial import
175
		begin.setOnClickListener( new View.OnClickListener() {
176
			public void onClick( View view ) {
10 by edam
- made behaviour of next button overridable
177
				manualAbort();
1 by edam
Initial import
178
			}
179
		} );
180
41 by edam
- updated TODO
181
		_started_progress = false;
182
		_max_progress = 0;
183
		_tmp_progress = 0;
1 by edam
Initial import
184
		_progress = 0;
185
		_handler = new DoitHandler();
186
41 by edam
- updated TODO
187
		_count_overwrites = 0;
188
		_count_creates = 0;
189
		_count_merges = 0;
190
		_count_skips = 0;
1 by edam
Initial import
191
10 by edam
- made behaviour of next button overridable
192
		updateNext( NEXT_BEGIN );
193
1 by edam
Initial import
194
		updateProgress();
195
		updateStats();
196
	}
197
198
	@Override
199
	protected void onPause()
200
	{
201
		super.onPause();
202
2 by edam
- added toaster message about import abortion in onPause()
203
		// saving the state of an import sounds complicated! Lets just abort!
41 by edam
- updated TODO
204
		if( _next_action != NEXT_CLOSE )
19 by edam
- added file chooser
205
			manualAbort( true );
1 by edam
Initial import
206
	}
207
208
	@Override
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
209
	protected Dialog onCreateDialog( int id )
1 by edam
Initial import
210
	{
211
		switch( id )
212
		{
213
		case DIALOG_ERROR:
214
			return new AlertDialog.Builder( this )
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
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() {
41 by edam
- updated TODO
220
						public void onClick( DialogInterface dialog,
221
							int whichButton )
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
222
						{
44 by edam
- added checks for Doit.this == null when handling dialog buttons (I managed to abort an import as a duplicate contacts dialog was shown, but can't reproduce it now)
223
							if( Doit.this != null )
224
								Doit.this._importer.wake();
1 by edam
Initial import
225
						}
226
					} )
41 by edam
- updated TODO
227
				.setOnCancelListener( _dialog_on_cancel_listener )
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
228
				.create();
1 by edam
Initial import
229
		case DIALOG_CONTINUEORABORT:
230
			return new AlertDialog.Builder( this )
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
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() {
41 by edam
- updated TODO
236
						public void onClick( DialogInterface dialog,
237
							int which_button )
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
238
						{
44 by edam
- added checks for Doit.this == null when handling dialog buttons (I managed to abort an import as a duplicate contacts dialog was shown, but can't reproduce it now)
239
							if( Doit.this != null )
240
								Doit.this._importer.wake(
241
									Importer.RESPONSE_POSITIVE );
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
242
						}
243
					} )
244
				.setNegativeButton( R.string.error_abort,
245
					new DialogInterface.OnClickListener() {
41 by edam
- updated TODO
246
						public void onClick( DialogInterface dialog,
247
							int which_button )
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
248
						{
44 by edam
- added checks for Doit.this == null when handling dialog buttons (I managed to abort an import as a duplicate contacts dialog was shown, but can't reproduce it now)
249
							if( Doit.this != null )
250
								Doit.this._importer.wake(
251
									Importer.RESPONSE_NEGATIVE );
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
252
						}
253
					} )
41 by edam
- updated TODO
254
				.setOnCancelListener( _dialog_on_cancel_listener )
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
255
				.create();
1 by edam
Initial import
256
		case DIALOG_MERGEPROMPT:
257
			// custom layout in an AlertDialog
258
			LayoutInflater factory = LayoutInflater.from( this );
41 by edam
- updated TODO
259
			final View dialog_view = factory.inflate(
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
260
				R.layout.mergeprompt, null );
41 by edam
- updated TODO
261
			( (CheckBox)dialog_view.findViewById( R.id.mergeprompt_always ) ).
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
262
				setOnCheckedChangeListener(
263
					new CompoundButton.OnCheckedChangeListener() {
41 by edam
- updated TODO
264
						public void onCheckedChanged(
265
							CompoundButton button_view, boolean is_checked )
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
266
						{
44 by edam
- added checks for Doit.this == null when handling dialog buttons (I managed to abort an import as a duplicate contacts dialog was shown, but can't reproduce it now)
267
							if( Doit.this != null )
268
								Doit.this._merge_prompt_always_selected =
269
									is_checked;
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
270
						}
271
					} );
41 by edam
- updated TODO
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;
1 by edam
Initial import
281
			return new AlertDialog.Builder( this )
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
282
				.setIcon( R.drawable.alert_dialog_icon )
283
				.setTitle( R.string.mergeprompt_title )
41 by edam
- updated TODO
284
				.setView( dialog_view )
285
				.setOnCancelListener( _dialog_on_cancel_listener )
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
286
				.create();
1 by edam
Initial import
287
		}
288
		return null;
289
	}
290
41 by edam
- updated TODO
291
	private OnClickListener _merge_prompt_button_listener =
292
		new OnClickListener()
293
	{
10 by edam
- made behaviour of next button overridable
294
		public void onClick( View view )
295
		{
44 by edam
- added checks for Doit.this == null when handling dialog buttons (I managed to abort an import as a duplicate contacts dialog was shown, but can't reproduce it now)
296
			if( Doit.this == null ) return;
297
10 by edam
- made behaviour of next button overridable
298
			// handle abort
299
			if( view.getId() == R.id.abort )
300
				manualAbort();
301
19 by edam
- added file chooser
302
			// else, response (just check we haven't aborted already!)
303
			else if( Doit.this._importer != null ) {
41 by edam
- updated TODO
304
				int response_extra = _merge_prompt_always_selected?
36 by edam
- formatting: removed some double-indents on overrunning lines
305
					Importer.RESPONSEEXTRA_ALWAYS : Importer.RESPONSEEXTRA_NONE;
10 by edam
- made behaviour of next button overridable
306
				Doit.this._importer.wake( convertIdToAction( view.getId() ),
41 by edam
- updated TODO
307
					response_extra );
10 by edam
- made behaviour of next button overridable
308
			}
309
310
			// close dialog and free (don't keep a reference)
41 by edam
- updated TODO
311
			Doit.this._merge_prompt_dialog.dismiss();
312
			Doit.this._merge_prompt_dialog = null;
1 by edam
Initial import
313
		}
314
	};
315
10 by edam
- made behaviour of next button overridable
316
	@Override
317
	protected void onNext()
318
	{
319
		Button next = (Button)findViewById( R.id.next );
320
		next.setEnabled( false );
321
41 by edam
- updated TODO
322
		switch( _next_action )
10 by edam
- made behaviour of next button overridable
323
		{
324
		case NEXT_BEGIN:
325
			importContacts();
326
			break;
327
		case NEXT_CLOSE:
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
328
			setResult( RESULT_OK );
10 by edam
- made behaviour of next button overridable
329
			finish();
330
			break;
331
		}
332
	}
333
334
	private void manualAbort()
335
	{
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
336
		manualAbort( false );
337
	}
338
41 by edam
- updated TODO
339
	private void manualAbort( boolean show_toaster_popup )
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
340
	{
41 by edam
- updated TODO
341
		abortImport( show_toaster_popup );
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
342
10 by edam
- made behaviour of next button overridable
343
		updateNext( NEXT_CLOSE );
344
		( (Button)findViewById( R.id.back ) ).setEnabled( true );
345
		findViewById( R.id.doit_abort_disp ).setVisibility( View.GONE );
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
346
		( (TextView)findViewById( R.id.doit_aborted ) ).
347
			setVisibility( View.VISIBLE );
348
		( (TextView)findViewById( R.id.doit_alldone ) ).
349
			setVisibility( View.GONE );
19 by edam
- added file chooser
350
351
		// close any open dialogs
352
		try {
41 by edam
- updated TODO
353
			dismissDialog( _current_dialog_id );
19 by edam
- added file chooser
354
		}
355
		catch( Exception e ) {
36 by edam
- formatting: removed some double-indents on overrunning lines
356
			// ignore errors
19 by edam
- added file chooser
357
		}
10 by edam
- made behaviour of next button overridable
358
	}
359
41 by edam
- updated TODO
360
	private void updateNext( int next_action )
10 by edam
- made behaviour of next button overridable
361
	{
362
		Button next = (Button)findViewById( R.id.next );
41 by edam
- updated TODO
363
		switch( next_action ) {
10 by edam
- made behaviour of next button overridable
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 );
41 by edam
- updated TODO
368
		_next_action = next_action;
10 by edam
- made behaviour of next button overridable
369
	}
370
9 by edam
- added scroll view to all layouts
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
41 by edam
- updated TODO
389
	private DialogInterface.OnCancelListener _dialog_on_cancel_listener =
390
		new DialogInterface.OnCancelListener()
391
	{
1 by edam
Initial import
392
		public void onCancel( DialogInterface dialog ) {
19 by edam
- added file chooser
393
			manualAbort();
1 by edam
Initial import
394
		}
395
	};
396
19 by edam
- added file chooser
397
1 by edam
Initial import
398
	@Override
41 by edam
- updated TODO
399
	protected void onActivityResult( int request_code, int result_code,
400
		Intent data )
1 by edam
Initial import
401
	{
2 by edam
- added toaster message about import abortion in onPause()
402
		// if we're cancelling, abort any import
41 by edam
- updated TODO
403
		if( result_code == RESULT_CANCELED )
10 by edam
- made behaviour of next button overridable
404
			abortImport( true );
1 by edam
Initial import
405
	}
406
407
	@Override
41 by edam
- updated TODO
408
	protected void onPrepareDialog( int id, Dialog dialog )
1 by edam
Initial import
409
	{
41 by edam
- updated TODO
410
		_current_dialog_id = id;
14 by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
411
1 by edam
Initial import
412
		switch( id )
413
		{
414
		case DIALOG_ERROR:	// fall through
415
		case DIALOG_CONTINUEORABORT:
416
			// set dialog message
41 by edam
- updated TODO
417
			( (AlertDialog)dialog ).setMessage( _dialog_message );
1 by edam
Initial import
418
			break;
419
		case DIALOG_MERGEPROMPT:
420
			// set contact's name
41 by edam
- updated TODO
421
			( (TextView)dialog.findViewById( R.id.mergeprompt_name ) )
422
				.setText( _dialog_message );
1 by edam
Initial import
423
			// and set up reference to dialog
41 by edam
- updated TODO
424
			_merge_prompt_dialog = dialog;
1 by edam
Initial import
425
			break;
426
		}
427
428
		super.onPrepareDialog( id, dialog );
429
	}
430
431
	private void importContacts()
432
	{
433
		// switch interfaces
434
		( findViewById( R.id.doit_page_1 ) ).setVisibility( View.GONE );
435
		( findViewById( R.id.doit_page_2 ) ).setVisibility( View.VISIBLE );
436
437
		// disable back button
438
		( (Button)findViewById( R.id.back ) ).setEnabled( false );
439
440
		// create importer
42 by edam
- renamed VCFImporter to VcardImporter and VCard to Vcard
441
		_importer = new VcardImporter( this );
1 by edam
Initial import
442
443
		// start the service's thread
444
		_importer.start();
445
	}
446
447
	private void updateProgress()
448
	{
449
		ProgressBar bar = (ProgressBar)findViewById( R.id.doit_progress );
41 by edam
- updated TODO
450
		TextView out_of = (TextView)findViewById( R.id.doit_outof );
1 by edam
Initial import
451
41 by edam
- updated TODO
452
		if( _max_progress > 0 )
1 by edam
Initial import
453
		{
41 by edam
- updated TODO
454
			bar.setMax( _max_progress );
455
			bar.setSecondaryProgress( _tmp_progress );
1 by edam
Initial import
456
41 by edam
- updated TODO
457
			if( _started_progress )
1 by edam
Initial import
458
			{
459
				( (TextView)findViewById( R.id.doit_percentage ) ).setText(
41 by edam
- updated TODO
460
					(int)Math.round( 100 * _progress / _max_progress ) + "%" );
461
				out_of.setText( _progress + "/" + _max_progress );
1 by edam
Initial import
462
				bar.setProgress( _progress );
463
			}
464
		}
465
	}
466
467
	private void updateStats()
468
	{
469
		( (TextView)findViewById( R.id.doit_overwrites ) ).setText(
41 by edam
- updated TODO
470
			"" + _count_overwrites );
1 by edam
Initial import
471
		( (TextView)findViewById( R.id.doit_creates ) ).setText(
41 by edam
- updated TODO
472
			"" + _count_creates );
1 by edam
Initial import
473
		( (TextView)findViewById( R.id.doit_merges ) ).setText(
41 by edam
- updated TODO
474
			"" + _count_merges );
1 by edam
Initial import
475
		( (TextView)findViewById( R.id.doit_skips ) ).setText(
41 by edam
- updated TODO
476
			"" + _count_skips );
1 by edam
Initial import
477
	}
478
41 by edam
- updated TODO
479
	private void abortImport( boolean show_toaster_popup )
1 by edam
Initial import
480
	{
481
		if( _importer != null )
482
		{
3 by edam
- added "all done" message
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 ) {}
1 by edam
Initial import
493
				}
3 by edam
- added "all done" message
494
495
				// notify the user
41 by edam
- updated TODO
496
				if( show_toaster_popup )
10 by edam
- made behaviour of next button overridable
497
					Toast.makeText( this, R.string.doit_importaborted,
36 by edam
- formatting: removed some double-indents on overrunning lines
498
						Toast.LENGTH_LONG ).show();
1 by edam
Initial import
499
			}
500
		}
10 by edam
- made behaviour of next button overridable
501
502
		// destroy some stuff
503
		_importer = null;
504
		_handler = null;
1 by edam
Initial import
505
	}
506
}