Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with cordova's id of the package #30

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 2 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Clipboard
=========

Clipboard management plugin for Cordova/PhoneGap that supports iOS, Android, and Windows Phone 8.
Clipboard management plugin for Cordova/PhoneGap that supports iOS, Android, Windows, and Windows Phone 8.

## Usage

Install the plugin using the CLI, for instance with PhoneGap:

phonegap local plugin add https://github.com/VersoSolutions/CordovaClipboard
phonegap local plugin add danielsogl-cordova-plugin-clipboard

The plugin creates the object `cordova.plugins.clipboard` with the methods `copy(text, onSuccess, onError)` and `paste(onSuccess, onError)`.

Expand Down Expand Up @@ -36,27 +36,3 @@ Example:
## Acknowledgements

This plugin was inspired by [ClipboardManagerPlugin](https://github.com/jacob/ClipboardManagerPlugin) (Android) and [ClipboardPlugin](https://github.com/phonegap/phonegap-plugins/tree/master/iPhone/ClipboardPlugin) (iOS).

## License

The MIT License (MIT)

Copyright (c) 2013 Verso Solutions LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
40 changes: 40 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "danielsogl-cordova-plugin-clipboard",
"version": "1.0.2",
"description": "Clipboard management plugin for Cordova/PhoneGap",
"cordova": {
"id": "com.danielsogl.cordova.clipboard",
"platforms": [
"ios",
"android",
"wp8",
"windows"
]
},
"repository": {
"type": "git",
"url": "git+https://github.com/danielsogl/cordova-plugin-clipboard.git"
},
"keywords": [
"clipboard",
"copy",
"paste",
"ecosystem:cordova",
"cordova-ios",
"cordova-android",
"cordova-wp8",
"cordova-windows"
],
"engines": [
{
"name": "cordova",
"version": ">=4.0.0"
}
],
"author": "Daniel Sogl",
"license": "MIT",
"bugs": {
"url": "https://github.com/danielsogl/cordova-plugin-clipboard/issues"
},
"homepage": "https://github.com/danielsogl/cordova-plugin-clipboard#readme"
}
12 changes: 9 additions & 3 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="com.verso.cordova.clipboard"
version="0.1.0">
id="com.danielsogl.cordova.clipboard"
version="1.0.2">

<engines>
<engine name="cordova" version=">=3.0.0" />
<engine name="cordova" version=">=4.0.0" />
</engines>

<name>Clipboard</name>
Expand Down Expand Up @@ -56,4 +56,10 @@
<source-file src="src/wp8/Clipboard.cs" />
</platform>

<!-- Windows uwp -->
<platform name="windows">
<js-module src="src/windows/ClipboardProxy.js" name="ClipboardProxy">
<merges target="" />
</js-module>
</platform>
</plugin>
90 changes: 44 additions & 46 deletions src/android/Clipboard.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.verso.cordova.clipboard;
package com.danielsogl.cordova.clipboard;

import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
Expand All @@ -13,50 +13,48 @@
import android.content.ClipDescription;

public class Clipboard extends CordovaPlugin {

private static final String actionCopy = "copy";
private static final String actionPaste = "paste";

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
ClipboardManager clipboard = (ClipboardManager) cordova.getActivity().getSystemService(Context.CLIPBOARD_SERVICE);

if (action.equals(actionCopy)) {
try {
String text = args.getString(0);
ClipData clip = ClipData.newPlainText("Text", text);

clipboard.setPrimaryClip(clip);

callbackContext.success(text);

return true;
} catch (JSONException e) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
} catch (Exception e) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.toString()));
}
} else if (action.equals(actionPaste)) {
if (!clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.NO_RESULT));
}

try {
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
String text = item.getText().toString();

if (text == null) text = "";

callbackContext.success(text);

return true;
} catch (Exception e) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.toString()));
}
}

return false;

private static final String actionCopy = "copy";
private static final String actionPaste = "paste";

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
ClipboardManager clipboard = (ClipboardManager) cordova.getActivity().getSystemService(Context.CLIPBOARD_SERVICE);

if (action.equals(actionCopy)) {
try {
String text = args.getString(0);
ClipData clip = ClipData.newPlainText("Text", text);

clipboard.setPrimaryClip(clip);

callbackContext.success(text);

return true;
} catch (JSONException e) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
} catch (Exception e) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.toString()));
}
} else if (action.equals(actionPaste)) {
if (!clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.NO_RESULT));
}

try {
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
String text = item.getText().toString();

if (text == null) text = "";

callbackContext.success(text);

return true;
} catch (Exception e) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.toString()));
}
}
}


return false;
}
}
40 changes: 40 additions & 0 deletions src/windows/ClipboardProxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
var cordova = require('cordova');

module.exports = {

copy: function(successCallback, errorCallback, args) {
var text = "";
try {
text = args[0];
} catch (e) {
errorCallback(e);
return;
}

try {
var dataPackage = new Windows.ApplicationModel.DataTransfer.DataPackage();
dataPackage.setText(text);
Windows.ApplicationModel.DataTransfer.Clipboard.setContent(dataPackage);
successCallback(text);
} catch (e) {
errorCallback(e);;
}
},
paste: function(successCallback, errorCallback, args) {
var text = "";

try {
var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.getContent();
if (dataPackageView.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text)) {
dataPackageView.getTextAsync().then(function(value) {
text = value;
successCallback(text);
});
}
} catch (e) {
errorCallback(e);;
}
}
}; // exports

require("cordova/exec/proxy").add("Clipboard", module.exports);
14 changes: 7 additions & 7 deletions www/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ var cordova = require('cordova');

/**
* Clipboard plugin for Cordova
*
*
* @constructor
*/
function Clipboard () {}
function Clipboard() {}

/**
* Sets the clipboard content
Expand All @@ -14,9 +14,9 @@ function Clipboard () {}
* @param {Function} onSuccess The function to call in case of success (takes the copied text as argument)
* @param {Function} onFail The function to call in case of error
*/
Clipboard.prototype.copy = function (text, onSuccess, onFail) {
if (typeof text === "undefined" || text === null) text = "";
cordova.exec(onSuccess, onFail, "Clipboard", "copy", [text]);
Clipboard.prototype.copy = function(text, onSuccess, onFail) {
if (typeof text === "undefined" || text === null) text = "";
cordova.exec(onSuccess, onFail, "Clipboard", "copy", [text]);
};

/**
Expand All @@ -25,8 +25,8 @@ Clipboard.prototype.copy = function (text, onSuccess, onFail) {
* @param {Function} onSuccess The function to call in case of success
* @param {Function} onFail The function to call in case of error
*/
Clipboard.prototype.paste = function (onSuccess, onFail) {
cordova.exec(onSuccess, onFail, "Clipboard", "paste", []);
Clipboard.prototype.paste = function(onSuccess, onFail) {
cordova.exec(onSuccess, onFail, "Clipboard", "paste", []);
};

// Register the plugin
Expand Down