Skip to content
Snippets Groups Projects
Commit 82fb78d1 authored by ect1u17's avatar ect1u17
Browse files

Daily Commit

Changes:
- Implemented more of the survey creation page including:
0   A notification section
0   A completed survey layout (with one specific bug, but everything else works great)
parent e36c3b04
No related branches found
No related tags found
No related merge requests found
Showing
with 673 additions and 132 deletions
......@@ -19,6 +19,8 @@ android {
}
}
configurations.all {exclude group: 'com.yearthreeproject.xbframework', module: 'ExperimentSurveyCreatorActivity'}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
......
......@@ -15,6 +15,8 @@
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
tools:ignore="GoogleAppIndexingWarning">
<receiver android:name=".MyNotificationPublisher" />
<activity android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
......@@ -29,6 +31,11 @@
android:label="About"
android:theme="@style/AppTheme.NoActionBar"/>
<activity
android:name=".TestingActivity"
android:label="Testing"
android:theme="@style/AppTheme.NoActionBar"/>
<activity
android:name=".LoginActivity"
android:label="Login"
......
......@@ -145,7 +145,7 @@ public class BoxesActivity extends AppCompatActivity {
JSONObject localData = new JSONObject(FileStoreReader.readFile(BoxesActivity.this, "localUserData.json"));
if (!locked && checkDateLimit(localData.getString("DateUntil"))) {
if (!locked && checkDateLimit(localData.getString("dateUntil"))) {
Intent openPage = new Intent(BoxesActivity.this, ExperimentActivity.class);
openPage.putExtra("JSON", box.toString());
startActivity(openPage);
......
......@@ -141,7 +141,8 @@ public class ExperimentActivity extends AppCompatActivity {
calendar.add(Calendar.DATE, 5);
String dateUntil = simpleDateFormat.format(calendar.getTime());
editJSON.put("DateUntil", dateUntil);
editJSON.put("dateUntil", dateUntil);
editJSON.put("locked", true);
FileStoreReader.saveFile(ExperimentActivity.this, "localUserData.json", editJSON.toString());
......
......@@ -35,8 +35,9 @@ import static android.util.Log.d;
public class MainActivity extends AppCompatActivity {
private Button homeButton, loginButton, shopButton, experimentsButton, progressButton, aboutButton;
private Button homeButton, loginButton, shopButton, experimentsButton, progressButton, aboutButton, surveyButton;
private Toolbar toolbar;
private boolean shouldRecreate;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
......@@ -73,20 +74,18 @@ public class MainActivity extends AppCompatActivity {
experimentsButton = findViewById(R.id.HomeExperimentsButton);
progressButton = findViewById(R.id.HomeProgressButton);
aboutButton = findViewById(R.id.HomeAboutButton);
surveyButton = findViewById(R.id.HomeSurveyButton);
homeButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
d("testing", "When is this used?");
}
});
LinearLayout homeACT = findViewById(R.id.HomeActivityLayout);
homeACT.removeView(homeButton);
LinearLayout homeActLay = findViewById(R.id.HomeActivityLayout);
homeActLay.removeView(homeButton);
loginButton.setOnClickListener(new View.OnClickListener() {
Button testingButton = new Button(this);
testingButton.setText("Testing");
homeActLay.addView(testingButton);
testingButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, LoginActivity.class));
startActivity(new Intent(MainActivity.this, TestingActivity.class));
}
});
......@@ -95,56 +94,78 @@ public class MainActivity extends AppCompatActivity {
d("testing", localUserJSON.toString());
if(localUserJSON.get("savedUserID") != JSONObject.NULL){
d("test", "got user id");
LinearLayout homeActLay = findViewById(R.id.HomeActivityLayout);
homeActLay.removeView(loginButton);
} else{
d("test", "do not got user id");
LinearLayout homeActLay = findViewById(R.id.HomeActivityLayout);
homeActLay.removeAllViews();
homeActLay.addView(loginButton);
}
if(localUserJSON.opt("locked") != JSONObject.NULL && localUserJSON.optBoolean("locked") == true){
d("test", "is locked to experiment"+localUserJSON.opt("locked").toString());
homeActLay.removeView(experimentsButton);
} else{
d("test", "is not locked to experiment");
homeActLay.removeView(surveyButton);
}
} catch (JSONException e) {
e.printStackTrace();
}
// Hacky method to reset the screen on each refocus, only put request code to 0 if it can change the look of the home screen
final Intent[] intentTest = new Intent[1];
homeButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
d("testing", "When is this used?");
}
});
loginButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
intentTest[0] = new Intent(MainActivity.this, LoginActivity.class);
startActivityForResult(intentTest[0], 0);
}
});
shopButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, ShopActivity.class));
intentTest[0] = new Intent(MainActivity.this, ShopActivity.class);
startActivity(intentTest[0]);
}
});
experimentsButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, BoxesActivity.class));
intentTest[0] = new Intent(MainActivity.this, BoxesActivity.class);
startActivityForResult(intentTest[0], 0);
}
});
progressButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, ProgressActivity.class));
intentTest[0] = new Intent(MainActivity.this, ProgressActivity.class);
startActivity(intentTest[0]);
}
});
aboutButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, AboutActivity.class));
intentTest[0] = new Intent(MainActivity.this, AboutActivity.class);
startActivity(intentTest[0]);
}
});
}
private void checkLocalUserFile() {
File file = new File(this.getFilesDir(), "localUserData.json");
if(!file.exists()) {
// Do stuff to initialise the file
FileStoreReader.saveFile(this, "localUserData.json", "{\"DateUntil\":\"01/31/1999\",\"savedUserID\":\"A01\"}");
FileStoreReader.saveFile(this, "localUserData.json", "{\"d\":\"01/31/1999\",\"savedUserID\":\"A01\"}");
} else {
// Do nothing
}
......@@ -192,10 +213,36 @@ public class MainActivity extends AppCompatActivity {
FileStoreReader.saveFile(this, "boxData.json", boxesData);
FileStoreReader.saveFile(this, "localUserData.json", "{\"DateUntil\": \"01/31/1999\",\n\"savedUserID\": \"A01\"}");
FileStoreReader.saveFile(this, "localUserData.json", "{\"dateUntil\": \"01/31/1999\",\n\"savedUserID\": \"A01\",\n\"locked\": false}");
d("file", FileStoreReader.readFile(this, "boxData.json"));
d("file", FileStoreReader.readFile(this, "localUserData.json"));
recreate();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 0){
shouldRecreate = true;
}
}
@Override
protected void onResume() {
super.onResume();
if (shouldRecreate){
overridePendingTransition(0, 0);
Intent intent = getIntent();
overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
overridePendingTransition(0, 0);
finish();
overridePendingTransition(0, 0);
startActivity(intent);
overridePendingTransition(0, 0);
}
}
// Image permission check
......@@ -258,4 +305,6 @@ public class MainActivity extends AppCompatActivity {
d("Perm", "Already granted");
}
}
}
\ No newline at end of file
package com.yearthreeproject.xbframework;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class MyNotificationPublisher extends BroadcastReceiver {
public static String NOTIFICATION_ID = "notification-id" ;
public static String NOTIFICATION = "notification" ;
public void onReceive (Context context , Intent intent) {
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context. NOTIFICATION_SERVICE ) ;
Notification notification = intent.getParcelableExtra( NOTIFICATION ) ;
if (android.os.Build.VERSION. SDK_INT >= android.os.Build.VERSION_CODES. O ) {
int importance = NotificationManager. IMPORTANCE_HIGH ;
NotificationChannel notificationChannel = new NotificationChannel( "10001" , "NOTIFICATION_CHANNEL_NAME" , importance) ;
assert notificationManager != null;
notificationManager.createNotificationChannel(notificationChannel) ;
}
int id = intent.getIntExtra( NOTIFICATION_ID , 0 ) ;
assert notificationManager != null;
notificationManager.notify(id , notification) ;
}
}
......@@ -93,7 +93,7 @@ public class NewBox extends AppCompatActivity {
@Override
public void onNothingSelected(AdapterView<?> parent) {
// Do nothing
}
});
......
......@@ -3,6 +3,7 @@ package com.yearthreeproject.xbframework;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
......@@ -27,6 +28,9 @@ public class ProgressActivity extends AppCompatActivity {
getSupportActionBar().setLogo(R.mipmap.ic_launcher);
getSupportActionBar().setDisplayUseLogoEnabled(true);
TextView onlyTextView = findViewById(R.id.ProgressPlaceholderTextView);
onlyTextView.setText(FileStoreReader.readFile(ProgressActivity.this, "localUserData.json"));
backHomeButton = findViewById(R.id.ProgressBackHomButton);
backHomeButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
......
package com.yearthreeproject.xbframework;
import android.app.AlarmManager;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.NotificationCompat;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Calendar;
public class TestingActivity extends AppCompatActivity {
private Toolbar toolbar;
private Button backHomeButton;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_testing);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setLogo(R.mipmap.ic_launcher);
getSupportActionBar().setDisplayUseLogoEnabled(true);
Button testButton = findViewById(R.id.testingRunButton);
runOnLoad();
testButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
runOnButton();
}
});
backHomeButton = findViewById(R.id.TestingBackHomButton);
backHomeButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});
}
private void runOnLoad(){
// Run immediate code in here
String NOTIFICATION_CHANNEL_ID = "10001" ;
String default_notification_channel_id = "default" ;
NotificationCompat.Builder builder = new NotificationCompat.Builder( this, default_notification_channel_id ) ;
builder.setContentTitle( "Scheduled Notification" ) ;
builder.setContentText("Testing delay") ;
builder.setSmallIcon(R.drawable. ic_launcher_foreground ) ;
builder.setAutoCancel( true ) ;
builder.setChannelId( NOTIFICATION_CHANNEL_ID ) ;
Calendar firingCal= Calendar.getInstance();
firingCal.set(Calendar.HOUR, 12); // At the hour you wanna fire
firingCal.set(Calendar.MINUTE, 40); // Particular minute
firingCal.set(Calendar.SECOND, 0); // particular second
scheduleNotification(builder.build(), firingCal);
}
private void runOnButton(){
// Code to run on button press
Intent runIntent = new Intent(this, ExperimentSurveyCreatorActivity.class);
JSONObject box = null;
try {
box = new JSONObject();
box.put("Name", "SleepBoxV2");
box.put("Group", "Sleep");
box.put("Blurb", "A less featurefull SleepBox");
box.put("Locked", false);
box.put("Image", JSONObject.NULL);
box.put("Description", "Does not do anything close to SleepBox, just is my method of testing!");
box.put("WarningText", "Once an experiment is chosen, will be locked into that experiment for 5 days.");
JSONArray experimentGroups = new JSONArray();
JSONObject experimentGroupInfo = new JSONObject();
experimentGroupInfo.put("Group", "Light");
JSONArray groupExperimentList = new JSONArray();
JSONObject experiment = new JSONObject();
experiment.put("Title", "Sunlight");
experiment.put("Instructions", "Get 30 to 45 minutes of sunlight a day. Make sure your room captures sunlight.");
experiment.put("Description", "This will boost circadium rhythm.");
groupExperimentList.put(experiment);
experimentGroupInfo.put("Options", groupExperimentList);
experimentGroups.put(experimentGroupInfo);
box.put("Experiments", experimentGroups);
} catch (JSONException e) {
e.printStackTrace();
}
runIntent.putExtra("JSON", box.toString());
runIntent.putExtra("ExperimentIndex", 0);
runIntent.putExtra("GroupIndex", 0);
startActivity(runIntent);
}
private void scheduleNotification (Notification notification , Calendar firingCal) {
Calendar currentCal = Calendar.getInstance();
Intent notificationIntent = new Intent( this, MyNotificationPublisher. class ) ;
notificationIntent.putExtra(MyNotificationPublisher. NOTIFICATION_ID , 1 ) ;
notificationIntent.putExtra(MyNotificationPublisher. NOTIFICATION , notification) ;
PendingIntent pendingIntent = PendingIntent. getBroadcast ( this, 0 , notificationIntent , PendingIntent. FLAG_UPDATE_CURRENT ) ;
long currentTime = currentCal.getTimeInMillis();
long intendedTime = firingCal.getTimeInMillis();
AlarmManager alarmManager = (AlarmManager) getSystemService(Context. ALARM_SERVICE ) ;
assert alarmManager != null;
if(intendedTime >= currentTime){
Log.d("time", "intende time is today");
// you can add buffer time too here to ignore some small differences in milliseconds
// set from today
alarmManager.setRepeating(AlarmManager.RTC, intendedTime, AlarmManager.INTERVAL_DAY, pendingIntent);
} else{
// set from next day
// you might consider using calendar.add() for adding one day to the current day
firingCal.add(Calendar.DAY_OF_MONTH, 1);
intendedTime = firingCal.getTimeInMillis();
alarmManager.setRepeating(AlarmManager.RTC, intendedTime, AlarmManager.INTERVAL_DAY, pendingIntent);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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:orientation="vertical"
tools:context=".TestingActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:minHeight="56dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_testing" />
</LinearLayout>
\ No newline at end of file
......@@ -26,6 +26,13 @@
android:layout_weight="1"
android:text="@string/main_login" />
<Button
android:id="@+id/HomeSurveyButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Survey" />
<Button
android:id="@+id/HomeShopButton"
android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ProgressActivityLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:layout_marginTop="32dp"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".TestingActivity"
tools:showIn="@layout/activity_testing">
<ScrollView
android:id="@+id/TestingScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:id="@+id/ContentContainerLayoutTesting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/testingRunButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Run" />
</LinearLayout>
</ScrollView>
<Button
android:id="@+id/TestingBackHomButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="@string/about_back_home_button" />
</LinearLayout>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment