Example #1
0
exports.loaded = function(args) {
	_page = args.object;

	if (applicationModule.ios) {
		frameModule.topmost().ios.navBarVisibility = "never";
	}

	var webView = _page.getViewById("releaseNotesView");

	var releaseNotesFolder = "./components/releases/versionInfo";
	var fullPath = fs.path.join(fs.knownFolders.currentApp().path, releaseNotesFolder);

	var releaseFolder = fs.Folder.fromPath(fullPath);
	var releaseNotes = releaseFolder.getFile(global.appVersion + ".md");

	releaseNotes.readText().then(function(content){
		var convertedReleaseNotes = marked(content);

		if (applicationModule.ios) {
			webView.ios.loadHTMLStringBaseURL(convertedReleaseNotes, null);
		}

		if (applicationModule.android) {
			webview.android.loadData(convertedReleaseNotes, "text/html", null);
		}
	});
};
function resolvePageFromEntry(entry) {
    var page;
    if (entry.create) {
        page = entry.create();
        if (!(page && page instanceof pages.Page)) {
            throw new Error("Failed to create Page with entry.create() function.");
        }
    }
    else if (entry.moduleName) {
        var currentAppPath = fs.knownFolders.currentApp().path;
        var moduleNamePath = fs.path.join(currentAppPath, entry.moduleName);
        var moduleExports;
        var moduleExportsResolvedPath = fileResolverModule.resolveFileName(moduleNamePath, "js");
        if (moduleExportsResolvedPath) {
            trace.write("Loading JS file: " + moduleExportsResolvedPath, trace.categories.Navigation);
            moduleExportsResolvedPath = moduleExportsResolvedPath.substr(0, moduleExportsResolvedPath.length - 3);
            moduleExports = require(moduleExportsResolvedPath);
        }
        if (moduleExports && moduleExports.createPage) {
            trace.write("Calling createPage()", trace.categories.Navigation);
            page = moduleExports.createPage();
        }
        else {
            page = pageFromBuilder(moduleNamePath, moduleExports);
        }
        if (!(page && page instanceof pages.Page)) {
            throw new Error("Failed to load Page from entry.moduleName: " + entry.moduleName);
        }
        var cssFileName = fileResolverModule.resolveFileName(moduleNamePath, "css");
        if (cssFileName) {
            page.addCssFile(cssFileName);
        }
    }
    return page;
}
 Font.prototype.loadFontFromAsset = function (fontFamily) {
     appAssets = appAssets || application.android.context.getAssets();
     if (!appAssets) {
         return null;
     }
     var result = typefaceCache.get(fontFamily);
     if (types.isUndefined(result)) {
         result = null;
         var fontAssetPath;
         var basePath = fs.path.join(fs.knownFolders.currentApp().path, "fonts", fontFamily);
         if (fs.File.exists(basePath + ".ttf")) {
             fontAssetPath = FONTS_BASE_PATH + fontFamily + ".ttf";
         }
         else if (fs.File.exists(basePath + ".otf")) {
             fontAssetPath = FONTS_BASE_PATH + fontFamily + ".otf";
         }
         else {
             trace.write("Could not find font file for " + fontFamily, trace.categories.Error, trace.messageType.error);
         }
         if (fontAssetPath) {
             try {
                 result = android.graphics.Typeface.createFromAsset(appAssets, fontAssetPath);
             }
             catch (e) {
                 trace.write("Error loading font asset: " + fontAssetPath, trace.categories.Error, trace.messageType.error);
             }
         }
         typefaceCache.set(fontFamily, result);
     }
     return result;
 };
 ImageSource.prototype.loadFromFile = function (path) {
     var fileName = types.isString(path) ? path.trim() : "";
     if (fileName.indexOf("~/") === 0) {
         fileName = fs.path.join(fs.knownFolders.currentApp().path, fileName.replace("~/", ""));
     }
     this.android = android.graphics.BitmapFactory.decodeFile(fileName, null);
     return this.android != null;
 };
