Skip to content

Commit

Permalink
Merge pull request #22 from Macro-Deck-App/disable-screen-orientation…
Browse files Browse the repository at this point in the history
…-lock-android-oreo

Disable screen lock in Android 8
  • Loading branch information
manuelmayer-dev authored May 9, 2024
2 parents ee129f7 + eadb1c2 commit 5943df9
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 20 deletions.
1 change: 1 addition & 0 deletions android/app/capacitor.build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
dependencies {
implementation project(':capacitor-community-keep-awake')
implementation project(':capacitor-app')
implementation project(':capacitor-device')
implementation project(':capacitor-haptics')
implementation project(':capacitor-keyboard')
implementation project(':capawesome-capacitor-screen-orientation')
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/AppTheme.NoActionBarLaunch"
android:theme="@style/AppTheme"
android:launchMode="singleTask"
android:exported="true">

Expand Down
16 changes: 5 additions & 11 deletions android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:background">@null</item>
</style>

<style name="AppTheme.NoActionBarLaunch" parent="Theme.SplashScreen">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
</resources>
3 changes: 3 additions & 0 deletions android/capacitor.settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ project(':capacitor-community-keep-awake').projectDir = new File('../node_module
include ':capacitor-app'
project(':capacitor-app').projectDir = new File('../node_modules/@capacitor/app/android')

include ':capacitor-device'
project(':capacitor-device').projectDir = new File('../node_modules/@capacitor/device/android')

include ':capacitor-haptics'
project(':capacitor-haptics').projectDir = new File('../node_modules/@capacitor/haptics/android')

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@capacitor/android": "5.7.5",
"@capacitor/app": "5.0.7",
"@capacitor/core": "5.7.5",
"@capacitor/device": "^6.0.0",
"@capacitor/haptics": "5.0.7",
"@capacitor/ios": "5.7.5",
"@capacitor/keyboard": "5.0.8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,17 @@
@if (isiOSorAndroid()) {
<ion-item>
<ion-icon slot="start" class="mdi mdi-screen-rotation d-flex align-items-center"></ion-icon>
<ion-select [(ngModel)]="screenOrientation" label="Screen orientation">
<ion-select-option value="0">Auto</ion-select-option>
<ion-select-option value="1">Landscape</ion-select-option>
<ion-select-option value="2">Landscape alternative</ion-select-option>
<ion-select-option value="3">Portrait</ion-select-option>
</ion-select>
@if (!isAndroidOreo) {
<ion-select [(ngModel)]="screenOrientation" label="Screen orientation">
<ion-select-option value="0">Auto</ion-select-option>
<ion-select-option value="1">Landscape</ion-select-option>
<ion-select-option value="2">Landscape alternative</ion-select-option>
<ion-select-option value="3">Portrait</ion-select-option>
</ion-select>
} @else {
<ion-label>Screen orientation</ion-label>
<ion-label slot="end">Not available</ion-label>
}
</ion-item>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class SettingsModalComponent implements OnInit {

public static settingsApplied: EventEmitter<any> = new EventEmitter();

isAndroidOreo: boolean = false;
preventScreenTimeout: boolean = false;
showMenuButton: boolean = false;
skipSslValidation: boolean = false;
Expand All @@ -39,6 +40,7 @@ export class SettingsModalComponent implements OnInit {

async ngOnInit() {
await this.loadCurrentSettings();
this.isAndroidOreo = await this.diagnosticService.isAndroidOreo();
}

async confirm() {
Expand Down
18 changes: 16 additions & 2 deletions src/app/services/diagnostic/diagnostic.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import {App} from "@capacitor/app";
import {Platform} from "@ionic/angular";
import {Capacitor} from "@capacitor/core";
import {Device} from "@capacitor/device";

@Injectable({
providedIn: 'root'
Expand All @@ -19,6 +19,20 @@ export class DiagnosticService {
return "Web Client";
}

async isAndroidOreo() {
if (!this.isAndroid()) {
return false;
}

let androidSdk = await this.getAndroidSdkVersion();
return androidSdk == 26 || androidSdk == 27;
}

async getAndroidSdkVersion() {
const info = await Device.getInfo();
return info.androidSDKVersion;
}

public isAndroid() {
return this.platform.is("android");
}
Expand All @@ -34,7 +48,7 @@ export class DiagnosticService {
return "i";
}

return "";
return "pwa";
}

public isiOSorAndroid() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export class ScreenOrientationService {
return;
}

if (await this.diagnosticService.isAndroidOreo()) {
return;
}

let screenOrientation = await this.settingsService.getScreenOrientation();
try {
switch (screenOrientation) {
Expand Down

0 comments on commit 5943df9

Please sign in to comment.