Android examples for Graphics:Canvas
is Canvas Hardware Accelerated
/**************************************************************************** **/*from ww w . ja v a 2 s.c om*/ ** Copyright (C) 2010-2012 UC Mobile Ltd. All Rights Reserved ** File : CanvasHelper.java ** ** Description : Use reflection to call methods on Canvas above Android 2.2 ** ** Creation : 2012/11/07 ** Author : Roger (yixx@ucweb.com) ** History : ** Creation, 2012/11/07, Roger, Create the file ** ****************************************************************************/ //package com.java2s; import java.lang.ref.WeakReference; import java.lang.reflect.Method; import android.graphics.Canvas; public class Main { public static final boolean IS_HARDWARE_ACCELERATED_FAST_CALL = true; private static Method methodIsHardwareAccelerated; private static WeakReference<Canvas> sLastCanvas; private static boolean sLastCanvasIsHardwareAccelerated; static public boolean isHardwareAccelerated(Canvas canvas) { // Return cached value, faster than use reflection if (sLastCanvas != null && sLastCanvas.get() == canvas) { return sLastCanvasIsHardwareAccelerated; } sLastCanvasIsHardwareAccelerated = false; if (methodIsHardwareAccelerated != null) { try { Object result = methodIsHardwareAccelerated.invoke(canvas); sLastCanvasIsHardwareAccelerated = (Boolean) result; } catch (Throwable t) { } } if (IS_HARDWARE_ACCELERATED_FAST_CALL) sLastCanvas = new WeakReference<Canvas>(canvas); return sLastCanvasIsHardwareAccelerated; } }