forked from phonegap/phonegap-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
62 changes: 62 additions & 0 deletions
62
Android/Screenshot/v2.0.0/src/org/apache/cordova/Screenshot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Copyright (C) 2012 30ideas (http://30ide.as) | ||
* MIT licensed | ||
* | ||
* @author Josemando Sobral | ||
* @created Jul 2nd, 2012. | ||
*/ | ||
package org.apache.cordova; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
|
||
import org.apache.cordova.api.Plugin; | ||
import org.apache.cordova.api.PluginResult; | ||
import org.json.JSONArray; | ||
|
||
import android.graphics.Bitmap; | ||
import android.os.Environment; | ||
import android.view.View; | ||
|
||
public class Screenshot extends Plugin { | ||
|
||
@Override | ||
public PluginResult execute(String action, JSONArray args, String callbackId) { | ||
// starting on ICS, some WebView methods | ||
// can only be called on UI threads | ||
final Plugin that = this; | ||
final String id = callbackId; | ||
super.cordova.getActivity().runOnUiThread(new Runnable() { | ||
//@Override | ||
public void run() { | ||
View view = webView.getRootView(); | ||
|
||
view.setDrawingCacheEnabled(true); | ||
Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache()); | ||
view.setDrawingCacheEnabled(false); | ||
|
||
try { | ||
File folder = new File(Environment.getExternalStorageDirectory(), "Pictures"); | ||
if (!folder.exists()) { | ||
folder.mkdirs(); | ||
} | ||
|
||
File f = new File(folder, "screenshot_" + System.currentTimeMillis() + ".png"); | ||
|
||
FileOutputStream fos = new FileOutputStream(f); | ||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); | ||
that.success(new PluginResult(PluginResult.Status.OK), id); | ||
|
||
} catch (IOException e) { | ||
that.success(new PluginResult(PluginResult.Status.IO_EXCEPTION, e.getMessage()), id); | ||
} | ||
} | ||
}); | ||
|
||
PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT); | ||
result.setKeepCallback(true); | ||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* This code is adapted from the work of Michael Nachbaur | ||
* by Simon Madine of The Angry Robot Zombie Factory | ||
* - Converted to Cordova 1.6.1 by Josemando Sobral. | ||
* - Converted to Cordova 2.0.0 by Simon MacDonald | ||
* 2012-07-03 | ||
* MIT licensed | ||
*/ | ||
|
||
cordova.define("cordova/plugin/screenshot", function(require, exports, module) { | ||
var exec = require('cordova/exec'); | ||
|
||
/** | ||
* This class exposes the ability to take a Screenshot to JavaScript | ||
*/ | ||
var Screenshot = function() {}; | ||
|
||
/** | ||
* Save the screenshot to the user's Photo Library | ||
*/ | ||
Screenshot.prototype.saveScreenshot = function() { | ||
exec(null, null, "Screenshot", "saveScreenshot", []); | ||
}; | ||
|
||
var screenshot = new Screenshot(); | ||
module.exports = screenshot; | ||
|
||
}); | ||
|
||
if (!window.plugins) { | ||
window.plugins = {}; | ||
} | ||
if (!window.plugins.screenshot) { | ||
window.plugins.screenshot = cordova.require("cordova/plugin/screenshot"); | ||
} |