4
* Copyright (C) 2010 Tim Marston <edam@waxworlds.org>
4
* Copyright (C) 2010 Tim Marston <tim@ed.am>
6
6
* This file is part of the Export Contacts program (hereafter referred
7
7
* to as "this program"). For more information, see
8
* http://www.waxworlds.org/edam/software/android/export-contacts
8
* http://ed.am/dev/android/export-contacts
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/>.
24
package org.waxworlds.edam.exportcontacts;
24
package am.ed.exportcontacts;
26
import java.io.IOException;
28
import android.app.AlertDialog;
29
import android.app.Dialog;
30
import android.content.DialogInterface;
26
31
import android.content.SharedPreferences;
27
32
import android.os.Bundle;
33
import android.os.Environment;
34
import android.view.View;
35
import android.widget.Button;
28
36
import android.widget.EditText;
30
38
public class ConfigureVCF extends WizardActivity
40
public final static int DIALOG_FILECHOOSER = 1;
41
public final static int DIALOG_NOSDCARD = 2;
43
private FileChooser _file_chooser = null;
33
49
protected void onCreate( Bundle savedInstanceState )
35
51
setContentView( R.layout.configure_vcf );
36
52
super.onCreate( savedInstanceState );
38
// setNextActivity( Doit.class );
54
setNextActivity( Doit.class );
57
String sdcard_prefix = getSdCardPathPrefix();
58
if( sdcard_prefix == null )
59
showDialog( DIALOG_NOSDCARD );
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 )
70
if( _file_chooser.getOk() ) {
71
_path = _file_chooser.getPath();
76
_file_chooser.setPathPrefix( "/sdcard" );
78
Button path_button = (Button)findViewById( R.id.path );
79
path_button.setOnClickListener( new View.OnClickListener() {
80
public void onClick( View view ) {
45
90
SharedPreferences.Editor editor = getSharedPreferences().edit();
48
EditText location = (EditText)findViewById( R.id.location );
49
editor.putString( "location", location.getText().toString() );
93
editor.putString( "path", _path );
94
EditText filename = (EditText)findViewById( R.id.filename );
95
editor.putString( "filename", filename.getText().toString() );
58
104
SharedPreferences prefs = getSharedPreferences();
61
EditText location = (EditText)findViewById( R.id.location );
62
location.setText( prefs.getString( "location", "/sdcard/contacts.vcf" ) );
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 ) );
114
_path = prefs.getString( "path", "/" );
116
EditText filename = (EditText)findViewById( R.id.filename );
117
filename.setText( prefs.getString( "filename",
118
"android-contacts.vcf" ) );
121
static protected String getSdCardPathPrefix()
123
// check sdcard status
124
String state = Environment.getExternalStorageState();
125
if( !Environment.MEDIA_MOUNTED.equals( state ) &&
126
!Environment.MEDIA_MOUNTED_READ_ONLY.equals( state ) )
135
sdcard_path = Environment.getExternalStorageDirectory()
137
if( sdcard_path.charAt( sdcard_path.length() - 1 ) == '/' )
139
sdcard_path.substring( 0, sdcard_path.length() - 1 );
141
catch( IOException e ) {
148
protected void updatePathButton()
150
Button path_button = (Button)findViewById( R.id.path );
152
_file_chooser.prettyPrint( "/sdcard" + _path, true ) );
155
protected void onBrowse()
158
Button path_button = (Button)findViewById( R.id.path );
160
// set a path for this incantation
161
_file_chooser.setPath( path_button.getText().toString() );
163
showDialog( DIALOG_FILECHOOSER );
167
protected Dialog onCreateDialog( int id )
173
case DIALOG_FILECHOOSER:
174
ret = _file_chooser.onCreateDialog();
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,
187
// close the whole app!
188
setResult( RESULT_OK );
200
protected void onPrepareDialog( int id, Dialog dialog )
204
case DIALOG_FILECHOOSER:
205
_file_chooser.onPrepareDialog( this, dialog );
209
super.onPrepareDialog( id, dialog );