Subversion Repositories SmartDukaan

Rev

Rev 14991 | Go to most recent revision | 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.ProgressDialog;
4
import android.content.Context;
5
import android.content.Intent;
6
import android.content.SharedPreferences;
7
import android.graphics.Bitmap;
8
import android.graphics.BitmapShader;
9
import android.graphics.Canvas;
10
import android.graphics.Paint;
11
import android.net.ConnectivityManager;
12
import android.os.AsyncTask;
13
import android.os.Bundle;
14
import android.app.Fragment;
15
import android.text.TextUtils;
16
import android.util.Base64;
17
import android.util.Log;
18
import android.view.KeyEvent;
19
import android.view.LayoutInflater;
20
import android.view.View;
21
import android.view.ViewGroup;
22
import android.webkit.WebView;
23
import android.widget.Button;
24
import android.widget.EditText;
25
import android.widget.ImageView;
26
import android.widget.TextView;
27
import android.widget.Toast;
28
 
29
import com.google.android.gms.analytics.HitBuilders;
30
import com.google.android.gms.analytics.Tracker;
31
import com.mixpanel.android.mpmetrics.MixpanelAPI;
32
import com.saholic.profittill.Constants.ProfitTillConstants;
33
import com.saholic.profittill.R;
34
import com.squareup.picasso.Picasso;
35
import com.squareup.picasso.Transformation;
36
import com.testin.agent.TestinAgent;
37
 
38
import org.apache.http.HttpEntity;
39
import org.apache.http.HttpResponse;
40
import org.apache.http.NameValuePair;
41
import org.apache.http.client.ClientProtocolException;
42
import org.apache.http.client.HttpClient;
43
import org.apache.http.client.entity.UrlEncodedFormEntity;
44
import org.apache.http.client.methods.HttpGet;
45
import org.apache.http.client.methods.HttpPost;
46
import org.apache.http.entity.StringEntity;
47
import org.apache.http.impl.client.DefaultHttpClient;
48
import org.apache.http.message.BasicNameValuePair;
49
import org.apache.http.util.EntityUtils;
50
import org.json.JSONException;
51
import org.json.JSONObject;
52
 
53
import java.io.IOException;
54
import java.util.ArrayList;
55
 
