-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
plugins { | ||
id 'com.android.application' | ||
} | ||
|
||
android { | ||
namespace 'com.example.sensorrecorder' | ||
compileSdk 33 | ||
|
||
defaultConfig { | ||
applicationId "com.example.sensorrecorder" | ||
minSdk 21 | ||
targetSdk 33 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
//noinspection GradleCompatible | ||
implementation 'com.android.support:appcompat-v7:28.0.0' | ||
implementation 'com.android.support.constraint:constraint-layout:2.0.4' | ||
implementation 'androidx.exifinterface:exifinterface:1.3.5' | ||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.2' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.example.sensorrecorder; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); | ||
assertEquals("com.example.sensorrecorder", appContext.getPackageName()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||
<application | ||
android:allowBackup="true" | ||
android:dataExtractionRules="@xml/data_extraction_rules" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.SensorRecorder" | ||
tools:targetApi="31"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
|
||
<meta-data | ||
android:name="android.app.lib_name" | ||
android:value="" /> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.example.sensorrecorder; | ||
|
||
import android.content.Context; | ||
import android.hardware.Sensor; | ||
import android.hardware.SensorEvent; | ||
import android.hardware.SensorEventListener; | ||
import android.hardware.SensorManager; | ||
import android.util.Log; | ||
|
||
|
||
public class Accelerometer { | ||
public interface Listener { | ||
void setText(String timeStamp, String x, String y, String z); | ||
} | ||
|
||
private Listener listener; | ||
|
||
public void setListener(Listener l) { | ||
listener = l; | ||
} | ||
|
||
private SensorManager sensorManager; | ||
private Sensor acc_sensor; | ||
private SensorEventListener sensorEventListener; | ||
private String timeStamp, x_acc, y_acc, z_acc; | ||
private int i = 0; | ||
|
||
public Accelerometer(Context context) { | ||
sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); | ||
acc_sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); | ||
sensorEventListener = new SensorEventListener() { | ||
@Override | ||
public void onSensorChanged(SensorEvent event) { | ||
timeStamp = utils.getTimeStamp(); | ||
x_acc = Float.toString(event.values[0]); | ||
y_acc = Float.toString(event.values[1]); | ||
z_acc = Float.toString(event.values[2]); | ||
Log.i("Freq ->", "acc " + i++); | ||
listener.setText(timeStamp, x_acc, y_acc, z_acc); | ||
} | ||
|
||
@Override | ||
public void onAccuracyChanged(Sensor sensor, int accuracy) { | ||
|
||
} | ||
}; | ||
|
||
} | ||
|
||
public void register(int sensitivity) { | ||
sensorManager.registerListener(sensorEventListener, acc_sensor, sensitivity); | ||
} | ||
|
||
public void unregister() { | ||
sensorManager.unregisterListener(sensorEventListener); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.example.sensorrecorder; | ||
|
||
import static android.support.v4.content.ContextCompat.getSystemService; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.hardware.Sensor; | ||
import android.hardware.SensorManager; | ||
import android.support.annotation.NonNull; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.widget.TextView; | ||
|
||
import java.util.List; | ||
|
||
public class DetectSensor{ | ||
private SensorManager sensorManager; | ||
private StringBuilder sbAllSensors = new StringBuilder(); | ||
|
||
public DetectSensor(Context context) { | ||
sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); | ||
List<Sensor> allSensors = sensorManager.getSensorList(Sensor.TYPE_ALL); | ||
sbAllSensors.append("This mobile phone has ").append(allSensors.size()).append(" sensors, include: \n\n"); | ||
for (Sensor s : allSensors) { | ||
switch (s.getType()) { | ||
case Sensor.TYPE_ACCELEROMETER: | ||
sbAllSensors.append(s.getType()).append(" Accelerometer sensor").append("\n").append("Sensor Name:\t").append(s.getName()).append("\n").append("Sensor Vendor:\t").append(s.getVendor()).append("\n").append("Sensor Power:\t").append(s.getPower()).append("\n").append("\n"); | ||
break; | ||
case Sensor.TYPE_GYROSCOPE: | ||
sbAllSensors.append(s.getType()).append(" Gyroscope sensor").append("\n").append("Sensor Name:\t").append(s.getName()).append("\n").append("Sensor Vendor:\t").append(s.getVendor()).append("\n").append("Sensor Power:\t").append(s.getPower()).append("\n").append("\n"); | ||
break; | ||
case Sensor.TYPE_MAGNETIC_FIELD: | ||
sbAllSensors.append(s.getType()).append(" Magnetic field sensor").append("\n").append("Sensor Name:\t").append(s.getName()).append("\n").append("Sensor Vendor:\t").append(s.getVendor()).append("\n").append("Sensor Power:\t").append(s.getPower()).append("\n").append("\n"); | ||
break; | ||
default: | ||
// sbAllSensors.append(s.getType()).append(" 其他传感器").append("\n").append("Sensor Name:\t").append(s.getName()).append("\n").append("Sensor Vendor:\t").append(s.getVendor()).append("\n").append("Sensor Power:\t").append(s.getPower()).append("\n"); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
public void setText(TextView tv){ | ||
tv.setText(sbAllSensors); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.example.sensorrecorder; | ||
|
||
import static com.example.sensorrecorder.MainActivity.start; | ||
|
||
import android.content.Context; | ||
import android.hardware.Sensor; | ||
import android.hardware.SensorEvent; | ||
import android.hardware.SensorEventListener; | ||
import android.hardware.SensorManager; | ||
import android.util.Log; | ||
|
||
public class Gyroscope { | ||
public interface Listener { | ||
void setText(String timeStamp, String x, String y, String z); | ||
} | ||
|
||
private Listener listener; | ||
|
||
public void setListener(Listener l) { | ||
listener = l; | ||
} | ||
|
||
private SensorManager sensorManager; | ||
private Sensor sensor; | ||
private SensorEventListener sensorEventListener; | ||
private String timeStamp, x, y, z; | ||
private int i = 0; | ||
|
||
public Gyroscope(Context context) { | ||
sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); | ||
sensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); | ||
sensorEventListener = new SensorEventListener() { | ||
@Override | ||
public void onSensorChanged(SensorEvent event) { | ||
timeStamp = utils.getTimeStamp(); | ||
x = Float.toString(event.values[0]); | ||
y = Float.toString(event.values[1]); | ||
z = Float.toString(event.values[2]); | ||
Log.i("Freq ->", "gyro "+ i++); | ||
listener.setText(timeStamp, x, y, z); | ||
} | ||
|
||
@Override | ||
public void onAccuracyChanged(Sensor sensor, int accuracy) { | ||
|
||
} | ||
}; | ||
} | ||
|
||
|
||
public void register(int sensitivity) { | ||
sensorManager.registerListener(sensorEventListener, sensor, sensitivity); | ||
} | ||
|
||
public void unregister() { | ||
sensorManager.unregisterListener(sensorEventListener); | ||
} | ||
} |