Repository files navigation

Appcelerator Titanium :: SquareCamera

An Appcelerator Titanium module that uses AVFoundation to allow for a much more customizable camera.

I have wanted (multiple times now) the option of being able to customize the camera size, shape, and functionality without just using the camera overlay. This lets you do that :)

  • NOTE: The name can be misleading, the camera does not HAVE to be a square :)

Supports

Devices

- iPhone (Tested with 3G, 3GS, 4, 4s, 5, 5c and 5s, 6, and 6s) - iPad (Tested with multiple iPads) - iPod Touch

iOS Versions

- 6.0+ (up to the latest iOS 8) - [7.0+ for 2d code detection in module version 0.7]

Titanium SDK Versions

- 3.2.0 - 3.2.1 - 3.2.3 - 3.3.X - 3.4.0 - 3.4.1 - 3.4.2 - 3.5.0.GA - 5.0.0.GA - 5.0.2.GA
  • Note: I am sure it works on many more versions than this, but these are just the one's I've used

Setup

Include the module in your tiapp.xml:


com.mfogg.squarecamera

Usage


var SquareCamera = require('com.mfogg.squarecamera'); // Initialize the SquareCamera module
// open a single window
var win = Ti.UI.createWindow({backgroundColor:"#eee"});
var camera_view = SquareCamera.createView({
top: 0,
height: 320,
width: 320,
backgroundColor: "#fff",
frontQuality: SquareCamera.QUALITY_HIGH, // Optional Defaults to QUALITY_HIGH
backQuality: SquareCamera.QUALITY_HD, // Optional Defaults to QUALITY_HD
camera: "back" // Optional "back" or "front",
forceHorizontal: true, // Optional sets the camera to horizontal mode if you app is horizontal only (Default false)
detectCodes: true, // Since version 0.7 : optional boolean to activate 2d code detection. Dection fires "code" event contaning e.codeType and e.value -All codes types are supported. Will not work on iPhone 4 with iOS 7 (crashes upon adding SquareCamera to view).
scanCrop: { // Available since v 0.8
x: ((Ti.Platform.displayCaps.platformWidth-220)/2),
y: ((Ti.Platform.displayCaps.platformHeight-220)/2),
width: 220,
height: 220
},
scanCropPreview: true, // Available since v 0.8
barcodeTypes: [ // Available since v 0.8
"UPCE",
"UPCA",
"EAN13",
"CODE128"
]
});
var label_message = Ti.UI.createLabel({
height:Ti.UI.SIZE,
left:10,
right:10,
text:'ready',
top:330,
});
var image_preview = Ti.UI.createImageView({
right: 10,
bottom: 10,
width: 160,
borderWidth:1,
borderColor:'#ddd',
height: 160,
backgroundColor: '#444'
});
camera_view.addEventListener("success", function(e){
image_preview.image = e.media;
});
win.add(cameraView);
// Since 0.7 : 2d code detection. Requires detectCodes:true on the camera view.
camera_view.addEventListener("code", function(e){
label_message.text = e.codeType+' : '+e.value;
});
win.add(cameraView);
win.add(label_message);
win.add(image_preview);
win.open();
  • NOTE: The created view (ex. 'camera_view' above) can have other views added on top of it to act as a camera overlay (exactly how you would a standard Ti.UI.view)

Camera Quality

You are now able to change the quality when initializing the camera by setting frontQuality and backQuality parameters.


SquareCamera.QUALITY_LOW // AVCaptureSessionPresetLow
SquareCamera.QUALITY_MEDIUM // AVCaptureSessionPresetMedium
SquareCamera.QUALITY_HIGH // AVCaptureSessionPresetHigh
SquareCamera.QUALITY_HD // AVCaptureSessionPreset1920x1080 (Note: back camera only)

Detect Codes

As of 0.7 @kosso added the ability to detect barcodes. I've extended this functionality to allow you to:

Set a certain area of the screen that is able to detect codes using scanCrop:


scanCrop: {
x: 0,
y: 0,
width: 220,
height: 220
}

Make the scanCrop area slightly red for testing/debugging:


scanCropPreview: true

Set which types of barcodes you'd like to scan when the view is initialized:


barcodeTypes: [
"UPCE",
"EAN13"
]
Available Code Types:
UPCE
Code39
Code39Mod43
EAN13
EAN8
Code93
Code128
PDF417
QR
Aztec
Interleaved2of5
ITF14
DataMatrix

Note: Apple supports UPC-A by returning EAN13 with a leading zero (see https://developer.apple.com/library/ios/technotes/tn2325/_index.html#//apple_ref/doc/uid/DTS40013824-CH1-IS_UPC_A_SUPPORTED_)

Functions

camera_view.takePhoto();

Takes the photo (and fires the "success" event)

camera_view.turnFlashOff();

Turns the flash off (and fires the "onFlashOff" event)

camera_view.turnFlashOn();

Turns the flash on (and fires the "onFlashOn" event)

camera_view.setCamera(camera);

Takes the parameters "front" or "back" to change the position of the camera (and fires the "onCameraChange" event)

camera_view.pause();

Pauses the camera feed (and fires the "onStateChange" event with the state param "paused")

camera_view.resume();

Resumes the camera feed (and fires the "onStateChange" event with the state param "resumed")

Listeners

"success"

Will fire when a picture is taken.


camera_view.addEventListener("success", function(e){
Ti.API.info(JSON.stringify(e));
Ti.API.info(e.media); // The actual blob data
Ti.API.info(e.camera); // The "front" or "back" string for where the picture was taken
image_preview.image = e.media;
});

"onFlashOn"

Will fire when the flash is turned on.


camera_view.addEventListener("onFlashOn", function(e){
Ti.API.info("Flash Turned On");
});

"onFlashOff"

Will fire when the flash is turned off.


camera_view.addEventListener("onFlashOff", function(e){
Ti.API.info("Flash Turned Off");
});

"onCameraChange"

Will fire when the camera is changed between front and back


camera_view.addEventListener("onCameraChange", function(e){
// e.camera returns one of:
// "front" : using the front camera
// "back" : using the back camera
Ti.API.info("Now using the "+e.camera+" camera"); // See what camera we're now using
});

"onStateChange"

Will fire when the camera itself changes states


// Event that listens for the camera to switch
camera_view.addEventListener("stateChange", function(e){
// Camera state change event:
// "started" : The camera has started running!
// "stopped" : The camera has been stopped (and is being torn down)
// "paused" : You've paused the camera
// "resumed" : You've resumed the camera after pausing
// e.state = The new state of the camera (one of the above options)
Ti.API.info("Camera state changed to "+e.state);
});

"code"

Since 0.7. Fires when detectCodes:true

  • Note: detectCodes:true crashes iPhone 4 when SquareCamera view is added and made visible

camera_view.addEventListener("code", function(e){
// returns :
// e.value : The value.
// e.codeType : The 2D Code Type
/*
Available Code Types:
UPCECode
Code39Code
Code39Mod43Code
EAN13Code
EAN8Code
Code93Code
Code128Code
PDF417Code
QRCode
AztecCode
Interleaved2of5Code
ITF14Code
DataMatrixCode
*/
Ti.API.info("2D code detected : "+e.codeType+' : '+e.value);
});

Known Issues and Future Improvements

  1. Android support
  2. detectCodes:true crashes iPhone 4 when SquareCamera view is added and made visible. Probably won't be fixed since iPhone 4 no longer getting iOS updates from Apple.

... anything else :)

Please let me know if you'd like any additions or something isn't working!

License

Do whatever you want, however you want, whenever you want. And if you find a problem on your way, let me know so I can fix it for my own apps too :)

Other Stuff

Contributors (TONS of thanks!)

@Kosso @reymundolopez @yuhsak

About

SquareCamera is a Titanium Module that allows you to use the AVFoundation framework to take your photos and allows for more manual customization of the camera view.

Resources

Stars

66 stars

Watchers

13 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Repository files navigation

Appcelerator Titanium :: SquareCamera

An Appcelerator Titanium module that uses AVFoundation to allow for a much more customizable camera.

I have wanted (multiple times now) the option of being able to customize the camera size, shape, and functionality without just using the camera overlay. This lets you do that :)

  • NOTE: The name can be misleading, the camera does not HAVE to be a square :)

Supports

Devices

- iPhone (Tested with 3G, 3GS, 4, 4s, 5, 5c and 5s, 6, and 6s) - iPad (Tested with multiple iPads) - iPod Touch

iOS Versions

- 6.0+ (up to the latest iOS 8) - [7.0+ for 2d code detection in module version 0.7]

Titanium SDK Versions

- 3.2.0 - 3.2.1 - 3.2.3 - 3.3.X - 3.4.0 - 3.4.1 - 3.4.2 - 3.5.0.GA - 5.0.0.GA - 5.0.2.GA
  • Note: I am sure it works on many more versions than this, but these are just the one's I've used

Setup

Include the module in your tiapp.xml:


com.mfogg.squarecamera

Usage


var SquareCamera = require('com.mfogg.squarecamera'); // Initialize the SquareCamera module
// open a single window
var win = Ti.UI.createWindow({backgroundColor:"#eee"});
var camera_view = SquareCamera.createView({
top: 0,
height: 320,
width: 320,
backgroundColor: "#fff",
frontQuality: SquareCamera.QUALITY_HIGH, // Optional Defaults to QUALITY_HIGH
backQuality: SquareCamera.QUALITY_HD, // Optional Defaults to QUALITY_HD
camera: "back" // Optional "back" or "front",
forceHorizontal: true, // Optional sets the camera to horizontal mode if you app is horizontal only (Default false)
detectCodes: true, // Since version 0.7 : optional boolean to activate 2d code detection. Dection fires "code" event contaning e.codeType and e.value -All codes types are supported. Will not work on iPhone 4 with iOS 7 (crashes upon adding SquareCamera to view).
scanCrop: { // Available since v 0.8
x: ((Ti.Platform.displayCaps.platformWidth-220)/2),
y: ((Ti.Platform.displayCaps.platformHeight-220)/2),
width: 220,
height: 220
},
scanCropPreview: true, // Available since v 0.8
barcodeTypes: [ // Available since v 0.8
"UPCE",
"UPCA",
"EAN13",
"CODE128"
]
});
var label_message = Ti.UI.createLabel({
height:Ti.UI.SIZE,
left:10,
right:10,
text:'ready',
top:330,
});
var image_preview = Ti.UI.createImageView({
right: 10,
bottom: 10,
width: 160,
borderWidth:1,
borderColor:'#ddd',
height: 160,
backgroundColor: '#444'
});
camera_view.addEventListener("success", function(e){
image_preview.image = e.media;
});
win.add(cameraView);
// Since 0.7 : 2d code detection. Requires detectCodes:true on the camera view.
camera_view.addEventListener("code", function(e){
label_message.text = e.codeType+' : '+e.value;
});
win.add(cameraView);
win.add(label_message);
win.add(image_preview);
win.open();
  • NOTE: The created view (ex. 'camera_view' above) can have other views added on top of it to act as a camera overlay (exactly how you would a standard Ti.UI.view)

Camera Quality

You are now able to change the quality when initializing the camera by setting frontQuality and backQuality parameters.


SquareCamera.QUALITY_LOW // AVCaptureSessionPresetLow
SquareCamera.QUALITY_MEDIUM // AVCaptureSessionPresetMedium
SquareCamera.QUALITY_HIGH // AVCaptureSessionPresetHigh
SquareCamera.QUALITY_HD // AVCaptureSessionPreset1920x1080 (Note: back camera only)

Detect Codes

As of 0.7 @kosso added the ability to detect barcodes. I've extended this functionality to allow you to:

Set a certain area of the screen that is able to detect codes using scanCrop:


scanCrop: {
x: 0,
y: 0,
width: 220,
height: 220
}

Make the scanCrop area slightly red for testing/debugging:


scanCropPreview: true

Set which types of barcodes you'd like to scan when the view is initialized:


barcodeTypes: [
"UPCE",
"EAN13"
]
Available Code Types:
UPCE
Code39
Code39Mod43
EAN13
EAN8
Code93
Code128
PDF417
QR
Aztec
Interleaved2of5
ITF14
DataMatrix

Note: Apple supports UPC-A by returning EAN13 with a leading zero (see https://developer.apple.com/library/ios/technotes/tn2325/_index.html#//apple_ref/doc/uid/DTS40013824-CH1-IS_UPC_A_SUPPORTED_)

Functions

camera_view.takePhoto();

Takes the photo (and fires the "success" event)

camera_view.turnFlashOff();

Turns the flash off (and fires the "onFlashOff" event)

camera_view.turnFlashOn();

Turns the flash on (and fires the "onFlashOn" event)

camera_view.setCamera(camera);

Takes the parameters "front" or "back" to change the position of the camera (and fires the "onCameraChange" event)

camera_view.pause();

Pauses the camera feed (and fires the "onStateChange" event with the state param "paused")

camera_view.resume();

Resumes the camera feed (and fires the "onStateChange" event with the state param "resumed")

Listeners

"success"

Will fire when a picture is taken.


camera_view.addEventListener("success", function(e){
Ti.API.info(JSON.stringify(e));
Ti.API.info(e.media); // The actual blob data
Ti.API.info(e.camera); // The "front" or "back" string for where the picture was taken
image_preview.image = e.media;
});

"onFlashOn"

Will fire when the flash is turned on.


camera_view.addEventListener("onFlashOn", function(e){
Ti.API.info("Flash Turned On");
});

"onFlashOff"

Will fire when the flash is turned off.


camera_view.addEventListener("onFlashOff", function(e){
Ti.API.info("Flash Turned Off");
});

"onCameraChange"

Will fire when the camera is changed between front and back


camera_view.addEventListener("onCameraChange", function(e){
// e.camera returns one of:
// "front" : using the front camera
// "back" : using the back camera
Ti.API.info("Now using the "+e.camera+" camera"); // See what camera we're now using
});

"onStateChange"

Will fire when the camera itself changes states


// Event that listens for the camera to switch
camera_view.addEventListener("stateChange", function(e){
// Camera state change event:
// "started" : The camera has started running!
// "stopped" : The camera has been stopped (and is being torn down)
// "paused" : You've paused the camera
// "resumed" : You've resumed the camera after pausing
// e.state = The new state of the camera (one of the above options)
Ti.API.info("Camera state changed to "+e.state);
});

"code"

Since 0.7. Fires when detectCodes:true

  • Note: detectCodes:true crashes iPhone 4 when SquareCamera view is added and made visible

camera_view.addEventListener("code", function(e){
// returns :
// e.value : The value.
// e.codeType : The 2D Code Type
/*
Available Code Types:
UPCECode
Code39Code
Code39Mod43Code
EAN13Code
EAN8Code
Code93Code
Code128Code
PDF417Code
QRCode
AztecCode
Interleaved2of5Code
ITF14Code
DataMatrixCode
*/
Ti.API.info("2D code detected : "+e.codeType+' : '+e.value);
});

Known Issues and Future Improvements

  1. Android support
  2. detectCodes:true crashes iPhone 4 when SquareCamera view is added and made visible. Probably won't be fixed since iPhone 4 no longer getting iOS updates from Apple.

... anything else :)

Please let me know if you'd like any additions or something isn't working!

License

Do whatever you want, however you want, whenever you want. And if you find a problem on your way, let me know so I can fix it for my own apps too :)

Other Stuff

Contributors (TONS of thanks!)

@Kosso @reymundolopez @yuhsak

About

SquareCamera is a Titanium Module that allows you to use the AVFoundation framework to take your photos and allows for more manual customization of the camera view.

Resources

Stars

66 stars

Watchers

