/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/am/ed/exportcontacts/ConfigureVCF.java

  • Committer: edam
  • Date: 2012-04-24 11:29:44 UTC
  • Revision ID: tim@ed.am-20120424112944-6fic236bul6r9cqi
changed all the URLs to ed.am, including copyrights, package names and project
site

Show diffs side-by-side

added added

removed removed

4
4
 * Copyright (C) 2010 Tim Marston <tim@ed.am>
5
5
 *
6
6
 * This file is part of the Export Contacts program (hereafter referred
7
 
 * to as "this program").  For more information, see
 
7
 * to as "this program"). For more information, see
8
8
 * http://ed.am/dev/android/export-contacts
9
9
 *
10
10
 * This program is free software: you can redistribute it and/or modify
23
23
 
24
24
package am.ed.exportcontacts;
25
25
 
26
 
import java.io.IOException;
27
 
 
28
 
import android.app.AlertDialog;
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
 
56
48
 
57
49
                setNextActivity( Doit.class );
58
50
 
59
 
                // get sdcard prefix
60
 
                _sdcard_prefix = getSdCardPathPrefix();
61
 
                if( _sdcard_prefix == null )
62
 
                        showDialog( DIALOG_NOSDCARD );
63
 
 
64
51
                // create file chooser
65
52
                _file_chooser = new FileChooser( this );
66
53
                _file_chooser.setMode( FileChooser.MODE_DIR );
76
63
                                        }
77
64
                                }
78
65
                        } );
79
 
                if( _sdcard_prefix != null )
80
 
                        _file_chooser.setPathPrefix( _sdcard_prefix );
 
66
                _file_chooser.setPathPrefix( "/sdcard" );
81
67
 
82
 
                // set up browser button
83
68
                Button path_button = (Button)findViewById( R.id.path );
84
69
                path_button.setOnClickListener( new View.OnClickListener() {
85
70
                        public void onClick( View view ) {
95
80
                SharedPreferences.Editor editor = getSharedPreferences().edit();
96
81
 
97
82
                // path and filename
98
 
                editor.putString( "path", _path );
 
83
                editor.putString(  "path", _path );
99
84
                EditText filename = (EditText)findViewById( R.id.filename );
100
85
                editor.putString( "filename", filename.getText().toString() );
101
86
 
123
108
                        "android-contacts.vcf" ) );
124
109
        }
125
110
 
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
111
        protected void updatePathButton()
154
112
        {
155
113
                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 ) );
 
114
                path_button.setText(
 
115
                        _file_chooser.prettyPrint( "/sdcard" + _path, true ) );
159
116
        }
160
117
 
161
118
        protected void onBrowse()
179
136
                case DIALOG_FILECHOOSER:
180
137
                        ret = _file_chooser.onCreateDialog();
181
138
                        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;
200
139
                }
201
140
 
202
141
                return ret;