bzr branch
http://bzr.ed.am/android/export-contacts
1
by edam
- initial checkin |
1 |
/* |
2 |
* ConfigureVCF.java |
|
3 |
* |
|
12
by edam
changed all the URLs to ed.am, including copyrights, package names and project |
4 |
* Copyright (C) 2010 Tim Marston <tim@ed.am> |
1
by edam
- initial checkin |
5 |
* |
6 |
* This file is part of the Export Contacts program (hereafter referred |
|
30
by Tim Marston
minor style tweaks |
7 |
* to as "this program"). For more information, see |
12
by edam
changed all the URLs to ed.am, including copyrights, package names and project |
8 |
* http://ed.am/dev/android/export-contacts |
1
by edam
- initial checkin |
9 |
* |
10 |
* This program is free software: you can redistribute it and/or modify |
|
11 |
* it under the terms of the GNU General Public License as published by |
|
12 |
* the Free Software Foundation, either version 3 of the License, or |
|
13 |
* (at your option) any later version. |
|
14 |
* |
|
15 |
* This program is distributed in the hope that it will be useful, |
|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 |
* GNU General Public License for more details. |
|
19 |
* |
|
20 |
* You should have received a copy of the GNU General Public License |
|
21 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
22 |
*/ |
|
23 |
||
12
by edam
changed all the URLs to ed.am, including copyrights, package names and project |
24 |
package am.ed.exportcontacts; |
1
by edam
- initial checkin |
25 |
|
13
by edam
fixed bad error_ok string and added check for no sd card |
26 |
import java.io.IOException; |
27 |
||
28 |
import android.app.AlertDialog; |
|
2
by edam
- added file chooser |
29 |
import android.app.Dialog; |
30 |
import android.content.DialogInterface; |
|
1
by edam
- initial checkin |
31 |
import android.content.SharedPreferences; |
32 |
import android.os.Bundle; |
|
13
by edam
fixed bad error_ok string and added check for no sd card |
33 |
import android.os.Environment; |
2
by edam
- added file chooser |
34 |
import android.view.View; |
35 |
import android.widget.Button; |
|
1
by edam
- initial checkin |
36 |
import android.widget.EditText; |
37 |
||
38 |
public class ConfigureVCF extends WizardActivity |
|
39 |
{ |
|
2
by edam
- added file chooser |
40 |
public final static int DIALOG_FILECHOOSER = 1; |
13
by edam
fixed bad error_ok string and added check for no sd card |
41 |
public final static int DIALOG_NOSDCARD = 2; |
2
by edam
- added file chooser |
42 |
|
43 |
private FileChooser _file_chooser = null; |
|
44 |
||
40
by Tim Marston
removed hard-coded path to sdcard |
45 |
// the sdcard path prefix |
46 |
private String _sdcard_prefix; |
|
47 |
||
2
by edam
- added file chooser |
48 |
// the save path |
49 |
private String _path; |
|
50 |
||
1
by edam
- initial checkin |
51 |
@Override |
52 |
protected void onCreate( Bundle savedInstanceState ) |
|
53 |
{ |
|
54 |
setContentView( R.layout.configure_vcf ); |
|
55 |
super.onCreate( savedInstanceState ); |
|
56 |
||
5
by edam
- added ContactReader interface |
57 |
setNextActivity( Doit.class ); |
2
by edam
- added file chooser |
58 |
|
13
by edam
fixed bad error_ok string and added check for no sd card |
59 |
// get sdcard prefix |
40
by Tim Marston
removed hard-coded path to sdcard |
60 |
_sdcard_prefix = getSdCardPathPrefix(); |
61 |
if( _sdcard_prefix == null ) |
|
13
by edam
fixed bad error_ok string and added check for no sd card |
62 |
showDialog( DIALOG_NOSDCARD ); |
63 |
||
3
by edam
- merged changes to file chooser from import contacts |
64 |
// create file chooser |
65 |
_file_chooser = new FileChooser( this ); |
|
66 |
_file_chooser.setMode( FileChooser.MODE_DIR ); |
|
5
by edam
- added ContactReader interface |
67 |
// String[] extensions = { "vcf" }; |
68 |
// _file_chooser.setExtensions( extensions ); |
|
3
by edam
- merged changes to file chooser from import contacts |
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 |
} ); |
|
40
by Tim Marston
removed hard-coded path to sdcard |
79 |
if( _sdcard_prefix != null ) |
80 |
_file_chooser.setPathPrefix( _sdcard_prefix ); |
|
3
by edam
- merged changes to file chooser from import contacts |
81 |
|
40
by Tim Marston
removed hard-coded path to sdcard |
82 |
// set up browser button |
2
by edam
- added file chooser |
83 |
Button path_button = (Button)findViewById( R.id.path ); |
84 |
path_button.setOnClickListener( new View.OnClickListener() { |
|
85 |
public void onClick( View view ) { |
|
86 |
onBrowse(); |
|
87 |
} |
|
88 |
} ); |
|
1
by edam
- initial checkin |
89 |
} |
90 |
||
91 |
@Override |
|
92 |
protected void onPause() { |
|
93 |
super.onPause(); |
|
94 |
||
95 |
SharedPreferences.Editor editor = getSharedPreferences().edit(); |
|
96 |
||
2
by edam
- added file chooser |
97 |
// path and filename |
40
by Tim Marston
removed hard-coded path to sdcard |
98 |
editor.putString( "path", _path ); |
2
by edam
- added file chooser |
99 |
EditText filename = (EditText)findViewById( R.id.filename ); |
100 |
editor.putString( "filename", filename.getText().toString() ); |
|
1
by edam
- initial checkin |
101 |
|
102 |
editor.commit(); |
|
103 |
} |
|
104 |
||
105 |
@Override |
|
106 |
protected void onResume() { |
|
107 |
super.onResume(); |
|
108 |
||
109 |
SharedPreferences prefs = getSharedPreferences(); |
|
110 |
||
2
by edam
- added file chooser |
111 |
/* // default filename |
112 |
Calendar now = Calendar.getInstance(); |
|
113 |
NumberFormat formatter = new DecimalFormat( "00" ); |
|
114 |
String date = now.get( Calendar.YEAR ) + "-" + |
|
115 |
formatter.format( now.get( Calendar.MONTH ) ) + "-" + |
|
116 |
formatter.format( now.get( Calendar.DAY_OF_MONTH ) ); |
|
117 |
*/ |
|
118 |
// path and filename |
|
119 |
_path = prefs.getString( "path", "/" ); |
|
120 |
updatePathButton(); |
|
121 |
EditText filename = (EditText)findViewById( R.id.filename ); |
|
122 |
filename.setText( prefs.getString( "filename", |
|
123 |
"android-contacts.vcf" ) ); |
|
124 |
} |
|
125 |
||
13
by edam
fixed bad error_ok string and added check for no sd card |
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 |
||
2
by edam
- added file chooser |
153 |
protected void updatePathButton() |
154 |
{ |
|
155 |
Button path_button = (Button)findViewById( R.id.path ); |
|
40
by Tim Marston
removed hard-coded path to sdcard |
156 |
if( _sdcard_prefix != null ) |
157 |
path_button.setText( |
|
158 |
_file_chooser.prettyPrint( _sdcard_prefix + _path, true ) ); |
|
2
by edam
- added file chooser |
159 |
} |
160 |
||
161 |
protected void onBrowse() |
|
162 |
{ |
|
163 |
// get path |
|
164 |
Button path_button = (Button)findViewById( R.id.path ); |
|
165 |
||
166 |
// set a path for this incantation |
|
167 |
_file_chooser.setPath( path_button.getText().toString() ); |
|
168 |
||
169 |
showDialog( DIALOG_FILECHOOSER ); |
|
170 |
} |
|
171 |
||
172 |
@Override |
|
173 |
protected Dialog onCreateDialog( int id ) |
|
174 |
{ |
|
175 |
Dialog ret = null; |
|
176 |
||
177 |
switch( id ) |
|
178 |
{ |
|
179 |
case DIALOG_FILECHOOSER: |
|
3
by edam
- merged changes to file chooser from import contacts |
180 |
ret = _file_chooser.onCreateDialog(); |
181 |
break; |
|
13
by edam
fixed bad error_ok string and added check for no sd card |
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; |
|
2
by edam
- added file chooser |
200 |
} |
201 |
||
202 |
return ret; |
|
203 |
} |
|
204 |
||
205 |
@Override |
|
206 |
protected void onPrepareDialog( int id, Dialog dialog ) |
|
207 |
{ |
|
208 |
switch( id ) |
|
209 |
{ |
|
210 |
case DIALOG_FILECHOOSER: |
|
211 |
_file_chooser.onPrepareDialog( this, dialog ); |
|
212 |
break; |
|
213 |
} |
|
214 |
||
215 |
super.onPrepareDialog( id, dialog ); |
|
1
by edam
- initial checkin |
216 |
} |
217 |
} |