Android Open Source - AndroIUT F T P Activity






From Project

Back to project page AndroIUT.

License

The source code is released under:

GNU General Public License

If you think the Android project AndroIUT listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.iutdijon.androiut2.ftp.activities;
/*from   w ww .j  av a 2 s. c  o  m*/
import java.io.File;

import org.apache.commons.net.ftp.FTPFile;

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;

import com.iutdijon.androiut2.R;
import com.iutdijon.androiut2.ftp.adapters.FTPFileListAdapter;
import com.iutdijon.androiut2.ftp.data.FTPCommand;
import com.iutdijon.androiut2.ftp.data.FTPCommandResult;
import com.iutdijon.androiut2.ftp.data.FTPCommandWrapper;
import com.iutdijon.androiut2.ftp.services.FTPServiceCall;
import com.iutdijon.androiut2.global.AndroIUTApplication;
import com.iutdijon.androiut2.iut.data.account.UserAccount;
import com.iutdijon.androiut2.util.IOUtils;
import com.iutdijon.androiut2.util.UIUtil;
import com.iutdijon.androiut2.util.bridge.BridgeFinder;

/**
 * IHM pour le service FTP de l'IUT. <br/> 
 * Les m?thodes qui g?rent le cycle de vie de l'IHM sont surcharg?es pour faire correspondre
 * le cycle de vie du Socket utilis? par le client FTP au cycle de vie de l'IHM. Et ?viter 
 * d'user la batterie inutilement.
 * 
 * @author Morgan Funtowicz
 *
 */
public class FTPActivity extends ListActivity implements OnItemLongClickListener{

  private FTPServiceCall client;
  private UserAccount account;
  
  private static Handler mHandler;
  private static ProgressDialog progressBar; 
  
  private static String path = "./";
  
  public FTPActivity() {
    account = AndroIUTApplication.getInstance().getAccount();
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    if(IOUtils.isUniversityWifi(this)){
      UIUtil.showMessage(this, R.string.ftp_on_university_wifi_disable);
      return;
    }
    
    if(savedInstanceState != null){
      if(savedInstanceState.getString("path") != null){
        path = savedInstanceState.getString("path");
      }
    }
    
    mHandler = new FTPCommandHandler(){
      @Override
      public void handleMessage(Message msg) {
        if(msg.what == FTPServiceCall.FTP_COMMAND_START){
          onComandStart((FTPCommandWrapper) msg.obj);
        }else{
          onCommandExecuted((FTPCommandResult) msg.obj);
        }
      }
    };
    
    setContentView(R.layout.activity_ftp);
    
    getListView().setOnItemLongClickListener(this);
    
    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    String operatorName = telephonyManager.getNetworkOperatorName().toLowerCase();
    
    if(operatorName.contains("bouygues") || operatorName.contains("free")){
      UIUtil.showMessage(this, R.string.ftp_on_bouy_free_operator);
    }
  }
  
  @Override
  protected void onStart() {
    super.onStart();
    
    client = new FTPServiceCall(this, mHandler, FTPServiceCall.UNIVERSITY_FTP_SERVER_URL, FTPServiceCall.UNIVERSITY_FTP_SERVER_PORT);
    client.start();
    client.sendCommand(new FTPCommandWrapper(FTPCommand.FTP_LOGIN, account.getLogin()+":"+account.getPassword()));
    
    if(!path.equalsIgnoreCase("./")){
      client.sendCommand(new FTPCommandWrapper(FTPCommand.FTP_CD, path));
    }
    
    
  }
  
  @Override
  protected void onPause() {
    
    if( progressBar != null && progressBar.isShowing()){
      progressBar.dismiss();
      progressBar = null;
    }
    client.sendCommand(new FTPCommandWrapper(FTPCommand.FTP_LOGOUT, null));
    super.onPause();
  }
  
  @Override
  protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putString("path", path);
  }
  
  @Override
  protected void onRestoreInstanceState(Bundle state) {
    super.onRestoreInstanceState(state);
    
    if(state.getString("path") != null){
      path = state.getString("path");
    }
    
    if(client != null){
      client.sendCommand(new FTPCommandWrapper(FTPCommand.FTP_CD, path));
    }
    
  }
  
  @Override
  protected void onDestroy() {
    client = null;
    path = "./";
    super.onDestroy();
  }

  @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    FTPFile file = (FTPFile) l.getItemAtPosition(position);
    
    if(file.isDirectory()){
      
      if(file.getName().equalsIgnoreCase("..")){
        path = path.substring(0, path.length()-1);
        path = path.substring(0, path.lastIndexOf('/')+1);
      }else{
        path = path.concat(file.getName()+"/");
      }
      client.sendCommand(new FTPCommandWrapper(FTPCommand.FTP_CD, file.getName()));
    }
  }
  
  @Override
  public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    FTPFile file = (FTPFile) getListView().getItemAtPosition(position);
    if(file.isFile()){
      client.sendCommand(new FTPCommandWrapper(FTPCommand.FTP_GET, file.getName()));
    }
    return file.isFile();
  }
  
  private void onCommandExecuted(FTPCommandResult result) {
    
    if( progressBar != null && progressBar.isShowing()){
      progressBar.dismiss();
      progressBar = null;
    }
    
    if(result != null){
      if(result.getDirectoryFiles() != null) {

        FTPFileListAdapter adapter = (FTPFileListAdapter) getListAdapter();
        
        if(adapter == null){
          adapter = new FTPFileListAdapter(this,  R.layout.ftp_list_item, result.getDirectoryFiles());
          setListAdapter(adapter);
        }else{
          ((FTPFileListAdapter)getListAdapter()).updateFileList(result.getDirectoryFiles());
        }
        
      }else if(result.getStoredFile() != null){
        
        File file = result.getStoredFile();
    
        try{
          Intent viewer = BridgeFinder.getDefaultApplicationFromFileName(file);
          startActivity(viewer);
          
        }catch(ActivityNotFoundException ex){
          UIUtil.showMessage(this, "Aucune application n'est install?e pour ouvrir ce type de fichier");
        }
      }
    }
  }
  private void onComandStart(FTPCommandWrapper command){
    if(command.getCommandID() != FTPCommand.FTP_LOGOUT){
      progressBar  = ProgressDialog.show(FTPActivity.this, "", getText(R.string.ftp_command_running),true,true);
    }
  }
  
  static class FTPCommandHandler extends Handler{
    
  }
}




