This commit is contained in:
juloo 2015-08-03 00:01:04 +02:00
parent 3d3aa4bc98
commit 7dd5845883
2 changed files with 33 additions and 0 deletions

View File

@ -3,6 +3,7 @@
package="juloo.keyboard2" package="juloo.keyboard2"
android:versionCode="1" android:versionCode="1"
android:versionName="1.0"> android:versionName="1.0">
<application android:label="@string/app_name" <application android:label="@string/app_name"
android:icon="@drawable/ic_launcher"> android:icon="@drawable/ic_launcher">
@ -17,4 +18,7 @@
</service> </service>
</application> </application>
<uses-permission android:name="android.permission.VIBRATE" />
</manifest> </manifest>

View File

@ -6,6 +6,7 @@ import android.graphics.RectF;
import android.graphics.Paint; import android.graphics.Paint;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.os.Vibrator;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import java.util.LinkedList; import java.util.LinkedList;
@ -14,6 +15,8 @@ public class Keyboard2View extends View
implements View.OnTouchListener implements View.OnTouchListener
{ {
private static final float KEY_PER_ROW = 10; private static final float KEY_PER_ROW = 10;
private static final long VIBRATE_LONG = 25;
private static final long VIBRATE_MIN_INTERVAL = 100;
private Keyboard2 _ime; private Keyboard2 _ime;
private KeyboardData _keyboard; private KeyboardData _keyboard;
@ -22,6 +25,9 @@ public class Keyboard2View extends View
private int _flags = 0; private int _flags = 0;
private Vibrator _vibratorService;
private long _lastVibration = 0;
private float _verticalMargin; private float _verticalMargin;
private float _horizontalMargin; private float _horizontalMargin;
private float _keyWidth; private float _keyWidth;
@ -39,6 +45,7 @@ public class Keyboard2View extends View
public Keyboard2View(Context context, AttributeSet attrs) public Keyboard2View(Context context, AttributeSet attrs)
{ {
super(context, attrs); super(context, attrs);
_vibratorService = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
_verticalMargin = getResources().getDimension(R.dimen.vertical_margin); _verticalMargin = getResources().getDimension(R.dimen.vertical_margin);
_horizontalMargin = getResources().getDimension(R.dimen.horizontal_margin); _horizontalMargin = getResources().getDimension(R.dimen.horizontal_margin);
_keyHeight = getResources().getDimension(R.dimen.key_height); _keyHeight = getResources().getDimension(R.dimen.key_height);
@ -119,7 +126,10 @@ public class Keyboard2View extends View
KeyDown k = getKeyDown(pointerId); KeyDown k = getKeyDown(pointerId);
if (k != null && k.updateDown(moveX, moveY)) if (k != null && k.updateDown(moveX, moveY))
{
updateFlags(); updateFlags();
vibrate();
}
} }
private void onTouchDown(float touchX, float touchY, int pointerId) private void onTouchDown(float touchX, float touchY, int pointerId)
@ -153,6 +163,7 @@ public class Keyboard2View extends View
} }
else else
_downKeys.add(new KeyDown(pointerId, key, touchX, touchY)); _downKeys.add(new KeyDown(pointerId, key, touchX, touchY));
vibrate();
updateFlags(); updateFlags();
invalidate(); invalidate();
return ; return ;
@ -198,6 +209,24 @@ public class Keyboard2View extends View
_flags |= k.flags; _flags |= k.flags;
} }
private void vibrate()
{
long now = System.currentTimeMillis();
if ((now - _lastVibration) > VIBRATE_MIN_INTERVAL)
{
_lastVibration = now;
try
{
_vibratorService.vibrate(VIBRATE_LONG);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
@Override @Override
public void onMeasure(int wSpec, int hSpec) public void onMeasure(int wSpec, int hSpec)
{ {