46
23
private final static int DIALOG_CONTINUEORABORT = 1;
47
24
private final static int DIALOG_MERGEPROMPT = 2;
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;
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;
68
public final static int NEXT_BEGIN = 0;
69
public final static int NEXT_CLOSE = 1;
71
26
private boolean _startedProgress;
72
27
private int _maxProgress;
73
28
private int _tmpProgress;
93
46
public void handleMessage( Message msg ) {
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(
108
_dialogMessage = (String)msg.obj;
49
case Importer.MESSAGE_FINISHED:
50
( (LinearLayout)findViewById( R.id.doit_closedisplay ) ).
51
setVisibility( View.VISIBLE );
53
case Importer.MESSAGE_FINISHED_BACK:
54
( (Button)findViewById( R.id.back ) ).setEnabled( true );
56
case Importer.MESSAGE_ERROR:
57
Doit.this._dialogMessage = (String)msg.obj;
109
58
showDialog( DIALOG_ERROR );
111
case MESSAGE_CONTINUEORABORT:
112
_dialogMessage = (String)msg.obj;
60
case Importer.MESSAGE_CONTINUEORABORT:
61
Doit.this._dialogMessage = (String)msg.obj;
113
62
showDialog( DIALOG_CONTINUEORABORT );
115
case MESSAGE_SETPROGRESSMESSAGE:
64
case Importer.MESSAGE_SETPROGRESSMESSAGE:
116
65
( (TextView)findViewById( R.id.doit_percentage ) ).
117
66
setText( (String)msg.obj );
119
case MESSAGE_SETMAXPROGRESS:
68
case Importer.MESSAGE_SETMAXPROGRESS:
120
69
if( _maxProgress > 0 ) {
121
if( _tmpProgress == _maxProgress - 1 )
70
if( _tmpProgress == _maxProgress )
122
71
_tmpProgress = (Integer)msg.obj;
123
if( _progress == _maxProgress - 1 )
72
if( _progress == _maxProgress )
124
73
_progress = (Integer)msg.obj;
126
75
_maxProgress = (Integer)msg.obj;
129
case MESSAGE_SETTMPPROGRESS:
78
case Importer.MESSAGE_SETTMPPROGRESS:
130
79
_tmpProgress = (Integer)msg.obj;
133
case MESSAGE_SETPROGRESS:
82
case Importer.MESSAGE_SETPROGRESS:
134
83
_startedProgress = true;
135
84
_progress = (Integer)msg.obj;
138
case MESSAGE_MERGEPROMPT:
87
case Importer.MESSAGE_MERGEPROMPT:
139
88
_dialogMessage = (String)msg.obj;
140
89
showDialog( DIALOG_MERGEPROMPT );
142
case MESSAGE_CONTACTOVERWRITTEN:
91
case Importer.MESSAGE_CONTACTOVERWRITTEN:
143
92
_countOverwrites++;
146
case MESSAGE_CONTACTCREATED:
95
case Importer.MESSAGE_CONTACTCREATED:
150
case MESSAGE_CONTACTMERGED:
99
case Importer.MESSAGE_CONTACTMERGED:
154
case MESSAGE_CONTACTSKIPPED:
103
case Importer.MESSAGE_CONTACTSKIPPED:
203
// close any open dialogs
205
dismissDialog( _currentDialogId );
207
catch( Exception e ) {
210
// saving the state of an import sounds complicated! Lets just abort!
215
protected Dialog onCreateDialog( int id )
169
protected Dialog onCreateDialog(int id)
219
173
case DIALOG_ERROR:
220
174
return new AlertDialog.Builder( this )
221
.setIcon( R.drawable.alert_dialog_icon )
222
.setTitle( R.string.error_title )
224
.setPositiveButton( R.string.error_ok,
225
new DialogInterface.OnClickListener() {
175
.setIcon( R.drawable.alert_dialog_icon )
176
.setTitle( R.string.error_title )
178
.setPositiveButton( R.string.error_ok,
179
new DialogInterface.OnClickListener() {
226
180
public void onClick(DialogInterface dialog,
229
182
Doit.this._importer.wake();
232
.setOnCancelListener( _dialogOnCancelListener )
185
.setOnCancelListener( _dialogOnCancelListener )
234
187
case DIALOG_CONTINUEORABORT:
235
188
return new AlertDialog.Builder( this )
236
.setIcon( R.drawable.alert_dialog_icon )
237
.setTitle( R.string.error_title )
239
.setPositiveButton( R.string.error_continue,
240
new DialogInterface.OnClickListener() {
241
public void onClick(DialogInterface dialog,
244
Doit.this._importer.wake(
245
Importer.RESPONSE_POSITIVE );
248
.setNegativeButton( R.string.error_abort,
249
new DialogInterface.OnClickListener() {
250
public void onClick(DialogInterface dialog,
253
Doit.this._importer.wake(
254
Importer.RESPONSE_NEGATIVE );
257
.setOnCancelListener( _dialogOnCancelListener )
189
.setIcon( R.drawable.alert_dialog_icon )
190
.setTitle( R.string.error_title )
192
.setPositiveButton( R.string.error_continue,
193
new DialogInterface.OnClickListener() {
194
public void onClick(DialogInterface dialog,
196
Doit.this._importer.wake(
197
Importer.RESPONSE_POSITIVE );
200
.setNegativeButton( R.string.error_abort,
201
new DialogInterface.OnClickListener() {
202
public void onClick(DialogInterface dialog,
204
Doit.this._importer.wake(
205
Importer.RESPONSE_NEGATIVE );
208
.setOnCancelListener( _dialogOnCancelListener )
259
210
case DIALOG_MERGEPROMPT:
260
211
// custom layout in an AlertDialog
261
212
LayoutInflater factory = LayoutInflater.from( this );
262
213
final View dialogView = factory.inflate(
263
R.layout.mergeprompt, null );
214
R.layout.mergeprompt, null );
264
215
( (CheckBox)dialogView.findViewById( R.id.mergeprompt_always ) ).
265
setOnCheckedChangeListener(
266
new CompoundButton.OnCheckedChangeListener() {
267
public void onCheckedChanged( CompoundButton buttonView,
270
Doit.this._mergePromptAlwaysSelected = isChecked;
216
setOnCheckedChangeListener(
217
new CompoundButton.OnCheckedChangeListener() {
218
public void onCheckedChanged( CompoundButton buttonView,
219
boolean isChecked ) {
220
Doit.this._mergePromptAlwaysSelected = isChecked;
273
223
( (Button)dialogView.findViewById( R.id.merge_keep ) ).
274
setOnClickListener( _mergePromptButtonListener );
224
setOnClickListener( _mergePromptButtonListener );
275
225
( (Button)dialogView.findViewById( R.id.merge_overwrite ) ).
276
setOnClickListener( _mergePromptButtonListener );
226
setOnClickListener( _mergePromptButtonListener );
277
227
( (Button)dialogView.findViewById( R.id.merge_merge ) ).
278
setOnClickListener( _mergePromptButtonListener );
279
( (Button)dialogView.findViewById( R.id.abort ) ).
280
setOnClickListener( _mergePromptButtonListener );
228
setOnClickListener( _mergePromptButtonListener );
281
229
_mergePromptAlwaysSelected = false;
282
230
return new AlertDialog.Builder( this )
283
.setIcon( R.drawable.alert_dialog_icon )
284
.setTitle( R.string.mergeprompt_title )
285
.setView( dialogView )
286
.setOnCancelListener( _dialogOnCancelListener )
231
.setIcon( R.drawable.alert_dialog_icon )
232
.setTitle( R.string.mergeprompt_title )
233
.setView( dialogView )
234
.setOnCancelListener( _dialogOnCancelListener )
292
private OnClickListener _mergePromptButtonListener = new OnClickListener() {
293
public void onClick( View view )
296
if( view.getId() == R.id.abort )
301
int responseExtra = _mergePromptAlwaysSelected?
302
Importer.RESPONSEEXTRA_ALWAYS : Importer.RESPONSEEXTRA_NONE;
303
Doit.this._importer.wake( convertIdToAction( view.getId() ),
307
// close dialog and free (don't keep a reference)
240
private OnClickListener _mergePromptButtonListener = new OnClickListener() {
241
public void onClick( View view ) {
242
int responseExtra = _mergePromptAlwaysSelected?
243
Importer.RESPONSEEXTRA_ALWAYS : Importer.RESPONSEEXTRA_NONE;
308
244
Doit.this._mergePromptDialog.dismiss();
309
Doit.this._mergePromptDialog = null;
245
Doit.this._mergePromptDialog = null; // dont keep a reference!
246
Doit.this._importer.wake( view.getId(), responseExtra );
314
protected void onNext()
316
Button next = (Button)findViewById( R.id.next );
317
next.setEnabled( false );
319
switch( _nextAction )
325
setResult( RESULT_OK );
331
private void manualAbort()
333
manualAbort( false );
336
private void manualAbort( boolean showToasterPopup )
338
abortImport( showToasterPopup );
340
updateNext( NEXT_CLOSE );
341
( (Button)findViewById( R.id.back ) ).setEnabled( true );
342
findViewById( R.id.doit_abort_disp ).setVisibility( View.GONE );
343
( (TextView)findViewById( R.id.doit_aborted ) ).
344
setVisibility( View.VISIBLE );
345
( (TextView)findViewById( R.id.doit_alldone ) ).
346
setVisibility( View.GONE );
349
private void updateNext( int nextAction )
351
Button next = (Button)findViewById( R.id.next );
352
switch( nextAction ) {
353
case NEXT_BEGIN: next.setText( R.string.doit_begin ); break;
354
case NEXT_CLOSE: next.setText( R.string.doit_close ); break;
356
next.setEnabled( true );
357
_nextAction = nextAction;
360
public static int convertIdToAction( int id ) {
362
case R.id.merge_keep: return ACTION_KEEP;
363
case R.id.merge_merge: return ACTION_MERGE_MERGE;
364
case R.id.merge_overwrite: return ACTION_OVERWRITE;
365
default: return ACTION_PROMPT;
369
public static int convertActionToId( int action ) {
371
case ACTION_KEEP: return R.id.merge_keep;
372
case ACTION_MERGE_MERGE:return R.id.merge_merge;
373
case ACTION_OVERWRITE: return R.id.merge_overwrite;
374
default: return R.id.merge_prompt;
378
250
private DialogInterface.OnCancelListener _dialogOnCancelListener =
379
251
new DialogInterface.OnCancelListener() {
380
252
public void onCancel( DialogInterface dialog ) {