vibration on suggestion selection
This commit is contained in:
parent
9f4c04d286
commit
d7043060d0
9 changed files with 46 additions and 23 deletions
|
|
@ -1,12 +1,24 @@
|
|||
package io.github.sspanak.tt9.ui.main;
|
||||
package io.github.sspanak.tt9.ui;
|
||||
|
||||
import android.os.Build;
|
||||
import android.view.HapticFeedbackConstants;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||
import io.github.sspanak.tt9.ui.main.keys.SoftKey;
|
||||
import io.github.sspanak.tt9.ui.main.keys.SoftNumberKey;
|
||||
|
||||
public class Vibration {
|
||||
@NonNull private final SettingsStore settings;
|
||||
private final View view;
|
||||
|
||||
public Vibration(@NonNull SettingsStore settings, View view) {
|
||||
this.settings = settings;
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
public static int getNoVibration() {
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -30,4 +42,14 @@ public class Vibration {
|
|||
return HapticFeedbackConstants.VIRTUAL_KEY;
|
||||
}
|
||||
}
|
||||
|
||||
public void vibrate(int vibrationType) {
|
||||
if (settings.getHapticFeedback() && view != null) {
|
||||
view.performHapticFeedback(vibrationType, HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
|
||||
}
|
||||
}
|
||||
|
||||
public void vibrate() {
|
||||
vibrate(getPressVibration(null));
|
||||
}
|
||||
}
|
||||
|
|
@ -7,8 +7,11 @@ import androidx.annotation.NonNull;
|
|||
|
||||
import io.github.sspanak.tt9.ime.TraditionalT9;
|
||||
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||
import io.github.sspanak.tt9.ui.Vibration;
|
||||
|
||||
public class ResizableMainView extends MainView implements View.OnAttachStateChangeListener {
|
||||
private Vibration vibration;
|
||||
|
||||
private int height;
|
||||
private float resizeStartY;
|
||||
private long lastResizeTime;
|
||||
|
|
@ -58,6 +61,8 @@ public class ResizableMainView extends MainView implements View.OnAttachStateCha
|
|||
main.getView().removeOnAttachStateChangeListener(this);
|
||||
main.getView().addOnAttachStateChangeListener(this);
|
||||
|
||||
vibration = new Vibration(tt9.getSettings(), main.getView());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -125,12 +130,12 @@ public class ResizableMainView extends MainView implements View.OnAttachStateCha
|
|||
settings.setMainViewLayout(SettingsStore.LAYOUT_SMALL);
|
||||
height = heightSmall;
|
||||
tt9.onCreateInputView();
|
||||
vibrate();
|
||||
vibration.vibrate();
|
||||
} else if (settings.isMainLayoutSmall()) {
|
||||
settings.setMainViewLayout(SettingsStore.LAYOUT_NUMPAD);
|
||||
height = (int) Math.max(Math.max(heightNumpad * 0.6, heightSmall * 1.1), height + delta);
|
||||
tt9.onCreateInputView();
|
||||
vibrate();
|
||||
vibration.vibrate();
|
||||
} else {
|
||||
changeHeight(delta, heightSmall, heightNumpad);
|
||||
}
|
||||
|
|
@ -148,12 +153,12 @@ public class ResizableMainView extends MainView implements View.OnAttachStateCha
|
|||
settings.setMainViewLayout(SettingsStore.LAYOUT_TRAY);
|
||||
height = heightTray;
|
||||
tt9.onCreateInputView();
|
||||
vibrate();
|
||||
vibration.vibrate();
|
||||
} else if (!changeHeight(delta, heightSmall, heightNumpad)) {
|
||||
settings.setMainViewLayout(SettingsStore.LAYOUT_SMALL);
|
||||
height = heightSmall;
|
||||
tt9.onCreateInputView();
|
||||
vibrate();
|
||||
vibration.vibrate();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -196,11 +201,4 @@ public class ResizableMainView extends MainView implements View.OnAttachStateCha
|
|||
calculateInitialHeight();
|
||||
setHeight(height, heightSmall, heightNumpad);
|
||||
}
|
||||
|
||||
|
||||
private void vibrate() {
|
||||
if (tt9.getSettings().getHapticFeedback() && main != null && main.getView() != null) {
|
||||
main.getView().performHapticFeedback(Vibration.getPressVibration(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import android.view.KeyEvent;
|
|||
|
||||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.languages.LanguageKind;
|
||||
import io.github.sspanak.tt9.ui.main.Vibration;
|
||||
import io.github.sspanak.tt9.ui.Vibration;
|
||||
|
||||
public class SoftBackspaceKey extends SoftKey {
|
||||
private boolean hold;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import android.content.Context;
|
|||
import android.util.AttributeSet;
|
||||
|
||||
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||
import io.github.sspanak.tt9.ui.main.Vibration;
|
||||
import io.github.sspanak.tt9.ui.Vibration;
|
||||
|
||||
public class SoftFilterKey extends SoftKey {
|
||||
public SoftFilterKey(Context context) { super(context); setFontSize(); }
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import android.content.Context;
|
|||
import android.util.AttributeSet;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.ui.main.Vibration;
|
||||
import io.github.sspanak.tt9.ui.Vibration;
|
||||
|
||||
public class SoftInputModeKey extends SoftKey {
|
||||
public SoftInputModeKey(Context context) {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import android.text.Spanned;
|
|||
import android.text.style.RelativeSizeSpan;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.HapticFeedbackConstants;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
|
|
@ -19,7 +18,7 @@ import androidx.core.content.ContextCompat;
|
|||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.ime.TraditionalT9;
|
||||
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||
import io.github.sspanak.tt9.ui.main.Vibration;
|
||||
import io.github.sspanak.tt9.ui.Vibration;
|
||||
import io.github.sspanak.tt9.util.Characters;
|
||||
import io.github.sspanak.tt9.util.Logger;
|
||||
import io.github.sspanak.tt9.util.Text;
|
||||
|
|
@ -28,6 +27,7 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
|
|||
private final String LOG_TAG = getClass().getSimpleName();
|
||||
|
||||
protected TraditionalT9 tt9;
|
||||
protected Vibration vibration;
|
||||
|
||||
protected float complexLabelTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_TITLE_RELATIVE_SIZE;
|
||||
protected float complexLabelSubTitleSize = SettingsStore.SOFT_KEY_COMPLEX_LABEL_SUB_TITLE_RELATIVE_SIZE;
|
||||
|
|
@ -271,8 +271,9 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement
|
|||
|
||||
|
||||
protected void vibrate(int vibrationType) {
|
||||
if (tt9 != null && tt9.getSettings().getHapticFeedback() && vibrationType != Vibration.getNoVibration()) {
|
||||
getRootView().performHapticFeedback(vibrationType, HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
|
||||
if (tt9 != null) {
|
||||
vibration = vibration == null ? new Vibration(tt9.getSettings(), this) : vibration;
|
||||
vibration.vibrate(vibrationType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import android.content.Context;
|
|||
import android.util.AttributeSet;
|
||||
|
||||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.ui.main.Vibration;
|
||||
import io.github.sspanak.tt9.ui.Vibration;
|
||||
|
||||
public class SoftKeyArrow extends SoftKey {
|
||||
private boolean hold;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import io.github.sspanak.tt9.ime.modes.InputMode;
|
|||
import io.github.sspanak.tt9.languages.Language;
|
||||
import io.github.sspanak.tt9.languages.LanguageKind;
|
||||
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||
import io.github.sspanak.tt9.ui.main.Vibration;
|
||||
import io.github.sspanak.tt9.ui.Vibration;
|
||||
import io.github.sspanak.tt9.util.Logger;
|
||||
|
||||
public class SoftNumberKey extends SoftKey {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import java.util.List;
|
|||
|
||||
import io.github.sspanak.tt9.R;
|
||||
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||
import io.github.sspanak.tt9.ui.Vibration;
|
||||
import io.github.sspanak.tt9.ui.main.ResizableMainView;
|
||||
|
||||
public class SuggestionsBar {
|
||||
|
|
@ -33,6 +34,7 @@ public class SuggestionsBar {
|
|||
private final RecyclerView mView;
|
||||
private final SettingsStore settings;
|
||||
private SuggestionsAdapter mSuggestionsAdapter;
|
||||
private Vibration vibration;
|
||||
|
||||
private final Handler alternativeScrollingHandler = new Handler();
|
||||
|
||||
|
|
@ -52,8 +54,7 @@ public class SuggestionsBar {
|
|||
initDataAdapter(context);
|
||||
initSeparator(context);
|
||||
configureAnimation();
|
||||
|
||||
|
||||
vibration = new Vibration(settings, mView);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -258,6 +259,7 @@ public class SuggestionsBar {
|
|||
* Passes through suggestion selected using the touchscreen.
|
||||
*/
|
||||
private void handleItemClick(int position) {
|
||||
vibration.vibrate();
|
||||
selectedIndex = position;
|
||||
onItemClick.run();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue