/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-22 18:56:17 UTC
  • Revision ID: edam@waxworlds.org-20101022185617-6p6ivjqt28avwlzo
- added file chooser
- changed directory edit box for a directory "browse" button
- wired file chooser in to configure vcf page
- fixed intro
- made app debuggable
- added licence and changelog

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
                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
                } );
39
57
        }
40
58
 
41
59
        @Override
44
62
 
45
63
                SharedPreferences.Editor editor = getSharedPreferences().edit();
46
64
 
47
 
                // location
48
 
                EditText location = (EditText)findViewById( R.id.location );
49
 
                editor.putString( "location", location.getText().toString() );
 
65
                // path and filename
 
66
                editor.putString(  "path", _path );
 
67
                EditText filename = (EditText)findViewById( R.id.filename );
 
68
                editor.putString( "filename", filename.getText().toString() );
50
69
 
51
70
                editor.commit();
52
71
        }
57
76
 
58
77
                SharedPreferences prefs = getSharedPreferences();
59
78
 
60
 
                // location
61
 
                EditText location = (EditText)findViewById( R.id.location );
62
 
                location.setText( prefs.getString( "location", "/sdcard/contacts.vcf" ) );
 
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 );
63
157
        }
64
158
}