@Override
  public void onActivityResult(int requestCode, int resultCode, Intent intent) {

    switch (requestCode) {
      case CATEGORY_REQUEST:
        if (resultCode == RESULT_OK) {
          loggedUser.setMajorJobCategory(intent.getStringExtra("major"));
          loggedUser.setMinorJobCategory(intent.getStringExtra("minor"));
          displayCategory();
        }
        break;
      case SKILL_REQUEST:
        if (resultCode == RESULT_OK) {
          loggedUser.setSkills(intent.getStringExtra("strongestSkillsList"));
          displaySkill();
        }
        break;
      case PROFILE_PIC_REQUEST:
        if (resultCode == RESULT_OK) {
          Uri selectedImage = imageUri;

          if (selectedImage != null) {
            getContentResolver().notifyChange(selectedImage, null);

            try {
              OutputStream fOut = null;

              Bitmap bitmap =
                  MediaStore.Images.Media.getBitmap(getContentResolver(), selectedImage);
              Bitmap resizedImage = GraphicUtils.resizeProfileImage(bitmap);

              File file = new File(new URI(selectedImage.toString()));
              fOut = new FileOutputStream(file);

              // Set picture compression
              resizedImage.compress(CompressFormat.JPEG, 70, fOut);
              fOut.flush();
              fOut.close();

            } catch (IOException e) {
            } catch (URISyntaxException e) {
            }

            // Upload user Photo
            exe.uploadUserProfilePhoto();

          } else {
            new CustomDialog(
                    ActivitySettings.this,
                    "Info",
                    "Unable to save picture! We are working on that...")
                .show();
          }
        }

        break;
    }
  }
  private void actionFinished(int action) {
    result = exe.getResult();

    switch (action) {
      case Executor.HANDLE_SET_USER_PROFILE_DATA:
        textEmail.setVisibility(View.VISIBLE);
        textNickName.setVisibility(View.VISIBLE);
        boolean res = (Boolean) result.getObject();
        if (res) {
          Toast.makeText(ActivitySettings.this, result.getResponseMessage(), Toast.LENGTH_LONG)
              .show();
          hideKeyboard();
        } else {
          new CustomDialog(ActivitySettings.this, "Info", result.getResponseMessage()).show();
        }
        isUserDataChanged = true;
        break;

      case Executor.HANDLE_GET_USER_DATA:
        if (result.getObject() != null) {
          loggedUser = (UserSmart) result.getObject();
          useUserData();
        }
        break;

      case Executor.HANDLE_GET_SKILLS:
        break;

      case Executor.HANDLE_UPLOAD_USER_PROFILE_PHOTO:
        if (result != null) {
          if (result.getObject() != null) {
            if (result.getObject() instanceof String) {
              new CustomDialog(ActivitySettings.this, "Info", (String) result.getObject()).show();
              loadProfilePhoto();
            }
          }
        }
        break;

      case Executor.HANDLE_ACCOUNT_DELETE_SUCCEEDED:
        Intent i = new Intent();
        i.setClass(getApplicationContext(), ActivityLoginPage.class);
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(i);
        break;

      case Executor.HANDLE_ACCOUNT_DELETE_FAILED:
        if (result != null) {
          if (result.getObject() != null) {
            if (result.getObject() instanceof String) {
              new CustomDialog(ActivitySettings.this, "Info", (String) result.getObject()).show();
            }
          }
        }
        break;
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_user_profile);

    // Get data from intent
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
      email_required = extras.getString("email_required");
    }
    // Executor
    exe = new Executor(ActivitySettings.this);
    exe.setExecutorListener(
        new ExecutorInterface() {
          @Override
          public void onErrorReceived() {
            errorReceived();
          }

          @Override
          public void onActionFinished(int action) {
            actionFinished(action);
          }
        });

    imageLoader = new ImageLoader(this);

    // Views
    title = (CustomFontView) findViewById(R.id.textview_tile);
    textNickName = (EditText) findViewById(R.id.edit_nickname);
    textEmail = (EditText) findViewById(R.id.edit_email);
    imageProfilePhoto = (ImageView) findViewById(R.id.imagebutton_user_face);
    strongestSkill = (Button) findViewById(R.id.strongSkill);
    jobCategory = (Button) findViewById(R.id.jobCategory);
    profileVisibility = (Spinner) findViewById(R.id.profileVisibility);
    deleteAccount = (Button) findViewById(R.id.deleteAccount);
    cancelButton = (Button) findViewById(R.id.button_cancel_name);

    jobCategory.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent();
            intent.putExtra("major", loggedUser.getMajorJobCategory());
            intent.putExtra("minor", loggedUser.getMinorJobCategory());
            intent.setClass(getApplicationContext(), ActivityJobCategory.class);
            startActivityForResult(intent, CATEGORY_REQUEST);
          }
        });

    imageProfilePhoto.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            onClickPhoto(v);
          }
        });

    // Get logged user
    exe.getUserData();

    // Change Nick Name
    textNickName.setOnEditorActionListener(
        new OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

            if ((actionId == EditorInfo.IME_ACTION_SEND)
                || (actionId == EditorInfo.IME_NULL
                    && event.getKeyCode() == KeyEvent.KEYCODE_ENTER
                    && event.getAction() == KeyEvent.ACTION_DOWN)) {
              if (loggedUser != null) {
                loggedUser.setNickName(textNickName.getText().toString());
                exe.setUserProfileData(loggedUser, false);
                AppCAP.setLoggedInUserNickname(textNickName.getText().toString());
              }
            }
            return false;
          }
        });

    // Change Email
    textEmail.setOnEditorActionListener(
        new OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((actionId == EditorInfo.IME_ACTION_SEND)
                || (actionId == EditorInfo.IME_NULL
                    && event.getKeyCode() == KeyEvent.KEYCODE_ENTER
                    && event.getAction() == KeyEvent.ACTION_DOWN)) {
              if (loggedUser != null) {
                loggedUser.setUsername(textEmail.getText().toString());
                exe.setUserProfileData(loggedUser, true);
                AppCAP.setLoggedInUserEmail(textEmail.getText().toString());
              }
            }
            return false;
          }
        });
    textNickName.setOnFocusChangeListener(
        new OnFocusChangeListener() {

          public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
              cancelButton.setVisibility(View.VISIBLE);
            }
          }
        });
    textEmail.setOnFocusChangeListener(
        new OnFocusChangeListener() {

          public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
              cancelButton.setVisibility(View.VISIBLE);
            }
          }
        });

    strongestSkill.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent();
            intent.setClass(getApplicationContext(), ActivityLinkedinSkills.class);
            startActivityForResult(intent, SKILL_REQUEST);
          }
        });

    // -- Setup the visibility options spinner
    String[] visibilityOptions = {
      getString(R.string.activity_settings_profile_visibility_everyone),
      getString(R.string.activity_settings_profile_visibility_logged_in)
    };
    ArrayAdapter<String> voAdapter =
        new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, visibilityOptions);
    voAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    profileVisibility.setAdapter(voAdapter);

    deleteAccount.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            showConfirmDialog();
          }
        });
  }