├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-ru
│ │ │ │ └── strings.xml
│ │ │ ├── values
│ │ │ │ ├── google_maps_api.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── drawable
│ │ │ │ └── ic_close_black_24dp.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── ru
│ │ │ │ └── eightbps
│ │ │ │ └── rxjavaautocomplete
│ │ │ │ ├── data
│ │ │ │ ├── model
│ │ │ │ │ ├── Geometry.java
│ │ │ │ │ ├── PlaceDetailsResult.java
│ │ │ │ │ ├── Location.java
│ │ │ │ │ ├── PlaceDetails.java
│ │ │ │ │ ├── PlaceAutocompleteResult.java
│ │ │ │ │ └── Prediction.java
│ │ │ │ ├── GooglePlacesClient.java
│ │ │ │ └── RestClient.java
│ │ │ │ ├── RxJavaAutocompleteApp.java
│ │ │ │ ├── utils
│ │ │ │ └── KeyboardHelper.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── ru
│ │ │ └── eightbps
│ │ │ └── rxjavaautocomplete
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── ru
│ │ └── eightbps
│ │ └── rxjavaautocomplete
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── art
└── sample.gif
├── .idea
├── copyright
│ └── profiles_settings.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
├── misc.xml
└── codeStyleSettings.xml
├── .gitignore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/art/sample.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexander-mironov/AndroidRxJavaAutocomplete/HEAD/art/sample.gif
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexander-mironov/AndroidRxJavaAutocomplete/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexander-mironov/AndroidRxJavaAutocomplete/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexander-mironov/AndroidRxJavaAutocomplete/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexander-mironov/AndroidRxJavaAutocomplete/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexander-mironov/AndroidRxJavaAutocomplete/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexander-mironov/AndroidRxJavaAutocomplete/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-ru/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Введите название города:
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/google_maps_api.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RxJavaAutocomplete
3 | Enter city name:
4 | Clear text
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Nov 29 21:47:10 MSK 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/java/ru/eightbps/rxjavaautocomplete/data/model/Geometry.java:
--------------------------------------------------------------------------------
1 | package ru.eightbps.rxjavaautocomplete.data.model;
2 |
3 | public class Geometry {
4 |
5 | public Location location;
6 |
7 | @Override
8 | public String toString() {
9 | return "Geometry{" +
10 | "location=" + location +
11 | '}';
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/ru/eightbps/rxjavaautocomplete/data/model/PlaceDetailsResult.java:
--------------------------------------------------------------------------------
1 | package ru.eightbps.rxjavaautocomplete.data.model;
2 |
3 | public class PlaceDetailsResult {
4 |
5 | public PlaceDetails result;
6 |
7 | @Override
8 | public String toString() {
9 | return "PlaceDetailsResult{" +
10 | "result=" + result +
11 | '}';
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/java/ru/eightbps/rxjavaautocomplete/data/model/Location.java:
--------------------------------------------------------------------------------
1 | package ru.eightbps.rxjavaautocomplete.data.model;
2 |
3 | public class Location {
4 |
5 | public double lat;
6 | public double lng;
7 |
8 | @Override
9 | public String toString() {
10 | return "Location{" +
11 | "lat=" + lat +
12 | ", lng=" + lng +
13 | '}';
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/ru/eightbps/rxjavaautocomplete/data/model/PlaceDetails.java:
--------------------------------------------------------------------------------
1 | package ru.eightbps.rxjavaautocomplete.data.model;
2 |
3 | public class PlaceDetails {
4 |
5 | public Geometry geometry;
6 | public String name;
7 |
8 | @Override
9 | public String toString() {
10 | return "PlaceDetails{" +
11 | "geometry=" + geometry +
12 | ", name='" + name + '\'' +
13 | '}';
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_close_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android AutoComplete Example (RxJava 2 + Retrofit 2 + Moshi + Google Maps)
2 |
3 | An example of using RxJava 2 to autocomplete searches with a delay and viewing search result on a map.
4 |
5 | ## Usage
6 |
7 | Clone and enter [your Google Maps API Key](https://developers.google.com/maps/documentation/android-api/signup) into `google_maps_api.xml`.
8 |
9 | ## Video
10 |
11 | 
12 |
13 |
--------------------------------------------------------------------------------
/app/src/test/java/ru/eightbps/rxjavaautocomplete/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package ru.eightbps.rxjavaautocomplete;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/ru/eightbps/rxjavaautocomplete/RxJavaAutocompleteApp.java:
--------------------------------------------------------------------------------
1 | package ru.eightbps.rxjavaautocomplete;
2 |
3 | import android.app.Application;
4 |
5 | public class RxJavaAutocompleteApp extends Application {
6 |
7 | @Override
8 | public void onCreate() {
9 | super.onCreate();
10 |
11 | String googleMapsKey = getString(R.string.google_maps_key);
12 | if (googleMapsKey.isEmpty()) {
13 | throw new RuntimeException("You should add your Google Maps API Key!");
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/ru/eightbps/rxjavaautocomplete/data/model/PlaceAutocompleteResult.java:
--------------------------------------------------------------------------------
1 | package ru.eightbps.rxjavaautocomplete.data.model;
2 |
3 | import java.util.List;
4 |
5 | public class PlaceAutocompleteResult {
6 |
7 | public String status;
8 | public List predictions;
9 |
10 | @Override
11 | public String toString() {
12 | return "PlaceAutocompleteResult{" +
13 | "status='" + status + '\'' +
14 | ", predictions=" + predictions +
15 | '}';
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/ru/eightbps/rxjavaautocomplete/data/model/Prediction.java:
--------------------------------------------------------------------------------
1 | package ru.eightbps.rxjavaautocomplete.data.model;
2 |
3 | import com.squareup.moshi.Json;
4 |
5 | public class Prediction {
6 | public String description;
7 | public String id;
8 |
9 | @Json(name = "place_id")
10 | public String placeId;
11 |
12 | @Override
13 | public String toString() {
14 | return "Prediction{" +
15 | "description='" + description + '\'' +
16 | ", id='" + id + '\'' +
17 | ", placeId='" + placeId + '\'' +
18 | '}';
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/ru/eightbps/rxjavaautocomplete/data/GooglePlacesClient.java:
--------------------------------------------------------------------------------
1 | package ru.eightbps.rxjavaautocomplete.data;
2 |
3 | import io.reactivex.Observable;
4 | import retrofit2.http.GET;
5 | import retrofit2.http.Query;
6 | import ru.eightbps.rxjavaautocomplete.data.model.PlaceAutocompleteResult;
7 | import ru.eightbps.rxjavaautocomplete.data.model.PlaceDetailsResult;
8 |
9 | public interface GooglePlacesClient {
10 | @GET("autocomplete/json?types=(cities)")
11 | Observable autocomplete(@Query("input") String str);
12 |
13 | @GET("details/json")
14 | Observable details(@Query("placeid") String placeId);
15 | }
16 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Android\android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/java/ru/eightbps/rxjavaautocomplete/utils/KeyboardHelper.java:
--------------------------------------------------------------------------------
1 | package ru.eightbps.rxjavaautocomplete.utils;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.view.View;
6 | import android.view.inputmethod.InputMethodManager;
7 |
8 | public final class KeyboardHelper {
9 |
10 | private KeyboardHelper() {
11 |
12 | }
13 |
14 | public static void hideKeyboard(Activity activity) {
15 | View view = activity.getCurrentFocus();
16 | if (view != null) {
17 | InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
18 | imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/ru/eightbps/rxjavaautocomplete/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package ru.eightbps.rxjavaautocomplete;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("ru.eightbps.rxjavaautocomplete", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | buildToolsVersion "27.0.1"
6 | defaultConfig {
7 | applicationId "ru.eightbps.rxjavaautocomplete"
8 | minSdkVersion 16
9 | targetSdkVersion 27
10 | versionCode 2
11 | versionName "2.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | compileOptions {
21 | sourceCompatibility JavaVersion.VERSION_1_8
22 | targetCompatibility JavaVersion.VERSION_1_8
23 | }
24 | }
25 |
26 | dependencies {
27 | androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
28 | exclude group: 'com.android.support', module: 'support-annotations'
29 | })
30 | implementation 'com.android.support:appcompat-v7:27.0.2'
31 | implementation 'io.reactivex.rxjava2:rxjava:2.1.7'
32 | implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
33 | implementation 'com.jakewharton.rxbinding2:rxbinding:2.0.0'
34 | implementation 'com.squareup.retrofit2:retrofit:2.3.0'
35 | implementation 'com.squareup.retrofit2:converter-moshi:2.3.0'
36 | implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
37 | implementation 'com.squareup.moshi:moshi:1.4.0'
38 | implementation('com.google.android.gms:play-services-maps:11.6.2') {
39 | exclude group: 'com.android.support', module: 'support-v4'
40 | }
41 | testImplementation 'junit:junit:4.12'
42 | }
43 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/java/ru/eightbps/rxjavaautocomplete/data/RestClient.java:
--------------------------------------------------------------------------------
1 | package ru.eightbps.rxjavaautocomplete.data;
2 |
3 | import android.support.annotation.NonNull;
4 |
5 | import java.io.IOException;
6 |
7 | import okhttp3.HttpUrl;
8 | import okhttp3.Interceptor;
9 | import okhttp3.OkHttpClient;
10 | import okhttp3.Request;
11 | import okhttp3.Response;
12 | import retrofit2.Retrofit;
13 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
14 | import retrofit2.converter.moshi.MoshiConverterFactory;
15 |
16 | public enum RestClient {
17 | INSTANCE;
18 |
19 | private static final String BASE_URL = "https://maps.googleapis.com/maps/api/place/";
20 | private static final String API_KEY = "AIzaSyD5-tQ5alcqco18LzeLd2pb5ov15Gb4Ghs"; // feel free to use this key. It just map's key that should be private
21 | private final GooglePlacesClient googlePlacesClient;
22 |
23 | RestClient() {
24 | OkHttpClient okHttpClient = new OkHttpClient.Builder()
25 | .addInterceptor(new GoogleApiInterceptor())
26 | .build();
27 | Retrofit retrofit = new Retrofit.Builder()
28 | .addConverterFactory(MoshiConverterFactory.create())
29 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
30 | .client(okHttpClient)
31 | .baseUrl(BASE_URL)
32 | .build();
33 | googlePlacesClient = retrofit.create(GooglePlacesClient.class);
34 | }
35 |
36 | public GooglePlacesClient getGooglePlacesClient() {
37 | return googlePlacesClient;
38 | }
39 |
40 | private static class GoogleApiInterceptor implements Interceptor {
41 | @Override
42 | public Response intercept(@NonNull Chain chain) throws IOException {
43 | Request request = chain.request();
44 | HttpUrl url = request.url().newBuilder().addQueryParameter("key", API_KEY).build();
45 | request = request.newBuilder().url(url).build();
46 | return chain.proceed(request);
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
23 |
24 |
36 |
37 |
46 |
47 |
48 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/ru/eightbps/rxjavaautocomplete/MainActivity.java:
--------------------------------------------------------------------------------
1 | package ru.eightbps.rxjavaautocomplete;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.util.Log;
6 | import android.view.View;
7 | import android.widget.ArrayAdapter;
8 | import android.widget.AutoCompleteTextView;
9 |
10 | import com.google.android.gms.maps.CameraUpdateFactory;
11 | import com.google.android.gms.maps.GoogleMap;
12 | import com.google.android.gms.maps.OnMapReadyCallback;
13 | import com.google.android.gms.maps.SupportMapFragment;
14 | import com.google.android.gms.maps.model.LatLng;
15 | import com.google.android.gms.maps.model.Marker;
16 | import com.google.android.gms.maps.model.MarkerOptions;
17 | import com.jakewharton.rxbinding2.view.RxView;
18 | import com.jakewharton.rxbinding2.widget.RxAutoCompleteTextView;
19 | import com.jakewharton.rxbinding2.widget.RxTextView;
20 |
21 | import java.util.ArrayList;
22 | import java.util.List;
23 | import java.util.concurrent.TimeUnit;
24 |
25 | import io.reactivex.Observable;
26 | import io.reactivex.android.schedulers.AndroidSchedulers;
27 | import io.reactivex.disposables.CompositeDisposable;
28 | import io.reactivex.schedulers.Schedulers;
29 | import ru.eightbps.rxjavaautocomplete.data.RestClient;
30 | import ru.eightbps.rxjavaautocomplete.data.model.Location;
31 | import ru.eightbps.rxjavaautocomplete.data.model.PlaceAutocompleteResult;
32 | import ru.eightbps.rxjavaautocomplete.data.model.PlaceDetailsResult;
33 | import ru.eightbps.rxjavaautocomplete.data.model.Prediction;
34 | import ru.eightbps.rxjavaautocomplete.utils.KeyboardHelper;
35 |
36 | public class MainActivity extends AppCompatActivity implements OnMapReadyCallback {
37 |
38 | private static final String TAG = "MainActivity";
39 | private static final long DELAY_IN_MILLIS = 500;
40 | public static final int MIN_LENGTH_TO_START = 2;
41 | public static final int DEFAULT_ZOOM = 5;
42 | private CompositeDisposable compositeDisposable = new CompositeDisposable();
43 | private GoogleMap map;
44 |
45 | @Override
46 | protected void onCreate(Bundle savedInstanceState) {
47 | super.onCreate(savedInstanceState);
48 | setContentView(R.layout.activity_main);
49 |
50 | SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
51 | .findFragmentById(R.id.map);
52 | mapFragment.getMapAsync(this);
53 |
54 | final AutoCompleteTextView autoCompleteTextView = findViewById(R.id.autocomplete_text);
55 | addOnAutoCompleteTextViewItemClickedSubscriber(autoCompleteTextView);
56 | addOnAutoCompleteTextViewTextChangedObserver(autoCompleteTextView);
57 |
58 | final View clearTextButton = findViewById(R.id.clear_text_button);
59 | compositeDisposable.add(RxView.clicks(clearTextButton).subscribe(o -> autoCompleteTextView.setText("")));
60 | }
61 |
62 | @Override
63 | public void onMapReady(GoogleMap googleMap) {
64 | map = googleMap;
65 | }
66 |
67 | private void addOnAutoCompleteTextViewTextChangedObserver(final AutoCompleteTextView autoCompleteTextView) {
68 | Observable autocompleteResponseObservable =
69 | RxTextView.textChangeEvents(autoCompleteTextView)
70 | .debounce(DELAY_IN_MILLIS, TimeUnit.MILLISECONDS)
71 | .map(textViewTextChangeEvent -> textViewTextChangeEvent.text().toString())
72 | .filter(s -> s.length() >= MIN_LENGTH_TO_START)
73 | .observeOn(Schedulers.io())
74 | .switchMap(s -> RestClient.INSTANCE.getGooglePlacesClient().autocomplete(s))
75 | .observeOn(AndroidSchedulers.mainThread())
76 | .retry();
77 |
78 | compositeDisposable.add(
79 | autocompleteResponseObservable.subscribe(
80 | placeAutocompleteResult -> {
81 | List list = new ArrayList<>();
82 | for (Prediction prediction : placeAutocompleteResult.predictions) {
83 | list.add(new NameAndPlaceId(prediction.description, prediction.placeId));
84 | }
85 |
86 | ArrayAdapter itemsAdapter = new ArrayAdapter<>(MainActivity.this,
87 | android.R.layout.simple_list_item_1, list);
88 | autoCompleteTextView.setAdapter(itemsAdapter);
89 | String enteredText = autoCompleteTextView.getText().toString();
90 | if (list.size() >= 1 && enteredText.equals(list.get(0).name)) {
91 | autoCompleteTextView.dismissDropDown();
92 | } else {
93 | autoCompleteTextView.showDropDown();
94 | }
95 | },
96 | e -> Log.e(TAG, "onError", e),
97 | () -> Log.i(TAG, "onCompleted")));
98 | }
99 |
100 | private void addOnAutoCompleteTextViewItemClickedSubscriber(final AutoCompleteTextView autoCompleteTextView) {
101 | Observable adapterViewItemClickEventObservable =
102 | RxAutoCompleteTextView.itemClickEvents(autoCompleteTextView)
103 | .map(adapterViewItemClickEvent -> {
104 | NameAndPlaceId item = (NameAndPlaceId) autoCompleteTextView.getAdapter()
105 | .getItem(adapterViewItemClickEvent.position());
106 | return item.placeId;
107 | })
108 | .observeOn(Schedulers.io())
109 | .switchMap(placeId -> RestClient.INSTANCE.getGooglePlacesClient().details(placeId))
110 | .observeOn(AndroidSchedulers.mainThread())
111 | .retry();
112 |
113 | compositeDisposable.add(
114 | adapterViewItemClickEventObservable.subscribe(
115 | placeDetailsResult -> {
116 | Log.i("PlaceAutocomplete", placeDetailsResult.toString());
117 | updateMap(placeDetailsResult);
118 | },
119 | throwable -> Log.e(TAG, "onError", throwable),
120 | () -> Log.i(TAG, "onCompleted")));
121 | }
122 |
123 | private void updateMap(PlaceDetailsResult placeDetailsResponse) {
124 | if (map != null) {
125 | map.clear();
126 | Location location = placeDetailsResponse.result.geometry.location;
127 | LatLng latLng = new LatLng(location.lat, location.lng);
128 | MarkerOptions markerOptions = new MarkerOptions()
129 | .position(latLng)
130 | .title(placeDetailsResponse.result.name);
131 | Marker marker = map.addMarker(markerOptions);
132 | marker.showInfoWindow();
133 | map.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, DEFAULT_ZOOM));
134 | KeyboardHelper.hideKeyboard(MainActivity.this);
135 | }
136 | }
137 |
138 | @Override
139 | protected void onDestroy() {
140 | super.onDestroy();
141 | compositeDisposable.dispose();
142 | }
143 |
144 | private static class NameAndPlaceId {
145 | final String name;
146 | final String placeId;
147 |
148 | NameAndPlaceId(String name, String placeId) {
149 | this.name = name;
150 | this.placeId = placeId;
151 | }
152 |
153 | @Override
154 | public String toString() {
155 | return name;
156 | }
157 | }
158 | }
159 |
--------------------------------------------------------------------------------
/.idea/codeStyleSettings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | xmlns:android
77 | ^$
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 | xmlns:.*
87 | ^$
88 |
89 |
90 | BY_NAME
91 |
92 |
93 |
94 |
95 |
96 |
97 | .*:id
98 | http://schemas.android.com/apk/res/android
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 | .*:name
108 | http://schemas.android.com/apk/res/android
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 | name
118 | ^$
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 | style
128 | ^$
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 | .*
138 | ^$
139 |
140 |
141 | BY_NAME
142 |
143 |
144 |
145 |
146 |
147 |
148 | .*:layout_width
149 | http://schemas.android.com/apk/res/android
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 | .*:layout_height
159 | http://schemas.android.com/apk/res/android
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 | .*:layout_.*
169 | http://schemas.android.com/apk/res/android
170 |
171 |
172 | BY_NAME
173 |
174 |
175 |
176 |
177 |
178 |
179 | .*:width
180 | http://schemas.android.com/apk/res/android
181 |
182 |
183 | BY_NAME
184 |
185 |
186 |
187 |
188 |
189 |
190 | .*:height
191 | http://schemas.android.com/apk/res/android
192 |
193 |
194 | BY_NAME
195 |
196 |
197 |
198 |
199 |
200 |
201 | .*
202 | http://schemas.android.com/apk/res/android
203 |
204 |
205 | BY_NAME
206 |
207 |
208 |
209 |
210 |
211 |
212 | .*
213 | .*
214 |
215 |
216 | BY_NAME
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
--------------------------------------------------------------------------------