Wednesday, August 24, 2011

Happy Birthday Aximedia Soft

Today is the birthday of Aximedia Soft LLC. Happy birthday Aximedia Soft! С днём рождения Аксимедиа Софт! Bonne anniversaire Aximedia Soft! 生日快乐 Aximedia Soft!

Tuesday, August 23, 2011

An error has occurred. Please try again later

I'm suddenly discovered that when tried to open Android Market on Android a message appeared:
"An error has occurred. Please try again later"

To get rid of it you just need to enable Background data checkbox:

This item is located here:
Settings -> Accounts & sync -> Background data

Friday, August 19, 2011

Android upload progress

Some time ago I got a task to create a file uploader for Android. Writing file uploader code it not difficult and I’ve done it quickly. To indicate the uploading progress I’ve shown standard rotating progress control while uploading.
But it’s not quite clear for users. Much better is to show the usual progress bar with bytes uploaded and total size. So I decided to implement this user friendliness.
Source code of BackgroundUploader class is here:

class BackgroundUploader extends AsyncTask<Void, Integer, Void> implements DialogInterface.OnCancelListener {

  private ProgressDialog progressDialog;
  private String url;
  private File file;

   public BackgroundUploader(String url, File file) {
    this.url = url;
    this.file = file;
  }

   @Override
  protected void onPreExecute() {
    progressDialog = new ProgressDialog(context);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setMessage("Uploading...");
    progressDialog.setCancelable(false);
    progressDialog.setMax((int) file.length());
    progressDialog.show();
  }

   @Override
  protected Void doInBackground(Void... v) {
    HttpURLConnection.setFollowRedirects(false);
    HttpURLConnection connection = null;
    String fileName = file.getName();
    try {
      connection = (HttpURLConnection) new URL(url).openConnection();
      connection.setRequestMethod("POST");
      String boundary = "---------------------------boundary";
      String tail = "\r\n--" + boundary + "--\r\n";
      connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
      connection.setDoOutput(true);

      String metadataPart = "--" + boundary + "\r\n"
          + "Content-Disposition: form-data; name=\"metadata\"\r\n\r\n"
          + "" + "\r\n";

      String fileHeader1 = "--" + boundary + "\r\n"
          + "Content-Disposition: form-data; name=\"uploadfile\"; filename=\""
          + fileName + "\"\r\n"
          + "Content-Type: application/octet-stream\r\n"
          + "Content-Transfer-Encoding: binary\r\n";

       long fileLength = file.length() + tail.length();
      String fileHeader2 = "Content-length: " + fileLength + "\r\n";
      String fileHeader = fileHeader1 + fileHeader2 + "\r\n";
      String stringData = metadataPart + fileHeader;

      long requestLength = stringData.length() + fileLength;
      connection.setRequestProperty("Content-length", "" + requestLength);
      connection.setFixedLengthStreamingMode((int) requestLength);
      connection.connect();

      DataOutputStream out = new DataOutputStream(connection.getOutputStream());
      out.writeBytes(stringData);
      out.flush();

      int progress = 0;
      int bytesRead = 0;
      byte buf[] = new byte[1024];
      BufferedInputStream bufInput = new BufferedInputStream(new FileInputStream(file));
      while ((bytesRead = bufInput.read(buf)) != -1) {
        // write output
        out.write(buf, 0, bytesRead);
        out.flush();
        progress += bytesRead;
        // update progress bar
        publishProgress(progress);
      }

       // Write closing boundary and close stream
      out.writeBytes(tail);
      out.flush();
      out.close();

       // Get server response
      BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
      String line = "";
      StringBuilder builder = new StringBuilder();
      while((line = reader.readLine()) != null) {
        builder.append(line);
      }

    } catch (Exception e) {
      // Exception
    } finally {
      if (connection != null) connection.disconnect();
    }

    return null;
  }

   @Override
  protected void onProgressUpdate(Integer... progress) {
    progressDialog.setProgress((int) (progress[0]));
  }

   @Override
  protected void onPostExecute(Void v) {
    progressDialog.dismiss();
  }

   @Override
  public void onCancel(DialogInterface dialog) {
    cancel(true);
    dialog.dismiss();
  }
}

* This source code was highlighted with Source Code Highlighter.


To execute file uploader the next code should be used:

new BackgroundUploader(url, file).execute();

I wrote the code based on the DNDApplet.java.

Friday, August 5, 2011

Wifi интернет для HTC с ноутбука

Для отладки проектов на HTC устройстве под управлением Android, потребовалось наличие на устройстве интернета.

Настроить интернет на устройстве, имея ноутбук с wifi, можно с помощью программы Virtual Router.

Данная программа позволяет создать wifi точку доступа на компьютере с ОС Windows 7 или Windows 2008 R2.

Скачать программу можно с сайта проекта http://virtualrouter.codeplex.com/

Saturday, July 2, 2011

IT songs

Недавно в твиттере увидел ссылку на список фильмов на IT тематику и сразу начал вспоминать какие песни я слышал про айтишников.
Сразу же, конечно, вспомнил песню про DOS (звонкой пеленой экран заполнил чистый DOS) и про Админа (Будь как дома юзер). Как и эти две песни, многие зарубежные используют музыку из известных песен с заменённым на IT тематику текстом.

Вот список песен про айтишников, программистов и админов.
Jonathan Coulton - Code Monkey
Richard Stallman - The Free Software Song
Morning Sidekick - My Cubicle
Weird Al Yankovic - It's All About The Pentiums (Вообще у него много веселых песенок на IT тематику.)
Loose Bruce Kerr - Java Song
The Beatles - Write in C
Julia Ecklar - The Eternal Flame (God Wrote in LISP)
GigFlapping
Weird Al Yankovic - White And Nerdy
Monzy - So much drama in the PhD

Ещё вот эти песни не могу не привести.
Chumbawamba - Add Me
Weird Al Yankovic - Ebay

Огромный список песен с наименованием оригинала и текстом на английском языке можно посмотреть здесь.

Tuesday, June 21, 2011

Gloomy view

Мне эта фотография напоминает Сталкер.

Monday, June 20, 2011

Android apk is installed but does not run on device

I faced a problem when I'm trying to debug my android apk from Eclipse on device/emulator, it successfully installed, but not automatically started.

It was necessary just to check AndroidManifest.xml

It should contain the line:
<category android:name="android.intent.category.LAUNCHER" />

And also must not contain errors!
When I removed the unused line (before mentioned above) the problem goes away.