bzr branch
http://bzr.ed.am/android/import-contacts
6
by edam
- added GPL header comments to all files |
1 |
/* |
13
by edam
- converted project to use Android 1.5 SDK |
2 |
* ConfigureVCF.java |
6
by edam
- added GPL header comments to all files |
3 |
* |
4 |
* Copyright (C) 2009 Tim Marston <edam@waxworlds.org> |
|
5 |
* |
|
6 |
* This file is part of the Import Contacts program (hereafter referred |
|
7 |
* to as "this program"). For more information, see |
|
8 |
* http://www.waxworlds.org/edam/software/android/import-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 |
||
14
by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one) |
24 |
package org.waxworlds.edam.importcontacts; |
1
by edam
Initial import |
25 |
|
19
by edam
- added file chooser |
26 |
import android.app.AlertDialog; |
27 |
import android.app.Dialog; |
|
28 |
import android.content.DialogInterface; |
|
1
by edam
Initial import |
29 |
import android.content.SharedPreferences; |
30 |
import android.os.Bundle; |
|
19
by edam
- added file chooser |
31 |
import android.view.LayoutInflater; |
32 |
import android.view.View; |
|
33 |
import android.widget.Button; |
|
34 |
import android.widget.TextView; |
|
1
by edam
Initial import |
35 |
|
11
by edam
- renamed ImportVCF class to ConfigureVCF |
36 |
public class ConfigureVCF extends WizardActivity |
1
by edam
Initial import |
37 |
{ |
19
by edam
- added file chooser |
38 |
public final static int DIALOG_FILEORDIR = 1; |
39 |
public final static int DIALOG_FILECHOOSER = 2; |
|
40 |
||
41 |
private FileChooser _file_chooser = null; |
|
42 |
||
43 |
// the save path |
|
44 |
private String _path; |
|
45 |
||
46 |
// was the dialog closed normally? |
|
47 |
private boolean _ok = false; |
|
48 |
||
49 |
// for the fileordir dialog, was file selected? |
|
50 |
boolean _ok_file; |
|
51 |
||
52 |
// reference to the dialog |
|
53 |
Dialog _dialog; |
|
54 |
||
1
by edam
Initial import |
55 |
@Override |
56 |
protected void onCreate( Bundle savedInstanceState ) |
|
57 |
{ |
|
11
by edam
- renamed ImportVCF class to ConfigureVCF |
58 |
setContentView( R.layout.configure_vcf ); |
1
by edam
Initial import |
59 |
super.onCreate( savedInstanceState ); |
60 |
||
14
by edam
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one) |
61 |
setNextActivity( Merge.class ); |
19
by edam
- added file chooser |
62 |
|
63 |
// create file chooser |
|
20
by edam
- fixed bug where a file chooser wouldn't know it's context when the context was used |
64 |
_file_chooser = new FileChooser( this ); |
19
by edam
- added file chooser |
65 |
String[] extensions = { "vcf" }; |
66 |
_file_chooser.setExtensions( extensions ); |
|
67 |
_file_chooser.setDismissListener( |
|
68 |
new DialogInterface.OnDismissListener() { |
|
69 |
public void onDismiss( DialogInterface dialog ) |
|
70 |
{ |
|
71 |
if( _file_chooser.getOk() ) { |
|
72 |
_path = _file_chooser.getPath(); |
|
73 |
updatePathButton(); |
|
74 |
} |
|
75 |
} |
|
76 |
} ); |
|
77 |
_file_chooser.setPathPrefix( "/sdcard" ); |
|
78 |
||
79 |
// set up browser button |
|
80 |
Button button = (Button)findViewById( R.id.path ); |
|
81 |
button.setOnClickListener( new View.OnClickListener() { |
|
82 |
public void onClick( View view ) { |
|
83 |
onBrowse(); |
|
84 |
} |
|
85 |
} ); |
|
86 |
} |
|
87 |
||
88 |
private void onBrowse() |
|
89 |
{ |
|
90 |
showDialog( DIALOG_FILEORDIR ); |
|
91 |
} |
|
92 |
||
93 |
private void showBrowseDialog() |
|
94 |
{ |
|
95 |
// set a path for this incantation |
|
96 |
_file_chooser.setMode( |
|
97 |
_ok_file? FileChooser.MODE_FILE : FileChooser.MODE_DIR ); |
|
98 |
_file_chooser.setPath( _path ); |
|
99 |
||
100 |
// show dialog |
|
101 |
showDialog( DIALOG_FILECHOOSER ); |
|
102 |
} |
|
103 |
||
104 |
protected void updatePathButton() |
|
105 |
{ |
|
106 |
Button path_button = (Button)findViewById( R.id.path ); |
|
107 |
path_button.setText( |
|
108 |
_file_chooser.prettyPrint( "/sdcard" + _path, true ) ); |
|
109 |
||
110 |
TextView location_text = (TextView)findViewById( R.id.location ); |
|
111 |
location_text.setText( getString( _path.endsWith( "/" )? |
|
112 |
R.string.vcf_location_dir : R.string.vcf_location_file ) ); |
|
1
by edam
Initial import |
113 |
} |
114 |
||
115 |
@Override |
|
116 |
protected void onPause() { |
|
117 |
super.onPause(); |
|
118 |
||
119 |
SharedPreferences.Editor editor = getSharedPreferences().edit(); |
|
120 |
||
19
by edam
- added file chooser |
121 |
editor.putString( "location", _path ); |
1
by edam
Initial import |
122 |
|
123 |
editor.commit(); |
|
124 |
} |
|
125 |
||
126 |
@Override |
|
127 |
protected void onResume() { |
|
128 |
super.onResume(); |
|
129 |
||
130 |
SharedPreferences prefs = getSharedPreferences(); |
|
131 |
||
132 |
// location |
|
19
by edam
- added file chooser |
133 |
_path = prefs.getString( "location", "/" ); |
134 |
updatePathButton(); |
|
135 |
} |
|
136 |
||
137 |
@Override |
|
138 |
protected Dialog onCreateDialog( int id ) |
|
139 |
{ |
|
140 |
Dialog ret = null; |
|
141 |
||
142 |
switch( id ) |
|
143 |
{ |
|
144 |
case DIALOG_FILEORDIR: |
|
145 |
// custom layout in an AlertDialog |
|
146 |
LayoutInflater factory = LayoutInflater.from( this ); |
|
147 |
final View dialogView = factory.inflate( |
|
148 |
R.layout.fileordir, null ); |
|
149 |
||
150 |
// wire up buttons |
|
151 |
( (Button)dialogView.findViewById( R.id.file ) ) |
|
152 |
.setOnClickListener( new View.OnClickListener() { |
|
153 |
public void onClick( View view ) { |
|
154 |
_ok = true; |
|
155 |
_ok_file = true; |
|
156 |
_dialog.dismiss(); |
|
157 |
} |
|
158 |
} ); |
|
159 |
( (Button)dialogView.findViewById( R.id.dir ) ) |
|
160 |
.setOnClickListener( new View.OnClickListener() { |
|
161 |
public void onClick( View view ) { |
|
162 |
_ok = true; |
|
163 |
_ok_file = false; |
|
164 |
_dialog.dismiss(); |
|
165 |
} |
|
166 |
} ); |
|
167 |
||
168 |
_dialog = ret = new AlertDialog.Builder( this ) |
|
169 |
.setTitle( "Do you want to?" ) |
|
170 |
.setView( dialogView ) |
|
171 |
.create(); |
|
172 |
ret.setOnDismissListener( |
|
173 |
new DialogInterface.OnDismissListener() { |
|
174 |
public void onDismiss( DialogInterface dialog ) |
|
175 |
{ |
|
176 |
if( _ok ) showBrowseDialog(); |
|
177 |
} |
|
178 |
} ); |
|
179 |
break; |
|
180 |
||
181 |
case DIALOG_FILECHOOSER: |
|
20
by edam
- fixed bug where a file chooser wouldn't know it's context when the context was used |
182 |
ret = _file_chooser.onCreateDialog(); |
19
by edam
- added file chooser |
183 |
break; |
184 |
} |
|
185 |
||
186 |
return ret; |
|
187 |
} |
|
188 |
||
189 |
@Override |
|
190 |
protected void onPrepareDialog( int id, Dialog dialog ) |
|
191 |
{ |
|
192 |
switch( id ) |
|
193 |
{ |
|
194 |
case DIALOG_FILEORDIR: |
|
195 |
_ok = false; |
|
196 |
break; |
|
197 |
||
198 |
case DIALOG_FILECHOOSER: |
|
199 |
_file_chooser.onPrepareDialog( this, dialog ); |
|
200 |
break; |
|
201 |
} |
|
202 |
||
203 |
super.onPrepareDialog( id, dialog ); |
|
1
by edam
Initial import |
204 |
} |
205 |
} |