|
| 1 | +import { Injectable } from '@angular/core'; |
| 2 | +import { Plugin, Cordova, IonicNativePlugin } from '@ionic-native/core'; |
| 3 | + |
| 4 | +/** |
| 5 | + * @name Android Notch |
| 6 | + * @description |
| 7 | + * This plugin enables developers to get the cutout and android devices inset sizes |
| 8 | + * It is based on the cordova plugin developed by @tobspr: https://github.com/tobspr/cordova-plugin-android-notch |
| 9 | + * This plugin works on all android versions, but we can only detect notches starting from Android 9. |
| 10 | + * |
| 11 | + * @usage |
| 12 | + * ```typescript |
| 13 | + * import { AndroidNotch } from '@ionic-native/android-notch/nx'; |
| 14 | + * |
| 15 | + * |
| 16 | + * constructor(private androidNotch: AndroidNotch) { } |
| 17 | + * |
| 18 | + * ... |
| 19 | + * |
| 20 | + * |
| 21 | + * this.androidNotch.hasCutout() |
| 22 | + * .then((px: number) => console.log('Inset size: '), px) |
| 23 | + * .catch((error: any) => console.log('Error: ', error)) |
| 24 | + * |
| 25 | + * this.androidNotch.getInsetTop() |
| 26 | + * .then((px: number) => console.log('Inset size: '), px) |
| 27 | + * .catch((error: any) => console.log('Error: ', error)) |
| 28 | + * |
| 29 | + * this.androidNotch.getInsetRight() |
| 30 | + * .then((px: number) => console.log('Inset size: '), px) |
| 31 | + * .catch((error: any) => console.log('Error: ', error)) |
| 32 | + * |
| 33 | + * this.androidNotch.getInsetBottom() |
| 34 | + * .then((px: number) => console.log('Inset size: '), px) |
| 35 | + * .catch((error: any) => console.log('Error: ', error)) |
| 36 | + * |
| 37 | + * this.androidNotch.getInsetLeft() |
| 38 | + * .then((px: number) => console.log('Inset size: '), px) |
| 39 | + * .catch((error: any) => console.log('Error: ', error)) |
| 40 | + * |
| 41 | + * ``` |
| 42 | + */ |
| 43 | +@Plugin({ |
| 44 | + pluginName: 'AndroidNotch', |
| 45 | + plugin: 'cordova-plugin-android-notch', |
| 46 | + pluginRef: 'AndroidNotch', |
| 47 | + repo: 'https://github.com/tobspr/cordova-plugin-android-notch.git', |
| 48 | + platforms: ['Android'], |
| 49 | +}) |
| 50 | +@Injectable() |
| 51 | +export class AndroidNotch extends IonicNativePlugin { |
| 52 | + /** |
| 53 | + * Returns true if the android device has cutout |
| 54 | + * |
| 55 | + * @return {Promise<boolean>} |
| 56 | + */ |
| 57 | + @Cordova() |
| 58 | + hasCutout(): Promise<boolean> { |
| 59 | + return; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Returns the heigth of the top inset |
| 64 | + * |
| 65 | + * @return {Promise<number>} |
| 66 | + */ |
| 67 | + @Cordova() |
| 68 | + getInsetTop(): Promise<number> { |
| 69 | + return; |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Returns the heigth of the right inset |
| 74 | + * |
| 75 | + * @return {Promise<number>} |
| 76 | + */ |
| 77 | + @Cordova() |
| 78 | + getInsetRight(): Promise<number> { |
| 79 | + return; |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * Returns the heigth of the bottom inset |
| 84 | + * @return {Promise<number>} |
| 85 | + */ |
| 86 | + @Cordova() |
| 87 | + getInsetBottom(): Promise<number> { |
| 88 | + return; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Returns the heigth of the left inset |
| 93 | + * @return {Promise<number>} |
| 94 | + */ |
| 95 | + @Cordova() |
| 96 | + getInsetLeft(): Promise<number> { |
| 97 | + return; |
| 98 | + } |
| 99 | +} |
0 commit comments