13 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Appcelerator Titanium :: SquareCamera

An Appcelerator Titanium module that uses AVFoundation to allow for a much more customizable camera.

I have wanted (multiple times now) the option of being able to customize the camera size, shape, and functionality without just using the camera overlay. This lets you do that :)

  • NOTE: The name can be misleading, the camera does not HAVE to be a square :)

Supports

Devices

- iPhone (Tested with 3G, 3GS, 4, 4s, 5, 5c and 5s, 6, and 6s) - iPad (Tested with multiple iPads) - iPod Touch

iOS Versions

- 6.0+ (up to the latest iOS 8) - [7.0+ for 2d code detection in module version 0.7]

Titanium SDK Versions

- 3.2.0 - 3.2.1 - 3.2.3 - 3.3.X - 3.4.0 - 3.4.1 - 3.4.2 - 3.5.0.GA - 5.0.0.GA - 5.0.2.GA
  • Note: I am sure it works on many more versions than this, but these are just the one's I've used

Setup

Include the module in your tiapp.xml:


com.mfogg.squarecamera

Usage


var SquareCamera = require('com.mfogg.squarecamera'); // Initialize the SquareCamera module
// open a single window
var win = Ti.UI.createWindow({backgroundColor:"#eee"});
var camera_view = SquareCamera.createView({
top: 0,
height: 320,
width: 320,
backgroundColor: "#fff",
frontQuality: SquareCamera.QUALITY_HIGH, // Optional Defaults to QUALITY_HIGH
backQuality: SquareCamera.QUALITY_HD, // Optional Defaults to QUALITY_HD
camera: "back" // Optional "back" or "front",
forceHorizontal: true, // Optional sets the camera to horizontal mode if you app is horizontal only (Default false)
detectCodes: true, // Since version 0.7 : optional boolean to activate 2d code detection. Dection fires "code" event contaning e.codeType and e.value -All codes types are supported. Will not work on iPhone 4 with iOS 7 (crashes upon adding SquareCamera to view).
scanCrop: { // Available since v 0.8
x: ((Ti.Platform.displayCaps.platformWidth-220)/2),
y: ((Ti.Platform.displayCaps.platformHeight-220)/2),
width: 220,
height: 220
},
scanCropPreview: true, // Available since v 0.8
barcodeTypes: [ // Available since v 0.8
"UPCE",
"UPCA",
"EAN13",
"CODE128"
]
});
var label_message = Ti.UI.createLabel({
height:Ti.UI.SIZE,
left:10,
right:10,
text:'ready',
top:330,
});
var image_preview = Ti.UI.createImageView({
right: 10,
bottom: 10,
width: 160,
borderWidth:1,
borderColor:'#ddd',
height: 160,
backgroundColor: '#444'
});
camera_view.addEventListener("success", function(e){
image_preview.image = e.media;
});
win.add(cameraView);
// Since 0.7 : 2d code detection. Requires detectCodes:true on the camera view.
camera_view.addEventListener("code", function(e){
label_message.text = e.codeType+' : '+e.value;
});
win.add(cameraView);
win.add(label_message);
win.add(image_preview);
win.open();
  • NOTE: The created view (ex. 'camera_view' above) can have other views added on top of it to act as a camera overlay (exactly how you would a standard Ti.UI.view)

Camera Quality

You are now able to change the quality when initializing the camera by setting frontQuality and backQuality parameters.


SquareCamera.QUALITY_LOW // AVCaptureSessionPresetLow
SquareCamera.QUALITY_MEDIUM // AVCaptureSessionPresetMedium
SquareCamera.QUALITY_HIGH // AVCaptureSessionPresetHigh
SquareCamera.QUALITY_HD // AVCaptureSessionPreset1920x1080 (Note: back camera only)

Detect Codes

As of 0.7 @kosso added the ability to detect barcodes. I've extended this functionality to allow you to:

Set a certain area of the screen that is able to detect codes using scanCrop:


scanCrop: {
x: 0,
y: 0,
width: 220,
height: 220
}

Make the scanCrop area slightly red for testing/debugging:


scanCropPreview: true

Set which types of barcodes you'd like to scan when the view is initialized:


barcodeTypes: [
"UPCE",
"EAN13"
]
Available Code Types:
UPCE
Code39
Code39Mod43
EAN13
EAN8
Code93
Code128
PDF417
QR
Aztec
Interleaved2of5
ITF14
DataMatrix

Note: Apple supports UPC-A by returning EAN13 with a leading zero (see https://developer.apple.com/library/ios/technotes/tn2325/_index.html#//apple_ref/doc/uid/DTS40013824-CH1-IS_UPC_A_SUPPORTED_)

Functions

camera_view.takePhoto();

Takes the photo (and fires the "success" event)

camera_view.turnFlashOff();

Turns the flash off (and fires the "onFlashOff" event)

camera_view.turnFlashOn();

Turns the flash on (and fires the "onFlashOn" event)

camera_view.setCamera(camera);

Takes the parameters "front" or "back" to change the position of the camera (and fires the "onCameraChange" event)

camera_view.pause();

Pauses the camera feed (and fires the "onStateChange" event with the state param "paused")

camera_view.resume();

Resumes the camera feed (and fires the "onStateChange" event with the state param "resumed")

Listeners

"success"

Will fire when a picture is taken.


camera_view.addEventListener("success", function(e){
Ti.API.info(JSON.stringify(e));
Ti.API.info(e.media); // The actual blob data
Ti.API.info(e.camera); // The "front" or "back" string for where the picture was taken
image_preview.image = e.media;
});

"onFlashOn"

Will fire when the flash is turned on.


camera_view.addEventListener("onFlashOn", function(e){
Ti.API.info("Flash Turned On");
});

"onFlashOff"

Will fire when the flash is turned off.


camera_view.addEventListener("onFlashOff", function(e){
Ti.API.info("Flash Turned Off");
});

"onCameraChange"

Will fire when the camera is changed between front and back


camera_view.addEventListener("onCameraChange", function(e){
// e.camera returns one of:
// "front" : using the front camera
// "back" : using the back camera
Ti.API.info("Now using the "+e.camera+" camera"); // See what camera we're now using
});

"onStateChange"

Will fire when the camera itself changes states


// Event that listens for the camera to switch
camera_view.addEventListener("stateChange", function(e){
// Camera state change event:
// "started" : The camera has started running!
// "stopped" : The camera has been stopped (and is being torn down)
// "paused" : You've paused the camera
// "resumed" : You've resumed the camera after pausing
// e.state = The new state of the camera (one of the above options)
Ti.API.info("Camera state changed to "+e.state);
});

"code"

Since 0.7. Fires when detectCodes:true

  • Note: detectCodes:true crashes iPhone 4 when SquareCamera view is added and made visible

camera_view.addEventListener("code", function(e){
// returns :
// e.value : The value.
// e.codeType : The 2D Code Type
/*
Available Code Types:
UPCECode
Code39Code
Code39Mod43Code
EAN13Code
EAN8Code
Code93Code
Code128Code
PDF417Code
QRCode
AztecCode
Interleaved2of5Code
ITF14Code
DataMatrixCode
*/
Ti.API.info("2D code detected : "+e.codeType+' : '+e.value);
});

Known Issues and Future Improvements

  1. Android support
  2. detectCodes:true crashes iPhone 4 when SquareCamera view is added and made visible. Probably won't be fixed since iPhone 4 no longer getting iOS updates from Apple.

... anything else :)

Please let me know if you'd like any additions or something isn't working!

License

Do whatever you want, however you want, whenever you want. And if you find a problem on your way, let me know so I can fix it for my own apps too :)

Other Stuff

Contributors (TONS of thanks!)

@Kosso @reymundolopez @yuhsak

About

SquareCamera is a Titanium Module that allows you to use the AVFoundation framework to take your photos and allows for more manual customization of the camera view.

Resources

Stars

66 stars

Watchers

