Skip to content
This repository was archived by the owner on Aug 31, 2020. It is now read-only.

Commit

Permalink
lvl3 - level working
Browse files Browse the repository at this point in the history
  • Loading branch information
WojciechSova committed Jul 13, 2020
1 parent 976f184 commit f0f05a5
Show file tree
Hide file tree
Showing 9 changed files with 285 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
.externalNativeBuild
.cxx
/.idea/
/app/release/
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</intent-filter>
</activity>
<activity android:name=".Levels"/>
<activity android:name=".Lvl3"/>
<activity android:name=".levels.Lvl3"/>
</application>

</manifest>
13 changes: 13 additions & 0 deletions app/src/main/java/com/g09/Levels.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,35 @@
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.g09.levels.Lvl3;

import javax.xml.datatype.Duration;

public class Levels extends AppCompatActivity {
private static Boolean[] levelComplete = new Boolean[7];
Duration[] levelTime = new Duration[7];
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.levels);
Button lvl3BTN = (Button)findViewById(R.id.lvl3BTN);
// LinearLayout lin = (LinearLayout)findViewById(R.id.linear);
// Button lvl1 = lin.findViewWithTag("lvl1");
// lvl1.setText("aaa");
lvl3BTN.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(getApplicationContext(), Lvl3.class));
}
});
}
static public void completeLevel(int level) {
levelComplete[level-1] = true;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.g09;
package com.g09.levels;


import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
Expand All @@ -16,9 +16,11 @@

import com.g09.R;

public class Lvl3 extends AppCompatActivity implements SensorEventListener {

public class ClassForHelp extends AppCompatActivity implements SensorEventListener {

TextView txt_compass;
TextView lvl3text;
int mAzimuth;
private SensorManager mSensorManager;
private Sensor mRotationV, mAccelerometer, mMagnetometer;
Expand All @@ -36,14 +38,16 @@ public class Lvl3 extends AppCompatActivity implements SensorEventListener {
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lvl3);

lvl3text = (TextView)findViewById(R.id.lvl3txt);
lvl3text.setText("aaa");
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
txt_compass = (TextView) findViewById(R.id.txt_azimuth);

start();
}

public void start() {
System.out.println("bbb");
if (mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR) == null) {
if ((mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) == null) || (mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) == null)) {
noSensorsAlert();
Expand All @@ -59,6 +63,7 @@ public void start() {
mRotationV = mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
haveSensor = mSensorManager.registerListener(this, mRotationV, SensorManager.SENSOR_DELAY_UI);
}

}

public void noSensorsAlert() {
Expand Down Expand Up @@ -87,6 +92,7 @@ public void stop() {
@Override
protected void onPause() {
super.onPause();
System.out.println("stop");
stop();
}

Expand All @@ -96,8 +102,10 @@ protected void onResume() {
start();
}

@SuppressLint("SetTextI18n")
@Override
public void onSensorChanged(SensorEvent event) {
System.out.println("aaaa");
if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
SensorManager.getRotationMatrixFromVector(rMat, event.values);
mAzimuth = (int) (Math.toDegrees(SensorManager.getOrientation(rMat, orientation)[0]) + 360) % 360;
Expand All @@ -106,23 +114,43 @@ public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
System.arraycopy(event.values, 0, mLastAccelerometer, 0, event.values.length);
mLastAccelerometerSet = true;
System.out.println("111111111");
} else if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
System.arraycopy(event.values, 0, mLastMagnetometer, 0, event.values.length);
mLastMagnetometerSet = true;
System.out.println("22222222");
}

if (mLastAccelerometerSet && mLastMagnetometerSet) {
SensorManager.getRotationMatrix(rMat, null, mLastAccelerometer, mLastMagnetometer);
SensorManager.getOrientation(rMat, orientation);
mAzimuth = (int) (Math.toDegrees(SensorManager.getOrientation(rMat, orientation)[0]) + 360) % 360;
System.out.println("truuuuuue");
}

// System.out.println("rmat");
// for (int i = 0; i<9; i++) {
// System.out.println(i+ " " + rMat[i] + "\n");
// }
// System.out.println("orient");
// for (int i = 0; i<3; i++) {
// System.out.println(i+ " " + orientation[i] + "\n");
// }
mAzimuth = Math.round(mAzimuth);

System.out.println("values");
for (int i = 0; i<event.values.length; i++) {
System.out.println(i+ " " + event.values[i] + "\n");
}

String where = "NW";

if (mAzimuth >= 350 || mAzimuth <= 10)
if (mAzimuth >= 350 || mAzimuth <= 10) {
where = "N";
if(mLastAccelerometer[2] < -8) {

lvl3text.setText("Udalo sie");
}
}

if (mAzimuth < 350 && mAzimuth > 280)
where = "NW";
if (mAzimuth <= 280 && mAzimuth > 260)
Expand All @@ -140,10 +168,18 @@ public void onSensorChanged(SensorEvent event) {


txt_compass.setText(mAzimuth + "° " + where);

for (int i = 0; i<3; i++) {
System.out.println(i+ " " + mLastAccelerometer[i] + "\n");
}
for (int i = 0; i<mLastMagnetometer.length; i++) {
System.out.println(i+ " " + mLastMagnetometer[i] + "\n");
}
//wartosc mLastAccelerometer[2] musi być mniejsza niż -8 (przyspieszenie ziemskie)
}

@Override
public void onAccuracyChanged(Sensor sensor, int i) {

System.out.println("accuracy");
}
}
130 changes: 130 additions & 0 deletions app/src/main/java/com/g09/levels/Lvl3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package com.g09.levels;


import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.g09.R;


public class Lvl3 extends AppCompatActivity implements SensorEventListener {

TextView txt_compass;
int mAzimuth;
private SensorManager mSensorManager;
private Sensor mAccelerometer, mMagnetometer;
float[] rMat = new float[9];
float[] orientation = new float[3];
private float[] mLastAccelerometer = new float[3];
private float[] mLastMagnetometer = new float[3];



@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lvl3);
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
txt_compass = (TextView) findViewById(R.id.txt_azimuth);

start();
}

