21
21
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24
package org.waxworlds.edam.importcontacts;
24
package org.waxworlds.importcontacts;
26
import android.app.AlertDialog;
27
import android.app.Dialog;
28
import android.content.DialogInterface;
29
26
import android.content.SharedPreferences;
30
27
import android.os.Bundle;
31
import android.view.LayoutInflater;
32
import android.view.View;
33
import android.widget.Button;
34
import android.widget.TextView;
28
import android.widget.EditText;
36
30
public class ConfigureVCF extends WizardActivity
38
public final static int DIALOG_FILEORDIR = 1;
39
public final static int DIALOG_FILECHOOSER = 2;
41
private FileChooser _file_chooser = null;
46
// was the dialog closed normally?
47
private boolean _ok = false;
49
// for the fileordir dialog, was file selected?
52
// reference to the dialog
56
33
protected void onCreate( Bundle savedInstanceState )
58
35
setContentView( R.layout.configure_vcf );
59
36
super.onCreate( savedInstanceState );
61
setNextActivity( Merge.class );
63
// create file chooser
64
_file_chooser = new FileChooser();
65
String[] extensions = { "vcf" };
66
_file_chooser.setExtensions( extensions );
67
_file_chooser.setDismissListener(
68
new DialogInterface.OnDismissListener() {
69
public void onDismiss( DialogInterface dialog )
71
if( _file_chooser.getOk() ) {
72
_path = _file_chooser.getPath();
77
_file_chooser.setPathPrefix( "/sdcard" );
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 ) {
88
private void onBrowse()
90
showDialog( DIALOG_FILEORDIR );
93
private void showBrowseDialog()
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 );
101
showDialog( DIALOG_FILECHOOSER );
104
protected void updatePathButton()
106
Button path_button = (Button)findViewById( R.id.path );
108
_file_chooser.prettyPrint( "/sdcard" + _path, true ) );
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 ) );
38
setNextState( ImportContacts.STATE_MERGE );
130
58
SharedPreferences prefs = getSharedPreferences();
133
_path = prefs.getString( "location", "/" );
138
protected Dialog onCreateDialog( int id )
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 );
151
( (Button)dialogView.findViewById( R.id.file ) )
152
.setOnClickListener( new View.OnClickListener() {
153
public void onClick( View view ) {
159
( (Button)dialogView.findViewById( R.id.dir ) )
160
.setOnClickListener( new View.OnClickListener() {
161
public void onClick( View view ) {
168
_dialog = ret = new AlertDialog.Builder( this )
169
.setTitle( "Do you want to?" )
170
.setView( dialogView )
172
ret.setOnDismissListener(
173
new DialogInterface.OnDismissListener() {
174
public void onDismiss( DialogInterface dialog )
176
if( _ok ) showBrowseDialog();
181
case DIALOG_FILECHOOSER:
182
ret = _file_chooser.onCreateDialog( this );
190
protected void onPrepareDialog( int id, Dialog dialog )
194
case DIALOG_FILEORDIR:
198
case DIALOG_FILECHOOSER:
199
_file_chooser.onPrepareDialog( this, dialog );
203
super.onPrepareDialog( id, dialog );
61
EditText location = (EditText)findViewById( R.id.location );
62
location.setText( prefs.getString( "location", "/sdcard/contacts" ) );