Search in sources :

Example 1 with Photo

use of com.cmput301w18t05.taskzilla.Photo in project Taskzilla by CMPUT301W18T05.

the class ViewTaskActivity method setProviderField.

/**
 * setPoviderField
 * sets the provider text and picture accordingly
 * if the task status is bidded then the best bidder will appear on the field
 * else if the task status is assigned or completed then the provider will appear
 * @author myapplestory
 */
public void setProviderField() {
    if (task.getStatus().equals("requested")) {
        Photo defaultPhoto = new Photo("");
        ProviderPicture.setImageBitmap(defaultPhoto.StringToBitmap());
        ProviderName.setText("No bidders :'(");
    } else if (task.getStatus().equals("bidded")) {
        ProfileController profileController = new ProfileController(this.findViewById(android.R.id.content), this);
        profileController.setUserID(task.getBestBidder());
        profileController.getUserRequest();
        User tempUser = profileController.getUser();
        String text = "Best bidder: " + tempUser.getName() + "\nBid amount: " + "$" + String.format(Locale.CANADA, "%.2f", task.getBestBid());
        ProviderName.setText(text);
        try {
            ProviderPicture.setImageBitmap(tempUser.getPhoto().StringToBitmap());
        } catch (Exception e) {
            Photo defaultPhoto = new Photo("");
            ProviderPicture.setImageBitmap(defaultPhoto.StringToBitmap());
        }
    } else if (task.getStatus().equals("assigned") || task.isComplete()) {
        String text = "Provider: " + TaskProvider.getName();
        ProviderName.setText(text);
        try {
            ProviderPicture.setImageBitmap(TaskProvider.getPhoto().StringToBitmap());
        } catch (Exception e) {
            Photo defaultPhoto = new Photo("");
            ProviderPicture.setImageBitmap(defaultPhoto.StringToBitmap());
        }
    }
}
Also used : ProfileController(com.cmput301w18t05.taskzilla.controller.ProfileController) User(com.cmput301w18t05.taskzilla.User) com.cmput301w18t05.taskzilla.currentUser(com.cmput301w18t05.taskzilla.currentUser) Photo(com.cmput301w18t05.taskzilla.Photo)

Example 2 with Photo

use of com.cmput301w18t05.taskzilla.Photo in project Taskzilla by CMPUT301W18T05.

the class ViewTaskActivity method setRequesterField.

/**
 * setRequesterField
 * sets the text and picture in the requester field
 * @author myapplestory
 */
public void setRequesterField() {
    String text = "Requester: " + TaskRequester.getName();
    RequesterName.setText(text);
    try {
        RequesterPicture.setImageBitmap(TaskRequester.getPhoto().StringToBitmap());
    } catch (Exception e) {
        Photo defaultPhoto = new Photo("");
        RequesterPicture.setImageBitmap(defaultPhoto.StringToBitmap());
    }
}
Also used : Photo(com.cmput301w18t05.taskzilla.Photo)

Example 3 with Photo

use of com.cmput301w18t05.taskzilla.Photo in project Taskzilla by CMPUT301W18T05.

the class ZoomImageActivity method onCreate.

/**
 * retrieve the photo from the previous activity and set
 * the imageview
 *
 * @param savedInstanceState
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_zoom_image);
    String stringOfImage = getIntent().getStringExtra("Photo");
    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>"));
    photo = new Photo(stringOfImage);
    ZoomedImageView = findViewById(R.id.ZoomedImage);
    ZoomedImageView.setImageBitmap(photo.StringToBitmap());
    dector = new ScaleGestureDetector(this, new ScaleListener());
}
Also used : AppColors(com.cmput301w18t05.taskzilla.AppColors) ColorDrawable(android.graphics.drawable.ColorDrawable) Photo(com.cmput301w18t05.taskzilla.Photo) ScaleGestureDetector(android.view.ScaleGestureDetector) ActionBar(android.support.v7.app.ActionBar)

Example 4 with Photo

use of com.cmput301w18t05.taskzilla.Photo 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);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Task(com.cmput301w18t05.taskzilla.Task) DialogInterface(android.content.DialogInterface) Photo(com.cmput301w18t05.taskzilla.Photo) RecyclerViewAdapter(com.cmput301w18t05.taskzilla.RecyclerViewAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) CustomOnItemClick(com.cmput301w18t05.taskzilla.CustomOnItemClick) AppColors(com.cmput301w18t05.taskzilla.AppColors) SupportMapFragment(com.google.android.gms.maps.SupportMapFragment) LatLng(com.google.android.gms.maps.model.LatLng) ActionBar(android.support.v7.app.ActionBar) Status(com.google.android.gms.common.api.Status) EditText(android.widget.EditText) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) PlaceSelectionListener(com.google.android.gms.location.places.ui.PlaceSelectionListener) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) ColorDrawable(android.graphics.drawable.ColorDrawable) Place(com.google.android.gms.location.places.Place)

Example 5 with Photo

use of com.cmput301w18t05.taskzilla.Photo 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();
    }
}
Also used : Bitmap(android.graphics.Bitmap) MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) InputStream(java.io.InputStream) DecimalFormat(java.text.DecimalFormat) FileNotFoundException(java.io.FileNotFoundException) Photo(com.cmput301w18t05.taskzilla.Photo) LatLng(com.google.android.gms.maps.model.LatLng) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Uri(android.net.Uri)

Aggregations

Photo (com.cmput301w18t05.taskzilla.Photo)12 ColorDrawable (android.graphics.drawable.ColorDrawable)5 ActionBar (android.support.v7.app.ActionBar)5 Intent (android.content.Intent)4 AppColors (com.cmput301w18t05.taskzilla.AppColors)4 LatLng (com.google.android.gms.maps.model.LatLng)4 Bitmap (android.graphics.Bitmap)3 Uri (android.net.Uri)3 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3 View (android.view.View)3 EditText (android.widget.EditText)3 CustomOnItemClick (com.cmput301w18t05.taskzilla.CustomOnItemClick)3 EmailAddress (com.cmput301w18t05.taskzilla.EmailAddress)3 PhoneNumber (com.cmput301w18t05.taskzilla.PhoneNumber)3 RecyclerViewAdapter (com.cmput301w18t05.taskzilla.RecyclerViewAdapter)3 SupportMapFragment (com.google.android.gms.maps.SupportMapFragment)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileNotFoundException (java.io.FileNotFoundException)3 InputStream (java.io.InputStream)3 DialogInterface (android.content.DialogInterface)2