コード例 #1
1
  public void onClick(View v, int position, int countitem) {
    ImageView selectedShip = ((MapBuilder) context).getSelectedShip();
    if (selectedShip != null) {
      ShipOnMap som = new ShipOnMap();
      RelativeLayout fl = (RelativeLayout) v;
      RelativeLayout.LayoutParams params =
          new RelativeLayout.LayoutParams(selectedShip.getWidth(), selectedShip.getHeight());
      som.start.x = x;
      som.start.y = y - v.getTop();
      som.time = (countitem - 1 - position) * 3 + 1;
      String[] shipinfo = ((String) selectedShip.getTag()).split(":");
      som.type = shipinfo[0];
      som.weapon = shipinfo[1];
      params.leftMargin = x - (selectedShip.getWidth() / 2);
      params.topMargin = y - v.getTop() - (selectedShip.getHeight() / 2);
      ImageView iv = new ImageView(context);
      iv.setImageDrawable(selectedShip.getDrawable());
      int h = fl.getHeight();
      int w = fl.getWidth();
      if (!ship.containsKey(position)) {
        ship.put(position, new LinkedList<ShipOnMap>());
      }

      som.ship = iv.getDrawable();
      som.param = params;
      List<ShipOnMap> lship = ship.get(position);
      lship.add(som);
      iv.setTag(position + "/" + (lship.size() - 1));
      ((MapBuilder) context).registerForContextMenu(iv);
      fl.addView(iv, params);
      fl.getLayoutParams().height = h;
      fl.getLayoutParams().width = w;
    }
  }
コード例 #2
1
  private void recomputePhotoAndScrollingMetrics() {
    mHeaderHeightPixels = mHeaderBox.getHeight();

    mPhotoHeightPixels = 0;
    if (mHasPhoto) {
      mPhotoHeightPixels = (int) (mPhotoView.getWidth() / PHOTO_ASPECT_RATIO);
      mPhotoHeightPixels = Math.min(mPhotoHeightPixels, mScrollView.getHeight() * 2 / 3);
    }

    ViewGroup.LayoutParams lp;
    lp = mPhotoViewContainer.getLayoutParams();
    if (lp.height != mPhotoHeightPixels) {
      lp.height = mPhotoHeightPixels;
      mPhotoViewContainer.setLayoutParams(lp);
    }

    ViewGroup.MarginLayoutParams mlp =
        (ViewGroup.MarginLayoutParams) mDetailsContainer.getLayoutParams();
    if (mlp.topMargin != mHeaderHeightPixels + mPhotoHeightPixels) {
      mlp.topMargin = mHeaderHeightPixels + mPhotoHeightPixels;
      mDetailsContainer.setLayoutParams(mlp);
    }

    onScrollChanged(0, 0); // trigger scroll handling
  }
コード例 #3
0
  private void dragView(int x, int y) {
    if (mRemoveMode == SLIDE) {
      float alpha = 1.0f;
      int width = mDragView.getWidth();
      if (x > width / 2) {
        alpha = ((float) (width - x)) / (width / 2);
      }
      mWindowParams.alpha = alpha;
    }

    if (mRemoveMode == FLING || mRemoveMode == TRASH) {
      mWindowParams.x = x - mDragPointX + mXOffset;
    } else {
      mWindowParams.x = 0;
    }
    mWindowParams.y = y - mDragPointY + mYOffset;
    mWindowManager.updateViewLayout(mDragView, mWindowParams);

    if (mTrashcan != null) {
      int width = mDragView.getWidth();
      if (y > getHeight() * 3 / 4) {
        mTrashcan.setLevel(2);
      } else if (width > 0 && x > width / 4) {
        mTrashcan.setLevel(1);
      } else {
        mTrashcan.setLevel(0);
      }
    }
  }
コード例 #4
0
  private void setOverlayImage(int idx) {
    try {
      String groupPath = "images/overlays/svg/" + overlayGroup;

      if (overlays == null) overlays = getAssets().list(groupPath);

      bitmap =
          Bitmap.createBitmap(
              mOverlayView.getWidth(), mOverlayView.getHeight(), Bitmap.Config.ARGB_8888);
      canvas = new Canvas(bitmap);

      String imgPath = groupPath + '/' + overlays[idx];
      //    SVG svg = SVGParser.getSVGFromAsset(getAssets(), "images/overlays/svg/" +
      // overlays[idx],0xFFFFFF,0xCC0000);

      SVG svg = SVGParser.getSVGFromAsset(getAssets(), imgPath);

      Rect rBounds = new Rect(0, 0, mOverlayView.getWidth(), mOverlayView.getHeight());
      Picture p = svg.getPicture();
      canvas.drawPicture(p, rBounds);

      mOverlayView.setImageBitmap(bitmap);
    } catch (IOException ex) {
      Log.e(AppConstants.TAG, "error rendering overlay", ex);
      return;
    }
  }
