add flutter_vibrate

This commit is contained in:
2026-01-13 22:03:47 -08:00
parent a2af086126
commit 7eb3d100ac
89 changed files with 2213 additions and 0 deletions
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -0,0 +1,8 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
+23
View File
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>vibrate</name>
<comment>Project vibrate created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,2 @@
connection.project.dir=
eclipse.preferences.version=1
@@ -0,0 +1,43 @@
group 'flutter.plugins.vibrate.vibrate'
version '1.0-SNAPSHOT'
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.2'
}
}
rootProject.allprojects {
repositories {
google()
mavenCentral()
}
}
apply plugin: 'com.android.library'
android {
namespace "flutter.plugins.vibrate"
compileSdkVersion 30
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
lintOptions {
disable 'InvalidPackage'
}
if (project.android.hasProperty("namespace")) {
namespace 'flutter.plugins.vibrate'
}
}
@@ -0,0 +1 @@
org.gradle.jvmargs=-Xmx1536M
@@ -0,0 +1,6 @@
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
@@ -0,0 +1 @@
rootProject.name = 'vibrate'
@@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>
@@ -0,0 +1,83 @@
package flutter.plugins.vibrate;
import android.os.Build;
import android.os.Vibrator;
import android.os.VibrationEffect;
import android.view.HapticFeedbackConstants;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
class VibrateMethodCallHandler implements MethodChannel.MethodCallHandler {
private final Vibrator vibrator;
private final boolean hasVibrator;
private final boolean legacyVibrator;
VibrateMethodCallHandler(Vibrator vibrator) {
assert (vibrator != null);
this.vibrator = vibrator;
this.hasVibrator = vibrator.hasVibrator();
this.legacyVibrator = Build.VERSION.SDK_INT < 26;
}
@SuppressWarnings("deprecation")
private void vibrate(int duration) {
if (hasVibrator) {
if (legacyVibrator) {
vibrator.vibrate(duration);
} else {
vibrator.vibrate(VibrationEffect.createOneShot(duration, VibrationEffect.DEFAULT_AMPLITUDE));
}
}
}
@Override
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
switch (call.method) {
case "canVibrate":
result.success(hasVibrator);
break;
case "vibrate":
final int duration = call.argument("duration");
vibrate(duration);
result.success(null);
break;
case "impact":
vibrate(HapticFeedbackConstants.VIRTUAL_KEY);
result.success(null);
break;
case "selection":
vibrate(HapticFeedbackConstants.KEYBOARD_TAP);
result.success(null);
break;
case "success":
vibrate(50);
result.success(null);
break;
case "warning":
vibrate(250);
result.success(null);
break;
case "error":
vibrate(500);
result.success(null);
break;
case "heavy":
vibrate(100);
result.success(null);
break;
case "medium":
vibrate(40);
result.success(null);
break;
case "light":
vibrate(10);
result.success(null);
break;
default:
result.notImplemented();
break;
}
}
}
@@ -0,0 +1,29 @@
package flutter.plugins.vibrate;
import android.content.Context;
import android.os.Vibrator;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodChannel;
public class VibratePlugin implements FlutterPlugin {
private MethodChannel methodChannel;
@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {
final Context context = binding.getApplicationContext();
final BinaryMessenger messenger = binding.getBinaryMessenger();
final Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
final VibrateMethodCallHandler methodCallHandler = new VibrateMethodCallHandler(vibrator);
this.methodChannel = new MethodChannel(messenger, "vibrate");
this.methodChannel.setMethodCallHandler(methodCallHandler);
}
@Override
public void onDetachedFromEngine(FlutterPluginBinding binding) {
this.methodChannel.setMethodCallHandler(null);
this.methodChannel = null;
}
}