Subversion Repositories SmartDukaan

Rev

Rev 14991 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.saholic.profittill.main;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.net.ConnectivityManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Fragment;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;
import com.mixpanel.android.mpmetrics.MixpanelAPI;
import com.saholic.profittill.Constants.ProfitTillConstants;
import com.saholic.profittill.R;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Transformation;
import com.testin.agent.TestinAgent;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;

public class MyProfile extends Fragment {
    SharedPreferences userData;
    SharedPreferences apiData;
    SharedPreferences.Editor userDataEditor;
    SharedPreferences.Editor apiSettingsEditor;
    ImageView profileImage;
    TextView phoneNumberMyProfileVerifyStatus,phoneNumberMyProfileEdit,profileNameMyProfileEdit,addressLine1MyProfileEdit,addressLine2MyProfileEdit,cityMyProfileEdit,pincodeMyProfileEdit;
    TextView profileName;
    EditText phoneNumberMyProfile,profileNameMyProfile,addressLine1MyProfile,addressLine2MyProfile,cityMyProfile,pincodeMyProfile;
    Button profileEdit,profileSave;
    ArrayList<NameValuePair> nameValuePairsProfile;
    public MyProfile() {

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View rootView = inflater.inflate(R.layout.fragment_my_profile, container, false);
        TestinAgent.init(getActivity());
        MixpanelAPI mixpanel = MixpanelAPI.getInstance(getActivity(), ProfitTillConstants.MIX_PANEL_TOKEN);

        Tracker t = ((GoogleAnalyticsTracker) getActivity().getApplicationContext()).getTracker(
                GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
        t.setScreenName("Profile Screen");
        t.send(new HitBuilders.ScreenViewBuilder().build());

        profileImage=(ImageView)rootView.findViewById(R.id.profilePicture);

        phoneNumberMyProfile = (EditText)rootView.findViewById(R.id.phoneNumberMyProfile);
        profileNameMyProfile = (EditText)rootView.findViewById(R.id.profileNameMyProfile);
        addressLine1MyProfile = (EditText)rootView.findViewById(R.id.addressLine1MyProfile);
        addressLine2MyProfile = (EditText)rootView.findViewById(R.id.addressLine2MyProfile);
        cityMyProfile = (EditText)rootView.findViewById(R.id.cityMyProfile);
        pincodeMyProfile =(EditText) rootView.findViewById(R.id.pincodeMyProfile);


        phoneNumberMyProfileEdit=(TextView) rootView.findViewById(R.id.phoneNumberMyProfileEdit);
        profileNameMyProfileEdit=(TextView) rootView.findViewById(R.id.profileNameMyProfileEdit);
        addressLine1MyProfileEdit=(TextView) rootView.findViewById(R.id.addressLine1MyProfileEdit);
        addressLine2MyProfileEdit=(TextView) rootView.findViewById(R.id.addressLine2MyProfileEdit);
        cityMyProfileEdit=(TextView) rootView.findViewById(R.id.cityMyProfileEdit);
        pincodeMyProfileEdit=(TextView) rootView.findViewById(R.id.pincodeMyProfileEdit);


        phoneNumberMyProfileVerifyStatus=(TextView) rootView.findViewById(R.id.phoneNumberMyProfileVerifyStatus);


        profileSave=(Button) rootView.findViewById(R.id.profileSave);

        userData = getActivity().getSharedPreferences("User_Data", Context.MODE_PRIVATE);
        apiData = getActivity().getSharedPreferences("API_Data", Context.MODE_PRIVATE);
        userDataEditor = userData.edit();
        apiSettingsEditor = apiData.edit();
        TestinAgent.setUserInfo(userData.getString("id", ""));
        JSONObject props = new JSONObject();
        try {
            mixpanel.identify(userData.getString("id",null));
            props.put("Screen", "My Profile");
            mixpanel.track("My Profile", props);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        editTextDisabled();
        if(isInternetOn()){
            pd = new ProgressDialog(getActivity());
            pd.setTitle("Please wait");
            pd.setMessage("Fetching Profile Information..");
            pd.show();
            new  fetchUserData().execute();
        }
        else{
            SearchFragment nextFrag= new SearchFragment();
            Bundle args = new Bundle();
            args.putString("finishingurl","");
            args.putString("fragmentNumber","10");
            nextFrag.setArguments(args);
            getActivity().getFragmentManager().beginTransaction()
                    .replace(R.id.frame_container, nextFrag)
                    .addToBackStack(null)
                    .commit();
       }
        phoneNumberMyProfile.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                phoneNumberMyProfile.setFocusable(true);
                phoneNumberMyProfile.setClickable(true);
                phoneNumberMyProfile.setFocusableInTouchMode(true);
                phoneNumberMyProfile.requestFocus();

                profileNameMyProfile.setFocusable(false);
                profileNameMyProfile.setClickable(false);
                addressLine1MyProfile.setFocusable(false);
                addressLine1MyProfile.setClickable(false);
                addressLine2MyProfile.setFocusable(false);
                addressLine2MyProfile.setClickable(false);
                cityMyProfile.setFocusable(false);
                cityMyProfile.setClickable(false);
                pincodeMyProfile.setFocusable(false);
                pincodeMyProfile.setClickable(false);
            }
        });

