MonkeyedSnackbar: work around Harsh's broken phone

I think I'd probably like to revert this, since presumably there's a
good reason in the first place why the support lib disables animations
when accessibility services are turned on?

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2018-07-29 18:35:26 +02:00
parent 219f4e8016
commit c4102992ae
7 changed files with 50 additions and 10 deletions

View File

@ -27,6 +27,7 @@ import com.wireguard.android.databinding.TunnelListItemBinding;
import com.wireguard.android.model.Tunnel; import com.wireguard.android.model.Tunnel;
import com.wireguard.android.model.Tunnel.State; import com.wireguard.android.model.Tunnel.State;
import com.wireguard.android.util.ExceptionLoggers; import com.wireguard.android.util.ExceptionLoggers;
import com.wireguard.android.widget.MonkeyedSnackbar;
/** /**
* Base class for fragments that need to know the currently-selected tunnel. Only does anything when * Base class for fragments that need to know the currently-selected tunnel. Only does anything when
@ -118,7 +119,7 @@ public abstract class BaseFragment extends Fragment implements OnSelectedTunnelC
final String message = getContext().getString(messageResId, error); final String message = getContext().getString(messageResId, error);
final View view = getView(); final View view = getView();
if (view != null) if (view != null)
Snackbar.make(view, message, Snackbar.LENGTH_LONG).show(); MonkeyedSnackbar.make(view, message, Snackbar.LENGTH_LONG).show();
else else
Toast.makeText(getContext(), message, Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), message, Toast.LENGTH_LONG).show();
Log.e(TAG, message, throwable); Log.e(TAG, message, throwable);

View File

@ -32,6 +32,7 @@ import com.wireguard.android.fragment.AppListDialogFragment.AppExclusionListener
import com.wireguard.android.model.Tunnel; import com.wireguard.android.model.Tunnel;
import com.wireguard.android.model.TunnelManager; import com.wireguard.android.model.TunnelManager;
import com.wireguard.android.util.ExceptionLoggers; import com.wireguard.android.util.ExceptionLoggers;
import com.wireguard.android.widget.MonkeyedSnackbar;
import com.wireguard.config.Attribute; import com.wireguard.config.Attribute;
import com.wireguard.config.Config; import com.wireguard.config.Config;
import com.wireguard.config.Peer; import com.wireguard.config.Peer;
@ -72,7 +73,7 @@ public class TunnelEditorFragment extends BaseFragment implements AppExclusionLi
message = getString(R.string.config_save_error, savedTunnel.getName(), error); message = getString(R.string.config_save_error, savedTunnel.getName(), error);
Log.e(TAG, message, throwable); Log.e(TAG, message, throwable);
if (binding != null) { if (binding != null) {
Snackbar.make(binding.mainContainer, message, Snackbar.LENGTH_LONG).show(); MonkeyedSnackbar.make(binding.mainContainer, message, Snackbar.LENGTH_LONG).show();
} }
} }
} }
@ -195,7 +196,7 @@ public class TunnelEditorFragment extends BaseFragment implements AppExclusionLi
final String tunnelName = tunnel == null ? binding.getConfig().getName() : tunnel.getName(); final String tunnelName = tunnel == null ? binding.getConfig().getName() : tunnel.getName();
final String message = getString(R.string.config_save_error, tunnelName, error); final String message = getString(R.string.config_save_error, tunnelName, error);
Log.e(TAG, message, e); Log.e(TAG, message, e);
Snackbar.make(binding.mainContainer, error, Snackbar.LENGTH_LONG).show(); MonkeyedSnackbar.make(binding.mainContainer, error, Snackbar.LENGTH_LONG).show();
return false; return false;
} }
if (tunnel == null) { if (tunnel == null) {
@ -248,7 +249,7 @@ public class TunnelEditorFragment extends BaseFragment implements AppExclusionLi
message = getString(R.string.tunnel_create_error, error); message = getString(R.string.tunnel_create_error, error);
Log.e(TAG, message, throwable); Log.e(TAG, message, throwable);
if (binding != null) { if (binding != null) {
Snackbar.make(binding.mainContainer, message, Snackbar.LENGTH_LONG).show(); MonkeyedSnackbar.make(binding.mainContainer, message, Snackbar.LENGTH_LONG).show();
} }
} }
} }
@ -267,7 +268,7 @@ public class TunnelEditorFragment extends BaseFragment implements AppExclusionLi
message = getString(R.string.tunnel_rename_error, error); message = getString(R.string.tunnel_rename_error, error);
Log.e(TAG, message, throwable); Log.e(TAG, message, throwable);
if (binding != null) { if (binding != null) {
Snackbar.make(binding.mainContainer, message, Snackbar.LENGTH_LONG).show(); MonkeyedSnackbar.make(binding.mainContainer, message, Snackbar.LENGTH_LONG).show();
} }
} }
} }

View File

@ -40,6 +40,7 @@ import com.wireguard.android.databinding.TunnelListItemBinding;
import com.wireguard.android.model.Tunnel; import com.wireguard.android.model.Tunnel;
import com.wireguard.android.util.ExceptionLoggers; import com.wireguard.android.util.ExceptionLoggers;
import com.wireguard.android.util.ObservableSortedKeyedList; import com.wireguard.android.util.ObservableSortedKeyedList;
import com.wireguard.android.widget.MonkeyedSnackbar;
import com.wireguard.android.widget.fab.FloatingActionsMenuRecyclerViewScrollListener; import com.wireguard.android.widget.fab.FloatingActionsMenuRecyclerViewScrollListener;
import com.wireguard.config.Config; import com.wireguard.config.Config;
@ -298,7 +299,7 @@ public class TunnelListFragment extends BaseFragment {
Log.e(TAG, message, throwable); Log.e(TAG, message, throwable);
} }
if (binding != null) { if (binding != null) {
Snackbar.make(binding.mainContainer, message, Snackbar.LENGTH_LONG).show(); MonkeyedSnackbar.make(binding.mainContainer, message, Snackbar.LENGTH_LONG).show();
} }
} }
@ -324,7 +325,7 @@ public class TunnelListFragment extends BaseFragment {
tunnels.size(), tunnels.size() + throwables.size()); tunnels.size(), tunnels.size() + throwables.size());
if (binding != null) if (binding != null)
Snackbar.make(binding.mainContainer, message, Snackbar.LENGTH_LONG).show(); MonkeyedSnackbar.make(binding.mainContainer, message, Snackbar.LENGTH_LONG).show();
} }
@Override @Override

View File

@ -20,6 +20,7 @@ import com.wireguard.android.Application;
import com.wireguard.android.R; import com.wireguard.android.R;
import com.wireguard.android.util.ExceptionLoggers; import com.wireguard.android.util.ExceptionLoggers;
import com.wireguard.android.util.FragmentUtils; import com.wireguard.android.util.FragmentUtils;
import com.wireguard.android.widget.MonkeyedSnackbar;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
@ -79,7 +80,7 @@ public class LogExporterPreference extends Preference {
final String error = ExceptionLoggers.unwrapMessage(throwable); final String error = ExceptionLoggers.unwrapMessage(throwable);
final String message = getContext().getString(R.string.log_export_error, error); final String message = getContext().getString(R.string.log_export_error, error);
Log.e(TAG, message, throwable); Log.e(TAG, message, throwable);
Snackbar.make( MonkeyedSnackbar.make(
FragmentUtils.getPrefActivity(this).findViewById(android.R.id.content), FragmentUtils.getPrefActivity(this).findViewById(android.R.id.content),
message, Snackbar.LENGTH_LONG).show(); message, Snackbar.LENGTH_LONG).show();
setEnabled(true); setEnabled(true);

View File

@ -21,6 +21,7 @@ import com.wireguard.android.R;
import com.wireguard.android.model.Tunnel; import com.wireguard.android.model.Tunnel;
import com.wireguard.android.util.ExceptionLoggers; import com.wireguard.android.util.ExceptionLoggers;
import com.wireguard.android.util.FragmentUtils; import com.wireguard.android.util.FragmentUtils;
import com.wireguard.android.widget.MonkeyedSnackbar;
import com.wireguard.config.Config; import com.wireguard.config.Config;
import java.io.File; import java.io.File;
@ -88,7 +89,7 @@ public class ZipExporterPreference extends Preference {
final String error = ExceptionLoggers.unwrapMessage(throwable); final String error = ExceptionLoggers.unwrapMessage(throwable);
final String message = getContext().getString(R.string.zip_export_error, error); final String message = getContext().getString(R.string.zip_export_error, error);
Log.e(TAG, message, throwable); Log.e(TAG, message, throwable);
Snackbar.make( MonkeyedSnackbar.make(
FragmentUtils.getPrefActivity(this).findViewById(android.R.id.content), FragmentUtils.getPrefActivity(this).findViewById(android.R.id.content),
message, Snackbar.LENGTH_LONG).show(); message, Snackbar.LENGTH_LONG).show();
setEnabled(true); setEnabled(true);

View File

@ -13,6 +13,8 @@ import android.support.design.widget.Snackbar;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import com.wireguard.android.widget.MonkeyedSnackbar;
/** /**
* Standalone utilities for interacting with the system clipboard. * Standalone utilities for interacting with the system clipboard.
*/ */
@ -33,6 +35,6 @@ public final class ClipboardUtils {
return; return;
final CharSequence description = view.getContentDescription(); final CharSequence description = view.getContentDescription();
((ClipboardManager) service).setPrimaryClip(ClipData.newPlainText(description, text)); ((ClipboardManager) service).setPrimaryClip(ClipData.newPlainText(description, text));
Snackbar.make(view, description + " copied to clipboard", Snackbar.LENGTH_LONG).show(); MonkeyedSnackbar.make(view, description + " copied to clipboard", Snackbar.LENGTH_LONG).show();
} }
} }

View File

@ -0,0 +1,33 @@
package com.wireguard.android.widget;
import android.support.annotation.NonNull;
import android.support.design.widget.BaseTransientBottomBar;
import android.support.design.widget.Snackbar;
import android.util.Log;
import android.view.View;
import android.view.accessibility.AccessibilityManager;
import com.wireguard.android.BootShutdownReceiver;
import java.lang.reflect.Field;
public class MonkeyedSnackbar {
private static final String TAG = "WireGuard/" + BootShutdownReceiver.class.getSimpleName();
public static Snackbar make(@NonNull final View view, @NonNull final CharSequence text,
@BaseTransientBottomBar.Duration final int duration) {
final Snackbar snackbar = Snackbar.make(view, text, duration);
try {
final Field accessibilityManager = Snackbar.class.getSuperclass().getDeclaredField("mAccessibilityManager");
accessibilityManager.setAccessible(true);
final Field isEnabled = AccessibilityManager.class.getDeclaredField("mIsEnabled");
isEnabled.setAccessible(true);
isEnabled.setBoolean(accessibilityManager.get(snackbar), false);
} catch (final Exception e) {
Log.e(TAG, "Unable to force-enable snackbar animations", e);
}
return snackbar;
}
}