コード例 #5
0
ファイル: MainActivity.java プロジェクト: t-nagatani/jyuubako
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    float x = event.getX();
    float y = event.getY();
    textx.setText("x:" + x);
    texty.setText("y:" + y);

    viewx.setText("x:" + imageview.getWidth());
    viewy.setText("y:" + imageview.getHeight());

    percentx.setText("x:" + 100 * x / imageview.getWidth());
    percenty.setText("y:" + 100 * y / imageview.getHeight());
    // TODO Auto-generated method stub

    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        state.setText("Down");
        break;
      case MotionEvent.ACTION_MOVE:
        state.setText("Move");
        break;
      case MotionEvent.ACTION_UP:
        state.setText("UP");
        break;
    }
    return true; // ここメソッドの自動追加したらfalseだけど、trueにしないとMoveとか動かないんだ。
  }
コード例 #6
0
  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;
  }
コード例 #7
0
  private void setPic() {

    Log.d("setPic", "Display image " + mCurrentPhotoPath);

    ImageView imageView = (ImageView) findViewById(R.id.cameraImage);

    int targetW = imageView.getWidth();
    int targetH = imageView.getHeight();

    Log.d("setPic", "layout ( " + targetW + " * " + targetH + " )");

    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;

    Log.d("setPic", "display ( " + width + " * " + height + " )");

    imageView.getLayoutParams().width = ((width / 100) * 80);
    ;
    imageView.getLayoutParams().height = ((height / 100) * 80);
    imageView.requestLayout();

    targetW = imageView.getWidth();
    targetH = imageView.getHeight();

    Log.d("setPic", "new layout ( " + targetW + " * " + targetH + " )");

    /*
    // working for local image
            Bitmap bmp;
            bmp=BitmapFactory.decodeResource(getResources(),R.drawable.miau);//image is your image
            bmp=Bitmap.createScaledBitmap(bmp, targetW,targetH, true);
            imageView.setImageBitmap(bmp);
    */

    // Get the dimensions of the bitmap
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
    int photoW = bmOptions.outWidth;
    int photoH = bmOptions.outHeight;

    Log.d("setPic", "photo ( " + photoW + " * " + photoH + " )");

    // Determine how much to scale down the image
    int scaleFactor = Math.min(photoW / targetW, photoH / targetH);

    // Decode the image file into a Bitmap sized to fill the View
    bmOptions.inJustDecodeBounds = false;
    bmOptions.inSampleSize = scaleFactor;
    bmOptions.inPurgeable = true;

    Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
    imageView.setImageBitmap(bitmap);
  }
コード例 #8
0
  private void initAnimNow() {
    doRotate(imgArrawTop, 0, 180, imgArrawTop.getWidth() / 2, imgArrawTop.getHeight() / 2, 0);
    doRotate(
        imgArrawBottom, 180, 0, imgArrawBottom.getWidth() / 2, imgArrawBottom.getHeight() / 2, 0);

    textRefreshTimeTop.setText(
        con.getSharedPreferences(shareName, 1)
            .getString(
                SHARE_NAME_REFRESHNAME,
                DateFormat.format("yyyy/MM/dd kk:mm:ss", System.currentTimeMillis()).toString()));
  }
コード例 #9
0
  private void callCrop() {
    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setDataAndType(mImageCaptureUri, "image/*");

    intent.putExtra("scale", true);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri());
    intent.putExtra("outputX", mPicture.getWidth());
    intent.putExtra("outputY", mPicture.getHeight());
    intent.putExtra("aspectX", mPicture.getWidth());
    intent.putExtra("aspectY", mPicture.getHeight());
    startActivityForResult(intent, MainActivity.CROP_FROM_CAMERA);
  }
