65
67
public final static int ACTION_MERGE_MERGE = 2;
66
68
public final static int ACTION_OVERWRITE = 3;
68
public final static int NEXT_BEGIN = 0;
69
public final static int NEXT_CLOSE = 1;
71
private boolean _started_progress;
72
private int _max_progress;
73
private int _tmp_progress;
70
private boolean _startedProgress;
71
private int _maxProgress;
72
private int _tmpProgress;
74
73
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;
74
protected String _dialogMessage;
75
private Dialog _mergePromptDialog;
76
private boolean _mergePromptAlwaysSelected;
81
private int _count_overwrites;
82
private int _count_creates;
83
private int _count_merges;
84
private int _count_skips;
78
private int _countOverwrites;
79
private int _countCreates;
80
private int _countMerges;
81
private int _countSkips;
86
83
protected Importer _importer = null;
93
90
public void handleMessage( Message msg ) {
93
case MESSAGE_FINISHED_ALLDONE:
97
94
( (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(
95
setVisibility( View.VISIBLE );
97
case MESSAGE_FINISHED:
98
( (LinearLayout)findViewById( R.id.doit_closedisplay ) ).
99
setVisibility( View.VISIBLE );
101
case MESSAGE_FINISHED_GOBACK:
102
( (Button)findViewById( R.id.back ) ).setEnabled( true );
107
104
case MESSAGE_ERROR:
108
_dialog_message = (String)msg.obj;
105
Doit.this._dialogMessage = (String)msg.obj;
109
106
showDialog( DIALOG_ERROR );
111
108
case MESSAGE_CONTINUEORABORT:
112
_dialog_message = (String)msg.obj;
109
Doit.this._dialogMessage = (String)msg.obj;
113
110
showDialog( DIALOG_CONTINUEORABORT );
115
112
case MESSAGE_SETPROGRESSMESSAGE:
116
113
( (TextView)findViewById( R.id.doit_percentage ) ).
117
setText( (String)msg.obj );
114
setText( (String)msg.obj );
119
116
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 )
117
if( _maxProgress > 0 ) {
118
if( _tmpProgress == _maxProgress )
119
_tmpProgress = (Integer)msg.obj;
120
if( _progress == _maxProgress )
124
121
_progress = (Integer)msg.obj;
126
_max_progress = (Integer)msg.obj;
123
_maxProgress = (Integer)msg.obj;
127
124
updateProgress();
129
126
case MESSAGE_SETTMPPROGRESS:
130
_tmp_progress = (Integer)msg.obj;
127
_tmpProgress = (Integer)msg.obj;
131
128
updateProgress();
133
130
case MESSAGE_SETPROGRESS:
134
_started_progress = true;
131
_startedProgress = true;
135
132
_progress = (Integer)msg.obj;
136
133
updateProgress();
138
135
case MESSAGE_MERGEPROMPT:
139
_dialog_message = (String)msg.obj;
136
_dialogMessage = (String)msg.obj;
140
137
showDialog( DIALOG_MERGEPROMPT );
142
139
case MESSAGE_CONTACTOVERWRITTEN:
146
143
case MESSAGE_CONTACTCREATED:
150
147
case MESSAGE_CONTACTMERGED:
154
151
case MESSAGE_CONTACTSKIPPED:
203
207
// saving the state of an import sounds complicated! Lets just abort!
204
if( _next_action != NEXT_CLOSE )
210
// destroy some stuff
209
protected Dialog onCreateDialog( int id )
216
protected Dialog onCreateDialog(int id)
213
220
case DIALOG_ERROR:
214
221
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,
223
if( Doit.this != null )
224
Doit.this._importer.wake();
222
.setIcon( R.drawable.alert_dialog_icon )
223
.setTitle( R.string.error_title )
225
.setPositiveButton( R.string.error_ok,
226
new DialogInterface.OnClickListener() {
227
public void onClick(DialogInterface dialog,
229
Doit.this._importer.wake();
227
.setOnCancelListener( _dialog_on_cancel_listener )
232
.setOnCancelListener( _dialogOnCancelListener )
229
234
case DIALOG_CONTINUEORABORT:
230
235
return new AlertDialog.Builder( this )
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,
239
if( Doit.this != null )
240
Doit.this._importer.wake(
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,
243
Doit.this._importer.wake(
241
244
Importer.RESPONSE_POSITIVE );
244
.setNegativeButton( R.string.error_abort,
245
new DialogInterface.OnClickListener() {
246
public void onClick( DialogInterface dialog,
249
if( Doit.this != null )
250
Doit.this._importer.wake(
247
.setNegativeButton( R.string.error_abort,
248
new DialogInterface.OnClickListener() {
249
public void onClick(DialogInterface dialog,
251
Doit.this._importer.wake(
251
252
Importer.RESPONSE_NEGATIVE );
254
.setOnCancelListener( _dialog_on_cancel_listener )
255
.setOnCancelListener( _dialogOnCancelListener )
256
257
case DIALOG_MERGEPROMPT:
257
258
// custom layout in an AlertDialog
258
259
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 )
267
if( Doit.this != null )
268
Doit.this._merge_prompt_always_selected =
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;
260
final View dialogView = factory.inflate(
261
R.layout.mergeprompt, null );
262
( (CheckBox)dialogView.findViewById( R.id.mergeprompt_always ) ).
263
setOnCheckedChangeListener(
264
new CompoundButton.OnCheckedChangeListener() {
265
public void onCheckedChanged( CompoundButton buttonView,
266
boolean isChecked ) {
267
Doit.this._mergePromptAlwaysSelected = isChecked;
270
( (Button)dialogView.findViewById( R.id.merge_keep ) ).
271
setOnClickListener( _mergePromptButtonListener );
272
( (Button)dialogView.findViewById( R.id.merge_overwrite ) ).
273
setOnClickListener( _mergePromptButtonListener );
274
( (Button)dialogView.findViewById( R.id.merge_merge ) ).
275
setOnClickListener( _mergePromptButtonListener );
276
_mergePromptAlwaysSelected = false;
281
277
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 )
278
.setIcon( R.drawable.alert_dialog_icon )
279
.setTitle( R.string.mergeprompt_title )
280
.setView( dialogView )
281
.setOnCancelListener( _dialogOnCancelListener )
291
private OnClickListener _merge_prompt_button_listener =
292
new OnClickListener()
294
public void onClick( View view )
296
if( Doit.this == null ) return;
299
if( view.getId() == R.id.abort )
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?
287
private OnClickListener _mergePromptButtonListener = new OnClickListener() {
288
public void onClick( View view ) {
289
int responseExtra = _mergePromptAlwaysSelected?
305
290
Importer.RESPONSEEXTRA_ALWAYS : Importer.RESPONSEEXTRA_NONE;
306
Doit.this._importer.wake( convertIdToAction( view.getId() ),
310
// close dialog and free (don't keep a reference)
311
Doit.this._merge_prompt_dialog.dismiss();
312
Doit.this._merge_prompt_dialog = null;
291
Doit.this._mergePromptDialog.dismiss();
292
Doit.this._mergePromptDialog = null; // don't keep a reference!
293
Doit.this._importer.wake( convertIdToAction( view.getId() ),
317
protected void onNext()
319
Button next = (Button)findViewById( R.id.next );
320
next.setEnabled( false );
322
switch( _next_action )
328
setResult( RESULT_OK );
334
private void manualAbort()
336
manualAbort( false );
339
private void manualAbort( boolean show_toaster_popup )
341
abortImport( show_toaster_popup );
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 );
351
// close any open dialogs
353
dismissDialog( _current_dialog_id );
355
catch( Exception e ) {
360
private void updateNext( int next_action )
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;
367
next.setEnabled( true );
368
_next_action = next_action;
371
298
public static int convertIdToAction( int id ) {
373
300
case R.id.merge_keep: return ACTION_KEEP;
389
private DialogInterface.OnCancelListener _dialog_on_cancel_listener =
390
new DialogInterface.OnCancelListener()
316
private DialogInterface.OnCancelListener _dialogOnCancelListener =
317
new DialogInterface.OnCancelListener() {
392
318
public void onCancel( DialogInterface dialog ) {
319
setResult( RESULT_CANCELED );
399
protected void onActivityResult( int request_code, int result_code,
325
protected void onActivityResult( int requestCode, int resultCode,
402
328
// if we're cancelling, abort any import
403
if( result_code == RESULT_CANCELED )
329
if( resultCode == RESULT_CANCELED )
408
protected void onPrepareDialog( int id, Dialog dialog )
334
protected void onPrepareDialog(int id, Dialog dialog)
410
_current_dialog_id = id;
414
338
case DIALOG_ERROR: // fall through
415
339
case DIALOG_CONTINUEORABORT:
416
340
// set dialog message
417
( (AlertDialog)dialog ).setMessage( _dialog_message );
341
( (AlertDialog)dialog ).setMessage( _dialogMessage );
419
343
case DIALOG_MERGEPROMPT:
420
344
// set contact's name
421
( (TextView)dialog.findViewById( R.id.mergeprompt_name ) )
422
.setText( _dialog_message );
345
( (TextView)dialog.findViewById( R.id.mergeprompt_name ) ).setText(
423
347
// and set up reference to dialog
424
_merge_prompt_dialog = dialog;
348
_mergePromptDialog = dialog;