enable Hardware Accelerate - Android Hardware

Android examples for Hardware:Sensor

Description

enable Hardware Accelerate

Demo Code


//package com.java2s;

import android.graphics.Paint;

import android.util.Log;

import android.view.View;

public class Main {
    private static final String TAG = "ViewUtils";

    public static void enableHardwareAccelerate(View view) {
        if (view == null) {
            Log.w(TAG,//from  w w w. j ava 2 s  .c  o m
                    "Argument 'view' is null at enableHardwareAccelerate()");
            return;
        }

        if (android.os.Build.VERSION.SDK_INT < 14) {
            Log.w(TAG, "SDK level must >= 14 on enableHardwareAccelerate");
            return;
        }

        try {
            java.lang.reflect.Method method = View.class.getMethod(
                    "setLayerType", int.class, Paint.class);
            method.invoke(view, /*LAYER_TYPE_HARDWARE=*/2, (Paint) null);

        } catch (java.lang.reflect.InvocationTargetException e) {
            Log.w(TAG,
                    "Method setLayerType exception at enableHardwareAccelerate()",
                    e);
        } catch (Exception e) {
            Log.w(TAG, "Unexpect exception at enableHardwareAccelerate()",
                    e);
        }
    }
}

Related Tutorials