Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.graphics.Color;
import android.net.wifi.WifiManager;
import android.support.test.espresso.action.ViewActions;
import android.support.test.espresso.assertion.ViewAssertions;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

Expand All @@ -22,13 +23,14 @@
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.hasBackground;
import static android.support.test.espresso.matcher.ViewMatchers.hasFocus;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withHint;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -100,6 +102,36 @@ public void onBackButtonPress_doesInvokeOnCancelCallback() throws Exception {
verify(listener, times(1)).onCancel();
}

@Test
public void onClearSearchQueryTextButtonPress_doesClearEditText() throws Exception {
ClearButtonListener clearButtonListener = mock(ClearButtonListener.class);
placeAutocompleteFragment.setOnClearButtonListener(clearButtonListener);
onView(withId(R.id.edittext_search)).check(ViewAssertions.matches((withText(""))));
}

@Test
public void onClearSearchQueryTextButtonPress_doesInvokeOnCancelCallback() throws Exception {
ClearButtonListener clearButtonListener = mock(ClearButtonListener.class);
placeAutocompleteFragment.setOnClearButtonListener(clearButtonListener);
verify(clearButtonListener, times(1)).onCancel();
}

@Test
public void onSearchQueryEditTextPress_doesAddFocusToEditText() throws Exception {
QueryFocusListener searchUiHasFocusListener = mock(QueryFocusListener.class);
placeAutocompleteFragment.setOnSearchUiHasFocusListener(searchUiHasFocusListener);
onView(withId(R.id.edittext_search)).perform(ViewActions.click());
onView(withId(R.id.edittext_search)).check(matches(hasFocus()));
}

@Test
public void onResultPress_doesRemoveFocus() throws Exception {
PlaceSelectionListener listener = mock(PlaceSelectionListener.class);
placeAutocompleteFragment.setOnPlaceSelectedListener(listener);
onView(withId(R.id.scroll_view_results)).perform(ViewActions.click());
onView(withId(R.id.edittext_search)).check(matches(not(hasFocus())));
}

//
// Offline state test
//
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity"/>
</activity>
<activity
android:name=".activity.places.PickerAutocompleteCombinedActivity"
android:description="@string/description_place_picker_autocomplete_combo"
android:label="@string/title_place_picker_autocomplete_combo"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="@string/category"
android:value="@string/category_places"/>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity"/>
</activity>
<activity
android:name=".activity.places.AutocompleteFragmentActivity"
android:description="@string/description_autocomplete_fragment"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.mapbox.mapboxsdk.plugins.testapp.activity.places

import android.graphics.Color
import android.os.Bundle
import android.support.v4.content.ContextCompat
import android.support.v7.app.AppCompatActivity
import android.widget.Toast

Expand All @@ -23,7 +22,7 @@ class AutocompleteFragmentActivity : AppCompatActivity() {
val autocompleteFragment: PlaceAutocompleteFragment
if (savedInstanceState == null) {
val placeOptions = PlaceOptions.builder()
.toolbarColor(ContextCompat.getColor(this, R.color.colorPrimary))
.toolbarColor(Color.RED)
.statusbarColor(Color.YELLOW)
.hint("Begin searching...")
.build()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.mapbox.mapboxsdk.plugins.testapp.activity.places

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.Toast

import com.mapbox.mapboxsdk.Mapbox
import com.mapbox.mapboxsdk.camera.CameraPosition
import com.mapbox.mapboxsdk.geometry.LatLng
import com.mapbox.mapboxsdk.plugins.places.picker.PlacePicker
import com.mapbox.mapboxsdk.plugins.places.picker.model.PlacePickerOptions
import com.mapbox.mapboxsdk.plugins.testapp.R
import kotlinx.android.synthetic.main.activity_picker_autocomplete_combo_launcher.*
import kotlinx.android.synthetic.main.activity_picker_launcher.fabLocationPicker
import kotlinx.android.synthetic.main.activity_picker_launcher.reverseGeocodingSwitch
import kotlinx.android.synthetic.main.activity_picker_launcher.userLocationSwitch

/**
* This activity shows how to create Place Picker UI with search included.
*/
class PickerAutocompleteCombinedActivity : AppCompatActivity() {

public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_picker_autocomplete_combo_launcher)

reverseGeocodingSwitch.text = getString(R.string.reverse_geocoding_enabled)
reverseGeocodingSwitch.setOnCheckedChangeListener { compoundButton, checked ->
reverseGeocodingSwitch.text = if (checked)
getString(R.string.reverse_geocoding_enabled)
else getString(R.string.reverse_geocoding_disabled)
}

includeSearchUiSwitch.text = getString(R.string.search_ui_enabled)
includeSearchUiSwitch.setOnCheckedChangeListener { compoundButton, checked ->
includeSearchUiSwitch.text = if (checked)
getString(R.string.search_ui_enabled)
else getString(R.string.search_ui_disabled)
}

userLocationSwitch.text = getString(R.string.user_location_button_enabled)
userLocationSwitch.setOnCheckedChangeListener { compoundButton, checked ->
userLocationSwitch.text = if (checked)
getString(R.string.user_location_button_enabled)
else getString(R.string.user_location_button_disabled)
}

fabLocationPicker.setOnClickListener { _ ->
Mapbox.getAccessToken()?.let {
startActivityForResult(
PlacePicker.IntentBuilder()
.accessToken(it)
.placeOptions(PlacePickerOptions.builder()
.includeReverseGeocode(reverseGeocodingSwitch.isChecked)
.includeSearch(includeSearchUiSwitch.isChecked)
.includeDeviceLocationButton(userLocationSwitch.isChecked)
.statingCameraPosition(CameraPosition.Builder()
.target(LatLng(40.7544, -73.9862))
.zoom(16.0)
.build())
.build())
.build(this), REQUEST_CODE)
}
}
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) {
if (reverseGeocodingSwitch.isChecked) {
val carmenFeature = PlacePicker.getPlace(data)
Toast.makeText(this, carmenFeature?.placeName(), Toast.LENGTH_LONG).show()
} else {
val cameraPosition = PlacePicker.getLastCameraPosition(data)
Toast.makeText(this, cameraPosition.target.toString(), Toast.LENGTH_LONG).show()
}
}
}

