CompareActivitypublic abstract class CompareActivity extends android.app.Activity
Fields Summary |
---|
private static final String | LOG_TAG | protected MainView | mHardwareView | protected android.graphics.Bitmap | mSoftwareBitmap | protected android.graphics.Bitmap | mHardwareBitmap | protected ErrorCalculator | mErrorCalculator | protected android.os.Handler | mHandler | Runnable | mDrawCallback | protected boolean | mRedrewFlag |
Methods Summary |
---|
protected abstract boolean | forceRecreateBitmaps()
| protected void | loadBitmaps()
Trace.traceBegin(Trace.TRACE_TAG_ALWAYS, "loadBitmaps");
if (forceRecreateBitmaps()) {
int width = mSoftwareBitmap.getWidth();
int height = mSoftwareBitmap.getHeight();
mSoftwareBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
mHardwareBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
}
Trace.traceBegin(Trace.TRACE_TAG_ALWAYS, "softwareDraw");
mHardwareView.draw(new Canvas(mSoftwareBitmap));
Trace.traceEnd(Trace.TRACE_TAG_ALWAYS);
try {
Method getHardwareLayer = View.class.getDeclaredMethod("getHardwareLayer");
if (!getHardwareLayer.isAccessible())
getHardwareLayer.setAccessible(true);
Object hardwareLayer = getHardwareLayer.invoke(mHardwareView);
if (hardwareLayer == null) {
Log.d(LOG_TAG, "failure to access hardware layer");
return;
}
Method copyInto = hardwareLayer.getClass()
.getDeclaredMethod("copyInto", Bitmap.class);
if (!copyInto.isAccessible())
copyInto.setAccessible(true);
Trace.traceBegin(Trace.TRACE_TAG_ALWAYS, "copyInto");
boolean success = (Boolean) copyInto.invoke(hardwareLayer, mHardwareBitmap);
Trace.traceEnd(Trace.TRACE_TAG_ALWAYS);
if (!success) {
Log.d(LOG_TAG, "failure to copy hardware layer into bitmap");
}
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
Trace.traceEnd(Trace.TRACE_TAG_ALWAYS);
| protected void | onCreateCommon(java.lang.Runnable postDrawCallback)
mDrawCallback = new Runnable() {
@Override
public void run() {
mRedrewFlag = true;
mHandler.post(postDrawCallback);
};
};
getWindow().setBackgroundDrawable(new ColorDrawable(0xffefefef));
ResourceModifiers.init(getResources());
mHardwareView = (MainView) findViewById(R.id.hardware_view);
mHardwareView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
mHardwareView.setBackgroundColor(Color.WHITE);
mHardwareView.addDrawCallback(mDrawCallback);
int width = getResources().getDimensionPixelSize(R.dimen.layer_width);
int height = getResources().getDimensionPixelSize(R.dimen.layer_height);
mSoftwareBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
mHardwareBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
mErrorCalculator = new ErrorCalculator(getApplicationContext(), getResources());
mHandler = new Handler();
|
|