93
85
public void handleMessage( Message msg ) {
88
case MESSAGE_FINISHED_ALLDONE:
97
89
( (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(
90
setVisibility( View.VISIBLE );
92
case MESSAGE_FINISHED:
93
( (LinearLayout)findViewById( R.id.doit_closedisplay ) ).
94
setVisibility( View.VISIBLE );
96
case MESSAGE_FINISHED_GOBACK:
97
( (Button)findViewById( R.id.back ) ).setEnabled( true );
107
99
case MESSAGE_ERROR:
108
_dialogMessage = (String)msg.obj;
100
Doit.this._dialogMessage = (String)msg.obj;
109
101
showDialog( DIALOG_ERROR );
111
103
case MESSAGE_CONTINUEORABORT:
112
_dialogMessage = (String)msg.obj;
104
Doit.this._dialogMessage = (String)msg.obj;
113
105
showDialog( DIALOG_CONTINUEORABORT );
115
107
case MESSAGE_SETPROGRESSMESSAGE:
116
108
( (TextView)findViewById( R.id.doit_percentage ) ).
117
setText( (String)msg.obj );
109
setText( (String)msg.obj );
119
111
case MESSAGE_SETMAXPROGRESS:
120
112
if( _maxProgress > 0 ) {
121
if( _tmpProgress == _maxProgress - 1 )
113
if( _tmpProgress == _maxProgress )
122
114
_tmpProgress = (Integer)msg.obj;
123
if( _progress == _maxProgress - 1 )
115
if( _progress == _maxProgress )
124
116
_progress = (Integer)msg.obj;
126
118
_maxProgress = (Integer)msg.obj;
203
202
// saving the state of an import sounds complicated! Lets just abort!
204
if( _nextAction != NEXT_CLOSE )
205
// destroy some stuff
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() {
217
.setIcon( R.drawable.alert_dialog_icon )
218
.setTitle( R.string.error_title )
220
.setPositiveButton( R.string.error_ok,
221
new DialogInterface.OnClickListener() {
220
222
public void onClick(DialogInterface dialog,
223
224
Doit.this._importer.wake();
226
.setOnCancelListener( _dialogOnCancelListener )
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( _dialogOnCancelListener )
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
255
final View dialogView = factory.inflate(
257
R.layout.mergeprompt, null );
256
R.layout.mergeprompt, null );
258
257
( (CheckBox)dialogView.findViewById( R.id.mergeprompt_always ) ).
259
setOnCheckedChangeListener(
260
new CompoundButton.OnCheckedChangeListener() {
261
public void onCheckedChanged( CompoundButton buttonView,
264
Doit.this._mergePromptAlwaysSelected = isChecked;
258
setOnCheckedChangeListener(
259
new CompoundButton.OnCheckedChangeListener() {
260
public void onCheckedChanged( CompoundButton buttonView,
261
boolean isChecked ) {
262
Doit.this._mergePromptAlwaysSelected = isChecked;
267
265
( (Button)dialogView.findViewById( R.id.merge_keep ) ).
268
setOnClickListener( _mergePromptButtonListener );
266
setOnClickListener( _mergePromptButtonListener );
269
267
( (Button)dialogView.findViewById( R.id.merge_overwrite ) ).
270
setOnClickListener( _mergePromptButtonListener );
268
setOnClickListener( _mergePromptButtonListener );
271
269
( (Button)dialogView.findViewById( R.id.merge_merge ) ).
272
setOnClickListener( _mergePromptButtonListener );
273
( (Button)dialogView.findViewById( R.id.abort ) ).
274
setOnClickListener( _mergePromptButtonListener );
270
setOnClickListener( _mergePromptButtonListener );
275
271
_mergePromptAlwaysSelected = false;
276
272
return new AlertDialog.Builder( this )
277
.setIcon( R.drawable.alert_dialog_icon )
278
.setTitle( R.string.mergeprompt_title )
279
.setView( dialogView )
280
.setOnCancelListener( _dialogOnCancelListener )
273
.setIcon( R.drawable.alert_dialog_icon )
274
.setTitle( R.string.mergeprompt_title )
275
.setView( dialogView )
276
.setOnCancelListener( _dialogOnCancelListener )
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?
282
private OnClickListener _mergePromptButtonListener = new OnClickListener() {
283
public void onClick( View view ) {
284
int responseExtra = _mergePromptAlwaysSelected?
296
285
Importer.RESPONSEEXTRA_ALWAYS : Importer.RESPONSEEXTRA_NONE;
297
Doit.this._importer.wake( convertIdToAction( view.getId() ),
301
// close dialog and free (don't keep a reference)
302
286
Doit.this._mergePromptDialog.dismiss();
303
Doit.this._mergePromptDialog = null;
287
Doit.this._mergePromptDialog = null; // dont keep a reference!
288
Doit.this._importer.wake( view.getId(), responseExtra );
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;
380
292
private DialogInterface.OnCancelListener _dialogOnCancelListener =
381
293
new DialogInterface.OnCancelListener() {
382
294
public void onCancel( DialogInterface dialog ) {
295
setResult( RESULT_CANCELED );
389
301
protected void onActivityResult( int requestCode, int resultCode,
392
304
// if we're cancelling, abort any import
393
305
if( resultCode == RESULT_CANCELED )
398
310
protected void onPrepareDialog(int id, Dialog dialog)
400
_currentDialogId = id;
404
314
case DIALOG_ERROR: // fall through