4
* Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
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
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.
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.
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/>.
24
package org.waxworlds.edam.importcontacts;
26
import java.io.IOException;
28
import android.app.AlertDialog;
29
import android.app.Dialog;
30
import android.content.DialogInterface;
1
package org.waxworlds.importcontacts;
31
3
import android.content.SharedPreferences;
32
4
import android.os.Bundle;
33
import android.os.Environment;
34
import android.view.LayoutInflater;
35
import android.view.View;
36
import android.widget.Button;
37
import android.widget.TextView;
5
import android.widget.EditText;
39
public class ConfigureVCF extends WizardActivity
7
public class ImportVCF extends WizardActivity
41
public final static int DIALOG_FILEORDIR = 1;
42
public final static int DIALOG_FILECHOOSER = 2;
43
public final static int DIALOG_NOSDCARD = 3;
45
private FileChooser _file_chooser = null;
47
// the sdcard path prefix
48
private String _sdcard_prefix;
53
// was the dialog closed normally?
54
private boolean _ok = false;
56
// for the fileordir dialog, was file selected?
59
// reference to the dialog
63
protected void onCreate( Bundle saved_instance_state )
65
setContentView( R.layout.configure_vcf );
66
super.onCreate( saved_instance_state );
68
setNextActivity( Merge.class );
71
_sdcard_prefix = getSdCardPathPrefix();
72
if( _sdcard_prefix == null )
73
showDialog( DIALOG_NOSDCARD );
75
// create file chooser
76
_file_chooser = new FileChooser( this );
77
String[] extensions = { "vcf" };
78
_file_chooser.setExtensions( extensions );
79
_file_chooser.setDismissListener(
80
new DialogInterface.OnDismissListener() {
81
public void onDismiss( DialogInterface dialog )
83
if( _file_chooser.getOk() ) {
84
_path = _file_chooser.getPath();
89
if( _sdcard_prefix != null )
90
_file_chooser.setPathPrefix( _sdcard_prefix );
92
// set up browser button
93
Button button = (Button)findViewById( R.id.path );
94
button.setOnClickListener( new View.OnClickListener() {
95
public void onClick( View view ) {
101
private void onBrowse()
103
showDialog( DIALOG_FILEORDIR );
106
private void showBrowseDialog()
108
// set a path for this incantation
109
_file_chooser.setMode(
110
_ok_file? FileChooser.MODE_FILE : FileChooser.MODE_DIR );
111
_file_chooser.setPath( _path );
114
showDialog( DIALOG_FILECHOOSER );
117
static protected String getSdCardPathPrefix()
119
// check sdcard status
120
String state = Environment.getExternalStorageState();
121
if( !Environment.MEDIA_MOUNTED.equals( state ) &&
122
!Environment.MEDIA_MOUNTED_READ_ONLY.equals( state ) )
131
sdcard_path = Environment.getExternalStorageDirectory()
133
if( sdcard_path.charAt( sdcard_path.length() - 1 ) == '/' )
135
sdcard_path.substring( 0, sdcard_path.length() - 1 );
137
catch( IOException e ) {
144
protected void updatePathButton()
146
Button path_button = (Button)findViewById( R.id.path );
147
if( _sdcard_prefix != null )
149
_file_chooser.prettyPrint( _sdcard_prefix + _path, true ) );
151
TextView location_text = (TextView)findViewById( R.id.location );
152
location_text.setText( getString( _path.endsWith( "/" )?
153
R.string.vcf_location_dir : R.string.vcf_location_file ) );
10
protected void onCreate( Bundle savedInstanceState )
12
setContentView( R.layout.import_vcf );
13
super.onCreate( savedInstanceState );
15
setNextState( ImportContacts.STATE_MERGE );
171
35
SharedPreferences prefs = getSharedPreferences();
174
_path = prefs.getString( "location", "/" );
179
protected Dialog onCreateDialog( int id )
185
case DIALOG_FILEORDIR:
186
// custom layout in an AlertDialog
187
LayoutInflater factory = LayoutInflater.from( this );
188
final View dialogView = factory.inflate(
189
R.layout.fileordir, null );
192
( (Button)dialogView.findViewById( R.id.file ) )
193
.setOnClickListener( new View.OnClickListener() {
194
public void onClick( View view ) {
200
( (Button)dialogView.findViewById( R.id.dir ) )
201
.setOnClickListener( new View.OnClickListener() {
202
public void onClick( View view ) {
209
_dialog = ret = new AlertDialog.Builder( this )
210
.setTitle( "Do you want to?" )
211
.setView( dialogView )
213
ret.setOnDismissListener(
214
new DialogInterface.OnDismissListener() {
215
public void onDismiss( DialogInterface dialog )
217
if( _ok ) showBrowseDialog();
222
case DIALOG_FILECHOOSER:
223
ret = _file_chooser.onCreateDialog();
226
case DIALOG_NOSDCARD:
227
ret = new AlertDialog.Builder( this )
228
.setIcon( R.drawable.alert_dialog_icon )
229
.setTitle( R.string.error_title )
230
.setMessage( R.string.error_nosdcard )
231
.setPositiveButton( R.string.error_ok,
232
new DialogInterface.OnClickListener() {
233
public void onClick(DialogInterface dialog,
236
// close the whole app!
237
setResult( RESULT_OK );
249
protected void onPrepareDialog( int id, Dialog dialog )
253
case DIALOG_FILEORDIR:
257
case DIALOG_FILECHOOSER:
258
_file_chooser.onPrepareDialog( this, dialog );
262
super.onPrepareDialog( id, dialog );
38
EditText location = (EditText)findViewById( R.id.location );
39
location.setText( prefs.getString( "location", "/sdcard/contacts" ) );