/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 19:16:04 UTC
  • Revision ID: edam@waxworlds.org-20090110191604-24xjo5brlvislhqw
- added toaster message about import abortion in onPause()
- added TODO list

Show diffs side-by-side

added added

removed removed

24
24
        private final static int DIALOG_CONTINUEORABORT = 1;
25
25
        private final static int DIALOG_MERGEPROMPT = 2;
26
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
 
 
42
27
        private boolean _startedProgress;
43
28
        private int _maxProgress;
44
29
        private int _tmpProgress;
52
37
        private int _countMerges;
53
38
        private int _countSkips;
54
39
 
55
 
        protected Importer _importer = null;
 
40
        protected Importer _importer;
56
41
 
57
42
        public Handler _handler;
58
43
 
62
47
                public void handleMessage( Message msg ) {
63
48
                        switch( msg.what )
64
49
                        {
65
 
                        case MESSAGE_FINISHED_ALLDONE:
66
 
                                ( (TextView)findViewById( R.id.doit_alldone ) ).
67
 
                                                setVisibility( View.VISIBLE );
68
 
                                // fall through
69
 
                        case MESSAGE_FINISHED:
 
50
                        case Importer.MESSAGE_FINISHED:
70
51
                                ( (LinearLayout)findViewById( R.id.doit_closedisplay ) ).
71
52
                                                setVisibility( View.VISIBLE );
72
53
                                break;
73
 
                        case MESSAGE_FINISHED_GOBACK:
 
54
                        case Importer.MESSAGE_FINISHED_BACK:
74
55
                                ( (Button)findViewById( R.id.back ) ).setEnabled( true );
75
56
                                break;
76
 
                        case MESSAGE_ERROR:
 
57
                        case Importer.MESSAGE_ERROR:
77
58
                                Doit.this._dialogMessage = (String)msg.obj;
78
59
                                showDialog( DIALOG_ERROR );
79
60
                                break;
80
 
                        case MESSAGE_CONTINUEORABORT:
 
61
                        case Importer.MESSAGE_CONTINUEORABORT:
81
62
                                Doit.this._dialogMessage = (String)msg.obj;
82
63
                                showDialog( DIALOG_CONTINUEORABORT );
83
64
                                break;
84
 
                        case MESSAGE_SETPROGRESSMESSAGE:
 
65
                        case Importer.MESSAGE_SETPROGRESSMESSAGE:
85
66
                                ( (TextView)findViewById( R.id.doit_percentage ) ).
86
67
                                                setText( (String)msg.obj );
87
68
                                break;
88
 
                        case MESSAGE_SETMAXPROGRESS:
 
69
                        case Importer.MESSAGE_SETMAXPROGRESS:
89
70
                                if( _maxProgress > 0 ) {
90
71
                                        if( _tmpProgress == _maxProgress )
91
72
                                                _tmpProgress = (Integer)msg.obj;
95
76
                                _maxProgress = (Integer)msg.obj;
96
77
                                updateProgress();
97
78
                                break;
98
 
                        case MESSAGE_SETTMPPROGRESS:
 
79
                        case Importer.MESSAGE_SETTMPPROGRESS:
99
80
                                _tmpProgress = (Integer)msg.obj;
100
81
                                updateProgress();
101
82
                                break;
102
 
                        case MESSAGE_SETPROGRESS:
 
83
                        case Importer.MESSAGE_SETPROGRESS:
103
84
                                _startedProgress = true;
104
85
                                _progress = (Integer)msg.obj;
105
86
                                updateProgress();
106
87
                                break;
107
 
                        case MESSAGE_MERGEPROMPT:
 
88
                        case Importer.MESSAGE_MERGEPROMPT:
108
89
                                _dialogMessage = (String)msg.obj;
109
90
                                showDialog( DIALOG_MERGEPROMPT );
110
91
                                break;
111
 
                        case MESSAGE_CONTACTOVERWRITTEN:
 
92
                        case Importer.MESSAGE_CONTACTOVERWRITTEN:
112
93
                                _countOverwrites++;
113
94
                                updateStats();
114
95
                                break;
115
 
                        case MESSAGE_CONTACTCREATED:
 
96
                        case Importer.MESSAGE_CONTACTCREATED:
116
97
                                _countCreates++;
117
98
                                updateStats();
118
99
                                break;
119
 
                        case MESSAGE_CONTACTMERGED:
 
100
                        case Importer.MESSAGE_CONTACTMERGED:
120
101
                                _countMerges++;
121
102
                                updateStats();
122
103
                                break;
123
 
                        case MESSAGE_CONTACTSKIPPED:
 
104
                        case Importer.MESSAGE_CONTACTSKIPPED:
124
105
                                _countSkips++;
125
106
                                updateStats();
126
107
                                break;
179
160
                // 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
        Toast.makeText( this, R.string.doit_importaborted,
 
165
                        Toast.LENGTH_LONG ).show();
185
166
        }
186
167
 
187
168
        @Override
357
338
        {
358
339
                if( _importer != null )
359
340
                {
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 ) {}
 
341
                        _importer.setAbort();
 
342
                        while( true ) {
 
343
                                try {
 
344
                                        _importer.join();
 
345
                                        break;
370
346
                                }
371
 
 
372
 
                                // notify the user
373
 
                        Toast.makeText( this, R.string.doit_importaborted,
374
 
                                        Toast.LENGTH_LONG ).show();
 
347
                                catch( InterruptedException e ) {}
375
348
                        }
376
349
                }
377
350
        }