Add haptic feedback to back, view and mic buttons

This commit is contained in:
Gabriel Calero 2018-04-24 11:56:01 -03:00
parent 8923c16b08
commit 103e9f92fa
10 changed files with 40 additions and 1 deletions

View file

@ -155,6 +155,11 @@ JNIEXPORT void Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeOnCrea
QAndroidJniObject string = QAndroidJniObject::fromString(a);
__interfaceActivity.callMethod<void>("openGotoActivity", "(Ljava/lang/String;)V", string.object<jstring>());
});
QObject::connect(&AndroidHelper::instance(), &AndroidHelper::hapticFeedbackRequested, [](const QString &c) {
QAndroidJniObject string = QAndroidJniObject::fromString(c);
__interfaceActivity.callMethod<void>("performHapticFeedback", "(Ljava/lang/String;)V", string.object<jstring>());
});
}
JNIEXPORT void Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeOnDestroy(JNIEnv* env, jobject obj) {

View file

@ -15,6 +15,7 @@ import android.content.Intent;
import android.content.res.AssetManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.HapticFeedbackConstants;
import android.view.WindowManager;
import android.util.Log;
import org.qtproject.qt5.android.bindings.QtActivity;
@ -218,4 +219,13 @@ public class InterfaceActivity extends QtActivity {
super.isLoading = false;
}
public void performHapticFeedback(String feedbackConstant) {
switch (feedbackConstant) {
case "CONTEXT_CLICK":
default:
findViewById(android.R.id.content).performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
break;
}
}
}

View file

@ -286,4 +286,14 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
}
@Override
public void onBackPressed() {
int index = getFragmentManager().getBackStackEntryCount() - 1;
if (index > -1) {
super.onBackPressed();
} else {
finishAffinity();
}
}
}

View file

@ -48,3 +48,7 @@ void AndroidHelper::notifyLoginComplete(bool success) {
emit loginComplete(success);
}
void AndroidHelper::performHapticFeedback(const QString& feedbackConstant) {
emit hapticFeedbackRequested(feedbackConstant);
}

View file

@ -28,6 +28,7 @@ public:
void goBackFromAndroidActivity();
void notifyLoginComplete(bool success);
void performHapticFeedback(const QString& feedbackConstant);
QSharedPointer<AccountManager> getAccountManager();
@ -38,6 +39,7 @@ signals:
void backFromAndroidActivity();
void qtAppLoadComplete();
void loginComplete(bool success);
void hapticFeedbackRequested(const QString &feedbackConstant);
private:
AndroidHelper();

View file

@ -7950,6 +7950,10 @@ void Application::restoreAfterAndroidActivity() {
#endif
}
void Application::performHapticFeedback(const QString& feedbackConstant) {
AndroidHelper::instance().performHapticFeedback(feedbackConstant);
}
#if defined(Q_OS_ANDROID)
void Application::enterBackground() {
qDebug() << "[Background-HIFI] enterBackground begin";

View file

@ -408,6 +408,7 @@ public slots:
Q_INVOKABLE bool askBeforeSetAvatarUrl(const QString& avatarUrl) { return askToSetAvatarUrl(avatarUrl); }
Q_INVOKABLE void openAndroidActivity(const QString& activityName);
Q_INVOKABLE void performHapticFeedback(const QString& feedbackConstant);
private slots:
void onDesktopRootItemCreated(QQuickItem* qmlContext);

View file

@ -38,7 +38,8 @@ function init() {
}
function onBackPressed() {
App.openAndroidActivity("Goto");
App.performHapticFeedback("CONTEXT_CLICK");
App.openAndroidActivity("Goto");
}

View file

@ -47,6 +47,7 @@ function onMuteClicked() {
printd("On Mute Clicked");
//Menu.setIsOptionChecked("Mute Microphone", !Menu.isOptionChecked("Mute Microphone"));
Audio.muted = !Audio.muted;
App.performHapticFeedback("CONTEXT_CLICK");
}
function onMuteToggled() {

View file

@ -59,6 +59,7 @@ function init() {
switchToMode(getCurrentModeSetting());
modeButton.clicked.connect(function() {
App.performHapticFeedback("CONTEXT_CLICK");
switchToMode(nextMode[currentMode]);
});
}