Skip to content

Commit

Permalink
drop down menu implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
zinaheng committed Apr 24, 2021
1 parent 6cb9100 commit 52355d6
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 22 deletions.
56 changes: 46 additions & 10 deletions app/src/main/java/com/example/petneeds/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Spinner;

import com.codepath.asynchttpclient.AsyncHttpClient;
import com.codepath.asynchttpclient.callback.JsonHttpResponseHandler;
Expand All @@ -31,14 +34,14 @@
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MainActivity extends FragmentActivity implements OnMapReadyCallback {
public class MainActivity extends FragmentActivity implements OnMapReadyCallback,AdapterView.OnItemSelectedListener {


public static final String TAG ="MainActivity";
public static final String TAG = "MainActivity";
static Double lng;
static Double lat;
List<PetInfo> info;

private Spinner sp;
GoogleMap map;

@Override
Expand All @@ -47,10 +50,32 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);



RecyclerView rvPetDetails = findViewById(R.id.rvPetDetails);
final EditText enteredZip = (EditText)findViewById(R.id.etZipcode);
final EditText enteredZip = (EditText) findViewById(R.id.etZipcode);
ImageButton search = findViewById(R.id.searchbutton);
//below is the code for setting up the drop down menu
sp = (Spinner) findViewById(R.id.drSpin);
// ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, items);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.Categories, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
sp.setAdapter(adapter);


sp.setOnItemSelectedListener(this);
// @Override
// public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
//
// }
//
// @Override
// public void onNothingSelected(AdapterView<?> parent){
//
// }
//
//}



info = new ArrayList<>();
final PetAdapter petAdapter = new PetAdapter(this, info);
Expand All @@ -60,20 +85,20 @@ protected void onCreate(Bundle savedInstanceState) {
search.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String value= enteredZip.getText().toString();
final String ZIPCODE = "https://maps.googleapis.com/maps/api/geocode/json?address=" +value+"&key=AIzaSyA3eIDiQk5MNmPvyx62qERmyb54UzORsIg";
String value = enteredZip.getText().toString();
final String ZIPCODE = "https://maps.googleapis.com/maps/api/geocode/json?address=" + value + "&key=AIzaSyA3eIDiQk5MNmPvyx62qERmyb54UzORsIg";
final AsyncHttpClient client = new AsyncHttpClient();

client.get(ZIPCODE, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int i, Headers headers, JSON json) {
JSONObject jsonObject = json.jsonObject;
try {
lng = ((JSONArray)jsonObject.get("results")).getJSONObject(0)
lng = ((JSONArray) jsonObject.get("results")).getJSONObject(0)
.getJSONObject("geometry").getJSONObject("location")
.getDouble("lng");

lat = ((JSONArray)jsonObject.get("results")).getJSONObject(0)
lat = ((JSONArray) jsonObject.get("results")).getJSONObject(0)
.getJSONObject("geometry").getJSONObject("location")
.getDouble("lat");

Expand Down Expand Up @@ -115,11 +140,22 @@ public void onFailure(int i, Headers headers, String s, Throwable throwable) {
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
LatLng Dallas = new LatLng(32.789444,96.791131);
LatLng Dallas = new LatLng(32.789444, 96.791131);
map.addMarker(new MarkerOptions().position(Dallas).title("Dallas"));
map.moveCamera(CameraUpdateFactory.newLatLng(Dallas));
}

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
parent.getItemAtPosition(position);
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}
}
26 changes: 15 additions & 11 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@
android:layout_toEndOf="@+id/etZipcode"
android:src="@android:drawable/ic_menu_search" />

<TextView
android:id="@+id/textView2"
android:layout_width="133dp"
android:layout_height="45dp"
android:layout_below="@+id/label"
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:layout_marginEnd="28dp"
android:background="#fff"
android:text="category" />

<com.google.android.gms.maps.MapView
android:id="@+id/mapView2"
Expand Down Expand Up @@ -92,6 +82,20 @@
android:layout_height="220dp"
android:layout_below="@+id/etZipcode"
android:layout_alignParentStart="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="43dp"
android:layout_marginTop="17dp" />
android:layout_marginTop="18dp" />

<Spinner
android:id="@+id/drSpin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/mapView2"
android:layout_alignStart="@+id/searchbutton"
android:layout_alignTop="@+id/searchbutton"
android:layout_marginStart="61dp"
android:layout_marginTop="14dp"
android:layout_marginBottom="23dp"
android:visibility="visible"
tools:visibility="visible" />
</RelativeLayout>
11 changes: 10 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
<resources>
<string name="app_name">PetNeeds</string>
</resources>
<string-array name="Categories">
<item>Pet Stores</item>
<item>Trainers</item>
<item>Vet Hospitals</item>
<item>ER</item>
<item>Dog Parks</item>
<item>Grooming Salons</item>
</string-array>
</resources>

0 comments on commit 52355d6

Please sign in to comment.