/android/import-contacts

To get this branch, use:
bzr branch http://bzr.ed.am/android/import-contacts

« back to all changes in this revision

Viewing changes to src/org/waxworlds/importcontacts/Doit.java

  • Committer: edam
  • Date: 2009-01-28 00:45:02 UTC
  • Revision ID: edam@waxworlds.org-20090128004502-erfklxlwmwhkx4i5
- added scroll view to all layouts
- added intro activity (with disclaimer)
- added action constants so that updates (and changed ids) won't affect saved data
- updated todo

Show diffs side-by-side

added added

removed removed

36
36
import android.widget.Button;
37
37
import android.widget.CheckBox;
38
38
import android.widget.CompoundButton;
 
39
import android.widget.LinearLayout;
39
40
import android.widget.ProgressBar;
40
41
import android.widget.TextView;
41
42
import android.widget.Toast;
66
67
        public final static int ACTION_MERGE_MERGE = 2;
67
68
        public final static int ACTION_OVERWRITE = 3;
68
69
 
69
 
        public final static int NEXT_BEGIN = 0;
70
 
        public final static int NEXT_CLOSE = 1;
71
 
 
72
70
        private boolean _startedProgress;
73
71
        private int _maxProgress;
74
72
        private int _tmpProgress;
76
74
        protected String _dialogMessage;
77
75
        private Dialog _mergePromptDialog;
78
76
        private boolean _mergePromptAlwaysSelected;
79
 
        private int _nextAction;
80
77
 
81
78
        private int _countOverwrites;
82
79
        private int _countCreates;
98
95
                                                setVisibility( View.VISIBLE );
99
96
                                // fall through
100
97
                        case MESSAGE_FINISHED:
101
 
                                updateNext( NEXT_CLOSE );
102
 
                                findViewById( R.id.doit_abort_disp ).setVisibility(
103
 
                                                View.GONE );
 
98
                                ( (LinearLayout)findViewById( R.id.doit_closedisplay ) ).
 
99
                                                setVisibility( View.VISIBLE );
104
100
                                break;
105
101
                        case MESSAGE_FINISHED_GOBACK:
106
102
                                ( (Button)findViewById( R.id.back ) ).setEnabled( true );
107
 
                                findViewById( R.id.doit_abort_disp ).setVisibility(
108
 
                                                View.GONE );
109
103
                                break;
110
104
                        case MESSAGE_ERROR:
111
105
                                Doit.this._dialogMessage = (String)msg.obj;
121
115
                                break;
122
116
                        case MESSAGE_SETMAXPROGRESS:
123
117
                                if( _maxProgress > 0 ) {
124
 
                                        if( _tmpProgress == _maxProgress - 1 )
 
118
                                        if( _tmpProgress == _maxProgress )
125
119
                                                _tmpProgress = (Integer)msg.obj;
126
 
                                        if( _progress == _maxProgress - 1 )
 
120
                                        if( _progress == _maxProgress )
127
121
                                                _progress = (Integer)msg.obj;
128
122
                                }
129
123
                                _maxProgress = (Integer)msg.obj;
173
167
                // hide page 2
174
168
                ( findViewById( R.id.doit_page_2 ) ).setVisibility( View.GONE );
175
169
 
176
 
                // set up abort button
177
 
                Button begin = (Button)findViewById( R.id.abort );
 
170
                // set up begin button
 
171
                Button begin = (Button)findViewById( R.id.doit_begin );
178
172
                begin.setOnClickListener( new View.OnClickListener() {
179
173
                        public void onClick( View view ) {
180
 
                                manualAbort();
 
174
                                importContacts();
 
175
                        }
 
176
                } );
 
177
 
 
178
                // set up close button
 
179
                Button close = (Button)findViewById( R.id.doit_close );
 
180
                close.setOnClickListener( new View.OnClickListener() {
 
181
                        public void onClick( View view ) {
 
182
                                setResult( RESULT_CANCELED );
 
183
                                finish();
181
184
                        }
182
185
                } );
183
186
 
192
195
                _countMerges = 0;
193
196
                _countSkips = 0;
194
197
 
195
 
                updateNext( NEXT_BEGIN );
196
 
 
197
198
                updateProgress();
198
199
                updateStats();
199
200
        }
204
205
                super.onPause();
205
206
 
206
207
                // saving the state of an import sounds complicated! Lets just abort!
207
 
                abortImport( true );
 
208
                abortImport();
 
209
 
 
210
                // destroy some stuff
 
211
                _importer = null;
 
212
                _handler = null;
208
213
        }
209
214
 
210
215
        @Override
