Esempio n. 1
0
 public SelectedBitmap(
     Bitmap bitmap, File imagePath, int sizeKB, BitmapUtil.ByteBufferHolder buffer) {
   mBuilder = new Image.Builder();
   mBuilder.calculateHashAndPreferences(buffer, bitmap);
   mBuilder.setRelativeImagePath(User.extractRelativePathInsideTempDirectory(imagePath));
   mPathInTemp = imagePath;
   mEstimatedSizeKB = sizeKB;
 }
Esempio n. 2
0
 private synchronized void ensureTempDirectory() {
   if (mTempDirectory == null) {
     mTempDirectory = User.getTempDirectory();
     if (mTempDirectory == null) {
       throw new IllegalStateException("No temp directory available");
     }
   }
 }
Esempio n. 3
0
 /** Applies origin to all selected bitmaps. */
 private void applyOrigin() {
   String origin = User.getInstance().getOriginName();
   if (origin == null) {
     return;
   }
   synchronized (mSelectedBitmaps) {
     for (SelectedBitmap bitmap : mSelectedBitmaps) {
       bitmap.mBuilder.setOrigin(origin);
     }
   }
 }
Esempio n. 4
0
  /** Fills the data currently available into the views. Fills selected bitmaps data. */
  private void fillData() {
    String origin = User.getInstance().getOriginName();
    if (origin != null) {
      mOriginName.setText(origin);
    } else {
      mOriginName.setText("");
    }

    if (mBundleNameText != null) {
      mBundleName.setText(mBundleNameText);
    } else {
      mBundleName.setText("");
    }
    fillSelectedBitmapsData();
  }
Esempio n. 5
0
  /**
   * Checks and updates all status indicators, updates current image's status indicators. If all
   * checks are passed, the bundle is allowed to save.
   */
  private void updateStatus() {
    String userOrigin = User.getInstance().getOriginName();
    boolean originOk =
        userOrigin != null && userOrigin.equals(mOriginName.getText().toString().trim());
    applyStatus(mOriginStatus, originOk);
    boolean bundleNameOk =
        mBundleNameText != null && mBundleNameText.equals(mBundleName.getText().toString().trim());
    applyStatus(mBundleNameStatus, bundleNameOk);
    boolean bitmapsOk = mSelectedBitmaps.size() > 0 && mBitmapsSelectCount == 0;
    applyStatus(mBitmapsStatus, bitmapsOk);
    boolean imageInformationOk =
        getCompletedImageDataCount() == mSelectedBitmaps.size() && mSelectedBitmaps.size() > 0;
    applyStatus(mImageStatus, imageInformationOk);

    boolean allOk = originOk && bundleNameOk && bitmapsOk && imageInformationOk;
    mSave.setEnabled(allOk);
    if (allOk) {
      if (mSaveResult == ImageXmlWriter.RESULT_SUCCESS) {
        mProgressText.setText(R.string.bundle_creator_progress_saved);
      } else if (mSaveResult == ImageXmlWriter.RESULT_NONE) {
        mProgressText.setText(R.string.bundle_creator_progress_ready_to_save);
      } else {
        mProgressText.setText(
            mProgressText
                .getResources()
                .getString(R.string.bundle_creator_progress_error_result, mSaveResult));
      }
      mSave.setCompoundDrawablesWithIntrinsicBounds(0, 0, ACCEPT_RESOURCE, 0);
    } else {
      mSaving = false;
      mSave.setCompoundDrawablesWithIntrinsicBounds(0, 0, REFUSE_RESOURCE, 0);
      mProgressText.setText(R.string.bundle_creator_progress_info_missing);
    }
    updateCurrentImageStatus();
    fillImageHeaderData();
  }
