UnsupportedOperationException в GLES20Canvas.clipPath с отключенным аппаратным ускорением в представлении

В моем приложении включено аппаратное ускорение, но я отключил его для одного из своих представлений, потому что у меня были проблемы с заглавными буквами и другими вещами.

Теперь я получаю следующую трассировку стека в консоли Google Play Crash Errors:

java.lang.UnsupportedOperationException
at android.view.GLES20Canvas.clipPath(GLES20Canvas.java:287)
at com.myapp.MyCustomView.onDraw(SourceFile:288)
at android.view.View.draw(View.java:9310)
at android.view.View.getDisplayList(View.java:8773)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2298)
...
at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:609)
at android.view.ViewRoot.draw(ViewRoot.java:1634)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1450)
at android.view.ViewRoot.handleMessage(ViewRoot.java:2094)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4123)
...

Я указал android:hardwareAccelerated="true"в AndroidManifest.xml. Но я специально отключил аппаратное ускорение в конструкторе своего пользовательского представления:

    public MyCustomView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);

            // ... code omitted

            // disable acceleration because Paint.setStrokeCap(Cap.ROUND) is not working otherwise
            Compatibility.disableHardwareAcceleration(this);
    }

С учетом совместимости:

public class Compatibility {
        // View.setLayerType() was introduced in Honeycomb
        private static Method setLayerTypeMethod = getMethod(View.class, "setLayerType", int.class,
                        Paint.class);

        private static Method getMethod(Class<?> clazz, String name, Class<?>... parameterTypes) {
                try {
                        return clazz.getMethod(name, parameterTypes);
                }
                catch (NoSuchMethodException e) {
                        return null;
                }
        }

        private Compatibility() {
        }

        public static void disableHardwareAcceleration(View view) {
                try {
                        if (setLayerTypeMethod != null) {
                                int layerType = 1; // View.LAYER_TYPE_SOFTWARE
                                setLayerTypeMethod.invoke(view, layerType, null);
                        }
                }
                catch (Exception ignored) {
                }
        }
}

К сожалению, консоль Crash Errors не показывает информацию о версии ОС Android или устройстве.

Любые идеи, что может происходить?

8
задан devconsole 16 April 2012 в 12:21
поделиться