/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-28 19:55:17 UTC
  • Revision ID: edam@waxworlds.org-20090128195517-z1rmmys8tc8zvgqe
- made behaviour of next button overridable
- added abort button to merge prompt
- moved begin and close buttons to the next button, iverriding its behaviour
- added abort button to import and wired it up
- bugfix: tmp-progress bar didn't fill up when progress max was changed

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 );
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
58
 
64
 
        @Override
65
 
        protected void  onActivityResult( int requestCode, int resultCode, Intent data )
66
 
        {
67
 
                if( resultCode == RESULT_OK ) {
68
 
                        setResult( RESULT_OK );
69
 
                        finish();
 
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 );
70
65
                }
71
66
        }
72
67
 
73
68
        protected void onNext()
74
69
        {
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
 
70
                switchToState( _nextState );
 
71
        }
 
72
 
 
73
        protected void setNextState( int nextState )
 
74
        {
 
75
                // set next state and enable button
 
76
                _nextState = nextState;
96
77
                ( (Button)findViewById( R.id.next ) ).setEnabled( true );
97
78
        }
98
79
 
 
80
        private void switchToState( int newState )
 
81
        {
 
82
                if( newState != 0 )
 
83
                {
 
84
                        // create result data bundle
 
85
                        Bundle bundle = new Bundle();
 
86
                        bundle.putInt( "nextstate", newState );
 
87
 
 
88
                        // create response intent and finish
 
89
                        Intent i = new Intent();
 
90
                        i.putExtras( bundle );
 
91
                        setResult( RESULT_OK, i );
 
92
                        finish();
 
93
                }
 
94
        }
 
95
 
99
96
        public SharedPreferences getSharedPreferences()
100
97
        {
101
98
                return super.getSharedPreferences( "ImportContacts", 0 );
102
99
        }
103
 
}
 
100
}
 
 
'\\ No newline at end of file'