Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8812] BlackBerry: Implement important Titanium.UI.Clipboard functionality

GitHub Issuen/a
TypeStory
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2013-04-11T22:20:49.000+0000
Affected Version/sn/a
Fix Version/s2013 Sprint 08 BB, 2013 Sprint 08, Release 3.2.0
ComponentsBlackBerry
Labelsnotable
ReporterFrancois Boisvert
AssigneeJosh Roesslein
Created2012-04-20T09:48:00.000+0000
Updated2017-03-03T00:54:02.000+0000

Description

Implement the methods for accessing and modifying data within the clipboard.

Acceptance Test

// Custom application MIME types for clipboard data.
const kTypeText = 'application/x-text',
      kTypeBlob = 'application/x-blob';

var win = Ti.UI.createWindow({
	backgroundColor: 'red',
	layout: 'vertical'
});

// Displays the current "plain text" in the clipboard.
var textLabel = Ti.UI.createLabel({
	text: Ti.UI.Clipboard.getText() || "No text."
});
win.add(textLabel);

// Displays the current custom text in the clipboard.
var customTextLabel = Ti.UI.createLabel({
	text: (Ti.UI.Clipboard.getData(kTypeText) || {text: 'No custom text.'}).text
});
win.add(customTextLabel);

// Displays the current custom blob data in the clipboard.
var customBlobLabel = Ti.UI.createLabel({
	text: (Ti.UI.Clipboard.getData(kTypeBlob) || {text: 'No custom blob.'}).text
});
win.add(customBlobLabel);

// Clears all data in clipboard.
var clearDataButton = Ti.UI.createButton({
	title: 'Clear Data'
});
clearDataButton.addEventListener('click', function() {
	Ti.UI.Clipboard.clearData();
});
win.add(clearDataButton);

// Paste some text into the clipboard.
var setTextButton = Ti.UI.createButton({
	title: 'Set Text'
});
setTextButton.addEventListener('click', function() {
	Ti.UI.Clipboard.setText('Text Inserted!');
});
win.add(setTextButton);

// Paste custom application data into the clipboard.
var setCustomDataButton = Ti.UI.createButton({
	title: 'Set Custom Data'
});
setCustomDataButton.addEventListener('click', function() {
	Ti.UI.Clipboard.setData(kTypeText, 'Custom Text!');

	var buffer = Ti.createBuffer({length: 16});
	'Custom Blob!'.split('').forEach(function(char, index) {
		buffer.fill(char.charCodeAt(0), index, 1);
	});
	Ti.UI.Clipboard.setData(kTypeBlob, buffer.toBlob());
});
win.add(setCustomDataButton);

win.open();

The three labels should display (in order from top to bottom)...

#* No text. #* No custom text. #* No custom blob.

Click "Set Text" then restart the app. The first label should read "Text Inserted!" now.

Close the app and open another app on the device (ex: browser). Copy some text into the clipboard.

Relaunch the test case app and the first label should now contained the text you copied.

Click "Set Custom Data" then restart the app.

The second label should read "Custom Text!" and the third label "Custom Blob!".

Click "Clear Data" and restart the app. The labels should be back to their initial values (step 1).

Comments

  1. Lee Morris 2017-03-03

    Closing ticket as Blackberry is no longer supported.

JSON Source