Skip to content

Commit

Permalink
CMScreenshot: Fix for screen rotation
Browse files Browse the repository at this point in the history
Fix for devices with 90 or 270 degree screen rotation. I even tested it this time.

Change-Id: Ib209152dc436feaad8443e88eaf780fe267e6d46
  • Loading branch information
TomGiordano committed Jul 11, 2011
1 parent 08e96c9 commit 1ed9c01
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/com/cyanogenmod/screenshot/ScreenshotActivity.java
Expand Up @@ -74,7 +74,7 @@ void takeScreenshot()
try try
{ {
Process p = Runtime.getRuntime().exec("/system/bin/screenshot"); Process p = Runtime.getRuntime().exec("/system/bin/screenshot");
Log.d("Screenshot","Ran helper"); Log.d("CMScreenshot","Ran helper");
p.waitFor(); p.waitFor();
InputStream rawFile = new FileInputStream(mRawScreenshot); InputStream rawFile = new FileInputStream(mRawScreenshot);
mBitmap = BitmapFactory.decodeStream(rawFile); mBitmap = BitmapFactory.decodeStream(rawFile);
Expand All @@ -83,20 +83,16 @@ void takeScreenshot()
tmpshot.delete(); tmpshot.delete();


// valid values for ro.sf.hwrotation are 0, 90, 180 & 270 // valid values for ro.sf.hwrotation are 0, 90, 180 & 270
int rot = SystemProperties.getInt("ro.sf.hwrotation",0); int rot = 360-SystemProperties.getInt("ro.sf.hwrotation",0);


Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();


// First round, natural device rotation // First round, natural device rotation
if(rot > 0){ if(rot > 0 && rot < 360){
Log.d("CMScreenshot","rotation="+rot); Log.d("CMScreenshot","rotation="+rot);
Matrix matrix = new Matrix(); Matrix matrix = new Matrix();
matrix.postRotate(rot); matrix.postRotate(rot);
// if rot = 90 or 270 swap height and width mBitmap = Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), matrix, true);
if(rot==90 || rot==270)
mBitmap = Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getHeight(), mBitmap.getWidth(), matrix, true);
else
mBitmap = Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), matrix, true);
} }


// Second round, device orientation: // Second round, device orientation:
Expand Down

0 comments on commit 1ed9c01

Please sign in to comment.