How to use the tns-core-modules/utils/utils.ad function in tns-core-modules

To help you get started, we’ve selected a few tns-core-modules examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NativeScript / sample-android-background-services / app / notifications / MyJobService.js View on Github external
const ad = require("tns-core-modules/utils/utils").ad;
const context = ad.getApplicationContext();

android.app.job.JobService.extend("com.tns.notifications.MyJobService", {
    onStartJob: function(params) {       
        console.log("Job execution ...");

        // Do something useful here, fetch data and show notification for example
        const builder = new android.app.Notification.Builder(context);
        builder.setContentTitle("Scheduled Notification")
            .setAutoCancel(true)
            .setColor(android.R.color.holo_purple)//getResources().getColor(R.color.colorAccent))
            .setContentText("This notification has been triggered by Notification Service")
            .setVibrate([100, 200, 100])
            .setSmallIcon(android.R.drawable.btn_star_big_on);
    
        // will open main NativeScript activity when the notification is pressed
github EddyVerbruggen / nativescript-local-notifications / local-notifications.android.js View on Github external
var utils = require("tns-core-modules/utils/utils");
var LocalNotifications = require("./local-notifications-common");
var context = utils.ad.getApplicationContext();

LocalNotifications.addOnMessageReceivedCallback = function (callback) {
  return new Promise(function (resolve, reject) {
    try {
      // note that this is ONLY triggered when the user clicked the notification in the statusbar
      com.telerik.localnotifications.LocalNotificationsPlugin.setOnMessageReceivedCallback(
          new com.telerik.localnotifications.LocalNotificationsPluginListener({
            success: function (notification) {
              callback(JSON.parse(notification));
            }
          })
      );
      resolve();
    } catch (ex) {
      console.log("Error in LocalNotifications.addOnMessageReceivedCallback: " + ex);
      reject(ex);
github EddyVerbruggen / nativescript-mapbox / src / mapbox.android.ts View on Github external
_downloadMarkerImages(markers).then(updatedMarkers => {
    for (let m in updatedMarkers) {
      let marker: any = updatedMarkers[m];
      _markers.push(marker);
      let markerOptions = new com.mapbox.mapboxsdk.annotations.MarkerOptions();
      markerOptions.setTitle(marker.title);
      markerOptions.setSnippet(marker.subtitle);
      markerOptions.setPosition(new com.mapbox.mapboxsdk.geometry.LatLng(parseFloat(marker.lat), parseFloat(marker.lng)));

      if (marker.icon) {
        // for markers from url see UrlMarker in https://github.com/mapbox/mapbox-gl-native/issues/5370
        if (marker.icon.startsWith("res://")) {
          let resourcename = marker.icon.substring(6);
          let res = utils.ad.getApplicationContext().getResources();
          let identifier = res.getIdentifier(resourcename, "drawable", utils.ad.getApplication().getPackageName());
          if (identifier === 0) {
            console.log(`No icon found for this device density for icon ' ${marker.icon}'. Falling back to the default icon.`);
          } else {
            markerOptions.setIcon(iconFactory.fromResource(identifier));
          }
        } else if (marker.icon.startsWith("http")) {
          if (marker.iconDownloaded !== null) {
            markerOptions.setIcon(iconFactory.fromBitmap(marker.iconDownloaded));
          }
        } else {
          console.log("Please use res://resourcename, http(s)://imageurl or iconPath to use a local path");
        }

      } else if (marker.iconPath) {
        let iconFullPath = fs.knownFolders.currentApp().path + "/" + marker.iconPath;
github armackey / nativescript-twilio-video / src / android / twilio-video.ts View on Github external
start_preview(): any {

        if (this.localVideoTrack && this.localVideoTrack !== null) {

            return;

        };
        // this.cameraCapturer = new CameraCapturer(utilsModule.ad.getApplicationContext(), CameraCapturer.CameraSource.FRONT_CAMERA, this.cameraListener());

        this.cameraCapturer = new CameraCapturer(utilsModule.ad.getApplicationContext(), CameraCapturer.CameraSource.FRONT_CAMERA, null);


        this.localVideoTrack = LocalVideoTrack.create(utilsModule.ad.getApplicationContext(), true, this.cameraCapturer, 'camera');


        this.localVideoTrack.addRenderer(this.localVideoView);


        this.localVideoView.setMirror(true);


    }
github EddyVerbruggen / nativescript-secure-storage / src / secure-storage.android.ts View on Github external
constructor() {
    super();
    this.hawk = com.orhanobut.hawk.Hawk.init(utils.ad.getApplicationContext()).build();
  }
github triniwiz / nativescript-stripe / src / stripe.android.ts View on Github external
constructor(apiKey: string) {
    this._stripe = new com.stripe.android.Stripe(
      utils.ad.getApplicationContext(),
      apiKey
    );
  }
github VideoSpike / nativescript-web-image-cache / and-ts-lib / helpers.js View on Github external
Helpers.getPlaceholderImageDrawable = function (value) {
        var 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;
                    var res = utils.ad.getApplicationContext().getResources();
                    var resName = fileName.substr(utils.RESOURCE_PREFIX.length);
                    var identifier = res.getIdentifier(resName, 'drawable', utils.ad.getApplication().getPackageName());
                    drawable = res.getDrawable(identifier);
                }
            }
        }
        return drawable;
    };
    Helpers.setSource = function (image, value) {
github EddyVerbruggen / nativescript-bluetooth / src / android / android_main.js View on Github external
return new Promise(function (resolve, reject) {
            try {
                if (!arg.UUID) {
                    reject('No UUID was passed');
                    return;
                }
                var bluetoothDevice = _this.adapter.getRemoteDevice(arg.UUID);
                if (bluetoothDevice === null) {
                    reject('Could not find peripheral with UUID ' + arg.UUID);
                }
                else {
                    common_1.CLog(common_1.CLogTypes.info, "Bluetooth.connect ---- Connecting to peripheral with UUID: " + arg.UUID);
                    var gatt = void 0;
                    if (SDK_INT >= 23) {
                        gatt = bluetoothDevice.connectGatt(utils.ad.getApplicationContext(), false, _this.bluetoothGattCallback);
                    }
                    else {
                        gatt = bluetoothDevice.connectGatt(utils.ad.getApplicationContext(), false, _this.bluetoothGattCallback, android.bluetooth.BluetoothDevice.TRANSPORT_LE);
                    }
                    _this.connections[arg.UUID] = {
                        state: 'connecting',
                        onConnected: arg.onConnected,
                        onDisconnected: arg.onDisconnected,
                        device: gatt
                    };
                    resolve();
                }
            }
            catch (ex) {
                common_1.CLog(common_1.CLogTypes.error, "Bluetooth.connect ---- error: " + ex);
                reject(ex);
github armackey / nativescript-twilio-video / src / android / remoteVideo.js View on Github external
function RemoteVideo() {
        var _this = _super.call(this) || this;
        _this.remoteVideoView = new com.twilio.video.VideoView(utils.ad.getApplicationContext());
        return _this;
    }
    Object.defineProperty(RemoteVideo.prototype, "android", {
github triniwiz / nativescript-image-zoom / src / image-zoom.android.ts View on Github external
[srcProperty.setNative](src: string) {
    if (!src) return;
    let source;
    if (src.startsWith('~/')) {
      const uri = fs.path.join(
        fs.knownFolders.currentApp().path,
        src.replace('~/', '')
      );
      source = com.davemorrissey.labs.subscaleview.ImageSource.uri(uri);
    } else if (src.startsWith('res://')) {
      const name = src.replace('res://', '');
      const identifier: number = utils.ad
        .getApplication()
        .getResources()
        .getIdentifier(
          name,
          'drawable',
          utils.ad.getApplication().getPackageName()
        );
      source = com.davemorrissey.labs.subscaleview.ImageSource.resource(
        identifier
      );
    } else if (src.startsWith('http')) {
      imageSource.fromUrl(src).then((data: imageSource.ImageSource) => {
        source = com.davemorrissey.labs.subscaleview.ImageSource.bitmap(
          data.android
        );
        this.nativeView.setImage(source);