Skip to content

Instantly share code, notes, and snippets.

@ZieIony
Last active October 4, 2015 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZieIony/2510c4a617c076c795d8 to your computer and use it in GitHub Desktop.
Save ZieIony/2510c4a617c076c795d8 to your computer and use it in GitHub Desktop.
EditText without Samsung's Gingerbread copy/paste menu
public class EditTextWithoutMenu extends EditText{
public EditTextWithoutMenu(Context context) {
this(context, null);
}
public EditTextWithoutMenu(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.carbon_editTextStyle);
}
public EditTextWithoutMenu(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
WindowManager brokenWindowManager = new WindowManager() {
@Override
public Display getDefaultDisplay() {
return null;
}
@Override
public void removeViewImmediate(View view) {
}
@Override
public void addView(View view, ViewGroup.LayoutParams params) {
final WindowManager.LayoutParams wparams
= (WindowManager.LayoutParams) params;
view.setLayoutParams(wparams);
}
@Override
public void updateViewLayout(View view, ViewGroup.LayoutParams params) {
final WindowManager.LayoutParams wparams
= (WindowManager.LayoutParams) params;
view.setLayoutParams(wparams);
}
@Override
public void removeView(View view) {
}
};
@Override
public int getSelectionStart() {
try {
if(brokenWindowManager!=null) {
Field ccmf = android.widget.TextView.class.getDeclaredField("mCursorControllerMenu");
ccmf.setAccessible(true);
Object ccm = ccmf.get(this);
{
Field pwf = ccm.getClass().getDeclaredField("mPopupWindow");
pwf.setAccessible(true);
PopupWindow pw = (PopupWindow) pwf.get(ccm);
Field wmf = pw.getClass().getDeclaredField("mWindowManager");
wmf.setAccessible(true);
wmf.set(pw, brokenWindowManager);
}
{
Field pwf = ccm.getClass().getDeclaredField("mPopupWindowArrowDown");
pwf.setAccessible(true);
PopupWindow pw = (PopupWindow) pwf.get(ccm);
Field wmf = pw.getClass().getDeclaredField("mWindowManager");
wmf.setAccessible(true);
wmf.set(pw, brokenWindowManager);
}
{
Field pwf = ccm.getClass().getDeclaredField("mPopupWindowArrowUp");
pwf.setAccessible(true);
PopupWindow pw = (PopupWindow) pwf.get(ccm);
Field wmf = pw.getClass().getDeclaredField("mWindowManager");
wmf.setAccessible(true);
wmf.set(pw, brokenWindowManager);
}
brokenWindowManager = null;
}
} catch (Exception e) {
}
return super.getSelectionStart();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment