fixed crash with blocked sensor
This commit is contained in:
parent
9eb9ccfb45
commit
a8302d4d2e
3 changed files with 50 additions and 12 deletions
|
@ -347,6 +347,7 @@ import EditRecipe from "./EditRecipe.vue";
|
||||||
import ViewRecipe from "./ViewRecipe.vue";
|
import ViewRecipe from "./ViewRecipe.vue";
|
||||||
import ActionDialog from "./modal/ActionDialog.vue";
|
import ActionDialog from "./modal/ActionDialog.vue";
|
||||||
import ConfirmDialog from "./modal/ConfirmDialog.vue";
|
import ConfirmDialog from "./modal/ConfirmDialog.vue";
|
||||||
|
import * as utils from "~/shared/utils.js";
|
||||||
let lastTime = 0;
|
let lastTime = 0;
|
||||||
let lastShake = 0;
|
let lastShake = 0;
|
||||||
let lastForce = 0;
|
let lastForce = 0;
|
||||||
|
@ -465,6 +466,7 @@ export default {
|
||||||
"setSortTypeAction",
|
"setSortTypeAction",
|
||||||
"deleteRecipeAction",
|
"deleteRecipeAction",
|
||||||
"deleteRecipesAction",
|
"deleteRecipesAction",
|
||||||
|
"setShakeAction",
|
||||||
]),
|
]),
|
||||||
onPageLoad(args) {
|
onPageLoad(args) {
|
||||||
const page = args.object;
|
const page = args.object;
|
||||||
|
@ -477,8 +479,11 @@ export default {
|
||||||
? this.setComponent("Filtered recipes")
|
? this.setComponent("Filtered recipes")
|
||||||
: this.setComponent("EnRecipes");
|
: this.setComponent("EnRecipes");
|
||||||
if (!this.selectMode) this.showFAB = true;
|
if (!this.selectMode) this.showFAB = true;
|
||||||
if (this.shakeEnabled)
|
if (this.shakeEnabled) {
|
||||||
|
if (utils.hasAccelerometer())
|
||||||
startAccelerometerUpdates((data) => this.onSensorData(data));
|
startAccelerometerUpdates((data) => this.onSensorData(data));
|
||||||
|
else this.setShakeAction(false);
|
||||||
|
}
|
||||||
if (this.showSearch || this.selectMode) this.hijackLocalBackEvent();
|
if (this.showSearch || this.selectMode) this.hijackLocalBackEvent();
|
||||||
this.showDrawer();
|
this.showDrawer();
|
||||||
this.closeDrawer();
|
this.closeDrawer();
|
||||||
|
|
|
@ -397,9 +397,13 @@ export default {
|
||||||
// SHAKE VIEW RANDOM RECIPE
|
// SHAKE VIEW RANDOM RECIPE
|
||||||
toggleShake(args) {
|
toggleShake(args) {
|
||||||
let checked = args.object.checked;
|
let checked = args.object.checked;
|
||||||
// let checked = !this.shakeEnabled
|
if (checked && !utils.hasAccelerometer()) {
|
||||||
|
args.object.checked = false;
|
||||||
|
Toast.makeText(localize("noAccSensor"), "long").show();
|
||||||
|
} else {
|
||||||
ApplicationSettings.setBoolean("shakeEnabled", checked);
|
ApplicationSettings.setBoolean("shakeEnabled", checked);
|
||||||
this.setShakeAction(checked);
|
this.setShakeAction(checked);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// EXPORT HANDLERS
|
// EXPORT HANDLERS
|
||||||
exportCheck() {
|
exportCheck() {
|
||||||
|
|
|
@ -1,15 +1,44 @@
|
||||||
import {Application} from "@nativescript/core"
|
import { Application, Utils } from '@nativescript/core'
|
||||||
export const restartApp = () => {
|
export const restartApp = () => {
|
||||||
const mStartActivity = new android.content.Intent(Application.android.context, Application.android.startActivity.getClass())
|
const mStartActivity = new android.content.Intent(
|
||||||
|
Application.android.context,
|
||||||
|
Application.android.startActivity.getClass()
|
||||||
|
)
|
||||||
const mPendingIntentId = parseInt(Math.random() * 100000, 10)
|
const mPendingIntentId = parseInt(Math.random() * 100000, 10)
|
||||||
const mPendingIntent = android.app.PendingIntent.getActivity(Application.android.context, mPendingIntentId, mStartActivity, android.app.PendingIntent.FLAG_CANCEL_CURRENT)
|
const mPendingIntent = android.app.PendingIntent.getActivity(
|
||||||
const mgr = Application.android.context.getSystemService(android.content.Context.ALARM_SERVICE)
|
Application.android.context,
|
||||||
mgr.set(android.app.AlarmManager.RTC, java.lang.System.currentTimeMillis() + 100, mPendingIntent)
|
mPendingIntentId,
|
||||||
|
mStartActivity,
|
||||||
|
android.app.PendingIntent.FLAG_CANCEL_CURRENT
|
||||||
|
)
|
||||||
|
const mgr = Application.android.context.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())
|
android.os.Process.killProcess(android.os.Process.myPid())
|
||||||
}
|
}
|
||||||
export const openAppSettingsPage = () => {
|
export const openAppSettingsPage = () => {
|
||||||
const intent = new android.content.Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
const intent = new android.content.Intent(
|
||||||
|
android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS
|
||||||
|
)
|
||||||
intent.addCategory(android.content.Intent.CATEGORY_DEFAULT)
|
intent.addCategory(android.content.Intent.CATEGORY_DEFAULT)
|
||||||
intent.setData(android.net.Uri.parse("package:" + Application.android.context.getPackageName()))
|
intent.setData(
|
||||||
|
android.net.Uri.parse(
|
||||||
|
'package:' + Application.android.context.getPackageName()
|
||||||
|
)
|
||||||
|
)
|
||||||
Application.android.foregroundActivity.startActivity(intent)
|
Application.android.foregroundActivity.startActivity(intent)
|
||||||
}
|
}
|
||||||
|
export const hasAccelerometer = () => {
|
||||||
|
let context = Utils.ad.getApplicationContext()
|
||||||
|
let sensorManager = context.getSystemService(
|
||||||
|
android.content.Context.SENSOR_SERVICE
|
||||||
|
)
|
||||||
|
return sensorManager.getDefaultSensor(
|
||||||
|
android.hardware.Sensor.TYPE_ACCELEROMETER
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue