/android/export-contacts

To get this branch, use:
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
49
//		setNextActivity( Doit.class );
2 by edam
- added file chooser
50
51
		Button path_button = (Button)findViewById( R.id.path );
52
		path_button.setOnClickListener( new View.OnClickListener() {
53
			public void onClick( View view ) {
54
				onBrowse();
55
			}
56
		} );
1 by edam
- initial checkin
57
	}
58
59
	@Override
60
	protected void onPause() {
61
		super.onPause();
62
63
		SharedPreferences.Editor editor = getSharedPreferences().edit();
64
2 by edam
- added file chooser
65
		// path and filename
66
		editor.putString(  "path", _path );
67
		EditText filename = (EditText)findViewById( R.id.filename );
68
		editor.putString( "filename", filename.getText().toString() );
1 by edam
- initial checkin
69
70
		editor.commit();
71
	}
72
73
	@Override
74
	protected void onResume() {
75
		super.onResume();
76
77
		SharedPreferences prefs = getSharedPreferences();
78
2 by edam
- added file chooser
79
/*		// default filename
80
		Calendar now = Calendar.getInstance();
81
		NumberFormat formatter = new DecimalFormat( "00" );
82
		String date = now.get( Calendar.YEAR ) + "-" +
83
			formatter.format( now.get( Calendar.MONTH ) ) + "-" +
84
			formatter.format( now.get( Calendar.DAY_OF_MONTH ) );
85
*/
86
		// path and filename
87
		_path = prefs.getString( "path", "/" );
88
		updatePathButton();
89
		EditText filename = (EditText)findViewById( R.id.filename );
90
		filename.setText( prefs.getString( "filename",
91
			"android-contacts.vcf" ) );
92
	}
93
94
	protected void updatePathButton()
95
	{
96
		Button path_button = (Button)findViewById( R.id.path );
97
		path_button.setText( FileChooser.prettyPrint(
98
			getApplicationContext(), "/sdcard" + _path, false ) );
99
		path_button.setCompoundDrawablesWithIntrinsicBounds(
100
			getResources().getDrawable(
101
				FileChooser.pathIcon( "/sdcard" + _path ) ), null,
102
				getResources().getDrawable( R.drawable.browse ), null );
103
	}
104
105
	protected void onBrowse()
106
	{
107
		// get path
108
		Button path_button = (Button)findViewById( R.id.path );
109
110
		// create file chooser
111
		if( _file_chooser == null ) {
112
			_file_chooser = new FileChooser( FileChooser.MODE_DIR );
113
			String[] extensions = { "vcf" };
114
			_file_chooser.setExtensions( extensions );
115
			_file_chooser.setDismissListener(
116
				new DialogInterface.OnDismissListener() {
117
					public void onDismiss( DialogInterface dialog )
118
					{
119
						_path = _file_chooser.getPath();
120
						updatePathButton();
121
					}
122
				} );
123
			_file_chooser.setPathPrefix( "/sdcard" );
124
		}
125
126
		// set a path for this incantation
127
		_file_chooser.setPath( path_button.getText().toString() );
128
129
		showDialog( DIALOG_FILECHOOSER );
130
	}
131
132
	@Override
133
	protected Dialog onCreateDialog( int id )
134
	{
135
		Dialog ret = null;
136
137
		switch( id )
138
		{
139
		case DIALOG_FILECHOOSER:
140
			ret = _file_chooser.onCreateDialog( this );
141
		}
142
143
		return ret;
144
	}
145
146
	@Override
147
	protected void onPrepareDialog( int id, Dialog dialog )
148
	{
149
		switch( id )
150
		{
151
		case DIALOG_FILECHOOSER:
152
			_file_chooser.onPrepareDialog( this, dialog );
153
			break;
154
		}
155
156
		super.onPrepareDialog( id, dialog );
1 by edam
- initial checkin
157
	}
158
}