Search in sources :

Example 1 with ShelterData

use of com.CS2340.shelterapp.Model.ShelterData in project ShelterApp by farzamtn.

the class MapsMasterActivity method newPopup.

/**
 * Event handler for FAB which filters the pins displayed on the map. - Farzam
 *
 * @param view the current view
 */
public void newPopup(View view) {
    // instantiate the maps_master_popup.xml layout file
    LayoutInflater layoutInflater = (LayoutInflater) MapsMasterActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    assert layoutInflater != null;
    View customView = layoutInflater.inflate(R.layout.maps_master_popup, null);
    men_checkbox = customView.findViewById(R.id.men_checkbox);
    women_checkbox = customView.findViewById(R.id.women_checkbox);
    youngAdult_checkbox = customView.findViewById(R.id.youngAdult_checkbox);
    children_checkbox = customView.findViewById(R.id.children_checkbox);
    families_checkbox = customView.findViewById(R.id.families_checkbox);
    veterans_checkbox = customView.findViewById(R.id.veterans_checkbox);
    Button closePopupBtn = customView.findViewById(R.id.closePopupBtn);
    Button resetBtn = customView.findViewById(R.id.resetBtn);
    // Retrieving saved instances of checkedboxes
    SharedPreferences sp = getSharedPreferences("Men Check Boxes", MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    men_checkbox.setChecked(sp.getBoolean("men check", false));
    women_checkbox.setChecked(sp.getBoolean("women check", false));
    youngAdult_checkbox.setChecked(sp.getBoolean("young adult check", false));
    children_checkbox.setChecked(sp.getBoolean("children check", false));
    families_checkbox.setChecked(sp.getBoolean("families check", false));
    veterans_checkbox.setChecked(sp.getBoolean("veterans check", false));
    // instantiate popup window
    popupWindow = new PopupWindow(customView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    popupWindow.setOutsideTouchable(false);
    popupWindow.setFocusable(true);
    CoordinatorLayout c = findViewById(R.id.coordinatorLayout);
    // display the popup window
    popupWindow.showAtLocation(c, Gravity.CENTER, 0, 0);
    // set filter and close the popupwindow
    closePopupBtn.setOnClickListener(v -> {
        // Saving checkbox instances
        editor.putBoolean("men check", men_checkbox.isChecked());
        editor.apply();
        editor.putBoolean("women check", women_checkbox.isChecked());
        editor.apply();
        editor.putBoolean("young adult check", youngAdult_checkbox.isChecked());
        editor.apply();
        editor.putBoolean("children check", children_checkbox.isChecked());
        editor.apply();
        editor.putBoolean("families check", families_checkbox.isChecked());
        editor.apply();
        editor.putBoolean("veterans check", veterans_checkbox.isChecked());
        editor.apply();
        // If all filters all selected show everything
        if (!(men_checkbox.isChecked() && women_checkbox.isChecked() && youngAdult_checkbox.isChecked() && children_checkbox.isChecked() && families_checkbox.isChecked() && veterans_checkbox.isChecked())) {
            for (Marker m : markers) {
                m.setVisible(true);
            }
        }
        // Making sure at least one filter is selected
        if (men_checkbox.isChecked() || women_checkbox.isChecked() || youngAdult_checkbox.isChecked() || children_checkbox.isChecked() || families_checkbox.isChecked() || veterans_checkbox.isChecked()) {
            for (Marker m : markers) {
                m.setVisible(false);
                ShelterData s = model.findItemByName(m.getTitle());
                assert s != null;
                String restrictions = s.getRestrictions().trim().toLowerCase();
                // Displaying shelters with no restrictions for all filters
                if ("anyone".equals(restrictions) || "no restrictions".equals(restrictions)) {
                    m.setVisible(true);
                }
                if (men_checkbox.isChecked()) {
                    if ("men".equals(restrictions)) {
                        m.setVisible(true);
                    }
                }
                if (women_checkbox.isChecked()) {
                    if (restrictions.contains("women")) {
                        m.setVisible(true);
                    }
                }
                if (youngAdult_checkbox.isChecked()) {
                    if ("young adults".equals(s.getRestrictions().toLowerCase())) {
                        m.setVisible(true);
                    }
                }
                if (children_checkbox.isChecked()) {
                    if (restrictions.contains("children")) {
                        m.setVisible(true);
                    }
                }
                if (families_checkbox.isChecked()) {
                    if (restrictions.contains("famil")) {
                        m.setVisible(true);
                    }
                }
                if (veterans_checkbox.isChecked()) {
                    if ("veterans".equals(restrictions)) {
                        m.setVisible(true);
                    }
                }
            }
        }
        popupWindow.dismiss();
    });
    // show all markers again and close the popupwindow
    resetBtn.setOnClickListener(view1 -> {
        for (Marker m : markers) {
            m.setVisible(true);
        }
        // Move camera to GT (DEFAULT) coordinates - Added by Farzam
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mDefaultLocation, DEFAULT_ZOOM));
        // Clearing all check boxes and their saved instances
        men_checkbox.setChecked(false);
        women_checkbox.setChecked(false);
        youngAdult_checkbox.setChecked(false);
        children_checkbox.setChecked(false);
        families_checkbox.setChecked(false);
        veterans_checkbox.setChecked(false);
        editor.putBoolean("men check", men_checkbox.isChecked());
        editor.apply();
        editor.putBoolean("women check", women_checkbox.isChecked());
        editor.apply();
        editor.putBoolean("young adult check", youngAdult_checkbox.isChecked());
        editor.apply();
        editor.putBoolean("children check", children_checkbox.isChecked());
        editor.apply();
        editor.putBoolean("families check", families_checkbox.isChecked());
        editor.apply();
        editor.putBoolean("veterans check", veterans_checkbox.isChecked());
        editor.apply();
        popupWindow.dismiss();
    });
}
Also used : CoordinatorLayout(android.support.design.widget.CoordinatorLayout) ShelterData(com.CS2340.shelterapp.Model.ShelterData) Button(android.widget.Button) SharedPreferences(android.content.SharedPreferences) LayoutInflater(android.view.LayoutInflater) PopupWindow(android.widget.PopupWindow) Marker(com.google.android.gms.maps.model.Marker) NavigationView(android.support.design.widget.NavigationView) View(android.view.View)

