Video not shown up in Photogallery in android app - titanium-mobile

Why I am not be able to see videos in Android app's from photogallery. The code i have used is as follows.
.
Titanium.Media.openPhotoGallery({
success:function(event) //success event
{
Ti.API.debug('Our type was: '+event.mediaType);
if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO,Ti.Media.MEDIA_TYPE_VIDEO)
{
UploadPhotoToServer(event.media);
}
},
cancel:function()
{
},
error:function(err)
{
Ti.API.error(err);
},
mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO,Ti.Media.MEDIA_TYPE_VIDEO]
});

This is no valid JS.
if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO,Ti.Media.MEDIA_TYPE_VIDEO)
{
UploadPhotoToServer(event.media);
}
Change to
if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO || event.mediaType == Ti.Media.MEDIA_TYPE_VIDEO)
{
UploadPhotoToServer(event.media);
}
(see if clause)

On Android, using Intent
var intent = Titanium.Android.createIntent({
action : Ti.Android.ACTION_PICK,
type : "video/*"
});
intent.addCategory(Ti.Android.CATEGORY_DEFAULT);
var activity = Titanium.Android.currentActivity;
activity.startActivityForResult(intent, function(e) { if (e.error) { ...} else { ...}}:

Related

ASK error, TypeError: Cannot read property 'type' of undefined

I'm creating a skill that will call back different incidents at different dates and times from a DynamoDB table through Alexa.
My 3 columns are data, time and incident
I've defined my partition and sort key in my Lambda function as
let GetMachineStateIntent = (context, callback) => {
var params = {
TableName: "updatedincident",
Key: {
date: "2017-03-21",
time: "07:38",
incident: "Blocked Primary",
}
};
When I try to test my skill I can't seem to recall the incident correctly, the error I'm getting in Cloudwatch is:
2018-03-28T14:48:53.397Z 042319cb-4a3e-49ae-8b33-1641367107d4 Unexpected error occurred in the skill handler! TypeError: Cannot read property 'type' of undefined
at exports.handler.e (/var/task/index.js:70:16)
as well as:
2018-03-28T14:48:53.417Z 042319cb-4a3e-49ae-8b33-1641367107d4
{
"errorMessage": "Unexpected error"
}
Here is my code from index.js
var AWSregion = 'us-east-1'; // us-east-1
var AWS = require('aws-sdk');
var dbClient = new AWS.DynamoDB.DocumentClient();
AWS.config.update({
region: "'us-east-1'"
});
let GetMachineStateIntent = (context, callback) => {
var params = {
TableName: "updatedincident",
Key: {
date: "2018-03-28",
time: "04:23",
}
};
dbClient.get(params, function (err, data) {
if (err) {
// failed to read from table for some reason..
console.log('failed to load data item:\n' + JSON.stringify(err, null, 2));
// let skill tell the user that it couldn't find the data
sendResponse(context, callback, {
output: "the data could not be loaded from your database",
endSession: false
});
} else {
console.log('loaded data item:\n' + JSON.stringify(data.Item, null, 2));
// assuming the item has an attribute called "incident"..
sendResponse(context, callback, {
output: data.Item.incident,
endSession: false
});
}
});
};
function sendResponse(context, callback, responseOptions) {
if(typeof callback === 'undefined') {
context.succeed(buildResponse(responseOptions));
} else {
callback(null, buildResponse(responseOptions));
}
}
function buildResponse(options) {
var alexaResponse = {
version: "1.0",
response: {
outputSpeech: {
"type": "SSML",
"ssml": `<speak><prosody rate="slow">${options.output}</prosody></speak>`
},
shouldEndSession: options.endSession
}
};
if (options.repromptText) {
alexaResponse.response.reprompt = {
outputSpeech: {
"type": "SSML",
"ssml": `<speak><prosody rate="slow">${options.reprompt}</prosody></speak>`
}
};
}
return alexaResponse;
}
exports.handler = (event, context, callback) => {
try {
var request = event.request;
if (request.type === "LaunchRequest") {
sendResponse(context, callback, {
output: "welcome to my skill. what data are you looking for?",
endSession: false
});
}
else if (request.type === "IntentRequest") {
let options = {};
if (request.intent.name === "GetMachineStateIntent") {
GetMachineStateIntent(context, callback);
} else if (request.intent.name === "AMAZON.StopIntent" || request.intent.name === "AMAZON.CancelIntent") {
sendResponse(context, callback, {
output: "ok. good bye!",
endSession: true
});
}
else if (request.intent.name === "AMAZON.HelpIntent") {
sendResponse(context, callback, {
output: "you can ask me about incidents that have happened",
reprompt: "what can I help you with?",
endSession: false
});
}
else {
sendResponse(context, callback, {
output: "I don't know that one! please try again!",
endSession: false
});
}
}
else if (request.type === "SessionEndedRequest") {
sendResponse(context, callback, ""); // no response needed
}
else {
// an unexpected request type received.. just say I don't know..
sendResponse(context, callback, {
output: "I don't know that one! please try again!",
endSession: false
});
}
} catch (e) {
// handle the error by logging it and sending back an failure
console.log('Unexpected error occurred in the skill handler!', e);
if(typeof callback === 'undefined') {
context.fail("Unexpected error");
} else {
callback("Unexpected error");
}
}
};
and this is my handler GetMachineState.js
function sendResponse(context, callback, responseOptions) {
if(typeof callback === 'undefined') {
context.succeed(buildResponse(responseOptions));
} else {
callback(null, buildResponse(responseOptions));
}
}
function buildResponse(options) {
var alexaResponse = {
version: "1.0",
response: {
outputSpeech: {
"type": "SSML",
"ssml": `<speak><prosody rate="slow">${options.output}</prosody></speak>`
},
shouldEndSession: options.endSession
}
};
if (options.repromptText) {
alexaResponse.response.reprompt = {
outputSpeech: {
"type": "SSML",
"ssml": `<speak><prosody rate="slow">${options.reprompt}</prosody></speak>`
}
};
}
return alexaResponse;
}
exports.handler = (event, context, callback) => {
try {
var request = event.request;
if (request.type === "LaunchRequest") {
sendResponse(context, callback, {
output: "welcome to my skill. what do you want to find?",
endSession: false
});
}
else if (request.type === "IntentRequest") {
let options = {};
if (request.intent.name === "GetMachineStateIntent") {
// this is where we will wire up the dynamo call
// for now, just send a simple response and end the session
sendResponse(context, callback, {
output: "cinema not implemented yet!",
endSession: true
});
} else if (request.intent.name === "AMAZON.StopIntent" || request.intent.name === "AMAZON.CancelIntent") {
sendResponse(context, callback, {
output: "ok. good bye!",
endSession: true
});
}
else if (request.intent.name === "AMAZON.HelpIntent") {
sendResponse(context, callback, {
output: "you can ask me about incidents that have happened",
reprompt: "what can I help you with?",
endSession: false
});
}
else {
sendResponse(context, callback, {
output: "I don't know that one! Good bye!",
endSession: true
});
}
}
else if (request.type === "SessionEndedRequest") {
sendResponse(context, callback, ""); // no response needed
}
else {
// an unexpected request type received.. just say I don't know..
sendResponse(context, callback, {
output: "I don't know that one! Good bye!",
endSession: true
});
}
} catch (e) {
// handle the error by logging it and sending back an failure
console.log('Unexpected error occurred in the skill handler!', e);
if(typeof callback === 'undefined') {
context.fail("Unexpected error");
} else {
callback("Unexpected error");
}
}
};
Its impossible to know for sure if this is the problem or not because you haven't shared the code from the index.js file. The error message you get is telling you that the problem occurs at line 70 in your index.js file so you should look there, and figure out what the problem is.
However, based on the fact that you also posted this as a comment on another question, I'm going to venture to guess that the issue you've run into is that you used the code snippet I provided in the answer to that question and the error is from dereferencing the request.type
You have to make sure the request variable is set to the actual request from the event, like so: var request = event.request where event is provided from exports.handler = (event, context, callback) => {
For example:
exports.handler = (event, context, callback) => {
var request = event.request;
if (request.type === "IntentRequest"
// make suret the name of the intent matches the one in your interaction model
&& request.intent.name == "GetMachineStateIntent") {
var dateSlot = request.intent.slots.Date != null ?
request.intent.slots.Date.value : "unknown date";
var timeSlot = request.intent.slots.Time != null ?
request.intent.slots.Time.value : "unknown time";
// respond with speech saying back what the skill thinks the user requested
sendResponse(context, callback, {
output: "You wanted the machine state at "
+ timeSlot + " on " + dateSlot,
endSession: true
});
} else {
// TODO: handle other types of requests..
sendResponse(context, callback, {
output: "I don't know how to handle this request yet!"
endSession: true
});
}
};
function sendResponse(context, callback, responseOptions) {
if(typeof callback === 'undefined') {
context.succeed(buildResponse(responseOptions));
} else {
callback(null, buildResponse(responseOptions));
}
}
function buildResponse(options) {
var alexaResponse = {
version: "1.0",
response: {
outputSpeech: {
"type": "SSML",
"ssml": `<speak><prosody rate="slow">${options.output}</prosody></speak>`
},
shouldEndSession: options.endSession
}
};
if (options.repromptText) {
alexaResponse.response.reprompt = {
outputSpeech: {
"type": "SSML",
"ssml": `<speak><prosody rate="slow">${options.reprompt}</prosody></speak>`
}
};
}
return alexaResponse;
}

jqgrid top header not moving with left scroll , when used mCustomScrol(v3.1.5)

I am trying to use mCustomScrollbar on jqgrid( 4.9.2). The design of the scrollbar is getting changed but when scrolling horizontally the top headers does not move as they do normally.
The example I am trying to work on is of collapsable grid.
and for the mCustomScroll
$(".ui-jqgrid-bdiv").mCustomScrollbar({
    axis:"yx",
});
Is it not possible at all to use any custom scroll bar on jqgrid ?
I had made some customized changes to jqgr so migrating to the other version will be a tough task, so Instead, I made the changes in the mcustomscrollbar and posting the answer so if any one else come across the same problem it will be beneficial.
so there is a methods _tweetTo, which is called for the container on which the scrollbar is assigned by the initializing as
$(".ui-jqgrid-bdiv").mCustomScrollbar({
    axis:"yx",
});
now just after the method call _tweenTo(line# 2131 for V:3.1.5) insert the following code
if ($(".ui-jqgrid-hdiv").length > 0) {
$(".ui-jqgrid-view").css("overflow", "hidden");
$(".ui-jqgrid-hdiv").css("width", $("#grid1").width() + "px"); // grid1 is the id of your gridcontainer/table
_tweenTo($(".ui-jqgrid-hdiv")[0], property, Math.round(scrollTo[0]), dur[0], options.scrollEasing, options.overwrite, {
onStart: function () {
if (options.callbacks && options.onStart && !d.tweenRunning) {
/* callbacks: onScrollStart */
if (_cb("onScrollStart")) { _mcs(); o.callbacks.onScrollStart.call(el[0]); }
d.tweenRunning = true;
_onDragClasses(mCSB_dragger);
d.cbOffsets = _cbOffsets();
}
}, onUpdate: function () {
if (options.callbacks && options.onUpdate) {
/* callbacks: whileScrolling */
if (_cb("whileScrolling")) { _mcs(); o.callbacks.whileScrolling.call(el[0]); }
}
}, onComplete: function () {
if (options.callbacks && options.onComplete) {
if (o.axis === "yx") { clearTimeout(mCSB_container[0].onCompleteTimeout); }
var t = mCSB_container[0].idleTimer || 0;
mCSB_container[0].onCompleteTimeout = setTimeout(function () {
/* callbacks: onScroll, onTotalScroll, onTotalScrollBack */
if (_cb("onScroll")) { _mcs(); o.callbacks.onScroll.call(el[0]); }
if (_cb("onTotalScroll") && scrollTo[1] >= limit[1] - totalScrollOffset && d.cbOffsets[0]) { _mcs(); o.callbacks.onTotalScroll.call(el[0]); }
if (_cb("onTotalScrollBack") && scrollTo[1] <= totalScrollBackOffset && d.cbOffsets[1]) { _mcs(); o.callbacks.onTotalScrollBack.call(el[0]); }
d.tweenRunning = false;
mCSB_container[0].idleTimer = 0;
_onDragClasses(mCSB_dragger, "hide");
}, t);
}
}
});
}
and in the method definition of _tweenTo there is another method _tween
update that method as
function _tween() {
// added condition so the top headers remains fixed
if (el.classList.contains("ui-jqgrid-hdiv") && prop == "top") {
return;
}
//ends here
if (duration > 0) {
tobj.currVal = _ease(tobj.time, from, diff, duration, easing);
elStyle[prop] = Math.round(tobj.currVal) + "px";
} else {
elStyle[prop] = to + "px";
}
onUpdate.call();
}
and the scrollbar is up and running.. !!

Trouble with d3 force directed graph

I'm rendering a force directed graph using d3js. The design is such that nodes are added to the graph at run time by querying a database. This works fine.
While the graph is being rendered, node-by-node, if I happen to click anywhere on the screen, at sometimes, the incoming node gets stuck at the top left of the div and the following error is displayed on debugging:
Error: Invalid value for <line> attribute x2="NaN"
Error: Invalid value for <g> attribute transform="translate(NaN,NaN)"
Sometimes, even an already formed link breaks and an old node gets stuck on the top left until the next refresh.
If I don't interfere, the rendering completes smoothly.
I really do not understand this behavior. Does anyone have any idea what must be going wrong here?
Find my code to compute the graph below:
var graph = { "nodes": [], "links": [] };
var nodeMap = [];
var timestamp;
var json_obj;
var newLogs = false;
$(document).ready(function () {
var count = 0;
doPoll();
function doPoll() {
json_obj = "some object";
var uri = 'api/values?id=' + json_obj;
newLogs = false;
$.getJSON(uri)
.done(function doPoll(data) {
$.each(data, function (key, item) {
newLogs = true;
timestamp = item.timestamp;
populateJson();
function populateJson() {
if (nameExistsInNodes(item.entityName) && item.state == "1") {
searchAndRemoveFromGraph(item.entityName);
}
if (item.entityId != null && !idExistsInNodes(item.entityId)) {
graph.nodes.push({
"eId": item.entityId,
"name": item.entityName,
"state": item.state
});
} else if (item.state == "0" && item.entityId == null) {
graph.nodes.push({
"eId": item.entityName,
"name": item.entityName,
"state": item.state
});
} else if (idExistsInNodes(item.entityId)) {
updateEntityInfo(item);
}
if (!existsInMap(item.entityId) && item.entityId != null) {
nodeMap.push({ "id": item.entityId, "index": count++ });
}
if (item.mapsTo != null && !existsInLinks(findIndexForId(item.entityId), findIndexForId(item.mapsTo))
&& findIndexForId(item.entityId) != null && findIndexForId(item.mapsTo) != null) {
graph.links.push({
"source": findIndexForId(item.entityId),
"target": findIndexForId(item.mapsTo)
});
}
}
});
if (newLogs) {
renderUsingD3(graph);
}
}) // end done
.always(function () { setTimeout(doPoll, 3000) })
} // end doPoll
});
Each item that comes in has an id, name and state and my logic plays around with these 3 to get the graph up.

Marionette - throws error on `removeRegions` how to solve it

In my app, i have the regions as header,content,footer - in which on the login page, I don't want to use the header, and footer. for that, on onRender i remove the regions what i don't want to be.
But I am getting an error saying: Cannot read property 'empty' of undefined.
here is my template : (i use jade )
div#wrapper
script(type='text/template', id="appTemplate")
div#header
div#content
div#footer
script(type='text/template', id="loginTemplate")
div this is login template
here is my layout.js:
socialApp.AppLayout = Backbone.Marionette.LayoutView.extend({
el:'#wrapper',
template:'#appTemplate',
regions: {
header : '#header',
content : '#content',
footer : '#footer'
},
onRender : function () {
this.removeRegion("header", "#header"); //i am removing header alone here.
}
});
here is my controller.js
socialApp.loginController = Marionette.Controller.extend({
_initialize:function(){
this.loginView = new loginView({model:new loginModel});
this.layout.onRender(); //calling onRender from here...
this.layout.content.show(this.loginView);
}
});
But it's all not working. any one help me the correct way please?
You should never call methods that are prefixed with on manually. Those are there for your code to react to given events, in this case that the view’s render method was invoked.
I would suggest that you instead of trying to remove and then later re-add regions, you create two different layouts. Then when your router hits the login route, you render LoginLayout into your App’s root region, and for other routes, the ‘normal’ layout. Here’s how I solved something similar:
app.js:
var App = new Marionette.Application;
App.addRegions({ root: '#acme' });
// Instantiate User model
App.addInitializer(function()
{
this.user = new UserModel;
});
// Render App layout
App.addInitializer(function()
{
this.layout = this.user.get('id') ? new ContentLayoutView({ identifier: 'content' }) : new UserLayoutView({ identifier: 'user' });
this.root.show(this.layout);
// And let the routers decide what goes in the content region of each layout
this.router = {
content: new ContentRouter,
user: new UserRouter
};
});
layout/content.js
var ContentLayout = Marionette.LayoutView.extend(
{
identifier: 'content',
template: ContentLayoutTemplate,
regions: {
content: '[data-region="content"]',
panelLeft: '[data-region="panel-left"]',
panelRight: '[data-region="panel-right"]'
},
initialize: function()
{
this.content.once('show', function(view)
{
this.panelLeft.show(new PanelLeftView);
this.panelRight.show(new PanelRightView);
}.bind(this));
}
});
layout/user.js
var UserLayout = Marionette.LayoutView.extend(
{
identifier: 'user',
template: UserLayoutTemplate,
regions: {
content: '[data-region="content"]'
}
});
router/content.js
var ContentRouter = Marionette.AppRouter.extend(
{
routes: {
'(/)': '...'
},
createLayout: function(callback)
{
if(App.root.currentView.options.identifier != 'content')
{
var layout = new ContentLayoutView({ identifier: 'content' });
this.region = layout.content;
this.listenTo(layout, 'show', callback);
App.root.show(layout);
}
else
{
this.region = App.root.currentView.content;
callback();
}
},
execute: function(callback, args)
{
if(App.user.get('id'))
{
this.createLayout(function()
{
callback.apply(this, args);
}.bind(this));
}
else
App.router.user.navigate('login', true);
}
});
router/user.js
var UserRouter = Marionette.AppRouter.extend(
{
routes: {
'login(/)': 'showLogin',
'logout(/)': 'showLogout'
},
createLayout: function(callback)
{
if(App.root.currentView.options.identifier != 'user')
{
var layout = new UserLayoutView({ identifier: 'user' });
this.region = layout.content;
this.listenTo(layout, 'show', callback);
App.root.show(layout);
}
else
{
this.region = App.root.currentView.content;
callback();
}
},
execute: function(callback, args)
{
this.createLayout(function()
{
callback.apply(this, args);
}.bind(this));
},
showLogin: function()
{
var LoginView = require('view/detail/login');
this.region.show(new LoginView);
},
showLogout: function()
{
var LogoutView = require('view/detail/logout');
this.region.show(new LogoutView);
}
});

Problems with using nsIURIContentListener in Firefox Extension

I am developing a small extension that has to redirect certain URLs to another Site. It's working fine, except for one situation: if open the Link with "Context-Menu -> Open in new Tab", the current page is redirectet to my page and a second tab opens with the link that should be redirected. What am I making wrong? Is there a better way to achieve what I want?
var myListener =
{
QueryInterface: function(iid)
{
if (iid.equals(Components.interfaces.nsIURIContentListener) ||
iid.equals(Components.interfaces.nsISupportsWeakReference) ||
iid.equals(Components.interfaces.nsISupports))
return this;
throw Components.results.NS_NOINTERFACE;
},
onStartURIOpen: function(aUri)
{
if (check_url(aUri)) {
getBrowser().mCurrentTab.linkedBrowser.loadURI(######REDIRECT IS HERE#############);
return true;
}
return false;
},
doContent: function(aContentType, aIsContentPreferred, aRequest, aContentHandler )
{
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
},
canHandleContent: function(aContentType, aIsContentPreferred, aDesiredContentType)
{
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
},
isPreferred: function(aContentType, aDesiredContentType)
{
try
{
var webNavInfo =
Components.classes["#mozilla.org/webnavigation-info;1"]
.getService(Components.interfaces.nsIWebNavigationInfo);
return webNavInfo.isTypeSupported(aContentType, null);
}
catch (e)
{
return false;
}
},
GetWeakReference : function()
{
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
}
}
The complete extension can be found here : http://github.com/bitboxer/firefox-detinyfy
Okay, I did some research. The Hook was a wrong aproach. I changed the code now. Look into the git to find out more...

Resources