Skip to content

Commit

Permalink
[expo-notifications] Add support for vibration pattern override
Browse files Browse the repository at this point in the history
  • Loading branch information
sjchmiela committed Feb 11, 2020
1 parent 212eeec commit 108dbdb
Showing 1 changed file with 24 additions and 0 deletions.
Expand Up @@ -8,6 +8,8 @@
import android.provider.Settings;
import android.util.Log;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.unimodules.core.ModuleRegistry;
import org.unimodules.interfaces.imageloader.ImageLoader;
Expand Down Expand Up @@ -107,6 +109,11 @@ protected NotificationCompat.Builder createBuilder() {
builder.setVibrate(NO_VIBRATE_PATTERN);
}

long[] vibrationPatternOverride = getVibrationPatternOverride();
if (vibrationPatternOverride != null) {
builder.setVibrate(vibrationPatternOverride);
}

if (shouldSetBadge()) {
// TODO: Set badge as an effect of presenting notification,
// not as an effect of building a notification.
Expand Down Expand Up @@ -192,4 +199,21 @@ private Number getPriorityOverride() {
return null;
}
}

private long[] getVibrationPatternOverride() {
try {
JSONArray vibrateJsonArray = mNotificationRequest.optJSONArray(VIBRATE_KEY);
if (vibrateJsonArray != null) {
long[] pattern = new long[vibrateJsonArray.length()];
for (int i = 0; i < vibrateJsonArray.length(); i++) {
pattern[i] = vibrateJsonArray.getLong(i);
}
return pattern;
}
} catch (JSONException e) {
Log.w("expo-notifications", "Failed to set custom vibration pattern from the notification: " + e.getMessage());
}

return null;
}
}

0 comments on commit 108dbdb

Please sign in to comment.