24
46
private final static int DIALOG_CONTINUEORABORT = 1;
25
47
private final static int DIALOG_MERGEPROMPT = 2;
27
private boolean _startedProgress;
28
private int _maxProgress;
29
private int _tmpProgress;
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
private boolean _started_progress;
72
private int _max_progress;
73
private int _tmp_progress;
30
74
private int _progress;
31
protected String _dialogMessage;
32
private Dialog _mergePromptDialog;
33
private boolean _mergePromptAlwaysSelected;
35
private int _countOverwrites;
36
private int _countCreates;
37
private int _countMerges;
38
private int _countSkips;
40
protected Importer _importer;
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;
81
private int _count_overwrites;
82
private int _count_creates;
83
private int _count_merges;
84
private int _count_skips;
86
protected Importer _importer = null;
42
88
public Handler _handler;
47
93
public void handleMessage( Message msg ) {
50
case Importer.MESSAGE_FINISHED:
51
( (LinearLayout)findViewById( R.id.doit_closedisplay ) ).
52
setVisibility( View.VISIBLE );
54
case Importer.MESSAGE_FINISHED_BACK:
55
( (Button)findViewById( R.id.back ) ).setEnabled( true );
57
case Importer.MESSAGE_ERROR:
58
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
_dialog_message = (String)msg.obj;
59
109
showDialog( DIALOG_ERROR );
61
case Importer.MESSAGE_CONTINUEORABORT:
62
Doit.this._dialogMessage = (String)msg.obj;
111
case MESSAGE_CONTINUEORABORT:
112
_dialog_message = (String)msg.obj;
63
113
showDialog( DIALOG_CONTINUEORABORT );
65
case Importer.MESSAGE_SETPROGRESSMESSAGE:
115
case MESSAGE_SETPROGRESSMESSAGE:
66
116
( (TextView)findViewById( R.id.doit_percentage ) ).
67
setText( (String)msg.obj );
117
setText( (String)msg.obj );
69
case Importer.MESSAGE_SETMAXPROGRESS:
70
if( _maxProgress > 0 ) {
71
if( _tmpProgress == _maxProgress )
72
_tmpProgress = (Integer)msg.obj;
73
if( _progress == _maxProgress )
119
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 )
74
124
_progress = (Integer)msg.obj;
76
_maxProgress = (Integer)msg.obj;
79
case Importer.MESSAGE_SETTMPPROGRESS:
80
_tmpProgress = (Integer)msg.obj;
83
case Importer.MESSAGE_SETPROGRESS:
84
_startedProgress = true;
126
_max_progress = (Integer)msg.obj;
129
case MESSAGE_SETTMPPROGRESS:
130
_tmp_progress = (Integer)msg.obj;
133
case MESSAGE_SETPROGRESS:
134
_started_progress = true;
85
135
_progress = (Integer)msg.obj;
88
case Importer.MESSAGE_MERGEPROMPT:
89
_dialogMessage = (String)msg.obj;
138
case MESSAGE_MERGEPROMPT:
139
_dialog_message = (String)msg.obj;
90
140
showDialog( DIALOG_MERGEPROMPT );
92
case Importer.MESSAGE_CONTACTOVERWRITTEN:
96
case Importer.MESSAGE_CONTACTCREATED:
100
case Importer.MESSAGE_CONTACTMERGED:
104
case Importer.MESSAGE_CONTACTSKIPPED:
142
case MESSAGE_CONTACTOVERWRITTEN:
146
case MESSAGE_CONTACTCREATED:
150
case MESSAGE_CONTACTMERGED:
154
case MESSAGE_CONTACTSKIPPED:
160
203
// saving the state of an import sounds complicated! Lets just abort!
164
Toast.makeText( this, R.string.doit_importaborted,
165
Toast.LENGTH_LONG ).show();
204
if( _next_action != 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() {
180
public void onClick(DialogInterface dialog,
182
Doit.this._importer.wake();
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();
185
.setOnCancelListener( _dialogOnCancelListener )
227
.setOnCancelListener( _dialog_on_cancel_listener )
187
229
case DIALOG_CONTINUEORABORT:
188
230
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(
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(
197
241
Importer.RESPONSE_POSITIVE );
200
.setNegativeButton( R.string.error_abort,
201
new DialogInterface.OnClickListener() {
202
public void onClick(DialogInterface dialog,
204
Doit.this._importer.wake(
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(
205
251
Importer.RESPONSE_NEGATIVE );
208
.setOnCancelListener( _dialogOnCancelListener )
254
.setOnCancelListener( _dialog_on_cancel_listener )
210
256
case DIALOG_MERGEPROMPT:
211
257
// custom layout in an AlertDialog
212
258
LayoutInflater factory = LayoutInflater.from( this );
213
final View dialogView = factory.inflate(
214
R.layout.mergeprompt, null );
215
( (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;
223
( (Button)dialogView.findViewById( R.id.merge_keep ) ).
224
setOnClickListener( _mergePromptButtonListener );
225
( (Button)dialogView.findViewById( R.id.merge_overwrite ) ).
226
setOnClickListener( _mergePromptButtonListener );
227
( (Button)dialogView.findViewById( R.id.merge_merge ) ).
228
setOnClickListener( _mergePromptButtonListener );
229
_mergePromptAlwaysSelected = false;
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;
230
281
return new AlertDialog.Builder( this )
231
.setIcon( R.drawable.alert_dialog_icon )
232
.setTitle( R.string.mergeprompt_title )
233
.setView( dialogView )
234
.setOnCancelListener( _dialogOnCancelListener )
282
.setIcon( R.drawable.alert_dialog_icon )
283
.setTitle( R.string.mergeprompt_title )
284
.setView( dialog_view )
285
.setOnCancelListener( _dialog_on_cancel_listener )
240
private OnClickListener _mergePromptButtonListener = new OnClickListener() {
241
public void onClick( View view ) {
242
int responseExtra = _mergePromptAlwaysSelected?
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?
243
305
Importer.RESPONSEEXTRA_ALWAYS : Importer.RESPONSEEXTRA_NONE;
244
Doit.this._mergePromptDialog.dismiss();
245
Doit.this._mergePromptDialog = null; // dont keep a reference!
246
Doit.this._importer.wake( view.getId(), responseExtra );
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;
250
private DialogInterface.OnCancelListener _dialogOnCancelListener =
251
new DialogInterface.OnCancelListener() {
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
public static int convertIdToAction( int id ) {
373
case R.id.merge_keep: return ACTION_KEEP;
374
case R.id.merge_merge: return ACTION_MERGE_MERGE;
375
case R.id.merge_overwrite: return ACTION_OVERWRITE;
376
default: return ACTION_PROMPT;
380
public static int convertActionToId( int action ) {
382
case ACTION_KEEP: return R.id.merge_keep;
383
case ACTION_MERGE_MERGE:return R.id.merge_merge;
384
case ACTION_OVERWRITE: return R.id.merge_overwrite;
385
default: return R.id.merge_prompt;
389
private DialogInterface.OnCancelListener _dialog_on_cancel_listener =
390
new DialogInterface.OnCancelListener()
252
392
public void onCancel( DialogInterface dialog ) {
253
setResult( RESULT_CANCELED );
259
protected void onActivityResult( int requestCode, int resultCode,
399
protected void onActivityResult( int request_code, int result_code,
262
402
// if we're cancelling, abort any import
263
if( resultCode == RESULT_CANCELED )
403
if( result_code == RESULT_CANCELED )
268
protected void onPrepareDialog(int id, Dialog dialog)
408
protected void onPrepareDialog( int id, Dialog dialog )
410
_current_dialog_id = id;
272
414
case DIALOG_ERROR: // fall through
273
415
case DIALOG_CONTINUEORABORT:
274
416
// set dialog message
275
( (AlertDialog)dialog ).setMessage( _dialogMessage );
417
( (AlertDialog)dialog ).setMessage( _dialog_message );
277
419
case DIALOG_MERGEPROMPT:
278
420
// set contact's name
279
( (TextView)dialog.findViewById( R.id.mergeprompt_name ) ).setText(
421
( (TextView)dialog.findViewById( R.id.mergeprompt_name ) )
422
.setText( _dialog_message );
281
423
// and set up reference to dialog
282
_mergePromptDialog = dialog;
424
_merge_prompt_dialog = dialog;