コード例 #10
0
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
          super.onSuccess(statusCode, headers, response);

          int result = 0;

          try {
            result = Integer.valueOf(response.getString("result"));
          } catch (NumberFormatException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
          if (result == 1 && statusCode == 200) {
            try {
              data.clear();
              JSONObject sData = response.getJSONObject("data");
              String img_url = LandousAppConst.special_img_head + sData.get("special_image");
              ImageLoader.getInstance()
                  .displayImage(img_url, banner, BeeFrameworkApp.options_no_default);

              android.view.ViewGroup.LayoutParams params = banner.getLayoutParams();
              params.height = banner.getWidth() / 5 * 2;
              params.width = banner.getWidth();
              banner.setLayoutParams(params);
              title.setText(sData.getString("special_title"));
              JSONArray array = sData.getJSONArray("special_product_list");
              for (int i = 0; i < array.length(); i++) {
                JSONObject jsonItem = array.getJSONObject(i);
                Map<String, String> map = new HashMap();
                String store_id = jsonItem.getString("store_id") + "/";
                map.put("goods_name", jsonItem.getString("goods_name"));
                map.put("store_name", jsonItem.getString("store_name"));
                map.put("goods_marketprice", jsonItem.getString("goods_marketprice"));
                map.put("goods_price", jsonItem.getString("goods_price"));
                map.put("goods_id", jsonItem.getString("goods_id"));
                map.put(
                    "goods_image",
                    LandousAppConst.HOME_IMG_URL + store_id + jsonItem.getString("goods_image"));
                data.add(map);
              }

            } catch (JSONException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
            goodsAdapter.notifyDataSetChanged();
            loadingPDialog.dismiss();
          }
        }
コード例 #11
0
  /**
   * Limit how much to drag the image
   *
   * @param m {@link Matrix} matrix of the current position of image
   * @param view {@link ImageView} the current image
   * @param imageWidth width of current image
   * @param imageHeight height of image
   */
  private void limitDrag(Matrix m, ImageView view, int imageWidth, int imageHeight) {
    float[] values = new float[9];
    m.getValues(values);
    float[] orig = new float[] {0, 0, imageWidth, imageHeight};
    float[] trans = new float[4];
    m.mapPoints(trans, orig);

    float transLeft = trans[0];
    float transTop = trans[1];
    float transRight = trans[2];
    float transBottom = trans[3];
    float transWidth = transRight - transLeft;
    float transHeight = transBottom - transTop;

    float xOffset = 0;
    if (transWidth > view.getWidth()) {
      if (transLeft > 0) {
        xOffset = -transLeft;
      } else if (transRight < view.getWidth()) {
        xOffset = view.getWidth() - transRight;
      }
    } else {
      if (transLeft < 0) {
        xOffset = -transLeft;
      } else if (transRight > view.getWidth()) {
        xOffset = -(transRight - view.getWidth());
      }
    }

    float yOffset = 0;
    if (transHeight > view.getHeight()) {
      if (transTop > 0) {
        yOffset = -transTop;
      } else if (transBottom < view.getHeight()) {
        yOffset = view.getHeight() - transBottom;
      }
    } else {
      if (transTop < 0) {
        yOffset = -transTop;
      } else if (transBottom > view.getHeight()) {
        yOffset = -(transBottom - view.getHeight());
      }
    }

    float transX = values[Matrix.MTRANS_X];
    float transY = values[Matrix.MTRANS_Y];

    values[Matrix.MTRANS_X] = transX + xOffset;
    values[Matrix.MTRANS_Y] = transY + yOffset;
    m.setValues(values);
  }
コード例 #12
0
ファイル: EasyDialog.java プロジェクト: qianjujun/EasyDialog
 /** 根据x,y,重新设置控件的位置 因为setX setY为0的时候,都是在状态栏以下的,所以app不是全屏的话,需要扣掉状态栏的高度 */
 private void relocation(int[] location) {
   ivTriangle.setX(location[0] - ivTriangle.getWidth() / 2);
   ivTriangle.setY(
       location[1]
           - ivTriangle.getHeight() / 2
           - (isFullScreen()
               ? 0.0f
               : getStatusBarHeight())); // 因为三角形是通过XML绘制出来的,可以到activity_tip_overlay.xml中把三角形的那个ImageView背景设置一下,就知道什么情况了。所以需要减掉一半的高度
   switch (gravity) {
     case GRAVITY_BOTTOM:
       llContent.setY(
           location[1]
               - ivTriangle.getHeight() / 2
               - (isFullScreen() ? 0.0f : getStatusBarHeight())
               + ivTriangle.getHeight());
       break;
     case GRAVITY_TOP:
       llContent.setY(
           location[1]
               - llContent.getHeight()
               - (isFullScreen() ? 0.0f : getStatusBarHeight())
               - ivTriangle.getHeight() / 2);
       break;
   }
   // 显示内容的区域往三角形靠拢
   int triangleCenterX = (int) (ivTriangle.getX() + ivTriangle.getWidth() / 2); // 三角形的中心点
   int contentWidth = llContent.getWidth();
   int rightMargin = getScreenWidth() - triangleCenterX; // 三角形中心距离屏幕右边的距离
   int leftMargin = getScreenWidth() - rightMargin; // 三角形中心距离屏幕左边的距离
   RelativeLayout.LayoutParams layoutParams =
       (RelativeLayout.LayoutParams) llContent.getLayoutParams();
   int availableLeftMargin = leftMargin - layoutParams.leftMargin; // 左边可用的距离
   int availableRightMargin = rightMargin - layoutParams.rightMargin; // 右边可用的距离
   int x = 0;
   if (contentWidth / 2 <= availableLeftMargin
       && contentWidth / 2 <= availableRightMargin) // 左右两边有足够的距离
   {
     x = triangleCenterX - contentWidth / 2;
   } else {
     if (availableLeftMargin <= availableRightMargin) // 判断三角形在屏幕中心的左边
     {
       x = layoutParams.leftMargin;
     } else // 三角形在屏幕中心的右边
     {
       x = getScreenWidth() - (contentWidth + layoutParams.rightMargin);
     }
   }
   llContent.setX(x);
 }
    void show(boolean animate) {
      text.setVisibility(View.VISIBLE);
      tab.setVisibility(View.VISIBLE);
      // target.setVisibility(View.INVISIBLE);
      if (animate) {
        boolean horiz = alignment == ALIGN_LEFT || alignment == ALIGN_RIGHT;
        int dx = horiz ? (alignment == ALIGN_LEFT ? tab.getWidth() : -tab.getWidth()) : 0;
        int dy = horiz ? 0 : (alignment == ALIGN_TOP ? tab.getHeight() : -tab.getHeight());

        Animation trans = new TranslateAnimation(-dx, 0, -dy, 0);
        trans.setDuration(ANIM_DURATION);
        tab.startAnimation(trans);
        text.startAnimation(trans);
      }
    }
コード例 #14
0
 /** Return to initial state */
 public void finish(int finishMode) {
   if (!mAttached) {
     return;
   }
   mTextHint.setVisibility(View.GONE);
   if (finishMode == FINISH_SLIDE_OUT) {
     PropertyValuesHolder slideX =
         PropertyValuesHolder.ofFloat(
             "translationX", new float[] {0.0f, mScreenshotView.getWidth()});
     mSlideoutAnimator = ObjectAnimator.ofPropertyValuesHolder(mScreenshotView, slideX);
     mSlideoutAnimator.setInterpolator(new AccelerateInterpolator());
     mSlideoutAnimator.setDuration(SLIDE_OUT_DURATION_MS);
     mSlideoutAnimator.addListener(this);
     mSlideoutAnimator.start();
   } else {
     float currentScale = mScreenshotView.getScaleX();
     float currentAlpha = mScreenshotView.getAlpha();
     PropertyValuesHolder scaleUpX =
         PropertyValuesHolder.ofFloat("scaleX", new float[] {currentScale, 1.0f});
     PropertyValuesHolder scaleUpY =
         PropertyValuesHolder.ofFloat("scaleY", new float[] {currentScale, 1.0f});
     PropertyValuesHolder scaleUpAlpha =
         PropertyValuesHolder.ofFloat("alpha", new float[] {currentAlpha, 1.0f});
     mScaleUpAnimator =
         ObjectAnimator.ofPropertyValuesHolder(mScreenshotView, scaleUpX, scaleUpY, scaleUpAlpha);
     mScaleUpAnimator.setInterpolator(new DecelerateInterpolator());
     mScaleUpAnimator.setDuration(SCALE_UP_DURATION_MS);
     mScaleUpAnimator.addListener(this);
     mScaleUpAnimator.start();
   }
 }
コード例 #15
0
 private float getTranslateX(float progress) {
   final int fairyEndX = mContentView.getWidth() / 2;
   final int fairyStartX = mImageViewFairy.getWidth() / 2;
   final int maxTravelDistance =
       Math.min(fairyEndX - fairyStartX, mContentView.getWidth() - mFairyContainer.getWidth());
   return maxTravelDistance * (progress / 100);
 }
コード例 #16
0
  private void checkMatrixBounds() {
    final ImageView imageView = getImageView();
    if (null == imageView) {
      return;
    }

    final RectF rect = getDisplayRect(getDisplayMatrix());
    if (null == rect) {
      return;
    }

    final float height = rect.height(), width = rect.width();
    float deltaX = 0, deltaY = 0;

    final int viewHeight = imageView.getHeight();
    if (height <= viewHeight) {
      switch (mScaleType) {
        case FIT_START:
          deltaY = -rect.top;
          break;
        case FIT_END:
          deltaY = viewHeight - height - rect.top;
          break;
        default:
          deltaY = (viewHeight - height) / 2 - rect.top;
          break;
      }
    } else if (rect.top > 0) {
      deltaY = -rect.top;
    } else if (rect.bottom < viewHeight) {
      deltaY = viewHeight - rect.bottom;
    }

    final int viewWidth = imageView.getWidth();
    if (width <= viewWidth) {
      switch (mScaleType) {
        case FIT_START:
          deltaX = -rect.left;
          break;
        case FIT_END:
          deltaX = viewWidth - width - rect.left;
          break;
        default:
          deltaX = (viewWidth - width) / 2 - rect.left;
          break;
      }
      mScrollEdge = EDGE_BOTH;
    } else if (rect.left > 0) {
      mScrollEdge = EDGE_LEFT;
      deltaX = -rect.left;
    } else if (rect.right < viewWidth) {
      deltaX = viewWidth - rect.right;
      mScrollEdge = EDGE_RIGHT;
    } else {
      mScrollEdge = EDGE_NONE;
    }

    // Finally actually translate the matrix
    mSuppMatrix.postTranslate(deltaX, deltaY);
  }
コード例 #17
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test_image);

    im = (ImageView) findViewById(R.id.image1);
    compass = (CompassView) findViewById(R.id.compass);

    int width = im.getWidth();
    LogUtil.d("width= " + width);
    int height = im.getHeight();
    LogUtil.d("height= " + height);

    //		getScreenDIP();

    DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    height = displayMetrics.heightPixels;
    width = displayMetrics.widthPixels;
    LogUtil.d("height: " + height);
    LogUtil.d("width: " + width);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, width);
    //		params.setMargins(margin, 0, margin, 0);
    //		params.rightMargin
    //		params.addRule(LinearLayout.ALIGN_PARENT_TOP);
    im.setLayoutParams(params);
  }
コード例 #18
0
  /**
   * Calculate Matrix for FIT_CENTER
   *
   * @param d - Drawable being displayed
   */
  private void updateBaseMatrix(Drawable d) {
    ImageView imageView = getImageView();
    if (null == imageView || null == d) {
      return;
    }

    final float viewWidth = imageView.getWidth();
    final float viewHeight = imageView.getHeight();
    final int drawableWidth = d.getIntrinsicWidth();
    final int drawableHeight = d.getIntrinsicHeight();

    mBaseMatrix.reset();

    final float widthScale = viewWidth / drawableWidth;
    final float heightScale = viewHeight / drawableHeight;

    if (mScaleType == ScaleType.CENTER) {
      mBaseMatrix.postTranslate(
          (viewWidth - drawableWidth) / 2F, (viewHeight - drawableHeight) / 2F);

    } else if (mScaleType == ScaleType.CENTER_CROP) {
      float scale = Math.max(widthScale, heightScale);
      mBaseMatrix.postScale(scale, scale);
      mBaseMatrix.postTranslate(
          (viewWidth - drawableWidth * scale) / 2F, (viewHeight - drawableHeight * scale) / 2F);

    } else if (mScaleType == ScaleType.CENTER_INSIDE) {
      float scale = Math.min(1.0f, Math.min(widthScale, heightScale));
      mBaseMatrix.postScale(scale, scale);
      mBaseMatrix.postTranslate(
          (viewWidth - drawableWidth * scale) / 2F, (viewHeight - drawableHeight * scale) / 2F);

    } else {
      RectF mTempSrc = new RectF(0, 0, drawableWidth, drawableHeight);
      RectF mTempDst = new RectF(0, 0, viewWidth, viewHeight);

      switch (mScaleType) {
        case FIT_CENTER:
          mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.CENTER);
          break;

        case FIT_START:
          mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.START);
          break;

        case FIT_END:
          mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.END);
          break;

        case FIT_XY:
          mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.FILL);
          break;

        default:
          break;
      }
    }

    resetMatrix();
  }
コード例 #19
0
ファイル: Utils.java プロジェクト: lymiao/MyMirror
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  private static ImageSize getImageViewSize(ImageView imageView) {
    ImageSize imageSize = new ImageSize();

    DisplayMetrics displayMetrics = imageView.getContext().getResources().getDisplayMetrics();
    ViewGroup.LayoutParams lp = imageView.getLayoutParams();

    /*
     * 获取图片压缩的宽和高
     * */
    int width = imageView.getWidth(); // 获取imageView的实际宽度
    if (width <= 0) {
      width = lp.width; // 获取imageView在布局中设置的宽度
    }
    if (width <= 0) {
      width = imageView.getMaxWidth();
    }
    if (width <= 0) {
      width = displayMetrics.widthPixels;
    }
    imageSize.width = width;
    int height = imageView.getHeight(); // 获取imageView的实际宽度
    if (height <= 0) {
      height = lp.height; // 获取imageView在布局中设置的宽度
    }
    if (height <= 0) {
      height = imageView.getMaxHeight();
    }
    if (height <= 0) {
      height = displayMetrics.heightPixels;
    }
    imageSize.height = height;
    return imageSize;
  }
コード例 #20
0
 public int[] getPreviewSize() {
   final ImageView i = (ImageView) findViewById(R.id.widget_preview);
   int[] maxSize = new int[2];
   maxSize[0] = i.getWidth() - mOriginalImagePadding.left - mOriginalImagePadding.right;
   maxSize[1] = i.getHeight() - mOriginalImagePadding.top;
   return maxSize;
 }
