Added hardware-check to verify availability of gyroscope. If unavailable, a message will be displayed when the app is launched.
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.hitlabnz.sensor_fusion_demo"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" >
|
||||
android:versionCode="3"
|
||||
android:versionName="1.2" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="11"
|
||||
android:targetSdkVersion="18" />
|
||||
android:targetSdkVersion="19" />
|
||||
|
||||
<application
|
||||
android:allowBackup="false"
|
||||
|
||||
@@ -11,4 +11,4 @@
|
||||
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
||||
|
||||
# Project target.
|
||||
target=android-18
|
||||
target=android-19
|
||||
|
||||
@@ -12,5 +12,8 @@
|
||||
<string name="title_section6">Akzelerometer und Kompass</string>
|
||||
<string name="title_activity_sensor_selection">Sensorfusions Demo</string>
|
||||
<string name="title_activity_about">Über</string>
|
||||
|
||||
<string name="gyroscope_missing">Fehlendes Gyroskop</string>
|
||||
<string name="gyroscope_missing_message">Dieses Gerät hat keinen Gyroskop-Sensor der aber notwendig ist, damit diese App richtig funktioniert. Bitte verwende ein aktuelleres Gerät, das ein Gyroskop hat.</string>
|
||||
<string name="OK">OK</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -12,5 +12,8 @@
|
||||
<string name="title_section6">Accelerometer and Compass</string>
|
||||
<string name="title_activity_sensor_selection">Sensor fusion demo</string>
|
||||
<string name="title_activity_about">About</string>
|
||||
<string name="gyroscope_missing">Gyroscope Missing</string>
|
||||
<string name="gyroscope_missing_message">Your device has no hardware gyroscope sensor, which would be necessary for this app to work properly. Please run it on a newer device that has a gyroscope.</string>
|
||||
<string name="OK">OK</string>
|
||||
|
||||
</resources>
|
||||
|
||||
27
src/org/hitlabnz/sensor_fusion_demo/HardwareChecker.java
Normal file
27
src/org/hitlabnz/sensor_fusion_demo/HardwareChecker.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package org.hitlabnz.sensor_fusion_demo;
|
||||
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorManager;
|
||||
|
||||
/**
|
||||
* Class that tests availability of hardware sensors.
|
||||
*
|
||||
* @author Alex
|
||||
*
|
||||
*/
|
||||
public class HardwareChecker implements SensorChecker {
|
||||
|
||||
boolean gyroscopeIsAvailable = false;
|
||||
|
||||
public HardwareChecker (SensorManager sensorManager) {
|
||||
if(sensorManager.getSensorList(Sensor.TYPE_GYROSCOPE).size() > 0) {
|
||||
gyroscopeIsAvailable = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean IsGyroscopeAvailable() {
|
||||
return gyroscopeIsAvailable;
|
||||
}
|
||||
|
||||
}
|
||||
11
src/org/hitlabnz/sensor_fusion_demo/SensorChecker.java
Normal file
11
src/org/hitlabnz/sensor_fusion_demo/SensorChecker.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package org.hitlabnz.sensor_fusion_demo;
|
||||
|
||||
public interface SensorChecker {
|
||||
|
||||
/**
|
||||
* Checks if the device that is currently running the application has a hardware gyroscope built into it.
|
||||
*
|
||||
* @return True, if a gyroscope is available. False otherwise.
|
||||
*/
|
||||
public boolean IsGyroscopeAvailable ();
|
||||
}
|
||||
@@ -10,6 +10,8 @@ import org.hitlabnz.sensor_fusion_demo.orientationProvider.ImprovedOrientationSe
|
||||
import org.hitlabnz.sensor_fusion_demo.orientationProvider.OrientationProvider;
|
||||
import org.hitlabnz.sensor_fusion_demo.orientationProvider.RotationVectorProvider;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.hardware.SensorManager;
|
||||
import android.opengl.GLSurfaceView;
|
||||
@@ -61,9 +63,29 @@ public class SensorSelectionActivity extends FragmentActivity {
|
||||
mViewPager = (ViewPager) findViewById(R.id.pager);
|
||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||
|
||||
// Check if device has a hardware gyroscope
|
||||
SensorChecker checker = new HardwareChecker((SensorManager) getSystemService(SENSOR_SERVICE));
|
||||
if(!checker.IsGyroscopeAvailable()) {
|
||||
// If a gyroscope is unavailable, display a warning.
|
||||
displayHardwareMissingWarning();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
private void displayHardwareMissingWarning() {
|
||||
AlertDialog ad = new AlertDialog.Builder(this).create();
|
||||
ad.setCancelable(false); // This blocks the 'BACK' button
|
||||
ad.setTitle(getResources().getString(R.string.gyroscope_missing));
|
||||
ad.setMessage(getResources().getString(R.string.gyroscope_missing_message));
|
||||
ad.setButton(DialogInterface.BUTTON_NEUTRAL, getResources().getString(R.string.OK), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
ad.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.sensor_selection, menu);
|
||||
|
||||
Reference in New Issue
Block a user