179
203
// saving the state of an import sounds complicated! Lets just abort!
182
// destroy some stuff
204
if( _nextAction != NEXT_CLOSE )
188
protected Dialog onCreateDialog(int id)
209
protected Dialog onCreateDialog( int id )
192
213
case DIALOG_ERROR:
193
214
return new AlertDialog.Builder( this )
194
.setIcon( R.drawable.alert_dialog_icon )
195
.setTitle( R.string.error_title )
197
.setPositiveButton( R.string.error_ok,
198
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() {
199
220
public void onClick(DialogInterface dialog,
201
223
Doit.this._importer.wake();
204
.setOnCancelListener( _dialogOnCancelListener )
226
.setOnCancelListener( _dialogOnCancelListener )
206
228
case DIALOG_CONTINUEORABORT:
207
229
return new AlertDialog.Builder( this )
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 )
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 )
229
253
case DIALOG_MERGEPROMPT:
230
254
// custom layout in an AlertDialog
231
255
LayoutInflater factory = LayoutInflater.from( this );
232
256
final View dialogView = factory.inflate(
233
R.layout.mergeprompt, null );
257
R.layout.mergeprompt, null );
234
258
( (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;
259
setOnCheckedChangeListener(
260
new CompoundButton.OnCheckedChangeListener() {
261
public void onCheckedChanged( CompoundButton buttonView,
264
Doit.this._mergePromptAlwaysSelected = isChecked;
242
267
( (Button)dialogView.findViewById( R.id.merge_keep ) ).
243
setOnClickListener( _mergePromptButtonListener );
268
setOnClickListener( _mergePromptButtonListener );
244
269
( (Button)dialogView.findViewById( R.id.merge_overwrite ) ).
245
setOnClickListener( _mergePromptButtonListener );
270
setOnClickListener( _mergePromptButtonListener );
246
271
( (Button)dialogView.findViewById( R.id.merge_merge ) ).
247
setOnClickListener( _mergePromptButtonListener );
272
setOnClickListener( _mergePromptButtonListener );
273
( (Button)dialogView.findViewById( R.id.abort ) ).
274
setOnClickListener( _mergePromptButtonListener );
248
275
_mergePromptAlwaysSelected = false;
249
276
return new AlertDialog.Builder( this )
250
.setIcon( R.drawable.alert_dialog_icon )
251
.setTitle( R.string.mergeprompt_title )
252
.setView( dialogView )
253
.setOnCancelListener( _dialogOnCancelListener )
277
.setIcon( R.drawable.alert_dialog_icon )
278
.setTitle( R.string.mergeprompt_title )
279
.setView( dialogView )
280
.setOnCancelListener( _dialogOnCancelListener )
259
private OnClickListener _mergePromptButtonListener = new OnClickListener() {
260
public void onClick( View view ) {
261
int responseExtra = _mergePromptAlwaysSelected?
262
Importer.RESPONSEEXTRA_ALWAYS : Importer.RESPONSEEXTRA_NONE;
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?
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)
263
302
Doit.this._mergePromptDialog.dismiss();
264
Doit.this._mergePromptDialog = null; // dont keep a reference!
265
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 ) {
350
private void updateNext( int nextAction )
352
Button next = (Button)findViewById( R.id.next );
353
switch( nextAction ) {
354
case NEXT_BEGIN: next.setText( R.string.doit_begin ); break;
355
case NEXT_CLOSE: next.setText( R.string.doit_close ); break;
357
next.setEnabled( true );
358
_nextAction = nextAction;
361
public static int convertIdToAction( int id ) {
363
case R.id.merge_keep: return ACTION_KEEP;
364
case R.id.merge_merge: return ACTION_MERGE_MERGE;
365
case R.id.merge_overwrite: return ACTION_OVERWRITE;
366
default: return ACTION_PROMPT;
370
public static int convertActionToId( int action ) {
372
case ACTION_KEEP: return R.id.merge_keep;
373
case ACTION_MERGE_MERGE:return R.id.merge_merge;
374
case ACTION_OVERWRITE: return R.id.merge_overwrite;
375
default: return R.id.merge_prompt;
269
379
private DialogInterface.OnCancelListener _dialogOnCancelListener =
270
380
new DialogInterface.OnCancelListener() {
271
381
public void onCancel( DialogInterface dialog ) {
272
setResult( RESULT_CANCELED );
278
388
protected void onActivityResult( int requestCode, int resultCode,
281
391
// if we're cancelling, abort any import
282
392
if( resultCode == RESULT_CANCELED )
287
397
protected void onPrepareDialog(int id, Dialog dialog)
399
_currentDialogId = id;
291
403
case DIALOG_ERROR: // fall through