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


TypeScript utils.ad类代码示例

本文整理汇总了TypeScript中utils/utils.ad的典型用法代码示例。如果您正苦于以下问题:TypeScript ad类的具体用法?TypeScript ad怎么用?TypeScript ad使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: constructor

 public constructor(databaseName: string) {
     this.context = utils.ad.getApplicationContext();
     try {
         this.manager = new com.couchbase.lite.Manager(new com.couchbase.lite.android.AndroidContext(this.context), null);
         this.database = this.manager.getDatabase(databaseName);
     } catch (exception) {
         console.error("MANAGER ERROR:", exception.message);
         throw new Error("MANAGER ERROR: " + exception.message);
     }
 }
开发者ID:couchbaselabs,项目名称:nativescript-couchbase,代码行数:10,代码来源:couchbase.android.ts

示例2: Promise

  return new Promise(function (resolve, reject) {
    try { 
      // or macaddress..
      if (!arg.UUID) {
        reject("No UUID was passed");
        return;
      }
      var bluetoothDevice = adapter.getRemoteDevice(arg.UUID);
      if (bluetoothDevice === null) {
        reject("Could not find peripheral with UUID " + arg.UUID);
      } else {
        console.log("Connecting to peripheral with UUID: " + arg.UUID);

        var bluetoothGatt;
        if (android.os.Build.VERSION.SDK_INT < 23 /*android.os.Build.VERSION_CODES.M */) {
          bluetoothGatt = bluetoothDevice.connectGatt(
              utils.ad.getApplicationContext(), // context
              false, // autoconnect
              new Bluetooth._MyGattCallback(/* TODO pass in onWhatever function */)
          );
        } else {
          bluetoothGatt = bluetoothDevice.connectGatt(
              utils.ad.getApplicationContext(), // context
              false, // autoconnect
              new Bluetooth._MyGattCallback(/* TODO pass in onWhatever function */),
              android.bluetooth.BluetoothDevice.TRANSPORT_LE // 2
          );
        }

        Bluetooth._connections[arg.UUID] = {
          state: 'connecting',
          onConnected: arg.onConnected,
          onDisconnected: arg.onDisconnected,
          device: bluetoothGatt // TODO rename device to gatt?
        };
      }
    } catch (ex) {
      console.log("Error in Bluetooth.connect: " + ex);
      reject(ex);
    }
  });
开发者ID:georgeedwards,项目名称:nativescript-bluetooth,代码行数:41,代码来源:bluetooth.android.ts

示例3: Promise

    return new Promise((resolve, reject) => {
        try {
            var types: typeof typesModule = require("utils/types");
            var utils: typeof utilsModule = require("utils/utils");

            var density = utils.layout.getDisplayDensity();
            if (options) {
                var reqWidth = options.width ? options.width * density : 0;
                var reqHeight = options.height ? options.height * density : reqWidth;
                var shouldKeepAspectRatio = types.isNullOrUndefined(options.keepAspectRatio) ? true : options.keepAspectRatio;
            }
            var takePictureIntent = new android.content.Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            var dateStamp = createDateTimeStamp();

            var fileSystem: typeof fileSystemModule = require("file-system");

            var tempPicturePath = fileSystem.path.join(utils.ad.getApplicationContext().getExternalFilesDir(null).getAbsolutePath(), "cameraPicture_" + dateStamp + ".jpg");
            var nativeFile = new java.io.File(tempPicturePath);
            var tempPictureUri = android.net.Uri.fromFile(nativeFile);
            takePictureIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, tempPictureUri);
            if (takePictureIntent.resolveActivity(utils.ad.getApplicationContext().getPackageManager()) != null) {

                var appModule: typeof applicationModule = require("application");

                var previousResult = appModule.android.onActivityResult;
                appModule.android.onActivityResult = (requestCode: number, resultCode: number, data: android.content.Intent) => {
                    appModule.android.onActivityResult = previousResult;

                    if (requestCode === REQUEST_IMAGE_CAPTURE && resultCode === android.app.Activity.RESULT_OK) {
                        var options = new android.graphics.BitmapFactory.Options();
                        options.inJustDecodeBounds = true;
                        android.graphics.BitmapFactory.decodeFile(tempPicturePath, options);

                        var sampleSize = calculateInSampleSize(options.outWidth, options.outHeight, reqWidth, reqHeight);

                        var finalBitmapOptions = new android.graphics.BitmapFactory.Options();
                        finalBitmapOptions.inSampleSize = sampleSize;
                        var bitmap = android.graphics.BitmapFactory.decodeFile(tempPicturePath, finalBitmapOptions);
                        var scaledSizeImage = null;
                        if (reqHeight > 0 && reqWidth > 0) {
                            if (shouldKeepAspectRatio) {

                                var common: typeof cameraCommonModule = require("./camera-common");

                                var aspectSafeSize = common.getAspectSafeDimensions(bitmap.getWidth(), bitmap.getHeight(), reqWidth, reqHeight);
                                scaledSizeImage = android.graphics.Bitmap.createScaledBitmap(bitmap, aspectSafeSize.width, aspectSafeSize.height, true);
                            }
                            else {
                                scaledSizeImage = android.graphics.Bitmap.createScaledBitmap(bitmap, reqWidth, reqHeight, true);
                            }
                        }
                        else {
                            scaledSizeImage = bitmap;
                        }

                        var imageSource: typeof imageSourceModule = require("image-source");

                        resolve(imageSource.fromNativeSource(scaledSizeImage));
                    }
                };

                appModule.android.foregroundActivity.startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);

            }
        } catch (e) {
            if (reject) {
                reject(e);
            }
        }
    });
开发者ID:ahmadissa2,项目名称:NativeScript,代码行数:70,代码来源:camera.android.ts

示例4: function

(function () {
  var bluetoothManager = utils.ad.getApplicationContext().getSystemService(android.content.Context.BLUETOOTH_SERVICE);
  adapter = bluetoothManager.getAdapter();

  if (android.os.Build.VERSION.SDK_INT >= 21 /*android.os.Build.VERSION_CODES.LOLLIPOP */) {
    var MyScanCallback = android.bluetooth.le.ScanCallback.extend({
      onBatchScanResults: function(results) {
        console.log("------- scanCallback.onBatchScanResults");
      },
      onScanFailed: function(errorCode) {
        console.log("------- scanCallback.onScanFailed errorCode: " + errorCode);
        var errorMessage;
        if (errorCode == android.bluetooth.le.ScanCallback.SCAN_FAILED_ALREADY_STARTED) {
          errorMessage = "Scan already started";
        } else if (errorCode == android.bluetooth.le.ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED) {
          errorMessage = "Application registration failed";
        } else if (errorCode == android.bluetooth.le.ScanCallback.SCAN_FAILED_FEATURE_UNSUPPORTED) {
          errorMessage = "Feature unsupported";
        } else if (errorCode == android.bluetooth.le.ScanCallback.SCAN_FAILED_INTERNAL_ERROR) {
          errorMessage = "Internal error";
        } else {
          errorMessage = "Scan failed to start";
        }
        console.log("------- scanCallback.onScanFailed errorMessage: " + errorMessage);
      },
      onScanResult: function(callbackType, result) {
        var stateObject = Bluetooth._connections[result.getDevice().getAddress()];
        if (!stateObject) {
          Bluetooth._connections[result.getDevice().getAddress()] = {
            state: 'disconnected'
          };
          var payload = {
            type: 'scanResult', // TODO or use different callback functions?
            UUID: result.getDevice().getAddress(),
            name: result.getDevice().getName(),
            RSSI: result.getRssi(),
            state: 'disconnected',
            advertisement: android.util.Base64.encodeToString(result.getScanRecord().getBytes(), android.util.Base64.NO_WRAP)
          };
          console.log("---- Lollipop+ scanCallback result: " + JSON.stringify(payload));
          onDiscovered(payload);
        }
      }
    });
    Bluetooth._scanCallback = new MyScanCallback();
  } else {
    Bluetooth._scanCallback = new android.bluetooth.BluetoothAdapter.LeScanCallback({
      // see https://github.com/randdusing/cordova-plugin-bluetoothle/blob/master/src/android/BluetoothLePlugin.java#L2181
      onLeScan: function(device, rssi, scanRecord) {
        var stateObject = Bluetooth._connections[device.getAddress()];
        if (!stateObject) {
          Bluetooth._connections[device.getAddress()] = {
            state: 'disconnected'
          };
          onDiscovered({
            type: 'scanResult', // TODO or use different callback functions?
            UUID: device.getAddress(), // TODO consider renaming to id (and iOS as well)
            name: device.getName(),
            RSSI: rssi,
            state: 'disconnected'
          });
        }
      }
    });
  }
})();
开发者ID:georgeedwards,项目名称:nativescript-bluetooth,代码行数:66,代码来源:bluetooth.android.ts

