4
* Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
6
* This file is part of the Import Contacts program (hereafter referred
7
* to as "this program"). For more information, see
8
* http://www.waxworlds.org/edam/software/android/import-contacts
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.
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.
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/>.
1
24
package org.waxworlds.importcontacts;
3
26
import android.app.AlertDialog;
24
47
private final static int DIALOG_CONTINUEORABORT = 1;
25
48
private final static int DIALOG_MERGEPROMPT = 2;
50
public final static int MESSAGE_FINISHED_ALLDONE = 0;
51
public final static int MESSAGE_FINISHED = 1;
52
public final static int MESSAGE_FINISHED_GOBACK = 2;
53
public final static int MESSAGE_ERROR = 3;
54
public final static int MESSAGE_CONTINUEORABORT = 4;
55
public final static int MESSAGE_SETPROGRESSMESSAGE = 5;
56
public final static int MESSAGE_SETMAXPROGRESS = 6;
57
public final static int MESSAGE_SETTMPPROGRESS = 7;
58
public final static int MESSAGE_SETPROGRESS = 8;
59
public final static int MESSAGE_MERGEPROMPT = 9;
60
public final static int MESSAGE_CONTACTOVERWRITTEN = 10;
61
public final static int MESSAGE_CONTACTCREATED = 11;
62
public final static int MESSAGE_CONTACTMERGED = 12;
63
public final static int MESSAGE_CONTACTSKIPPED = 13;
27
65
private boolean _startedProgress;
28
66
private int _maxProgress;
29
67
private int _tmpProgress;
47
85
public void handleMessage( Message msg ) {
50
case Importer.MESSAGE_FINISHED:
88
case MESSAGE_FINISHED_ALLDONE:
89
( (TextView)findViewById( R.id.doit_alldone ) ).
90
setVisibility( View.VISIBLE );
92
case MESSAGE_FINISHED:
51
93
( (LinearLayout)findViewById( R.id.doit_closedisplay ) ).
52
94
setVisibility( View.VISIBLE );
54
case Importer.MESSAGE_FINISHED_BACK:
96
case MESSAGE_FINISHED_GOBACK:
55
97
( (Button)findViewById( R.id.back ) ).setEnabled( true );
57
case Importer.MESSAGE_ERROR:
58
100
Doit.this._dialogMessage = (String)msg.obj;
59
101
showDialog( DIALOG_ERROR );
61
case Importer.MESSAGE_CONTINUEORABORT:
103
case MESSAGE_CONTINUEORABORT:
62
104
Doit.this._dialogMessage = (String)msg.obj;
63
105
showDialog( DIALOG_CONTINUEORABORT );
65
case Importer.MESSAGE_SETPROGRESSMESSAGE:
107
case MESSAGE_SETPROGRESSMESSAGE:
66
108
( (TextView)findViewById( R.id.doit_percentage ) ).
67
109
setText( (String)msg.obj );
69
case Importer.MESSAGE_SETMAXPROGRESS:
111
case MESSAGE_SETMAXPROGRESS:
70
112
if( _maxProgress > 0 ) {
71
113
if( _tmpProgress == _maxProgress )
72
114
_tmpProgress = (Integer)msg.obj;
76
118
_maxProgress = (Integer)msg.obj;
79
case Importer.MESSAGE_SETTMPPROGRESS:
121
case MESSAGE_SETTMPPROGRESS:
80
122
_tmpProgress = (Integer)msg.obj;
83
case Importer.MESSAGE_SETPROGRESS:
125
case MESSAGE_SETPROGRESS:
84
126
_startedProgress = true;
85
127
_progress = (Integer)msg.obj;
88
case Importer.MESSAGE_MERGEPROMPT:
130
case MESSAGE_MERGEPROMPT:
89
131
_dialogMessage = (String)msg.obj;
90
132
showDialog( DIALOG_MERGEPROMPT );
92
case Importer.MESSAGE_CONTACTOVERWRITTEN:
134
case MESSAGE_CONTACTOVERWRITTEN:
93
135
_countOverwrites++;
96
case Importer.MESSAGE_CONTACTCREATED:
138
case MESSAGE_CONTACTCREATED:
100
case Importer.MESSAGE_CONTACTMERGED:
142
case MESSAGE_CONTACTMERGED:
104
case Importer.MESSAGE_CONTACTSKIPPED:
146
case MESSAGE_CONTACTSKIPPED:
339
381
if( _importer != null )
341
_importer.setAbort();
383
// try and flag worker thread - did we need to?
384
if( _importer.setAbort() )
386
// wait for worker thread to end
392
catch( InterruptedException e ) {}
347
catch( InterruptedException e ) {}
396
Toast.makeText( this, R.string.doit_importaborted,
397
Toast.LENGTH_LONG ).show();