Commit 3b145ca2 by Sebastián Katzer

Implemented progressBar option for Android

parent acf59a84
...@@ -100,8 +100,16 @@ public class Builder { ...@@ -100,8 +100,16 @@ public class Builder {
.setVisibility(options.getVisibility()) .setVisibility(options.getVisibility())
.setPriority(options.getPriority()) .setPriority(options.getPriority())
.setShowWhen(options.getShowWhen()) .setShowWhen(options.getShowWhen())
.setUsesChronometer(options.isWithProgressBar())
.setLights(options.getLedColor(), options.getLedOn(), options.getLedOff()); .setLights(options.getLedColor(), options.getLedOn(), options.getLedOff());
if (options.isWithProgressBar()) {
builder.setProgress(
options.getProgressMaxValue(),
options.getProgressValue(),
options.isIndeterminateProgress());
}
if (smallIcon != 0) { if (smallIcon != 0) {
builder.setSmallIcon(smallIcon); builder.setSmallIcon(smallIcon);
builder.setLargeIcon(options.getLargeIcon()); builder.setLargeIcon(options.getLargeIcon());
......
...@@ -403,6 +403,48 @@ public class Options { ...@@ -403,6 +403,48 @@ public class Options {
} }
/** /**
* If the notification shall display a progress bar.
*/
boolean isWithProgressBar() {
return options
.optJSONObject("progressBar")
.optBoolean("enabled", false);
}
/**
* Gets the progress value.
*
* @return 0 by default.
*/
int getProgressValue() {
return options
.optJSONObject("progressBar")
.optInt("value", 0);
}
/**
* Gets the progress value.
*
* @return 100 by default.
*/
int getProgressMaxValue() {
return options
.optJSONObject("progressBar")
.optInt("maxValue", 100);
}
/**
* Gets the progress indeterminate value.
*
* @return false by default.
*/
boolean isIndeterminateProgress() {
return options
.optJSONObject("progressBar")
.optBoolean("indeterminate", false);
}
/**
* Gets the raw trigger spec as provided by the user. * Gets the raw trigger spec as provided by the user.
*/ */
public JSONObject getTrigger() { public JSONObject getTrigger() {
......
...@@ -60,8 +60,8 @@ exports.applyPlatformSpecificOptions = function () { ...@@ -60,8 +60,8 @@ exports.applyPlatformSpecificOptions = function () {
defaults.vibrate = false; defaults.vibrate = false;
defaults.lockscreen = true; defaults.lockscreen = true;
defaults.showWhen = true; defaults.showWhen = true;
defaults.priority = 0;
defaults.defaults = 0; defaults.defaults = 0;
defaults.priority = 0;
break; break;
} }
}; };
...@@ -265,12 +265,26 @@ exports.convertTrigger = function (options) { ...@@ -265,12 +265,26 @@ exports.convertTrigger = function (options) {
* @return [ Map ] Interaction object with trigger spec. * @return [ Map ] Interaction object with trigger spec.
*/ */
exports.convertProgressBar = function (options) { exports.convertProgressBar = function (options) {
var cfg = options.progressBar; var isAndroid = device.platform == 'Android',
cfg = options.progressBar;
if (typeof cfg === 'boolean') { if (typeof cfg === 'boolean') {
options.progressBar = { enabled: cfg }; cfg = options.progressBar = { enabled: cfg };
}
if (typeof cfg.enabled !== 'boolean') {
cfg.enabled = !!(cfg.value || cfg.maxValue || cfg.indeterminate !== undefined);
} }
cfg.value = cfg.value || 0;
if (isAndroid) {
cfg.maxValue = cfg.maxValue || 100;
cfg.indeterminate = cfg.indeterminate !== undefined ? cfg.indeterminate : false;
}
cfg.enabled = !!cfg.enabled;
return options; return options;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment