Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2017
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.00 KB | None | 0 0
  1. package hhh.ggg;
  2.  
  3. import android.app.Activity;
  4. import android.app.AlertDialog;
  5. import android.app.ProgressDialog;
  6. import android.os.AsyncTask;
  7. import android.os.Bundle;
  8. import java.io.File;
  9. import java.util.Timer;
  10.  
  11. import android.app.Activity;
  12. import android.graphics.Bitmap;
  13. import android.graphics.BitmapFactory;
  14. import android.os.Bundle;
  15. import android.view.View;
  16. import android.view.View.OnClickListener;
  17. import android.widget.Button;
  18. import android.widget.EditText;
  19. import android.widget.ImageView;
  20. import android.widget.TextView;
  21. //import it.sauronsoftware.ftp4j.FTPClient;
  22.  
  23. import it.sauronsoftware.ftp4j.*;
  24.  
  25.  
  26. public class hhh extends Activity {
  27.     /** Called when the activity is first created. */
  28.     FTPClient ftp;
  29.     int x = 0;
  30.     String sUserName = "";
  31.     String sPassword = "";
  32.     String user = "";
  33.     @Override
  34.    
  35.     public void onCreate(Bundle savedInstanceState) {
  36.         super.onCreate(savedInstanceState);
  37.         setContentView(R.layout.main);
  38.        
  39.      
  40.         TextView jpgName = (TextView)findViewById(R.id.jpgname);
  41.         jpgName.setText("WhiteFox Security");
  42.        
  43.        
  44.        
  45.        
  46.         Button btn1 = (Button)findViewById(R.id.btnClickMe);
  47.         btn1.setOnClickListener(btnListener);
  48.  
  49.  
  50.             //this.pd = ProgressDialog.show(this, "Working...", "*** Downloading Data...", true, false);
  51.             //new DownloadTask().execute(" parameters needed for download");
  52.        
  53.        
  54.        
  55.    
  56.     }
  57.  
  58.      private OnClickListener btnListener = new OnClickListener()
  59.         {
  60.             public void onClick(View v)
  61.             {   if(x ==0)
  62.                 {
  63.                
  64.                 EditText usernameEditText = (EditText) findViewById(R.id.txt_username);
  65.                
  66.                 EditText passwordEditText = (EditText) findViewById(R.id.txt_password);
  67.                 sUserName = usernameEditText.getText().toString();
  68.                 user = sUserName + "@thestorythusfar.co.uk";
  69.                
  70.                 String sPassword = passwordEditText.getText().toString();
  71.                
  72.                     try
  73.                     {
  74.                         ftp = new FTPClient();
  75.                         ftp.connect("213.175.221.80");
  76.                         ftp.login(user, sPassword);
  77.                         ftp.changeDirectory("public_ftp");
  78.                         TextView jpgName = (TextView)findViewById(R.id.jpgname);
  79.                         jpgName.setText("Successfully logged in...");
  80.                         x =1;
  81.                     }
  82.                     catch(Exception e)
  83.                     {
  84.                         TextView jpgName = (TextView)findViewById(R.id.jpgname);
  85.                         jpgName.setText("Incorrect Credentials");
  86.                         usernameEditText.setText("");
  87.                         passwordEditText.setText("");
  88.                        
  89.                     //e.printStackTrace();
  90.                     //new AlertDialog.Builder(this)
  91.                     //.setMessage(e.toString())
  92.                     //.show();
  93.                     }
  94.                     if(x == 1)
  95.                     {
  96.                        
  97.                     new DownloadTask().execute("parameters needed for download");
  98.                     //EditText usernameEditText = (EditText) findViewById(R.id.txt_username);
  99.                     usernameEditText.setVisibility(View.GONE);
  100.                     //EditText passwordEditText = (EditText) findViewById(R.id.txt_password);
  101.                     passwordEditText.setVisibility(View.GONE);
  102.                     TextView usernametext = (TextView) findViewById(R.id.username_text);
  103.                     usernametext.setVisibility(View.GONE);
  104.                     TextView passwordtext = (TextView) findViewById(R.id.password_text);
  105.                     passwordtext.setVisibility(View.GONE);
  106.                     }
  107.                 }
  108.            
  109.             if (x==1)
  110.             {
  111.                 new DownloadTask().execute("parameters needed for download");
  112.                
  113.             }
  114.             }
  115.         };    
  116.  
  117.    
  118.    
  119.         private class DownloadTask extends AsyncTask<String, Void, Object> {
  120.              protected Void doInBackground(String... args) {
  121.                  //Log.d("********Jorgesys", "Background thread starting......");
  122.                  
  123.                  startLongRunningOperation();
  124.                  
  125.                 return null;        
  126.              }
  127.  
  128.              protected void onPostExecute(Object result) {
  129.                  //Log.d("********Jorgesys", "onPostExecute......");
  130.  
  131.                  //if (Splash.this.pd != null) {
  132.                   //Splash.this.pd.dismiss();
  133.                  //}
  134.                  updateResultsInUi();
  135.  
  136.              }
  137.         }
  138.  
  139.  
  140.         protected void startLongRunningOperation() {
  141.                      try
  142.                      {
  143.                      //ftp = new FTPClient();
  144.                      //ftp.connect("213.175.221.80");
  145.                      //ftp.login("bruno@thestorythusfar.co.uk", "G1lead.");
  146.                      //ftp.changeDirectory("public_ftp");
  147.                      ftp.download("386.jpg", new java.io.File("/sdcard/386.jpg"));
  148.                      
  149.                      }
  150.               catch(Exception e)
  151.               {                
  152.                   e.printStackTrace();
  153.                   new AlertDialog.Builder(this)
  154.                   .setMessage(e.toString())
  155.                   .show();
  156.               }
  157.         }
  158.  
  159.         private void updateResultsInUi() {
  160.  
  161.             // Back in the UI thread -- update our UI elements based on the data in mResults
  162.  
  163.         try{
  164.             TextView jpgName = (TextView)findViewById(R.id.jpgname);      
  165.             ImageView jpgView = (ImageView)findViewById(R.id.jpgview);
  166.             String myJpgPath = "/sdcard/386.jpg";              
  167.             jpgName.setText("Live Remote View");
  168.            
  169.             BitmapFactory.Options options = new BitmapFactory.Options();  
  170.             options.inSampleSize = 2;
  171.             Bitmap bm = BitmapFactory.decodeFile(myJpgPath, options);
  172.             jpgView.setImageBitmap(bm);
  173.            
  174.            
  175.            
  176.            
  177.                            
  178.            
  179.         }
  180.         catch(Exception e)
  181.         {
  182.             e.printStackTrace();
  183.             new AlertDialog.Builder(this)
  184.             .setMessage(e.toString())
  185.             .show();
  186.         }
  187.  
  188.  
  189.  
  190.    
  191.         }
  192.    
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement