Search in sources :

Example 1 with Shelter

use of pinkpanthers.pinkshelters.Model.Shelter in project pink-panthers by MrTrai.

the class ListOfSheltersActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout);
    // data to populate the RecyclerView with
    ArrayList<String> shelterNames = new ArrayList<>();
    DBI db = new Db("pinkpanther", "PinkPantherReturns!");
    shelters = db.getAllShelters();
    for (int i = 0; i < shelters.size(); i++) {
        Shelter s = shelters.get(i);
        shelterNames.add(s.getShelterName());
    }
    // set up the RecyclerView
    RecyclerView recyclerView = findViewById(R.id.rvShelters);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    RecyclerAdapter adapter = new RecyclerAdapter(this, shelterNames);
    adapter.setClickListener(this);
    recyclerView.setAdapter(adapter);
    // set up search button
    Button search_button = findViewById(R.id.search_button);
    search_button.setVisibility(View.VISIBLE);
    search_button.setOnClickListener(this);
    Button map_search = findViewById(R.id.button2);
    map_search.setVisibility(View.VISIBLE);
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    assert extras != null;
    username = extras.getString("username");
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) DBI(pinkpanthers.pinkshelters.Model.DBI) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Button(android.widget.Button) Shelter(pinkpanthers.pinkshelters.Model.Shelter) RecyclerView(android.support.v7.widget.RecyclerView) Db(pinkpanthers.pinkshelters.Model.Db)

Example 2 with Shelter

use of pinkpanthers.pinkshelters.Model.Shelter in project pink-panthers by MrTrai.

the class ListOfSheltersActivity method onItemClick.

@Override
public void onItemClick(View view, int position) {
    // clicked on one shelter
    Intent detail = new Intent(this, ShelterDetails.class);
    Shelter s = shelters.get(position);
    detail.putExtra("shelterId", s.getId());
    detail.putExtra("username", username);
    startActivity(detail);
}
Also used : Intent(android.content.Intent) Shelter(pinkpanthers.pinkshelters.Model.Shelter)

Example 3 with Shelter

use of pinkpanthers.pinkshelters.Model.Shelter in project pink-panthers by MrTrai.

the class MapsActivity 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.
 * 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) {
    mMap = googleMap;
    // makes a new shelter when user clicks once on the map
    if (user instanceof Admin) {
        mMap.setOnMapLongClickListener(latLng -> {
            MarkerOptions markerOptions = new MarkerOptions();
            markerOptions.position(latLng);
            // create dialog box
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Add a shelter");
            // get view from xml and inflate into map activity
            LinearLayout mapLayout = findViewById(R.id.linearLayout2);
            LayoutInflater layoutInflater = getLayoutInflater();
            View addShelter = layoutInflater.inflate(R.layout.add_new_shelter, mapLayout, false);
            // get user inputs from dialog box
            EditText shelterNameText = addShelter.findViewById(R.id.accountUserName);
            EditText longitudeText = addShelter.findViewById(R.id.longitude);
            EditText latitudeText = addShelter.findViewById(R.id.latitude);
            EditText addressText = addShelter.findViewById(R.id.address);
            EditText phoneNumText = addShelter.findViewById(R.id.phoneNum);
            EditText restrictionsText = addShelter.findViewById(R.id.restrictions);
            EditText specialNoteText = addShelter.findViewById(R.id.specialNote);
            EditText capacityText = addShelter.findViewById(R.id.capacity);
            // set the longitude and latitude texts to the tapped position on map
            String tappedLongitude = "" + latLng.longitude;
            longitudeText.setText(tappedLongitude);
            String tappedLatitude = "" + latLng.latitude;
            latitudeText.setText(tappedLatitude);
            builder.setView(addShelter);
            // calculating the address from longitude and latitude
            setAddress(latLng, addressText);
            // click on "Add a shelter" button
            builder.setPositiveButton("add a shelter", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    Editable textName = shelterNameText.getText();
                    shelterName = textName.toString();
                    Editable textLongitude = longitudeText.getText();
                    String numLongitude = textLongitude.toString();
                    longitude = Double.parseDouble(numLongitude);
                    Editable textLatitude = latitudeText.getText();
                    String numLatitude = textLatitude.toString();
                    latitude = Double.parseDouble(numLatitude);
                    Editable textAddress = addressText.getText();
                    address = textAddress.toString();
                    Editable textPhone = phoneNumText.getText();
                    phoneNum = textPhone.toString();
                    Editable textRestrict = restrictionsText.getText();
                    restrictions = textRestrict.toString();
                    Editable textSpecial = specialNoteText.getText();
                    specialNote = textSpecial.toString();
                    Editable textCapacity = capacityText.getText();
                    capacity = textCapacity.toString();
                    Shelter newShelter = db.createShelter(shelterName, capacity, specialNote, latitude, longitude, phoneNum, restrictions, address);
                    newShelter.setUpdate_capacity(capacityConverter());
                    // details that pops up when user clicks onto the marker
                    markerOptions.title(newShelter.getShelterName());
                    markerOptions.snippet(newShelter.getAddress() + "\n Phone Number: + " + newShelter.getPhoneNumber() + "\n Restrictions: " + newShelter.getRestrictions() + "\n Vacancy: " + newShelter.getVacancy());
                    // add marker to map and move camera to center its screen around it
                    mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
                    Marker marker = mMap.addMarker(markerOptions);
                    marker.showInfoWindow();
                }
            });
            // click on "cancel" button
            builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    markerOptions.visible(false);
                }
            });
            // show the builder (the dialog window)
            builder.show();
        });
    }
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) DialogInterface(android.content.DialogInterface) Marker(com.google.android.gms.maps.model.Marker) Admin(pinkpanthers.pinkshelters.Model.Admin) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) LayoutInflater(android.view.LayoutInflater) Editable(android.text.Editable) Shelter(pinkpanthers.pinkshelters.Model.Shelter) LinearLayout(android.widget.LinearLayout)

Example 4 with Shelter

use of pinkpanthers.pinkshelters.Model.Shelter in project pink-panthers by MrTrai.

the class HomePageActivity method setShelterText.

/**
 * to set text if a user has claimed any shelter
 */
private void setShelterText() {
    TextView message = findViewById(R.id.shelterMessage);
    if (user instanceof Homeless) {
        try {
            Shelter shelter = db.getShelterById(((Homeless) user).getShelterId());
            String bed = (((Homeless) user).getFamilyMemberNumber() == 1) ? " bed" : " beds";
            message.setText("You have claim " + ((Homeless) user).getFamilyMemberNumber() + bed + " at shelter: " + shelter.getShelterName());
        } catch (NoSuchUserException e) {
            message.setText("You have not claimed any bed yet");
        }
    }
}
Also used : Homeless(pinkpanthers.pinkshelters.Model.Homeless) NoSuchUserException(pinkpanthers.pinkshelters.Model.NoSuchUserException) TextView(android.widget.TextView) Shelter(pinkpanthers.pinkshelters.Model.Shelter)

Example 5 with Shelter

use of pinkpanthers.pinkshelters.Model.Shelter in project pink-panthers by MrTrai.

the class SearchActivity method onItemClick.

@Override
public void onItemClick(View view, int position) {
    Intent detail = new Intent(this, ShelterDetails.class);
    Shelter s = myShelters.get(position);
    detail.putExtra("shelterId", s.getId());
    detail.putExtra("username", username);
    startActivity(detail);
}
Also used : Intent(android.content.Intent) Shelter(pinkpanthers.pinkshelters.Model.Shelter)

Aggregations

Shelter (pinkpanthers.pinkshelters.Model.Shelter)9 Intent (android.content.Intent)4 View (android.view.View)3 AdapterView (android.widget.AdapterView)3 TextView (android.widget.TextView)3 NoSuchUserException (pinkpanthers.pinkshelters.Model.NoSuchUserException)3 AlertDialog (android.app.AlertDialog)2 DialogInterface (android.content.DialogInterface)2 Bundle (android.os.Bundle)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 Editable (android.text.Editable)2 LinearLayout (android.widget.LinearLayout)2 Marker (com.google.android.gms.maps.model.Marker)2 MarkerOptions (com.google.android.gms.maps.model.MarkerOptions)2 ArrayList (java.util.ArrayList)2 Db (pinkpanthers.pinkshelters.Model.Db)2 Context (android.content.Context)1 TextWatcher (android.text.TextWatcher)1 LayoutInflater (android.view.LayoutInflater)1