68
69
public final static int NEXT_BEGIN = 0;
69
70
public final static int NEXT_CLOSE = 1;
71
private boolean _started_progress;
72
private int _max_progress;
73
private int _tmp_progress;
72
private boolean _startedProgress;
73
private int _maxProgress;
74
private int _tmpProgress;
74
75
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;
76
protected String _dialogMessage;
77
private Dialog _mergePromptDialog;
78
private boolean _mergePromptAlwaysSelected;
79
private int _nextAction;
81
private int _count_overwrites;
82
private int _count_creates;
83
private int _count_merges;
84
private int _count_skips;
81
private int _countOverwrites;
82
private int _countCreates;
83
private int _countMerges;
84
private int _countSkips;
86
86
protected Importer _importer = null;
93
93
public void handleMessage( Message msg ) {
96
case MESSAGE_FINISHED_ALLDONE:
97
97
( (TextView)findViewById( R.id.doit_alldone ) ).
98
setVisibility( View.VISIBLE );
99
( (Button)findViewById( R.id.back ) ).setEnabled( false );
98
setVisibility( View.VISIBLE );
100
case MESSAGE_FINISHED:
100
101
updateNext( NEXT_CLOSE );
101
102
findViewById( R.id.doit_abort_disp ).setVisibility(
105
case MESSAGE_FINISHED_GOBACK:
106
( (Button)findViewById( R.id.back ) ).setEnabled( true );
107
findViewById( R.id.doit_abort_disp ).setVisibility(
107
110
case MESSAGE_ERROR:
108
_dialog_message = (String)msg.obj;
111
Doit.this._dialogMessage = (String)msg.obj;
109
112
showDialog( DIALOG_ERROR );
111
114
case MESSAGE_CONTINUEORABORT:
112
_dialog_message = (String)msg.obj;
115
Doit.this._dialogMessage = (String)msg.obj;
113
116
showDialog( DIALOG_CONTINUEORABORT );
115
118
case MESSAGE_SETPROGRESSMESSAGE:
116
119
( (TextView)findViewById( R.id.doit_percentage ) ).
117
setText( (String)msg.obj );
120
setText( (String)msg.obj );
119
122
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 )
123
if( _maxProgress > 0 ) {
124
if( _tmpProgress == _maxProgress - 1 )
125
_tmpProgress = (Integer)msg.obj;
126
if( _progress == _maxProgress - 1 )
124
127
_progress = (Integer)msg.obj;
126
_max_progress = (Integer)msg.obj;
129
_maxProgress = (Integer)msg.obj;
127
130
updateProgress();
129
132
case MESSAGE_SETTMPPROGRESS:
130
_tmp_progress = (Integer)msg.obj;
133
_tmpProgress = (Integer)msg.obj;
131
134
updateProgress();
133
136
case MESSAGE_SETPROGRESS:
134
_started_progress = true;
137
_startedProgress = true;
135
138
_progress = (Integer)msg.obj;
136
139
updateProgress();
138
141
case MESSAGE_MERGEPROMPT:
139
_dialog_message = (String)msg.obj;
142
_dialogMessage = (String)msg.obj;
140
143
showDialog( DIALOG_MERGEPROMPT );
142
145
case MESSAGE_CONTACTOVERWRITTEN:
146
149
case MESSAGE_CONTACTCREATED:
150
153
case MESSAGE_CONTACTMERGED:
154
157
case MESSAGE_CONTACTSKIPPED:
203
206
// saving the state of an import sounds complicated! Lets just abort!
204
if( _next_action != NEXT_CLOSE )
209
protected Dialog onCreateDialog( int id )
211
protected Dialog onCreateDialog(int id)
213
215
case DIALOG_ERROR:
214
216
return new AlertDialog.Builder( this )
215
.setIcon( R.drawable.alert_dialog_icon )
216
.setTitle( R.string.error_title )
218
.setPositiveButton( R.string.error_ok,
219
new DialogInterface.OnClickListener() {
220
public void onClick( DialogInterface dialog,
217
.setIcon( R.drawable.alert_dialog_icon )
218
.setTitle( R.string.error_title )
220
.setPositiveButton( R.string.error_ok,
221
new DialogInterface.OnClickListener() {
222
public void onClick(DialogInterface dialog,
223
224
Doit.this._importer.wake();
226
.setOnCancelListener( _dialog_on_cancel_listener )
227
.setOnCancelListener( _dialogOnCancelListener )
228
229
case DIALOG_CONTINUEORABORT:
229
230
return new AlertDialog.Builder( this )
230
.setIcon( R.drawable.alert_dialog_icon )
231
.setTitle( R.string.error_title )
233
.setPositiveButton( R.string.error_continue,
234
new DialogInterface.OnClickListener() {
235
public void onClick( DialogInterface dialog,
238
Doit.this._importer.wake(
239
Importer.RESPONSE_POSITIVE );
242
.setNegativeButton( R.string.error_abort,
243
new DialogInterface.OnClickListener() {
244
public void onClick( DialogInterface dialog,
247
Doit.this._importer.wake(
248
Importer.RESPONSE_NEGATIVE );
251
.setOnCancelListener( _dialog_on_cancel_listener )
231
.setIcon( R.drawable.alert_dialog_icon )
232
.setTitle( R.string.error_title )
234
.setPositiveButton( R.string.error_continue,
235
new DialogInterface.OnClickListener() {
236
public void onClick(DialogInterface dialog,
238
Doit.this._importer.wake(
239
Importer.RESPONSE_POSITIVE );
242
.setNegativeButton( R.string.error_abort,
243
new DialogInterface.OnClickListener() {
244
public void onClick(DialogInterface dialog,
246
Doit.this._importer.wake(
247
Importer.RESPONSE_NEGATIVE );
250
.setOnCancelListener( _dialogOnCancelListener )
253
252
case DIALOG_MERGEPROMPT:
254
253
// custom layout in an AlertDialog
255
254
LayoutInflater factory = LayoutInflater.from( this );
256
final View dialog_view = factory.inflate(
257
R.layout.mergeprompt, null );
258
( (CheckBox)dialog_view.findViewById( R.id.mergeprompt_always ) ).
259
setOnCheckedChangeListener(
260
new CompoundButton.OnCheckedChangeListener() {
261
public void onCheckedChanged(
262
CompoundButton button_view, boolean is_checked )
264
Doit.this._merge_prompt_always_selected =
268
( (Button)dialog_view.findViewById( R.id.merge_keep ) ).
269
setOnClickListener( _merge_prompt_button_listener );
270
( (Button)dialog_view.findViewById( R.id.merge_overwrite ) ).
271
setOnClickListener( _merge_prompt_button_listener );
272
( (Button)dialog_view.findViewById( R.id.merge_merge ) ).
273
setOnClickListener( _merge_prompt_button_listener );
274
( (Button)dialog_view.findViewById( R.id.abort ) ).
275
setOnClickListener( _merge_prompt_button_listener );
276
_merge_prompt_always_selected = false;
255
final View dialogView = factory.inflate(
256
R.layout.mergeprompt, null );
257
( (CheckBox)dialogView.findViewById( R.id.mergeprompt_always ) ).
258
setOnCheckedChangeListener(
259
new CompoundButton.OnCheckedChangeListener() {
260
public void onCheckedChanged( CompoundButton buttonView,
261
boolean isChecked ) {
262
Doit.this._mergePromptAlwaysSelected = isChecked;
265
( (Button)dialogView.findViewById( R.id.merge_keep ) ).
266
setOnClickListener( _mergePromptButtonListener );
267
( (Button)dialogView.findViewById( R.id.merge_overwrite ) ).
268
setOnClickListener( _mergePromptButtonListener );
269
( (Button)dialogView.findViewById( R.id.merge_merge ) ).
270
setOnClickListener( _mergePromptButtonListener );
271
( (Button)dialogView.findViewById( R.id.abort ) ).
272
setOnClickListener( _mergePromptButtonListener );
273
_mergePromptAlwaysSelected = false;
277
274
return new AlertDialog.Builder( this )
278
.setIcon( R.drawable.alert_dialog_icon )
279
.setTitle( R.string.mergeprompt_title )
280
.setView( dialog_view )
281
.setOnCancelListener( _dialog_on_cancel_listener )
275
.setIcon( R.drawable.alert_dialog_icon )
276
.setTitle( R.string.mergeprompt_title )
277
.setView( dialogView )
278
.setOnCancelListener( _dialogOnCancelListener )
287
private OnClickListener _merge_prompt_button_listener =
288
new OnClickListener()
284
private OnClickListener _mergePromptButtonListener = new OnClickListener() {
290
285
public void onClick( View view )
293
288
if( view.getId() == R.id.abort )
296
// else, response (just check we haven't aborted already!)
297
else if( Doit.this._importer != null ) {
298
int response_extra = _merge_prompt_always_selected?
299
Importer.RESPONSEEXTRA_ALWAYS : Importer.RESPONSEEXTRA_NONE;
293
int responseExtra = _mergePromptAlwaysSelected?
294
Importer.RESPONSEEXTRA_ALWAYS : Importer.RESPONSEEXTRA_NONE;
300
295
Doit.this._importer.wake( convertIdToAction( view.getId() ),
304
299
// close dialog and free (don't keep a reference)
305
Doit.this._merge_prompt_dialog.dismiss();
306
Doit.this._merge_prompt_dialog = null;
300
Doit.this._mergePromptDialog.dismiss();
301
Doit.this._mergePromptDialog = null;
328
323
private void manualAbort()
330
manualAbort( false );
333
private void manualAbort( boolean show_toaster_popup )
335
abortImport( show_toaster_popup );
325
abortImport( false );
337
326
updateNext( NEXT_CLOSE );
338
327
( (Button)findViewById( R.id.back ) ).setEnabled( true );
339
328
findViewById( R.id.doit_abort_disp ).setVisibility( View.GONE );
340
( (TextView)findViewById( R.id.doit_aborted ) ).
341
setVisibility( View.VISIBLE );
342
( (TextView)findViewById( R.id.doit_alldone ) ).
343
setVisibility( View.GONE );
345
// close any open dialogs
347
dismissDialog( _current_dialog_id );
349
catch( Exception e ) {
354
private void updateNext( int next_action )
331
private void updateNext( int nextAction )
356
333
Button next = (Button)findViewById( R.id.next );
357
switch( next_action ) {
334
switch( nextAction ) {
358
335
case NEXT_BEGIN: next.setText( R.string.doit_begin ); break;
359
336
case NEXT_CLOSE: next.setText( R.string.doit_close ); break;
361
338
next.setEnabled( true );
362
_next_action = next_action;
339
_nextAction = nextAction;
365
342
public static int convertIdToAction( int id ) {
383
private DialogInterface.OnCancelListener _dialog_on_cancel_listener =
384
new DialogInterface.OnCancelListener()
360
private DialogInterface.OnCancelListener _dialogOnCancelListener =
361
new DialogInterface.OnCancelListener() {
386
362
public void onCancel( DialogInterface dialog ) {
363
setResult( RESULT_CANCELED );
393
protected void onActivityResult( int request_code, int result_code,
369
protected void onActivityResult( int requestCode, int resultCode,
396
372
// if we're cancelling, abort any import
397
if( result_code == RESULT_CANCELED )
373
if( resultCode == RESULT_CANCELED )
398
374
abortImport( true );
402
protected void onPrepareDialog( int id, Dialog dialog )
378
protected void onPrepareDialog(int id, Dialog dialog)
404
_current_dialog_id = id;
408
382
case DIALOG_ERROR: // fall through
409
383
case DIALOG_CONTINUEORABORT:
410
384
// set dialog message
411
( (AlertDialog)dialog ).setMessage( _dialog_message );
385
( (AlertDialog)dialog ).setMessage( _dialogMessage );
413
387
case DIALOG_MERGEPROMPT:
414
388
// set contact's name
415
( (TextView)dialog.findViewById( R.id.mergeprompt_name ) )
416
.setText( _dialog_message );
389
( (TextView)dialog.findViewById( R.id.mergeprompt_name ) ).setText(
417
391
// and set up reference to dialog
418
_merge_prompt_dialog = dialog;
392
_mergePromptDialog = dialog;