13 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Appcelerator Titanium :: SquareCamera

An Appcelerator Titanium module that uses AVFoundation to allow for a much more customizable camera.

I have wanted (multiple times now) the option of being able to customize the camera size, shape, and functionality without just using the camera overlay. This lets you do that :)

  • NOTE: The name can be misleading, the camera does not HAVE to be a square :)

Supports

Devices

- iPhone (Tested with 3G, 3GS, 4, 4s, 5, 5c and 5s, 6, and 6s) - iPad (Tested with multiple iPads) - iPod Touch

iOS Versions

- 6.0+ (up to the latest iOS 8) - [7.0+ for 2d code detection in module version 0.7]

Titanium SDK Versions

- 3.2.0 - 3.2.1 - 3.2.3 - 3.3.X - 3.4.0 - 3.4.1 - 3.4.2 - 3.5.0.GA - 5.0.0.GA - 5.0.2.GA
  • Note: I am sure it works on many more versions than this, but these are just the one's I've used

Setup

Include the module in your tiapp.xml:


com.mfogg.squarecamera

Usage


var SquareCamera = require('com.mfogg.squarecamera'); // Initialize the SquareCamera module
// open a single window
var win = Ti.UI.createWindow({backgroundColor:"#eee"});
var camera_view = SquareCamera.createView({
top: 0,
height: 320,
width: 320,
backgroundColor: "#fff",
frontQuality: SquareCamera.QUALITY_HIGH, // Optional Defaults to QUALITY_HIGH
backQuality: SquareCamera.QUALITY_HD, // Optional Defaults to QUALITY_HD
camera: "back" // Optional "back" or "front",
forceHorizontal: true, // Optional sets the camera to horizontal mode if you app is horizontal only (Default false)
detectCodes: true, // Since version 0.7 : optional boolean to activate 2d code detection. Dection fires "code" event contaning e.codeType and e.value -All codes types are supported. Will not work on iPhone 4 with iOS 7 (crashes upon adding SquareCamera to view).
scanCrop: { // Available since v 0.8
x: ((Ti.Platform.displayCaps.platformWidth-220)/2),
y: ((Ti.Platform.displayCaps.platformHeight-220)/2),
width: 220,
height: 220
},
scanCropPreview: true, // Available since v 0.8
barcodeTypes: [ // Available since v 0.8
"UPCE",
"UPCA",
"EAN13",
"CODE128"
]
});
var label_message = Ti.UI.createLabel({
height:Ti.UI.SIZE,
left:10,
right:10,
text:'ready',
top:330,
});
var image_preview = Ti.UI.createImageView({
right: 10,
bottom: 10,
width: 160,
borderWidth:1,
borderColor:'#ddd',
height: 160,
backgroundColor: '#444'
});
camera_view.addEventListener("success", function(e){
image_preview.image = e.media;
});
win.add(cameraView);
// Since 0.7 : 2d code detection. Requires detectCodes:true on the camera view.
camera_view.addEventListener("code", function(e){
label_message.text = e.codeType+' : '+e.value;
});
win.add(cameraView);
win.add(label_message);
win.add(image_preview);
win.open();
  • NOTE: The created view (ex. 'camera_view' above) can have other views added on top of it to act as a camera overlay (exactly how you would a standard Ti.UI.view)

Camera Quality

You are now able to change the quality when initializing the camera by setting frontQuality and backQuality parameters.


SquareCamera.QUALITY_LOW // AVCaptureSessionPresetLow
SquareCamera.QUALITY_MEDIUM // AVCaptureSessionPresetMedium
SquareCamera.QUALITY_HIGH // AVCaptureSessionPresetHigh
SquareCamera.QUALITY_HD // AVCaptureSessionPreset1920x1080 (Note: back camera only)

Detect Codes

As of 0.7 @kosso added the ability to detect barcodes. I've extended this functionality to allow you to:

Set a certain area of the screen that is able to detect codes using scanCrop:


scanCrop: {
x: 0,
y: 0,
width: 220,
height: 220
}

Make the scanCrop area slightly red for testing/debugging:


scanCropPreview: true

Set which types of barcodes you'd like to scan when the view is initialized:


barcodeTypes: [
"UPCE",
"EAN13"
]
Available Code Types:
UPCE
Code39
Code39Mod43
EAN13
EAN8
Code93
Code128
PDF417
QR
Aztec
Interleaved2of5
ITF14
DataMatrix

Note: Apple supports UPC-A by returning EAN13 with a leading zero (see https://developer.apple.com/library/ios/technotes/tn2325/_index.html#//apple_ref/doc/uid/DTS40013824-CH1-IS_UPC_A_SUPPORTED_)

Functions

camera_view.takePhoto();

Takes the photo (and fires the "success" event)

camera_view.turnFlashOff();

Turns the flash off (and fires the "onFlashOff" event)

camera_view.turnFlashOn();

Turns the flash on (and fires the "onFlashOn" event)

camera_view.setCamera(camera);

Takes the parameters "front" or "back" to change the position of the camera (and fires the "onCameraChange" event)

camera_view.pause();

Pauses the camera feed (and fires the "onStateChange" event with the state param "paused")

camera_view.resume();

Resumes the camera feed (and fires the "onStateChange" event with the state param "resumed")

Listeners

"success"

Will fire when a picture is taken.


camera_view.addEventListener("success", function(e){
Ti.API.info(JSON.stringify(e));
Ti.API.info(e.media); // The actual blob data
Ti.API.info(e.camera); // The "front" or "back" string for where the picture was taken
image_preview.image = e.media;
});

"onFlashOn"

Will fire when the flash is turned on.


camera_view.addEventListener("onFlashOn", function(e){
Ti.API.info("Flash Turned On");
});

"onFlashOff"

Will fire when the flash is turned off.


camera_view.addEventListener("onFlashOff", function(e){
Ti.API.info("Flash Turned Off");
});

"onCameraChange"

Will fire when the camera is changed between front and back


camera_view.addEventListener("onCameraChange", function(e){
// e.camera returns one of:
// "front" : using the front camera
// "back" : using the back camera
Ti.API.info("Now using the "+e.camera+" camera"); // See what camera we're now using
});

"onStateChange"

Will fire when the camera itself changes states


// Event that listens for the camera to switch
camera_view.addEventListener("stateChange", function(e){
// Camera state change event:
// "started" : The camera has started running!
// "stopped" : The camera has been stopped (and is being torn down)
// "paused" : You've paused the camera
// "resumed" : You've resumed the camera after pausing
// e.state = The new state of the camera (one of the above options)
Ti.API.info("Camera state changed to "+e.state);
});

"code"

Since 0.7. Fires when detectCodes:true

  • Note: detectCodes:true crashes iPhone 4 when SquareCamera view is added and made visible

camera_view.addEventListener("code", function(e){
// returns :
// e.value : The value.
// e.codeType : The 2D Code Type
/*
Available Code Types:
UPCECode
Code39Code
Code39Mod43Code
EAN13Code
EAN8Code
Code93Code
Code128Code
PDF417Code
QRCode
AztecCode
Interleaved2of5Code
ITF14Code
DataMatrixCode
*/
Ti.API.info("2D code detected : "+e.codeType+' : '+e.value);
});

Known Issues and Future Improvements

  1. Android support
  2. detectCodes:true crashes iPhone 4 when SquareCamera view is added and made visible. Probably won't be fixed since iPhone 4 no longer getting iOS updates from Apple.

... anything else :)

Please let me know if you'd like any additions or something isn't working!

License

Do whatever you want, however you want, whenever you want. And if you find a problem on your way, let me know so I can fix it for my own apps too :)

Other Stuff

Contributors (TONS of thanks!)

@Kosso @reymundolopez @yuhsak

About

SquareCamera is a Titanium Module that allows you to use the AVFoundation framework to take your photos and allows for more manual customization of the camera view.

Resources

Stars

66 stars

Watchers

13 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Repository files navigation