companion object {
private val REQUEST_CODE = 5678
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PickerLauncherActivity : AppCompatActivity() {
else getString(R.string.reverse_geocoding_disabled)
}

userLocationSwitch.text = getString(R.string.user_location_button_disabled)
userLocationSwitch.text = getString(R.string.user_location_button_enabled)
userLocationSwitch.setOnCheckedChangeListener { compoundButton, checked ->
userLocationSwitch.text = if (checked)
getString(R.string.user_location_button_enabled)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<Switch
android:id="@+id/reverseGeocodingSwitch"
android:layout_width="wrap_content"
android:layout_height="22dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:checked="true"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/includeSearchUiSwitch" />

<Switch
android:id="@+id/includeSearchUiSwitch"
android:layout_width="wrap_content"
android:layout_height="22dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:checked="true"
app:layout_constraintBottom_toTopOf="@+id/reverseGeocodingSwitch"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />

<Switch
android:id="@+id/userLocationSwitch"
android:layout_width="wrap_content"
android:layout_height="22dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:checked="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />

<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="@string/detailed_description_place_picker_combo"
android:textAlignment="center"
app:layout_constraintBottom_toTopOf="@+id/includeSearchUiSwitch"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/fabLocationPicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:tint="@android:color/white"
app:backgroundTint="@color/colorPrimary"
app:fabSize="normal"
app:layout_anchorGravity="bottom|right|end"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/mapbox_ic_place" />

</android.support.constraint.ConstraintLayout>
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_picker_launcher.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
app:layout_constraintBottom_toTopOf="@+id/reverseGeocodingSwitch"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
android:checked="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />

Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<string name="title_building">Building Plugin</string>
<string name="title_places_autocomplete">Places Autocomplete</string>
<string name="title_places_autocomplete_fragment">Places Autocomplete Fragment</string>
<string name="title_place_picker_autocomplete_combo">Autocomplete and Place Picker Combination</string>
<string name="title_offline_plugin">Create region</string>
<string name="title_offline_regions">List regions</string>
<string name="title_place_picker">Place picker</string>
Expand All @@ -42,6 +43,7 @@
<string name="description_building">Add 3D Building layer to a Mapbox map.</string>
<string name="description_autocomplete">Launch the autocomplete activity.</string>
<string name="description_autocomplete_fragment">Launch the autocomplete fragment inside an activity</string>
<string name="description_place_picker_autocomplete_combo">Show the Place Picker and autocomplete UI together.</string>
<string name="description_offline_plugin">Use a form to create an offline region.</string>
<string name="description_offline_regions">List all offline regions.</string>
<string name="description_place_picker">Launch the place picker activity and receive result</string>
Expand All @@ -62,10 +64,13 @@

<!-- Place picker -->
<string name="detailed_description_place_picker">Example shows how to launch the Place Picker using the Floating action button and receiving a result in onActivityResult.</string>
<string name="detailed_description_place_picker_combo">PickerAutocompleteCombinedActivity: Example shows how to launch the Place Picker combined with the autocomplete geocoding search UI.</string>
<string name="reverse_geocoding_enabled">Reverse geocoding enabled</string>
<string name="reverse_geocoding_disabled">Reverse geocoding disabled</string>
<string name="user_location_button_enabled">User location button enabled</string>
<string name="user_location_button_disabled">User location button disabled</string>
<string name="search_ui_enabled">Search autocomplete UI enabled</string>
<string name="search_ui_disabled">Search autocomplete UI disabled</string>

<!-- Misc -->
<string name="min_zoom_textview">Min zoom: %1$d</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.mapbox.mapboxsdk.plugins.places.autocomplete.ui;

/**
* This click interface notifies when the back arrow button is clicked
* in the {@link SearchView}.
*/
public interface BackButtonListener {

void onBackButtonPress();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mapbox.mapboxsdk.plugins.places.autocomplete.ui;

/**
* This click interface notifies when the clear button
* is clickedin the {@link SearchView} to clear the query text in the EditText.
*/
public interface ClearButtonListener {

void onClearButtonPress();

void onCancel();

}
Loading