Added adjustable vibration duration

This commit is contained in:
Sean Starnes 2014-07-15 21:38:14 -05:00
parent 1095ffbcf1
commit e0e25d0668
5 changed files with 98 additions and 1 deletions

View File

@ -67,6 +67,59 @@
</LinearLayout>
</TableRow>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:visibility="gone"
android:id="@+id/vibDuration_layout" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/vibDuration_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/vibration_duration" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="right"
android:layout_weight="1">
<TextView
android:id="@+id/vibDuration_current"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:ems="5"
android:gravity="center_vertical|right"
android:textSize="20sp"
android:layout_marginRight="10dp" />
</LinearLayout>
</TableRow>
<SeekBar
android:id="@+id/vib_seekBar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:ems="10"
android:max="60"
android:progress="0"
android:layout_weight="0.50"
android:layout_marginLeft="30dip"
android:layout_marginRight="30dip"
android:layout_marginTop="10dip" />
</LinearLayout>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >

View File

@ -55,6 +55,7 @@
<string name="customize_touch_controls">Customize Touch Controls</string>
<string name="launch_editor">Launch Editor</string>
<string name="touch_vibration">Haptic Feedback</string>
<string name="vibration_duration">Duration of Haptic Feedback</string>
<string name="controller_a">Controller A</string>
<string name="controller_b">Controller B</string>
<string name="controller_c">Controller C</string>

View File

@ -37,6 +37,7 @@ public class Config {
public static final String pref_renderdepth = "depth_render";
public static final String pref_touchvibe = "touch_vibration_enabled";
public static final String pref_vibrationDuration = "vibration_duration";
public static final String pref_mic = "mic_plugged_in";
public static final String pref_vmu = "vmu_floating";
@ -56,6 +57,7 @@ public class Config {
public static boolean pvrrender = false;
public static String cheatdisk = "null";
public static boolean nativeact = false;
public static int vibrationDuration = 20;
private SharedPreferences mPrefs;

View File

@ -3,6 +3,7 @@ package com.reicast.emulator.config;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
@ -10,6 +11,7 @@ import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.util.Log;
@ -22,6 +24,8 @@ import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TableLayout;
import android.widget.TextView;
import android.widget.Toast;
@ -48,6 +52,7 @@ public class InputFragment extends Fragment {
private Gamepad pad = new Gamepad();
public MOGAInput moga = new MOGAInput();
Vibrator vib;
// Container Activity must implement this interface
public interface OnClickListener {
@ -70,6 +75,9 @@ public class InputFragment extends Fragment {
sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(parentActivity);
Config.vibrationDuration = sharedPreferences.getInt(Config.pref_vibrationDuration, 20);
vib = (Vibrator) parentActivity.getSystemService(Context.VIBRATOR_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
ImageView icon_a = (ImageView) getView().findViewById(
R.id.controller_icon_a);
@ -97,11 +105,42 @@ public class InputFragment extends Fragment {
if (!MainActivity.isBiosExisting() || !MainActivity.isFlashExisting())
buttonLaunchEditor.setEnabled(false);
final TextView duration = (TextView) getView().findViewById(R.id.vibDuration_current);
final LinearLayout vibLay = (LinearLayout) getView().findViewById(R.id.vibDuration_layout);
final SeekBar vibSeek = (SeekBar) getView().findViewById(R.id.vib_seekBar);
if (sharedPreferences.getBoolean(Config.pref_touchvibe, true)) {
vibLay.setVisibility(View.VISIBLE);
} else {
vibLay.setVisibility(View.GONE);
}
duration.setText(String.valueOf(Config.vibrationDuration + " ms"));
vibSeek.setProgress(Config.vibrationDuration);
vibSeek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
duration.setText(String.valueOf(progress + 5 + " ms"));
}
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar) {
int progress = seekBar.getProgress() + 5;
sharedPreferences.edit().putInt(Config.pref_vibrationDuration, progress).commit();
Config.vibrationDuration = progress;
vib.vibrate(progress);
}
});
OnCheckedChangeListener touch_vibration = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
sharedPreferences.edit()
.putBoolean(Config.pref_touchvibe, isChecked).commit();
vibLay.setVisibility( isChecked ? View.VISIBLE : View.GONE );
}
};
switchTouchVibrationEnabled = (Switch) getView().findViewById(

View File

@ -83,6 +83,7 @@ public class GL2JNIView extends GLSurfaceView
Renderer rend;
private boolean touchVibrationEnabled;
private int vibrationDuration;
Context context;
public void restoreCustomVjoyValues(float[][] vjoy_d_cached) {
@ -150,6 +151,7 @@ public class GL2JNIView extends GLSurfaceView
ethd = new EmuThread(!Config.nosound);
touchVibrationEnabled = prefs.getBoolean(Config.pref_touchvibe, true);
vibrationDuration = prefs.getInt(Config.pref_vibrationDuration, 20);
int renderType = prefs.getInt(Config.pref_rendertype, LAYER_TYPE_HARDWARE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
@ -389,7 +391,7 @@ public class GL2JNIView extends GLSurfaceView
{
if (vjoy[j][5]==0)
if (!editVjoyMode && touchVibrationEnabled)
vib.vibrate(50);
vib.vibrate(vibrationDuration);
vjoy[j][5]=2;
}