Skip to content
Snippets Groups Projects
Commit 3a54cdbd authored by Peter Joseph De Jonckheere CESM2014's avatar Peter Joseph De Jonckheere CESM2014
Browse files

Added notification clicked class which will be the activity when a...

Added notification clicked class which will be the activity when a notification is clicked on. This will also add information to a file stored in external storage containing information about the notification. This will be compiled into statistics following a user trial.
parent a615f560
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@ import android.os.Build;
import android.support.v4.app.NotificationCompat;
import com.example.pharmacy.frontEnd.MainActivity;
import com.example.pharmacy.frontEnd.NotificationClicked;
/**
* Created by pharmacy on 09/01/2018.
......@@ -41,7 +42,7 @@ public abstract class Notification extends Service{
//Up to set Content Intent taken from developers page and must be refined or if works cited.
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, MainActivity.class);
Intent resultIntent = new Intent(this, NotificationClicked.class);
// The stack builder object will contain an artificial back stack for the
// started Activity.
......@@ -49,7 +50,7 @@ public abstract class Notification extends Service{
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addParentStack(NotificationClicked.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
......
package com.example.pharmacy.frontEnd;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
/**
* Created by pharmacy on 22/01/2018.
*/
public class NotificationClicked extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recordClick();
}
private void recordClick() {
int ns;
int nc;
int na;
if (isExternalStorageMounted()) {
File dir = getDirectory();
if (dir.isDirectory()) {
File file = new File(dir.getAbsolutePath() + "NLOG");
if (file.isFile() & file.canRead()) {
try {
BufferedReader br = new BufferedReader(new FileReader(file));
ns = Integer.parseInt(br.readLine());
nc = Integer.parseInt(br.readLine());
na = Integer.parseInt(br.readLine());
if (file.isFile() & file.canWrite()) {
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
nc++;
bw.write(ns);
bw.newLine();
bw.write(nc);
bw.newLine();
bw.write(na);
}
}catch (IOException e) {
}
}
}
}
}
/* Checks if external storage is available */
public boolean isExternalStorageMounted() {
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
return true;
}
return false;
}
/* Checks if external storage is available to at least read */
public boolean isExternalStorageReadable() {
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) ||
Environment.MEDIA_MOUNTED_READ_ONLY.equals(Environment.getExternalStorageState())) {
return true;
}
return false;
}
public File getDirectory(){
File file = new File(this.getExternalFilesDir(
Environment.DIRECTORY_DOCUMENTS), "NOTLOGS");
if (!file.mkdirs()) {
Log.e("ERR", "Directory not created");
}
return file;
}
}
package com.example.stimulusStrategy;
import android.app.Notification;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.IBinder;
import android.support.annotation.Nullable;
......@@ -12,10 +15,11 @@ import android.support.annotation.Nullable;
* Created by pharmacy on 17/01/2018.
*/
public class LinearAcceleration extends Service implements StimulusStrategy {
public class LinearAcceleration extends Service implements StimulusStrategy, SensorEventListener {
private SensorManager mSensorManager;
private Sensor laccl;
private final float calibrationValue = 1;
@Override
public void onCreate(){
......@@ -25,7 +29,8 @@ public class LinearAcceleration extends Service implements StimulusStrategy {
public void monitor() {
Intent i = new Intent(this, Notification.class);
this.sendBroadcast(i);
}
@Nullable
......@@ -33,4 +38,19 @@ public class LinearAcceleration extends Service implements StimulusStrategy {
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
for(float value: sensorEvent.values){
if(value < calibrationValue){
return;
}
}
monitor();
}
@Override
public void onAccuracyChanged(Sensor sensor, int i) {
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment