/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;
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< ? > _nextClass;
 
35
        private int _nextState = 0;
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
 
                // 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 );
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
58
 
65
 
        @Override
66
 
        protected void onActivityResult( int requestCode, int resultCode,
67
 
                Intent data )
68
 
        {
69
 
                if( resultCode == RESULT_OK ) {
70
 
                        setResult( RESULT_OK );
71
 
                        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 );
72
65
                }
73
66
        }
74
67
 
75
68
        protected void onNext()
76
69
        {
77
 
                // create bundle with back enabled state
78
 
                Bundle bundle = new Bundle();
79
 
                bundle.putBoolean( "back-enabled", true );
80
 
                Intent i = new Intent( this, _nextClass );
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
 
                _nextClass = cls;
96
 
 
97
 
                // 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;
98
77
                ( (Button)findViewById( R.id.next ) ).setEnabled( true );
99
78
        }
100
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
 
101
96
        public SharedPreferences getSharedPreferences()
102
97
        {
103
98
                return super.getSharedPreferences( "ImportContacts", 0 );
104
99
        }
105
 
 
106
 
        @Override
107
 
        public void onConfigurationChanged( Configuration newConfig ) {
108
 
                super.onConfigurationChanged( newConfig );
109
 
        }
110
 
}
 
100
}
 
 
'\\ No newline at end of file'