/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/WizardActivity.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.Activity;
27
27
import android.content.Intent;
32
32
 
33
33
public class WizardActivity extends Activity
34
34
{
35
 
        private int _nextState;
36
 
        private boolean _backEnabled;
 
35
        private Class< ? > _nextClass;
37
36
 
38
37
        @Override
39
 
        protected void onCreate(Bundle savedInstanceState)
 
38
        protected void onCreate( Bundle savedInstanceState )
40
39
        {
41
 
                super.onCreate(savedInstanceState);
42
 
 
43
 
                _nextState = 0;
44
 
 
45
 
                // deal with saved state vs. defaults
46
 
                if( savedInstanceState == null)
47
 
                {
48
 
                        _backEnabled = false;
49
 
 
50
 
                        Bundle extras = getIntent().getExtras();
51
 
                        if( extras != null )
52
 
                                _backEnabled = extras.getBoolean( "backstate" );
53
 
                }
54
 
                else
55
 
                {
56
 
                        _backEnabled = savedInstanceState.getBoolean( "_backEnabled" );
57
 
                }
58
 
 
59
 
                // enable/disable back button
60
 
                ( (Button)findViewById( R.id.back ) ).setEnabled( _backEnabled );
 
40
                super.onCreate( savedInstanceState );
 
41
 
 
42
                // enable back button based on intent data
 
43
                Bundle extras = getIntent().getExtras();
 
44
                if( extras != null )//&& extras.getBoolean( "back-enabled" ) )
 
45
                        ( (Button)findViewById( R.id.back ) ).setEnabled( true );
61
46
 
62
47
                // set up next button
63
48
                Button next = (Button)findViewById( R.id.next );
71
56
                Button back = (Button)findViewById( R.id.back );
72
57
                back.setOnClickListener( new View.OnClickListener() {
73
58
                        public void onClick( View view ) {
74
 
                                setResult( RESULT_OK );
75
 
                                finish();
 
59
                                onBack();
76
60
                        }
77
61
                } );
78
62
        }
79
63
 
80
64
        @Override
81
 
        protected void onSaveInstanceState( Bundle outState ) {
82
 
                super.onSaveInstanceState(outState);
83
 
                outState.putBoolean( "_backEnabled", _backEnabled );
84
 
        }
85
 
/*
86
 
        @Override
87
 
        protected void onPause()
 
65
        protected void  onActivityResult( int requestCode, int resultCode, Intent data )
88
66
        {
89
 
                super.onPause();
 
67
                if( resultCode == RESULT_OK ) {
 
68
                        setResult( RESULT_OK );
 
69
                        finish();
 
70
                }
90
71
        }
91
72
 
92
 
        @Override
93
 
        protected void onResume()
94
 
        {
95
 
                super.onResume();
96
 
        }
97
 
*/
98
73
        protected void onNext()
99
74
        {
100
 
                switchToState( _nextState );
101
 
        }
102
 
 
103
 
        protected void setNextState( int nextState )
104
 
        {
105
 
                // set next state and enable button
106
 
                _nextState = nextState;
 
75
                // create bundle with back enabled state
 
76
                Bundle bundle = new Bundle();
 
77
                bundle.putBoolean( "back-enabled", true );
 
78
                Intent i = new Intent( this, _nextClass );
 
79
                i.putExtras( bundle );
 
80
 
 
81
                // start next activity
 
82
                startActivityForResult( i, 0 );
 
83
        }
 
84
 
 
85
        protected void onBack()
 
86
        {
 
87
                setResult( RESULT_CANCELED );
 
88
                finish();
 
89
        }
 
90
 
 
91
        protected void setNextActivity( Class< ? > cls )
 
92
        {
 
93
                _nextClass = cls;
 
94
 
 
95
                // enable next button
107
96
                ( (Button)findViewById( R.id.next ) ).setEnabled( true );
108
97
        }
109
98
 
110
 
        private void switchToState( int newState )
111
 
        {
112
 
                if( newState != 0 )
113
 
                {
114
 
                        // create result data bundle
115
 
                        Bundle bundle = new Bundle();
116
 
                        bundle.putInt( "nextstate", newState );
117
 
 
118
 
                        // create response intent and finish
119
 
                        Intent i = new Intent();
120
 
                        i.putExtras( bundle );
121
 
                        setResult( RESULT_OK, i );
122
 
                        finish();
123
 
                }
124
 
        }
125
 
 
126
99
        public SharedPreferences getSharedPreferences()
127
100
        {
128
101
                return super.getSharedPreferences( "ImportContacts", 0 );