Commit 77e86d81 authored by s5_linde_o's avatar s5_linde_o
Browse files

Initial commit

parents
Pipeline #248 failed with stages
*.iml
.gradle
/local.properties
/.idea/caches/build_file_checksums.ser
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
.DS_Store
/build
/captures
.externalNativeBuild
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<Objective-C-extensions>
<file>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
</file>
<class>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
</class>
<extensions>
<pair source="cpp" header="h" fileNamingConvention="NONE" />
<pair source="c" header="h" fileNamingConvention="NONE" />
</extensions>
</Objective-C-extensions>
</code_scheme>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="7">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
<item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="6">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>
\ No newline at end of file
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.example.oskars.xyzregister_v2"
minSdkVersion 21
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
}
# 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
package com.example.oskars.xyzregister_v2;
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.getTargetContext();
assertEquals("com.example.oskars.xyzregister_v2", appContext.getPackageName());
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.oskars.xyzregister_v2">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
\ No newline at end of file
package com.example.oskars.xyzregister_v2;
// For data export
// C:\Users\Oskars\Downloads\adb>adb -d shell "run-as com.example.oskars.xyzregister_v2 cat /data/data/com.example.oskars.xyzregister_v2/files/accData.txt" > accData.txt
//Uzlikt ka failu uzmet uz 0, vai sāk jaunu ?
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.speech.tts.TextToSpeech;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.TextView;
import android.content.Context;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.sql.Timestamp;
import java.util.Locale;
import static java.lang.Math.abs;
public class MainActivity extends AppCompatActivity implements SensorEventListener, TextToSpeech.OnInitListener {
private static List<Float> x;
private static List<Float> y;
private static List<Float> z;
private TextView xValue;
private TextView yValue;
private TextView zValue;
private String xValueString;
private String yValueString;
private String zValueString;
private String dataLine;
private static int dataCounter;
private static boolean startDataRegister = false;
private static String filename;
private TextView test;
private TextView minutes;
private TextView hpButton;
private TextView orientationRecognitionTextview;
private EditText user;
private Switch walking;
private Switch up;
private Switch down;
private Switch standing;
private Switch limping;
private Switch headphones;
private Button one;
private Button five;
private Button ten;
private Button clear;
private Button orientationRecognitionButton;
private static String activityType;
private static String oldActivityType;
private static float meanAverageX = 0;
private static float meanAverageY = 0;
private static float meanAverageZ = 0;
private static float oldX = 0;
private static float oldY = 0;
private static float oldZ = 0;
private static float alpha = 0.01f;
private static int faceUpYupCounter = 0 ;
private static int faceUpYdownCounter = 0 ;
private static boolean isOrientationRecognitionEnabled = false;
private static boolean stopKickback = false;
private TextToSpeech textToSpeech;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
x = new ArrayList<>();
y = new ArrayList<>();
z = new ArrayList<>();
xValue = (TextView) findViewById(R.id.xValueTextview);
yValue = (TextView) findViewById(R.id.yValueTextview);
zValue = (TextView) findViewById(R.id.zValueTextview);
minutes = (TextView) findViewById(R.id.minutesTextview);
test = (TextView) findViewById(R.id.testValueTextview);
hpButton = (TextView) findViewById(R.id.buttonStateValueTextview);
orientationRecognitionTextview = (TextView) findViewById(R.id.orRecStateValueTextview);
walking = (Switch) findViewById(R.id.walkingSwitch);
up = (Switch) findViewById(R.id.upSwitch);
down = (Switch) findViewById(R.id.downSwitch);
standing = (Switch) findViewById(R.id.standingSwitch);
limping = (Switch) findViewById(R.id.limpingSwitch);
headphones = (Switch) findViewById(R.id.headphonesSwitch);
one = (Button) findViewById(R.id.oneButton);
five = (Button) findViewById(R.id.fiveButton);
ten = (Button) findViewById(R.id.tenButton);
clear = (Button) findViewById(R.id.clearButton);
orientationRecognitionButton = (Button) findViewById(R.id.bonus2Button);
user = (EditText) findViewById(R.id.userValueTextview);
one.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
minutes.setText("1");
}
});
five.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
minutes.setText("5");
}
});
ten.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
minutes.setText("10");
}
});
clear.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
test.setText("FILE CLEARED");
writeToFile(getBaseContext());
}
});
orientationRecognitionButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (orientationRecognitionTextview.getText() == "ON"){
orientationRecognitionTextview.setText("OFF");
isOrientationRecognitionEnabled = false;
}
else {
orientationRecognitionTextview.setText("ON");
isOrientationRecognitionEnabled = true;
}
faceUpYupCounter = 0;
faceUpYdownCounter = 0;
}
});
activityType = "0";
oldActivityType = "0";
textToSpeech = new TextToSpeech(this, this);
textToSpeech.setLanguage(Locale.US);
walking.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked){
activityType = "Walking";
up.setChecked(false);
down.setChecked(false);
standing.setChecked(false);
limping.setChecked(false);
}
}
});
up.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked){
activityType = "Upstairs";
walking.setChecked(false);
down.setChecked(false);
standing.setChecked(false);
limping.setChecked(false);
}
}
});
down.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked){
activityType = "Downstairs";
up.setChecked(false);
walking.setChecked(false);
standing.setChecked(false);
limping.setChecked(false);
}
}
});
standing.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked){
activityType = "Standing";
up.setChecked(false);
walking.setChecked(false);
down.setChecked(false);
limping.setChecked(false);
}
}
});
limping.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked){
activityType = "Limping";
up.setChecked(false);
walking.setChecked(false);
down.setChecked(false);
standing.setChecked(false);
}
}
});
headphones.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked){
test.setText("Headphone mode enabled");
}
}
});
}
protected void onResume() {
super.onResume();
getSensorManager().registerListener(this, getSensorManager().getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME);
//getSensorManager().registerListener(this, getSensorManager().getDefaultSensor(Sensor.TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_GAME);
}
protected void onPause() {
getSensorManager().unregisterListener(this);
super.onPause();
}
@Override
public void onInit(int status) {
}
@Override
public void onAccuracyChanged(Sensor sensor, int i) {
}
@Override
public void onSensorChanged(SensorEvent event) {
x.add(event.values[0]);
y.add(event.values[1]);
z.add(event.values[2]);
meanAverageX = (event.values[0]*alpha + meanAverageX * (1-alpha));
meanAverageY = (event.values[1]*alpha + meanAverageY * (1-alpha));
meanAverageZ = (event.values[2]*alpha + meanAverageZ * (1-alpha));
if (isOrientationRecognitionEnabled){
if(abs(meanAverageX) > abs(meanAverageY) && abs(meanAverageX) > abs(meanAverageZ)){
if (meanAverageX>0){
orientationRecognitionTextview.setText("Left Horizontal stand");
}else{
orientationRecognitionTextview.setText("Right Horizontal stand");
}
}
else if (abs(meanAverageY) > abs(meanAverageX) && abs(meanAverageY) > abs(meanAverageZ)){
if (meanAverageY>0){
orientationRecognitionTextview.setText("Vertical stand");
}else{
orientationRecognitionTextview.setText("Reverse Vertical stand");
}
}
else if (abs(meanAverageZ) > abs(meanAverageX) && abs(meanAverageZ) > abs(meanAverageY)){
if (meanAverageZ>0) {
orientationRecognitionTextview.setText("Face up Sleep");
}
else {
orientationRecognitionTextview.setText("Face down Sleep");
}
}
else {
orientationRecognitionTextview.setText("ERROR");
}
oldX = event.values[0];
oldY = event.values[1];
oldZ = event.values[2];
}
//orientationRecognitionTextview.setText(String.format("%s,%s,%s", abs(round(meanAverageX, 1)) , round(meanAverageY, 1), round(meanAverageZ, 1)));
xValueString = Float.toString(round(x.get(x.size() - 1), 2));
yValueString = Float.toString(round(y.get(y.size() - 1), 2));
zValueString = Float.toString(round(z.get(z.size() - 1), 2));
xValue.setText(xValueString);
yValue.setText(yValueString);
zValue.setText(zValueString);
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
if ((walking.isChecked() || up.isChecked() || down.isChecked() || standing.isChecked() || limping.isChecked()) && !headphones.isChecked()){
operateDataWriting(timestamp);
}
else if (headphones.isChecked() && (walking.isChecked() || up.isChecked() || down.isChecked() || standing.isChecked() || limping.isChecked()) && startDataRegister){
operateDataWritingWithHeadphones(timestamp);
}
else {
//activityType = "0";
//test.setText("");
one.setEnabled(true);
five.setEnabled(true);
ten.setEnabled(true);
dataCounter = 0;
}
oldActivityType = activityType;
if (startDataRegister){
hpButton.setText("Button pressed");
}
else {
hpButton.setText("Button not pressed");
}
}
private static float round(float d, int decimalPlace) {
BigDecimal bd = new BigDecimal(Float.toString(d));
bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP);
return bd.floatValue();
}
private SensorManager getSensorManager() {
return (SensorManager) getSystemService(SENSOR_SERVICE);
}
private void writeToFile(String data,Context context) {