268
273
                                        setOnClickListener( _mergePromptButtonListener );
269
274
                        ( (Button)dialogView.findViewById( R.id.merge_merge ) ).
270
275
                                        setOnClickListener( _mergePromptButtonListener );
271
 
                        ( (Button)dialogView.findViewById( R.id.abort ) ).
272
 
                                        setOnClickListener( _mergePromptButtonListener );
273
276
                        _mergePromptAlwaysSelected = false;
274
277
                        return new AlertDialog.Builder( this )
275
278
                                        .setIcon( R.drawable.alert_dialog_icon )
282
285
        }
283
286
 
284
287
    private OnClickListener _mergePromptButtonListener = new OnClickListener() {
285
 
                public void onClick( View view )
286
 
                {
287
 
                        // handle abort
288
 
                        if( view.getId() == R.id.abort )
289
 
                                manualAbort();
290
 
 
291
 
                        // else, response
292
 
                        else {
293
 
                                int responseExtra = _mergePromptAlwaysSelected?
294
 
                                                Importer.RESPONSEEXTRA_ALWAYS : Importer.RESPONSEEXTRA_NONE;
295
 
                                Doit.this._importer.wake( convertIdToAction( view.getId() ),
296
 
                                                responseExtra );
297
 
                        }
298
 
 
299
 
                        // close dialog and free (don't keep a reference)
 
288
                public void onClick( View view ) {
 
289
                        int responseExtra = _mergePromptAlwaysSelected?
 
290
                                        Importer.RESPONSEEXTRA_ALWAYS : Importer.RESPONSEEXTRA_NONE;
300
291
                        Doit.this._mergePromptDialog.dismiss();
301
 
                        Doit.this._mergePromptDialog = null;
 
292
                        Doit.this._mergePromptDialog = null;    // don't keep a reference!
 
293
                        Doit.this._importer.wake( convertIdToAction( view.getId() ),
 
294
                                        responseExtra );
302
295
                }
303
296
        };
304
297
 
305
 
        @Override
306
 
        protected void onNext()
307
 
        {
308
 
                Button next = (Button)findViewById( R.id.next );
309
 
                next.setEnabled( false );
310
 
 
311
 
                switch( _nextAction )
312
 
                {
313
 
                case NEXT_BEGIN:
314
 
                        importContacts();
315
 
                        break;
316
 
                case NEXT_CLOSE:
317
 
                        setResult( RESULT_CANCELED );
318
 
                        finish();
319
 
                        break;
320
 
                }
321
 
        }
322
 
 
323
 
        private void manualAbort()
324
 
        {
325
 
                abortImport( false );
326
 
                updateNext( NEXT_CLOSE );
327
 
                ( (Button)findViewById( R.id.back ) ).setEnabled( true );
328
 
                findViewById( R.id.doit_abort_disp ).setVisibility( View.GONE );
329
 
        }
330
 
 
331
 
        private void updateNext( int nextAction )
332
 
        {
333
 
                Button next = (Button)findViewById( R.id.next );
334
 
                switch( nextAction ) {
335
 
                case NEXT_BEGIN:        next.setText( R.string.doit_begin ); break;
336
 
                case NEXT_CLOSE:        next.setText( R.string.doit_close ); break;
337
 
                }
338
 
                next.setEnabled( true );
339
 
                _nextAction = nextAction;
340
 
        }
341
 
 
342
298
        public static int convertIdToAction( int id ) {
343
299
                switch( id ) {
344
300
                case R.id.merge_keep:           return ACTION_KEEP;
371
327
        {
372
328
                // if we're cancelling, abort any import
373
329
                if( resultCode == RESULT_CANCELED )
374
 
                        abortImport( true );
 
330
                        abortImport();
375
331
        }
376
332
 
377
333
        @Override
444
400
                                "" + _countSkips );
445
401
        }
446
402
 
447
 
        private void abortImport( boolean showToasterPopup )
 
403
        private void abortImport()
448
404
        {
449
405
                if( _importer != null )
450
406
                {
461
417
                                }
462
418
 
463
419
                                // notify the user
464
 
                                if( showToasterPopup )
465
 
                                        Toast.makeText( this, R.string.doit_importaborted,
466
 
                                                        Toast.LENGTH_LONG ).show();
 
420
                        Toast.makeText( this, R.string.doit_importaborted,
 
421
                                        Toast.LENGTH_LONG ).show();
467
422
                        }
468
423
                }
469
 
 
470
 
                // destroy some stuff
471
 
                _importer = null;
472
 
                _handler = null;
473
424
        }
474
425
}