Skip to content

Commit

Permalink
updated versions and name
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Perry committed Sep 19, 2016
1 parent c5eab17 commit 10f9f77
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 77 deletions.
39 changes: 3 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cordova-screenshot
==================

[![NPM version](http://img.shields.io/npm/v/com.darktalker.cordova.screenshot.svg?style=flat)](https://www.npmjs.com/package/com.darktalker.cordova.screenshot)
[![NPM version](http://img.shields.io/npm/v/com.sharerevolution.cordova.screenshot.svg?style=flat)](https://www.npmjs.com/package/com.sharerevolution.cordova.screenshot)


The Screenshot plugin allows your application to take screenshots of the current screen and save them into the phone.
Expand All @@ -16,44 +16,11 @@ cordova plugin add https://github.com/gitawego/cordova-screenshot.git

notice:
in iOS, only jpg format is supported
in Android, the default WebView and [Crosswalk](https://crosswalk-project.org/documentation/cordova.html) are both supported
in Android, [Crosswalk](https://crosswalk-project.org/documentation/cordova.html) is supported

##usage


```js
navigator.screenshot.save(function(error,res){
if(error){
console.error(error);
}else{
console.log('ok',res.filePath);
}
});
```
take screenshot with jpg and custom quality
```js
navigator.screenshot.save(function(error,res){
if(error){
console.error(error);
}else{
console.log('ok',res.filePath);
}
},'jpg',50);
```

define a filename
```js
navigator.screenshot.save(function(error,res){
if(error){
console.error(error);
}else{
console.log('ok',res.filePath); //should be path/to/myScreenshot.jpg
}
},'jpg',50,'myScreenShot');
```

screenshot files are stored in /sdcard/Pictures for android.

take screenshot and get it as Data URI
```js
navigator.screenshot.URI(function(error,res){
Expand All @@ -66,7 +33,7 @@ navigator.screenshot.URI(function(error,res){
},50);
```

##usage in AngularJS
##usage in AngularJS TODO: update to use URI

```js
.service('$cordovaScreenshot', ['$q', function ($q){
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "com.darktalker.cordova.screenshot",
"version": "0.1.5",
"description": "screenshot PhoneGap Plugin for Android",
"name": "com.sharerevolution.cordova.screenshot",
"version": "0.1.6",
"description": "screenshot Cordova Plugin for Android (Crosswalk) and iOS, only provides screenshot as URI, not as file.",
"cordova": {
"id": "com.darktalker.cordova.screenshot",
"id": "com.sharerevolution.cordova.screenshot",
"platforms": [
"android",
"ios",
Expand All @@ -12,7 +12,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/gitawego/cordova-screenshot.git"
"url": "git+https://github.com/perry2of5/cordova-screenshot.git"
},
"keywords": [
"cordova",
Expand All @@ -25,13 +25,13 @@
"engines": [
{
"name": "cordova",
"version": ">=3.0.0"
"version": ">=6.0.0"
}
],
"author": "Hongbo LU",
"author": "Tim Perry et. al. including Hongbo LU",
"license": "MIT",
"bugs": {
"url": "https://github.com/gitawego/cordova-screenshot/issues"
"url": "https://github.com/perry2of5/cordova-screenshot/issues"
},
"homepage": "https://github.com/gitawego/cordova-screenshot#readme"
"homepage": "https://github.com/perry2of5/cordova-screenshot#readme"
}
9 changes: 4 additions & 5 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin id="com.darktalker.cordova.screenshot" version="0.1.5"
<plugin id="com.sharerevolution.cordova.screenshot" version="0.1.6"
xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android" >
<name>Screenshot</name>
Expand All @@ -8,7 +8,7 @@
<keywords>cordova,screenshot</keywords>
<repo>https://github.com/gitawego/cordova-screenshot.git</repo>
<engines>
<engine name="cordova" version=">=3.0.0" />
<engine name="cordova" version=">=6.0.0" />
</engines>
<js-module src="www/Screenshot.js" name="screenshot">
<merges target="navigator.screenshot" />
Expand All @@ -21,10 +21,9 @@
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="/*">
<!-- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> -->
</config-file>
<source-file src="src/android/Screenshot.java" target-dir="src/com/darktalker/cordova/screenshot" />
<source-file src="src/android/PermissionHelper.java" target-dir="src/com/darktalker/cordova/screenshot" />
<source-file src="src/android/Screenshot.java" target-dir="src/com/sharerevolution/cordova/screenshot" />
<source-file src="src/android/PermissionHelper.java" target-dir="src/com/sharerevolution/cordova/screenshot" />
</platform>
<!-- ios -->
<platform name="ios">
Expand Down
2 changes: 1 addition & 1 deletion src/android/PermissionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Licensed to the Apache Software Foundation (ASF) under one
specific language governing permissions and limitations
under the License.
*/
package com.darktalker.cordova.screenshot;
package com.sharerevolution.cordova.screenshot;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down
4 changes: 3 additions & 1 deletion src/android/Screenshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
* @author Josemando Sobral
* @created Jul 2nd, 2012.
* improved by Hongbo LU
* changed 2016-09-02 by Tim Perry to remove save feature -- try to avoid prompting user for access to files
* when all I want is a screenshot of the current app.
*/
package com.darktalker.cordova.screenshot;
package com.sharerevolution.cordova.screenshot;

import android.Manifest;
import android.content.Intent;
Expand Down
3 changes: 2 additions & 1 deletion src/ios/Screenshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Copyright 2010 The Angry Robot Zombie Factory.
// - Converted to Cordova 1.6.1 by Josemando Sobral.
// MIT licensed
// changed 2016-09-02 by Tim Perry to remove save feature -- try to avoid prompting user for access to files
// when all I want is a screenshot of the current app.
//

#import <Foundation/Foundation.h>
Expand All @@ -14,7 +16,6 @@
@interface Screenshot : CDVPlugin {
}

//- (void)saveScreenshot:(NSArray*)arguments withDict:(NSDictionary*)options;
- (void)saveScreenshot:(CDVInvokedUrlCommand*)command;
- (void)getScreenshotAsURI:(CDVInvokedUrlCommand*)command;
@end
27 changes: 3 additions & 24 deletions src/ios/Screenshot.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
//
// Modifications to support orientation change by @ffd8
//
// changed 2016-09-02 by Tim Perry to remove save feature -- try to avoid prompting user for access to files
// when all I want is a screenshot of the current app.
//

#import <Cordova/CDV.h>
#import "Screenshot.h"
Expand All @@ -27,30 +30,6 @@ - (UIImage *)getScreenshot
return img;
}

- (void)saveScreenshot:(CDVInvokedUrlCommand*)command
{
NSString *filename = [command.arguments objectAtIndex:2];
NSNumber *quality = [command.arguments objectAtIndex:1];

NSString *path = [NSString stringWithFormat:@"%@.jpg",filename];
NSString *jpgPath = [NSTemporaryDirectory() stringByAppendingPathComponent:path];

UIImage *image = [self getScreenshot];
NSData *imageData = UIImageJPEGRepresentation(image,[quality floatValue]);
[imageData writeToFile:jpgPath atomically:NO];

CDVPluginResult* pluginResult = nil;
NSDictionary *jsonObj = [ [NSDictionary alloc]
initWithObjectsAndKeys :
jpgPath, @"filePath",
@"true", @"success",
nil
];

pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:jsonObj];
NSString* callbackId = command.callbackId;
[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
}

- (void) getScreenshotAsURI:(CDVInvokedUrlCommand*)command
{
Expand Down

0 comments on commit 10f9f77

Please sign in to comment.