Skip to content

Commit

Permalink
Map in dedicated Activity
Browse files Browse the repository at this point in the history
  • Loading branch information
pgmccann committed Apr 18, 2018
1 parent 152eb05 commit 7dec6f4
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 71 deletions.
11 changes: 9 additions & 2 deletions catch/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand All @@ -48,6 +47,14 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.EditFish1FormActivity" />
</activity>
<activity
android:name=".activities.MapActivity"
android:label="@string/title_activity_map"
android:parentActivityName=".activities.Fish1FormsActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.Fish1FormsActivity" />
</activity>

<service
android:name=".services.CatchLocationService"
Expand All @@ -57,7 +64,7 @@
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/google_maps_api_key"/>

</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
intent = new Intent(this, Fish1FormsActivity.class);
startActivity(intent);
return true;
case R.id.activity_map:
intent = new Intent(this, MapActivity.class);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
intent = new Intent(this, Fish1FormsActivity.class);
startActivity(intent);
return true;
case R.id.activity_map:
intent = new Intent(this, MapActivity.class);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,26 @@
package uk.ac.masts.sifids.activities;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.tasks.OnSuccessListener;

import java.util.ArrayList;

import java.util.List;

import uk.ac.masts.sifids.R;
import uk.ac.masts.sifids.database.CatchDatabase;
import uk.ac.masts.sifids.entities.CatchLocation;
import uk.ac.masts.sifids.entities.Fish1Form;
import uk.ac.masts.sifids.services.CatchLocationService;

public class Fish1FormsActivity extends AppCompatActivity implements OnMapReadyCallback {
public class Fish1FormsActivity extends AppCompatActivity {

FloatingActionButton fab;
public static RecyclerView recyclerView;
Expand All @@ -57,7 +39,7 @@ protected void onCreate(Bundle savedInstanceState) {

PreferenceManager.setDefaultValues(this, R.xml.pref_fishery_office_details, false);

db = CatchDatabase.getInstance(getApplicationContext());
db = CatchDatabase.getInstance(getApplicationContext());

Runnable r = new Runnable(){
@Override
Expand All @@ -79,11 +61,6 @@ public void run() {
Thread newThread= new Thread(r);
newThread.start();

MapFragment mapFragment = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);


fab=(FloatingActionButton)findViewById(R.id.fab);

fab.setOnClickListener(new View.OnClickListener() {
Expand Down Expand Up @@ -116,6 +93,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
intent = new Intent(this, Fish1FormsActivity.class);
startActivity(intent);
return true;
case R.id.activity_map:
intent = new Intent(this, MapActivity.class);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
Expand All @@ -129,38 +110,4 @@ public void stopTrackingLocation(View v) {
stopService(new Intent(this, CatchLocationService.class));
}

List<CatchLocation> points;

@Override
public void onMapReady(GoogleMap map) {

points = new ArrayList();

Runnable r = new Runnable(){
@Override
public void run() {
points = db.catchDao().getLastLocations(100);
}
};

Thread newThread= new Thread(r);
newThread.start();
try {
newThread.join();
}
catch (InterruptedException ie) {

}

boolean first = true;
for (CatchLocation point : points) {
Log.e("Map", "Got " + point.getCoordinates());
map.addMarker(new MarkerOptions().position(point.getLatLng()).title(point.getCoordinates()));
if (first) {
map.moveCamera(CameraUpdateFactory.newLatLngZoom(point.getLatLng(), (float) 10.0));
first = false;
}
}
}

}
110 changes: 110 additions & 0 deletions catch/src/main/java/uk/ac/masts/sifids/activities/MapActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package uk.ac.masts.sifids.activities;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.MarkerOptions;

import java.util.ArrayList;
import java.util.List;

import uk.ac.masts.sifids.R;
import uk.ac.masts.sifids.database.CatchDatabase;
import uk.ac.masts.sifids.entities.CatchLocation;

public class MapActivity extends AppCompatActivity implements OnMapReadyCallback {

CatchDatabase db;
List<CatchLocation> points;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_map);
// Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
// setSupportActionBar(toolbar);

db = CatchDatabase.getInstance(getApplicationContext());

MapFragment mapFragment = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
Intent intent;
switch (item.getItemId()) {
case R.id.settings:
intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
return true;
case R.id.activity_catch:
intent = new Intent(this, Fish1FormsActivity.class);
startActivity(intent);
return true;
case R.id.activity_map:
intent = new Intent(this, MapActivity.class);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}

@Override
public void onMapReady(GoogleMap map) {

points = new ArrayList();

Runnable r = new Runnable(){
@Override
public void run() {
points = db.catchDao().getLastLocations(100);
}
};

Thread newThread= new Thread(r);
newThread.start();
try {
newThread.join();
}
catch (InterruptedException ie) {

}

map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);

boolean first = true;
for (CatchLocation point : points) {
Log.e("Map", "Got " + point.getCoordinates());
map.addMarker(new MarkerOptions().position(point.getLatLng()).title(point.getCoordinates()));
if (first) {
map.moveCamera(CameraUpdateFactory.newLatLngZoom(point.getLatLng(), (float) 10.0));
first = false;
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
intent = new Intent(this, Fish1FormsActivity.class);
startActivity(intent);
return true;
case R.id.activity_map:
intent = new Intent(this, MapActivity.class);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
Expand Down
10 changes: 1 addition & 9 deletions catch/src/main/res/layout/activity_fish_1_forms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,9 @@ tools:context="uk.ac.masts.sifids.activities.Fish1FormsActivity">
android:text="Stop Tracking Location"
android:onClick="stopTrackingLocation" />

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.google.android.gms.maps.MapFragment"
android:id="@+id/map"
android:layout_marginTop="180dp"
android:layout_width="match_parent"
android:layout_height="240dp"/>


<android.support.v7.widget.RecyclerView
android:id="@+id/form_recycler_view"
android:layout_marginTop="420dp"
android:layout_marginTop="180dp"
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand Down
35 changes: 35 additions & 0 deletions catch/src/main/res/layout/activity_map.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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="uk.ac.masts.sifids.activities.MapActivity">

<!--<android.support.design.widget.AppBarLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:theme="@style/AppTheme.AppBarOverlay">-->

<!--<android.support.v7.widget.Toolbar-->
<!--android:id="@+id/toolbar"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="?attr/actionBarSize"-->
<!--android:background="?attr/colorPrimary"-->
<!--app:popupTheme="@style/AppTheme.PopupOverlay" />-->

<!--</android.support.design.widget.AppBarLayout>-->

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.google.android.gms.maps.MapFragment"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</RelativeLayout>

</android.support.constraint.ConstraintLayout>
2 changes: 2 additions & 0 deletions catch/src/main/res/menu/main_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/activity_catch"
android:title="@string/title_activity_catch" />
<item android:id="@+id/activity_map"
android:title="@string/title_activity_map" />
<item android:id="@+id/settings"
android:title="@string/title_activity_settings" />
</menu>
1 change: 1 addition & 0 deletions catch/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<resources>
<string name="app_name">sifids</string>
<string name="title_activity_settings">Settings</string>
<string name="title_activity_map">Map</string>

<!-- Strings related to Settings -->

Expand Down

0 comments on commit 7dec6f4

Please sign in to comment.