Android Open Source - android-jplay J Play Activity






From Project

Back to project page android-jplay.

License

The source code is released under:

Copyright (c) Nikolaj Baer All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. ...

If you think the Android project android-jplay 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

package com.nikolajbaer.androidrender;
//  ww  w .j av a  2s. com
import android.util.Log;
import android.view.Window;
import android.view.View;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.view.MotionEvent;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.GestureDetector;
import android.view.View;
import android.view.View.OnKeyListener;
import android.view.KeyEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorEvent;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.content.Context;
import android.content.pm.ActivityInfo;

public class JPlayActivity extends Activity
{
    private JPlayView mView;
    private SensorManager mSensorManager;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        mView = (JPlayView)findViewById(R.id.jplay);

        mSensorManager=(SensorManager)getSystemService(SENSOR_SERVICE);

        // TODO handle phones without accelerometers
        mSensorManager=(SensorManager)getSystemService(Context.SENSOR_SERVICE);
        mSensorManager.registerListener(listener,
                                        mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
                                        SensorManager.SENSOR_DELAY_GAME);

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mSensorManager.unregisterListener(listener);
    }

    private SensorEventListener listener=new SensorEventListener() {
        public void onSensorChanged(SensorEvent e) {
            //Log.v("MySensors","Got "+e.values[0]+" and "+e.values[1]);
            float x=e.values[0]/5.0f;
            float y=e.values[1]/5.0f;
            if(x>1.0f){ x=1.0f; }else if(x<-1.0f){ x=-1.0f; }
            if(y>1.0f){ y=1.0f; }else if(y<-1.0f){ y=-1.0f; }
            mView.applyTilt(x,y);
        }
 
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
            // unused
        }
    };

}




Java Source Code List

com.nikolajbaer.Util.java
com.nikolajbaer.androidrender.AndroidRenderObject.java
com.nikolajbaer.androidrender.DotRenderObject.java
com.nikolajbaer.androidrender.DrawableRenderObject.java
com.nikolajbaer.androidrender.JPlayActivity.java
com.nikolajbaer.androidrender.JPlayThread.java
com.nikolajbaer.androidrender.JPlayView.java
com.nikolajbaer.androidrender.PolygonRenderObject.java
com.nikolajbaer.awtrender.AWTRenderObject.java
com.nikolajbaer.awtrender.JPlay.java
com.nikolajbaer.awtrender.PNGRenderObject.java
com.nikolajbaer.awtrender.PolygonRenderObject.java
com.nikolajbaer.awtrender.RectRenderObject.java
com.nikolajbaer.game.Game.java
com.nikolajbaer.game.objects.BulletObject.java
com.nikolajbaer.game.objects.GameObjectEventListener.java
com.nikolajbaer.game.objects.GameObjectEvent.java
com.nikolajbaer.game.objects.GameObject.java
com.nikolajbaer.game.objects.ObstacleObject.java
com.nikolajbaer.game.objects.PlayerObject.java
com.nikolajbaer.game.objects.PolygonGameObject.java
com.nikolajbaer.game.objects.ShrapnelObject.java
com.nikolajbaer.game.players.GamePlayer.java
com.nikolajbaer.game.players.HunterPlayer.java
com.nikolajbaer.game.players.LambPlayer.java
com.nikolajbaer.game.players.LivePlayer.java
com.nikolajbaer.game.weapons.Blaster.java
com.nikolajbaer.game.weapons.TankCannon.java
com.nikolajbaer.game.weapons.Weapon.java
com.nikolajbaer.render.RenderObject.java
com.nikolajbaer.render.Renderable.java