/android/export-contacts

To get this branch, use:
bzr branch http://bzr.ed.am/android/export-contacts

« back to all changes in this revision

Viewing changes to src/org/waxworlds/edam/exportcontacts/ConfigureVCF.java

  • Committer: edam
  • Date: 2010-10-30 09:56:26 UTC
  • Revision ID: edam@waxworlds.org-20101030095626-cavsscp5jukannwl
- fixed bug in file chooser where "ok" button could remain disabled

Show diffs side-by-side

added added

removed removed

23
23
 
24
24
package org.waxworlds.edam.exportcontacts;
25
25
 
 
26
import android.app.Dialog;
 
27
import android.content.DialogInterface;
26
28
import android.content.SharedPreferences;
27
29
import android.os.Bundle;
 
30
import android.view.View;
 
31
import android.widget.Button;
28
32
import android.widget.EditText;
29
33
 
30
34
public class ConfigureVCF extends WizardActivity
31
35
{
 
36
        public final static int DIALOG_FILECHOOSER = 1;
 
37
 
 
38
        private FileChooser _file_chooser = null;
 
39
 
 
40
        // the save path
 
41
        private String _path;
 
42
 
32
43
        @Override
33
44
        protected void onCreate( Bundle savedInstanceState )
34
45
        {
36
47
                super.onCreate( savedInstanceState );
37
48
 
38
49
//              setNextActivity( Doit.class );
 
50
 
 
51
                // create file chooser
 
52
                _file_chooser = new FileChooser( this );
 
53
                _file_chooser.setMode( FileChooser.MODE_DIR );
 
54
                String[] extensions = { "vcf" };
 
55
                _file_chooser.setExtensions( extensions );
 
56
                _file_chooser.setDismissListener(
 
57
                        new DialogInterface.OnDismissListener() {
 
58
                                public void onDismiss( DialogInterface dialog )
 
59
                                {
 
60
                                        if( _file_chooser.getOk() ) {
 
61
                                                _path = _file_chooser.getPath();
 
62
                                                updatePathButton();
 
63
                                        }
 
64
                                }
 
65
                        } );
 
66
                _file_chooser.setPathPrefix( "/sdcard" );
 
67
 
 
68
                Button path_button = (Button)findViewById( R.id.path );
 
69
                path_button.setOnClickListener( new View.OnClickListener() {
 
70
                        public void onClick( View view ) {
 
71
                                onBrowse();
 
72
                        }
 
73
                } );
39
74
        }
40
75
 
41
76
        @Override
44
79
 
45
80
                SharedPreferences.Editor editor = getSharedPreferences().edit();
46
81
 
47
 
                // location
48
 
                EditText location = (EditText)findViewById( R.id.location );
49
 
                editor.putString( "location", location.getText().toString() );
 
82
                // path and filename
 
83
                editor.putString(  "path", _path );
 
84
                EditText filename = (EditText)findViewById( R.id.filename );
 
85
                editor.putString( "filename", filename.getText().toString() );
50
86
 
51
87
                editor.commit();
52
88
        }
57
93
 
58
94
                SharedPreferences prefs = getSharedPreferences();
59
95
 
60
 
                // location
61
 
                EditText location = (EditText)findViewById( R.id.location );
62
 
                location.setText( prefs.getString( "location", "/sdcard/contacts.vcf" ) );
 
96
/*              // default filename
 
97
                Calendar now = Calendar.getInstance();
 
98
                NumberFormat formatter = new DecimalFormat( "00" );
 
99
                String date = now.get( Calendar.YEAR ) + "-" +
 
100
                        formatter.format( now.get( Calendar.MONTH ) ) + "-" +
 
101
                        formatter.format( now.get( Calendar.DAY_OF_MONTH ) );
 
102
*/
 
103
                // path and filename
 
104
                _path = prefs.getString( "path", "/" );
 
105
                updatePathButton();
 
106
                EditText filename = (EditText)findViewById( R.id.filename );
 
107
                filename.setText( prefs.getString( "filename",
 
108
                        "android-contacts.vcf" ) );
 
109
        }
 
110
 
 
111
        protected void updatePathButton()
 
112
        {
 
113
                Button path_button = (Button)findViewById( R.id.path );
 
114
                path_button.setText(
 
115
                        _file_chooser.prettyPrint( "/sdcard" + _path, true ) );
 
116
        }
 
117
 
 
118
        protected void onBrowse()
 
119
        {
 
120
                // get path
 
121
                Button path_button = (Button)findViewById( R.id.path );
 
122
 
 
123
                // set a path for this incantation
 
124
                _file_chooser.setPath( path_button.getText().toString() );
 
125
 
 
126
                showDialog( DIALOG_FILECHOOSER );
 
127
        }
 
128
 
 
129
        @Override
 
130
        protected Dialog onCreateDialog( int id )
 
131
        {
 
132
                Dialog ret = null;
 
133
 
 
134
                switch( id )
 
135
                {
 
136
                case DIALOG_FILECHOOSER:
 
137
                        ret = _file_chooser.onCreateDialog();
 
138
                        break;
 
139
                }
 
140
 
 
141
                return ret;
 
142
        }
 
143
 
 
144
        @Override
 
145
        protected void onPrepareDialog( int id, Dialog dialog )
 
146
        {
 
147
                switch( id )
 
148
                {
 
149
                case DIALOG_FILECHOOSER:
 
150
                        _file_chooser.onPrepareDialog( this, dialog );
 
151
                        break;
 
152
                }
 
153
 
 
154
                super.onPrepareDialog( id, dialog );
63
155
        }
64
156
}