コード例 #1
0
  /*
   * ParseQueryAdapter loads ParseFiles into a ParseImageView at whatever size
   * they are saved. Since we never need a full-size image in our app, we'll
   * save a scaled one right away.
   */
  private void saveScaledPhoto(Bitmap data) {

    Bitmap profileImageScaled =
        Bitmap.createScaledBitmap(
            data, Constants.LIST_IMAGE_SIZE, Constants.LIST_IMAGE_SIZE, false);

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    profileImageScaled.compress(Bitmap.CompressFormat.PNG, 100, bos);

    byte[] scaledData = bos.toByteArray();

    // Save the scaled image to Parse
    String fileName =
        mTitleText.getText().length() > 0
            ? mTitleText.getText() + "logo.png"
            : mResourceType + "logo.png";
    ParseFile logoImageFile = new ParseFile(fileName, scaledData);
    switch (mResourceType) {
      case Constants.ORGANIZATION_RESOURCE:
        ((Organization) mResourceObject).setLogo(logoImageFile);
        break;
      case Constants.SCHOOL_RESOURCE:
        ((School) mResourceObject).setLogo(logoImageFile);
        break;
      case Constants.INTEREST_RESOURCE:
        ((Interest) mResourceObject).setLogo(logoImageFile);
        break;
      case Constants.SKILL_RESOURCE:
        ((Skill) mResourceObject).setLogo(logoImageFile);
        break;
    }
  }
コード例 #2
0
  private void initializeOrganizationSpinner(Spinner control) {
    ArrayAdapter<String> dataAdapter =
        new ArrayAdapter<>(
            this,
            android.R.layout.simple_spinner_item,
            Strings.isNullOrEmpty(mUserOrganization)
                ? Organization.getAllActiveOrganizationNames()
                : Lists.newArrayList(mUserOrganization));

    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    control.setPromptId(R.string.org_input_hint);
    control.setAdapter(new SelectorHintAdapter(dataAdapter, R.layout.org_selector_hint, this));
  }
