Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
14792 manas 1
package com.saholic.profittill.main;
2
 
3
import android.app.AlertDialog;
4
import android.app.ProgressDialog;
5
import android.content.Context;
6
import android.content.DialogInterface;
7
import android.content.Intent;
8
import android.content.SharedPreferences;
9
import android.graphics.Color;
10
import android.net.ConnectivityManager;
11
import android.net.Uri;
12
import android.os.AsyncTask;
15356 manas 13
import android.os.Bundle;
14792 manas 14
import android.support.v7.app.ActionBarActivity;
15
import android.text.InputType;
16
import android.util.Log;
17
import android.view.KeyEvent;
18
import android.view.Menu;
19
import android.view.MenuItem;
20
import android.view.View;
21
import android.view.inputmethod.InputMethodManager;
22
import android.widget.Button;
23
import android.widget.EditText;
24
import android.widget.TextView;
25
import android.widget.Toast;
26
 
27
import com.facebook.Session;
28
import com.google.android.gms.analytics.HitBuilders;
29
import com.google.android.gms.analytics.Tracker;
30
import com.google.android.gms.common.ConnectionResult;
31
import com.google.android.gms.common.api.GoogleApiClient;
32
import com.google.android.gms.plus.Plus;
33
import com.mixpanel.android.mpmetrics.MixpanelAPI;
34
import com.saholic.profittill.Constants.ProfitTillConstants;
35
import com.saholic.profittill.R;
16278 manas 36
import com.saholic.profittill.Utils.AnalyticsUtility;
15356 manas 37
import com.saholic.profittill.Utils.UtilityFunctions;
16278 manas 38
import com.saholic.profittill.Volley.Analytics;
39
import com.saholic.profittill.Volley.AnalyticsErrorResponse;
40
import com.saholic.profittill.Volley.AnalyticsJsonResponse;
14792 manas 41
 
42
import org.apache.http.HttpEntity;
43
import org.apache.http.HttpResponse;
44
import org.apache.http.NameValuePair;
45
import org.apache.http.client.ClientProtocolException;
46
import org.apache.http.client.HttpClient;
47
import org.apache.http.client.entity.UrlEncodedFormEntity;
48
import org.apache.http.client.methods.HttpPost;
49
import org.apache.http.impl.client.DefaultHttpClient;
50
import org.apache.http.message.BasicNameValuePair;
51
import org.apache.http.util.EntityUtils;
52
import org.json.JSONException;
53
import org.json.JSONObject;
54
 
55
import java.io.IOException;
56
import java.text.SimpleDateFormat;
57
import java.util.ArrayList;
58
import java.util.Date;
59
 
60
public class ReferrerActivity extends ActionBarActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
61
    EditText referalCode;
62
    EditText mobileNumber;
16278 manas 63
    MixpanelAPI mixpanel;
14792 manas 64
    TextView inviteMessage,inviteMessage1,inviteNumber,giveus,thanks,incorrect;
65
    Button referrerSend,mobileNumberSend;
66
    String type1;
67
    String invitationCode;
68
    SharedPreferences userData;
69
    SharedPreferences apiData;
70
    SharedPreferences.Editor userDataEditor;
71
    SharedPreferences.Editor apiSettingsEditor;
72
    SharedPreferences inviteD;
73
    SharedPreferences.Editor inviteDEditor;
74
    ArrayList<NameValuePair> nameValuePairsGcm;
75
    public GoogleApiClient mGoogleApiClient;
76
    boolean glogout;
77
    final ArrayList<String> invitationCodeList = new ArrayList<String>();
78
 
79
    boolean FLAG=false;
80
    ArrayList<NameValuePair> nameValuePairs;
81
    @Override