Appcelerator Titanium :: SquareCamera

An Appcelerator Titanium module that uses AVFoundation to allow for a much more customizable camera.

I have wanted (multiple times now) the option of being able to customize the camera size, shape, and functionality without just using the camera overlay. This lets you do that :)

  • NOTE: The name can be misleading, the camera does not HAVE to be a square :)

Supports

Devices

- iPhone (Tested with 3G, 3GS, 4, 4s, 5, 5c and 5s, 6, and 6s) - iPad (Tested with multiple iPads) - iPod Touch

iOS Versions

- 6.0+ (up to the latest iOS 8) - [7.0+ for 2d code detection in module version 0.7]

Titanium SDK Versions

- 3.2.0 - 3.2.1 - 3.2.3 - 3.3.X - 3.4.0 - 3.4.1 - 3.4.2 - 3.5.0.GA - 5.0.0.GA - 5.0.2.GA
  • Note: I am sure it works on many more versions than this, but these are just the one's I've used

Setup

Include the module in your tiapp.xml:


com.mfogg.squarecamera

Usage


var SquareCamera = require('com.mfogg.squarecamera'); // Initialize the SquareCamera module
// open a single window
var win = Ti.UI.createWindow({backgroundColor:"#eee"});
var camera_view = SquareCamera.createView({
top: 0,
height: 320,
width: 320,
backgroundColor: "#fff",
frontQuality: SquareCamera.QUALITY_HIGH, // Optional Defaults to QUALITY_HIGH
backQuality: SquareCamera.QUALITY_HD, // Optional Defaults to QUALITY_HD
camera: "back" // Optional "back" or "front",
forceHorizontal: true, // Optional sets the camera to horizontal mode if you app is horizontal only (Default false)
detectCodes: true, // Since version 0.7 : optional boolean to activate 2d code detection. Dection fires "code" event contaning e.codeType and e.value -All codes types are supported. Will not work on iPhone 4 with iOS 7 (crashes upon adding SquareCamera to view).
scanCrop: { // Available since v 0.8
x: ((Ti.Platform.displayCaps.platformWidth-220)/2),
y: ((Ti.Platform.displayCaps.platformHeight-220)/2),
width: 220,
height: 220
},
scanCropPreview: true, // Available since v 0.8
barcodeTypes: [ // Available since v 0.8
"UPCE",
"UPCA",
"EAN13",
"CODE128"
]
});
var label_message = Ti.UI.createLabel({
height:Ti.UI.SIZE,
left:10,
right:10,
text:'ready',
top:330,
});
var image_preview = Ti.UI.createImageView({
right: 10,
bottom: 10,
width: 160,
borderWidth:1,
borderColor:'#ddd',
height: 160,
backgroundColor: '#444'
});
camera_view.addEventListener("success", function(e){
image_preview.image = e.media;
});
win.add(cameraView);
// Since 0.7 : 2d code detection. Requires detectCodes:true on the camera view.
camera_view.addEventListener("code", function(e){
label_message.text = e.codeType+' : '+e.value;
});
win.add(cameraView);
win.add(label_message);
win.add(image_preview);
win.open();
  • NOTE: The created view (ex. 'camera_view' above) can have other views added on top of it to act as a camera overlay (exactly how you would a standard Ti.UI.view)

Camera Quality

You are now able to change the quality when initializing the camera by setting frontQuality and backQuality parameters.


SquareCamera.QUALITY_LOW // AVCaptureSessionPresetLow
SquareCamera.QUALITY_MEDIUM // AVCaptureSessionPresetMedium
SquareCamera.QUALITY_HIGH // AVCaptureSessionPresetHigh
SquareCamera.QUALITY_HD // AVCaptureSessionPreset1920x1080 (Note: back camera only)

Detect Codes

As of 0.7 @kosso added the ability to detect barcodes. I've extended this functionality to allow you to:

Set a certain area of the screen that is able to detect codes using scanCrop:


scanCrop: {
x: 0,
y: 0,
width: 220,
height: 220
}

Make the scanCrop area slightly red for testing/debugging:


scanCropPreview: true

Set which types of barcodes you'd like to scan when the view is initialized:


barcodeTypes: [
"UPCE",
"EAN13"
]
Available Code Types:
UPCE
Code39
Code39Mod43
EAN13
EAN8
Code93
Code128
PDF417
QR
Aztec
Interleaved2of5
ITF14
DataMatrix

Note: Apple supports UPC-A by returning EAN13 with a leading zero (see https://developer.apple.com/library/ios/technotes/tn2325/_index.html#//apple_ref/doc/uid/DTS40013824-CH1-IS_UPC_A_SUPPORTED_)

Functions

camera_view.takePhoto();

Takes the photo (and fires the "success" event)

camera_view.turnFlashOff();

Turns the flash off (and fires the "onFlashOff" event)

camera_view.turnFlashOn();

Turns the flash on (and fires the "onFlashOn" event)

camera_view.setCamera(camera);

Takes the parameters "front" or "back" to change the position of the camera (and fires the "onCameraChange" event)

camera_view.pause();

Pauses the camera feed (and fires the "onStateChange" event with the state param "paused")

camera_view.resume();

Resumes the camera feed (and fires the "onStateChange" event with the state param "resumed")

Listeners

"success"

Will fire when a picture is taken.


camera_view.addEventListener("success", function(e){
Ti.API.info(JSON.stringify(e));
Ti.API.info(e.media); // The actual blob data
Ti.API.info(e.camera); // The "front" or "back" string for where the picture was taken
image_preview.image = e.media;
});

"onFlashOn"

Will fire when the flash is turned on.


camera_view.addEventListener("onFlashOn", function(e){
Ti.API.info("Flash Turned On");
});

"onFlashOff"

Will fire when the flash is turned off.


camera_view.addEventListener("onFlashOff", function(e){
Ti.API.info("Flash Turned Off");
});

"onCameraChange"

Will fire when the camera is changed between front and back


camera_view.addEventListener("onCameraChange", function(e){
// e.camera returns one of:
// "front" : using the front camera
// "back" : using the back camera
Ti.API.info("Now using the "+e.camera+" camera"); // See what camera we're now using
});

"onStateChange"

Will fire when the camera itself changes states


// Event that listens for the camera to switch
camera_view.addEventListener("stateChange", function(e){
// Camera state change event:
// "started" : The camera has started running!
// "stopped" : The camera has been stopped (and is being torn down)
// "paused" : You've paused the camera
// "resumed" : You've resumed the camera after pausing
// e.state = The new state of the camera (one of the above options)
Ti.API.info("Camera state changed to "+e.state);
});

"code"

Since 0.7. Fires when detectCodes:true

  • Note: detectCodes:true crashes iPhone 4 when SquareCamera view is added and made visible

camera_view.addEventListener("code", function(e){
// returns :
// e.value : The value.
// e.codeType : The 2D Code Type
/*
Available Code Types:
UPCECode
Code39Code
Code39Mod43Code
EAN13Code
EAN8Code
Code93Code
Code128Code
PDF417Code
QRCode
AztecCode
Interleaved2of5Code
ITF14Code
DataMatrixCode
*/
Ti.API.info("2D code detected : "+e.codeType+' : '+e.value);
});

Known Issues and Future Improvements

  1. Android support
  2. detectCodes:true crashes iPhone 4 when SquareCamera view is added and made visible. Probably won't be fixed since iPhone 4 no longer getting iOS updates from Apple.

... anything else :)

Please let me know if you'd like any additions or something isn't working!

License

Do whatever you want, however you want, whenever you want. And if you find a problem on your way, let me know so I can fix it for my own apps too :)

Other Stuff

Contributors (TONS of thanks!)

@Kosso @reymundolopez @yuhsak

About

SquareCamera is a Titanium Module that allows you to use the AVFoundation framework to take your photos and allows for more manual customization of the camera view.

Resources

Stars

66 stars

Watchers

13 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Appcelerator Titanium :: SquareCamera

