Android Open Source - zomblind Zomblind Activity






From Project

Back to project page zomblind.

License

The source code is released under:

Apache License

If you think the Android project zomblind listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*******************************************************************************
 * Copyright 2013 Antonio Fern?ndez Ares (antares.es@gmail.com)
 * /*  w w w . java2s. co  m*/
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package antares.zomblind;

import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.Toast;
import antares.zomblind.core.*;
import antares.zomblind.in.*;
import antares.zomblind.out.*;

public class ZomblindActivity extends Activity {

  // Clases de control de entrada IN
  public Acelerometro _acelerometro = new Acelerometro(this);
  public Orientacion _orientacion = new Orientacion(this);
  public Pantalla _pantalla;

  // Clases de control de salida OUT
  public Debug _debug;
  public Interfaz _interfaz;
  public Habladora _habladora = new Habladora(this);
  public TextToSpeech _talker;
  public Vibrador _vibrador;

  // Clases manejadoras de eventos
  private static SensorManager _sensorServiceOrientacion;
  private static SensorManager _sensorServiceAcelerometro;
  private Sensor _sensorOrientacion, _sensorAcelerometro;

  // Clase de entorno de juego
  public Nucleo _entorno = null;

  // Variables booleanas de control
  public Boolean salir = false;
  public Boolean empezar = false;
  public Boolean muerto = false;

  protected void onCreate(Bundle savedInstanceState) {
    // Creamos la actividad
    super.onCreate(savedInstanceState);

    // Definimos su vista
    _interfaz = new Interfaz(this);
    setContentView(_interfaz);

    // Bloqueamos la orientaci?n
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    //Definimos los manejadores de la interfaz
    _pantalla = new Pantalla(this);
    _vibrador = new Vibrador(this);

    // Inicializamos el sensor de orientaci?n
    _sensorServiceOrientacion = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    _sensorOrientacion = _sensorServiceOrientacion
        .getDefaultSensor(Sensor.TYPE_ORIENTATION);
    if (_sensorOrientacion != null) {
      _sensorServiceOrientacion.registerListener(
          mySensorEventListenerOrientacion, _sensorOrientacion,
          SensorManager.SENSOR_DELAY_GAME);
      Log.i("Compass MainActivity", "Registerered for ORIENTATION Sensor");

    } else {
      Log.e("Compass MainActivity", "Registerered for ORIENTATION Sensor");
      Toast.makeText(this, "ORIENTATION Sensor not found",
          Toast.LENGTH_LONG).show();
      finish();
    }

    // Inicializamos el sensor de aceleraci?n
    _sensorServiceAcelerometro = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    _sensorAcelerometro = _sensorServiceAcelerometro
        .getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    if (_sensorAcelerometro != null) {
      _sensorServiceAcelerometro.registerListener(
          mySensorEventListenerAceleracion, _sensorAcelerometro,
          SensorManager.SENSOR_DELAY_GAME);
      Log.i("Compass MainActivity",
          "Registerered for ACCELEROMETERSensor");

    } else {
      Log.e("Compass MainActivity",
          "Registerered for ACCELEROMETER Sensor");
      Toast.makeText(this, "ACCELEROMETER Sensor not found",
          Toast.LENGTH_LONG).show();
      finish();
    }

    //_entorno = new Nucleo(this);
    _talker = new TextToSpeech(this, _habladora);
    _entorno = new Nucleo(this);
    _debug = new Debug(this);

  }

  private SensorEventListener mySensorEventListenerOrientacion = new SensorEventListener() {

    public void onAccuracyChanged(Sensor sensor, int accuracy) {
    }

    public void onSensorChanged(SensorEvent event) {
      if (!_orientacion.isCalibrate()) {
        _orientacion.calibrate(event);
      } else {
        _orientacion.update(event);
        _interfaz.invalidate();
      }
    }

  };

  private SensorEventListener mySensorEventListenerAceleracion = new SensorEventListener() {

    public void onAccuracyChanged(Sensor sensor, int accuracy) {
    }
    
    public void onSensorChanged(SensorEvent event) {
      synchronized (this) {
        _acelerometro.update(event);
      }
      _interfaz.invalidate();
    }

  };

  // Capturamos las pulsaciones de teclas
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_HOME)) {
      Log.d(this.getClass().getName(), "back button pressed");
      if (salir == true) {
        _entorno._eventos.cancel();
        _talker.shutdown();
        this.finish();
      } else {
        _habladora.decir(getString(R.string.speaker_button_back_exit));
        salir = true;
        return true;
      }
    } else if ((keyCode == KeyEvent.KEYCODE_MENU)) {
      _debug.change();
    } else if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
      this._habladora.decir("M?s volumen");
      return super.onKeyDown(keyCode, event);

    } else if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
      this._habladora.decir("Menos volumen");
      return super.onKeyDown(keyCode, event);
    }
    return super.onKeyDown(keyCode, event);
  }

  public boolean onKeyUp(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
      Log.i(this.getClass().getName(), "Volume Up button release");
      return true;
    }
    return super.onKeyUp(keyCode, event);
  }
}




Java Source Code List

antares.zomblind.ZomblindActivity.java
antares.zomblind.core.Jugador.java
antares.zomblind.core.Nucleo.java
antares.zomblind.core.levels.L000_menu.java
antares.zomblind.core.levels.NivelInfo.java
antares.zomblind.core.levels.checker.GolpeFrontal.java
antares.zomblind.core.levels.checker.Todos.java
antares.zomblind.core.levels.checker._Chequeador.java
antares.zomblind.core.levels.conditions.SinZombies.java
antares.zomblind.core.levels.conditions._Condicion.java
antares.zomblind.core.levels.generate.AleatorioFlojos.java
antares.zomblind.core.levels.generate.AleatorioTodos.java
antares.zomblind.core.levels.generate._Generador.java
antares.zomblind.core.levels.instancia.java
antares.zomblind.core.npcs.NpcData.java
antares.zomblind.core.npcs.NpcLista.java
antares.zomblind.core.npcs.npc.java
antares.zomblind.core.objetos.ArmaData.java
antares.zomblind.core.objetos.ArmaLista.java
antares.zomblind.core.objetos.Arma.java
antares.zomblind.core.objetos.Municion.java
antares.zomblind.core.opciones.java
antares.zomblind.in.acelerometro.java
antares.zomblind.in.orientacion.java
antares.zomblind.in.pantalla.java
antares.zomblind.in.teclado.java
antares.zomblind.out.debug.java
antares.zomblind.out.habladora.java
antares.zomblind.out.interfaz.java
antares.zomblind.out.vibrador.java