/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

1
 
/*
2
 
 * Doit.java
3
 
 *
4
 
 * Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
5
 
 *
6
 
 * This file is part of the Import Contacts program (hereafter referred
7
 
 * to as "this program"). For more information, see
8
 
 * http://www.waxworlds.org/edam/software/android/import-contacts
9
 
 *
10
 
 * This program is free software: you can redistribute it and/or modify
11
 
 * it under the terms of the GNU General Public License as published by
12
 
 * the Free Software Foundation, either version 3 of the License, or
13
 
 * (at your option) any later version.
14
 
 *
15
 
 * This program is distributed in the hope that it will be useful,
16
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 
 * GNU General Public License for more details.
19
 
 *
20
 
 * You should have received a copy of the GNU General Public License
21
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 
 */
23
 
 
24
1
package org.waxworlds.importcontacts;
25
2
 
26
3
import android.app.AlertDialog;
47
24
        private final static int DIALOG_CONTINUEORABORT = 1;
48
25
        private final static int DIALOG_MERGEPROMPT = 2;
49
26
 
50
 
        public final static int MESSAGE_FINISHED_ALLDONE = 0;
51
 
        public final static int MESSAGE_FINISHED = 1;
52
 
        public final static int MESSAGE_FINISHED_GOBACK = 2;
53
 
        public final static int MESSAGE_ERROR = 3;
54
 
        public final static int MESSAGE_CONTINUEORABORT = 4;
55
 
        public final static int MESSAGE_SETPROGRESSMESSAGE = 5;
56
 
        public final static int MESSAGE_SETMAXPROGRESS = 6;
57
 
        public final static int MESSAGE_SETTMPPROGRESS = 7;
58
 
        public final static int MESSAGE_SETPROGRESS = 8;
59
 
        public final static int MESSAGE_MERGEPROMPT = 9;
60
 
        public final static int MESSAGE_CONTACTOVERWRITTEN = 10;
61
 
        public final static int MESSAGE_CONTACTCREATED = 11;
62
 
        public final static int MESSAGE_CONTACTMERGED = 12;
63
 
        public final static int MESSAGE_CONTACTSKIPPED = 13;
64
 
 
65
27
        private boolean _startedProgress;
66
28
        private int _maxProgress;
67
29
        private int _tmpProgress;
75
37
        private int _countMerges;
76
38
        private int _countSkips;
77
39
 
78
 
        protected Importer _importer = null;
 
40
        protected Importer _importer;
79
41
 
80
42
        public Handler _handler;
81
43
 
