/*
 ============================================================================
 Author	    : Dmitry Moskalchuk
 Version	: 1.5
 Copyright  : Copyright (C) 2008 Rhomobile. All rights reserved.

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ============================================================================
 */
package com.rhomobile.rhodes.alert;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.media.MediaPlayer;
import android.os.Vibrator;

import com.rhomobile.rhodes.Logger;
import com.rhomobile.rhodes.Rhodes;
import com.rhomobile.rhodes.RhodesInstance;

public class Alert {
	
	private static final String TAG = "Alert";
	
	private static class ShowDialog implements Runnable {
		private String message;
		
		public ShowDialog(String m) {
			message = m;
		}

		public void run() {
			AlertDialog.Builder builder = new AlertDialog.Builder(RhodesInstance.getInstance());
			builder.setTitle("Alert");
			builder.setMessage(message);
			builder.setCancelable(false);
			builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					// Do nothing here
				}					
			});
			builder.show();
		}
	};
	
	private static void reportFail(String name, Exception e) {
		Logger.E(TAG, "Call of \"" + name + "\" failed: " + e.getMessage());
	}

	public static void showPopup(String message) {
		try {
			Rhodes.performOnUiThread(new ShowDialog(message));
		}
		catch (Exception e) {
			reportFail("showPopup", e);
		}
	}
	
	public static void vibrate(int duration) {
		try {
			Rhodes instance = RhodesInstance.getInstance();
			Vibrator vibrator = (Vibrator)instance.getSystemService(Context.VIBRATOR_SERVICE);
			vibrator.vibrate(duration);
		}
		catch (Exception e) {
			reportFail("showPopup", e);
		}
	}
	
	public static void playFile(String fileName, String mediaType) {
		try {
			MediaPlayer mp = new MediaPlayer();
			String source = RhodesInstance.getInstance().getRootPath() + "/apps/" + fileName;
			mp.setDataSource(source);
			mp.prepare();
			mp.start();
		} catch (Exception e) {
			reportFail("playFile", e);
		}
	}
	
}

@@ -928,16 +928,38 @@
 alert;%0A%0A
+import java.io.File;%0A%0A
 import a
@@ -2050,32 +2050,63 @@
 sage) %7B%0A%09%09try %7B%0A
+%09%09%09Logger.T(TAG, %22showPopup%22);%0A
 %09%09%09Rhodes.perfor
@@ -2263,16 +2263,58 @@
 %09%09try %7B%0A
+%09%09%09Logger.T(TAG, %22vibrate: %22 + duration);%0A
 %09%09%09Rhode
@@ -2622,63 +2622,364 @@
 %0A%09%09%09
-MediaPlayer mp = new MediaPlayer();%0A%09%09%09String source = 
+Logger.T(TAG, %22playFile: %22 + fileName + %22 (%22 + mediaType + %22)%22);%0A%09%09%09MediaPlayer mp = new MediaPlayer();%0A%09%09%09mp.setOnErrorListener(new MediaPlayer.OnErrorListener() %7B%0A%09%09%09%09public boolean onError(MediaPlayer mp, int what, int extra) %7B%0A%09%09%09%09%09Logger.E(TAG, %22Error when playing file : %22 + what + %22, %22 + extra);%0A%09%09%09%09%09return false;%0A%09%09%09%09%7D%0A%09%09%09%7D);%0A%09%09%09File f = new File(
 Rhod
@@ -3020,30 +3020,156 @@
 th()
- +
+);%0A%09%09%09f = new File(f,
  %22
-/
 apps
-/%22 + fileName
+%22);%0A%09%09%09f = new File(f, fileName);%0A%09%09%09String source = f.getCanonicalPath();%0A%09%09%09Logger.T(TAG, %22Final file name: %22 + source)
 ;%0A%09%09

Fix Alert.playFile on Android