mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-20 23:56:20 +08:00
Removing the assets phonegap.js
This commit is contained in:
parent
87b5c1255a
commit
9957dfca73
File diff suppressed because it is too large
Load Diff
54
src/com/phonegap/demo/CompassListener.java
Normal file
54
src/com/phonegap/demo/CompassListener.java
Normal file
@ -0,0 +1,54 @@
|
||||
package com.phonegap.demo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.content.Context;
|
||||
import android.webkit.WebView;
|
||||
|
||||
public class CompassListener implements SensorEventListener{
|
||||
WebView mAppView;
|
||||
Context mCtx;
|
||||
Sensor mSensor;
|
||||
|
||||
private SensorManager sensorManager;
|
||||
|
||||
CompassListener(Context ctx, WebView appView)
|
||||
{
|
||||
mCtx = ctx;
|
||||
mAppView = appView;
|
||||
sensorManager = (SensorManager) mCtx.getSystemService(Context.SENSOR_SERVICE);
|
||||
}
|
||||
|
||||
|
||||
public void start()
|
||||
{
|
||||
List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_ORIENTATION);
|
||||
if (list.size() > 0)
|
||||
{
|
||||
this.mSensor = list.get(0);
|
||||
this.sensorManager.registerListener(this, this.mSensor, SensorManager.SENSOR_DELAY_NORMAL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void stop()
|
||||
{
|
||||
this.sensorManager.unregisterListener(this);
|
||||
}
|
||||
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
// We only care about the orientation as far as it refers to Magnetic North
|
||||
float heading = event.values[0];
|
||||
mAppView.loadUrl("javascript:gotBearing(" + heading + ")");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user