/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

1
1
/*
2
2
 * ConfigureVCF.java
3
3
 *
4
 
 * Copyright (C) 2010 Tim Marston <tim@ed.am>
 
4
 * Copyright (C) 2010 Tim Marston <edam@waxworlds.org>
5
5
 *
6
6
 * This file is part of the Export Contacts program (hereafter referred
7
 
 * to as "this program").  For more information, see
8
 
 * http://ed.am/dev/android/export-contacts
 
7
 * to as "this program"). For more information, see
 
8
 * http://www.waxworlds.org/edam/software/android/export-contacts
9
9
 *
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/>.
22
22
 */
23
23
 
24
 
package am.ed.exportcontacts;
25
 
 
26
 
import java.io.IOException;
27
 
 
28
 
import android.app.AlertDialog;
 
24
package org.waxworlds.edam.exportcontacts;
 
25
 
29
26
import android.app.Dialog;
30
27
import android.content.DialogInterface;
31
28
import android.content.SharedPreferences;
32
29
import android.os.Bundle;
33
 
import android.os.Environment;
34
30
import android.view.View;
35
31
import android.widget.Button;
36
32
import android.widget.EditText;
38
34
public class ConfigureVCF extends WizardActivity
39
35
{
40
36
        public final static int DIALOG_FILECHOOSER = 1;
41
 
        public final static int DIALOG_NOSDCARD = 2;
42
37
 
43
38
        private FileChooser _file_chooser = null;
44
39
 
45
 
        // the sdcard path prefix
46
 
        private String _sdcard_prefix;
47
 
 
48
40
        // the save path
49
41
        private String _path;
50
42
 
54
46
                setContentView( R.layout.configure_vcf );
55
47
                super.onCreate( savedInstanceState );
56
48
 
57
 
                setNextActivity( Doit.class );
58
 
 
59
 
                // get sdcard prefix
60
 
                _sdcard_prefix = getSdCardPathPrefix();
61
 
                if( _sdcard_prefix == null )
62
 
                        showDialog( DIALOG_NOSDCARD );
63
 
 
64
 
                // create file chooser
65
 
                _file_chooser = new FileChooser( this );
66
 
                _file_chooser.setMode( FileChooser.MODE_DIR );
67
 
//              String[] extensions = { "vcf" };
68
 
//              _file_chooser.setExtensions( extensions );
69
 
                _file_chooser.setDismissListener(
70
 
                        new DialogInterface.OnDismissListener() {
71
 
                                public void onDismiss( DialogInterface dialog )
72
 
                                {
73
 
                                        if( _file_chooser.getOk() ) {
74
 
                                                _path = _file_chooser.getPath();
75
 
                                                updatePathButton();
76
 
                                        }
77
 
                                }
78
 
                        } );
79
 
                if( _sdcard_prefix != null )
80
 
                        _file_chooser.setPathPrefix( _sdcard_prefix );
81
 
 
82
 
                // set up browser button
 
49
//              setNextActivity( Doit.class );
 
50
 
83
51
                Button path_button = (Button)findViewById( R.id.path );
84
52
                path_button.setOnClickListener( new View.OnClickListener() {
85
53
                        public void onClick( View view ) {
95
63
                SharedPreferences.Editor editor = getSharedPreferences().edit();
96
64
 
97
65
                // path and filename
98
 
                editor.putString( "path", _path );
 
66
                editor.putString(  "path", _path );
99
67
                EditText filename = (EditText)findViewById( R.id.filename );
100
68
                editor.putString( "filename", filename.getText().toString() );
101
69
 
123
91
                        "android-contacts.vcf" ) );
124
92
        }
125
93
 
126
 
        static protected String getSdCardPathPrefix()
127
 
        {
128
 
                // check sdcard status
129
 
                String state = Environment.getExternalStorageState();
130
 
                if( !Environment.MEDIA_MOUNTED.equals( state ) &&
131
 
                        !Environment.MEDIA_MOUNTED_READ_ONLY.equals( state ) )
132
 
                {
133
 
                        // no sdcard mounted
134
 
                        return null;
135
 
                }
136
 
 
137
 
                // get sdcard path
138
 
                String sdcard_path;
139
 
                try {
140
 
                        sdcard_path = Environment.getExternalStorageDirectory()
141
 
                                .getCanonicalPath();
142
 
                        if( sdcard_path.charAt( sdcard_path.length() - 1 ) == '/' )
143
 
                                sdcard_path =
144
 
                                        sdcard_path.substring( 0, sdcard_path.length() - 1 );
145
 
                }
146
 
                catch( IOException e ) {
147
 
                        sdcard_path = null;
148
 
                }
149
 
 
150
 
                return sdcard_path;
151
 
        }
152
 
 
153
94
        protected void updatePathButton()
154
95
        {
155
96
                Button path_button = (Button)findViewById( R.id.path );
156
 
                if( _sdcard_prefix != null )
157
 
                        path_button.setText(
158
 
                                _file_chooser.prettyPrint( _sdcard_prefix + _path, true ) );
 
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 );
159
103
        }
160
104
 
161
105
        protected void onBrowse()
163
107
                // get path
164
108
                Button path_button = (Button)findViewById( R.id.path );
165
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
 
166
126
                // set a path for this incantation
167
127
                _file_chooser.setPath( path_button.getText().toString() );
168
128
 
177
137
                switch( id )
178
138
                {
179
139
                case DIALOG_FILECHOOSER:
180
 
                        ret = _file_chooser.onCreateDialog();
181
 
                        break;
182
 
 
183
 
                case DIALOG_NOSDCARD:
184
 
                        ret = new AlertDialog.Builder( this )
185
 
                        .setIcon( R.drawable.alert_dialog_icon )
186
 
                        .setTitle( R.string.error_title )
187
 
                        .setMessage( R.string.error_nosdcard )
188
 
                        .setPositiveButton( R.string.error_ok,
189
 
                                new DialogInterface.OnClickListener() {
190
 
                                        public void onClick(DialogInterface dialog,
191
 
                                                int whichButton)
192
 
                                        {
193
 
                                                // close the whole app!
194
 
                                                setResult( RESULT_OK );
195
 
                                                finish();
196
 
                                        }
197
 
                                } )
198
 
                        .create();
199
 
                        break;
 
140
                        ret = _file_chooser.onCreateDialog( this );
200
141
                }
201
142
 
202
143
                return ret;