Skip to content

Commit

Permalink
Add support for named screenshots
Browse files Browse the repository at this point in the history
Also remove file prefix option as it might not be necessary.
  • Loading branch information
rtyley committed Feb 7, 2012
1 parent f638013 commit d0b6009
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
package com.github.rtyley.android.screenshot.celebrity;

import static java.lang.Thread.sleep;

import android.util.Log;

import static java.lang.Thread.sleep;

public class Screenshots {

/**
* The paparazzo process filters logcat for this tag
*/
public static final String TAG = "screenshot_request";

public static void poseForScreenshot() {
poseForScreenshotWithKeyValueString("");
}

public static void poseForScreenshotNamed(String name) {
poseForScreenshotWithKeyValue("name", name);
}



private static void poseForScreenshotWithKeyValue(String key, String value) {
poseForScreenshotWithKeyValueString(key+"="+value);
}

private static void poseForScreenshotWithKeyValueString(String keyValueString) {
/* Note that the log message can not be blank, otherwise it won't
* register with logcat.
*/
Log.d(TAG, "{}");
Log.d(TAG, "{"+keyValueString+"}");

/* Wait for the development machine to take the screenshot (usually takes about
* half a second)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
package com.github.rtyley.android.screenshot.paparazzo.processors;

import static java.lang.String.format;
import static java.lang.System.currentTimeMillis;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.NumberFormat;
import java.util.Map;

public class ImageSaver implements ScreenshotProcessor {

private final File screenshotDirectory;
private final String fileNamePrefix;
private int screenshotCount = 0;

public ImageSaver(File screenshotDirectory, String fileNamePrefix) {
public ImageSaver(File screenshotDirectory) {
this.screenshotDirectory = screenshotDirectory;
this.fileNamePrefix = fileNamePrefix;
}

@Override
public void process(BufferedImage image, Map<String, String> requestData) {
File screenshotFile = new File(screenshotDirectory, fileNamePrefix + "-" + currentTimeMillis() + ".png");
public void process(BufferedImage image, Map<String, String> request) {
String name=request.containsKey("name")?request.get("name"):format("%04d", screenshotCount++);

File screenshotFile = new File(screenshotDirectory, name + ".png");
try {
// log.info("Writing " + screenshotFile.getAbsolutePath());
ImageIO.write(image, "png", screenshotFile);
} catch (IOException e) {
// log error?
}
}

@Override
public void finish() {
// No resources to dispose of
}

}

0 comments on commit d0b6009

Please sign in to comment.