public MapView(Context ctx, boolean allowNetAccess, int mode) {
    super(ctx);

    Display display;

    this.allowNetAccess = allowNetAccess;

    geoUtils = new GeoUtils(mode);

    setBackgroundColor(0xFF555570);
    display = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    scrWidth = display.getWidth();
    scrHeight = display.getHeight();
    setMinimumHeight(scrWidth);
    setMinimumWidth(scrHeight);
    tileWidth = (int) Math.ceil(scrWidth / 256.0) + 1;
    tileHeight = (int) Math.ceil(scrHeight / 256.0) + 1;
    gestureDetector = new GestureDetector(ctx, new GestureListener());

    zoomOutButton = new Button(ctx);
    zoomOutButton.setText("  -  ");
    zoomOutButton.setOnClickListener(this);

    zoomInButton = new Button(ctx);
    zoomInButton.setText("  +  ");
    zoomInButton.setOnClickListener(this);

    updateUI(true);
    addView(zoomOutButton);
    addView(zoomInButton);
  }
示例#2
0
 @Override
 public void onSensorChanged(SensorEvent event) {
   if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
     float x, y;
     switch (mDisplay.getRotation()) {
       case Surface.ROTATION_90:
         x = -event.values[1];
         y = event.values[0];
         break;
       case Surface.ROTATION_270:
         x = event.values[1];
         y = -event.values[0];
         break;
       case Surface.ROTATION_180:
         x = -event.values[1];
         y = -event.values[0];
         break;
       default:
         x = event.values[0];
         y = event.values[1];
         break;
     }
     SDLActivity.onNativeAccel(
         -x / SensorManager.GRAVITY_EARTH,
         y / SensorManager.GRAVITY_EARTH,
         event.values[2] / SensorManager.GRAVITY_EARTH - 1);
   }
 }
示例#3
0
  // Called when the surface is resized
  @Override
  public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    Log.v("SDL", "surfaceChanged()");

    int sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565 by default
    switch (format) {
      case PixelFormat.A_8:
        Log.v("SDL", "pixel format A_8");
        break;
      case PixelFormat.LA_88:
        Log.v("SDL", "pixel format LA_88");
        break;
      case PixelFormat.L_8:
        Log.v("SDL", "pixel format L_8");
        break;
      case PixelFormat.RGBA_4444:
        Log.v("SDL", "pixel format RGBA_4444");
        sdlFormat = 0x15421002; // SDL_PIXELFORMAT_RGBA4444
        break;
      case PixelFormat.RGBA_5551:
        Log.v("SDL", "pixel format RGBA_5551");
        sdlFormat = 0x15441002; // SDL_PIXELFORMAT_RGBA5551
        break;
      case PixelFormat.RGBA_8888:
        Log.v("SDL", "pixel format RGBA_8888");
        sdlFormat = 0x16462004; // SDL_PIXELFORMAT_RGBA8888
        break;
      case PixelFormat.RGBX_8888:
        Log.v("SDL", "pixel format RGBX_8888");
        sdlFormat = 0x16261804; // SDL_PIXELFORMAT_RGBX8888
        break;
      case PixelFormat.RGB_332:
        Log.v("SDL", "pixel format RGB_332");
        sdlFormat = 0x14110801; // SDL_PIXELFORMAT_RGB332
        break;
      case PixelFormat.RGB_565:
        Log.v("SDL", "pixel format RGB_565");
        sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565
        break;
      case PixelFormat.RGB_888:
        Log.v("SDL", "pixel format RGB_888");
        // Not sure this is right, maybe SDL_PIXELFORMAT_RGB24 instead?
        sdlFormat = 0x16161804; // SDL_PIXELFORMAT_RGB888
        break;
      default:
        Log.v("SDL", "pixel format unknown " + format);
        break;
    }

    mWidth = width;
    mHeight = height;
    SDLActivity.onNativeResize(width, height, sdlFormat, mDisplay.getRefreshRate());
    Log.v("SDL", "Window size:" + width + "x" + height);

    // Set mIsSurfaceReady to 'true' *before* making a call to handleResume
    SDLActivity.mIsSurfaceReady = true;
    SDLActivity.onNativeSurfaceChanged();

    if (SDLActivity.mSDLThread == null) {
      // This is the entry point to the C app.
      // Start up the C app thread and enable sensor input for the first time

      final Thread sdlThread = new Thread(new SDLMain(), "SDLThread");
      enableSensor(Sensor.TYPE_ACCELEROMETER, true);
      sdlThread.start();

      // Set up a listener thread to catch when the native thread ends
      SDLActivity.mSDLThread =
          new Thread(
              new Runnable() {
                @Override
                public void run() {
                  try {
                    sdlThread.join();
                  } catch (Exception e) {
                  } finally {
                    // Native thread has finished
                    if (!SDLActivity.mExitCalledFromJava) {
                      SDLActivity.handleNativeExit();
                    }
                  }
                }
              },
              "SDLThreadListener");
      SDLActivity.mSDLThread.start();
    }
  }