Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] #5282 - Adding clear button and related functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
bleege committed Jun 10, 2016
1 parent e3cebcf commit e4c4b87
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
Expand Down Expand Up @@ -41,6 +42,8 @@ public class LocationPickerActivity extends AppCompatActivity {

private ImageView dropPinView = null;
private Marker resultsPin = null;
private Button selectLocationButton = null;
private ImageButton clearDisplayViewButton = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -72,8 +75,8 @@ public void onMapReady(MapboxMap map) {
dropPinView.setLayoutParams(params);
mapView.addView(dropPinView);

final Button selectLocation = (Button) findViewById(R.id.selectLocationButton);
selectLocation.setOnClickListener(
selectLocationButton = (Button) findViewById(R.id.selectLocationButton);
selectLocationButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -88,6 +91,14 @@ public void onClick(View v) {
}
}
);

clearDisplayViewButton = (ImageButton) findViewById(R.id.clearDisplayViewButton);
clearDisplayViewButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showAddressPin(null);
}
});
}

private float[] getDropPinTipCoordinates() {
Expand Down Expand Up @@ -142,6 +153,8 @@ private void showAddressPin(final String address) {
// Set back to search mode
resultsPin = null;
dropPinView.setVisibility(View.VISIBLE);
clearDisplayViewButton.setVisibility(View.GONE);
selectLocationButton.setClickable(true);

return;
}
Expand All @@ -154,6 +167,9 @@ private void showAddressPin(final String address) {
MarkerOptions markerOptions = new MarkerOptions().title(address).position(latLng);
resultsPin = mapboxMap.addMarker(markerOptions);
mapboxMap.selectMarker(resultsPin);

clearDisplayViewButton.setVisibility(View.VISIBLE);
selectLocationButton.setClickable(false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFF"
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@
android:layout_height="match_parent"
android:layout_below="@id/toolbar"/>

<ImageButton
android:id="@+id/clearDisplayViewButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_clear_24dp"
android:background="@color/accent"
android:visibility="gone"
android:layout_marginLeft="@dimen/full_button_margin"
android:layout_above="@+id/selectLocationButton"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>

<Button
android:id="@+id/selectLocationButton"
android:layout_width="fill_parent"
Expand Down

0 comments on commit e4c4b87

Please sign in to comment.