/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: Tim Marston
  • Date: 2014-03-01 18:03:39 UTC
  • Revision ID: tim@ed.am-20140301180339-rmfh8x7wys2inc65
new family pic

Show diffs side-by-side

added added

removed removed

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