11 |
12 |
--------------------------------------------------------------------------------
/License.txt:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SampleApp
2 | # Android Project Structure
3 |
4 |
5 | [](https://www.codacy.com/app/saveendhiman/SampleApp?utm_source=github.com&utm_medium=referral&utm_content=saveendhiman/SampleApp&utm_campaign=badger)
6 | [](https://twitter.com/saveendhiman)
7 |
8 | [](https://android-arsenal.com/api?level=14)
9 |
10 | [](https://www.apache.org/licenses/LICENSE-2.0.html)
11 |
12 |
13 | Hi guys, I have made one Project Structure for Android. This is the open project for any contributer who want to improve something here.
14 |
15 | This a Sample Project Structure for Android which you can follow for a clean architecture.
16 |
17 | **NOTE:** It's quite old one. You can refer [ComplexRecycler] Sample project. It's in Kotlin too.
18 |
19 | It shows usage of following libraries:
20 |
21 | * [Retrofit2] for REST API.
22 |
23 | * [RX java] for background process and Retrofit integration.
24 |
25 | * [Dagger2] for dependency injection.
26 |
27 | * [Firebase] for push notifications.
28 |
29 | * [Calligraphy] for font.
30 |
31 | * [Picasso] for image loading.
32 |
33 | * [Komensky] validations for annotation based validations.
34 |
35 | * [Fabric] for crashlytics.
36 |
37 | * [Butterknife] for view binding.
38 |
39 | * [Timber] for logging.
40 |
41 | It uses MVP (Model View Presenter) pattern. MVP is a derivative from the well known MVC (Model View Controller), which for a while now is gaining importance in the development of Android applications.This project also contains basic utility classes required for day to day programming.
42 |
43 |
44 | Location Handling by fused api.
45 |
46 | Utils classes.
47 |
48 |
49 | # Here is what the app gradle look likes.
50 |
51 | buildscript {
52 | repositories {
53 | maven { url 'https://maven.fabric.io/public' }
54 | }
55 |
56 | dependencies {
57 | classpath 'io.fabric.tools:gradle:1.+'
58 | }
59 | }
60 | apply plugin: 'com.android.application'
61 | apply plugin: 'io.fabric'
62 | apply plugin: 'com.neenbedankt.android-apt'
63 | apply plugin: 'me.tatarka.retrolambda'
64 |
65 | android {
66 | compileSdkVersion rootProject.ext.compileSdkVersion
67 | buildToolsVersion rootProject.ext.buildToolsVersion
68 |
69 | //app versioning
70 | def versionMajor = 1
71 | def versionMinor = 0
72 | def versionPatch = 0
73 | def versionBuild = 0
74 |
75 | defaultConfig {
76 | applicationId "com.sampleapp"
77 | minSdkVersion rootProject.ext.minSdkVersion
78 | targetSdkVersion rootProject.ext.targetSdkVersion
79 | versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
80 | versionName "${versionMajor}.${versionMinor}.${versionPatch}"
81 | }
82 | buildTypes {
83 | release {
84 | minifyEnabled false
85 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
86 | }
87 | }
88 |
89 | compileOptions {
90 | sourceCompatibility JavaVersion.VERSION_1_8
91 | targetCompatibility JavaVersion.VERSION_1_8
92 | }
93 | }
94 |
95 | repositories {
96 | maven {
97 | url "https://jitpack.io"
98 | }
99 | maven { url 'https://maven.fabric.io/public' }
100 | }
101 |
102 | dependencies {
103 | compile fileTree(include: ['*.jar'], dir: 'libs')
104 | compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
105 | compile "com.android.support:design:$rootProject.supportLibraryVersion"
106 | apt "com.google.dagger:dagger-compiler:$rootProject.daggerVersion"
107 | provided "org.glassfish:javax.annotation:$rootProject.ext.annotationVersion"
108 | compile "com.google.dagger:dagger:$rootProject.daggerVersion"
109 | compile "com.squareup.retrofit2:retrofit:$rootProject.ext.retrofitVersion"
110 | compile "com.squareup.retrofit2:converter-gson:$rootProject.ext.retrofitVersion"
111 | compile "com.squareup.retrofit2:adapter-rxjava:$rootProject.ext.retrofitVersion"
112 | compile "com.squareup.okhttp3:logging-interceptor:$rootProject.ext.loggerVersion"
113 | compile "io.reactivex:rxjava:$rootProject.ext.rxJavaVersion"
114 | compile "io.reactivex:rxandroid:$rootProject.ext.rxAndroidVersion"
115 | compile "com.jakewharton:butterknife:$rootProject.ext.butterknifeVersion"
116 | apt "com.jakewharton:butterknife-compiler:$rootProject.ext.butterknifeVersion"
117 | compile "com.jakewharton.timber:timber:$rootProject.ext.timberVersion"
118 | compile "com.google.android.gms:play-services-location:$rootProject.ext.playServiceVersion"
119 | compile "com.google.firebase:firebase-messaging:$rootProject.ext.playServiceVersion"
120 | compile "com.google.android.gms:play-services-maps:$rootProject.ext.playServiceVersion"
121 | compile "uk.co.chrisjenx:calligraphy:$rootProject.ext.calligraphyVersion"
122 | compile "com.squareup.picasso:picasso:$rootProject.ext.picassoVersion"
123 | compile "eu.inmite.android.lib:android-validation-komensky:$rootProject.ext.komenskyValidation@aar"
124 | compile("com.crashlytics.sdk.android:crashlytics:$rootProject.ext.crashVersion@aar") {
125 | transitive = true;
126 | }
127 |
128 | }
129 | apply plugin: 'com.google.gms.google-services'
130 |
131 | ##DONATIONS
132 |
133 | This project needs you! If you would like to support this project's further development, the creator of this project or the continuous maintenance of this project, feel free to donate. Your donation is highly appreciated (and I love food, coffee and beer). Thank you!
134 |
135 | **PayPal**
136 |
137 | * **[Donate $5]**: Thank's for creating this project, here's a coffee (or some beer) for you!
138 |
139 | * **[Donate $10]**: Wow, I am stunned. Let me take you to the movies!ù
140 |
141 | * **[Donate $15]**: I really appreciate your work, let's grab some lunch!
142 |
143 | * **[Donate $25]**: That's some awesome stuff you did right there, dinner is on me!
144 |
145 | * **[Donate $50]**: I really really want to support this project, great job!
146 |
147 | * **[Donate $100]**: You are the man! This project saved me hours (if not days) of struggle and hard work, simply awesome!
148 |
149 | * **[Donate $2799]**: Go buddy, buy Macbook Pro for yourself!
150 |
151 | Of course, you can also choose what you want to donate, all donations are awesome!!
152 |
153 |
154 | #Start from
155 |
156 | minSdkVersion 14
157 |
158 | #LICENSE
159 |
160 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
161 |
162 | http://www.apache.org/licenses/LICENSE-2.0
163 |
164 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
165 |
166 | #Authors
167 |
168 | [Saveen Dhiman] original Author
169 |
170 |
171 | [Donate $5]: https://www.paypal.me/saveendhiman/5
172 | [Donate $10]: https://www.paypal.me/saveendhiman/10
173 | [Donate $15]: https://www.paypal.me/saveendhiman/15
174 | [Donate $25]: https://www.paypal.me/saveendhiman/25
175 | [Donate $50]: https://www.paypal.me/saveendhiman/50
176 | [Donate $100]: https://www.paypal.me/saveendhiman/100
177 | [Donate $2799]: https://www.paypal.me/saveendhiman/2799
178 |
179 | [Saveen Dhiman]: https://github.com/saveendhiman
180 |
181 | [Retrofit2]: https://square.github.io/retrofit
182 | [RX java]: https://github.com/ReactiveX/RxJava
183 | [Dagger2]: https://google.github.io/dagger
184 | [Firebase]: https://firebase.google.com
185 | [Calligraphy]: https://github.com/chrisjenx/Calligraphy
186 | [Picasso]: http://square.github.io/picasso
187 | [Komensky]: https://github.com/inmite/android-validation-komensky
188 | [Fabric]: https://get.fabric.io/#
189 | [Butterknife]: http://jakewharton.github.io/butterknife
190 | [Timber]: https://github.com/JakeWharton/timber
191 |
192 | [ComplexRecycler]: https://github.com/saveendhiman/ComplexRecycler
193 |
194 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | maven { url 'https://maven.fabric.io/public' }
4 | }
5 |
6 | dependencies {
7 | classpath 'io.fabric.tools:gradle:1.+'
8 | }
9 | }
10 | apply plugin: 'com.android.application'
11 | apply plugin: 'io.fabric'
12 | apply plugin: 'com.neenbedankt.android-apt'
13 | apply plugin: 'me.tatarka.retrolambda'
14 |
15 | android {
16 | compileSdkVersion rootProject.ext.compileSdkVersion
17 | buildToolsVersion rootProject.ext.buildToolsVersion
18 |
19 | //app versioning
20 | def versionMajor = 1
21 | def versionMinor = 0
22 | def versionPatch = 0
23 | def versionBuild = 0
24 |
25 | defaultConfig {
26 | applicationId "com.sampleapp"
27 | minSdkVersion rootProject.ext.minSdkVersion
28 | targetSdkVersion rootProject.ext.targetSdkVersion
29 | versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
30 | versionName "${versionMajor}.${versionMinor}.${versionPatch}"
31 | }
32 | buildTypes {
33 | release {
34 | minifyEnabled false
35 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
36 | }
37 | }
38 |
39 | compileOptions {
40 | sourceCompatibility JavaVersion.VERSION_1_8
41 | targetCompatibility JavaVersion.VERSION_1_8
42 | }
43 | }
44 |
45 | repositories {
46 | maven {
47 | url "https://jitpack.io"
48 | }
49 | maven { url 'https://maven.fabric.io/public' }
50 | }
51 |
52 | dependencies {
53 | compile fileTree(include: ['*.jar'], dir: 'libs')
54 | compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
55 | compile "com.android.support:design:$rootProject.supportLibraryVersion"
56 | apt "com.google.dagger:dagger-compiler:$rootProject.daggerVersion"
57 | provided "org.glassfish:javax.annotation:$rootProject.ext.annotationVersion"
58 | compile "com.google.dagger:dagger:$rootProject.daggerVersion"
59 | compile "com.squareup.retrofit2:retrofit:$rootProject.ext.retrofitVersion"
60 | compile "com.squareup.retrofit2:converter-gson:$rootProject.ext.retrofitVersion"
61 | compile "com.squareup.retrofit2:adapter-rxjava:$rootProject.ext.retrofitVersion"
62 | compile "com.squareup.okhttp3:logging-interceptor:$rootProject.ext.loggerVersion"
63 | compile "io.reactivex:rxjava:$rootProject.ext.rxJavaVersion"
64 | compile "io.reactivex:rxandroid:$rootProject.ext.rxAndroidVersion"
65 | compile "com.jakewharton:butterknife:$rootProject.ext.butterknifeVersion"
66 | apt "com.jakewharton:butterknife-compiler:$rootProject.ext.butterknifeVersion"
67 | compile "com.jakewharton.timber:timber:$rootProject.ext.timberVersion"
68 | compile "com.google.android.gms:play-services-location:$rootProject.ext.playServiceVersion"
69 | compile "com.google.firebase:firebase-messaging:$rootProject.ext.playServiceVersion"
70 | compile "com.google.android.gms:play-services-maps:$rootProject.ext.playServiceVersion"
71 | compile "uk.co.chrisjenx:calligraphy:$rootProject.ext.calligraphyVersion"
72 | compile "com.squareup.picasso:picasso:$rootProject.ext.picassoVersion"
73 | compile "eu.inmite.android.lib:android-validation-komensky:$rootProject.ext.komenskyValidation@aar"
74 | compile "com.facebook.android:facebook-android-sdk:$rootProject.ext.facebookVersion"
75 | compile("com.crashlytics.sdk.android:crashlytics:$rootProject.ext.crashVersion@aar") {
76 | transitive = true;
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/app/google-services.json:
--------------------------------------------------------------------------------
1 | {
2 | "project_info": {
3 | "project_number": "196724664631",
4 | "firebase_url": "https://sampleapp-142606.firebaseio.com",
5 | "project_id": "sampleapp-142606",
6 | "storage_bucket": "sampleapp-142606.appspot.com"
7 | },
8 | "client": [
9 | {
10 | "client_info": {
11 | "mobilesdk_app_id": "1:196724664631:android:bfc12da51f75173a",
12 | "android_client_info": {
13 | "package_name": "com.sampleapp"
14 | }
15 | },
16 | "oauth_client": [
17 | {
18 | "client_id": "196724664631-58g4d8kr1dm6jnm0le9hu5fct9sguq8p.apps.googleusercontent.com",
19 | "client_type": 3
20 | },
21 | {
22 | "client_id": "196724664631-o8jkrt2i43j9to35l0hnmpn0el4bt5h8.apps.googleusercontent.com",
23 | "client_type": 3
24 | }
25 | ],
26 | "api_key": [
27 | {
28 | "current_key": "AIzaSyCQGcZEBeElSApIJdZ1IMNmg8_t1qc8J64"
29 | }
30 | ],
31 | "services": {
32 | "analytics_service": {
33 | "status": 1
34 | },
35 | "appinvite_service": {
36 | "status": 1,
37 | "other_platform_oauth_client": []
38 | },
39 | "ads_service": {
40 | "status": 2
41 | }
42 | }
43 | }
44 | ],
45 | "configuration_version": "1"
46 | }
--------------------------------------------------------------------------------
/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 |
19 | #Butterknife
20 |
21 | -keep class butterknife.** { *; }
22 | -keepnames class * { @butterknife.Bind *;}
23 |
24 | -dontwarn butterknife.internal.**
25 | -keep class **$$ViewBinder { *; }
26 |
27 | -keepclasseswithmembernames class * {
28 | @butterknife.* ;
29 | }
30 |
31 | -keepclasseswithmembernames class * {
32 | @butterknife.* ;
33 | }
34 |
35 | # Retain generated class which implement ViewBinder.
36 | -keep public class * implements butterknife.internal.ViewBinder { public (); }
37 |
38 | # Prevent obfuscation of types which use ButterKnife annotations since the simple name
39 | # is used to reflectively look up the generated ViewBinder.
40 | -keep class butterknife.*
41 | -keepclasseswithmembernames class * { @butterknife.* ; }
42 | -keepclasseswithmembernames class * { @butterknife.* ; }
43 |
44 | # rxjava
45 | -keep class rx.schedulers.Schedulers {
46 | public static ;
47 | }
48 | -keep class rx.schedulers.ImmediateScheduler {
49 | public ;
50 | }
51 | -keep class rx.schedulers.TestScheduler {
52 | public ;
53 | }
54 | -keep class rx.schedulers.Schedulers {
55 | public static ** test();
56 | }
57 | -keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
58 | long producerIndex;
59 | long consumerIndex;
60 | }
61 | -keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
62 | long producerNode;
63 | long consumerNode;
64 | }
65 |
66 | # Support library
67 | -dontwarn android.support.**
68 | -dontwarn android.support.v4.**
69 | -keep class android.support.v4.** { *; }
70 | -keep interface android.support.v4.** { *; }
71 | -dontwarn android.support.v7.**
72 | -keep class android.support.v7.** { *; }
73 | -keep interface android.support.v7.** { *; }
74 |
75 | # support design
76 | -dontwarn android.support.design.**
77 | -keep class android.support.design.** { *; }
78 | -keep interface android.support.design.** { *; }
79 | -keep public class android.support.design.R$* { *; }
80 |
81 |
82 | # Retrofit 2.X
83 | ## https://square.github.io/retrofit/ ##
84 |
85 | -dontwarn rx.**
86 | -dontwarn retrofit2.**
87 | -keep class retrofit2.** { *; }
88 | -keepattributes Signature
89 | -keepattributes Exceptions
90 | -keepattributes *Annotation*
91 | -keep class com.squareup.okhttp.** { *; }
92 | -keep interface com.squareup.okhttp.** { *; }
93 | -dontwarn com.squareup.okhttp.**
94 |
95 | -keepclasseswithmembers class * {
96 | @retrofit2.http.* ;
97 | }
98 |
99 | -keep class sun.misc.Unsafe { *; }
100 | #your package path where your gson models are stored
101 | -keep class com.xyz.model.** { *; }
102 |
103 | # Keep these for GSON and Jackson
104 | -keepattributes Signature
105 | -keepattributes *Annotation*
106 | -keepattributes EnclosingMethod
107 | -keep class sun.misc.Unsafe { *; }
108 | -keep class com.google.gson.** { *; }
109 |
110 | ## keep komensky validation
111 | -keepattributes *Annotation*
112 | -keep class eu.inmite.android.lib.validations.form.annotations.** { *; }
113 | -keep class * implements eu.inmite.android.lib.validations.form.iface.ICondition
114 | -keep class * implements eu.inmite.android.lib.validations.form.iface.IValidator
115 | -keep class * implements eu.inmite.android.lib.validations.form.iface.IFieldAdapter
116 | -keepclassmembers class ** {
117 | @eu.inmite.android.lib.validations.form.annotations.** *;
118 | }
119 |
120 | #facebook
121 | -keep class com.facebook.** {
122 | *;
123 | }
124 | -keepattributes Signature
125 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/sampleapp/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/debug/res/values/google_maps_api.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 | AIzaSyDKYb1BxAP5DxdG1f9hFVegJkKsjSf9yH4
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
43 |
44 |
47 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/api/NetModule.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.api;
2 |
3 |
4 | import com.sampleapp.constants.ApiConstants;
5 |
6 | import java.util.concurrent.TimeUnit;
7 |
8 | import javax.inject.Singleton;
9 |
10 | import dagger.Module;
11 | import dagger.Provides;
12 | import okhttp3.OkHttpClient;
13 | import okhttp3.logging.HttpLoggingInterceptor;
14 | import retrofit2.Retrofit;
15 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
16 | import retrofit2.converter.gson.GsonConverterFactory;
17 |
18 | /**
19 | * Created by saveen_dhiman on 05-November-16.
20 | * contains object related to network communication and API consumption
21 | */
22 | @Module
23 | public class NetModule {
24 |
25 | //get retrofit instance
26 | @Singleton
27 | @Provides
28 | public RestService getRestService() {
29 |
30 | Retrofit retrofit = new Retrofit.Builder()
31 | .baseUrl(ApiConstants.BASE_URL)
32 | .addConverterFactory(GsonConverterFactory.create())
33 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
34 | .client(getOkHttpClient())
35 | .build();
36 |
37 | return retrofit.create(RestService.class);
38 | }
39 |
40 | //get OkHttp instance
41 | @Singleton
42 | @Provides
43 | public OkHttpClient getOkHttpClient() {
44 |
45 | HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
46 | httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
47 |
48 | OkHttpClient.Builder builder = new OkHttpClient.Builder();
49 | builder.interceptors().add(httpLoggingInterceptor);
50 | builder.readTimeout(60, TimeUnit.SECONDS);
51 | builder.connectTimeout(60, TimeUnit.SECONDS);
52 | return builder.build();
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/api/RestService.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.api;
2 |
3 | import com.sampleapp.constants.ApiConstants;
4 | import com.sampleapp.model.request.LoginRequest;
5 | import com.sampleapp.model.response.LoginResponse;
6 |
7 | import retrofit2.http.Body;
8 | import retrofit2.http.POST;
9 | import rx.Observable;
10 |
11 | /**
12 | * Created by saveen_dhiman on 05-November-16.
13 | * Contains API methods to be consumed
14 | */
15 | public interface RestService {
16 |
17 | //LOGIN API
18 | @POST(ApiConstants.LOGIN)
19 | Observable login(@Body LoginRequest loginRequest);
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/base/AppComponent.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.base;
2 |
3 | import com.sampleapp.module.fragmentsample.SampleFragment;
4 | import com.sampleapp.module.fragmentsample.SamplePresenter;
5 | import com.sampleapp.utils.LocationTracker;
6 | import com.sampleapp.utils.UtilsModule;
7 |
8 | import javax.inject.Singleton;
9 |
10 | import dagger.Component;
11 |
12 | /**
13 | * Created by saveen_dhiman on 05-November-16.
14 | * Injections for Application class
15 | */
16 |
17 | @Singleton
18 | @Component(modules = {UtilsModule.class})
19 | public interface AppComponent {
20 | void inject(LocationTracker locationTracker);
21 |
22 | void inject(SamplePresenter samplePresenter);
23 |
24 | void inject(SampleFragment sampleFragment);
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/base/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.base;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.LayoutRes;
5 | import android.support.v7.app.AppCompatActivity;
6 |
7 | import butterknife.ButterKnife;
8 |
9 | /**
10 | * Created by saveen_dhiman on 05-November-16.
11 | * To be extended by all Activities
12 | */
13 | public abstract class BaseActivity extends AppCompatActivity {
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(getLayout());
19 | //bind view here for all activities extending this Activity
20 | ButterKnife.bind(this);
21 | }
22 |
23 | /**
24 | * get layout to inflate
25 | */
26 | public abstract
27 | @LayoutRes
28 | int getLayout();
29 |
30 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/base/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.base;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.LayoutRes;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | import butterknife.ButterKnife;
12 | import butterknife.Unbinder;
13 |
14 | /**
15 | * Created by saveen_dhiman on 05-November-16.
16 | * To be extended by all fragments
17 | */
18 | public abstract class BaseFragment extends Fragment {
19 |
20 | Unbinder mUnbinder;
21 | public boolean hasMore = false;
22 | public int pageNumber = 1;
23 |
24 | @Nullable
25 | @Override
26 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
27 | View view = inflater.inflate(getLayoutId(), container, false);
28 | mUnbinder = ButterKnife.bind(this, view);
29 | return view;
30 | }
31 |
32 | public abstract
33 | @LayoutRes
34 | int
35 | getLayoutId();
36 |
37 | @Override
38 | public void onDestroyView() {
39 | super.onDestroyView();
40 | mUnbinder.unbind();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/base/SampleApplication.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.base;
2 |
3 | import android.app.Application;
4 |
5 | import com.crashlytics.android.Crashlytics;
6 | import com.sampleapp.BuildConfig;
7 | import com.sampleapp.utils.UtilsModule;
8 |
9 | import io.fabric.sdk.android.Fabric;
10 | import timber.log.Timber;
11 |
12 |
13 | /**
14 | * Created by saveen_dhiman on 05-November-16.
15 | * Initialization of required libraries
16 | */
17 | public class SampleApplication extends Application {
18 |
19 | private AppComponent mAppComponent;
20 |
21 | @Override
22 | public void onCreate() {
23 | super.onCreate();
24 | Fabric.with(this, new Crashlytics());
25 |
26 | //create component
27 | mAppComponent = DaggerAppComponent.builder()
28 | .utilsModule(new UtilsModule(this)).build();
29 |
30 | //configure timber for logging
31 | if (BuildConfig.DEBUG) {
32 | Timber.plant(new Timber.DebugTree());
33 | }
34 | }
35 |
36 | public AppComponent getAppComponent() {
37 | return mAppComponent;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/constants/ApiConstants.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.constants;
2 |
3 | /**
4 | * Created by saveen_dhiman on 05-November-16.
5 | * contains all the constants related to API's
6 | */
7 | public interface ApiConstants {
8 | int STATUS_SUCCESS = 200;
9 | String STATUS_SESSION_EXPIRE = "203";
10 | String BASE_URL = "http://abc.com/";
11 | String CONTROLLER = "/index.php/webController";
12 | String LOGIN = CONTROLLER + "/apilogin";
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/constants/PrefernceConstants.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.constants;
2 |
3 | /**
4 | * Created by saveen_dhiman on 05-November-16.
5 | * Contains all the keys used in SharedPrefernce of application
6 | */
7 | public interface PrefernceConstants {
8 | String PREFERENCE_NAME = "SAMPLE_APP_PREFERENCES";
9 | String USER_DATA = "user_data";
10 | String IS_LOGIN = "isLogin";
11 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/constants/ValueConstants.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.constants;
2 |
3 | import android.support.annotation.IntDef;
4 |
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 |
8 | /**
9 | * Created by saveen_dhiman on 05-November-16.
10 | * contains constant values used in application
11 | */
12 | public interface ValueConstants {
13 |
14 | String LOCATION_PERMISSION = android.Manifest.permission.ACCESS_FINE_LOCATION;
15 | int REQUEST_CAMERA = 1001;
16 | int REQUEST_Gallery = 1002;
17 | int REQUEST_LOCATION = 1003;
18 | String DEVICE_TYPE = "android";
19 | String NEW_THREAD = "newThread";
20 | String MAIN_THREAD = "mainThread";
21 | String DATE_INPUT_FORMAT = "yyyy-MM-dd HH:mm:ss";
22 | String DATE_OUTPUT_FORMAT = "EEEE, h:mm a";
23 |
24 | // type check for error during login
25 | @IntDef({ValidationType.VALID, ValidationType.USER_NAME_INVALID, ValidationType.PASSWORD_INVALID})
26 | @Retention(RetentionPolicy.SOURCE)
27 | @interface ValidationType {
28 | int VALID = 0, USER_NAME_INVALID = 1, PASSWORD_INVALID = 2;
29 | }
30 |
31 | // type of dialog opened in MainActivity
32 | @IntDef({DialogType.DIALOG_DENY, DialogType.DIALOG_NEVER_ASK})
33 | @Retention(RetentionPolicy.SOURCE)
34 | @interface DialogType {
35 | int DIALOG_DENY = 0, DIALOG_NEVER_ASK = 1;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/interfaces/LocationUpdateListener.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.interfaces;
2 |
3 | import android.location.Location;
4 |
5 |
6 | /**
7 | * Created by saveen_dhiman on 05-November-16.
8 | *
9 | * An interface to receive high-level updates on where your location is.
10 | * @author aalcock
11 | *
12 | */
13 | public interface LocationUpdateListener {
14 |
15 | /**
16 | * Called immediately the service starts if the service can obtain location
17 | */
18 | void canReceiveLocationUpdates();
19 |
20 | /**
21 | * Called immediately the service tries to start if it cannot obtain location - eg the user has disabled wireless and
22 | */
23 | void cannotReceiveLocationUpdates();
24 |
25 | /**
26 | * Called whenever the location has changed (at least non-trivially)
27 | * @param location
28 | */
29 | void updateLocation(Location location);
30 |
31 | /**
32 | * Called when GoogleLocationServices detects that the device has moved to a new location.
33 | * @param localityName The name of the locality (somewhere below street but above area).
34 | */
35 | void updateLocationName(String localityName, Location location);
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/interfaces/OnDialogButtonClickListener.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.interfaces;
2 |
3 | /**
4 | * Created by saveen_dhiman on 05-November-16.
5 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.sampleapp.notification;
18 |
19 | import com.google.firebase.iid.FirebaseInstanceId;
20 | import com.google.firebase.iid.FirebaseInstanceIdService;
21 |
22 | import timber.log.Timber;
23 |
24 | /**
25 | * Created by saveen_dhiman on 05-November-16.
26 | * To get device token from firebase server for the purpose of push notifications
27 | */
28 |
29 | public class SampleAppFirebaseInstanceIDService extends FirebaseInstanceIdService {
30 |
31 | /**
32 | * Called if InstanceID token is updated. This may occur if the security of
33 | * the previous token had been compromised. Note that this is called when the InstanceID token
34 | * is initially generated so this is where you would retrieve the token.
35 | */
36 | // [START refresh_token]
37 | @Override
38 | public void onTokenRefresh() {
39 | // Get updated InstanceID token.
40 | String refreshedToken = FirebaseInstanceId.getInstance().getToken();
41 | Timber.e("Refreshed token: " + refreshedToken);
42 | }
43 | // [END refresh_token]
44 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/utils/AppUtils.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.utils;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.location.LocationManager;
7 | import android.net.ConnectivityManager;
8 | import android.net.NetworkInfo;
9 | import android.net.Uri;
10 | import android.provider.Settings;
11 | import android.view.View;
12 | import android.view.inputmethod.InputMethodManager;
13 | import android.widget.Toast;
14 |
15 | import com.google.android.gms.common.ConnectionResult;
16 | import com.google.android.gms.common.GoogleApiAvailability;
17 | import com.sampleapp.R;
18 |
19 | /**
20 | * Created by saveen_dhiman on 05-November-16.
21 | *
22 | * Contains commonly used methods in an Android App
23 | */
24 | public class AppUtils {
25 |
26 | private Context mContext;
27 |
28 | public AppUtils(Context context) {
29 | this.mContext = context;
30 | }
31 |
32 | /**
33 | * Description : Check if user is online or not
34 | *
35 | * @return true if online else false
36 | */
37 | public boolean isOnline(View v) {
38 | ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
39 | NetworkInfo netInfo = cm.getActiveNetworkInfo();
40 | if (netInfo != null && netInfo.isConnectedOrConnecting()) {
41 | return true;
42 | }
43 | showSnackBar(v, mContext.getString(R.string.toast_network_not_available));
44 | return false;
45 | }
46 |
47 |
48 | /**
49 | * Description : Hide the soft keyboard
50 | *
51 | * @param view : Pass the current view
52 | */
53 | public void hideSoftKeyboard(View view) {
54 | InputMethodManager inputMethodManager = (InputMethodManager) mContext.getSystemService(Activity.INPUT_METHOD_SERVICE);
55 | inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
56 | }
57 |
58 | /**
59 | * Show snackbar
60 | *
61 | * @param view view clicked
62 | * @param text text to be displayed on snackbar
63 | */
64 | public void showSnackBar(View view, String text) {
65 | // Snackbar.make(view, text, Snackbar.LENGTH_SHORT).show();
66 | }
67 |
68 | /**
69 | * Show snackbar
70 | *
71 | * @param text text to be displayed on Toast
72 | */
73 | public void showToast(String text) {
74 | Toast.makeText(mContext, text, Toast.LENGTH_SHORT).show();
75 | }
76 |
77 | /**
78 | * send email via. intent
79 | *
80 | * @param email to whom you want to send email
81 | */
82 | public void sendEmail(Context context, String email) {
83 | Intent i = new Intent(Intent.ACTION_SEND);
84 | i.setType("message/rfc822");
85 | i.putExtra(Intent.EXTRA_EMAIL, email);
86 | try {
87 | context.startActivity(Intent.createChooser(i, context.getResources().getString(R.string.send_mail)));
88 | } catch (android.content.ActivityNotFoundException ex) {
89 | Toast.makeText(context, context.getResources().getString(R.string.no_email_client), Toast.LENGTH_SHORT).show();
90 | }
91 | }
92 |
93 | /**
94 | * To open a website in phone browser
95 | *
96 | * @param address valid email link
97 | */
98 | public void openBrowser(String address) {
99 | try {
100 | if (!address.startsWith("http://") && !address.startsWith("https://")) {
101 | address = "http://" + address;
102 | }
103 | Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(address));
104 | mContext.startActivity(browserIntent);
105 | } catch (Exception e) {
106 | showToast(mContext.getResources().getString(R.string.warning_invalid_link));
107 | }
108 | }
109 |
110 | /**
111 | * Check the device to make sure it has the Google Play Services APK. If
112 | * it doesn't, display a dialog that allows users to download the APK from
113 | * the Google Play Store or enable it in the device's system settings.
114 | */
115 | public boolean checkPlayServices() {
116 | GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
117 | int resultCode = apiAvailability.isGooglePlayServicesAvailable(mContext);
118 | if (resultCode != ConnectionResult.SUCCESS) {
119 | if (apiAvailability.isUserResolvableError(resultCode)) {
120 | apiAvailability.getErrorDialog((Activity) mContext, resultCode, 9000)
121 | .show();
122 | } else {
123 | showToast(mContext.getResources().getString(R.string.warning_play_services));
124 | }
125 | return false;
126 | }
127 | return true;
128 | }
129 |
130 | /**
131 | * redirect user to your application settings in device
132 | */
133 | public void redirectToAppSettings() {
134 | Intent intent = new Intent();
135 | intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
136 | Uri uri = Uri.fromParts("package", mContext.getPackageName(), null);
137 | intent.setData(uri);
138 | mContext.startActivity(intent);
139 | }
140 |
141 | /**
142 | * check if user has enabled Gps of device
143 | *
144 | * @return true or false depending upon device Gps status
145 | */
146 | public boolean isGpsEnabled() {
147 | final LocationManager manager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
148 | return manager.isProviderEnabled(LocationManager.GPS_PROVIDER);
149 | }
150 |
151 | /**
152 | * Redirect user to enable GPS
153 | */
154 | public void goToGpsSettings() {
155 | Intent callGPSSettingIntent = new Intent(
156 | Settings.ACTION_LOCATION_SOURCE_SETTINGS);
157 | mContext.startActivity(callGPSSettingIntent);
158 | }
159 |
160 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/utils/DateTimeUtils.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.utils;
2 |
3 | import android.annotation.SuppressLint;
4 |
5 | import java.text.DateFormat;
6 | import java.text.ParseException;
7 | import java.text.SimpleDateFormat;
8 | import java.util.Date;
9 | import java.util.Locale;
10 | import java.util.TimeZone;
11 |
12 | /**
13 | * Created by saveen_dhiman on 05-November-16.
14 | * contains commonly used methods related to date & time conversion
15 | */
16 | public class DateTimeUtils {
17 | /**
18 | * get date form timestamp
19 | *
20 | * @param timestamp time to be converter
21 | * @return date in string
22 | */
23 |
24 | public String getDateFromTimestamp(String timestamp) {
25 |
26 | long time = Long.parseLong(timestamp) * 1000;
27 | try {
28 | DateFormat sdf = new SimpleDateFormat("dd MMMM yyyy", Locale.getDefault());
29 | Date netDate = (new Date(time));
30 | return sdf.format(netDate);
31 | } catch (Exception ex) {
32 | return "xx xxxx xxxx";
33 | }
34 | }
35 |
36 | /**
37 | * To convert a date to timestamp
38 | *
39 | * @param dateToConvert date to be converted
40 | * @param dateFormat format of date entered
41 | * @return timestamp in milliseconds
42 | */
43 |
44 | public long convertDateToTimeStamp(String dateToConvert, String dateFormat) {
45 | DateFormat formatter = new SimpleDateFormat(dateFormat, Locale.getDefault());
46 | Date date = null;
47 | try {
48 | date = formatter.parse(dateToConvert);
49 | } catch (ParseException e) {
50 | e.printStackTrace();
51 | }
52 | return date.getTime();
53 | }
54 |
55 | /**
56 | * Get current timestamp in seconds
57 | *
58 | * @return current device time in seconds
59 | */
60 | public static long getTimeStampInSeconds() {
61 | return System.currentTimeMillis() / 1000;
62 | }
63 |
64 |
65 | /**
66 | * get difference between current time and provided timezone
67 | *
68 | * @return
69 | */
70 | public long getTimeOffset() {
71 | long currentTime = System.currentTimeMillis();
72 | int edtOffset = TimeZone.getTimeZone("Your Time Zone").getOffset(currentTime);
73 | int current = TimeZone.getDefault().getOffset(currentTime);
74 | return current - edtOffset;
75 | }
76 |
77 | /**
78 | * Convert date from one format to another
79 | *
80 | * @param dateToConvert date to be converted
81 | * @param formatFrom the format of the date to be converted
82 | * @param formatTo the format of date you want the output
83 | * @return date in string as per the entered formats
84 | */
85 | @SuppressLint("SimpleDateFormat")
86 | public String convertDateOneToAnother(String dateToConvert, String formatFrom, String formatTo) {
87 | String outputDateStr = null;
88 | DateFormat inputFormat = new SimpleDateFormat(formatFrom);
89 | DateFormat outputFormat = new SimpleDateFormat(formatTo);
90 | Date date;
91 | try {
92 | date = inputFormat.parse(dateToConvert);
93 | outputDateStr = outputFormat.format(date);
94 | } catch (ParseException e) {
95 | e.printStackTrace();
96 | }
97 | return outputDateStr;
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/utils/DialogsUtil.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.utils;
2 |
3 | import android.app.AlertDialog;
4 | import android.content.Context;
5 |
6 | import com.sampleapp.R;
7 | import com.sampleapp.interfaces.OnDialogButtonClickListener;
8 |
9 | /**
10 | * Created by saveen_dhiman on 05-November-16.
11 | * contains Dialogs to be used in the application
12 | */
13 | public class DialogsUtil {
14 |
15 | private Context mContext;
16 |
17 | public DialogsUtil(Context context) {
18 | this.mContext = context;
19 | }
20 |
21 | /**
22 | * Return an alert dialog
23 | *
24 | * @param message message for the alert dialog
25 | * @param listener listener to trigger selection methods
26 | */
27 | public void openAlertDialog(Context context, String message, String positiveBtnText, String negativeBtnText,
28 | final OnDialogButtonClickListener listener) {
29 |
30 | AlertDialog.Builder builder = new AlertDialog.Builder(context);
31 | builder.setPositiveButton(positiveBtnText, (dialog, which) -> {
32 | dialog.dismiss();
33 | listener.onPositiveButtonClicked();
34 |
35 | });
36 |
37 | builder.setNegativeButton(negativeBtnText, (dialog, which) -> {
38 | dialog.dismiss();
39 | listener.onNegativeButtonClicked();
40 |
41 | });
42 | builder.setTitle(context.getResources().getString(R.string.app_name));
43 | builder.setMessage(message);
44 | builder.setIcon(android.R.drawable.ic_dialog_alert);
45 | builder.setCancelable(false);
46 | builder.create().show();
47 | }
48 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/utils/FragmentUtils.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.utils;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 |
6 | /**
7 | * Created by saveen_dhiman on 05-November-16.
8 | * contains methods related to fragment transactions
9 | */
10 | public class FragmentUtils {
11 |
12 | // replace fragment in a container
13 | public void replaceFragment(int container, FragmentManager manager, Fragment fragment) {
14 | manager.beginTransaction().replace(container, fragment).commitAllowingStateLoss();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/utils/ImageUtility.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.utils;
2 |
3 | /**
4 | * Created by saveen_dhiman on 05-November-16.
5 | * Image related utility methods
6 | */
7 |
8 | import android.app.Activity;
9 | import android.content.Context;
10 | import android.content.Intent;
11 | import android.database.Cursor;
12 | import android.graphics.Bitmap;
13 | import android.graphics.Bitmap.Config;
14 | import android.graphics.BitmapFactory;
15 | import android.graphics.Canvas;
16 | import android.graphics.Matrix;
17 | import android.graphics.Paint;
18 | import android.media.ExifInterface;
19 | import android.net.Uri;
20 | import android.os.Environment;
21 | import android.provider.MediaStore;
22 | import android.support.v7.app.AlertDialog;
23 | import android.util.Base64;
24 | import android.util.Log;
25 | import android.widget.ImageView;
26 |
27 | import com.sampleapp.R;
28 | import com.squareup.picasso.Picasso;
29 |
30 | import java.io.ByteArrayOutputStream;
31 | import java.io.File;
32 | import java.io.FileNotFoundException;
33 | import java.io.FileOutputStream;
34 | import java.io.IOException;
35 |
36 | import okhttp3.MediaType;
37 | import okhttp3.RequestBody;
38 | import rx.Observable;
39 | import rx.Subscriber;
40 |
41 | public class ImageUtility {
42 | private Context context;
43 |
44 | public ImageUtility(Context context) {
45 | this.context = context;
46 | }
47 |
48 | public Uri CameraGalleryIntent(final int cameraRequestCode, final int galleryRequestCode) {
49 | final File root = getFile();
50 | root.mkdirs();
51 | String filename = getUniqueImageFilename();
52 | File sdImageMainDirectory = new File(root, filename);
53 | final Uri outputFileUri = Uri.fromFile(sdImageMainDirectory);
54 | AlertDialog.Builder dialog = new AlertDialog.Builder(context);
55 | CharSequence items[] = new CharSequence[]{context.getResources().getString(R.string.camera), context.getResources().getString(R.string.gallery)};
56 | dialog.setItems(items, (d, n) -> {
57 | switch (n) {
58 | case 0:
59 | Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
60 | intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
61 | ((Activity) context).startActivityForResult(intent, cameraRequestCode);
62 | break;
63 | case 1:
64 | Intent pickIntent = new Intent(Intent.ACTION_PICK);
65 | pickIntent.setType("image/*");
66 | ((Activity) context).startActivityForResult(pickIntent, galleryRequestCode);
67 | break;
68 | default:
69 | break;
70 | }
71 | });
72 | dialog.setTitle(context.getResources().getString(R.string.selection));
73 | if (outputFileUri != null) {
74 | dialog.show();
75 | }
76 | return outputFileUri;
77 | }
78 |
79 | /**
80 | * Compresses the image
81 | *
82 | * @param filePath : Location of image file
83 | * @return
84 | */
85 | @SuppressWarnings("deprecation")
86 | public String compressImage(String filePath) {
87 | Bitmap scaledBitmap = null;
88 |
89 | BitmapFactory.Options options = new BitmapFactory.Options();
90 | options.inJustDecodeBounds = true;
91 | Bitmap bmp = BitmapFactory.decodeFile(filePath, options);
92 |
93 | int actualHeight = options.outHeight;
94 | int actualWidth = options.outWidth;
95 | float maxHeight = 816.0f;
96 | float maxWidth = 612.0f;
97 | float imgRatio = actualWidth / actualHeight;
98 | float maxRatio = maxWidth / maxHeight;
99 |
100 | if (actualHeight > maxHeight || actualWidth > maxWidth) {
101 | if (imgRatio < maxRatio) {
102 | imgRatio = maxHeight / actualHeight;
103 | actualWidth = (int) (imgRatio * actualWidth);
104 | actualHeight = (int) maxHeight;
105 | } else if (imgRatio > maxRatio) {
106 | imgRatio = maxWidth / actualWidth;
107 | actualHeight = (int) (imgRatio * actualHeight);
108 | actualWidth = (int) maxWidth;
109 | } else {
110 | actualHeight = (int) maxHeight;
111 | actualWidth = (int) maxWidth;
112 | }
113 | }
114 |
115 | options.inSampleSize = ImageUtility.calculateInSampleSize(options, actualWidth, actualHeight);
116 | options.inJustDecodeBounds = false;
117 | options.inDither = false;
118 | options.inPurgeable = true;
119 | options.inInputShareable = true;
120 | options.inTempStorage = new byte[16 * 1024];
121 |
122 | try {
123 | bmp = BitmapFactory.decodeFile(filePath, options);
124 | } catch (OutOfMemoryError exception) {
125 | exception.printStackTrace();
126 |
127 | }
128 | try {
129 | scaledBitmap = Bitmap.createBitmap(actualWidth, actualHeight, Config.ARGB_8888);
130 | } catch (OutOfMemoryError exception) {
131 | exception.printStackTrace();
132 | }
133 |
134 | float ratioX = actualWidth / (float) options.outWidth;
135 | float ratioY = actualHeight / (float) options.outHeight;
136 | float middleX = actualWidth / 2.0f;
137 | float middleY = actualHeight / 2.0f;
138 |
139 | Matrix scaleMatrix = new Matrix();
140 | scaleMatrix.setScale(ratioX, ratioY, middleX, middleY);
141 |
142 | Canvas canvas = new Canvas(scaledBitmap);
143 | canvas.setMatrix(scaleMatrix);
144 | canvas.drawBitmap(bmp, middleX - bmp.getWidth() / 2, middleY - bmp.getHeight() / 2, new Paint(
145 | Paint.FILTER_BITMAP_FLAG));
146 |
147 | ExifInterface exif;
148 | try {
149 | exif = new ExifInterface(filePath);
150 |
151 | int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
152 | Log.e("EXIF", "Exif: " + orientation);
153 | Matrix matrix = new Matrix();
154 | if (orientation == 6) {
155 | matrix.postRotate(90);
156 | Log.e("EXIF", "Exif: " + orientation);
157 | } else if (orientation == 3) {
158 | matrix.postRotate(180);
159 | Log.e("EXIF", "Exif: " + orientation);
160 | } else if (orientation == 8) {
161 | matrix.postRotate(270);
162 | Log.e("EXIF", "Exif: " + orientation);
163 | }
164 | scaledBitmap = Bitmap.createBitmap(scaledBitmap, 0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight(),
165 | matrix, true);
166 | } catch (IOException e) {
167 | e.printStackTrace();
168 | }
169 | FileOutputStream out = null;
170 | String filename = getFilename();
171 | try {
172 | out = new FileOutputStream(filename);
173 | scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 95, out);
174 | } catch (FileNotFoundException e) {
175 | e.printStackTrace();
176 | } finally {
177 | if (bmp != null) {
178 | bmp.recycle();
179 | bmp = null;
180 | }
181 | if (scaledBitmap != null) {
182 | scaledBitmap.recycle();
183 | }
184 | }
185 | return filename;
186 |
187 | }
188 |
189 | public String getFilename() {
190 |
191 | final File root = getFile();
192 | root.mkdirs();
193 | final String filename = getUniqueImageFilename();
194 | File file = new File(root, filename);
195 | return file.getAbsolutePath();
196 | }
197 |
198 | private File getFile() {
199 | return new File(Environment.getExternalStorageDirectory() + File.separator + "SampleApp"
200 | + File.separator);
201 | }
202 |
203 | public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
204 | final int height = options.outHeight;
205 | final int width = options.outWidth;
206 | int inSampleSize = 1;
207 |
208 | if (height > reqHeight || width > reqWidth) {
209 | if (width > height) {
210 | inSampleSize = Math.round((float) height / (float) reqHeight);
211 | } else {
212 | inSampleSize = Math.round((float) width / (float) reqWidth);
213 | }
214 | }
215 | return inSampleSize;
216 | }
217 |
218 | public static String getUniqueImageFilename() {
219 | return "img_" + System.currentTimeMillis() + ".png";
220 | }
221 |
222 | public String getRealPathFromURI(Uri contentUri) {
223 | // can post image
224 | String[] proj = {MediaStore.Images.Media.DATA};
225 | @SuppressWarnings("deprecation")
226 | Cursor cursor = ((Activity) context).managedQuery(contentUri, proj, // Which
227 | // columns
228 | // to
229 | // return
230 | null, // WHERE clause; which rows to return (all rows)
231 | null, // WHERE clause selection arguments (none)
232 | null); // Order-by clause (ascending by name)
233 | int column_index = cursor
234 | .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
235 | cursor.moveToFirst();
236 | return cursor.getString(column_index);
237 | }
238 |
239 |
240 | public void LoadImage(String url, ImageView imageView) {
241 | LoadImage(url, imageView, false);
242 | }
243 |
244 | public void LoadImage(String url, ImageView imageView, boolean isRounded) {
245 | Picasso.with(context).load(url).into(imageView);
246 | }
247 |
248 | /**
249 | * Compress image and convert to multipart
250 | *
251 | * @param filePath path of the file to be converted
252 | * @return multipart image for the path supplied
253 | */
254 | public Observable getCompressedFile(final String filePath, final ImageUtility imageUtility) {
255 | return Observable.create(new Observable.OnSubscribe() {
256 | @Override
257 | public void call(Subscriber super RequestBody> subscriber) {
258 | try {
259 | String newFilePath = getCompressedImage(filePath);
260 | subscriber.onNext(imageUtility.getRequestBodyImage(new File(newFilePath)));
261 | subscriber.onCompleted();
262 | } catch (Exception e) {
263 | subscriber.onError(e);
264 | }
265 | }
266 | });
267 | }
268 |
269 | /**
270 | * get request body image
271 | */
272 | public RequestBody getRequestBodyImage(File file) {
273 | return RequestBody.create(MediaType.parse("image/png"), file);
274 | }
275 |
276 | /**
277 | * convert image to base 64 string
278 | *
279 | * @param filePath path of image
280 | * @return base 64 string
281 | */
282 | public String getBase64Image(String filePath) {
283 | filePath = getCompressedImage(filePath);
284 | Bitmap bm = BitmapFactory.decodeFile(filePath);
285 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
286 | bm.compress(Bitmap.CompressFormat.PNG, 100, baos); //bm is the bitmap object
287 | byte[] b = baos.toByteArray();
288 | return Base64.encodeToString(b, Base64.DEFAULT);
289 | }
290 |
291 | /**
292 | * get compressed image
293 | */
294 | private String getCompressedImage(String filePath) {
295 | String newFilePath;
296 | int file_size = Integer.parseInt(String.valueOf(new File(filePath).length() >> 10));
297 | if (file_size >= 120) {
298 | newFilePath = compressImage(filePath);
299 | } else {
300 | newFilePath = filePath;
301 | }
302 | return filePath;
303 | }
304 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/utils/LocationHelper.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.utils;
2 |
3 | import android.content.Context;
4 | import android.location.Address;
5 | import android.location.Geocoder;
6 | import android.location.Location;
7 |
8 | import com.google.android.gms.maps.model.LatLng;
9 |
10 | import java.io.IOException;
11 | import java.util.List;
12 | import java.util.Locale;
13 |
14 | /**
15 | * Created by saveen_dhiman on 05-November-16.
16 | * contains helper methods to manipulate user location
17 | */
18 | public class LocationHelper {
19 |
20 | private Context mContext;
21 |
22 | public LocationHelper(Context context) {
23 | this.mContext = context;
24 | }
25 |
26 | /**
27 | * @param latitude latitude of address
28 | * @param longitude longitude of address
29 | * @return simplified address of location
30 | */
31 |
32 | public String getSimplifiedAddress(double latitude, double longitude) {
33 | String location = "";
34 | try {
35 | Geocoder geocoder = new Geocoder(mContext, Locale.getDefault());
36 | List addresses = geocoder.getFromLocation(latitude, longitude, 1);
37 | if (addresses.size() > 0) {
38 | Address address = addresses.get(0);
39 | String admin = address.getAdminArea();
40 | String subLocality = address.getSubLocality();
41 | String locality = address.getLocality();
42 | if (admin.length() > 10) {
43 | admin = admin.substring(0, 10) + "..";
44 | }
45 | if (locality != null && subLocality != null) {
46 | location = subLocality + "," + locality;
47 | } else if (subLocality != null) {
48 | location = subLocality + "," + admin;
49 | } else {
50 | location = locality + "," + admin;
51 | }
52 | }
53 | } catch (IOException e) {
54 | e.printStackTrace();
55 | }
56 |
57 | return location;
58 | }
59 |
60 | /**
61 | * @param latitude latitude of address
62 | * @param longitude longitude of address
63 | * @return complete address of location
64 | */
65 |
66 | public String getCompleteAddress(double latitude, double longitude) {
67 | String location = "";
68 | try {
69 | Geocoder geocoder = new Geocoder(mContext, Locale.getDefault());
70 | List addresses = geocoder.getFromLocation(latitude, longitude, 1);
71 | if (addresses.size() > 0) {
72 | Address address = addresses.get(0);
73 | String state, city, zip, street;
74 | if (address.getAdminArea() != null) {
75 | state = address.getAdminArea();
76 | } else {
77 | state = "";
78 | }
79 | if (address.getLocality() != null) {
80 | city = address.getLocality();
81 | } else {
82 | city = "";
83 | }
84 | if (address.getPostalCode() != null) {
85 | zip = address.getPostalCode();
86 | } else {
87 | zip = "";
88 | }
89 |
90 | if (address.getThoroughfare() != null) {
91 | street = address.getSubLocality() + "," + address.getThoroughfare();
92 | } else {
93 | street = address.getSubLocality() + "," + address.getFeatureName();
94 | }
95 | location = street + "," + city + "," + zip + "," + state;
96 | }
97 | } catch (IOException e) {
98 | e.printStackTrace();
99 | }
100 |
101 | return location;
102 | }
103 |
104 | /**
105 | * Calculate distance between two
106 | *
107 | * @param src lat/long of source
108 | * @param des lat/lng of destination
109 | * @return distance between two location in miles
110 | */
111 | public double calculateDistance(LatLng src, LatLng des) {
112 | double distance;
113 | double finalValue = 0;
114 | try {
115 | Location locationA = new Location("");
116 | locationA.setLatitude(src.latitude);
117 | locationA.setLongitude(src.longitude);
118 | Location locationB = new Location("");
119 | locationB.setLatitude(des.latitude);
120 | locationB.setLongitude(des.longitude);
121 | distance = locationA.distanceTo(locationB) / 1000;
122 | finalValue = Math.round(distance * 100.0) / 100.0;
123 | } catch (Exception e) {
124 | e.printStackTrace();
125 | }
126 |
127 | return finalValue;
128 | }
129 |
130 | /**
131 | * to get latitude and longitude of an address
132 | *
133 | * @param strAddress address string
134 | * @return lat and lng in comma separated string
135 | */
136 | public String getLocationFromAddress(String strAddress) {
137 |
138 | Geocoder coder = new Geocoder(mContext);
139 | List address;
140 |
141 | try {
142 | address = coder.getFromLocationName(strAddress, 1);
143 | if (address == null) {
144 | return null;
145 | }
146 | Address location = address.get(0);
147 | double lat = location.getLatitude();
148 | double lng = location.getLongitude();
149 |
150 | return lat + "," + lng;
151 | } catch (Exception e) {
152 | return null;
153 | }
154 | }
155 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/utils/LocationTracker.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.utils;
2 |
3 | import android.content.Context;
4 | import android.location.Location;
5 | import android.os.Bundle;
6 | import android.support.annotation.NonNull;
7 |
8 | import com.google.android.gms.common.ConnectionResult;
9 | import com.google.android.gms.common.api.GoogleApiClient;
10 | import com.google.android.gms.location.LocationListener;
11 | import com.google.android.gms.location.LocationRequest;
12 | import com.google.android.gms.location.LocationServices;
13 | import com.sampleapp.R;
14 | import com.sampleapp.base.SampleApplication;
15 |
16 | import javax.inject.Inject;
17 |
18 | import timber.log.Timber;
19 |
20 | @SuppressWarnings("MissingPermission")
21 | public class LocationTracker implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
22 |
23 | private Context context;
24 | private GoogleApiClient mGoogleApiClient;
25 | private static int UPDATE_INTERVAL = 0;
26 | private static int FATEST_INTERVAL = 0;
27 | private static int DISPLACEMENT = 2000; // 2KM
28 | private LocationRequest mLocationRequest;
29 | private Location mLastLocation;
30 | private onLocationListener listener;
31 |
32 | @Inject
33 | AppUtils mAppUtils;
34 |
35 | public LocationTracker(Context context) {
36 | this.context = context;
37 |
38 | ((SampleApplication)context).getAppComponent().inject(this);
39 |
40 | if (mAppUtils.checkPlayServices()) {
41 | buildGoogleApiClient();
42 | createLocationRequest();
43 | if (mGoogleApiClient != null) {
44 | mGoogleApiClient.connect();
45 | }
46 | } else {
47 | mAppUtils.showToast(context.getResources().getString(R.string.warning_play_services));
48 | }
49 | }
50 |
51 |
52 | protected synchronized void buildGoogleApiClient() {
53 | mGoogleApiClient = new GoogleApiClient.Builder(context)
54 | .addConnectionCallbacks(this)
55 | .addOnConnectionFailedListener(this)
56 | .addApi(LocationServices.API).build();
57 | }
58 |
59 | @Override
60 | public void onConnected(Bundle bundle) {
61 | displayLocation();
62 | startLocationUpdates();
63 | }
64 |
65 | @Override
66 | public void onConnectionSuspended(int i) {
67 | mGoogleApiClient.connect();
68 | }
69 |
70 | @Override
71 | public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
72 | Timber.e(connectionResult.toString());
73 | }
74 |
75 | /**
76 | * Creating location request object
77 | */
78 | private void createLocationRequest() {
79 | mLocationRequest = new LocationRequest();
80 | mLocationRequest.setInterval(UPDATE_INTERVAL);
81 | mLocationRequest.setFastestInterval(FATEST_INTERVAL);
82 | mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
83 | mLocationRequest.setSmallestDisplacement(DISPLACEMENT);
84 | }
85 |
86 | /**
87 | * Method to display the location on UI
88 | */
89 | private void displayLocation() {
90 | mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
91 | if (mLastLocation != null) {
92 | double latitude = mLastLocation.getLatitude();
93 | double longitude = mLastLocation.getLongitude();
94 | Timber.e(latitude + "," + longitude);
95 | listener.onConnected(mLastLocation);
96 | }
97 | }
98 |
99 | /**
100 | * Starting the location updates
101 | */
102 | private void startLocationUpdates() {
103 | LocationServices.FusedLocationApi
104 | .requestLocationUpdates(mGoogleApiClient, mLocationRequest, locationListener);
105 | Timber.e("startLocationUpdates");
106 | }
107 |
108 | /**
109 | * Stopping location updates
110 | */
111 | public void stopLocationUpdates() {
112 | try {
113 | LocationServices.FusedLocationApi
114 | .removeLocationUpdates(mGoogleApiClient, locationListener);
115 | Timber.e("stopLocationUpdates");
116 | } catch (Exception e) {
117 | e.printStackTrace();
118 | }
119 | }
120 |
121 | private LocationListener locationListener = new LocationListener() {
122 | @Override
123 | public void onLocationChanged(Location location) {
124 | mLastLocation = location;
125 | displayLocation();
126 | }
127 | };
128 |
129 | public void setLocationListener(onLocationListener listener) {
130 | this.listener = listener;
131 | }
132 |
133 | public interface onLocationListener {
134 | void onConnected(Location location);
135 | }
136 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/utils/PreferenceManager.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.utils;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 |
6 | import com.google.gson.Gson;
7 | import com.sampleapp.constants.PrefernceConstants;
8 | import com.sampleapp.model.UserData;
9 |
10 |
11 | /**
12 | * Created by saveen_dhiman on 05-November-16.
13 | * Contains method to store and retrieve SharedPreferences data
14 | */
15 | public class PreferenceManager {
16 |
17 | private static Context context1;
18 |
19 | public PreferenceManager(Context context) {
20 | PreferenceManager.context1 = context;
21 | }
22 |
23 | //get shared pref
24 | private SharedPreferences getPreferences() {
25 | return context1.getSharedPreferences(PrefernceConstants.PREFERENCE_NAME, Context.MODE_PRIVATE);
26 | }
27 |
28 |
29 | //save data of current logged in user
30 | public void setUserData(String userData) {
31 | getPreferences().edit().putString(PrefernceConstants.USER_DATA, userData).commit();
32 | }
33 |
34 | //get user data as string
35 | private String getUserDataFromPref() {
36 | return getPreferences().getString(PrefernceConstants.USER_DATA, null);
37 | }
38 |
39 | //get saved data of current user as an object
40 | public UserData.ResponseBean.AuthBean getUserData() {
41 | UserData.ResponseBean.AuthBean userData = null;
42 | if (getUserDataFromPref() != null) {
43 | userData = new Gson().fromJson(getUserDataFromPref(), UserData.ResponseBean.AuthBean.class);
44 | }
45 | return userData;
46 | }
47 |
48 | //returns true when user is logged in
49 | public void setUserLoggedIn(boolean isLogin) {
50 | getPreferences().edit().putBoolean(PrefernceConstants.IS_LOGIN, isLogin).commit();
51 | }
52 |
53 | //set true when user is logegd in else false
54 | public boolean isUserLoggedIn() {
55 | return getPreferences().getBoolean(PrefernceConstants.IS_LOGIN, false);
56 | }
57 |
58 | //clear user shared preferences
59 | public void clearPrefrences() {
60 | getPreferences().edit().clear().commit();
61 | }
62 |
63 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/utils/ProgressBarHandler.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.utils;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.support.v4.content.ContextCompat;
6 | import android.view.Gravity;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.ProgressBar;
10 | import android.widget.RelativeLayout;
11 |
12 | import com.sampleapp.R;
13 |
14 |
15 | public class ProgressBarHandler {
16 |
17 | private ProgressBar mProgressBar;
18 |
19 | public ProgressBarHandler(Context context) {
20 |
21 | ViewGroup layout = (ViewGroup) ((Activity) context).findViewById(android.R.id.content).getRootView();
22 |
23 | mProgressBar = new ProgressBar(context, null);
24 | mProgressBar.setIndeterminate(true);
25 |
26 | mProgressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(context, R.color.colorPrimary),
27 | android.graphics.PorterDuff.Mode.MULTIPLY);
28 |
29 | RelativeLayout.LayoutParams params = new
30 | RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
31 |
32 | RelativeLayout rl = new RelativeLayout(context);
33 |
34 | rl.setGravity(Gravity.CENTER);
35 | rl.addView(mProgressBar);
36 |
37 | layout.addView(rl, params);
38 |
39 | hideProgress();
40 | }
41 |
42 | public void showProgress() {
43 | mProgressBar.setVisibility(View.VISIBLE);
44 | }
45 |
46 | public void hideProgress() {
47 | mProgressBar.setVisibility(View.INVISIBLE);
48 | }
49 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/utils/UtilsModule.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.utils;
2 |
3 | import android.content.Context;
4 |
5 | import com.sampleapp.constants.ValueConstants;
6 |
7 | import javax.inject.Named;
8 | import javax.inject.Singleton;
9 |
10 | import dagger.Module;
11 | import dagger.Provides;
12 | import rx.Scheduler;
13 | import rx.android.schedulers.AndroidSchedulers;
14 | import rx.schedulers.Schedulers;
15 |
16 | /**
17 | * Created by saveen_dhiman on 05-November-16.
18 | * Provide injects for utility objects
19 | */
20 |
21 | @Module
22 | public class UtilsModule {
23 |
24 | private Context mContext;
25 |
26 | public UtilsModule(Context context) {
27 | this.mContext = context;
28 | }
29 |
30 | // get AppUtils instance
31 | @Provides
32 | @Singleton
33 | public AppUtils getAppUtils() {
34 | return new AppUtils(mContext);
35 | }
36 |
37 | // get DateTimeUtils instance
38 | @Provides
39 | @Singleton
40 | public DateTimeUtils getDateTimeUtils() {
41 | return new DateTimeUtils();
42 | }
43 |
44 | // get ProgressBarHandler instance
45 | @Provides
46 | @Singleton
47 | public ProgressBarHandler getProgressBar() {
48 | return new ProgressBarHandler(mContext);
49 | }
50 |
51 | //get dialog utils
52 | @Provides
53 | @Singleton
54 | public DialogsUtil getDialogUtils() {
55 | return new DialogsUtil(mContext);
56 | }
57 |
58 | //get new thread
59 | @Provides
60 | @Singleton
61 | @Named(ValueConstants.NEW_THREAD)
62 | public Scheduler getNewThread() {
63 | return Schedulers.io();
64 | }
65 |
66 | //get main thread
67 | @Provides
68 | @Singleton
69 | @Named(ValueConstants.MAIN_THREAD)
70 | public Scheduler getMainThread() {
71 | return AndroidSchedulers.mainThread();
72 | }
73 |
74 | //get Preference Manager
75 | @Provides
76 | @Singleton
77 | public PreferenceManager getPreferences() {
78 | return new PreferenceManager(mContext);
79 | }
80 |
81 | //get Fragment utils
82 | @Provides
83 | @Singleton
84 | public FragmentUtils getFragUtils() {
85 | return new FragmentUtils();
86 | }
87 |
88 | //get location helper methods
89 | @Provides
90 | @Singleton
91 | public LocationHelper getLocationUtils() {
92 | return new LocationHelper(mContext);
93 | }
94 |
95 | //get location tracker
96 | @Provides
97 | @Singleton
98 | public LocationTracker getLocationTrackerOF() {
99 | return new LocationTracker(mContext);
100 | }
101 |
102 | //get image utils
103 | @Provides
104 | @Singleton
105 | public ImageUtility getImageUtils() {
106 | return new ImageUtility(mContext);
107 | }
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/views/RemoveErrorEditText.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.views;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.Context;
5 | import android.os.Build;
6 | import android.text.Editable;
7 | import android.text.TextWatcher;
8 | import android.util.AttributeSet;
9 | import android.widget.EditText;
10 |
11 | /**
12 | * Created by saveen_dhiman on 05-November-16.
13 | * Custom editText to remove error on editText field when onTextChange is called
14 | */
15 | public class RemoveErrorEditText extends EditText {
16 | public RemoveErrorEditText(Context context) {
17 | super(context);
18 | removeError();
19 | }
20 |
21 | public RemoveErrorEditText(Context context, AttributeSet attrs) {
22 | super(context, attrs);
23 | removeError();
24 | }
25 |
26 | public RemoveErrorEditText(Context context, AttributeSet attrs, int defStyleAttr) {
27 | super(context, attrs, defStyleAttr);
28 | removeError();
29 | }
30 |
31 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
32 | public RemoveErrorEditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
33 | super(context, attrs, defStyleAttr, defStyleRes);
34 | removeError();
35 | }
36 |
37 |
38 | private void removeError() {
39 |
40 | addTextChangedListener(new TextWatcher() {
41 | @Override
42 | public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
43 | }
44 |
45 | @Override
46 | public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
47 | }
48 |
49 | @Override
50 | public void afterTextChanged(Editable editable) {
51 | setError(null);
52 | }
53 | });
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/general_click_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/general_click_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
19 |
20 |
25 |
26 |
31 |
32 |
37 |
38 |
41 |
42 |
47 |
48 |
49 |
50 |
55 |
56 |
60 |
61 |
67 |
68 |
69 |
70 |
71 |
72 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
89 |
90 |
91 |
92 |
93 |
94 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
113 |
114 |
118 |
119 |
127 |
128 |
137 |
138 |
139 |
140 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_register.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_splash.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_sample.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saveendhiman/SampleApp/7dfbb21df24c2dd76e88021b5d97244944496220/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saveendhiman/SampleApp/7dfbb21df24c2dd76e88021b5d97244944496220/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saveendhiman/SampleApp/7dfbb21df24c2dd76e88021b5d97244944496220/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saveendhiman/SampleApp/7dfbb21df24c2dd76e88021b5d97244944496220/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saveendhiman/SampleApp/7dfbb21df24c2dd76e88021b5d97244944496220/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-hdpi/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
7 | 5dp
8 | 10dp
9 | 15dp
10 | 20dp
11 | 25dp
12 | 30dp
13 | 35dp
14 | 40dp
15 | 45dp
16 | 50dp
17 | 60dp
18 | 75dp
19 | 80dp
20 |
21 | 8sp
22 | 11sp
23 | 14sp
24 | 18sp
25 | 20sp
26 | 22sp
27 | 24sp
28 |
29 |
30 | 4dp
31 | 150dp
32 |
33 |
34 | 160dp
35 | 200dp
36 | 0.9dp
37 | 2dp
38 | 200dp
39 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values-xhdpi/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
7 | 7dp
8 | 12dp
9 | 17dp
10 | 22dp
11 | 27dp
12 | 32dp
13 | 37dp
14 | 42dp
15 | 47dp
16 | 52dp
17 | 78dp
18 | 64dp
19 | 85dp
20 |
21 |
22 | 9sp
23 | 12sp
24 | 15sp
25 | 19sp
26 | 21.5sp
27 | 24sp
28 | 26sp
29 |
30 |
31 | 4dp
32 | 160dp
33 |
34 |
35 | 170dp
36 | 205dp
37 | 1.1dp
38 |
39 | 205dp
40 |
41 |
42 |
--------------------------------------------------------------------------------
/app/src/main/res/values-xxhdpi/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
7 | 10dp
8 | 15dp
9 | 20dp
10 | 25dp
11 | 30dp
12 | 35dp
13 | 40dp
14 | 45dp
15 | 50dp
16 | 55dp
17 | 82dp
18 | 70dp
19 | 90dp
20 |
21 |
22 | 10sp
23 | 13sp
24 | 16sp
25 | 20sp
26 | 22.5sp
27 | 25sp
28 | 27.5sp
29 |
30 |
31 | 6dp
32 | 170dp
33 |
34 |
35 | 180dp
36 | 205dp
37 | 1.8dp
38 |
39 | 205dp
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/app/src/main/res/values-xxxhdpi/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
7 | 12dp
8 | 17dp
9 | 22dp
10 | 27dp
11 | 32dp
12 | 37dp
13 | 42dp
14 | 47dp
15 | 52dp
16 | 57dp
17 | 74dp
18 | 85dp
19 | 95dp
20 |
21 |
22 | 11sp
23 | 14sp
24 | 17sp
25 | 22sp
26 | 24sp
27 | 26.5sp
28 | 28sp
29 |
30 |
31 | 6dp
32 | 180dp
33 |
34 |
35 | 190dp
36 | 210dp
37 | 2dp
38 |
39 | 210dp
40 |
41 |
42 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #9FB7B7B7
7 | #3B66C4
8 | #32CCFF
9 | #969696
10 | #939393
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SampleApp
3 | Please check your internet connection!
4 | Send email
5 | No email client found!
6 | Invalid website link!
7 | Google Play Services are missing from your device!
8 | Select type
9 | Camera
10 | Gallery
11 | This field cannot be empty
12 | Login With Facebook
13 | Login With Twitter
14 | Password must be a minimum of 6 characters
15 | Email Address or Username
16 | Password
17 | Or Login With Email
18 | Login
19 | Create Account
20 | Need Help?
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
15 |
16 |
17 |
25 |
26 |
27 |
36 |
37 |
38 |
42 |
43 |
47 |
48 |
54 |
55 |
56 |
57 |
66 |
67 |
68 |
69 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/app/src/release/res/values/google_maps_api.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 | AIzaSyDKYb1BxAP5DxdG1f9hFVegJkKsjSf9yH4
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/test/java/com/sampleapp/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.1.3'
9 | classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
10 | classpath 'me.tatarka:gradle-retrolambda:3.2.5'
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | jcenter()
20 | }
21 | }
22 |
23 | task clean(type: Delete) {
24 | delete rootProject.buildDir
25 | }
26 |
27 | ext {
28 | minSdkVersion = 16
29 | targetSdkVersion = 23
30 | compileSdkVersion = 24
31 | buildToolsVersion = '24.0.1'
32 | supportLibraryVersion = '24.0.0-alpha1'
33 | daggerVersion = '2.5'
34 | retrofitVersion = '2.0.2'
35 | rxJavaVersion = '1.1.6'
36 | rxAndroidVersion = '1.2.1'
37 | butterknifeVersion = '8.2.1'
38 | loggerVersion = '3.3.1'
39 | timberVersion = '4.1.2'
40 | playServiceVersion = '9.4.0'
41 | calligraphyVersion = '2.2.0'
42 | annotationVersion = '10.0-b28'
43 | routeVersion = '1.1.0'
44 | picassoVersion = '2.5.2'
45 | komenskyValidation = '0.9.4'
46 | facebookVersion = '4.15.0'
47 | crashVersion = '2.6.2'
48 | }
49 |
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saveendhiman/SampleApp/7dfbb21df24c2dd76e88021b5d97244944496220/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
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 | #distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
8 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------