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

lift emulateShiftHeld to our custom WebView subclass

This commit is contained in:
Jesse Vincent 2010-12-25 22:30:34 +00:00
parent 8e2e4e515f
commit daf5a9d704
2 changed files with 25 additions and 20 deletions

View File

@ -1948,7 +1948,8 @@ public class MessageView extends K9Activity implements OnClickListener
onShowAdditionalHeaders(); onShowAdditionalHeaders();
break; break;
case R.id.select_text: case R.id.select_text:
emulateShiftHeld(mMessageContentView); mToggleScrollView.setScrolling(false);
mMessageContentView.emulateShiftHeld();
break; break;
default: default:
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
@ -2677,25 +2678,6 @@ public class MessageView extends K9Activity implements OnClickListener
updateDecryptLayout(); updateDecryptLayout();
} }
/*
* 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);
Toast.makeText(this, R.string.select_text_now, Toast.LENGTH_SHORT).show();
}
catch (Exception e)
{
Log.e(K9.LOG_TAG, "Exception in emulateShiftHeld()", e);
}
}
} }

View File

@ -4,9 +4,12 @@ import android.content.Context;
import android.os.Build; import android.os.Build;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
import android.widget.Toast;
import com.fsck.k9.K9; import com.fsck.k9.K9;
import com.fsck.k9.R;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -117,4 +120,24 @@ public class MessageWebView extends WebView {
// Disable network images by default. This is overriden by preferences. // Disable network images by default. This is overriden by preferences.
blockNetworkData(true); blockNetworkData(true);
} }
/*
* Emulate the shift key being pressed to trigger the text selection mode
* of a WebView.
*/
public void emulateShiftHeld()
{
try
{
KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);
shiftPressEvent.dispatch(this);
Toast.makeText(getContext() , R.string.select_text_now, Toast.LENGTH_SHORT).show();
}
catch (Exception e)
{
Log.e(K9.LOG_TAG, "Exception in emulateShiftHeld()", e);
}
}
} }