/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/edam/importcontacts/Doit.java

  • Committer: edam
  • Date: 2010-07-04 14:44:48 UTC
  • Revision ID: edam@waxworlds.org-20100704144448-1m30v811opup20fs
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
- massively simplified the WizzardActivity class so it works propperly
- moved all code to org.waxworlds.edam
- added an "aborted" message when the importion is aborted
- simplified the 3 actions the worker thread can take when stopping (only 2 were actualy used) to "aborted" or "alldone"
- changed intro message to match website
- bugfix: don't blow up when the My Contacts group is missing

Show diffs side-by-side

added added

removed removed

21
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
22
 */
23
23
 
24
 
package org.waxworlds.importcontacts;
 
24
package org.waxworlds.edam.importcontacts;
25
25
 
26
26
import android.app.AlertDialog;
27
27
import android.app.Dialog;
46
46
        private final static int DIALOG_CONTINUEORABORT = 1;
47
47
        private final static int DIALOG_MERGEPROMPT = 2;
48
48
 
49
 
        public final static int MESSAGE_FINISHED_ALLDONE = 0;
50
 
        public final static int MESSAGE_FINISHED = 1;
51
 
        public final static int MESSAGE_FINISHED_GOBACK = 2;
 
49
        public final static int MESSAGE_ALLDONE = 0;
 
50
        public final static int MESSAGE_ABORT = 1;
52
51
        public final static int MESSAGE_ERROR = 3;
53
52
        public final static int MESSAGE_CONTINUEORABORT = 4;
54
53
        public final static int MESSAGE_SETPROGRESSMESSAGE = 5;
77
76
        private Dialog _mergePromptDialog;
78
77
        private boolean _mergePromptAlwaysSelected;
79
78
        private int _nextAction;
 
79
        private int _currentDialogId;
80
80
 
81
81
        private int _countOverwrites;
82
82
        private int _countCreates;
93
93
                public void handleMessage( Message msg ) {
94
94
                        switch( msg.what )
95
95
                        {
96
 
                        case MESSAGE_FINISHED_ALLDONE:
 
96
                        case MESSAGE_ALLDONE:
97
97
                                ( (TextView)findViewById( R.id.doit_alldone ) ).
98
 
                                                setVisibility( View.VISIBLE );
99
 
                                // fall through
100
 
                        case MESSAGE_FINISHED:
 
98
                                        setVisibility( View.VISIBLE );
 
99
                                ( (Button)findViewById( R.id.back ) ).setEnabled( false );
101
100
                                updateNext( NEXT_CLOSE );
102
101
                                findViewById( R.id.doit_abort_disp ).setVisibility(
103
102
                                                View.GONE );
104
103
                                break;
105
 
                        case MESSAGE_FINISHED_GOBACK:
106
 
                                ( (Button)findViewById( R.id.back ) ).setEnabled( true );
107
 
                                findViewById( R.id.doit_abort_disp ).setVisibility(
108
 
                                                View.GONE );
 
104
                        case MESSAGE_ABORT:
 
105
                                manualAbort();
109
106
                                break;
110
107
                        case MESSAGE_ERROR:
111
 
                                Doit.this._dialogMessage = (String)msg.obj;
 
108
                                _dialogMessage = (String)msg.obj;
112
109
                                showDialog( DIALOG_ERROR );
113
110
                                break;
114
111
                        case MESSAGE_CONTINUEORABORT:
115
 
                                Doit.this._dialogMessage = (String)msg.obj;
 
112
                                _dialogMessage = (String)msg.obj;
116
113
                                showDialog( DIALOG_CONTINUEORABORT );
117
114
                                break;
118
115
                        case MESSAGE_SETPROGRESSMESSAGE:
203
200
        {
204
201
                super.onPause();
205
202
 
 
203
                // close any open dialogs
 
204
                try {
 
205
                        dismissDialog( _currentDialogId );
 
206
                }
 
207
                catch( Exception e ) {
 
208
                }
 
209
 
206
210
                // saving the state of an import sounds complicated! Lets just abort!
207
 
                abortImport( true );
 
211
                manualAbort( true );
208
212
        }
209
213
 
210
214
        @Override
211
 
        protected Dialog onCreateDialog(int id)
 
215
        protected Dialog onCreateDialog( int id )
212
216
        {
213
217
                switch( id )
214
218
                {
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 )
219
 
                                        .setMessage( "" )
220
 
                                        .setPositiveButton( R.string.error_ok,
221
 
                                                        new DialogInterface.OnClickListener() {
 
221
                                .setIcon( R.drawable.alert_dialog_icon )
 
222
                                .setTitle( R.string.error_title )
 
223
                                .setMessage( "" )
 
224
                                .setPositiveButton( R.string.error_ok,
 
225
                                        new DialogInterface.OnClickListener() {
222
226
                                                public void onClick(DialogInterface dialog,
223
 
                                                                int whichButton) {
 
227
                                                        int whichButton)
 
228
                                                {
224
229
                                                        Doit.this._importer.wake();
225
230
                                                }
226
231
                                        } )
227
 
                                        .setOnCancelListener( _dialogOnCancelListener )
228
 
                                        .create();
 
232
                                .setOnCancelListener( _dialogOnCancelListener )
 
233
                                .create();
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 )
233
 
                                        .setMessage( "" )
234
 
                                        .setPositiveButton( R.string.error_continue,
235
 
                                                        new DialogInterface.OnClickListener() {
236
 
                                                public void onClick(DialogInterface dialog,
237
 
                                                                int whichButton) {
238
 
                                                        Doit.this._importer.wake(
239
 
                                                                        Importer.RESPONSE_POSITIVE );
240
 
                                                }
241
 
                                        } )
242
 
                                        .setNegativeButton( R.string.error_abort,
243
 
                                                        new DialogInterface.OnClickListener() {
244
 
                                                public void onClick(DialogInterface dialog,
245
 
                                                                int whichButton) {
246
 
                                                        Doit.this._importer.wake(
247
 
                                                                        Importer.RESPONSE_NEGATIVE );
248
 
                                                }
249
 
                                        } )
250
 
                                        .setOnCancelListener( _dialogOnCancelListener )
251
 
                                        .create();
 
236
                                .setIcon( R.drawable.alert_dialog_icon )
 
237
                                .setTitle( R.string.error_title )
 
238
                                .setMessage( "" )
 
239
                                .setPositiveButton( R.string.error_continue,
 
240
                                        new DialogInterface.OnClickListener() {
 
241
                                                public void onClick(DialogInterface dialog,
 
242
                                                        int whichButton)
 
243
                                                {
 
244
                                                        Doit.this._importer.wake(
 
245
                                                                Importer.RESPONSE_POSITIVE );
 
246
                                                }
 
247
                                        } )
 
248
                                .setNegativeButton( R.string.error_abort,
 
249
                                        new DialogInterface.OnClickListener() {
 
250
                                                public void onClick(DialogInterface dialog,
 
251
                                                        int whichButton)
 
252
                                                {
 
253
                                                        Doit.this._importer.wake(
 
254
                                                                Importer.RESPONSE_NEGATIVE );
 
255
                                                }
 
256
                                        } )
 
257
                                .setOnCancelListener( _dialogOnCancelListener )
 
258
                                .create();
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;
263
 
                                }
264
 
                        } );
 
265
                                setOnCheckedChangeListener(
 
266
                                        new CompoundButton.OnCheckedChangeListener() {
 
267
                                                public void onCheckedChanged( CompoundButton buttonView,
 
268
                                                        boolean isChecked )
 
269
                                                {
 
270
                                                        Doit.this._mergePromptAlwaysSelected = isChecked;
 
271
                                                }
 
272
                                        } );
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 );
271
279
                        ( (Button)dialogView.findViewById( R.id.abort ) ).
