Commit 75c20ecf authored by Christof Wolke's avatar Christof Wolke

get the current event

parent 63d749f9
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" /> <ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" /> <ConfirmationsSetting value="0" id="Remove" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">
......
package classes;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
/**
* Created by Christof on 23.08.2016.
*/
@JsonObject
public class AppContainer {
@JsonField(name = "id")
private int appContainerId;
@JsonField(name = "feedback")
private Feedback feedback;
@JsonField(name = "forum")
private Forum forum;
@JsonField(name = "materials")
private Materials materials;
public AppContainer() {
}
public AppContainer(int appContainerId, Feedback feedback, Forum forum, Materials materials) {
this.appContainerId = appContainerId;
this.feedback = feedback;
this.forum = forum;
this.materials = materials;
}
public int getAppContainerId() {
return appContainerId;
}
public void setAppContainerId(int appContainerId) {
this.appContainerId = appContainerId;
}
public Feedback getFeedback() {
return feedback;
}
public void setFeedback(Feedback feedback) {
this.feedback = feedback;
}
public Forum getForum() {
return forum;
}
public void setForum(Forum forum) {
this.forum = forum;
}
public Materials getMaterials() {
return materials;
}
public void setMaterials(Materials materials) {
this.materials = materials;
}
@Override
public String toString() {
return "AppContainer{" +
"appContainerId=" + appContainerId +
", feedback=" + feedback +
", forum=" + forum +
", materials=" + materials +
'}';
}
}
package classes;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.util.Date;
/**
* Created by Christof on 23.08.2016.
*/
@JsonObject
public class Comment {
@JsonField(name = "id")
private int commentID;
@JsonField(name = "text")
private String text;
@JsonField(name = "timestamp")
private Date timestamp;
public Comment() {
}
public Comment(int commentID, String text, Date timestamp) {
this.commentID = commentID;
this.text = text;
this.timestamp = timestamp;
}
public int getCommentID() {
return commentID;
}
public void setCommentID(int commentID) {
this.commentID = commentID;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public Date getTimestamp() {
return timestamp;
}
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}
@Override
public String toString() {
return "Comment{" +
"commentID=" + commentID +
", text='" + text + '\'' +
", timestamp=" + timestamp +
'}';
}
}
package classes;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
/**
* Created by Christof on 23.08.2016.
*/
@JsonObject
public class Event {
@JsonField(name = "id")
private int eventId;
@JsonField(name = "name")
private String name;
@JsonField(name = "appContainer")
private AppContainer appContainer;
public Event() {
}
public Event(int eventId, String name, AppContainer appContainer) {
this.eventId = eventId;
this.name = name;
this.appContainer = appContainer;
}
public int getEventId() {
return eventId;
}
public void setEventId(int eventId) {
this.eventId = eventId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public AppContainer getAppContainer() {
return appContainer;
}
public void setAppContainer(AppContainer appContainer) {
this.appContainer = appContainer;
}
@Override
public String toString() {
return "Event{" +
"eventId=" + eventId +
", name='" + name + '\'' +
", appContainer=" + appContainer +
'}';
}
}
package classes;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
/**
* Created by Christof on 23.08.2016.
*/
@JsonObject
public class Feedback {
@JsonField(name = "id")
private int feedbackId;
@JsonField(name = "title")
private String title;
public Feedback() {
}
public Feedback(int feedbackId, String title) {
this.feedbackId = feedbackId;
this.title = title;
}
public int getFeedbackId() {
return feedbackId;
}
public void setFeedbackId(int feedbackId) {
this.feedbackId = feedbackId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@Override
public String toString() {
return "Feedback{" +
"feedbackId=" + feedbackId +
", title='" + title + '\'' +
'}';
}
}
package classes;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.util.ArrayList;
/**
* Created by Christof on 23.08.2016.
*/
@JsonObject
public class Forum {
@JsonField(name = "id")
private int forumId;
@JsonField(name = "comments")
private ArrayList<Comment>comments;
public Forum(){
}
public Forum(int forumId, ArrayList<Comment> comments) {
this.forumId = forumId;
this.comments = comments;
}
public int getForumId() {
return forumId;
}
public void setForumId(int forumId) {
this.forumId = forumId;
}
public ArrayList<Comment> getComments() {
return comments;
}
public void setComments(ArrayList<Comment> comments) {
this.comments = comments;
}
@Override
public String toString() {
return "Forum{" +
"forumId=" + forumId +
", comments=" + comments +
'}';
}
}
package classes;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
/**
* Created by Christof on 23.08.2016.
*/
@JsonObject
public class Materials {
@JsonField(name = "id")
private int materialsId;
@JsonField(name = "title")
private String title;
@JsonField(name = "url")
private String url;
public Materials() {
}
public Materials(int materialsId, String title, String url) {
this.materialsId = materialsId;
this.title = title;
this.url = url;
}
public int getMaterialsId() {
return materialsId;
}
public void setMaterialsId(int materialsId) {
this.materialsId = materialsId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
@Override
public String toString() {
return "Materials{" +
"materialsId=" + materialsId +
", title='" + title + '\'' +
", url='" + url + '\'' +
'}';
}
}
...@@ -5,7 +5,7 @@ import com.bluelinelabs.logansquare.annotation.JsonObject; ...@@ -5,7 +5,7 @@ import com.bluelinelabs.logansquare.annotation.JsonObject;
/** /**
* Represent a User and al important informations * Represent a User and all important informations
* Created by Christof on 04.08.2016. * Created by Christof on 04.08.2016.
*/ */
@JsonObject @JsonObject
......
package de.uni_oldenburg.bidl.base_view; package de.uni_oldenburg.bidl.base_view;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Handler; import android.os.Handler;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.estimote.sdk.Beacon;
import com.estimote.sdk.BeaconManager;
import com.estimote.sdk.Region;
import com.estimote.sdk.SystemRequirementsChecker;
import java.util.List;
import java.util.UUID;
import classes.Event;
import de.uni_oldenburg.bidl.R; import de.uni_oldenburg.bidl.R;
import de.uni_oldenburg.bidl.guest_view.LoginActivity; import services.servercommunication.NetworkService;
import static com.estimote.sdk.repackaged.gson_v2_3_1.com.google.gson.internal.UnsafeAllocator.create; import static de.uni_oldenburg.bidl.R.string.noBeaconFound;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
/** Tag for Logging **/
private static final String TAG = MainActivity.class.getSimpleName();
/** Estimote Beacon UUID **/
private static final UUID PROXIMITY_UUID = UUID.fromString("B9407F30-F5F8-466E-AFF9-25556B57FE6D");
/** GUI **/ /** GUI **/
private TextView beaconID; private TextView beaconID;
/** values **/ /** values **/
boolean doubleBackToExitPressedOnce = false; boolean doubleBackToExitPressedOnce = false;
private Region region;
private BeaconManager beaconManager;
private Beacon nearestBeacon;
...@@ -32,11 +49,75 @@ public class MainActivity extends AppCompatActivity { ...@@ -32,11 +49,75 @@ public class MainActivity extends AppCompatActivity {
/** init **/ /** init **/
beaconID = (TextView) findViewById(R.id.BeaconID); beaconID = (TextView) findViewById(R.id.BeaconID);
/**
* Start ranging for beacons.
**/
beaconManager = new BeaconManager(this);
/** region is the hole university --> all beacons have the same proximity_UUID **/
region = new Region("ranged region", PROXIMITY_UUID, null, null);
beaconManager.setRangingListener(new BeaconManager.RangingListener() {
@Override
public void onBeaconsDiscovered(Region region, List<Beacon> list) {
if (!list.isEmpty() && !list.get(0).equals(nearestBeacon)){
// TODO: 30.07.2016 React, when the user is nearer to another Beacon.
nearestBeacon = list.get(0);
getEventFromServer(nearestBeacon);
} if (list.isEmpty()){
showMessage();
}
}
});
} }
private void getEventFromServer(Beacon nearestBeacon) {
String uud = nearestBeacon.getProximityUUID().toString().toUpperCase();
int major = nearestBeacon.getMajor();
int minor = nearestBeacon.getMinor();
NetworkService.getEvent(uud, major, minor, new NetworkService.RequestGetEventHandler() {
@Override
public void done(final Event event) {
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
beaconID.setText(event.getName());
}
});
}
});
}
@Override
protected void onResume(){
super.onResume();
// is Bluetooth on, is Location on, etc.
SystemRequirementsChecker.checkWithDefaultDialogs(this);
// Start ranging for beacons, when the activity appears on the screen
beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
@Override
public void onServiceReady() {
beaconManager.startRanging(region);
}
});
}
/**
* Ranging ist stopped, if the Activity disappears.
*/
@Override
public void onPause(){
beaconManager.stopRanging(region);
super.onPause();
}
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if (doubleBackToExitPressedOnce) { if (doubleBackToExitPressedOnce) {
...@@ -57,4 +138,8 @@ public class MainActivity extends AppCompatActivity { ...@@ -57,4 +138,8 @@ public class MainActivity extends AppCompatActivity {
} }
}, 2000); }, 2000);
} }
private void showMessage() {
Toast.makeText(this, noBeaconFound, Toast.LENGTH_SHORT).show();
}
} }
package de.uni_oldenburg.bidl.base_view; package de.uni_oldenburg.bidl.base_view;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
...@@ -41,6 +42,7 @@ public class SplashActivity extends AppCompatActivity { ...@@ -41,6 +42,7 @@ public class SplashActivity extends AppCompatActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -73,8 +75,8 @@ public class SplashActivity extends AppCompatActivity { ...@@ -73,8 +75,8 @@ public class SplashActivity extends AppCompatActivity {
toLoginActivity(); toLoginActivity();
// TODO: 30.07.2016 save the Beacon in the database and overwrite the DB, when the nearestBeacon != the saved beacon. // TODO: 30.07.2016 save the Beacon in the database and overwrite the DB, when the nearestBeacon != the saved beacon.
} if (list.isEmpty()){ } if (list.isEmpty()){
// TODO: 30.07.2016 toScrenn beacon not found...
showMessage(); showMessage();
toLoginActivity();
} }
} }
......
...@@ -11,6 +11,8 @@ import android.widget.ImageView; ...@@ -11,6 +11,8 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.estimote.sdk.SystemRequirementsChecker;
import classes.User; import classes.User;
import de.uni_oldenburg.bidl.R; import de.uni_oldenburg.bidl.R;
import de.uni_oldenburg.bidl.base_view.MainActivity; import de.uni_oldenburg.bidl.base_view.MainActivity;
...@@ -97,6 +99,11 @@ public class LoginActivity extends AppCompatActivity { ...@@ -97,6 +99,11 @@ public class LoginActivity extends AppCompatActivity {
}); });
} }
protected void onResume(){
super.onResume();
//is Bluetooth on, is Location on, etc.
SystemRequirementsChecker.checkWithDefaultDialogs(this);
}
@Override @Override
public void onBackPressed() { public void onBackPressed() {
super.onBackPressed(); super.onBackPressed();
......
...@@ -12,6 +12,7 @@ import com.squareup.okhttp.Response; ...@@ -12,6 +12,7 @@ import com.squareup.okhttp.Response;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import classes.Event;
import classes.StatusResponse; import classes.StatusResponse;
import classes.User; import classes.User;
...@@ -127,4 +128,52 @@ public abstract class NetworkService { ...@@ -127,4 +128,52 @@ public abstract class NetworkService {
public interface RequestRegisterHandler { public interface RequestRegisterHandler {
void done(String statusResponse); void done(String statusResponse);
} }
public static void getEvent(String uud, int major, int minor, final RequestGetEventHandler handler){
okHttpClient.setReadTimeout(15, TimeUnit.SECONDS);
/* OkHttpClient
Request body mit POST params
*/
RequestBody requestBody = new FormEncodingBuilder()
.add("uud", uud)
.add("major", String.valueOf(major))
.add("minor", String.valueOf(minor))
.build();
/* add body to POST-request */
Request req = new Request.Builder()
.url(REST.SPRING_GETEVENT)
.post(requestBody)
.build();
/* Server call preparation */
Call call = okHttpClient.newCall(req);
/* Async call */
call.enqueue(new Callback() {
@Override
public