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