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

Android Menu Button / iOS Overlay Layout #64

Closed
walkthelot opened this issue Jan 16, 2018 · 6 comments
Closed

Android Menu Button / iOS Overlay Layout #64

walkthelot opened this issue Jan 16, 2018 · 6 comments

Comments

@walkthelot
Copy link

When pressing the Android menu button on an Android device, the host app crashes. allowMenu seems to have no effect.

In iOS, the overlay view, no matter what you do, is not able to be formatted for width and other view layout properties. No matter what you do, the view (via createView) always aligns upper left and it is impossible to have it's width or height fill the parent window. Everything in this regard works as expected in Android.

@m1ga
Copy link
Contributor

m1ga commented Jan 16, 2018

Could you please provide some test code for both problems. Would make it quicker to test it

@walkthelot
Copy link
Author

walkthelot commented Jan 16, 2018

var winSample = Ti.UI.createWindow({  
    title:'sample'
});

var Barcode = require('ti.barcode');
Barcode.allowRotation = true;
Barcode.displayedMessage = ' ';
Barcode.allowMenu = false;
Barcode.allowInstructions = false;
Barcode.useLED = false;

var buttonScan = Titanium.UI.createButton({
    textAlign:'center',
    title:'scan barcode or qrcode'
});
winSample.add(buttonScan);

winSample.open();

var checkCameraPermissions = function(callback) {
    
    if (Ti.Media.hasCameraPermissions()) {
        callback(true);
    } else { 
        Ti.Media.requestCameraPermissions(function(e) {
             if (e.success === true) {
                 callback(true);
             } else {
                 callback(false);
             }
        });
    }
};    

buttonScan.addEventListener('click',function() {

    checkCameraPermissions(function(returnedDataVIN) {

        if (returnedDataVIN == true) {

            var overlay = Ti.UI.createView({
                backgroundColor: 'transparent',
                width:Titanium.UI.FILL,
                height:Titanium.UI.SIZE
            });

            var ledButton = Ti.UI.createButton({
                title: 'toggle led', textAlign: 'center',
                bottom: '10dp',
                left: '10dp',
                height: '39dp',
                width: '125dp',                
                borderRadius: 0,
                borderWidth:'1dp',
                font:{fontSize:'15dp'},
                textAlign:'center'
            });
            ledButton.addEventListener('click', function () {
                Barcode.useLED = !Barcode.useLED;
                ledButton.title = Barcode.useLED ? 'led is on' : 'led is off';
            });
            overlay.add(ledButton);

            var cancelButton = Ti.UI.createButton({
                title: 'cancel',
                bottom: '10dp',
                right: '10dp',
                height: '39dp',
                width: '125dp',              
                borderRadius: 0,
                borderWidth:'1dp',
                font:{fontSize:'15dp'},
                textAlign:'center'
            });
            cancelButton.addEventListener('click', function () {
                Barcode.cancel();
            });
            overlay.add(cancelButton);
           
            Barcode.addEventListener('error', function (e) {
                Ti.UI.createAlertDialog({ cancel: 0, buttonNames: ['OK'], title:'Scanning Error', message:'Error while scanning. Error: ' + e.message}).show();
            });

            Barcode.addEventListener('cancel', function (e) {
                Ti.API.info('Cancel received');
            });

            Barcode.addEventListener('success', function (e) {
                if (e != undefined && e.result != undefined) {                    
                    var scanResult = right(e.result.toUpperCase().trim(), 17);                    
                    Barcode.cancel();            
                    alert(e.format + ' barcode ' + scanResult);                    
                }
            });
                                    
            Barcode.capture({
                overlay: overlay,
                showCancel: false,
                showRectangle: true,
                keepOpen: false,                
                acceptedFormats: [
                    Barcode.FORMAT_QR_CODE,
                    Barcode.FORMAT_CODE_39
                ]
            });
                        
        } else {
            Ti.UI.createAlertDialog({ cancel: 0, buttonNames: ['OK'], title:'Permission Not Granted', message:'You have not granted the app the needed permissions to access your camera and/or device storage.\n\nPlease review the app permissions within your device Settings in order to grant the needed permissions.'}).show();
        }
        
    });                        
        
});

@m1ga
Copy link
Contributor

m1ga commented Feb 4, 2018

I don't have a menu button so I only can test it via adb shell input keyevent 1 and don't see a crash there.

@walkthelot
Copy link
Author

walkthelot commented Feb 9, 2018 via email

@m1ga
Copy link
Contributor

m1ga commented Mar 11, 2018

@kenrucker just had to implement Ti.Barcode with an overlay on iOS (iPhone) and it is not visible as you already mentioned.

var Barcode = require('ti.barcode');
		Barcode.allowMenu = false;
		Barcode.allowInstructions = false;
		Barcode.displayedMessage = ' ';
		Barcode.allowRotation = true;

		var overlay = Ti.UI.createView({
			backgroundColor: 'transparent',
			top: 0,
			right: 0,
			bottom: 0,
			left: 0,
			width: Ti.UI.FILL,
			height: Ti.UI.FILL,
		});
		var lbl = Ti.UI.createLabel({
			bottom: 10,
			left: 10,
			right: 10,
			textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
			text: "text",
			color: "#fff",
			backgroundColor: "transparent",
			touchEnabled: false
		});
		overlay.add(lbl);
		var cancelButton = Ti.UI.createButton({
			title: 'X',
			top: 0,
			right: 0,
			width: 30,
			right: 30,
			backgroundColor: "transparent",
			color: "#fff"
		});
		cancelButton.addEventListener('click', function() {
			Barcode.cancel();
		});
		overlay.add(cancelButton);

		Barcode.capture({
			animate: true,
			overlay: overlay,
			showCancel: false,
			showRectangle: true,
			keepOpen: false,
		});
		Barcode.addEventListener('success', function(e) {
			Ti.API.info('Success called with barcode: ' + e.result + " " + e.format);
		});

working fine on Android.
Also it looks like the rotation bug (https://jira.appcelerator.org/browse/MOD-1909) is back again too

Filed a bug ticket: https://jira.appcelerator.org/browse/AC-5654

@hansemannn
Copy link
Contributor

Fixed in recent versions of the module. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants