/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-10-28 15:49:21 UTC
  • Revision ID: edam@waxworlds.org-20101028154921-98svlxlpno3cpzb8
- added file chooser
- changed file/dir entry box for a button that opens the file chooser
- added dialog to ask if you want to select a dir to scan or a file
- fixed bug where you could abort as dialog opened and the dialog wasn't cancelled
- fixed crash where you could abort as the merge prompt opened and it would try to use the just-destroyed importer
- fixed bug where closing the application at the end would show "aborted!" erroniously

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 = 0;
 
35
        private Class< ? > _nextClass;
36
36
 
37
37
        @Override
38
 
        protected void onCreate(Bundle savedInstanceState)
 
38
        protected void onCreate( Bundle savedInstanceState )
39
39
        {
40
 
                super.onCreate(savedInstanceState);
 
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 );
41
46
 
42
47
                // set up next button
43
48
                Button next = (Button)findViewById( R.id.next );
44
49
                next.setOnClickListener( new View.OnClickListener() {
45
50
                        public void onClick( View view ) {
46
 
                                switchToState( _nextState );
 
51
                                onNext();
47
52
                        }
48
53
                } );
49
54
 
51
56
                Button back = (Button)findViewById( R.id.back );
52
57
                back.setOnClickListener( new View.OnClickListener() {
53
58
                        public void onClick( View view ) {
54
 
                                setResult( RESULT_OK );
55
 
                                finish();
 
59
                                onBack();
56
60
                        }
57
61
                } );
 
62
        }
58
63
 
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 );
 
64
        @Override
 
65
        protected void  onActivityResult( int requestCode, int resultCode, Intent data )
 
66
        {
 
67
                if( resultCode == RESULT_OK ) {
 
68
                        setResult( RESULT_OK );
 
69
                        finish();
65
70
                }
66
71
        }
67
72
 
68
 
        protected void setNextState( int nextState )
69
 
        {
70
 
                // set next state and enable button
71
 
                _nextState = nextState;
 
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
72
96
                ( (Button)findViewById( R.id.next ) ).setEnabled( true );
73
97
        }
74
98
 
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 );
87
 
                        finish();
88
 
                }
89
 
        }
90
 
 
91
99
        public SharedPreferences getSharedPreferences()
92
100
        {
93
101
                return super.getSharedPreferences( "ImportContacts", 0 );
94
102
        }
95
 
}
 
 
'\\ No newline at end of file'
 
103
}