diff --git a/catch/src/main/AndroidManifest.xml b/catch/src/main/AndroidManifest.xml index f138301..2f4545d 100644 --- a/catch/src/main/AndroidManifest.xml +++ b/catch/src/main/AndroidManifest.xml @@ -27,7 +27,6 @@ android:theme="@style/AppTheme.NoActionBar"> - @@ -48,6 +47,14 @@ android:name="android.support.PARENT_ACTIVITY" android:value=".activities.EditFish1FormActivity" /> + + + - + diff --git a/catch/src/main/java/uk/ac/masts/sifids/activities/EditFish1FormActivity.java b/catch/src/main/java/uk/ac/masts/sifids/activities/EditFish1FormActivity.java index cb22848..85170d0 100644 --- a/catch/src/main/java/uk/ac/masts/sifids/activities/EditFish1FormActivity.java +++ b/catch/src/main/java/uk/ac/masts/sifids/activities/EditFish1FormActivity.java @@ -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); } diff --git a/catch/src/main/java/uk/ac/masts/sifids/activities/EditFish1FormRowActivity.java b/catch/src/main/java/uk/ac/masts/sifids/activities/EditFish1FormRowActivity.java index 9b1a2d6..25e94eb 100644 --- a/catch/src/main/java/uk/ac/masts/sifids/activities/EditFish1FormRowActivity.java +++ b/catch/src/main/java/uk/ac/masts/sifids/activities/EditFish1FormRowActivity.java @@ -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); } diff --git a/catch/src/main/java/uk/ac/masts/sifids/activities/Fish1FormsActivity.java b/catch/src/main/java/uk/ac/masts/sifids/activities/Fish1FormsActivity.java index 7ed6d25..85740a1 100644 --- a/catch/src/main/java/uk/ac/masts/sifids/activities/Fish1FormsActivity.java +++ b/catch/src/main/java/uk/ac/masts/sifids/activities/Fish1FormsActivity.java @@ -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; @@ -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 @@ -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() { @@ -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); } @@ -129,38 +110,4 @@ public void stopTrackingLocation(View v) { stopService(new Intent(this, CatchLocationService.class)); } - List 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; - } - } - } - } diff --git a/catch/src/main/java/uk/ac/masts/sifids/activities/MapActivity.java b/catch/src/main/java/uk/ac/masts/sifids/activities/MapActivity.java new file mode 100644 index 0000000..870d922 --- /dev/null +++ b/catch/src/main/java/uk/ac/masts/sifids/activities/MapActivity.java @@ -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 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; + } + } + } + +} diff --git a/catch/src/main/java/uk/ac/masts/sifids/activities/SettingsActivity.java b/catch/src/main/java/uk/ac/masts/sifids/activities/SettingsActivity.java index c1cf54e..4f5ed7b 100644 --- a/catch/src/main/java/uk/ac/masts/sifids/activities/SettingsActivity.java +++ b/catch/src/main/java/uk/ac/masts/sifids/activities/SettingsActivity.java @@ -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); } diff --git a/catch/src/main/res/layout/activity_fish_1_forms.xml b/catch/src/main/res/layout/activity_fish_1_forms.xml index 3774ed5..d2a62f2 100644 --- a/catch/src/main/res/layout/activity_fish_1_forms.xml +++ b/catch/src/main/res/layout/activity_fish_1_forms.xml @@ -42,17 +42,9 @@ tools:context="uk.ac.masts.sifids.activities.Fish1FormsActivity"> android:text="Stop Tracking Location" android:onClick="stopTrackingLocation" /> - - - diff --git a/catch/src/main/res/layout/activity_map.xml b/catch/src/main/res/layout/activity_map.xml new file mode 100644 index 0000000..31ea356 --- /dev/null +++ b/catch/src/main/res/layout/activity_map.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/catch/src/main/res/menu/main_menu.xml b/catch/src/main/res/menu/main_menu.xml index 856c65e..906a226 100644 --- a/catch/src/main/res/menu/main_menu.xml +++ b/catch/src/main/res/menu/main_menu.xml @@ -2,6 +2,8 @@ + \ No newline at end of file diff --git a/catch/src/main/res/values/strings.xml b/catch/src/main/res/values/strings.xml index 6bf46a8..2b87779 100644 --- a/catch/src/main/res/values/strings.xml +++ b/catch/src/main/res/values/strings.xml @@ -1,6 +1,7 @@ sifids Settings + Map