| 21190 |
rajender |
1 |
package com.saholic.profittill.main;
|
|
|
2 |
|
|
|
3 |
import android.Manifest;
|
|
|
4 |
import android.app.AlertDialog;
|
|
|
5 |
import android.app.ProgressDialog;
|
|
|
6 |
import android.content.Context;
|
|
|
7 |
import android.content.DialogInterface;
|
|
|
8 |
import android.content.Intent;
|
|
|
9 |
import android.content.SharedPreferences;
|
|
|
10 |
import android.content.pm.PackageManager;
|
|
|
11 |
import android.graphics.Bitmap;
|
|
|
12 |
import android.graphics.BitmapFactory;
|
|
|
13 |
import android.graphics.Color;
|
|
|
14 |
import android.graphics.drawable.ColorDrawable;
|
|
|
15 |
import android.net.ConnectivityManager;
|
|
|
16 |
import android.net.Uri;
|
|
|
17 |
import android.os.AsyncTask;
|
|
|
18 |
import android.os.Build;
|
|
|
19 |
import android.os.Environment;
|
|
|
20 |
import android.provider.MediaStore;
|
|
|
21 |
import android.support.v7.app.ActionBar;
|
|
|
22 |
import android.support.v7.app.ActionBarActivity;
|
|
|
23 |
import android.os.Bundle;
|
|
|
24 |
import android.text.InputType;
|
|
|
25 |
import android.util.Base64;
|
|
|
26 |
import android.util.Log;
|
|
|
27 |
import android.view.KeyEvent;
|
|
|
28 |
import android.view.Menu;
|
|
|
29 |
import android.view.MenuItem;
|
|
|
30 |
import android.view.View;
|
|
|
31 |
import android.view.inputmethod.InputMethodManager;
|
|
|
32 |
import android.widget.ArrayAdapter;
|
|
|
33 |
import android.widget.Button;
|
|
|
34 |
import android.widget.EditText;
|
|
|
35 |
import android.widget.ImageButton;
|
|
|
36 |
import android.widget.ImageView;
|
|
|
37 |
import android.widget.ListView;
|
|
|
38 |
import android.widget.RelativeLayout;
|
|
|
39 |
import android.widget.TextView;
|
|
|
40 |
import android.widget.Toast;
|
|
|
41 |
|
|
|
42 |
import com.android.internal.http.multipart.MultipartEntity;
|
|
|
43 |
import com.facebook.Session;
|
|
|
44 |
import com.google.android.gms.analytics.HitBuilders;
|
|
|
45 |
import com.google.android.gms.analytics.Tracker;
|
|
|
46 |
import com.google.android.gms.common.ConnectionResult;
|
|
|
47 |
import com.google.android.gms.common.api.GoogleApiClient;
|
|
|
48 |
import com.google.android.gms.plus.Plus;
|
|
|
49 |
import com.google.android.gms.plus.model.people.Person;
|
|
|
50 |
import com.kosalgeek.android.photoutil.CameraPhoto;
|
|
|
51 |
import com.kosalgeek.android.photoutil.GalleryPhoto;
|
|
|
52 |
import com.kosalgeek.android.photoutil.ImageBase64;
|
|
|
53 |
import com.kosalgeek.android.photoutil.ImageLoader;
|
|
|
54 |
import com.kosalgeek.genasync12.AsyncResponse;
|
|
|
55 |
import com.kosalgeek.genasync12.EachExceptionsHandler;
|
|
|
56 |
import com.kosalgeek.genasync12.PostResponseAsyncTask;
|
|
|
57 |
import com.mixpanel.android.mpmetrics.MixpanelAPI;
|
|
|
58 |
import com.saholic.profittill.Constants.ProfitTillConstants;
|
|
|
59 |
import com.saholic.profittill.R;
|
|
|
60 |
import com.saholic.profittill.Utils.AnalyticsUtility;
|
|
|
61 |
import com.saholic.profittill.Utils.Utility;
|
|
|
62 |
import com.saholic.profittill.Utils.UtilityFunctions;
|
|
|
63 |
import com.saholic.profittill.Volley.Analytics;
|
|
|
64 |
import com.saholic.profittill.Volley.AnalyticsErrorResponse;
|
|
|
65 |
import com.saholic.profittill.Volley.AnalyticsJsonResponse;
|
|
|
66 |
|
|
|
67 |
import org.apache.http.HttpEntity;
|
|
|
68 |
import org.apache.http.HttpResponse;
|
|
|
69 |
import org.apache.http.NameValuePair;
|
|
|
70 |
import org.apache.http.client.ClientProtocolException;
|
|
|
71 |
import org.apache.http.client.HttpClient;
|
|
|
72 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
73 |
import org.apache.http.client.methods.HttpPost;
|
|
|
74 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
75 |
import org.apache.http.message.BasicNameValuePair;
|
|
|
76 |
import org.apache.http.util.EntityUtils;
|
|
|
77 |
import org.json.JSONArray;
|
|
|
78 |
import org.json.JSONException;
|
|
|
79 |
import org.json.JSONObject;
|
|
|
80 |
|
|
|
81 |
import java.io.BufferedReader;
|
|
|
82 |
import java.io.ByteArrayInputStream;
|
|
|
83 |
import java.io.ByteArrayOutputStream;
|
|
|
84 |
import java.io.File;
|
|
|
85 |
import java.io.FileInputStream;
|
|
|
86 |
import java.io.FileNotFoundException;
|
|
|
87 |
import java.io.FileOutputStream;
|
|
|
88 |
import java.io.IOException;
|
|
|
89 |
import java.io.InputStream;
|
|
|
90 |
import java.io.InputStreamReader;
|
|
|
91 |
import java.io.UnsupportedEncodingException;
|
|
|
92 |
import java.net.MalformedURLException;
|
|
|
93 |
import java.net.ProtocolException;
|
|
|
94 |
import java.text.SimpleDateFormat;
|
|
|
95 |
import java.util.ArrayList;
|
|
|
96 |
import java.util.Date;
|
|
|
97 |
import java.util.HashMap;
|
|
|
98 |
import java.util.Map;
|
|
|
99 |
|
|
|
100 |
public class ReferrerActivity extends ActionBarActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener,View.OnClickListener {
|
|
|
101 |
EditText referalCode;
|
|
|
102 |
MixpanelAPI mixpanel;
|
|
|
103 |
Button referrerSend;
|
|
|
104 |
ImageButton remove, remove2;
|
|
|
105 |
String type1;
|
|
|
106 |
TextView supportList;
|
|
|
107 |
ImageView ivImage, ivImage2;
|
|
|
108 |
GalleryPhoto galleryPhoto;
|
|
|
109 |
CameraPhoto cameraPhoto;
|
|
|
110 |
private int REQUEST_CAMERA_ONE = 2, SELECT_FILE_ONE = 3;
|
|
|
111 |
private String userChoosenTask;
|
|
|
112 |
SharedPreferences userData;
|
|
|
113 |
SharedPreferences apiData;
|
|
|
114 |
private int REQUEST_CAMERA = 0, SELECT_FILE = 1;
|
|
|
115 |
SharedPreferences.Editor userDataEditor;
|
|
|
116 |
SharedPreferences.Editor apiSettingsEditor;
|
|
|
117 |
SharedPreferences inviteD;
|
|
|
118 |
SharedPreferences.Editor inviteDEditor;
|
|
|
119 |
ArrayList<NameValuePair> nameValuePairsGcm;
|
|
|
120 |
public GoogleApiClient mGoogleApiClient;
|
|
|
121 |
boolean glogout;
|
|
|
122 |
RelativeLayout storeDocument,supportDocument;
|
|
|
123 |
String selectedPath1="";
|
|
|
124 |
String selectedPath2= "";
|
|
|
125 |
HttpEntity resEntity;
|
|
|
126 |
private final String TAG = this.getClass().getName();
|
|
|
127 |
final ArrayList<String> invitationCodeList = new ArrayList<String>();
|
|
|
128 |
|
|
|
129 |
ArrayList<NameValuePair> nameValuePairs;
|
|
|
130 |
|
|
|
131 |
|
|
|
132 |
@Override
|
|
|
133 |
protected void onCreate(Bundle savedInstanceState) {
|
|
|
134 |
super.onCreate(savedInstanceState);
|
|
|
135 |
setContentView(R.layout.activity_referrer);
|
|
|
136 |
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.White)));
|
|
|
137 |
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
|
|
|
138 |
getSupportActionBar().setCustomView(R.layout.profitmandiicon);
|
|
|
139 |
userData = getApplicationContext().getSharedPreferences("User_Data", MODE_PRIVATE);
|
|
|
140 |
apiData = getApplicationContext().getSharedPreferences("API_Data", MODE_PRIVATE);
|
|
|
141 |
userDataEditor = userData.edit();
|
|
|
142 |
apiSettingsEditor = apiData.edit();
|
|
|
143 |
inviteD = getApplicationContext().getSharedPreferences("Invite", MODE_PRIVATE);
|
|
|
144 |
inviteDEditor = inviteD.edit();
|
|
|
145 |
remove = (ImageButton) findViewById(R.id.remove);
|
|
|
146 |
remove2 = (ImageButton) findViewById(R.id.remove2);
|
|
|
147 |
supportList=(TextView)findViewById(R.id.supportList);
|
|
|
148 |
ivImage = (ImageView) findViewById(R.id.ivImage);
|
|
|
149 |
ivImage2 = (ImageView) findViewById(R.id.ivImage2);
|
|
|
150 |
referalCode = (EditText) findViewById(R.id.referalCode);
|
|
|
151 |
storeDocument=(RelativeLayout)findViewById(R.id.storeDocument);
|
|
|
152 |
storeDocument.setOnClickListener(this);
|
|
|
153 |
supportDocument=(RelativeLayout)findViewById(R.id.supportDocument);
|
|
|
154 |
supportDocument.setOnClickListener(this);
|
|
|
155 |
referrerSend = (Button) findViewById(R.id.referrerSend);
|
|
|
156 |
galleryPhoto = new GalleryPhoto(getApplicationContext());
|
|
|
157 |
cameraPhoto = new CameraPhoto(getApplicationContext());
|
|
|
158 |
mixpanel = MixpanelAPI.getInstance(getApplicationContext(), ProfitTillConstants.MIX_PANEL_TOKEN);
|
|
|
159 |
|
|
|
160 |
Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
|
|
|
161 |
GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
|
|
|
162 |
t.setScreenName("Referrer Screen");
|
|
|
163 |
t.send(new HitBuilders.ScreenViewBuilder().build());
|
|
|
164 |
new Analytics(ProfitTillConstants.ANALYTICS_URL,
|
|
|
165 |
AnalyticsUtility.getAnalyticsRequest(ReferrerActivity.this, userData.getString("id", ""), "Screen", "Referrer", "Referrer Screen"),
|
|
|
166 |
AnalyticsJsonResponse.getAnalyticsRequestInstance(),
|
|
|
167 |
AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(ReferrerActivity.this);
|
|
|
168 |
|
|
|
169 |
if (getIntent().getAction() == "Login") {
|
|
|
170 |
new Analytics(ProfitTillConstants.ANALYTICS_URL,
|
|
|
171 |
AnalyticsUtility.getAnalyticsRequest(ReferrerActivity.this, userData.getString("id", ""), "Notification", "Notification Opened Referrer", getIntent().getExtras().getString("cid")),
|
|
|
172 |
AnalyticsJsonResponse.getAnalyticsRequestInstance(),
|
|
|
173 |
AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(ReferrerActivity.this);
|
|
|
174 |
|
|
|
175 |
nameValuePairsGcm = new ArrayList<>();
|
|
|
176 |
nameValuePairsGcm.add(new BasicNameValuePair("cid", getIntent().getExtras().getString("cid")));
|
|
|
177 |
nameValuePairsGcm.add(new BasicNameValuePair("user_id", userData.getString("id", "")));
|
|
|
178 |
nameValuePairsGcm.add(new BasicNameValuePair("timestamp", UtilityFunctions.notificationDate()));
|
|
|
179 |
nameValuePairsGcm.add(new BasicNameValuePair("result", "referrer"));
|
|
|
180 |
getIntent().getExtras().remove("cid");
|
|
|
181 |
new NotificationOpenedData().execute(nameValuePairsGcm);
|
|
|
182 |
} else if (getIntent().getAction() == "31") {
|
|
|
183 |
String emailURL = String.valueOf(getIntent().getData());
|
|
|
184 |
Uri url = Uri.parse(emailURL);
|
|
|
185 |
String campaignId = url.getQueryParameter("campaign");
|
|
|
186 |
if (url.getQueryParameter("intent_type").equalsIgnoreCase("url")) {
|
|
|
187 |
t.send(new HitBuilders.EventBuilder()
|
|
|
188 |
.setCategory("Message/Email")
|
|
|
189 |
.setAction("Message/Email Opened For User Id " + UtilityFunctions.campaignUserId(url))
|
|
|
190 |
.setLabel("Campaign Id " + campaignId)
|
|
|
191 |
.build());
|
|
|
192 |
new Analytics(ProfitTillConstants.ANALYTICS_URL,
|
|
|
193 |
AnalyticsUtility.getAnalyticsRequest(ReferrerActivity.this, UtilityFunctions.campaignUserId(url), "Message", "Message Opened Referrer", campaignId),
|
|
|
194 |
AnalyticsJsonResponse.getAnalyticsRequestInstance(),
|
|
|
195 |
AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(ReferrerActivity.this);
|
|
|
196 |
|
|
|
197 |
nameValuePairsGcm = new ArrayList<>();
|
|
|
198 |
nameValuePairsGcm.add(new BasicNameValuePair("user_id", UtilityFunctions.campaignUserId(url)));
|
|
|
199 |
nameValuePairsGcm.add(new BasicNameValuePair("cid", campaignId));
|
|
|
200 |
nameValuePairsGcm.add(new BasicNameValuePair("timestamp", UtilityFunctions.notificationDate()));
|
|
|
201 |
nameValuePairsGcm.add(new BasicNameValuePair("result", "message_opened_referrer"));
|
|
|
202 |
new NotificationOpenedData().execute(nameValuePairsGcm);
|
|
|
203 |
} else {
|
|
|
204 |
nameValuePairsGcm = new ArrayList<>();
|
|
|
205 |
nameValuePairsGcm.add(new BasicNameValuePair("user_id", userData.getString("id", "")));
|
|
|
206 |
nameValuePairsGcm.add(new BasicNameValuePair("cid", campaignId));
|
|
|
207 |
nameValuePairsGcm.add(new BasicNameValuePair("timestamp", UtilityFunctions.notificationDate()));
|
|
|
208 |
nameValuePairsGcm.add(new BasicNameValuePair("result", "message_opened_referrer"));
|
|
|
209 |
new NotificationOpenedData().execute(nameValuePairsGcm);
|
|
|
210 |
}
|
|
|
211 |
}
|
|
|
212 |
|
|
|
213 |
remove.setOnClickListener(this);
|
|
|
214 |
remove2.setOnClickListener(this);
|
|
|
215 |
|
|
|
216 |
supportList.setOnClickListener(new View.OnClickListener() {
|
|
|
217 |
@Override
|
|
|
218 |
public void onClick(View v) {
|
|
|
219 |
|
|
|
220 |
|
|
|
221 |
final CharSequence[] items = {"Sales tax/ VAT registration","Service tax registration","Excise registration","Trade licenses ","Certificate/registration under Shops and Establishment Act","License for undertaking retail trade (like tehbazari and similar license for hawkers) from Government Authorities/Local Self Government Bodies or","Certificate of incorporation or registration as a society or registration as public trust for their self consumption, if purchase is made for self consumption."};
|
|
|
222 |
|
|
|
223 |
AlertDialog.Builder builder = new AlertDialog.Builder(ReferrerActivity.this);
|
|
|
224 |
builder.setTitle("Document List");
|
|
|
225 |
builder.setItems(items, new DialogInterface.OnClickListener() {
|
|
|
226 |
@Override
|
|
|
227 |
public void onClick(DialogInterface dialog, int item) {
|
|
|
228 |
|
|
|
229 |
}
|
|
|
230 |
});
|
|
|
231 |
AlertDialog alert = builder.create();
|
|
|
232 |
ListView listView=alert.getListView();
|
|
|
233 |
listView.setDivider(new ColorDrawable((getResources().getColor(R.color.Silver)))); // set color
|
|
|
234 |
listView.setDividerHeight(2);
|
|
|
235 |
listView.setOverscrollFooter(new ColorDrawable(Color.TRANSPARENT));
|
|
|
236 |
listView.setFooterDividersEnabled(false);
|
|
|
237 |
alert.show();
|
|
|
238 |
}});
|
|
|
239 |
referalCode.setOnClickListener(new View.OnClickListener() {
|
|
|
240 |
@Override
|
|
|
241 |
public void onClick(View v) {
|
|
|
242 |
|
|
|
243 |
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
244 |
inputMethodManager.showSoftInput(referalCode, InputMethodManager.SHOW_IMPLICIT);
|
|
|
245 |
referalCode.requestFocus();
|
|
|
246 |
}
|
|
|
247 |
});
|
|
|
248 |
|
|
|
249 |
|
|
|
250 |
JSONObject props = new JSONObject();
|
|
|
251 |
try {
|
|
|
252 |
props.put("Referrer", "Referrer Screen");
|
|
|
253 |
mixpanel.track("Referrer Screen", props);
|
|
|
254 |
} catch (JSONException e) {
|
|
|
255 |
|
|
|
256 |
e.printStackTrace();
|
|
|
257 |
}
|
|
|
258 |
type1 = userData.getString("type", null);
|
|
|
259 |
|
|
|
260 |
if (type1 != null && type1.equalsIgnoreCase("google")) {
|
|
|
261 |
mGoogleApiClient = new GoogleApiClient.Builder(this)
|
|
|
262 |
.addConnectionCallbacks(this)
|
|
|
263 |
.addOnConnectionFailedListener(this).addApi(Plus.API)
|
|
|
264 |
.addScope(Plus.SCOPE_PLUS_LOGIN).build();
|
|
|
265 |
mGoogleApiClient.connect();
|
|
|
266 |
}
|
|
|
267 |
|
|
|
268 |
|
|
|
269 |
referrerSend.setOnClickListener(new View.OnClickListener() {
|
|
|
270 |
@Override
|
|
|
271 |
public void onClick(View v) {
|
|
|
272 |
try {
|
|
|
273 |
if (!referalCode.getText().toString().equals("")) {
|
|
|
274 |
new PushReferrerData().execute(referalCode.getText().toString());
|
|
|
275 |
} else if (!selectedPath1.equals("")&& !selectedPath2.equals("")) {
|
|
|
276 |
new UploadImage().execute();
|
|
|
277 |
} else {
|
|
|
278 |
Toast.makeText(getApplicationContext(), "One field is required", Toast.LENGTH_SHORT).show();
|
|
|
279 |
}
|
|
|
280 |
} catch (Exception e) {
|
|
|
281 |
e.printStackTrace();
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
}});
|
|
|
285 |
}
|
|
|
286 |
|
|
|
287 |
public void requestCamera() {
|
|
|
288 |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
289 |
if (checkSelfPermission(Manifest.permission.CAMERA)
|
|
|
290 |
!= PackageManager.PERMISSION_GRANTED) {
|
|
|
291 |
requestPermissions(new String[]{Manifest.permission.CAMERA},
|
|
|
292 |
101);
|
|
|
293 |
}
|
|
|
294 |
}
|
|
|
295 |
}
|
|
|
296 |
|
|
|
297 |
|
|
|
298 |
@Override
|
|
|
299 |
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
300 |
|
|
|
301 |
if (requestCode == REQUEST_CAMERA && resultCode == RESULT_OK) {
|
|
|
302 |
String Photopath = cameraPhoto.getPhotoPath();
|
|
|
303 |
selectedPath1 = Photopath;
|
|
|
304 |
try {
|
|
|
305 |
Bitmap bitmap = ImageLoader.init().from(Photopath).requestSize(512, 512).getBitmap();
|
|
|
306 |
final int sizeInBytes = bitmap.getByteCount();
|
|
|
307 |
Log.d("Tag", String.valueOf(sizeInBytes));
|
|
|
308 |
ivImage.setImageBitmap(bitmap);
|
|
|
309 |
remove.setVisibility(View.VISIBLE);
|
|
|
310 |
} catch (FileNotFoundException e) {
|
|
|
311 |
Toast.makeText(getApplicationContext(), "Error while loading Photo", Toast.LENGTH_LONG).show();
|
|
|
312 |
}
|
|
|
313 |
} else if (requestCode == SELECT_FILE && resultCode == RESULT_OK) {
|
|
|
314 |
Uri selectedImageUri = data.getData();
|
|
|
315 |
galleryPhoto.setPhotoUri(selectedImageUri);
|
|
|
316 |
String Photopath = galleryPhoto.getPath();
|
|
|
317 |
selectedPath1 = Photopath;
|
|
|
318 |
try {
|
|
|
319 |
Bitmap bitmap = ImageLoader.init().from(Photopath).requestSize(512, 512).getBitmap();
|
|
|
320 |
ivImage.setImageBitmap(bitmap);
|
|
|
321 |
remove.setVisibility(View.VISIBLE);
|
|
|
322 |
} catch (FileNotFoundException e) {
|
|
|
323 |
Toast.makeText(getApplicationContext(), "Error while loading Photo", Toast.LENGTH_LONG).show();
|
|
|
324 |
}
|
|
|
325 |
|
|
|
326 |
} else if (requestCode == REQUEST_CAMERA_ONE && resultCode == RESULT_OK) {
|
|
|
327 |
String Photopath = cameraPhoto.getPhotoPath();
|
|
|
328 |
selectedPath2 = Photopath;
|
|
|
329 |
try {
|
|
|
330 |
Bitmap bitmap = ImageLoader.init().from(Photopath).requestSize(512, 512).getBitmap();
|
|
|
331 |
ivImage2.setImageBitmap(bitmap);
|
|
|
332 |
remove2.setVisibility(View.VISIBLE);
|
|
|
333 |
} catch (FileNotFoundException e) {
|
|
|
334 |
Toast.makeText(getApplicationContext(), "Error while loading Photo", Toast.LENGTH_LONG).show();
|
|
|
335 |
}
|
|
|
336 |
|
|
|
337 |
} else if (requestCode == SELECT_FILE_ONE && resultCode == RESULT_OK) {
|
|
|
338 |
Uri selectedImageUri = data.getData();
|
|
|
339 |
galleryPhoto.setPhotoUri(selectedImageUri);
|
|
|
340 |
String Photopath = galleryPhoto.getPath();
|
|
|
341 |
selectedPath2 = Photopath;
|
|
|
342 |
try {
|
|
|
343 |
Bitmap bitmap = ImageLoader.init().from(Photopath).requestSize(512, 512).getBitmap();
|
|
|
344 |
ivImage2.setImageBitmap(bitmap);
|
|
|
345 |
remove2.setVisibility(View.VISIBLE);
|
|
|
346 |
} catch (FileNotFoundException e) {
|
|
|
347 |
Toast.makeText(getApplicationContext(), "Error while loading Photo", Toast.LENGTH_LONG).show();
|
|
|
348 |
}
|
|
|
349 |
}
|
|
|
350 |
|
|
|
351 |
}
|
|
|
352 |
|
|
|
353 |
@Override
|
|
|
354 |
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
355 |
getMenuInflater().inflate(R.menu.menu_referrer, menu);
|
|
|
356 |
return true;
|
|
|
357 |
}
|
|
|
358 |
|
|
|
359 |
@Override
|
|
|
360 |
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
361 |
|
|
|
362 |
int id = item.getItemId();
|
|
|
363 |
if (id == R.id.action_settings) {
|
|
|
364 |
return true;
|
|
|
365 |
}
|
|
|
366 |
return super.onOptionsItemSelected(item);
|
|
|
367 |
}
|
|
|
368 |
|
|
|
369 |
@Override
|
|
|
370 |
public void onConnected(Bundle bundle) {
|
|
|
371 |
|
|
|
372 |
}
|
|
|
373 |
|
|
|
374 |
@Override
|
|
|
375 |
public void onConnectionSuspended(int i) {
|
|
|
376 |
|
|
|
377 |
}
|
|
|
378 |
|
|
|
379 |
|
|
|
380 |
@Override
|
|
|
381 |
public void onClick(View v) {
|
|
|
382 |
if (v == storeDocument) {
|
|
|
383 |
requestCamera();
|
|
|
384 |
Utility.checkPermission(ReferrerActivity.this);
|
|
|
385 |
final CharSequence[] items = {"Take Photo", "Choose from Library",
|
|
|
386 |
"Cancel"};
|
|
|
387 |
|
|
|
388 |
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
389 |
builder.setTitle("Add Photo!");
|
|
|
390 |
builder.setItems(items, new DialogInterface.OnClickListener() {
|
|
|
391 |
@Override
|
|
|
392 |
public void onClick(DialogInterface dialog, int item) {
|
|
|
393 |
boolean result = Utility.checkPermission(ReferrerActivity.this);
|
|
|
394 |
if (items[item].equals("Take Photo")) {
|
|
|
395 |
userChoosenTask = "Take Photo";
|
|
|
396 |
if (result) {
|
|
|
397 |
|
|
|
398 |
try {
|
|
|
399 |
startActivityForResult(cameraPhoto.takePhotoIntent(), REQUEST_CAMERA);
|
|
|
400 |
cameraPhoto.addToGallery();
|
|
|
401 |
} catch (IOException e) {
|
|
|
402 |
Toast.makeText(getApplicationContext(), "Something Wrong while taking photo", Toast.LENGTH_LONG).show();
|
|
|
403 |
}
|
|
|
404 |
}
|
|
|
405 |
} else if (items[item].equals("Choose from Library")) {
|
|
|
406 |
userChoosenTask = "Choose from Library";
|
|
|
407 |
if (result) {
|
|
|
408 |
startActivityForResult(galleryPhoto.openGalleryIntent(), SELECT_FILE);
|
|
|
409 |
}
|
|
|
410 |
} else if (items[item].equals("Cancel")) {
|
|
|
411 |
dialog.dismiss();
|
|
|
412 |
}
|
|
|
413 |
}
|
|
|
414 |
});
|
|
|
415 |
builder.show();
|
|
|
416 |
} else if (v == supportDocument) {
|
|
|
417 |
requestCamera();
|
|
|
418 |
Utility.checkPermission(ReferrerActivity.this);
|
|
|
419 |
|
|
|
420 |
final CharSequence[] items = {"Take Photo", "Choose from Library",
|
|
|
421 |
"Cancel"};
|
|
|
422 |
|
|
|
423 |
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
424 |
builder.setTitle("Add Photo!");
|
|
|
425 |
builder.setItems(items, new DialogInterface.OnClickListener() {
|
|
|
426 |
|
|
|
427 |
@Override
|
|
|
428 |
public void onClick(DialogInterface dialog, int item) {
|
|
|
429 |
boolean result = Utility.checkPermission(ReferrerActivity.this);
|
|
|
430 |
|
|
|
431 |
if (items[item].equals("Take Photo")) {
|
|
|
432 |
userChoosenTask = "Take Photo";
|
|
|
433 |
if (result) {
|
|
|
434 |
try {
|
|
|
435 |
startActivityForResult(cameraPhoto.takePhotoIntent(), REQUEST_CAMERA_ONE);
|
|
|
436 |
cameraPhoto.addToGallery();
|
|
|
437 |
} catch (IOException e) {
|
|
|
438 |
Toast.makeText(getApplicationContext(), "Something Wrong while taking photo", Toast.LENGTH_LONG).show();
|
|
|
439 |
}
|
|
|
440 |
|
|
|
441 |
}
|
|
|
442 |
} else if (items[item].equals("Choose from Library")) {
|
|
|
443 |
userChoosenTask = "Choose from Library";
|
|
|
444 |
if (result) {
|
|
|
445 |
startActivityForResult(galleryPhoto.openGalleryIntent(), SELECT_FILE_ONE);
|
|
|
446 |
}
|
|
|
447 |
} else if (items[item].equals("Cancel")) {
|
|
|
448 |
dialog.dismiss();
|
|
|
449 |
}
|
|
|
450 |
}
|
|
|
451 |
});
|
|
|
452 |
builder.show();
|
|
|
453 |
} else if (v == remove) {
|
|
|
454 |
selectedPath1="";
|
|
|
455 |
ivImage.setImageBitmap(null);
|
|
|
456 |
remove.setVisibility(View.INVISIBLE);
|
|
|
457 |
} else if (v == remove2) {
|
|
|
458 |
ivImage2.setImageBitmap(null);
|
|
|
459 |
selectedPath2="";
|
|
|
460 |
remove2.setVisibility(View.INVISIBLE);
|
|
|
461 |
}
|
|
|
462 |
}
|
|
|
463 |
|
|
|
464 |
@Override
|
|
|
465 |
public void onConnectionFailed(ConnectionResult connectionResult) {
|
|
|
466 |
|
|
|
467 |
}
|
|
|
468 |
|
|
|
469 |
|
|
|
470 |
class UploadImage extends AsyncTask<String, Integer, JSONObject> {
|
|
|
471 |
|
|
|
472 |
@Override
|
|
|
473 |
protected void onPreExecute() {
|
|
|
474 |
super.onPreExecute();
|
|
|
475 |
pd2 = new ProgressDialog(ReferrerActivity.this);
|
|
|
476 |
pd2.setMessage("Please wait...");
|
|
|
477 |
pd2.setCancelable(false);
|
|
|
478 |
pd2.show();
|
|
|
479 |
|
|
|
480 |
}
|
|
|
481 |
|
|
|
482 |
@Override
|
|
|
483 |
protected JSONObject doInBackground(String... arg0) {
|
|
|
484 |
String id = null;
|
|
|
485 |
if (isInternetOn()) {
|
|
|
486 |
byte[] BYTE;
|
|
|
487 |
Bitmap bitmap = null;
|
|
|
488 |
try {
|
|
|
489 |
bitmap = ImageLoader.init().from(selectedPath1).requestSize(512, 512).getBitmap();
|
|
|
490 |
} catch (FileNotFoundException e) {
|
|
|
491 |
e.printStackTrace();
|
|
|
492 |
}
|
|
|
493 |
final int sizeInBytes = bitmap.getByteCount();
|
|
|
494 |
double qualityFactor = 1;
|
|
|
495 |
if (sizeInBytes > 200 * 1024) {
|
|
|
496 |
qualityFactor = Math.cbrt(Math.cbrt((double) sizeInBytes / (double) (200 * 1024)));
|
|
|
497 |
}
|
|
|
498 |
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
499 |
bitmap.compress(Bitmap.CompressFormat.JPEG, (int) (100.0 / qualityFactor), bos);
|
|
|
500 |
BYTE = bos.toByteArray();
|
|
|
501 |
String encodedImage = Base64.encodeToString(BYTE, Base64.DEFAULT);
|
|
|
502 |
Log.d("Tag", encodedImage);
|
|
|
503 |
|
|
|
504 |
Bitmap bitmap2 = null;
|
|
|
505 |
try {
|
|
|
506 |
bitmap2 = ImageLoader.init().from(selectedPath2).requestSize(512, 512).getBitmap();
|
|
|
507 |
} catch (FileNotFoundException e) {
|
|
|
508 |
e.printStackTrace();
|
|
|
509 |
}
|
|
|
510 |
final int sizeInBytes2 = bitmap2.getByteCount();
|
|
|
511 |
double qualityFactors = 1;
|
|
|
512 |
if (sizeInBytes2 > 200 * 1024) {
|
|
|
513 |
qualityFactors = Math.cbrt(Math.cbrt((double) sizeInBytes2 / (double) (200 * 1024)));
|
|
|
514 |
}
|
|
|
515 |
ByteArrayOutputStream boss = new ByteArrayOutputStream();
|
|
|
516 |
bitmap2.compress(Bitmap.CompressFormat.JPEG, (int) (100.0 / qualityFactors), boss);
|
|
|
517 |
BYTE = boss.toByteArray();
|
|
|
518 |
String encodedImage2 = Base64.encodeToString(BYTE, Base64.DEFAULT);
|
|
|
519 |
Log.d("Tag", encodedImage2);
|
|
|
520 |
try {
|
|
|
521 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
522 |
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
|
|
523 |
String updateURL = apiData.getString("useredit.url", "");
|
|
|
524 |
String url = updateURL + userData.getString("id", "");
|
|
|
525 |
nameValuePairs.add(new BasicNameValuePair("id", userData.getString("id", null)));
|
|
|
526 |
nameValuePairs.add(new BasicNameValuePair("storeImage", encodedImage));
|
|
|
527 |
nameValuePairs.add(new BasicNameValuePair("supportDocument", encodedImage2));
|
|
|
528 |
HttpPost httppost = new HttpPost(url);
|
|
|
529 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
530 |
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
|
|
|
531 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
532 |
HttpEntity entity = response.getEntity();
|
|
|
533 |
int status = response.getStatusLine().getStatusCode();
|
|
|
534 |
JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
|
|
|
535 |
return jObjGmail;
|
|
|
536 |
|
|
|
537 |
}
|
|
|
538 |
catch (Exception e) {
|
|
|
539 |
e.printStackTrace();
|
|
|
540 |
|
|
|
541 |
}
|
|
|
542 |
}
|
|
|
543 |
Toast.makeText(getApplicationContext(),"Internet problem",Toast.LENGTH_LONG).show();
|
|
|
544 |
return null;
|
|
|
545 |
}
|
|
|
546 |
|
|
|
547 |
@Override
|
|
|
548 |
protected void onPostExecute(JSONObject result) {
|
|
|
549 |
super.onPostExecute(result);
|
|
|
550 |
pd2.dismiss();
|
|
|
551 |
if(result==null){
|
|
|
552 |
finish();
|
|
|
553 |
}
|
|
|
554 |
try {
|
|
|
555 |
if (result.getBoolean("success")){
|
|
|
556 |
Toast.makeText(getApplicationContext(), "Image Upload Sucessfully", Toast.LENGTH_LONG).show();
|
|
|
557 |
Intent i = new Intent(ReferrerActivity.this, PendingActivity.class);
|
|
|
558 |
startActivity(i);
|
|
|
559 |
} else {
|
|
|
560 |
Toast.makeText(getApplicationContext(), "Error While Uploading", Toast.LENGTH_LONG).show();
|
|
|
561 |
}
|
|
|
562 |
} catch (JSONException e) {
|
|
|
563 |
e.printStackTrace();
|
|
|
564 |
}
|
|
|
565 |
}
|
|
|
566 |
}
|
|
|
567 |
|
|
|
568 |
|
|
|
569 |
class PushReferrerData extends AsyncTask<String, Integer, String> {
|
|
|
570 |
|
|
|
571 |
@Override
|
|
|
572 |
protected void onPreExecute() {
|
|
|
573 |
super.onPreExecute();
|
|
|
574 |
referrerSend.setEnabled(false);
|
|
|
575 |
pd2 = new ProgressDialog(ReferrerActivity.this);
|
|
|
576 |
pd2.setMessage("Please wait...");
|
|
|
577 |
pd2.setCancelable(false);
|
|
|
578 |
pd2.show();
|
|
|
579 |
|
|
|
580 |
}
|
|
|
581 |
|
|
|
582 |
@Override
|
|
|
583 |
protected String doInBackground(String... arg0) {
|
|
|
584 |
String id = null;
|
|
|
585 |
if (isInternetOn()) {
|
|
|
586 |
|
|
|
587 |
try {
|
|
|
588 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
589 |
nameValuePairs = new ArrayList<>();
|
|
|
590 |
String updateURL = apiData.getString("useredit.url", "");
|
|
|
591 |
String url = updateURL + userData.getString("id", "");
|
|
|
592 |
nameValuePairs.add(new BasicNameValuePair("id", userData.getString("id", null)));
|
|
|
593 |
nameValuePairs.add(new BasicNameValuePair("referrer", arg0[0]));
|
|
|
594 |
HttpPost httppost = new HttpPost(url);
|
|
|
595 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
596 |
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
|
|
|
597 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
598 |
HttpEntity entity = response.getEntity();
|
|
|
599 |
int status = response.getStatusLine().getStatusCode();
|
|
|
600 |
JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
|
|
|
601 |
System.out.println("JSON Object in referrer " + jObjGmail.toString());
|
|
|
602 |
String success = jObjGmail.getString("success");
|
|
|
603 |
if (status == 200) {
|
|
|
604 |
inviteDEditor.putString("referrerCode", arg0[0]);
|
|
|
605 |
inviteDEditor.commit();
|
|
|
606 |
Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
|
|
|
607 |
GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
|
|
|
608 |
t.send(new HitBuilders.EventBuilder()
|
|
|
609 |
.setCategory("Referrer ")
|
|
|
610 |
.setAction("Referrer Saved Successfully")
|
|
|
611 |
.setLabel("Referrer for User" + userData.getString("id", null) + " is " + arg0[0])
|
|
|
612 |
.build());
|
|
|
613 |
}
|
|
|
614 |
if (success.equalsIgnoreCase("true")) {
|
|
|
615 |
MixpanelAPI mixpanel = MixpanelAPI.getInstance(getApplicationContext(), ProfitTillConstants.MIX_PANEL_TOKEN);
|
|
|
616 |
JSONObject props = new JSONObject();
|
|
|
617 |
try {
|
|
|
618 |
props.put("Referrer", "Referrer Saved Successfully");
|
|
|
619 |
mixpanel.track("Referrer Saved", props);
|
|
|
620 |
} catch (JSONException e) {
|
|
|
621 |
e.printStackTrace();
|
|
|
622 |
}
|
|
|
623 |
userDataEditor.putString("referralCodeRequired", "false");
|
|
|
624 |
userDataEditor.commit();
|
|
|
625 |
return "true";
|
|
|
626 |
} else {
|
|
|
627 |
userDataEditor.putString("referralCodeRequired", "true");
|
|
|
628 |
userDataEditor.commit();
|
|
|
629 |
return "false";
|
|
|
630 |
}
|
|
|
631 |
|
|
|
632 |
} catch (Exception e) {
|
|
|
633 |
Log.e("Fail 1", e.toString());
|
|
|
634 |
return "false";
|
|
|
635 |
}
|
|
|
636 |
|
|
|
637 |
}
|
|
|
638 |
return null;
|
|
|
639 |
}
|
|
|
640 |
|
|
|
641 |
@Override
|
|
|
642 |
protected void onPostExecute(String result) {
|
|
|
643 |
super.onPostExecute(result);
|
|
|
644 |
pd2.dismiss();
|
|
|
645 |
if (result.equalsIgnoreCase("true")) {
|
|
|
646 |
|
|
|
647 |
new Analytics(ProfitTillConstants.ANALYTICS_URL,
|
|
|
648 |
AnalyticsUtility.getAnalyticsRequest(ReferrerActivity.this, userData.getString("id", ""), "Clicks", "Referrer", "Invite Code Entered"),
|
|
|
649 |
AnalyticsJsonResponse.getAnalyticsRequestInstance(),
|
|
|
650 |
AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(ReferrerActivity.this);
|
|
|
651 |
|
|
|
652 |
if (userData.getString("message", "false").equalsIgnoreCase("true")) {
|
|
|
653 |
nameValuePairs = new ArrayList<NameValuePair>();
|
|
|
654 |
Intent i = new Intent(ReferrerActivity.this, MobileNumber.class);
|
|
|
655 |
i.putExtra("displayView", "7");
|
|
|
656 |
startActivity(i);
|
|
|
657 |
} else {
|
|
|
658 |
if (!(userData.getString("mobileNumber", "").isEmpty())) {
|
|
|
659 |
Intent i = new Intent(ReferrerActivity.this, MobileVerificationFirstTime.class);
|
|
|
660 |
i.putExtra("numberVerification", userData.getString("mobileNumber", ""));
|
|
|
661 |
startActivity(i);
|
|
|
662 |
} else {
|
|
|
663 |
Intent i = new Intent(ReferrerActivity.this, MainActivity.class);
|
|
|
664 |
i.putExtra("displayView", "7");
|
|
|
665 |
startActivity(i);
|
|
|
666 |
|
|
|
667 |
}
|
|
|
668 |
}
|
|
|
669 |
} else {
|
|
|
670 |
referrerSend.setEnabled(true);
|
|
|
671 |
referalCode.setError("Incorrect Code");
|
|
|
672 |
}
|
|
|
673 |
}
|
|
|
674 |
}
|
|
|
675 |
|
|
|
676 |
|
|
|
677 |
|
|
|
678 |
|
|
|
679 |
ProgressDialog pd2;
|
|
|
680 |
|
|
|
681 |
@Override
|
|
|
682 |
public void onBackPressed() {
|
|
|
683 |
new AlertDialog.Builder(this)
|
|
|
684 |
.setIcon(android.R.drawable.ic_dialog_alert)
|
|
|
685 |
.setTitle("Exit!")
|
|
|
686 |
.setMessage("Are you sure you want to sign out?")
|
|
|
687 |
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
|
|
688 |
@Override
|
|
|
689 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
690 |
JSONObject props = new JSONObject();
|
|
|
691 |
try {
|
|
|
692 |
mixpanel.identify(userData.getString("id", null));
|
|
|
693 |
props.put("Screen", "Signing Out");
|
|
|
694 |
mixpanel.track("Signing Out Referrer", props);
|
|
|
695 |
} catch (JSONException e) {
|
|
|
696 |
e.printStackTrace();
|
|
|
697 |
}
|
|
|
698 |
|
|
|
699 |
if (type1.equalsIgnoreCase("facebook")) {
|
|
|
700 |
Log.d("fblogout", "logout");
|
|
|
701 |
if (Session.getActiveSession() != null) {
|
|
|
702 |
Session.getActiveSession().closeAndClearTokenInformation();
|
|
|
703 |
}
|
|
|
704 |
Session.setActiveSession(null);
|
|
|
705 |
userDataEditor.clear().commit();
|
|
|
706 |
startActivity(new Intent(ReferrerActivity.this, LoginActivity.class));
|
|
|
707 |
} else {
|
|
|
708 |
Log.d("gmailLogout", "logout");
|
|
|
709 |
signOutFromGplus();
|
|
|
710 |
if (glogout == true) {
|
|
|
711 |
startActivity(new Intent(ReferrerActivity.this, LoginActivity.class));
|
|
|
712 |
}
|
|
|
713 |
}
|
|
|
714 |
|
|
|
715 |
}
|
|
|
716 |
|
|
|
717 |
})
|
|
|
718 |
.setNegativeButton("No", null)
|
|
|
719 |
.show();
|
|
|
720 |
}
|
|
|
721 |
|
|
|
722 |
public void signOutFromGplus() {
|
|
|
723 |
if (mGoogleApiClient.isConnected()) {
|
|
|
724 |
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
|
|
|
725 |
mGoogleApiClient.disconnect();
|
|
|
726 |
mGoogleApiClient.connect();
|
|
|
727 |
glogout = true;
|
|
|
728 |
userDataEditor.clear().commit();
|
|
|
729 |
} else {
|
|
|
730 |
glogout = false;
|
|
|
731 |
}
|
|
|
732 |
}
|
|
|
733 |
|
|
|
734 |
public final boolean isInternetOn() {
|
|
|
735 |
|
|
|
736 |
ConnectivityManager connection =
|
|
|
737 |
(ConnectivityManager) getSystemService(this.getBaseContext().CONNECTIVITY_SERVICE);
|
|
|
738 |
|
|
|
739 |
if (connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||
|
|
|
740 |
connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||
|
|
|
741 |
connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||
|
|
|
742 |
connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED) {
|
|
|
743 |
return true;
|
|
|
744 |
|
|
|
745 |
} else if (
|
|
|
746 |
connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||
|
|
|
747 |
connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED) {
|
|
|
748 |
return false;
|
|
|
749 |
}
|
|
|
750 |
return false;
|
|
|
751 |
}
|
|
|
752 |
|
|
|
753 |
|
|
|
754 |
class NotificationOpenedData extends AsyncTask<ArrayList<NameValuePair>, Integer, String> {
|
|
|
755 |
|
|
|
756 |
@Override
|
|
|
757 |
protected void onPreExecute() {
|
|
|
758 |
super.onPreExecute();
|
|
|
759 |
|
|
|
760 |
}
|
|
|
761 |
|
|
|
762 |
@Override
|
|
|
763 |
protected String doInBackground(ArrayList<NameValuePair>... arg0) {
|
|
|
764 |
|
|
|
765 |
try {
|
|
|
766 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
767 |
HttpPost httppost = new HttpPost(apiData.getString("notication.data.url", "http://api.profittill.com/pushnotifications/add"));
|
|
|
768 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
769 |
httppost.setEntity(new UrlEncodedFormEntity(arg0[0]));
|
|
|
770 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
771 |
HttpEntity entity = response.getEntity();
|
|
|
772 |
int status = response.getStatusLine().getStatusCode();
|
|
|
773 |
|
|
|
774 |
if (status == 200) {
|
|
|
775 |
Log.d("Notification Opened", "Notication opened and sent to server");
|
|
|
776 |
Log.d("ResponseCode GCM ", status + "");
|
|
|
777 |
} else {
|
|
|
778 |
Log.d("ResponseCode GCM ", status + "");
|
|
|
779 |
}
|
|
|
780 |
|
|
|
781 |
nameValuePairsGcm.clear();
|
|
|
782 |
Log.e("pass 1", "connection success ");
|
|
|
783 |
} catch (Exception e) {
|
|
|
784 |
Log.e("Fail 1", e.toString());
|
|
|
785 |
|
|
|
786 |
}
|
|
|
787 |
return "success";
|
|
|
788 |
}
|
|
|
789 |
|
|
|
790 |
@Override
|
|
|
791 |
protected void onPostExecute(String result) {
|
|
|
792 |
super.onPostExecute(result);
|
|
|
793 |
Log.d("Notification Opened", "Notication opened and login page");
|
|
|
794 |
}
|
|
|
795 |
}
|
|
|
796 |
|
|
|
797 |
}
|
|
|
798 |
|
|
|
799 |
|