Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

69 rader
1.7 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. package net.lolengine;
  11. import android.app.NativeActivity; /* NativeActivity */
  12. import android.os.Bundle; /* Bundle */
  13. import android.content.res.AssetManager; /* getAssets() */
  14. import android.graphics.Bitmap;
  15. import android.graphics.BitmapFactory;
  16. public class LolActivity extends NativeActivity
  17. {
  18. static
  19. {
  20. /* Need to preload libstlport_shared.so somewhere; also need to
  21. * preload lib@PROGRAM@.so otherwise nativeInit() can’t be found. */
  22. System.loadLibrary("stlport_shared");
  23. System.loadLibrary("@PROGRAM@");
  24. }
  25. @Override
  26. protected void onCreate(Bundle saved_instance)
  27. {
  28. super.onCreate(saved_instance);
  29. m_assets = getAssets();
  30. }
  31. private AssetManager m_assets;
  32. /*
  33. * Bitmap loading helpers
  34. */
  35. public Bitmap openImage(String name)
  36. {
  37. try
  38. {
  39. return BitmapFactory.decodeStream(m_assets.open(name));
  40. }
  41. catch (Exception e) { }
  42. return null;
  43. }
  44. public int getWidth(Bitmap bmp) { return bmp.getWidth(); }
  45. public int getHeight(Bitmap bmp) { return bmp.getHeight(); }
  46. public void getPixels(Bitmap bmp, int[] pixels)
  47. {
  48. int w = bmp.getWidth();
  49. int h = bmp.getHeight();
  50. bmp.getPixels(pixels, 0, w, 0, 0, w, h);
  51. }
  52. public void closeImage(Bitmap bmp)
  53. {
  54. bmp.recycle();
  55. }
  56. }