blob: 5957c94391ea15a62c42a4af617f5cdc3a50d357 [file] [log] [blame]
Jason Sams177f8442010-10-29 10:19:21 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.balls;
18
19import android.renderscript.RSSurfaceView;
20import android.renderscript.RenderScript;
21
22import android.app.Activity;
23import android.content.res.Configuration;
24import android.os.Bundle;
25import android.os.Handler;
26import android.os.Looper;
27import android.os.Message;
28import android.provider.Settings.System;
29import android.util.Config;
30import android.util.Log;
31import android.view.Menu;
32import android.view.MenuItem;
33import android.view.View;
34import android.view.Window;
35import android.widget.Button;
36import android.widget.ListView;
37
38import java.lang.Runtime;
39
40import android.app.Activity;
41import android.content.Context;
42import android.os.Bundle;
43import android.view.View;
44import android.hardware.Sensor;
45import android.hardware.SensorEvent;
46import android.hardware.SensorEventListener;
47import android.hardware.SensorManager;
48
49public class Balls extends Activity implements SensorEventListener {
50 //EventListener mListener = new EventListener();
51
52 private static final String LOG_TAG = "libRS_jni";
53 private static final boolean DEBUG = false;
54 private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;
55
56 private BallsView mView;
57 private SensorManager mSensorManager;
58
59 // get the current looper (from your Activity UI thread for instance
60
61
62 public void onSensorChanged(SensorEvent event) {
63 //android.util.Log.d("rs", "sensor: " + event.sensor + ", x: " + event.values[0] + ", y: " + event.values[1] + ", z: " + event.values[2]);
64 synchronized (this) {
65 if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
66 if(mView != null) {
67 mView.setAccel(event.values[0], event.values[1], event.values[2]);
68 }
69 }
70 }
71 }
72
73 public void onAccuracyChanged(Sensor sensor, int accuracy) {
74 }
75
76 @Override
77 public void onCreate(Bundle icicle) {
78 super.onCreate(icicle);
79
80 mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
81
82 // Create our Preview view and set it as the content of our
83 // Activity
84 mView = new BallsView(this);
85 setContentView(mView);
86 }
87
88 @Override
89 protected void onResume() {
90 mSensorManager.registerListener(this,
91 mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
92 SensorManager.SENSOR_DELAY_FASTEST);
93
94 // Ideally a game should implement onResume() and onPause()
95 // to take appropriate action when the activity looses focus
96 super.onResume();
97 mView.onResume();
98 }
99
100 @Override
101 protected void onPause() {
102 Log.e("rs", "onPause");
103
104 // Ideally a game should implement onResume() and onPause()
105 // to take appropriate action when the activity looses focus
106 super.onPause();
107 mView.onPause();
108
109
110
111 //Runtime.getRuntime().exit(0);
112 }
113
114 @Override
115 protected void onStop() {
116 mSensorManager.unregisterListener(this);
117 super.onStop();
118 }
119
120 static void log(String message) {
121 if (LOG_ENABLED) {
122 Log.v(LOG_TAG, message);
123 }
124 }
125
126
127}
128