85
47
                public void handleMessage( Message msg ) {
86
48
                        switch( msg.what )
87
49
                        {
88
 
                        case MESSAGE_FINISHED_ALLDONE:
89
 
                                ( (TextView)findViewById( R.id.doit_alldone ) ).
90
 
                                                setVisibility( View.VISIBLE );
91
 
                                // fall through
92
 
                        case MESSAGE_FINISHED:
 
50
                        case Importer.MESSAGE_FINISHED:
93
51
                                ( (LinearLayout)findViewById( R.id.doit_closedisplay ) ).
94
52
                                                setVisibility( View.VISIBLE );
95
53
                                break;
96
 
                        case MESSAGE_FINISHED_GOBACK:
 
54
                        case Importer.MESSAGE_FINISHED_BACK:
97
55
                                ( (Button)findViewById( R.id.back ) ).setEnabled( true );
98
56
                                break;
99
 
                        case MESSAGE_ERROR:
 
57
                        case Importer.MESSAGE_ERROR:
100
58
                                Doit.this._dialogMessage = (String)msg.obj;
101
59
                                showDialog( DIALOG_ERROR );
102
60
                                break;
103
 
                        case MESSAGE_CONTINUEORABORT:
 
61
                        case Importer.MESSAGE_CONTINUEORABORT:
104
62
                                Doit.this._dialogMessage = (String)msg.obj;
105
63
                                showDialog( DIALOG_CONTINUEORABORT );
106
64
                                break;
107
 
                        case MESSAGE_SETPROGRESSMESSAGE:
 
65
                        case Importer.MESSAGE_SETPROGRESSMESSAGE:
108
66
                                ( (TextView)findViewById( R.id.doit_percentage ) ).
109
67
                                                setText( (String)msg.obj );
110
68
                                break;
111
 
                        case MESSAGE_SETMAXPROGRESS:
 
69
                        case Importer.MESSAGE_SETMAXPROGRESS:
112
70
                                if( _maxProgress > 0 ) {
113
71
                                        if( _tmpProgress == _maxProgress )
114
72
                                                _tmpProgress = (Integer)msg.obj;
118
76
                                _maxProgress = (Integer)msg.obj;
119
77
                                updateProgress();
120
78
                                break;
121
 
                        case MESSAGE_SETTMPPROGRESS:
 
79
                        case Importer.MESSAGE_SETTMPPROGRESS:
122
80
                                _tmpProgress = (Integer)msg.obj;
123
81
                                updateProgress();
124
82
                                break;
125
 
                        case MESSAGE_SETPROGRESS:
 
83
                        case Importer.MESSAGE_SETPROGRESS:
126
84
                                _startedProgress = true;
127
85
                                _progress = (Integer)msg.obj;
128
86
                                updateProgress();
129
87
                                break;
130
 
                        case MESSAGE_MERGEPROMPT:
 
88
                        case Importer.MESSAGE_MERGEPROMPT:
131
89
                                _dialogMessage = (String)msg.obj;
132
90
                                showDialog( DIALOG_MERGEPROMPT );
133
91
                                break;
134
 
                        case MESSAGE_CONTACTOVERWRITTEN:
 
92
                        case Importer.MESSAGE_CONTACTOVERWRITTEN:
135
93
                                _countOverwrites++;
136
94
                                updateStats();
137
95
                                break;
138
 
                        case MESSAGE_CONTACTCREATED:
 
96
                        case Importer.MESSAGE_CONTACTCREATED:
139
97
                                _countCreates++;
140
98
                                updateStats();
141
99
                                break;
142
 
                        case MESSAGE_CONTACTMERGED:
 
100
                        case Importer.MESSAGE_CONTACTMERGED:
143
101
                                _countMerges++;
144
102
                                updateStats();
145
103
                                break;
146
 
                        case MESSAGE_CONTACTSKIPPED:
 
104
                        case Importer.MESSAGE_CONTACTSKIPPED:
147
105
                                _countSkips++;
148
106
                                updateStats();
149
107
                                break;
202
160
                // saving the state of an import sounds complicated! Lets just abort!
203
161
                abortImport();
204
162
 
205
 
                // destroy some stuff
206
 
                _importer = null;
207
 
                _handler = null;
 
163
                // notify the user
 
164
        Toast.makeText( this, R.string.doit_importaborted,
 
165
                        Toast.LENGTH_LONG ).show();
208
166
        }
209
167
 
210
168
        @Override
380
338
        {
381
339
                if( _importer != null )
382
340
                {
383
 
                        // try and flag worker thread - did we need to?
384
 
                        if( _importer.setAbort() )
385
 
                        {
386
 
                                // wait for worker thread to end
387
 
                                while( true ) {
388
 
                                        try {
389
 
                                                _importer.join();
390
 
                                                break;
391
 
                                        }
392
 
                                        catch( InterruptedException e ) {}
 
341
                        _importer.setAbort();
 
342
                        while( true ) {
 
343
                                try {
 
344
                                        _importer.join();
 
345
                                        break;
393
346
                                }
394
 
 
395
 
                                // notify the user
396
 
                        Toast.makeText( this, R.string.doit_importaborted,
397
 
                                        Toast.LENGTH_LONG ).show();
 
347
                                catch( InterruptedException e ) {}
398
348
                        }
399
349
                }
400
350
        }