1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
| package com.freedev.freeco;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
private Button valider = null;
private EditText loginField = null;
private EditText passField = null;
FTPClient ftp = new FTPClient();
// String host = "192.168.1.10";
String host = "10.0.2.2";
// String host = "172.16.0.2";
int port = 21;
byte[] binaryIp = null;
InetAddress adress = null;
HashMap <String, String> item = null;
ArrayList <HashMap<String, String> > listItem = null;
/*
* @InjectView (R.id.valider) Button valider;
*
* @InjectView (R.id.loginField) TextView loginField;
*
* @InjectView (R.id.passField) TextView passField;
*
* @InjectView (R.id.login) EditText login;
*
* @InjectView (R.id.pass) EditText pass;
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
valider = (Button) findViewById(R.id.valider);
loginField = (EditText) findViewById(R.id.loginField);
passField = (EditText) findViewById(R.id.passField);
try{
adress = InetAddress.getByName(host);
} catch (UnknownHostException e) {
e.printStackTrace();
}
binaryIp = adress.getAddress();
valider.setOnClickListener(clickTableBoutons);
}
private OnClickListener clickTableBoutons = new View.OnClickListener() {
@Override
public void onClick(View v) {
new Thread(new Runnable() {
@Override
public void run() {
try {
// ftp.connect(binaryIp, login.getText().toString(),
// pass.getText().toString(), 21);
// ftp.connect(InetAddress.getByAddress(binaryIp), port);
ftp.connect(InetAddress.getByName(host), port);
if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
ftp.disconnect();
System.out.println("FTP server refused connection");
System.exit(1);
}
// ftp.setFileType(FTP.BINARY_FILE_TYPE);
ftp.enterLocalPassiveMode();
ftp.login(loginField.getText().toString(), passField.getText().toString());
listItem = new ArrayList<HashMap<String, String>>();
FTPFile[] files = ftp.listFiles("/Jeux");
// FTPFile[] files = ftp.listFiles("video/Films");
for (FTPFile file : files) {
Log.i("TAG", file.getName());
}
// Log.i("TAG", ftp.printWorkingDirectory());
// ftp.listFiles();
// ftp.makeDirectory("antoine");
// ftp.removeDirectory("/antoine");
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
registerForContextMenu(valider); // associer menu à klk chose
/*
* Intent activity = null; activity = new Intent(MainActivity.this,
* StandardActivity.class); activity.putExtra(name, ftp);
* startActivity(activity);
*/
}
};
@Override
public void onCreateContextMenu(ContextMenu menu, View vue,
ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, vue, menuInfo);
menu.setHeaderTitle("Option");
menu.add(0, vue.getId(), 0, "renomer");
menu.add(0, vue.getId(), 0, "copier");
menu.add(0, vue.getId(), 0, "coller");
menu.add(0, vue.getId(), 0, "supprimer");
}
@Override
public boolean onContextItemSelected(MenuItem menuItem) {
/*
* if (menuItem.getTitle() == "renomer"){ ftp.rename(from, to); } else
* if (menuItem.getTitle() == "copier"){ //copier dans presse papier }
* else if (menuItem.getTitle() == "coller"){ // coller depuis presse
* papier } else if (menuItem.getTitle() == "supprimer"){
* ftp.removeDirectory(pathname); ftp.deleteFile(pathname); }
*/
return false;
}
} |
Partager