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 |
||
45 |
// the save path |
|
46 |
private String _path; |
|
47 |
||
1
by edam
- initial checkin |
48 |
@Override |
49 |
protected void onCreate( Bundle savedInstanceState ) |
|
50 |
{ |
|
51 |
setContentView( R.layout.configure_vcf ); |
|
52 |
super.onCreate( savedInstanceState ); |
|
53 |
||
5
by edam
- added ContactReader interface |
54 |
setNextActivity( Doit.class ); |
2
by edam
- added file chooser |
55 |
|
13
by edam
fixed bad error_ok string and added check for no sd card |
56 |
// get sdcard prefix |
57 |
String sdcard_prefix = getSdCardPathPrefix(); |
|
58 |
if( sdcard_prefix == null ) |
|
59 |
showDialog( DIALOG_NOSDCARD ); |
|
60 |
||
3
by edam
- merged changes to file chooser from import contacts |
61 |
// create file chooser |
62 |
_file_chooser = new FileChooser( this ); |
|
63 |
_file_chooser.setMode( FileChooser.MODE_DIR ); |
|
5
by edam
- added ContactReader interface |
64 |
// String[] extensions = { "vcf" }; |
65 |
// _file_chooser.setExtensions( extensions ); |
|
3
by edam
- merged changes to file chooser from import contacts |
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" ); |
|
77 |
||
2
by edam
- added file chooser |
78 |
Button path_button = (Button)findViewById( R.id.path ); |
79 |
path_button.setOnClickListener( new View.OnClickListener() { |
|
80 |
public void onClick( View view ) { |
|
81 |
onBrowse(); |
|
82 |
} |
|
83 |
} ); |
|
1
by edam
- initial checkin |
84 |
} |
85 |
||
86 |
@Override |
|
87 |
protected void onPause() { |
|
88 |
super.onPause(); |
|
89 |
||
90 |
SharedPreferences.Editor editor = getSharedPreferences().edit(); |
|
91 |
||
2
by edam
- added file chooser |
92 |
// path and filename |
93 |
editor.putString( "path", _path ); |
|
94 |
EditText filename = (EditText)findViewById( R.id.filename ); |
|
95 |
editor.putString( "filename", filename.getText().toString() ); |
|
1
by edam
- initial checkin |
96 |
|
97 |
editor.commit(); |
|
98 |
} |
|
99 |
||
100 |
@Override |
|
101 |
protected void onResume() { |
|
102 |
super.onResume(); |
|
103 |
||
104 |
SharedPreferences prefs = getSharedPreferences(); |
|
105 |
||
2
by edam
- added file chooser |
106 |
/* // default filename |
107 |
Calendar now = Calendar.getInstance(); |
|
108 |
NumberFormat formatter = new DecimalFormat( "00" ); |
|
109 |
String date = now.get( Calendar.YEAR ) + "-" + |
|
110 |
formatter.format( now.get( Calendar.MONTH ) ) + "-" + |
|
111 |
formatter.format( now.get( Calendar.DAY_OF_MONTH ) ); |
|
112 |
*/ |
|
113 |
// path and filename |
|
114 |
_path = prefs.getString( "path", "/" ); |
|
115 |
updatePathButton(); |
|
116 |
EditText filename = (EditText)findViewById( R.id.filename ); |
|
117 |
filename.setText( prefs.getString( "filename", |
|
118 |
"android-contacts.vcf" ) ); |
|
119 |
} |
|
120 |
||
13
by edam
fixed bad error_ok string and added check for no sd card |
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 |
||
2
by edam
- added file chooser |
148 |
protected void updatePathButton() |
149 |
{ |
|
150 |
Button path_button = (Button)findViewById( R.id.path ); |
|
3
by edam
- merged changes to file chooser from import contacts |
151 |
path_button.setText( |
152 |
_file_chooser.prettyPrint( "/sdcard" + _path, true ) ); |
|
2
by edam
- added file chooser |
153 |
} |
154 |
||
155 |
protected void onBrowse() |
|
156 |
{ |
|
157 |
// get path |
|
158 |
Button path_button = (Button)findViewById( R.id.path ); |
|
159 |
||
160 |
// set a path for this incantation |
|
161 |
_file_chooser.setPath( path_button.getText().toString() ); |
|
162 |
||
163 |
showDialog( DIALOG_FILECHOOSER ); |
|
164 |
} |
|
165 |
||
166 |
@Override |
|
167 |
protected Dialog onCreateDialog( int id ) |
|
168 |
{ |
|
169 |
Dialog ret = null; |
|
170 |
||
171 |
switch( id ) |
|
172 |
{ |
|
173 |
case DIALOG_FILECHOOSER: |
|
3
by edam
- merged changes to file chooser from import contacts |
174 |
ret = _file_chooser.onCreateDialog(); |
175 |
break; |
|
13
by edam
fixed bad error_ok string and added check for no sd card |
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; |
|
2
by edam
- added file chooser |
194 |
} |
195 |
||
196 |
return ret; |
|
197 |
} |
|
198 |
||
199 |
@Override |
|
200 |
protected void onPrepareDialog( int id, Dialog dialog ) |
|
201 |
{ |
|
202 |
switch( id ) |
|
203 |
{ |
|
204 |
case DIALOG_FILECHOOSER: |
|
205 |
_file_chooser.onPrepareDialog( this, dialog ); |
|
206 |
break; |
|
207 |
} |
|
208 |
||
209 |
super.onPrepareDialog( id, dialog ); |
|
1
by edam
- initial checkin |
210 |
} |
211 |
} |