1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
/*
* ConfigureVCF.java
*
* Copyright (C) 2010 Tim Marston <tim@ed.am>
*
* This file is part of the Export Contacts program (hereafter referred
* to as "this program"). For more information, see
* http://ed.am/dev/android/export-contacts
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package am.ed.exportcontacts;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class ConfigureVCF extends WizardActivity
{
public final static int DIALOG_FILECHOOSER = 1;
private FileChooser _file_chooser = null;
// the save path
private String _path;
@Override
protected void onCreate( Bundle savedInstanceState )
{
setContentView( R.layout.configure_vcf );
super.onCreate( savedInstanceState );
setNextActivity( Doit.class );
// create file chooser
_file_chooser = new FileChooser( this );
_file_chooser.setMode( FileChooser.MODE_DIR );
// String[] extensions = { "vcf" };
// _file_chooser.setExtensions( extensions );
_file_chooser.setDismissListener(
new DialogInterface.OnDismissListener() {
public void onDismiss( DialogInterface dialog )
{
if( _file_chooser.getOk() ) {
_path = _file_chooser.getPath();
updatePathButton();
}
}
} );
_file_chooser.setPathPrefix( "/sdcard" );
Button path_button = (Button)findViewById( R.id.path );
path_button.setOnClickListener( new View.OnClickListener() {
public void onClick( View view ) {
onBrowse();
}
} );
}
@Override
protected void onPause() {
super.onPause();
SharedPreferences.Editor editor = getSharedPreferences().edit();
// path and filename
editor.putString( "path", _path );
EditText filename = (EditText)findViewById( R.id.filename );
editor.putString( "filename", filename.getText().toString() );
editor.commit();
}
@Override
protected void onResume() {
super.onResume();
SharedPreferences prefs = getSharedPreferences();
/* // default filename
Calendar now = Calendar.getInstance();
NumberFormat formatter = new DecimalFormat( "00" );
String date = now.get( Calendar.YEAR ) + "-" +
formatter.format( now.get( Calendar.MONTH ) ) + "-" +
formatter.format( now.get( Calendar.DAY_OF_MONTH ) );
*/
// path and filename
_path = prefs.getString( "path", "/" );
updatePathButton();
EditText filename = (EditText)findViewById( R.id.filename );
filename.setText( prefs.getString( "filename",
"android-contacts.vcf" ) );
}
protected void updatePathButton()
{
Button path_button = (Button)findViewById( R.id.path );
path_button.setText(
_file_chooser.prettyPrint( "/sdcard" + _path, true ) );
}
protected void onBrowse()
{
// get path
Button path_button = (Button)findViewById( R.id.path );
// set a path for this incantation
_file_chooser.setPath( path_button.getText().toString() );
showDialog( DIALOG_FILECHOOSER );
}
@Override
protected Dialog onCreateDialog( int id )
{
Dialog ret = null;
switch( id )
{
case DIALOG_FILECHOOSER:
ret = _file_chooser.onCreateDialog();
break;
}
return ret;
}
@Override
protected void onPrepareDialog( int id, Dialog dialog )
{
switch( id )
{
case DIALOG_FILECHOOSER:
_file_chooser.onPrepareDialog( this, dialog );
break;
}
super.onPrepareDialog( id, dialog );
}
}
|