2
2
* WizardActivity.java
4
* Copyright (C) 2009 Tim Marston <tim@ed.am>
4
* Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
6
6
* This file is part of the Import Contacts program (hereafter referred
7
7
* to as "this program"). For more information, see
8
* http://ed.am/dev/android/import-contacts
8
* http://www.waxworlds.org/edam/software/android/import-contacts
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/>.
24
package am.ed.importcontacts;
24
package org.waxworlds.importcontacts;
26
26
import android.app.Activity;
27
27
import android.content.Intent;
28
28
import android.content.SharedPreferences;
29
import android.content.res.Configuration;
30
29
import android.os.Bundle;
31
30
import android.view.View;
32
31
import android.widget.Button;
34
33
public class WizardActivity extends Activity
36
private Class< ? > _next_class;
35
private int _nextState;
36
private boolean _backEnabled;
39
protected void onCreate( Bundle saved_instance_state )
39
protected void onCreate(Bundle savedInstanceState)
41
super.onCreate( saved_instance_state );
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 );
41
super.onCreate(savedInstanceState);
45
// deal with saved state vs. defaults
46
if( savedInstanceState == null)
50
Bundle extras = getIntent().getExtras();
52
_backEnabled = extras.getBoolean( "backstate" );
56
_backEnabled = savedInstanceState.getBoolean( "_backEnabled" );
59
// enable/disable back button
60
( (Button)findViewById( R.id.back ) ).setEnabled( _backEnabled );
48
62
// set up next button
49
63
Button next = (Button)findViewById( R.id.next );
57
71
Button back = (Button)findViewById( R.id.back );
58
72
back.setOnClickListener( new View.OnClickListener() {
59
73
public void onClick( View view ) {
74
setResult( RESULT_OK );
66
protected void onActivityResult( int request_code, int result_code,
81
protected void onSaveInstanceState( Bundle outState ) {
82
super.onSaveInstanceState(outState);
83
outState.putBoolean( "_backEnabled", _backEnabled );
87
protected void onPause()
69
if( result_code == RESULT_OK ) {
70
setResult( RESULT_OK );
93
protected void onResume()
75
98
protected void onNext()
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 );
83
// start next activity
84
startActivityForResult( i, 0 );
87
protected void onBack()
89
setResult( RESULT_CANCELED );
93
protected void setNextActivity( Class< ? > cls )
100
switchToState( _nextState );
103
protected void setNextState( int nextState )
105
// set next state and enable button
106
_nextState = nextState;
98
107
( (Button)findViewById( R.id.next ) ).setEnabled( true );
110
private void switchToState( int newState )
114
// create result data bundle
115
Bundle bundle = new Bundle();
116
bundle.putInt( "nextstate", newState );
118
// create response intent and finish
119
Intent i = new Intent();
120
i.putExtras( bundle );
121
setResult( RESULT_OK, i );
101
126
public SharedPreferences getSharedPreferences()
103
128
return super.getSharedPreferences( "ImportContacts", 0 );
107
public void onConfigurationChanged( Configuration new_config ) {
108
super.onConfigurationChanged( new_config );
b'\\ No newline at end of file'