An Appcelerator Titanium module that uses AVFoundation to allow for a much more customizable camera.

I have wanted (multiple times now) the option of being able to customize the camera size, shape, and functionality without just using the camera overlay. This lets you do that :)

  • NOTE: The name can be misleading, the camera does not HAVE to be a square :)

Supports

Devices

- iPhone (Tested with 3G, 3GS, 4, 4s, 5, 5c and 5s, 6, and 6s) - iPad (Tested with multiple iPads) - iPod Touch

iOS Versions

- 6.0+ (up to the latest iOS 8) - [7.0+ for 2d code detection in module version 0.7]

Titanium SDK Versions

- 3.2.0 - 3.2.1 - 3.2.3 - 3.3.X - 3.4.0 - 3.4.1 - 3.4.2 - 3.5.0.GA - 5.0.0.GA - 5.0.2.GA
  • Note: I am sure it works on many more versions than this, but these are just the one's I've used

Setup

Include the module in your tiapp.xml:


com.mfogg.squarecamera

Usage


var SquareCamera = require('com.mfogg.squarecamera'); // Initialize the SquareCamera module
// open a single window
var win = Ti.UI.createWindow({backgroundColor:"#eee"});
var camera_view = SquareCamera.createView({
top: 0,
height: 320,
width: 320,
backgroundColor: "#fff",
frontQuality: SquareCamera.QUALITY_HIGH, // Optional Defaults to QUALITY_HIGH
backQuality: SquareCamera.QUALITY_HD, // Optional Defaults to QUALITY_HD
camera: "back" // Optional "back" or "front",
forceHorizontal: true, // Optional sets the camera to horizontal mode if you app is horizontal only (Default false)
detectCodes: true, // Since version 0.7 : optional boolean to activate 2d code detection. Dection fires "code" event contaning e.codeType and e.value -All codes types are supported. Will not work on iPhone 4 with iOS 7 (crashes upon adding SquareCamera to view).
scanCrop: { // Available since v 0.8
x: ((Ti.Platform.displayCaps.platformWidth-220)/2),
y: ((Ti.Platform.displayCaps.platformHeight-220)/2),
width: 220,
height: 220
},
scanCropPreview: true, // Available since v 0.8
barcodeTypes: [ // Available since v 0.8
"UPCE",
"UPCA",
"EAN13",
"CODE128"
]
});
var label_message = Ti.UI.createLabel({
height:Ti.UI.SIZE,
left:10,
right:10,
text:'ready',
top:330,
});
var image_preview = Ti.UI.createImageView({
right: 10,
bottom: 10,
width: 160,
borderWidth:1,
borderColor:'#ddd',
height: 160,
backgroundColor: '#444'
});
camera_view.addEventListener("success", function(e){
image_preview.image = e.media;
});
win.add(cameraView);
// Since 0.7 : 2d code detection. Requires detectCodes:true on the camera view.
camera_view.addEventListener("code", function(e){
label_message.text = e.codeType+' : '+e.value;
});
win.add(cameraView);
win.add(label_message);
win.add(image_preview);
win.open();
  • NOTE: The created view (ex. 'camera_view' above) can have other views added on top of it to act as a camera overlay (exactly how you would a standard Ti.UI.view)

Camera Quality

You are now able to change the quality when initializing the camera by setting frontQuality and backQuality parameters.


SquareCamera.QUALITY_LOW // AVCaptureSessionPresetLow
SquareCamera.QUALITY_MEDIUM // AVCaptureSessionPresetMedium
SquareCamera.QUALITY_HIGH // AVCaptureSessionPresetHigh
SquareCamera.QUALITY_HD // AVCaptureSessionPreset1920x1080 (Note: back camera only)

Detect Codes

As of 0.7 @kosso added the ability to detect barcodes. I've extended this functionality to allow you to:

Set a certain area of the screen that is able to detect codes using scanCrop:


scanCrop: {
x: 0,
y: 0,
width: 220,
height: 220
}

Make the scanCrop area slightly red for testing/debugging:


scanCropPreview: true

Set which types of barcodes you'd like to scan when the view is initialized:


barcodeTypes: [
"UPCE",
"EAN13"
]
Available Code Types:
UPCE
Code39
Code39Mod43
EAN13
EAN8
Code93
Code128
PDF417
QR
Aztec
Interleaved2of5
ITF14
DataMatrix

Note: Apple supports UPC-A by returning EAN13 with a leading zero (see https://developer.apple.com/library/ios/technotes/tn2325/_index.html#//apple_ref/doc/uid/DTS40013824-CH1-IS_UPC_A_SUPPORTED_)

Functions

camera_view.takePhoto();

Takes the photo (and fires the "success" event)

camera_view.turnFlashOff();

Turns the flash off (and fires the "onFlashOff" event)

camera_view.turnFlashOn();

Turns the flash on (and fires the "onFlashOn" event)

camera_view.setCamera(camera);

Takes the parameters "front" or "back" to change the position of the camera (and fires the "onCameraChange" event)

camera_view.pause();

Pauses the camera feed (and fires the "onStateChange" event with the state param "paused")

camera_view.resume();

Resumes the camera feed (and fires the "onStateChange" event with the state param "resumed")

Listeners

"success"

Will fire when a picture is taken.


camera_view.addEventListener("success", function(e){
Ti.API.info(JSON.stringify(e));
Ti.API.info(e.media); // The actual blob data
Ti.API.info(e.camera); // The "front" or "back" string for where the picture was taken
image_preview.image = e.media;
});

"onFlashOn"

Will fire when the flash is turned on.


camera_view.addEventListener("onFlashOn", function(e){
Ti.API.info("Flash Turned On");
});

"onFlashOff"

Will fire when the flash is turned off.


camera_view.addEventListener("onFlashOff", function(e){
Ti.API.info("Flash Turned Off");
});

"onCameraChange"

Will fire when the camera is changed between front and back


camera_view.addEventListener("onCameraChange", function(e){
// e.camera returns one of:
// "front" : using the front camera
// "back" : using the back camera
Ti.API.info("Now using the "+e.camera+" camera"); // See what camera we're now using
});

"onStateChange"

Will fire when the camera itself changes states


// Event that listens for the camera to switch
camera_view.addEventListener("stateChange", function(e){
// Camera state change event:
// "started" : The camera has started running!
// "stopped" : The camera has been stopped (and is being torn down)
// "paused" : You've paused the camera
// "resumed" : You've resumed the camera after pausing
// e.state = The new state of the camera (one of the above options)
Ti.API.info("Camera state changed to "+e.state);
});

"code"

Since 0.7. Fires when detectCodes:true

  • Note: detectCodes:true crashes iPhone 4 when SquareCamera view is added and made visible

camera_view.addEventListener("code", function(e){
// returns :
// e.value : The value.
// e.codeType : The 2D Code Type
/*
Available Code Types:
UPCECode
Code39Code
Code39Mod43Code
EAN13Code
EAN8Code
Code93Code
Code128Code
PDF417Code
QRCode
AztecCode
Interleaved2of5Code
ITF14Code
DataMatrixCode
*/
Ti.API.info("2D code detected : "+e.codeType+' : '+e.value);
});

Known Issues and Future Improvements

  1. Android support
  2. detectCodes:true crashes iPhone 4 when SquareCamera view is added and made visible. Probably won't be fixed since iPhone 4 no longer getting iOS updates from Apple.

... anything else :)

Please let me know if you'd like any additions or something isn't working!

License

Do whatever you want, however you want, whenever you want. And if you find a problem on your way, let me know so I can fix it for my own apps too :)

Other Stuff

Contributors (TONS of thanks!)

@Kosso @reymundolopez @yuhsak

About

SquareCamera is a Titanium Module that allows you to use the AVFoundation framework to take your photos and allows for more manual customization of the camera view.

Resources

Stars

66 stars

Watchers

13 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Appcelerator Titanium :: SquareCamera

