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

Further attempts to fix spinner. Narrowed error down to null pointer at...

Further attempts to fix spinner. Narrowed error down to null pointer at setAdapter line either spinner or adapter is null but on debug inspection this doesn't appear to be the case.
parent 4222f22e
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,8 @@ import android.widget.Button;
import com.example.stimulus.Stimulus;
import com.example.stimulus.SedentaryStimulus;
import com.example.stimulusStrategy.Accelerometer;
import com.example.stimulusStrategy.Clock;
import com.example.stimulusStrategy.SigMotionDetect;
public class MainActivity extends AppCompatActivity {
......@@ -33,7 +35,7 @@ public class MainActivity extends AppCompatActivity {
}
private void setUpStimulus(){
Stimulus stimulus = new SedentaryStimulus(this, new SigMotionDetect());
Stimulus stimulus = new SedentaryStimulus(this, new Clock());
}
......
......@@ -4,6 +4,7 @@ package com.example.pharmacy.frontEnd;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
......@@ -35,12 +36,13 @@ public class Settings extends AppCompatActivity{
((CheckBox)findViewById(R.id.Audio)).setChecked(shared.getBoolean(getString(R.string.audio), false));
((CheckBox)findViewById(R.id.Vibration)).setChecked(shared.getBoolean(getString(R.string.vibration), false));
((CheckBox)findViewById(R.id.LEDFlash)).setChecked(shared.getBoolean(getString(R.string.led), false));
((Spinner)findViewById(R.id.spinner)).setSelection(shared.getInt(getString(R.string.daily_goal), R.integer.notify_period_minutes));
((Spinner)findViewById(R.id.PeriodSpinner)).setSelection(shared.getInt(getString(R.string.daily_goal), R.integer.notify_period_minutes));
((EditText)findViewById(R.id.notificationMessage)).setText(shared.getString(getString(R.string.daily_goal_text), getString(R.string.notf_text)));
}
private void setUpButtons(){
ImageButton back = (ImageButton)findViewById(R.id.back);
back.bringToFront();
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
......@@ -56,8 +58,14 @@ public class Settings extends AppCompatActivity{
}
private void populateSpinner(){
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.notification_periods, android.R.layout.simple_spinner_item);
Spinner spinner = findViewById(R.id.PeriodSpinner);
Resources r = this.getResources();
String[] periods = r.getStringArray(R.array.notification_periods);
//ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, periods);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item,
android.R.id.text1, periods);
// ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.notification_periods, android.R.layout.simple_spinner_dropdown_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
}
......@@ -70,7 +78,7 @@ public class Settings extends AppCompatActivity{
boolean audio = ((CheckBox)findViewById(R.id.Audio)).isChecked();
boolean vibration = ((CheckBox)findViewById(R.id.Vibration)).isChecked();
boolean led = ((CheckBox)findViewById(R.id.LEDFlash)).isChecked();
int notifyGap = ((Spinner)findViewById(R.id.spinner)).getSelectedItemPosition();//???
int notifyGap = ((Spinner)findViewById(R.id.PeriodSpinner)).getSelectedItemPosition();//???
String message = ((EditText)findViewById(R.id.notificationMessage)).getText().toString();
SharedPreferences sharedPref = view.getContext().getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
......
......@@ -10,7 +10,7 @@ import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.util.Log;
/**
......@@ -37,6 +37,8 @@ public class Accelerometer extends Service implements StimulusStrategy, SensorEv
}*/
public void monitor() {
Log.d("MOTION", "HUZZAH");
Intent i = new Intent(this, Notification.class);
this.sendBroadcast(i);
}
......
......@@ -7,6 +7,7 @@ import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.util.Log;
import com.example.notification.Notification;
......@@ -29,7 +30,7 @@ public class Clock extends Service implements StimulusStrategy {
AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(this, Notification.class);
PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, 0);
am.set(AlarmManager.ELAPSED_REALTIME, AlarmManager.INTERVAL_HOUR, pi);
am.set(AlarmManager.ELAPSED_REALTIME, AlarmManager.INTERVAL_FIFTEEN_MINUTES, pi);
}
@Nullable
......
......@@ -12,8 +12,10 @@ import android.hardware.TriggerEventListener;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.Toast;
import com.example.notification.Notification;
import com.example.pharmacy.frontEnd.R;
/**
* Created by pharmacy on 17/01/2018.
......@@ -55,7 +57,7 @@ public class SigMotionDetect extends Service implements StimulusStrategy {
public void monitor() {
//Use step counter sensor? to detect if movement lasted for a prolonged period of time.
Log.d("MOTION", "HUZZAH");
am.cancel(am.getNextAlarmClock().getShowIntent());
setUpClock();
mSensorManager.requestTriggerSensor(tel, md);
......
......@@ -4,7 +4,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
tools:context="com.example.pharmacy.frontEnd.Settings">
<ImageButton
android:id="@+id/back"
......@@ -80,13 +81,12 @@
app:layout_constraintTop_toBottomOf="@+id/textView6" />
<Spinner
android:id="@+id/spinner"
android:id="@+id/PeriodSpinner"
android:layout_width="162dp"
android:layout_height="38dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:entries="@string/spinner_opt"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView7"
app:layout_constraintTop_toBottomOf="@+id/NotSwitch" />
......@@ -139,7 +139,7 @@
android:text="@string/audio"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView8"
app:layout_constraintTop_toBottomOf="@+id/spinner" />
app:layout_constraintTop_toBottomOf="@+id/PeriodSpinner" />
<CheckBox
android:id="@+id/Vibration"
......
......@@ -16,5 +16,4 @@
<item>90</item>
<item>120</item>
</integer-array>
</resources>
\ No newline at end of file
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