| Line 4... |
Line 4... |
| 4 |
import android.app.ProgressDialog;
|
4 |
import android.app.ProgressDialog;
|
| 5 |
import android.content.Context;
|
5 |
import android.content.Context;
|
| 6 |
import android.content.DialogInterface;
|
6 |
import android.content.DialogInterface;
|
| 7 |
import android.content.Intent;
|
7 |
import android.content.Intent;
|
| 8 |
import android.content.SharedPreferences;
|
8 |
import android.content.SharedPreferences;
|
| 9 |
import android.content.pm.PackageInfo;
|
- |
|
| 10 |
import android.content.pm.PackageManager;
|
- |
|
| 11 |
import android.net.ConnectivityManager;
|
9 |
import android.net.ConnectivityManager;
|
| 12 |
import android.os.AsyncTask;
|
10 |
import android.os.AsyncTask;
|
| 13 |
import android.os.Build;
|
- |
|
| 14 |
import android.os.Bundle;
|
11 |
import android.os.Bundle;
|
| 15 |
import android.support.v7.app.ActionBarActivity;
|
12 |
import android.support.v7.app.ActionBarActivity;
|
| 16 |
import android.telephony.TelephonyManager;
|
13 |
import android.telephony.TelephonyManager;
|
| 17 |
import android.util.Log;
|
14 |
import android.util.Log;
|
| 18 |
import android.view.Menu;
|
15 |
import android.view.Menu;
|
| 19 |
import android.view.MenuItem;
|
16 |
import android.view.MenuItem;
|
| 20 |
import android.widget.ProgressBar;
|
17 |
import android.widget.ProgressBar;
|
| 21 |
import android.widget.Toast;
|
- |
|
| 22 |
|
18 |
|
| 23 |
import com.google.android.gms.analytics.HitBuilders;
|
19 |
import com.google.android.gms.analytics.HitBuilders;
|
| 24 |
import com.google.android.gms.analytics.Tracker;
|
20 |
import com.google.android.gms.analytics.Tracker;
|
| - |
|
21 |
import com.google.android.gms.gcm.GoogleCloudMessaging;
|
| 25 |
import com.saholic.profittill.Constants.ProfitTillConstants;
|
22 |
import com.saholic.profittill.Constants.ProfitTillConstants;
|
| 26 |
import com.saholic.profittill.Utils.UtilityFunctions;
|
23 |
import com.saholic.profittill.Utils.UtilityFunctions;
|
| 27 |
import com.saholic.profittill.main.GoogleAnalyticsTracker;
|
24 |
import com.saholic.profittill.main.GoogleAnalyticsTracker;
|
| 28 |
import com.saholic.profittill.main.LoginActivity;
|
25 |
import com.saholic.profittill.main.LoginActivity;
|
| 29 |
import com.saholic.profittill.main.MainActivity;
|
26 |
import com.saholic.profittill.main.MainActivity;
|
| Line 41... |
Line 38... |
| 41 |
import org.apache.http.message.BasicNameValuePair;
|
38 |
import org.apache.http.message.BasicNameValuePair;
|
| 42 |
import org.apache.http.util.EntityUtils;
|
39 |
import org.apache.http.util.EntityUtils;
|
| 43 |
import org.json.JSONArray;
|
40 |
import org.json.JSONArray;
|
| 44 |
import org.json.JSONObject;
|
41 |
import org.json.JSONObject;
|
| 45 |
|
42 |
|
| - |
|
43 |
import java.io.IOException;
|
| 46 |
import java.util.ArrayList;
|
44 |
import java.util.ArrayList;
|
| 47 |
|
45 |
|
| 48 |
|
46 |
|
| 49 |
public class SplashScreen extends ActionBarActivity {
|
47 |
public class SplashScreen extends ActionBarActivity {
|
| 50 |
SharedPreferences apiData, userData,apkData;
|
48 |
SharedPreferences apiData, userData,apkData;
|
| 51 |
SharedPreferences.Editor apiEditor,userEditor,apkDataEditor;
|
49 |
SharedPreferences.Editor apiEditor,userEditor,apkDataEditor;
|
| 52 |
UtilityFunctions utilityFunctions;
|
50 |
UtilityFunctions utilityFunctions;
|
| 53 |
AlertDialog dialog1;
|
51 |
AlertDialog dialog1;
|
| 54 |
AlertDialog.Builder b;
|
52 |
AlertDialog.Builder b;
|
| 55 |
ProgressBar pd;
|
53 |
ProgressBar pd;
|
| 56 |
|
- |
|
| - |
|
54 |
GoogleCloudMessaging gcm;
|
| - |
|
55 |
String regId;
|
| 57 |
ArrayList<NameValuePair> apkDataListValue;
|
56 |
ArrayList<NameValuePair> apkDataListValue;
|
| - |
|
57 |
ArrayList<NameValuePair> nameValuePairsGcm;
|
| 58 |
@Override
|
58 |
@Override
|
| 59 |
protected void onCreate(Bundle savedInstanceState) {
|
59 |
protected void onCreate(Bundle savedInstanceState) {
|
| 60 |
TestinAgent.init(this);
|
60 |
TestinAgent.init(this);
|
| 61 |
super.onCreate(savedInstanceState);
|
61 |
super.onCreate(savedInstanceState);
|
| 62 |
Log.d("On Create","On Create");
|
- |
|
| 63 |
setContentView(R.layout.activity_splash_screen);
|
62 |
setContentView(R.layout.activity_splash_screen);
|
| 64 |
getSupportActionBar().hide();
|
63 |
getSupportActionBar().hide();
|
| 65 |
userData = getApplicationContext().getSharedPreferences("User_Data", MODE_PRIVATE);
|
64 |
userData = getApplicationContext().getSharedPreferences("User_Data", MODE_PRIVATE);
|
| 66 |
apkData = getApplicationContext().getSharedPreferences("APK_Data", MODE_PRIVATE);
|
65 |
apkData = getApplicationContext().getSharedPreferences("APK_Data", MODE_PRIVATE);
|
| 67 |
apiData = getApplicationContext().getSharedPreferences("API_Data", MODE_PRIVATE);
|
66 |
apiData = getApplicationContext().getSharedPreferences("API_Data", MODE_PRIVATE);
|
| Line 190... |
Line 189... |
| 190 |
}
|
189 |
}
|
| 191 |
|
190 |
|
| 192 |
@Override
|
191 |
@Override
|
| 193 |
protected JSONObject doInBackground(String... arg0) {
|
192 |
protected JSONObject doInBackground(String... arg0) {
|
| 194 |
try {
|
193 |
try {
|
| 195 |
|
- |
|
| - |
|
194 |
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
| 196 |
HttpClient httpclient = new DefaultHttpClient();
|
195 |
HttpClient httpclient = new DefaultHttpClient();
|
| - |
|
196 |
String url = ProfitTillConstants.MOBILE_API+"?t="+apkData.getString("timestamp","0")+"&imeinumber="+telephonyManager.getDeviceId();
|
| 197 |
HttpPost httppost = new HttpPost(ProfitTillConstants.MOBILE_API+"?t="+apkData.getString("timestamp","0"));
|
197 |
//HttpPost httppost = new HttpPost(ProfitTillConstants.MOBILE_API+"?t="+apkData.getString("timestamp","0"));
|
| - |
|
198 |
HttpPost httppost=new HttpPost(url);
|
| 198 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
199 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
| 199 |
HttpResponse response = httpclient.execute(httppost);
|
200 |
HttpResponse response = httpclient.execute(httppost);
|
| 200 |
HttpEntity entity = response.getEntity();
|
201 |
HttpEntity entity = response.getEntity();
|
| 201 |
JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
|
202 |
JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
|
| 202 |
System.out.println(jObjGmail.toString());
|
203 |
System.out.println(jObjGmail.toString());
|
| Line 229... |
Line 230... |
| 229 |
apiEditor.putString(j.getString("setting"), j.getString("value"));
|
230 |
apiEditor.putString(j.getString("setting"), j.getString("value"));
|
| 230 |
apiEditor.commit();
|
231 |
apiEditor.commit();
|
| 231 |
}
|
232 |
}
|
| 232 |
}
|
233 |
}
|
| 233 |
String timestamp=result.getString("t");
|
234 |
String timestamp=result.getString("t");
|
| 234 |
System.out.println("Time stamp " + timestamp);
|
235 |
String failureCount=result.getString("failureCount");
|
| 235 |
apkDataEditor.putString("timestamp",timestamp);
|
236 |
apkDataEditor.putString("timestamp",timestamp);
|
| 236 |
apkDataEditor.commit();
|
237 |
apkDataEditor.commit();
|
| 237 |
final String idCheck = userData.getString("id",null);
|
238 |
final String idCheck = userData.getString("id",null);
|
| 238 |
//String check = userData.getString("which screen needs to be displayed");
|
239 |
//String check = userData.getString("which screen needs to be displayed");
|
| - |
|
240 |
if(Integer.parseInt(failureCount)<=0) {
|
| 239 |
if(userData.getString("referralCodeRequired","false").equalsIgnoreCase("true")){
|
241 |
if (userData.getString("referralCodeRequired", "false").equalsIgnoreCase("true")) {
|
| 240 |
startActivity(new Intent(SplashScreen.this,ReferrerActivity.class));
|
242 |
startActivity(new Intent(SplashScreen.this, ReferrerActivity.class));
|
| 241 |
}else if(userData.getString("message","false").equalsIgnoreCase("true")){
|
243 |
} else if (userData.getString("message", "false").equalsIgnoreCase("true")) {
|
| 242 |
startActivity(new Intent(SplashScreen.this,MobileNumber.class));
|
244 |
startActivity(new Intent(SplashScreen.this, MobileNumber.class));
|
| 243 |
}else if(idCheck!=null){
|
245 |
} else if (idCheck != null) {
|
| 244 |
startActivity(new Intent(SplashScreen.this,MainActivity.class));
|
246 |
startActivity(new Intent(SplashScreen.this, MainActivity.class));
|
| 245 |
}else {
|
247 |
} else {
|
| 246 |
startActivity(new Intent(SplashScreen.this, LoginActivity.class));
|
248 |
startActivity(new Intent(SplashScreen.this, LoginActivity.class));
|
| 247 |
|
249 |
|
| - |
|
250 |
}
|
| - |
|
251 |
}else{
|
| - |
|
252 |
registerGCM();
|
| 248 |
}
|
253 |
}
|
| 249 |
}catch (Exception e){
|
254 |
}catch (Exception e){
|
| 250 |
finish();
|
255 |
finish();
|
| 251 |
}
|
256 |
}
|
| 252 |
}
|
257 |
}
|
| Line 432... |
Line 437... |
| 432 |
/*@Override
|
437 |
/*@Override
|
| 433 |
protected void onPause() {
|
438 |
protected void onPause() {
|
| 434 |
Log.d("On Pause","On Pause");
|
439 |
Log.d("On Pause","On Pause");
|
| 435 |
super.onPause();
|
440 |
super.onPause();
|
| 436 |
}*/
|
441 |
}*/
|
| - |
|
442 |
public void registerGCM() {
|
| - |
|
443 |
|
| - |
|
444 |
gcm = GoogleCloudMessaging.getInstance(SplashScreen.this);
|
| - |
|
445 |
registerInBackground();
|
| - |
|
446 |
|
| - |
|
447 |
}
|
| - |
|
448 |
|
| - |
|
449 |
private void registerInBackground() {
|
| - |
|
450 |
new AsyncTask<Void, Void, String>() {
|
| - |
|
451 |
@Override
|
| - |
|
452 |
protected String doInBackground(Void... params) {
|
| - |
|
453 |
String msg = "";
|
| - |
|
454 |
try {
|
| - |
|
455 |
if (gcm == null) {
|
| - |
|
456 |
gcm = GoogleCloudMessaging.getInstance(SplashScreen.this);
|
| - |
|
457 |
}
|
| - |
|
458 |
regId = gcm.register(ProfitTillConstants.GOOGLE_SENDER_ID);
|
| - |
|
459 |
msg = "Device registered";
|
| - |
|
460 |
|
| - |
|
461 |
} catch (IOException ex) {
|
| - |
|
462 |
msg = "Error :" + ex.getMessage();
|
| - |
|
463 |
}
|
| - |
|
464 |
return msg;
|
| - |
|
465 |
}
|
| - |
|
466 |
|
| - |
|
467 |
@Override
|
| - |
|
468 |
protected void onPostExecute(String msg) {
|
| - |
|
469 |
new gcmPushData().execute(msg);
|
| - |
|
470 |
}
|
| - |
|
471 |
}.execute(null, null, null);
|
| - |
|
472 |
}
|
| - |
|
473 |
|
| - |
|
474 |
|
| - |
|
475 |
class gcmPushData extends AsyncTask<String, Integer, String> {
|
| - |
|
476 |
|
| - |
|
477 |
@Override
|
| - |
|
478 |
protected void onPreExecute() {
|
| - |
|
479 |
super.onPreExecute();
|
| - |
|
480 |
}
|
| - |
|
481 |
|
| - |
|
482 |
@Override
|
| - |
|
483 |
protected String doInBackground(String... arg0) {
|
| - |
|
484 |
String id = null;
|
| - |
|
485 |
try {
|
| - |
|
486 |
HttpClient httpclient = new DefaultHttpClient();
|
| - |
|
487 |
HttpPost httppost = new HttpPost(apiData.getString("gcm.push.url", "http://staging.profittill.com/gcm_users/add"));
|
| - |
|
488 |
nameValuePairsGcm = new ArrayList<>();
|
| - |
|
489 |
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
| - |
|
490 |
nameValuePairsGcm.add(new BasicNameValuePair("gcm_regid", regId));
|
| - |
|
491 |
nameValuePairsGcm.add(new BasicNameValuePair("imeinumber", telephonyManager.getDeviceId()));
|
| - |
|
492 |
nameValuePairsGcm.add(new BasicNameValuePair("user_id", userData.getString("id", null)));
|
| - |
|
493 |
nameValuePairsGcm.add(new BasicNameValuePair("device_message", arg0[0]));
|
| - |
|
494 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
| - |
|
495 |
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairsGcm));
|
| - |
|
496 |
HttpResponse response = httpclient.execute(httppost);
|
| - |
|
497 |
HttpEntity entity = response.getEntity();
|
| - |
|
498 |
int status = response.getStatusLine().getStatusCode();
|
| - |
|
499 |
|
| - |
|
500 |
if (status == 200) {
|
| - |
|
501 |
Log.d("ResponseCode GCM ", status + "");
|
| - |
|
502 |
} else {
|
| - |
|
503 |
Log.d("ResponseCode GCM ", status + "");
|
| - |
|
504 |
}
|
| - |
|
505 |
|
| - |
|
506 |
nameValuePairsGcm.clear();
|
| - |
|
507 |
Log.e("pass 1", "connection success ");
|
| - |
|
508 |
} catch (Exception e) {
|
| - |
|
509 |
Log.e("Fail 1", e.toString());
|
| - |
|
510 |
|
| - |
|
511 |
}
|
| - |
|
512 |
return id;
|
| - |
|
513 |
}
|
| - |
|
514 |
|
| - |
|
515 |
@Override
|
| - |
|
516 |
protected void onPostExecute(String result) {
|
| - |
|
517 |
super.onPostExecute(result);
|
| - |
|
518 |
final String idCheck = userData.getString("id",null);
|
| - |
|
519 |
if (userData.getString("referralCodeRequired", "false").equalsIgnoreCase("true")) {
|
| - |
|
520 |
startActivity(new Intent(SplashScreen.this, ReferrerActivity.class));
|
| - |
|
521 |
} else if (userData.getString("message", "false").equalsIgnoreCase("true")) {
|
| - |
|
522 |
startActivity(new Intent(SplashScreen.this, MobileNumber.class));
|
| - |
|
523 |
} else if (idCheck != null) {
|
| - |
|
524 |
startActivity(new Intent(SplashScreen.this, MainActivity.class));
|
| - |
|
525 |
} else {
|
| - |
|
526 |
startActivity(new Intent(SplashScreen.this, LoginActivity.class));
|
| - |
|
527 |
}
|
| - |
|
528 |
}
|
| - |
|
529 |
}
|
| 437 |
}
|
530 |
}
|
| - |
|
531 |
|