@Override
  public View getItemView(Issue issue, View v, ViewGroup parent) {
    if (v == null) {
      v = View.inflate(getContext(), R.layout.layout_issue_row, null);
    }

    super.getItemView(issue, v, parent);

    ParseImageView issueImage = (ParseImageView) v.findViewById(R.id.list_issue_image);
    ParseFile photoFile = issue.getParseFile("photo");
    if (photoFile != null) {
      issueImage.setParseFile(photoFile);
      issueImage.loadInBackground(
          new GetDataCallback() {
            @Override
            public void done(byte[] data, ParseException e) {
              // nothing to do
            }
          });
    }

    TextView titleTextView = (TextView) v.findViewById(R.id.list_issue_title);
    titleTextView.setText(issue.getTitle());
    TextView issueDescriptionTextView = (TextView) v.findViewById(R.id.list_issue_description);
    issueDescriptionTextView.setText(issue.getDescription());
    TextView issueBidTextView = (TextView) v.findViewById(R.id.list_issue_bid);
    issueBidTextView.setText(String.valueOf(issue.getBid()));

    return v;
  }
  public void saveImage() {

    // Store the image inot the database
    // This will prob have to have it's own function
    if (profileImg.getDrawable() != null) {
      Bitmap bImage = ((BitmapDrawable) profileImg.getDrawable()).getBitmap();
      ByteArrayOutputStream stream = new ByteArrayOutputStream();
      bImage.compress(Bitmap.CompressFormat.PNG, 100, stream);

      byte[] byteArray = stream.toByteArray();
      final ParseFile pImg = new ParseFile("profile.png", byteArray);
      pImg.saveInBackground(
          new SaveCallback() {
            @Override
            public void done(ParseException e) {
              if (e == null) {
                // success
                ParseUser tempUser = ParseUser.getCurrentUser();
                tempUser.put("profileImg", pImg);
                tempUser.saveInBackground();
              } else {
                // failed
              }
            }
          }); // end of the saveinbackground
    }
  }
 private void setLogoImage(ParseFile logoImage) {
   if (logoImage != null) {
     mLogoImageButton.setParseFile(logoImage);
     mLogoImageButton.loadInBackground();
   } else {
     String title = mTitleText.getText().toString();
     String firstChar = title.isEmpty() ? "N" : title.substring(0, 1).toUpperCase();
     ColorGenerator generator = ColorGenerator.MATERIAL;
     int alphabetColor = generator.getColor(firstChar);
     final TextDrawable drawable = TextDrawable.builder().buildRound(firstChar, alphabetColor);
     mLogoImageButton.setImageDrawable(drawable);
   }
 }
  @Override
  public View getView(int position, View view, ViewGroup parent) {
    // TODO Auto-generated method stub
    View row = view;
    position1 = position;

    String productname;
    if (row == null) {
      row = inflater.inflate(R.layout.imagecell, null);

      final TextView txtproductid = (TextView) row.findViewById(R.id._productid);
      TextView txtView = (TextView) row.findViewById(R.id._productName);
      TextView txtproductcost = (TextView) row.findViewById(R.id._productcost);
      ParseImageView imgView = (ParseImageView) row.findViewById(R.id._image);

      p = data.get(position);

      ParseFile image = (ParseFile) p.getImage();
      imgView.setParseFile(image);
      imgView.loadInBackground(
          new GetDataCallback() {

            @Override
            public void done(byte[] data, ParseException e) {
              // TODO Auto-generated method stub

            }
          });

      txtproductid.setText(p.getObjectId());
      txtView.setText(p.getName());
      txtproductcost.setText("$ " + Double.toString(p.getPrice()));
      imgView.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              // TODO Auto-generated method stub
              Bundle args = new Bundle();
              FragmentManager fragmanager = ((Activity) context).getFragmentManager();
              Fragment productdetail = new ProductDetailFragment();
              FragmentTransaction fragtrans = fragmanager.beginTransaction();
              args.putString("productid", txtproductid.getText().toString());
              productdetail.setArguments(args);
              fragtrans.replace(R.id.content_frame, productdetail).addToBackStack(null).commit();
            }
          });
    }

    return row;
  }
  @Override
  public View getItemView(final Stamp stamp, View v, ViewGroup parent) {

    if (v == null) {
      v = View.inflate(getContext(), R.layout.image, null);
    }

    super.getItemView(stamp, v, parent);

    ParseImageView stampImage = (ParseImageView) v.findViewById(R.id.image_view);
    ParseFile photoFile = stamp.getPhotoFile();
    if (photoFile != null) {
      stampImage.setParseFile(photoFile);
      stampImage.loadInBackground(
          new GetDataCallback() {
            @Override
            public void done(byte[] data, ParseException e) {
              // nothing to do
            }
          });
    }

    CardView card = (CardView) v.findViewById(R.id.image_card);
    card.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent(cont, PgStampInfoActivity.class);
            /*
            event.getObjectId();
            stamp.getObjectId();
            String stampId = item.getID();
            ArrayList<String> stampIdList = getStampObjectIdArrayList();
            int pos = stampIdList.indexOf(stampId);
            intent.putExtra("clicked_stamp_pos", pos);
            intent.putExtra("stamp_id_list", stampIdList);*/
            cont.startActivity(intent);
          }
        });
    return v;
  }
  private void initalizeControls() {

    mProgressBar = (ProgressBar) findViewById(R.id.manage_res_progress);
    mSaveResourceForm = findViewById(R.id.save_resource_form);
    mTitleText = (EditText) findViewById(R.id.manage_res_title);
    mDescriptionText = (EditText) findViewById(R.id.manage_res_description);
    mActiveStatus = (CheckBox) findViewById(R.id.manage_active);
    mSubmitButton = (Button) findViewById(R.id.manage_res_submit);
    mSubmitButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            onSubmitClick(v);
          }
        });

    // Category controls
    mColorHexText = (EditText) findViewById(R.id.manage_category_indicator);
    mColorHexRep = (TextView) findViewById(R.id.manage_category_color_indicator);
    // Interest, School, Org logo
    mCropImageView = (CropImageView) findViewById(R.id.res_cropImageView);
    mLogoImageButton = (ParseImageView) findViewById(R.id.resource_image);
    mLogoImageButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            startActivityForResult(
                getPickImageChooserIntent(), Constants.IMAGE_PICKER_REQUEST_CODE);
          }
        });

    // User management controls
    mUserMgmtContainer = (RelativeLayout) findViewById(R.id.user_mgmt_section);
    mUserOrgSpinner = (Spinner) findViewById(R.id.manage_user_org);
    mUserRoleSpinner = (Spinner) findViewById(R.id.manage_user_role);

    mRecognitionMgmtContainer = (RelativeLayout) findViewById(R.id.manage_recognition_container);
    mRecognitionTypeSpinner = (Spinner) findViewById(R.id.manage_recog_type);
    mRecognitionUnit = (CheckBox) findViewById(R.id.manage_recog_pts_category);
    mRecogReqPtsText = (EditText) findViewById(R.id.manage_recog_pts_req);
    mRecogMaxUnitsText = (EditText) findViewById(R.id.manage_recog_max_units);
    mRecognitionActivitySpinner = (Spinner) findViewById(R.id.manage_recog_activity);

    mExpandCollapseUsers = (ImageView) findViewById(R.id.expand_users);
    mUserListContainer = (RelativeLayout) findViewById(R.id.user_list_container);
    mUsersRecyclerView = (RecyclerView) findViewById(R.id.user_list);
    mEmptyUserList = (TextView) findViewById(R.id.empty_user_list);
    mUserListHeaderText = (TextView) findViewById(R.id.user_list_item_header);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_user_profile);

    // Retrieve current user from Parse.com
    // This is how you get the user from the cache
    // so we don't need to pass the user as a parameter
    ParseUser currentUser = ParseUser.getCurrentUser();

    // Convert currentUser into String
    String struser = currentUser.getUsername();

    // Locate TextView in welcome.xml
    txtuser = (TextView) findViewById(R.id.txtuser);

    // Set the currentUser String into TextView
    txtuser.setText(struser);
    // get the button for the log out
    logout = (Button) findViewById(R.id.logOutB);
    uQuizButton = (ImageButton) findViewById(R.id.quizButton);
    uUpdateButton = (ImageButton) findViewById(R.id.updateButton);
    uFindButton = (ImageButton) findViewById(R.id.findButton);
    profileImg = (ParseImageView) findViewById(R.id.profile_img);
    aboutMe = (TextView) findViewById(R.id.aboutText);
    location = (TextView) findViewById(R.id.locationText);

    // get the about me and location infromation from parse database
    aboutMe.setText(currentUser.getString("AboutMe"));
    location.setText(currentUser.getString("Location"));
    retrieveImage(struser);
    // getUserInfo();

    uQuizButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), questions_page.class);
            startActivity(intent);
          }
        });

    uUpdateButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), update_info_activity.class);
            startActivity(intent);
          }
        });

    uFindButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), friend_suggestion_activity.class);
            startActivity(intent);
          }
        });

    // allow the user to select an image from his gallery
    profileImg.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent photoPickerIntent =
                new Intent(
                    Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(photoPickerIntent, RESULT_LOAD_IMAGE);
            saveImage();
          }
        });

    // Logout Button Click Listener
    logout.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View arg0) {
            // Logout current user
            ParseUser.logOut();
            // take back to login page
            //
            Intent intent = new Intent(getApplicationContext(), MainActivity.class);
            startActivity(intent);
          }
        });
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    Intent manageIntent = getIntent();
    mResourceType = manageIntent.getStringExtra(Constants.MANAGE_ITEM_KEY);
    mResourceObjectId = manageIntent.getStringExtra(Constants.OBJECT_ID_KEY);
    mUserOrganization = manageIntent.getStringExtra(Constants.USER_ORGANIZATION_KEY);

    if (mResourceType.equals(Constants.OPPORTUNITY_RESOURCE)) {
      Intent intent = new Intent(this, OpportunityDetailActivity.class);
      intent.putExtra(Constants.OBJECT_ID_KEY, mResourceObjectId);
      intent.putExtra(Constants.USER_ORGANIZATION_KEY, mUserOrganization);
      intent.putExtra(Constants.ACCESS_MODE_KEY, Constants.WRITE_MODE);
      startActivityForResult(intent, Constants.ADD_RESOURCE_REQUEST_CODE);
      // return;
    }

    setTitle(getResources().getText(R.string.manage_title) + " " + mResourceType);
    final boolean isNewAddition = Strings.isNullOrEmpty(mResourceObjectId);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.manage_single_resource_activity);

    ImageButton colorPicker = (ImageButton) findViewById(R.id.manage_category_color_picker_button);
    RelativeLayout categoryContainer = (RelativeLayout) findViewById(R.id.manage_color_picker);

    initalizeControls();

    // Set control visibility based on the selection.
    mProgressBar.setVisibility(View.VISIBLE);

    // region ResourceType switch-case
    switch (mResourceType) {
      case Constants.ANNOUNCEMENT_RESOURCE:
        mTitleText.setVisibility(View.INVISIBLE);
        ParseQuery<Announcement> announcementQuery = ParseQuery.getQuery(Announcement.class);
        announcementQuery.whereEqualTo(Constants.OBJECT_ID_KEY, mResourceObjectId);
        announcementQuery.getFirstInBackground(
            new GetCallback<Announcement>() {
              @Override
              public void done(Announcement object, ParseException e) {
                if (e == null) {
                  mResourceObject = object;
                } else {
                  mResourceObject = new Announcement();
                }

                if (!isNewAddition) {
                  mDescriptionText.setText(((Announcement) mResourceObject).getAnnouncementText());
                  mActiveStatus.setChecked(((Announcement) mResourceObject).isActive());
                }

                mProgressBar.setVisibility(View.GONE);
              }
            });
        break;

      case Constants.CATEGORY_RESOURCE:
        categoryContainer.setVisibility(View.VISIBLE);
        final int[] currentColor = new int[1];

        ParseQuery<Category> categoryQuery = ParseQuery.getQuery(Category.class);
        categoryQuery.whereEqualTo(Constants.OBJECT_ID_KEY, mResourceObjectId);
        categoryQuery.getFirstInBackground(
            new GetCallback<Category>() {
              @Override
              public void done(Category object, ParseException e) {
                if (e == null) {
                  mResourceObject = object;
                } else {
                  mResourceObject = new Category();
                }

                if (!isNewAddition) {
                  mTitleText.setText(((Category) mResourceObject).getCategoryName());
                  mDescriptionText.setText(((Category) mResourceObject).getDescription());
                  mActiveStatus.setChecked(((Category) mResourceObject).isActive());

                  String categoryColorHex = ((Category) mResourceObject).getCategoryColor();
                  mColorHexText.setText(categoryColorHex);
                  mColorHexRep.setBackgroundColor(Color.parseColor(categoryColorHex));
                  currentColor[0] = Color.parseColor(categoryColorHex);
                }

                mProgressBar.setVisibility(View.GONE);
              }
            });

        final AmbilWarnaDialog dialog =
            new AmbilWarnaDialog(
                this,
                currentColor[0],
                new AmbilWarnaDialog.OnAmbilWarnaListener() {
                  @Override
                  public void onOk(AmbilWarnaDialog dialog, int color) {
                    // color is the color selected by the user.
                    mColorHexText.setText(String.format("#%06X", (0xFFFFFF & color)));
                    mColorHexRep.setBackgroundColor(color);
                  }

                  @Override
                  public void onCancel(AmbilWarnaDialog dialog) {
                    // cancel was selected by the user
                  }
                });

        colorPicker.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                dialog.show();
              }
            });
        break;

      case Constants.RECOGNITION_RESOURCE:
        mLogoImageButton.setVisibility(View.VISIBLE);
        mCropImageView.setVisibility(View.VISIBLE);
        mRecognitionMgmtContainer.setVisibility(View.VISIBLE);
        initializeRecognitionTypeSpinner();
        initializeRecognitionOpportunitySpinner();

        ParseQuery<Recognition> recognitionQuery = ParseQuery.getQuery(Recognition.class);
        recognitionQuery.whereEqualTo(Constants.OBJECT_ID_KEY, mResourceObjectId);
        recognitionQuery.getFirstInBackground(
            new GetCallback<Recognition>() {
              @Override
              public void done(Recognition object, ParseException e) {
                if (e == null) {
                  mResourceObject = object;
                } else {
                  mResourceObject = new Recognition();
                }

                if (!isNewAddition) {
                  mTitleText.setText(((Recognition) mResourceObject).getTitle());
                  mDescriptionText.setText(((Recognition) mResourceObject).getDescription());
                  mRecogReqPtsText.setText(((Recognition) mResourceObject).getPointsRequired());
                  mRecogMaxUnitsText.setText(((Recognition) mResourceObject).getMaxUnits());
                  mRecognitionUnit.setChecked(((Recognition) mResourceObject).isHoursBased());
                  mUserListContainer.setVisibility(View.VISIBLE);
                  loadRecognizedUsers();

                  for (int i = 1; i <= mRecognitionTypeSpinner.getCount(); i++) {
                    if (mRecognitionTypeSpinner
                        .getItemAtPosition(i)
                        .toString()
                        .equals(((Recognition) mResourceObject).getRecognitionType())) {
                      mRecognitionTypeSpinner.setSelection(i);
                      break;
                    }
                  }

                  mActiveStatus.setChecked(((Recognition) mResourceObject).isActive());
                  setLogoImage(((Recognition) mResourceObject).getImage());
                }

                mProgressBar.setVisibility(View.GONE);
              }
            });

        break;

      case Constants.INTEREST_RESOURCE:
        mLogoImageButton.setVisibility(View.VISIBLE);
        mCropImageView.setVisibility(View.VISIBLE);

        ParseQuery<Interest> interestQuery = ParseQuery.getQuery(Interest.class);
        interestQuery.whereEqualTo(Constants.OBJECT_ID_KEY, mResourceObjectId);
        interestQuery.getFirstInBackground(
            new GetCallback<Interest>() {
              @Override
              public void done(Interest object, ParseException e) {
                if (e == null) {
                  mResourceObject = object;
                } else {
                  mResourceObject = new Interest();
                }
                if (!isNewAddition) {
                  mTitleText.setText(((Interest) mResourceObject).getInterestTitle());
                  mDescriptionText.setText(((Interest) mResourceObject).getDescription());
                  mActiveStatus.setChecked(((Interest) mResourceObject).isActive());
                  mUserListContainer.setVisibility(View.VISIBLE);
                  loadUsersWithInterest();
                  setLogoImage(((Interest) mResourceObject).getLogo());
                }

                mProgressBar.setVisibility(View.GONE);
              }
            });

        break;

      case Constants.SKILL_RESOURCE:
        mLogoImageButton.setVisibility(View.VISIBLE);
        mCropImageView.setVisibility(View.VISIBLE);

        ParseQuery<Skill> skillsQuery = ParseQuery.getQuery(Skill.class);
        skillsQuery.whereEqualTo(Constants.OBJECT_ID_KEY, mResourceObjectId);
        skillsQuery.getFirstInBackground(
            new GetCallback<Skill>() {
              @Override
              public void done(Skill object, ParseException e) {
                if (e == null) {
                  mResourceObject = object;
                } else {
                  mResourceObject = new Skill();
                }

                if (!isNewAddition) {
                  mTitleText.setText(((Skill) mResourceObject).getSkillTitle());
                  mDescriptionText.setText(((Skill) mResourceObject).getDescription());
                  mActiveStatus.setChecked(((Skill) mResourceObject).isActive());
                  mUserListContainer.setVisibility(View.VISIBLE);
                  loadUsersWithSkills();
                  setLogoImage(((Skill) mResourceObject).getLogo());
                }

                mProgressBar.setVisibility(View.GONE);
              }
            });
        break;

      case Constants.USER_RESOURCE:
        mUserMgmtContainer.setVisibility(View.VISIBLE);
        initializeUserTypeSpinner();
        initializeOrganizationSpinner(mUserOrgSpinner);

        ParseQuery<SpecialUser> splUserQuery = ParseQuery.getQuery(SpecialUser.class);
        splUserQuery.whereEqualTo(Constants.OBJECT_ID_KEY, mResourceObjectId);
        splUserQuery.getFirstInBackground(
            new GetCallback<SpecialUser>() {
              @Override
              public void done(SpecialUser object, ParseException e) {
                if (e == null) {
                  mResourceObject = object;
                } else {
                  mResourceObject = new SpecialUser();
                }

                if (!isNewAddition) {
                  mTitleText.setText(((SpecialUser) mResourceObject).getEmailId());
                  mDescriptionText.setText(((SpecialUser) mResourceObject).getDescription());
                  mActiveStatus.setChecked(((SpecialUser) mResourceObject).isActive());

                  for (int i = 1; i <= mUserOrgSpinner.getCount(); i++) {
                    if (mUserOrgSpinner
                        .getItemAtPosition(i)
                        .toString()
                        .equals(((SpecialUser) mResourceObject).getOrganizationName())) {
                      mUserOrgSpinner.setSelection(i);
                      break;
                    }
                  }

                  for (int i = 1; i <= mUserRoleSpinner.getCount(); i++) {
                    if (mUserRoleSpinner
                        .getItemAtPosition(i)
                        .toString()
                        .equals(((SpecialUser) mResourceObject).getRole())) {
                      mUserRoleSpinner.setSelection(i);
                      break;
                    }
                  }
                }

                mProgressBar.setVisibility(View.GONE);
              }
            });

        mProgressBar.setVisibility(View.GONE);
        break;

      case Constants.SCHOOL_RESOURCE:
        mLogoImageButton.setVisibility(View.VISIBLE);
        mCropImageView.setVisibility(View.VISIBLE);

        ParseQuery<School> schoolQuery = ParseQuery.getQuery(School.class);
        schoolQuery.whereEqualTo(Constants.OBJECT_ID_KEY, mResourceObjectId);
        schoolQuery.getFirstInBackground(
            new GetCallback<School>() {
              @Override
              public void done(School object, ParseException e) {
                if (e == null) {
                  mResourceObject = object;
                } else {
                  mResourceObject = new School();
                }

                if (!isNewAddition) {
                  String schoolName = ((School) mResourceObject).getSchoolName();
                  mTitleText.setText(schoolName);
                  mDescriptionText.setText(((School) mResourceObject).getDescription());
                  mActiveStatus.setChecked(((School) mResourceObject).isActive());
                  mUserListContainer.setVisibility(View.VISIBLE);
                  loadSchoolUsers(schoolName);
                  setLogoImage(((School) mResourceObject).getLogo());
                }

                mProgressBar.setVisibility(View.GONE);
              }
            });
        break;

      case Constants.GROUP_RESOURCE:
        mProgressBar.setVisibility(View.GONE);
        break;

      case Constants.ORGANIZATION_RESOURCE:
        mLogoImageButton.setVisibility(View.VISIBLE);
        mCropImageView.setVisibility(View.VISIBLE);

        ParseQuery<Organization> orgQuery = ParseQuery.getQuery(Organization.class);
        orgQuery.whereEqualTo(Constants.OBJECT_ID_KEY, mResourceObjectId);
        orgQuery.getFirstInBackground(
            new GetCallback<Organization>() {
              @Override
              public void done(Organization object, ParseException e) {
                if (e == null) {
                  mResourceObject = object;
                } else {
                  mResourceObject = new Organization();
                }

                if (!isNewAddition) {
                  String orgName = ((Organization) mResourceObject).getOrganizationName();
                  mTitleText.setText(orgName);
                  mDescriptionText.setText(((Organization) mResourceObject).getDescription());
                  mActiveStatus.setChecked(((Organization) mResourceObject).isActive());
                  mUserListContainer.setVisibility(View.VISIBLE);
                  // loadOrganizationUsers(orgName);
                  loadOrganizationEvents(orgName);
                  setLogoImage(((Organization) mResourceObject).getLogo());
                }

                mProgressBar.setVisibility(View.GONE);
              }
            });
        break;
        //
        //            case Constants.OPPORTUNITY_RESOURCE:
        //                mActivityMgmtContainer.setVisibility(View.VISIBLE);
        //                initializeOrganizationSpinner(mActivityOrgSpinner);
        //                initializeCategorySpinner();
        //
        //                mResourceObject =
        // VolunteerOpportunity.getOpportunityDetails(mResourceObjectId);
        //
        //
        //
        //                mProgressBar.setVisibility(View.GONE);
        //
        //                break;
    }
    // endregion
  }