Example 2 with ShelterData

use of com.CS2340.shelterapp.Model.ShelterData in project ShelterApp by farzamtn.

the class FindItemsByQueryTests method setUp.

@BeforeClass
public static void setUp() {
    model = Shelters.INSTANCE;
    sampleData1 = new ShelterData(0, "Atlanta House", "150", "Men", -84.410142, 33.780174, "921 Howell Mill Road, Atlanta, Georgia 30318", "General recovery services", "(404) 000-0001");
    sampleData2 = new ShelterData(1, "My House, Your House", "30", "Women/Children", -84.408771, 33.784889, "1300 Joseph E. Boone Blvd NW, Atlanta, GA 30314", "Family services", "(404) 987-4545");
    sampleData3 = new ShelterData(2, "Atlanta Center", "120", "Families w/ Newborns", -84.39265, 33.765162, "156 Mills Street, Atlanta, Georgia 30313", "Trasitional housing", "(404) 404-4404");
    sampleData4 = new ShelterData(3, "Gatech's Inn", "80", "Children/Young Adults", -84.392273, 33.76515, "607 Peachtree Street NE Atlanta, GA 30308", "Shelter and recovery services", "(404) 100-2340");
    sampleData5 = new ShelterData(4, "East Center", "100", "Anyone", -84.384433, 33.770949, "1559 Johnson Road NW, Atlanta, GA 30318", "Emergency Shelter", "(404) 123-4567");
    model.addItem(sampleData1);
    model.addItem(sampleData2);
    model.addItem(sampleData3);
    model.addItem(sampleData4);
    model.addItem(sampleData5);
    male = new ArrayList<>();
    male.add(sampleData1);
    male.add(sampleData3);
    male.add(sampleData4);
    male.add(sampleData5);
    female = new ArrayList<>();
    female.add(sampleData2);
    female.add(sampleData3);
    female.add(sampleData4);
    female.add(sampleData5);
    family = new ArrayList<>();
    family.add(sampleData3);
    child = new ArrayList<>();
    child.add(sampleData2);
    child.add(sampleData4);
    youngAdult = new ArrayList<>();
    youngAdult.add(sampleData4);
    anyone = new ArrayList<>();
    anyone.add(sampleData5);
    name1 = new ArrayList<>();
    name1.add(sampleData1);
    name1.add(sampleData2);
    name2 = new ArrayList<>();
    name2.add(sampleData3);
    name2.add(sampleData5);
    address1 = new ArrayList<>();
    address1.add(sampleData1);
    address1.add(sampleData5);
    address2 = new ArrayList<>();
    address2.add(sampleData1);
    address2.add(sampleData3);
    specialNote1 = new ArrayList<>();
    specialNote1.add(sampleData5);
    specialNote2 = new ArrayList<>();
    specialNote2.add(sampleData1);
    specialNote2.add(sampleData4);
}
Also used : ShelterData(com.CS2340.shelterapp.Model.ShelterData) BeforeClass(org.junit.BeforeClass)