function saveToFile() {
    var knownPath = fs.knownFolders.documents();
    var folderPath = fs.path.join(knownPath.path, "CosmosDataBank");
    var folder = fs.Folder.fromPath(folderPath);
    var path = fs.path.join(folderPath, "Test.png");
    var saved = myImageSource.saveToFile(path, "png");
    console.log(saved);
}
 ImageSource.prototype.loadFromFile = function (path) {
     var fileName = types.isString(path) ? path.trim() : "";
     if (fileName.indexOf("~/") === 0) {
         fileName = fs.path.join(fs.knownFolders.currentApp().path, fileName.replace("~/", ""));
     }
     this.ios = UIImage.imageWithContentsOfFile(fileName);
     return this.ios != null;
 };
 FileSystemXHR.prototype.get = function (url) {
     var appDir = file_system_1.knownFolders.currentApp().path;
     var templatePath = file_system_1.path.join(appDir, url);
     if (!file_system_1.File.exists(templatePath)) {
         throw new Error("File " + url + " does not exist.");
     }
     var templateFile = file_system_1.File.fromPath(templatePath);
     return templateFile.readText();
 };
 PageService.prototype.getPages = function () {
     var file = fileSystem.knownFolders.documents().getFile("scrapbook.json");
     var pages = file.readTextSync().length === 0
         ? new Array()
         : JSON.parse(file.readTextSync());
     pages.forEach(function (page) {
         page.Image = image.fromBase64(page.ImageBase64);
     });
     return pages;
 };
function getSpeakerAvatars(path) {
    var avatarList = [];
    var currentAppFolder = fileSystemModule.knownFolders.currentApp();
    var menAvatarsFile = currentAppFolder.getFile(path);
    var fileText = menAvatarsFile.readTextSync();
    var lines = fileText.split('\n');
    for (var i = 0; i < lines.length; i++) {
        avatarList.push('data:image/png;base64,' + lines[i]);
    }
    return avatarList;
}
	return new Promise((resolve) => {
		const fsFolder = fs.knownFolders.documents().getFolder(folder);
		fsFolder.clear()
			.then(function () {
				debug.debug('Removed local folder: ' + folder);
				resolve();
			}, function () {
				debug.debug('Could not remove local folder: ' + folder, 'error');
				resolve();
			});
	});
function takeAccessTokenFromFile() {
	var documents = fs.knownFolders.documents();
	var myFile = documents.getFile("access_token.txt");
	var written;
	// Writing text to the file.
	myFile.readText().then(function (content) {
        localSettings.setString('access_token', content);
    }, function (error) {
        console.log('>> couldnt read access token');
    });
}
var Clicker = function(resourceFolderPath, fileName) {
    var soundPath = fs.path.join(fs.knownFolders.currentApp().path, resourceFolderPath, fileName);
    var soundUrl = NSURL.fileURLWithPath(soundPath);
    var player = AVAudioPlayer.alloc().initWithContentsOfURLError(soundUrl, null);
    player.prepareToPlay();

    this.click = function() {
        player.currentTime = 0.0;
        player.play();
    };
};
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;
            });
            definition.cssSelectorsCache = styleScope.StyleScope.createSelectorsFromCss(applicationCss, cssFileName);
        }
    }
}
function loadCss() {
    if (definition.cssFile) {
        var cssFileName = fs.path.join(fs.knownFolders.currentApp().path, definition.cssFile);
        if (fs.File.exists(cssFileName)) {
            var file = fs.File.fromPath(cssFileName);
            var applicationCss = file.readTextSync();
            if (applicationCss) {
                definition.cssSelectorsCache = styleScope.StyleScope.createSelectorsFromCss(applicationCss, cssFileName);
            }
        }
    }
}
Example #15
0
 function registerFont(fontFile) {
     var filePath = fs.path.join(fs.knownFolders.currentApp().path, "fonts", fontFile);
     if (!fs.File.exists(filePath)) {
         filePath = fs.path.join(fs.knownFolders.currentApp().path, fontFile);
     }
     var fontData = NSFileManager.defaultManager().contentsAtPath(filePath);
     if (!fontData) {
         throw new Error("Could not load font from: " + fontFile);
     }
     var provider = CGDataProviderCreateWithCFData(fontData);
     var font = CGFontCreateWithDataProvider(provider);
     if (!font) {
         throw new Error("Could not load font from: " + fontFile);
     }
     var error = new interop.Reference();
     if (!CTFontManagerRegisterGraphicsFont(font, error)) {
         var trace = require("trace");
         trace.write("Error occur while registering font: " + CFErrorCopyDescription(error.value), trace.categories.Error, trace.messageType.error);
     }
     areSystemFontSetsValid = false;
 }
