/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-07-04 14:44:48 UTC
  • Revision ID: edam@waxworlds.org-20100704144448-1m30v811opup20fs
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
- massively simplified the WizzardActivity class so it works propperly
- moved all code to org.waxworlds.edam
- added an "aborted" message when the importion is aborted
- simplified the 3 actions the worker thread can take when stopping (only 2 were actualy used) to "aborted" or "alldone"
- changed intro message to match website
- bugfix: don't blow up when the My Contacts group is missing

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 <edam@waxworlds.org>
 
5
 *
 
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
 
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 org.waxworlds.edam.importcontacts;
2
25
 
3
26
import android.app.Activity;
4
27
import android.content.Intent;
9
32
 
10
33
public class WizardActivity extends Activity
11
34
{
12
 
        private int _nextState = 0;
 
35
        private Class< ? > _nextClass;
13
36
 
14
37
        @Override
15
 
        protected void onCreate(Bundle savedInstanceState)
 
38
        protected void onCreate( Bundle savedInstanceState )
16
39
        {
17
 
                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 );
18
46
 
19
47
                // set up next button
20
48
                Button next = (Button)findViewById( R.id.next );
21
49
                next.setOnClickListener( new View.OnClickListener() {
22
50
                        public void onClick( View view ) {
23
 
                                switchToState( _nextState );
 
51
                                onNext();
24
52
                        }
25
53
                } );
26
54
 
28
56
                Button back = (Button)findViewById( R.id.back );
29
57
                back.setOnClickListener( new View.OnClickListener() {
30
58
                        public void onClick( View view ) {
31
 
                                setResult( RESULT_OK );
32
 
                                finish();
 
59
                                onBack();
33
60
                        }
34
61
                } );
 
62
        }
35
63
 
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 );
 
64
        @Override
 
65
        protected void  onActivityResult( int requestCode, int resultCode, Intent data )
 
66
        {
 
67
                if( resultCode == RESULT_OK ) {
 
68
                        setResult( RESULT_OK );
 
69
                        finish();
42
70
                }
43
71
        }
44
72
 
45
 
        protected void setNextState( int nextState )
46
 
        {
47
 
                // set next state and enable button
48
 
                _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
49
96
                ( (Button)findViewById( R.id.next ) ).setEnabled( true );
50
97
        }
51
98
 
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
99
        public SharedPreferences getSharedPreferences()
69
100
        {
70
101
                return super.getSharedPreferences( "ImportContacts", 0 );
71
102
        }
72
 
}
 
 
'\\ No newline at end of file'
 
103
}