Skip to content

Commit

Permalink
Merge pull request #9907 from garymathews/TIMOB-17889
Browse files Browse the repository at this point in the history
[TIMOB-17889] Android: Support Integer to Boolean conversion
  • Loading branch information
lokeshchdhry committed May 8, 2018
2 parents e0ed9a5 + 77448af commit d3eb6ce
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ public static boolean toBoolean(Object value)
} else if (value instanceof String) {
return Boolean.parseBoolean(((String) value));

} else if (value instanceof Integer) {
// in Javascript anything other than zero is 'true'
return ((Integer) value) != 0;

} else {
throw new IllegalArgumentException(
"Unable to convert " + (value == null ? "null" : value.getClass().getName()) + " to boolean.");
Expand Down
21 changes: 21 additions & 0 deletions tests/Resources/ti.api.addontest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Appcelerator Titanium Mobile
* Copyright (c) 2011-Present by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
/* eslint-env mocha */
/* global Ti */
/* eslint no-unused-expressions: "off" */
'use strict';
var should = require('./utilities/assertions');

describe('Titanium.API', function () {
it('integer to boolean conversion', function () {
var view = Ti.UI.createView({ bubbleParent: 0 });

should(view.bubbleParent).be.eql(false);
view.bubbleParent = 1;
should(view.bubbleParent).be.eql(true);
});
});

0 comments on commit d3eb6ce

Please sign in to comment.