diff --git a/BIDL/BIDL/.idea/misc.xml b/BIDL/BIDL/.idea/misc.xml index 8cdb7ebee9bdb0d9cfdcb28291ee31cfa5755674..13e60141ef45611842312e768b215b8deeecab1d 100644 --- a/BIDL/BIDL/.idea/misc.xml +++ b/BIDL/BIDL/.idea/misc.xml @@ -37,7 +37,7 @@ - + diff --git a/BIDL/BIDL/app/src/main/java/classes/AppContainer.java b/BIDL/BIDL/app/src/main/java/classes/AppContainer.java new file mode 100644 index 0000000000000000000000000000000000000000..b369b3b9a442582c0e58a4595c0e832159820f69 --- /dev/null +++ b/BIDL/BIDL/app/src/main/java/classes/AppContainer.java @@ -0,0 +1,75 @@ +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 + + '}'; + } +} diff --git a/BIDL/BIDL/app/src/main/java/classes/Comment.java b/BIDL/BIDL/app/src/main/java/classes/Comment.java new file mode 100644 index 0000000000000000000000000000000000000000..06a14252a90f7b1dae518b72482ec9728e626416 --- /dev/null +++ b/BIDL/BIDL/app/src/main/java/classes/Comment.java @@ -0,0 +1,64 @@ +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 + + '}'; + } +} diff --git a/BIDL/BIDL/app/src/main/java/classes/Event.java b/BIDL/BIDL/app/src/main/java/classes/Event.java new file mode 100644 index 0000000000000000000000000000000000000000..99c424b78b2be442a5ad463f061494fbbf657f93 --- /dev/null +++ b/BIDL/BIDL/app/src/main/java/classes/Event.java @@ -0,0 +1,62 @@ +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 + + '}'; + } +} diff --git a/BIDL/BIDL/app/src/main/java/classes/Feedback.java b/BIDL/BIDL/app/src/main/java/classes/Feedback.java new file mode 100644 index 0000000000000000000000000000000000000000..54590b452da148a4d8d4294f728e480b29cfbe7d --- /dev/null +++ b/BIDL/BIDL/app/src/main/java/classes/Feedback.java @@ -0,0 +1,49 @@ +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 + '\'' + + '}'; + } +} diff --git a/BIDL/BIDL/app/src/main/java/classes/Forum.java b/BIDL/BIDL/app/src/main/java/classes/Forum.java new file mode 100644 index 0000000000000000000000000000000000000000..397fa36b28d04f3fa6213d955102cc97ac743215 --- /dev/null +++ b/BIDL/BIDL/app/src/main/java/classes/Forum.java @@ -0,0 +1,52 @@ +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 ArrayListcomments; + + public Forum(){ + + } + + public Forum(int forumId, ArrayList comments) { + this.forumId = forumId; + this.comments = comments; + } + + public int getForumId() { + return forumId; + } + + public void setForumId(int forumId) { + this.forumId = forumId; + } + + public ArrayList getComments() { + return comments; + } + + public void setComments(ArrayList comments) { + this.comments = comments; + } + + @Override + public String toString() { + return "Forum{" + + "forumId=" + forumId + + ", comments=" + comments + + '}'; + } +} diff --git a/BIDL/BIDL/app/src/main/java/classes/Materials.java b/BIDL/BIDL/app/src/main/java/classes/Materials.java new file mode 100644 index 0000000000000000000000000000000000000000..954b05e539ca70f6562b5cdb1a4bc8c53528036e --- /dev/null +++ b/BIDL/BIDL/app/src/main/java/classes/Materials.java @@ -0,0 +1,62 @@ +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 + '\'' + + '}'; + } +} diff --git a/BIDL/BIDL/app/src/main/java/classes/User.java b/BIDL/BIDL/app/src/main/java/classes/User.java index e1e50992aea014d4a6559f237d5ce9cd3505f119..27fa02fd8db3acf8436c9434475c98a7c18b4583 100644 --- a/BIDL/BIDL/app/src/main/java/classes/User.java +++ b/BIDL/BIDL/app/src/main/java/classes/User.java @@ -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. */ @JsonObject diff --git a/BIDL/BIDL/app/src/main/java/de/uni_oldenburg/bidl/base_view/MainActivity.java b/BIDL/BIDL/app/src/main/java/de/uni_oldenburg/bidl/base_view/MainActivity.java index 6399b060feb750fe54c1efa9265e0b4d8660dcdb..e4ba61891b4d639d726bac56d9e64f412e910479 100644 --- a/BIDL/BIDL/app/src/main/java/de/uni_oldenburg/bidl/base_view/MainActivity.java +++ b/BIDL/BIDL/app/src/main/java/de/uni_oldenburg/bidl/base_view/MainActivity.java @@ -1,26 +1,43 @@ package de.uni_oldenburg.bidl.base_view; -import android.content.DialogInterface; -import android.content.Intent; + import android.os.Handler; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; 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.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 { + /** 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 **/ private TextView beaconID; /** values **/ boolean doubleBackToExitPressedOnce = false; + private Region region; + private BeaconManager beaconManager; + private Beacon nearestBeacon; @@ -32,11 +49,75 @@ public class MainActivity extends AppCompatActivity { /** init **/ 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 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 public void onBackPressed() { if (doubleBackToExitPressedOnce) { @@ -57,4 +138,8 @@ public class MainActivity extends AppCompatActivity { } }, 2000); } + + private void showMessage() { + Toast.makeText(this, noBeaconFound, Toast.LENGTH_SHORT).show(); + } } diff --git a/BIDL/BIDL/app/src/main/java/de/uni_oldenburg/bidl/base_view/SplashActivity.java b/BIDL/BIDL/app/src/main/java/de/uni_oldenburg/bidl/base_view/SplashActivity.java index a66d9f4ad5794e17d12af1b0ccaa755aebd49d17..1cea42ffad4c749bc72853831daa51e172c872d9 100644 --- a/BIDL/BIDL/app/src/main/java/de/uni_oldenburg/bidl/base_view/SplashActivity.java +++ b/BIDL/BIDL/app/src/main/java/de/uni_oldenburg/bidl/base_view/SplashActivity.java @@ -1,6 +1,7 @@ package de.uni_oldenburg.bidl.base_view; import android.content.Intent; +import android.content.SharedPreferences; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; @@ -41,6 +42,7 @@ public class SplashActivity extends AppCompatActivity { + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -73,8 +75,8 @@ public class SplashActivity extends AppCompatActivity { toLoginActivity(); // TODO: 30.07.2016 save the Beacon in the database and overwrite the DB, when the nearestBeacon != the saved beacon. } if (list.isEmpty()){ - // TODO: 30.07.2016 toScrenn beacon not found... showMessage(); + toLoginActivity(); } } diff --git a/BIDL/BIDL/app/src/main/java/de/uni_oldenburg/bidl/guest_view/LoginActivity.java b/BIDL/BIDL/app/src/main/java/de/uni_oldenburg/bidl/guest_view/LoginActivity.java index dfd17d48201fefa49a69771da87663679bcacb37..caef6e9058f4d83f3d74a8d3ed52c644b93356cf 100644 --- a/BIDL/BIDL/app/src/main/java/de/uni_oldenburg/bidl/guest_view/LoginActivity.java +++ b/BIDL/BIDL/app/src/main/java/de/uni_oldenburg/bidl/guest_view/LoginActivity.java @@ -11,6 +11,8 @@ import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; +import com.estimote.sdk.SystemRequirementsChecker; + import classes.User; import de.uni_oldenburg.bidl.R; import de.uni_oldenburg.bidl.base_view.MainActivity; @@ -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 public void onBackPressed() { super.onBackPressed(); diff --git a/BIDL/BIDL/app/src/main/java/services/servercommunication/NetworkService.java b/BIDL/BIDL/app/src/main/java/services/servercommunication/NetworkService.java index 2875df7d13991896443724f846009f61a8f686fb..dddf1f670f8c0e9f1c74016adca5f33f01c3b5cd 100644 --- a/BIDL/BIDL/app/src/main/java/services/servercommunication/NetworkService.java +++ b/BIDL/BIDL/app/src/main/java/services/servercommunication/NetworkService.java @@ -12,6 +12,7 @@ import com.squareup.okhttp.Response; import java.io.IOException; import java.util.concurrent.TimeUnit; +import classes.Event; import classes.StatusResponse; import classes.User; @@ -127,4 +128,52 @@ public abstract class NetworkService { public interface RequestRegisterHandler { 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 void onFailure(Request request, IOException e) { + handler.done(null); + e.printStackTrace(); + } + + @Override + public void onResponse(Response response) throws IOException { + try { + /* Server response parsing */ + if (response.isSuccessful()){ + String responseString = response.body().string(); + Event event = LoganSquare.parse(responseString, Event.class); + handler.done(event); + } + }catch (IOException e){ + handler.done(null); + e.printStackTrace(); + } + } + }); + } + + + public interface RequestGetEventHandler { + void done(Event event); + } } diff --git a/BIDL/BIDL/app/src/main/java/services/servercommunication/REST.java b/BIDL/BIDL/app/src/main/java/services/servercommunication/REST.java index a03228a54a2c836ecf89d54281d0af2c2c1650c8..266d312737f178fc2aedf1d76ed330aeb8ea3ee4 100644 --- a/BIDL/BIDL/app/src/main/java/services/servercommunication/REST.java +++ b/BIDL/BIDL/app/src/main/java/services/servercommunication/REST.java @@ -23,7 +23,7 @@ public abstract class REST { public static String FULL_URL = LOCAL_URL; - // Login path + //Login path private static final String LOGIN = "/login"; public static String SPRING_LOGIN = FULL_URL + LOGIN; @@ -31,4 +31,8 @@ public abstract class REST { private static final String REGISTER = "/register"; public static String SPRING_REGISTER = FULL_URL + REGISTER; + //getEvent path + private static final String GETEVENT = "/getEvent"; + public static String SPRING_GETEVENT = FULL_URL + GETEVENT; + }