/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-10 16:14:11 UTC
  • Revision ID: edam@waxworlds.org-20090110161411-4d17l9hs9d6j277q
Initial import

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