Skip to content
Merged
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
22 changes: 2 additions & 20 deletions android/src/main/java/com/capacitorjs/plugins/haptics/Haptics.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,7 @@ private Vibrator getDeprecatedVibrator(Context context) {
}

public void vibrate(int duration) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
vibrator.vibrate(VibrationEffect.createOneShot(duration, VibrationEffect.DEFAULT_AMPLITUDE));
} else {
vibratePre26(duration);
}
}

@SuppressWarnings({ "deprecation" })
private void vibratePre26(int duration) {
vibrator.vibrate(duration);
}

@SuppressWarnings({ "deprecation" })
private void vibratePre26(long[] pattern) {
vibrator.vibrate(pattern, -1);
vibrator.vibrate(VibrationEffect.createOneShot(duration, VibrationEffect.DEFAULT_AMPLITUDE));
}

public void selectionStart() {
Expand All @@ -60,10 +46,6 @@ public void selectionEnd() {
}

public void performHaptics(HapticsVibrationType type) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
vibrator.vibrate(VibrationEffect.createWaveform(type.getTimings(), type.getAmplitudes(), -1));
} else {
vibratePre26(type.getOldSDKPattern());
}
vibrator.vibrate(VibrationEffect.createWaveform(type.getTimings(), type.getAmplitudes(), -1));
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package com.capacitorjs.plugins.haptics.arguments;

public enum HapticsImpactType implements HapticsVibrationType {
LIGHT("LIGHT", new long[] { 0, 50 }, new int[] { 0, 110 }, new long[] { 0, 20 }),
MEDIUM("MEDIUM", new long[] { 0, 43 }, new int[] { 0, 180 }, new long[] { 0, 43 }),
HEAVY("HEAVY", new long[] { 0, 60 }, new int[] { 0, 255 }, new long[] { 0, 61 });
LIGHT("LIGHT", new long[] { 0, 50 }, new int[] { 0, 110 }),
MEDIUM("MEDIUM", new long[] { 0, 43 }, new int[] { 0, 180 }),
HEAVY("HEAVY", new long[] { 0, 60 }, new int[] { 0, 255 });

private final String type;
private final long[] timings;
private final int[] amplitudes;
private final long[] oldSDKPattern;

HapticsImpactType(String type, long[] timings, int[] amplitudes, long[] oldSDKPattern) {
HapticsImpactType(String type, long[] timings, int[] amplitudes) {
this.type = type;
this.timings = timings;
this.amplitudes = amplitudes;
this.oldSDKPattern = oldSDKPattern;
}

public static HapticsImpactType fromString(String style) {
Expand All @@ -35,9 +33,4 @@ public long[] getTimings() {
public int[] getAmplitudes() {
return amplitudes;
}

@Override
public long[] getOldSDKPattern() {
return oldSDKPattern;
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
package com.capacitorjs.plugins.haptics.arguments;

public enum HapticsNotificationType implements HapticsVibrationType {
SUCCESS("SUCCESS", new long[] { 0, 35, 65, 21 }, new int[] { 0, 250, 0, 180 }, new long[] { 0, 35, 65, 21 }),
WARNING(
"WARNING",
new long[] { 0, 30, 40, 30, 50, 60 },
new int[] { 255, 255, 255, 255, 255, 255 },
new long[] { 0, 30, 40, 30, 50, 60 }
),
ERROR("ERROR", new long[] { 0, 27, 45, 50 }, new int[] { 0, 120, 0, 250 }, new long[] { 0, 27, 45, 50 });
SUCCESS("SUCCESS", new long[] { 0, 35, 65, 21 }, new int[] { 0, 250, 0, 180 }),
WARNING("WARNING", new long[] { 0, 30, 40, 30, 50, 60 }, new int[] { 255, 255, 255, 255, 255, 255 }),
ERROR("ERROR", new long[] { 0, 27, 45, 50 }, new int[] { 0, 120, 0, 250 });

private final String type;
private final long[] timings;
private final int[] amplitudes;
private final long[] oldSDKPattern;

HapticsNotificationType(String type, long[] timings, int[] amplitudes, long[] oldSDKPattern) {
HapticsNotificationType(String type, long[] timings, int[] amplitudes) {
this.type = type;
this.timings = timings;
this.amplitudes = amplitudes;
this.oldSDKPattern = oldSDKPattern;
}

public static HapticsNotificationType fromString(String type) {
Expand All @@ -40,9 +33,4 @@ public long[] getTimings() {
public int[] getAmplitudes() {
return amplitudes;
}

@Override
public long[] getOldSDKPattern() {
return oldSDKPattern;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ public class HapticsSelectionType implements HapticsVibrationType {

private static final long[] timings = { 0, 100 };
private static final int[] amplitudes = { 0, 100 };
private static final long[] oldSDKPattern = { 0, 70 };

@Override
public long[] getTimings() {
Expand All @@ -15,9 +14,4 @@ public long[] getTimings() {
public int[] getAmplitudes() {
return amplitudes;
}

@Override
public long[] getOldSDKPattern() {
return oldSDKPattern;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ public interface HapticsVibrationType {
long[] getTimings();

int[] getAmplitudes();

long[] getOldSDKPattern();
}