| Line 1... |
Line 1... |
| 1 |
package com.saholic.profittill.main;
|
1 |
package com.saholic.profittill.main;
|
| 2 |
|
2 |
|
| 3 |
import android.Manifest;
|
3 |
import android.Manifest;
|
| - |
|
4 |
import android.annotation.SuppressLint;
|
| 4 |
import android.app.AlertDialog;
|
5 |
import android.app.AlertDialog;
|
| 5 |
import android.app.FragmentManager;
|
6 |
import android.app.FragmentManager;
|
| 6 |
import android.app.ProgressDialog;
|
7 |
import android.app.ProgressDialog;
|
| 7 |
import android.content.Context;
|
8 |
import android.content.Context;
|
| 8 |
import android.content.DialogInterface;
|
9 |
import android.content.DialogInterface;
|
| Line 16... |
Line 17... |
| 16 |
import android.os.AsyncTask;
|
17 |
import android.os.AsyncTask;
|
| 17 |
import android.os.Build;
|
18 |
import android.os.Build;
|
| 18 |
import android.os.Bundle;
|
19 |
import android.os.Bundle;
|
| 19 |
import android.support.v4.app.ActivityCompat;
|
20 |
import android.support.v4.app.ActivityCompat;
|
| 20 |
import android.support.v4.content.ContextCompat;
|
21 |
import android.support.v4.content.ContextCompat;
|
| - |
|
22 |
|
| 21 |
import android.support.v7.app.ActionBarActivity;
|
23 |
import android.support.v7.app.AppCompatActivity;
|
| 22 |
import android.telephony.TelephonyManager;
|
24 |
import android.telephony.TelephonyManager;
|
| 23 |
import android.text.TextUtils;
|
25 |
import android.text.TextUtils;
|
| 24 |
import android.util.Log;
|
26 |
import android.util.Log;
|
| 25 |
import android.view.Menu;
|
27 |
import android.view.Menu;
|
| 26 |
import android.view.MenuItem;
|
28 |
import android.view.MenuItem;
|
| Line 65... |
Line 67... |
| 65 |
import java.io.UnsupportedEncodingException;
|
67 |
import java.io.UnsupportedEncodingException;
|
| 66 |
import java.net.URL;
|
68 |
import java.net.URL;
|
| 67 |
import java.util.ArrayList;
|
69 |
import java.util.ArrayList;
|
| 68 |
import java.util.Date;
|
70 |
import java.util.Date;
|
| 69 |
|
71 |
|
| 70 |
public class LoginActivity extends ActionBarActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{
|
72 |
public class LoginActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{
|
| 71 |
public GoogleApiClient mGoogleApiClient;
|
73 |
public GoogleApiClient mGoogleApiClient;
|
| 72 |
String scope = "oauth2:" + Scopes.PLUS_LOGIN +" " +Scopes.PLUS_ME + " " + Scopes.EMAIL;
|
74 |
String scope = "oauth2:" + Scopes.PLUS_LOGIN +" " +Scopes.PLUS_ME + " " + Scopes.EMAIL;
|
| 73 |
private boolean mIntentInProgress;
|
75 |
private boolean mIntentInProgress;
|
| 74 |
private boolean mSignInClicked;
|
76 |
private boolean mSignInClicked;
|
| 75 |
private ConnectionResult mConnectionResult;
|
77 |
private ConnectionResult mConnectionResult;
|
| 76 |
private static final int RC_SIGN_IN = 0;
|
78 |
private static final int RC_SIGN_IN = 0;
|
| 77 |
public static final int REQUEST_CODE_TOKEN_AUTH =1;
|
79 |
public static final int REQUEST_CODE_TOKEN_AUTH =1;
|
| - |
|
80 |
|
| 78 |
ArrayList<NameValuePair> nameValuePairsGcm;
|
81 |
ArrayList<NameValuePair> nameValuePairsGcm;
|
| 79 |
SharedPreferences userData;
|
82 |
SharedPreferences userData;
|
| 80 |
SharedPreferences apiData;
|
83 |
SharedPreferences apiData;
|
| 81 |
SharedPreferences.Editor inviteDataEditor;
|
84 |
SharedPreferences.Editor inviteDataEditor;
|
| 82 |
SharedPreferences inviteData;
|
85 |
SharedPreferences inviteData;
|
| Line 363... |
Line 366... |
| 363 |
@Override
|
366 |
@Override
|
| 364 |
protected String doInBackground(String... params) {
|
367 |
protected String doInBackground(String... params) {
|
| 365 |
String registered=null;
|
368 |
String registered=null;
|
| 366 |
String googletoken = null;
|
369 |
String googletoken = null;
|
| 367 |
Bundle appActivities = new Bundle();
|
370 |
Bundle appActivities = new Bundle();
|
| 368 |
appActivities.putString(GoogleAuthUtil.KEY_REQUEST_VISIBLE_ACTIVITIES,"MainActivity");
|
371 |
// appActivities.putString(GoogleAuthUtil.,"MainActivity");
|
| 369 |
try {
|
372 |
try {
|
| 370 |
googletoken = GoogleAuthUtil.getToken(
|
373 |
googletoken = GoogleAuthUtil.getToken(
|
| 371 |
LoginActivity.this,
|
374 |
LoginActivity.this,
|
| 372 |
Plus.AccountApi.getAccountName(mGoogleApiClient),
|
375 |
Plus.AccountApi.getAccountName(mGoogleApiClient),
|
| 373 |
scope,appActivities);
|
376 |
scope,appActivities);
|
| Line 377... |
Line 380... |
| 377 |
JSONObject jsonObject = new JSONObject();
|
380 |
JSONObject jsonObject = new JSONObject();
|
| 378 |
jsonObject.put("type", "GOOGLE");
|
381 |
jsonObject.put("type", "GOOGLE");
|
| 379 |
jsonObject.put("token", googletoken);
|
382 |
jsonObject.put("token", googletoken);
|
| 380 |
json = jsonObject.toString();
|
383 |
json = jsonObject.toString();
|
| 381 |
HttpPost httppost = new HttpPost(apiData.getString("Web_Api_Login","http://app.profitmandi.com/apis/user/googleLogin"));
|
384 |
HttpPost httppost = new HttpPost(apiData.getString("Web_Api_Login","http://app.profitmandi.com/apis/user/googleLogin"));
|
| - |
|
385 |
|
| - |
|
386 |
// HttpPost httppost = new HttpPost("http://192.168.120.52:8080/profitmandi-web/user/googleLogin");
|
| 382 |
StringEntity se = new StringEntity(json);
|
387 |
StringEntity se = new StringEntity(json);
|
| 383 |
httppost.setEntity(se);
|
388 |
httppost.setEntity(se);
|
| 384 |
httppost.setHeader("Content-type", "application/json");
|
389 |
httppost.setHeader("Content-type", "application/json");
|
| 385 |
HttpResponse response = httpclient.execute(httppost);
|
390 |
HttpResponse response = httpclient.execute(httppost);
|
| 386 |
HttpEntity entity = response.getEntity();
|
391 |
HttpEntity entity = response.getEntity();
|
| Line 459... |
Line 464... |
| 459 |
@Override
|
464 |
@Override
|
| 460 |
protected String doInBackground(String... params) {
|
465 |
protected String doInBackground(String... params) {
|
| 461 |
try {
|
466 |
try {
|
| 462 |
HttpClient httpclient = new DefaultHttpClient();
|
467 |
HttpClient httpclient = new DefaultHttpClient();
|
| 463 |
HttpGet httpget = new HttpGet(apiData.getString("Web_Api_Tokendetail","http://app.profitmandi.com/apis/user/detail/token"));
|
468 |
HttpGet httpget = new HttpGet(apiData.getString("Web_Api_Tokendetail","http://app.profitmandi.com/apis/user/detail/token"));
|
| 464 |
//HttpGet httpget = new HttpGet(ProfitTillConstants.Web_Api + "/user/token-info");
|
469 |
//HttpGet httpget = new HttpGet("http://192.168.120.52:8080/profitmandi-web/user/detail/token");
|
| 465 |
httpget.setHeader("Auth-Token", userData.getString("token", ""));
|
470 |
httpget.setHeader("Auth-Token", userData.getString("token", ""));
|
| 466 |
HttpResponse response = httpclient.execute(httpget);
|
471 |
HttpResponse response = httpclient.execute(httpget);
|
| 467 |
HttpEntity entity = response.getEntity();
|
472 |
HttpEntity entity = response.getEntity();
|
| 468 |
int status = response.getStatusLine().getStatusCode();
|
473 |
int status = response.getStatusLine().getStatusCode();
|
| 469 |
JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
|
474 |
JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
|
| Line 520... |
Line 525... |
| 520 |
}
|
525 |
}
|
| 521 |
boolean doubleBackToExitPressedOnce = false;
|
526 |
boolean doubleBackToExitPressedOnce = false;
|
| 522 |
@Override
|
527 |
@Override
|
| 523 |
public void onBackPressed() {
|
528 |
public void onBackPressed() {
|
| 524 |
new AlertDialog.Builder(this)
|
529 |
new AlertDialog.Builder(this)
|
| 525 |
.setIcon(R.drawable.symbol)
|
530 |
.setIcon(R.drawable.exitsymbol)
|
| 526 |
.setTitle("Exit!")
|
531 |
.setTitle("Exit!")
|
| 527 |
.setMessage("Are you sure you want to close?")
|
532 |
.setMessage("Are you sure you want to close?")
|
| 528 |
.setPositiveButton("Yes", new DialogInterface.OnClickListener()
|
533 |
.setPositiveButton("Yes", new DialogInterface.OnClickListener()
|
| 529 |
{
|
534 |
{
|
| 530 |
@Override
|
535 |
@Override
|
| Line 602... |
Line 607... |
| 602 |
.setAction("Login Successful")
|
607 |
.setAction("Login Successful")
|
| 603 |
.setLabel("Successful for User" +userData.getString("id",null))
|
608 |
.setLabel("Successful for User" +userData.getString("id",null))
|
| 604 |
.build());
|
609 |
.build());
|
| 605 |
}
|
610 |
}
|
| 606 |
|
611 |
|
| - |
|
612 |
@SuppressLint("MissingPermission")
|
| 607 |
@Override
|
613 |
@Override
|
| 608 |
protected String doInBackground(String... arg0) {
|
614 |
protected String doInBackground(String... arg0) {
|
| 609 |
String id=null;
|
615 |
String id=null;
|
| 610 |
try {
|
616 |
try {
|
| 611 |
HttpClient httpclient = new DefaultHttpClient();
|
617 |
HttpClient httpclient = new DefaultHttpClient();
|
| Line 752... |
Line 758... |
| 752 |
@Override
|
758 |
@Override
|
| 753 |
protected String doInBackground(ArrayList<NameValuePair>... arg0) {
|
759 |
protected String doInBackground(ArrayList<NameValuePair>... arg0) {
|
| 754 |
try {
|
760 |
try {
|
| 755 |
HttpClient httpclient = new DefaultHttpClient();
|
761 |
HttpClient httpclient = new DefaultHttpClient();
|
| 756 |
HttpPost httppost = new HttpPost(apiData.getString("devices_info","http://api.profittill.com/devices/add"));
|
762 |
HttpPost httppost = new HttpPost(apiData.getString("devices_info","http://api.profittill.com/devices/add"));
|
| - |
|
763 |
// HttpPost httppost = new HttpPost("http://192.168.120.52:8080/profitmandi-web/devices/add");
|
| 757 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
764 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
| 758 |
httppost.setEntity(new UrlEncodedFormEntity(arg0[0]));
|
765 |
httppost.setEntity(new UrlEncodedFormEntity(arg0[0]));
|
| 759 |
HttpResponse response = httpclient.execute(httppost);
|
766 |
HttpResponse response = httpclient.execute(httppost);
|
| 760 |
HttpEntity entity = response.getEntity();
|
767 |
HttpEntity entity = response.getEntity();
|
| 761 |
int status = response.getStatusLine().getStatusCode();
|
768 |
int status = response.getStatusLine().getStatusCode();
|