Example #16
0
function loadCustomComponent(componentPath, componentName, attributes, context, parentPage) {
    if (!parentPage && context) {
        parentPage = context["_parentPage"];
        delete context["_parentPage"];
    }
    var result;
    componentPath = componentPath.replace("~/", "");
    var moduleName = componentPath + "/" + componentName;
    var fullComponentPathFilePathWithoutExt = componentPath;
    if (!file_system_1.File.exists(componentPath) || componentPath === "." || componentPath === "./") {
        fullComponentPathFilePathWithoutExt = file_system_1.path.join(file_system_1.knownFolders.currentApp().path, componentPath, componentName);
    }
    var xmlFilePath = file_name_resolver_1.resolveFileName(fullComponentPathFilePathWithoutExt, "xml");
    if (xmlFilePath) {
        var jsFilePath = file_name_resolver_1.resolveFileName(fullComponentPathFilePathWithoutExt, "js");
        var subExports = context;
        if (global.moduleExists(moduleName)) {
            subExports = global.loadModule(moduleName);
        }
        else {
            if (jsFilePath) {
                subExports = global.loadModule(jsFilePath);
            }
        }
        if (!subExports) {
            subExports = {};
        }
        subExports["_parentPage"] = parentPage;
        result = loadInternal(xmlFilePath, subExports);
        if (types_1.isDefined(result) && types_1.isDefined(result.component) && types_1.isDefined(attributes)) {
            var attr;
            for (attr in attributes) {
                component_builder_1.setPropertyValue(result.component, subExports, context, attr, attributes[attr]);
            }
        }
    }
    else {
        result = component_builder_1.getComponentModule(componentName, componentPath, attributes, context);
    }
    var cssFilePath = file_name_resolver_1.resolveFileName(fullComponentPathFilePathWithoutExt, "css");
    if (cssFilePath) {
        if (parentPage) {
            parentPage.addCssFile(cssFilePath);
        }
        else {
            ensureTrace();
            trace.write("CSS file found but no page specified. Please specify page in the options!", trace.categories.Error, trace.messageType.error);
        }
    }
    return result;
}
 toFile: function (destinationFilePath) {
     var fs = require("file-system");
     var fileName = options.url;
     if (!destinationFilePath) {
         destinationFilePath = fs.path.join(fs.knownFolders.documents().path, fileName.substring(fileName.lastIndexOf('/') + 1));
     }
     if (data instanceof NSData) {
         data.writeToFileAtomically(destinationFilePath, true);
         return fs.File.fromPath(destinationFilePath);
     }
     else {
         reject(new Error("Cannot save file with path: " + destinationFilePath + "."));
     }
 }
 function openFile(filePath) {
     try {
         var fs = require("file-system");
         var path = filePath.replace("~", fs.knownFolders.currentApp().path);
         var controller = UIDocumentInteractionController.interactionControllerWithURL(NSURL.fileURLWithPath(path));
         controller.delegate = new UIDocumentInteractionControllerDelegateImpl();
         return controller.presentPreviewAnimated(true);
     }
     catch (e) {
         ensureTrace();
         trace.write("Error in openFile", trace.categories.Error, trace.messageType.error);
     }
     return false;
 }
 return new Promise(function (resolve, reject) {
     try {
         var fileName = types.isString(path) ? path.trim() : "";
         if (fileName.indexOf("~/") === 0) {
             fileName = fs.path.join(fs.knownFolders.currentApp().path, fileName.replace("~/", ""));
         }
         UIImage.tns_decodeImageWidthContentsOfFileCompletion(fileName, function (image) {
             _this.ios = image;
             resolve(true);
         });
     }
     catch (ex) {
         reject(ex);
     }
 });
 Page.prototype.addCssFile = function (cssFileName) {
     if (cssFileName.indexOf("~/") === 0) {
         cssFileName = fs.path.join(fs.knownFolders.currentApp().path, cssFileName.replace("~/", ""));
     }
     if (!this._cssFiles[cssFileName]) {
         if (fs.File.exists(cssFileName)) {
             var file = fs.File.fromPath(cssFileName);
             var text = file.readTextSync();
             if (text) {
                 this._addCssInternal(text, cssFileName);
                 this._cssFiles[cssFileName] = true;
             }
         }
     }
 };
