Apply v 0.9.0
|
@ -7,7 +7,7 @@
|
|||
"Description": "",
|
||||
"BundleVersion": "1.0",
|
||||
"Framework": "NativeScript",
|
||||
"FrameworkVersion": "0.3.1",
|
||||
"FrameworkVersion": "0.9.0",
|
||||
"ProjectTypeGuids": "{F0A65104-D4F4-4012-B799-F612D75820F6}",
|
||||
"AndroidPermissions": [
|
||||
"android.permission.ACCESS_COARSE_LOCATION",
|
||||
|
@ -53,4 +53,4 @@
|
|||
"ProjectGuid": "{8153a1dd-8591-4620-8c27-6fc63d5106e7}",
|
||||
"WP8PublisherID": "{7c62fb9d-e968-4bd7-970d-f82bd0a47bab}",
|
||||
"WP8ProductID": "{c4b78029-c2e8-4ee0-bee9-8639ed4cada2}"
|
||||
}
|
||||
}
|
||||
|
|
Двоичные данные
nativescript-sample-cuteness/App_Resources/Android/drawable-hdpi/icon.png
Normal file
После Ширина: | Высота: | Размер: 2.1 KiB |
Двоичные данные
nativescript-sample-cuteness/App_Resources/Android/drawable-ldpi/icon.png
Normal file
После Ширина: | Высота: | Размер: 1.6 KiB |
Двоичные данные
nativescript-sample-cuteness/App_Resources/Android/drawable-mdpi/icon.png
Normal file
После Ширина: | Высота: | Размер: 1.7 KiB |
Двоичные данные
nativescript-sample-cuteness/App_Resources/Android/drawable-nodpi/splashscreen.9.png
Normal file
После Ширина: | Высота: | Размер: 8.5 KiB |
После Ширина: | Высота: | Размер: 16 KiB |
После Ширина: | Высота: | Размер: 16 KiB |
После Ширина: | Высота: | Размер: 37 KiB |
После Ширина: | Высота: | Размер: 16 KiB |
После Ширина: | Высота: | Размер: 38 KiB |
После Ширина: | Высота: | Размер: 8.2 KiB |
После Ширина: | Высота: | Размер: 16 KiB |
После Ширина: | Высота: | Размер: 1.8 KiB |
После Ширина: | Высота: | Размер: 2.7 KiB |
После Ширина: | Высота: | Размер: 1.5 KiB |
После Ширина: | Высота: | Размер: 1.9 KiB |
После Ширина: | Высота: | Размер: 1.6 KiB |
После Ширина: | Высота: | Размер: 2.3 KiB |
После Ширина: | Высота: | Размер: 1.9 KiB |
После Ширина: | Высота: | Размер: 3.0 KiB |
После Ширина: | Высота: | Размер: 2.1 KiB |
После Ширина: | Высота: | Размер: 3.4 KiB |
После Ширина: | Высота: | Размер: 2.2 KiB |
После Ширина: | Высота: | Размер: 3.6 KiB |
После Ширина: | Высота: | Размер: 1.9 KiB |
После Ширина: | Высота: | Размер: 2.9 KiB |
|
@ -1,26 +0,0 @@
|
|||
var baseActivityModule = require("base_activity");
|
||||
var activityBody = new baseActivityModule.activityBody();
|
||||
|
||||
activityBody.setupUI = function() {
|
||||
this.setContentView(helpers.getLayoutId(this, "about_activity"));
|
||||
};
|
||||
|
||||
activityBody.updateOptionsMenu = function(menu){
|
||||
this.layoutActionButton.setVisible(false);
|
||||
};
|
||||
|
||||
activityBody.setupActionBar = function(){
|
||||
var actionBar = this.getActionBar();
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
};
|
||||
|
||||
activityBody.onOptionsItemSelected = function(item){
|
||||
var id = item.getItemId();
|
||||
if(id === constants.ID_HOME){
|
||||
this.finish();
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.activity = com.tns.NativeScriptActivity.extends(activityBody);
|
|
@ -1,54 +0,0 @@
|
|||
var ImageSource = require("image-source").ImageSource;
|
||||
|
||||
var AboutViewController = UIKit.UIViewController.extends({
|
||||
viewDidLoad: function() {
|
||||
this.super.viewDidLoad();
|
||||
|
||||
this.title = 'About';
|
||||
|
||||
this.view.backgroundColor = UIKit.UIColor.whiteColor();
|
||||
|
||||
this.label = UIKit.UILabel.initWithFrame(CoreGraphics.CGRectMake(24, 92, this.view.frame.size.width - 48, this.view.frame.size.height - 92));
|
||||
this.label.font = UIKit.UIFont.fontWithNameSize("HelveticaNeue-Thin", 18);
|
||||
this.label.numberOfLines = 0;
|
||||
this.label.autoresizingMask = UIKit.UIViewAutoresizing.UIViewAutoresizingFlexibleWidth | UIKit.UIViewAutoresizing.UIViewAutoresizingFlexibleHeight;
|
||||
this.label.text = "Cuteness is a proof of concept app demonstrating the Telerik's cross-compile solution for writing native mobile applications using JavaScript.";
|
||||
this.label.sizeToFit();
|
||||
this.view.addSubview(this.label);
|
||||
|
||||
var imgTelerik = new ImageSource();
|
||||
imgTelerik.loadFromResource('telerik-logo');
|
||||
this.imgView = UIKit.UIImageView.initWithImage(imgTelerik.ios);
|
||||
this.imgView.frame = CoreGraphics.CGRectMake(24, this.label.frame.size.height + 112, imgTelerik.width, imgTelerik.height);
|
||||
this.view.addSubview(this.imgView);
|
||||
|
||||
// slide out menu button (hamburger button)
|
||||
var imgSlide = new ImageSource();
|
||||
imgSlide.loadFromResource('iconSlide');
|
||||
var slideOutButton = UIKit.UIBarButtonItem.initWithImageStyleTargetAction(imgSlide.ios, 0, this, 'toggleMenu');
|
||||
this.navigationItem.leftBarButtonItem = slideOutButton;
|
||||
},
|
||||
|
||||
viewDidLayoutSubviews: function () {
|
||||
var orientation = UIKit.UIApplication.sharedApplication().statusBarOrientation
|
||||
var orientationIsPortrait = (UIKit.UIInterfaceOrientation.UIInterfaceOrientationPortrait == orientation) || (UIKit.UIInterfaceOrientation.UIInterfaceOrientationPortraitUpsideDown == orientation);
|
||||
|
||||
this.label.frame = CoreGraphics.CGRectMake(24, orientationIsPortrait ? 92 : 80, this.view.frame.size.width - 48, this.view.frame.size.height - 92);
|
||||
this.label.sizeToFit();
|
||||
|
||||
var frame = this.imgView.frame;
|
||||
frame.origin.y = this.label.frame.size.height + 112;
|
||||
this.imgView.frame = frame;
|
||||
},
|
||||
|
||||
toggleMenu: function() {
|
||||
this.slideOut.toggleMenu();
|
||||
}
|
||||
|
||||
}, {
|
||||
exposedMethods: {
|
||||
'toggleMenu': 'v@:@',
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = AboutViewController;
|
|
@ -0,0 +1,3 @@
|
|||
var application = require("application");
|
||||
application.mainModule = "app/main-page";
|
||||
application.start();
|
|
@ -1,237 +0,0 @@
|
|||
var http = require("http");
|
||||
var modelModule = require("model");
|
||||
var ImageSource = require("image-source").ImageSource;
|
||||
|
||||
var baseImage = new ImageSource();
|
||||
baseImage.loadFromResource('logo');
|
||||
|
||||
var CollectionChangedAction;
|
||||
(function (CollectionChangedAction) {
|
||||
CollectionChangedAction[CollectionChangedAction["Add"] = 0] = "Add";
|
||||
CollectionChangedAction[CollectionChangedAction["Remove"] = 1] = "Remove";
|
||||
CollectionChangedAction[CollectionChangedAction["Replace"] = 2] = "Replace";
|
||||
CollectionChangedAction[CollectionChangedAction["Move"] = 3] = "Move";
|
||||
CollectionChangedAction[CollectionChangedAction["Reset"] = 4] = "Reset";
|
||||
})(CollectionChangedAction || (CollectionChangedAction = {}));
|
||||
|
||||
var CollectionChangedArgs = (function () {
|
||||
function CollectionChangedArgs(index, count, action) {
|
||||
this._index = index;
|
||||
this._count = count;
|
||||
this._action = action;
|
||||
}
|
||||
Object.defineProperty(CollectionChangedArgs.prototype, "index", {
|
||||
get: function () {
|
||||
return this._index;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(CollectionChangedArgs.prototype, "count", {
|
||||
get: function () {
|
||||
return this._count;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(CollectionChangedArgs.prototype, "action", {
|
||||
get: function () {
|
||||
return this._action;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return CollectionChangedArgs;
|
||||
})();
|
||||
|
||||
|
||||
var appModel = (function () {
|
||||
var batchSize = 30;
|
||||
var jsonUrl = "http://www.reddit.com/r/aww.json?limit=" + batchSize;
|
||||
|
||||
function appModel() {
|
||||
this.items = [];
|
||||
this.changedListeners = [];
|
||||
this.pendingDownloads = [];
|
||||
this.concurrentDownloads = 0;
|
||||
}
|
||||
|
||||
appModel.prototype.isDefaultImage = function(thumbnail) {
|
||||
return thumbnail === 'default' || thumbnail === 'self' || thumbnail === '';
|
||||
};
|
||||
|
||||
appModel.prototype.downloadThumbnail = function(item) {
|
||||
if(item.downloadingThumbnail) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!item.callback) {
|
||||
var index = this.pendingDownloads.indexOf(item);
|
||||
if (index > -1) {
|
||||
this.pendingDownloads.splice(index, 1);
|
||||
}
|
||||
this.tryDownloadNextRequest();
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.bitmap || item.downloadRequestCompleted) {
|
||||
item.callback(item.bitmap);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isDefaultImage(item.imageUrl)) {
|
||||
this.setBitmap(item, null);
|
||||
}
|
||||
else {
|
||||
if(this.concurrentDownloads < 4) {
|
||||
this.concurrentDownloads++;
|
||||
item.downloadingThumbnail = true;
|
||||
var that = this;
|
||||
|
||||
http.getImage(item.imageUrl).then(function(image) {
|
||||
that.onImageDownloaded(item, image);
|
||||
}).fail(function(error) {
|
||||
that.onImageDownloaded(item, null);
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.pendingDownloads.push(item);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
appModel.prototype.onImageDownloaded = function(item, image) {
|
||||
this.concurrentDownloads--;
|
||||
|
||||
this.setBitmap(item, image);
|
||||
this.tryDownloadNextRequest();
|
||||
};
|
||||
|
||||
appModel.prototype.setBitmap = function(item, image) {
|
||||
if (!image) {
|
||||
image = baseImage;
|
||||
}
|
||||
|
||||
item.bitmap = image;
|
||||
item.downloadingThumbnail = false;
|
||||
if (item.callback) {
|
||||
item.callback(image);
|
||||
}
|
||||
};
|
||||
|
||||
appModel.prototype.tryDownloadNextRequest = function() {
|
||||
if(this.pendingDownloads.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var item = this.pendingDownloads.pop();
|
||||
this.downloadThumbnail(item);
|
||||
};
|
||||
|
||||
appModel.prototype.addChangedListener = function (listener) {
|
||||
if (listener) {
|
||||
this.changedListeners.push(listener);
|
||||
}
|
||||
};
|
||||
|
||||
appModel.prototype.itemAt = function (index) {
|
||||
return this.items[index];
|
||||
};
|
||||
|
||||
appModel.prototype.notifyChanged = function (collectionChangedArgs) {
|
||||
var i,
|
||||
listener;
|
||||
for(i = 0; i < this.changedListeners.length; i++) {
|
||||
listener = this.changedListeners[i];
|
||||
if(listener.onItemsChanged) {
|
||||
listener.onItemsChanged(collectionChangedArgs);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
appModel.prototype.requestMoreItems = function () {
|
||||
if (this._downloadStarted) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._downloadStarted = true;
|
||||
var url = jsonUrl;
|
||||
if (this.itemCount > 0) {
|
||||
url += "&after=" + this.items[this.itemCount - 1].fullName;
|
||||
}
|
||||
|
||||
var that = this;
|
||||
http.getJSON(url)
|
||||
.then(function (result) {
|
||||
that.onItemsDownloaded(result);
|
||||
});
|
||||
};
|
||||
|
||||
appModel.prototype.onItemsDownloaded = function (result) {
|
||||
var children = result.data.children;
|
||||
var i,
|
||||
child,
|
||||
model;
|
||||
|
||||
var index = this.items.length;
|
||||
var action = index === 0 ? CollectionChangedAction.Reset : CollectionChangedAction.Add;
|
||||
|
||||
for(i = 0; i < children.length; i++){
|
||||
child = children[i].data;
|
||||
model = new modelModule.model(child.title, child.thumbnail);
|
||||
model.author = child.author;
|
||||
model.fullName = child.name;
|
||||
var url = child.url;
|
||||
var imgurIndex = url.indexOf("imgur.com");
|
||||
if(imgurIndex >= 0) {
|
||||
var invalidUrl = url.indexOf("i.") === -1 || url.lastIndexOf(".gif") !== -1;
|
||||
if (invalidUrl) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
model.largeImageUrl = url;
|
||||
model.commentsCount = child.num_comments;
|
||||
model.commentsUrl = child.permalink;
|
||||
model.score = child.score;
|
||||
|
||||
var dateCreated = new Date(child.created);
|
||||
model.created = dateCreated.toLocaleTimeString();
|
||||
|
||||
this.items.push(model);
|
||||
}
|
||||
|
||||
this._downloadStarted = false;
|
||||
var args = new CollectionChangedArgs(index, this.items.length - index, action);
|
||||
this.notifyChanged(args);
|
||||
};
|
||||
|
||||
Object.defineProperty(appModel.prototype, "itemCount", {
|
||||
get: function () {
|
||||
return this.items.length;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: false
|
||||
});
|
||||
|
||||
Object.defineProperty(appModel.prototype, "selectedItem", {
|
||||
get: function () {
|
||||
return this._selectedItem;
|
||||
},
|
||||
set: function(value) {
|
||||
this._selectedItem = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: false
|
||||
});
|
||||
|
||||
appModel.instance = new appModel();
|
||||
return appModel;
|
||||
})();
|
||||
|
||||
exports.CollectionChangedArgs = CollectionChangedArgs;
|
||||
exports.CollectionChangedAction = CollectionChangedAction;
|
||||
exports.appModel = appModel;
|
||||
exports.baseImage = baseImage;
|
|
@ -1,20 +0,0 @@
|
|||
var activityBody = (function(){
|
||||
function activity(){
|
||||
this.onCreate = function(bundle){
|
||||
this.super.onCreate(bundle);
|
||||
|
||||
// This function is not defined here, inheritors will define it
|
||||
if(this.setupUI){
|
||||
this.setupUI();
|
||||
}
|
||||
|
||||
if(this.setupActionBar){
|
||||
this.setupActionBar();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return activity;
|
||||
})();
|
||||
|
||||
exports.activityBody = activityBody;
|
|
@ -1,74 +0,0 @@
|
|||
var __extends_ts = function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
|
||||
var __extends = function(Child, Parent) {
|
||||
|
||||
if (Parent.extends) {
|
||||
if (Parent.__extended) {
|
||||
throw new Error("Can not extend an already extended native object.");
|
||||
}
|
||||
|
||||
function extend(child, parent) {
|
||||
|
||||
if (!child.__extended) {
|
||||
child.__extended = parent.extends(child.prototype);
|
||||
}
|
||||
|
||||
return child.__extended;
|
||||
};
|
||||
|
||||
Parent.call = function(thiz) {
|
||||
var Extended = extend(thiz.__proto__.__child, thiz.__proto__.__parent);
|
||||
if (arguments.length > 1)
|
||||
{
|
||||
thiz.__proto__ = new (Function.prototype.bind.apply(Extended, [null].concat(Array.prototype.slice.call(arguments, 1))));
|
||||
}
|
||||
else
|
||||
{
|
||||
thiz.__proto__ = new Extended();
|
||||
}
|
||||
};
|
||||
|
||||
Parent.apply = function(thiz, args) {
|
||||
var Extended = extend(thiz.__proto__.__child, thiz.__proto__.__parent);
|
||||
if (args && args.length > 0)
|
||||
{
|
||||
thiz.__proto__ = new (Function.prototype.bind.apply(Extended, [null].concat(args)));
|
||||
}
|
||||
else
|
||||
{
|
||||
thiz.__proto__ = new Extended();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
__extends_ts(Child, Parent);
|
||||
|
||||
|
||||
if (Parent.extends) {
|
||||
Child.__isPrototypeImplementationObject = true;
|
||||
Child.__proto__ = Parent;
|
||||
Child.prototype.__parent = Parent;
|
||||
Child.prototype.__child = Child;
|
||||
}
|
||||
}
|
||||
|
||||
global.__extends = __extends;
|
||||
|
||||
var appModule = require("application");
|
||||
|
||||
app.init({
|
||||
|
||||
getActivity: function(intent) {
|
||||
return appModule.android.getActivity(intent);
|
||||
},
|
||||
|
||||
onCreate: function() {
|
||||
appModule.init(this);
|
||||
require("main");
|
||||
}
|
||||
});
|
|
@ -1,41 +0,0 @@
|
|||
var m_app = require("application");
|
||||
m_app.init(null);
|
||||
|
||||
var MainViewController = require("mainPage");
|
||||
var AboutViewController = require("aboutPage");
|
||||
var CutenessUtils = require("cutenessUtils");
|
||||
var SlideOutViewController = require("slideOutViewController");
|
||||
var MenuViewController = require("menuViewController");
|
||||
|
||||
m_app.onLaunch = function() {
|
||||
|
||||
var slideOut = new SlideOutViewController();
|
||||
|
||||
var menuViewController = new MenuViewController();
|
||||
menuViewController.slideOut = slideOut;
|
||||
|
||||
var mainViewController = new MainViewController(new UIKit.UICollectionViewFlowLayout());
|
||||
mainViewController.slideOut = slideOut;
|
||||
var mainNavController = new UIKit.UINavigationController(mainViewController);
|
||||
|
||||
var aboutViewController = new AboutViewController();
|
||||
aboutViewController.slideOut = slideOut;
|
||||
var aboutNavController = new UIKit.UINavigationController(aboutViewController);
|
||||
|
||||
menuViewController.setViewControllers([mainNavController, aboutNavController]);
|
||||
slideOut.setup(menuViewController, mainNavController);
|
||||
|
||||
// style
|
||||
UIKit.UIApplication.sharedApplication().delegate.window.backgroundColor = UIKit.UIColor.colorWithRedGreenBlueAlpha(0.866667, 0.886275, 0.894118, 1);
|
||||
UIKit.UIApplication.sharedApplication().setStatusBarStyleAnimated(UIKit.UIStatusBarStyle.UIStatusBarStyleDarkContent, false);
|
||||
mainNavController.navigationBar.titleTextAttributes = CutenessUtils.JSToNSDictionary({ 'NSColor' : UIKit.UIColor.whiteColor() });
|
||||
// mainNavController.navigationBar().setBarTintColor(UIKit.UIColor.colorWithRedGreenBlueAlpha(16/255, 196/255, 178/255, 1));
|
||||
mainNavController.navigationBar.barTintColor = UIKit.UIColor.colorWithRedGreenBlueAlpha(0.976471, 0.976471, 0.972549, 1);
|
||||
mainNavController.navigationBar.tintColor = UIKit.UIColor.colorWithRedGreenBlueAlpha(0.023529, 0.505882, 0.454902, 1);
|
||||
|
||||
aboutNavController.navigationBar.titleTextAttributes = CutenessUtils.JSToNSDictionary({ 'NSColor' : UIKit.UIColor.colorWithRedGreenBlueAlpha(0.023529, 0.505882, 0.454902, 1) });
|
||||
aboutNavController.navigationBar.barTintColor = UIKit.UIColor.colorWithRedGreenBlueAlpha(0.976471, 0.976471, 0.972549, 1);
|
||||
aboutNavController.navigationBar.tintColor = UIKit.UIColor.colorWithRedGreenBlueAlpha(0.023529, 0.505882, 0.454902, 1);
|
||||
|
||||
return slideOut;
|
||||
};
|
|
@ -1,26 +0,0 @@
|
|||
|
||||
function JSToNSDictionary(obj) {
|
||||
if (obj) {
|
||||
var dict = new Foundation.NSMutableDictionary();
|
||||
for (var id in obj) {
|
||||
try {
|
||||
if (typeof (obj[id]) !== 'function') {
|
||||
dict.setObjectForKey(obj[id], id);
|
||||
}
|
||||
} catch (err) {
|
||||
}
|
||||
}
|
||||
return dict;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function decodeHtml(str)
|
||||
{
|
||||
return str.replace(/&/g, '&').replace(/>/g, '>').replace(/</g, '<').replace(/"/g, '"');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
'JSToNSDictionary' : JSToNSDictionary,
|
||||
'decodeHtml': decodeHtml
|
||||
};
|
|
@ -0,0 +1,14 @@
|
|||
Page {
|
||||
background-color: #363940;
|
||||
}
|
||||
|
||||
.detailsTitle {
|
||||
color: #FFFFFF;
|
||||
font-size: 30;
|
||||
margin: 10;
|
||||
}
|
||||
|
||||
ActivityIndicator {
|
||||
width: 50;
|
||||
height: 50;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
function pageNavigatedTo(args) {
|
||||
var page = args.object;
|
||||
page.bindingContext = page.navigationContext;
|
||||
}
|
||||
exports.pageNavigatedTo = pageNavigatedTo;
|
|
@ -0,0 +1,24 @@
|
|||
<Page xmlns="http://www.nativescript.org/tns.xsd" navigatedTo="pageNavigatedTo">
|
||||
<GridLayout rows="*, auto">
|
||||
<ScrollView>
|
||||
<StackLayout>
|
||||
<Image source="{{ imageSource }}" stretch="aspectFill"/>
|
||||
<Label text="{{ title }}" cssClass="detailsTitle" textWrap="true" />
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
<StackLayout orientation="horizontal" row="1">
|
||||
<Label margin="2">
|
||||
<Label.formattedText>
|
||||
<FormattedString fontSize="20" foregroundColor="#C6C6C6">
|
||||
<FormattedString.spans>
|
||||
<Span text="{{ author ? 'by ' + author : '' }}"/>
|
||||
<Span text="{{ num_comments ? ' | ' : '' }}" />
|
||||
<Span text="{{ num_comments ? num_comments + ' comments' : '' }}" foregroundColor="#10C2B0"/>
|
||||
</FormattedString.spans>
|
||||
</FormattedString>
|
||||
</Label.formattedText>
|
||||
</Label>
|
||||
</StackLayout>
|
||||
<ActivityIndicator busy="{{ isLoading }}" />
|
||||
</GridLayout>
|
||||
</Page>
|
|
@ -1,155 +0,0 @@
|
|||
var appModelModule = require("app_model");
|
||||
var appModel = appModelModule.appModel.instance;
|
||||
var http = require("http");
|
||||
|
||||
var baseActivityModule = require("base_activity");
|
||||
var activityBody = new baseActivityModule.activityBody();
|
||||
|
||||
var redditUrl = "http://www.reddit.com";
|
||||
var userUrl = "http://www.reddit.com/user/";
|
||||
var Html = android.text.Html;
|
||||
|
||||
activityBody.setupUI = function() {
|
||||
var selectedItem = appModel.selectedItem;
|
||||
|
||||
var layoutParams;
|
||||
var relativeLayout = new android.widget.RelativeLayout(this);
|
||||
layoutParams = new android.view.ViewGroup.LayoutParams(constants.LAYOUT_MATCH_PARENT, constants.LAYOUT_MATCH_PARENT);
|
||||
relativeLayout.setLayoutParams(layoutParams);
|
||||
|
||||
var progressBar = new android.widget.ProgressBar(this);
|
||||
layoutParams = new android.widget.RelativeLayout.LayoutParams(android.view.Gravity.CENTER_HORIZONTAL, android.view.Gravity.TOP);
|
||||
var length = metrics.toDIP(this, 72);
|
||||
layoutParams.width = length;
|
||||
layoutParams.height = length;
|
||||
layoutParams.addRule(android.widget.RelativeLayout.ALIGN_PARENT_LEFT);
|
||||
layoutParams.addRule(android.widget.RelativeLayout.ALIGN_PARENT_TOP);
|
||||
layoutParams.addRule(android.widget.RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
layoutParams.topMargin = metrics.toDIP(this, 100);
|
||||
progressBar.setLayoutParams(layoutParams);
|
||||
relativeLayout.addView(progressBar);
|
||||
|
||||
progressBar.setIndeterminate(true);
|
||||
progressBar.setVisibility(constants.VISIBILITY_VISIBLE);
|
||||
this.progressBar = progressBar;
|
||||
|
||||
var imageView = new android.widget.ImageView(this);
|
||||
layoutParams = new android.widget.RelativeLayout.LayoutParams(constants.LAYOUT_WRAP_CONTENT, constants.LAYOUT_WRAP_CONTENT);
|
||||
layoutParams.addRule(android.widget.RelativeLayout.ALIGN_PARENT_LEFT);
|
||||
layoutParams.addRule(android.widget.RelativeLayout.ALIGN_PARENT_TOP);
|
||||
layoutParams.addRule(android.widget.RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
layoutParams.addRule(android.widget.RelativeLayout.ALIGN_PARENT_BOTTOM);
|
||||
layoutParams.bottomMargin = metrics.toDIP(this, 160);
|
||||
imageView.setLayoutParams(layoutParams);
|
||||
relativeLayout.addView(imageView);
|
||||
|
||||
var scrollView = new android.widget.ScrollView(this);
|
||||
layoutParams = new android.widget.RelativeLayout.LayoutParams(constants.LAYOUT_MATCH_PARENT, metrics.toDIP(this, 160));
|
||||
layoutParams.addRule(android.widget.RelativeLayout.ALIGN_PARENT_LEFT);
|
||||
layoutParams.addRule(android.widget.RelativeLayout.ALIGN_PARENT_BOTTOM);
|
||||
scrollView.setLayoutParams(layoutParams);
|
||||
scrollView.setBackgroundColor(android.graphics.Color.parseColor("#363940"));
|
||||
|
||||
relativeLayout.addView(scrollView);
|
||||
|
||||
var linearLayout = new android.widget.LinearLayout(this);
|
||||
var length = metrics.toDIP(this, 6);
|
||||
linearLayout.setPadding(metrics.toDIP(this, 16), metrics.toDIP(this, 10), metrics.toDIP(this, 16), metrics.toDIP(this, 10));
|
||||
linearLayout.setOrientation(constants.VERTICAL);
|
||||
|
||||
scrollView.addView(linearLayout);
|
||||
|
||||
var tvTitle = new android.widget.TextView(this);
|
||||
tvTitle.setTextColor(android.graphics.Color.WHITE);
|
||||
tvTitle.setText(selectedItem.header);
|
||||
tvTitle.setLayoutParams(new android.widget.LinearLayout.LayoutParams(constants.LAYOUT_WRAP_CONTENT, constants.LAYOUT_WRAP_CONTENT));
|
||||
tvTitle.setTextSize(20);
|
||||
|
||||
linearLayout.addView(tvTitle);
|
||||
|
||||
// the layout that will store the author and comments links
|
||||
var linearLayoutBottom = new android.widget.LinearLayout(this);
|
||||
linearLayoutBottom.setOrientation(constants.HORIZONTAL);
|
||||
layoutParams = new android.widget.LinearLayout.LayoutParams(constants.LAYOUT_WRAP_CONTENT, constants.LAYOUT_WRAP_CONTENT);
|
||||
layoutParams.topMargin = metrics.toDIP(this, 12);
|
||||
linearLayoutBottom.setLayoutParams(layoutParams);
|
||||
|
||||
var textSize = 16;
|
||||
// the "by " text view
|
||||
var tvBy = new android.widget.TextView(this);
|
||||
tvBy.setTextColor(android.graphics.Color.WHITE);
|
||||
tvBy.setText("by ");
|
||||
tvBy.setTextSize(textSize);
|
||||
|
||||
linearLayoutBottom.addView(tvBy);
|
||||
|
||||
var url = userUrl + selectedItem.author;
|
||||
var authorUrl = Html.fromHtml("<font color='#3DA799'><a href='" + url + "'>" + selectedItem.author + "</a></font>");
|
||||
|
||||
// the author TextView
|
||||
var tvAuthor = new android.widget.TextView(this);
|
||||
tvAuthor.setText(authorUrl);
|
||||
tvAuthor.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
|
||||
tvAuthor.setTextSize(textSize);
|
||||
|
||||
linearLayoutBottom.addView(tvAuthor);
|
||||
|
||||
// the separator TextView
|
||||
var tvSeparator = new android.widget.TextView(this);
|
||||
tvSeparator.setTextColor(android.graphics.Color.WHITE);
|
||||
tvSeparator.setText(" | ");
|
||||
tvSeparator.setTextSize(textSize);
|
||||
|
||||
linearLayoutBottom.addView(tvSeparator);
|
||||
|
||||
url = redditUrl + selectedItem.commentsUrl;
|
||||
var comments = selectedItem.commentsCount + " comments";
|
||||
var commentsUrl = Html.fromHtml("<font color='#3DA799'><a href='" + url + "'>" + comments + "</a></font>");
|
||||
|
||||
// the comments TextView
|
||||
var tvComments = new android.widget.TextView(this);
|
||||
tvComments.setText(commentsUrl);
|
||||
tvComments.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
|
||||
tvComments.setTextSize(textSize);
|
||||
|
||||
linearLayoutBottom.addView(tvComments);
|
||||
linearLayout.addView(linearLayoutBottom);
|
||||
this.setContentView(relativeLayout);
|
||||
this.loadPicture(selectedItem, imageView);
|
||||
this.imageView = imageView;
|
||||
};
|
||||
|
||||
activityBody.loadPicture = function(item, imageView) {
|
||||
var that = this;
|
||||
http.getImage(item.largeImageUrl)
|
||||
.then(function(image) {
|
||||
that.progressBar.setIndeterminate(false);
|
||||
that.progressBar.setVisibility(constants.VISIBILITY_GONE);
|
||||
|
||||
if(image) {
|
||||
imageView.setImageBitmap(image.android);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
activityBody.setupActionBar = function() {
|
||||
var actionBar = this.getActionBar();
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
};
|
||||
|
||||
activityBody.onOptionsItemSelected = function(item){
|
||||
var id = item.getItemId();
|
||||
if(id === constants.ID_HOME) {
|
||||
this.finish();
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
activityBody.onDestroy = function(){
|
||||
this.super.onDestroy();
|
||||
|
||||
this.imageView.setImageBitmap(null);
|
||||
}
|
||||
|
||||
exports.activity = com.tns.NativeScriptActivity.extends(activityBody);
|
|
@ -1,139 +0,0 @@
|
|||
var CutenessUtils = require("cutenessUtils");
|
||||
var http = require("http");
|
||||
var ImageSource = require("image-source").ImageSource;
|
||||
//var GifAnimator = require("animatedGIF");
|
||||
var redditUrl = "http://www.reddit.com";
|
||||
|
||||
var imgLogo = new ImageSource();
|
||||
imgLogo.loadFromResource('logo');
|
||||
|
||||
var DetailViewController = UIKit.UIViewController.extends({
|
||||
viewDidLoad: function() {
|
||||
this.super.viewDidLoad();
|
||||
|
||||
var imgView = UIKit.UIImageView.initWithImage(imgLogo.ios);
|
||||
this.navigationItem.titleView = imgView;
|
||||
|
||||
this.view.backgroundColor = UIKit.UIColor.colorWithRedGreenBlueAlpha(0.211765, 0.223529, 0.250980, 1);
|
||||
this.activityIndicator = UIKit.UIActivityIndicatorView.initWithActivityIndicatorStyle(UIKit.UIActivityIndicatorViewStyle.UIActivityIndicatorViewStyleWhiteLarge);
|
||||
this.activityIndicator.center = this.view.center;
|
||||
this.view.addSubview(this.activityIndicator);
|
||||
this.activityIndicator.startAnimating();
|
||||
|
||||
this.scrollView = UIKit.UIScrollView.initWithFrame(this.view.frame);
|
||||
this.scrollView.autoresizingMask = UIKit.UIViewAutoresizing.UIViewAutoresizingFlexibleWidth | UIKit.UIViewAutoresizing.UIViewAutoresizingFlexibleHeight;
|
||||
this.scrollView.hidden = true;
|
||||
this.scrollView.contentInset = UIKit.UIEdgeInsetsMake(this.navigationController.navigationBar.frame.size.height + 20, 0, 0, 0);
|
||||
this.view.addSubview(this.scrollView);
|
||||
|
||||
this.imgView = new UIKit.UIImageView();
|
||||
this.scrollView.addSubview(this.imgView);
|
||||
|
||||
this.titleLabel = UIKit.UILabel.initWithFrame(this.view.frame);
|
||||
this.titleLabel.font = UIKit.UIFont.fontWithNameSize("HelveticaNeue-Thin", 28);
|
||||
this.titleLabel.numberOfLines = 0;
|
||||
this.titleLabel.textColor = UIKit.UIColor.whiteColor();
|
||||
this.titleLabel.text = CutenessUtils.decodeHtml(this.item.header);
|
||||
this.scrollView.addSubview(this.titleLabel);
|
||||
|
||||
this.detailLabel = UIKit.UILabel.initWithFrame(this.view.frame);
|
||||
this.detailLabel.font = UIKit.UIFont.fontWithNameSize("HelveticaNeue-Thin", 16);
|
||||
this.detailLabel.numberOfLines = 0;
|
||||
this.detailLabel.userInteractionEnabled = true;
|
||||
|
||||
var tapGestureRecognizer = UIKit.UITapGestureRecognizer.initWithTargetAction(this, 'onTap');
|
||||
this.detailLabel.addGestureRecognizer(tapGestureRecognizer);
|
||||
|
||||
var text = 'by ' + this.item.author + ' | ' + this.item.commentsCount + ' comments';
|
||||
var attributedText = UIKit.NSMutableAttributedString.initWithString(text);
|
||||
|
||||
attributedText.addAttributeValueRange('NSColor', UIKit.UIColor.whiteColor(), Foundation.NSMakeRange(0, text.length));
|
||||
attributedText.addAttributeValueRange('NSColor', UIKit.UIColor.colorWithRedGreenBlueAlpha(0.023529, 0.505882, 0.454902, 1), Foundation.NSMakeRange(6 + this.item.author.toString().length, (9 + this.item.commentsCount.toString().length)));
|
||||
this.detailLabel.attributedText = attributedText;
|
||||
this.scrollView.addSubview(this.detailLabel);
|
||||
|
||||
this.getData();
|
||||
},
|
||||
|
||||
didRotateFromInterfaceOrientation: function (fromInterfaceOrientation) {
|
||||
this.scrollView.contentInset = UIKit.UIEdgeInsetsMake(this.navigationController.navigationBar.frame.size.height + 20, 0, 0, 0);
|
||||
this.activityIndicator.center = this.view.center;
|
||||
},
|
||||
|
||||
onTap: function() {
|
||||
var url = redditUrl + this.item.commentsUrl;
|
||||
UIKit.UIApplication.sharedApplication().openURL(Foundation.NSURL.URLWithString(url));
|
||||
},
|
||||
|
||||
getData: function() {
|
||||
UIKit.UIApplication.sharedApplication().networkActivityIndicatorVisible = true;
|
||||
var url = this.item.largeImageUrl;
|
||||
if (url.match(/http:\/\/imgur.com\/.[^\/]/i) || url.match(/http:\/\/imgur.com\/a\//i) || url.match(/http:\/\/imgur.com\/gallery\//i)) {
|
||||
var str = Foundation.NSString.stringWithString(url);
|
||||
url = 'http://i.imgur.com/' + str.lastPathComponent() + '.jpg';
|
||||
}
|
||||
|
||||
/* if (url.match(/\.gif$/i)) {
|
||||
var res = GifAnimator.animatedImageWithAnimatedGIFURL(url);
|
||||
}
|
||||
else {*/
|
||||
var that = this;
|
||||
http.getImage(url)
|
||||
.then(function(image) {
|
||||
if (image && image.ios) {
|
||||
that.image = image;
|
||||
}
|
||||
else
|
||||
{
|
||||
that.image = null;
|
||||
that.titleLabel.text = 'Error loading image!';
|
||||
that.detailLabel.text = '';
|
||||
}
|
||||
that.scrollView.hidden = false;
|
||||
that.view.setNeedsLayout();
|
||||
that.activityIndicator.stopAnimating();
|
||||
UIKit.UIApplication.sharedApplication().networkActivityIndicatorVisible = false;
|
||||
})
|
||||
.fail(function(error) {
|
||||
that.image = null;
|
||||
that.titleLabel.text = 'Error loading image!';
|
||||
that.detailLabel.text = '';
|
||||
that.scrollView.hidden = false;
|
||||
that.view.setNeedsLayout();
|
||||
that.activityIndicator.stopAnimating();
|
||||
UIKit.UIApplication.sharedApplication().networkActivityIndicatorVisible = false;
|
||||
});
|
||||
/* }*/
|
||||
},
|
||||
|
||||
viewDidLayoutSubviews: function() {
|
||||
this.super.viewDidLayoutSubviews();
|
||||
this.activityIndicator.center = this.view.center;
|
||||
if (this.image && this.image.ios) {
|
||||
var maxWidth = this.view.frame.size.width;
|
||||
var expectedWidth = expectedWidth = maxWidth;
|
||||
var expectedHeight = maxWidth * (this.image.height / this.image.width);
|
||||
|
||||
this.imgView.image = this.image.ios;
|
||||
this.imgView.frame = CoreGraphics.CGRectMake(0, 0, expectedWidth, expectedHeight);
|
||||
|
||||
this.titleLabel.frame = CoreGraphics.CGRectMake(20, expectedHeight + 15, expectedWidth - 30, 9999);
|
||||
this.titleLabel.sizeToFit();
|
||||
|
||||
this.detailLabel.frame = CoreGraphics.CGRectMake(20, expectedHeight + 30 + this.titleLabel.frame.size.height, expectedWidth - 20, 9999);
|
||||
this.detailLabel.sizeToFit();
|
||||
|
||||
this.scrollView.contentSize = CoreGraphics.CGSizeMake(this.view.frame.size.width, expectedHeight + this.titleLabel.frame.size.height + this.detailLabel.frame.size.height + 45);
|
||||
}
|
||||
else {
|
||||
this.titleLabel.frame = CoreGraphics.CGRectMake(20, 15, this.view.frame.size.width - 40, 9999);
|
||||
this.titleLabel.sizeToFit();
|
||||
}
|
||||
}
|
||||
}, {
|
||||
exposedMethods: {
|
||||
'onTap': 'v@:@'
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = DetailViewController;
|
|
@ -1,25 +0,0 @@
|
|||
var item = (function (){
|
||||
function item(context){
|
||||
var layoutParams;
|
||||
|
||||
var relativeLayout = new android.widget.RelativeLayout(context);
|
||||
layoutParams = new android.widget.AbsListView.LayoutParams(constants.LAYOUT_MATCH_PARENT, metrics.toDIP(context, 48));
|
||||
relativeLayout.setLayoutParams(layoutParams);
|
||||
|
||||
var textView = new android.widget.TextView(context);
|
||||
layoutParams = new android.widget.RelativeLayout.LayoutParams(constants.LAYOUT_WRAP_CONTENT, constants.LAYOUT_WRAP_CONTENT);
|
||||
layoutParams.leftMargin = metrics.toDIP(context, 16);
|
||||
layoutParams.addRule(android.widget.RelativeLayout.CENTER_VERTICAL);
|
||||
textView.setLayoutParams(layoutParams);
|
||||
textView.setTextSize(20);
|
||||
|
||||
relativeLayout.addView(textView);
|
||||
|
||||
this.rootView = relativeLayout;
|
||||
this.text = textView;
|
||||
};
|
||||
|
||||
return item;
|
||||
})();
|
||||
|
||||
exports.item = item;
|
|
@ -1,37 +0,0 @@
|
|||
var adapterBody = {
|
||||
getCount: function () {
|
||||
return 1;
|
||||
},
|
||||
|
||||
getItem: function (position){
|
||||
return "About";
|
||||
},
|
||||
|
||||
getView: function (position, convertView, parent){
|
||||
var item = this.getItem(position);
|
||||
|
||||
var itemLayout;
|
||||
if(!convertView || !convertView.getTag()){
|
||||
var layoutModule = require("drawer_item_layout");
|
||||
itemLayout = new layoutModule.item(parent.getContext());
|
||||
convertView = itemLayout.rootView;
|
||||
|
||||
// we need a java object here, cannot use setTag with a JS object
|
||||
var javaObject = new java.lang.Object();
|
||||
javaObject.item = itemLayout;
|
||||
convertView.setTag(javaObject);
|
||||
} else {
|
||||
itemLayout = convertView.getTag().item;
|
||||
}
|
||||
|
||||
itemLayout.text.setText(item);
|
||||
|
||||
return convertView;
|
||||
},
|
||||
|
||||
getItemId: function (position){
|
||||
return long(position);
|
||||
}
|
||||
};
|
||||
|
||||
exports.adapterBody = adapterBody;
|
|
@ -1,127 +0,0 @@
|
|||
var app = require("application");
|
||||
var appModelModule = require("app_model");
|
||||
var appModel = appModelModule.appModel.instance;
|
||||
var baseImage = appModelModule.baseImage;
|
||||
|
||||
var item = (function () {
|
||||
function item(context) {
|
||||
var linearLayout = new android.widget.LinearLayout(context);
|
||||
linearLayout.setLayoutParams(new android.widget.AbsListView.LayoutParams(constants.LAYOUT_MATCH_PARENT, constants.LAYOUT_WRAP_CONTENT));
|
||||
linearLayout.setOrientation(constants.HORIZONTAL);
|
||||
|
||||
var margin = metrics.toDIP(context, 8);
|
||||
var length = metrics.toDIP(context, 72);
|
||||
var imageView = getImageView(context, length, margin);
|
||||
linearLayout.addView(imageView);
|
||||
this.image = imageView;
|
||||
|
||||
length = context.getResources().getDisplayMetrics().widthPixels / 2;
|
||||
imageView = getImageView(context, length, 0);
|
||||
imageView.setVisibility(constants.VISIBILITY_GONE);
|
||||
linearLayout.addView(imageView);
|
||||
this.image2 = imageView;
|
||||
|
||||
var that = this;
|
||||
var onClickListener = new android.view.View.OnClickListener({
|
||||
onClick: function(view) {
|
||||
if (that.item2) {
|
||||
appModel.selectedItem = that.item2;
|
||||
var currentActivity = app.android.currentActivity;
|
||||
var intent = new android.content.Intent(currentActivity, com.tns.NativeScriptActivity.class);
|
||||
intent.putExtra("details_activity", 0);
|
||||
currentActivity.startActivity(intent);
|
||||
}
|
||||
}
|
||||
});
|
||||
imageView.setOnClickListener(onClickListener);
|
||||
|
||||
var linearLayoutDetails = new android.widget.LinearLayout(context);
|
||||
linearLayoutDetails.setOrientation(constants.VERTICAL);
|
||||
|
||||
var layoutParams = new android.widget.LinearLayout.LayoutParams(constants.LAYOUT_WRAP_CONTENT, constants.LAYOUT_WRAP_CONTENT);
|
||||
var margin = metrics.toDIP(context, 8);
|
||||
layoutParams.setMargins(margin, margin, margin, margin);
|
||||
linearLayoutDetails.setLayoutParams(layoutParams);
|
||||
linearLayout.addView(linearLayoutDetails);
|
||||
|
||||
var tvHeader = new android.widget.TextView(context);
|
||||
layoutParams = new android.widget.LinearLayout.LayoutParams(constants.LAYOUT_WRAP_CONTENT, constants.LAYOUT_WRAP_CONTENT);
|
||||
tvHeader.setLayoutParams(layoutParams);
|
||||
tvHeader.setTextSize(20);
|
||||
tvHeader.setTextColor(android.graphics.Color.BLACK);
|
||||
|
||||
linearLayoutDetails.addView(tvHeader);
|
||||
|
||||
var tvAuthor = new android.widget.TextView(context);
|
||||
layoutParams = new android.widget.LinearLayout.LayoutParams(constants.LAYOUT_WRAP_CONTENT, constants.LAYOUT_WRAP_CONTENT);
|
||||
tvAuthor.setLayoutParams(layoutParams);
|
||||
tvAuthor.setTextSize(12);
|
||||
|
||||
linearLayoutDetails.addView(tvAuthor);
|
||||
|
||||
this.rootView = linearLayout;
|
||||
this.header = tvHeader;
|
||||
this.author = tvAuthor;
|
||||
this.detailsLayout = linearLayoutDetails;
|
||||
|
||||
this.isWrapLayout = false;
|
||||
};
|
||||
|
||||
function getImageView(context, length, margin) {
|
||||
var imageView = new android.widget.ImageView(context);
|
||||
layoutParams = new android.widget.LinearLayout.LayoutParams(constants.LAYOUT_WRAP_CONTENT, constants.LAYOUT_WRAP_CONTENT);
|
||||
layoutParams.width = length;
|
||||
layoutParams.height = length;
|
||||
layoutParams.setMargins(margin, margin, margin, margin);
|
||||
imageView.setLayoutParams(layoutParams);
|
||||
imageView.setScaleType(android.widget.ImageView.ScaleType.FIT_XY);
|
||||
imageView.setImageBitmap(baseImage.android);
|
||||
|
||||
return imageView;
|
||||
};
|
||||
|
||||
item.prototype.setItem = function(item) {
|
||||
this.header.setText(item.header);
|
||||
|
||||
var text = new android.text.SpannableString("by " + item.author + " | " + item.commentsCount + " comments");
|
||||
var start = 6 + item.author.length;
|
||||
var end = start + (item.commentsCount + ' comments').length;
|
||||
text.setSpan(new android.text.style.ForegroundColorSpan(android.graphics.Color.argb(255, 15, 194, 176)), start, end, android.text.Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
||||
|
||||
this.author.setText(text);
|
||||
};
|
||||
|
||||
item.prototype.updateLayout = function(wrap) {
|
||||
if(this.isWrapLayout === wrap){
|
||||
return;
|
||||
}
|
||||
|
||||
var context = this.rootView.getContext();
|
||||
var length;
|
||||
var margin;
|
||||
if(wrap) {
|
||||
margin = 0;
|
||||
length = context.getResources().getDisplayMetrics().widthPixels / 2;
|
||||
this.detailsLayout.setVisibility(constants.VISIBILITY_GONE);
|
||||
this.image2.setVisibility(constants.VISIBILITY_VISIBLE);
|
||||
}
|
||||
else {
|
||||
margin = 8;
|
||||
length = metrics.toDIP(context, 72);
|
||||
this.detailsLayout.setVisibility(constants.VISIBILITY_VISIBLE);
|
||||
this.image2.setVisibility(constants.VISIBILITY_GONE);
|
||||
}
|
||||
|
||||
margin = metrics.toDIP(context, margin);
|
||||
var layoutParams = this.image.getLayoutParams();
|
||||
layoutParams.width = length;
|
||||
layoutParams.height = length;
|
||||
layoutParams.setMargins(margin, margin, margin, margin);
|
||||
|
||||
this.isWrapLayout = wrap;
|
||||
};
|
||||
|
||||
return item;
|
||||
})();
|
||||
|
||||
exports.item = item;
|
|
@ -1,132 +0,0 @@
|
|||
var appModelModule = require("app_model");
|
||||
var appInstance = appModelModule.appModel.instance;
|
||||
var baseImage = appModelModule.baseImage;
|
||||
|
||||
var adapterBody = {
|
||||
loadMoreItem: {},
|
||||
pendingDownloads: [],
|
||||
isDownloading: false,
|
||||
isScrolling: false,
|
||||
isWrapLayout: false,
|
||||
layoutChanged: false,
|
||||
|
||||
getCount: function () {
|
||||
if(appInstance.itemCount === 0) {
|
||||
appInstance.requestMoreItems();
|
||||
}
|
||||
|
||||
var count = appInstance.itemCount;
|
||||
if(this.isWrapLayout) {
|
||||
return Math.round(count / 2) + 1;
|
||||
}
|
||||
|
||||
return count + 1;
|
||||
},
|
||||
|
||||
getItem: function (position) {
|
||||
var index = this.isWrapLayout ? position * 2 : position;
|
||||
if(index < appInstance.itemCount) {
|
||||
return appInstance.itemAt(index);
|
||||
}
|
||||
|
||||
appInstance.requestMoreItems();
|
||||
return this.loadMoreItem;
|
||||
},
|
||||
|
||||
getView: function (position, convertView, parent) {
|
||||
var item = this.getItem(position);
|
||||
|
||||
if(!item) {
|
||||
return convertView;
|
||||
}
|
||||
|
||||
if(item === this.loadMoreItem) {
|
||||
// item is LoadMore Item
|
||||
if (!this.progressView) {
|
||||
this.progressView = this.getLoadMoreView(parent.getContext());
|
||||
}
|
||||
|
||||
this.progressView.setIndeterminate(true);
|
||||
this.progressView.setVisibility(constants.VISIBILITY_VISIBLE);
|
||||
return this.progressView;
|
||||
}
|
||||
|
||||
var itemLayout;
|
||||
var context = parent.getContext();
|
||||
|
||||
if(!convertView || !convertView.getTag() || !convertView.getTag().item) {
|
||||
var layoutModule = require("item_layout");
|
||||
itemLayout = new layoutModule.item(context);
|
||||
convertView = itemLayout.rootView;
|
||||
|
||||
// we need a java object here, cannot use setTag with a JS object
|
||||
var javaObject = new java.lang.Object();
|
||||
javaObject.item = itemLayout;
|
||||
convertView.setTag(javaObject);
|
||||
}
|
||||
else {
|
||||
itemLayout = convertView.getTag().item;
|
||||
}
|
||||
|
||||
itemLayout.item = item;
|
||||
this.downloadImage(item, itemLayout.image, position);
|
||||
if(this.isWrapLayout) {
|
||||
var nextPosition = (position * 2) + 1;
|
||||
if (nextPosition < appInstance.itemCount) {
|
||||
var item2 = appInstance.itemAt(nextPosition);
|
||||
itemLayout.item2 = item2;
|
||||
this.downloadImage(item2, itemLayout.image2, position);
|
||||
}
|
||||
else {
|
||||
appInstance.requestMoreItems();
|
||||
}
|
||||
}
|
||||
else {
|
||||
itemLayout.setItem(item);
|
||||
}
|
||||
itemLayout.updateLayout(this.isWrapLayout);
|
||||
|
||||
return convertView;
|
||||
},
|
||||
|
||||
downloadImage: function(item, imageControl, position) {
|
||||
var imageUI = imageControl
|
||||
if(!item.bitmap && !item.downloadRequestCompleted) {
|
||||
var that = this;
|
||||
if(!item.callback) {
|
||||
item.callback = function(image) {
|
||||
if (that.isInVisibleRange(position)) {
|
||||
imageUI.setImageBitmap(image.android);
|
||||
}
|
||||
};
|
||||
|
||||
appInstance.downloadThumbnail(item);
|
||||
}
|
||||
}
|
||||
else {
|
||||
imageUI.setImageBitmap(item.bitmap.android);
|
||||
}
|
||||
},
|
||||
|
||||
isInVisibleRange: function(position) {
|
||||
var first = this.view.getFirstVisiblePosition();
|
||||
var last = this.view.getLastVisiblePosition();
|
||||
if(position < first || position > last) {
|
||||
console.log("Out Of View.")
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
getItemId: function (position){
|
||||
return long(position);
|
||||
},
|
||||
|
||||
getLoadMoreView: function(context){
|
||||
var progressBar = new android.widget.ProgressBar(context);
|
||||
return progressBar;
|
||||
}
|
||||
};
|
||||
|
||||
exports.adapterBody = adapterBody;
|
|
@ -0,0 +1,29 @@
|
|||
.title {
|
||||
font-size: 20;
|
||||
margin: 3;
|
||||
}
|
||||
|
||||
.author {
|
||||
font-size: 14;
|
||||
horizontal-align: left;
|
||||
vertical-align: bottom;
|
||||
margin: 3;
|
||||
}
|
||||
|
||||
.comments {
|
||||
color: #10C2B0;
|
||||
font-size: 14;
|
||||
vertical-align: bottom;
|
||||
margin: 3;
|
||||
}
|
||||
|
||||
.thumbnail {
|
||||
width: 72;
|
||||
height: 72;
|
||||
margin: 3;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
TabView {
|
||||
background-color: white;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
var frames = require("ui/frame");
|
||||
var redditAppViewModel = require("./reddit-app-view-model");
|
||||
var appViewModel = new redditAppViewModel.AppViewModel();
|
||||
function pageLoaded(args) {
|
||||
var page = args.object;
|
||||
page.bindingContext = appViewModel;
|
||||
if (frames.topmost().android) {
|
||||
frames.topmost().android.cachePagesOnNavigate = true;
|
||||
}
|
||||
}
|
||||
exports.pageLoaded = pageLoaded;
|
||||
function listViewItemTap(args) {
|
||||
frames.topmost().navigate({
|
||||
moduleName: "app/details-page",
|
||||
context: appViewModel.redditItems.getItem(args.index)
|
||||
});
|
||||
}
|
||||
exports.listViewItemTap = listViewItemTap;
|
||||
function listViewLoadMoreItems(args) {
|
||||
appViewModel.redditItems.length += appViewModel.redditItems.loadSize;
|
||||
}
|
||||
exports.listViewLoadMoreItems = listViewLoadMoreItems;
|
|
@ -0,0 +1,30 @@
|
|||
<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="pageLoaded">
|
||||
<TabView>
|
||||
<TabView.items>
|
||||
<TabEntry title="List">
|
||||
<TabEntry.view>
|
||||
<ListView items="{{ redditItems }}" isScrolling="{{ isScrolling }}" itemTap="listViewItemTap" loadMoreItems="listViewLoadMoreItems">
|
||||
<ListView.itemTemplate>
|
||||
<!-- Binding in template property of an component will use the bindingContext provided by the component. -->
|
||||
<GridLayout columns="auto, *, auto" rows="auto, 25">
|
||||
<Image source="{{ thumbnailImageSource || defaultThumbnailImageSource }}" cssClass="thumbnail" rowSpan="2"/>
|
||||
<Label text="{{ title || 'Downloading...' }}" textWrap="true" cssClass="title" col="1" colSpan="2" minHeight="50" />
|
||||
<Label text="{{ author ? 'by ' + author : '' }}" cssClass="author" col="1" row="1" />
|
||||
<Label text="{{ num_comments ? num_comments + ' comments' : '' }}" cssClass="comments" col="2" row="1" />
|
||||
</GridLayout>
|
||||
<!-- End of tempplate. -->
|
||||
</ListView.itemTemplate>
|
||||
</ListView>
|
||||
</TabEntry.view>
|
||||
</TabEntry>
|
||||
<TabEntry title="About">
|
||||
<TabEntry.view>
|
||||
<StackLayout>
|
||||
<Image margin="10" url="~/app/res/telerik-logo.png" />
|
||||
<Label margin="10" textWrap="true" text="{{ aboutText }}" />
|
||||
</StackLayout>
|
||||
</TabEntry.view>
|
||||
</TabEntry>
|
||||
</TabView.items>
|
||||
</TabView>
|
||||
</Page>
|
|
@ -1,80 +0,0 @@
|
|||
var app = require("application");
|
||||
|
||||
app.onLaunch = function() {
|
||||
var main_activity_module = require("mainPage");
|
||||
return main_activity_module.activity;
|
||||
};
|
||||
|
||||
app.android.getActivity = function (intent){
|
||||
if (intent.hasExtra("about_activity")) {
|
||||
return require("aboutPage").activity;
|
||||
}
|
||||
else if (intent.hasExtra("details_activity")) {
|
||||
return require("detailsPage").activity;
|
||||
}
|
||||
else if (intent.getAction() == android.content.Intent.ACTION_MAIN) {
|
||||
return app.onLaunch();
|
||||
}
|
||||
else {
|
||||
fail("Can't create activity. Unknown action");
|
||||
}
|
||||
}
|
||||
|
||||
constants = {
|
||||
LAYOUT_MATCH_PARENT: android.view.ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
LAYOUT_WRAP_CONTENT: android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
HORIZONTAL: 0,
|
||||
VERTICAL: 1,
|
||||
UNIT_SCALED_PIXEL: 2,
|
||||
VISIBILITY_VISIBLE: 0,
|
||||
VISIBILITY_INVISIBLE: 4,
|
||||
VISIBILITY_GONE: 8,
|
||||
ID_HOME: 16908332,
|
||||
};
|
||||
|
||||
metrics = {
|
||||
toDIP: function(context, num){
|
||||
return android.util.TypedValue.applyDimension(android.util.TypedValue.COMPLEX_UNIT_DIP, num, context.getResources().getDisplayMetrics());
|
||||
}
|
||||
};
|
||||
|
||||
helpers = {
|
||||
setupActionBar: function(actionBar, layout){
|
||||
actionBar.setBackgroundDrawable(new android.graphics.drawable.ColorDrawable(android.graphics.Color.parseColor("#DDDDDD")));
|
||||
actionBar.setDisplayShowHomeEnabled(false);
|
||||
actionBar.setDisplayHomeAsUpEnabled(false);
|
||||
actionBar.setDisplayShowTitleEnabled(false);
|
||||
|
||||
actionBar.setDisplayShowCustomEnabled(true);
|
||||
actionBar.setCustomView(layout);
|
||||
},
|
||||
|
||||
getDrawableId: function(context, name) {
|
||||
return this.getResourceId(context, ":drawable/" + name);
|
||||
},
|
||||
|
||||
getLayoutId: function(context, name){
|
||||
return this.getResourceId(context, ":layout/" + name);
|
||||
},
|
||||
|
||||
getMenuId: function(context, name){
|
||||
return this.getResourceId(context, ":menu/" + name);
|
||||
},
|
||||
|
||||
getStringId: function(context, name){
|
||||
return this.getResourceId(context, ":string/" + name);
|
||||
},
|
||||
|
||||
getId: function(context, name){
|
||||
return this.getResourceId(context, ":id/" + name);
|
||||
},
|
||||
|
||||
getResourceId: function(context, name) {
|
||||
var resources = context.getResources();
|
||||
var packageName = context.getPackageName();
|
||||
var uri = packageName + name;
|
||||
var resId = resources.getIdentifier(uri, null, null);
|
||||
|
||||
return resId;
|
||||
}
|
||||
}
|
|
@ -1,218 +0,0 @@
|
|||
var appModelModule = require("app_model");
|
||||
var appModel = appModelModule.appModel.instance;
|
||||
var baseImage = appModelModule.baseImage;
|
||||
var itemsAdapterModule = require("items_adapter");
|
||||
var drawerListAdapterModule = require("drawer_list_adapter");
|
||||
|
||||
// TODO: We hit a problem saving app state to local settings, check why later
|
||||
// var localSettings = require("local-settings");
|
||||
|
||||
var ListView = android.widget.ListView;
|
||||
var LayoutParams = android.view.ViewGroup.LayoutParams;
|
||||
|
||||
var dataChangedListener = function (adapter) {
|
||||
this.nativeInstance = adapter;
|
||||
this.onItemsChanged = function(collectionChangedArgs) {
|
||||
this.nativeInstance.notifyDataSetChanged();
|
||||
};
|
||||
};
|
||||
|
||||
var baseActivityModule = require("base_activity");
|
||||
var activityBody = new baseActivityModule.activityBody();
|
||||
|
||||
activityBody.drawerToggle = undefined;
|
||||
activityBody.listView = undefined;
|
||||
activityBody.drawerList = undefined;
|
||||
activityBody.drawerLayout = undefined;
|
||||
|
||||
activityBody.onCreateOptionsMenu = function(menu){
|
||||
var inflater = this.getMenuInflater();
|
||||
inflater.inflate(helpers.getMenuId(this, "menu"), menu);
|
||||
|
||||
// cache the Layout action button for later use
|
||||
var id = helpers.getId(this, "action_layout");
|
||||
this.layoutActionButton = menu.findItem(id);
|
||||
|
||||
return this.super.onCreateOptionsMenu(menu);
|
||||
};
|
||||
|
||||
activityBody.setupUI = function() {
|
||||
this.setContentView(helpers.getLayoutId(this, "main_activity"));
|
||||
|
||||
var listView = this.findViewById(helpers.getId(this, "listView"));
|
||||
this.listView = listView;
|
||||
// TODO: See why commented at top of the file
|
||||
// this.userPrefs = userPrefsModule;
|
||||
this.drawerList = this.findViewById(helpers.getId(this, "drawer_list"));
|
||||
|
||||
this.adapterBody = itemsAdapterModule.adapterBody;
|
||||
this.adapterBody.view = listView;
|
||||
var adapter = new android.widget.BaseAdapter.extends(this.adapterBody)();
|
||||
this.adapter = adapter;
|
||||
|
||||
appModel.addChangedListener(new dataChangedListener(adapter));
|
||||
listView.setAdapter(adapter);
|
||||
|
||||
// NOTE: Uncomment to enable hardware acceleration.
|
||||
|
||||
// listView.setScrollingCacheEnabled(true);
|
||||
// listView.setSmoothScrollbarEnabled(true);
|
||||
// var window = this.getWindow();
|
||||
// window.setFlags(android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
|
||||
// android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
|
||||
//
|
||||
// listView.setLayerType(android.view.View.LAYER_TYPE_HARDWARE, null);
|
||||
|
||||
var recyclerListener = new android.widget.AbsListView.RecyclerListener({
|
||||
onMovedToScrapHeap: function(view) {
|
||||
var tag = view.getTag();
|
||||
if (tag !== null) {
|
||||
var itemLayout = tag.item;
|
||||
if (itemLayout.item) {
|
||||
itemLayout.item.callback = null;
|
||||
itemLayout.item = null;
|
||||
}
|
||||
if (itemLayout.image) {
|
||||
itemLayout.image.setImageBitmap(baseImage.android);
|
||||
}
|
||||
|
||||
if (itemLayout.item2) {
|
||||
itemLayout.item2.callback = null;
|
||||
itemLayout.item2 = null;
|
||||
}
|
||||
if (itemLayout.image2) {
|
||||
itemLayout.image2.setImageBitmap(baseImage.android);
|
||||
}
|
||||
}
|
||||
|
||||
if (view.class === android.widget.ProgressBar.class) {
|
||||
view.setIndeterminate(false);
|
||||
view.setVisibility(constants.VISIBILITY_GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
listView.setRecyclerListener(recyclerListener);
|
||||
|
||||
var that = this;
|
||||
var itemClickListener = new android.widget.AdapterView.OnItemClickListener({
|
||||
onItemClick: function(arg0, arg1, arg2, arg3) {
|
||||
if (arg2 < appModel.itemCount) {
|
||||
var item = adapter.getItem(arg2);
|
||||
appModel.selectedItem = item;
|
||||
var intent = new android.content.Intent(that, com.tns.NativeScriptActivity.class);
|
||||
intent.putExtra("details_activity", 0);
|
||||
that.startActivity(intent);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
listView.setOnItemClickListener(itemClickListener);
|
||||
|
||||
this.setupDrawerToggle();
|
||||
this.setupDrawerList();
|
||||
};
|
||||
|
||||
activityBody.onOptionsItemSelected = function(item){
|
||||
var id = item.getItemId();
|
||||
if(id === helpers.getId(this, "action_layout")){
|
||||
this.changeLayout();
|
||||
}
|
||||
else if(id === helpers.getId(this, "action_about")){
|
||||
this.navigateToAbout();
|
||||
}
|
||||
else if(this.drawerToggle.onOptionsItemSelected(item)){
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
activityBody.setupDrawerList = function(){
|
||||
var that = this;
|
||||
var adapter = new android.widget.BaseAdapter.extends(drawerListAdapterModule.adapterBody) ();
|
||||
var itemClickListener = new android.widget.AdapterView.OnItemClickListener({
|
||||
onItemClick: function(arg0, arg1, arg2, arg3){
|
||||
that.drawerLayout.closeDrawer(that.drawerList);
|
||||
|
||||
that.navigateToAbout();
|
||||
},
|
||||
});
|
||||
|
||||
this.drawerList.setAdapter(adapter);
|
||||
this.drawerList.setOnItemClickListener(itemClickListener);
|
||||
};
|
||||
|
||||
activityBody.setupActionBar = function(){
|
||||
var actionBar = this.getActionBar();
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setHomeButtonEnabled(true);
|
||||
};
|
||||
|
||||
activityBody.setupDrawerToggle = function(){
|
||||
this.drawerLayout = this.findViewById(helpers.getId(this, "drawer_layout"));
|
||||
this.drawerToggle = new android.support.v4.app.ActionBarDrawerToggle(
|
||||
this,
|
||||
this.drawerLayout,
|
||||
helpers.getDrawableId(this, "ic_drawer"),
|
||||
helpers.getStringId(this, "action_open_drawer"),
|
||||
helpers.getStringId(this, "action_close_drawer")
|
||||
);
|
||||
this.drawerLayout.setDrawerListener(this.drawerToggle);
|
||||
this.drawerToggle.syncState();
|
||||
};
|
||||
|
||||
activityBody.onStart = function() {
|
||||
this.super.onStart();
|
||||
|
||||
// TODO: See why commented at top of the file
|
||||
// if(this.userPrefs.hasKey("WrapLayout")){
|
||||
// this.wrapLayout = this.userPrefs.getBoolean("WrapLayout");
|
||||
// this.updateLayout();
|
||||
// }
|
||||
|
||||
// if(this.userPrefs.hasKey("ScrollPosY")){
|
||||
// //this.listView.setScrollY(this.userPrefs.getNumber("ScrollPosY"));
|
||||
// }
|
||||
};
|
||||
|
||||
activityBody.onPause = function() {
|
||||
this.super.onPause();
|
||||
|
||||
// TODO: There is an exception here, check why
|
||||
// this.userPrefs.setNumber("ScrollPosY", this.listView.getScrollY());
|
||||
// this.userPrefs.setBoolean("WrapLayout", this.wrapLayout);
|
||||
};
|
||||
|
||||
activityBody.updateLayout = function () {
|
||||
var layoutIconId;
|
||||
if(this.wrapLayout) {
|
||||
this.listView.setDividerHeight(0);
|
||||
layoutIconId = helpers.getDrawableId(this, "list_layout");
|
||||
}
|
||||
else {
|
||||
this.listView.setDividerHeight(1);
|
||||
layoutIconId = helpers.getDrawableId(this, "wrap_layout");
|
||||
}
|
||||
|
||||
if(this.layoutActionButton) {
|
||||
this.layoutActionButton.setIcon(layoutIconId);
|
||||
}
|
||||
this.adapterBody.isWrapLayout = this.wrapLayout;
|
||||
};
|
||||
|
||||
activityBody.changeLayout = function() {
|
||||
this.wrapLayout = !this.wrapLayout;
|
||||
this.adapterBody.layoutChanged = true;
|
||||
|
||||
this.updateLayout();
|
||||
this.adapter.notifyDataSetChanged();
|
||||
};
|
||||
|
||||
activityBody.navigateToAbout = function() {
|
||||
var intent = new android.content.Intent(this, com.tns.NativeScriptActivity.class);
|
||||
intent.putExtra("about_activity", 0);
|
||||
this.startActivity(intent);
|
||||
};
|
||||
|
||||
exports.activity = com.tns.NativeScriptActivity.extends(activityBody);
|
|
@ -1,391 +0,0 @@
|
|||
var CutenessUtils = require("cutenessUtils");
|
||||
var ImageSource = require("image-source").ImageSource;
|
||||
var DetailViewController = require("detailsPage");
|
||||
|
||||
var appModule = require("app_model");
|
||||
var baseImage = appModule.baseImage;
|
||||
var appInstance = appModule.appModel.instance;
|
||||
var CollectionChangedArgs = appModule.CollectionChangedArgs;
|
||||
var CollectionChangedAction = appModule.CollectionChangedAction;
|
||||
|
||||
var imgLogo = new ImageSource();
|
||||
imgLogo.loadFromResource('logo');
|
||||
|
||||
var imgSlide = new ImageSource();
|
||||
imgSlide.loadFromResource('iconSlide');
|
||||
|
||||
var dataChangedListener = function (instance) {
|
||||
this.instance = instance;
|
||||
this.onItemsChanged = function(collectionChangedArgs) {
|
||||
this.instance.onCollectionChanged(collectionChangedArgs);
|
||||
}
|
||||
}
|
||||
|
||||
var PostCell = UIKit.UICollectionViewCell.extends({
|
||||
initWithFrame: function(frame) {
|
||||
this.super.initWithFrame(frame);
|
||||
|
||||
this.backgroundColor = UIKit.UIColor.whiteColor();
|
||||
|
||||
this.imgView = UIKit.UIImageView.initWithFrame(CoreGraphics.CGRectMake(8, 8, 72, 72));
|
||||
this.imgView.contentMode = UIKit.UIViewContentMode.UIViewContentModeScaleAspectFill;
|
||||
|
||||
this.imgView.masksToBounds = true;
|
||||
this.imgView.clipsToBounds = true;
|
||||
|
||||
this.imgView.image = baseImage.ios;
|
||||
this.contentView.addSubview(this.imgView);
|
||||
|
||||
this.label = UIKit.UILabel.initWithFrame(CoreGraphics.CGRectMake(88, 5, frame.size.width - 90, frame.size.height - 20));
|
||||
this.label.font = UIKit.UIFont.fontWithNameSize("HelveticaNeue-Thin", 20); // size must match with sizeLabel in MainViewController
|
||||
this.label.numberOfLines = 0;
|
||||
// this.label.autoresizingMask = UIKit.UIViewAutoresizing.UIViewAutoresizingFlexibleWidth | UIKit.UIViewAutoresizing.UIViewAutoresizingFlexibleHeight;
|
||||
this.contentView.addSubview(this.label);
|
||||
|
||||
this.detailLabel = UIKit.UILabel.initWithFrame(CoreGraphics.CGRectMake(88, frame.size.height - 22, frame.size.width - 90, 16));
|
||||
this.detailLabel.font = UIKit.UIFont.fontWithNameSize("HelveticaNeue-Thin", 12);
|
||||
this.detailLabel.autoresizingMask = UIKit.UIViewAutoresizing.UIViewAutoresizingFlexibleWidth | UIKit.UIViewAutoresizing.UIViewAutoresizingFlexibleTopMargin
|
||||
this.contentView.addSubview(this.detailLabel);
|
||||
|
||||
// cell delimiter
|
||||
this.border = UIKit.UIView.initWithFrame(CoreGraphics.CGRectMake(0, frame.size.height - 1, frame.size.width, 1));
|
||||
this.border.autoresizingMask = UIKit.UIViewAutoresizing.UIViewAutoresizingFlexibleWidth | UIKit.UIViewAutoresizing.UIViewAutoresizingFlexibleTopMargin;
|
||||
this.border.backgroundColor = UIKit.UIColor.lightGrayColor();
|
||||
this.contentView.addSubview(this.border);
|
||||
|
||||
// selected background view
|
||||
var selectedBGView = UIKit.UIView.initWithFrame(this.bounds);
|
||||
selectedBGView.backgroundColor = UIKit.UIColor.colorWithRedGreenBlueAlpha(0.023529, 0.505882, 0.454902, 1);
|
||||
this.selectedBackgroundView = selectedBGView;
|
||||
|
||||
this.layer.shouldRasterize = true;
|
||||
this.layer.rasterizationScale = UIKit.UIScreen.mainScreen().scale;
|
||||
|
||||
this.orientationIsPortrait = this.isPortrait();
|
||||
},
|
||||
|
||||
isPortrait: function () {
|
||||
var orientation = UIKit.UIApplication.sharedApplication().statusBarOrientation;
|
||||
return UIKit.UIInterfaceOrientation.UIInterfaceOrientationPortrait === orientation
|
||||
|| UIKit.UIInterfaceOrientation.UIInterfaceOrientationPortraitUpsideDown === orientation;
|
||||
},
|
||||
|
||||
prepareForReuse: function () {
|
||||
this.super.prepareForReuse();
|
||||
this.imgView.image = baseImage.ios;
|
||||
},
|
||||
|
||||
getImageSize: function () {
|
||||
var size = UIKit.UIScreen.mainScreen().bounds.size;
|
||||
var length = this.isPortrait() ? size.width / 2 : size.height / 3;
|
||||
return CoreGraphics.CGRectMake(0, 0, length, length);
|
||||
},
|
||||
|
||||
updateOrientation: function (isPortrait) {
|
||||
if(this.thumbView) {
|
||||
this.imgView.frame = this.getImageSize();
|
||||
}
|
||||
else {
|
||||
this.label.frame = CoreGraphics.CGRectMake(this.label.frame.origin.x, this.label.frame.origin.y, this.frame.size.width - 90, this.label.font.pointSize);
|
||||
this.label.sizeToFit();
|
||||
}
|
||||
},
|
||||
|
||||
updateView: function (inThumbView) {
|
||||
this.updateVisibility(inThumbView);
|
||||
var imageFrame = inThumbView ? this.getImageSize() : CoreGraphics.CGRectMake(8, 8, 72, 72);
|
||||
if(this.imgView.frame !== imageFrame) {
|
||||
this.imgView.frame = imageFrame;
|
||||
}
|
||||
|
||||
if (!inThumbView) {
|
||||
var size = UIKit.UIScreen.mainScreen().bounds.size;
|
||||
var length = this.isPortrait() ? size.width : size.height;
|
||||
this.label.frame = CoreGraphics.CGRectMake(this.label.frame.origin.x, this.label.frame.origin.y, length - 90, this.label.font.pointSize);
|
||||
this.label.sizeToFit();
|
||||
}
|
||||
},
|
||||
|
||||
updateVisibility: function (inThumbView) {
|
||||
if(this.thumbView !== inThumbView) {
|
||||
this.thumbView = inThumbView;
|
||||
this.label.hidden = inThumbView;
|
||||
this.detailLabel.hidden = inThumbView;
|
||||
this.border.hidden = inThumbView;
|
||||
this.selectedBackgroundView.hidden = inThumbView;
|
||||
}
|
||||
},
|
||||
|
||||
setItem: function (item, inThumbView) {
|
||||
this.label.text = CutenessUtils.decodeHtml(item.header);
|
||||
this.updateView(inThumbView);
|
||||
|
||||
var attributedText = new UIKit.NSMutableAttributedString();
|
||||
attributedText.replaceCharactersInRangeWithString(Foundation.NSMakeRange(0, 0), 'by ' + item.author + ' | ' + item.commentsCount + ' comments');
|
||||
attributedText.addAttributeValueRange('NSColor', UIKit.UIColor.colorWithRedGreenBlueAlpha(0.023529, 0.505882, 0.454902, 1), Foundation.NSMakeRange(6 + item.author.length, (item.commentsCount + ' comments').length));
|
||||
this.detailLabel.attributedText = attributedText;
|
||||
|
||||
var that = this;
|
||||
item.callback = function(image)
|
||||
{
|
||||
that.imgView.image = image.ios;
|
||||
};
|
||||
|
||||
appInstance.downloadThumbnail(item);
|
||||
}
|
||||
});
|
||||
|
||||
var WaitCell = UIKit.UICollectionViewCell.extends({
|
||||
initWithFrame: function(frame) {
|
||||
this.super.initWithFrame(frame);
|
||||
|
||||
this.backgroundColor = UIKit.UIColor.whiteColor();
|
||||
|
||||
this.activity = UIKit.UIActivityIndicatorView.initWithActivityIndicatorStyle(2);
|
||||
this.activity.center = this.contentView.center;
|
||||
this.activity.startAnimating();
|
||||
this.contentView.addSubview(this.activity);
|
||||
},
|
||||
|
||||
layoutSubviews: function() {
|
||||
this.super.layoutSubviews();
|
||||
this.activity.center = this.contentView.center;
|
||||
},
|
||||
|
||||
updateOrientation: function (isPortrait) {
|
||||
},
|
||||
|
||||
updateView: function (inThumbView) {
|
||||
}
|
||||
}, {
|
||||
});
|
||||
|
||||
var MainViewController = UIKit.UICollectionViewController.extends({
|
||||
viewDidLoad: function() {
|
||||
this.super.viewDidLoad();
|
||||
this.thumbView = false;
|
||||
this.imgGrid = new ImageSource();
|
||||
this.imgGrid.loadFromResource('nav-grid');
|
||||
this.imgMenu = new ImageSource();
|
||||
this.imgMenu.loadFromResource('nav-menu');
|
||||
|
||||
var imgView = UIKit.UIImageView.initWithImage(imgLogo.ios);
|
||||
this.navigationItem.titleView = imgView;
|
||||
|
||||
// setting up collection view
|
||||
// using an instance is currently the only way (i know) to get .class
|
||||
this.postCell = new PostCell();
|
||||
this.waitCell = new WaitCell();
|
||||
|
||||
this.collectionView.registerClassForCellWithReuseIdentifier(this.postCell.class(), "Cell");
|
||||
this.collectionView.registerClassForCellWithReuseIdentifier(this.waitCell.class(), "WaitCell");
|
||||
this.collectionView.backgroundColor = UIKit.UIColor.whiteColor();
|
||||
|
||||
// preparing refresh control for our collection view
|
||||
this.refreshControl = new UIKit.UIRefreshControl();
|
||||
this.refreshControl.addTargetActionForControlEvents(this, 'refresh', UIKit.UIControlEvents.UIControlEventValueChanged);
|
||||
this.collectionView.addSubview(this.refreshControl);
|
||||
this.refreshControl.beginRefreshing();
|
||||
|
||||
// mode button to switch collection view layouts
|
||||
this.modeButton = UIKit.UIBarButtonItem.initWithImageStyleTargetAction(this.imgGrid.ios, UIKit.UIBarButtonItemStyle.UIBarButtonItemStylePlain, this, 'toggleLayout');
|
||||
this.navigationItem.rightBarButtonItem = this.modeButton;
|
||||
|
||||
// slide out menu button (hamburger button)
|
||||
var slideOutButton = UIKit.UIBarButtonItem.initWithImageStyleTargetAction(imgSlide.ios, UIKit.UIBarButtonItemStyle.UIBarButtonItemStylePlain, this, 'toggleMenu');
|
||||
this.navigationItem.leftBarButtonItem = slideOutButton;
|
||||
|
||||
// size label is one of the ways to measure size
|
||||
this.sizeLabel = UIKit.UILabel.initWithFrame(CoreGraphics.CGRectMake(0, 0, 300, 200));
|
||||
this.sizeLabel.autoresizingMask = UIKit.UIViewAutoresizing.UIViewAutoresizingFlexibleWidth | UIKit.UIViewAutoresizing.UIViewAutoresizingFlexibleHeight;
|
||||
this.sizeLabel.font = UIKit.UIFont.fontWithNameSize("HelveticaNeue-Thin", 20); // size must match with the size of main label in PostCell
|
||||
this.sizeLabel.numberOfLines = -1;
|
||||
|
||||
this.thumbView = false;
|
||||
this.updateOrientation();
|
||||
appInstance.addChangedListener(new dataChangedListener(this));
|
||||
this.getData();
|
||||
},
|
||||
|
||||
viewDidAppear: function (animated) {
|
||||
this.updateOrientation();
|
||||
var that = this;
|
||||
this.getVisibleCells().forEach(function (cell) {
|
||||
cell.updateView(that.thumbView);
|
||||
cell.updateOrientation(that.orientationIsPortrait);
|
||||
});
|
||||
this.collectionView.performBatchUpdatesCompletion(null, null);
|
||||
},
|
||||
|
||||
updateOrientation: function () {
|
||||
var orientation = UIKit.UIApplication.sharedApplication().statusBarOrientation;
|
||||
this.orientationIsPortrait = UIKit.UIInterfaceOrientation.UIInterfaceOrientationPortrait == orientation
|
||||
|| UIKit.UIInterfaceOrientation.UIInterfaceOrientationPortraitUpsideDown == orientation;
|
||||
},
|
||||
|
||||
didRotateFromInterfaceOrientation: function (fromInterfaceOrientation) {
|
||||
this.updateOrientation();
|
||||
var that = this;
|
||||
this.getVisibleCells().forEach(function (cell) {
|
||||
cell.updateOrientation(that.orientationIsPortrait);
|
||||
});
|
||||
this.collectionView.performBatchUpdatesCompletion(null, null);
|
||||
},
|
||||
|
||||
toggleLayout: function() {
|
||||
this.thumbView = !this.thumbView;
|
||||
this.navigationItem.rightBarButtonItem.image = (this.thumbView ? this.imgMenu.ios : this.imgGrid.ios);
|
||||
var that = this;
|
||||
this.getVisibleCells().forEach(function (cell) {
|
||||
cell.updateView(that.thumbView);
|
||||
});
|
||||
this.collectionView.performBatchUpdatesCompletion(null, null);
|
||||
},
|
||||
|
||||
getVisibleCells: function() {
|
||||
var cells = [];
|
||||
var visibleIndexPaths = this.collectionView.indexPathsForVisibleItems();
|
||||
var count = visibleIndexPaths.count();
|
||||
for(var i = 0; i < count; i++) {
|
||||
var index = visibleIndexPaths.objectAtIndex(i);
|
||||
var cell = this.collectionView.cellForItemAtIndexPath(index);
|
||||
cells.push(cell);
|
||||
}
|
||||
return cells;
|
||||
},
|
||||
|
||||
toggleMenu: function() {
|
||||
this.slideOut.toggleMenu();
|
||||
},
|
||||
|
||||
refresh: function() {
|
||||
this.getData();
|
||||
},
|
||||
|
||||
textHeight: function(text) {
|
||||
this.sizeLabel.text = text;
|
||||
var size = this.sizeLabel.sizeThatFits(CoreGraphics.CGSizeMake(this.view.frame.size.width - 106, 0));
|
||||
if (!size.height) {
|
||||
return 44;
|
||||
}
|
||||
return size.height;
|
||||
},
|
||||
|
||||
onCollectionChanged: function(collectionChangedArgs) {
|
||||
UIKit.UIApplication.sharedApplication().networkActivityIndicatorVisible = false;
|
||||
this.refreshControl.endRefreshing();
|
||||
|
||||
var action = collectionChangedArgs.action;
|
||||
if(action === CollectionChangedAction.Add) {
|
||||
var arrayWithIndexPaths = new Foundation.NSMutableArray();
|
||||
var index = collectionChangedArgs.index;
|
||||
var count = index + collectionChangedArgs.count;
|
||||
while(index < count) {
|
||||
var indexPath = Foundation.NSIndexPath.indexPathForRowInSection(index++, 0);
|
||||
arrayWithIndexPaths.addObject(indexPath);
|
||||
}
|
||||
|
||||
this.collectionView.insertItemsAtIndexPaths(arrayWithIndexPaths);
|
||||
}
|
||||
else if (action === CollectionChangedAction.Reset) {
|
||||
this.collectionView.reloadData();
|
||||
}
|
||||
},
|
||||
|
||||
getData: function() {
|
||||
UIKit.UIApplication.sharedApplication().networkActivityIndicatorVisible = true;
|
||||
appInstance.requestMoreItems();
|
||||
}
|
||||
|
||||
}, {
|
||||
exposedMethods: {
|
||||
'toggleLayout': 'v@:@',
|
||||
'toggleMenu': 'v@:@',
|
||||
'refresh': 'v@:@'
|
||||
}
|
||||
}).implements({
|
||||
|
||||
protocol: "UICollectionViewDataSource",
|
||||
|
||||
implementation: {
|
||||
collectionViewNumberOfItemsInSection: function(collectionView, section) {
|
||||
var length = appInstance.itemCount;
|
||||
if (0 === length) {
|
||||
return 0;
|
||||
}
|
||||
return length + 1;
|
||||
},
|
||||
|
||||
collectionViewCellForItemAtIndexPath: function(collectionView, indexPath) {
|
||||
var cell = null;
|
||||
if (indexPath.row >= appInstance.itemCount) {
|
||||
cell = collectionView.dequeueReusableCellWithReuseIdentifierForIndexPath("WaitCell", indexPath);
|
||||
this.getData();
|
||||
}
|
||||
else {
|
||||
cell = collectionView.dequeueReusableCellWithReuseIdentifierForIndexPath("Cell", indexPath);
|
||||
var item = appInstance.itemAt(indexPath.row);
|
||||
cell.parent = this;
|
||||
cell.setItem(item, this.thumbView);
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
}
|
||||
}
|
||||
).implements({
|
||||
|
||||
protocol: "UICollectionViewDelegateFlowLayout",
|
||||
|
||||
implementation: {
|
||||
|
||||
collectionViewLayoutMinimumLineSpacingForSectionAtIndex: function(collectionView, collectionViewLayout, section) {
|
||||
return 0;
|
||||
},
|
||||
|
||||
collectionViewLayoutMinimumInteritemSpacingForSectionAtIndex: function(collectionView, collectionViewLayout, section) {
|
||||
return 0;
|
||||
},
|
||||
|
||||
collectionViewLayoutInsetForSectionAtIndex: function(collectionView, collectionViewLayout, section) {
|
||||
return UIKit.UIEdgeInsetsMake(0, 0, 0, 0);
|
||||
},
|
||||
|
||||
collectionViewLayoutSizeForItemAtIndexPath: function(collectionView, collectionViewLayout, indexPath) {
|
||||
if (indexPath.row >= appInstance.itemCount) {
|
||||
// this is the wait to reload cell
|
||||
return CoreGraphics.CGSizeMake(collectionView.frame.size.width, 44);
|
||||
}
|
||||
|
||||
if (this.thumbView) {
|
||||
var size = UIKit.UIScreen.mainScreen().bounds.size;
|
||||
var length = this.orientationIsPortrait ? size.width / 2 : size.height / 3;
|
||||
length = Math.floor(length);
|
||||
return CoreGraphics.CGSizeMake(length, length);
|
||||
}
|
||||
|
||||
var item = appInstance.itemAt(indexPath.row);
|
||||
var height = Math.max(this.textHeight(CutenessUtils.decodeHtml(item.header)) + 30, 88);
|
||||
return CoreGraphics.CGSizeMake(collectionView.frame.size.width, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
).implements({
|
||||
|
||||
protocol: "UICollectionViewDelegate",
|
||||
|
||||
implementation: {
|
||||
|
||||
collectionViewDidSelectItemAtIndexPath: function(collectionView, indexPath) {
|
||||
if (indexPath.row < appInstance.itemCount && (!this.slideOut.menuVisible)) {
|
||||
var item = appInstance.itemAt(indexPath.row);
|
||||
var details = new DetailViewController();
|
||||
details.item = item;
|
||||
this.navigationController.pushViewControllerAnimated(details, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = MainViewController;
|
|
@ -1,113 +0,0 @@
|
|||
var ImageSource = require("image-source").ImageSource;
|
||||
var cellIdentifier = "Cell";
|
||||
|
||||
var MenuViewController = UIKit.UITableViewController.extends({
|
||||
viewDidLoad: function() {
|
||||
this.super.viewDidLoad();
|
||||
|
||||
this.cellData = [
|
||||
{
|
||||
name: 'Home'
|
||||
},
|
||||
{
|
||||
name: 'About'
|
||||
}
|
||||
];
|
||||
|
||||
this.selectedRow = 0;
|
||||
|
||||
// setup table view
|
||||
this.tableView.backgroundColor = UIKit.UIColor.colorWithRedGreenBlueAlpha(0.866667, 0.886275, 0.894118, 1);
|
||||
this.tableView.rowHeight = 50;
|
||||
this.tableView.separatorStyle = UIKit.UITableViewCellSeparatorStyle.UITableViewCellSeparatorStyleNone;
|
||||
this.tableView.backgroundView = null; // otherwise background color cannot be seen
|
||||
|
||||
// header view
|
||||
var headerView = UIKit.UIView.initWithFrame(CoreGraphics.CGRectMake(0, 0, this.tableView.frame.size.width, 44));
|
||||
var label = UIKit.UILabel.initWithFrame(CoreGraphics.CGRectMake(60, 0, this.tableView.frame.size.width - 60, 44));
|
||||
label.autoresizingMask = UIKit.UIViewAutoresizing.UIViewAutoresizingFlexibleWidth;
|
||||
label.font = UIKit.UIFont.fontWithNameSize("HelveticaNeue-Thin", 29);
|
||||
label.text = 'Cuteness';
|
||||
headerView.addSubview(label);
|
||||
|
||||
var imageView = UIKit.UIImageView.initWithFrame(CoreGraphics.CGRectMake(24, 6, 28, 31));
|
||||
var image = new ImageSource();
|
||||
image.loadFromResource('logo');
|
||||
imageView.image = image.ios;
|
||||
headerView.addSubview(imageView);
|
||||
|
||||
this.tableView.tableHeaderView = headerView;
|
||||
},
|
||||
|
||||
viewWillAppear: function(animated) {
|
||||
var indexPath = UIKit.NSIndexPath.indexPathForRowInSection(this.selectedRow, 0);
|
||||
this.tableView.selectRowAtIndexPathAnimatedScrollPosition(indexPath, false, UIKit.UITableViewScrollPosition.UITableViewScrollPositionNone);
|
||||
},
|
||||
|
||||
setViewControllers: function(viewControllers) {
|
||||
this.viewControllers = viewControllers;
|
||||
}
|
||||
|
||||
}, {
|
||||
}).implements({
|
||||
|
||||
protocol: "UITableViewDataSource",
|
||||
|
||||
implementation: {
|
||||
tableViewNumberOfRowsInSection: function(tableView, section) {
|
||||
return 2;
|
||||
},
|
||||
|
||||
tableViewCellForRowAtIndexPath: function(tableView, indexPath) {
|
||||
var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier);
|
||||
|
||||
if (!cell) {
|
||||
// setup new cell
|
||||
cell = UIKit.UITableViewCell.initWithStyleReuseIdentifier(UIKit.UITableViewCellStyle.UITableViewCellStyleDefault, cellIdentifier);
|
||||
|
||||
var lineView = UIKit.UIView.initWithFrame(CoreGraphics.CGRectMake(8, 49, 256 - 8, 1));
|
||||
lineView.backgroundColor = UIKit.UIColor.colorWithRedGreenBlueAlpha(0.752941, 0.784314, 0.800000, 1);
|
||||
cell.contentView.addSubview(lineView);
|
||||
|
||||
var bgView = new UIKit.UIView();
|
||||
bgView.backgroundColor = UIKit.UIColor.colorWithRedGreenBlueAlpha(0.866667, 0.886275, 0.894118, 1);
|
||||
cell.backgroundView = bgView;
|
||||
|
||||
var selectedBGView = new UIKit.UIView();
|
||||
selectedBGView.backgroundColor = UIKit.UIColor.colorWithRedGreenBlueAlpha(16/255, 196/255, 178/255, 1);
|
||||
cell.selectedBackgroundView = selectedBGView;
|
||||
|
||||
cell.textLabel.font = UIKit.UIFont.fontWithNameSize("HelveticaNeue-Thin", 17);
|
||||
|
||||
cell.indentationWidth = 8;
|
||||
cell.indentationLevel = 1;
|
||||
}
|
||||
|
||||
cell.textLabel.text = this.cellData[indexPath.row].name;
|
||||
|
||||
if (indexPath.row === this.selectedRow) {
|
||||
tableView.selectRowAtIndexPathAnimatedScrollPosition(indexPath, false, UIKit.UITableViewScrollPosition.UITableViewScrollPositionNone);
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
}
|
||||
}
|
||||
).implements({
|
||||
|
||||
protocol: "UITableViewDelegate",
|
||||
|
||||
implementation: {
|
||||
tableViewDidSelectRowAtIndexPath: function(tableView, indexPath) {
|
||||
if (this.selectedRow !== indexPath.row) {
|
||||
this.selectedRow = indexPath.row;
|
||||
|
||||
this.slideOut.changeMain(this.viewControllers[this.selectedRow]);
|
||||
this.slideOut.toggleMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = MenuViewController;
|
|
@ -1,145 +0,0 @@
|
|||
var model = (function(){
|
||||
|
||||
function model(header, imageUrl) {
|
||||
this._header = header;
|
||||
this._imageUrl = imageUrl;
|
||||
}
|
||||
|
||||
Object.defineProperty(model.prototype, "header", {
|
||||
get: function () {
|
||||
return this._header;
|
||||
},
|
||||
set: function(value) {
|
||||
this._header = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(model.prototype, "imageUrl", {
|
||||
get: function () {
|
||||
return this._imageUrl;
|
||||
},
|
||||
set: function(value) {
|
||||
this._imageUrl = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(model.prototype, "bitmap", {
|
||||
get: function () {
|
||||
return this._bitmap;
|
||||
},
|
||||
set: function(value) {
|
||||
this._bitmap = value;
|
||||
this._downloadingImage = false;
|
||||
this._downloadCompleted = true;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(model.prototype, "author", {
|
||||
get: function () {
|
||||
return this._author;
|
||||
},
|
||||
set: function(value) {
|
||||
this._author = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(model.prototype, "score", {
|
||||
get: function () {
|
||||
return this._score;
|
||||
},
|
||||
set: function(value) {
|
||||
this._score = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(model.prototype, "created", {
|
||||
get: function () {
|
||||
return this._created;
|
||||
},
|
||||
set: function(value) {
|
||||
this._created = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(model.prototype, "fullName", {
|
||||
get: function () {
|
||||
return this._fullName;
|
||||
},
|
||||
set: function(value) {
|
||||
this._fullName = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(model.prototype, "largeImageUrl", {
|
||||
get: function () {
|
||||
return this._largeImageUrl;
|
||||
},
|
||||
set: function(value) {
|
||||
this._largeImageUrl = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(model.prototype, "commentsCount", {
|
||||
get: function () {
|
||||
return this._commentsCount;
|
||||
},
|
||||
set: function(value) {
|
||||
this._commentsCount = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(model.prototype, "commentsUrl", {
|
||||
get: function () {
|
||||
return this._commentsUrl;
|
||||
},
|
||||
set: function(value) {
|
||||
this._commentsUrl = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(model.prototype, "downloadingImage", {
|
||||
get: function () {
|
||||
return this._downloadingImage;
|
||||
},
|
||||
set: function(value) {
|
||||
this._downloadingImage = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(model.prototype, "downloadRequestCompleted", {
|
||||
get: function () {
|
||||
return this._downloadCompleted;
|
||||
},
|
||||
set: function(value) {
|
||||
this._downloadCompleted = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
return model;
|
||||
})();
|
||||
|
||||
exports.model = model;
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "tns-samples-cuteness.io",
|
||||
"main": "app.js",
|
||||
"version": "0.9.0",
|
||||
"description": "Nativescript cuteness.io sample application"
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
var imageSource = require("image-source");
|
||||
var virtualArray = require("data/virtual-array");
|
||||
var http = require("http");
|
||||
var observable = require("data/observable");
|
||||
var imageCache = require("ui/image-cache");
|
||||
var redditViewModel = require("./reddit-item-view-model");
|
||||
var aboutText = "Cuteness is a proof of concept app demonstrating the Telerik's NativeScript for writing native mobile applications using JavaScript.";
|
||||
exports.defaultThumbnailImageSource = imageSource.fromFile("~/app/res/reddit-logo.png");
|
||||
exports.defaultNoThumbnailImageSource = imageSource.fromFile("~/app/res/no-image.png");
|
||||
var redditUrl = "http://www.reddit.com/r/aww.json?limit=";
|
||||
var after;
|
||||
var ISSCROLLING = "isLoading";
|
||||
exports.cache = new imageCache.Cache();
|
||||
exports.cache.invalid = exports.defaultNoThumbnailImageSource;
|
||||
exports.cache.placeholder = exports.defaultThumbnailImageSource;
|
||||
exports.cache.maxRequests = 5;
|
||||
var AppViewModel = (function (_super) {
|
||||
__extends(AppViewModel, _super);
|
||||
function AppViewModel() {
|
||||
_super.apply(this, arguments);
|
||||
this._isScrolling = false;
|
||||
}
|
||||
Object.defineProperty(AppViewModel.prototype, "redditItems", {
|
||||
get: function () {
|
||||
var _this = this;
|
||||
if (!this._redditItems) {
|
||||
this._redditItems = new virtualArray.VirtualArray(1000);
|
||||
this._redditItems.loadSize = 50;
|
||||
this._redditItems.on(virtualArray.knownEvents.itemsLoading, function (args) {
|
||||
http.getJSON(redditUrl + args.count + (after ? "&after=" + after : "")).then(function (result) {
|
||||
var itemsToLoad = result.data.children.map(function (i) {
|
||||
return new redditViewModel.RedditViewModel(i.data);
|
||||
});
|
||||
_this._redditItems.load(args.index, itemsToLoad);
|
||||
var lastItem = itemsToLoad[itemsToLoad.length - 1];
|
||||
if (lastItem) {
|
||||
after = itemsToLoad[itemsToLoad.length - 1].source.name;
|
||||
}
|
||||
}, function (e) {
|
||||
console.log(e.message);
|
||||
}).catch(function (e) {
|
||||
setTimeout(function () {
|
||||
throw e;
|
||||
});
|
||||
});
|
||||
;
|
||||
});
|
||||
}
|
||||
return this._redditItems;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(AppViewModel.prototype, "isScrolling", {
|
||||
get: function () {
|
||||
return this._isScrolling;
|
||||
},
|
||||
set: function (value) {
|
||||
if (this._isScrolling !== value) {
|
||||
this._isScrolling = value;
|
||||
if (value) {
|
||||
exports.cache.disableDownload();
|
||||
}
|
||||
else {
|
||||
exports.cache.enableDownload();
|
||||
}
|
||||
this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: ISSCROLLING, value: value });
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(AppViewModel.prototype, "aboutText", {
|
||||
get: function () {
|
||||
return aboutText;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(AppViewModel.prototype, "defaultThumbnailImageSource", {
|
||||
get: function () {
|
||||
return exports.defaultThumbnailImageSource;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(AppViewModel.prototype, "defaultNoThumbnailImageSource", {
|
||||
get: function () {
|
||||
return exports.defaultNoThumbnailImageSource;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return AppViewModel;
|
||||
})(observable.Observable);
|
||||
exports.AppViewModel = AppViewModel;
|
|
@ -0,0 +1,108 @@
|
|||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
var observable = require("data/observable");
|
||||
var imageSource = require("image-source");
|
||||
var redditAppViewModel = require("./reddit-app-view-model");
|
||||
var firstThumbnailImageSource = imageSource.fromFile("~/app/res/first-image.png");
|
||||
var defaultImageSource = imageSource.fromFile("~/app/res/reddit-logo-transparent.png");
|
||||
var ISLOADING = "isLoading";
|
||||
var THUMBNAIL_IMAGE_SOURCE = "thumbnailImageSource";
|
||||
var IMAGE_SOURCE = "imageSource";
|
||||
var RedditViewModel = (function (_super) {
|
||||
__extends(RedditViewModel, _super);
|
||||
function RedditViewModel(source) {
|
||||
_super.call(this);
|
||||
this._isLoading = false;
|
||||
this._source = source;
|
||||
if (this._source) {
|
||||
var property;
|
||||
for (property in this._source) {
|
||||
this.set(property, this._source[property]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Object.defineProperty(RedditViewModel.prototype, "source", {
|
||||
get: function () {
|
||||
return this._source;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(RedditViewModel.prototype, "isLoading", {
|
||||
get: function () {
|
||||
return this._isLoading;
|
||||
},
|
||||
set: function (value) {
|
||||
if (this._isLoading !== value) {
|
||||
this._isLoading = value;
|
||||
this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: ISLOADING, value: value });
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(RedditViewModel.prototype, "thumbnailImageSource", {
|
||||
get: function () {
|
||||
var _this = this;
|
||||
if (this._source) {
|
||||
if (this._source.title === "reddit 101") {
|
||||
this._thumbnailImageSource = firstThumbnailImageSource;
|
||||
}
|
||||
else if (redditAppViewModel.cache) {
|
||||
var url = this._source.thumbnail;
|
||||
var imgSource = redditAppViewModel.cache.get(url);
|
||||
if (imgSource) {
|
||||
this._thumbnailImageSource = imgSource;
|
||||
}
|
||||
else if (_isValidImageUrl(url)) {
|
||||
this.isLoading = true;
|
||||
redditAppViewModel.cache.push({
|
||||
key: url,
|
||||
url: url,
|
||||
completed: function (result, key) {
|
||||
if (url === key) {
|
||||
_this.isLoading = false;
|
||||
_this._thumbnailImageSource = result;
|
||||
_this.notify({ object: _this, eventName: observable.knownEvents.propertyChange, propertyName: THUMBNAIL_IMAGE_SOURCE, value: result });
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
this._thumbnailImageSource = redditAppViewModel.defaultNoThumbnailImageSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
return this._thumbnailImageSource || redditAppViewModel.defaultThumbnailImageSource;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(RedditViewModel.prototype, "imageSource", {
|
||||
get: function () {
|
||||
var _this = this;
|
||||
if (this._source) {
|
||||
var url = this._source.url;
|
||||
if (_isValidImageUrl(url)) {
|
||||
this.isLoading = true;
|
||||
imageSource.fromUrl(url).then(function (result) {
|
||||
_this.isLoading = false;
|
||||
_this.notify({ object: _this, eventName: observable.knownEvents.propertyChange, propertyName: IMAGE_SOURCE, value: result });
|
||||
});
|
||||
}
|
||||
}
|
||||
return defaultImageSource;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return RedditViewModel;
|
||||
})(observable.Observable);
|
||||
exports.RedditViewModel = RedditViewModel;
|
||||
function _isValidImageUrl(url) {
|
||||
return url && (url.indexOf(".png") !== -1 || url.indexOf(".jpg") !== -1);
|
||||
}
|
После Ширина: | Высота: | Размер: 990 B |
После Ширина: | Высота: | Размер: 2.1 KiB |
После Ширина: | Высота: | Размер: 30 KiB |
После Ширина: | Высота: | Размер: 26 KiB |
После Ширина: | Высота: | Размер: 42 KiB |
|
@ -1,168 +0,0 @@
|
|||
var MENU_WIDTH = 256;
|
||||
|
||||
var SlideOutViewController = UIKit.UIViewController.extends({
|
||||
|
||||
setup: function(menuVC, mainVC) {
|
||||
this.menuVC = menuVC;
|
||||
this.mainVC = mainVC;
|
||||
|
||||
menuVC.setValueForKey(this, 'parentViewController');
|
||||
mainVC.setValueForKey(this, 'parentViewController');
|
||||
|
||||
this.addChildViewController(this.menuVC);
|
||||
this.menuVC.didMoveToParentViewController(this);
|
||||
|
||||
this.addChildViewController(this.mainVC);
|
||||
this.mainVC.didMoveToParentViewController(this);
|
||||
},
|
||||
|
||||
toggleMenu: function() {
|
||||
this.showMenu(!this.menuVisible);
|
||||
},
|
||||
|
||||
viewDidLoad: function() {
|
||||
this.super.viewDidLoad();
|
||||
this.view.autoresizingMask = UIKit.UIViewAutoresizing.UIViewAutoresizingFlexibleWidth | UIKit.UIViewAutoresizing.UIViewAutoresizingFlexibleHeight;
|
||||
},
|
||||
|
||||
viewDidUnload: function() {
|
||||
this.super.viewDidUnload();
|
||||
|
||||
if (this.menuVC) {
|
||||
this.menuVC.parentViewController = null;
|
||||
this.menuVC = null;
|
||||
}
|
||||
|
||||
if (this.mainVC) {
|
||||
this.mainVC.parentViewController = null;
|
||||
this.mainVC = null;
|
||||
}
|
||||
|
||||
this.menuView = null;
|
||||
this.mainView = null;
|
||||
},
|
||||
|
||||
loadView: function() {
|
||||
this.super.loadView();
|
||||
|
||||
this.menuView = UIKit.UIView.initWithFrame(CoreGraphics.CGRectMake(0, 0, MENU_WIDTH, this.view.frame.size.height));
|
||||
this.menuView.autoresizingMask = UIKit.UIViewAutoresizing.UIViewAutoresizingFlexibleWidth | UIKit.UIViewAutoresizing.UIViewAutoresizingFlexibleHeight;
|
||||
|
||||
this.menuVC.viewWillAppear(false);
|
||||
this.menuView.addSubview(this.menuVC.view);
|
||||
this.menuVC.viewDidAppear(false);
|
||||
|
||||
this.mainView = UIKit.UIView.initWithFrame(CoreGraphics.CGRectMake(0, 0, this.view.frame.size.width, this.view.frame.size.height));
|
||||
this.mainView.autoresizingMask = UIKit.UIViewAutoresizing.UIViewAutoresizingFlexibleWidth | UIKit.UIViewAutoresizing.UIViewAutoresizingFlexibleHeight;
|
||||
|
||||
this.mainVC.viewWillAppear(false);
|
||||
this.mainView.addSubview(this.mainVC.view);
|
||||
this.mainVC.viewDidAppear(false);
|
||||
|
||||
this.mainView.layer.shadowOffset = CoreGraphics.CGSizeMake(-1, -1);
|
||||
this.mainView.layer.shadowRadius = 5;
|
||||
this.mainView.layer.shadowOpacity = 0.5;
|
||||
this.mainView.layer.shadowColor = UIKit.UIColor.blackColor().CGColor;
|
||||
this.mainView.layer.shadowPath = UIKit.UIBezierPath.bezierPathWithRect(this.mainView.bounds).CGPath;
|
||||
|
||||
var masterFrame = this.menuVC.view.frame;
|
||||
masterFrame.size.width = MENU_WIDTH;
|
||||
this.menuVC.view.frame = masterFrame;
|
||||
|
||||
this.view.addSubview(this.menuView);
|
||||
this.view.addSubview(this.mainView);
|
||||
|
||||
var swipe = UIKit.UISwipeGestureRecognizer.initWithTargetAction(this, 'performSwipe');
|
||||
swipe.numberOfTouchesRequired = 1;
|
||||
swipe.direction = UIKit.UISwipeGestureRecognizerDirection.UISwipeGestureRecognizerDirectionRight;
|
||||
this.mainView.addGestureRecognizer(swipe);
|
||||
|
||||
swipe = UIKit.UISwipeGestureRecognizer.initWithTargetAction(this, 'performSwipe');
|
||||
swipe.numberOfTouchesRequired = 1;
|
||||
swipe.direction = UIKit.UISwipeGestureRecognizerDirection.UISwipeGestureRecognizerDirectionLeft;
|
||||
this.mainView.addGestureRecognizer(swipe);
|
||||
|
||||
swipe = UIKit.UISwipeGestureRecognizer.initWithTargetAction(this, 'performSwipe');
|
||||
swipe.numberOfTouchesRequired = 1;
|
||||
swipe.direction = UIKit.UISwipeGestureRecognizerDirection.UISwipeGestureRecognizerDirectionLeft;
|
||||
this.menuVC.view.addGestureRecognizer(swipe);
|
||||
|
||||
this.menuVisible = false;
|
||||
},
|
||||
|
||||
didRotateFromInterfaceOrientation: function (fromInterfaceOrientation) {
|
||||
this.mainVC.didRotateFromInterfaceOrientation(fromInterfaceOrientation);
|
||||
},
|
||||
|
||||
performSwipe: function(swipe) {
|
||||
var direction = swipe.direction;
|
||||
if (UIKit.UISwipeGestureRecognizerDirection.UISwipeGestureRecognizerDirectionLeft == direction && this.menuVisible) {
|
||||
this.showMenu(false);
|
||||
}
|
||||
else if (UIKit.UISwipeGestureRecognizerDirection.UISwipeGestureRecognizerDirectionRight == direction && !this.menuVisible) {
|
||||
this.showMenu(true);
|
||||
}
|
||||
},
|
||||
|
||||
showMenu: function(show) {
|
||||
if (this.menuVisible)
|
||||
this.menuVC.viewWillDisappear(true);
|
||||
else
|
||||
this.menuVC.viewWillAppear(true);
|
||||
|
||||
var frame = this.mainView.frame;
|
||||
|
||||
if (show)
|
||||
frame.origin.x = this.view.frame.size.width - (this.view.frame.size.width - MENU_WIDTH);
|
||||
else
|
||||
frame.origin.x = 0;
|
||||
|
||||
UIKit.UIView.beginAnimationsContext("master", null);
|
||||
UIKit.UIView.setAnimationCurve(UIKit.UIViewAnimationCurve.UIViewAnimationCurveEaseIn);
|
||||
UIKit.UIView.setAnimationDuration(0.2);
|
||||
UIKit.UIView.setAnimationDelegate(this);
|
||||
UIKit.UIView.setAnimationDidStopSelector('masterDidAnimate');
|
||||
|
||||
this.mainView.frame = frame;
|
||||
if (!show) {
|
||||
this.mainVC.view.frame = frame;
|
||||
}
|
||||
|
||||
UIKit.UIView.commitAnimations();
|
||||
|
||||
this.menuVisible = show;
|
||||
},
|
||||
|
||||
masterDidAnimate: function(sender) {
|
||||
if (this.menuVisible) {
|
||||
this.menuVC.viewDidAppear(true);
|
||||
}
|
||||
else {
|
||||
this.menuVC.viewDidDisappear(true);
|
||||
}
|
||||
},
|
||||
|
||||
changeMain: function(mainVC) {
|
||||
if (this.mainVC) {
|
||||
this.mainVC.viewWillDisappear(false);
|
||||
this.mainVC.view.removeFromSuperview();
|
||||
this.mainVC.viewDidDisappear(false);
|
||||
}
|
||||
|
||||
this.mainVC = mainVC;
|
||||
|
||||
this.mainVC.viewWillAppear(false);
|
||||
this.mainView.addSubview(this.mainVC.view);
|
||||
this.mainVC.viewDidAppear(false);
|
||||
|
||||
this.addChildViewController(this.mainVC);
|
||||
this.mainVC.didMoveToParentViewController(this);
|
||||
}
|
||||
}, {
|
||||
exposedMethods: {
|
||||
'performSwipe': 'v@:@',
|
||||
'masterDidAnimate': 'v@:@'
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = SlideOutViewController;
|
|
@ -1,16 +1,29 @@
|
|||
require("globals");
|
||||
|
||||
require("globals");
|
||||
var definition = require("application");
|
||||
var cssParser = require("js-libs/reworkcss");
|
||||
var fs = require("file-system");
|
||||
var fileSystemAccess = require("file-system/file-system-access");
|
||||
var styleScope = require("ui/styling/style-scope");
|
||||
exports.cssFile = "app/app.css";
|
||||
exports.onUncaughtError = undefined;
|
||||
exports.onLaunch = undefined;
|
||||
|
||||
exports.onSuspend = undefined;
|
||||
|
||||
exports.onResume = undefined;
|
||||
|
||||
exports.onExit = undefined;
|
||||
|
||||
exports.onLowMemory = undefined;
|
||||
|
||||
exports.android = undefined;
|
||||
|
||||
exports.ios = undefined;
|
||||
//# sourceMappingURL=application-common.js.map
|
||||
function loadCss() {
|
||||
if (definition.cssFile) {
|
||||
var cssFileName = fs.path.join(fs.knownFolders.currentApp().path, definition.cssFile);
|
||||
var applicationCss;
|
||||
if (fs.File.exists(cssFileName)) {
|
||||
new fileSystemAccess.FileSystemAccess().readText(cssFileName, function (r) {
|
||||
applicationCss = r;
|
||||
});
|
||||
var applicationCssSyntaxTree = cssParser.parse(applicationCss, undefined);
|
||||
definition.cssSelectorsCache = styleScope.StyleScope.createSelectorsFromSyntaxTree(applicationCssSyntaxTree);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.loadCss = loadCss;
|
||||
|
|
|
@ -1,57 +1,55 @@
|
|||
var appModule = require("application/application-common");
|
||||
|
||||
var appModule = require("application/application-common");
|
||||
var dts = require("application");
|
||||
var frame = require("ui/frame");
|
||||
var types = require("utils/types");
|
||||
require("utils/module-merge").merge(appModule, exports);
|
||||
|
||||
var callbacks = android.app.Application.ActivityLifecycleCallbacks;
|
||||
|
||||
exports.mainModule;
|
||||
var initEvents = function () {
|
||||
var androidApp = exports.android;
|
||||
|
||||
var lifecycleCallbacks = new callbacks({
|
||||
onActivityCreated: function (activity, bundle) {
|
||||
if (!androidApp.startActivity) {
|
||||
androidApp.startActivity = activity;
|
||||
|
||||
if (androidApp.onActivityCreated) {
|
||||
androidApp.onActivityCreated(activity, bundle);
|
||||
}
|
||||
}
|
||||
androidApp.currentContext = activity;
|
||||
},
|
||||
onActivityDestroyed: function (activity) {
|
||||
if (activity === androidApp.currentActivity) {
|
||||
androidApp.currentActivity = undefined;
|
||||
if (activity === androidApp.foregroundActivity) {
|
||||
androidApp.foregroundActivity = undefined;
|
||||
}
|
||||
if (activity === androidApp.currentContext) {
|
||||
androidApp.currentContext = undefined;
|
||||
}
|
||||
|
||||
if (activity === androidApp.startActivity) {
|
||||
if (exports.onExit) {
|
||||
exports.onExit();
|
||||
}
|
||||
}
|
||||
|
||||
if (androidApp.onActivityDestroyed) {
|
||||
androidApp.onActivityDestroyed(activity);
|
||||
}
|
||||
|
||||
gc();
|
||||
},
|
||||
onActivityPaused: function (activity) {
|
||||
if (activity === androidApp.currentActivity) {
|
||||
if (activity === androidApp.foregroundActivity) {
|
||||
if (exports.onSuspend) {
|
||||
exports.onSuspend();
|
||||
}
|
||||
}
|
||||
|
||||
if (androidApp.onActivityPaused) {
|
||||
androidApp.onActivityPaused(activity);
|
||||
}
|
||||
},
|
||||
onActivityResumed: function (activity) {
|
||||
if (activity === androidApp.currentActivity) {
|
||||
if (activity === androidApp.foregroundActivity) {
|
||||
if (exports.onResume) {
|
||||
exports.onResume();
|
||||
}
|
||||
}
|
||||
|
||||
if (androidApp.onActivityResumed) {
|
||||
androidApp.onActivityResumed(activity);
|
||||
}
|
||||
|
@ -62,8 +60,7 @@ var initEvents = function () {
|
|||
}
|
||||
},
|
||||
onActivityStarted: function (activity) {
|
||||
androidApp.currentActivity = activity;
|
||||
|
||||
androidApp.foregroundActivity = activity;
|
||||
if (androidApp.onActivityStarted) {
|
||||
androidApp.onActivityStarted(activity);
|
||||
}
|
||||
|
@ -74,29 +71,42 @@ var initEvents = function () {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
return lifecycleCallbacks;
|
||||
};
|
||||
|
||||
var initialized;
|
||||
exports.init = function (nativeApp) {
|
||||
if (initialized) {
|
||||
return;
|
||||
app.init({
|
||||
getActivity: function (intent) {
|
||||
return exports.android.getActivity(intent);
|
||||
},
|
||||
onCreate: function () {
|
||||
var androidApp = new AndroidApplication(this);
|
||||
exports.android = androidApp;
|
||||
androidApp.init();
|
||||
}
|
||||
|
||||
var app = new AndroidApplication(nativeApp);
|
||||
exports.android = app;
|
||||
app.init();
|
||||
|
||||
initialized = true;
|
||||
};
|
||||
|
||||
});
|
||||
var AndroidApplication = (function () {
|
||||
function AndroidApplication(nativeApp) {
|
||||
this.nativeApp = nativeApp;
|
||||
this.packageName = nativeApp.getPackageName();
|
||||
this.context = nativeApp.getApplicationContext();
|
||||
}
|
||||
AndroidApplication.prototype.getActivity = function (intent) {
|
||||
if (intent && intent.Action === android.content.Intent.ACTION_MAIN) {
|
||||
if (exports.onLaunch) {
|
||||
exports.onLaunch(intent);
|
||||
}
|
||||
}
|
||||
var topFrame = frame.topmost();
|
||||
if (!topFrame) {
|
||||
if (exports.mainModule) {
|
||||
topFrame = new frame.Frame();
|
||||
topFrame.navigate(exports.mainModule);
|
||||
}
|
||||
else {
|
||||
throw new Error("A Frame must be used to navigate to a Page.");
|
||||
}
|
||||
}
|
||||
return topFrame.android.onActivityRequested(intent);
|
||||
};
|
||||
AndroidApplication.prototype.init = function () {
|
||||
this._eventsToken = initEvents();
|
||||
this.nativeApp.registerActivityLifecycleCallbacks(this._eventsToken);
|
||||
|
@ -104,4 +114,17 @@ var AndroidApplication = (function () {
|
|||
};
|
||||
return AndroidApplication;
|
||||
})();
|
||||
//# sourceMappingURL=application.android.js.map
|
||||
global.__onUncaughtError = function (error) {
|
||||
if (!types.isFunction(exports.onUncaughtError)) {
|
||||
return;
|
||||
}
|
||||
var nsError = {
|
||||
message: error.message,
|
||||
name: error.name,
|
||||
nativeError: error.nativeException
|
||||
};
|
||||
exports.onUncaughtError(nsError);
|
||||
};
|
||||
exports.start = function () {
|
||||
dts.loadCss();
|
||||
};
|
||||
|
|
|
@ -1,135 +0,0 @@
|
|||
|
||||
declare module "application" {
|
||||
|
||||
/**
|
||||
* The main entry point event. This method is expected to return an instance of the root UI for the application.
|
||||
* This will be an Activity extends for Android and a RootViewController for iOS.
|
||||
*/
|
||||
export function onLaunch(): any;
|
||||
|
||||
/**
|
||||
* This method will be called when the Application is suspended.
|
||||
*/
|
||||
export function onSuspend();
|
||||
|
||||
/**
|
||||
* This method will be called when the Application is resumed after it has been suspended.
|
||||
*/
|
||||
export function onResume();
|
||||
|
||||
/**
|
||||
* This method will be called when the Application is about to exit.
|
||||
*/
|
||||
export function onExit();
|
||||
|
||||
/**
|
||||
* This method will be called when there is low memory on the target device.
|
||||
*/
|
||||
export function onLowMemory();
|
||||
|
||||
/**
|
||||
* This is the Android-specific application object instance.
|
||||
* Encapsulates methods and properties specific to the Android platform.
|
||||
* Will be undefined when TargetOS is iOS.
|
||||
*/
|
||||
export var android: AndroidApplication;
|
||||
|
||||
/**
|
||||
* This is the iOS-specific application object instance.
|
||||
* Encapsulates methods and properties specific to the iOS platform.
|
||||
* Will be undefined when TargetOS is Android.
|
||||
*/
|
||||
export var ios: iOSApplication;
|
||||
|
||||
/**
|
||||
* Entry point for the module. Initializes the Application singleton and hooks application lifecycle events.
|
||||
* @param nativeApp The instance of the platform Application object - e.g. android.app.Application
|
||||
*/
|
||||
export function init(nativeApp: any);
|
||||
|
||||
/**
|
||||
* The abstraction of an Android-specific application object.
|
||||
*/
|
||||
interface AndroidApplication {
|
||||
/**
|
||||
* The android.app.Application object instance provided to the init of the module.
|
||||
*/
|
||||
nativeApp: android.app.Application;
|
||||
|
||||
/**
|
||||
* The application android.content.Context object instance.
|
||||
*/
|
||||
context: android.content.Context;
|
||||
|
||||
/**
|
||||
* The currently active (loaded) android.app.Activity. This property is automatically updated upon Activity events.
|
||||
*/
|
||||
currentActivity: android.app.Activity;
|
||||
|
||||
/**
|
||||
* The main (start) Activity for the application.
|
||||
*/
|
||||
startActivity: android.app.Activity;
|
||||
|
||||
/**
|
||||
* The name of the application package.
|
||||
*/
|
||||
packageName: string;
|
||||
|
||||
/**
|
||||
* This method is called by the JavaScript Bridge when navigation to a new activity is triggered.
|
||||
* The return value of this method should be com.tns.NativeScriptActivity.extends implementation.
|
||||
*/
|
||||
getActivity: (intent: android.content.Intent) => any;
|
||||
|
||||
/**
|
||||
* Direct handler of the android.app.Application.ActivityLifecycleCallbacks.onActivityCreated method.
|
||||
*/
|
||||
onActivityCreated: (activity: android.app.Activity, bundle: android.os.Bundle) => void;
|
||||
|
||||
/**
|
||||
* Direct handler of the android.app.Application.ActivityLifecycleCallbacks.onActivityDestroyed method.
|
||||
*/
|
||||
onActivityDestroyed: (activity: android.app.Activity) => void;
|
||||
|
||||
/**
|
||||
* Direct handler of the android.app.Application.ActivityLifecycleCallbacks.onActivityDestroyed method.
|
||||
*/
|
||||
onActivityStarted: (activity: android.app.Activity) => void;
|
||||
|
||||
/**
|
||||
* Direct handler of the android.app.Application.ActivityLifecycleCallbacks.onActivityPaused method.
|
||||
*/
|
||||
onActivityPaused: (activity: android.app.Activity) => void;
|
||||
|
||||
/**
|
||||
* Direct handler of the android.app.Application.ActivityLifecycleCallbacks.onActivityResumed method.
|
||||
*/
|
||||
onActivityResumed: (activity: android.app.Activity) => void;
|
||||
|
||||
/**
|
||||
* Direct handler of the android.app.Application.ActivityLifecycleCallbacks.onActivityStopped method.
|
||||
*/
|
||||
onActivityStopped: (activity: android.app.Activity) => void;
|
||||
|
||||
/**
|
||||
* Direct handler of the android.app.Application.ActivityLifecycleCallbacks.onSaveActivityState method.
|
||||
*/
|
||||
onSaveActivityState: (activity: android.app.Activity, bundle: android.os.Bundle) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* The abstraction of an iOS-specific application object.
|
||||
*/
|
||||
interface iOSApplication {
|
||||
/**
|
||||
* The root view controller for the application.
|
||||
*/
|
||||
rootController: UIKit.UIViewController;
|
||||
|
||||
/**
|
||||
* The android.app.Application object instance provided to the init of the module.
|
||||
*/
|
||||
nativeApp: UIKit.UIApplication;
|
||||
}
|
||||
}
|
|
@ -1,81 +1,155 @@
|
|||
var appModule = require("application/application-common");
|
||||
|
||||
require("utils/module-merge").merge(appModule, exports);
|
||||
|
||||
var initialized;
|
||||
exports.init = function (nativeApp) {
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
var app = new iOSApplication(nativeApp);
|
||||
exports.ios = app;
|
||||
app.init();
|
||||
|
||||
initialized = true;
|
||||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
|
||||
var iOSApplication = (function () {
|
||||
function iOSApplication(nativeApp) {
|
||||
this.nativeApp = UIKit.UIApplication.sharedApplication();
|
||||
var appModule = require("application/application-common");
|
||||
var frame = require("ui/frame");
|
||||
var utils = require("utils/utils");
|
||||
var types = require("utils/types");
|
||||
require("utils/module-merge").merge(appModule, exports);
|
||||
exports.mainModule;
|
||||
var Window = (function (_super) {
|
||||
__extends(Window, _super);
|
||||
function Window() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
iOSApplication.prototype.init = function () {
|
||||
var that = this;
|
||||
UIKit.UIResponder.extends({}, {
|
||||
name: "TNSAppDelegate"
|
||||
}).implements({
|
||||
protocol: "UIApplicationDelegate",
|
||||
implementation: {
|
||||
applicationDidFinishLaunchingWithOptions: function () {
|
||||
log("Application launched: applicationDidFinishLaunchingWithOptions.");
|
||||
|
||||
this.window = new UIKit.UIWindow(UIKit.UIScreen.mainScreen().bounds);
|
||||
this.window.backgroundColor = UIKit.UIColor.whiteColor();
|
||||
this.window.makeKeyAndVisible();
|
||||
|
||||
if (exports.onLaunch) {
|
||||
that.rootController = exports.onLaunch();
|
||||
this.window.rootViewController = that.rootController;
|
||||
} else {
|
||||
log("Missing Application.onLaunch");
|
||||
}
|
||||
|
||||
log("applicationDidFinishLaunchingWithOptions finished.");
|
||||
return true;
|
||||
},
|
||||
applicationDidBecomeActive: function (application) {
|
||||
log("applicationDidBecomeActive: " + application);
|
||||
if (exports.onResume) {
|
||||
exports.onResume();
|
||||
}
|
||||
},
|
||||
applicationWillResignActive: function (application) {
|
||||
log("applicationWillResignActive: " + application);
|
||||
},
|
||||
applicationDidEnterBackground: function (application) {
|
||||
log("applicationDidEnterBackground: " + application);
|
||||
if (exports.onSuspend) {
|
||||
exports.onSuspend();
|
||||
}
|
||||
},
|
||||
applicationWillEnterForeground: function (application) {
|
||||
log("applicationWillEnterForeground: " + application);
|
||||
},
|
||||
applicationWillTerminate: function (application) {
|
||||
log("applicationWillTerminate: " + application);
|
||||
if (exports.onExit) {
|
||||
exports.onExit();
|
||||
}
|
||||
},
|
||||
applicationDidReceiveMemoryWarning: function (application) {
|
||||
log("applicationDidReceiveMemoryWarning: " + application);
|
||||
if (exports.onLowMemory) {
|
||||
exports.onLowMemory();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Window.prototype.initWithFrame = function (frame) {
|
||||
var window = _super.prototype.initWithFrame.call(this, frame);
|
||||
if (window) {
|
||||
window.autoresizingMask = UIViewAutoresizing.UIViewAutoresizingNone;
|
||||
}
|
||||
return window;
|
||||
};
|
||||
return iOSApplication;
|
||||
Object.defineProperty(Window.prototype, "content", {
|
||||
get: function () {
|
||||
return this._content;
|
||||
},
|
||||
set: function (value) {
|
||||
this._content = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Window.prototype.layoutSubviews = function () {
|
||||
if (!this._content) {
|
||||
return;
|
||||
}
|
||||
var statusFrame = UIApplication.sharedApplication().statusBarFrame;
|
||||
var statusBarHeight = 0;
|
||||
try {
|
||||
statusBarHeight = Math.min(statusFrame.size.width, statusFrame.size.height);
|
||||
}
|
||||
catch (ex) {
|
||||
console.log("exception: " + ex);
|
||||
}
|
||||
var isLandscape = utils.ios.isLandscape();
|
||||
var iOSMajorVersion = utils.ios.MajorVersion;
|
||||
if (isLandscape && iOSMajorVersion > 7) {
|
||||
statusBarHeight = 0;
|
||||
}
|
||||
var deviceFrame = UIScreen.mainScreen().bounds;
|
||||
var size = deviceFrame.size;
|
||||
var width = size.width;
|
||||
var height = size.height;
|
||||
if (iOSMajorVersion < 8 && isLandscape) {
|
||||
width = size.height;
|
||||
height = size.width;
|
||||
}
|
||||
var origin = deviceFrame.origin;
|
||||
var left = origin.x;
|
||||
var top = origin.y + statusBarHeight;
|
||||
var widthSpec = utils.layout.makeMeasureSpec(width, utils.layout.EXACTLY);
|
||||
var heightSpec = utils.layout.makeMeasureSpec(height - statusBarHeight, utils.layout.EXACTLY);
|
||||
this._content.measure(widthSpec, heightSpec);
|
||||
this._content.layout(left, top, width, height);
|
||||
};
|
||||
return Window;
|
||||
})(UIWindow);
|
||||
var TNSAppDelegate = (function (_super) {
|
||||
__extends(TNSAppDelegate, _super);
|
||||
function TNSAppDelegate() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
TNSAppDelegate.prototype.applicationDidFinishLaunchingWithOptions = function (application, launchOptions) {
|
||||
this.window = Window.alloc().initWithFrame(UIScreen.mainScreen().bounds);
|
||||
this.window.backgroundColor = UIColor.whiteColor();
|
||||
if (exports.onLaunch) {
|
||||
exports.onLaunch();
|
||||
}
|
||||
var topFrame = frame.topmost();
|
||||
if (!topFrame) {
|
||||
if (exports.mainModule) {
|
||||
topFrame = new frame.Frame();
|
||||
topFrame.navigate(exports.mainModule);
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.window.content = topFrame;
|
||||
this.window.rootViewController = topFrame.ios.controller;
|
||||
var app = exports.ios;
|
||||
app.rootController = this.window.rootViewController;
|
||||
this.window.makeKeyAndVisible();
|
||||
return true;
|
||||
};
|
||||
TNSAppDelegate.prototype.applicationDidBecomeActive = function (application) {
|
||||
if (exports.onResume) {
|
||||
exports.onResume();
|
||||
}
|
||||
};
|
||||
TNSAppDelegate.prototype.applicationWillResignActive = function (application) {
|
||||
};
|
||||
TNSAppDelegate.prototype.applicationDidEnterBackground = function (application) {
|
||||
if (exports.onSuspend) {
|
||||
exports.onSuspend();
|
||||
}
|
||||
};
|
||||
TNSAppDelegate.prototype.applicationWillEnterForeground = function (application) {
|
||||
};
|
||||
TNSAppDelegate.prototype.applicationWillTerminate = function (application) {
|
||||
if (exports.onExit) {
|
||||
exports.onExit();
|
||||
}
|
||||
};
|
||||
TNSAppDelegate.prototype.applicationDidReceiveMemoryWarning = function (application) {
|
||||
if (exports.onLowMemory) {
|
||||
exports.onLowMemory();
|
||||
}
|
||||
};
|
||||
TNSAppDelegate.prototype.applicationOpenURLSourceApplicationAnnotation = function (application, url, sourceApplication, annotation) {
|
||||
var dictionary = new NSMutableDictionary();
|
||||
dictionary.setObjectForKey(url, "TLKApplicationOpenURL");
|
||||
dictionary.setObjectForKey(application, "TLKApplication");
|
||||
NSNotificationCenter.defaultCenter().postNotificationNameObjectUserInfo("com.telerik.TLKApplicationOpenURL", null, dictionary);
|
||||
return true;
|
||||
};
|
||||
TNSAppDelegate.ObjCProtocols = [UIApplicationDelegate];
|
||||
return TNSAppDelegate;
|
||||
})(UIResponder);
|
||||
var IOSApplication = (function () {
|
||||
function IOSApplication() {
|
||||
this.nativeApp = UIApplication.sharedApplication();
|
||||
}
|
||||
IOSApplication.prototype.init = function () {
|
||||
this._tnsAppdelegate = new TNSAppDelegate();
|
||||
};
|
||||
return IOSApplication;
|
||||
})();
|
||||
//# sourceMappingURL=application.ios.js.map
|
||||
var app = new IOSApplication();
|
||||
exports.ios = app;
|
||||
app.init();
|
||||
exports.start = function () {
|
||||
appModule.loadCss();
|
||||
try {
|
||||
UIApplicationMain(0, null, null, "TNSAppDelegate");
|
||||
}
|
||||
catch (error) {
|
||||
if (!types.isFunction(exports.onUncaughtError)) {
|
||||
return;
|
||||
}
|
||||
exports.onUncaughtError(error);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
module.exports = require("application/application");
|
||||
//# sourceMappingURL=index.js.map
|
|
@ -0,0 +1,2 @@
|
|||
{ "name" : "application",
|
||||
"main" : "application.js" }
|
|
@ -0,0 +1,23 @@
|
|||
var imageSource = require("image-source");
|
||||
var appModule = require("application");
|
||||
var REQUEST_IMAGE_CAPTURE = 3453;
|
||||
exports.takePicture = function () {
|
||||
return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
var takePictureIntent = new android.content.Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
|
||||
if (takePictureIntent.resolveActivity(appModule.android.context.getPackageManager()) != null) {
|
||||
var previousResult = appModule.android.onActivityResult;
|
||||
appModule.android.onActivityResult = function (requestCode, resultCode, data) {
|
||||
appModule.android.onActivityResult = previousResult;
|
||||
if (requestCode === REQUEST_IMAGE_CAPTURE && resultCode === android.app.Activity.RESULT_OK) {
|
||||
resolve(imageSource.fromNativeSource(data.getExtras().get("data")));
|
||||
}
|
||||
};
|
||||
appModule.android.foregroundActivity.startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
};
|
|
@ -1,80 +0,0 @@
|
|||
|
||||
declare module "camera" {
|
||||
|
||||
import promises = require("promises");
|
||||
import imageSource = require("image-source");
|
||||
|
||||
/**
|
||||
* Specifies a camera position on a device.
|
||||
*/
|
||||
enum CameraPosition {
|
||||
/**
|
||||
* The camera is located at the back of the device.
|
||||
*/
|
||||
BACK = 0,
|
||||
|
||||
/**
|
||||
* The camera is located at the front of the device, facing the user.
|
||||
*/
|
||||
FRONT = 1,
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies a camera flash mode.
|
||||
*/
|
||||
enum FlashMode {
|
||||
/**
|
||||
* The camera flash is disabled.
|
||||
*/
|
||||
OFF = -1,
|
||||
/**
|
||||
* Flash will be fired automatically when required.
|
||||
*/
|
||||
AUTO = 0,
|
||||
/**
|
||||
* The camera flash is enabled.
|
||||
*/
|
||||
ON = 1,
|
||||
}
|
||||
|
||||
/**
|
||||
* Camera options for capture an image. Currently not guaranteed to be used on Android
|
||||
*/
|
||||
interface Options {
|
||||
/**
|
||||
* Specifies which Camera to use.
|
||||
*/
|
||||
cameraPosition?: CameraPosition;
|
||||
|
||||
/**
|
||||
* Specifies flash mode.
|
||||
*/
|
||||
flashMode?: FlashMode;
|
||||
}
|
||||
|
||||
// TODO most of hardware related parts need to handle onPause and onResume of the calling activities
|
||||
|
||||
/**
|
||||
* TODO replace it with promise methods only and remove this class
|
||||
* This class provides access to the device camera and photo libraries.
|
||||
*/
|
||||
class CameraManager {
|
||||
/**
|
||||
* Take a photo using the camera.
|
||||
*/
|
||||
takePicture(params: any, onSuccess: (imageData: any) => any, onError?: (error: any) => any);
|
||||
|
||||
// TODO: Create an interface with the pictrue from library options: { useSavedPhotos: true }
|
||||
|
||||
/**
|
||||
* Requests an image from the user.
|
||||
* The result may be a new photo taken or an existing image from the library.
|
||||
*/
|
||||
pictureFromLibrary(params: any, onSuccess: (imageData: any) => any, onError?: (error: any) => any);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a photo using the camera.
|
||||
*/
|
||||
function takePicture(options?: Options): promises.Promise<imageSource.ImageSource>;
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
var imageSource = require("image-source");
|
||||
var frame = require("ui/frame");
|
||||
var UIImagePickerControllerDelegateImpl = (function (_super) {
|
||||
__extends(UIImagePickerControllerDelegateImpl, _super);
|
||||
function UIImagePickerControllerDelegateImpl() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
UIImagePickerControllerDelegateImpl.new = function () {
|
||||
return _super.new.call(this);
|
||||
};
|
||||
UIImagePickerControllerDelegateImpl.prototype.initWithCallback = function (callback) {
|
||||
this._callback = callback;
|
||||
return this;
|
||||
};
|
||||
UIImagePickerControllerDelegateImpl.prototype.imagePickerControllerDidFinishPickingMediaWithInfo = function (picker, info) {
|
||||
if (info) {
|
||||
var source = info.valueForKey(UIImagePickerControllerOriginalImage);
|
||||
if (source) {
|
||||
var image = imageSource.fromNativeSource(source);
|
||||
if (this._callback) {
|
||||
this._callback(image);
|
||||
}
|
||||
}
|
||||
}
|
||||
picker.presentingViewController.dismissViewControllerAnimatedCompletion(true, null);
|
||||
};
|
||||
UIImagePickerControllerDelegateImpl.prototype.imagePickerControllerDidCancel = function (picker) {
|
||||
picker.presentingViewController.dismissViewControllerAnimatedCompletion(true, null);
|
||||
};
|
||||
UIImagePickerControllerDelegateImpl.ObjCProtocols = [UIImagePickerControllerDelegate];
|
||||
return UIImagePickerControllerDelegateImpl;
|
||||
})(NSObject);
|
||||
exports.takePicture = function () {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var imagePickerController = new UIImagePickerController();
|
||||
var listener = UIImagePickerControllerDelegateImpl.new().initWithCallback(resolve);
|
||||
imagePickerController.delegate = listener;
|
||||
if (UIDevice.currentDevice().model !== "iPhone Simulator") {
|
||||
imagePickerController.mediaTypes = UIImagePickerController.availableMediaTypesForSourceType(UIImagePickerControllerSourceType.UIImagePickerControllerSourceTypeCamera);
|
||||
imagePickerController.sourceType = UIImagePickerControllerSourceType.UIImagePickerControllerSourceTypeCamera;
|
||||
}
|
||||
imagePickerController.modalPresentationStyle = UIModalPresentationStyle.UIModalPresentationCurrentContext;
|
||||
var topMostFrame = frame.topmost();
|
||||
if (topMostFrame) {
|
||||
var viewController = topMostFrame.currentPage && topMostFrame.currentPage.ios;
|
||||
if (viewController) {
|
||||
viewController.presentModalViewControllerAnimated(imagePickerController, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
|
@ -0,0 +1,2 @@
|
|||
{ "name" : "camera",
|
||||
"main" : "camera.js" }
|
|
@ -0,0 +1,146 @@
|
|||
var types = require("utils/types");
|
||||
var knownColors = require("color/known-colors");
|
||||
var AMP = "#";
|
||||
var Color = (function () {
|
||||
function Color() {
|
||||
if (arguments.length === 1) {
|
||||
var arg = arguments[0];
|
||||
if (types.isString(arg)) {
|
||||
if (knownColors.isKnownName(arg)) {
|
||||
this._hex = knownColors.getKnownColor(arg);
|
||||
this._name = arg;
|
||||
}
|
||||
else {
|
||||
this._hex = this._normalizeHex(arg);
|
||||
}
|
||||
this._argb = this._argbFromString(this._hex);
|
||||
}
|
||||
else if (types.isNumber(arg)) {
|
||||
this._argb = arg;
|
||||
}
|
||||
else {
|
||||
throw new Error("Expected 1 or 4 constructor parameters.");
|
||||
}
|
||||
this._parseComponents();
|
||||
if (!this._hex) {
|
||||
this._hex = this._buildHex();
|
||||
}
|
||||
}
|
||||
else if (arguments.length === 4) {
|
||||
this._a = arguments[0];
|
||||
this._r = arguments[1];
|
||||
this._g = arguments[2];
|
||||
this._b = arguments[3];
|
||||
this._buildArgb();
|
||||
this._hex = this._buildHex();
|
||||
}
|
||||
else {
|
||||
throw new Error("Expected 1 or 4 constructor parameters.");
|
||||
}
|
||||
}
|
||||
Object.defineProperty(Color.prototype, "a", {
|
||||
get: function () {
|
||||
return this._a;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Color.prototype, "r", {
|
||||
get: function () {
|
||||
return this._r;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Color.prototype, "g", {
|
||||
get: function () {
|
||||
return this._g;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Color.prototype, "b", {
|
||||
get: function () {
|
||||
return this._b;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Color.prototype, "argb", {
|
||||
get: function () {
|
||||
return this._argb;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Color.prototype, "hex", {
|
||||
get: function () {
|
||||
return this._hex;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Color.prototype, "name", {
|
||||
get: function () {
|
||||
return this._name;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Color.prototype, "ios", {
|
||||
get: function () {
|
||||
return undefined;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Color.prototype, "android", {
|
||||
get: function () {
|
||||
return undefined;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Color.prototype._argbFromString = function (hex) {
|
||||
return undefined;
|
||||
};
|
||||
Color.prototype.equals = function (value) {
|
||||
return this.argb === value.argb;
|
||||
};
|
||||
Color.equals = function (value1, value2) {
|
||||
if (!value1 || !value2) {
|
||||
return false;
|
||||
}
|
||||
return value1.equals(value2);
|
||||
};
|
||||
Color.prototype._buildHex = function () {
|
||||
return AMP + this._componentToHex(this._a) + this._componentToHex(this._r) + this._componentToHex(this._g) + this._componentToHex(this._b);
|
||||
};
|
||||
Color.prototype._componentToHex = function (component) {
|
||||
var hex = component.toString(16);
|
||||
if (hex.length === 1) {
|
||||
hex = "0" + hex;
|
||||
}
|
||||
return hex;
|
||||
};
|
||||
Color.prototype._parseComponents = function () {
|
||||
if (!this._argb) {
|
||||
throw new Error("Missing the ARGB numeric value");
|
||||
}
|
||||
this._a = (this._argb >> 24) & 255;
|
||||
this._r = (this._argb >> 16) & 255;
|
||||
this._g = (this._argb >> 8) & 255;
|
||||
this._b = this._argb & 255;
|
||||
};
|
||||
Color.prototype._buildArgb = function () {
|
||||
this._argb = (this._a << 24) | (this._r << 16) | (this._g << 8) | this._b;
|
||||
};
|
||||
Color.prototype._normalizeHex = function (hexStr) {
|
||||
if (hexStr.charAt(0) === AMP && hexStr.length === 4) {
|
||||
hexStr = hexStr.charAt(0) + hexStr.charAt(1) + hexStr.charAt(1) + hexStr.charAt(2) + hexStr.charAt(2) + hexStr.charAt(3) + hexStr.charAt(3);
|
||||
}
|
||||
return hexStr;
|
||||
};
|
||||
return Color;
|
||||
})();
|
||||
exports.Color = Color;
|
|
@ -0,0 +1,25 @@
|
|||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
var common = require("color/color-common");
|
||||
var Color = (function (_super) {
|
||||
__extends(Color, _super);
|
||||
function Color() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
Object.defineProperty(Color.prototype, "android", {
|
||||
get: function () {
|
||||
return this.argb;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Color.prototype._argbFromString = function (hex) {
|
||||
return android.graphics.Color.parseColor(hex);
|
||||
};
|
||||
return Color;
|
||||
})(common.Color);
|
||||
exports.Color = Color;
|
|
@ -0,0 +1,36 @@
|
|||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
var common = require("color/color-common");
|
||||
var AMP = "#";
|
||||
var Color = (function (_super) {
|
||||
__extends(Color, _super);
|
||||
function Color() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
Object.defineProperty(Color.prototype, "ios", {
|
||||
get: function () {
|
||||
if (!this._ios) {
|
||||
this._ios = UIColor.alloc().initWithRedGreenBlueAlpha(this.r / 255, this.g / 255, this.b / 255, this.a / 255);
|
||||
}
|
||||
return this._ios;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Color.prototype._argbFromString = function (hex) {
|
||||
if (hex.charAt(0) === AMP) {
|
||||
hex = hex.substr(1);
|
||||
}
|
||||
var intVal = parseInt(hex, 16);
|
||||
if (hex.length === 6) {
|
||||
intVal |= 255 << 24;
|
||||
}
|
||||
return intVal;
|
||||
};
|
||||
return Color;
|
||||
})(common.Color);
|
||||
exports.Color = Color;
|
|
@ -0,0 +1,165 @@
|
|||
exports.AliceBlue = "#F0F8FF";
|
||||
exports.AntiqueWhite = "#FAEBD7";
|
||||
exports.Aqua = "#00FFFF";
|
||||
exports.Aquamarine = "#7FFFD4";
|
||||
exports.Azure = "#F0FFFF";
|
||||
exports.Beige = "#F5F5DC";
|
||||
exports.Bisque = "#FFE4C4";
|
||||
exports.Black = "#000000";
|
||||
exports.BlanchedAlmond = "#FFEBCD";
|
||||
exports.Blue = "#0000FF";
|
||||
exports.BlueViolet = "#8A2BE2";
|
||||
exports.Brown = "#A52A2A";
|
||||
exports.BurlyWood = "#DEB887";
|
||||
exports.CadetBlue = "#5F9EA0";
|
||||
exports.Chartreuse = "#7FFF00";
|
||||
exports.Chocolate = "#D2691E";
|
||||
exports.Coral = "#FF7F50";
|
||||
exports.CornflowerBlue = "#6495ED";
|
||||
exports.Cornsilk = "#FFF8DC";
|
||||
exports.Crimson = "#DC143C";
|
||||
exports.Cyan = "#00FFFF";
|
||||
exports.DarkBlue = "#00008B";
|
||||
exports.DarkCyan = "#008B8B";
|
||||
exports.DarkGoldenRod = "#B8860B";
|
||||
exports.DarkGray = "#A9A9A9";
|
||||
exports.DarkGreen = "#006400";
|
||||
exports.DarkKhaki = "#BDB76B";
|
||||
exports.DarkMagenta = "#8B008B";
|
||||
exports.DarkOliveGreen = "#556B2F";
|
||||
exports.DarkOrange = "#FF8C00";
|
||||
exports.DarkOrchid = "#9932CC";
|
||||
exports.DarkRed = "#8B0000";
|
||||
exports.DarkSalmon = "#E9967A";
|
||||
exports.DarkSeaGreen = "#8FBC8F";
|
||||
exports.DarkSlateBlue = "#483D8B";
|
||||
exports.DarkSlateGray = "#2F4F4F";
|
||||
exports.DarkTurquoise = "#00CED1";
|
||||
exports.DarkViolet = "#9400D3";
|
||||
exports.DeepPink = "#FF1493";
|
||||
exports.DeepSkyBlue = "#00BFFF";
|
||||
exports.DimGray = "#696969";
|
||||
exports.DodgerBlue = "#1E90FF";
|
||||
exports.FireBrick = "#B22222";
|
||||
exports.FloralWhite = "#FFFAF0";
|
||||
exports.ForestGreen = "#228B22";
|
||||
exports.Fuchsia = "#FF00FF";
|
||||
exports.Gainsboro = "#DCDCDC";
|
||||
exports.GhostWhite = "#F8F8FF";
|
||||
exports.Gold = "#FFD700";
|
||||
exports.GoldenRod = "#DAA520";
|
||||
exports.Gray = "#808080";
|
||||
exports.Green = "#008000";
|
||||
exports.GreenYellow = "#ADFF2F";
|
||||
exports.HoneyDew = "#F0FFF0";
|
||||
exports.HotPink = "#FF69B4";
|
||||
exports.IndianRed = "#CD5C5C";
|
||||
exports.Indigo = "#4B0082";
|
||||
exports.Ivory = "#FFFFF0";
|
||||
exports.Khaki = "#F0E68C";
|
||||
exports.Lavender = "#E6E6FA";
|
||||
exports.LavenderBlush = "#FFF0F5";
|
||||
exports.LawnGreen = "#7CFC00";
|
||||
exports.LemonChiffon = "#FFFACD";
|
||||
exports.LightBlue = "#ADD8E6";
|
||||
exports.LightCoral = "#F08080";
|
||||
exports.LightCyan = "#E0FFFF";
|
||||
exports.LightGoldenRodYellow = "#FAFAD2";
|
||||
exports.LightGray = "#D3D3D3";
|
||||
exports.LightGreen = "#90EE90";
|
||||
exports.LightPink = "#FFB6C1";
|
||||
exports.LightSalmon = "#FFA07A";
|
||||
exports.LightSeaGreen = "#20B2AA";
|
||||
exports.LightSkyBlue = "#87CEFA";
|
||||
exports.LightSlateGray = "#778899";
|
||||
exports.LightSteelBlue = "#B0C4DE";
|
||||
exports.LightYellow = "#FFFFE0";
|
||||
exports.Lime = "#00FF00";
|
||||
exports.LimeGreen = "#32CD32";
|
||||
exports.Linen = "#FAF0E6";
|
||||
exports.Magenta = "#FF00FF";
|
||||
exports.Maroon = "#800000";
|
||||
exports.MediumAquaMarine = "#66CDAA";
|
||||
exports.MediumBlue = "#0000CD";
|
||||
exports.MediumOrchid = "#BA55D3";
|
||||
exports.MediumPurple = "#9370DB";
|
||||
exports.MediumSeaGreen = "#3CB371";
|
||||
exports.MediumSlateBlue = "#7B68EE";
|
||||
exports.MediumSpringGreen = "#00FA9A";
|
||||
exports.MediumTurquoise = "#48D1CC";
|
||||
exports.MediumVioletRed = "#C71585";
|
||||
exports.MidnightBlue = "#191970";
|
||||
exports.MintCream = "#F5FFFA";
|
||||
exports.MistyRose = "#FFE4E1";
|
||||
exports.Moccasin = "#FFE4B5";
|
||||
exports.NavajoWhite = "#FFDEAD";
|
||||
exports.Navy = "#000080";
|
||||
exports.OldLace = "#FDF5E6";
|
||||
exports.Olive = "#808000";
|
||||
exports.OliveDrab = "#6B8E23";
|
||||
exports.Orange = "#FFA500";
|
||||
exports.OrangeRed = "#FF4500";
|
||||
exports.Orchid = "#DA70D6";
|
||||
exports.PaleGoldenRod = "#EEE8AA";
|
||||
exports.PaleGreen = "#98FB98";
|
||||
exports.PaleTurquoise = "#AFEEEE";
|
||||
exports.PaleVioletRed = "#DB7093";
|
||||
exports.PapayaWhip = "#FFEFD5";
|
||||
exports.PeachPuff = "#FFDAB9";
|
||||
exports.Peru = "#CD853F";
|
||||
exports.Pink = "#FFC0CB";
|
||||
exports.Plum = "#DDA0DD";
|
||||
exports.PowderBlue = "#B0E0E6";
|
||||
exports.Purple = "#800080";
|
||||
exports.Red = "#FF0000";
|
||||
exports.RosyBrown = "#BC8F8F";
|
||||
exports.RoyalBlue = "#4169E1";
|
||||
exports.SaddleBrown = "#8B4513";
|
||||
exports.Salmon = "#FA8072";
|
||||
exports.SandyBrown = "#F4A460";
|
||||
exports.SeaGreen = "#2E8B57";
|
||||
exports.SeaShell = "#FFF5EE";
|
||||
exports.Sienna = "#A0522D";
|
||||
exports.Silver = "#C0C0C0";
|
||||
exports.SkyBlue = "#87CEEB";
|
||||
exports.SlateBlue = "#6A5ACD";
|
||||
exports.SlateGray = "#708090";
|
||||
exports.Snow = "#FFFAFA";
|
||||
exports.SpringGreen = "#00FF7F";
|
||||
exports.SteelBlue = "#4682B4";
|
||||
exports.Tan = "#D2B48C";
|
||||
exports.Teal = "#008080";
|
||||
exports.Thistle = "#D8BFD8";
|
||||
exports.Tomato = "#FF6347";
|
||||
exports.Turquoise = "#40E0D0";
|
||||
exports.Violet = "#EE82EE";
|
||||
exports.Wheat = "#F5DEB3";
|
||||
exports.White = "#FFFFFF";
|
||||
exports.WhiteSmoke = "#F5F5F5";
|
||||
exports.Yellow = "#FFFF00";
|
||||
exports.YellowGreen = "#9ACD32";
|
||||
var _allColors = {};
|
||||
(function () {
|
||||
var name;
|
||||
var underscore = "_";
|
||||
for (var p in exports) {
|
||||
name = p;
|
||||
if (name.charAt(0) !== underscore) {
|
||||
_allColors[name.toLowerCase()] = exports[p];
|
||||
}
|
||||
}
|
||||
})();
|
||||
function isKnownName(name) {
|
||||
if (!name) {
|
||||
return undefined;
|
||||
}
|
||||
return name.toLowerCase() in _allColors;
|
||||
}
|
||||
exports.isKnownName = isKnownName;
|
||||
function getKnownColor(name) {
|
||||
if (!name) {
|
||||
return undefined;
|
||||
}
|
||||
return _allColors[name.toLowerCase()];
|
||||
}
|
||||
exports.getKnownColor = getKnownColor;
|
|
@ -0,0 +1,2 @@
|
|||
{ "name" : "color",
|
||||
"main" : "color.js" }
|
|
@ -1,22 +1,16 @@
|
|||
var TAG = 'JS';
|
||||
|
||||
var TAG = 'JS';
|
||||
exports.helper_log = function (message) {
|
||||
android.util.Log.v(TAG, message);
|
||||
};
|
||||
|
||||
exports.info = function (message) {
|
||||
android.util.Log.i(TAG, message);
|
||||
};
|
||||
|
||||
exports.error = function (message) {
|
||||
android.util.Log.e(TAG, message);
|
||||
};
|
||||
|
||||
exports.warn = function (message) {
|
||||
android.util.Log.w(TAG, message);
|
||||
};
|
||||
|
||||
exports.timeMillis = function () {
|
||||
return java.lang.System.nanoTime() / 1000000;
|
||||
};
|
||||
//# sourceMappingURL=console-native.android.js.map
|
||||
|
|
|
@ -1,24 +1,17 @@
|
|||
function nslog(prefix, message) {
|
||||
Foundation.NSLog("%@: %@", [{ type: PrimitiveType.POINTER, value: prefix }, { type: PrimitiveType.POINTER, value: message }]);
|
||||
function nslog(prefix, message) {
|
||||
}
|
||||
|
||||
exports.helper_log = function (message) {
|
||||
nslog('log', message);
|
||||
};
|
||||
|
||||
exports.info = function (message) {
|
||||
nslog('info', message);
|
||||
};
|
||||
|
||||
exports.error = function (message) {
|
||||
nslog('error', message);
|
||||
};
|
||||
|
||||
exports.warn = function (message) {
|
||||
nslog('warning', message);
|
||||
};
|
||||
|
||||
exports.timeMillis = function () {
|
||||
return QuartzCore.CACurrentMediaTime() * 1000;
|
||||
return CACurrentMediaTime() * 1000;
|
||||
};
|
||||
//# sourceMappingURL=console-native.ios.js.map
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
/**
|
||||
* Encapsulates methods used to print some information in the console.
|
||||
* Instance of this class is declared in the global JavaScript context and is accessible by directly calling console.[xxx] methods.
|
||||
*/
|
||||
export declare class Console {
|
||||
/**
|
||||
* Begins counting a time span for a given name (key).
|
||||
* @param reportName The key for the operation.
|
||||
*/
|
||||
public time(reportName: string): void;
|
||||
|
||||
/**
|
||||
* Ends a previously started time span through the time method.
|
||||
* @param reportName The key for the operation. Must have an already started time(reportName) operation with the same key.
|
||||
*/
|
||||
public timeEnd(reportName: string): void;
|
||||
|
||||
/**
|
||||
* Asserts a boolean condition and prints a message in case the assert fails.
|
||||
* @param test A value that should not be Falsy.
|
||||
* @param message The message to be displayed in case the asserted value is Falsy.
|
||||
* @param formatParams Optional formatting parameters to be applied to the printed message.
|
||||
*/
|
||||
public assert(test: boolean, message: string, ...formatParams: any[]): void;
|
||||
|
||||
/**
|
||||
* Reports some information.
|
||||
* @param message The information message to be printed to the console.
|
||||
* @param formatParams Optional formatting parameters to be applied to the printed message.
|
||||
*/
|
||||
public info(message: any, ...formatParams: any[]): void;
|
||||
|
||||
/**
|
||||
* Reports a warning.
|
||||
* @param message The warning message to be printed to the console.
|
||||
* @param formatParams Optional formatting parameters to be applied to the printed message.
|
||||
*/
|
||||
public warn(message: any, ...formatParams: any[]): void;
|
||||
|
||||
/**
|
||||
* Reports an error.
|
||||
* @param message The error message to be printed to the console.
|
||||
* @param formatParams Optional formatting parameters to be applied to the printed message.
|
||||
*/
|
||||
public error(message: any, ...formatParams: any[]): void;
|
||||
|
||||
/**
|
||||
* Verbously logs a message.
|
||||
* @param message The message to be printed to the console.
|
||||
* @param formatParams Optional formatting parameters to be applied to the printed message.
|
||||
*/
|
||||
public log(message: any, ...formatParams: any[]): void;
|
||||
|
||||
/**
|
||||
* Prints the current stack trace in the console.
|
||||
*/
|
||||
public trace(): void;
|
||||
|
||||
/**
|
||||
* Prints the state of the specified object to the console.
|
||||
* @param obj The object instance to be dumped.
|
||||
*/
|
||||
public dump(obj: any): void;
|
||||
|
||||
/**
|
||||
* Prints the state of the specified object to the console.
|
||||
*/
|
||||
public dir(obj: any): void;
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
var helperModule = require("console/console-native");
|
||||
|
||||
var Console = (function () {
|
||||
function Console() {
|
||||
this.dir = this.dump;
|
||||
|
@ -10,7 +9,6 @@ var Console = (function () {
|
|||
var a = arguments;
|
||||
var i = 0;
|
||||
var format = a[i++];
|
||||
|
||||
var pad = function (str, len, chr, leftJustify) {
|
||||
if (!chr) {
|
||||
chr = ' ';
|
||||
|
@ -18,19 +16,18 @@ var Console = (function () {
|
|||
var padding = (str.length >= len) ? '' : new Array(1 + len - str.length >>> 0).join(chr);
|
||||
return leftJustify ? str + padding : padding + str;
|
||||
};
|
||||
|
||||
var justify = function (value, prefix, leftJustify, minWidth, zeroPad, customPadChar) {
|
||||
var diff = minWidth - value.length;
|
||||
if (diff > 0) {
|
||||
if (leftJustify || !zeroPad) {
|
||||
value = pad(value, minWidth, customPadChar, leftJustify);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
value = value.slice(0, prefix.length) + pad('', diff, '0', true) + value.slice(prefix.length);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
};
|
||||
|
||||
var formatBaseX = function (value, base, prefix, leftJustify, minWidth, precision, zeroPad) {
|
||||
var number = value >>> 0;
|
||||
prefix = prefix && number && {
|
||||
|
@ -41,21 +38,17 @@ var Console = (function () {
|
|||
value = prefix + pad(number.toString(base), precision || 0, '0', false);
|
||||
return justify(value, prefix, leftJustify, minWidth, zeroPad);
|
||||
};
|
||||
|
||||
var formatString = function (value, leftJustify, minWidth, precision, zeroPad, customPadChar) {
|
||||
if (precision != null) {
|
||||
value = value.slice(0, precision);
|
||||
}
|
||||
return justify(value, '', leftJustify, minWidth, zeroPad, customPadChar);
|
||||
};
|
||||
|
||||
var doFormat = function (substring, valueIndex, flags, minWidth, _, precision, type) {
|
||||
var number, prefix, method, textTransform, value;
|
||||
|
||||
if (substring === '%%') {
|
||||
return '%';
|
||||
}
|
||||
|
||||
var leftJustify = false;
|
||||
var positivePrefix = '';
|
||||
var zeroPad = false;
|
||||
|
@ -85,38 +78,38 @@ var Console = (function () {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!minWidth) {
|
||||
minWidth = 0;
|
||||
} else if (minWidth === '*') {
|
||||
}
|
||||
else if (minWidth === '*') {
|
||||
minWidth = +a[i++];
|
||||
} else if (minWidth.charAt(0) == '*') {
|
||||
}
|
||||
else if (minWidth.charAt(0) === '*') {
|
||||
minWidth = +a[minWidth.slice(1, -1)];
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
minWidth = +minWidth;
|
||||
}
|
||||
|
||||
if (minWidth < 0) {
|
||||
minWidth = -minWidth;
|
||||
leftJustify = true;
|
||||
}
|
||||
|
||||
if (!isFinite(minWidth)) {
|
||||
throw new Error('sprintf: (minimum-)width must be finite');
|
||||
}
|
||||
|
||||
if (!precision) {
|
||||
precision = 'fFeE'.indexOf(type) > -1 ? 6 : (type === 'd') ? 0 : undefined;
|
||||
} else if (precision === '*') {
|
||||
}
|
||||
else if (precision === '*') {
|
||||
precision = +a[i++];
|
||||
} else if (precision.charAt(0) == '*') {
|
||||
}
|
||||
else if (precision.charAt(0) === '*') {
|
||||
precision = +a[precision.slice(1, -1)];
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
precision = +precision;
|
||||
}
|
||||
|
||||
value = valueIndex ? a[valueIndex.slice(0, -1)] : a[i++];
|
||||
|
||||
switch (type) {
|
||||
case 's':
|
||||
return formatString(String(value), leftJustify, minWidth, precision, zeroPad, customPadChar);
|
||||
|
@ -135,7 +128,6 @@ var Console = (function () {
|
|||
case 'i':
|
||||
case 'd':
|
||||
number = +value || 0;
|
||||
|
||||
number = Math.round(number - number % 1);
|
||||
prefix = number < 0 ? '-' : positivePrefix;
|
||||
value = prefix + pad(String(Math.abs(number)), precision, '0', false);
|
||||
|
@ -156,10 +148,8 @@ var Console = (function () {
|
|||
return substring;
|
||||
}
|
||||
};
|
||||
|
||||
return format.replace(regex, doFormat);
|
||||
};
|
||||
|
||||
Console.prototype.formatParams = function (message) {
|
||||
if (arguments.length <= 1) {
|
||||
return message ? message : '';
|
||||
|
@ -171,16 +161,15 @@ var Console = (function () {
|
|||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
Console.prototype.time = function (reportName) {
|
||||
var name = reportName ? '__' + reportName : '__internal_console_time__';
|
||||
if (('undefined' === typeof (this._timers[name])) || (this._timers.hasOwnProperty(name))) {
|
||||
this._timers[name] = helperModule.timeMillis();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
this.warn('invalid name for timer console.time(' + reportName + ')');
|
||||
}
|
||||
};
|
||||
|
||||
Console.prototype.timeEnd = function (reportName) {
|
||||
var name = reportName ? '__' + reportName : '__internal_console_time__';
|
||||
if (this._timers.hasOwnProperty(name)) {
|
||||
|
@ -189,55 +178,50 @@ var Console = (function () {
|
|||
var time = helperModule.timeMillis();
|
||||
this.info('console.time(' + reportName + '): %.6f ms', (time - val));
|
||||
this._timers[name] = undefined;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
this.warn('undefined console.time(' + reportName + ')');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Console.prototype.assert = function (test, message) {
|
||||
var formatParams = [];
|
||||
for (var _i = 0; _i < (arguments.length - 2); _i++) {
|
||||
formatParams[_i] = arguments[_i + 2];
|
||||
for (var _i = 2; _i < arguments.length; _i++) {
|
||||
formatParams[_i - 2] = arguments[_i];
|
||||
}
|
||||
if (!test) {
|
||||
Array.prototype.shift.apply(arguments);
|
||||
helperModule.error(this.formatParams.apply(this, arguments));
|
||||
}
|
||||
};
|
||||
|
||||
Console.prototype.info = function (message) {
|
||||
var formatParams = [];
|
||||
for (var _i = 0; _i < (arguments.length - 1); _i++) {
|
||||
formatParams[_i] = arguments[_i + 1];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
formatParams[_i - 1] = arguments[_i];
|
||||
}
|
||||
helperModule.info(this.formatParams.apply(this, arguments));
|
||||
};
|
||||
|
||||
Console.prototype.warn = function (message) {
|
||||
var formatParams = [];
|
||||
for (var _i = 0; _i < (arguments.length - 1); _i++) {
|
||||
formatParams[_i] = arguments[_i + 1];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
formatParams[_i - 1] = arguments[_i];
|
||||
}
|
||||
helperModule.warn(this.formatParams.apply(this, arguments));
|
||||
};
|
||||
|
||||
Console.prototype.error = function (message) {
|
||||
var formatParams = [];
|
||||
for (var _i = 0; _i < (arguments.length - 1); _i++) {
|
||||
formatParams[_i] = arguments[_i + 1];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
formatParams[_i - 1] = arguments[_i];
|
||||
}
|
||||
helperModule.error(this.formatParams.apply(this, arguments));
|
||||
};
|
||||
|
||||
Console.prototype.log = function (message) {
|
||||
var formatParams = [];
|
||||
for (var _i = 0; _i < (arguments.length - 1); _i++) {
|
||||
formatParams[_i] = arguments[_i + 1];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
formatParams[_i - 1] = arguments[_i];
|
||||
}
|
||||
helperModule.helper_log(this.formatParams.apply(this, arguments));
|
||||
};
|
||||
|
||||
Console.prototype.trace = function () {
|
||||
var callstack = [];
|
||||
var currentFunction = arguments.callee.caller;
|
||||
|
@ -252,13 +236,12 @@ var Console = (function () {
|
|||
this.log(callstack.join('\n'));
|
||||
}
|
||||
};
|
||||
|
||||
Console.prototype.dump = function (obj) {
|
||||
if (null == obj) {
|
||||
this.log("=== dump(): object is 'null' ===");
|
||||
return;
|
||||
}
|
||||
if ("undefined" == typeof obj) {
|
||||
if ("undefined" === typeof obj) {
|
||||
this.log("=== dump(): object is 'undefined' ===");
|
||||
return;
|
||||
}
|
||||
|
@ -266,11 +249,12 @@ var Console = (function () {
|
|||
result.push(JSON.stringify(obj, null, 4));
|
||||
result.push('=== dump(): dumping function names ===');
|
||||
for (var id in obj) {
|
||||
try {
|
||||
if (typeof (obj[id]) == 'function') {
|
||||
try {
|
||||
if (typeof (obj[id]) === 'function') {
|
||||
result.push(id + '()');
|
||||
}
|
||||
} catch (err) {
|
||||
}
|
||||
catch (err) {
|
||||
result.push(id + ': inaccessible');
|
||||
}
|
||||
}
|
||||
|
@ -280,4 +264,3 @@ var Console = (function () {
|
|||
return Console;
|
||||
})();
|
||||
exports.Console = Console;
|
||||
//# sourceMappingURL=console.js.map
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
module.exports = require("console/console");
|
||||
//# sourceMappingURL=index.js.map
|
|
@ -0,0 +1,2 @@
|
|||
{ "name" : "console",
|
||||
"main" : "console.js" }
|
|
@ -0,0 +1,187 @@
|
|||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
var observable = require("data/observable");
|
||||
var ChangeType = (function () {
|
||||
function ChangeType() {
|
||||
}
|
||||
ChangeType.Add = "add";
|
||||
ChangeType.Delete = "delete";
|
||||
ChangeType.Update = "update";
|
||||
ChangeType.Splice = "splice";
|
||||
return ChangeType;
|
||||
})();
|
||||
exports.ChangeType = ChangeType;
|
||||
var CHANGE = "change";
|
||||
var knownEvents;
|
||||
(function (knownEvents) {
|
||||
knownEvents.change = CHANGE;
|
||||
})(knownEvents = exports.knownEvents || (exports.knownEvents = {}));
|
||||
var ObservableArray = (function (_super) {
|
||||
__extends(ObservableArray, _super);
|
||||
function ObservableArray() {
|
||||
_super.call(this);
|
||||
if (arguments.length === 1 && Array.isArray(arguments[0])) {
|
||||
this._array = arguments[0].slice();
|
||||
}
|
||||
else {
|
||||
this._array = Array.apply(null, arguments);
|
||||
}
|
||||
this._addArgs = {
|
||||
eventName: CHANGE,
|
||||
object: this,
|
||||
action: ChangeType.Add,
|
||||
index: null,
|
||||
removed: new Array(),
|
||||
addedCount: 1
|
||||
};
|
||||
this._deleteArgs = {
|
||||
eventName: CHANGE,
|
||||
object: this,
|
||||
action: ChangeType.Delete,
|
||||
index: null,
|
||||
removed: null,
|
||||
addedCount: 0
|
||||
};
|
||||
}
|
||||
ObservableArray.prototype.getItem = function (index) {
|
||||
return this._array[index];
|
||||
};
|
||||
ObservableArray.prototype.setItem = function (index, value) {
|
||||
this._array[index] = value;
|
||||
this.notify({
|
||||
eventName: CHANGE,
|
||||
object: this,
|
||||
action: ChangeType.Update,
|
||||
index: index,
|
||||
removed: new Array(1),
|
||||
addedCount: 1
|
||||
});
|
||||
};
|
||||
Object.defineProperty(ObservableArray.prototype, "length", {
|
||||
get: function () {
|
||||
return this._array.length;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
ObservableArray.prototype.toString = function () {
|
||||
return this._array.toString();
|
||||
};
|
||||
ObservableArray.prototype.toLocaleString = function () {
|
||||
return this._array.toLocaleString();
|
||||
};
|
||||
ObservableArray.prototype.concat = function () {
|
||||
this._addArgs.index = this._array.length;
|
||||
var result = this._array.concat.apply(this._array, arguments);
|
||||
this._addArgs.addedCount = result.length - this._array.length;
|
||||
this.notify(this._addArgs);
|
||||
return result;
|
||||
};
|
||||
ObservableArray.prototype.join = function (separator) {
|
||||
return this._array.join(separator);
|
||||
};
|
||||
ObservableArray.prototype.pop = function () {
|
||||
this._deleteArgs.index = this._array.length - 1;
|
||||
var result = this._array.pop();
|
||||
this._deleteArgs.removed = [result];
|
||||
this.notify(this._deleteArgs);
|
||||
return result;
|
||||
};
|
||||
ObservableArray.prototype.push = function () {
|
||||
this._addArgs.index = this._array.length;
|
||||
if (arguments.length === 1 && Array.isArray(arguments[0])) {
|
||||
var source = arguments[0];
|
||||
for (var i = 0, l = source.length; i < l; i++) {
|
||||
this._array.push(source[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this._array.push.apply(this._array, arguments);
|
||||
}
|
||||
this._addArgs.addedCount = this._array.length - this._addArgs.index;
|
||||
this.notify(this._addArgs);
|
||||
return this._array.length;
|
||||
};
|
||||
ObservableArray.prototype.reverse = function () {
|
||||
return this._array.reverse();
|
||||
};
|
||||
ObservableArray.prototype.shift = function () {
|
||||
var result = this._array.shift();
|
||||
this._deleteArgs.index = 0;
|
||||
this._deleteArgs.removed = [result];
|
||||
this.notify(this._deleteArgs);
|
||||
return result;
|
||||
};
|
||||
ObservableArray.prototype.slice = function (start, end) {
|
||||
return this._array.slice(start, end);
|
||||
};
|
||||
ObservableArray.prototype.sort = function (compareFn) {
|
||||
return this._array.sort(compareFn);
|
||||
};
|
||||
ObservableArray.prototype.splice = function (start, deleteCount) {
|
||||
var length = this._array.length;
|
||||
var result = this._array.splice.apply(this._array, arguments);
|
||||
this.notify({
|
||||
eventName: CHANGE,
|
||||
object: this,
|
||||
action: ChangeType.Splice,
|
||||
index: start,
|
||||
removed: result,
|
||||
addedCount: this._array.length > length ? this._array.length - length : 0
|
||||
});
|
||||
return result;
|
||||
};
|
||||
ObservableArray.prototype.unshift = function () {
|
||||
var length = this._array.length;
|
||||
var result = this._array.unshift.apply(this._array, arguments);
|
||||
this._addArgs.index = 0;
|
||||
this._addArgs.addedCount = result - length;
|
||||
this.notify(this._addArgs);
|
||||
return result;
|
||||
};
|
||||
ObservableArray.prototype.indexOf = function (searchElement, fromIndex) {
|
||||
var index = fromIndex ? fromIndex : 0;
|
||||
for (var i = index, l = this._array.length; i < l; i++) {
|
||||
if (this._array[i] === searchElement) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
ObservableArray.prototype.lastIndexOf = function (searchElement, fromIndex) {
|
||||
var index = fromIndex ? fromIndex : this._array.length - 1;
|
||||
for (var i = index; i >= 0; i--) {
|
||||
if (this._array[i] === searchElement) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
ObservableArray.prototype.every = function (callbackfn, thisArg) {
|
||||
return this._array.every(callbackfn, thisArg);
|
||||
};
|
||||
ObservableArray.prototype.some = function (callbackfn, thisArg) {
|
||||
return this._array.some(callbackfn, thisArg);
|
||||
};
|
||||
ObservableArray.prototype.forEach = function (callbackfn, thisArg) {
|
||||
this._array.forEach(callbackfn, thisArg);
|
||||
};
|
||||
ObservableArray.prototype.map = function (callbackfn, thisArg) {
|
||||
return this._array.map(callbackfn, thisArg);
|
||||
};
|
||||
ObservableArray.prototype.filter = function (callbackfn, thisArg) {
|
||||
return this._array.filter(callbackfn, thisArg);
|
||||
};
|
||||
ObservableArray.prototype.reduce = function (callbackfn, initialValue) {
|
||||
return this._array.reduce(callbackfn, initialValue);
|
||||
};
|
||||
ObservableArray.prototype.reduceRight = function (callbackfn, initialValue) {
|
||||
return this._array.reduceRight(callbackfn, initialValue);
|
||||
};
|
||||
return ObservableArray;
|
||||
})(observable.Observable);
|
||||
exports.ObservableArray = ObservableArray;
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"name" : "observable-array",
|
||||
"main" : "observable-array.js"
|
||||
}
|
|
@ -0,0 +1,140 @@
|
|||
var types = require("utils/types");
|
||||
var knownEvents;
|
||||
(function (knownEvents) {
|
||||
knownEvents.propertyChange = "propertyChange";
|
||||
})(knownEvents = exports.knownEvents || (exports.knownEvents = {}));
|
||||
var Observable = (function () {
|
||||
function Observable() {
|
||||
this._observers = {};
|
||||
}
|
||||
Object.defineProperty(Observable.prototype, "typeName", {
|
||||
get: function () {
|
||||
return types.getClass(this);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Observable.prototype.on = function (eventNames, callback, thisArg) {
|
||||
this.addEventListener(eventNames, callback, thisArg);
|
||||
};
|
||||
Observable.prototype.off = function (eventNames, callback) {
|
||||
this.removeEventListener(eventNames, callback);
|
||||
};
|
||||
Observable.prototype.addEventListener = function (eventNames, callback, thisArg) {
|
||||
types.verifyCallback(callback);
|
||||
var events = eventNames.split(",");
|
||||
for (var i = 0, l = events.length; i < l; i++) {
|
||||
var event = events[i].trim();
|
||||
var list = this._getEventList(event, true);
|
||||
list.push({
|
||||
callback: callback,
|
||||
thisArg: thisArg
|
||||
});
|
||||
}
|
||||
};
|
||||
Observable.prototype.removeEventListener = function (eventNames, callback, thisArg) {
|
||||
var events = eventNames.split(",");
|
||||
for (var i = 0, l = events.length; i < l; i++) {
|
||||
var event = events[i].trim();
|
||||
if (callback) {
|
||||
var list = this._getEventList(event, false);
|
||||
if (list) {
|
||||
var index = this._indexOfListener(list, callback, thisArg);
|
||||
if (index >= 0) {
|
||||
list.splice(index, 1);
|
||||
}
|
||||
if (list.length === 0) {
|
||||
delete this._observers[event];
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
this._observers[event] = undefined;
|
||||
delete this._observers[event];
|
||||
}
|
||||
}
|
||||
};
|
||||
Observable.prototype.set = function (name, value) {
|
||||
if (this[name] === value) {
|
||||
return;
|
||||
}
|
||||
var data = this._createPropertyChangeData(name, value);
|
||||
this._setCore(data);
|
||||
this.notify(data);
|
||||
};
|
||||
Observable.prototype.get = function (name) {
|
||||
return this[name];
|
||||
};
|
||||
Observable.prototype._setCore = function (data) {
|
||||
this[data.propertyName] = data.value;
|
||||
};
|
||||
Observable.prototype.notify = function (data) {
|
||||
var observers = this._getEventList(data.eventName);
|
||||
if (!observers) {
|
||||
return;
|
||||
}
|
||||
var i;
|
||||
var entry;
|
||||
for (i = 0; i < observers.length; i++) {
|
||||
entry = observers[i];
|
||||
if (entry.thisArg) {
|
||||
entry.callback.apply(entry.thisArg, [data]);
|
||||
}
|
||||
else {
|
||||
entry.callback(data);
|
||||
}
|
||||
}
|
||||
};
|
||||
Observable.prototype.hasListeners = function (eventName) {
|
||||
return eventName in this._observers;
|
||||
};
|
||||
Observable.prototype._createPropertyChangeData = function (name, value) {
|
||||
return {
|
||||
eventName: knownEvents.propertyChange,
|
||||
propertyName: name,
|
||||
object: this,
|
||||
value: value
|
||||
};
|
||||
};
|
||||
Observable.prototype._emit = function (eventNames) {
|
||||
var events = eventNames.split(",");
|
||||
for (var i = 0, l = events.length; i < l; i++) {
|
||||
var event = events[i].trim();
|
||||
this.notify({ eventName: event, object: this });
|
||||
}
|
||||
};
|
||||
Observable.prototype._getEventList = function (eventName, createIfNeeded) {
|
||||
if (!eventName) {
|
||||
throw new TypeError("EventName must be valid string.");
|
||||
}
|
||||
var list = this._observers[eventName];
|
||||
if (!list && createIfNeeded) {
|
||||
list = [];
|
||||
this._observers[eventName] = list;
|
||||
}
|
||||
return list;
|
||||
};
|
||||
Observable.prototype._indexOfListener = function (list, callback, thisArg) {
|
||||
var i;
|
||||
var entry;
|
||||
for (i = 0; i < list.length; i++) {
|
||||
entry = list[i];
|
||||
if (thisArg) {
|
||||
if (entry.callback === callback && entry.thisArg === thisArg) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (entry.callback === callback) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
Observable.prototype.toString = function () {
|
||||
return this.typeName;
|
||||
};
|
||||
return Observable;
|
||||
})();
|
||||
exports.Observable = Observable;
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"name" : "observable",
|
||||
"main" : "observable.js"
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"name" : "virtual-array",
|
||||
"main" : "virtual-array.js"
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
var observable = require("data/observable");
|
||||
var types = require("utils/types");
|
||||
var CHANGE = "change", UPDATE = "update", DELETE = "delete", ADD = "add";
|
||||
var knownEvents;
|
||||
(function (knownEvents) {
|
||||
knownEvents.itemsLoading = "itemsLoading";
|
||||
knownEvents.change = "change";
|
||||
})(knownEvents = exports.knownEvents || (exports.knownEvents = {}));
|
||||
var ChangeType = (function () {
|
||||
function ChangeType() {
|
||||
}
|
||||
ChangeType.Add = "add";
|
||||
ChangeType.Delete = "delete";
|
||||
ChangeType.Update = "update";
|
||||
ChangeType.Splice = "splice";
|
||||
return ChangeType;
|
||||
})();
|
||||
exports.ChangeType = ChangeType;
|
||||
var VirtualArray = (function (_super) {
|
||||
__extends(VirtualArray, _super);
|
||||
function VirtualArray(length) {
|
||||
if (length === void 0) { length = 0; }
|
||||
_super.call(this);
|
||||
this._length = length;
|
||||
this._cache = {};
|
||||
this._requestedIndexes = [];
|
||||
this._loadedIndexes = [];
|
||||
}
|
||||
Object.defineProperty(VirtualArray.prototype, "length", {
|
||||
get: function () {
|
||||
return this._length;
|
||||
},
|
||||
set: function (value) {
|
||||
if (this._length !== value) {
|
||||
var index = this._length;
|
||||
var count = value - this._length;
|
||||
this._length = value;
|
||||
this.notify({
|
||||
eventName: CHANGE,
|
||||
object: this,
|
||||
action: count > 0 ? ADD : DELETE,
|
||||
index: index,
|
||||
removed: new Array(count < 0 ? Math.abs(count) : 0),
|
||||
addedCount: count > 0 ? count : 0
|
||||
});
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(VirtualArray.prototype, "loadSize", {
|
||||
get: function () {
|
||||
return this._loadSize;
|
||||
},
|
||||
set: function (value) {
|
||||
this._loadSize = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
VirtualArray.prototype.getItem = function (index) {
|
||||
var item = this._cache[index];
|
||||
if (types.isUndefined(item)) {
|
||||
if (index >= 0 && index < this.length && this._requestedIndexes.indexOf(index) < 0 && this._loadedIndexes.indexOf(index) < 0) {
|
||||
this.requestItems(index);
|
||||
}
|
||||
}
|
||||
return item;
|
||||
};
|
||||
VirtualArray.prototype.setItem = function (index, value) {
|
||||
if (this._cache[index] !== value) {
|
||||
this.load(index, [value]);
|
||||
}
|
||||
};
|
||||
VirtualArray.prototype.load = function (index, items) {
|
||||
var i;
|
||||
for (i = 0; i < items.length; i++) {
|
||||
var itemIndex = index + i;
|
||||
this._cache[itemIndex] = items[i];
|
||||
this._requestedIndexes.splice(this._requestedIndexes.indexOf(itemIndex), 1);
|
||||
if (this._loadedIndexes.indexOf(itemIndex) < 0) {
|
||||
this._loadedIndexes.push(itemIndex);
|
||||
}
|
||||
}
|
||||
if (this._requestedIndexes.length > 0) {
|
||||
for (i = 0; i < this.loadSize - items.length; i++) {
|
||||
this._requestedIndexes.splice(this._requestedIndexes.indexOf(index + i), 1);
|
||||
}
|
||||
}
|
||||
this.notify({
|
||||
eventName: CHANGE,
|
||||
object: this,
|
||||
action: UPDATE,
|
||||
index: index,
|
||||
removed: new Array(items.length),
|
||||
addedCount: items.length
|
||||
});
|
||||
};
|
||||
VirtualArray.prototype.requestItems = function (index) {
|
||||
var indexesToLoad = [];
|
||||
var pageIndex = this._loadSize > 0 ? this._loadSize * Math.floor(index / this._loadSize) : index;
|
||||
var count = 0;
|
||||
var start = -1;
|
||||
for (var i = 0; i < this.loadSize; i++) {
|
||||
var itemIndex = pageIndex + i;
|
||||
if (itemIndex >= this._length) {
|
||||
break;
|
||||
}
|
||||
if (this._loadedIndexes.indexOf(itemIndex) < 0) {
|
||||
if (start < 0) {
|
||||
start = itemIndex;
|
||||
}
|
||||
indexesToLoad.push(itemIndex);
|
||||
if (this._requestedIndexes.indexOf(itemIndex) < 0) {
|
||||
this._requestedIndexes.push(itemIndex);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
else {
|
||||
if (count > 0) {
|
||||
this.notify({
|
||||
eventName: knownEvents.itemsLoading,
|
||||
object: this,
|
||||
index: start,
|
||||
count: count
|
||||
});
|
||||
}
|
||||
start = -1;
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
if (start >= 0 && count > 0) {
|
||||
this.notify({
|
||||
eventName: knownEvents.itemsLoading,
|
||||
object: this,
|
||||
index: start,
|
||||
count: count
|
||||
});
|
||||
}
|
||||
};
|
||||
return VirtualArray;
|
||||
})(observable.Observable);
|
||||
exports.VirtualArray = VirtualArray;
|
|
@ -1,6 +1,6 @@
|
|||
var appModule = require("application");
|
||||
var textModule = require("text/text");
|
||||
|
||||
var appModule = require("application");
|
||||
var textModule = require("text");
|
||||
var types = require("utils/types");
|
||||
var FileSystemAccess = (function () {
|
||||
function FileSystemAccess() {
|
||||
this._pathSeparator = java.io.File.separator.toString();
|
||||
|
@ -9,278 +9,243 @@ var FileSystemAccess = (function () {
|
|||
var javaFile = new java.io.File(path);
|
||||
return new Date(javaFile.lastModified());
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.getParent = function (path, onError) {
|
||||
try {
|
||||
try {
|
||||
var javaFile = new java.io.File(path);
|
||||
var parent = javaFile.getParentFile();
|
||||
|
||||
return { path: parent.getAbsolutePath(), name: parent.getName() };
|
||||
} catch (exception) {
|
||||
}
|
||||
catch (exception) {
|
||||
if (onError) {
|
||||
onError(exception);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.getFile = function (path, onError) {
|
||||
return this.ensureFile(new java.io.File(path), false, onError);
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.getFolder = function (path, onError) {
|
||||
var javaFile = new java.io.File(path);
|
||||
var dirInfo = this.ensureFile(javaFile, true, onError);
|
||||
if (!dirInfo) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return { path: dirInfo.path, name: dirInfo.name };
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.eachEntity = function (path, onEntity, onError) {
|
||||
if (!onEntity) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.enumEntities(path, onEntity, onError);
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.getEntities = function (path, onSuccess, onError) {
|
||||
if (!onSuccess) {
|
||||
return;
|
||||
}
|
||||
|
||||
var fileInfos = new Array();
|
||||
var onEntity = function (entity) {
|
||||
fileInfos.push(entity);
|
||||
return true;
|
||||
};
|
||||
|
||||
var errorOccurred;
|
||||
var localError = function (error) {
|
||||
if (onError) {
|
||||
onError(error);
|
||||
}
|
||||
|
||||
errorOccurred = true;
|
||||
};
|
||||
|
||||
this.enumEntities(path, onEntity, localError);
|
||||
|
||||
if (!errorOccurred) {
|
||||
onSuccess(fileInfos);
|
||||
}
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.fileExists = function (path) {
|
||||
var file = new java.io.File(path);
|
||||
return file.exists();
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.folderExists = function (path) {
|
||||
var file = new java.io.File(path);
|
||||
var exists = file.exists();
|
||||
var dir = file.isDirectory();
|
||||
var isFile = file.isFile();
|
||||
var hidden = file.isHidden();
|
||||
|
||||
return exists && dir;
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.deleteFile = function (path, onSuccess, onError) {
|
||||
try {
|
||||
try {
|
||||
var javaFile = new java.io.File(path);
|
||||
if (!javaFile.isFile()) {
|
||||
if (onError) {
|
||||
onError({ message: "The specified parameter is not a File entity." });
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!javaFile.delete()) {
|
||||
if (onError) {
|
||||
onError({ message: "File deletion failed" });
|
||||
}
|
||||
} else if (onSuccess) {
|
||||
}
|
||||
else if (onSuccess) {
|
||||
onSuccess();
|
||||
}
|
||||
} catch (exception) {
|
||||
}
|
||||
catch (exception) {
|
||||
if (onError) {
|
||||
onError(exception);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.deleteFolder = function (path, isKnown, onSuccess, onError) {
|
||||
try {
|
||||
try {
|
||||
var javaFile = new java.io.File(path);
|
||||
if (!javaFile.getCanonicalFile().isDirectory()) {
|
||||
if (onError) {
|
||||
onError({ message: "The specified parameter is not a Folder entity." });
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.deleteFolderContent(javaFile);
|
||||
|
||||
if (!isKnown) {
|
||||
if (javaFile.delete()) {
|
||||
if (onSuccess) {
|
||||
onSuccess();
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (onError) {
|
||||
onError({ message: "Folder deletion failed." });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
} catch (exception) {
|
||||
else {
|
||||
}
|
||||
}
|
||||
catch (exception) {
|
||||
if (onError) {
|
||||
onError(exception);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.emptyFolder = function (path, onSuccess, onError) {
|
||||
try {
|
||||
try {
|
||||
var javaFile = new java.io.File(path);
|
||||
if (!javaFile.getCanonicalFile().isDirectory()) {
|
||||
if (onError) {
|
||||
onError({ message: "The specified parameter is not a Folder entity." });
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.deleteFolderContent(javaFile);
|
||||
|
||||
if (onSuccess) {
|
||||
onSuccess();
|
||||
}
|
||||
} catch (exception) {
|
||||
}
|
||||
catch (exception) {
|
||||
if (onError) {
|
||||
onError(exception);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.rename = function (path, newPath, onSuccess, onError) {
|
||||
var javaFile = new java.io.File(path);
|
||||
if (!javaFile.exists()) {
|
||||
if (onError) {
|
||||
onError(new Error("The file to rename does not exist"));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var newFile = new java.io.File(newPath);
|
||||
if (newFile.exists()) {
|
||||
if (onError) {
|
||||
onError(new Error("A file with the same name already exists."));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!javaFile.renameTo(newFile)) {
|
||||
if (onError) {
|
||||
onError(new Error("Failed to rename file '" + path + "' to '" + newPath + "'"));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (onSuccess) {
|
||||
onSuccess();
|
||||
}
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.getDocumentsFolderPath = function () {
|
||||
var context = appModule.android.context;
|
||||
var dir = context.getFilesDir();
|
||||
return dir.getAbsolutePath();
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.getTempFolderPath = function () {
|
||||
var context = appModule.android.context;
|
||||
var dir = context.getCacheDir();
|
||||
return dir.getAbsolutePath();
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.readText = function (path, onSuccess, onError, encoding) {
|
||||
try {
|
||||
try {
|
||||
var javaFile = new java.io.File(path);
|
||||
var stream = new java.io.FileInputStream(javaFile);
|
||||
|
||||
var actualEncoding = encoding;
|
||||
if (!actualEncoding) {
|
||||
actualEncoding = textModule.encoding.UTF_8;
|
||||
}
|
||||
var reader = new java.io.InputStreamReader(stream, actualEncoding);
|
||||
var bufferedReader = new java.io.BufferedReader(reader);
|
||||
|
||||
var line = undefined;
|
||||
var result = "";
|
||||
while (true) {
|
||||
line = bufferedReader.readLine();
|
||||
if (!line) {
|
||||
if (types.isUndefined(line)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (result.length > 0) {
|
||||
result += "\n";
|
||||
}
|
||||
|
||||
result += line;
|
||||
}
|
||||
|
||||
if (actualEncoding === textModule.encoding.UTF_8) {
|
||||
result = FileSystemAccess._removeUtf8Bom(result);
|
||||
}
|
||||
bufferedReader.close();
|
||||
|
||||
if (onSuccess) {
|
||||
onSuccess(result);
|
||||
}
|
||||
} catch (exception) {
|
||||
}
|
||||
catch (exception) {
|
||||
if (onError) {
|
||||
onError(exception);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
FileSystemAccess._removeUtf8Bom = function (s) {
|
||||
if (s.charCodeAt(0) === 0xFEFF) {
|
||||
s = s.slice(1);
|
||||
}
|
||||
return s;
|
||||
};
|
||||
FileSystemAccess.prototype.writeText = function (path, content, onSuccess, onError, encoding) {
|
||||
try {
|
||||
try {
|
||||
var javaFile = new java.io.File(path);
|
||||
var stream = new java.io.FileOutputStream(javaFile);
|
||||
|
||||
var actualEncoding = encoding;
|
||||
if (!actualEncoding) {
|
||||
actualEncoding = textModule.encoding.UTF_8;
|
||||
}
|
||||
var writer = new java.io.OutputStreamWriter(stream, actualEncoding);
|
||||
|
||||
writer.write(content);
|
||||
writer.close();
|
||||
|
||||
if (onSuccess) {
|
||||
onSuccess();
|
||||
}
|
||||
} catch (exception) {
|
||||
}
|
||||
catch (exception) {
|
||||
if (onError) {
|
||||
onError(exception);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.deleteFolderContent = function (file) {
|
||||
var filesList = file.listFiles();
|
||||
|
||||
var i, childFile, success = false;
|
||||
|
||||
for (i = 0; i < filesList.length; i++) {
|
||||
childFile = filesList[i];
|
||||
if (childFile.getCanonicalFile().isDirectory()) {
|
||||
|
@ -289,126 +254,108 @@ var FileSystemAccess = (function () {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
success = childFile.delete();
|
||||
}
|
||||
|
||||
return success;
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.ensureFile = function (javaFile, isFolder, onError) {
|
||||
try {
|
||||
try {
|
||||
if (!javaFile.exists()) {
|
||||
var created;
|
||||
if (isFolder) {
|
||||
created = javaFile.mkdirs();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
created = javaFile.createNewFile();
|
||||
}
|
||||
|
||||
if (!created) {
|
||||
if (onError) {
|
||||
onError("Failed to create new java File for path " + javaFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
return undefined;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
javaFile.setReadable(true);
|
||||
javaFile.setWritable(true);
|
||||
}
|
||||
}
|
||||
|
||||
var path = javaFile.getAbsolutePath();
|
||||
return { path: path, name: javaFile.getName(), extension: this.getFileExtension(path) };
|
||||
} catch (exception) {
|
||||
}
|
||||
catch (exception) {
|
||||
if (onError) {
|
||||
onError(exception);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.getFileExtension = function (path) {
|
||||
var dotIndex = path.lastIndexOf(".");
|
||||
if (dotIndex && dotIndex >= 0 && dotIndex < path.length) {
|
||||
return path.substring(dotIndex);
|
||||
}
|
||||
|
||||
return "";
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.enumEntities = function (path, callback, onError) {
|
||||
try {
|
||||
try {
|
||||
var javaFile = new java.io.File(path);
|
||||
if (!javaFile.getCanonicalFile().isDirectory()) {
|
||||
if (onError) {
|
||||
onError("There is no folder existing at path " + path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var filesList = javaFile.listFiles();
|
||||
var length = filesList.length, i, filePath, info, retVal;
|
||||
|
||||
var length = filesList.length;
|
||||
var i;
|
||||
var info;
|
||||
var retVal;
|
||||
for (i = 0; i < length; i++) {
|
||||
javaFile = filesList[i];
|
||||
|
||||
info = {
|
||||
path: javaFile.getAbsolutePath(),
|
||||
name: javaFile.getName()
|
||||
};
|
||||
|
||||
if (javaFile.isFile()) {
|
||||
info.extension = this.getFileExtension(info.path);
|
||||
}
|
||||
|
||||
retVal = callback(info);
|
||||
if (retVal === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (exception) {
|
||||
}
|
||||
catch (exception) {
|
||||
if (onError) {
|
||||
onError(exception);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.getPathSeparator = function () {
|
||||
return this._pathSeparator;
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.normalizePath = function (path) {
|
||||
var file = new java.io.File(path);
|
||||
return file.getAbsolutePath();
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.joinPath = function (left, right) {
|
||||
var file1 = new java.io.File(left);
|
||||
var file2 = new java.io.File(file1, right);
|
||||
|
||||
return file2.getAbsolutePath();
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.joinPaths = function (paths) {
|
||||
if (!paths || paths.length === 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (paths.length === 1) {
|
||||
return paths[0];
|
||||
}
|
||||
|
||||
var i, result = paths[0];
|
||||
for (i = 1; i < paths.length; i++) {
|
||||
result = this.joinPath(result, paths[i]);
|
||||
}
|
||||
|
||||
return this.normalizePath(result);
|
||||
};
|
||||
return FileSystemAccess;
|
||||
})();
|
||||
exports.FileSystemAccess = FileSystemAccess;
|
||||
//# sourceMappingURL=file-system-access.android.js.map
|
||||
|
|
|
@ -1,183 +1,143 @@
|
|||
var utilsModule = require("utils/utils_ios");
|
||||
var textModule = require("text/text");
|
||||
|
||||
var utilsModule = require("utils/utils");
|
||||
var textModule = require("text");
|
||||
var FileSystemAccess = (function () {
|
||||
function FileSystemAccess() {
|
||||
this.keyFileType = "NSFileType";
|
||||
this.keyModificationTime = "NSFileModificationDate";
|
||||
this.keyReadonly = "NSFileImmutable";
|
||||
this.documentDir = 9;
|
||||
this.cachesDir = 13;
|
||||
this.userDomain = 1;
|
||||
this.NSUTF8StringEncoding = 4;
|
||||
}
|
||||
FileSystemAccess.prototype.getLastModified = function (path) {
|
||||
var fileManager = Foundation.NSFileManager.defaultManager();
|
||||
var fileManager = NSFileManager.defaultManager();
|
||||
var attributes = fileManager.attributesOfItemAtPathError(path, null);
|
||||
|
||||
if (attributes) {
|
||||
var date = attributes.objectForKey(this.keyModificationTime);
|
||||
var interval = date.timeIntervalSince1970();
|
||||
|
||||
return new Date(interval * 1000);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return new Date();
|
||||
}
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.getParent = function (path, onError) {
|
||||
try {
|
||||
var fileManager = Foundation.NSFileManager.defaultManager();
|
||||
var nsString = Foundation.NSString.initWithString(path);
|
||||
|
||||
var parentPath = nsString.stringByDeletingLastPathComponent();
|
||||
try {
|
||||
var fileManager = NSFileManager.defaultManager();
|
||||
var nsString = NSString.alloc().initWithString(path);
|
||||
var parentPath = nsString.stringByDeletingLastPathComponent;
|
||||
var name = fileManager.displayNameAtPath(parentPath);
|
||||
|
||||
return {
|
||||
path: parentPath.toString(),
|
||||
name: name
|
||||
};
|
||||
} catch (exception) {
|
||||
}
|
||||
catch (exception) {
|
||||
if (onError) {
|
||||
onError(exception);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.getFile = function (path, onError) {
|
||||
try {
|
||||
var fileManager = Foundation.NSFileManager.defaultManager();
|
||||
try {
|
||||
var fileManager = NSFileManager.defaultManager();
|
||||
var exists = fileManager.fileExistsAtPath(path);
|
||||
|
||||
if (!exists) {
|
||||
if (!fileManager.createFileAtPathContentsAttributes(path, null, null)) {
|
||||
if (onError) {
|
||||
onError(new Error("Failed to create folder at path '" + path + "'"));
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
var fileName = fileManager.displayNameAtPath(path);
|
||||
|
||||
return {
|
||||
path: path,
|
||||
name: fileName,
|
||||
extension: this.getFileExtension(path)
|
||||
};
|
||||
} catch (exception) {
|
||||
}
|
||||
catch (exception) {
|
||||
if (onError) {
|
||||
onError(exception);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.getFolder = function (path, onError) {
|
||||
try {
|
||||
var fileManager = Foundation.NSFileManager.defaultManager();
|
||||
try {
|
||||
var fileManager = NSFileManager.defaultManager();
|
||||
var exists = this.folderExists(path);
|
||||
|
||||
if (!exists) {
|
||||
if (!fileManager.createDirectoryAtPathWithIntermediateDirectoriesAttributesError(path, true, null, null)) {
|
||||
if (onError) {
|
||||
onError(new Error("Failed to create folder at path '" + path + "'"));
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
var dirName = fileManager.displayNameAtPath(path);
|
||||
|
||||
return {
|
||||
path: path,
|
||||
name: dirName
|
||||
};
|
||||
} catch (ex) {
|
||||
}
|
||||
catch (ex) {
|
||||
if (onError) {
|
||||
onError(new Error("Failed to create folder at path '" + path + "'"));
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.eachEntity = function (path, onEntity, onError) {
|
||||
if (!onEntity) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.enumEntities(path, onEntity, onError);
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.getEntities = function (path, onSuccess, onError) {
|
||||
if (!onSuccess) {
|
||||
return;
|
||||
}
|
||||
|
||||
var fileInfos = new Array();
|
||||
var onEntity = function (entity) {
|
||||
fileInfos.push(entity);
|
||||
return true;
|
||||
};
|
||||
|
||||
var errorOccurred;
|
||||
var localError = function (error) {
|
||||
if (onError) {
|
||||
onError(error);
|
||||
}
|
||||
|
||||
errorOccurred = true;
|
||||
};
|
||||
|
||||
this.enumEntities(path, onEntity, onError);
|
||||
|
||||
this.enumEntities(path, onEntity, localError);
|
||||
if (!errorOccurred) {
|
||||
onSuccess(fileInfos);
|
||||
}
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.fileExists = function (path) {
|
||||
var fileManager = Foundation.NSFileManager.defaultManager();
|
||||
var fileManager = NSFileManager.defaultManager();
|
||||
return fileManager.fileExistsAtPath(path);
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.folderExists = function (path) {
|
||||
var fileManager = Foundation.NSFileManager.defaultManager();
|
||||
|
||||
var buffer = NativePointer.create(PrimitiveType.BOOL, 1);
|
||||
var exists = fileManager.fileExistsAtPathIsDirectory(path, buffer);
|
||||
|
||||
var isDir = buffer[0] && buffer[0] > 0;
|
||||
|
||||
buffer.delete();
|
||||
|
||||
return exists && isDir;
|
||||
var fileManager = NSFileManager.defaultManager();
|
||||
var outVal = new interop.Reference();
|
||||
var exists = fileManager.fileExistsAtPathIsDirectory(path, outVal);
|
||||
return exists && outVal.value > 0;
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.concatPath = function (left, right) {
|
||||
var nsArray = utilsModule.Collections.jsArrayToNSArray([left, right]);
|
||||
var nsString = Foundation.NSString.pathWithComponents(nsArray);
|
||||
|
||||
var nsArray = utilsModule.ios.collections.jsArrayToNSArray([left, right]);
|
||||
var nsString = NSString.pathWithComponents(nsArray);
|
||||
return nsString.toString();
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.deleteFile = function (path, onSuccess, onError) {
|
||||
this.deleteEntity(path, onSuccess, onError);
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.deleteFolder = function (path, isKnown, onSuccess, onError) {
|
||||
this.deleteEntity(path, onSuccess, onError);
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.emptyFolder = function (path, onSuccess, onError) {
|
||||
var fileManager = Foundation.NSFileManager.defaultManager();
|
||||
|
||||
var fileManager = NSFileManager.defaultManager();
|
||||
var filesEnum = function (files) {
|
||||
var i;
|
||||
for (i = 0; i < files.length; i++) {
|
||||
|
@ -185,173 +145,147 @@ var FileSystemAccess = (function () {
|
|||
if (onError) {
|
||||
onError(new Error("Failed to empty folder '" + path + "'"));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (onSuccess) {
|
||||
onSuccess();
|
||||
}
|
||||
};
|
||||
|
||||
this.getEntities(path, filesEnum, onError);
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.rename = function (path, newPath, onSuccess, onError) {
|
||||
var fileManager = Foundation.NSFileManager.defaultManager();
|
||||
var fileManager = NSFileManager.defaultManager();
|
||||
if (!fileManager.moveItemAtPathToPathError(path, newPath, null)) {
|
||||
if (onError) {
|
||||
onError(new Error("Failed to rename '" + path + "' to '" + newPath + "'"));
|
||||
}
|
||||
} else if (onSuccess) {
|
||||
}
|
||||
else if (onSuccess) {
|
||||
onSuccess();
|
||||
}
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.getDocumentsFolderPath = function () {
|
||||
return this.getKnownPath(this.documentDir);
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.getTempFolderPath = function () {
|
||||
return this.getKnownPath(this.cachesDir);
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.readText = function (path, onSuccess, onError, encoding) {
|
||||
var actualEncoding = encoding;
|
||||
if (!actualEncoding) {
|
||||
actualEncoding = textModule.encoding.UTF_8;
|
||||
}
|
||||
|
||||
var nsString = Foundation.NSString.stringWithContentsOfFileEncodingError(path, actualEncoding, null);
|
||||
var nsString = NSString.stringWithContentsOfFileEncodingError(path, actualEncoding, null);
|
||||
if (!nsString) {
|
||||
if (onError) {
|
||||
onError(new Error("Failed to read file at path '" + path + "'"));
|
||||
}
|
||||
} else if (onSuccess) {
|
||||
}
|
||||
else if (onSuccess) {
|
||||
onSuccess(nsString.toString());
|
||||
}
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.writeText = function (path, content, onSuccess, onError, encoding) {
|
||||
var nsString = Foundation.NSString.initWithString(content);
|
||||
|
||||
var nsString = NSString.alloc().initWithString(content);
|
||||
var actualEncoding = encoding;
|
||||
if (!actualEncoding) {
|
||||
actualEncoding = textModule.encoding.UTF_8;
|
||||
}
|
||||
|
||||
if (!nsString.writeToFileAtomicallyEncodingError(path, false, actualEncoding, null)) {
|
||||
if (onError) {
|
||||
onError(new Error("Failed to write to file '" + path + "'"));
|
||||
}
|
||||
} else if (onSuccess) {
|
||||
}
|
||||
else if (onSuccess) {
|
||||
onSuccess();
|
||||
}
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.getKnownPath = function (folderType) {
|
||||
var fileManager = Foundation.NSFileManager.defaultManager();
|
||||
var fileManager = NSFileManager.defaultManager();
|
||||
var paths = fileManager.URLsForDirectoryInDomains(folderType, this.userDomain);
|
||||
|
||||
var url = paths.objectAtIndex(0);
|
||||
return url.path();
|
||||
return url.path;
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.getFileExtension = function (path) {
|
||||
var dotIndex = path.lastIndexOf(".");
|
||||
if (dotIndex && dotIndex >= 0 && dotIndex < path.length) {
|
||||
return path.substring(dotIndex);
|
||||
}
|
||||
|
||||
return "";
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.deleteEntity = function (path, onSuccess, onError) {
|
||||
var fileManager = Foundation.NSFileManager.defaultManager();
|
||||
var fileManager = NSFileManager.defaultManager();
|
||||
if (!fileManager.removeItemAtPathError(path, null)) {
|
||||
if (onError) {
|
||||
onError(new Error("Failed to delete file at path '" + path + "'"));
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (onSuccess) {
|
||||
onSuccess();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.enumEntities = function (path, callback, onError) {
|
||||
try {
|
||||
var fileManager = Foundation.NSFileManager.defaultManager();
|
||||
try {
|
||||
var fileManager = NSFileManager.defaultManager();
|
||||
var files = fileManager.contentsOfDirectoryAtPathError(path, null);
|
||||
|
||||
if (!files) {
|
||||
if (onError) {
|
||||
onError(new Error("Failed to enum files for forlder '" + path + "'"));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var fileInfos = new Array();
|
||||
var file, i, info, retVal;
|
||||
|
||||
for (i = 0; i < files.count(); i++) {
|
||||
var file;
|
||||
var i;
|
||||
var info;
|
||||
var retVal;
|
||||
for (i = 0; i < files.count; i++) {
|
||||
file = files.objectAtIndex(i);
|
||||
|
||||
info = {
|
||||
path: this.concatPath(path, file),
|
||||
name: file
|
||||
};
|
||||
|
||||
if (!this.folderExists(file)) {
|
||||
info.extension = this.getFileExtension(info.path);
|
||||
}
|
||||
|
||||
retVal = callback(info);
|
||||
if (retVal === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (ex) {
|
||||
}
|
||||
catch (ex) {
|
||||
if (onError) {
|
||||
onError(ex);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.getPathSeparator = function () {
|
||||
return "/";
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.normalizePath = function (path) {
|
||||
var nsString = Foundation.NSString.stringWithString(path);
|
||||
var normalized = nsString.stringByStandardizingPath();
|
||||
|
||||
var nsString = NSString.stringWithString(path);
|
||||
var normalized = nsString.stringByStandardizingPath;
|
||||
return normalized;
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.joinPath = function (left, right) {
|
||||
var nsString = Foundation.NSString.stringWithString(left);
|
||||
var nsString = NSString.stringWithString(left);
|
||||
return nsString.stringByAppendingPathComponent(right);
|
||||
};
|
||||
|
||||
FileSystemAccess.prototype.joinPaths = function (paths) {
|
||||
if (!paths || paths.length === 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
var nsArray = new Foundation.NSMutableArray(paths.length);
|
||||
|
||||
var nsArray = NSMutableArray.alloc().initWithCapacity(paths.length);
|
||||
var i;
|
||||
for (i = 0; i < paths.length; i++) {
|
||||
nsArray.addObject(paths[i]);
|
||||
}
|
||||
|
||||
var nsString = Foundation.NSString.stringWithString(Foundation.NSString.pathWithComponents(nsArray));
|
||||
return nsString.stringByStandardizingPath();
|
||||
var nsString = NSString.stringWithString(NSString.pathWithComponents(nsArray));
|
||||
return nsString.stringByStandardizingPath;
|
||||
};
|
||||
return FileSystemAccess;
|
||||
})();
|
||||
exports.FileSystemAccess = FileSystemAccess;
|
||||
//# sourceMappingURL=file-system-access.ios.js.map
|
||||
|
|
|
@ -1,177 +0,0 @@
|
|||
|
||||
declare module "file-system" {
|
||||
|
||||
import promises = require("promises");
|
||||
|
||||
/**
|
||||
* Represents a single entity on the file system.
|
||||
*/
|
||||
export class FileSystemEntity {
|
||||
/**
|
||||
* Gets the Date object specifying the last time this entity was modified.
|
||||
*/
|
||||
public lastModified: Date;
|
||||
|
||||
/**
|
||||
* Gets the name of the entity.
|
||||
*/
|
||||
public name: string;
|
||||
|
||||
/**
|
||||
* Gets the fully-qualified path (including the extension for a File) of the entity.
|
||||
*/
|
||||
public path: string;
|
||||
|
||||
/**
|
||||
* Gets the Folder object representing the parent of this entity.
|
||||
* Will be null for a root folder like Documents or Temporary.
|
||||
* This property is readonly.
|
||||
*/
|
||||
public parent: Folder;
|
||||
|
||||
/**
|
||||
* Removes (deletes) the current Entity from the file system.
|
||||
*/
|
||||
public remove(): promises.Promise<any>;
|
||||
|
||||
/**
|
||||
* Renames the current entity using the specified name.
|
||||
* @param newName The new name to be applied to the entity.
|
||||
*/
|
||||
public rename(newName: string): promises.Promise<any>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a File entity on the file system.
|
||||
*/
|
||||
export class File extends FileSystemEntity {
|
||||
/**
|
||||
* Checks whether a File with the specified path already exists.
|
||||
* @param path The path to check for.
|
||||
*/
|
||||
public static exists(path: string): boolean;
|
||||
|
||||
/**
|
||||
* Gets the extension of the file.
|
||||
*/
|
||||
public extension: string;
|
||||
|
||||
/**
|
||||
* Gets a value indicating whether the file is currently locked, meaning a background operation associated with this file is running.
|
||||
*/
|
||||
public isLocked: boolean;
|
||||
|
||||
/**
|
||||
* Gets or creates a File entity at the specified path.
|
||||
* @param path The path to get/create the file at.
|
||||
*/
|
||||
public static fromPath(path: string): File;
|
||||
|
||||
/**
|
||||
* Reads the content of the file as a string using the specified encoding (defaults to UTF-8).
|
||||
* @param encoding An optional value specifying the preferred encoding (defaults to UTF-8).
|
||||
*/
|
||||
public readText(encoding?: string): promises.Promise<string>;
|
||||
|
||||
/**
|
||||
* Writes the provided string to the file, using the specified encoding (defaults to UTF-8).
|
||||
* @param content The content to be saved to the file.
|
||||
* @param encoding An optional value specifying the preferred encoding (defaults to UTF-8).
|
||||
*/
|
||||
public writeText(content: string, encoding?: string): promises.Promise<any>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a Folder (directory) entity on the file system.
|
||||
*/
|
||||
export class Folder extends FileSystemEntity {
|
||||
/**
|
||||
* Determines whether this instance is a KnownFolder (accessed through the KnownFolders object).
|
||||
*/
|
||||
public isKnown: boolean;
|
||||
|
||||
/**
|
||||
* Gets or creates a Folder entity at the specified path.
|
||||
* @param path The path to get/create the folder at.
|
||||
*/
|
||||
public static fromPath(path: string): Folder;
|
||||
|
||||
/**
|
||||
* Checks whether a Folder with the specified path already exists.
|
||||
* @param path The path to check for.
|
||||
*/
|
||||
public static exists(path: string): boolean;
|
||||
|
||||
/**
|
||||
* Checks whether this Folder contains an Entity with the specified name.
|
||||
* The path of the folder is added to the name to resolve the complete path to check for.
|
||||
* @param name The name of the entity to check for.
|
||||
*/
|
||||
public contains(name: string): boolean;
|
||||
|
||||
/**
|
||||
* Deletes all the files and folders (recursively), contained within this Folder.
|
||||
*/
|
||||
public clear(): promises.Promise<any>;
|
||||
|
||||
/**
|
||||
* Gets or creates a File entity with the specified name within this Folder.
|
||||
* @param name The name of the file to get/create.
|
||||
*/
|
||||
public getFile(name: string): File;
|
||||
|
||||
/**
|
||||
* Gets or creates a Folder entity with the specified name within this Folder.
|
||||
* @param name The name of the folder to get/create.
|
||||
*/
|
||||
public getFolder(name: string): Folder;
|
||||
|
||||
/**
|
||||
* Gets all the top-level entities residing within this folder.
|
||||
*/
|
||||
public getEntities(): promises.Promise<Array<FileSystemEntity>>;
|
||||
|
||||
/**
|
||||
* Enumerates all the top-level FileSystem entities residing within this folder.
|
||||
* @param onEntity A callback that receives the current entity. If the callback returns false this will mean for the iteration to stop.
|
||||
*/
|
||||
public eachEntity(onEntity: (entity: FileSystemEntity) => boolean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides access to the top-level Folders instances that are accessible from the application. Use these as entry points to access the FileSystem.
|
||||
*/
|
||||
export module knownFolders {
|
||||
/**
|
||||
* Gets the Documents folder available for the current application. This Folder is private for the application and not accessible from Users/External apps.
|
||||
*/
|
||||
export function documents(): Folder;
|
||||
|
||||
/**
|
||||
* Gets the Temporary (Caches) folder available for the current application. This Folder is private for the application and not accessible from Users/External apps.
|
||||
*/
|
||||
export function temp(): Folder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables path-specific operations like join, extension, etc.
|
||||
*/
|
||||
export module path {
|
||||
/**
|
||||
* Normalizes a path, taking care of occurrances like ".." and "//".
|
||||
* @param path The path to be normalized.
|
||||
*/
|
||||
export function normalize(path: string): string;
|
||||
|
||||
/**
|
||||
* Joins all the provided string components, forming a valid and normalized path.
|
||||
* @param paths An array of string components to be joined.
|
||||
*/
|
||||
export function join(...paths: string[]): string;
|
||||
|
||||
/**
|
||||
* Gets the string used to separate file paths.
|
||||
*/
|
||||
export var separator: string;
|
||||
}
|
||||
}
|
|
@ -1,56 +1,44 @@
|
|||
var __extends = this.__extends || function (d, b) {
|
||||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
var file_access_module = require("file-system/file-system-access");
|
||||
var promises = require("promises");
|
||||
|
||||
var fileAccess;
|
||||
var getFileAccess = function () {
|
||||
if (!fileAccess) {
|
||||
fileAccess = new file_access_module.FileSystemAccess();
|
||||
}
|
||||
|
||||
return fileAccess;
|
||||
};
|
||||
|
||||
var nameProperty = "_name";
|
||||
var pathProperty = "_path";
|
||||
var isKnownProperty = "_isKnown";
|
||||
var fileLockedProperty = "_locked";
|
||||
var extensionProperty = "_extension";
|
||||
var lastModifiedProperty = "_lastModified";
|
||||
|
||||
var createFile = function (info) {
|
||||
var file = new File();
|
||||
file[pathProperty] = info.path;
|
||||
file[nameProperty] = info.name;
|
||||
file[extensionProperty] = info.extension;
|
||||
|
||||
return file;
|
||||
};
|
||||
|
||||
var createFolder = function (info) {
|
||||
var documents = knownFolders.documents();
|
||||
if (info.path === documents.path) {
|
||||
return documents;
|
||||
}
|
||||
|
||||
var temp = knownFolders.temp();
|
||||
if (info.path === temp.path) {
|
||||
return temp;
|
||||
}
|
||||
|
||||
var folder = new Folder();
|
||||
|
||||
folder[pathProperty] = info.path;
|
||||
folder[nameProperty] = info.name;
|
||||
|
||||
return folder;
|
||||
};
|
||||
|
||||
var FileSystemEntity = (function () {
|
||||
function FileSystemEntity() {
|
||||
}
|
||||
|
@ -59,79 +47,62 @@ var FileSystemEntity = (function () {
|
|||
var onError = function (error) {
|
||||
throw error;
|
||||
};
|
||||
|
||||
var folderInfo = getFileAccess().getParent(this.path, onError);
|
||||
if (!folderInfo) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return createFolder(folderInfo);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
FileSystemEntity.prototype.remove = function () {
|
||||
var fileAccess = getFileAccess();
|
||||
var promise = promises.defer();
|
||||
|
||||
var localSucces = function () {
|
||||
promise.resolve();
|
||||
};
|
||||
var localError = function (error) {
|
||||
promise.reject(error);
|
||||
};
|
||||
|
||||
if (this instanceof File) {
|
||||
fileAccess.deleteFile(this.path, localSucces, localError);
|
||||
} else if (this instanceof Folder) {
|
||||
fileAccess.deleteFolder(this.path, this[isKnownProperty], localSucces, localError);
|
||||
}
|
||||
|
||||
return promise.promise();
|
||||
var _this = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
var fileAccess = getFileAccess();
|
||||
var localSucces = function () {
|
||||
resolve();
|
||||
};
|
||||
var localError = function (error) {
|
||||
reject(error);
|
||||
};
|
||||
if (_this instanceof File) {
|
||||
fileAccess.deleteFile(_this.path, localSucces, localError);
|
||||
}
|
||||
else if (_this instanceof Folder) {
|
||||
fileAccess.deleteFolder(_this.path, _this[isKnownProperty], localSucces, localError);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
FileSystemEntity.prototype.rename = function (newName) {
|
||||
var deferred = promises.defer();
|
||||
|
||||
if (this instanceof Folder) {
|
||||
if (this[isKnownProperty]) {
|
||||
deferred.reject(new Error("Cannot rename known folder."));
|
||||
return deferred.promise();
|
||||
var _this = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (_this instanceof Folder) {
|
||||
if (_this[isKnownProperty]) {
|
||||
reject(new Error("Cannot rename known folder."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var parentFolder = this.parent;
|
||||
if (!parentFolder) {
|
||||
deferred.reject(new Error("No parent folder."));
|
||||
return deferred.promise();
|
||||
}
|
||||
|
||||
var fileAccess = getFileAccess();
|
||||
var path = parentFolder.path;
|
||||
var newPath = fileAccess.joinPath(path, newName);
|
||||
|
||||
var that = this;
|
||||
var localSucceess = function () {
|
||||
that[pathProperty] = newPath;
|
||||
that[nameProperty] = newName;
|
||||
|
||||
if (that instanceof File) {
|
||||
that[extensionProperty] = fileAccess.getFileExtension(newPath);
|
||||
var parentFolder = _this.parent;
|
||||
if (!parentFolder) {
|
||||
reject(new Error("No parent folder."));
|
||||
}
|
||||
|
||||
deferred.resolve();
|
||||
};
|
||||
|
||||
var localError = function (error) {
|
||||
deferred.reject(error);
|
||||
};
|
||||
|
||||
fileAccess.rename(this.path, newPath, localSucceess, localError);
|
||||
|
||||
return deferred.promise();
|
||||
var fileAccess = getFileAccess();
|
||||
var path = parentFolder.path;
|
||||
var newPath = fileAccess.joinPath(path, newName);
|
||||
var localSucceess = function () {
|
||||
_this[pathProperty] = newPath;
|
||||
_this[nameProperty] = newName;
|
||||
if (_this instanceof File) {
|
||||
_this[extensionProperty] = fileAccess.getFileExtension(newPath);
|
||||
}
|
||||
resolve();
|
||||
};
|
||||
var localError = function (error) {
|
||||
reject(error);
|
||||
};
|
||||
fileAccess.rename(_this.path, newPath, localSucceess, localError);
|
||||
});
|
||||
};
|
||||
|
||||
Object.defineProperty(FileSystemEntity.prototype, "name", {
|
||||
get: function () {
|
||||
return this[nameProperty];
|
||||
|
@ -139,7 +110,6 @@ var FileSystemEntity = (function () {
|
|||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(FileSystemEntity.prototype, "path", {
|
||||
get: function () {
|
||||
return this[pathProperty];
|
||||
|
@ -147,14 +117,12 @@ var FileSystemEntity = (function () {
|
|||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(FileSystemEntity.prototype, "lastModified", {
|
||||
get: function () {
|
||||
var value = this[lastModifiedProperty];
|
||||
if (!this[lastModifiedProperty]) {
|
||||
value = this[lastModifiedProperty] = getFileAccess().getLastModified(this.path);
|
||||
}
|
||||
|
||||
return value;
|
||||
},
|
||||
enumerable: true,
|
||||
|
@ -163,7 +131,6 @@ var FileSystemEntity = (function () {
|
|||
return FileSystemEntity;
|
||||
})();
|
||||
exports.FileSystemEntity = FileSystemEntity;
|
||||
|
||||
var File = (function (_super) {
|
||||
__extends(File, _super);
|
||||
function File() {
|
||||
|
@ -173,19 +140,15 @@ var File = (function (_super) {
|
|||
var onError = function (error) {
|
||||
throw error;
|
||||
};
|
||||
|
||||
var fileInfo = getFileAccess().getFile(path, onError);
|
||||
if (!fileInfo) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return createFile(fileInfo);
|
||||
};
|
||||
|
||||
File.exists = function (path) {
|
||||
return getFileAccess().fileExists(path);
|
||||
};
|
||||
|
||||
Object.defineProperty(File.prototype, "extension", {
|
||||
get: function () {
|
||||
return this[extensionProperty];
|
||||
|
@ -193,7 +156,6 @@ var File = (function (_super) {
|
|||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(File.prototype, "isLocked", {
|
||||
get: function () {
|
||||
return this[fileLockedProperty];
|
||||
|
@ -201,51 +163,39 @@ var File = (function (_super) {
|
|||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
File.prototype.readText = function (encoding) {
|
||||
var _this = this;
|
||||
this.checkAccess();
|
||||
|
||||
var deferred = promises.defer();
|
||||
this[fileLockedProperty] = true;
|
||||
|
||||
var that = this;
|
||||
var localSuccess = function (content) {
|
||||
that[fileLockedProperty] = false;
|
||||
deferred.resolve(content);
|
||||
};
|
||||
|
||||
var localError = function (error) {
|
||||
that[fileLockedProperty] = false;
|
||||
deferred.reject(error);
|
||||
};
|
||||
|
||||
getFileAccess().readText(this.path, localSuccess, localError, encoding);
|
||||
|
||||
return deferred.promise();
|
||||
return new Promise(function (resolve, reject) {
|
||||
_this[fileLockedProperty] = true;
|
||||
var localSuccess = function (content) {
|
||||
_this[fileLockedProperty] = false;
|
||||
resolve(content);
|
||||
};
|
||||
var localError = function (error) {
|
||||
_this[fileLockedProperty] = false;
|
||||
reject(error);
|
||||
};
|
||||
getFileAccess().readText(_this.path, localSuccess, localError, encoding);
|
||||
});
|
||||
};
|
||||
|
||||
File.prototype.writeText = function (content, encoding) {
|
||||
var _this = this;
|
||||
this.checkAccess();
|
||||
|
||||
var deferred = promises.defer();
|
||||
this[fileLockedProperty] = true;
|
||||
|
||||
var that = this;
|
||||
var localSuccess = function () {
|
||||
that[fileLockedProperty] = false;
|
||||
deferred.resolve();
|
||||
};
|
||||
|
||||
var localError = function (error) {
|
||||
that[fileLockedProperty] = false;
|
||||
deferred.reject(error);
|
||||
};
|
||||
|
||||
getFileAccess().writeText(this.path, content, localSuccess, localError, encoding);
|
||||
|
||||
return deferred.promise();
|
||||
return new Promise(function (resolve, reject) {
|
||||
_this[fileLockedProperty] = true;
|
||||
var that = _this;
|
||||
var localSuccess = function () {
|
||||
that[fileLockedProperty] = false;
|
||||
resolve();
|
||||
};
|
||||
var localError = function (error) {
|
||||
that[fileLockedProperty] = false;
|
||||
reject(error);
|
||||
};
|
||||
getFileAccess().writeText(_this.path, content, localSuccess, localError, encoding);
|
||||
});
|
||||
};
|
||||
|
||||
File.prototype.checkAccess = function () {
|
||||
if (this.isLocked) {
|
||||
throw new Error("Cannot access a locked file.");
|
||||
|
@ -254,7 +204,6 @@ var File = (function (_super) {
|
|||
return File;
|
||||
})(FileSystemEntity);
|
||||
exports.File = File;
|
||||
|
||||
var Folder = (function (_super) {
|
||||
__extends(Folder, _super);
|
||||
function Folder() {
|
||||
|
@ -264,45 +213,35 @@ var Folder = (function (_super) {
|
|||
var onError = function (error) {
|
||||
throw error;
|
||||
};
|
||||
|
||||
var folderInfo = getFileAccess().getFolder(path, onError);
|
||||
if (!folderInfo) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return createFolder(folderInfo);
|
||||
};
|
||||
|
||||
Folder.exists = function (path) {
|
||||
return getFileAccess().folderExists(path);
|
||||
};
|
||||
|
||||
Folder.prototype.contains = function (name) {
|
||||
var fileAccess = getFileAccess();
|
||||
var path = fileAccess.joinPath(this.path, name);
|
||||
|
||||
if (fileAccess.fileExists(path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return fileAccess.folderExists(path);
|
||||
};
|
||||
|
||||
Folder.prototype.clear = function () {
|
||||
var deferred = promises.defer();
|
||||
|
||||
var onSuccess = function () {
|
||||
deferred.resolve();
|
||||
};
|
||||
var onError = function (error) {
|
||||
deferred.reject(error);
|
||||
};
|
||||
|
||||
getFileAccess().emptyFolder(this.path, onSuccess, onError);
|
||||
|
||||
return deferred.promise();
|
||||
var _this = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
var onSuccess = function () {
|
||||
resolve();
|
||||
};
|
||||
var onError = function (error) {
|
||||
reject(error);
|
||||
};
|
||||
getFileAccess().emptyFolder(_this.path, onSuccess, onError);
|
||||
});
|
||||
};
|
||||
|
||||
Object.defineProperty(Folder.prototype, "isKnown", {
|
||||
get: function () {
|
||||
return this[isKnownProperty];
|
||||
|
@ -310,96 +249,79 @@ var Folder = (function (_super) {
|
|||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Folder.prototype.getFile = function (name) {
|
||||
var fileAccess = getFileAccess();
|
||||
var path = fileAccess.joinPath(this.path, name);
|
||||
|
||||
var onError = function (error) {
|
||||
throw error;
|
||||
};
|
||||
|
||||
var fileInfo = fileAccess.getFile(path, onError);
|
||||
if (!fileInfo) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return createFile(fileInfo);
|
||||
};
|
||||
|
||||
Folder.prototype.getFolder = function (name) {
|
||||
var fileAccess = getFileAccess();
|
||||
var path = fileAccess.joinPath(this.path, name);
|
||||
|
||||
var onError = function (error) {
|
||||
throw error;
|
||||
};
|
||||
|
||||
var folderInfo = fileAccess.getFolder(path, onError);
|
||||
if (!folderInfo) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return createFolder(folderInfo);
|
||||
};
|
||||
|
||||
Folder.prototype.getEntities = function () {
|
||||
var deferred = promises.defer();
|
||||
|
||||
var onSuccess = function (fileInfos) {
|
||||
var entities = new Array();
|
||||
var i, path, entity;
|
||||
|
||||
for (i = 0; i < fileInfos.length; i++) {
|
||||
if (fileInfos[i].extension) {
|
||||
entities.push(createFile(fileInfos[i]));
|
||||
} else {
|
||||
entities.push(createFolder(fileInfos[i]));
|
||||
var _this = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
var onSuccess = function (fileInfos) {
|
||||
var entities = new Array();
|
||||
var i;
|
||||
for (i = 0; i < fileInfos.length; i++) {
|
||||
if (fileInfos[i].extension) {
|
||||
entities.push(createFile(fileInfos[i]));
|
||||
}
|
||||
else {
|
||||
entities.push(createFolder(fileInfos[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deferred.resolve(entities);
|
||||
};
|
||||
|
||||
var onError = function (error) {
|
||||
throw error;
|
||||
};
|
||||
|
||||
getFileAccess().getEntities(this.path, onSuccess, onError);
|
||||
|
||||
return deferred.promise();
|
||||
resolve(entities);
|
||||
};
|
||||
var onError = function (error) {
|
||||
throw error;
|
||||
};
|
||||
getFileAccess().getEntities(_this.path, onSuccess, onError);
|
||||
});
|
||||
};
|
||||
|
||||
Folder.prototype.eachEntity = function (onEntity) {
|
||||
if (!onEntity) {
|
||||
return;
|
||||
}
|
||||
|
||||
var onSuccess = function (fileInfo) {
|
||||
var entity;
|
||||
if (fileInfo.extension) {
|
||||
entity = createFile(fileInfo);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
entity = createFolder(fileInfo);
|
||||
}
|
||||
|
||||
return onEntity(entity);
|
||||
};
|
||||
|
||||
var onError = function (error) {
|
||||
throw error;
|
||||
};
|
||||
|
||||
getFileAccess().eachEntity(this.path, onSuccess, onError);
|
||||
};
|
||||
return Folder;
|
||||
})(FileSystemEntity);
|
||||
exports.Folder = Folder;
|
||||
|
||||
var knownFolders;
|
||||
(function (knownFolders) {
|
||||
var _documents;
|
||||
var _temp;
|
||||
|
||||
var _app;
|
||||
knownFolders.documents = function () {
|
||||
if (!_documents) {
|
||||
var path = getFileAccess().getDocumentsFolderPath();
|
||||
|
@ -407,10 +329,8 @@ exports.Folder = Folder;
|
|||
_documents[pathProperty] = path;
|
||||
_documents[isKnownProperty] = true;
|
||||
}
|
||||
|
||||
return _documents;
|
||||
};
|
||||
|
||||
knownFolders.temp = function () {
|
||||
if (!_temp) {
|
||||
var path = getFileAccess().getTempFolderPath();
|
||||
|
@ -418,29 +338,33 @@ exports.Folder = Folder;
|
|||
_temp[pathProperty] = path;
|
||||
_temp[isKnownProperty] = true;
|
||||
}
|
||||
|
||||
return _temp;
|
||||
};
|
||||
})(exports.knownFolders || (exports.knownFolders = {}));
|
||||
var knownFolders = exports.knownFolders;
|
||||
|
||||
knownFolders.currentApp = function () {
|
||||
if (!_app) {
|
||||
var currentDir = __dirname;
|
||||
var path = currentDir.substring(0, currentDir.indexOf("/tns_modules"));
|
||||
_app = new Folder();
|
||||
_app[pathProperty] = path;
|
||||
_app[isKnownProperty] = true;
|
||||
}
|
||||
return _app;
|
||||
};
|
||||
})(knownFolders = exports.knownFolders || (exports.knownFolders = {}));
|
||||
var path;
|
||||
(function (_path) {
|
||||
function normalize(path) {
|
||||
return getFileAccess().normalizePath(path);
|
||||
}
|
||||
_path.normalize = normalize;
|
||||
|
||||
function join() {
|
||||
var paths = [];
|
||||
for (var _i = 0; _i < (arguments.length - 0); _i++) {
|
||||
paths[_i] = arguments[_i + 0];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
paths[_i - 0] = arguments[_i];
|
||||
}
|
||||
var fileAccess = getFileAccess();
|
||||
return fileAccess.joinPaths(paths);
|
||||
}
|
||||
_path.join = join;
|
||||
|
||||
_path.separator = getFileAccess().getPathSeparator();
|
||||
})(exports.path || (exports.path = {}));
|
||||
var path = exports.path;
|
||||
//# sourceMappingURL=file-system.impl.js.map
|
||||
})(path = exports.path || (exports.path = {}));
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
module.exports = require("file-system/file-system");
|
||||
//# sourceMappingURL=index.js.map
|
|
@ -0,0 +1,2 @@
|
|||
{ "name" : "file-system",
|
||||
"main" : "file-system.js" }
|
|
@ -0,0 +1,65 @@
|
|||
var fpsNative = require("fps-meter/fps-native");
|
||||
var callbacks = {}, idCounter = 0, _minFps = 1000, framesRendered = 0, frameStartTime = 0;
|
||||
function doFrame(currentTimeMillis) {
|
||||
var fps = 0;
|
||||
if (frameStartTime > 0) {
|
||||
var timeSpan = (currentTimeMillis - frameStartTime);
|
||||
framesRendered++;
|
||||
if (timeSpan > 1000) {
|
||||
fps = framesRendered * 1000 / timeSpan;
|
||||
if (fps < _minFps) {
|
||||
_minFps = fps;
|
||||
}
|
||||
notify(fps);
|
||||
frameStartTime = currentTimeMillis;
|
||||
framesRendered = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
frameStartTime = currentTimeMillis;
|
||||
}
|
||||
}
|
||||
var native = new fpsNative.FPSCallback(doFrame);
|
||||
function reset() {
|
||||
_minFps = 1000;
|
||||
frameStartTime = 0;
|
||||
framesRendered = 0;
|
||||
}
|
||||
exports.reset = reset;
|
||||
function running() {
|
||||
return native.running;
|
||||
}
|
||||
exports.running = running;
|
||||
function minFps() {
|
||||
return _minFps;
|
||||
}
|
||||
exports.minFps = minFps;
|
||||
function start() {
|
||||
native.start();
|
||||
}
|
||||
exports.start = start;
|
||||
function stop() {
|
||||
native.stop();
|
||||
reset();
|
||||
}
|
||||
exports.stop = stop;
|
||||
function addCallback(callback) {
|
||||
var id = idCounter;
|
||||
callbacks[id] = callback;
|
||||
idCounter++;
|
||||
return id;
|
||||
}
|
||||
exports.addCallback = addCallback;
|
||||
function removeCallback(id) {
|
||||
if (id in callbacks) {
|
||||
delete callbacks[id];
|
||||
}
|
||||
}
|
||||
exports.removeCallback = removeCallback;
|
||||
function notify(fps) {
|
||||
var callback;
|
||||
for (var id in callbacks) {
|
||||
callback = callbacks[id];
|
||||
callback(fps, _minFps);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
var FPSCallback = (function () {
|
||||
function FPSCallback(onFrame) {
|
||||
var _this = this;
|
||||
this.running = false;
|
||||
this.onFrame = onFrame;
|
||||
this.impl = new android.view.Choreographer.FrameCallback({
|
||||
doFrame: function (nanos) {
|
||||
_this.handleFrame(nanos);
|
||||
}
|
||||
});
|
||||
}
|
||||
FPSCallback.prototype.start = function () {
|
||||
if (this.running) {
|
||||
return;
|
||||
}
|
||||
android.view.Choreographer.getInstance().postFrameCallback(this.impl);
|
||||
this.running = true;
|
||||
};
|
||||
FPSCallback.prototype.stop = function () {
|
||||
if (!this.running) {
|
||||
return;
|
||||
}
|
||||
android.view.Choreographer.getInstance().removeFrameCallback(this.impl);
|
||||
this.running = false;
|
||||
};
|
||||
FPSCallback.prototype.handleFrame = function (nanos) {
|
||||
if (!this.running) {
|
||||
return;
|
||||
}
|
||||
this.onFrame(nanos / 1000000);
|
||||
android.view.Choreographer.getInstance().postFrameCallback(this.impl);
|
||||
};
|
||||
return FPSCallback;
|
||||
})();
|
||||
exports.FPSCallback = FPSCallback;
|
|
@ -0,0 +1,57 @@
|
|||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
var FrameHandlerImpl = (function (_super) {
|
||||
__extends(FrameHandlerImpl, _super);
|
||||
function FrameHandlerImpl() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
FrameHandlerImpl.new = function () {
|
||||
return _super.new.call(this);
|
||||
};
|
||||
FrameHandlerImpl.prototype.initWithOwner = function (owner) {
|
||||
this._owner = owner;
|
||||
return this;
|
||||
};
|
||||
FrameHandlerImpl.prototype.handleFrame = function (sender) {
|
||||
this._owner._handleFrame(sender);
|
||||
};
|
||||
FrameHandlerImpl.ObjCExposedMethods = {
|
||||
"handleFrame": { returns: interop.types.void, params: [CADisplayLink] }
|
||||
};
|
||||
return FrameHandlerImpl;
|
||||
})(NSObject);
|
||||
var FPSCallback = (function () {
|
||||
function FPSCallback(onFrame) {
|
||||
this.onFrame = onFrame;
|
||||
this.impl = FrameHandlerImpl.new().initWithOwner(this);
|
||||
this.displayLink = CADisplayLink.displayLinkWithTargetSelector(this.impl, "handleFrame");
|
||||
this.displayLink.paused = true;
|
||||
this.displayLink.addToRunLoopForMode(NSRunLoop.currentRunLoop(), NSDefaultRunLoopMode);
|
||||
}
|
||||
FPSCallback.prototype.start = function () {
|
||||
if (this.running) {
|
||||
return;
|
||||
}
|
||||
this.running = true;
|
||||
this.displayLink.paused = false;
|
||||
};
|
||||
FPSCallback.prototype.stop = function () {
|
||||
if (!this.running) {
|
||||
return;
|
||||
}
|
||||
this.displayLink.paused = true;
|
||||
this.running = false;
|
||||
};
|
||||
FPSCallback.prototype._handleFrame = function (sender) {
|
||||
if (!this.running) {
|
||||
return;
|
||||
}
|
||||
this.onFrame(sender.timestamp * 1000);
|
||||
};
|
||||
return FPSCallback;
|
||||
})();
|
||||
exports.FPSCallback = FPSCallback;
|
|
@ -0,0 +1,2 @@
|
|||
{ "name" : "fps-meter",
|
||||
"main" : "fps-meter.js" }
|
|
@ -0,0 +1,14 @@
|
|||
var types = require("utils/types");
|
||||
var timer = require("timer");
|
||||
var consoleModule = require("console");
|
||||
var http = require("http");
|
||||
var dialogs = require("ui/dialogs");
|
||||
global.setTimeout = timer.setTimeout;
|
||||
global.clearTimeout = timer.clearTimeout;
|
||||
global.setInterval = timer.setInterval;
|
||||
global.clearInterval = timer.clearInterval;
|
||||
if (types.isUndefined(global.NSObject)) {
|
||||
global.console = new consoleModule.Console();
|
||||
}
|
||||
global.XMLHttpRequest = http.XMLHttpRequest;
|
||||
global.alert = dialogs.alert;
|
|
@ -1,10 +0,0 @@
|
|||
var timer = require("timer/timer");
|
||||
var consoleModule = require("console/console");
|
||||
|
||||
setTimeout = timer.setTimeout;
|
||||
clearTimeout = timer.clearTimeout;
|
||||
setInterval = timer.setInterval;
|
||||
clearInterval = timer.clearInterval;
|
||||
|
||||
console = new consoleModule.Console();
|
||||
//# sourceMappingURL=index.js.map
|
|
@ -0,0 +1,2 @@
|
|||
{ "name" : "globals",
|
||||
"main" : "globals.js" }
|