Example 3 with ShelterData

use of com.CS2340.shelterapp.Model.ShelterData in project ShelterApp by farzamtn.

the class MapsMasterActivity method onMapReady.

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    // Move camera to GT (DEFAULT) coordinates - Added by Farzam
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mDefaultLocation, DEFAULT_ZOOM));
    markers = new ArrayList<>();
    // Adding marker pins for all shelters in the DB
    for (ShelterData s : model.getItems()) {
        String shelterName = s.getName();
        double shelterLatitude = s.getLatitude();
        double shelterLongitude = s.getLongitude();
        String shelterPhoneNumber = s.getPhoneNumber();
        LatLng shelterLocation = new LatLng(shelterLatitude, shelterLongitude);
        Marker m = mMap.addMarker(new MarkerOptions().position(shelterLocation).title(shelterName).snippet(shelterPhoneNumber));
        // For later use in filtering markers
        markers.add(m);
    }
    // Starting the respective Detail page about this shelter using the key - Farzam
    mMap.setOnInfoWindowClickListener(marker -> {
        Intent intent = new Intent(getBaseContext(), ShelterItemDetailActivity.class);
        intent.putExtra(ShelterItemDetailFragment.ARG_ITEM_ID, Objects.requireNonNull(model.findItemByName(marker.getTitle())).getKey());
        startActivity(intent);
    });
    // Prompt the user for permission.
    getLocationPermission();
    // Turn on the My Location layer and the related control on the map.
    updateLocationUI();
    // Get the current location of the device and set the position of the map.
    getDeviceLocation();
}
Also used : ShelterData(com.CS2340.shelterapp.Model.ShelterData) MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) Intent(android.content.Intent) LatLng(com.google.android.gms.maps.model.LatLng) Marker(com.google.android.gms.maps.model.Marker)

Example 4 with ShelterData

use of com.CS2340.shelterapp.Model.ShelterData in project ShelterApp by farzamtn.

the class ShelterItemDetailActivity method displayCheckInError.

private void displayCheckInError() {
    ShelterData mItem = Shelters.INSTANCE.findItemById(checkedIn);
    AlertDialog.Builder builder = new AlertDialog.Builder(ShelterItemDetailActivity.this);
    builder.setTitle("User Already Checked-In");
    assert mItem != null;
    builder.setMessage("The current user is already checked-in to another Shelter.\n" + "User checked in at " + mItem.getName());
    // Set up the buttons
    builder.setPositiveButton("OK", (dialog, which) -> {
    });
    builder.show();
}
Also used : AlertDialog(android.app.AlertDialog) ShelterData(com.CS2340.shelterapp.Model.ShelterData)

Example 5 with ShelterData

use of com.CS2340.shelterapp.Model.ShelterData in project ShelterApp by farzamtn.

the class ShelterModelTest method setUp.

@BeforeClass
public static // (Or we can put addItem in every method)
void setUp() {
    model = Shelters.INSTANCE;
    sampleShelterData = new ShelterData(0, "Test Shelter", "20", "Men", 33.7756, -84.3963, "123 Test Dr, Atlanta, GA 30332", "NONE", "1231231234");
    model.addItem(sampleShelterData);
}
Also used : ShelterData(com.CS2340.shelterapp.Model.ShelterData) BeforeClass(org.junit.BeforeClass)

Aggregations

ShelterData (com.CS2340.shelterapp.Model.ShelterData)5 Marker (com.google.android.gms.maps.model.Marker)2 BeforeClass (org.junit.BeforeClass)2 AlertDialog (android.app.AlertDialog)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)1 NavigationView (android.support.design.widget.NavigationView)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 Button (android.widget.Button)1 PopupWindow (android.widget.PopupWindow)1 LatLng (com.google.android.gms.maps.model.LatLng)1 MarkerOptions (com.google.android.gms.maps.model.MarkerOptions)1