Skip to content

Commit

Permalink
#14 Theming the dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Feb 19, 2015
1 parent 62536f9 commit 72fcf4b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ or copy-paste some of the code below to replicate the ActionSheets of the screen

function testShareSheet() {
var options = {
'androidTheme': window.plugins.actionsheet.ANDROID_THEMES.THEME_HOLO_LIGHT, // default is THEME_TRADITIONAL
'title': 'What do you want with this image?',
'buttonLabels': ['Share via Facebook', 'Share via Twitter'],
'androidEnableCancelButton' : true, // default false
Expand Down Expand Up @@ -155,10 +156,14 @@ or copy-paste some of the code below to replicate the ActionSheets of the screen
## 5. Credits
iOS and WP8 code: [Eddy Verbruggen](https://github.com/EddyVerbruggen)

Android code: [Brill Papping](https://github.com/bpappin)
Android code: mostly [Brill Papping](https://github.com/bpappin)


## 6. License
## 6. Change history
1.1.2 You can now select a theme for your Android popup, see the first example above


## 7. License

[The MIT License (MIT)](http://www.opensource.org/licenses/mit-license.html)

Expand Down
1 change: 1 addition & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ <h1>ActionSheet demo</h1>

function testShareSheet() {
var options = {
'androidTheme' : window.plugins.actionsheet.ANDROID_THEMES.THEME_HOLO_LIGHT,
'title': 'What do you want with this image?',
'buttonLabels': ['Share via Facebook', 'Share via Twitter'],
'addCancelButtonWithLabel': 'Cancel',
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plugin
xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="nl.x-services.plugins.actionsheet"
version="1.1.1">
version="1.1.2">

<name>ActionSheet</name>

Expand Down
11 changes: 10 additions & 1 deletion src/android/ActionSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Build;
import android.text.TextUtils;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
Expand Down Expand Up @@ -31,6 +32,7 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
JSONObject options = args.optJSONObject(0);

String title = options.optString("title");
int theme = options.optInt("androidTheme", 1);
JSONArray buttons = options.optJSONArray("buttonLabels");

boolean androidEnableCancelButton = options.optBoolean("androidEnableCancelButton", false);
Expand All @@ -40,6 +42,7 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo

this.show(title, buttons, addCancelButtonWithLabel,
androidEnableCancelButton, addDestructiveButtonWithLabel,
theme,
callbackContext);
// need to return as this call is async.
return true;
Expand All @@ -52,14 +55,20 @@ public synchronized void show(final String title,
final String addCancelButtonWithLabel,
final boolean androidEnableCancelButton,
final String addDestructiveButtonWithLabel,
final int theme,
final CallbackContext callbackContext) {

final CordovaInterface cordova = this.cordova;

Runnable runnable = new Runnable() {
public void run() {

final AlertDialog.Builder builder = new AlertDialog.Builder(cordova.getActivity());
final AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
builder = new AlertDialog.Builder(cordova.getActivity(), theme);
} else {
builder = new AlertDialog.Builder(cordova.getActivity());
}

builder
.setTitle(title)
Expand Down
8 changes: 8 additions & 0 deletions www/ActionSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ ActionSheet.prototype.hide = function () {
cordova.exec(null, null, "ActionSheet", "hide", []);
};

ActionSheet.prototype.ANDROID_THEMES = {
THEME_TRADITIONAL : 1, // default
THEME_HOLO_DARK : 2,
THEME_HOLO_LIGHT : 3,
THEME_DEVICE_DEFAULT_DARK : 4,
THEME_DEVICE_DEFAULT_LIGHT : 5
};

ActionSheet.install = function () {
if (!window.plugins) {
window.plugins = {};
Expand Down

0 comments on commit 72fcf4b

Please sign in to comment.