Beispiel #1
0
    @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("");
    }
Beispiel #2
0
    @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();
    }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);

    ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);
    // You can also assign the title programmatically by passing a
    // CharSequence or resource id.
    //        actionBar.setTitle("Black List");
    actionBar.setSub_menu_Visibility(View.GONE);
    actionBar.setHomeLogo(R.drawable.ic_launcher);
    actionBar
        .getHomeLogo()
        .setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                // TODO Auto-generated method stub
                //				Intent intent = new Intent(ActivityInformeSemanal.this, ActivityPerfil.class);
                //
                //				startActivity(intent);
                //
                //				finish();

                builder = new AlertDialog.Builder(ActivitySettings.this);
                builder
                    .setMessage("Si cancelas, se perder‡n los datos. ÀQuieres cancelar?")
                    .setPositiveButton(
                        "Si",
                        new DialogInterface.OnClickListener() {

                          @Override
                          public void onClick(DialogInterface dialog, int which) {
                            // TODO Auto-generated method stub

                            finish();
                          }
                        })
                    .setNegativeButton(
                        "No",
                        new DialogInterface.OnClickListener() {

                          @Override
                          public void onClick(DialogInterface dialog, int which) {
                            // TODO Auto-generated method stub

                          }
                        });
                builder.setTitle(" ");
                builder.setIcon(R.drawable.ic_launcher);
                builder.show();
              }
            });
    //        actionBar.setHomeAction(new IntentAction(this, ActivityPerfil.createIntent(this),
    // R.drawable.ic_title_home_default));
    actionBar.setDisplayHomeAsUpEnabled(true);
    //        actionBar.addAction( new UpdateAllAction());
    //        actionBar.addAction( new Action(){
    //
    //			@Override
    //			public int getDrawable() {
    //				// TODO Auto-generated method stub
    ////				return 0;
    //				return R.drawable.action_search;
    //			}
    //
    //			@Override
    //			public void performAction(View view) {
    //				// TODO Auto-generated method stub
    //						final Dialog mDialog = new Dialog(ActivitySettings.this, android.R.style.Theme_Panel);
    //
    //
    //						LayoutInflater inflater = getLayoutInflater();
    //		//				TextView tv_texto = (TextView) mDialog.findViewById(R.id.tv_texto);
    //
    //
    //						View view_dialog = inflater.inflate(R.layout.custom_dialog_message1, null);
    //						TextView tv = (TextView) view_dialog.findViewById(R.id.tv_texto); //id defined in
    // camera.xml
    //		//				tv.setText("");
    //
    //
    //						texto_entrada = (EditText) view_dialog.findViewById(R.id.editText_texto_Entrada);
    //
    //
    //						ImageView close = (ImageView) view_dialog.findViewById(R.id.imageViewClose); //id
    // defined in camera.xml
    //						close.setOnClickListener(new OnClickListener() {
    //
    //							@Override
    //							public void onClick(View v) {
    //								// TODO Auto-generated method stub
    //								mDialog.cancel();
    //							}
    //						});
    //
    //						LinearLayout codBarras = (LinearLayout)
    // view_dialog.findViewById(R.id.LinearLayoutCodBarras); //id defined in camera.xml
    //						codBarras.setOnClickListener(new OnClickListener() {
    //
    //							@Override
    //							public void onClick(View v) {
    //								// TODO Auto-generated method stub
    //
    //
    //									Log.d(this.getClass().getSimpleName(),"Ckick Boton Scanner");
    //									//Tiendas.setBackgroundResource(R.drawable.catalogoclick);
    //									// Get instance of Vibrator from current Context
    //									Vibrator vib = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    //
    //									// Vibrate for 5 milliseconds
    //									vib.vibrate(50);
    //									//BotonCatalogo.setBackgroundResource(R.drawable.catalogo);
    //
    //
    //
    ////									new
    // AsyncTask_Search_Concept_from_Bitmap_webservice(ActivityScrollableMenu.this).execute("");
    //									new
    // AsyncTask_Search_Concept_webservice(texto_entrada.getText().toString()).execute("");
    //
    //							}
    //						});
    //
    //
    //		//				View tv_texto = inflater.getinflate(R.id.tv_texto, arg0);
    //		//				((TextView) tv_texto).setText(sb.toString());
    //
    //		//				mDialog.addContentView(inflater.inflate(R.layout.custom_dialog, null), new
    // LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    //						mDialog.addContentView(view_dialog, new  LayoutParams(LayoutParams.WRAP_CONTENT,
    // LayoutParams.WRAP_CONTENT));
    //						mDialog.show();
    //			}
    //
    //
    //        });
    //        actionBar.addAction( new Action(){
    //
    //        	@Override
    //			public int getDrawable() {
    //				// TODO Auto-generated method stub
    ////				return 0;
    //				return R.drawable.action_settings;
    //			}
    //
    //    	    @Override
    //    	    public void performAction(View view) {
    //
    //    	    	Intent intent = new Intent(ActivitySettings.this, ActivitySettings.class);
    //				startActivity(intent);
    //
    //    	    }
    //
    //        });

    // Datos Producto
    bundle = getIntent().getExtras();

    if (bundle != null) {

      //			getcoordinador = bundle.getParcelable("coordinador");
      //			Log.v(TAG,"coordinador = "+getcoordinador.getNombre());

    }

    /*
     * Comprueba el estado de la conexion a internet
     */
    Log.i(this.getClass().getSimpleName(), "Compruebo el estado de la conexion a internet");

    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (!(netInfo != null && netInfo.isConnectedOrConnecting())) {
      Log.w(this.getClass().getSimpleName(), "No hay conexion a interntet!");
      AlertDialog alertDialog = new AlertDialog.Builder(ActivitySettings.this).create();

      alertDialog.setTitle("Conexi—n a Internet");
      alertDialog.setMessage("Esta aplicaci—n necesita internet para funcionar correctamente.");
      alertDialog.setButton(
          "OK",
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

              // here you can add functions

            }
          });
      alertDialog.setIcon(R.drawable.ic_launcher);
      alertDialog.show();
    }
  }
Beispiel #4
0
    @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;
      }
    }