コード例 #21
0
ファイル: MainActivity.java プロジェクト: gudao20080/Temtest
  private void setPic() {
    // Get the dimensions of the View
    int targetW = mImageView.getWidth();
    int targetH = mImageView.getHeight();

    // Get the dimensions of the bitmap
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
    int photoW = bmOptions.outWidth;
    int photoH = bmOptions.outHeight;

    // Determine how much to scale down the image
    int scaleFactor = Math.min(photoW / targetW, photoH / targetH);

    // Decode the image file into a Bitmap sized to fill the View
    bmOptions.inJustDecodeBounds = false;
    bmOptions.inSampleSize = scaleFactor;
    bmOptions.inPurgeable = true;

    Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
    mImageView.setImageBitmap(bitmap);

    Intent intent = new Intent(this, CropImageActivity.class);
    //        intent.putExtra("bitmap", bitmap);
    MyApplication application = (MyApplication) getApplication();
    application.mBitmap = bitmap;
    startActivity(intent);

    String directoryDcim = Environment.DIRECTORY_DCIM;
  }
コード例 #22
0
  /**
   * 根据ImageView获得适当的压缩的宽和高
   *
   * @param imageView
   * @return
   */
  private ImageSize getImageViewWidth(ImageView imageView) {
    ImageSize imageSize = new ImageSize();
    final DisplayMetrics displayMetrics = imageView.getContext().getResources().getDisplayMetrics();
    final LayoutParams params = imageView.getLayoutParams();

    int width =
        params.width == LayoutParams.WRAP_CONTENT
            ? 0
            : imageView.getWidth(); // Get actual image width
    if (width <= 0) width = params.width; // Get layout width parameter
    if (width <= 0) width = getImageViewFieldValue(imageView, "mMaxWidth"); // Check
    // maxWidth
    // parameter
    if (width <= 0) width = displayMetrics.widthPixels;
    int height =
        params.height == LayoutParams.WRAP_CONTENT
            ? 0
            : imageView.getHeight(); // Get actual image height
    if (height <= 0) height = params.height; // Get layout height parameter
    if (height <= 0) height = getImageViewFieldValue(imageView, "mMaxHeight"); // Check
    // maxHeight
    // parameter
    if (height <= 0) height = displayMetrics.heightPixels;
    imageSize.width = width;
    imageSize.height = height;
    return imageSize;
  }
コード例 #23
0
ファイル: MenuFrg.java プロジェクト: dipeca/rs
  private void setPic() {

    /* There isn't enough memory to open up more than a couple camera photos */
    /* So pre-scale the target bitmap into which the file is decoded */

    /* Get the size of the ImageView */
    int targetW = mImageView.getWidth();
    int targetH = mImageView.getHeight();

    /* Get the size of the image */
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
    int photoW = bmOptions.outWidth;
    int photoH = bmOptions.outHeight;

    /* Figure out which way needs to be reduced less */
    int scaleFactor = 1;
    if ((targetW > 0) || (targetH > 0)) {
      scaleFactor = Math.min(photoW / targetW, photoH / targetH);
    }

    /* Set bitmap options to scale the image decode target */
    bmOptions.inJustDecodeBounds = false;
    bmOptions.inSampleSize = scaleFactor;
    bmOptions.inPurgeable = true;

    /* Decode the JPEG file into a Bitmap */
    Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);

    /* Associate the Bitmap to the ImageView */
    mImageView.setImageBitmap(bitmap);
    mImageView.setVisibility(View.VISIBLE);
  }