82
    protected void onCreate(Bundle savedInstanceState) {
83
        super.onCreate(savedInstanceState);
84
        setContentView(R.layout.activity_referrer);
85
        getSupportActionBar().hide();
86
 
87
        userData = getApplicationContext().getSharedPreferences("User_Data", MODE_PRIVATE);
88
        apiData = getApplicationContext().getSharedPreferences("API_Data", MODE_PRIVATE);
89
        userDataEditor = userData.edit();
90
        apiSettingsEditor = apiData.edit();
91
        inviteD = getApplicationContext().getSharedPreferences("Invite", MODE_PRIVATE);
92
        inviteDEditor = inviteD.edit();
93
 
94
        inviteMessage=(TextView)findViewById(R.id.inviteMessage);
95
        inviteMessage1=(TextView)findViewById(R.id.inviteMessage1);
96
        inviteNumber=(TextView)findViewById(R.id.inviteNumber);
97
        giveus=(TextView)findViewById(R.id.giveus);
98
        thanks=(TextView)findViewById(R.id.thanks);
99
        incorrect=(TextView)findViewById(R.id.incorrect);
100
 
101
        referalCode=(EditText)findViewById(R.id.referralCode);
102
        mobileNumber=(EditText)findViewById(R.id.mobileNumberReferrer);
103
        referrerSend =(Button)findViewById(R.id.referrerSend);
104
        mobileNumberSend =(Button)findViewById(R.id.mobileNumberReferrerSend);
105
        mixpanel= MixpanelAPI.getInstance(getApplicationContext(), ProfitTillConstants.MIX_PANEL_TOKEN);
106
        inviteMessage.setText(apiData.getString("referralinvite.text", "Got your Invite Code?"));
107
        inviteMessage1.setText(apiData.getString("no.referralinvite", "Haven't got the code..."));
108
        giveus.setText(apiData.getString("referralMobileNumber.text","Leave ur no & we'll get back to you"));
109
        inviteNumber.setVisibility(View.VISIBLE);
110
        inviteNumber.setText("Call " + apiData.getString("contactus.number", "") + " now");
16278 manas 111
 
112
        Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
113
                GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
114
        t.setScreenName("Referrer Screen");
115
        t.send(new HitBuilders.ScreenViewBuilder().build());
116
        new Analytics(ProfitTillConstants.ANALYTICS_URL,
117
                AnalyticsUtility.getAnalyticsRequest(ReferrerActivity.this, userData.getString("id", ""), "Screen", "Referrer", "Referrer Screen"),
118
                AnalyticsJsonResponse.getAnalyticsRequestInstance(),
119
                AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(ReferrerActivity.this);
120
 
14792 manas 121
        referalCode.setInputType(0);
122
        mobileNumber.setInputType(0);
123
        if(getIntent().getAction()=="Login"){
16310 manas 124
            new Analytics(ProfitTillConstants.ANALYTICS_URL,
125
                    AnalyticsUtility.getAnalyticsRequest(ReferrerActivity.this,userData.getString("id",""),"Notification","Notification Opened Referrer",getIntent().getExtras().getString("cid")),
126
                    AnalyticsJsonResponse.getAnalyticsRequestInstance(),
127
                    AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(ReferrerActivity.this);
128
 
14792 manas 129
            nameValuePairsGcm = new ArrayList<>();
130
            nameValuePairsGcm.add(new BasicNameValuePair("cid",getIntent().getExtras().getString("cid")));
131
            nameValuePairsGcm.add(new BasicNameValuePair("user_id",userData.getString("id", "")));
15356 manas 132
            nameValuePairsGcm.add(new BasicNameValuePair("timestamp", UtilityFunctions.notificationDate()));
14792 manas 133
            nameValuePairsGcm.add(new BasicNameValuePair("result","referrer"));
134
            getIntent().getExtras().remove("cid");
135
            new NotificationOpenedData().execute(nameValuePairsGcm);
136
        }
137
 
138
        referalCode.setOnClickListener(new View.OnClickListener() {
139
            @Override
140
            public void onClick(View v) {
141
                InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
142
                inputMethodManager.showSoftInput(referalCode, InputMethodManager.SHOW_IMPLICIT);
143
                referalCode.requestFocus();
144
            }
145
        });
146
        mobileNumber.setOnClickListener(new View.OnClickListener() {
147
            @Override
148
            public void onClick(View v) {
149
                mobileNumber.setInputType(InputType.TYPE_CLASS_PHONE);
150
            }
151
        });
152
        inviteNumber.setOnClickListener(new View.OnClickListener() {
153
            @Override
154
            public void onClick(View v) {
16278 manas 155
                new Analytics(ProfitTillConstants.ANALYTICS_URL,
156
                        AnalyticsUtility.getAnalyticsRequest(ReferrerActivity.this, userData.getString("id", ""), "Clicks", "Referrer", "Call to get Invite Code"),
157
                        AnalyticsJsonResponse.getAnalyticsRequestInstance(),
158
                        AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(ReferrerActivity.this);
14792 manas 159
                Intent callIntent = new Intent(Intent.ACTION_CALL);
160
                callIntent.setData(Uri.parse("tel:0" + apiData.getString("contactus.number", "")));
161
                startActivity(callIntent);
162
            }
163
        });
164
 
165
        JSONObject props = new JSONObject();
166
        try {
167
            props.put("Referrer", "Referrer Screen");
168
            mixpanel.track("Referrer Screen", props);
169
        } catch (JSONException e) {
170
 
171
            e.printStackTrace();
172
        }
173
        type1 = userData.getString("type",null);
174
 
175
        if(type1!=null && type1.equalsIgnoreCase("google")) {
176
            mGoogleApiClient = new GoogleApiClient.Builder(this)
177
                    .addConnectionCallbacks(this)
178
                    .addOnConnectionFailedListener(this).addApi(Plus.API)
179
                    .addScope(Plus.SCOPE_PLUS_LOGIN).build();
180
            mGoogleApiClient.connect();
181
        }
182
        referalCode.setOnKeyListener(new View.OnKeyListener() {
183
            @Override
184
            public boolean onKey(View v, int keyCode, KeyEvent event) {
185
                if (event.getAction() == KeyEvent.ACTION_DOWN)
186
                {
187
                    switch (keyCode)
188
                    {
189
                        case KeyEvent.KEYCODE_DPAD_CENTER:
190
 
191
                        case KeyEvent.KEYCODE_ENTER:
192
 
193
                            if(referalCode.getText().toString().equalsIgnoreCase("")) {
194
                                incorrect.setVisibility(View.VISIBLE);
195
                                incorrect.setText(apiData.getString("incorrect.referralinvite","Incorrect Code"));
196
                                incorrect.setTextColor(Color.RED);
197
                                referalCode.setHint("Retry");
198
                                InputMethodManager imm = (InputMethodManager)getSystemService(
199
                                        Context.INPUT_METHOD_SERVICE);
200
                                imm.hideSoftInputFromWindow(referalCode.getWindowToken(), 0);
201
                            }
202
                            else{
203
                                if(isInternetOn()) {
204
                                    InputMethodManager imm = (InputMethodManager)getSystemService(
205
                                            Context.INPUT_METHOD_SERVICE);
206
                                    imm.hideSoftInputFromWindow(referalCode.getWindowToken(), 0);
16278 manas 207
 
14792 manas 208
                                    new PushReferrerData().execute(referalCode.getText().toString());
209
                                }else{
210
                                    InputMethodManager imm = (InputMethodManager)getSystemService(
211
                                            Context.INPUT_METHOD_SERVICE);
212
                                    imm.hideSoftInputFromWindow(referalCode.getWindowToken(), 0);
213
                                    Toast.makeText(getApplicationContext(), "No internet connection. Please try again.", Toast.LENGTH_SHORT).show();
214
                                }
215
                            }
216
                            return true;
217
 
218
                        default:
219
                            break;
220
                    }
221
                }
222
                return false;
223
            }
224
 
225
 
226
        });
227
 
228
        mobileNumber.setOnKeyListener(new View.OnKeyListener() {
229
            @Override
230
            public boolean onKey(View v, int keyCode, KeyEvent event) {
231
                if (event.getAction() == KeyEvent.ACTION_DOWN)
232
                {
233
                    switch (keyCode)
234
                    {
235
                        case KeyEvent.KEYCODE_DPAD_CENTER:
236
 
237
                        case KeyEvent.KEYCODE_ENTER:
238
                            if(mobileNumber.getText().toString().length()==10){
239
                                if(isInternetOn()) {
240
                                    incorrect.setVisibility(View.GONE);
241
                                    referalCode.setHint("Enter Invite Code");
242
                                    InputMethodManager imm = (InputMethodManager)getSystemService(
243
                                            Context.INPUT_METHOD_SERVICE);
244
                                    imm.hideSoftInputFromWindow(mobileNumber.getWindowToken(), 0);
245
                                    new pushVerification().execute();
246
                                }else{
247
                                    InputMethodManager imm = (InputMethodManager)getSystemService(
248
                                            Context.INPUT_METHOD_SERVICE);
249
                                    imm.hideSoftInputFromWindow(mobileNumber.getWindowToken(), 0);
250
                                    Toast.makeText(getApplicationContext(), "No internet connection. Please try again.", Toast.LENGTH_SHORT).show();
251
                                }
252
 
253
                            }
254
                            else{
255
                                InputMethodManager imm = (InputMethodManager)getSystemService(
256
                                        Context.INPUT_METHOD_SERVICE);
257
                                imm.hideSoftInputFromWindow(mobileNumber.getWindowToken(), 0);
258
                                Toast.makeText(getApplicationContext(), "Mobile Number not valid.", Toast.LENGTH_SHORT).show();
259
                            }
260
                            return true;
261
 
262
                        default:
263
                            break;
264
                    }
265
                }
266
                return false;
267
            }
268
 
269
 
270
        });
271
 
272
        referrerSend.setOnClickListener(new View.OnClickListener() {
273
            @Override
274
            public void onClick(View v) {
275
 
276
 
277
                if(referalCode.getText().toString().equalsIgnoreCase("")) {
278
                    incorrect.setVisibility(View.VISIBLE);
279
                    incorrect.setText(apiData.getString("incorrect.referralinvite","Incorrect Code"));
280
                    incorrect.setTextColor(Color.RED);
281
                    referalCode.setHint("Retry");
282
                    InputMethodManager imm = (InputMethodManager)getSystemService(
283
                            Context.INPUT_METHOD_SERVICE);
284
                    imm.hideSoftInputFromWindow(referalCode.getWindowToken(), 0);
285
                }
286
                else{
287
                    if(isInternetOn()) {
288
                        InputMethodManager imm = (InputMethodManager)getSystemService(
289
                                Context.INPUT_METHOD_SERVICE);
290
                        imm.hideSoftInputFromWindow(referalCode.getWindowToken(), 0);
291
                        new PushReferrerData().execute(referalCode.getText().toString());
292
                    }else{
293
                        InputMethodManager imm = (InputMethodManager)getSystemService(
294
                                Context.INPUT_METHOD_SERVICE);
295
                        imm.hideSoftInputFromWindow(referalCode.getWindowToken(), 0);
296
                        Toast.makeText(getApplicationContext(), "No internet connection. Please try again.", Toast.LENGTH_SHORT).show();
297
                    }
298
                }
299
            }
300
        });
301
 
302
        mobileNumberSend.setOnClickListener(new View.OnClickListener() {
303
            @Override
304
            public void onClick(View v) {
305
 
306
                if(mobileNumber.getText().toString().length()==10){
307
                    if(isInternetOn()) {
308
                        InputMethodManager imm = (InputMethodManager)getSystemService(
309
                                Context.INPUT_METHOD_SERVICE);
310
                        imm.hideSoftInputFromWindow(mobileNumber.getWindowToken(), 0);
311
                        incorrect.setVisibility(View.GONE);
312
                        referalCode.setHint("Enter Invite Code");
313
                        new pushVerification().execute();
314
                    }else{
315
                        InputMethodManager imm = (InputMethodManager)getSystemService(
316
                                Context.INPUT_METHOD_SERVICE);
317
                        imm.hideSoftInputFromWindow(mobileNumber.getWindowToken(), 0);
318
                        Toast.makeText(getApplicationContext(), "No internet connection. Please try again.", Toast.LENGTH_SHORT).show();
319
                    }
320
 
321
                }
322
                else{
323
                    InputMethodManager imm = (InputMethodManager)getSystemService(
324
                            Context.INPUT_METHOD_SERVICE);
325
                    imm.hideSoftInputFromWindow(mobileNumber.getWindowToken(), 0);
326
                    Toast.makeText(getApplicationContext(), "Mobile Number not valid.", Toast.LENGTH_SHORT).show();
327
                }
328
            }
329
        });
330
    }
331
 
332
 
333
    @Override
334
    public boolean onCreateOptionsMenu(Menu menu) {
335
        // Inflate the menu; this adds items to the action bar if it is present.
336
        getMenuInflater().inflate(R.menu.menu_referrer, menu);
337
        return true;
338
    }
339
 
340
    @Override
341
    public boolean onOptionsItemSelected(MenuItem item) {
342
        // Handle action bar item clicks here. The action bar will
343
        // automatically handle clicks on the Home/Up button, so long
344
        // as you specify a parent activity in AndroidManifest.xml.
345
        int id = item.getItemId();
346
 
347
        //noinspection SimplifiableIfStatement
348
        if (id == R.id.action_settings) {
349
            return true;
350
        }
351
 
352
        return super.onOptionsItemSelected(item);
353
    }
354
    @Override
355
    public void onConnected(Bundle bundle) {
356
 
357
    }
358
 
359
    @Override
360
    public void onConnectionSuspended(int i) {
361
 
362
    }
363
 
364
    @Override
365
    public void onConnectionFailed(ConnectionResult connectionResult) {
366
 
367
    }
368
 
369
    class PushReferrerData extends AsyncTask<String, Integer, String> {
370
 
371
        @Override
372
        protected void onPreExecute() {
373
            super.onPreExecute();
374
            referrerSend.setEnabled(false);
375
            referalCode.setInputType(0);
376
            mobileNumber.setInputType(0);
377
            pd2 = new ProgressDialog(ReferrerActivity.this);
378
            pd2.setMessage("Please wait...");
379
            pd2.setCancelable(false);
380
            pd2.show();
381
 
382
        }
383
 
384
        @Override
385
        protected String doInBackground(String... arg0) {
386
            String id=null;
387
            try {
388
                HttpClient httpclient = new DefaultHttpClient();
389
 
390
                nameValuePairs = new ArrayList<>();
391
                String updateURL = apiData.getString("useredit.url","");
392
                String url = updateURL+userData.getString("id","");
17059 manas 393
                nameValuePairs.add(new BasicNameValuePair("id",userData.getString("id",null)));
14792 manas 394
                nameValuePairs.add(new BasicNameValuePair("referrer",arg0[0]));
395
                HttpPost httppost = new HttpPost(url);
396
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
397
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
398
                HttpResponse response = httpclient.execute(httppost);
399
                HttpEntity entity = response.getEntity();
400
                int status = response.getStatusLine().getStatusCode();
401
                JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
402
                System.out.println("JSON Object in referrer " + jObjGmail.toString());
403
                String success = jObjGmail.getString("success");
404
                if(status == 200){
405
                    inviteDEditor.putString("referrerCode",arg0[0]);
406
                    inviteDEditor.commit();
407
                    Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
408
                            GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
409
                    t.send(new HitBuilders.EventBuilder()
410
                            .setCategory("Referrer ")
411
                            .setAction("Referrer Saved Successfully")
412
                            .setLabel("Referrer for User" +userData.getString("id",null) + " is " + arg0[0])
413
                            .build());
414
                }
415
                if(success.equalsIgnoreCase("true")){
416
                    MixpanelAPI mixpanel= MixpanelAPI.getInstance(getApplicationContext(), ProfitTillConstants.MIX_PANEL_TOKEN);
417
                    JSONObject props = new JSONObject();
418
                    try {
419
                        props.put("Referrer", "Referrer Saved Successfully");
420
                        mixpanel.track("Referrer Saved", props);
421
                    } catch (JSONException e) {
422
 
423
                        e.printStackTrace();
424
                    }
425
                    userDataEditor.putString("referralCodeRequired","false");;
426
                    userDataEditor.commit();
427
                    return "true";
428
                }else{
429
                    userDataEditor.putString("referralCodeRequired","true");;
430
                    userDataEditor.commit();
431
                    return "false";
432
                }
433
 
434
            } catch (Exception e) {
435
                Log.e("Fail 1", e.toString());
436
                return "false";
437
            }
438
        }
439
 
440
        @Override
441
        protected void onPostExecute(String result) {
442
            super.onPostExecute(result);
443
            pd2.dismiss();
444
            if(result.equalsIgnoreCase("true")) {
16278 manas 445
 
446
                new Analytics(ProfitTillConstants.ANALYTICS_URL,
447
                        AnalyticsUtility.getAnalyticsRequest(ReferrerActivity.this, userData.getString("id", ""), "Clicks", "Referrer", "Invite Code Entered"),
448
                        AnalyticsJsonResponse.getAnalyticsRequestInstance(),
449
                        AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(ReferrerActivity.this);
450
 
14792 manas 451
                if(userData.getString("message","false").equalsIgnoreCase("true")) {
452
                    Intent i = new Intent(ReferrerActivity.this, MobileNumber.class);
453
                    i.putExtra("displayView", "7");
454
                    startActivity(i);
455
                }else{
456
                    if(!(userData.getString("mobileNumber","").isEmpty())) {
457
                        Intent i = new Intent(ReferrerActivity.this, MobileVerificationFirstTime.class);
458
                        i.putExtra("numberVerification", userData.getString("mobileNumber",""));
459
                        startActivity(i);
460
                    }else{
461
                        Intent i = new Intent(ReferrerActivity.this, MainActivity.class);
462
                        i.putExtra("displayView", "7");
463
                        startActivity(i);
464
 
465
                    }
466
                }
467
            }else{
468
                referrerSend.setEnabled(true);
469
                incorrect.setVisibility(View.VISIBLE);
470
                incorrect.setText(apiData.getString("incorrect.referralinvite","Incorrect Code"));
471
                incorrect.setTextColor(Color.RED);
472
                referalCode.setHint("Retry");
473
            }
474
        }
475
    }
476
    class pushVerification extends AsyncTask<String, Integer, String> {
477
 
478
        @Override
479
        protected void onPreExecute() {
480
            super.onPreExecute();
481
            JSONObject props = new JSONObject();
482
            try {
483
                mixpanel.identify(userData.getString("id",null));
484
                props.put("Screen", "Mobile Entered Referrer");
485
                mixpanel.track("Mobile Number Entered Referrer",props);
486
            } catch (JSONException e) {
487
                e.printStackTrace();
488
            }
489
            referalCode.setInputType(0);
490
            mobileNumber.setInputType(0);
491
            pd2 = new ProgressDialog(ReferrerActivity.this);
492
            pd2.setMessage("Please wait...");
493
            pd2.setCancelable(false);
494
            pd2.show();
495
 
496
        }
497
 
498
        @Override
499
        protected String doInBackground(String... arg0) {
500
            HttpClient httpclient = new DefaultHttpClient();
501
            try {
502
 
503
                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
504
                SimpleDateFormat sdf = new SimpleDateFormat(ProfitTillConstants.SQL_DATE_FORMAT);
505
                String dateUpdated = sdf.format(new Date());
506
                nameValuePairs.add(new BasicNameValuePair("id",userData.getString("id","")));
507
                nameValuePairs.add(new BasicNameValuePair("mobile_number",mobileNumber.getText().toString()));
508
                nameValuePairs.add(new BasicNameValuePair("mobile_number_last_updated",dateUpdated));
509
                String updateURL = apiData.getString("useredit.url","");
510
                String url = updateURL+userData.getString("id","");
511
                HttpPost httppost = new HttpPost(url);
512
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
513
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
514
                HttpResponse response = httpclient.execute(httppost);
515
                HttpEntity entity = response.getEntity();
516
                int status = response.getStatusLine().getStatusCode();
517
                JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
518
                System.out.println("JSON Object in mobile " + jObjGmail.toString());
519
                String success = jObjGmail.getString("success");
520
 
521
                if(status == 200){
522
                    Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
523
                            GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
524
                    t.send(new HitBuilders.EventBuilder()
525
                            .setCategory("First Time Mobile Entered ")
526
                            .setAction("Number entered")
527
                            .setLabel("First Time Mobile entered")
528
                            .build());
16278 manas 529
                    new Analytics(ProfitTillConstants.ANALYTICS_URL,
530
                            AnalyticsUtility.getAnalyticsRequest(ReferrerActivity.this, userData.getString("id", ""), "Clicks", "Referrer", "Number Entered"),
531
                            AnalyticsJsonResponse.getAnalyticsRequestInstance(),
532
                            AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(ReferrerActivity.this);
14792 manas 533
                }
534
                if(success.equalsIgnoreCase("true")){
535
                    userDataEditor.putString("message","false");;
536
                    userDataEditor.putString("mobileNumber",mobileNumber.getText().toString());
537
                    userDataEditor.commit();
538
                    return "true";
539
                }else{
540
                    userDataEditor.putString("message","true");;
541
                    userDataEditor.commit();
542
                    return "false";
543
                }
544
            } catch (ClientProtocolException e) {
545
                return "false";
546
            } catch (IOException e) {
547
                return "false";
548
            }catch (Exception e){
549
                return "false";
550
            }
551
        }
552
 
553
        @Override
554
        protected void onPostExecute(String result) {
555
            super.onPostExecute(result);
556
            pd2.dismiss();
557
            thanks.setText(apiData.getString("thanks.referrer.message","Thanks and we will get back to you"));
558
            thanks.setVisibility(View.VISIBLE);
559
        }
560
    }
561
    ProgressDialog pd2;
562
    @Override
563
    public void onBackPressed() {
564
        new AlertDialog.Builder(this)
565
                .setIcon(android.R.drawable.ic_dialog_alert)
566
                .setTitle("Exit!")
567
                .setMessage("Are you sure you want to sign out?")
568
                .setPositiveButton("Yes", new DialogInterface.OnClickListener()
569
                {
570
                    @Override
571
                    public void onClick(DialogInterface dialog, int which) {
572
                        JSONObject props = new JSONObject();
573
                        try {
574
                            mixpanel.identify(userData.getString("id",null));
575
                            props.put("Screen", "Signing Out");
576
                            mixpanel.track("Signing Out Referrer",props);
577
                        } catch (JSONException e) {
578
                            e.printStackTrace();
579
                        }
580
 
581
                        if(type1.equalsIgnoreCase("facebook")) {
582
                            Log.d("fblogout","logout");
583
                            if (Session.getActiveSession() != null) {
584
                                Session.getActiveSession().closeAndClearTokenInformation();
585
                            }
586
                            Session.setActiveSession(null);
587
                            userDataEditor.clear().commit();
588
                            startActivity(new Intent(ReferrerActivity.this, LoginActivity.class));
589
                        }
590
                        else{
591
                            Log.d("gmailLogout","logout");
592
                            signOutFromGplus();
593
                            if(glogout==true){
594
                                startActivity(new Intent(ReferrerActivity.this, LoginActivity.class));
595
                            }
596
                        }
597
 
598
                    }
599
 
600
                })
601
                .setNegativeButton("No", null)
602
                .show();
603
    }
604
    public void signOutFromGplus() {
605
        if (mGoogleApiClient.isConnected()) {
606
            Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
607
            mGoogleApiClient.disconnect();
608
            mGoogleApiClient.connect();
609
            glogout=true;
610
            userDataEditor.clear().commit();
611
        } else {
612
            glogout=false;
613
        }
614
    }
615
 
616
    public final boolean isInternetOn() {
617
 
618
        ConnectivityManager connection =
619
                (ConnectivityManager)getSystemService(this.getBaseContext().CONNECTIVITY_SERVICE);
620
 
621
        if ( connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||
622
                connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||
623
                connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||
624
                connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED ) {
625
            return true;
626
 
627
        } else if (
628
                connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||
629
                        connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED  ) {
630
            return false;
631
        }
632
        return false;
633
    }
634
 
635
 
636
    class NotificationOpenedData extends AsyncTask<ArrayList<NameValuePair>, Integer, String> {
637
 
638
        @Override
639
        protected void onPreExecute() {
640
            super.onPreExecute();
641
 
642
        }
643
 
644
        @Override
645
        protected String doInBackground(ArrayList<NameValuePair>... arg0) {
646
 
647
            try {
648
                HttpClient httpclient = new DefaultHttpClient();
649
                HttpPost httppost = new HttpPost(apiData.getString("notication.data.url","http://api.profittill.com/pushnotifications/add"));
650
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
651
                httppost.setEntity(new UrlEncodedFormEntity(arg0[0]));
652
                HttpResponse response = httpclient.execute(httppost);
653
                HttpEntity entity = response.getEntity();
654
                int status = response.getStatusLine().getStatusCode();
655
 
656
                if(status == 200){
657
                    Log.d("Notification Opened","Notication opened and sent to server");
658
                    Log.d("ResponseCode GCM ",status+"");
659
                } else {
660
                    Log.d("ResponseCode GCM ",status+"");
661
                }
662
 
663
                nameValuePairsGcm.clear();
664
                Log.e("pass 1", "connection success ");
665
            } catch (Exception e) {
666
                Log.e("Fail 1", e.toString());
667
 
668
            }
669
            return "success";
670
        }
671
 
672
        @Override
673
        protected void onPostExecute(String result) {
674
            super.onPostExecute(result);
675
            Log.d("Notification Opened","Notication opened and login page");
676
        }
677
    }
678
}
679