/android/import-contacts

To get this branch, use:
bzr branch http://bzr.ed.am/android/import-contacts
6 by edam
- added GPL header comments to all files
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
1 by edam
Initial import
24
package org.waxworlds.importcontacts;
25
26
import android.app.Activity;
27
import android.content.Intent;
28
import android.content.SharedPreferences;
29
import android.os.Bundle;
30
import android.view.View;
31
import android.widget.Button;
32
33
public class WizardActivity extends Activity
34
{
35
	private int _nextState = 0;
36
37
	@Override
38
	protected void onCreate(Bundle savedInstanceState)
39
	{
40
		super.onCreate(savedInstanceState);
41
42
		// set up next button
43
		Button next = (Button)findViewById( R.id.next );
44
		next.setOnClickListener( new View.OnClickListener() {
45
			public void onClick( View view ) {
10 by edam
- made behaviour of next button overridable
46
				onNext();
1 by edam
Initial import
47
			}
48
		} );
49
50
		// set up back button
51
		Button back = (Button)findViewById( R.id.back );
52
		back.setOnClickListener( new View.OnClickListener() {
53
			public void onClick( View view ) {
54
				setResult( RESULT_OK );
55
				finish();
56
			}
57
		} );
58
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 );
65
		}
66
	}
67
10 by edam
- made behaviour of next button overridable
68
	protected void onNext()
69
	{
70
		switchToState( _nextState );
71
	}
72
1 by edam
Initial import
73
	protected void setNextState( int nextState )
74
	{
75
		// set next state and enable button
76
		_nextState = nextState;
77
		( (Button)findViewById( R.id.next ) ).setEnabled( true );
78
	}
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
96
	public SharedPreferences getSharedPreferences()
97
	{
98
		return super.getSharedPreferences( "ImportContacts", 0 );
99
	}
100
}