@Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    super.onLayout(changed, l, t, r, b);

    final int width = r - l;
    final int height = b - t;

    /*
     * We can't use onSizeChanged here as this is called before the layout
     * of child View is actually done ... Because we need the size of some
     * child children we need to check for View size change manually
     */
    if (width != mPreviousWidth || height != mPreviousHeight) {

      mPreviousWidth = width;
      mPreviousHeight = height;

      mTouchDelegateGroup.clearTouchDelegates();

      // @formatter:off
      addTouchDelegate(
          new Rect(0, 0, mSelectButton.getWidth() + mTouchAddition, height),
          COLOR_SELECT_AREA,
          mSelectButton);

      addTouchDelegate(
          new Rect(width - mStarButton.getWidth() - mTouchAddition, 0, width, height),
          COLOR_STAR_AREA,
          mStarButton);
      // @formatter:on

      setTouchDelegate(mTouchDelegateGroup);
    }
  }
Example #2
0
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {

    Log.d(TAG, "I'm here in ImageCollector's onActivityResult");

    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == Activity.RESULT_OK) {

      int iBWidth = mImageButton.getWidth();
      int iBHeight = mImageButton.getHeight();

      // First decode with inJustDecodeBounds=true to check dimensions
      BitmapFactory.Options options = new BitmapFactory.Options();
      options.inJustDecodeBounds = true;
      BitmapFactory.decodeFile(mCurrentPhotoPath, options);

      // Calculate inSampleSize
      options.inSampleSize = ImageAdapter.calculateInSampleSize(options, iBWidth, iBHeight);
      options.inJustDecodeBounds = false;

      mImageButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
      mImageButton.setImageBitmap(BitmapFactory.decodeFile(mCurrentPhotoPath, options));

      GridView imageGrid = (GridView) findViewById(R.id.image_collector_grid);
      imageGrid.setAdapter(mAdapter);
      // mAdapter.loadBitmap(mImageButton, mThumbPosition);
      // mAdapter.notifyDataSetChanged();
    } else Log.d(TAG, "Image Capture Failed or Cancelled");
  }
  private void rotate(int degree) {
    ImageButton[] btns = {mButton, mMaskButton, mFocusButton};

    int target = 0;
    // TODO:for tablet
    if (degree == 0) {
      target = 0;
    } else if (degree == 90) {
      target = -90;
    } else if (degree == 180) {
      target = 180;
    } else if (degree == 270) {
      target = 90;
    }

    for (ImageButton btn : btns) {
      if (btn.equals(mMaskButton) && mMode == 1) {
        continue;
      }
      RotateAnimation rotate =
          new RotateAnimation(mPrevTarget, target, btn.getWidth() / 2, btn.getHeight() / 2);
      rotate.setDuration(500);
      rotate.setFillAfter(true);
      btn.startAnimation(rotate);
    }

    RotateAnimation rotate =
        new RotateAnimation(mPrevTarget, target, mText.getWidth() / 2, mText.getHeight() / 2);
    rotate.setDuration(500);
    rotate.setFillAfter(true);
    mText.startAnimation(rotate);

    RotateAnimation rotateZoomIn =
        new RotateAnimation(mPrevTarget, target, mZoomIn.getWidth() / 2, mZoomIn.getHeight() / 2);
    rotateZoomIn.setDuration(500);
    rotateZoomIn.setFillAfter(true);
    mZoomIn.startAnimation(rotateZoomIn);

    RotateAnimation rotateZoomOut =
        new RotateAnimation(mPrevTarget, target, mZoomOut.getWidth() / 2, mZoomOut.getHeight() / 2);
    rotateZoomOut.setDuration(500);
    rotateZoomOut.setFillAfter(true);
    mZoomOut.startAnimation(rotateZoomOut);

    // 回転時、表示がズレるので、断念
    /*
    if(mWebView != null){
        int x = mWebView.getWidth()/2;
        int y = mWebView.getHeight()/2;
        Log.d(TAG, "x,y = " + x + "," + y);
        RotateAnimation rotateWeb = new RotateAnimation(mPrevTarget, target, 100, 100);
        rotateWeb.setDuration(0);
        rotateWeb.setFillAfter(true);
        mWebView.startAnimation(rotate);
    }
    */

    mPrevTarget = target;
  }
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    parentWidth = (int) (MeasureSpec.getSize(widthMeasureSpec));
    parentHeight = (int) (MeasureSpec.getSize(heightMeasureSpec));
    startX = (parentWidth - button.getWidth()) / 2;
    startY = (parentHeight - button.getHeight()) / 2;
  }
 void enableMask() {
   // 隠しモードボタンを表示する(撮影時以下)
   if (mMode == 0) {
     mMaskButton.clearAnimation();
     mMaskButton.setVisibility(View.VISIBLE);
     // TODO:for tablet
     if (mDegree != 0) {
       RotateAnimation rotate =
           new RotateAnimation(
               0, mPrevTarget, mMaskButton.getWidth() / 2, mMaskButton.getHeight() / 2);
       rotate.setDuration(0);
       rotate.setFillAfter(true);
       mMaskButton.startAnimation(rotate);
     }
   }
 }
  void stop() {
    mPreview.stopShooting();
    mMode = 0;
    // フォーカスボタン、マスクボタン、ズームボタンを見えるようにする
    // mFocusButton.setVisibility(View.VISIBLE);
    mMaskButton.clearAnimation();
    mMaskButton.setVisibility(View.VISIBLE);
    // TODO:for tablet
    if (mDegree != 0) {
      RotateAnimation rotate =
          new RotateAnimation(
              0, mPrevTarget, mMaskButton.getWidth() / 2, mMaskButton.getHeight() / 2);
      rotate.setDuration(0);
      rotate.setFillAfter(true);
      mMaskButton.startAnimation(rotate);
    }

    if (mPreview.isZoomSupported()) {
      FrameLayout zoom = (FrameLayout) findViewById(R.id.zoom_layout);
      zoom.setVisibility(View.VISIBLE);
    }
  }
  /** Animates the pause button to a play button. */
  private void animatePauseToPlay() {

    // Check to make sure the current icon is the pause icon.
    if (mPlayPauseButton.getId() != R.drawable.pause_light) return;

    // Scale out the pause button.
    final ScaleAnimation scaleOut =
        new ScaleAnimation(
            1.0f,
            0.0f,
            1.0f,
            0.0f,
            mPlayPauseButton.getWidth() / 2,
            mPlayPauseButton.getHeight() / 2);
    scaleOut.setDuration(150);
    scaleOut.setInterpolator(new AccelerateInterpolator());

    // Scale in the play button.
    final ScaleAnimation scaleIn =
        new ScaleAnimation(
            0.0f,
            1.0f,
            0.0f,
            1.0f,
            mPlayPauseButton.getWidth() / 2,
            mPlayPauseButton.getHeight() / 2);
    scaleIn.setDuration(150);
    scaleIn.setInterpolator(new DecelerateInterpolator());

    scaleOut.setAnimationListener(
        new Animation.AnimationListener() {

          @Override
          public void onAnimationStart(Animation animation) {}

          @Override
          public void onAnimationEnd(Animation animation) {
            mPlayPauseButton.setImageResource(R.drawable.play_light);
            mPlayPauseButton.setPadding(0, 0, -5, 0);
            mPlayPauseButton.startAnimation(scaleIn);
          }

          @Override
          public void onAnimationRepeat(Animation animation) {}
        });

    scaleIn.setAnimationListener(
        new Animation.AnimationListener() {

          @Override
          public void onAnimationStart(Animation animation) {}

          @Override
          public void onAnimationEnd(Animation animation) {
            mPlayPauseButton.setScaleX(1.0f);
            mPlayPauseButton.setScaleY(1.0f);
            mPlayPauseButton.setId(R.drawable.play_light);
          }

          @Override
          public void onAnimationRepeat(Animation animation) {}
        });

    mPlayPauseButton.startAnimation(scaleOut);
  }
