fixed crash with blocked sensor

This commit is contained in:
vishnuraghavb 2021-02-28 23:04:27 +05:30
parent 9eb9ccfb45
commit a8302d4d2e
3 changed files with 50 additions and 12 deletions

View file

@ -347,6 +347,7 @@ import EditRecipe from "./EditRecipe.vue";
import ViewRecipe from "./ViewRecipe.vue";
import ActionDialog from "./modal/ActionDialog.vue";
import ConfirmDialog from "./modal/ConfirmDialog.vue";
import * as utils from "~/shared/utils.js";
let lastTime = 0;
let lastShake = 0;
let lastForce = 0;
@ -465,6 +466,7 @@ export default {
"setSortTypeAction",
"deleteRecipeAction",
"deleteRecipesAction",
"setShakeAction",
]),
onPageLoad(args) {
const page = args.object;
@ -477,8 +479,11 @@ export default {
? this.setComponent("Filtered recipes")
: this.setComponent("EnRecipes");
if (!this.selectMode) this.showFAB = true;
if (this.shakeEnabled)
startAccelerometerUpdates((data) => this.onSensorData(data));
if (this.shakeEnabled) {
if (utils.hasAccelerometer())
startAccelerometerUpdates((data) => this.onSensorData(data));
else this.setShakeAction(false);
}
if (this.showSearch || this.selectMode) this.hijackLocalBackEvent();
this.showDrawer();
this.closeDrawer();

View file

@ -397,9 +397,13 @@ export default {
// SHAKE VIEW RANDOM RECIPE
toggleShake(args) {
let checked = args.object.checked;
// let checked = !this.shakeEnabled
ApplicationSettings.setBoolean("shakeEnabled", checked);
this.setShakeAction(checked);
if (checked && !utils.hasAccelerometer()) {
args.object.checked = false;
Toast.makeText(localize("noAccSensor"), "long").show();
} else {
ApplicationSettings.setBoolean("shakeEnabled", checked);
this.setShakeAction(checked);
}
},
// EXPORT HANDLERS
exportCheck() {

View file

@ -1,15 +1,44 @@
import {Application} from "@nativescript/core"
import { Application, Utils } from '@nativescript/core'
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 mPendingIntent = android.app.PendingIntent.getActivity(Application.android.context, 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)
const mPendingIntent = android.app.PendingIntent.getActivity(
Application.android.context,
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())
}
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.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)
}
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
)
}