當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript file-system.knownFolders類代碼示例

本文整理匯總了TypeScript中tns-core-modules/file-system.knownFolders的典型用法代碼示例。如果您正苦於以下問題:TypeScript knownFolders類的具體用法?TypeScript knownFolders怎麽用?TypeScript knownFolders使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了knownFolders類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: function

export var test_getContentAsFile = function (done) {
    var result;

    // >> http-get-urlfile-content
    var filePath = fs.path.join(fs.knownFolders.documents().path, "test.png");
    http.getFile("https://httpbin.org/image/png?testQuery=query&anotherParam=param", filePath).then(function (r) {
        //// Argument (r) is File!
        // >> (hide)
        result = r;
        try {
            TKUnit.assert(result instanceof fs.File, "Result from getFile() should be valid File object!");
            done(null);
        }
        catch (err) {
            done(err);
        }
        // << (hide)
    }, function (e) {
        //// Argument (e) is Error!
        // >> (hide)
        done(e);
        // << (hide)
    });
    // << http-get-urlfile-content
};
開發者ID:sitefinitysteve,項目名稱:NativeScript,代碼行數:25,代碼來源:http-tests.ts

示例2: getPlaceholderImageDrawable

  public static getPlaceholderImageDrawable(value) {

    let fileName = "",
      drawable = null;


    if (types.isString(value)) {

      value = value.trim();

      if (utils.isFileOrResourcePath(value)) {


        if (0 === value.indexOf("~/")) {
          fileName = fs.path.join(fs.knownFolders.currentApp().path, value.replace("~/", ""));
          drawable = android.graphics.drawable.Drawable.createFromPath(fileName);
        } else if (0 === value.indexOf("res")) {
          fileName = value;
          let res = utils.ad.getApplicationContext().getResources();
          let resName = fileName.substr(utils.RESOURCE_PREFIX.length);
          let identifier = res.getIdentifier(resName, 'drawable', utils.ad.getApplication().getPackageName());
          drawable = res.getDrawable(identifier);
        }


      }
    }

    return drawable;

  }
開發者ID:VideoSpike,項目名稱:nativescript-web-image-cache,代碼行數:31,代碼來源:helpers.ts

示例3: testSaveToFile_WithQuality

export function testSaveToFile_WithQuality() {
    const img = imageSource.fromFile(imagePath);
    const folder = fs.knownFolders.documents();
    const path = fs.path.join(folder.path, "test.png");
    const saved = img.saveToFile(path, "png", 70);
    TKUnit.assert(saved, "Image not saved to file");
    TKUnit.assert(fs.File.exists(path), "Image not saved to file");
}
開發者ID:NathanWalker,項目名稱:NativeScript,代碼行數:8,代碼來源:image-source-tests.ts

示例4:

 source.fromAsset(imageAsset).then((imageSource) => {
     let folder = fs.knownFolders.documents().path;
     let fileName = "test.png";
     let path = fs.path.join(folder, fileName);
     let saved = imageSource.saveToFile(path, "png");
     if (saved) {
         console.log("Image saved successfully!");
     }
 })
開發者ID:NathanWalker,項目名稱:NativeScript,代碼行數:9,代碼來源:image-source-snippet.ts

示例5:

 source.fromAsset(imageAsset).then((source) => {
     let folder = fs.knownFolders.documents().path;
     let fileName = "test.png"
     let path = fs.path.join(folder, fileName);
     let saved = source.saveToFile(path, "png");
     if(saved){
        console.log("saved image")
     }
 })
開發者ID:sitefinitysteve,項目名稱:NativeScript,代碼行數:9,代碼來源:image-source-snippet.ts

示例6: testSaveToFile

export function testSaveToFile() {
    // >> imagesource-save-to
    const img = imageSource.fromFile(imagePath);
    const folder = fs.knownFolders.documents();
    const path = fs.path.join(folder.path, "test.png");
    const saved = img.saveToFile(path, "png");
    // << imagesource-save-to
    TKUnit.assert(saved, "Image not saved to file");
    TKUnit.assert(fs.File.exists(path), "Image not saved to file");
}
開發者ID:NathanWalker,項目名稱:NativeScript,代碼行數:10,代碼來源:image-source-tests.ts

示例7: _storeImageSource

  private static _storeImageSource(image: ImageSource): string {
    const folder: fs.Folder = fs.knownFolders.temp();
    const path = fs.path.join(folder.path, "temp.jpeg");

    if (image.saveToFile(path, "jpeg", 100)) {
      return path;
    }
    else {
      return null;
    }
  }
開發者ID:bthurlow,項目名稱:nativescript-imagecropper,代碼行數:11,代碼來源:imagecropper.android.ts

示例8: toFile

 http.request({ url: "https://raw.githubusercontent.com/NativeScript/NativeScript/master/tests/app/logo.png", method: "GET" }).then(function (response) {
     const filePath = fs.path.join(fs.knownFolders.temp().path, "test", "some", "path", "logo.png");
     result = response.content.toFile(filePath);
     try {
         TKUnit.assert(result instanceof fs.File, "Result from toFile() should be valid File object!");
         TKUnit.assert(result.size > 0, "result from to file should be greater than 0 in size");
         done(null);
     }
     catch (err) {
         done(err);
     }
 }, function (e) {
開發者ID:m-abs,項目名稱:NativeScript,代碼行數:12,代碼來源:http-tests.ts

示例9: testFromFile

export function testFromFile() {
    // >> imagesource-load-local
    const folder = fs.knownFolders.documents();
    const path = fs.path.join(folder.path, "test.png");
    const img = imageSource.fromFile(path);
    // << imagesource-load-local

    TKUnit.assert(img.height > 0, "image.fromResource failed");

    // remove the image from the file system
    const file = folder.getFile("test.png");
    file.remove();
    TKUnit.assert(!fs.File.exists(path), "test.png not removed");
}
開發者ID:NathanWalker,項目名稱:NativeScript,代碼行數:14,代碼來源:image-source-tests.ts

示例10: _setSrcProperty

  private _setSrcProperty(value: string) {
    if (value) {
      value = value.trim();
      let isUrl = false;

      if (value.indexOf('://') !== -1) {
        if (value.indexOf('res://') === -1) {
          isUrl = true;
        }
      }
      this._src = value;
      if (!isUrl) {
        const currentPath = knownFolders.currentApp().path;

        if (value[1] === '/' && (value[0] === '.' || value[0] === '~')) {
          value = value.substr(2);
        }

        if (value[0] !== '/') {
          value = currentPath + '/' + value;
        }

        this._drawable = new pl.droidsonroids.gif.GifDrawable(value);
        this.nativeView.setImageDrawable(this._drawable);
      } else {
        const requestOptions: any = { url: value, method: 'GET' };
        if (this._headers !== null) {
          requestOptions.headers = this._headers;
        }
        HttpRequest(requestOptions).then(
          r => {
            if (r.statusCode === 200) {
              this._drawable = new pl.droidsonroids.gif.GifDrawable(
                r.content.raw.toByteArray()
              );
              this.nativeView.setImageDrawable(this._drawable);
            } else {
              console.log('error getting image: ' + r.statusCode);
            }
          },
          err => {
            console.log(err);
          }
        );
      }
    } else {
      console.log('No src property set for the Gif.');
    }
  }
開發者ID:bradmartin,項目名稱:nativescript-gif,代碼行數:49,代碼來源:gif.android.ts


注:本文中的tns-core-modules/file-system.knownFolders類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。