/** @brief Set Picture */ public void setElementImage(Drawable image) { // any change? if (image == mElementImageDrawable.getElementImage()) return; // remember mElementImageDrawable.setElementImage(image); // redraw doLayout(); }
/** * @brief Helper function to get aspect ratio * @return Current valid aspect ratio */ private float getElementAspectRatio() { if (mElementImageDrawable == null) return CONST_ASPECT_RATIO; if (mElementImageDrawable.getIntrinsicWidth() >= mElementImageDrawable.getIntrinsicHeight()) { return CONST_ASPECT_RATIO; } else { return 1 / CONST_ASPECT_RATIO; } }
/** @brief update function for the image layer (image self, image gradient, image inner-shadow) */ private void updateElementImageDrawable(Rect bounds) { PDEColor highColor, mainColor; PDEColor lowColor; // float placeHolderFrameDistance; Rect imgBounds; // int // placeHolderFrameDistance = (bounds.width() - polaroidRelativeValue(176.5f) )/2.0f + // Math.round(polaroidRelativeValue(2.5f)); // Rect frameRect = new Rect((int)placeHolderFrameDistance, // (int)placeHolderFrameDistance, // (int)placeHolderFrameDistance + // (int)polaroidRelativeValue(176.5f), // (int)placeHolderFrameDistance + // (int)polaroidRelativeValue(176.5f)); int border = Math.round(polaroidRelativeValue(2.5f)); // Rect frameRect = new Rect(bounds.left + border,bounds.top + border,bounds.right - // border, // bounds.bottom - border); Rect frameRect = new Rect(0, 0, bounds.width(), bounds.height()); // mElementImageDrawable.enableAspectRatio(false); // mElementImageDrawable.setBounds(frameRect.left + border, frameRect.top + border, // frameRect.right - 2 * border, // frameRect.right - border); mElementImageDrawable.setLayoutOffset(frameRect.left + 2 * border, frameRect.top + 2 * border); mElementImageDrawable.setLayoutWidth(frameRect.width() - 4 * border); Path clipPath; clipPath = new Path(); float radius = mElementPolaroidDrawable.getElementCornerRadius() - border / 2.0f; // calculate clip path // clipPath.addRoundRect(new RectF(mElementImageDrawable.getBounds().left /*+ border*/, // mElementImageDrawable.getBounds().top /*+ border*/, // mElementImageDrawable.getBounds().right, // mElementImageDrawable.getBounds().bottom),radius, // radius, // Path.Direction.CW); clipPath.addRoundRect( new RectF( 0.5f /*+ border*/, 0.5f /*+ border*/, mElementImageDrawable.getBounds().width() - 0.5f, mElementImageDrawable.getBounds().height() - 0.5f), radius, radius, Path.Direction.CW); clipPath.close(); // mElementImageDrawable.setElementClipPath(clipPath,true); mElementImageDrawable.setElementClipPath(clipPath); // Add some gradient to the image view. highColor = new PDEColor(1.0f, 1.0f, 1.0f, 0.5f); mainColor = new PDEColor(0.5f, 0.5f, 0.5f, 0.25f); lowColor = new PDEColor(0.0f, 0.0f, 0.0f, 0.0f); // highColor = new PDEColor(1.0f,0.0f,0.0f,0.5f); // mainColor = new PDEColor(1.0f,0.0f,0.0f,0.5f); // lowColor = new PDEColor(1.0f,0.0f,0.0f,0.5f); imgBounds = mElementImageDrawable.getBounds(); mElementImageGradientDrawable.setLayoutRect( new Rect(imgBounds.left - 1, imgBounds.top - 1, imgBounds.right + 1, imgBounds.bottom + 1)); mElementImageGradientDrawable.setElementBorderColor(PDEColor.valueOf("DTTransparentBlack")); mElementImageGradientDrawable.setElementCornerRadius(radius); mElementImageGradientDrawable.setElementBackgroundGradientColors( highColor, mainColor, lowColor); // set inner shadow on image mElementInnerShadowDrawable.setElementBlurRadius(polaroidRelativeValue(8.0f)); /* RectF layoutRect = new RectF(mElementImageDrawable.getBounds().left, mElementImageDrawable.getBounds().top, mElementImageDrawable.getBounds().right, mElementImageDrawable.getBounds().bottom);*/ mElementInnerShadowDrawable.setLayoutRect(mElementImageGradientDrawable.getBounds()); mElementInnerShadowDrawable.setElementShapeRoundedRect(radius); }
/** @brief Get Picture */ public Drawable getmElementImageDrawable() { return mElementImageDrawable.getElementImage(); }