bzr branch
http://bzr.ed.am/android/export-contacts
1
by edam
- initial checkin |
1 |
/* |
2 |
* ConfigureVCF.java |
|
3 |
* |
|
4 |
* Copyright (C) 2010 Tim Marston <edam@waxworlds.org> |
|
5 |
* |
|
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 |
|
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 |
||
24 |
package org.waxworlds.edam.exportcontacts; |
|
25 |
||
2
by edam
- added file chooser |
26 |
import android.app.Dialog; |
27 |
import android.content.DialogInterface; |
|
1
by edam
- initial checkin |
28 |
import android.content.SharedPreferences; |
29 |
import android.os.Bundle; |
|
2
by edam
- added file chooser |
30 |
import android.view.View; |
31 |
import android.widget.Button; |
|
1
by edam
- initial checkin |
32 |
import android.widget.EditText; |
33 |
||
34 |
public class ConfigureVCF extends WizardActivity |
|
35 |
{ |
|
2
by edam
- added file chooser |
36 |
public final static int DIALOG_FILECHOOSER = 1; |
37 |
||
38 |
private FileChooser _file_chooser = null; |
|
39 |
||
40 |
// the save path |
|
41 |
private String _path; |
|
42 |
||
1
by edam
- initial checkin |
43 |
@Override |
44 |
protected void onCreate( Bundle savedInstanceState ) |
|
45 |
{ |
|
46 |
setContentView( R.layout.configure_vcf ); |
|
47 |
super.onCreate( savedInstanceState ); |
|
48 |
||
5
by edam
- added ContactReader interface |
49 |
setNextActivity( Doit.class ); |
2
by edam
- added file chooser |
50 |
|
3
by edam
- merged changes to file chooser from import contacts |
51 |
// create file chooser |
52 |
_file_chooser = new FileChooser( this ); |
|
53 |
_file_chooser.setMode( FileChooser.MODE_DIR ); |
|
5
by edam
- added ContactReader interface |
54 |
// String[] extensions = { "vcf" }; |
55 |
// _file_chooser.setExtensions( extensions ); |
|
3
by edam
- merged changes to file chooser from import contacts |
56 |
_file_chooser.setDismissListener( |
57 |
new DialogInterface.OnDismissListener() { |
|
58 |
public void onDismiss( DialogInterface dialog ) |
|
59 |
{ |
|
60 |
if( _file_chooser.getOk() ) { |
|
61 |
_path = _file_chooser.getPath(); |
|
62 |
updatePathButton(); |
|
63 |
} |
|
64 |
} |
|
65 |
} ); |
|
66 |
_file_chooser.setPathPrefix( "/sdcard" ); |
|
67 |
||
2
by edam
- added file chooser |
68 |
Button path_button = (Button)findViewById( R.id.path ); |
69 |
path_button.setOnClickListener( new View.OnClickListener() { |
|
70 |
public void onClick( View view ) { |
|
71 |
onBrowse(); |
|
72 |
} |
|
73 |
} ); |
|
1
by edam
- initial checkin |
74 |
} |
75 |
||
76 |
@Override |
|
77 |
protected void onPause() { |
|
78 |
super.onPause(); |
|
79 |
||
80 |
SharedPreferences.Editor editor = getSharedPreferences().edit(); |
|
81 |
||
2
by edam
- added file chooser |
82 |
// path and filename |
83 |
editor.putString( "path", _path ); |
|
84 |
EditText filename = (EditText)findViewById( R.id.filename ); |
|
85 |
editor.putString( "filename", filename.getText().toString() ); |
|
1
by edam
- initial checkin |
86 |
|
87 |
editor.commit(); |
|
88 |
} |
|
89 |
||
90 |
@Override |
|
91 |
protected void onResume() { |
|
92 |
super.onResume(); |
|
93 |
||
94 |
SharedPreferences prefs = getSharedPreferences(); |
|
95 |
||
2
by edam
- added file chooser |
96 |
/* // default filename |
97 |
Calendar now = Calendar.getInstance(); |
|
98 |
NumberFormat formatter = new DecimalFormat( "00" ); |
|
99 |
String date = now.get( Calendar.YEAR ) + "-" + |
|
100 |
formatter.format( now.get( Calendar.MONTH ) ) + "-" + |
|
101 |
formatter.format( now.get( Calendar.DAY_OF_MONTH ) ); |
|
102 |
*/ |
|
103 |
// path and filename |
|
104 |
_path = prefs.getString( "path", "/" ); |
|
105 |
updatePathButton(); |
|
106 |
EditText filename = (EditText)findViewById( R.id.filename ); |
|
107 |
filename.setText( prefs.getString( "filename", |
|
108 |
"android-contacts.vcf" ) ); |
|
109 |
} |
|
110 |
||
111 |
protected void updatePathButton() |
|
112 |
{ |
|
113 |
Button path_button = (Button)findViewById( R.id.path ); |
|
3
by edam
- merged changes to file chooser from import contacts |
114 |
path_button.setText( |
115 |
_file_chooser.prettyPrint( "/sdcard" + _path, true ) ); |
|
2
by edam
- added file chooser |
116 |
} |
117 |
||
118 |
protected void onBrowse() |
|
119 |
{ |
|
120 |
// get path |
|
121 |
Button path_button = (Button)findViewById( R.id.path ); |
|
122 |
||
123 |
// set a path for this incantation |
|
124 |
_file_chooser.setPath( path_button.getText().toString() ); |
|
125 |
||
126 |
showDialog( DIALOG_FILECHOOSER ); |
|
127 |
} |
|
128 |
||
129 |
@Override |
|
130 |
protected Dialog onCreateDialog( int id ) |
|
131 |
{ |
|
132 |
Dialog ret = null; |
|
133 |
||
134 |
switch( id ) |
|
135 |
{ |
|
136 |
case DIALOG_FILECHOOSER: |
|
3
by edam
- merged changes to file chooser from import contacts |
137 |
ret = _file_chooser.onCreateDialog(); |
138 |
break; |
|
2
by edam
- added file chooser |
139 |
} |
140 |
||
141 |
return ret; |
|
142 |
} |
|
143 |
||
144 |
@Override |
|
145 |
protected void onPrepareDialog( int id, Dialog dialog ) |
|
146 |
{ |
|
147 |
switch( id ) |
|
148 |
{ |
|
149 |
case DIALOG_FILECHOOSER: |
|
150 |
_file_chooser.onPrepareDialog( this, dialog ); |
|
151 |
break; |
|
152 |
} |
|
153 |
||
154 |
super.onPrepareDialog( id, dialog ); |
|
1
by edam
- initial checkin |
155 |
} |
156 |
} |