Skip to content

Cherry pick commit 3ed778ad6389c901077fee38bb77abd55dd4eba4 to support TW_NO_HAPTICS flag #304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: android-7.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ endif
ifeq ($(TW_NO_EXFAT_FUSE), true)
LOCAL_CFLAGS += -DTW_NO_EXFAT_FUSE
endif
ifeq ($(TW_NO_HAPTICS), true)
LOCAL_CFLAGS += -DTW_NO_HAPTICS
endif
ifeq ($(TW_INCLUDE_JB_CRYPTO), true)
TW_INCLUDE_CRYPTO := true
endif
Expand Down
9 changes: 9 additions & 0 deletions data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,16 @@ void DataManager::SetDefaultValues()
mConst.SetValue("false", "0");

mConst.SetValue(TW_VERSION_VAR, TW_VERSION_STR);

#ifndef TW_NO_HAPTICS
mPersist.SetValue("tw_button_vibrate", "80");
mPersist.SetValue("tw_keyboard_vibrate", "40");
mPersist.SetValue("tw_action_vibrate", "160");
mConst.SetValue("tw_disable_haptics", "0");
#else
LOGINFO("TW_NO_HAPTICS := true\n");
mConst.SetValue("tw_disable_haptics", "1");
#endif

TWPartition *store = PartitionManager.Get_Default_Storage_Partition();
if (store)
Expand Down Expand Up @@ -1047,9 +1054,11 @@ string DataManager::GetSettingsStoragePath(void)

void DataManager::Vibrate(const string& varName)
{
#ifndef TW_NO_HAPTICS
int vib_value = 0;
GetValue(varName, vib_value);
if (vib_value) {
vibrate(vib_value);
}
#endif
}
2 changes: 2 additions & 0 deletions gui/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,10 @@ void GUIAction::operation_end(const int operation_status)
blankTimer.resetTimerAndUnblank();
property_set("twrp.action_complete", "1");
time(&Stop);
#ifndef TW_NO_HAPTICS
if ((int) difftime(Stop, Start) > 10)
DataManager::Vibrate("tw_action_vibrate");
#endif
LOGINFO("operation_end - status=%d\n", operation_status);
}

