Commit 3b145ca2 by Sebastián Katzer

Implemented progressBar option for Android

parent acf59a84
......@@ -100,8 +100,16 @@ public class Builder {
.setVisibility(options.getVisibility())
.setPriority(options.getPriority())
.setShowWhen(options.getShowWhen())
.setUsesChronometer(options.isWithProgressBar())
.setLights(options.getLedColor(), options.getLedOn(), options.getLedOff());
if (options.isWithProgressBar()) {
builder.setProgress(
options.getProgressMaxValue(),
options.getProgressValue(),
options.isIndeterminateProgress());
}
if (smallIcon != 0) {
builder.setSmallIcon(smallIcon);
builder.setLargeIcon(options.getLargeIcon());
......
......@@ -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.
*/
public JSONObject getTrigger() {
......
......@@ -60,8 +60,8 @@ exports.applyPlatformSpecificOptions = function () {
defaults.vibrate = false;
defaults.lockscreen = true;
defaults.showWhen = true;
defaults.priority = 0;
defaults.defaults = 0;
defaults.priority = 0;
break;
}
};
......@@ -265,12 +265,26 @@ exports.convertTrigger = function (options) {
* @return [ Map ] Interaction object with trigger spec.
*/
exports.convertProgressBar = function (options) {
var cfg = options.progressBar;
var isAndroid = device.platform == 'Android',
cfg = options.progressBar;
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;
};
......
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