Esempio n. 6
0
  public BundleCreator(Activity activity) {
    mSaveResult = ImageXmlWriter.RESULT_NONE;
    mActivity = activity;
    mBuffer = new BitmapUtil.ByteBufferHolder();
    mSelectedBitmaps = new ArrayList<>();
    LayoutInflater inflater =
        (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mView = inflater.inflate(R.layout.workshop_bundle_creator, null);

    // first obtain all relevant view references and setup listeners
    mProgressText = (TextView) mView.findViewById(R.id.progress_descr);
    mSave = (Button) mView.findViewById(R.id.bundle_save);
    mSave.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            onSaveStarted();
          }
        });
    mOriginStatus = (ImageView) mView.findViewById(R.id.origin_status);
    mOriginName = (EditText) mView.findViewById(R.id.bundle_origin);
    mOriginName.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence originText, int start, int before, int count) {
            boolean newOrigin = User.getInstance().saveOriginName(originText.toString());
            if (newOrigin) {
              applyOrigin();
            }
            updateStatus();
          }

          @Override
          public void afterTextChanged(Editable s) {}
        });

    mBundleNameStatus = (ImageView) mView.findViewById(R.id.bundle_name_status);
    mBundleName = (EditText) mView.findViewById(R.id.bundle_name);
    mBundleName.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence text, int start, int before, int count) {
            String fileName = User.isValidFileName(text.toString());
            if (fileName != null) {
              mBundleNameText = fileName;
            } else {
              mBundleNameText = null;
            }
            updateStatus();
          }

          @Override
          public void afterTextChanged(Editable s) {}
        });

    mBitmapsDescr = (TextView) mView.findViewById(R.id.bitmaps_descr);
    mBitmapsSelect = (Button) mView.findViewById(R.id.bitmap_open_selection);
    mBitmapsSelect.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            openSelectBitmaps();
          }
        });
    mBitmapsSelectProgress = (ProgressBar) mView.findViewById(R.id.bitmap_opening_progress);
    mBitmapsSelectProgress.setVisibility(View.INVISIBLE);
    mBitmapsSelectCount = 0;
    mBitmapsSelectProgress.setIndeterminate(true);
    mBitmapsStatus = (ImageView) mView.findViewById(R.id.bitmaps_status);

    mImageInformationContainer = mView.findViewById(R.id.image_information_container);
    mImageInformationContainer.setVisibility(View.INVISIBLE);
    mImageDescr = (TextView) mView.findViewById(R.id.image_descr);
    mImageStatus = (ImageView) mView.findViewById(R.id.image_status);

    mBitmapSnapshot = (ImageView) mView.findViewById(R.id.bitmap_snapshot);
    mNextImage = (ImageButton) mView.findViewById(R.id.next_image);
    mNextImage.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (mSaving) {
              return;
            }
            mDisplayedImageIndex++;
            fillImageData();
            updateStatus();
          }
        });
    mPreviousImage = (ImageButton) mView.findViewById(R.id.previous_image);
    mPreviousImage.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (mSaving) {
              return;
            }
            mDisplayedImageIndex--;
            fillImageData();
            updateStatus();
          }
        });

    mSolutionWordsStatus = (ImageView) mView.findViewById(R.id.solution_words_status);
    mSolutionWords = (EditText) mView.findViewById(R.id.solution_words);
    mSolutionWords.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (!mFillingImageData) {
              if (updateCurrentSolutionWords()) {
                updateStatus();
              }
            }
          }

          @Override
          public void afterTextChanged(Editable s) {}
        });
    mSolutionLanguages = (Spinner) mView.findViewById(R.id.solution_words_languages);
    mTongues = Tongue.values();
    mSolutionLanguages.setAdapter(
        new ArrayAdapter<>(mActivity, android.R.layout.simple_spinner_dropdown_item, mTongues));
    mSolutionLanguages.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (!mFillingImageData) {
              fillImageDataSolution();
            }
          }

          @Override
          public void onNothingSelected(AdapterView<?> parent) {
            if (!mFillingImageData) {
              fillImageDataSolution();
            }
          }
        });

    mAuthorStatus = (ImageView) mView.findViewById(R.id.author_status);
    TextWatcher authorInfoListener =
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (!mFillingImageData) {
              if (updateCurrentAuthorData()) {
                updateStatus();
              }
            }
          }

          @Override
          public void afterTextChanged(Editable s) {}
        };
    mAuthorName = (EditText) mView.findViewById(R.id.author_name);
    mAuthorName.addTextChangedListener(authorInfoListener);
    mAuthorSource = (EditText) mView.findViewById(R.id.author_source);
    mAuthorSource.addTextChangedListener(authorInfoListener);
    mAuthorExtras = (EditText) mView.findViewById(R.id.author_extras);
    mAuthorExtras.addTextChangedListener(authorInfoListener);
    mAuthorApplyToOthers = (Button) mView.findViewById(R.id.apply_author_info_to_others);
    mAuthorApplyToOthers.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            applyAuthorInfoToOthers();
          }
        });

    // wipe temp storage
    mTempDirectory = User.clearTempDirectory();

    // fill data into views
    fillData();

    // check for missing or illegal information and show this with status images
    updateStatus();
  }