Skip to content
This repository has been archived by the owner on Jul 9, 2019. It is now read-only.

addOverlay on launch + launcher label variable #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ By adding this Cordova plugin the Cordova app becomes the the homescreen (also k

To add plugin into existing Cordova / Phonegap application:

cordova plugin add https://github.com/honza889/cordova-plugin-kiosk.git
cordova plugin add https://github.com/honza889/cordova-plugin-kiosk.git --variable KIOSK_LABEL='My Kiosk Laucher Label'

If no `KIOSK_LABEL` value is defined, the default `Cordova Kiosk Mode` is used.

The `AndroidManifest.xml` should be updated immediately. If not, you can force it by removing and re-adding Android platform:

Expand Down
10 changes: 8 additions & 2 deletions android/KioskActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ protected void onStart() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());
if(Build.VERSION.SDK_INT >= 23) {
sp.edit().putBoolean(PREF_KIOSK_MODE, false).commit();
checkDrawOverlayPermission();
if(checkDrawOverlayPermission()){
addOverlay();
}
} else {
sp.edit().putBoolean(PREF_KIOSK_MODE, true).commit();
addOverlay();
Expand All @@ -48,11 +50,15 @@ protected void onStart() {
}
//http://stackoverflow.com/questions/7569937/unable-to-add-window-android-view-viewrootw44da9bc0-permission-denied-for-t
@TargetApi(Build.VERSION_CODES.M)
public void checkDrawOverlayPermission() {
public boolean checkDrawOverlayPermission() {
if (!Settings.canDrawOverlays(this.getApplicationContext())) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, REQUEST_CODE);
return false;
}
else{
return true;
}
}

Expand Down
6 changes: 4 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-kiosk" version="0.2">
id="cordova-plugin-kiosk" version="0.2.0">

<name>Cordova Kiosk Mode</name>
<author>Jan Kalina</author>
Expand Down Expand Up @@ -28,6 +28,8 @@
<js-module src="kiosk.js" name="kioskPlugin">
<clobbers target="window.KioskPlugin" />
</js-module>

<preference name="KIOSK_LABEL" default="Cordova Kiosk Mode" />

<platform name="android">

Expand Down Expand Up @@ -56,7 +58,7 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:label="Rilevatore Presenze Modalità Chiosco" android:launchMode="singleInstance" android:keepScreenOn="true" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|uiMode" android:windowSoftInputMode="adjustResize" android:name="jk.cordova.plugin.kiosk.KioskActivity" android:screenOrientation="sensorLandscape">
<activity android:label="$KIOSK_LABEL" android:launchMode="singleInstance" android:keepScreenOn="true" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|uiMode" android:windowSoftInputMode="adjustResize" android:name="jk.cordova.plugin.kiosk.KioskActivity" android:screenOrientation="sensorLandscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
Expand Down