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

  • Committer: Tim Marston
  • Date: 2013-10-20 17:52:21 UTC
  • Revision ID: tim@ed.am-20131020175221-7f9i6dhl55xz39ui
eclipse file changes (who knows!)

Show diffs side-by-side

added added

removed removed

1
1
/*
2
2
 * WizardActivity.java
3
3
 *
4
 
 * Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
 
4
 * Copyright (C) 2009 Tim Marston <tim@ed.am>
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://www.waxworlds.org/edam/software/android/import-contacts
 
7
 * to as "this program").  For more information, see
 
8
 * http://ed.am/dev/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 org.waxworlds.importcontacts;
 
24
package am.ed.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;
29
30
import android.os.Bundle;
30
31
import android.view.View;
31
32
import android.widget.Button;
32
33
 
33
34
public class WizardActivity extends Activity
34
35
{
35
 
        private int _nextState;
36
 
        private boolean _backEnabled;
 
36
        private Class< ? > _next_class;
37
37
 
38
38
        @Override
39
 
        protected void onCreate(Bundle savedInstanceState)
 
39
        protected void onCreate( Bundle saved_instance_state )
40
40
        {
41
 
                super.onCreate(savedInstanceState);
42
 
 
43
 
                _nextState = 0;
44
 
 
45
 
                // deal with saved state vs. defaults
46
 
                if( savedInstanceState == null)
47
 
                {
48
 
                        _backEnabled = false;
49
 
 
50
 
                        Bundle extras = getIntent().getExtras();
51
 
                        if( extras != null )
52
 
                                _backEnabled = extras.getBoolean( "backstate" );
53
 
                }
54
 
                else
55
 
                {
56
 
                        _backEnabled = savedInstanceState.getBoolean( "_backEnabled" );
57
 
                }
58
 
 
59
 
                // enable/disable back button
60
 
                ( (Button)findViewById( R.id.back ) ).setEnabled( _backEnabled );
 
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 );
61
47
 
62
48
                // set up next button
63
49
                Button next = (Button)findViewById( R.id.next );
71
57
                Button back = (Button)findViewById( R.id.back );
72
58
                back.setOnClickListener( new View.OnClickListener() {
73
59
                        public void onClick( View view ) {
74
 
                                setResult( RESULT_OK );
75
 
                                finish();
 
60
                                onBack();
76
61
                        }
77
62
                } );
78
63
        }
79
64
 
80
65
        @Override
81
 
        protected void onSaveInstanceState( Bundle outState ) {
82
 
                super.onSaveInstanceState(outState);
83
 
                outState.putBoolean( "_backEnabled", _backEnabled );
84
 
        }
85
 
/*
86
 
        @Override
87
 
        protected void onPause()
 
66
        protected void onActivityResult( int request_code, int result_code,
 
67
                Intent data )
88
68
        {
89
 
                super.onPause();
 
69
                if( result_code == RESULT_OK ) {
 
70
                        setResult( RESULT_OK );
 
71
                        finish();
 
72
                }
90
73
        }
91
74
 
92
 
        @Override
93
 
        protected void onResume()
94
 
        {
95
 
                super.onResume();
96
 
        }
97
 
*/
98
75
        protected void onNext()
99
76
        {
100
 
                switchToState( _nextState );
101
 
        }
102
 
 
103
 
        protected void setNextState( int nextState )
104
 
        {
105
 
                // set next state and enable button
106
 
                _nextState = nextState;
 
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
107
98
                ( (Button)findViewById( R.id.next ) ).setEnabled( true );
108
99
        }
109
100
 
110
 
        private void switchToState( int newState )
111
 
        {
112
 
                if( newState != 0 )
113
 
                {
114
 
                        // create result data bundle
115
 
                        Bundle bundle = new Bundle();
116
 
                        bundle.putInt( "nextstate", newState );
117
 
 
118
 
                        // create response intent and finish
119
 
                        Intent i = new Intent();
120
 
                        i.putExtras( bundle );
121
 
                        setResult( RESULT_OK, i );
122
 
                        finish();
123
 
                }
124
 
        }
125
 
 
126
101
        public SharedPreferences getSharedPreferences()
127
102
        {
128
103
                return super.getSharedPreferences( "ImportContacts", 0 );
129
104
        }
 
105
 
 
106
        @Override
 
107
        public void onConfigurationChanged( Configuration new_config ) {
 
108
                super.onConfigurationChanged( new_config );
 
109
        }
130
110
}