/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

1
1
/*
2
2
 * WizardActivity.java
3
3
 *
4
 
 * Copyright (C) 2009 Tim Marston <tim@ed.am>
 
4
 * Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
5
5
 *
6
6
 * This file is part of the Import Contacts program (hereafter referred
7
 
 * to as "this program").  For more information, see
8
 
 * http://ed.am/dev/android/import-contacts
 
7
 * to as "this program"). For more information, see
 
8
 * http://www.waxworlds.org/edam/software/android/import-contacts
9
9
 *
10
10
 * This program is free software: you can redistribute it and/or modify
11
11
 * it under the terms of the GNU General Public License as published by
21
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
22
 */
23
23
 
24
 
package am.ed.importcontacts;
 
24
package org.waxworlds.importcontacts;
25
25
 
26
26
import android.app.Activity;
27
27
import android.content.Intent;
28
28
import android.content.SharedPreferences;
29
 
import android.content.res.Configuration;
30
29
import android.os.Bundle;
31
30
import android.view.View;
32
31
import android.widget.Button;
33
32
 
34
33
public class WizardActivity extends Activity
35
34
{
36
 
        private Class< ? > _next_class;
 
35
        private int _nextState = 0;
37
36
 
38
37
        @Override
39
 
        protected void onCreate( Bundle saved_instance_state )
 
38
        protected void onCreate(Bundle savedInstanceState)
40
39
        {
41
 
                super.onCreate( saved_instance_state );
42
 
 
43
 
                // enable back button based on intent data
44
 
                Bundle extras = getIntent().getExtras();
45
 
                if( extras != null )//&& extras.getBoolean( "back-enabled" ) )
46
 
                        ( (Button)findViewById( R.id.back ) ).setEnabled( true );
 
40
                super.onCreate(savedInstanceState);
47
41
 
48
42
                // set up next button
49
43
                Button next = (Button)findViewById( R.id.next );
50
44
                next.setOnClickListener( new View.OnClickListener() {
51
45
                        public void onClick( View view ) {
52
 
                                onNext();
 
46
                                switchToState( _nextState );
53
47
                        }
54
48
                } );
55
49
 
57
51
                Button back = (Button)findViewById( R.id.back );
58
52
                back.setOnClickListener( new View.OnClickListener() {
59
53
                        public void onClick( View view ) {
60
 
                                onBack();
 
54
                                setResult( RESULT_OK );
 
55
                                finish();
61
56
                        }
62
57
                } );
63
 
        }
64
 
 
65
 
        @Override
66
 
        protected void onActivityResult( int request_code, int result_code,
67
 
                Intent data )
68
 
        {
69
 
                if( result_code == RESULT_OK ) {
70
 
                        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 );
71
87
                        finish();
72
88
                }
73
89
        }
74
90
 
75
 
        protected void onNext()
76
 
        {
77
 
                // create bundle with back enabled state
78
 
                Bundle bundle = new Bundle();
79
 
                bundle.putBoolean( "back-enabled", true );
80
 
                Intent i = new Intent( this, _next_class );
81
 
                i.putExtras( bundle );
82
 
 
83
 
                // start next activity
84
 
                startActivityForResult( i, 0 );
85
 
        }
86
 
 
87
 
        protected void onBack()
88
 
        {
89
 
                setResult( RESULT_CANCELED );
90
 
                finish();
91
 
        }
92
 
 
93
 
        protected void setNextActivity( Class< ? > cls )
94
 
        {
95
 
                _next_class = cls;
96
 
 
97
 
                // enable next button
98
 
                ( (Button)findViewById( R.id.next ) ).setEnabled( true );
99
 
        }
100
 
 
101
91
        public SharedPreferences getSharedPreferences()
102
92
        {
103
93
                return super.getSharedPreferences( "ImportContacts", 0 );
104
94
        }
105
 
 
106
 
        @Override
107
 
        public void onConfigurationChanged( Configuration new_config ) {
108
 
                super.onConfigurationChanged( new_config );
109
 
        }
110
 
}
 
95
}
 
 
'\\ No newline at end of file'