272
 
                                        setOnClickListener( _mergePromptButtonListener );
 
280
                                setOnClickListener( _mergePromptButtonListener );
273
281
                        _mergePromptAlwaysSelected = false;
274
282
                        return new AlertDialog.Builder( this )
275
 
                                        .setIcon( R.drawable.alert_dialog_icon )
276
 
                                        .setTitle( R.string.mergeprompt_title )
277
 
                                        .setView( dialogView )
278
 
                                        .setOnCancelListener( _dialogOnCancelListener )
279
 
                                        .create();
 
283
                                .setIcon( R.drawable.alert_dialog_icon )
 
284
                                .setTitle( R.string.mergeprompt_title )
 
285
                                .setView( dialogView )
 
286
                                .setOnCancelListener( _dialogOnCancelListener )
 
287
                                .create();
280
288
                }
281
289
                return null;
282
290
        }
314
322
                        importContacts();
315
323
                        break;
316
324
                case NEXT_CLOSE:
317
 
                        setResult( RESULT_CANCELED );
 
325
                        setResult( RESULT_OK );
318
326
                        finish();
319
327
                        break;
320
328
                }
322
330
 
323
331
        private void manualAbort()
324
332
        {
325
 
                abortImport( false );
 
333
                manualAbort( false );
 
334
        }
 
335
 
 
336
        private void manualAbort( boolean showToasterPopup )
 
337
        {
 
338
                abortImport( showToasterPopup );
 
339
 
326
340
                updateNext( NEXT_CLOSE );
327
341
                ( (Button)findViewById( R.id.back ) ).setEnabled( true );
328
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 );
329
347
        }
330
348
 
331
349
        private void updateNext( int nextAction )
377
395
        @Override
378
396
        protected void onPrepareDialog(int id, Dialog dialog)
379
397
        {
 
398
                _currentDialogId = id;
 
399
 
380
400
                switch( id )
381
401
                {
382
402
                case DIALOG_ERROR:      // fall through