Haptic feedback

This commit is contained in:
M66B
2018-10-15 07:22:51 +00:00
parent b50877bfd1
commit 600284b69c
8 changed files with 42 additions and 1 deletions

View File

@@ -247,6 +247,8 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
return;
TupleMessageEx message = getItem(pos);
Helper.hapticFeedback(itemView);
if (EntityFolder.DRAFTS.equals(message.folderType))
context.startActivity(
new Intent(context, ActivityCompose.class)

View File

@@ -194,7 +194,11 @@ public class FragmentCompose extends FragmentEx {
@Override
public void onFocusChange(View view, boolean hasFocus) {
free = hasFocus;
Helper.hapticFeedback(view);
getActivity().invalidateOptionsMenu();
grpHeader.setVisibility(hasFocus ? View.GONE : View.VISIBLE);
if (hasFocus) {
addresses = (grpAddresses.getVisibility() != View.GONE);
@@ -212,6 +216,7 @@ public class FragmentCompose extends FragmentEx {
case KeyEvent.KEYCODE_BACK:
if (grpHeader.getVisibility() == View.GONE) {
free = false;
getActivity().invalidateOptionsMenu();
grpHeader.setVisibility(View.VISIBLE);
if (addresses)

View File

@@ -351,6 +351,9 @@ public class FragmentMessage extends FragmentEx {
@Override
public void onClick(View view) {
free = true;
Helper.hapticFeedback(view);
getActivity().invalidateOptionsMenu();
grpHeader.setVisibility(View.GONE);
@@ -373,6 +376,7 @@ public class FragmentMessage extends FragmentEx {
public boolean onBackPressed() {
if (free && isVisible()) {
free = false;
getActivity().invalidateOptionsMenu();
grpHeader.setVisibility(View.VISIBLE);

View File

@@ -380,6 +380,7 @@ public class FragmentMessages extends FragmentEx {
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Helper.hapticFeedback(view);
startActivity(new Intent(getContext(), ActivityCompose.class)
.putExtra("action", "new")
.putExtra("account", (Long) fab.getTag())

View File

@@ -37,6 +37,7 @@ public class FragmentOptions extends FragmentEx {
private CheckBox cbLight;
private CheckBox cbBrowse;
private CheckBox cbSwipe;
private CheckBox cbHaptic;
private CheckBox cbDebug;
@Override
@@ -52,6 +53,7 @@ public class FragmentOptions extends FragmentEx {
cbLight = view.findViewById(R.id.cbLight);
cbBrowse = view.findViewById(R.id.cbBrowse);
cbSwipe = view.findViewById(R.id.cbSwipe);
cbHaptic = view.findViewById(R.id.cbHaptic);
cbDebug = view.findViewById(R.id.cbDebug);
// Wire controls
@@ -102,6 +104,14 @@ public class FragmentOptions extends FragmentEx {
}
});
cbHaptic.setChecked(prefs.getBoolean("haptic", true));
cbHaptic.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("haptic", checked).apply();
}
});
cbDebug.setChecked(prefs.getBoolean("debug", false));
cbDebug.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override

View File

@@ -23,6 +23,7 @@ import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.TypedArray;
@@ -31,6 +32,7 @@ import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
import android.view.HapticFeedbackConstants;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
@@ -82,6 +84,12 @@ public class Helper {
}
};
static void hapticFeedback(View view) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(view.getContext());
if (prefs.getBoolean("haptic", true))
view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
}
static void view(Context context, Intent intent) {
Uri uri = intent.getData();
if ("http".equals(uri.getScheme()) || "https".equals(uri.getScheme()))