cleaning utils
This commit is contained in:
parent
926914e3c4
commit
460c5a5cbe
1 changed files with 39 additions and 71 deletions
|
@ -15,48 +15,13 @@ declare const global, android, androidx, com, java, Array: any
|
||||||
|
|
||||||
const View = android.view.View
|
const View = android.view.View
|
||||||
const PowerManager = android.os.PowerManager
|
const PowerManager = android.os.PowerManager
|
||||||
const pm = Utils.android
|
const ctx = Utils.android.getApplicationContext()
|
||||||
.getApplicationContext()
|
const pm = ctx.getSystemService(android.content.Context.POWER_SERVICE)
|
||||||
.getSystemService(android.content.Context.POWER_SERVICE)
|
|
||||||
const wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, 'Timers')
|
const wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, 'Timers')
|
||||||
|
|
||||||
const sdkv = parseInt(Device.sdkVersion)
|
const sdkv = parseInt(Device.sdkVersion)
|
||||||
|
|
||||||
export function restartApp() {
|
|
||||||
const ctx = Utils.ad.getApplicationContext()
|
|
||||||
let mStartActivity = new android.content.Intent(
|
|
||||||
ctx,
|
|
||||||
Application.android.startActivity.getClass()
|
|
||||||
)
|
|
||||||
let mPendingIntentId = Math.random() * 100000
|
|
||||||
let mPendingIntent = android.app.PendingIntent.getActivity(
|
|
||||||
ctx,
|
|
||||||
mPendingIntentId,
|
|
||||||
mStartActivity,
|
|
||||||
android.app.PendingIntent.FLAG_CANCEL_CURRENT
|
|
||||||
)
|
|
||||||
let mgr = ctx.getSystemService(android.content.Context.ALARM_SERVICE)
|
|
||||||
mgr.set(
|
|
||||||
android.app.AlarmManager.RTC,
|
|
||||||
java.lang.System.currentTimeMillis() + 100,
|
|
||||||
mPendingIntent
|
|
||||||
)
|
|
||||||
android.os.Process.killProcess(android.os.Process.myPid())
|
|
||||||
}
|
|
||||||
export function openAppSettingsPage() {
|
|
||||||
let intent = new android.content.Intent(
|
|
||||||
android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS
|
|
||||||
)
|
|
||||||
intent.addCategory(android.content.Intent.CATEGORY_DEFAULT)
|
|
||||||
intent.setData(
|
|
||||||
android.net.Uri.parse(
|
|
||||||
'package:' + Application.android.context.getPackageName()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
Application.android.foregroundActivity.startActivity(intent)
|
|
||||||
}
|
|
||||||
export function hasAccelerometer() {
|
export function hasAccelerometer() {
|
||||||
let ctx = Utils.ad.getApplicationContext()
|
// let ctx = Utils.ad.getApplicationContext()
|
||||||
let sensorManager = ctx.getSystemService(
|
let sensorManager = ctx.getSystemService(
|
||||||
android.content.Context.SENSOR_SERVICE
|
android.content.Context.SENSOR_SERVICE
|
||||||
)
|
)
|
||||||
|
@ -98,7 +63,7 @@ function callIntent(ctx, intent, msg, pickerType) {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// IMAGE PICKER
|
// ImagePicker
|
||||||
export function getRecipePhoto() {
|
export function getRecipePhoto() {
|
||||||
const ctx =
|
const ctx =
|
||||||
Application.android.foregroundActivity || Application.android.startActivity
|
Application.android.foregroundActivity || Application.android.startActivity
|
||||||
|
@ -114,6 +79,7 @@ export function getRecipePhoto() {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function copyPhotoToCache(src: string, dest: string) {
|
export function copyPhotoToCache(src: string, dest: string) {
|
||||||
const ContentResolver = Application.android.nativeApp.getContentResolver()
|
const ContentResolver = Application.android.nativeApp.getContentResolver()
|
||||||
const isURI = src.includes('content://')
|
const isURI = src.includes('content://')
|
||||||
|
@ -147,7 +113,7 @@ export function copyPhotoToCache(src: string, dest: string) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// COPY DB FILE
|
// CopyDbFile
|
||||||
export function copyDBToExport() {
|
export function copyDBToExport() {
|
||||||
const src = path.join(knownFolders.documents().path, 'EnRecipes.db')
|
const src = path.join(knownFolders.documents().path, 'EnRecipes.db')
|
||||||
const dst = path.join(
|
const dst = path.join(
|
||||||
|
@ -167,7 +133,7 @@ export function copyDBToExport() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// BACKUP FOLDER PICKER
|
// BackupFolderPicker
|
||||||
export function getBackupFolder() {
|
export function getBackupFolder() {
|
||||||
const ctx =
|
const ctx =
|
||||||
Application.android.foregroundActivity || Application.android.startActivity
|
Application.android.foregroundActivity || Application.android.startActivity
|
||||||
|
@ -183,7 +149,7 @@ export function getBackupFolder() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BACKUP FILE PICKER
|
// BackupFilePicker
|
||||||
export function getBackupFile() {
|
export function getBackupFile() {
|
||||||
const ctx =
|
const ctx =
|
||||||
Application.android.foregroundActivity || Application.android.startActivity
|
Application.android.foregroundActivity || Application.android.startActivity
|
||||||
|
@ -202,7 +168,7 @@ export function getBackupFile() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ZIP OPERATIONS
|
// ZipOperations
|
||||||
export class Zip {
|
export class Zip {
|
||||||
static getSubFiles(src: string, isRootFolder?: number) {
|
static getSubFiles(src: string, isRootFolder?: number) {
|
||||||
const fileList = new java.util.ArrayList()
|
const fileList = new java.util.ArrayList()
|
||||||
|
@ -216,7 +182,7 @@ export class Zip {
|
||||||
if (isRootFolder) {
|
if (isRootFolder) {
|
||||||
fileList.add(tempList[i])
|
fileList.add(tempList[i])
|
||||||
}
|
}
|
||||||
fileList.addAll(Zip.getSubFiles(tempList[i].getAbsolutePath()))
|
fileList.addAll(this.getSubFiles(tempList[i].getAbsolutePath()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fileList
|
return fileList
|
||||||
|
@ -233,7 +199,7 @@ export class Zip {
|
||||||
let destFile = uri.createFile('application/zip', filename).getUri()
|
let destFile = uri.createFile('application/zip', filename).getUri()
|
||||||
const outputStream = ContentResolver.openOutputStream(destFile)
|
const outputStream = ContentResolver.openOutputStream(destFile)
|
||||||
const zipOutputStream = new java.util.zip.ZipOutputStream(outputStream)
|
const zipOutputStream = new java.util.zip.ZipOutputStream(outputStream)
|
||||||
const sourceFiles = Zip.getSubFiles(src, 1)
|
const sourceFiles = this.getSubFiles(src, 1)
|
||||||
for (let i = 0; i < sourceFiles.size(); i++) {
|
for (let i = 0; i < sourceFiles.size(); i++) {
|
||||||
let len
|
let len
|
||||||
let buffer = Array.create('byte', 4096)
|
let buffer = Array.create('byte', 4096)
|
||||||
|
@ -291,10 +257,10 @@ export class Zip {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SHARE OPERATIONS
|
// ShareOperations
|
||||||
|
|
||||||
function share(intent, subject) {
|
function share(intent, subject) {
|
||||||
const ctx = Application.android.context
|
// const ctx = Application.android.context
|
||||||
const shareIntent = android.content.Intent.createChooser(intent, subject)
|
const shareIntent = android.content.Intent.createChooser(intent, subject)
|
||||||
shareIntent.setFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK)
|
shareIntent.setFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
ctx.startActivity(shareIntent)
|
ctx.startActivity(shareIntent)
|
||||||
|
@ -310,7 +276,7 @@ export function shareText(text, subject) {
|
||||||
share(intent, subject)
|
share(intent, subject)
|
||||||
}
|
}
|
||||||
export function shareImage(image, subject, title) {
|
export function shareImage(image, subject, title) {
|
||||||
let ctx = Application.android.context
|
// let ctx = Application.android.context
|
||||||
const intent = getSendIntent('image/jpeg')
|
const intent = getSendIntent('image/jpeg')
|
||||||
const baos = new java.io.ByteArrayOutputStream()
|
const baos = new java.io.ByteArrayOutputStream()
|
||||||
image.android.compress(android.graphics.Bitmap.CompressFormat.JPEG, 100, baos)
|
image.android.compress(android.graphics.Bitmap.CompressFormat.JPEG, 100, baos)
|
||||||
|
@ -336,7 +302,21 @@ export function keepScreenOn(n: number) {
|
||||||
n ? window.addFlags(flag) : window.clearFlags(flag)
|
n ? window.addFlags(flag) : window.clearFlags(flag)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TIMER NOTIFICATION
|
interface INotification {
|
||||||
|
multi?: boolean
|
||||||
|
actions?: number
|
||||||
|
bID: string
|
||||||
|
cID: string
|
||||||
|
nID: number
|
||||||
|
cName: string
|
||||||
|
description: string
|
||||||
|
priority: number
|
||||||
|
sound: string
|
||||||
|
title: string
|
||||||
|
vibrate?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
// TimerNotification
|
||||||
export class TimerNotif {
|
export class TimerNotif {
|
||||||
static getIcon(ctx, icon) {
|
static getIcon(ctx, icon) {
|
||||||
const packageName = ctx.getApplicationInfo().packageName
|
const packageName = ctx.getApplicationInfo().packageName
|
||||||
|
@ -347,7 +327,7 @@ export class TimerNotif {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
static clear(nID) {
|
static clear(nID) {
|
||||||
let ctx = Utils.ad.getApplicationContext()
|
// let ctx = Utils.ad.getApplicationContext()
|
||||||
const NotifySrv = ctx.getSystemService(
|
const NotifySrv = ctx.getSystemService(
|
||||||
android.content.Context.NOTIFICATION_SERVICE
|
android.content.Context.NOTIFICATION_SERVICE
|
||||||
)
|
)
|
||||||
|
@ -366,18 +346,7 @@ export class TimerNotif {
|
||||||
sound,
|
sound,
|
||||||
title,
|
title,
|
||||||
vibrate,
|
vibrate,
|
||||||
}: {
|
}: INotification,
|
||||||
multi?: boolean
|
|
||||||
actions?: number
|
|
||||||
bID: string
|
|
||||||
cID: string
|
|
||||||
cName: string
|
|
||||||
description: string
|
|
||||||
priority: number
|
|
||||||
sound: string
|
|
||||||
title: string
|
|
||||||
vibrate?: number
|
|
||||||
},
|
|
||||||
ctx
|
ctx
|
||||||
) {
|
) {
|
||||||
let soundUri: any
|
let soundUri: any
|
||||||
|
@ -423,7 +392,7 @@ export class TimerNotif {
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT
|
PendingIntent.FLAG_UPDATE_CURRENT
|
||||||
)
|
)
|
||||||
|
|
||||||
// Action intent
|
// ActionIntent
|
||||||
let actionInt1,
|
let actionInt1,
|
||||||
actionInt2,
|
actionInt2,
|
||||||
actionInt3,
|
actionInt3,
|
||||||
|
@ -457,8 +426,7 @@ export class TimerNotif {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CREATE NOTIFICATION
|
// CreateNotification
|
||||||
|
|
||||||
let icon = this.getIcon(ctx, 'notify')
|
let icon = this.getIcon(ctx, 'notify')
|
||||||
let builder = new NotificationCompat.Builder(ctx, cID)
|
let builder = new NotificationCompat.Builder(ctx, cID)
|
||||||
.setColor(new Color('#ff5200').android)
|
.setColor(new Color('#ff5200').android)
|
||||||
|
@ -489,8 +457,8 @@ export class TimerNotif {
|
||||||
|
|
||||||
return notification
|
return notification
|
||||||
}
|
}
|
||||||
static show(data) {
|
static show(data: INotification) {
|
||||||
const ctx = Utils.ad.getApplicationContext()
|
// const ctx = Utils.ad.getApplicationContext()
|
||||||
const NotifySrv = ctx.getSystemService(
|
const NotifySrv = ctx.getSystemService(
|
||||||
android.content.Context.NOTIFICATION_SERVICE
|
android.content.Context.NOTIFICATION_SERVICE
|
||||||
)
|
)
|
||||||
|
@ -530,10 +498,10 @@ export class Printer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET RINGTONES LIST
|
// GetRingtonesList
|
||||||
export function getTones() {
|
export function getTones() {
|
||||||
const RingtoneManager = android.media.RingtoneManager
|
const RingtoneManager = android.media.RingtoneManager
|
||||||
let ctx = Utils.ad.getApplicationContext()
|
// let ctx = Utils.ad.getApplicationContext()
|
||||||
const ringtonesMgr = new RingtoneManager(ctx)
|
const ringtonesMgr = new RingtoneManager(ctx)
|
||||||
ringtonesMgr.setType(RingtoneManager.TYPE_ALARM)
|
ringtonesMgr.setType(RingtoneManager.TYPE_ALARM)
|
||||||
const cursor = ringtonesMgr.getCursor()
|
const cursor = ringtonesMgr.getCursor()
|
||||||
|
@ -566,7 +534,7 @@ export function getTones() {
|
||||||
return { tones, defaultTone: defaultToneUri ? defaultTone : tones[0] }
|
return { tones, defaultTone: defaultToneUri ? defaultTone : tones[0] }
|
||||||
}
|
}
|
||||||
|
|
||||||
//WAKE LOCK
|
// WakeLock
|
||||||
export function wakeLock(n): void {
|
export function wakeLock(n): void {
|
||||||
n ? !wl.isHeld() && wl.acquire() : wl.isHeld() && wl.release()
|
n ? !wl.isHeld() && wl.acquire() : wl.isHeld() && wl.release()
|
||||||
}
|
}
|
||||||
|
@ -589,7 +557,7 @@ export function updateLocale() {
|
||||||
let lang = ApplicationSettings.getString('appLocale', 'none').split('-')
|
let lang = ApplicationSettings.getString('appLocale', 'none').split('-')
|
||||||
const l = lang[0]
|
const l = lang[0]
|
||||||
const c = lang[1]
|
const c = lang[1]
|
||||||
const ctx = Utils.android.getApplicationContext()
|
// const ctx = Utils.android.getApplicationContext()
|
||||||
const res = ctx.getResources()
|
const res = ctx.getResources()
|
||||||
const config = res.getConfiguration()
|
const config = res.getConfiguration()
|
||||||
if (l !== 'none') {
|
if (l !== 'none') {
|
||||||
|
|
Loading…
Reference in a new issue