当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript knownFolders.temp方法代码示例

本文整理汇总了TypeScript中tns-core-modules/file-system.knownFolders.temp方法的典型用法代码示例。如果您正苦于以下问题:TypeScript knownFolders.temp方法的具体用法?TypeScript knownFolders.temp怎么用?TypeScript knownFolders.temp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tns-core-modules/file-system.knownFolders的用法示例。


在下文中一共展示了knownFolders.temp方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: _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

示例2: 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

示例3: done

    imageSource.fromAsset(asset).then((source) => {
        TKUnit.assertEqual(source.width, scaleWidth);
        TKUnit.assertEqual(source.height, scaleHeight);

        const targetFilename = `splashscreenTemp.png`;
        const tempPath = fs.knownFolders.temp().path;
        const localFullPath = fs.path.join(tempPath, targetFilename);

        const fullImageSaved = source.saveToFile(localFullPath, "png");

        if (fullImageSaved) {
            let sourceImage = new imageSource.ImageSource();
            sourceImage.fromFile(localFullPath).then(() => {
                TKUnit.assertEqual(sourceImage.width, scaleWidth);
                TKUnit.assertEqual(sourceImage.height, scaleHeight);
                done();
            });
        } else {
            done(`Error saving photo to local temp folder: ${localFullPath}`);
        }
    }, (error) => {
开发者ID:NathanWalker,项目名称:NativeScript,代码行数:21,代码来源:image-source-tests.ts

示例4: _cleanFiles

 private static _cleanFiles(): void {
   // Clear Temp
   const folder: fs.Folder = fs.knownFolders.temp();
   folder.clear();
 }
开发者ID:bthurlow,项目名称:nativescript-imagecropper,代码行数:5,代码来源:imagecropper.android.ts

示例5: if

    return new Promise<Result>((resolve: (val: Result) => void, reject: (val: Result) => void) => {
      try {
        _options = options;
        if (image.android) {
          const sourcePathTemp: string = ImageCropper._storeImageSource(image);
          const folder: fs.Folder = fs.knownFolders.temp();
          const destinationPathTemp: string = fs.path.join(folder.path, "destTemp.jpeg");
          if (sourcePathTemp == null) {
            ImageCropper._cleanFiles();
            reject({
              response: "Error",
              image: null
            });
          }

          const sourcePath: android.net.Uri = android.net.Uri.parse("file://" + sourcePathTemp); // Fix our path that comes from {N} file-system.
          const destinationPath: android.net.Uri = android.net.Uri.parse("file://" + destinationPathTemp); // Fix our path that comes from {N} file-system.

          const onResult = function(args) {
            const requestCode = args.requestCode;
            const resultCode = args.resultCode;
            const data = args.intent;
            // var _that = this;

            if (resultCode === android.app.Activity.RESULT_OK && requestCode === com.yalantis.ucrop.UCrop.REQUEST_CROP) {
              const resultUri: android.net.Uri = com.yalantis.ucrop.UCrop.getOutput(data);
              const is: ImageSource = new ImageSource();
              try {
                is.setNativeSource(android.graphics.BitmapFactory.decodeFile(resultUri.getPath()));
              } catch (e) {
                console.error(e);
              }
              ImageCropper._cleanFiles();
              application.android.off(application.AndroidApplication.activityResultEvent, onResult);
              if (is.android) {
                resolve({
                  response: "Success",
                  image: is,
                });
              } else {
                reject({
                  response: "Error",
                  image: null
                });
              }
              return;
            }
            else if (resultCode === android.app.Activity.RESULT_CANCELED && requestCode === com.yalantis.ucrop.UCrop.REQUEST_CROP) {
              ImageCropper._cleanFiles();
              application.android.off(application.AndroidApplication.activityResultEvent, onResult);
              resolve({
                response: "Cancelled",
                image: null
              });
              return;
            }
            else if (resultCode === com.yalantis.ucrop.UCrop.RESULT_ERROR) {
              ImageCropper._cleanFiles();
              const cropError: java.lang.Throwable = com.yalantis.ucrop.UCrop.getError(data);
              console.log(cropError.getMessage());
              application.android.off(application.AndroidApplication.activityResultEvent, onResult);
              reject({
                response: "Error",
                image: null
              });
              return;
            }
          };

          application.android.on(application.AndroidApplication.activityResultEvent, onResult);

          if (_options && _options.width && _options.height) {
            const gcd = ImageCropper._gcd(_options.width, _options.height);
            // console.log("gcd:" + gcd.toString());

            com.yalantis.ucrop.UCrop.of(sourcePath, destinationPath)
              .withAspectRatio(_options.width / gcd, _options.height / gcd)
              .withMaxResultSize(_options.width, _options.height)
              .start(ImageCropper._getContext());
          }
          else {
            com.yalantis.ucrop.UCrop.of(sourcePath, destinationPath)
              // .useSourceImageAspectRatio()
              .start(ImageCropper._getContext());
          }
        }
        else {
          // application.android.off(application.AndroidApplication.activityResultEvent, this.onResult);
          reject({
            response: "Error",
            image: null
          });
        }
      } catch (e) {
        // application.android.off(application.AndroidApplication.activityResultEvent, this.onResult);
        reject({
          response: "Error",
          image: null
        });
      }
//.........这里部分代码省略.........
开发者ID:bthurlow,项目名称:nativescript-imagecropper,代码行数:101,代码来源:imagecropper.android.ts


注:本文中的tns-core-modules/file-system.knownFolders.temp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。