Example #21
0
function resolvePageFromEntry(entry) {
    var page;
    if (entry.create) {
        page = entry.create();
        if (!(page && page instanceof page_1.Page)) {
            throw new Error("Failed to create Page with entry.create() function.");
        }
    }
    else if (entry.moduleName) {
        var currentAppPath = fs.knownFolders.currentApp().path;
        var moduleNamePath = fs.path.join(currentAppPath, entry.moduleName);
        var moduleExports;
        if (global.moduleExists(entry.moduleName)) {
            if (trace.enabled) {
                trace.write("Loading pre-registered JS module: " + entry.moduleName, trace.categories.Navigation);
            }
            moduleExports = global.loadModule(entry.moduleName);
        }
        else {
            var moduleExportsResolvedPath = file_name_resolver_1.resolveFileName(moduleNamePath, "js");
            if (moduleExportsResolvedPath) {
                if (trace.enabled) {
                    trace.write("Loading JS file: " + moduleExportsResolvedPath, trace.categories.Navigation);
                }
                moduleExportsResolvedPath = moduleExportsResolvedPath.substr(0, moduleExportsResolvedPath.length - 3);
                moduleExports = global.loadModule(moduleExportsResolvedPath);
            }
        }
        if (moduleExports && moduleExports.createPage) {
            if (trace.enabled) {
                trace.write("Calling createPage()", trace.categories.Navigation);
            }
            page = moduleExports.createPage();
        }
        else {
            page = pageFromBuilder(moduleNamePath, moduleExports);
        }
        if (!(page && page instanceof page_1.Page)) {
            throw new Error("Failed to load Page from entry.moduleName: " + entry.moduleName);
        }
        var cssFileName = file_name_resolver_1.resolveFileName(moduleNamePath, "css");
        if (cssFileName && !page["cssFile"]) {
            page.addCssFile(cssFileName);
        }
    }
    return page;
}
Example #22
0
 MGLMapViewDelegateImpl.prototype.mapViewImageForAnnotation = function(mapView, annotation) {
   var cachedMarker = _getTappedMarkerDetails(annotation);
   if (cachedMarker && cachedMarker.iconPath) {
     if (cachedMarker.reuseIdentifier) {
       return mapView.dequeueReusableAnnotationImageWithIdentifier(cachedMarker.reuseIdentifier);
     }
     var appPath = fs.knownFolders.currentApp().path;
     var iconFullPath = appPath + "/" + cachedMarker.iconPath;
     if (fs.File.exists(iconFullPath)) {
       var image = imgSrc.fromFile(iconFullPath).ios;
       // TODO (future) add resize options for nice retina rendering
       cachedMarker.reuseIdentifier = cachedMarker.iconPath;
       return MGLAnnotationImage.annotationImageWithImageReuseIdentifier(image, cachedMarker.reuseIdentifier);
     }
   }
   return null;
 };
function loadCss(cssFile) {
    if (!cssFile) {
        return undefined;
    }
    var result;
    var fs = require("file-system");
    var styleScope = require("ui/styling/style-scope");
    var cssFileName = fs.path.join(fs.knownFolders.currentApp().path, cssFile);
    if (fs.File.exists(cssFileName)) {
        var file = fs.File.fromPath(cssFileName);
        var applicationCss = file.readTextSync();
        if (applicationCss) {
            result = styleScope.StyleScope.createSelectorsFromCss(applicationCss, cssFileName);
        }
    }
    return result;
}
// Event handler for Page "navigatingTo" event attached in main-page.xml
function navigatingTo(args) {
    // Get the event sender
    var page = args.object;
    var observable = new observable_1.Observable();
    var documents = file_system_1.knownFolders.currentApp();
    var jsonFile = documents.getFile('files/studentDetails.json');
    var jsonData;
    jsonFile.readText()
        .then(function (content) {
        jsonData = JSON.parse(content);
        // console.log(content);
        // console.dump(jsonData);
        observable.set("info", jsonData);
    }, function (error) {
        throw new Error('Could not read JSON file');
    });
    page.bindingContext = observable;
}
 Image.prototype._createImageSourceFromSrc = function () {
     var imageView = this._android;
     if (!imageView || !this.src) {
         return;
     }
     var value = this.src;
     var async = this.loadMode === ASYNC;
     var owner = new WeakRef(this);
     var listener = new org.nativescript.widgets.image.Worker.OnImageLoadedListener({
         onImageLoaded: function (success) {
             var that = owner.get();
             if (that) {
                 that._setValue(Image.isLoadingProperty, false);
             }
         }
     });
     this._resetValue(Image.imageSourceProperty);
     if (types.isString(value)) {
         value = value.trim();
         this._setValue(Image.isLoadingProperty, true);
         if (utils.isDataURI(value)) {
             _super.prototype._createImageSourceFromSrc.call(this);
         }
         else if (imageSource.isFileOrResourcePath(value)) {
             if (value.indexOf(utils.RESOURCE_PREFIX) === 0) {
                 imageView.setUri(value, this.decodeWidth, this.decodeHeight, this.useCache, async, listener);
             }
             else {
                 var fileName = value;
                 if (fileName.indexOf("~/") === 0) {
                     fileName = fs.path.join(fs.knownFolders.currentApp().path, fileName.replace("~/", ""));
                 }
                 imageView.setUri(FILE_PREFIX + fileName, this.decodeWidth, this.decodeHeight, this.useCache, async, listener);
             }
         }
         else {
             imageView.setUri(value, this.decodeWidth, this.decodeHeight, this.useCache, true, listener);
         }
     }
     else {
         _super.prototype._createImageSourceFromSrc.call(this);
     }
 };