Example #8
0
  private void addPic(Intent data) {
    if (null != data) {
      Uri selectedImage = data.getData();
      String[] filePathColumn = {MediaStore.Images.Media.DATA};

      Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
      cursor.moveToFirst();

      int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
      String picturePath = cursor.getString(columnIndex);
      cursor.close();

      // 获取图片
      BitmapFactory.Options opts = new BitmapFactory.Options();
      opts.inJustDecodeBounds = true;
      BitmapFactory.decodeFile(picturePath, opts);
      opts.inSampleSize = computeSampleSize(opts, -1, 1080 * 700);
      opts.inJustDecodeBounds = false;
      final Bitmap bmp;
      try {
        bmp = BitmapFactory.decodeFile(picturePath, opts);
      } catch (OutOfMemoryError err) {
        showNotification(2, "图片太大!", R.id.root);
        return;
      }
      if (null == picsList) {
        picsList = new ArrayList<Bitmap>(4);
      }
      picsList.add(bmp);

      final ImageView image = new ImageView(PostActivity.this);
      LayoutParams params = (LayoutParams) btn_pic.getLayoutParams();
      params.width = btn_pic.getWidth();
      params.height = btn_pic.getHeight();
      image.setScaleType(ScaleType.CENTER_CROP);
      image.setLayoutParams(params);
      image.setImageBitmap(bmp);
      image.setClickable(true);
      image.setOnLongClickListener(
          new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
              if (null != mpics && mpics.getChildCount() > 0) {
                mpics.removeView(image);
                picsList.remove(bmp);
                mpics.postInvalidate();
                if (mpics.getChildCount() < 5) {
                  btn_pic.setVisibility(View.VISIBLE);
                }
                return true;
              }
              return false;
            }
          });
      int count = mpics.getChildCount();
      if (4 == count) {
        btn_pic.setVisibility(View.GONE);
      }
      mpics.addView(image, count - 1);
      mpics.postInvalidate();
    }
  }