Logx.java 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package nl.digitalthings.mebarista;
  2. import android.content.Context;
  3. import android.widget.Toast;
  4. public class Logx {
  5. Context ctxt;
  6. MainActivity main;
  7. public static final String TAG = "BT-for-STK";
  8. public Logx(MainActivity main, Context ctxt){
  9. this.ctxt = ctxt;
  10. this.main = main;
  11. }
  12. /** prints a msg on the UI screen **/
  13. public void makeToast(String msg){
  14. final String out = msg;
  15. main.runOnUiThread(new Runnable() {
  16. @Override
  17. public void run() {
  18. Toast.makeText(ctxt, out, Toast.LENGTH_SHORT).show();
  19. }
  20. });
  21. }
  22. public void printToConsole(String msg){
  23. final String out = msg;
  24. main.runOnUiThread(new Runnable() {
  25. @Override
  26. public void run() {
  27. // System.out.println(out);
  28. // main.printToConsole(out);
  29. main.log(out);
  30. }
  31. });
  32. }
  33. public void logcat(String msg, String level) {
  34. if (level.equals("v")) {
  35. android.util.Log.v(TAG, msg);
  36. main.log(msg);
  37. }
  38. else if (level.equals("d")){
  39. android.util.Log.d(TAG, msg);
  40. main.log(msg);
  41. }
  42. else if (level.equals("i")) {
  43. android.util.Log.i(TAG, msg);
  44. main.log(msg);
  45. }
  46. else if (level.equals("w")) {
  47. android.util.Log.w(TAG, msg);
  48. main.log(msg);
  49. }
  50. else if (level.equals("e")) {
  51. android.util.Log.e(TAG, msg);
  52. main.log(msg);
  53. }
  54. }
  55. }