/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:51:59 UTC
  • Revision ID: tim@ed.am-20131020175159-xbei6qwxo8jxejdm
removed TODO from project

Show diffs side-by-side

added added

removed removed

1
 
package org.waxworlds.importcontacts;
 
1
/*
 
2
 * WizardActivity.java
 
3
 *
 
4
 * Copyright (C) 2009 Tim Marston <tim@ed.am>
 
5
 *
 
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
 
9
 *
 
10
 * This program is free software: you can redistribute it and/or modify
 
11
 * it under the terms of the GNU General Public License as published by
 
12
 * the Free Software Foundation, either version 3 of the License, or
 
13
 * (at your option) any later version.
 
14
 *
 
15
 * This program is distributed in the hope that it will be useful,
 
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 * GNU General Public License for more details.
 
19
 *
 
20
 * You should have received a copy of the GNU General Public License
 
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
22
 */
 
23
 
 
24
package am.ed.importcontacts;
2
25
 
3
26
import android.app.Activity;
4
27
import android.content.Intent;
5
28
import android.content.SharedPreferences;
 
29
import android.content.res.Configuration;
6
30
import android.os.Bundle;
7
31
import android.view.View;
8
32
import android.widget.Button;
9
33
 
10
34
public class WizardActivity extends Activity
11
35
{
12
 
        private int _nextState = 0;
 
36
        private Class< ? > _next_class;
13
37
 
14
38
        @Override
15
 
        protected void onCreate(Bundle savedInstanceState)
 
39
        protected void onCreate( Bundle saved_instance_state )
16
40
        {
17
 
                super.onCreate(savedInstanceState);
 
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 );
18
47
 
19
48
                // set up next button
20
49
                Button next = (Button)findViewById( R.id.next );
21
50
                next.setOnClickListener( new View.OnClickListener() {
22
51
                        public void onClick( View view ) {
23
 
                                switchToState( _nextState );
 
52
                                onNext();
24
53
                        }
25
54
                } );
26
55
 
28
57
                Button back = (Button)findViewById( R.id.back );
29
58
                back.setOnClickListener( new View.OnClickListener() {
30
59
                        public void onClick( View view ) {
31
 
                                setResult( RESULT_OK );
32
 
                                finish();
 
60
                                onBack();
33
61
                        }
34
62
                } );
 
63
        }
35
64
 
36
 
                // enable back button?
37
 
                Bundle extras = getIntent().getExtras();
38
 
                if( extras != null ) {
39
 
                        Boolean backstate = extras.getBoolean( "backstate" );
40
 
                        if( backstate != null )
41
 
                                ( (Button)findViewById( R.id.back ) ).setEnabled( true );
 
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 );
 
71
                        finish();
42
72
                }
43
73
        }
44
74
 
45
 
        protected void setNextState( int nextState )
46
 
        {
47
 
                // set next state and enable button
48
 
                _nextState = nextState;
 
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
49
98
                ( (Button)findViewById( R.id.next ) ).setEnabled( true );
50
99
        }
51
100
 
52
 
        private void switchToState( int newState )
53
 
        {
54
 
                if( newState != 0 )
55
 
                {
56
 
                        // create result data bundle
57
 
                        Bundle bundle = new Bundle();
58
 
                        bundle.putInt( "nextstate", newState );
59
 
 
60
 
                        // create response intent and finish
61
 
                        Intent i = new Intent();
62
 
                        i.putExtras( bundle );
63
 
                        setResult( RESULT_OK, i );
64
 
                        finish();
65
 
                }
66
 
        }
67
 
 
68
101
        public SharedPreferences getSharedPreferences()
69
102
        {
70
103
                return super.getSharedPreferences( "ImportContacts", 0 );
71
104
        }
72
 
}
 
 
'\\ No newline at end of file'
 
105
 
 
106
        @Override
 
107
        public void onConfigurationChanged( Configuration new_config ) {
 
108
                super.onConfigurationChanged( new_config );
 
109
        }
 
110
}