コード例 #24
0
ファイル: Utils.java プロジェクト: benkurama/iOTA-App
  // =========================================================================
  public static Bitmap setCustomizeImage(ImageView img, String imgPath) {
    // Get the dimensions of the View
    /** HOTSPOT BEGIN */
    int targetW = img.getWidth();
    int targetH = img.getHeight();

    // Get the dimensions of the bitmap
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(imgPath, bmOptions);
    int photoW = bmOptions.outWidth;
    int photoH = bmOptions.outHeight;

    // Determine how much to scale down the image
    int scaleFactor = Math.min(photoW / targetW, photoH / targetH);

    // Decode the image file into a Bitmap sized to fill the View
    bmOptions.inJustDecodeBounds = false;
    bmOptions.inSampleSize = scaleFactor;
    bmOptions.inPurgeable = true;

    Bitmap bitmap = BitmapFactory.decodeFile(imgPath, bmOptions);

    // try
    OutputStream stream;
    try {
      stream = new FileOutputStream(imgPath);
      bitmap.compress(CompressFormat.JPEG, 100, stream);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
    //
    /** HOTSPOT END */
    // region Saving Bitmap icon to sdcard icon folder RESERVED CODES FOR CREATING THUMBNAILS
    //	    String root = Environment.getExternalStorageDirectory().toString();
    //	    File myDir = new File(root + "/iOTA_Thumbs");
    //
    //	    if(!myDir.exists()){
    //	    	myDir.mkdirs();
    //	    }
    //
    //	    String fname = new File(imgPath).getName();
    //
    //	    File file = new File (myDir, fname);
    //
    //	    //if (file.exists ()) file.delete ();
    //	    try {
    //	           FileOutputStream out = new FileOutputStream(file);
    //	           bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
    //	           out.flush();
    //	           out.close();
    //
    //	    } catch (Exception e) {
    //	           e.printStackTrace();
    //	    }
    // endregion
    return bitmap;
  }
コード例 #25
0
  public static Rect getBitmapRectFromImageView(ImageView imageView) {
    Drawable drawable = imageView.getDrawable();
    Bitmap bitmap = null;
    if (drawable instanceof BitmapDrawable) {
      bitmap = ((BitmapDrawable) drawable).getBitmap();
    }

    Rect rect = new Rect();
    boolean result = imageView.getGlobalVisibleRect(rect);

    boolean checkWidth = rect.width() < imageView.getWidth();
    boolean checkHeight = rect.height() < imageView.getHeight();

    boolean clipped = !result || checkWidth || checkHeight;

    if (bitmap != null && !clipped) {

      int bitmapWidth = bitmap.getWidth();
      int bitmapHeight = bitmap.getHeight();

      int imageViewWidth = imageView.getWidth();
      int imageviewHeight = imageView.getHeight();

      float startScale;
      if ((float) imageViewWidth / bitmapWidth > (float) imageviewHeight / bitmapHeight) {
        // Extend start bounds horizontally
        startScale = (float) imageviewHeight / bitmapHeight;

      } else {
        startScale = (float) imageViewWidth / bitmapWidth;
      }

      bitmapHeight = (int) (bitmapHeight * startScale);
      bitmapWidth = (int) (bitmapWidth * startScale);

      int deltaX = (imageViewWidth - bitmapWidth) / 2;
      int deltaY = (imageviewHeight - bitmapHeight) / 2;

      rect.set(rect.left + deltaX, rect.top + deltaY, rect.right - deltaX, rect.bottom - deltaY);

      return rect;
    } else {
      return null;
    }
  }
コード例 #26
0
 @Override
 public void onBitmapDownloaded(ImageView holder, Bitmap image) {
   int width = holder.getWidth();
   int height = holder.getHeight();
   Bitmap thumbail =
       ThumbnailUtils.extractThumbnail(
           image, width, height, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
   holder.setImageBitmap(thumbail);
 }
コード例 #27
0
ファイル: ThumbnailView.java プロジェクト: aknik/SMSSecure
 @Override
 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
   super.onLayout(changed, left, top, right, bottom);
   if (removeButton != null) {
     final int paddingHorizontal = removeButton.getWidth() / 2;
     final int paddingVertical = removeButton.getHeight() / 2;
     image.setPadding(paddingHorizontal, paddingVertical, paddingHorizontal, 0);
   }
 }
  private void moveToEdge() {
    try {
      int w = floatingImage.getWidth();
      if (paramsF.x + w / 2 <= szWindow.x / 2) {
        final int x = paramsF.x;
        new CountDownTimer(500, 5) {
          public void onTick(long t) {
            long step = (500 - t) / 5;
            paramsF.x = (int) (double) bounceValue(step, x) - floatingImage.getWidth();
            try {
              windowManager.updateViewLayout(FloatingHorizontalLayout.this.floatingImage, paramsF);
            } catch (Exception ignored) {
            }
          }

          public void onFinish() {
            paramsF.x = 0;
            try {
              windowManager.updateViewLayout(FloatingHorizontalLayout.this.floatingImage, paramsF);
            } catch (Exception ignored) {
            }
            if (AppHelper.isSavePositionEnabled(context)) {
              AppHelper.savePosition(context, paramsF.y, paramsF.x);
            }
          }
        }.start();

      } else if (paramsF.x + w / 2 > szWindow.x / 2) {
        final int x = paramsF.x;
        new CountDownTimer(500, 5) {
          public void onTick(long t) {
            long step = (500 - t) / 5;
            paramsF.x = szWindow.x + (int) (double) bounceValue(step, x);
            try {
              windowManager.updateViewLayout(FloatingHorizontalLayout.this.floatingImage, paramsF);
            } catch (Exception ignored) {
            }
          }

          public void onFinish() {
            paramsF.x = szWindow.x - floatingImage.getWidth();
            try {
              windowManager.updateViewLayout(FloatingHorizontalLayout.this.floatingImage, paramsF);
            } catch (Exception ignored) {
            }
            if (AppHelper.isSavePositionEnabled(context)) {
              AppHelper.savePosition(context, paramsF.y, paramsF.x);
            }
          }
        }.start();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #29
0
  public void setData(int requestCode, Intent data) {

    String fileSrc = null;
    if (requestCode == RB_IMAGE_REQUEST_CODE) {
      if ("file".equals(data.getData().getScheme())) {
        // 有些低版本机型返回的Uri模式为file
        fileSrc = data.getData().getPath();
      } else {
        // Uri模型为content
        String[] proj = {MediaStore.Images.Media.DATA};
        Cursor cursor = getContentResolver().query(data.getData(), proj, null, null, null);
        cursor.moveToFirst();
        int idx = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        fileSrc = cursor.getString(idx);
        cursor.close();
      }
    } else if (requestCode == RB_CAMERA_REQUEST_CODE) {
      fileSrc = pictureFile.getAbsolutePath();
    }
    pictureFile = new File(fileSrc);
    Log.d(TAG, "fileSrc=" + fileSrc);
    // 获取图片的宽和高
    Options options = new Options();
    options.inJustDecodeBounds = true;
    Bitmap img = BitmapFactory.decodeFile(fileSrc, options);

    // 压缩图片
    options.inSampleSize =
        Math.max(
            1,
            (int)
                Math.ceil(
                    Math.max(
                        (double) options.outWidth / 1024f, (double) options.outHeight / 1024f)));
    options.inJustDecodeBounds = false;
    img = BitmapFactory.decodeFile(fileSrc, options);

    // 部分手机会对图片做旋转,这里检测旋转角度
    int degree = ImageTool.readPictureDegree(fileSrc);
    if (degree != 0) {
      // 把图片旋转为正的方向
      img = ImageTool.rotateImage(degree, img);
    }

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    // 可根据流量及网络状况对图片进行压缩
    img.compress(Bitmap.CompressFormat.JPEG, 80, baos);
    // byte[] imgData = baos.toByteArray();

    img_content.setImageBitmap(img);

    Log.d(TAG, img_content.getWidth() + "," + img_content.getHeight());
  }
 private void setViewForMiddle() {
   ImageView v = (ImageView) mMiddle.findViewById(R.id.long_bar);
   v.setImageResource(mid_image_selected_list[mSelectedPosition % mid_image_selected_list.length]);
   int t = v.getTop();
   int height = v.getHeight();
   int l = mSelectedPosition % ITEM_NUM * 240;
   int width = v.getWidth();
   RelativeLayout.LayoutParams lp = (LayoutParams) v.getLayoutParams();
   lp.leftMargin = mSelectedPosition % ITEM_NUM * 240;
   v.setLayoutParams(lp);
 }