Expand Down
2 changes: 2 additions & 0 deletions gui/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ int GUIButton::NotifyTouch(TOUCH_STATE state, int x, int y)
} else {
if (last_state == 0) {
last_state = 1;
#ifndef TW_NO_HAPTICS
DataManager::Vibrate("tw_button_vibrate");
#endif
if (mButtonLabel != NULL)
mButtonLabel->isHighlighted = true;
if (mButtonImg != NULL)
Expand Down
3 changes: 2 additions & 1 deletion gui/checkbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ int GUICheckbox::NotifyTouch(TOUCH_STATE state, int x __unused, int y __unused)
DataManager::GetValue(mVarName, lastState);
lastState = (lastState == 0) ? 1 : 0;
DataManager::SetValue(mVarName, lastState);

#ifndef TW_NO_HAPTICS
DataManager::Vibrate("tw_button_vibrate");
#endif
}
return 0;
}
Expand Down
4 changes: 4 additions & 0 deletions gui/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,9 @@ int GUIKeyboard::NotifyTouch(TOUCH_STATE state, int x, int y)
bool repeatKey = false;
Layout& lay = layouts[currentLayout - 1];
if (state == TOUCH_RELEASE && was_held == 0) {
#ifndef TW_NO_HAPTICS
DataManager::Vibrate("tw_keyboard_vibrate");
#endif
if (key.layout > 0) {
// Switch layouts
if (lay.is_caps && key.layout == lay.revert_layout && !CapsLockOn) {
Expand Down Expand Up @@ -593,7 +595,9 @@ int GUIKeyboard::NotifyTouch(TOUCH_STATE state, int x, int y)
was_held = 1;
if (key.longpresskey > 0) {
// Long Press Key
#ifndef TW_NO_HAPTICS
DataManager::Vibrate("tw_keyboard_vibrate");
#endif
PageManager::NotifyCharInput(key.longpresskey);
}
else
Expand Down
4 changes: 4 additions & 0 deletions gui/patternpassword.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,9 @@ int GUIPatternPassword::NotifyTouch(TOUCH_STATE state, int x, int y)
mTrackingTouch = true;
ResetActiveDots();
ConnectDot(dot_idx);
#ifndef TW_NO_HAPTICS
DataManager::Vibrate("tw_button_vibrate");
#endif
mCurLineX = x;
mCurLineY = y;
mNeedRender = true;
Expand All @@ -387,7 +389,9 @@ int GUIPatternPassword::NotifyTouch(TOUCH_STATE state, int x, int y)
{
ConnectIntermediateDots(dot_idx);
ConnectDot(dot_idx);
#ifndef TW_NO_HAPTICS
DataManager::Vibrate("tw_button_vibrate");
#endif
}

mCurLineX = x;
Expand Down
3 changes: 2 additions & 1 deletion gui/scrolllist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,9 @@ int GUIScrollList::NotifyTouch(TOUCH_STATE state, int x, int y)
// We've selected an item!
NotifySelect(selectedItem);
mUpdate = 1;

#ifndef TW_NO_HAPTICS
DataManager::Vibrate("tw_button_vibrate");
#endif
selectedItem = NO_ITEM;
} else {
// Start kinetic scrolling
Expand Down
2 changes: 2 additions & 0 deletions gui/slider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,10 @@ int GUISlider::NotifyTouch(TOUCH_STATE state, int x, int y)
return 0;

if (sCurTouchX >= mRenderX + mRenderW - sTouchW) {
#ifndef TW_NO_HAPTICS
DataManager::Vibrate("tw_button_vibrate");
sAction->doActions();
#endif
}

sCurTouchX = mRenderX;
Expand Down
2 changes: 2 additions & 0 deletions gui/terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,9 @@ class TerminalEngine
switch (ch)
{
case 7: // BEL
#ifndef TW_NO_HAPTICS
DataManager::Vibrate("tw_button_vibrate");
#endif
break;
case 8: // BS
left();
Expand Down
9 changes: 9 additions & 0 deletions gui/theme/common/landscape.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3159,25 +3159,34 @@
<text>{@vibration_hdr=Vibration}</text>
</text>

<text style="text_m">
<condition var1="tw_disable_haptics" var2="1"/>
<placement x="col1_x_left" y="%row4_y%" w="%content_width%"/>
<text>{@vibration_disabled=Vibration Disabled for Device}</text>
</text>

<template name="tabs_settings"/>

<fill color="%text_color%">
<placement x="%tab5_col4_x%" y="%row_tab_y%" w="%tab5_width%" h="%tab_indicator_height%"/>
</fill>

<slidervalue>
<condition var1="tw_disable_haptics" var2="0"/>
<placement x="col1_x_left" y="%row4_y%" w="%content_width%"/>
<text>{@button_vibration=Button Vibration:}</text>
<data variable="tw_button_vibrate" min="0" max="300"/>
</slidervalue>

<slidervalue>
<condition var1="tw_disable_haptics" var2="0"/>
<placement x="col1_x_left" y="%row9_y%" w="%content_width%"/>
<text>{@kb_vibration=Keyboard Vibration:}</text>
<data variable="tw_keyboard_vibrate" min="0" max="300"/>
</slidervalue>

<slidervalue>
<condition var1="tw_disable_haptics" var2="0"/>
<placement x="col1_x_left" y="%row14_y%" w="%content_width%"/>
<text>{@act_vibration=Action Vibration:}</text>
<data variable="tw_action_vibrate" min="0" max="500"/>
Expand Down
1 change: 1 addition & 0 deletions gui/theme/common/languages/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@
<string name="settings_tz_btn">Time Zone</string>
<string name="settings_screen_btn">Screen</string>
<string name="settings_screen_bright_btn">Screen Brightness</string>
<string name="vibration_disabled">Vibration is disabled for this device</string>
<string name="settings_vibration_btn">Vibration</string>
<string name="settings_language_btn">Language</string>
<string name="time_zone_hdr">Time Zone</string>
Expand Down
9 changes: 9 additions & 0 deletions gui/theme/common/portrait.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3322,25 +3322,34 @@
<text>{@vibration_hdr=Vibration}</text>
</text>

<text style="text_m">
<condition var1="tw_disable_haptics" var2="1"/>
<placement x="%indent%" y="%row4_y%"/>
<text>{@vibration_disabled=Vibration Disabled for Device}</text>
</text>

<template name="tabs_settings"/>

<fill color="%text_color%">
<placement x="%tab5_col4_x%" y="%row_tab_y%" w="%tab5_width%" h="%tab_indicator_height%"/>
</fill>

<slidervalue>
<condition var1="tw_disable_haptics" var2="0"/>
<placement x="indent" y="%row4_y%" w="%content_width%"/>
<text>{@button_vibration=Button Vibration:}</text>
<data variable="tw_button_vibrate" min="0" max="300"/>
</slidervalue>

<slidervalue>
<condition var1="tw_disable_haptics" var2="0"/>
<placement x="indent" y="%row9_y%" w="%content_width%"/>
<text>{@kb_vibration=Keyboard Vibration:}</text>
<data variable="tw_keyboard_vibrate" min="0" max="300"/>
</slidervalue>

<slidervalue>
<condition var1="tw_disable_haptics" var2="0"/>
<placement x="indent" y="%row14_y%" w="%content_width%"/>
<text>{@act_vibration=Action Vibration:}</text>
<data variable="tw_action_vibrate" min="0" max="500"/>
Expand Down
1 change: 1 addition & 0 deletions gui/theme/common/watch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3532,6 +3532,7 @@
</button>

<button style="main_button">
<condition var1="tw_disable_haptics" var2="0"/>
<placement x="%col1_x_right%" y="%row6_y%"/>
<text>{@settings_vibration_btn=Vibration}</text>
<action function="page">settings_vibration</action>
Expand Down
6 changes: 4 additions & 2 deletions minuitwrp/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ static inline int ABS(int x) {
return x<0?-x:x;
}

#ifndef TW_NO_HAPTICS
int vibrate(int timeout_ms)
{
char str[20];
Expand All @@ -129,6 +130,7 @@ int vibrate(int timeout_ms)

return 0;
}
#endif

/* Returns empty tokens */
static char *vk_strtok_r(char *str, const char *delim, char **save_str)
Expand Down Expand Up @@ -715,9 +717,9 @@ static int vk_modify(struct ev *e, struct input_event *ev)
ev->value = 1;

last_virt_key = e->vks[i].scancode;

#ifndef TW_NO_HAPTICS
vibrate(VIBRATOR_TIME_MS);

#endif
// Mark that all further movement until lift is discard,
// and make sure we don't come back into this area
discard = 1;
Expand Down