/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/WizardActivity.java

  • Committer: edam
  • Date: 2009-01-13 06:35:26 UTC
  • Revision ID: edam@waxworlds.org-20090113063526-l9t1s9git4bav60a
- new contact's phone numebrs and email addresses are added to the caches after those contacts are updated to account for the situation where the same contact is imported again from another file (or the contact exists twice in the same file!?)

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.edam.importcontacts;
 
24
package org.waxworlds.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 Class< ? > _nextClass;
 
35
        private int _nextState = 0;
36
36
 
37
37
        @Override
38
 
        protected void onCreate( Bundle savedInstanceState )
 
38
        protected void onCreate(Bundle savedInstanceState)
39
39
        {
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 );
 
40
                super.onCreate(savedInstanceState);
46
41
 
47
42
                // set up next button
48
43
                Button next = (Button)findViewById( R.id.next );
49
44
                next.setOnClickListener( new View.OnClickListener() {
50
45
                        public void onClick( View view ) {
51
 
                                onNext();
 
46
                                switchToState( _nextState );
52
47
                        }
53
48
                } );
54
49
 
56
51
                Button back = (Button)findViewById( R.id.back );
57
52
                back.setOnClickListener( new View.OnClickListener() {
58
53
                        public void onClick( View view ) {
59
 
                                onBack();
 
54
                                setResult( RESULT_OK );
 
55
                                finish();
60
56
                        }
61
57
                } );
62
 
        }
63
 
 
64
 
        @Override
65
 
        protected void  onActivityResult( int requestCode, int resultCode, Intent data )
66
 
        {
67
 
                if( resultCode == RESULT_OK ) {
68
 
                        setResult( RESULT_OK );
 
58
 
 
59
                // enable back button?
 
60
                Bundle extras = getIntent().getExtras();
 
61
                if( extras != null ) {
 
62
                        Boolean backstate = extras.getBoolean( "backstate" );
 
63
                        if( backstate != null )
 
64
                                ( (Button)findViewById( R.id.back ) ).setEnabled( true );
 
65
                }
 
66
        }
 
67
 
 
68
        protected void setNextState( int nextState )
 
69
        {
 
70
                // set next state and enable button
 
71
                _nextState = nextState;
 
72
                ( (Button)findViewById( R.id.next ) ).setEnabled( true );
 
73
        }
 
74
 
 
75
        private void switchToState( int newState )
 
76
        {
 
77
                if( newState != 0 )
 
78
                {
 
79
                        // create result data bundle
 
80
                        Bundle bundle = new Bundle();
 
81
                        bundle.putInt( "nextstate", newState );
 
82
 
 
83
                        // create response intent and finish
 
84
                        Intent i = new Intent();
 
85
                        i.putExtras( bundle );
 
86
                        setResult( RESULT_OK, i );
69
87
                        finish();
70
88
                }
71
89
        }
72
90
 
73
 
        protected void onNext()
74
 
        {
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
96
 
                ( (Button)findViewById( R.id.next ) ).setEnabled( true );
97
 
        }
98
 
 
99
91
        public SharedPreferences getSharedPreferences()
100
92
        {
101
93
                return super.getSharedPreferences( "ImportContacts", 0 );
102
94
        }
103
 
}
 
95
}
 
 
'\\ No newline at end of file'