Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //LinkMovementMethod will cause app to crash if there is no activity to handle clicked link (link without schema, or with unknown one)
- public final class ExceptionSafeLinkMovementMethod extends LinkMovementMethod
- {
- @Override
- public boolean onTouchEvent(final TextView widget, final Spannable buffer, final MotionEvent event)
- {
- try
- {
- return super.onTouchEvent(widget, buffer, event);
- }
- catch (final Throwable e)
- {
- return false;
- }
- }
- @Override @TargetApi(11) // 11 == Build.VERSION_CODES.HONEYCOMB
- protected boolean handleMovementKey(
- final TextView widget, final Spannable buffer, final int keyCode, final int movementMetaState, final KeyEvent event)
- {
- try
- {
- return super.handleMovementKey(widget, buffer, keyCode, movementMetaState, event);
- }
- catch (final Throwable e)
- {
- return false;
- }
- }
- @Override
- protected boolean up(final TextView widget, final Spannable buffer)
- {
- try
- {
- return super.up(widget, buffer);
- }
- catch (final Throwable e)
- {
- return false;
- }
- }
- @Override
- protected boolean down(final TextView widget, final Spannable buffer)
- {
- try
- {
- return super.down(widget, buffer);
- }
- catch (final Throwable e)
- {
- return false;
- }
- }
- @Override
- protected boolean left(final TextView widget, final Spannable buffer)
- {
- try
- {
- return super.left(widget, buffer);
- }
- catch (final Throwable e)
- {
- return false;
- }
- }
- @Override
- protected boolean right(final TextView widget, final Spannable buffer)
- {
- try
- {
- return super.right(widget, buffer);
- }
- catch (final Throwable e)
- {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement