Sie sind auf Seite 1von 4

package com.ideatest.

kpi;
import it.sauronsoftware.ftp4j.FTPClient;
import it.sauronsoftware.ftp4j.FTPDataTransferListener;
import java.io.File;
import java.io.IOException;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Environment;
import android.os.StrictMode;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class KPI extends Activity {
TextFileHelper TextFileH;
// where our text file will be created
String filePath = Environment.getExternalStorageDirectory() + "/";
long siz=1;
double per=0.0;
// name of our text file
String fileName ="q.txt";
String fileNamea ="webopen.html";
// filePath and fileName combined
String actualFile = filePath + fileName;
String actualFilea = filePath + fileNamea;
TextView contentsTextView;
ProgressDialog dialog = null;
/********* work only for Dedicated IP ***********/
static final String FTP_HOST= "192.168.100.10";

/********* FTP USERNAME ***********/
static final String FTP_USER = "idea";

/********* FTP PASSWORD ***********/
static final String FTP_PASS ="idea";
static final String FN ="/home/idea/p.txt";
static final String FNa ="/home/idea/webopen.html";
Button btn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

btn = (Button) findViewById(R.id.readBtn);


View.OnClickListener handler = new View.OnClickListener() {
public void onClick(View v) {

/********** Pick file from sdcard *******/
//File f = new File(actualFile);

File fa = new File(actualFilea);
if (fa.exists()) {
fa.delete();
}
try {
fa.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Bui
lder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
TextFileH = new TextFileHelper(KPI.this);
TextFileH.createPath(filePath);
// Upload sdcard file
//downloadFile(FN ,f);
downloadFile(FNa ,fa);
// initialize our TextFileHelper here

// first, make sure the path to your text file is created


// so we can show file contents to the user
//contentsTextView = (TextView) findViewById(R.id.contentsTextView);

final WebView wv;
wv = (WebView) findViewById(R.id.webview);
wv.getSettings().setUseWideViewPort(true);
wv.getSettings().setLoadWithOverviewMode(true);

// here is the actual button listener


wv.loadUrl("file:///"+actualFilea);
// we will use switch statement and just
// get the buttons id to make things easier
// switch (v.getId()) {
// when create button was clicked
//case R.id.createBtn:
// TextFileH.createTextFile(actualFile);
// contentsTextView.setText( );
//break;
// when read button was clicked
// case R.id.readBtn:
// String contents = TextFileH.readTextFile(actualFile);
// contentsTextView.setText(contents);
// break;
// when update button was clicked
//case R.id.updateBtn:
//TextFileH.updateTextFile(actualFile, Mike is so handsome!nN
ew line here!);
//contentsTextView.setText();
// break;
// when edit button was clicked
//case R.id.deleteBtn:
// TextFileH.deleteTextFile(actualFile);
// contentsTextView.setText();
// break;



// we will get the button views and set the listener (handler)
//findViewById(R.id.createBtn).setOnClickListener(handler);

// findViewById(R.id.updateBtn).setOnClickListener(handler);
// findViewById(R.id.deleteBtn).setOnClickListener(handler);

}

};

findViewById(R.id.readBtn).setOnClickListener(handler);

}
public void downloadFile(String FNN ,File fileName) {



FTPClient client = new FTPClient();

try {

client.connect(FTP_HOST,21);
client.login(FTP_USER, FTP_PASS);
client.setType(FTPClient.TYPE_BINARY);

client.download(FNN ,fileName, new MyTransferListener());

} catch (Exception e) {
e.printStackTrace();
try {
client.disconnect(true);
} catch (Exception e2) {
e2.printStackTrace();
}
}

}

/******* Used to file upload and show progress **********/

public class MyTransferListener implements FTPDataTransferListener {

public void started() {

btn.setVisibility(View.GONE);
// Transfer started
//dialog = ProgressDialog.show(KPI.this, "", "trasnfer started...",
true);
Toast.makeText(getBaseContext(), " download Started ...", Toast.LENG
TH_SHORT).show();
//System.out.println(" Upload Started ...");
}

public void transferred(int length) {

// Yet other length bytes has been transferred since the last time t
his
// method was called
//long sz=64249;
//siz=siz+length;
//per=siz/sz*100;
//dialog = ProgressDialog.show(KPI.this, "", "trasnfering "+per,
true);
//Toast.makeText(getBaseContext(), "transfered " + siz + " of " + sz
+" Bytes", Toast.LENGTH_SHORT).show();
//System.out.println(" transferred ..." + length);
}

public void completed() {

btn.setVisibility(View.VISIBLE);
// Transfer completed
//dialog = ProgressDialog.show(KPI.this, "", "trasnfer complete", tr
ue);
Toast.makeText(getBaseContext(), " completed ...", Toast.LENGTH_SHOR
T).show();
//System.out.println(" completed ..." );
}

public void aborted() {

btn.setVisibility(View.VISIBLE);
// Transfer aborted
Toast.makeText(getBaseContext()," transfer aborted ,please try again
...", Toast.LENGTH_SHORT).show();
//System.out.println(" aborted ..." );
}

public void failed() {

btn.setVisibility(View.VISIBLE);
// Transfer failed
System.out.println(" failed ..." );
}

}
}

Das könnte Ihnen auch gefallen