203
// close any open dialogs
205
dismissDialog( _currentDialogId );
207
catch( Exception e ) {
202
210
// saving the state of an import sounds complicated! Lets just abort!
205
// destroy some stuff
211
protected Dialog onCreateDialog(int id)
215
protected Dialog onCreateDialog( int id )
215
219
case DIALOG_ERROR:
216
220
return new AlertDialog.Builder( this )
217
.setIcon( R.drawable.alert_dialog_icon )
218
.setTitle( R.string.error_title )
220
.setPositiveButton( R.string.error_ok,
221
new DialogInterface.OnClickListener() {
221
.setIcon( R.drawable.alert_dialog_icon )
222
.setTitle( R.string.error_title )
224
.setPositiveButton( R.string.error_ok,
225
new DialogInterface.OnClickListener() {
222
226
public void onClick(DialogInterface dialog,
224
229
Doit.this._importer.wake();
227
.setOnCancelListener( _dialogOnCancelListener )
232
.setOnCancelListener( _dialogOnCancelListener )
229
234
case DIALOG_CONTINUEORABORT:
230
235
return new AlertDialog.Builder( this )
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 )
236
.setIcon( R.drawable.alert_dialog_icon )
237
.setTitle( R.string.error_title )
239
.setPositiveButton( R.string.error_continue,
240
new DialogInterface.OnClickListener() {
241
public void onClick(DialogInterface dialog,
244
Doit.this._importer.wake(
245
Importer.RESPONSE_POSITIVE );
248
.setNegativeButton( R.string.error_abort,
249
new DialogInterface.OnClickListener() {
250
public void onClick(DialogInterface dialog,
253
Doit.this._importer.wake(
254
Importer.RESPONSE_NEGATIVE );
257
.setOnCancelListener( _dialogOnCancelListener )
252
259
case DIALOG_MERGEPROMPT:
253
260
// custom layout in an AlertDialog
254
261
LayoutInflater factory = LayoutInflater.from( this );
255
262
final View dialogView = factory.inflate(
256
R.layout.mergeprompt, null );
263
R.layout.mergeprompt, null );
257
264
( (CheckBox)dialogView.findViewById( R.id.mergeprompt_always ) ).
258
setOnCheckedChangeListener(
259
new CompoundButton.OnCheckedChangeListener() {
260
public void onCheckedChanged( CompoundButton buttonView,
261
boolean isChecked ) {
262
Doit.this._mergePromptAlwaysSelected = isChecked;
265
setOnCheckedChangeListener(
266
new CompoundButton.OnCheckedChangeListener() {
267
public void onCheckedChanged( CompoundButton buttonView,
270
Doit.this._mergePromptAlwaysSelected = isChecked;
265
273
( (Button)dialogView.findViewById( R.id.merge_keep ) ).
266
setOnClickListener( _mergePromptButtonListener );
274
setOnClickListener( _mergePromptButtonListener );
267
275
( (Button)dialogView.findViewById( R.id.merge_overwrite ) ).
268
setOnClickListener( _mergePromptButtonListener );
276
setOnClickListener( _mergePromptButtonListener );
269
277
( (Button)dialogView.findViewById( R.id.merge_merge ) ).
270
setOnClickListener( _mergePromptButtonListener );
278
setOnClickListener( _mergePromptButtonListener );
279
( (Button)dialogView.findViewById( R.id.abort ) ).
280
setOnClickListener( _mergePromptButtonListener );
271
281
_mergePromptAlwaysSelected = false;
272
282
return new AlertDialog.Builder( this )
273
.setIcon( R.drawable.alert_dialog_icon )
274
.setTitle( R.string.mergeprompt_title )
275
.setView( dialogView )
276
.setOnCancelListener( _dialogOnCancelListener )
283
.setIcon( R.drawable.alert_dialog_icon )
284
.setTitle( R.string.mergeprompt_title )
285
.setView( dialogView )
286
.setOnCancelListener( _dialogOnCancelListener )
282
private OnClickListener _mergePromptButtonListener = new OnClickListener() {
283
public void onClick( View view ) {
284
int responseExtra = _mergePromptAlwaysSelected?
285
Importer.RESPONSEEXTRA_ALWAYS : Importer.RESPONSEEXTRA_NONE;
292
private OnClickListener _mergePromptButtonListener = new OnClickListener() {
293
public void onClick( View view )
296
if( view.getId() == R.id.abort )
301
int responseExtra = _mergePromptAlwaysSelected?
302
Importer.RESPONSEEXTRA_ALWAYS : Importer.RESPONSEEXTRA_NONE;
303
Doit.this._importer.wake( convertIdToAction( view.getId() ),
307
// close dialog and free (don't keep a reference)
286
308
Doit.this._mergePromptDialog.dismiss();
287
Doit.this._mergePromptDialog = null; // dont keep a reference!
288
Doit.this._importer.wake( view.getId(), responseExtra );
309
Doit.this._mergePromptDialog = null;
314
protected void onNext()
316
Button next = (Button)findViewById( R.id.next );
317
next.setEnabled( false );
319
switch( _nextAction )
325
setResult( RESULT_OK );
331
private void manualAbort()
333
manualAbort( false );
336
private void manualAbort( boolean showToasterPopup )
338
abortImport( showToasterPopup );
340
updateNext( NEXT_CLOSE );
341
( (Button)findViewById( R.id.back ) ).setEnabled( true );
342
findViewById( R.id.doit_abort_disp ).setVisibility( View.GONE );
343
( (TextView)findViewById( R.id.doit_aborted ) ).
344
setVisibility( View.VISIBLE );
345
( (TextView)findViewById( R.id.doit_alldone ) ).
346
setVisibility( View.GONE );
349
private void updateNext( int nextAction )
351
Button next = (Button)findViewById( R.id.next );
352
switch( nextAction ) {
353
case NEXT_BEGIN: next.setText( R.string.doit_begin ); break;
354
case NEXT_CLOSE: next.setText( R.string.doit_close ); break;
356
next.setEnabled( true );
357
_nextAction = nextAction;
360
public static int convertIdToAction( int id ) {
362
case R.id.merge_keep: return ACTION_KEEP;
363
case R.id.merge_merge: return ACTION_MERGE_MERGE;
364
case R.id.merge_overwrite: return ACTION_OVERWRITE;
365
default: return ACTION_PROMPT;
369
public static int convertActionToId( int action ) {
371
case ACTION_KEEP: return R.id.merge_keep;
372
case ACTION_MERGE_MERGE:return R.id.merge_merge;
373
case ACTION_OVERWRITE: return R.id.merge_overwrite;
374
default: return R.id.merge_prompt;
292
378
private DialogInterface.OnCancelListener _dialogOnCancelListener =
293
379
new DialogInterface.OnCancelListener() {
294
380
public void onCancel( DialogInterface dialog ) {