Skip to content
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
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ScreenDim

> PhoneGap/Cordova plugin for enabling/disabling screen dim
Cordova/Phonegap plugin for enabling/disabling screen dim.

## Usage

Expand All @@ -27,7 +27,9 @@

## Installation

Use `pluginstall` - https://github.com/alunny/pluginstall
```
cordova plugin add <this repo url>
```

## What/Why

Expand All @@ -51,3 +53,10 @@ part of your app, and enable it again once you're done.
## LICENSE

MIT

## Changelog

* 1.0.3 Update for cordova >= 3.6.x (Android)
* 1.0.2 Update for cordova >= 3.6.x (iOS)
* 1.0.1 Update for cordova 3.0.x (Android/iOS)
* 1.0.0 Initial release (Android/iOS)
55 changes: 31 additions & 24 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="com.phonegap.build.screendim"
version="1.0.0">
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="com.phonegap.build.screendim"
version="1.0.3">

<name>Screen Dim</name>
<name>Screen Dim</name>
<description>Cordova Screen Dim Plugin</description>
<keywords>cordova,screendim</keywords>

<asset src="www/screendim.js" target="screendim.js" />
<engines>
<engine name="cordova" version=">=3.0.0" />
</engines>

<!-- ios -->
<platform name="ios">
<plugins-plist key="ScreenDim"
string="ScreenDimPlugin" />
<js-module src="www/screendim.js" name="screenDim">
<clobbers target="cordova.screenDim" />
</js-module>

<header-file src="ScreenDimPlugin.h" />

<source-file src="ScreenDimPlugin.m" />
</platform>
<!-- ios -->
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="ScreenDim">
<param name="ios-package" value="ScreenDim"/>
</feature>
</config-file>
<header-file src="src/ios/ScreenDim.h" />
<source-file src="src/ios/ScreenDim.m" />
</platform>

<!-- android -->
<platform name="android">
<source-file src="src/android/ScreenDim.java"
target-dir="src/com/phonegap/build/screendim" />

<config-file target="res/xml/plugins.xml" parent="/plugins">
<plugin name="ScreenDim"
value="com.phonegap.build.screendim.ScreenDim" />
</config-file>
</platform>
<platform name="android">
<source-file src="src/android/ScreenDim.java" target-dir="src/com/phonegap/build/screendim" />
<config-file target="res/xml/config.xml" parent="/*">
<feature name="ScreenDim" >
<param name="android-package" value="com.phonegap.build.screendim.ScreenDim"/>
</feature>
</config-file>
</platform>
</plugin>
29 changes: 19 additions & 10 deletions src/android/ScreenDim.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,46 @@

import org.json.JSONArray;

import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.apache.cordova.api.LOG;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult.Status;
import org.json.JSONArray;
import org.json.JSONException;

import android.app.Activity;
import android.view.WindowManager;
import android.view.Window;
import android.util.Log;

public class ScreenDim extends CordovaPlugin {
public final static String TAG = "ScreenDim";

public class ScreenDim extends Plugin {
public PluginResult execute(String action, JSONArray args, String callbackId) {
@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext)
throws JSONException {
if (action.equals("enable")) {
enable();
} else if (action.equals("disable")) {
disable();
} else {
// Returning false results in a "MethodNotFound" error.
return false;
}

return new PluginResult(PluginResult.Status.OK);
return true;
}

public void enable() {
LOG.d("CordovaLog", "Enable called");
Log.d(TAG, "Enable screen dimmer");
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

public void disable() {
LOG.d("CordovaLog", "Disable called");
Log.d(TAG, "Disable screen dimmer");
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

protected Window getWindow() {
Activity ctxActivity = (Activity) ctx.getContext();
return ctxActivity.getWindow();
return cordova.getActivity().getWindow();
}
}
17 changes: 17 additions & 0 deletions src/ios/ScreenDim.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// ScreenDim.h
// ios-cordova
//
// Created by Andrew Lunny on 12-07-11.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <Cordova/CDVPlugin.h>

@interface ScreenDim : CDVPlugin

- (void) enable:(CDVInvokedUrlCommand *)command;
- (void) disable:(CDVInvokedUrlCommand *)command;

@end
26 changes: 26 additions & 0 deletions src/ios/ScreenDim.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// ScreenDim.m
// ios-cordova
//
// Created by Andrew Lunny on 12-07-11.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "ScreenDim.h"

@implementation ScreenDim

- (void) enable:(CDVInvokedUrlCommand *)command
{
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
NSLog(@" ScreenDim Plugin: dim enabled");
}


- (void) disable:(CDVInvokedUrlCommand *)command
{
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
NSLog(@" ScreenDim Plugin: dim disabled");
}

@end
8 changes: 2 additions & 6 deletions src/ios/ScreenDimPlugin.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
//
// ScreenDimPlugin.h
// ScreenDim.h
// ios-cordova
//
// Created by Andrew Lunny on 12-07-11.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#ifdef CORDOVA_FRAMEWORK
#import <Cordova/CDVPlugin.h>
#else
#import "CDVPlugin.h"
#endif

@interface ScreenDimPlugin : CDVPlugin
@interface ScreenDim : CDVPlugin

- (void) enable:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
- (void) disable:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
Expand Down
2 changes: 2 additions & 0 deletions src/ios/ScreenDimPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ @implementation ScreenDimPlugin
- (void) enable:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
NSLog(@" ScreenDim Plugin: dim enabled");
}


- (void) disable:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
NSLog(@" ScreenDim Plugin: dim disabled");
}

@end
34 changes: 17 additions & 17 deletions www/screendim.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
(function (gap) {
// dims by default
var on = true;
var exec = require("cordova/exec");

gap.screenDim = { };
module.exports = {
on: true,

enable: function () {
this.on = true;
exec(null, null, 'ScreenDim', 'enable', []);
},

gap.screenDim.enable = function () {
on = true;
gap.exec(null, null, 'ScreenDim', 'enable', []);
};
disable: function () {
this.on = false;
exec(null, null, 'ScreenDim', 'disable', []);
},

gap.screenDim.disable = function () {
on = false;
gap.exec(null, null, 'ScreenDim', 'disable', []);
};

gap.screenDim.toggle = function () {
if (on) {
toggle: function () {
if (this.on) {
this.disable();
} else {
this.enable();
}
};
}).call(this, (window.cordova || window.Cordova));
},

};