1
0
mirror of https://github.com/moparisthebest/SSLDroid synced 2024-11-27 03:12:18 -05:00

Implemented file chooser for picking the PKCS12 file for the tunnel

Signed-off-by: Balint Kovacs <blint@blint.hu>
This commit is contained in:
Balint Kovacs 2011-04-20 21:45:56 +02:00
parent 8a28244471
commit 79c357576c
6 changed files with 68 additions and 3 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -10,7 +10,7 @@
android:paddingRight="10dip" android:gravity="right|center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText android:id="@+id/name" android:hint="Internal Webserver"
<EditText android:id="@+id/name" android:hint="Company mail server"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:singleLine="true" android:layout_weight="1" />
</TableRow>

View File

@ -14,4 +14,6 @@
<string name="start_service">Start service</string>
<string name="no_tunnels">No tunnels configured yet</string>
<string name="menu_delete">Delete tunnel</string>
<string name="pkcsfile_pick">Pick a PKCS12 file from SD card</string>
<string name="alert_sdcard_absent">No SD card present, please insert one to continue</string>
</resources>

View File

@ -1,9 +1,18 @@
package hu.blint.ssldroid;
import java.io.File;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.Button;
@ -35,6 +44,14 @@ public class SSLDroidTunnelDetails extends Activity {
remoteport = (EditText) findViewById(R.id.remoteport);
pkcsfile = (EditText) findViewById(R.id.pkcsfile);
pkcspass = (EditText) findViewById(R.id.pkcspass);
Button pickFile = (Button) findViewById(R.id.pickFile);
pickFile.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
pickFileSimple();
}
});
rowId = null;
Bundle extras = getIntent().getExtras();
@ -75,6 +92,50 @@ public class SSLDroidTunnelDetails extends Activity {
});
}
//pick a file from /sdcard, courtesy of ConnectBot
private void pickFileSimple() {
// build list of all files in sdcard root
final File sdcard = Environment.getExternalStorageDirectory();
Log.d("SSLDroid", "SD Card location: "+sdcard.toString());
// Don't show a dialog if the SD card is completely absent.
final String state = Environment.getExternalStorageState();
if (!Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)
&& !Environment.MEDIA_MOUNTED.equals(state)) {
new AlertDialog.Builder(SSLDroidTunnelDetails.this)
.setMessage(R.string.alert_sdcard_absent)
.setNegativeButton(android.R.string.cancel, null).create().show();
return;
}
List<String> names = new LinkedList<String>();
{
File[] files = sdcard.listFiles();
if (files != null) {
for(File file : sdcard.listFiles()) {
if(file.isDirectory()) continue;
names.add(file.getName());
}
}
}
Collections.sort(names);
final String[] namesList = names.toArray(new String[] {});
Log.d("SSLDroid", "Gathered file names: "+names.toString());
// prompt user to select any file from the sdcard root
new AlertDialog.Builder(SSLDroidTunnelDetails.this)
.setTitle(R.string.pkcsfile_pick)
.setItems(namesList, new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
String name = namesList[arg1];
pkcsfile.setText(sdcard+"/"+name);
}
})
.setNegativeButton(android.R.string.cancel, null).create().show();
}
private void populateFields() {
if (rowId != null) {
Cursor Tunnel = dbHelper.fetchTunnel(rowId);
@ -147,12 +208,14 @@ public class SSLDroidTunnelDetails extends Activity {
}
if (rowId == null) {
long id = dbHelper.createTunnel(sName, sLocalport, sRemotehost, sRemoteport, sPkcsfile, sPkcspass);
long id = dbHelper.createTunnel(sName, sLocalport, sRemotehost,
sRemoteport, sPkcsfile, sPkcspass);
if (id > 0) {
rowId = id;
}
} else {
dbHelper.updateTunnel(rowId, sName, sLocalport, sRemotehost, sRemoteport, sPkcsfile, sPkcspass);
dbHelper.updateTunnel(rowId, sName, sLocalport, sRemotehost, sRemoteport,
sPkcsfile, sPkcspass);
}
Log.d("SSLDroid", "Saving settings...");