Skip to content

Instantly share code, notes, and snippets.

View roblav96's full-sized avatar

Robert Laverty roblav96

View GitHub Profile
@roblav96
roblav96 / permissions.android.ts
Last active September 10, 2016 17:13
Example of platform specific ng2 injectable services in NativeScript
//
import * as application from "application"
import {Injectable} from "@angular/core"
function permissionResult(permission: string, type: string): boolean {
if (!android.support || !android.support.v4 || !android.support.v4.content || !android.support.v4.content.ContextCompat || !android.support.v4.content.ContextCompat.checkSelfPermission) {
let result: boolean = (type == 'PERMISSION_GRANTED') ? true : false
@roblav96
roblav96 / permissions.ios.ts
Created September 27, 2016 20:38
Get contacts permissions on ios10
export class PermissionsClass {
private static _contactStore: CNContactStore = CNContactStore.alloc().init()
private _getContactsAuthorization(): CNAuthorizationStatus {
return CNContactStore.authorizationStatusForEntityType(CNEntityType.Contacts)
}
isContactsAuthorized(): boolean {
return this._getContactsAuthorization() == CNAuthorizationStatus.Authorized
@JavaProxy('com.tns.NativeScriptActivity')
class Activity extends android.app.Activity {
private _callbacks: frame.AndroidActivityCallbacks
onCreate(savedInstanceState: android.os.Bundle): void {
if (!this._callbacks) {
(<any>frame).setActivityCallbacks(this)
}
this._callbacks.onCreate(this, savedInstanceState, super.onCreate)
declare var EVContactsPickerVersionNumber: number;
declare var EVContactsPickerVersionString: interop.Reference<number>;
declare class EVContactsPickerViewController extends UIViewController implements CNContactViewControllerDelegate, UIScrollViewDelegate, UITableViewDataSource, UITableViewDelegate {
static alloc(): EVContactsPickerViewController; // inherited from NSObject
static new(): EVContactsPickerViewController; // inherited from NSObject

@objc exposes the delegate

@objc public protocol EPPickerDelegate { // NOTICE THE @objc
    optional    func epContactPicker(_: EPContactsPicker, didContactFetchFailed error: NSError)
    optional    func epContactPicker(_: EPContactsPicker, didCancel error: NSError)
    optional    func epContactPicker(_: EPContactsPicker, didSelectContact contact: EPContact)
    optional    func epContactPicker(_: EPContactsPicker, didSelectMultipleContacts contacts: [EPContact])
}
@roblav96
roblav96 / database.android.ts
Created November 9, 2016 20:44
nativescript-sqlite
export class DatabaseClass<T> extends DatabaseClassCommon<T> {
private _sqlite: io.requery.android.database.sqlite.SQLiteDatabase
constructor(opts: DatabaseOpts) {
super(opts)
if (application.android.context) {
this._initTable()
} else {
@roblav96
roblav96 / picker.android.ts
Created November 9, 2016 20:50
nativescript-image-picker
export function pickImage(): Promise<ImageSource> {
return new Promise(function(resolve, reject) {
let reqid: number = Math.floor(Math.random() * 999)
function onActivityResult(args: application.AndroidActivityResultEventData) {
Utils.parseActivityResult(args, reqid, resolve, reject)
}
application.android.addEventListener(application.AndroidApplication.activityResultEvent, onActivityResult)
@roblav96
roblav96 / picker.android.ts
Created November 9, 2016 20:52
nativescript-contacts-picker
export function pickContacts(): Promise<ContactsPickerItem> {
return new Promise(function(resolve, reject) {
let reqid: number = Math.floor(Math.random() * 999)
function onActivityResult(args: application.AndroidActivityResultEventData) {
Utils.parseActivityResult(args, reqid, resolve, reject)
}
application.android.addEventListener(application.AndroidApplication.activityResultEvent, onActivityResult)
Utils.uiAsync(() => {
@roblav96
roblav96 / coach.android.ts
Created November 21, 2016 22:57
nativescript-coaches
//
import * as application from 'application'
import { Color } from 'color'
import { ad } from 'utils/utils'
import * as Utils from '../utils/utils'
import { CoachItem, CoachOpts } from './coach'
import { CoachShape, CoachLabelPosition, CoachLabelAlignment } from './coach.common'
//
import common = require('./iimage.common')
import * as application from 'application'
import { View } from 'ui/core/view'
import { Property, PropertyMetadataSettings, PropertyChangeData } from 'ui/core/dependency-observable'
import { PropertyMetadata } from 'ui/core/proxy'
import { Stretch } from 'ui/enums'
import { ImageSource } from 'image-source'
import { knownFolders, path } from 'file-system'