46
93
public void handleMessage( Message msg ) {
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;
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;
58
109
showDialog( DIALOG_ERROR );
60
case Importer.MESSAGE_CONTINUEORABORT:
61
Doit.this._dialogMessage = (String)msg.obj;
111
case MESSAGE_CONTINUEORABORT:
112
_dialogMessage = (String)msg.obj;
62
113
showDialog( DIALOG_CONTINUEORABORT );
64
case Importer.MESSAGE_SETPROGRESSMESSAGE:
115
case MESSAGE_SETPROGRESSMESSAGE:
65
116
( (TextView)findViewById( R.id.doit_percentage ) ).
66
setText( (String)msg.obj );
117
setText( (String)msg.obj );
68
case Importer.MESSAGE_SETMAXPROGRESS:
119
case MESSAGE_SETMAXPROGRESS:
69
120
if( _maxProgress > 0 ) {
70
if( _tmpProgress == _maxProgress )
121
if( _tmpProgress == _maxProgress - 1 )
71
122
_tmpProgress = (Integer)msg.obj;
72
if( _progress == _maxProgress )
123
if( _progress == _maxProgress - 1 )
73
124
_progress = (Integer)msg.obj;
75
126
_maxProgress = (Integer)msg.obj;
78
case Importer.MESSAGE_SETTMPPROGRESS:
129
case MESSAGE_SETTMPPROGRESS:
79
130
_tmpProgress = (Integer)msg.obj;
82
case Importer.MESSAGE_SETPROGRESS:
133
case MESSAGE_SETPROGRESS:
83
134
_startedProgress = true;
84
135
_progress = (Integer)msg.obj;
87
case Importer.MESSAGE_MERGEPROMPT:
138
case MESSAGE_MERGEPROMPT:
88
139
_dialogMessage = (String)msg.obj;
89
140
showDialog( DIALOG_MERGEPROMPT );
91
case Importer.MESSAGE_CONTACTOVERWRITTEN:
142
case MESSAGE_CONTACTOVERWRITTEN:
92
143
_countOverwrites++;
95
case Importer.MESSAGE_CONTACTCREATED:
146
case MESSAGE_CONTACTCREATED:
99
case Importer.MESSAGE_CONTACTMERGED:
150
case MESSAGE_CONTACTMERGED:
103
case Importer.MESSAGE_CONTACTSKIPPED:
154
case MESSAGE_CONTACTSKIPPED:
203
// saving the state of an import sounds complicated! Lets just abort!
204
if( _nextAction != NEXT_CLOSE )
169
protected Dialog onCreateDialog(int id)
209
protected Dialog onCreateDialog( int id )
173
213
case DIALOG_ERROR:
174
214
return new AlertDialog.Builder( this )
175
.setIcon( R.drawable.alert_dialog_icon )
176
.setTitle( R.string.error_title )
178
.setPositiveButton( R.string.error_ok,
179
new DialogInterface.OnClickListener() {
215
.setIcon( R.drawable.alert_dialog_icon )
216
.setTitle( R.string.error_title )
218
.setPositiveButton( R.string.error_ok,
219
new DialogInterface.OnClickListener() {
180
220
public void onClick(DialogInterface dialog,
182
223
Doit.this._importer.wake();
185
.setOnCancelListener( _dialogOnCancelListener )
226
.setOnCancelListener( _dialogOnCancelListener )
187
228
case DIALOG_CONTINUEORABORT:
188
229
return new AlertDialog.Builder( this )
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 )
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( _dialogOnCancelListener )
210
253
case DIALOG_MERGEPROMPT:
211
254
// custom layout in an AlertDialog
212
255
LayoutInflater factory = LayoutInflater.from( this );
213
256
final View dialogView = factory.inflate(
214
R.layout.mergeprompt, null );
257
R.layout.mergeprompt, null );
215
258
( (CheckBox)dialogView.findViewById( R.id.mergeprompt_always ) ).
216
setOnCheckedChangeListener(
217
new CompoundButton.OnCheckedChangeListener() {
218
public void onCheckedChanged( CompoundButton buttonView,
219
boolean isChecked ) {
220
Doit.this._mergePromptAlwaysSelected = isChecked;
259
setOnCheckedChangeListener(
260
new CompoundButton.OnCheckedChangeListener() {
261
public void onCheckedChanged( CompoundButton buttonView,
264
Doit.this._mergePromptAlwaysSelected = isChecked;
223
267
( (Button)dialogView.findViewById( R.id.merge_keep ) ).
224
setOnClickListener( _mergePromptButtonListener );
268
setOnClickListener( _mergePromptButtonListener );
225
269
( (Button)dialogView.findViewById( R.id.merge_overwrite ) ).
226
setOnClickListener( _mergePromptButtonListener );
270
setOnClickListener( _mergePromptButtonListener );
227
271
( (Button)dialogView.findViewById( R.id.merge_merge ) ).
228
setOnClickListener( _mergePromptButtonListener );
272
setOnClickListener( _mergePromptButtonListener );
273
( (Button)dialogView.findViewById( R.id.abort ) ).
274
setOnClickListener( _mergePromptButtonListener );
229
275
_mergePromptAlwaysSelected = false;
230
276
return new AlertDialog.Builder( this )
231
.setIcon( R.drawable.alert_dialog_icon )
232
.setTitle( R.string.mergeprompt_title )
233
.setView( dialogView )
234
.setOnCancelListener( _dialogOnCancelListener )
277
.setIcon( R.drawable.alert_dialog_icon )
278
.setTitle( R.string.mergeprompt_title )
279
.setView( dialogView )
280
.setOnCancelListener( _dialogOnCancelListener )
240
private OnClickListener _mergePromptButtonListener = new OnClickListener() {
241
public void onClick( View view ) {
242
int responseExtra = _mergePromptAlwaysSelected?
286
private OnClickListener _mergePromptButtonListener = new OnClickListener() {
287
public void onClick( View view )
290
if( view.getId() == R.id.abort )
293
// else, response (just check we haven't aborted already!)
294
else if( Doit.this._importer != null ) {
295
int responseExtra = _mergePromptAlwaysSelected?
243
296
Importer.RESPONSEEXTRA_ALWAYS : Importer.RESPONSEEXTRA_NONE;
297
Doit.this._importer.wake( convertIdToAction( view.getId() ),
301
// close dialog and free (don't keep a reference)
244
302
Doit.this._mergePromptDialog.dismiss();
245
Doit.this._mergePromptDialog = null; // dont keep a reference!
246
Doit.this._importer.wake( view.getId(), responseExtra );
303
Doit.this._mergePromptDialog = null;
308
protected void onNext()
310
Button next = (Button)findViewById( R.id.next );
311
next.setEnabled( false );
313
switch( _nextAction )
319
setResult( RESULT_OK );
325
private void manualAbort()
327
manualAbort( false );
330
private void manualAbort( boolean showToasterPopup )
332
abortImport( showToasterPopup );
334
updateNext( NEXT_CLOSE );
335
( (Button)findViewById( R.id.back ) ).setEnabled( true );
336
findViewById( R.id.doit_abort_disp ).setVisibility( View.GONE );
337
( (TextView)findViewById( R.id.doit_aborted ) ).
338
setVisibility( View.VISIBLE );
339
( (TextView)findViewById( R.id.doit_alldone ) ).
340
setVisibility( View.GONE );
342
// close any open dialogs
344
dismissDialog( _currentDialogId );
346
catch( Exception e ) {
351
private void updateNext( int nextAction )
353
Button next = (Button)findViewById( R.id.next );
354
switch( nextAction ) {
355
case NEXT_BEGIN: next.setText( R.string.doit_begin ); break;
356
case NEXT_CLOSE: next.setText( R.string.doit_close ); break;
358
next.setEnabled( true );
359
_nextAction = nextAction;
362
public static int convertIdToAction( int id ) {
364
case R.id.merge_keep: return ACTION_KEEP;
365
case R.id.merge_merge: return ACTION_MERGE_MERGE;
366
case R.id.merge_overwrite: return ACTION_OVERWRITE;
367
default: return ACTION_PROMPT;
371
public static int convertActionToId( int action ) {
373
case ACTION_KEEP: return R.id.merge_keep;
374
case ACTION_MERGE_MERGE:return R.id.merge_merge;
375
case ACTION_OVERWRITE: return R.id.merge_overwrite;
376
default: return R.id.merge_prompt;
250
380
private DialogInterface.OnCancelListener _dialogOnCancelListener =
251
381
new DialogInterface.OnCancelListener() {
252
382
public void onCancel( DialogInterface dialog ) {
253
setResult( RESULT_CANCELED );
259
389
protected void onActivityResult( int requestCode, int resultCode,
392
// if we're cancelling, abort any import
262
393
if( resultCode == RESULT_CANCELED )
267
398
protected void onPrepareDialog(int id, Dialog dialog)
400
_currentDialogId = id;
271
404
case DIALOG_ERROR: // fall through