コード例 #1
0
ファイル: instalacion.java プロジェクト: sodapop/BioNlpOcr
    @Override
    protected void onPostExecute(Integer result) {
      // Log.w("LOGGER", "...Done");

      if (result == 0) {
        try {
          // DESCOMPRIMIR

          accion.setText("Descomprimiendo archivos");
          downloading.setProgress(0);

          new Async_UnZip(activity, mDialog, accion, downloading).execute();

          //			    			 File dir = Environment.getExternalStorageDirectory();
          //			    			 dir = Environment.getExternalStorageDirectory();
          //			    			 File zipfile = new File(dir, "/tessdata.zip");
          //
          //			    			 unzipArchive(activity, zipfile, dir.getAbsolutePath(),mDialog,
          // accion,downloading);

          //			    				File zipFile = zipfile;
          //			    				String directory = null;
          //			    				directory = zipFile.getParent();
          //			    				directory = directory + "/";
          //
          //			    				new Async_UnZip(zipFile, directory).execute();

        } catch (Exception e) {
          // TODO: handle exception
          // Log.e("instalacion","Error con el ftp :"+e.getMessage());
        }
      } else if (result == 1) {

      } else if (result == -2) {

        Toast.makeText(activity, "ERROR DE CONEXION CON EL SERVIDOR", Toast.LENGTH_LONG).show();
        accion.setText("ERROR DE CONEXION CON EL SERVIDOR");
        mDialog.dismiss();
        activity.finish();

      } else {

      }

      //	    	mDialog.dismiss();

      actionBar.setProgressBarVisibility(ProgressBar.GONE);
      actionBar.setTitle("");
    }
コード例 #2
0
ファイル: instalacion.java プロジェクト: sodapop/BioNlpOcr
    @Override
    protected void onPreExecute() {
      // TODO Auto-generated method stub
      //	    	this.progressComprobarVersion.show();
      actionBar.setProgressBarVisibility(ProgressBar.VISIBLE);
      actionBar.setTitle(" Comprobando lenguajes");

      LayoutInflater inflater = activity.getLayoutInflater();
      View dialoglayout =
          inflater.inflate(R.layout.alert_loading_simple, (ViewGroup) activity.getCurrentFocus());
      mDialog = new Dialog(activity, android.R.style.Theme_Translucent_NoTitleBar);

      downloading = (ProgressBar) dialoglayout.findViewById(R.id.progressBarDownlaod);
      downloading.setMax(100);

      accion = (TextView) dialoglayout.findViewById(R.id.textViewAccion);
      accion.setText("Descargando lenguajes");

      LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
      mDialog.addContentView(dialoglayout, params);
      mDialog.show();

      super.onPreExecute();
    }
コード例 #3
0
ファイル: instalacion.java プロジェクト: sodapop/BioNlpOcr
    @Override
    protected Integer doInBackground(Long... params) {
      // Log.w("LOGGER", "Starting...doInBackground");

      try {

        actionBar.setProgressBarVisibility(ProgressBar.VISIBLE);
        con = new FTPClient();
        try {
          String version_actualizar = "";

          // set time out
          con.setConnectTimeout(9000);

          // Log.v("instalacion", "conectando");
          con.connect("62.212.77.173");

          // Log.v("instalacion", "conectado");
          if (con.login("soda", "pepino")) {
            // Log.v("instalacion", "login");
            con.enterLocalPassiveMode(); // important!

            Log.v("instalacion", "changeWorkingDirectory -     " + con.printWorkingDirectory());

            //			  				        con.changeWorkingDirectory("" + "tessdata" + "");

            Log.v("instalacion", "changeWorkingDirectory -     " + con.printWorkingDirectory());

            String[] files = con.listNames();
            FTPFile[] directories = con.listDirectories();
            FTPFile[] archivos = con.listFiles();

            for (int i = 0; i < directories.length; i++) {
              Log.v("instalacion", directories[i].getName().toString());
            }
            for (int i = 0; i < archivos.length; i++) {
              Log.v("instalacion", archivos[i].getName().toString());
            }

            // DESCARGA
            System.out.println("  ---   Remote system is " + con.getSystemName());

            con.setFileType(FTP.BINARY_FILE_TYPE);
            con.enterLocalPassiveMode();

            filename = "tessdata.zip";

            for (int i = 0; i < archivos.length; i++) {
              Log.v("----- instalacion", archivos[i].getName().toString());

              if (archivos[i].getName().toString().equals(filename)) {
                size = archivos[i].getSize();
              }
            }

            try {

              fos =
                  new BufferedOutputStream(
                      new FileOutputStream(
                          Environment.getExternalStorageDirectory().toString() + "/" + filename));
              // Log.i("instalacion"," FileOutputStream ");

              InputStream input = con.retrieveFileStream("tessdata.zip");

              byte data[] = new byte[1024];
              long total = 0;
              int count;
              while ((count = input.read(data)) != -1) {
                total += count;
                // publishing the progress....
                //				  				                publishProgress((int) (total * 100 / data.length));

                publishProgress(
                    Integer.valueOf((int) (((total * 100 / data.length) * 1000) / size)));
                //				  				                Log.i("instalacion", String.valueOf( (((int) (total *
                // 100 / data.length))*100)/size ));

                //				  				                publishProgress(count);
                fos.write(data, 0, count);
              }

              fos.flush();
              fos.close();

              con.logout();
              con.disconnect();
            } catch (Exception e) {
              // TODO: handle exception
              Log.e(
                  "instalacion",
                  "ERROR al obtener la actualizaci—n de Elara  : " + e.getMessage() + "    ");
              return -4;
            }

          } else {
            // Log.e("instalacion","Nombre usuario o contrase–a ftp no valido.");
            Log.e("instalacion", "Nombre usuario o contrase–a ftp no valido. ");
            return -5;
          }
        } catch (Exception e) {

          Log.e("instalacion", "ERROR de conexion  : " + e.getMessage() + "    ");
          return -2;
        }

        try {
          con.logout();
          return 0;
        } catch (IOException e) {
          // Log.e("instalacion",e.getMessage());
          Log.e("instalacion", "ERROR al desconectar del FTP : " + e.getMessage() + "    ");
          return 0;
        }

      } catch (Exception e) {
        // Log.e("instalacion",e.getMessage());
        Log.e(
            "instalacion", "ERROR al buscar actualizaciones de Elara: " + e.getMessage() + "    ");
        return -1;
      }
    }