├── 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
│ │ ├── drawable
│ │ │ ├── ic_search.xml
│ │ │ └── scrim_detail.xml
│ │ ├── values
│ │ │ ├── dimens.xml
│ │ │ ├── colors.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ ├── values-v21
│ │ │ └── styles.xml
│ │ └── layout
│ │ │ ├── activity_main.xml
│ │ │ └── activity_details.xml
│ │ ├── java
│ │ └── com
│ │ │ └── solidgeargroup
│ │ │ └── priorityjobqueueexample
│ │ │ ├── events
│ │ │ ├── LocationFailedEvent.java
│ │ │ └── LocationFetchedEvent.java
│ │ │ ├── networking
│ │ │ ├── WsMethods.java
│ │ │ ├── exceptions
│ │ │ │ └── ErrorRequestException.java
│ │ │ └── requests
│ │ │ │ └── GeocodingInterface.java
│ │ │ ├── jobs
│ │ │ ├── JobConstants.java
│ │ │ ├── FetchRandomLatLngJob.java
│ │ │ ├── FetchLocationByLatLngJob.java
│ │ │ └── FetchLocationByAddressJob.java
│ │ │ ├── model
│ │ │ ├── Geocode.java
│ │ │ ├── LatLng.java
│ │ │ ├── Geometry.java
│ │ │ └── AddressComponent.java
│ │ │ ├── services
│ │ │ ├── AppGcmJobService.java
│ │ │ └── AppJobService.java
│ │ │ ├── App.java
│ │ │ ├── utils
│ │ │ └── AppDataBindingUtils.java
│ │ │ ├── ui
│ │ │ ├── DetailsActivity.java
│ │ │ └── MainActivity.java
│ │ │ ├── database
│ │ │ └── FakeDatabase.java
│ │ │ └── managers
│ │ │ ├── AppRetrofitManager.java
│ │ │ └── AppJobManager.java
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .gitignore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── LICENSE
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /.idea/
4 | .DS_Store
5 | /build
6 | /captures
7 | local.properties
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/solidgear/priority-job-queue/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/solidgear/priority-job-queue/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/solidgear/priority-job-queue/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/solidgear/priority-job-queue/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/solidgear/priority-job-queue/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/solidgear/priority-job-queue/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Sep 01 15:17:08 CEST 2016
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-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/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\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 |
--------------------------------------------------------------------------------
/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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | Copyright (c) 2016 Solid Gear SL
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 |
6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 |
8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_search.xml:
--------------------------------------------------------------------------------
1 |
16 |
21 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/solidgeargroup/priorityjobqueueexample/events/LocationFailedEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package com.solidgeargroup.priorityjobqueueexample.events;
20 |
21 | /**
22 | * Created by jcmontesmartos on 2016/09/12.
23 | */
24 | public class LocationFailedEvent {
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
22 | 16dp
23 | 4dp
24 | 256dp
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/solidgeargroup/priorityjobqueueexample/networking/WsMethods.java:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package com.solidgeargroup.priorityjobqueueexample.networking;
20 |
21 | /**
22 | * Created by jcmontesmartos on 2016/09/12.
23 | */
24 | public class WsMethods {
25 |
26 | public static final String GEOCODE_JSON_WS = "geocode/json";
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/solidgeargroup/priorityjobqueueexample/jobs/JobConstants.java:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package com.solidgeargroup.priorityjobqueueexample.jobs;
20 |
21 | /**
22 | * Created by jcmontesmartos on 2016/09/12.
23 | */
24 | public class JobConstants {
25 |
26 | public static final int PRIORITY_HIGH = 100;
27 | public static final int PRIORITY_NORMAL = 100;
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/scrim_detail.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
23 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
22 | #2196F3
23 | #1976D2
24 | #FFC107
25 | @android:color/white
26 |
27 | #212121
28 | #757575
29 | @android:color/white
30 |
31 | #BDBDBD
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/solidgeargroup/priorityjobqueueexample/networking/exceptions/ErrorRequestException.java:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package com.solidgeargroup.priorityjobqueueexample.networking.exceptions;
20 |
21 | import retrofit2.Response;
22 |
23 | /**
24 | * Created by jcmontesmartos on 2016/09/12.
25 | */
26 | public class ErrorRequestException extends Exception {
27 |
28 | private Response mResponse;
29 |
30 | public ErrorRequestException(Response response) {
31 | mResponse = response;
32 | }
33 |
34 | public Response getResponse() {
35 | return mResponse;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/solidgeargroup/priorityjobqueueexample/model/Geocode.java:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package com.solidgeargroup.priorityjobqueueexample.model;
20 |
21 |
22 | import java.util.ArrayList;
23 |
24 | /**
25 | * Created by jcmontesmartos on 2016/09/12.
26 | */
27 | public class Geocode {
28 |
29 | private ArrayList results;
30 |
31 |
32 | public Geocode() {
33 |
34 | }
35 |
36 | public ArrayList getResults() {
37 | return results;
38 | }
39 |
40 | public void setResults(ArrayList results) {
41 | this.results = results;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/solidgeargroup/priorityjobqueueexample/events/LocationFetchedEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package com.solidgeargroup.priorityjobqueueexample.events;
20 |
21 | import com.solidgeargroup.priorityjobqueueexample.model.AddressComponent;
22 |
23 | /**
24 | * Created by jcmontesmartos on 2016/09/12.
25 | */
26 | public class LocationFetchedEvent {
27 |
28 | private AddressComponent mAddressComponent;
29 |
30 | public LocationFetchedEvent(AddressComponent addressComponent) {
31 | mAddressComponent = addressComponent;
32 | }
33 |
34 | public AddressComponent getAddressComponent() {
35 | return mAddressComponent;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/solidgeargroup/priorityjobqueueexample/services/AppGcmJobService.java:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package com.solidgeargroup.priorityjobqueueexample.services;
20 |
21 | import android.support.annotation.NonNull;
22 |
23 | import com.birbit.android.jobqueue.JobManager;
24 | import com.birbit.android.jobqueue.scheduling.GcmJobSchedulerService;
25 | import com.solidgeargroup.priorityjobqueueexample.managers.AppJobManager;
26 |
27 | /**
28 | * Created by jcmontesmartos on 2016/09/12.
29 | */
30 | public class AppGcmJobService extends GcmJobSchedulerService {
31 |
32 | @NonNull
33 | @Override
34 | protected JobManager getJobManager() {
35 | return AppJobManager.getJobManager();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/solidgeargroup/priorityjobqueueexample/services/AppJobService.java:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package com.solidgeargroup.priorityjobqueueexample.services;
20 |
21 | import android.support.annotation.NonNull;
22 |
23 | import com.birbit.android.jobqueue.JobManager;
24 | import com.birbit.android.jobqueue.scheduling.FrameworkJobSchedulerService;
25 | import com.solidgeargroup.priorityjobqueueexample.managers.AppJobManager;
26 |
27 | /**
28 | * Created by jcmontesmartos on 2016/09/12.
29 | */
30 | public class AppJobService extends FrameworkJobSchedulerService {
31 |
32 | @NonNull
33 | @Override
34 | protected JobManager getJobManager() {
35 | return AppJobManager.getJobManager();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/solidgeargroup/priorityjobqueueexample/App.java:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package com.solidgeargroup.priorityjobqueueexample;
20 |
21 | import android.app.Application;
22 |
23 | import com.solidgeargroup.priorityjobqueueexample.managers.AppJobManager;
24 | import com.solidgeargroup.priorityjobqueueexample.managers.AppRetrofitManager;
25 |
26 |
27 | /**
28 | * Created by jcmontesmartos on 2016/09/12.
29 | */
30 | public class App extends Application {
31 |
32 | @Override
33 | public void onCreate() {
34 | super.onCreate();
35 |
36 | initApp();
37 | }
38 |
39 |
40 | private void initApp() {
41 | AppJobManager.getJobManager(this);
42 |
43 | AppRetrofitManager.getRetrofit();
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/solidgeargroup/priorityjobqueueexample/networking/requests/GeocodingInterface.java:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package com.solidgeargroup.priorityjobqueueexample.networking.requests;
20 |
21 | import com.solidgeargroup.priorityjobqueueexample.model.Geocode;
22 | import com.solidgeargroup.priorityjobqueueexample.model.LatLng;
23 | import com.solidgeargroup.priorityjobqueueexample.networking.WsMethods;
24 |
25 | import retrofit2.Call;
26 | import retrofit2.http.GET;
27 | import retrofit2.http.Query;
28 |
29 | /**
30 | * Created by jcmontesmartos on 2016/09/12.
31 | */
32 | public interface GeocodingInterface {
33 |
34 | @GET(WsMethods.GEOCODE_JSON_WS)
35 | Call getInfoByAddress(@Query("address") String address);
36 |
37 | @GET(WsMethods.GEOCODE_JSON_WS)
38 | Call getInfoByLatLng(@Query("latlng") LatLng latlng);
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/solidgeargroup/priorityjobqueueexample/utils/AppDataBindingUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package com.solidgeargroup.priorityjobqueueexample.utils;
20 |
21 | import android.databinding.BindingAdapter;
22 | import android.widget.ImageView;
23 |
24 | import com.solidgeargroup.priorityjobqueueexample.BuildConfig;
25 | import com.solidgeargroup.priorityjobqueueexample.model.LatLng;
26 | import com.squareup.picasso.Picasso;
27 |
28 | /**
29 | * Created by jcmontesmartos on 2016/09/12.
30 | */
31 | public class AppDataBindingUtils {
32 |
33 | @BindingAdapter({"mapUrl"})
34 | public static void loadMapImage(ImageView view, LatLng latLng) {
35 | String location = latLng.toString().replace(" ", "");
36 | String url = String.format(BuildConfig.GOOGLE_STATIC_MAPS, location, location);
37 | Picasso.with(view.getContext()).load(url).into(view);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/solidgeargroup/priorityjobqueueexample/model/LatLng.java:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package com.solidgeargroup.priorityjobqueueexample.model;
20 |
21 | import java.util.Locale;
22 |
23 | /**
24 | * Created by jcmontesmartos on 2016/09/12.
25 | */
26 | public class LatLng {
27 |
28 | private double lat;
29 |
30 | private double lng;
31 |
32 | public LatLng() {
33 | }
34 |
35 | public LatLng(double lat, double lng) {
36 | this.lat = lat;
37 | this.lng = lng;
38 | }
39 |
40 | public double getLat() {
41 | return lat;
42 | }
43 |
44 | public void setLat(double lat) {
45 | this.lat = lat;
46 | }
47 |
48 | public double getLng() {
49 | return lng;
50 | }
51 |
52 | public void setLng(double lng) {
53 | this.lng = lng;
54 | }
55 |
56 | @Override
57 | public String toString() {
58 | return String.format(Locale.ENGLISH, "%f, %f", this.lat, this.lng);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
20 |
21 | Address Info Finder
22 |
23 |
24 | This is just an example of using "Android Priority Job Queue"
25 | shown during an Android Corner at SolidGear.\n
26 | If you want to run a serial execution, search by "Random Address",
27 | otherwise, search by "address".\n\n
28 |
29 |
30 | Note: Sorry, for the UI, it is just an example.
31 |
32 |
33 | Random Location
34 | Address
35 | GPS Coordinates
36 |
37 | The Best Result
38 |
39 | Fill the address before searching
40 | Location not found
41 |
42 |
--------------------------------------------------------------------------------
/app/src/main/java/com/solidgeargroup/priorityjobqueueexample/model/Geometry.java:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package com.solidgeargroup.priorityjobqueueexample.model;
20 |
21 | import com.google.gson.annotations.SerializedName;
22 |
23 |
24 | /**
25 | * Created by jcmontesmartos on 2016/09/12.
26 | */
27 | public class Geometry {
28 |
29 | private LatLng location;
30 |
31 | @SerializedName("location_type")
32 | private String locationType;
33 |
34 | public Geometry() {
35 |
36 | }
37 |
38 | public LatLng getLocation() {
39 | return location;
40 | }
41 |
42 | public void setLocation(LatLng location) {
43 | this.location = location;
44 | }
45 |
46 | public String getLocationType() {
47 | return locationType;
48 | }
49 |
50 | public void setLocationType(String locationType) {
51 | this.locationType = locationType;
52 | }
53 |
54 | @Override
55 | public String toString() {
56 | return location.toString();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ###Android Priority Job Queue Example
2 |
3 | This is just an example of using *Android Priority Job Queue* library shown during an Android Corner at Solid Gear.
4 |
5 | In this app, you can see how to run jobs in parallel o create a serial execution, integrate with other Schedulers... Also, you are free to create new jobs or test other configuration to understand better the usage of the library.
6 |
7 | > *Note*
8 | Sorry for the UI, it is just an example.
9 |
10 | ###Dependencies
11 |
12 | - [Android Job Priority Queue](https://github.com/yigit/android-priority-jobqueue)
13 | - [Android Support Libraries:](https://developer.android.com/topic/libraries/support-library/features.html) v7-appcompat, design and CardView
14 | - [Picasso](https://github.com/square/picasso)
15 | - [Retrofit](https://github.com/square/retrofit)
16 | - [Gson](https://github.com/google/gson)
17 | - [Google Play Services](https://developers.google.com/android/guides/setup)
18 | - [EventBus](https://github.com/greenrobot/EventBus)
19 |
20 | ###License
21 |
22 | This code is under a MIT License except all libraries and icons used that have their own license.
23 |
24 | The MIT License (MIT)
25 | Copyright (c) 2016 Solid Gear SL
26 |
27 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
28 |
29 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
30 |
31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 |
30 |
31 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/solidgeargroup/priorityjobqueueexample/ui/DetailsActivity.java:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package com.solidgeargroup.priorityjobqueueexample.ui;
20 |
21 | import android.databinding.DataBindingUtil;
22 | import android.os.Bundle;
23 | import android.support.annotation.Nullable;
24 | import android.support.v7.app.AppCompatActivity;
25 |
26 | import com.google.gson.Gson;
27 | import com.solidgeargroup.priorityjobqueueexample.R;
28 | import com.solidgeargroup.priorityjobqueueexample.databinding.ActivityDetailsBinding;
29 | import com.solidgeargroup.priorityjobqueueexample.model.AddressComponent;
30 |
31 | /**
32 | * Created by jcmontesmartos on 2016/09/12.
33 | */
34 | public class DetailsActivity extends AppCompatActivity {
35 |
36 | public static final String ADDRESS_KEY = "ADDRESS_KEY";
37 |
38 | private ActivityDetailsBinding mBinding;
39 |
40 | @Override
41 | protected void onCreate(@Nullable Bundle savedInstanceState) {
42 | super.onCreate(savedInstanceState);
43 |
44 | mBinding = DataBindingUtil.setContentView(this, R.layout.activity_details);
45 |
46 | setSupportActionBar(mBinding.toolbar);
47 |
48 | AddressComponent addressComponent = new Gson().fromJson(
49 | getIntent().getStringExtra(ADDRESS_KEY), AddressComponent.class);
50 |
51 | mBinding.setAddressComponent(addressComponent);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/solidgeargroup/priorityjobqueueexample/model/AddressComponent.java:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package com.solidgeargroup.priorityjobqueueexample.model;
20 |
21 | import com.google.gson.annotations.SerializedName;
22 |
23 | /**
24 | * Created by jcmontesmartos on 2016/09/12.
25 | */
26 | public class AddressComponent {
27 | @SerializedName("formatted_address")
28 | private String formattedAddress;
29 |
30 | private Geometry geometry;
31 |
32 | @SerializedName("place_id")
33 | private String placeId;
34 |
35 | public AddressComponent() {
36 | }
37 |
38 | public String getFormattedAddress() {
39 | return formattedAddress;
40 | }
41 |
42 | public void setFormattedAddress(String formattedAddress) {
43 | this.formattedAddress = formattedAddress;
44 | }
45 |
46 | public String getFormattedAddressInMultipleLines() {
47 | if (formattedAddress == null) {
48 | return null;
49 | }
50 |
51 | return formattedAddress.replace(", ", "\n");
52 | }
53 |
54 | public Geometry getGeometry() {
55 | return geometry;
56 | }
57 |
58 | public void setGeometry(Geometry geometry) {
59 | this.geometry = geometry;
60 | }
61 |
62 | public String getPlaceId() {
63 | return placeId;
64 | }
65 |
66 | public void setPlaceId(String placeId) {
67 | this.placeId = placeId;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
20 |
21 |
24 |
25 |
26 |
27 |
34 |
35 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
50 |
51 |
52 |
54 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 |
23 |
30 |
31 |
38 |
39 |
40 |
41 |
42 |
43 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 |
20 | apply plugin: 'com.android.application'
21 |
22 | android {
23 | compileSdkVersion 24
24 | buildToolsVersion "24.0.2"
25 |
26 | defaultConfig {
27 | applicationId "com.solidgeargroup.priorityjobqueueexample"
28 | minSdkVersion 16
29 | targetSdkVersion 24
30 | versionCode 1
31 | versionName "1.0"
32 |
33 | buildConfigField "String", "GOOGLE_API_MAPS", '"https://maps.googleapis.com/maps/api/"'
34 | buildConfigField "String", "GOOGLE_STATIC_MAPS", '"https://maps.googleapis.com/maps/api/staticmap?size=640x640&zoom=16¢er=%s&markers=color:blue%%7C%s"'
35 |
36 | vectorDrawables.useSupportLibrary = true
37 | }
38 | buildTypes {
39 | release {
40 | minifyEnabled false
41 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
42 | }
43 | }
44 |
45 | dataBinding {
46 | enabled = true
47 | }
48 | }
49 |
50 | dependencies {
51 | compile fileTree(dir: 'libs', include: ['*.jar'])
52 |
53 | // Support libraries
54 | compile 'com.android.support:appcompat-v7:24.2.0'
55 | compile 'com.android.support:design:24.2.0'
56 | compile 'com.android.support:cardview-v7:24.2.0'
57 |
58 | // Networking libraries
59 | compile 'com.squareup.picasso:picasso:2.5.2'
60 | compile 'com.squareup.retrofit2:retrofit:2.1.0'
61 | compile 'com.squareup.retrofit2:converter-gson:2.1.0'
62 | compile "com.google.code.gson:gson:2.7"
63 |
64 | // Priority Job Queue Library
65 | compile 'com.birbit:android-priority-jobqueue:2.0.0'
66 |
67 | // Event Bus Library
68 | compile 'org.greenrobot:eventbus:3.0.0'
69 |
70 | // To have integration with GCM Network Manager
71 | compile 'com.google.android.gms:play-services-gcm:9.4.0'
72 | }
73 |
--------------------------------------------------------------------------------
/app/src/main/java/com/solidgeargroup/priorityjobqueueexample/database/FakeDatabase.java:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package com.solidgeargroup.priorityjobqueueexample.database;
20 |
21 | import android.content.Context;
22 | import android.content.SharedPreferences;
23 |
24 | import com.google.gson.Gson;
25 | import com.solidgeargroup.priorityjobqueueexample.model.LatLng;
26 |
27 | /**
28 | * Created by jcmontesmartos on 2016/09/12.
29 | */
30 | public class FakeDatabase {
31 |
32 | private static final String FAKE_DB_NAME = "FAKE_DB_NAME";
33 |
34 | private static final String KEY_LAST_ADDRESS = "KEY_LAST_ADDRESS";
35 | private static final String KEY_LAST_LATLNG = "KEY_LAST_LATLNG";
36 |
37 | public static String getLastAddress(Context context) {
38 | SharedPreferences sharedPreferences = context.getSharedPreferences(FAKE_DB_NAME, Context.MODE_PRIVATE);
39 |
40 | return sharedPreferences.getString(KEY_LAST_ADDRESS, "");
41 | }
42 |
43 | public static void setLastAddress(Context context, String address) {
44 | SharedPreferences sharedPreferences = context.getSharedPreferences(FAKE_DB_NAME, Context.MODE_PRIVATE);
45 | SharedPreferences.Editor editor = sharedPreferences.edit();
46 |
47 | editor.putString(KEY_LAST_ADDRESS, address);
48 |
49 | editor.commit();
50 | }
51 |
52 | public static LatLng getLastLatLng(Context context) {
53 | SharedPreferences sharedPreferences = context.getSharedPreferences(FAKE_DB_NAME, Context.MODE_PRIVATE);
54 |
55 | String latLngJson = sharedPreferences.getString(KEY_LAST_LATLNG, "");
56 |
57 | return new Gson().fromJson(latLngJson, LatLng.class);
58 | }
59 |
60 | public static void setLastLatLng(Context context, LatLng latLng) {
61 | SharedPreferences sharedPreferences = context.getSharedPreferences(FAKE_DB_NAME, Context.MODE_PRIVATE);
62 | SharedPreferences.Editor editor = sharedPreferences.edit();
63 |
64 | editor.putString(KEY_LAST_LATLNG, new Gson().toJson(latLng));
65 |
66 | editor.commit();
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/app/src/main/java/com/solidgeargroup/priorityjobqueueexample/managers/AppRetrofitManager.java:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package com.solidgeargroup.priorityjobqueueexample.managers;
20 |
21 | import com.google.gson.Gson;
22 | import com.solidgeargroup.priorityjobqueueexample.BuildConfig;
23 | import com.solidgeargroup.priorityjobqueueexample.networking.exceptions.ErrorRequestException;
24 | import com.solidgeargroup.priorityjobqueueexample.networking.requests.GeocodingInterface;
25 |
26 | import java.io.IOException;
27 |
28 | import okhttp3.OkHttpClient;
29 | import retrofit2.Call;
30 | import retrofit2.Retrofit;
31 | import retrofit2.converter.gson.GsonConverterFactory;
32 |
33 | /**
34 | * Created by jcmontesmartos on 2016/09/12.
35 | */
36 | public class AppRetrofitManager {
37 |
38 | private static Retrofit mRetrofit;
39 |
40 | private static GeocodingInterface mGeocodingInterface;
41 |
42 | public static Retrofit getRetrofit() {
43 | if (mRetrofit == null) {
44 | OkHttpClient okHttpClient = new OkHttpClient.Builder()
45 | .build();
46 | mRetrofit = new Retrofit.Builder()
47 | .baseUrl(BuildConfig.GOOGLE_API_MAPS)
48 | .addConverterFactory(GsonConverterFactory.create(new Gson()))
49 | .client(okHttpClient)
50 | .build();
51 |
52 | mGeocodingInterface = mRetrofit.create(GeocodingInterface.class);
53 | }
54 | return mRetrofit;
55 | }
56 |
57 | public static T performRequest(Call request) throws IOException, ErrorRequestException {
58 | retrofit2.Response response = request.execute();
59 |
60 | if (response == null || !response.isSuccessful() || response.errorBody() != null) {
61 | throw new ErrorRequestException(response);
62 | }
63 |
64 | return response.body();
65 | }
66 |
67 | public static GeocodingInterface getGeocodingInterface() {
68 | if (mGeocodingInterface == null) {
69 | getRetrofit();
70 | }
71 | return mGeocodingInterface;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/solidgeargroup/priorityjobqueueexample/jobs/FetchRandomLatLngJob.java:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package com.solidgeargroup.priorityjobqueueexample.jobs;
20 |
21 | import android.support.annotation.NonNull;
22 | import android.support.annotation.Nullable;
23 |
24 | import com.birbit.android.jobqueue.Job;
25 | import com.birbit.android.jobqueue.Params;
26 | import com.birbit.android.jobqueue.RetryConstraint;
27 | import com.solidgeargroup.priorityjobqueueexample.database.FakeDatabase;
28 | import com.solidgeargroup.priorityjobqueueexample.model.LatLng;
29 |
30 | import java.util.Random;
31 |
32 | /**
33 | * Created by jcmontesmartos on 2016/09/12.
34 | */
35 | public class FetchRandomLatLngJob extends Job {
36 |
37 | private static final double POINT_X = 37.474715;
38 | private static final double POINT_Y = -4.429496;
39 | private static final double POINT_RADIUS = 100000;
40 |
41 | public FetchRandomLatLngJob(String groupId) {
42 | super(new Params(JobConstants.PRIORITY_HIGH)
43 | .groupBy(groupId)
44 | );
45 | }
46 |
47 | @Override
48 | public void onAdded() {
49 | // Nothing to do
50 | }
51 |
52 | @Override
53 | public void onRun() throws Throwable {
54 | Random random = new Random();
55 |
56 | // Convert radius from meters to degrees
57 | double radiusInDegrees = POINT_RADIUS / 111000f;
58 |
59 | double u = random.nextFloat();
60 | double v = random.nextFloat();
61 | double w = radiusInDegrees * Math.sqrt(u);
62 | double t = 2 * Math.PI * v;
63 | double x = w * Math.cos(t);
64 | double y = w * Math.sin(t);
65 |
66 | // Adjust the x-coordinate for the shrinking of the east-west distances
67 | double new_x = x / Math.cos(POINT_Y);
68 |
69 | double foundLatitude = new_x + POINT_X;
70 | double foundLongitude = y + POINT_Y;
71 | LatLng randomLatLng = new LatLng(foundLatitude, foundLongitude);
72 |
73 | // Insert the location in our fake database
74 | FakeDatabase.setLastLatLng(getApplicationContext(), randomLatLng);
75 | }
76 |
77 | @Override
78 | protected void onCancel(int cancelReason, @Nullable Throwable throwable) {
79 | // Impossible to fail
80 | // Nothing to do here
81 | }
82 |
83 | @Override
84 | protected RetryConstraint shouldReRunOnThrowable(@NonNull Throwable throwable, int runCount, int maxRunCount) {
85 | return RetryConstraint.RETRY;
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/app/src/main/java/com/solidgeargroup/priorityjobqueueexample/jobs/FetchLocationByLatLngJob.java:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package com.solidgeargroup.priorityjobqueueexample.jobs;
20 |
21 | import android.support.annotation.NonNull;
22 | import android.support.annotation.Nullable;
23 |
24 | import com.birbit.android.jobqueue.Job;
25 | import com.birbit.android.jobqueue.Params;
26 | import com.birbit.android.jobqueue.RetryConstraint;
27 | import com.solidgeargroup.priorityjobqueueexample.database.FakeDatabase;
28 | import com.solidgeargroup.priorityjobqueueexample.events.LocationFailedEvent;
29 | import com.solidgeargroup.priorityjobqueueexample.events.LocationFetchedEvent;
30 | import com.solidgeargroup.priorityjobqueueexample.managers.AppRetrofitManager;
31 | import com.solidgeargroup.priorityjobqueueexample.model.Geocode;
32 | import com.solidgeargroup.priorityjobqueueexample.model.LatLng;
33 | import com.solidgeargroup.priorityjobqueueexample.networking.exceptions.ErrorRequestException;
34 | import com.solidgeargroup.priorityjobqueueexample.networking.requests.GeocodingInterface;
35 |
36 | import org.greenrobot.eventbus.EventBus;
37 |
38 | import retrofit2.Call;
39 |
40 | /**
41 | * Created by jcmontesmartos on 2016/09/12.
42 | */
43 | public class FetchLocationByLatLngJob extends Job {
44 |
45 | public static final String TAG = FetchLocationByLatLngJob.class.getCanonicalName();
46 |
47 | public FetchLocationByLatLngJob(String groupId) {
48 | super(new Params(JobConstants.PRIORITY_NORMAL)
49 | .setGroupId(groupId)
50 | .addTags(TAG)
51 | );
52 | }
53 |
54 | @Override
55 | public void onAdded() {
56 | }
57 |
58 | @Override
59 | public void onRun() throws Throwable {
60 | GeocodingInterface service = AppRetrofitManager.getGeocodingInterface();
61 |
62 | LatLng latLng = FakeDatabase.getLastLatLng(getApplicationContext());
63 |
64 | Call request = service.getInfoByLatLng(latLng);
65 | Geocode geocode = AppRetrofitManager.performRequest(request);
66 |
67 | // Ensure we have information about the searched gps coordinates
68 | if (geocode == null || geocode.getResults().size() <= 0) {
69 | EventBus.getDefault().post(new LocationFailedEvent());
70 | return;
71 | }
72 |
73 | EventBus.getDefault().post(new LocationFetchedEvent(geocode.getResults().get(0)));
74 | }
75 |
76 | @Override
77 | protected void onCancel(int cancelReason, @Nullable Throwable throwable) {
78 | EventBus.getDefault().post(new LocationFailedEvent());
79 | }
80 |
81 | @Override
82 | protected RetryConstraint shouldReRunOnThrowable(@NonNull Throwable throwable, int runCount, int maxRunCount) {
83 | if (throwable instanceof ErrorRequestException) {
84 |
85 | ErrorRequestException error = (ErrorRequestException) throwable;
86 |
87 | int statusCode = error.getResponse().raw().code();
88 |
89 | if (statusCode >= 400 && statusCode < 500) {
90 | return RetryConstraint.CANCEL;
91 | }
92 | }
93 |
94 | return RetryConstraint.RETRY;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/app/src/main/java/com/solidgeargroup/priorityjobqueueexample/jobs/FetchLocationByAddressJob.java:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package com.solidgeargroup.priorityjobqueueexample.jobs;
20 |
21 | import android.support.annotation.NonNull;
22 | import android.support.annotation.Nullable;
23 |
24 | import com.birbit.android.jobqueue.Job;
25 | import com.birbit.android.jobqueue.Params;
26 | import com.birbit.android.jobqueue.RetryConstraint;
27 | import com.solidgeargroup.priorityjobqueueexample.database.FakeDatabase;
28 | import com.solidgeargroup.priorityjobqueueexample.events.LocationFailedEvent;
29 | import com.solidgeargroup.priorityjobqueueexample.events.LocationFetchedEvent;
30 | import com.solidgeargroup.priorityjobqueueexample.managers.AppRetrofitManager;
31 | import com.solidgeargroup.priorityjobqueueexample.model.Geocode;
32 | import com.solidgeargroup.priorityjobqueueexample.networking.exceptions.ErrorRequestException;
33 | import com.solidgeargroup.priorityjobqueueexample.networking.requests.GeocodingInterface;
34 |
35 | import org.greenrobot.eventbus.EventBus;
36 |
37 | import retrofit2.Call;
38 |
39 | /**
40 | * Created by jcmontesmartos on 2016/09/12.
41 | */
42 | public class FetchLocationByAddressJob extends Job {
43 |
44 | private String mAddress;
45 |
46 | public static final String TAG = FetchLocationByAddressJob.class.getCanonicalName();
47 |
48 | public FetchLocationByAddressJob(String address) {
49 | super(new Params(JobConstants.PRIORITY_NORMAL)
50 | .requireNetwork()
51 | .singleInstanceBy(TAG)
52 | .addTags(TAG)
53 | );
54 |
55 | mAddress = address;
56 | }
57 |
58 | @Override
59 | public void onAdded() {
60 | // Store address in database
61 | FakeDatabase.setLastAddress(getApplicationContext(), mAddress);
62 | }
63 |
64 | @Override
65 | public void onRun() throws Throwable {
66 | String address = FakeDatabase.getLastAddress(getApplicationContext());
67 |
68 | GeocodingInterface service = AppRetrofitManager.getGeocodingInterface();
69 |
70 | Call request = service.getInfoByAddress(address);
71 | Geocode geocode = AppRetrofitManager.performRequest(request);
72 |
73 | // Ensure we have information about the search address
74 | if (geocode == null || geocode.getResults().size() <= 0) {
75 | EventBus.getDefault().post(new LocationFailedEvent());
76 | return;
77 | }
78 |
79 | // Just retrieve the first result
80 | EventBus.getDefault().post(new LocationFetchedEvent(geocode.getResults().get(0)));
81 | }
82 |
83 | @Override
84 | protected void onCancel(int cancelReason, @Nullable Throwable throwable) {
85 | EventBus.getDefault().post(new LocationFailedEvent());
86 | }
87 |
88 | @Override
89 | protected RetryConstraint shouldReRunOnThrowable(@NonNull Throwable throwable, int runCount, int maxRunCount) {
90 | if (throwable instanceof ErrorRequestException) {
91 |
92 | ErrorRequestException error = (ErrorRequestException) throwable;
93 |
94 | int statusCode = error.getResponse().raw().code();
95 |
96 | if (statusCode >= 400 && statusCode < 500) {
97 | return RetryConstraint.CANCEL;
98 | }
99 | }
100 |
101 | return RetryConstraint.RETRY;
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/app/src/main/java/com/solidgeargroup/priorityjobqueueexample/managers/AppJobManager.java:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package com.solidgeargroup.priorityjobqueueexample.managers;
20 |
21 | import android.content.Context;
22 | import android.os.Build;
23 | import android.util.Log;
24 |
25 | import com.birbit.android.jobqueue.JobManager;
26 | import com.birbit.android.jobqueue.config.Configuration;
27 | import com.birbit.android.jobqueue.log.CustomLogger;
28 | import com.birbit.android.jobqueue.scheduling.FrameworkJobSchedulerService;
29 | import com.birbit.android.jobqueue.scheduling.GcmJobSchedulerService;
30 | import com.google.android.gms.common.ConnectionResult;
31 | import com.google.android.gms.common.GoogleApiAvailability;
32 | import com.solidgeargroup.priorityjobqueueexample.services.AppGcmJobService;
33 | import com.solidgeargroup.priorityjobqueueexample.services.AppJobService;
34 |
35 | /**
36 | * Created by jcmontesmartos on 2016/09/12.
37 | */
38 | public class AppJobManager {
39 |
40 | private static JobManager mJobManager;
41 |
42 | public static synchronized JobManager getJobManager() {
43 | return mJobManager;
44 | }
45 |
46 | public static synchronized JobManager getJobManager(Context context) {
47 | if (mJobManager == null) {
48 | configureJobManager(context);
49 | }
50 | return mJobManager;
51 | }
52 |
53 | private static synchronized void configureJobManager(Context context) {
54 | if (mJobManager == null) {
55 | Configuration.Builder builder = new Configuration.Builder(context)
56 | .minConsumerCount(1) // always keep at least one consumer alive
57 | .maxConsumerCount(3) // up to 3 consumers at a time
58 | .loadFactor(3) // 3 jobs per consumer
59 | .consumerKeepAlive(120) // wait 2 minute
60 | .customLogger(new CustomLogger() {
61 | private static final String TAG = "JOBS";
62 | @Override
63 | public boolean isDebugEnabled() {
64 | return true;
65 | }
66 |
67 | @Override
68 | public void d(String text, Object... args) {
69 | Log.d(TAG, String.format(text, args));
70 | }
71 |
72 | @Override
73 | public void e(Throwable t, String text, Object... args) {
74 | Log.e(TAG, String.format(text, args), t);
75 | }
76 |
77 | @Override
78 | public void e(String text, Object... args) {
79 | Log.e(TAG, String.format(text, args));
80 | }
81 |
82 | @Override
83 | public void v(String text, Object... args) {
84 |
85 | }
86 | });
87 |
88 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
89 | builder.scheduler(FrameworkJobSchedulerService.createSchedulerFor(context,
90 | AppJobService.class), true);
91 | } else {
92 | int enableGcm = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context);
93 | if (enableGcm == ConnectionResult.SUCCESS) {
94 | builder.scheduler(GcmJobSchedulerService.createSchedulerFor(context,
95 | AppGcmJobService.class), true);
96 | }
97 | }
98 | mJobManager = new JobManager(builder.build());
99 | }
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/app/src/main/java/com/solidgeargroup/priorityjobqueueexample/ui/MainActivity.java:
--------------------------------------------------------------------------------
1 | /**
2 | The MIT License (MIT)
3 | Copyright (c) 2016 Solid Gear SL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial
11 | portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package com.solidgeargroup.priorityjobqueueexample.ui;
20 |
21 | import android.content.Intent;
22 | import android.databinding.DataBindingUtil;
23 | import android.os.Bundle;
24 | import android.support.annotation.Nullable;
25 | import android.support.design.widget.Snackbar;
26 | import android.support.v7.app.AppCompatActivity;
27 | import android.view.View;
28 | import android.widget.RadioGroup;
29 |
30 | import com.google.gson.Gson;
31 | import com.solidgeargroup.priorityjobqueueexample.R;
32 | import com.solidgeargroup.priorityjobqueueexample.databinding.ActivityMainBinding;
33 | import com.solidgeargroup.priorityjobqueueexample.events.LocationFailedEvent;
34 | import com.solidgeargroup.priorityjobqueueexample.events.LocationFetchedEvent;
35 | import com.solidgeargroup.priorityjobqueueexample.jobs.FetchLocationByAddressJob;
36 | import com.solidgeargroup.priorityjobqueueexample.jobs.FetchLocationByLatLngJob;
37 | import com.solidgeargroup.priorityjobqueueexample.jobs.FetchRandomLatLngJob;
38 | import com.solidgeargroup.priorityjobqueueexample.managers.AppJobManager;
39 | import com.solidgeargroup.priorityjobqueueexample.model.AddressComponent;
40 |
41 | import org.greenrobot.eventbus.EventBus;
42 | import org.greenrobot.eventbus.Subscribe;
43 | import org.greenrobot.eventbus.ThreadMode;
44 |
45 | import java.util.UUID;
46 |
47 | /**
48 | * Created by jcmontesmartos on 2016/09/12.
49 | */
50 | public class MainActivity extends AppCompatActivity
51 | implements View.OnClickListener, RadioGroup.OnCheckedChangeListener {
52 |
53 | private ActivityMainBinding mBinding;
54 |
55 | @Override
56 | protected void onCreate(@Nullable Bundle savedInstanceState) {
57 | super.onCreate(savedInstanceState);
58 | mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);
59 |
60 | setSupportActionBar(mBinding.toolbar);
61 |
62 | mBinding.options.setOnCheckedChangeListener(this);
63 | mBinding.searchFab.setOnClickListener(this);
64 |
65 | mBinding.setSelectedOption(mBinding.options.getCheckedRadioButtonId());
66 | }
67 |
68 | @Override
69 | protected void onResume() {
70 | super.onResume();
71 | EventBus.getDefault().register(this);
72 | }
73 |
74 | @Override
75 | protected void onPause() {
76 | super.onPause();
77 | EventBus.getDefault().unregister(this);
78 | }
79 |
80 | @Override
81 | public void onClick(View view) {
82 | if (mBinding.getSelectedOption() == R.id.radio_random_location) {
83 |
84 | String serialId = UUID.randomUUID().toString();
85 | AppJobManager.getJobManager().addJobInBackground(new FetchRandomLatLngJob(serialId));
86 | AppJobManager.getJobManager().addJobInBackground(new FetchLocationByLatLngJob(serialId));
87 |
88 | mBinding.addressLayout.setErrorEnabled(false);
89 | } else {
90 |
91 | String address = mBinding.address.getEditableText().toString().trim();
92 |
93 | if (address == null || address.length() == 0) {
94 | mBinding.addressLayout.setErrorEnabled(true);
95 | mBinding.addressLayout.setError(getString(R.string.error_empty_address));
96 | return;
97 | }
98 |
99 | mBinding.addressLayout.setErrorEnabled(false);
100 |
101 | AppJobManager.getJobManager().addJobInBackground(new FetchLocationByAddressJob(address));
102 | }
103 | }
104 |
105 | @Override
106 | public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
107 | mBinding.setSelectedOption(checkedId);
108 | }
109 |
110 | @Subscribe(threadMode = ThreadMode.MAIN)
111 | public void onLocationFetchedEvent(LocationFetchedEvent event) {
112 | AddressComponent addressComponent = event.getAddressComponent();
113 |
114 | Intent intent = new Intent(this, DetailsActivity.class);
115 | intent.putExtra(DetailsActivity.ADDRESS_KEY, new Gson().toJson(addressComponent));
116 | startActivity(intent);
117 | }
118 |
119 | @Subscribe(threadMode = ThreadMode.MAIN)
120 | public void onLocationFailedEvent(LocationFailedEvent event) {
121 | Snackbar.make(mBinding.content, R.string.error_not_found, Snackbar.LENGTH_LONG).show();
122 | }
123 |
124 | }
--------------------------------------------------------------------------------
/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/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
35 |
36 |
40 |
41 |
45 |
46 |
51 |
52 |
53 |
54 |
55 |
56 |
63 |
64 |
68 |
69 |
74 |
75 |
81 |
82 |
89 |
95 |
96 |
97 |
104 |
105 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
127 |
128 |
129 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_details.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
36 |
37 |
42 |
43 |
49 |
50 |
57 |
58 |
65 |
66 |
71 |
72 |
73 |
74 |
75 |
76 |
83 |
84 |
88 |
89 |
93 |
94 |
98 |
99 |
106 |
107 |
113 |
114 |
115 |
116 |
117 |
118 |
122 |
123 |
127 |
128 |
135 |
136 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
--------------------------------------------------------------------------------