| 14792 |
manas |
1 |
package com.saholic.profittill.main;
|
|
|
2 |
|
|
|
3 |
import android.app.AlertDialog;
|
|
|
4 |
import android.content.Context;
|
|
|
5 |
import android.content.DialogInterface;
|
|
|
6 |
import android.content.Intent;
|
|
|
7 |
import android.content.SharedPreferences;
|
|
|
8 |
import android.net.ConnectivityManager;
|
|
|
9 |
import android.os.AsyncTask;
|
|
|
10 |
import android.support.v7.app.ActionBarActivity;
|
|
|
11 |
import android.os.Bundle;
|
|
|
12 |
import android.util.Log;
|
|
|
13 |
import android.view.Menu;
|
|
|
14 |
import android.view.MenuItem;
|
|
|
15 |
import android.view.View;
|
|
|
16 |
import android.widget.Button;
|
|
|
17 |
import android.widget.EditText;
|
|
|
18 |
import android.widget.TextView;
|
|
|
19 |
import android.widget.Toast;
|
|
|
20 |
|
|
|
21 |
import com.facebook.Session;
|
|
|
22 |
import com.google.android.gms.analytics.HitBuilders;
|
|
|
23 |
import com.google.android.gms.analytics.Tracker;
|
|
|
24 |
import com.google.android.gms.common.ConnectionResult;
|
|
|
25 |
import com.google.android.gms.common.api.GoogleApiClient;
|
|
|
26 |
import com.google.android.gms.plus.Plus;
|
|
|
27 |
import com.mixpanel.android.mpmetrics.MixpanelAPI;
|
|
|
28 |
import com.saholic.profittill.Constants.ProfitTillConstants;
|
|
|
29 |
import com.saholic.profittill.R;
|
|
|
30 |
import com.testin.agent.TestinAgent;
|
|
|
31 |
|
|
|
32 |
import org.apache.http.HttpEntity;
|
|
|
33 |
import org.apache.http.HttpResponse;
|
|
|
34 |
import org.apache.http.NameValuePair;
|
|
|
35 |
import org.apache.http.client.ClientProtocolException;
|
|
|
36 |
import org.apache.http.client.HttpClient;
|
|
|
37 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
38 |
import org.apache.http.client.methods.HttpPost;
|
|
|
39 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
40 |
import org.apache.http.message.BasicNameValuePair;
|
|
|
41 |
import org.apache.http.util.EntityUtils;
|
|
|
42 |
import org.json.JSONException;
|
|
|
43 |
import org.json.JSONObject;
|
|
|
44 |
|
|
|
45 |
import java.io.IOException;
|
|
|
46 |
import java.text.SimpleDateFormat;
|
|
|
47 |
import java.util.ArrayList;
|
|
|
48 |
import java.util.Date;
|
|
|
49 |
|
|
|
50 |
public class MobileNumber extends ActionBarActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
|
|
|
51 |
SharedPreferences userData;
|
|
|
52 |
SharedPreferences apiData;
|
|
|
53 |
SharedPreferences.Editor userDataEditor;
|
|
|
54 |
SharedPreferences.Editor apiSettingsEditor;
|
|
|
55 |
EditText phoneNumberFirstTime;
|
|
|
56 |
TextView skipMobileNumber;
|
|
|
57 |
Button phoneNumberFirstTimeButton;
|
|
|
58 |
boolean glogout;
|
|
|
59 |
MixpanelAPI mixpanel;
|
|
|
60 |
String type1;
|
|
|
61 |
public GoogleApiClient mGoogleApiClient;
|
|
|
62 |
@Override
|
|
|
63 |
protected void onCreate(Bundle savedInstanceState) {
|
|
|
64 |
super.onCreate(savedInstanceState);
|
|
|
65 |
setContentView(R.layout.activity_mobile_number);
|
|
|
66 |
TestinAgent.init(this);
|
|
|
67 |
getSupportActionBar().hide();
|
|
|
68 |
mixpanel= MixpanelAPI.getInstance(getApplicationContext(), ProfitTillConstants.MIX_PANEL_TOKEN);
|
|
|
69 |
userData = getApplicationContext().getSharedPreferences("User_Data", Context.MODE_PRIVATE);
|
|
|
70 |
apiData = getApplicationContext().getSharedPreferences("API_Data", Context.MODE_PRIVATE);
|
|
|
71 |
userDataEditor = userData.edit();
|
|
|
72 |
apiSettingsEditor = apiData.edit();
|
|
|
73 |
TestinAgent.setUserInfo(userData.getString("id", ""));
|
|
|
74 |
Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
|
|
|
75 |
GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
|
|
|
76 |
t.setScreenName("First Time Mobile Entered Screen");
|
|
|
77 |
t.send(new HitBuilders.ScreenViewBuilder().build());
|
|
|
78 |
|
|
|
79 |
type1 = userData.getString("type",null);
|
|
|
80 |
|
|
|
81 |
if(type1!=null && type1.equalsIgnoreCase("google")) {
|
|
|
82 |
mGoogleApiClient = new GoogleApiClient.Builder(this)
|
|
|
83 |
.addConnectionCallbacks(this)
|
|
|
84 |
.addOnConnectionFailedListener(this).addApi(Plus.API)
|
|
|
85 |
.addScope(Plus.SCOPE_PLUS_LOGIN).build();
|
|
|
86 |
mGoogleApiClient.connect();
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
phoneNumberFirstTime=(EditText)findViewById(R.id.phoneNumberFirstTime);
|
|
|
90 |
skipMobileNumber = (TextView)findViewById(R.id.skipMobileNumber);
|
|
|
91 |
phoneNumberFirstTimeButton=(Button)findViewById(R.id.phoneNumberFirstTimeButton);
|
|
|
92 |
|
|
|
93 |
skipMobileNumber.setOnClickListener(new View.OnClickListener() {
|
|
|
94 |
@Override
|
|
|
95 |
public void onClick(View v) {
|
|
|
96 |
|
|
|
97 |
JSONObject props = new JSONObject();
|
|
|
98 |
try {
|
|
|
99 |
mixpanel.identify(userData.getString("id",null));
|
|
|
100 |
props.put("Screen", "Mobile Verification");
|
|
|
101 |
mixpanel.track("First Time Mobile Number Skipped",props);
|
|
|
102 |
} catch (JSONException e) {
|
|
|
103 |
e.printStackTrace();
|
|
|
104 |
}
|
|
|
105 |
Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
|
|
|
106 |
GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
|
|
|
107 |
t.send(new HitBuilders.EventBuilder()
|
|
|
108 |
.setCategory("First Time Mobile Entered ")
|
|
|
109 |
.setAction("Number not entered")
|
|
|
110 |
.setLabel("First Time Mobile Not entered")
|
|
|
111 |
.build());
|
|
|
112 |
|
|
|
113 |
Intent i = new Intent(MobileNumber.this,MainActivity.class);
|
|
|
114 |
i.putExtra("displayView","7");
|
|
|
115 |
startActivity(i);
|
|
|
116 |
}
|
|
|
117 |
});
|
|
|
118 |
phoneNumberFirstTimeButton.setOnClickListener(new View.OnClickListener() {
|
|
|
119 |
@Override
|
|
|
120 |
public void onClick(View v) {
|
|
|
121 |
if(phoneNumberFirstTime.getText().toString().length()==10){
|
|
|
122 |
if(isInternetOn()) {
|
|
|
123 |
JSONObject props = new JSONObject();
|
|
|
124 |
try {
|
|
|
125 |
mixpanel.identify(userData.getString("id",null));
|
|
|
126 |
props.put("Screen", "Mobile Verification");
|
|
|
127 |
mixpanel.track("First Time Mobile Number Entered",props);
|
|
|
128 |
} catch (JSONException e) {
|
|
|
129 |
e.printStackTrace();
|
|
|
130 |
}
|
|
|
131 |
new pushVerification().execute();
|
|
|
132 |
}else{
|
|
|
133 |
Toast.makeText(getApplicationContext(), "No internet connection. Please try again.", Toast.LENGTH_SHORT).show();
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
}
|
|
|
137 |
else{
|
|
|
138 |
Toast.makeText(getApplicationContext(), "Mobile Number not valid.", Toast.LENGTH_SHORT).show();
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
}
|
|
|
142 |
});
|
|
|
143 |
|
|
|
144 |
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
|
|
|
148 |
@Override
|
|
|
149 |
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
150 |
getMenuInflater().inflate(R.menu.menu_mobile_number, menu);
|
|
|
151 |
return true;
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
@Override
|
|
|
155 |
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
156 |
|
|
|
157 |
int id = item.getItemId();
|
|
|
158 |
if (id == R.id.action_settings) {
|
|
|
159 |
return true;
|
|
|
160 |
}
|
|
|
161 |
return super.onOptionsItemSelected(item);
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
@Override
|
|
|
165 |
public void onConnected(Bundle bundle) {
|
|
|
166 |
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
@Override
|
|
|
170 |
public void onConnectionSuspended(int i) {
|
|
|
171 |
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
@Override
|
|
|
175 |
public void onConnectionFailed(ConnectionResult connectionResult) {
|
|
|
176 |
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
class pushVerification extends AsyncTask<String, Integer, String> {
|
|
|
180 |
|
|
|
181 |
@Override
|
|
|
182 |
protected void onPreExecute() {
|
|
|
183 |
super.onPreExecute();
|
|
|
184 |
Log.e("Push Service", "Pre execute");
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
@Override
|
|
|
188 |
protected String doInBackground(String... arg0) {
|
|
|
189 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
190 |
try {
|
|
|
191 |
|
|
|
192 |
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
|
|
193 |
SimpleDateFormat sdf = new SimpleDateFormat(ProfitTillConstants.SQL_DATE_FORMAT);
|
|
|
194 |
String dateUpdated = sdf.format(new Date());
|
|
|
195 |
nameValuePairs.add(new BasicNameValuePair("id",userData.getString("id","")));
|
|
|
196 |
nameValuePairs.add(new BasicNameValuePair("mobile_number",phoneNumberFirstTime.getText().toString()));
|
|
|
197 |
nameValuePairs.add(new BasicNameValuePair("mobile_number_last_updated",dateUpdated));
|
|
|
198 |
String updateURL = apiData.getString("useredit.url","");
|
|
|
199 |
String url = updateURL+userData.getString("id","");
|
|
|
200 |
HttpPost httppost = new HttpPost(url);
|
|
|
201 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
202 |
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
|
|
|
203 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
204 |
HttpEntity entity = response.getEntity();
|
|
|
205 |
int status = response.getStatusLine().getStatusCode();
|
|
|
206 |
JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
|
|
|
207 |
System.out.println("JSON Object in mobile " + jObjGmail.toString());
|
|
|
208 |
String success = jObjGmail.getString("success");
|
|
|
209 |
|
|
|
210 |
if(status == 200){
|
|
|
211 |
Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
|
|
|
212 |
GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
|
|
|
213 |
t.send(new HitBuilders.EventBuilder()
|
|
|
214 |
.setCategory("First Time Mobile Entered ")
|
|
|
215 |
.setAction("Number entered")
|
|
|
216 |
.setLabel("First Time Mobile entered")
|
|
|
217 |
.build());
|
|
|
218 |
|
|
|
219 |
} else {
|
|
|
220 |
System.out.println(" NOT Transfered");
|
|
|
221 |
|
|
|
222 |
}
|
|
|
223 |
|
|
|
224 |
if(success.equalsIgnoreCase("true")){
|
|
|
225 |
userDataEditor.putString("message","false");;
|
|
|
226 |
userDataEditor.commit();
|
|
|
227 |
return "true";
|
|
|
228 |
}else{
|
|
|
229 |
userDataEditor.putString("message","true");;
|
|
|
230 |
userDataEditor.commit();
|
|
|
231 |
return "false";
|
|
|
232 |
}
|
|
|
233 |
} catch (ClientProtocolException e) {
|
|
|
234 |
return "false";
|
|
|
235 |
} catch (IOException e) {
|
|
|
236 |
return "false";
|
|
|
237 |
}catch (Exception e){
|
|
|
238 |
return "false";
|
|
|
239 |
}
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
@Override
|
|
|
243 |
protected void onPostExecute(String result) {
|
|
|
244 |
super.onPostExecute(result);
|
|
|
245 |
Intent i = new Intent(MobileNumber.this,MobileVerificationFirstTime.class);
|
|
|
246 |
i.putExtra("numberVerification",phoneNumberFirstTime.getText().toString());
|
|
|
247 |
startActivity(i);
|
|
|
248 |
}
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
@Override
|
|
|
252 |
public void onBackPressed() {
|
|
|
253 |
/* super.onBackPressed();*/
|
|
|
254 |
new AlertDialog.Builder(this)
|
|
|
255 |
.setIcon(android.R.drawable.ic_dialog_alert)
|
|
|
256 |
.setTitle("Exit!")
|
|
|
257 |
.setMessage("Are you sure you want to sign out?")
|
|
|
258 |
.setPositiveButton("Yes", new DialogInterface.OnClickListener()
|
|
|
259 |
{
|
|
|
260 |
@Override
|
|
|
261 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
262 |
|
|
|
263 |
if(type1.equalsIgnoreCase("facebook")) {
|
|
|
264 |
Log.d("fblogout","logout");
|
|
|
265 |
if (Session.getActiveSession() != null) {
|
|
|
266 |
Session.getActiveSession().closeAndClearTokenInformation();
|
|
|
267 |
}
|
|
|
268 |
Session.setActiveSession(null);
|
|
|
269 |
/*
|
|
|
270 |
userDataEditor.remove("id");
|
|
|
271 |
userDataEditor.remove("type");
|
|
|
272 |
userDataEditor.remove("email");
|
|
|
273 |
*/
|
|
|
274 |
userDataEditor.clear().commit();
|
|
|
275 |
/* userDataEditor.commit();*/
|
|
|
276 |
startActivity(new Intent(MobileNumber.this, LoginActivity.class));
|
|
|
277 |
}
|
|
|
278 |
else{
|
|
|
279 |
Log.d("gmailLogout","logout");
|
|
|
280 |
signOutFromGplus();
|
|
|
281 |
if(glogout==true){
|
|
|
282 |
startActivity(new Intent(MobileNumber.this, LoginActivity.class));
|
|
|
283 |
}
|
|
|
284 |
}
|
|
|
285 |
|
|
|
286 |
}
|
|
|
287 |
|
|
|
288 |
})
|
|
|
289 |
.setNegativeButton("No", null)
|
|
|
290 |
.show();
|
|
|
291 |
}
|
|
|
292 |
|
|
|
293 |
public void signOutFromGplus() {
|
|
|
294 |
if (mGoogleApiClient.isConnected()) {
|
|
|
295 |
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
|
|
|
296 |
mGoogleApiClient.disconnect();
|
|
|
297 |
mGoogleApiClient.connect();
|
|
|
298 |
glogout=true;
|
|
|
299 |
userDataEditor.clear();
|
|
|
300 |
userDataEditor.commit();
|
|
|
301 |
} else {
|
|
|
302 |
glogout=false;
|
|
|
303 |
}
|
|
|
304 |
}
|
|
|
305 |
|
|
|
306 |
public final boolean isInternetOn() {
|
|
|
307 |
|
|
|
308 |
ConnectivityManager connec =
|
|
|
309 |
(ConnectivityManager)this.getSystemService(getBaseContext().CONNECTIVITY_SERVICE);
|
|
|
310 |
|
|
|
311 |
if ( connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||
|
|
|
312 |
connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||
|
|
|
313 |
connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||
|
|
|
314 |
connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED ) {
|
|
|
315 |
return true;
|
|
|
316 |
|
|
|
317 |
} else if (
|
|
|
318 |
connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||
|
|
|
319 |
connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED ) {
|
|
|
320 |
|
|
|
321 |
return false;
|
|
|
322 |
}
|
|
|
323 |
return false;
|
|
|
324 |
}
|
|
|
325 |
|
|
|
326 |
}
|