/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-11 13:00:52 UTC
  • Revision ID: edam@waxworlds.org-20090111130052-q9bh0zz4ey47egbv
- updated todo list

Show diffs side-by-side

added added

removed removed

16
16
import android.widget.LinearLayout;
17
17
import android.widget.ProgressBar;
18
18
import android.widget.TextView;
 
19
import android.widget.Toast;
19
20
 
20
21
public class Doit extends WizardActivity
21
22
{
23
24
        private final static int DIALOG_CONTINUEORABORT = 1;
24
25
        private final static int DIALOG_MERGEPROMPT = 2;
25
26
 
 
27
        public final static int MESSAGE_FINISHED_ALLDONE = 0;
 
28
        public final static int MESSAGE_FINISHED = 1;
 
29
        public final static int MESSAGE_FINISHED_GOBACK = 2;
 
30
        public final static int MESSAGE_ERROR = 3;
 
31
        public final static int MESSAGE_CONTINUEORABORT = 4;
 
32
        public final static int MESSAGE_SETPROGRESSMESSAGE = 5;
 
33
        public final static int MESSAGE_SETMAXPROGRESS = 6;
 
34
        public final static int MESSAGE_SETTMPPROGRESS = 7;
 
35
        public final static int MESSAGE_SETPROGRESS = 8;
 
36
        public final static int MESSAGE_MERGEPROMPT = 9;
 
37
        public final static int MESSAGE_CONTACTOVERWRITTEN = 10;
 
38
        public final static int MESSAGE_CONTACTCREATED = 11;
 
39
        public final static int MESSAGE_CONTACTMERGED = 12;
 
40
        public final static int MESSAGE_CONTACTSKIPPED = 13;
 
41
 
26
42
        private boolean _startedProgress;
27
43
        private int _maxProgress;
28
44
        private int _tmpProgress;
36
52
        private int _countMerges;
37
53
        private int _countSkips;
38
54
 
39
 
        protected Importer _importer;
 
55
        protected Importer _importer = null;
40
56
 
41
57
        public Handler _handler;
42
58
 
46
62
                public void handleMessage( Message msg ) {
47
63
                        switch( msg.what )
48
64
                        {
49
 
                        case Importer.MESSAGE_FINISHED:
 
65
                        case MESSAGE_FINISHED_ALLDONE:
 
66
                                ( (TextView)findViewById( R.id.doit_alldone ) ).
 
67
                                                setVisibility( View.VISIBLE );
 
68
                                // fall through
 
69
                        case MESSAGE_FINISHED:
50
70
                                ( (LinearLayout)findViewById( R.id.doit_closedisplay ) ).
51
71
                                                setVisibility( View.VISIBLE );
52
72
                                break;
53
 
                        case Importer.MESSAGE_FINISHED_BACK:
 
73
                        case MESSAGE_FINISHED_GOBACK:
54
74
                                ( (Button)findViewById( R.id.back ) ).setEnabled( true );
55
75
                                break;
56
 
                        case Importer.MESSAGE_ERROR:
 
76
                        case MESSAGE_ERROR:
57
77
                                Doit.this._dialogMessage = (String)msg.obj;
58
78
                                showDialog( DIALOG_ERROR );
59
79
                                break;
60
 
                        case Importer.MESSAGE_CONTINUEORABORT:
 
80
                        case MESSAGE_CONTINUEORABORT:
61
81
                                Doit.this._dialogMessage = (String)msg.obj;
62
82
                                showDialog( DIALOG_CONTINUEORABORT );
63
83
                                break;
64
 
                        case Importer.MESSAGE_SETPROGRESSMESSAGE:
 
84
                        case MESSAGE_SETPROGRESSMESSAGE:
65
85
                                ( (TextView)findViewById( R.id.doit_percentage ) ).
66
86
                                                setText( (String)msg.obj );
67
87
                                break;
68
 
                        case Importer.MESSAGE_SETMAXPROGRESS:
 
88
                        case MESSAGE_SETMAXPROGRESS:
69
89
                                if( _maxProgress > 0 ) {
70
90
                                        if( _tmpProgress == _maxProgress )
71
91
                                                _tmpProgress = (Integer)msg.obj;
75
95
                                _maxProgress = (Integer)msg.obj;
76
96
                                updateProgress();
77
97
                                break;
78
 
                        case Importer.MESSAGE_SETTMPPROGRESS:
 
98
                        case MESSAGE_SETTMPPROGRESS:
79
99
                                _tmpProgress = (Integer)msg.obj;
80
100
                                updateProgress();
81
101
                                break;
82
 
                        case Importer.MESSAGE_SETPROGRESS:
 
102
                        case MESSAGE_SETPROGRESS:
83
103
                                _startedProgress = true;
84
104
                                _progress = (Integer)msg.obj;
85
105
                                updateProgress();
86
106
                                break;
87
 
                        case Importer.MESSAGE_MERGEPROMPT:
 
107
                        case MESSAGE_MERGEPROMPT:
88
108
                                _dialogMessage = (String)msg.obj;
89
109
                                showDialog( DIALOG_MERGEPROMPT );
90
110
                                break;
91
 
                        case Importer.MESSAGE_CONTACTOVERWRITTEN:
 
111
                        case MESSAGE_CONTACTOVERWRITTEN:
92
112
                                _countOverwrites++;
93
113
                                updateStats();
94
114
                                break;
95
 
                        case Importer.MESSAGE_CONTACTCREATED:
 
115
                        case MESSAGE_CONTACTCREATED:
96
116
                                _countCreates++;
97
117
                                updateStats();
98
118
                                break;
99
 
                        case Importer.MESSAGE_CONTACTMERGED:
 
119
                        case MESSAGE_CONTACTMERGED:
100
120
                                _countMerges++;
101
121
                                updateStats();
102
122
                                break;
103
 
                        case Importer.MESSAGE_CONTACTSKIPPED:
 
123
                        case MESSAGE_CONTACTSKIPPED:
104
124
                                _countSkips++;
105
125
                                updateStats();
106
126
                                break;
136
156
                        }
137
157
                } );
138
158
 
139
 
 
140
 
 
141
159
                _startedProgress = false;
142
160
                _maxProgress = 0;
143
161
                _tmpProgress = 0;
158
176
        {
159
177
                super.onPause();
160
178
 
 
179
                // saving the state of an import sounds complicated! Lets just abort!
161
180
                abortImport();
162
181
 
163
 
                // notify the user
164
 
 
165
 
 
 
182
                // destroy some stuff
 
183
                _importer = null;
 
184
                _handler = null;
166
185
        }
167
186
 
168
187
        @Override
259
278
        protected void onActivityResult( int requestCode, int resultCode,
260
279
                        Intent data )
261
280
        {
 
281
                // if we're cancelling, abort any import
262
282
                if( resultCode == RESULT_CANCELED )
263
283
                        abortImport();
264
284
        }
337
357
        {
338
358
                if( _importer != null )
339
359
                {
340
 
                        _importer.setAbort();
341
 
                        while( true ) {
342
 
                                try {
343
 
                                        _importer.join();
344
 
                                        break;
 
360
                        // try and flag worker thread - did we need to?
 
361
                        if( _importer.setAbort() )
 
362
                        {
 
363
                                // wait for worker thread to end
 
364
                                while( true ) {
 
365
                                        try {
 
366
                                                _importer.join();
 
367
                                                break;
 
368
                                        }
 
369
                                        catch( InterruptedException e ) {}
345
370
                                }
346
 
                                catch( InterruptedException e ) {}
 
371
 
 
372
                                // notify the user
 
373
                        Toast.makeText( this, R.string.doit_importaborted,
 
374
                                        Toast.LENGTH_LONG ).show();
347
375
                        }
348
376
                }
349
377
        }