/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/ImportContacts.java

  • Committer: edam
  • Date: 2009-01-10 16:14:11 UTC
  • Revision ID: edam@waxworlds.org-20090110161411-4d17l9hs9d6j277q
Initial import

Show diffs side-by-side

added added

removed removed

 
1
package org.waxworlds.importcontacts;
 
2
 
 
3
import java.util.Stack;
 
4
 
 
5
import android.app.Activity;
 
6
import android.content.Intent;
 
7
import android.os.Bundle;
 
8
 
 
9
public class ImportContacts extends Activity
 
10
{
 
11
        public static final int STATE_NONE = 0;
 
12
        public static final int STATE_IMPORT_VCF = 1;
 
13
        public static final int STATE_MERGE = 2;
 
14
        public static final int STATE_DOIT = 3;
 
15
 
 
16
        private Stack< Integer > _stateStack;
 
17
 
 
18
        /** Called when the activity is first created. */
 
19
        @Override
 
20
    public void onCreate(Bundle savedInstanceState)
 
21
    {
 
22
                super.onCreate(savedInstanceState);
 
23
 
 
24
                _stateStack = new Stack< Integer >();
 
25
 
 
26
                startState( STATE_IMPORT_VCF );
 
27
    }
 
28
 
 
29
        @Override
 
30
        protected void onActivityResult(int requestCode, int resultCode, Intent data)
 
31
        {
 
32
                super.onActivityResult(requestCode, resultCode, data);
 
33
 
 
34
                // quit?
 
35
                if( resultCode == RESULT_CANCELED ) {
 
36
                        finish();
 
37
                }
 
38
                else {
 
39
                        int newState = STATE_NONE;
 
40
                        if( data != null ) {
 
41
                                Bundle extras = data.getExtras();
 
42
                                if( extras != null ) {
 
43
                                        Integer tmp = extras.getInt( "nextstate" );
 
44
                                        if( tmp != null ) {
 
45
                                                newState = tmp.intValue();
 
46
                                        }
 
47
                                }
 
48
                        }
 
49
                        startState( newState );
 
50
                }
 
51
        }
 
52
 
 
53
        private void startState( int newState )
 
54
        {
 
55
                if( newState == STATE_NONE )
 
56
                {
 
57
                        // we're going back, so pop top state off stack
 
58
                        _stateStack.pop();
 
59
                        newState = ( (Integer)_stateStack.peek() ).intValue();
 
60
                }
 
61
                else
 
62
                {
 
63
                        // push new state on state
 
64
                        _stateStack.push( new Integer( newState ) );
 
65
                }
 
66
 
 
67
                // figure out the class
 
68
                Class cls = null;
 
69
                switch( newState ) {
 
70
                case STATE_IMPORT_VCF: cls = ImportVCF.class; break;
 
71
                case STATE_MERGE: cls = Merge.class; break;
 
72
                case STATE_DOIT: cls = Doit.class; break;
 
73
                }
 
74
 
 
75
                // start activity
 
76
                Intent i = new Intent( this, cls );
 
77
                if( _stateStack.size() > 1 ) i.putExtra( "backstate", true );
 
78
                startActivityForResult( i, 0 );
 
79
        }
 
80
}
 
 
'\\ No newline at end of file'