use of com.cmput301w18t05.taskzilla.Task in project Taskzilla by CMPUT301W18T05.
the class EditTaskActivity method onCreate.
/**
* Activity uses the activity_edit_task.xml layout
* Initialize a task with edited fields
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
task = new Task();
ctx = getApplicationContext();
super.onCreate(savedInstanceState);
setTitle("Edit Task");
setContentView(R.layout.activity_edit_task);
Double taskLat = Double.parseDouble(getIntent().getStringExtra("Lat"));
Double taskLon = Double.parseDouble(getIntent().getStringExtra("Lon"));
taskLocation = new LatLng(taskLat, taskLon);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.dragdropMap2);
mapFragment.getMapAsync(this);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
currentLocationButton = findViewById(R.id.currentLocationButton);
autocompleteFragment = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
/**
* When the user searchs a location
* set the hint and the taskLocation
* @param place
*/
@Override
public void onPlaceSelected(Place place) {
// TODO: Get info about the selected place.
autocompleteFragment.setHint(place.getName());
taskLocation = place.getLatLng();
}
@Override
public void onError(Status status) {
// TODO: Handle the error.
taskLocation = null;
Log.i("err", "An error occurred: " + status);
}
});
autocompleteFragment.setHint(getIntent().getStringExtra("Lat") + ", " + getIntent().getStringExtra("Lon"));
autocompleteFragment.setText(getIntent().getStringExtra("Lat") + ", " + getIntent().getStringExtra("Lon"));
getLocation();
autocompleteFragment.setBoundsBias(new LatLngBounds(new LatLng(lat - 0.25, lon - 0.25), new LatLng(lat + 0.25, lon + 0.25)));
currentLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
setCurrentLocation();
}
});
AppColors appColors = AppColors.getInstance();
ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(appColors.getActionBarColor())));
actionBar.setTitle(Html.fromHtml("<font color='" + appColors.getActionBarTextColor() + "'>Taskzilla</font>"));
EditText TaskNameText = findViewById(R.id.TaskName);
EditText DescriptionText = findViewById(R.id.Description);
String taskName = getIntent().getStringExtra("task Name");
String taskDescription = getIntent().getStringExtra("Description");
// Dummy
task.setName(taskName);
// Dummy
task.setDescription(taskDescription);
TaskNameText.setText(task.getName());
DescriptionText.setText(task.getDescription());
photos = new ArrayList<>();
ArrayList<String> photosString = getIntent().getStringArrayListExtra("photos");
for (int i = 0; i < photosString.size(); i++) {
Log.i("test", photosString.get(i));
photos.add(new Photo(photosString.get(i)));
}
recyclerPhotosView = findViewById(R.id.listOfPhotos);
layoutManager = new LinearLayoutManager(ctx, LinearLayoutManager.HORIZONTAL, false);
recyclerPhotosView.setLayoutManager(layoutManager);
recyclerPhotosViewAdapter = new RecyclerViewAdapter(ctx, photos, new CustomOnItemClick() {
@Override
public void onColumnClicked(final int position) {
// taken from https://stackoverflow.com/questions/2115758/how-do-i-display-an-alert-dialog-on-android
// 2018-03-16
AlertDialog.Builder alert = new AlertDialog.Builder(EditTaskActivity.this);
alert.setTitle("Delete Photo");
alert.setMessage("Are you sure you want to delete this photo?");
// DELETE CODE
alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
photos.remove(position);
dialogInterface.dismiss();
recyclerPhotosViewAdapter.notifyDataSetChanged();
}
});
// DELETE CANCEL CODE
alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
alert.show();
}
});
recyclerPhotosView.setAdapter(recyclerPhotosViewAdapter);
}
use of com.cmput301w18t05.taskzilla.Task in project Taskzilla by CMPUT301W18T05.
the class EditTaskActivity method onActivityResult.
/**
* Upon returning from selecting photos, list of photos
* is set for the task
*
* if reqcode is 2
* get the lat and lon passed back and add a marker to the map
*
* @param reqCode
* @param resultCode
* @param data
*/
@Override
protected void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
// 2018-04-03
if (resultCode == RESULT_OK) {
if (reqCode == 2) {
DecimalFormat df = new DecimalFormat("#.#####");
taskLocation = new LatLng(Double.parseDouble(data.getStringExtra("Lat")), Double.parseDouble(data.getStringExtra("Lon")));
autocompleteFragment.setHint(df.format(Double.parseDouble(data.getStringExtra("Lat"))) + ", " + df.format(Double.parseDouble(data.getStringExtra("Lon"))));
autocompleteFragment.setText(df.format(Double.parseDouble(data.getStringExtra("Lat"))) + ", " + df.format(Double.parseDouble(data.getStringExtra("Lon"))));
mMap.clear();
mMap.addMarker(new MarkerOptions().position(taskLocation).title("Your Location"));
moveToCurrentLocation(taskLocation);
} else {
try {
final Uri imageUri = data.getData();
final InputStream imageStream = getContentResolver().openInputStream(imageUri);
final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
maxSize = 65536;
Log.i("ACTUAL SIZE", String.valueOf(selectedImage.getByteCount()));
Integer width = 1200;
Integer height = 1200;
Bitmap resizedImage;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
selectedImage.compress(Bitmap.CompressFormat.JPEG, 50, stream);
Log.i("size", String.valueOf(stream.size()));
while (stream.size() > maxSize) {
width = width - 200;
height = height - 200;
stream = new ByteArrayOutputStream();
resizedImage = Bitmap.createScaledBitmap(selectedImage, width, height, false);
resizedImage.compress(Bitmap.CompressFormat.JPEG, 50, stream);
Log.i("size", String.valueOf(stream.size()));
}
byte[] byteImage;
byteImage = stream.toByteArray();
String image = Base64.encodeToString(byteImage, Base64.DEFAULT);
photos.add(new Photo(image));
Log.i("hi", String.valueOf(photos.size()));
recyclerPhotosViewAdapter.notifyDataSetChanged();
} catch (FileNotFoundException e) {
e.printStackTrace();
Toast.makeText(EditTaskActivity.this, "Something went wrong", Toast.LENGTH_LONG).show();
}
}
} else {
Toast.makeText(EditTaskActivity.this, "You haven't picked Image", Toast.LENGTH_LONG).show();
}
}
use of com.cmput301w18t05.taskzilla.Task in project Taskzilla by CMPUT301W18T05.
the class MapActivity method onMapReady.
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
getLocation();
mMap = googleMap;
if (getIntent().getStringExtra("drag") != null) {
LatLng yourLocation = new LatLng(lat, lon);
moveToCurrentLocation(yourLocation);
final Marker locationMarker = mMap.addMarker(new MarkerOptions().position(new LatLng(lat, lon)).title("Hold and drag to pick your task location").draggable(true));
locationMarker.showInfoWindow();
mMap.setOnMarkerDragListener(new GoogleMap.OnMarkerDragListener() {
/**
* Hide marker window when dragging
* @param arg0
*/
@Override
public void onMarkerDragStart(Marker arg0) {
// TODO Auto-generated method stub
arg0.hideInfoWindow();
}
/**
* Show LatLon of final location of their marker and prompt user to click
* Switch back to previous activity returning the latitude and longitude
* @param arg0
*/
@SuppressWarnings("unchecked")
@Override
public void onMarkerDragEnd(Marker arg0) {
// TODO Auto-generated method stub
DecimalFormat df = new DecimalFormat("#.#####");
mMap.animateCamera(CameraUpdateFactory.newLatLng(arg0.getPosition()));
arg0.setTitle("Lat: " + Double.toString(Double.valueOf(df.format(arg0.getPosition().latitude))) + " Lon: " + Double.toString(Double.valueOf(df.format(arg0.getPosition().longitude))));
arg0.setSnippet("Click here to confirm location");
arg0.showInfoWindow();
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Intent intent = new Intent();
intent.putExtra("Lat", Double.toString(Double.valueOf(marker.getPosition().latitude)));
intent.putExtra("Lon", Double.toString(Double.valueOf(marker.getPosition().longitude)));
setResult(RESULT_OK, intent);
finish();
}
});
}
/**
* Hide window when dragging marker on map
* @param arg0
*/
@Override
public void onMarkerDrag(Marker arg0) {
// TODO Auto-generated method stub
arg0.hideInfoWindow();
}
});
} else if (getIntent().getStringExtra("lat") != null) {
LatLng tLocation = new LatLng(Double.parseDouble(getIntent().getStringExtra("lat")), Double.parseDouble(getIntent().getStringExtra("lon")));
mMap.addMarker(new MarkerOptions().position(tLocation).title(getIntent().getStringExtra("TaskName")).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))).showInfoWindow();
mMap.moveCamera(CameraUpdateFactory.newLatLng(tLocation));
moveToCurrentLocation(tLocation);
LatLng yourLocation = new LatLng(lat, lon);
mMap.addMarker(new MarkerOptions().position(yourLocation).title("Your Location").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN))).showInfoWindow();
} else {
myLocation = new Location("You");
myLocation.setLatitude(lat);
myLocation.setLongitude(lon);
myLocation.setTime(new Date().getTime());
// Add a marker to your location and move the camera
LatLng yourLocation = new LatLng(lat, lon);
mMap.addMarker(new MarkerOptions().position(yourLocation).title("Your Location").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN))).showInfoWindow();
mMap.moveCamera(CameraUpdateFactory.newLatLng(yourLocation));
moveToCurrentLocation(yourLocation);
mMap.addCircle(new CircleOptions().center(yourLocation).radius(5000).strokeColor(Color.RED).strokeWidth((float) 5.0));
Location taskLocation;
// *Add locations of tasks*//
for (Task t : tasks) {
if (t.getLocation() != null) {
taskLocation = new Location("Task");
taskLocation.setLatitude(t.getLocation().latitude);
taskLocation.setLongitude(t.getLocation().longitude);
// Set time as current Date
taskLocation.setTime(new Date().getTime());
if (myLocation.distanceTo(taskLocation) <= 5000) {
LatLng taskslonlat = new LatLng(t.getLocation().latitude, t.getLocation().longitude);
if (t.getStatus().equalsIgnoreCase("requested")) {
mMap.addMarker(new MarkerOptions().position(taskslonlat).title(t.getName()).snippet("No Bids").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN))).setTag(t.getId());
}
if (t.getStatus().equalsIgnoreCase("bidded")) {
mMap.addMarker(new MarkerOptions().position(taskslonlat).title(t.getName()).snippet("Best Bid: $" + t.getBestBid().toString()).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE))).setTag(t.getId());
}
}
}
}
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
if (marker.getTag() != null) {
Intent intent = new Intent(getApplicationContext(), ViewTaskActivity.class);
intent.putExtra("TaskId", marker.getTag().toString());
startActivity(intent);
}
}
});
}
}
use of com.cmput301w18t05.taskzilla.Task in project Taskzilla by CMPUT301W18T05.
the class NotificationsController method checkTaskExistRequest.
/**
* Returns boolean value which checks if task user put in exists in the elasticsearch server
*
* @param taskId Task to be checked
* @return Boolean value
*/
public boolean checkTaskExistRequest(String taskId) {
GetTaskRequest getTaskRequest = new GetTaskRequest(taskId);
RequestManager.getInstance().invokeRequest(ctx, getTaskRequest);
if (getTaskRequest.getResult() == null)
return false;
else
return true;
}
use of com.cmput301w18t05.taskzilla.Task in project Taskzilla by CMPUT301W18T05.
the class RequestManagerTest method testGetTaskRequest.
public void testGetTaskRequest() {
addUser();
addTask();
GetTaskRequest getTaskRequest = new GetTaskRequest(task.getId());
RequestManager.getInstance().invokeRequest(ctx, getTaskRequest);
Task ret = getTaskRequest.getResult();
Log.i("Event", "RETURNED TASK: " + ret.toString());
assertEquals(task.getId(), ret.getId());
assertEquals(task.getName(), ret.getName());
assertEquals(task.getDescription(), ret.getDescription());
}
Aggregations