예제 #1
0
  private String getFilumLetter(String currentLanguageName) {

    String[] biocatNamesEnglish =
        baseContext.getResources().getStringArray(R.array.thesaurusFilumsEnglish);
    int pos = Utilities.findString(biocatNamesEnglish, currentLanguageName);

    if (pos > -1) {

      String[] biocatFilumsLetters =
          baseContext.getResources().getStringArray(R.array.thesaurusFilumsLetters);

      return biocatFilumsLetters[pos];

    } else return "";
  }
예제 #2
0
  @Override
  protected void onPostExecute(String fileName) {

    mProgressDialog.dismiss();

    if (fileName == null) {

      Utilities.showToast(context.getString(R.string.noThConnection), context);

    } else {

      if (handler != null) {

        Bundle b = new Bundle();
        b.putString("filePath", fileName);

        Message msg = new Message();
        msg.setData(b);
        handler.sendMessage(msg);
      }
    }
  }
예제 #3
0
  @Override
  protected String doInBackground(String... aurl) {

    int count;
    String fileName = "";

    // aurl[0] -> url
    // aurl[1] -> fileDest
    // aurl[2] -> optionalFile

    try {

      URL url = new URL(aurl[0]);

      Log.i("Thesaurus", "Downloading TH: " + url);

      HttpURLConnection conexion = (HttpURLConnection) url.openConnection();
      conexion.setInstanceFollowRedirects(false);

      conexion.setUseCaches(false);
      conexion.setDoInput(true);
      conexion.setDoOutput(true);

      // filumLetter=aurl[2];

      conexion.setRequestMethod("GET");
      conexion.connect();

      // pirula que s'ha d'arreglar

      int lenghtOfFile = 1835632;
      int connexionContentLenght = conexion.getContentLength();

      if (connexionContentLenght > 0) {

        lenghtOfFile = connexionContentLenght;
        fileName =
            url.getFile().substring(url.getFile().lastIndexOf('/') + 1, url.getFile().length());

      } else {

        String header = conexion.getHeaderField("Content-Disposition");

        if (header != null) {

          int position = header.indexOf("filename=");
          fileName = header.substring(position + 9);

        } else fileName = aurl[2];
      }

      mProgressDialog.setMax(lenghtOfFile);

      InputStream input = new BufferedInputStream(url.openStream());

      File f = new File(aurl[1] + fileName);
      if (!f.exists()) {

        f.createNewFile();
      }

      OutputStream output = new FileOutputStream(aurl[1] + fileName);

      byte data[] = new byte[1024];

      long total = 0;

      while ((count = input.read(data)) != -1) {

        total += count;
        publishProgress("" + (int) total);

        output.write(data, 0, count);
      }

      output.flush();
      output.close();
      input.close();

      return fileName;

    } catch (IOException e) {

      Log.d("Thesaurus", "Action ->ThDownload Error->:Host Unresearcheable");
      Utilities.showToast("Host Unresearcheable", context);

    } catch (Exception e) {

      e.printStackTrace();
    }
    return null;
  }