Java Source Code List

.ADEResourcesDataTree.java
com.iutdijon.androiut2.ade.activities.ADEActivity.java
com.iutdijon.androiut2.ade.activities.ADEListResourcesChooser.java
com.iutdijon.androiut2.ade.activities.OnImageDownloadedCallback.java
com.iutdijon.androiut2.ade.service.ADEICalendarDownloader.java
com.iutdijon.androiut2.ftp.activities.FTPActivity.java
com.iutdijon.androiut2.ftp.adapters.FTPFileListAdapter.java
com.iutdijon.androiut2.ftp.data.FTPCommandResult.java
com.iutdijon.androiut2.ftp.data.FTPCommandWrapper.java
com.iutdijon.androiut2.ftp.data.FTPCommand.java
com.iutdijon.androiut2.ftp.services.FTPDownloadMonitor.java
com.iutdijon.androiut2.ftp.services.FTPServiceCall.java
com.iutdijon.androiut2.ftp.services.ProgressDownload.java
com.iutdijon.androiut2.global.AndroIUTApplication.java
com.iutdijon.androiut2.iut.activities.HomeActivity.java
com.iutdijon.androiut2.iut.activities.LoginActivity.java
com.iutdijon.androiut2.iut.data.Credential.java
com.iutdijon.androiut2.iut.data.UserFactory.java
com.iutdijon.androiut2.iut.data.account.StudentAccount.java
com.iutdijon.androiut2.iut.data.account.TeacherAccount.java
com.iutdijon.androiut2.iut.data.account.UserAccount.java
com.iutdijon.androiut2.iut.services.IUTLoginServiceCall.java
com.iutdijon.androiut2.mail.activities.MailActivity.java
com.iutdijon.androiut2.mail.activities.MailReaderActivity.java
com.iutdijon.androiut2.mail.adapters.MailDisplayAdapter.java
com.iutdijon.androiut2.mail.adapters.MailsListAdapter.java
com.iutdijon.androiut2.mail.services.EmailUtils.java
com.iutdijon.androiut2.mail.services.MailReader.java
com.iutdijon.androiut2.mail.services.MailService.java
com.iutdijon.androiut2.schooling.activities.SchoolingActivity.java
com.iutdijon.androiut2.schooling.activities.SchoolingTabActivity.java
com.iutdijon.androiut2.schooling.adapters.SectionedAdapter.java
com.iutdijon.androiut2.schooling.data.Absence.java
com.iutdijon.androiut2.schooling.data.Mark.java
com.iutdijon.androiut2.schooling.data.SchoolingData.java
com.iutdijon.androiut2.schooling.service.SchoolingDataServiceCall.java
com.iutdijon.androiut2.util.AndroIUTLogger.java
com.iutdijon.androiut2.util.IOUtils.java
com.iutdijon.androiut2.util.PreferencesManager.java
com.iutdijon.androiut2.util.UIUtil.java
com.iutdijon.androiut2.util.adapters.AbsencesAdapter.java
com.iutdijon.androiut2.util.adapters.BitmapAdapter.java
com.iutdijon.androiut2.util.adapters.CalendarAdapter.java
com.iutdijon.androiut2.util.adapters.IAdapter.java
com.iutdijon.androiut2.util.adapters.MarksAdapter.java
com.iutdijon.androiut2.util.adapters.UserAdapter.java
com.iutdijon.androiut2.util.adapters.XmlAdapter.java
com.iutdijon.androiut2.util.bridge.BridgeFinder.java
com.iutdijon.androiut2.util.loaders.AndroIUTHTTPConnection.java
com.iutdijon.androiut2.util.loaders.AsyncServiceCall.java
com.iutdijon.androiut2.util.loaders.BitmapDownloaderTask.java
com.iutdijon.androiut2.util.loaders.GetAsyncServiceCall.java
com.iutdijon.androiut2.util.loaders.ImageDownloader.java
com.iutdijon.androiut2.util.loaders.PostAsyncServiceCall.java
com.iutdijon.androiut2.util.observers.Observable.java
com.iutdijon.androiut2.util.observers.Observer.java
com.iutdijon.androiut2.util.security.SecureCenter.java
com.iutdijon.androiut2.util.view.ImageZoomView.java
com.iutdijon.androiut2.util.zoom.AspectQuotient.java
com.iutdijon.androiut2.util.zoom.DynamicZoomControl.java
com.iutdijon.androiut2.util.zoom.LongPressZoomListener.java
com.iutdijon.androiut2.util.zoom.PinchZoomListener.java
com.iutdijon.androiut2.util.zoom.SimpleZoomListener.java
com.iutdijon.androiut2.util.zoom.ZoomState.java
com.iutdijon.androiut2.util.zoom.util.Dynamics.java
com.iutdijon.androiut2.util.zoom.util.SpringDynamics.java