Back to project page BrokenDisplay.
The source code is released under:
Apache License
If you think the Android project BrokenDisplay listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.foolish.brokendisplay; //from w w w . j a v a 2s . co m import android.content.Context; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.view.Surface; import android.widget.ImageView; public class MyImageView extends ImageView { private Bitmap mSource; public MyImageView(Context context) { super(context); init(); } private MyImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(); } private MyImageView(Context context, AttributeSet attrs) { super(context, attrs); init(); } private void init() { mSource = BitmapFactory.decodeResource(getResources(), R.drawable.glass_test); } public int dpToPx(int dp) { DisplayMetrics displayMetrics = getResources().getDisplayMetrics(); int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT)); return px; } @Override protected void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); int rotation = getDisplay().getRotation(); int angle = 0; switch (rotation) { case Surface.ROTATION_90: angle = -90; break; case Surface.ROTATION_180: angle = 180; break; case Surface.ROTATION_270: angle = 90; break; default: angle = 0; break; } Matrix matrix = new Matrix(); matrix.postRotate(angle); Bitmap bmp = Bitmap.createBitmap(mSource, 0, 0, mSource.getWidth(), mSource.getHeight(), matrix, true); setImageBitmap(bmp); } }