anoopch / AnalogGaugeView

Simple Analog Gauge Widget
Other
0 stars 0 forks source link

The needle animation is not working with android:hardwareAccelerated="true" in the manifest (for post Honeycomb devices) #2

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Turn on hardware acceleration in the manifest 
(android:hardwareAccelerated="true")

What is the expected output? What do you see instead?

I expect to see the needle moving. Instead the needle is not shown at all.

What version of the product are you using? On what operating system?

Tested on Android ICS (Galaxy Nexus) with hardware acceleration on.

Please provide any additional information below.

It has to do with the new rendering model introduced in Honeycomb but I'm not 
sure what are the steps to fix this problem.

Original issue reported on code.google.com by Evelyn...@gmail.com on 24 Aug 2012 at 8:44

GoogleCodeExporter commented 8 years ago
Hi,

I got the same problem on an Acer Iconia Tab with Android 4.0. Setting 
android:hardwareAccelerated="false" solves the problem, but this is could be a 
real solution.

Original comment by plin...@gmail.com on 19 Oct 2012 at 7:44

GoogleCodeExporter commented 8 years ago
This is a recognised problem by Google, the issue is that the HW Acceleration 
causes the path to be rasterized to a 1x1 output, so you can't see it.

I have a workaround, which checks for HW acceleration and draws a line rather 
than a path, it's not as pretty, but it's functional.

private void drawHand(Canvas canvas) {
        if (handInitialized) {
            float handAngle = degreeToAngle(handPosition);
            canvas.save(Canvas.MATRIX_SAVE_FLAG);
            canvas.rotate(handAngle, 0.5f, 0.5f);
            if(canvas.isHardwareAccelerated()) {
                handPaint.setStrokeWidth(0.01f);
                canvas.drawLine(0.5f, 0.7f,0.5f + 0.002f, 0.5f - 0.32f, handPaint);
            } else {
                canvas.drawPath(handPath, handPaint);
            }

            canvas.restore();

            canvas.drawCircle(0.5f, 0.5f, 0.01f, handScrewPaint);
        }
    }

This is easy to debug using the emulator, just set the Emulator to "Use host 
GPU" to see the behaviour change.

Original comment by doug.e...@gmail.com on 25 Feb 2013 at 4:30

GoogleCodeExporter commented 8 years ago
I've found a little bit nicer of a workaround.  With the above method, the 
needle is just a straight line.  What you can do instead is disable hardware 
acceleration on *only* the view you are needing the needle.  
In code, once you've initialized the view:

    private Gauge fuelGauge;
    fuelGauge = (Gauge) getActivity().findViewById(R.id.fuelGauge);

Turn off hardware acceleration
    fuelGauge.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

This leave global hardware acceleration on, but off on only the views needed.

Original comment by efrie...@gmail.com on 13 Jun 2014 at 7:16