/**
 * This is the loadCss helper function to replace the one on Application
 */
function loadCss() {
    var cssFileName = fs.path.join(fs.knownFolders.currentApp().path, application.cssFile);

    var applicationCss;
    if (FSA.fileExists(cssFileName)) {
        applicationCss = FSA.readText(cssFileName);
        //noinspection JSUnusedAssignment
        application.cssSelectorsCache = styleScope.StyleScope.createSelectorsFromCss(applicationCss, cssFileName);

        // Add New CSS to Current Page
        var f = frameCommon.topmost();
        if (f && f.currentPage) {
            f.currentPage._resetCssValues();
            f.currentPage._styleScope = new styleScope.StyleScope();
            //noinspection JSUnusedAssignment
            f.currentPage._addCssInternal(applicationCss, cssFileName);
            f.currentPage._refreshCss();
        }
    }
}
                selected_item.getImage().then(function (imagesource) {
                    var localPath = null;

                    if (platformModule.device.os === "Android") {
                        localPath = selected_item.android;
                    } else {
                        // selected_item.ios for iOS is PHAsset and not path - so we are creating own path
                        let folder = fs.knownFolders.documents();
                        let path = fs.path.join(folder.path, "Test" + counter + ".png");
                        let saved = imagesource.saveToFile(path, "png");

                        localPath = path;
                    }

                    if (localPath) {
                        var task = sendImages("Image" + counter + ".png", localPath);
                        mainViewModel.get("items").push(fromObject({ thumb: imagesource, uri: "Image" + counter + ".png", uploadTask: task }));
                    }
                    counter++;
                })
  DemoAppModel.prototype.doUploadFile = function () {
    // let's first create a File object using the tns file module
    var appPath = fs.knownFolders.currentApp().path;
    var logoPath = appPath + "/res/telerik-logo.png";

    firebase.uploadFile({
      remoteFullPath: 'uploads/images/telerik-logo-uploaded.png',
      // localFile: fs.File.fromPath(logoPath) // use this (a file-system module File object)
      localFullPath: logoPath // or this, a full file path
    }).then(
        function (uploadedFile) {
          dialogs.alert({
            title: "File upload successful!",
            message: JSON.stringify(uploadedFile),
            okButtonText: "Cool!"
          });
        },
        function (error) {
          console.log("firebase.doUploadFile error: " + error);
        }
    );
  };
 PageService.prototype.savePage = function (scrapbookPage) {
     var file = fileSystem.knownFolders.documents().getFile("scrapbook.json");
     var pages = this.getPages();
     var index = this.findPageIndex(pages, scrapbookPage.Id);
     var page = new page_1.Page();
     page.Id = scrapbookPage.Id;
     page.Title = scrapbookPage.Title;
     page.Gender = scrapbookPage.Gender;
     page.Age = scrapbookPage.Age;
     page.BirthDate = scrapbookPage.BirthDate;
     page.ImageBase64 = scrapbookPage.ImageBase64;
     page.Lat = scrapbookPage.Lat;
     page.Long = scrapbookPage.Long;
     if (index !== -1) {
         pages[index] = scrapbookPage;
     }
     else {
         pages.push(scrapbookPage);
     }
     var json = JSON.stringify(pages);
     file.writeText(json);
 };
Example #30
0
 toFile: function (destinationFilePath) {
     var fs = require("file-system");
     var fileName = callbacks.url;
     if (!destinationFilePath) {
         destinationFilePath = fs.path.join(fs.knownFolders.documents().path, fileName.substring(fileName.lastIndexOf('/') + 1));
     }
     var stream;
     try {
         var javaFile = new java.io.File(destinationFilePath);
         stream = new java.io.FileOutputStream(javaFile);
         stream.write(result.raw.toByteArray());
         return fs.File.fromPath(destinationFilePath);
     }
     catch (exception) {
         throw new Error("Cannot save file with path: " + destinationFilePath + ".");
     }
     finally {
         if (stream) {
             stream.close();
         }
     }
 }