├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── app
├── .gitignore
├── build.gradle
├── google-services.json
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── tutorial
│ │ └── authentication
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── tutorial
│ │ │ └── authentication
│ │ │ ├── BaseActivity.java
│ │ │ ├── MainActivity.java
│ │ │ ├── NavDrawerActivity.java
│ │ │ ├── model
│ │ │ └── User.java
│ │ │ └── utils
│ │ │ ├── Constants.java
│ │ │ ├── SharedPrefManager.java
│ │ │ └── Utils.java
│ └── res
│ │ ├── drawable
│ │ ├── ic_android_black_24dp.xml
│ │ ├── ic_build_black_24dp.xml
│ │ ├── ic_forward_black_24dp.xml
│ │ └── ic_invert_colors_black_24dp.xml
│ │ ├── layout
│ │ ├── activity_base.xml
│ │ ├── activity_main.xml
│ │ ├── activity_nav_drawer.xml
│ │ └── nav_header.xml
│ │ ├── menu
│ │ └── menu_navigation.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── tutorial
│ └── authentication
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | FirebaseAuthentication
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
23 |
24 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.0"
6 |
7 | defaultConfig {
8 | applicationId "com.tutorial.authentication"
9 | minSdkVersion 15
10 | targetSdkVersion 25
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:25.0.0'
26 | compile 'com.android.support:design:25.0.0'
27 | compile 'com.google.firebase:firebase-core:9.8.0'
28 | compile 'com.google.firebase:firebase-auth:9.8.0'
29 | compile 'com.google.android.gms:play-services-auth:9.8.0'
30 | compile 'com.facebook.android:facebook-android-sdk:4.0.1'
31 | compile 'com.google.firebase:firebase-database:9.8.0'
32 | compile 'com.firebase:firebase-client-android:2.4.0'
33 | compile 'com.squareup.picasso:picasso:2.5.2'
34 | compile 'de.hdodenhof:circleimageview:1.3.0'
35 | }
36 | apply plugin: 'com.google.gms.google-services'
--------------------------------------------------------------------------------
/app/google-services.json:
--------------------------------------------------------------------------------
1 | {
2 | "project_info": {
3 | "project_number": "916393918766",
4 | "firebase_url": "https://authentication-4fa99.firebaseio.com",
5 | "project_id": "authentication-4fa99",
6 | "storage_bucket": "authentication-4fa99.appspot.com"
7 | },
8 | "client": [
9 | {
10 | "client_info": {
11 | "mobilesdk_app_id": "1:916393918766:android:8a39e539a94dccee",
12 | "android_client_info": {
13 | "package_name": "com.tutorial.authentication"
14 | }
15 | },
16 | "oauth_client": [
17 | {
18 | "client_id": "916393918766-rjqug06o79ot5upmh0s0rd5ros6vc2o8.apps.googleusercontent.com",
19 | "client_type": 1,
20 | "android_info": {
21 | "package_name": "com.tutorial.authentication",
22 | "certificate_hash": "3efbd6ecd45f6e429e22c98e412291b0b99a7fa0"
23 | }
24 | },
25 | {
26 | "client_id": "916393918766-5eqgcc3mjle43mqu9judcogs1s57ad1p.apps.googleusercontent.com",
27 | "client_type": 3
28 | }
29 | ],
30 | "api_key": [
31 | {
32 | "current_key": "AIzaSyD1SL38yAiYeyIAqMge_rvNrxdrnJ7diL4"
33 | }
34 | ],
35 | "services": {
36 | "analytics_service": {
37 | "status": 1
38 | },
39 | "appinvite_service": {
40 | "status": 2,
41 | "other_platform_oauth_client": [
42 | {
43 | "client_id": "916393918766-5eqgcc3mjle43mqu9judcogs1s57ad1p.apps.googleusercontent.com",
44 | "client_type": 3
45 | }
46 | ]
47 | },
48 | "ads_service": {
49 | "status": 2
50 | }
51 | }
52 | }
53 | ],
54 | "configuration_version": "1"
55 | }
--------------------------------------------------------------------------------
/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:\Users\Gino Osahon\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/tutorial/authentication/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.tutorial.authentication;
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/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tutorial/authentication/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.tutorial.authentication;
2 |
3 | import android.app.ProgressDialog;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 |
7 | import com.firebase.client.Firebase;
8 |
9 | public class BaseActivity extends AppCompatActivity {
10 | public ProgressDialog mProgressDialog;
11 |
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_base);
16 |
17 | //Initialize Firebase
18 | Firebase.setAndroidContext(this);
19 | }
20 |
21 | public void showProgressDialog() {
22 | if (mProgressDialog == null) {
23 | mProgressDialog = new ProgressDialog(this);
24 | mProgressDialog.setMessage(getString(R.string.loading));
25 | mProgressDialog.setIndeterminate(true);
26 | }
27 |
28 | mProgressDialog.show();
29 | }
30 |
31 | public void hideProgressDialog() {
32 | if (mProgressDialog != null && mProgressDialog.isShowing()) {
33 | mProgressDialog.dismiss();
34 | }
35 | }
36 |
37 | @Override
38 | protected void onStop() {
39 | super.onStop();
40 | hideProgressDialog();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tutorial/authentication/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.tutorial.authentication;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.support.annotation.NonNull;
7 | import android.os.Bundle;
8 | import android.support.annotation.Nullable;
9 | import android.support.design.widget.NavigationView;
10 | import android.util.Log;
11 | import android.view.View;
12 | import android.widget.Toast;
13 |
14 | import com.firebase.client.FirebaseError;
15 | import com.google.android.gms.auth.api.Auth;
16 | import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
17 | import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
18 | import com.google.android.gms.auth.api.signin.GoogleSignInResult;
19 | import com.google.android.gms.common.ConnectionResult;
20 | import com.google.android.gms.common.SignInButton;
21 | import com.google.android.gms.common.api.GoogleApiClient;
22 | import com.google.android.gms.tasks.OnCompleteListener;
23 | import com.google.android.gms.tasks.Task;
24 | import com.google.firebase.auth.AuthCredential;
25 | import com.google.firebase.auth.AuthResult;
26 | import com.google.firebase.auth.FirebaseAuth;
27 | import com.google.firebase.auth.FirebaseUser;
28 | import com.google.firebase.auth.GoogleAuthProvider;
29 | import com.google.firebase.database.ServerValue;
30 | import com.tutorial.authentication.utils.Constants;
31 | import com.tutorial.authentication.utils.SharedPrefManager;
32 | import com.tutorial.authentication.utils.Utils;
33 | import com.tutorial.authentication.model.User;
34 | import com.firebase.client.Firebase;
35 |
36 | import java.util.HashMap;
37 |
38 |
39 | /**
40 | * Created by Gino Osahon on 03/03/2017.
41 | */
42 |
43 | // This class handles Google Firebase Authentication and also saves the user details to Firebase
44 | public class MainActivity extends BaseActivity implements GoogleApiClient.ConnectionCallbacks,
45 | GoogleApiClient.OnConnectionFailedListener,
46 | View.OnClickListener {
47 |
48 | private GoogleApiClient mGoogleApiClient;
49 | private FirebaseAuth mAuth;
50 | private FirebaseAuth.AuthStateListener mAuthListener;
51 | private static final int RC_SIGN_IN = 9001;
52 | private static final String TAG = "MainActivity";
53 | private String idToken;
54 | public SharedPrefManager sharedPrefManager;
55 | private final Context mContext = this;
56 |
57 | private String name, email;
58 | private String photo;
59 | private Uri photoUri;
60 | private SignInButton mSignInButton;
61 |
62 | @Override
63 | protected void onCreate(Bundle savedInstanceState) {
64 | super.onCreate(savedInstanceState);
65 | setContentView(R.layout.activity_main);
66 |
67 | mSignInButton = (SignInButton) findViewById(R.id.login_with_google);
68 | mSignInButton.setSize(SignInButton.SIZE_WIDE);
69 |
70 | mSignInButton.setOnClickListener(this);
71 |
72 | configureSignIn();
73 |
74 | mAuth = com.google.firebase.auth.FirebaseAuth.getInstance();
75 |
76 | //this is where we start the Auth state Listener to listen for whether the user is signed in or not
77 | mAuthListener = new FirebaseAuth.AuthStateListener(){
78 | @Override
79 | public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
80 | // Get signedIn user
81 | FirebaseUser user = firebaseAuth.getCurrentUser();
82 |
83 | //if user is signed in, we call a helper method to save the user details to Firebase
84 | if (user != null) {
85 | // User is signed in
86 | createUserInFirebaseHelper();
87 | Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
88 | } else {
89 | // User is signed out
90 | Log.d(TAG, "onAuthStateChanged:signed_out");
91 | }
92 | }
93 | };
94 | }
95 |
96 | //This method creates a new user on our own Firebase database
97 | //after a successful Authentication on Firebase
98 | //It also saves the user info to SharedPreference
99 | private void createUserInFirebaseHelper(){
100 |
101 | //Since Firebase does not allow "." in the key name, we'll have to encode and change the "." to ","
102 | // using the encodeEmail method in class Utils
103 | final String encodedEmail = Utils.encodeEmail(email.toLowerCase());
104 |
105 | //create an object of Firebase database and pass the the Firebase URL
106 | final Firebase userLocation = new Firebase(Constants.FIREBASE_URL_USERS).child(encodedEmail);
107 |
108 | //Add a Listerner to that above location
109 | userLocation.addListenerForSingleValueEvent(new com.firebase.client.ValueEventListener() {
110 | @Override
111 | public void onDataChange(com.firebase.client.DataSnapshot dataSnapshot) {
112 | if (dataSnapshot.getValue() == null){
113 | /* Set raw version of date to the ServerValue.TIMESTAMP value and save into dateCreatedMap */
114 | HashMap timestampJoined = new HashMap<>();
115 | timestampJoined.put(Constants.FIREBASE_PROPERTY_TIMESTAMP, ServerValue.TIMESTAMP);
116 |
117 | // Insert into Firebase database
118 | User newUser = new User(name, photo, encodedEmail, timestampJoined);
119 | userLocation.setValue(newUser);
120 |
121 | Toast.makeText(MainActivity.this, "Account created!", Toast.LENGTH_SHORT).show();
122 |
123 | // After saving data to Firebase, goto next activity
124 | // Intent intent = new Intent(MainActivity.this, NavDrawerActivity.class);
125 | // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
126 | // startActivity(intent);
127 | // finish();
128 | }
129 | }
130 |
131 | @Override
132 | public void onCancelled(FirebaseError firebaseError) {
133 |
134 | Log.d(TAG, getString(R.string.log_error_occurred) + firebaseError.getMessage());
135 | //hideProgressDialog();
136 | if (firebaseError.getCode() == FirebaseError.EMAIL_TAKEN){
137 | }
138 | else {
139 | Toast.makeText(MainActivity.this, firebaseError.getMessage(), Toast.LENGTH_SHORT).show();
140 | }
141 | }
142 | });
143 | }
144 |
145 | // This method configures Google SignIn
146 | public void configureSignIn(){
147 | // Configure sign-in to request the user's basic profile like name and email
148 | GoogleSignInOptions options = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
149 | .requestIdToken(MainActivity.this.getResources().getString(R.string.web_client_id))
150 | .requestEmail()
151 | .build();
152 |
153 | // Build a GoogleApiClient with access to GoogleSignIn.API and the options above.
154 | mGoogleApiClient = new GoogleApiClient.Builder(mContext)
155 | .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
156 | .addApi(Auth.GOOGLE_SIGN_IN_API, options)
157 | .build();
158 | mGoogleApiClient.connect();
159 | }
160 |
161 | // This method is called when the signIn button is clicked on the layout
162 | // It prompts the user to select a Google account.
163 | private void signIn() {
164 | Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
165 | startActivityForResult(signInIntent, RC_SIGN_IN);
166 | }
167 |
168 |
169 | // This IS the method where the result of clicking the signIn button will be handled
170 | @Override
171 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
172 | super.onActivityResult(requestCode, resultCode, data);
173 |
174 | // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
175 | if (requestCode == RC_SIGN_IN) {
176 | GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
177 | if (result.isSuccess()) {
178 | // Google Sign In was successful, save Token and a state then authenticate with Firebase
179 | GoogleSignInAccount account = result.getSignInAccount();
180 |
181 | idToken = account.getIdToken();
182 |
183 | name = account.getDisplayName();
184 | email = account.getEmail();
185 | photoUri = account.getPhotoUrl();
186 | photo = photoUri.toString();
187 |
188 | // Save Data to SharedPreference
189 | sharedPrefManager = new SharedPrefManager(mContext);
190 | sharedPrefManager.saveIsLoggedIn(mContext, true);
191 |
192 | sharedPrefManager.saveEmail(mContext, email);
193 | sharedPrefManager.saveName(mContext, name);
194 | sharedPrefManager.savePhoto(mContext, photo);
195 |
196 | sharedPrefManager.saveToken(mContext, idToken);
197 | //sharedPrefManager.saveIsLoggedIn(mContext, true);
198 |
199 | AuthCredential credential = GoogleAuthProvider.getCredential(idToken, null);
200 | firebaseAuthWithGoogle(credential);
201 | } else {
202 | // Google Sign In failed, update UI appropriately
203 | Log.e(TAG, "Login Unsuccessful. ");
204 | Toast.makeText(this, "Login Unsuccessful", Toast.LENGTH_SHORT)
205 | .show();
206 | }
207 | }
208 | }
209 |
210 | //After a successful sign into Google, this method now authenticates the user with Firebase
211 | private void firebaseAuthWithGoogle(AuthCredential credential){
212 | showProgressDialog();
213 | mAuth.signInWithCredential(credential)
214 | .addOnCompleteListener(this, new OnCompleteListener() {
215 | @Override
216 | public void onComplete(@NonNull Task task) {
217 | Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
218 | if (!task.isSuccessful()) {
219 | Log.w(TAG, "signInWithCredential" + task.getException().getMessage());
220 | task.getException().printStackTrace();
221 | Toast.makeText(MainActivity.this, "Authentication failed.",
222 | Toast.LENGTH_SHORT).show();
223 | }else {
224 | createUserInFirebaseHelper();
225 | Toast.makeText(MainActivity.this, "Login successful",
226 | Toast.LENGTH_SHORT).show();
227 | Intent intent = new Intent(MainActivity.this, NavDrawerActivity.class);
228 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
229 | startActivity(intent);
230 | finish();
231 | }
232 | hideProgressDialog();
233 | }
234 | });
235 | }
236 |
237 | @Override
238 | protected void onStart() {
239 | super.onStart();
240 | if (mAuthListener != null){
241 | FirebaseAuth.getInstance().signOut();
242 | }
243 | mAuth.addAuthStateListener(mAuthListener);
244 | }
245 |
246 | @Override
247 | protected void onStop() {
248 | super.onStop();
249 | if (mAuthListener != null){
250 | mAuth.removeAuthStateListener(mAuthListener);
251 | }
252 | }
253 |
254 | @Override
255 | public void onConnected(@Nullable Bundle bundle) {
256 |
257 | }
258 |
259 | @Override
260 | public void onConnectionSuspended(int i) {
261 |
262 | }
263 |
264 | @Override
265 | public void onClick(View view) {
266 |
267 | Utils utils = new Utils(this);
268 | int id = view.getId();
269 |
270 | if (id == R.id.login_with_google){
271 | if (utils.isNetworkAvailable()){
272 | signIn();
273 | }else {
274 | Toast.makeText(MainActivity.this, "Oops! no internet connection!", Toast.LENGTH_SHORT).show();
275 | }
276 | }
277 | }
278 |
279 | @Override
280 | public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
281 |
282 | }
283 | }
284 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tutorial/authentication/NavDrawerActivity.java:
--------------------------------------------------------------------------------
1 | package com.tutorial.authentication;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.support.annotation.NonNull;
7 | import android.support.v4.widget.DrawerLayout;
8 | import android.os.Bundle;
9 | import android.support.v7.app.ActionBarDrawerToggle;
10 | import android.support.v7.widget.Toolbar;
11 | import android.view.MenuItem;
12 | import android.view.View;
13 | import android.widget.TextView;
14 | import de.hdodenhof.circleimageview.CircleImageView;
15 | import android.support.design.widget.NavigationView;
16 | import android.widget.Toast;
17 |
18 | import com.google.android.gms.auth.api.Auth;
19 | import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
20 | import com.google.android.gms.common.ConnectionResult;
21 | import com.google.android.gms.common.api.GoogleApiClient;
22 | import com.google.android.gms.common.api.ResultCallback;
23 | import com.google.android.gms.common.api.Status;
24 | import com.google.firebase.auth.FirebaseAuth;
25 | import com.squareup.picasso.Picasso;
26 | import com.tutorial.authentication.utils.SharedPrefManager;
27 |
28 | /**
29 | * Created by Gino Osahon on 03/03/2017.
30 | */
31 |
32 | // This class is a simple activity with NavigationDrawer
33 | // we get data stored in sharedPrefference and display on the header view of the NavigationDrawer
34 | public class NavDrawerActivity extends BaseActivity implements
35 | GoogleApiClient.OnConnectionFailedListener{
36 |
37 | Context mContext = this;
38 |
39 | private DrawerLayout drawerLayout;
40 | private Toolbar toolbar;
41 | private NavigationView navigationView;
42 | private TextView mFullNameTextView, mEmailTextView;
43 | private CircleImageView mProfileImageView;
44 | private String mUsername, mEmail;
45 |
46 | SharedPrefManager sharedPrefManager;
47 | private GoogleApiClient mGoogleApiClient;
48 | private FirebaseAuth mAuth;
49 |
50 | @Override
51 | protected void onCreate(Bundle savedInstanceState) {
52 | super.onCreate(savedInstanceState);
53 | setContentView(R.layout.activity_nav_drawer);
54 |
55 | toolbar = (Toolbar) findViewById(R.id.toolbar);
56 | setSupportActionBar(toolbar);
57 |
58 | initNavigationDrawer();
59 |
60 | View header = navigationView.getHeaderView(0);
61 |
62 | mFullNameTextView = (TextView) header.findViewById(R.id.fullName);
63 | mEmailTextView = (TextView) header.findViewById(R.id.email);
64 | mProfileImageView = (CircleImageView) header.findViewById(R.id.profileImage);
65 |
66 | // create an object of sharedPreferenceManager and get stored user data
67 | sharedPrefManager = new SharedPrefManager(mContext);
68 | mUsername = sharedPrefManager.getName();
69 | mEmail = sharedPrefManager.getUserEmail();
70 | String uri = sharedPrefManager.getPhoto();
71 | Uri mPhotoUri = Uri.parse(uri);
72 |
73 | //Set data gotten from SharedPreference to the Navigation Header view
74 | mFullNameTextView.setText(mUsername);
75 | mEmailTextView.setText(mEmail);
76 |
77 | Picasso.with(mContext)
78 | .load(mPhotoUri)
79 | .placeholder(android.R.drawable.sym_def_app_icon)
80 | .error(android.R.drawable.sym_def_app_icon)
81 | .into(mProfileImageView);
82 |
83 | configureSignIn();
84 | }
85 |
86 | @Override
87 | public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
88 |
89 | }
90 |
91 | // Initialize and add Listener to NavigationDrawer
92 | public void initNavigationDrawer(){
93 |
94 | navigationView = (NavigationView) findViewById(R.id.navigation_view);
95 | navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
96 | @Override
97 | public boolean onNavigationItemSelected(MenuItem item) {
98 |
99 | int id = item.getItemId();
100 |
101 | switch (id){
102 | case R.id.freebie:
103 | Toast.makeText(getApplicationContext(),"Home",Toast.LENGTH_SHORT).show();
104 | drawerLayout.closeDrawers();
105 | break;
106 | case R.id.payment:
107 | Toast.makeText(getApplicationContext(),"Settings",Toast.LENGTH_SHORT).show();
108 | drawerLayout.closeDrawers();
109 | break;
110 | case R.id.trip:
111 | Toast.makeText(getApplicationContext(),"Trash",Toast.LENGTH_SHORT).show();
112 | drawerLayout.closeDrawers();
113 | break;
114 | case R.id.logout:
115 | signOut();
116 | drawerLayout.closeDrawers();
117 | break;
118 | case R.id.tips:
119 | Toast.makeText(getApplicationContext(),"Trash",Toast.LENGTH_SHORT).show();
120 | drawerLayout.closeDrawers();
121 | break;
122 | }
123 | return false;
124 | }
125 | });
126 |
127 | //set up navigation drawer
128 | drawerLayout = (DrawerLayout) findViewById(R.id.drawer);
129 | ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this,drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close){
130 | @Override
131 | public void onDrawerClosed(View drawerView) {
132 | super.onDrawerClosed(drawerView);
133 | }
134 |
135 | @Override
136 | public void onDrawerOpened(View drawerView) {
137 | super.onDrawerOpened(drawerView);
138 | }
139 | };
140 | drawerLayout.addDrawerListener(actionBarDrawerToggle);
141 | actionBarDrawerToggle.syncState();
142 | }
143 |
144 | // This method configures Google SignIn
145 | public void configureSignIn(){
146 | // Configure sign-in to request the user's basic profile like name and email
147 | GoogleSignInOptions options = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
148 | .requestEmail()
149 | .build();
150 |
151 | // Build a GoogleApiClient with access to GoogleSignIn.API and the options above.
152 | mGoogleApiClient = new GoogleApiClient.Builder(mContext)
153 | .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
154 | .addApi(Auth.GOOGLE_SIGN_IN_API, options)
155 | .build();
156 | mGoogleApiClient.connect();
157 | }
158 |
159 | //method to logout
160 | private void signOut(){
161 | new SharedPrefManager(mContext).clear();
162 | mAuth.signOut();
163 |
164 | Auth.GoogleSignInApi.revokeAccess(mGoogleApiClient).setResultCallback(
165 | new ResultCallback() {
166 | @Override
167 | public void onResult(@NonNull Status status) {
168 | Intent intent = new Intent(NavDrawerActivity.this, MainActivity.class);
169 | startActivity(intent);
170 | }
171 | }
172 | );
173 | }
174 | }
175 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tutorial/authentication/model/User.java:
--------------------------------------------------------------------------------
1 | package com.tutorial.authentication.model;
2 |
3 | import java.util.HashMap;
4 |
5 | /**
6 | * Created by Gino Osahon on 04/03/2017.
7 | */
8 |
9 | public class User {
10 |
11 | private String fullName;
12 | private String photo;
13 | private String email;
14 | private HashMap timestampJoined;
15 |
16 | public User() {
17 | }
18 |
19 | /**
20 | * Use this constructor to create new User.
21 | * Takes user name, email and timestampJoined as params
22 | *
23 | * @param timestampJoined
24 | */
25 | public User(String mFullName, String mPhoneNo, String mEmail, HashMap timestampJoined) {
26 | this.fullName = mFullName;
27 | this.photo = mPhoneNo;
28 | this.email = mEmail;
29 | this.timestampJoined = timestampJoined;
30 | }
31 |
32 |
33 | public String getFullName() {
34 | return fullName;
35 | }
36 |
37 | public String getPhoto() {
38 | return photo;
39 | }
40 |
41 | public String getEmail() {
42 | return email;
43 | }
44 |
45 | public HashMap getTimestampJoined() {
46 | return timestampJoined;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tutorial/authentication/utils/Constants.java:
--------------------------------------------------------------------------------
1 | package com.tutorial.authentication.utils;
2 |
3 | /**
4 | * Created by Gino Osahon on 04/03/2017.
5 | */
6 | public class Constants {
7 |
8 | public static final String FIREBASE_URL = "INCLUDE YOUR FIREBASE URL HERE";
9 | public static final String FIREBASE_LOCATION_USERS = "users";
10 | public static final String FIREBASE_URL_USERS = FIREBASE_URL + "/" + FIREBASE_LOCATION_USERS;
11 | public static final String FIREBASE_PROPERTY_TIMESTAMP = "timestamp";
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tutorial/authentication/utils/SharedPrefManager.java:
--------------------------------------------------------------------------------
1 | package com.tutorial.authentication.utils;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 |
6 | /**
7 | * Created by Gino Osahon on 04/03/2017.
8 | */
9 | public class SharedPrefManager {
10 |
11 | SharedPreferences sharedPreferences;
12 | Context mContext;
13 | // shared pref mode
14 | int PRIVATE_MODE = 0;
15 | // Shared preferences file name
16 | private static final String PREF_NAME = "sessionPref";
17 | SharedPreferences.Editor editor;
18 |
19 | public SharedPrefManager (Context context) {
20 | mContext = context;
21 | sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
22 | editor = sharedPreferences.edit();
23 | }
24 |
25 |
26 | public void saveIsLoggedIn(Context context, Boolean isLoggedIn){
27 | mContext = context;
28 | sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
29 | SharedPreferences.Editor editor = sharedPreferences.edit();
30 | editor.putBoolean ("IS_LOGGED_IN", isLoggedIn);
31 | editor.commit();
32 |
33 | }
34 |
35 | public boolean getISLogged_IN() {
36 | //mContext = context;
37 | sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
38 | return sharedPreferences.getBoolean("IS_LOGGED_IN", false);
39 | }
40 |
41 | public void saveToken(Context context, String toke){
42 | mContext = context;
43 | sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
44 | SharedPreferences.Editor editor = sharedPreferences.edit();
45 | editor.putString("ID_TOKEN", toke);
46 | editor.commit();
47 | }
48 |
49 | public String getUserToken(){
50 | //mContext = context;
51 | sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
52 | return sharedPreferences.getString("ID_TOKEN", "");
53 | }
54 |
55 | public void saveEmail(Context context, String email){
56 | mContext = context;
57 | sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
58 | SharedPreferences.Editor editor = sharedPreferences.edit();
59 | editor.putString("EMAIL", email);
60 | editor.commit();
61 | }
62 |
63 | public String getUserEmail(){
64 | sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
65 | return sharedPreferences.getString("EMAIL", null);
66 | }
67 |
68 |
69 | public void saveName(Context context, String name){
70 | mContext = context;
71 | sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
72 | SharedPreferences.Editor editor = sharedPreferences.edit();
73 | editor.putString("NAME", name);
74 | editor.commit();
75 | }
76 |
77 | public String getName(){
78 | sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
79 | return sharedPreferences.getString("NAME", null);
80 | }
81 |
82 | public void savePhoto(Context context, String photo){
83 | mContext = context;
84 | sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
85 | SharedPreferences.Editor editor = sharedPreferences.edit();
86 | editor.putString("PHOTO", photo);
87 | editor.commit();
88 | }
89 |
90 | public String getPhoto(){
91 | sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
92 | return sharedPreferences.getString("PHOTO", null);
93 | }
94 |
95 | public void clear(){
96 | editor.clear();
97 | editor.apply();
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tutorial/authentication/utils/Utils.java:
--------------------------------------------------------------------------------
1 | package com.tutorial.authentication.utils;
2 |
3 | import android.content.Context;
4 | import android.net.ConnectivityManager;
5 | import android.net.NetworkInfo;
6 |
7 | /**
8 | * Created by Gino Osahon on 04/03/2017.
9 | */
10 | public class Utils {
11 |
12 | private Context mContext = null;
13 |
14 | /**
15 | * Public constructor that takes mContext for later use
16 | */
17 | public Utils(Context con) {
18 | mContext = con;
19 | }
20 |
21 | /**
22 | * Encode user email to use it as a Firebase key (Firebase does not allow "." in the key name)
23 | * Encoded email is also used as "userEmail", list and item "owner" value
24 | */
25 | public static String encodeEmail(String userEmail) {
26 | return userEmail.replace(".", ",");
27 | }
28 |
29 | //This is a method to Check if the device internet connection is currently on
30 | public boolean isNetworkAvailable() {
31 |
32 | ConnectivityManager connectivityManager
33 |
34 | = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
35 |
36 | NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
37 |
38 | return activeNetworkInfo != null && activeNetworkInfo.isConnected();
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_android_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_build_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_forward_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_invert_colors_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_base.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_nav_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
17 |
18 |
22 |
23 |
29 |
30 |
31 |
32 |
33 |
34 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/nav_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
19 |
20 |
28 |
29 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_navigation.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ginowine/android-firebase-authentication/5a3cedc29d4efba74cdec1f347b5654f659a800e/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ginowine/android-firebase-authentication/5a3cedc29d4efba74cdec1f347b5654f659a800e/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ginowine/android-firebase-authentication/5a3cedc29d4efba74cdec1f347b5654f659a800e/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ginowine/android-firebase-authentication/5a3cedc29d4efba74cdec1f347b5654f659a800e/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ginowine/android-firebase-authentication/5a3cedc29d4efba74cdec1f347b5654f659a800e/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #FFFFFF
7 | #0D47A1
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 10dp
6 | 160dp
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Firebase Authentication
3 | Loading…
4 | "Error occurred: "
5 | Open
6 | Close
7 |
8 | Include your web client id here
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
15 |
16 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/test/java/com/tutorial/authentication/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.tutorial.authentication;
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.2'
9 | classpath 'com.google.gms:google-services:3.0.0'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | }
20 | }
21 |
22 | task clean(type: Delete) {
23 | delete rootProject.buildDir
24 | }
25 |
--------------------------------------------------------------------------------
/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/Ginowine/android-firebase-authentication/5a3cedc29d4efba74cdec1f347b5654f659a800e/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.10-all.zip
7 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------