Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Ville Haapavaara committed May 10, 2017
1 parent c9aec26 commit 8ab6131
Show file tree
Hide file tree
Showing 16 changed files with 146 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ private void setupView() {
tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);

ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
ViewPagerAdapter adapter = new ViewPagerAdapter(
getSupportFragmentManager());
adapter.addFragment(new NewHikeFragment(), "New Hike");
adapter.addFragment(new HikeListFragment(), "Your Hikes");
adapter.addFragment(new HikePlansFragment(), "Hike Plans");
Expand Down
59 changes: 40 additions & 19 deletions app/src/main/java/ville/fi/hikemate/Activities/MapActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,21 @@ protected void onCreate(Bundle savedInstanceState) {
saveTrackingButton = (Button) findViewById(R.id.button_stopAndSave);
saveTrackingButton.setEnabled(false);

SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
SupportMapFragment mapFragment =
(SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);

LocalBroadcastManager.getInstance(host).registerReceiver(mMessageReceiver, new IntentFilter("GPSLocations"));
LocalBroadcastManager.getInstance(host).registerReceiver(
mMessageReceiver, new IntentFilter("GPSLocations"));
locationServiceIntent = new Intent(host, LocationService.class);

if (ContextCompat.checkSelfPermission(host,
Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {

if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.ACCESS_FINE_LOCATION)) {
if (ActivityCompat.shouldShowRequestPermissionRationale(
thisActivity, Manifest.permission.ACCESS_FINE_LOCATION)) {

} else {
ActivityCompat.requestPermissions(thisActivity,
Expand Down Expand Up @@ -250,21 +252,28 @@ public void saveHike(View v) {
*/
public void takeImage(View v) {
if (locationFound) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Intent takePictureIntent = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE);

if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
if (takePictureIntent.resolveActivity(
getPackageManager()) != null) {

File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File storageDir = Environment
.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
.format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_.jpg";
File photoFile = new File(storageDir, imageFileName);
mCurrentPhotoPath = photoFile.getAbsolutePath();

if (photoFile != null) {

Uri photoURI = Uri.fromFile(photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
takePictureIntent.putExtra(
MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(
takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
Expand All @@ -281,12 +290,14 @@ public void takeImage(View v) {
* @param data data of the result
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
System.out.println("We have results!");

mMap.addMarker(new MarkerOptions()
.position(new LatLng(hikeLatLng.getLast().latitude, hikeLatLng.getLast().longitude))
.position(new LatLng(hikeLatLng.getLast().latitude,
hikeLatLng.getLast().longitude))
);
hike.addPhotoMapMarker(mCurrentPhotoPath,
hikeLatLng.getLast().latitude,
Expand All @@ -299,7 +310,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
* Sets the user taken photo to the gallery of the device.
*/
private void galleryAddPic() {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Intent mediaScanIntent = new Intent(
Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(mCurrentPhotoPath);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
Expand All @@ -314,7 +326,6 @@ private void galleryAddPic() {
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

}

/**
Expand All @@ -326,15 +337,19 @@ public void onMapReady(GoogleMap googleMap) {
*/
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
String[] permissions,
int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_LOCATION: {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
&& grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
startService(locationServiceIntent);
Debug.toastThisLonger(host, "Fetching location...");
} else {

}

return;
}
}
Expand Down Expand Up @@ -365,7 +380,8 @@ public Hike getHike() {
*/
@Override
public void onReceive(Context context, Intent intent) {
LinkedList<LatLng> locations = (LinkedList) intent.getExtras().get("Locations");
LinkedList<LatLng> locations =
(LinkedList) intent.getExtras().get("Locations");

if (locationFound == false) {
Debug.toastThis(host, "Location fetched, tracking started!");
Expand All @@ -383,10 +399,15 @@ public void onReceive(Context context, Intent intent) {
hikePolyLine.setPoints(hikeLatLng);

if (firstLocationGot == false) {
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(locations.getLast().latitude, locations.getLast().longitude), 15));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(locations.getLast().latitude,
locations.getLast().longitude), 15));
firstLocationGot = true;
} else {
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(locations.getLast().latitude, locations.getLast().longitude), mMap.getCameraPosition().zoom));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(locations.getLast().latitude,
locations.getLast().longitude),
mMap.getCameraPosition().zoom));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
* @version 10.5.2017
* @since 1.8
*/
public class StoredMapActivity extends FragmentActivity implements OnMapReadyCallback {
public class StoredMapActivity extends FragmentActivity
implements OnMapReadyCallback {

/**
* Context of the activity.
Expand Down Expand Up @@ -100,24 +101,30 @@ protected void onCreate(Bundle savedInstanceState) {
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {

if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
if (ActivityCompat.shouldShowRequestPermissionRationale(
thisActivity,
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

} else {
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
new String[]{
Manifest.permission.WRITE_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
}
} else {
sh = new StorageHandler();

SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
SupportMapFragment mapFragment =
(SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.stored_map);
mapFragment.getMapAsync(this);

hikes = sh.readStorage(host);
hike = HikeToLatLng.getLatLng(hikes.get((int) getIntent().getExtras().get("position")));
photoMapMarkers = hikes.get((int) getIntent().getExtras().get("position")).getPhotoMapMarkers();
hike = HikeToLatLng.getLatLng(hikes.get(
(int) getIntent().getExtras().get("position")));
photoMapMarkers = hikes.get(
(int) getIntent().getExtras().get("position"))
.getPhotoMapMarkers();
}
}

Expand All @@ -135,7 +142,6 @@ public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setInfoWindowAdapter(new MarkerInfoWindowAdapter(this));


hikePolyLine = mMap.addPolyline(new PolylineOptions()
.clickable(false));
hikePolyLine.setPoints(hike);
Expand All @@ -150,7 +156,8 @@ public void onMapReady(GoogleMap googleMap) {

initMarkerClickListener(googleMap);

mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(hike.get(0).latitude, hike.get(0).longitude), 15));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(hike.get(0).latitude, hike.get(0).longitude), 15));
}

/**
Expand Down Expand Up @@ -194,23 +201,29 @@ public boolean onMarkerClick(Marker marker) {
*/
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
String[] permissions,
int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE: {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
&& grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
sh = new StorageHandler();

SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
SupportMapFragment mapFragment =
(SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.stored_map);
mapFragment.getMapAsync(this);

hikes = sh.readStorage(host);
hike = HikeToLatLng.getLatLng(hikes.get((int) getIntent().getExtras().get("position")));
photoMapMarkers = hikes.get((int) getIntent().getExtras().get("position")).getPhotoMapMarkers();

hike = HikeToLatLng.getLatLng(hikes.get((int) getIntent()
.getExtras().get("position")));
photoMapMarkers = hikes.get((int) getIntent().getExtras()
.get("position")).getPhotoMapMarkers();
} else {

}

return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class HikeListFragment extends Fragment {
* Default constructor.
*/
public HikeListFragment() {

}

/**
Expand All @@ -66,23 +67,35 @@ public void onCreate(Bundle savedInstanceState) {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_hike_list, container, false);
View view = inflater.inflate(R.layout.fragment_hike_list, container,
false);

emptyList = (TextView) view.findViewById(R.id.list_emptyList);

StorageHandler sh = new StorageHandler();
hikes = sh.readStorage(getActivity());

if (hikes.size() < 1) {
emptyList.setVisibility(View.VISIBLE);
} else {
emptyList.setVisibility(View.GONE);
}

HikeListAdapter adapter = new HikeListAdapter(getActivity(), R.layout.hike_list_item, hikes);
HikeListAdapter adapter = new HikeListAdapter(getActivity(),
R.layout.hike_list_item, hikes);

ListView listView = (ListView) view.findViewById(R.id.ListView_hikes);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

/**
* Starts an activity on item click.
*
* @param parent parent of the adapter
* @param view view of the adapter
* @param position position of the item
* @param id id of the item
*/
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i = new Intent(getActivity(), StoredMapActivity.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class HikePlansFragment extends Fragment {
* Default constructor.
*/
public HikePlansFragment() {

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class NewHikeFragment extends Fragment {
* Default constructor.
*/
public NewHikeFragment() {

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public int getCount() {
return mFragmentList.size();
}

/**
* Adds a fragment to a list.
*
* @param fragment fragment to be added
* @param title fragment's title
*/
public void addFragment(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/ville/fi/hikemate/Resources/Hike.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ public void addPhotoMapMarker(String path, double lat, double lon) {
*
* @return hike's photo markers list.
*/
public LinkedList<PhotoMapMarker> getPhotoMapMarkers() { return photoMapMarkers; }
public LinkedList<PhotoMapMarker> getPhotoMapMarkers() {
return photoMapMarkers;
}

/**
* Returns the hike's location list.
Expand All @@ -134,8 +136,10 @@ public LinkedList<HikeLocation> getLocations() {
public String toString() {
String hike = "";
hike += "[";

for (HikeLocation l : locations) {
hike += l.toString();

if (!l.equals(locations.get(locations.size() - 1))) {
hike += ", ";
}
Expand All @@ -145,6 +149,7 @@ public String toString() {

for (PhotoMapMarker p : photoMapMarkers) {
hike += p.toString();

if (!p.equals(photoMapMarkers.get(photoMapMarkers.size() -1))) {
hike += ", ";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
* @since 1.8
*/
public class HikeList extends LinkedList<Hike> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public double getLat() {
*/
@Override
public String toString() {
return "{ \"lat\":" + String.valueOf(lat) + ", \"lng\":" + String.valueOf(lng) + " }";
return "{ \"lat\":" + String.valueOf(lat) + ", \"lng\":" +
String.valueOf(lng) + " }";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public String toString() {

str += "{";

return "{ \"path\": " + path + ", \"lat\": " + String.valueOf(lat) + ", \"lng\": " + String.valueOf(lon) + "}";
return "{ \"path\": " + path + ", \"lat\": " + String.valueOf(lat) +
", \"lng\": " + String.valueOf(lon) + "}";
}
}
Loading

0 comments on commit 8ab6131

Please sign in to comment.