93
62
public void handleMessage( Message msg ) {
65
case MESSAGE_FINISHED_ALLDONE:
97
66
( (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(
67
setVisibility( View.VISIBLE );
69
case MESSAGE_FINISHED:
70
( (LinearLayout)findViewById( R.id.doit_closedisplay ) ).
71
setVisibility( View.VISIBLE );
73
case MESSAGE_FINISHED_GOBACK:
74
( (Button)findViewById( R.id.back ) ).setEnabled( true );
107
76
case MESSAGE_ERROR:
108
_dialog_message = (String)msg.obj;
77
Doit.this._dialogMessage = (String)msg.obj;
109
78
showDialog( DIALOG_ERROR );
111
80
case MESSAGE_CONTINUEORABORT:
112
_dialog_message = (String)msg.obj;
81
Doit.this._dialogMessage = (String)msg.obj;
113
82
showDialog( DIALOG_CONTINUEORABORT );
115
84
case MESSAGE_SETPROGRESSMESSAGE:
116
85
( (TextView)findViewById( R.id.doit_percentage ) ).
117
setText( (String)msg.obj );
86
setText( (String)msg.obj );
119
88
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 )
89
if( _maxProgress > 0 ) {
90
if( _tmpProgress == _maxProgress )
91
_tmpProgress = (Integer)msg.obj;
92
if( _progress == _maxProgress )
124
93
_progress = (Integer)msg.obj;
126
_max_progress = (Integer)msg.obj;
95
_maxProgress = (Integer)msg.obj;
129
98
case MESSAGE_SETTMPPROGRESS:
130
_tmp_progress = (Integer)msg.obj;
99
_tmpProgress = (Integer)msg.obj;
131
100
updateProgress();
133
102
case MESSAGE_SETPROGRESS:
134
_started_progress = true;
103
_startedProgress = true;
135
104
_progress = (Integer)msg.obj;
136
105
updateProgress();
138
107
case MESSAGE_MERGEPROMPT:
139
_dialog_message = (String)msg.obj;
108
_dialogMessage = (String)msg.obj;
140
109
showDialog( DIALOG_MERGEPROMPT );
142
111
case MESSAGE_CONTACTOVERWRITTEN:
146
115
case MESSAGE_CONTACTCREATED:
150
119
case MESSAGE_CONTACTMERGED:
154
123
case MESSAGE_CONTACTSKIPPED:
203
179
// saving the state of an import sounds complicated! Lets just abort!
204
if( _next_action != NEXT_CLOSE )
182
// destroy some stuff
209
protected Dialog onCreateDialog( int id )
188
protected Dialog onCreateDialog(int id)
213
192
case DIALOG_ERROR:
214
193
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,
194
.setIcon( R.drawable.alert_dialog_icon )
195
.setTitle( R.string.error_title )
197
.setPositiveButton( R.string.error_ok,
198
new DialogInterface.OnClickListener() {
199
public void onClick(DialogInterface dialog,
223
201
Doit.this._importer.wake();
226
.setOnCancelListener( _dialog_on_cancel_listener )
204
.setOnCancelListener( _dialogOnCancelListener )
228
206
case DIALOG_CONTINUEORABORT:
229
207
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 )
208
.setIcon( R.drawable.alert_dialog_icon )
209
.setTitle( R.string.error_title )
211
.setPositiveButton( R.string.error_continue,
212
new DialogInterface.OnClickListener() {
213
public void onClick(DialogInterface dialog,
215
Doit.this._importer.wake(
216
Importer.RESPONSE_POSITIVE );
219
.setNegativeButton( R.string.error_abort,
220
new DialogInterface.OnClickListener() {
221
public void onClick(DialogInterface dialog,
223
Doit.this._importer.wake(
224
Importer.RESPONSE_NEGATIVE );
227
.setOnCancelListener( _dialogOnCancelListener )
253
229
case DIALOG_MERGEPROMPT:
254
230
// custom layout in an AlertDialog
255
231
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;
232
final View dialogView = factory.inflate(
233
R.layout.mergeprompt, null );
234
( (CheckBox)dialogView.findViewById( R.id.mergeprompt_always ) ).
235
setOnCheckedChangeListener(
236
new CompoundButton.OnCheckedChangeListener() {
237
public void onCheckedChanged( CompoundButton buttonView,
238
boolean isChecked ) {
239
Doit.this._mergePromptAlwaysSelected = isChecked;
242
( (Button)dialogView.findViewById( R.id.merge_keep ) ).
243
setOnClickListener( _mergePromptButtonListener );
244
( (Button)dialogView.findViewById( R.id.merge_overwrite ) ).
245
setOnClickListener( _mergePromptButtonListener );
246
( (Button)dialogView.findViewById( R.id.merge_merge ) ).
247
setOnClickListener( _mergePromptButtonListener );
248
_mergePromptAlwaysSelected = false;
277
249
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 )
250
.setIcon( R.drawable.alert_dialog_icon )
251
.setTitle( R.string.mergeprompt_title )
252
.setView( dialogView )
253
.setOnCancelListener( _dialogOnCancelListener )
287
private OnClickListener _merge_prompt_button_listener =
288
new OnClickListener()
290
public void onClick( View view )
293
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?
259
private OnClickListener _mergePromptButtonListener = new OnClickListener() {
260
public void onClick( View view ) {
261
int responseExtra = _mergePromptAlwaysSelected?
299
262
Importer.RESPONSEEXTRA_ALWAYS : Importer.RESPONSEEXTRA_NONE;
300
Doit.this._importer.wake( convertIdToAction( view.getId() ),
304
// close dialog and free (don't keep a reference)
305
Doit.this._merge_prompt_dialog.dismiss();
306
Doit.this._merge_prompt_dialog = null;
263
Doit.this._mergePromptDialog.dismiss();
264
Doit.this._mergePromptDialog = null; // dont keep a reference!
265
Doit.this._importer.wake( view.getId(), responseExtra );
311
protected void onNext()
313
Button next = (Button)findViewById( R.id.next );
314
next.setEnabled( false );
316
switch( _next_action )
322
setResult( RESULT_OK );
269
private DialogInterface.OnCancelListener _dialogOnCancelListener =
270
new DialogInterface.OnCancelListener() {
271
public void onCancel( DialogInterface dialog ) {
272
setResult( RESULT_CANCELED );
328
private void manualAbort()
330
manualAbort( false );
333
private void manualAbort( boolean show_toaster_popup )
335
abortImport( show_toaster_popup );
337
updateNext( NEXT_CLOSE );
338
( (Button)findViewById( R.id.back ) ).setEnabled( true );
339
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 )
356
Button next = (Button)findViewById( R.id.next );
357
switch( next_action ) {
358
case NEXT_BEGIN: next.setText( R.string.doit_begin ); break;
359
case NEXT_CLOSE: next.setText( R.string.doit_close ); break;
361
next.setEnabled( true );
362
_next_action = next_action;
365
public static int convertIdToAction( int id ) {
367
case R.id.merge_keep: return ACTION_KEEP;
368
case R.id.merge_merge: return ACTION_MERGE_MERGE;
369
case R.id.merge_overwrite: return ACTION_OVERWRITE;
370
default: return ACTION_PROMPT;
374
public static int convertActionToId( int action ) {
376
case ACTION_KEEP: return R.id.merge_keep;
377
case ACTION_MERGE_MERGE:return R.id.merge_merge;
378
case ACTION_OVERWRITE: return R.id.merge_overwrite;
379
default: return R.id.merge_prompt;
383
private DialogInterface.OnCancelListener _dialog_on_cancel_listener =
384
new DialogInterface.OnCancelListener()
386
public void onCancel( DialogInterface dialog ) {
393
protected void onActivityResult( int request_code, int result_code,
278
protected void onActivityResult( int requestCode, int resultCode,
396
281
// if we're cancelling, abort any import
397
if( result_code == RESULT_CANCELED )
282
if( resultCode == RESULT_CANCELED )
402
protected void onPrepareDialog( int id, Dialog dialog )
287
protected void onPrepareDialog(int id, Dialog dialog)
404
_current_dialog_id = id;
408
291
case DIALOG_ERROR: // fall through
409
292
case DIALOG_CONTINUEORABORT:
410
293
// set dialog message
411
( (AlertDialog)dialog ).setMessage( _dialog_message );
294
( (AlertDialog)dialog ).setMessage( _dialogMessage );
413
296
case DIALOG_MERGEPROMPT:
414
297
// set contact's name
415
( (TextView)dialog.findViewById( R.id.mergeprompt_name ) )
416
.setText( _dialog_message );
298
( (TextView)dialog.findViewById( R.id.mergeprompt_name ) ).setText(
417
300
// and set up reference to dialog
418
_merge_prompt_dialog = dialog;
301
_mergePromptDialog = dialog;