public void start() {
if ((mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) == null) || (mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) == null)) {
noSensorsAlert();
}
else {
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mMagnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
}
}

public void noSensorsAlert() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setMessage("Your device doesn't support the sensors used in level.")
.setCancelable(false)
.setNegativeButton("Close",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
alertDialog.show();
}

public void stop() {
mSensorManager.unregisterListener(this,mAccelerometer);
mSensorManager.unregisterListener(this,mMagnetometer);
}

@Override
protected void onPause() {
super.onPause();
System.out.println("stop");
stop();
}

@Override
protected void onResume() {
super.onResume();
start();
}

@SuppressLint("SetTextI18n")
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
System.arraycopy(event.values, 0, mLastAccelerometer, 0, event.values.length);
} else if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
System.arraycopy(event.values, 0, mLastMagnetometer, 0, event.values.length);
}
SensorManager.getRotationMatrix(rMat, null, mLastAccelerometer, mLastMagnetometer);
SensorManager.getOrientation(rMat, orientation);
mAzimuth = (int) (Math.toDegrees(SensorManager.getOrientation(rMat, orientation)[0]) + 360) % 360;


mAzimuth = Math.round(mAzimuth);


String where = "NW";

if (mAzimuth >= 350 || mAzimuth <= 10) {
where = "N";
if(mLastAccelerometer[2] < -8) { //wartosc mLastAccelerometer[2] musi być mniejsza niż -8 (przyspieszenie ziemskie)
where += " udalo sie";
//Miejsce na funkcję, konczaca level
}
}
if (mAzimuth < 350 && mAzimuth > 280)
where = "NW";
if (mAzimuth <= 280 && mAzimuth > 260)
where = "W";
if (mAzimuth <= 260 && mAzimuth > 190)
where = "SW";
if (mAzimuth <= 190 && mAzimuth > 170)
where = "S";
if (mAzimuth <= 170 && mAzimuth > 100)
where = "SE";
if (mAzimuth <= 100 && mAzimuth > 80)
where = "E";
if (mAzimuth <= 80 && mAzimuth > 10)
where = "NE";


txt_compass.setText(mAzimuth + "° " + where);
}

@Override
public void onAccuracyChanged(Sensor sensor, int i) {
}
}
67 changes: 67 additions & 0 deletions app/src/main/java/com/g09/levels/Lvl6.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.g09.levels;

import android.content.DialogInterface;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class Lvl6 extends AppCompatActivity implements SensorEventListener {
private SensorManager mSensorManager;
private Sensor mRotationV;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

}

public void start() {


}
public void stop() {

}

@Override
protected void onPause() {
super.onPause();
stop();
}

@Override
protected void onResume() {
super.onResume();
start();
}

public void noSensorsAlert() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setMessage("Your device doesn't support the Compass.")
.setCancelable(false)
.setNegativeButton("Close",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
alertDialog.show();
}

@Override
public void onSensorChanged(SensorEvent sensorEvent) {

}

@Override
public void onAccuracyChanged(Sensor sensor, int i) {

}
}
Binary file added app/src/main/res/drawable/lvl3image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit f0f05a5

Please sign in to comment.