/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-07-04 14:54:18 UTC
  • Revision ID: edam@waxworlds.org-20100704145418-vcpya2sxsop0dlrq
- initial checkin
- copied intro and basic vcf-configure activities from import-contacts
- copied WizzardActivity class from import-contacts

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