本文整理汇总了TypeScript中utils/utils.ad.getApplicationContext方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ad.getApplicationContext方法的具体用法?TypeScript ad.getApplicationContext怎么用?TypeScript ad.getApplicationContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils/utils.ad
的用法示例。
在下文中一共展示了ad.getApplicationContext方法的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);
}
}
示例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);
}
});
示例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);
}
}
});
示例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'
});
}
}
});
}
})();
示例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);
}
}
//.........这里部分代码省略.........
示例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)
}
示例7: function
return function () {
if (resources === null) {
resources = utils.ad.getApplicationContext().getResources();
}
return resources;
};