aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/AndroidManifest.xml7
-rw-r--r--app/src/main/java/org/marcinzelent/liberavem/BirdPickerActivity.java13
-rw-r--r--app/src/main/java/org/marcinzelent/liberavem/DataKeeper.java2
-rw-r--r--app/src/main/java/org/marcinzelent/liberavem/NewObservationActivity.java111
-rw-r--r--app/src/main/java/org/marcinzelent/liberavem/Observation.java91
-rw-r--r--app/src/main/java/org/marcinzelent/liberavem/ObservationsFragment.java5
-rw-r--r--app/src/main/res/layout/activity_bird_picker.xml9
-rw-r--r--app/src/main/res/layout/activity_new_observation.xml19
-rw-r--r--app/src/main/res/layout/activity_observation_details.xml5
-rw-r--r--app/src/main/res/values/strings.xml1
10 files changed, 230 insertions, 33 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index edc0b5d..7f947ee 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -26,7 +26,12 @@
<activity
android:name=".SettingsActivity"
android:label="@string/title_activity_settings" />
- <activity android:name=".ObservationDetailsActivity"></activity>
+ <activity android:name=".ObservationDetailsActivity" />
+ <activity
+ android:name=".NewObservationActivity"
+ android:label="@string/title_activity_new_observation"
+ android:theme="@style/AppTheme.NoActionBar" />
+ <activity android:name=".BirdPickerActivity"></activity>
</application>
</manifest> \ No newline at end of file
diff --git a/app/src/main/java/org/marcinzelent/liberavem/BirdPickerActivity.java b/app/src/main/java/org/marcinzelent/liberavem/BirdPickerActivity.java
new file mode 100644
index 0000000..15c38cf
--- /dev/null
+++ b/app/src/main/java/org/marcinzelent/liberavem/BirdPickerActivity.java
@@ -0,0 +1,13 @@
+package org.marcinzelent.liberavem;
+
+import android.support.v7.app.AppCompatActivity;
+import android.os.Bundle;
+
+public class BirdPickerActivity extends AppCompatActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_bird_picker);
+ }
+}
diff --git a/app/src/main/java/org/marcinzelent/liberavem/DataKeeper.java b/app/src/main/java/org/marcinzelent/liberavem/DataKeeper.java
index 67eba43..27f9dc4 100644
--- a/app/src/main/java/org/marcinzelent/liberavem/DataKeeper.java
+++ b/app/src/main/java/org/marcinzelent/liberavem/DataKeeper.java
@@ -106,7 +106,7 @@ public class DataKeeper {
MyObservationsFragment mo = (MyObservationsFragment) ((MainActivity)activity).getAllFragments().get(0);
List<Observation> myObservationsList = new ArrayList<>();
for (Observation o : observations)
- if (o.getUserId().equals("Nancy")) myObservationsList.add(o);
+ if (o.getUserId().equals("Sminem")) myObservationsList.add(o);
Observation[] myObservations = new Observation[myObservationsList.size()];
myObservations = myObservationsList.toArray(myObservations);
diff --git a/app/src/main/java/org/marcinzelent/liberavem/NewObservationActivity.java b/app/src/main/java/org/marcinzelent/liberavem/NewObservationActivity.java
new file mode 100644
index 0000000..cf1cf18
--- /dev/null
+++ b/app/src/main/java/org/marcinzelent/liberavem/NewObservationActivity.java
@@ -0,0 +1,111 @@
+package org.marcinzelent.liberavem;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.support.design.widget.FloatingActionButton;
+import android.support.design.widget.Snackbar;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.Toolbar;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.Toast;
+
+import com.android.volley.AuthFailureError;
+import com.android.volley.NetworkResponse;
+import com.android.volley.Request;
+import com.android.volley.Response;
+import com.android.volley.VolleyError;
+import com.android.volley.VolleyLog;
+import com.android.volley.toolbox.HttpHeaderParser;
+import com.android.volley.toolbox.StringRequest;
+import com.android.volley.toolbox.Volley;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.Map;
+
+public class NewObservationActivity extends AppCompatActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_new_observation);
+ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
+
+ Button button = findViewById(R.id.button);
+ button.setOnClickListener(new Button.OnClickListener() {
+ public void onClick(View view) {
+ postNewObservation();
+ }
+ });
+ }
+
+ public void postNewObservation() {
+ try {
+ JSONObject jsonBody = new JSONObject();
+ jsonBody.put("BirdId", "51");
+ jsonBody.put("Comment", "Værsgo, my friend");
+ jsonBody.put("Created", "/Date(1524182400000+0000)/");
+ jsonBody.put("Id", "162");
+ jsonBody.put("Latitude", "30.1187718");
+ jsonBody.put("Longitude", "51.381484");
+ jsonBody.put("Placename", "Black lodge");
+ jsonBody.put("Population", "5");
+ jsonBody.put("UserId", "Sminem");
+ jsonBody.put("NameDanish", "gråkrage");
+ jsonBody.put("NameEnglish", "hooded crow");
+ final String requestBody = jsonBody.toString();
+
+ String url = "http://birdobservationservice.azurewebsites.net/Service1.svc/observations";
+ StringRequest request = new StringRequest(Request.Method.POST, url,
+ new Response.Listener<String>() {
+ @Override
+ public void onResponse(String response) {
+ Toast.makeText(getBaseContext(), "Couldn't add observation to the database!", Toast.LENGTH_LONG).show();
+ }
+ },
+ new Response.ErrorListener() {
+ @Override
+ public void onErrorResponse(VolleyError error) {
+ Toast.makeText(getBaseContext(), "Successfully added activity to the database!", Toast.LENGTH_LONG).show();
+ }
+ }) {
+
+ @Override
+ public String getBodyContentType() {
+ return "application/json; charset=utf-8";
+ }
+
+ @Override
+ public byte[] getBody() throws AuthFailureError {
+ try {
+ return requestBody == null ? null : requestBody.getBytes("utf-8");
+ } catch (UnsupportedEncodingException uee) {
+ VolleyLog.wtf("Unsupported Encoding while trying to get the bytes of %s using %s", requestBody, "utf-8");
+ return null;
+ }
+ }
+
+ @Override
+ protected Response<String> parseNetworkResponse(NetworkResponse response) {
+ String responseString = "";
+ if (response != null) {
+ responseString = String.valueOf(response.statusCode);
+ // can get more details such as response.headers
+ }
+ return Response.success(responseString, HttpHeaderParser.parseCacheHeaders(response));
+ }
+ };
+
+ Volley.newRequestQueue(getBaseContext()).add(request);
+ }
+ catch (JSONException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/app/src/main/java/org/marcinzelent/liberavem/Observation.java b/app/src/main/java/org/marcinzelent/liberavem/Observation.java
index be02812..1aca80b 100644
--- a/app/src/main/java/org/marcinzelent/liberavem/Observation.java
+++ b/app/src/main/java/org/marcinzelent/liberavem/Observation.java
@@ -5,89 +5,126 @@ import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
public class Observation implements Serializable {
- @SerializedName("Id")
- private int id;
+ @SerializedName("BirdId")
+ private int birdId;
+ @SerializedName("Comment")
+ private String comment;
@SerializedName("Created")
private String created;
+ @SerializedName("Id")
+ private int id;
@SerializedName("Latitude")
private double latitude;
@SerializedName("Longitude")
private double longitude;
@SerializedName("Placename")
private String placeName;
- @SerializedName("Comment")
- private String comment;
+ @SerializedName("Population")
+ private int population;
@SerializedName("UserId")
private String userId;
- @SerializedName("BirdId")
- private int birdId;
- @SerializedName("NameEnglish")
- private String nameEnglish;
@SerializedName("NameDanish")
private String nameDanish;
- @SerializedName("Population")
- private int population;
+ @SerializedName("NameEnglish")
+ private String nameEnglish;
public Observation(int id, String created, double latitude, double longitude, String placeName,
String comment, String userId, int birdId, String nameEnglish,
String nameDanish, int population) {
- this.id = id;
+ this.birdId = birdId;
+ this.comment = comment;
this.created = created;
+ this.id = id;
this.latitude = latitude;
this.longitude = longitude;
this.placeName = placeName;
- this.comment = comment;
+ this.population = population;
this.userId = userId;
- this.birdId = birdId;
- this.nameEnglish = nameEnglish;
this.nameDanish = nameDanish;
- this.population = population;
+ this.nameEnglish = nameEnglish;
}
- public int getId() {
- return id;
+ public int getBirdId() {
+ return birdId;
+ }
+
+ public void setBirdId(int birdId) {
+ this.birdId = birdId;
+ }
+
+ public String getComment() {
+ return comment;
+ }
+
+ public void setComment(String comment) {
+ this.comment = comment;
}
public String getCreated() {
return created;
}
+
public void setCreated(String created) {
this.created = created;
}
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
public double getLatitude() {
return latitude;
}
+ public void setLatitude(double latitude) {
+ this.latitude = latitude;
+ }
+
public double getLongitude() {
return longitude;
}
+ public void setLongitude(double longitude) {
+ this.longitude = longitude;
+ }
+
public String getPlaceName() {
return placeName;
}
- public String getComment() {
- return comment;
+ public void setPlaceName(String placeName) {
+ this.placeName = placeName;
}
- public String getUserId() {
- return userId;
+ public int getPopulation() {
+ return population;
}
- public int getBirdId() {
- return birdId;
+ public void setPopulation(int population) {
+ this.population = population;
}
- public String getNameEnglish() {
- return nameEnglish;
+ public String getUserId() {
+ return userId;
+ }
+
+ public void setUserId(String userId) {
+ this.userId = userId;
}
public String getNameDanish() {
return nameDanish;
}
- public int getPopulation() {
- return population;
+ public String getNameEnglish() {
+ return nameEnglish;
+ }
+
+ public void setNameEnglish(String nameEnglish) {
+ this.nameEnglish = nameEnglish;
}
}
diff --git a/app/src/main/java/org/marcinzelent/liberavem/ObservationsFragment.java b/app/src/main/java/org/marcinzelent/liberavem/ObservationsFragment.java
index b093461..128cbe9 100644
--- a/app/src/main/java/org/marcinzelent/liberavem/ObservationsFragment.java
+++ b/app/src/main/java/org/marcinzelent/liberavem/ObservationsFragment.java
@@ -1,6 +1,7 @@
package org.marcinzelent.liberavem;
import android.content.Context;
+import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
@@ -98,8 +99,8 @@ public class ObservationsFragment extends Fragment {
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- Snackbar.make(view, "Here's a Snackbar", Snackbar.LENGTH_LONG)
- .setAction("Action", null).show();
+ Intent intent = new Intent(getActivity(), NewObservationActivity.class);
+ startActivity(intent);
}
});
}
diff --git a/app/src/main/res/layout/activity_bird_picker.xml b/app/src/main/res/layout/activity_bird_picker.xml
new file mode 100644
index 0000000..62f086b
--- /dev/null
+++ b/app/src/main/res/layout/activity_bird_picker.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.v7.widget.GridLayout 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"
+ tools:context=".BirdPickerActivity">
+
+</android.support.v7.widget.GridLayout> \ No newline at end of file
diff --git a/app/src/main/res/layout/activity_new_observation.xml b/app/src/main/res/layout/activity_new_observation.xml
new file mode 100644
index 0000000..1160131
--- /dev/null
+++ b/app/src/main/res/layout/activity_new_observation.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout 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"
+ tools:context=".NewObservationActivity">
+
+ <Button
+ android:id="@+id/button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="8dp"
+ android:layout_marginStart="8dp"
+ android:layout_marginTop="8dp"
+ android:text="Button"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
+</android.support.constraint.ConstraintLayout> \ No newline at end of file
diff --git a/app/src/main/res/layout/activity_observation_details.xml b/app/src/main/res/layout/activity_observation_details.xml
index 938fe91..4372b9a 100644
--- a/app/src/main/res/layout/activity_observation_details.xml
+++ b/app/src/main/res/layout/activity_observation_details.xml
@@ -84,7 +84,7 @@
android:id="@+id/details_user_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_weight="1"
+ android:ellipsize="none"
android:text="@string/author"
android:textStyle="bold" />
@@ -93,7 +93,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
- android:layout_weight="1" />
+ android:layout_weight="1"
+ android:ellipsize="end" />
</LinearLayout>
<LinearLayout
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 1561e86..54fe20a 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -95,4 +95,5 @@
<string name="latitude">Latitude:</string>
<string name="longitude">Longitude:</string>
<string name="comment">Comment:</string>
+ <string name="title_activity_new_observation">NewObservationActivity</string>
</resources>