        profileNameMyProfile.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                profileNameMyProfile.setFocusable(true);
                profileNameMyProfile.setClickable(true);
                profileNameMyProfile.setFocusableInTouchMode(true);
                profileNameMyProfile.requestFocus();

                phoneNumberMyProfile.setFocusable(false);
                phoneNumberMyProfile.setClickable(false);
                addressLine1MyProfile.setFocusable(false);
                addressLine1MyProfile.setClickable(false);
                addressLine2MyProfile.setFocusable(false);
                addressLine2MyProfile.setClickable(false);
                cityMyProfile.setFocusable(false);
                cityMyProfile.setClickable(false);
                pincodeMyProfile.setFocusable(false);
                pincodeMyProfile.setClickable(false);
            }
        });

        addressLine1MyProfile.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                addressLine1MyProfile.setFocusable(true);
                addressLine1MyProfile.setClickable(true);
                addressLine1MyProfile.setFocusableInTouchMode(true);
                addressLine1MyProfile.requestFocus();

                phoneNumberMyProfile.setFocusable(false);
                phoneNumberMyProfile.setClickable(false);
                profileNameMyProfile.setFocusable(false);
                profileNameMyProfile.setClickable(false);
                addressLine2MyProfile.setFocusable(false);
                addressLine2MyProfile.setClickable(false);
                cityMyProfile.setFocusable(false);
                cityMyProfile.setClickable(false);
                pincodeMyProfile.setFocusable(false);
                pincodeMyProfile.setClickable(false);
            }
        });


        addressLine2MyProfile.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                addressLine2MyProfile.setFocusable(true);
                addressLine2MyProfile.setClickable(true);
                addressLine2MyProfile.setFocusableInTouchMode(true);
                addressLine2MyProfile.requestFocus();

                phoneNumberMyProfile.setFocusable(false);
                phoneNumberMyProfile.setClickable(false);
                profileNameMyProfile.setFocusable(false);
                profileNameMyProfile.setClickable(false);
                addressLine1MyProfile.setFocusable(false);
                addressLine1MyProfile.setClickable(false);
                cityMyProfile.setFocusable(false);
                cityMyProfile.setClickable(false);
                pincodeMyProfile.setFocusable(false);
                pincodeMyProfile.setClickable(false);
            }
        });

        cityMyProfile.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cityMyProfile.setFocusable(true);
                cityMyProfile.setClickable(true);
                cityMyProfile.setFocusableInTouchMode(true);
                cityMyProfile.requestFocus();

                phoneNumberMyProfile.setFocusable(false);
                phoneNumberMyProfile.setClickable(false);
                profileNameMyProfile.setFocusable(false);
                profileNameMyProfile.setClickable(false);
                addressLine1MyProfile.setFocusable(false);
                addressLine1MyProfile.setClickable(false);
                addressLine2MyProfile.setFocusable(false);
                addressLine2MyProfile.setClickable(false);
                pincodeMyProfile.setFocusable(false);
                pincodeMyProfile.setClickable(false);
            }
        });


        pincodeMyProfile.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pincodeMyProfile.setFocusable(true);
                pincodeMyProfile.setClickable(true);
                pincodeMyProfile.setFocusableInTouchMode(true);
                pincodeMyProfile.requestFocus();

                phoneNumberMyProfile.setFocusable(false);
                phoneNumberMyProfile.setClickable(false);
                profileNameMyProfile.setFocusable(false);
                profileNameMyProfile.setClickable(false);
                addressLine1MyProfile.setFocusable(false);
                addressLine1MyProfile.setClickable(false);
                addressLine2MyProfile.setFocusable(false);
                addressLine2MyProfile.setClickable(false);
                cityMyProfile.setFocusable(false);
                cityMyProfile.setClickable(false);
            }
        });

        phoneNumberMyProfileEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                phoneNumberMyProfile.setFocusable(true);
                phoneNumberMyProfile.setClickable(true);
                phoneNumberMyProfile.setFocusableInTouchMode(true);
                phoneNumberMyProfile.setCursorVisible(true);
                phoneNumberMyProfile.requestFocus();

                profileNameMyProfile.setFocusable(false);
                profileNameMyProfile.setClickable(false);
                addressLine1MyProfile.setFocusable(false);
                addressLine1MyProfile.setClickable(false);
                addressLine2MyProfile.setFocusable(false);
                addressLine2MyProfile.setClickable(false);
                cityMyProfile.setFocusable(false);
                cityMyProfile.setClickable(false);
                pincodeMyProfile.setFocusable(false);
                pincodeMyProfile.setClickable(false);
            }
        });

       profileNameMyProfileEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                profileNameMyProfile.setFocusable(true);
                profileNameMyProfile.setClickable(true);
                profileNameMyProfile.setFocusableInTouchMode(true);
                profileNameMyProfile.requestFocus();

                phoneNumberMyProfile.setFocusable(false);
                phoneNumberMyProfile.setClickable(false);
                addressLine1MyProfile.setFocusable(false);
                addressLine1MyProfile.setClickable(false);
                addressLine2MyProfile.setFocusable(false);
                addressLine2MyProfile.setClickable(false);
                cityMyProfile.setFocusable(false);
                cityMyProfile.setClickable(false);
                pincodeMyProfile.setFocusable(false);
                pincodeMyProfile.setClickable(false);
            }
        });

        addressLine1MyProfileEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                addressLine1MyProfile.setFocusable(true);
                addressLine1MyProfile.setClickable(true);
                addressLine1MyProfile.setFocusableInTouchMode(true);
                addressLine1MyProfile.requestFocus();

                phoneNumberMyProfile.setFocusable(false);
                phoneNumberMyProfile.setClickable(false);
                profileNameMyProfile.setFocusable(false);
                profileNameMyProfile.setClickable(false);
                addressLine2MyProfile.setFocusable(false);
                addressLine2MyProfile.setClickable(false);
                cityMyProfile.setFocusable(false);
                cityMyProfile.setClickable(false);
                pincodeMyProfile.setFocusable(false);
                pincodeMyProfile.setClickable(false);
            }
        });

        addressLine2MyProfileEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                addressLine2MyProfile.setFocusable(true);
                addressLine2MyProfile.setClickable(true);
                addressLine2MyProfile.setFocusableInTouchMode(true);
                addressLine2MyProfile.requestFocus();

                phoneNumberMyProfile.setFocusable(false);
                phoneNumberMyProfile.setClickable(false);
                profileNameMyProfile.setFocusable(false);
                profileNameMyProfile.setClickable(false);
                addressLine1MyProfile.setFocusable(false);
                addressLine1MyProfile.setClickable(false);
                cityMyProfile.setFocusable(false);
                cityMyProfile.setClickable(false);
                pincodeMyProfile.setFocusable(false);
                pincodeMyProfile.setClickable(false);

            }
        });


        cityMyProfileEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cityMyProfile.setFocusable(true);
                cityMyProfile.setClickable(true);
                cityMyProfile.setFocusableInTouchMode(true);
                cityMyProfile.requestFocus();

                phoneNumberMyProfile.setFocusable(false);
                phoneNumberMyProfile.setClickable(false);
                profileNameMyProfile.setFocusable(false);
                profileNameMyProfile.setClickable(false);
                addressLine1MyProfile.setFocusable(false);
                addressLine1MyProfile.setClickable(false);
                addressLine2MyProfile.setFocusable(false);
                addressLine2MyProfile.setClickable(false);
                pincodeMyProfile.setFocusable(false);
                pincodeMyProfile.setClickable(false);
            }
        });

        pincodeMyProfileEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pincodeMyProfile.setFocusable(true);
                pincodeMyProfile.setClickable(true);
                pincodeMyProfile.setFocusableInTouchMode(true);
                pincodeMyProfile.requestFocus();

                phoneNumberMyProfile.setFocusable(false);
                phoneNumberMyProfile.setClickable(false);
                profileNameMyProfile.setFocusable(false);
                profileNameMyProfile.setClickable(false);
                addressLine1MyProfile.setFocusable(false);
                addressLine1MyProfile.setClickable(false);
                addressLine2MyProfile.setFocusable(false);
                addressLine2MyProfile.setClickable(false);
                cityMyProfile.setFocusable(false);
                cityMyProfile.setClickable(false);
            }
        });


        profileSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if((phoneNumberMyProfile.getText().toString().length()==10 || phoneNumberMyProfile.getText().toString().isEmpty()) && (pincodeMyProfile.getText().toString().length()==6 || pincodeMyProfile.getText().toString().isEmpty())) {
                    if (isInternetOn()) {
                        nameValuePairsProfile = new ArrayList<NameValuePair>();
                        nameValuePairsProfile.add(new BasicNameValuePair("id", userData.getString("id", null)));
                        nameValuePairsProfile.add(new BasicNameValuePair("mobile_number", phoneNumberMyProfile.getText().toString()));
                        nameValuePairsProfile.add(new BasicNameValuePair("address_line_1", addressLine1MyProfile.getText().toString()));
                        nameValuePairsProfile.add(new BasicNameValuePair("address_line_2", addressLine2MyProfile.getText().toString()));
                        nameValuePairsProfile.add(new BasicNameValuePair("city", cityMyProfile.getText().toString()));
                        nameValuePairsProfile.add(new BasicNameValuePair("pincode", pincodeMyProfile.getText().toString()));
                        nameValuePairsProfile.add(new BasicNameValuePair("first_name", profileNameMyProfile.getText().toString()));
                        new PushDataProfile().execute();
                    } else {
                        Toast.makeText(getActivity(), "Sorry could not update the details. Please try again later", Toast.LENGTH_SHORT).show();
                    }
                }else if(phoneNumberMyProfile.getText().toString().length()!=10){
                    Toast.makeText(getActivity(), "Mobile Number not valid", Toast.LENGTH_SHORT).show();
                }else if(pincodeMyProfile.getText().toString().length()!=6){
                    Toast.makeText(getActivity(), "Pincode not valid", Toast.LENGTH_SHORT).show();
                }
            }
        });
        rootView.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if(event.getAction() == KeyEvent.ACTION_DOWN){
                    switch(keyCode) {
                        case KeyEvent.KEYCODE_BACK:
                            Intent i = new Intent(getActivity(), MainActivity.class);
                            i.putExtra("displayView", "0");
                            startActivity(i);
                            return true;
                    }
                }
                return false;
            }
        });
        return rootView;

    }

   private void editTextDisabled(){
            phoneNumberMyProfile.setFocusable(false);
            phoneNumberMyProfile.setClickable(false);

            profileNameMyProfile.setFocusable(false);
            profileNameMyProfile.setClickable(false);

            addressLine1MyProfile.setFocusable(false);
            addressLine1MyProfile.setClickable(false);

            addressLine2MyProfile.setFocusable(false);
            addressLine2MyProfile.setClickable(false);

            cityMyProfile.setFocusable(false);
            cityMyProfile.setClickable(false);

            pincodeMyProfile.setFocusable(false);
            pincodeMyProfile.setClickable(false);

    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }


    class fetchUserData extends AsyncTask<String, Integer, JSONObject> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected JSONObject doInBackground(String... arg0) {
            HttpClient httpclient = new DefaultHttpClient();
            try {
                String fetchUrl = apiData.getString("userprofile.url",null)+"?user_id="+ userData.getString("id",null);
                HttpGet httppost = new HttpGet(fetchUrl);
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
                HttpResponse response = httpclient.execute(httppost);

                HttpEntity entity = response.getEntity();
                int status = response.getStatusLine().getStatusCode();
                JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
                System.out.println(jObjGmail.toString());

                return jObjGmail;


            } catch (ClientProtocolException e) {
                Log.e("data","data " + e.getMessage());
                return null;
            } catch (IOException e) {
                Log.e("data","data " + e.getMessage());
                return null;
            }catch (Exception e){
                Log.e("data","data " + e.getMessage());
                return null;
            }
        }

        @Override
        protected void onPostExecute(JSONObject result) {
            super.onPostExecute(result);
            if(result==null){
                pd.dismiss();
            }else {
                try {
                    if (result.getString("first_name") == "null") {

                    } else {
                        profileNameMyProfile.setText(result.getString("first_name").toString());
                    }
                    if (result.getString("mobile_number") == "null") {

                    } else {
                        phoneNumberMyProfile.setText(result.getString("mobile_number").toString());
                    }
                    if (result.getString("address_line_1") == "null") {

                    } else {
                        addressLine1MyProfile.setText(result.getString("address_line_1").toString());
                    }
                    if (result.getString("address_line_2") == "null") {

                    } else {
                        addressLine2MyProfile.setText(result.getString("address_line_2").toString());
                    }
                    if (result.getString("city") == "null") {

                    } else {
                        cityMyProfile.setText(result.getString("city").toString());
                    }
                    if (result.getString("pincode") == "null" || result.getString("pincode") == "0") {

                    } else {
                        pincodeMyProfile.setText(result.getString("pincode").toString());
                    }
                    if (result.getString("profile_pic").equalsIgnoreCase("null")) {
                            profileImage.setImageResource(R.drawable.noimageavailable);
                            profileImage.setMaxHeight(300);
                            profileImage.setMaxWidth(300);
                        } else if (userData.getString("type", null).equalsIgnoreCase("google")) {
                            String profileImageUrl = result.getString("profile_pic");
                            String x = profileImageUrl.split("sz=")[1];
                            String updatedUrl = profileImageUrl.replace("sz=" + x, "sz=300");
                            Picasso.with(getActivity())
                                    .load(updatedUrl)
                                    .transform(new CircleTransform())
                                    .into(profileImage);
                        } else if (userData.getString("type", null).equalsIgnoreCase("facebook")) {
                            String profileImageUrl = result.getString("profile_pic").toString();
                            String replaceString = profileImageUrl.replace("http", "https");
                            String appendDimen = "?&height=300&type=normal&width=300";
                            String updatedUrl = replaceString.concat(appendDimen);

                            Picasso.with(getActivity())
                                    .load(updatedUrl)
                                    .transform(new CircleTransform())
                                    .into(profileImage);
                            //Toast.makeText(getActivity(),"facebook "+profileImageUrl,Toast.LENGTH_SHORT).show();
                        } else {
                            profileImage.setImageResource(R.drawable.noimageavailable);
                            profileImage.setMaxHeight(300);
                            profileImage.setMaxWidth(300);
                        }

                    if (result.getString("mobile_verified") == "true") {
                        phoneNumberMyProfileVerifyStatus.setText("Verified");
                        /*phoneNumberMyProfileVerifyStatus.setClickable(true);
                        phoneNumberMyProfileVerifyStatus.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Intent i = new Intent(getActivity(),MObileNumberVerificationActivity.class);
                                i.putExtra("numberVerification",phoneNumberMyProfile.getText().toString());
                                startActivity(i);
                            }
                        });*/
                    } else {
                        phoneNumberMyProfileVerifyStatus.setText("Verify Now to get Cashback");
                        phoneNumberMyProfileVerifyStatus.setClickable(true);
                        if (isInternetOn()) {
                            if (phoneNumberMyProfile.getText().toString().isEmpty() || phoneNumberMyProfile.getText().toString().length() != 10) {
                                Toast.makeText(getActivity(), "Please Enter a number to be verified", Toast.LENGTH_SHORT).show();
                            } else {
                                phoneNumberMyProfileVerifyStatus.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        Intent i = new Intent(getActivity(), MObileNumberVerificationActivity.class);
                                        i.putExtra("numberVerification", phoneNumberMyProfile.getText().toString());
                                        startActivity(i);
                                    }
                                });
                            }
                        } else {
                            Toast.makeText(getActivity(), "No internet connection.Phone number could not be verified", Toast.LENGTH_SHORT).show();
                        }
                    }

                    pd.dismiss();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public class CircleTransform implements Transformation {
        @Override
        public Bitmap transform(Bitmap source) {
            int size = Math.min(source.getWidth(), source.getHeight());

            int x = (source.getWidth() - size) / 2;
            int y = (source.getHeight() - size) / 2;

            Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
            if (squaredBitmap != source) {
                source.recycle();
            }

            Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());

            Canvas canvas = new Canvas(bitmap);
            Paint paint = new Paint();
            BitmapShader shader = new BitmapShader(squaredBitmap,
                    BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
            paint.setShader(shader);
            paint.setAntiAlias(true);

            float r = size / 2f;
            canvas.drawCircle(r, r, r, paint);

            squaredBitmap.recycle();
            return bitmap;
        }

        @Override
        public String key() {
            return "circle";
        }
    }

    ProgressDialog pd = null;

    public final boolean isInternetOn() {

        ConnectivityManager connec =
                (ConnectivityManager)getActivity().getSystemService(getActivity().getBaseContext().CONNECTIVITY_SERVICE);

        if ( connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||
                connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||
                connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||
                connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED ) {

            return true;

        } else if (
                connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||
                        connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED  ) {
            return false;
        }
        return false;
    }
    @Override
    public void onResume() {
        super.onResume();
        getView().setFocusableInTouchMode(true);
        getView().requestFocus();
        getView().setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {

                if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK){
                    Intent i = new Intent(getActivity(), MainActivity.class);
                    i.putExtra("displayView", "0");
                    startActivity(i);
                    return true;
                }
                return false;
            }
        });
    }



    class PushDataProfile extends AsyncTask<String, Integer, String> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected String doInBackground(String... arg0) {
            HttpClient httpclient = new DefaultHttpClient();
            try {

                String fetchUrl = apiData.getString("useredit.url",null)+ userData.getString("id",null);
                HttpPost httppost = new HttpPost(fetchUrl);
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairsProfile));
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                return "success";
            } catch (ClientProtocolException e) {
                return "failure";
            } catch (IOException e) {
                return "failure";
            }catch (Exception e){
                return "failure";
            }
        }

        @Override
        protected void onPostExecute(String result) {
            Intent i = new Intent(getActivity(),MainActivity.class);
            i.putExtra("displayView","15");
            startActivity(i);
            super.onPostExecute(result);
        }
    }
}