56
public class MyProfile extends Fragment {
57
    SharedPreferences userData;
58
    SharedPreferences apiData;
59
    SharedPreferences.Editor userDataEditor;
60
    SharedPreferences.Editor apiSettingsEditor;
61
    ImageView profileImage;
62
    TextView phoneNumberMyProfileVerifyStatus,phoneNumberMyProfileEdit,profileNameMyProfileEdit,addressLine1MyProfileEdit,addressLine2MyProfileEdit,cityMyProfileEdit,pincodeMyProfileEdit;
63
    TextView profileName;
64
    EditText phoneNumberMyProfile,profileNameMyProfile,addressLine1MyProfile,addressLine2MyProfile,cityMyProfile,pincodeMyProfile;
65
    Button profileEdit,profileSave;
66
    ArrayList<NameValuePair> nameValuePairsProfile;
67
    public MyProfile() {
68
 
69
    }
70
 
71
 
72
    @Override
73
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
74
                             Bundle savedInstanceState) {
75
        // Inflate the layout for this fragment
76
        View rootView = inflater.inflate(R.layout.fragment_my_profile, container, false);
77
        TestinAgent.init(getActivity());
78
        MixpanelAPI mixpanel = MixpanelAPI.getInstance(getActivity(), ProfitTillConstants.MIX_PANEL_TOKEN);
79
 
80
        Tracker t = ((GoogleAnalyticsTracker) getActivity().getApplicationContext()).getTracker(
81
                GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
82
        t.setScreenName("Profile Screen");
83
        t.send(new HitBuilders.ScreenViewBuilder().build());
84
 
85
        profileImage=(ImageView)rootView.findViewById(R.id.profilePicture);
86
 
87
        phoneNumberMyProfile = (EditText)rootView.findViewById(R.id.phoneNumberMyProfile);
88
        profileNameMyProfile = (EditText)rootView.findViewById(R.id.profileNameMyProfile);
89
        addressLine1MyProfile = (EditText)rootView.findViewById(R.id.addressLine1MyProfile);
90
        addressLine2MyProfile = (EditText)rootView.findViewById(R.id.addressLine2MyProfile);
91
        cityMyProfile = (EditText)rootView.findViewById(R.id.cityMyProfile);
92
        pincodeMyProfile =(EditText) rootView.findViewById(R.id.pincodeMyProfile);
93
 
94
 
95
        phoneNumberMyProfileEdit=(TextView) rootView.findViewById(R.id.phoneNumberMyProfileEdit);
96
        profileNameMyProfileEdit=(TextView) rootView.findViewById(R.id.profileNameMyProfileEdit);
97
        addressLine1MyProfileEdit=(TextView) rootView.findViewById(R.id.addressLine1MyProfileEdit);
98
        addressLine2MyProfileEdit=(TextView) rootView.findViewById(R.id.addressLine2MyProfileEdit);
99
        cityMyProfileEdit=(TextView) rootView.findViewById(R.id.cityMyProfileEdit);
100
        pincodeMyProfileEdit=(TextView) rootView.findViewById(R.id.pincodeMyProfileEdit);
101
 
102
 
103
        phoneNumberMyProfileVerifyStatus=(TextView) rootView.findViewById(R.id.phoneNumberMyProfileVerifyStatus);
104
 
105
 
106
        profileSave=(Button) rootView.findViewById(R.id.profileSave);
107
 
108
        userData = getActivity().getSharedPreferences("User_Data", Context.MODE_PRIVATE);
109
        apiData = getActivity().getSharedPreferences("API_Data", Context.MODE_PRIVATE);
110
        userDataEditor = userData.edit();
111
        apiSettingsEditor = apiData.edit();
112
        TestinAgent.setUserInfo(userData.getString("id", ""));
113
        JSONObject props = new JSONObject();
114
        try {
115
            mixpanel.identify(userData.getString("id",null));
116
            props.put("Screen", "My Profile");
117
            mixpanel.track("My Profile", props);
118
        } catch (JSONException e) {
119
            e.printStackTrace();
120
        }
121
        editTextDisabled();
122
        if(isInternetOn()){
123
            pd = new ProgressDialog(getActivity());
124
            pd.setTitle("Please wait");
125
            pd.setMessage("Fetching Profile Information..");
126
            pd.show();
127
            new  fetchUserData().execute();
128
        }
129
        else{
130
            SearchFragment nextFrag= new SearchFragment();
131
            Bundle args = new Bundle();
132
            args.putString("finishingurl","");
133
            args.putString("fragmentNumber","10");
134
            nextFrag.setArguments(args);
135
            getActivity().getFragmentManager().beginTransaction()
136
                    .replace(R.id.frame_container, nextFrag)
137
                    .addToBackStack(null)
138
                    .commit();
139
       }
140
        phoneNumberMyProfile.setOnClickListener(new View.OnClickListener() {
141
            @Override
142
            public void onClick(View v) {
143
                phoneNumberMyProfile.setFocusable(true);
144
                phoneNumberMyProfile.setClickable(true);
145
                phoneNumberMyProfile.setFocusableInTouchMode(true);
146
                phoneNumberMyProfile.requestFocus();
147
 
148
                profileNameMyProfile.setFocusable(false);
149
                profileNameMyProfile.setClickable(false);
150
                addressLine1MyProfile.setFocusable(false);
151
                addressLine1MyProfile.setClickable(false);
152
                addressLine2MyProfile.setFocusable(false);
153
                addressLine2MyProfile.setClickable(false);
154
                cityMyProfile.setFocusable(false);
155
                cityMyProfile.setClickable(false);
156
                pincodeMyProfile.setFocusable(false);
157
                pincodeMyProfile.setClickable(false);
158
            }
159
        });
160
 
161
        profileNameMyProfile.setOnClickListener(new View.OnClickListener() {
162
            @Override
163
            public void onClick(View v) {
164
                profileNameMyProfile.setFocusable(true);
165
                profileNameMyProfile.setClickable(true);
166
                profileNameMyProfile.setFocusableInTouchMode(true);
167
                profileNameMyProfile.requestFocus();
168
 
169
                phoneNumberMyProfile.setFocusable(false);
170
                phoneNumberMyProfile.setClickable(false);
171
                addressLine1MyProfile.setFocusable(false);
172
                addressLine1MyProfile.setClickable(false);
173
                addressLine2MyProfile.setFocusable(false);
174
                addressLine2MyProfile.setClickable(false);
175
                cityMyProfile.setFocusable(false);
176
                cityMyProfile.setClickable(false);
177
                pincodeMyProfile.setFocusable(false);
178
                pincodeMyProfile.setClickable(false);
179
            }
180
        });
181
 
182
        addressLine1MyProfile.setOnClickListener(new View.OnClickListener() {
183
            @Override
184
            public void onClick(View v) {
185
                addressLine1MyProfile.setFocusable(true);
186
                addressLine1MyProfile.setClickable(true);
187
                addressLine1MyProfile.setFocusableInTouchMode(true);
188
                addressLine1MyProfile.requestFocus();
189
 
190
                phoneNumberMyProfile.setFocusable(false);
191
                phoneNumberMyProfile.setClickable(false);
192
                profileNameMyProfile.setFocusable(false);
193
                profileNameMyProfile.setClickable(false);
194
                addressLine2MyProfile.setFocusable(false);
195
                addressLine2MyProfile.setClickable(false);
196
                cityMyProfile.setFocusable(false);
197
                cityMyProfile.setClickable(false);
198
                pincodeMyProfile.setFocusable(false);
199
                pincodeMyProfile.setClickable(false);
200
            }
201
        });
202
 
203
 
204
        addressLine2MyProfile.setOnClickListener(new View.OnClickListener() {
205
            @Override
206
            public void onClick(View v) {
207
                addressLine2MyProfile.setFocusable(true);
208
                addressLine2MyProfile.setClickable(true);
209
                addressLine2MyProfile.setFocusableInTouchMode(true);
210
                addressLine2MyProfile.requestFocus();
211
 
212
                phoneNumberMyProfile.setFocusable(false);
213
                phoneNumberMyProfile.setClickable(false);
214
                profileNameMyProfile.setFocusable(false);
215
                profileNameMyProfile.setClickable(false);
216
                addressLine1MyProfile.setFocusable(false);
217
                addressLine1MyProfile.setClickable(false);
218
                cityMyProfile.setFocusable(false);
219
                cityMyProfile.setClickable(false);
220
                pincodeMyProfile.setFocusable(false);
221
                pincodeMyProfile.setClickable(false);
222
            }
223
        });
224
 
225
        cityMyProfile.setOnClickListener(new View.OnClickListener() {
226
            @Override
227
            public void onClick(View v) {
228
                cityMyProfile.setFocusable(true);
229
                cityMyProfile.setClickable(true);
230
                cityMyProfile.setFocusableInTouchMode(true);
231
                cityMyProfile.requestFocus();
232
 
233
                phoneNumberMyProfile.setFocusable(false);
234
                phoneNumberMyProfile.setClickable(false);
235
                profileNameMyProfile.setFocusable(false);
236
                profileNameMyProfile.setClickable(false);
237
                addressLine1MyProfile.setFocusable(false);
238
                addressLine1MyProfile.setClickable(false);
239
                addressLine2MyProfile.setFocusable(false);
240
                addressLine2MyProfile.setClickable(false);
241
                pincodeMyProfile.setFocusable(false);
242
                pincodeMyProfile.setClickable(false);
243
            }
244
        });
245
 
246
 
247
        pincodeMyProfile.setOnClickListener(new View.OnClickListener() {
248
            @Override
249
            public void onClick(View v) {
250
                pincodeMyProfile.setFocusable(true);
251
                pincodeMyProfile.setClickable(true);
252
                pincodeMyProfile.setFocusableInTouchMode(true);
253
                pincodeMyProfile.requestFocus();
254
 
255
                phoneNumberMyProfile.setFocusable(false);
256
                phoneNumberMyProfile.setClickable(false);
257
                profileNameMyProfile.setFocusable(false);
258
                profileNameMyProfile.setClickable(false);
259
                addressLine1MyProfile.setFocusable(false);
260
                addressLine1MyProfile.setClickable(false);
261
                addressLine2MyProfile.setFocusable(false);
262
                addressLine2MyProfile.setClickable(false);
263
                cityMyProfile.setFocusable(false);
264
                cityMyProfile.setClickable(false);
265
            }
266
        });
267
 
268
        phoneNumberMyProfileEdit.setOnClickListener(new View.OnClickListener() {
269
            @Override
270
            public void onClick(View v) {
271
                phoneNumberMyProfile.setFocusable(true);
272
                phoneNumberMyProfile.setClickable(true);
273
                phoneNumberMyProfile.setFocusableInTouchMode(true);
274
                phoneNumberMyProfile.setCursorVisible(true);
275
                phoneNumberMyProfile.requestFocus();
276
 
277
                profileNameMyProfile.setFocusable(false);
278
                profileNameMyProfile.setClickable(false);
279
                addressLine1MyProfile.setFocusable(false);
280
                addressLine1MyProfile.setClickable(false);
281
                addressLine2MyProfile.setFocusable(false);
282
                addressLine2MyProfile.setClickable(false);
283
                cityMyProfile.setFocusable(false);
284
                cityMyProfile.setClickable(false);
285
                pincodeMyProfile.setFocusable(false);
286
                pincodeMyProfile.setClickable(false);
287
            }
288
        });
289
 
290
       profileNameMyProfileEdit.setOnClickListener(new View.OnClickListener() {
291
            @Override
292
            public void onClick(View v) {
293
                profileNameMyProfile.setFocusable(true);
294
                profileNameMyProfile.setClickable(true);
295
                profileNameMyProfile.setFocusableInTouchMode(true);
296
                profileNameMyProfile.requestFocus();
297
 
298
                phoneNumberMyProfile.setFocusable(false);
299
                phoneNumberMyProfile.setClickable(false);
300
                addressLine1MyProfile.setFocusable(false);
301
                addressLine1MyProfile.setClickable(false);
302
                addressLine2MyProfile.setFocusable(false);
303
                addressLine2MyProfile.setClickable(false);
304
                cityMyProfile.setFocusable(false);
305
                cityMyProfile.setClickable(false);
306
                pincodeMyProfile.setFocusable(false);
307
                pincodeMyProfile.setClickable(false);
308
            }
309
        });
310
 
311
        addressLine1MyProfileEdit.setOnClickListener(new View.OnClickListener() {
312
            @Override
313
            public void onClick(View v) {
314
                addressLine1MyProfile.setFocusable(true);
315
                addressLine1MyProfile.setClickable(true);
316
                addressLine1MyProfile.setFocusableInTouchMode(true);
317
                addressLine1MyProfile.requestFocus();
318
 
319
                phoneNumberMyProfile.setFocusable(false);
320
                phoneNumberMyProfile.setClickable(false);
321
                profileNameMyProfile.setFocusable(false);
322
                profileNameMyProfile.setClickable(false);
323
                addressLine2MyProfile.setFocusable(false);
324
                addressLine2MyProfile.setClickable(false);
325
                cityMyProfile.setFocusable(false);
326
                cityMyProfile.setClickable(false);
327
                pincodeMyProfile.setFocusable(false);
328
                pincodeMyProfile.setClickable(false);
329
            }
330
        });
331
 
332
        addressLine2MyProfileEdit.setOnClickListener(new View.OnClickListener() {
333
            @Override
334
            public void onClick(View v) {
335
                addressLine2MyProfile.setFocusable(true);
336
                addressLine2MyProfile.setClickable(true);
337
                addressLine2MyProfile.setFocusableInTouchMode(true);
338
                addressLine2MyProfile.requestFocus();
339
 
340
                phoneNumberMyProfile.setFocusable(false);
341
                phoneNumberMyProfile.setClickable(false);
342
                profileNameMyProfile.setFocusable(false);
343
                profileNameMyProfile.setClickable(false);
344
                addressLine1MyProfile.setFocusable(false);
345
                addressLine1MyProfile.setClickable(false);
346
                cityMyProfile.setFocusable(false);
347
                cityMyProfile.setClickable(false);
348
                pincodeMyProfile.setFocusable(false);
349
                pincodeMyProfile.setClickable(false);
350
 
351
            }
352
        });
353
 
354
 
355
        cityMyProfileEdit.setOnClickListener(new View.OnClickListener() {
356
            @Override
357
            public void onClick(View v) {
358
                cityMyProfile.setFocusable(true);
359
                cityMyProfile.setClickable(true);
360
                cityMyProfile.setFocusableInTouchMode(true);
361
                cityMyProfile.requestFocus();
362
 
363
                phoneNumberMyProfile.setFocusable(false);
364
                phoneNumberMyProfile.setClickable(false);
365
                profileNameMyProfile.setFocusable(false);
366
                profileNameMyProfile.setClickable(false);
367
                addressLine1MyProfile.setFocusable(false);
368
                addressLine1MyProfile.setClickable(false);
369
                addressLine2MyProfile.setFocusable(false);
370
                addressLine2MyProfile.setClickable(false);
371
                pincodeMyProfile.setFocusable(false);
372
                pincodeMyProfile.setClickable(false);
373
            }
374
        });
375
 
376
        pincodeMyProfileEdit.setOnClickListener(new View.OnClickListener() {
377
            @Override
378
            public void onClick(View v) {
379
                pincodeMyProfile.setFocusable(true);
380
                pincodeMyProfile.setClickable(true);
381
                pincodeMyProfile.setFocusableInTouchMode(true);
382
                pincodeMyProfile.requestFocus();
383
 
384
                phoneNumberMyProfile.setFocusable(false);
385
                phoneNumberMyProfile.setClickable(false);
386
                profileNameMyProfile.setFocusable(false);
387
                profileNameMyProfile.setClickable(false);
388
                addressLine1MyProfile.setFocusable(false);
389
                addressLine1MyProfile.setClickable(false);
390
                addressLine2MyProfile.setFocusable(false);
391
                addressLine2MyProfile.setClickable(false);
392
                cityMyProfile.setFocusable(false);
393
                cityMyProfile.setClickable(false);
394
            }
395
        });
396
 
397
 
398
        profileSave.setOnClickListener(new View.OnClickListener() {
399
            @Override
400
            public void onClick(View v) {
401
 
402
                if((phoneNumberMyProfile.getText().toString().length()==10 || phoneNumberMyProfile.getText().toString().isEmpty()) && (pincodeMyProfile.getText().toString().length()==6 || pincodeMyProfile.getText().toString().isEmpty())) {
403
                    if (isInternetOn()) {
404
                        nameValuePairsProfile = new ArrayList<NameValuePair>();
405
                        nameValuePairsProfile.add(new BasicNameValuePair("id", userData.getString("id", null)));
406
                        nameValuePairsProfile.add(new BasicNameValuePair("mobile_number", phoneNumberMyProfile.getText().toString()));
407
                        nameValuePairsProfile.add(new BasicNameValuePair("address_line_1", addressLine1MyProfile.getText().toString()));
408
                        nameValuePairsProfile.add(new BasicNameValuePair("address_line_2", addressLine2MyProfile.getText().toString()));
409
                        nameValuePairsProfile.add(new BasicNameValuePair("city", cityMyProfile.getText().toString()));
410
                        nameValuePairsProfile.add(new BasicNameValuePair("pincode", pincodeMyProfile.getText().toString()));
411
                        nameValuePairsProfile.add(new BasicNameValuePair("first_name", profileNameMyProfile.getText().toString()));
412
                        new PushDataProfile().execute();
413
                    } else {
414
                        Toast.makeText(getActivity(), "Sorry could not update the details. Please try again later", Toast.LENGTH_SHORT).show();
415
                    }
416
                }else if(phoneNumberMyProfile.getText().toString().length()!=10){
417
                    Toast.makeText(getActivity(), "Mobile Number not valid", Toast.LENGTH_SHORT).show();
418
                }else if(pincodeMyProfile.getText().toString().length()!=6){
419
                    Toast.makeText(getActivity(), "Pincode not valid", Toast.LENGTH_SHORT).show();
420
                }
421
            }
422
        });
423
        rootView.setOnKeyListener(new View.OnKeyListener() {
424
            @Override
425
            public boolean onKey(View v, int keyCode, KeyEvent event) {
426
                if(event.getAction() == KeyEvent.ACTION_DOWN){
427
                    switch(keyCode) {
428
                        case KeyEvent.KEYCODE_BACK:
429
                            Intent i = new Intent(getActivity(), MainActivity.class);
430
                            i.putExtra("displayView", "0");
431
                            startActivity(i);
432
                            return true;
433
                    }
434
                }
435
                return false;
436
            }
437
        });
438
        return rootView;
439
 
440
    }
441
 
442
   private void editTextDisabled(){
443
            phoneNumberMyProfile.setFocusable(false);
444
            phoneNumberMyProfile.setClickable(false);
445
 
446
            profileNameMyProfile.setFocusable(false);
447
            profileNameMyProfile.setClickable(false);
448
 
449
            addressLine1MyProfile.setFocusable(false);
450
            addressLine1MyProfile.setClickable(false);
451
 
452
            addressLine2MyProfile.setFocusable(false);
453
            addressLine2MyProfile.setClickable(false);
454
 
455
            cityMyProfile.setFocusable(false);
456
            cityMyProfile.setClickable(false);
457
 
458
            pincodeMyProfile.setFocusable(false);
459
            pincodeMyProfile.setClickable(false);
460
 
461
    }
462
 
463
    @Override
464
    public void onViewCreated(View view, Bundle savedInstanceState) {
465
        super.onViewCreated(view, savedInstanceState);
466
    }
467
 
468
 
469
    class fetchUserData extends AsyncTask<String, Integer, JSONObject> {
470
 
471
        @Override
472
        protected void onPreExecute() {
473
            super.onPreExecute();
474
        }
475
 
476
        @Override
477
        protected JSONObject doInBackground(String... arg0) {
478
            HttpClient httpclient = new DefaultHttpClient();
479
            try {
480
                String fetchUrl = apiData.getString("userprofile.url",null)+"?user_id="+ userData.getString("id",null);
481
                HttpGet httppost = new HttpGet(fetchUrl);
482
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
483
                HttpResponse response = httpclient.execute(httppost);
484
 
485
                HttpEntity entity = response.getEntity();
486
                int status = response.getStatusLine().getStatusCode();
487
                JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
488
                System.out.println(jObjGmail.toString());
489
 
490
                return jObjGmail;
491
 
492
 
493
            } catch (ClientProtocolException e) {
494
                Log.e("data","data " + e.getMessage());
495
                return null;
496
            } catch (IOException e) {
497
                Log.e("data","data " + e.getMessage());
498
                return null;
499
            }catch (Exception e){
500
                Log.e("data","data " + e.getMessage());
501
                return null;
502
            }
503
        }
504
 
505
        @Override
506
        protected void onPostExecute(JSONObject result) {
507
            super.onPostExecute(result);
508
            if(result==null){
509
                pd.dismiss();
510
            }else {
511
                try {
512
                    if (result.getString("first_name") == "null") {
513
 
514
                    } else {
515
                        profileNameMyProfile.setText(result.getString("first_name").toString());
516
                    }
517
                    if (result.getString("mobile_number") == "null") {
518
 
519
                    } else {
520
                        phoneNumberMyProfile.setText(result.getString("mobile_number").toString());
521
                    }
522
                    if (result.getString("address_line_1") == "null") {
523
 
524
                    } else {
525
                        addressLine1MyProfile.setText(result.getString("address_line_1").toString());
526
                    }
527
                    if (result.getString("address_line_2") == "null") {
528
 
529
                    } else {
530
                        addressLine2MyProfile.setText(result.getString("address_line_2").toString());
531
                    }
532
                    if (result.getString("city") == "null") {
533
 
534
                    } else {
535
                        cityMyProfile.setText(result.getString("city").toString());
536
                    }
537
                    if (result.getString("pincode") == "null" || result.getString("pincode") == "0") {
538
 
539
                    } else {
540
                        pincodeMyProfile.setText(result.getString("pincode").toString());
541
                    }
542
                    if (result.getString("profile_pic").equalsIgnoreCase("null")) {
543
                            profileImage.setImageResource(R.drawable.noimageavailable);
544
                            profileImage.setMaxHeight(300);
545
                            profileImage.setMaxWidth(300);
546
                        } else if (userData.getString("type", null).equalsIgnoreCase("google")) {
547
                            String profileImageUrl = result.getString("profile_pic");
548
                            String x = profileImageUrl.split("sz=")[1];
549
                            String updatedUrl = profileImageUrl.replace("sz=" + x, "sz=300");
550
                            Picasso.with(getActivity())
551
                                    .load(updatedUrl)
552
                                    .transform(new CircleTransform())
553
                                    .into(profileImage);
554
                        } else if (userData.getString("type", null).equalsIgnoreCase("facebook")) {
555
                            String profileImageUrl = result.getString("profile_pic").toString();
556
                            String replaceString = profileImageUrl.replace("http", "https");
557
                            String appendDimen = "?&height=300&type=normal&width=300";
558
                            String updatedUrl = replaceString.concat(appendDimen);
559
 
560
                            Picasso.with(getActivity())
561
                                    .load(updatedUrl)
562
                                    .transform(new CircleTransform())
563
                                    .into(profileImage);
564
                            //Toast.makeText(getActivity(),"facebook "+profileImageUrl,Toast.LENGTH_SHORT).show();
565
                        } else {
566
                            profileImage.setImageResource(R.drawable.noimageavailable);
567
                            profileImage.setMaxHeight(300);
568
                            profileImage.setMaxWidth(300);
569
                        }
570
 
571
                    if (result.getString("mobile_verified") == "true") {
572
                        phoneNumberMyProfileVerifyStatus.setText("Verified");
573
                        /*phoneNumberMyProfileVerifyStatus.setClickable(true);
574
                        phoneNumberMyProfileVerifyStatus.setOnClickListener(new View.OnClickListener() {
575
                            @Override
576
                            public void onClick(View v) {
577
                                Intent i = new Intent(getActivity(),MObileNumberVerificationActivity.class);
578
                                i.putExtra("numberVerification",phoneNumberMyProfile.getText().toString());
579
                                startActivity(i);
580
                            }
581
                        });*/
582
                    } else {
583
                        phoneNumberMyProfileVerifyStatus.setText("Verify Now to get Cashback");
584
                        phoneNumberMyProfileVerifyStatus.setClickable(true);
585
                        if (isInternetOn()) {
586
                            if (phoneNumberMyProfile.getText().toString().isEmpty() || phoneNumberMyProfile.getText().toString().length() != 10) {
587
                                Toast.makeText(getActivity(), "Please Enter a number to be verified", Toast.LENGTH_SHORT).show();
588
                            } else {
589
                                phoneNumberMyProfileVerifyStatus.setOnClickListener(new View.OnClickListener() {
590
                                    @Override
591
                                    public void onClick(View v) {
592
                                        Intent i = new Intent(getActivity(), MObileNumberVerificationActivity.class);
593
                                        i.putExtra("numberVerification", phoneNumberMyProfile.getText().toString());
594
                                        startActivity(i);
595
                                    }
596
                                });
597
                            }
598
                        } else {
599
                            Toast.makeText(getActivity(), "No internet connection.Phone number could not be verified", Toast.LENGTH_SHORT).show();
600
                        }
601
                    }
602
 
603
                    pd.dismiss();
604
                } catch (JSONException e) {
605
                    e.printStackTrace();
606
                }
607
            }
608
        }
609
    }
610
 
611
    public class CircleTransform implements Transformation {
612
        @Override
613
        public Bitmap transform(Bitmap source) {
614
            int size = Math.min(source.getWidth(), source.getHeight());
615
 
616
            int x = (source.getWidth() - size) / 2;
617
            int y = (source.getHeight() - size) / 2;
618
 
619
            Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
620
            if (squaredBitmap != source) {
621
                source.recycle();
622
            }
623
 
624
            Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());
625
 
626
            Canvas canvas = new Canvas(bitmap);
627
            Paint paint = new Paint();
628
            BitmapShader shader = new BitmapShader(squaredBitmap,
629
                    BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
630
            paint.setShader(shader);
631
            paint.setAntiAlias(true);
632
 
633
            float r = size / 2f;
634
            canvas.drawCircle(r, r, r, paint);
635
 
636
            squaredBitmap.recycle();
637
            return bitmap;
638
        }
639
 
640
        @Override
641
        public String key() {
642
            return "circle";
643
        }
644
    }
645
 
646
    ProgressDialog pd = null;
647
 
648
    public final boolean isInternetOn() {
649
 
650
        ConnectivityManager connec =
651
                (ConnectivityManager)getActivity().getSystemService(getActivity().getBaseContext().CONNECTIVITY_SERVICE);
652
 
653
        if ( connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||
654
                connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||
655
                connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||
656
                connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED ) {
657
 
658
            return true;
659
 
660
        } else if (
661
                connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||
662
                        connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED  ) {
663
            return false;
664
        }
665
        return false;
666
    }
667
    @Override
668
    public void onResume() {
669
        super.onResume();
670
        getView().setFocusableInTouchMode(true);
671
        getView().requestFocus();
672
        getView().setOnKeyListener(new View.OnKeyListener() {
673
            @Override
674
            public boolean onKey(View v, int keyCode, KeyEvent event) {
675
 
676
                if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK){
677
                    Intent i = new Intent(getActivity(), MainActivity.class);
678
                    i.putExtra("displayView", "0");
679
                    startActivity(i);
680
                    return true;
681
                }
682
                return false;
683
            }
684
        });
685
    }
686
 
687
 
688
 
689
    class PushDataProfile extends AsyncTask<String, Integer, String> {
690
 
691
        @Override
692
        protected void onPreExecute() {
693
            super.onPreExecute();
694
        }
695
 
696
        @Override
697
        protected String doInBackground(String... arg0) {
698
            HttpClient httpclient = new DefaultHttpClient();
699
            try {
700
 
701
                String fetchUrl = apiData.getString("useredit.url",null)+ userData.getString("id",null);
702
                HttpPost httppost = new HttpPost(fetchUrl);
703
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
704
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairsProfile));
705
                HttpResponse response = httpclient.execute(httppost);
706
                HttpEntity entity = response.getEntity();
707
                return "success";
708
            } catch (ClientProtocolException e) {
709
                return "failure";
710
            } catch (IOException e) {
711
                return "failure";
712
            }catch (Exception e){
713
                return "failure";
714
            }
715
        }
716
 
717
        @Override
718
        protected void onPostExecute(String result) {
719
            Intent i = new Intent(getActivity(),MainActivity.class);
720
            i.putExtra("displayView","15");
721
            startActivity(i);
722
            super.onPostExecute(result);
723
        }
724
    }
725
}