/android/import-contacts

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

« back to all changes in this revision

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

  • Committer: edam
  • Date: 2010-12-12 11:25:00 UTC
  • Revision ID: edam@waxworlds.org-20101212112500-ml96qi57t0epia2s
- import phone numbers even when they have no specified type (default to mobile)
- allow all keypad chars in a phone number so that network commands can be prefixed to them

Show diffs side-by-side

added added

removed removed

1
1
/*
2
2
 * ConfigureVCF.java
3
3
 *
4
 
 * Copyright (C) 2009 Tim Marston <tim@ed.am>
 
4
 * Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
5
5
 *
6
6
 * This file is part of the Import Contacts program (hereafter referred
7
 
 * to as "this program").  For more information, see
8
 
 * http://ed.am/dev/android/import-contacts
 
7
 * to as "this program"). For more information, see
 
8
 * http://www.waxworlds.org/edam/software/android/import-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.importcontacts;
25
 
 
26
 
import java.io.IOException;
 
24
package org.waxworlds.edam.importcontacts;
27
25
 
28
26
import android.app.AlertDialog;
29
27
import android.app.Dialog;
30
28
import android.content.DialogInterface;
31
29
import android.content.SharedPreferences;
32
30
import android.os.Bundle;
33
 
import android.os.Environment;
34
31
import android.view.LayoutInflater;
35
32
import android.view.View;
36
33
import android.widget.Button;
40
37
{
41
38
        public final static int DIALOG_FILEORDIR = 1;
42
39
        public final static int DIALOG_FILECHOOSER = 2;
43
 
        public final static int DIALOG_NOSDCARD = 3;
44
40
 
45
41
        private FileChooser _file_chooser = null;
46
42
 
47
 
        // the sdcard path prefix
48
 
        private String _sdcard_prefix;
49
 
 
50
43
        // the save path
51
44
        private String _path;
52
45
 
60
53
        Dialog _dialog;
61
54
 
62
55
        @Override
63
 
        protected void onCreate( Bundle saved_instance_state )
 
56
        protected void onCreate( Bundle savedInstanceState )
64
57
        {
65
58
                setContentView( R.layout.configure_vcf );
66
 
                super.onCreate( saved_instance_state );
 
59
                super.onCreate( savedInstanceState );
67
60
 
68
61
                setNextActivity( Merge.class );
69
62
 
70
 
                // get sdcard prefix
71
 
                _sdcard_prefix = getSdCardPathPrefix();
72
 
                if( _sdcard_prefix == null )
73
 
                        showDialog( DIALOG_NOSDCARD );
74
 
 
75
63
                // create file chooser
76
64
                _file_chooser = new FileChooser( this );
77
65
                String[] extensions = { "vcf" };
86
74
                                        }
87
75
                                }
88
76
                        } );
89
 
                if( _sdcard_prefix != null )
90
 
                        _file_chooser.setPathPrefix( _sdcard_prefix );
 
77
                _file_chooser.setPathPrefix( "/sdcard" );
91
78
 
92
79
                // set up browser button
93
80
                Button button = (Button)findViewById( R.id.path );
114
101
                showDialog( DIALOG_FILECHOOSER );
115
102
        }
116
103
 
117
 
        static protected String getSdCardPathPrefix()
118
 
        {
119
 
                // check sdcard status
120
 
                String state = Environment.getExternalStorageState();
121
 
                if( !Environment.MEDIA_MOUNTED.equals( state ) &&
122
 
                        !Environment.MEDIA_MOUNTED_READ_ONLY.equals( state ) )
123
 
                {
124
 
                        // no sdcard mounted
125
 
                        return null;
126
 
                }
127
 
 
128
 
                // get sdcard path
129
 
                String sdcard_path;
130
 
                try {
131
 
                        sdcard_path = Environment.getExternalStorageDirectory()
132
 
                                .getCanonicalPath();
133
 
                        if( sdcard_path.charAt( sdcard_path.length() - 1 ) == '/' )
134
 
                                sdcard_path =
135
 
                                        sdcard_path.substring( 0, sdcard_path.length() - 1 );
136
 
                }
137
 
                catch( IOException e ) {
138
 
                        sdcard_path = null;
139
 
                }
140
 
 
141
 
                return sdcard_path;
142
 
        }
143
 
 
144
104
        protected void updatePathButton()
145
105
        {
146
106
                Button path_button = (Button)findViewById( R.id.path );
147
 
                if( _sdcard_prefix != null )
148
 
                        path_button.setText(
149
 
                                _file_chooser.prettyPrint( _sdcard_prefix + _path, true ) );
 
107
                path_button.setText(
 
108
                        _file_chooser.prettyPrint( "/sdcard" + _path, true ) );
150
109
 
151
110
                TextView location_text = (TextView)findViewById( R.id.location );
152
111
                location_text.setText( getString( _path.endsWith( "/" )?
222
181
                case DIALOG_FILECHOOSER:
223
182
                        ret = _file_chooser.onCreateDialog();
224
183
                        break;
225
 
 
226
 
                case DIALOG_NOSDCARD:
227
 
                        ret = new AlertDialog.Builder( this )
228
 
                        .setIcon( R.drawable.alert_dialog_icon )
229
 
                        .setTitle( R.string.error_title )
230
 
                        .setMessage( R.string.error_nosdcard )
231
 
                        .setPositiveButton( R.string.error_ok,
232
 
                                new DialogInterface.OnClickListener() {
233
 
                                        public void onClick(DialogInterface dialog,
234
 
                                                int whichButton)
235
 
                                        {
236
 
                                                // close the whole app!
237
 
                                                setResult( RESULT_OK );
238
 
                                                finish();
239
 
                                        }
240
 
                                } )
241
 
                        .create();
242
 
                        break;
243
184
                }
244
185
 
245
186
                return ret;