An Appcelerator Titanium module that uses AVFoundation to allow for a much more customizable camera.

I have wanted (multiple times now) the option of being able to customize the camera size, shape, and functionality without just using the camera overlay. This lets you do that :)

  • NOTE: The name can be misleading, the camera does not HAVE to be a square :)

Supports

Devices

- iPhone (Tested with 3G, 3GS, 4, 4s, 5, 5c and 5s, 6, and 6s) - iPad (Tested with multiple iPads) - iPod Touch

iOS Versions

- 6.0+ (up to the latest iOS 8) - [7.0+ for 2d code detection in module version 0.7]

Titanium SDK Versions

- 3.2.0 - 3.2.1 - 3.2.3 - 3.3.X - 3.4.0 - 3.4.1 - 3.4.2 - 3.5.0.GA - 5.0.0.GA - 5.0.2.GA
  • Note: I am sure it works on many more versions than this, but these are just the one's I've used

Setup

Include the module in your tiapp.xml:


com.mfogg.squarecamera

Usage


var SquareCamera = require('com.mfogg.squarecamera'); // Initialize the SquareCamera module
// open a single window
var win = Ti.UI.createWindow({backgroundColor:"#eee"});
var camera_view = SquareCamera.createView({
top: 0,
height: 320,
width: 320,
backgroundColor: "#fff",
frontQuality: SquareCamera.QUALITY_HIGH, // Optional Defaults to QUALITY_HIGH
backQuality: SquareCamera.QUALITY_HD, // Optional Defaults to QUALITY_HD
camera: "back" // Optional "back" or "front",
forceHorizontal: true, // Optional sets the camera to horizontal mode if you app is horizontal only (Default false)
detectCodes: true, // Since version 0.7 : optional boolean to activate 2d code detection. Dection fires "code" event contaning e.codeType and e.value -All codes types are supported. Will not work on iPhone 4 with iOS 7 (crashes upon adding SquareCamera to view).
scanCrop: { // Available since v 0.8
x: ((Ti.Platform.displayCaps.platformWidth-220)/2),
y: ((Ti.Platform.displayCaps.platformHeight-220)/2),
width: 220,
height: 220
},
scanCropPreview: true, // Available since v 0.8
barcodeTypes: [ // Available since v 0.8
"UPCE",
"UPCA",
"EAN13",
"CODE128"
]
});
var label_message = Ti.UI.createLabel({
height:Ti.UI.SIZE,
left:10,
right:10,
text:'ready',
top:330,
});
var image_preview = Ti.UI.createImageView({
right: 10,
bottom: 10,
width: 160,
borderWidth:1,
borderColor:'#ddd',
height: 160,
backgroundColor: '#444'
});
camera_view.addEventListener("success", function(e){
image_preview.image = e.media;
});
win.add(cameraView);
// Since 0.7 : 2d code detection. Requires detectCodes:true on the camera view.
camera_view.addEventListener("code", function(e){
label_message.text = e.codeType+' : '+e.value;
});
win.add(cameraView);
win.add(label_message);
win.add(image_preview);
win.open();
  • NOTE: The created view (ex. 'camera_view' above) can have other views added on top of it to act as a camera overlay (exactly how you would a standard Ti.UI.view)

Camera Quality

You are now able to change the quality when initializing the camera by setting frontQuality and backQuality parameters.


SquareCamera.QUALITY_LOW // AVCaptureSessionPresetLow
SquareCamera.QUALITY_MEDIUM // AVCaptureSessionPresetMedium
SquareCamera.QUALITY_HIGH // AVCaptureSessionPresetHigh
SquareCamera.QUALITY_HD // AVCaptureSessionPreset1920x1080 (Note: back camera only)

Detect Codes

As of 0.7 @kosso added the ability to detect barcodes. I've extended this functionality to allow you to:

Set a certain area of the screen that is able to detect codes using scanCrop:


scanCrop: {
x: 0,
y: 0,
width: 220,
height: 220
}

Make the scanCrop area slightly red for testing/debugging:


scanCropPreview: true

Set which types of barcodes you'd like to scan when the view is initialized:


barcodeTypes: [
"UPCE",
"EAN13"
]
Available Code Types:
UPCE
Code39
Code39Mod43
EAN13
EAN8
Code93
Code128
PDF417
QR
Aztec
Interleaved2of5
ITF14
DataMatrix

Note: Apple supports UPC-A by returning EAN13 with a leading zero (see https://developer.apple.com/library/ios/technotes/tn2325/_index.html#//apple_ref/doc/uid/DTS40013824-CH1-IS_UPC_A_SUPPORTED_)

Functions

camera_view.takePhoto();

Takes the photo (and fires the "success" event)

camera_view.turnFlashOff();

Turns the flash off (and fires the "onFlashOff" event)

camera_view.turnFlashOn();

Turns the flash on (and fires the "onFlashOn" event)

camera_view.setCamera(camera);

Takes the parameters "front" or "back" to change the position of the camera (and fires the "onCameraChange" event)

camera_view.pause();

Pauses the camera feed (and fires the "onStateChange" event with the state param "paused")

camera_view.resume();

Resumes the camera feed (and fires the "onStateChange" event with the state param "resumed")

Listeners

"success"

Will fire when a picture is taken.


camera_view.addEventListener("success", function(e){
Ti.API.info(JSON.stringify(e));
Ti.API.info(e.media); // The actual blob data
Ti.API.info(e.camera); // The "front" or "back" string for where the picture was taken
image_preview.image = e.media;
});

"onFlashOn"

Will fire when the flash is turned on.


camera_view.addEventListener("onFlashOn", function(e){
Ti.API.info("Flash Turned On");
});

"onFlashOff"

Will fire when the flash is turned off.


camera_view.addEventListener("onFlashOff", function(e){
Ti.API.info("Flash Turned Off");
});

"onCameraChange"

Will fire when the camera is changed between front and back


camera_view.addEventListener("onCameraChange", function(e){
// e.camera returns one of:
// "front" : using the front camera
// "back" : using the back camera
Ti.API.info("Now using the "+e.camera+" camera"); // See what camera we're now using
});

"onStateChange"

Will fire when the camera itself changes states


// Event that listens for the camera to switch
camera_view.addEventListener("stateChange", function(e){
// Camera state change event:
// "started" : The camera has started running!
// "stopped" : The camera has been stopped (and is being torn down)
// "paused" : You've paused the camera
// "resumed" : You've resumed the camera after pausing
// e.state = The new state of the camera (one of the above options)
Ti.API.info("Camera state changed to "+e.state);
});

"code"

Since 0.7. Fires when detectCodes:true

  • Note: detectCodes:true crashes iPhone 4 when SquareCamera view is added and made visible

camera_view.addEventListener("code", function(e){
// returns :
// e.value : The value.
// e.codeType : The 2D Code Type
/*
Available Code Types:
UPCECode
Code39Code
Code39Mod43Code
EAN13Code
EAN8Code
Code93Code
Code128Code
PDF417Code
QRCode
AztecCode
Interleaved2of5Code
ITF14Code
DataMatrixCode
*/
Ti.API.info("2D code detected : "+e.codeType+' : '+e.value);
});

Known Issues and Future Improvements

  1. Android support
  2. detectCodes:true crashes iPhone 4 when SquareCamera view is added and made visible. Probably won't be fixed since iPhone 4 no longer getting iOS updates from Apple.

... anything else :)

Please let me know if you'd like any additions or something isn't working!

License

Do whatever you want, however you want, whenever you want. And if you find a problem on your way, let me know so I can fix it for my own apps too :)

Other Stuff

Contributors (TONS of thanks!)

@Kosso @reymundolopez @yuhsak

About

SquareCamera is a Titanium Module that allows you to use the AVFoundation framework to take your photos and allows for more manual customization of the camera view.

Resources

Stars

66 stars

Watchers

13 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Repository files navigation

Appcelerator Titanium :: SquareCamera

