1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Added menu option to select & copy text in the message view.

The standard ScrollView causes problems when selecting text (and the message is long enough so scrolling is possible). The newly introduced ToggleScrollView can be set to disable scrolling via touch gestures thus making copying multi-line text sections possible.

Fixes issue 662
This commit is contained in:
cketti 2010-07-07 22:14:45 +00:00
parent 76df04e949
commit 1eb37c2031
6 changed files with 89 additions and 6 deletions

View File

@ -5,7 +5,7 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView
<com.fsck.k9.activity.ToggleScrollView
android:id="@+id/top_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
@ -96,7 +96,7 @@
</LinearLayout>
</LinearLayout>
</ScrollView>
</com.fsck.k9.activity.ToggleScrollView>
<LinearLayout
android:id="@+id/move_buttons"
android:orientation="horizontal"

View File

@ -5,7 +5,7 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView
<com.fsck.k9.activity.ToggleScrollView
android:id="@+id/top_view"
android:layout_width="fill_parent"
android:layout_height="0dip"
@ -108,7 +108,7 @@
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</com.fsck.k9.activity.ToggleScrollView>
<LinearLayout
android:id="@+id/move_buttons"
android:orientation="horizontal"

View File

@ -61,4 +61,8 @@
android:id="@+id/copy"
android:title="@string/copy_action"
/>
<item
android:id="@+id/select_text"
android:title="@string/select_text_action"
/>
</menu>

View File

@ -92,6 +92,7 @@
<string name="copy_action">Copy</string>
<string name="show_full_header_action">Show full header</string>
<string name="hide_full_header_action">Hide full header</string>
<string name="select_text_action">Select text</string>
<string name="mark_as_unread_action">Mark as unread</string>
<string name="move_to_action">Move to</string>

View File

@ -40,6 +40,7 @@ import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
@ -52,7 +53,6 @@ import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
@ -111,6 +111,7 @@ public class MessageView extends K9Activity implements OnClickListener
private View mArchiveScrolling;
private View mMoveScrolling;
private View mSpamScrolling;
private ToggleScrollView mToggleScrollView;
private Account mAccount;
private MessageReference mMessageReference;
@ -151,6 +152,17 @@ public class MessageView extends K9Activity implements OnClickListener
}
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev)
{
if (ev.getAction() == MotionEvent.ACTION_UP)
{
// Text selection is finished. Allow scrolling again.
mToggleScrollView.setScrolling(true);
}
return super.dispatchTouchEvent(ev);
}
@Override
public boolean dispatchKeyEvent(KeyEvent event)
@ -173,6 +185,16 @@ public class MessageView extends K9Activity implements OnClickListener
{
switch (keyCode)
{
case KeyEvent.KEYCODE_SHIFT_LEFT:
case KeyEvent.KEYCODE_SHIFT_RIGHT:
{
/*
* Selecting text started via shift key. Disable scrolling as
* this causes problems when selecting text.
*/
mToggleScrollView.setScrolling(false);
break;
}
case KeyEvent.KEYCODE_DEL:
{
onDelete();
@ -644,7 +666,7 @@ public class MessageView extends K9Activity implements OnClickListener
mDateView = (TextView)findViewById(R.id.date);
mTimeView = (TextView)findViewById(R.id.time);
mTopView = (ScrollView)findViewById(R.id.top_view);
mTopView = mToggleScrollView = (ToggleScrollView)findViewById(R.id.top_view);
mMessageContentView = (WebView)findViewById(R.id.message_content);
mAttachments = (LinearLayout)findViewById(R.id.attachments);
@ -1536,6 +1558,9 @@ public class MessageView extends K9Activity implements OnClickListener
case R.id.show_full_header:
onShowAdditionalHeaders();
break;
case R.id.select_text:
emulateShiftHeld(mMessageContentView);
break;
default:
return super.onOptionsItemSelected(item);
}
@ -2114,4 +2139,24 @@ public class MessageView extends K9Activity implements OnClickListener
slide.setInterpolator(new AccelerateInterpolator());
return slide;
}
/**
* Emulate the shift key being pressed to trigger the text selection mode
* of a WebView.
*/
private void emulateShiftHeld(WebView view)
{
try
{
mToggleScrollView.setScrolling(false);
KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);
shiftPressEvent.dispatch(view);
}
catch (Exception e)
{
Log.e(K9.LOG_TAG, "Exception in emulateShiftHeld()", e);
}
}
}

View File

@ -0,0 +1,33 @@
package com.fsck.k9.activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ScrollView;
public class ToggleScrollView extends ScrollView
{
private boolean mScrolling = true;
public ToggleScrollView(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public void setScrolling(boolean enable)
{
mScrolling = enable;
}
@Override
public boolean onTouchEvent(MotionEvent ev)
{
return (mScrolling) ? super.onTouchEvent(ev) : true;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev)
{
return (mScrolling) ? super.onInterceptTouchEvent(ev) : false;
}
}