siyamed / android-shape-imageview

Custom shaped android imageview components
MIT License
2.66k stars 599 forks source link

SVG-based ImageView can't be displayed on Samsung GT-N7100 #22

Open dannysunyu opened 9 years ago

dannysunyu commented 9 years ago

I run the sample code and find out that all svg-based ImageView can't be displayed on Samsung GT-N7100 and GT-I9100G. I don't have many handsets to test but those are the only handsets with the issue.

I am integrating this library into a commercial project and I am trying to figure out the cause. It's important for me to resolve the issue.

kingstone59 commented 8 years ago

Got the same issue on GT-I8190 stock 4.1.2. Any solution to detect if rendering fail or nothing display ?

dannysunyu commented 8 years ago

@kingstone59 In SvgShader.calculate, calls shapePath.addPath(path, pathMatrix); instead of shapePath.transform(path, pathMatrix);. That'll help!

kingstone59 commented 8 years ago

@dannysuen hapePath instead of shapePath ? Can't find your line in SvgShader.java Do you import library file directly in your project ?

dannysunyu commented 8 years ago

@kingstone59 Yes, I fixed the bug and put it as a library locally instead of remote dependency. Locate the calculate method of class SvgShader, and call shapePath.addPath(borderPath, pathMatrix); instead of shapePath.transform(pathMatrix, borderPath);. It resolves the issue.

kingstone59 commented 8 years ago

shapePath in SvgShader.java is type of PathInfo so to have add addPath to PathInfo public void addPath(Path dst, Matrix matrix) { path.addPath(dst, matrix); } But know nothing render (also with device that work with transform)

dannysunyu commented 8 years ago

Refer to this post: https://groups.google.com/forum/#!msg/android-developers/eTxV4KPy1G4/tAe2zUPCjMcJ

Add a method addPath in PathInfo:

public void addPath(Path dst, Matrix matrix) {
     dst.addPath(path, matrix);
}

Also I paste the code for calculate here:

@Override
public void calculate(int bitmapWidth, int bitmapHeight, float width, float height, float scale, float translateX, float translateY) {
    path.reset();
    borderPath.reset();

    pathDimensions[0] = shapePath.getWidth();
    pathDimensions[1] = shapePath.getHeight();

    pathMatrix.reset();

    scale = Math.min(width / pathDimensions[0], height / pathDimensions[1]);
    translateX = Math.round((width - pathDimensions[0] * scale) * 0.5f);
    translateY = Math.round((height - pathDimensions[1] * scale) * 0.5f);
    pathMatrix.setScale(scale, scale);
    pathMatrix.postTranslate(translateX, translateY);
//        shapePath.transform(pathMatrix, path);
    shapePath.addPath(path, pathMatrix);
    path.offset(borderWidth, borderWidth);

    if (borderWidth > 0) {
        pathMatrix.reset();
        float newWidth;
        float newHeight;
        float d;
        if (borderType == BORDER_TYPE_DEFAULT) {
            newWidth = viewWidth - borderWidth;
            newHeight = viewHeight - borderWidth;
            d = borderWidth / 2f;
        } else {
            newWidth = viewWidth;
            newHeight = viewHeight;
            d = 0;
        }
        scale = Math.min(newWidth / pathDimensions[0], newHeight / pathDimensions[1]);
        translateX = Math.round((newWidth - pathDimensions[0] * scale) * 0.5f + d);
        translateY = Math.round((newHeight - pathDimensions[1] * scale) * 0.5f + d);
        pathMatrix.setScale(scale, scale);
        pathMatrix.postTranslate(translateX, translateY);
//            shapePath.transform(pathMatrix, borderPath);
        shapePath.addPath(borderPath, pathMatrix);
//            borderPath.op(path, Path.Op.DIFFERENCE);
    }

    pathMatrix.reset();
    matrix.invert(pathMatrix);
    path.transform(pathMatrix);
}