An Appcelerator Titanium module that uses AVFoundation to allow for a much more customizable camera.

I have wanted (multiple times now) the option of being able to customize the camera size, shape, and functionality without just using the camera overlay. This lets you do that :)

  • NOTE: The name can be misleading, the camera does not HAVE to be a square :)

Supports

Devices

- iPhone (Tested with 3G, 3GS, 4, 4s, 5, 5c and 5s, 6, and 6s) - iPad (Tested with multiple iPads) - iPod Touch

iOS Versions

- 6.0+ (up to the latest iOS 8) - [7.0+ for 2d code detection in module version 0.7]

Titanium SDK Versions

- 3.2.0 - 3.2.1 - 3.2.3 - 3.3.X - 3.4.0 - 3.4.1 - 3.4.2 - 3.5.0.GA - 5.0.0.GA - 5.0.2.GA
  • Note: I am sure it works on many more versions than this, but these are just the one's I've used

Setup

Include the module in your tiapp.xml:


com.mfogg.squarecamera

Usage


var SquareCamera = require('com.mfogg.squarecamera'); // Initialize the SquareCamera module
// open a single window
var win = Ti.UI.createWindow({backgroundColor:"#eee"});
var camera_view = SquareCamera.createView({
top: 0,
height: 320,
width: 320,
backgroundColor: "#fff",
frontQuality: SquareCamera.QUALITY_HIGH, // Optional Defaults to QUALITY_HIGH
backQuality: SquareCamera.QUALITY_HD, // Optional Defaults to QUALITY_HD
camera: "back" // Optional "back" or "front",
forceHorizontal: true, // Optional sets the camera to horizontal mode if you app is horizontal only (Default false)
detectCodes: true, // Since version 0.7 : optional boolean to activate 2d code detection. Dection fires "code" event contaning e.codeType and e.value -All codes types are supported. Will not work on iPhone 4 with iOS 7 (crashes upon adding SquareCamera to view).
scanCrop: { // Available since v 0.8
x: ((Ti.Platform.displayCaps.platformWidth-220)/2),
y: ((Ti.Platform.displayCaps.platformHeight-220)/2),
width: 220,
height: 220
},
scanCropPreview: true, // Available since v 0.8
barcodeTypes: [ // Available since v 0.8
"UPCE",
"UPCA",
"EAN13",
"CODE128"
]
});
var label_message = Ti.UI.createLabel({
height:Ti.UI.SIZE,
left:10,
right:10,
text:'ready',
top:330,
});
var image_preview = Ti.UI.createImageView({
right: 10,
bottom: 10,
width: 160,
borderWidth:1,
borderColor:'#ddd',
height: 160,
backgroundColor: '#444'
});
camera_view.addEventListener("success", function(e){
image_preview.image = e.media;
});
win.add(cameraView);
// Since 0.7 : 2d code detection. Requires detectCodes:true on the camera view.
camera_view.addEventListener("code", function(e){
label_message.text = e.codeType+' : '+e.value;
});
win.add(cameraView);
win.add(label_message);
win.add(image_preview);
win.open();
  • NOTE: The created view (ex. 'camera_view' above) can have other views added on top of it to act as a camera overlay (exactly how you would a standard Ti.UI.view)

Camera Quality

You are now able to change the quality when initializing the camera by setting frontQuality and backQuality parameters.


SquareCamera.QUALITY_LOW // AVCaptureSessionPresetLow
SquareCamera.QUALITY_MEDIUM // AVCaptureSessionPresetMedium
SquareCamera.QUALITY_HIGH // AVCaptureSessionPresetHigh
SquareCamera.QUALITY_HD // AVCaptureSessionPreset1920x1080 (Note: back camera only)

Detect Codes

As of 0.7 @kosso added the ability to detect barcodes. I've extended this functionality to allow you to:

Set a certain area of the screen that is able to detect codes using scanCrop:


scanCrop: {
x: 0,
y: 0,
width: 220,
height: 220
}

Make the scanCrop area slightly red for testing/debugging:


scanCropPreview: true

Set which types of barcodes you'd like to scan when the view is initialized:


barcodeTypes: [
"UPCE",
"EAN13"
]
Available Code Types:
UPCE
Code39
Code39Mod43
EAN13
EAN8
Code93
Code128
PDF417
QR
Aztec
Interleaved2of5
ITF14
DataMatrix

Note: Apple supports UPC-A by returning EAN13 with a leading zero (see https://developer.apple.com/library/ios/technotes/tn2325/_index.html#//apple_ref/doc/uid/DTS40013824-CH1-IS_UPC_A_SUPPORTED_)

Functions

camera_view.takePhoto();

Takes the photo (and fires the "success" event)

camera_view.turnFlashOff();

Turns the flash off (and fires the "onFlashOff" event)

camera_view.turnFlashOn();

Turns the flash on (and fires the "onFlashOn" event)

camera_view.setCamera(camera);

Takes the parameters "front" or "back" to change the position of the camera (and fires the "onCameraChange" event)

camera_view.pause();

Pauses the camera feed (and fires the "onStateChange" event with the state param "paused")

camera_view.resume();

Resumes the camera feed (and fires the "onStateChange" event with the state param "resumed")

Listeners

"success"

Will fire when a picture is taken.


camera_view.addEventListener("success", function(e){
Ti.API.info(JSON.stringify(e));
Ti.API.info(e.media); // The actual blob data
Ti.API.info(e.camera); // The "front" or "back" string for where the picture was taken
image_preview.image = e.media;
});

"onFlashOn"

Will fire when the flash is turned on.


camera_view.addEventListener("onFlashOn", function(e){
Ti.API.info("Flash Turned On");
});

"onFlashOff"

Will fire when the flash is turned off.


camera_view.addEventListener("onFlashOff", function(e){
Ti.API.info("Flash Turned Off");
});

"onCameraChange"

Will fire when the camera is changed between front and back


camera_view.addEventListener("onCameraChange", function(e){
// e.camera returns one of:
// "front" : using the front camera
// "back" : using the back camera
Ti.API.info("Now using the "+e.camera+" camera"); // See what camera we're now using
});

"onStateChange"

Will fire when the camera itself changes states


// Event that listens for the camera to switch
camera_view.addEventListener("stateChange", function(e){
// Camera state change event:
// "started" : The camera has started running!
// "stopped" : The camera has been stopped (and is being torn down)
// "paused" : You've paused the camera
// "resumed" : You've resumed the camera after pausing
// e.state = The new state of the camera (one of the above options)
Ti.API.info("Camera state changed to "+e.state);
});

"code"

Since 0.7. Fires when detectCodes:true

  • Note: detectCodes:true crashes iPhone 4 when SquareCamera view is added and made visible

camera_view.addEventListener("code", function(e){
// returns :
// e.value : The value.
// e.codeType : The 2D Code Type
/*
Available Code Types:
UPCECode
Code39Code
Code39Mod43Code
EAN13Code
EAN8Code
Code93Code
Code128Code
PDF417Code
QRCode
AztecCode
Interleaved2of5Code
ITF14Code
DataMatrixCode
*/
Ti.API.info("2D code detected : "+e.codeType+' : '+e.value);
});

Known Issues and Future Improvements

  1. Android support
  2. detectCodes:true crashes iPhone 4 when SquareCamera view is added and made visible. Probably won't be fixed since iPhone 4 no longer getting iOS updates from Apple.

... anything else :)

Please let me know if you'd like any additions or something isn't working!

License

Do whatever you want, however you want, whenever you want. And if you find a problem on your way, let me know so I can fix it for my own apps too :)

Other Stuff

Contributors (TONS of thanks!)

@Kosso @reymundolopez @yuhsak

About

SquareCamera is a Titanium Module that allows you to use the AVFoundation framework to take your photos and allows for more manual customization of the camera view.

Resources

Stars

66 stars

Watchers

13 watching

Forks

Releases

Packages

Contributors

Languages