示例5: Promise

    return new Promise((resolve, reject) => {
        try {
            let types: typeof typesModule = require("utils/types");
            let utils: typeof utilsModule = require("utils/utils");
            
            let saveToGallery;
            let reqWidth;
            let reqHeight;
            let shouldKeepAspectRatio;

            let density = utils.layout.getDisplayDensity();
            if (options) {
                saveToGallery = options.saveToGallery ? true : false;
                reqWidth = options.width ? options.width * density : 0;
                reqHeight = options.height ? options.height * density : reqWidth;
                shouldKeepAspectRatio = types.isNullOrUndefined(options.keepAspectRatio) ? true : options.keepAspectRatio;
            }
            let takePictureIntent = new android.content.Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            let dateStamp = createDateTimeStamp();
            
            let picturePath: string;
            let nativeFile;
            let tempPictureUri;

            if (saveToGallery) {
                picturePath = android.os.Environment.getExternalStoragePublicDirectory(
                    android.os.Environment.DIRECTORY_PICTURES).getAbsolutePath() + "/" + "cameraPicture_" + dateStamp + ".jpg";
                nativeFile = new java.io.File(picturePath);
                tempPictureUri = android.net.Uri.fromFile(nativeFile);
                takePictureIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, tempPictureUri);
            } else {
                picturePath = utils.ad.getApplicationContext().getExternalFilesDir(null).getAbsolutePath() + "/" + "cameraPicture_" + dateStamp + ".jpg";
                nativeFile = new java.io.File(picturePath);
                tempPictureUri = android.net.Uri.fromFile(nativeFile);
                takePictureIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, tempPictureUri);
            }

            if (takePictureIntent.resolveActivity(utils.ad.getApplicationContext().getPackageManager()) != null) {

                let appModule: typeof applicationModule = require("application");

                let previousResult = appModule.android.onActivityResult;
                appModule.android.onActivityResult = (requestCode: number, resultCode: number, data: android.content.Intent) => {
                    appModule.android.onActivityResult = previousResult;

                    if (requestCode === REQUEST_IMAGE_CAPTURE && resultCode === android.app.Activity.RESULT_OK) {
                        let imageSource: typeof imageSourceModule = require("image-source");
                        let options = new android.graphics.BitmapFactory.Options();
                        options.inJustDecodeBounds = true;
                        android.graphics.BitmapFactory.decodeFile(picturePath, options);

                        let sampleSize = calculateInSampleSize(options.outWidth, options.outHeight, reqWidth, reqHeight);

                        let finalBitmapOptions = new android.graphics.BitmapFactory.Options();
                        finalBitmapOptions.inSampleSize = sampleSize;
                        let bitmap = android.graphics.BitmapFactory.decodeFile(picturePath, finalBitmapOptions);
                        let scaledSizeImage = null;
                        if (reqHeight > 0 && reqWidth > 0) {
                            if (shouldKeepAspectRatio) {

                                let common: typeof cameraCommonModule = require("./camera-common");

                                let aspectSafeSize = common.getAspectSafeDimensions(bitmap.getWidth(), bitmap.getHeight(), reqWidth, reqHeight);
                                scaledSizeImage = android.graphics.Bitmap.createScaledBitmap(bitmap, aspectSafeSize.width, aspectSafeSize.height, true);
                            }
                            else {
                                scaledSizeImage = android.graphics.Bitmap.createScaledBitmap(bitmap, reqWidth, reqHeight, true);
                            }
                        }
                        else {
                            scaledSizeImage = bitmap;
                        }

                        let ei = new android.media.ExifInterface(picturePath);
                        let orientation = ei.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION, android.media.ExifInterface.ORIENTATION_NORMAL);

                        switch (orientation) {
                            case android.media.ExifInterface.ORIENTATION_ROTATE_90:
                                scaledSizeImage = rotateBitmap(scaledSizeImage, 90);
                                break;
                            case android.media.ExifInterface.ORIENTATION_ROTATE_180:
                                scaledSizeImage = rotateBitmap(scaledSizeImage, 180);
                                break;
                            case android.media.ExifInterface.ORIENTATION_ROTATE_270:
                                scaledSizeImage = rotateBitmap(scaledSizeImage, 270);
                                break;
                        }

                        resolve(imageSource.fromNativeSource(scaledSizeImage));
                    }
                };

                appModule.android.foregroundActivity.startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);

            }
        } catch (e) {
            if (reject) {
                reject(e);
            }
        }
//.........这里部分代码省略.........
开发者ID:329379172,项目名称:NativeScript,代码行数:101,代码来源:camera.android.ts

示例6: function

export var isAvailable = function () {
    var utils: typeof utilsModule = require("utils/utils");
    
    return utils.ad.getApplicationContext().getPackageManager().hasSystemFeature(android.content.pm.PackageManager.FEATURE_CAMERA)
}
开发者ID:329379172,项目名称:NativeScript,代码行数:5,代码来源:camera.android.ts

示例7: function

 return function () {
   if (resources === null) {
     resources = utils.ad.getApplicationContext().getResources();
   }
   return resources;
 };
开发者ID:surdu,项目名称:nativescript-localize,代码行数:6,代码来源:localize.android.ts


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