コード例 #3
0
  public void onSubmitClick(View v) {
    // Validate and Save the resource
    mProgressBar.setVisibility(View.VISIBLE);
    String errorMessage = validateResource();

    if (!Strings.isNullOrEmpty(errorMessage)) {
      showError(errorMessage);
      mProgressBar.setVisibility(View.GONE);
      return;
    }

    mSubmitButton.setEnabled(false);
    switch (mResourceType) {
      case Constants.ANNOUNCEMENT_RESOURCE:
        mResourceObject =
            Strings.isNullOrEmpty(mResourceObjectId)
                ? new Announcement()
                : ParseObject.createWithoutData(Announcement.class, mResourceObjectId);
        ((Announcement) mResourceObject).setAnnouncementText(mDescriptionText.getText().toString());
        ((Announcement) mResourceObject).setIsActive(mActiveStatus.isChecked());
        Announcement.saveAnnouncement((Announcement) mResourceObject, onResourceSave());
        break;

      case Constants.CATEGORY_RESOURCE:
        mResourceObject =
            Strings.isNullOrEmpty(mResourceObjectId)
                ? new Category()
                : ParseObject.createWithoutData(Category.class, mResourceObjectId);
        ((Category) mResourceObject).setCategoryName(mTitleText.getText().toString());
        ((Category) mResourceObject).setDescription(mDescriptionText.getText().toString());
        ((Category) mResourceObject).setCategoryColor(mColorHexText.getText().toString());
        ((Category) mResourceObject).setIsActive(mActiveStatus.isChecked());

        try {
          Category.saveCategory((Category) mResourceObject, onResourceSave());
        } catch (ParseException ex) {

        }

        break;

      case Constants.RECOGNITION_RESOURCE:
        mResourceObject =
            Strings.isNullOrEmpty(mResourceObjectId)
                ? new Recognition()
                : ParseObject.createWithoutData(Recognition.class, mResourceObjectId);
        ((Recognition) mResourceObject).setTitle(mTitleText.getText().toString());
        ((Recognition) mResourceObject).setDescription(mDescriptionText.getText().toString());
        ((Recognition) mResourceObject)
            .setPointsRequired(Integer.parseInt(mRecogReqPtsText.getText().toString()));
        ((Recognition) mResourceObject)
            .setMaxUnits(Integer.parseInt(mRecogMaxUnitsText.getText().toString()));
        ((Recognition) mResourceObject).setIsHoursBased(mRecognitionUnit.isChecked());
        ((Recognition) mResourceObject)
            .setRecognitionType(String.valueOf(mRecognitionTypeSpinner.getSelectedItem()));
        // TODO: Set logo
        ////// ((Recognition)mResourceObject).getLogo();
        ((Recognition) mResourceObject).setIsActive(mActiveStatus.isChecked());

        Recognition.saveRecognition((Recognition) mResourceObject, onResourceSave());
        break;

      case Constants.INTEREST_RESOURCE:
        mResourceObject =
            Strings.isNullOrEmpty(mResourceObjectId)
                ? new Interest()
                : ParseObject.createWithoutData(Interest.class, mResourceObjectId);
        ((Interest) mResourceObject).setInterestTitle(mTitleText.getText().toString());
        ((Interest) mResourceObject).setDescription(mDescriptionText.getText().toString());
        // TODO: Set logo
        ////// ((Interest)mResourceObject).getLogo();
        ((Interest) mResourceObject).setIsActive(mActiveStatus.isChecked());

        Interest.saveInterest((Interest) mResourceObject, onResourceSave());
        break;

      case Constants.SKILL_RESOURCE:
        mResourceObject =
            Strings.isNullOrEmpty(mResourceObjectId)
                ? new Skill()
                : ParseObject.createWithoutData(Skill.class, mResourceObjectId);
        ((Skill) mResourceObject).setSkillTitle(mTitleText.getText().toString());
        ((Skill) mResourceObject).setDescription(mDescriptionText.getText().toString());
        // TODO: Set logo
        // ((Skill)mResourceObject).setLogo();
        ((Skill) mResourceObject).setIsActive(mActiveStatus.isChecked());

        Skill.saveSkill((Skill) mResourceObject, onResourceSave());
        break;

      case Constants.USER_RESOURCE:
        mResourceObject =
            Strings.isNullOrEmpty(mResourceObjectId)
                ? new SpecialUser()
                : ParseObject.createWithoutData(SpecialUser.class, mResourceObjectId);
        ((SpecialUser) mResourceObject).setEmailId(mTitleText.getText().toString());
        ((SpecialUser) mResourceObject).setRole(String.valueOf(mUserRoleSpinner.getSelectedItem()));
        ((SpecialUser) mResourceObject)
            .setOrganizationName(String.valueOf(mUserOrgSpinner.getSelectedItem()));
        ((SpecialUser) mResourceObject).setIsActive(mActiveStatus.isChecked());
        SpecialUser.saveSpecialUser((SpecialUser) mResourceObject, onResourceSave());
        break;

      case Constants.SCHOOL_RESOURCE:
        mResourceObject =
            Strings.isNullOrEmpty(mResourceObjectId)
                ? new School()
                : ParseObject.createWithoutData(School.class, mResourceObjectId);
        ((School) mResourceObject).setSchoolName(mTitleText.getText().toString());
        ((School) mResourceObject).setDescription(mDescriptionText.getText().toString());
        // TODO: Set logo
        // ((School)mResourceObject).setLogo();
        ((School) mResourceObject).setIsActive(mActiveStatus.isChecked());
        School.saveSchool((School) mResourceObject, onResourceSave());
        break;

      case Constants.GROUP_RESOURCE:
        mResourceObject =
            Strings.isNullOrEmpty(mResourceObjectId)
                ? new InterestGroup()
                : ParseObject.createWithoutData(InterestGroup.class, mResourceObjectId);
        ((InterestGroup) mResourceObject).setGroupName(mTitleText.getText().toString());
        ((InterestGroup) mResourceObject)
            .setGroupDescription(mDescriptionText.getText().toString());
        // TODO: Set logo
        // ((InterestGroup)mResourceObject).setLogo();
        ((InterestGroup) mResourceObject).setIsActive(mActiveStatus.isChecked());
        InterestGroup.saveGroup((InterestGroup) mResourceObject, onResourceSave());
        // TODO: Add members
        break;

      case Constants.ORGANIZATION_RESOURCE:
        mResourceObject =
            Strings.isNullOrEmpty(mResourceObjectId)
                ? new Organization()
                : ParseObject.createWithoutData(Organization.class, mResourceObjectId);
        ((Organization) mResourceObject).setOrganizationName(mTitleText.getText().toString());
        ((Organization) mResourceObject).setDescription(mDescriptionText.getText().toString());
        // TODO: Set logo
        // ((Organization)mResourceObject).setLogo();
        ((Organization) mResourceObject).setIsActive(mActiveStatus.isChecked());

        Organization.saveOrganization((Organization) mResourceObject, onResourceSave());
        break;

      default:
        mResourceObject.saveInBackground(
            new SaveCallback() {
              @Override
              public void done(ParseException e) {
                Snackbar snackbar =
                    Snackbar.make(
                        mSaveResourceForm, R.string.msg_data_success, Snackbar.LENGTH_LONG);
                snackbar.show();
              }
            });
    }
    mProgressBar.setVisibility(View.GONE);
  }