/** * Define what version of code we need to use */ private void editTextVersion() { if (android.os.Build.VERSION.SDK_INT < 14) { setOldDeviceKeyboard(true); setOldDeviceTextAllCaps(true); } else { setOldDeviceKeyboard(true); setOldDeviceTextAllCaps(false); } //Custom internal listener setListenerTextWatcherInternal(new CustomTextWatcher(this)); addTextChangedListener(getListenerTextWatcherInternal()); //System service mImm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); //Autofocus disabled by default mAutoFocus = false; mCustomPassWordTransformation = false; }
/** * Force hide keyboard */ public void hideKeyboard() { this.clearFocus(); Context context = getContext(); if (Activity.class.isInstance(context)) { ((Activity) context).getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); } //mImm.hideSoftInputFromWindow(this.getWindowToken(), 0); //mImm.toggleSoftInput(0, 0); }
public AutoCompleteEditText(Context context, AttributeSet attrs) { super(context, attrs); editTextVersion(); setDisableCopyAndPaste(context, attrs); setCancelClipboard(context, attrs); setAutoFocus(context, attrs); if (isOldDeviceTextAllCaps()) { setAllCaps(context, attrs); } }
/** * Force show keyboard */ public void showKeyboard() { this.requestFocus(); Context context = getContext(); if (Activity.class.isInstance(context)) { ((Activity) context).getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } //mImm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT | InputMethodManager.SHOW_FORCED); //mImm.toggleSoftInput(0, 0); // Trick used to create a fake touch event on the editText MotionEvent event = MotionEvent.obtain(0, SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN | MotionEvent.ACTION_UP, this.getMeasuredWidth(), 0, 0); this.onTouchEvent(event); event.recycle(); }
/** * Use this method to uppercase all char in text. * * @param allCaps */ @SuppressLint("NewApi") @Override public void setAllCaps(boolean allCaps) { //FIXME: if user input new char, it's generate a crash on Paint methods if (this.isOldDeviceTextAllCaps()) { if (allCaps) { setTransformationMethod(new AllCapsTransformationMethod( getContext())); } else { setTransformationMethod(null); } } else { super.setAllCaps(allCaps); } }
/** * Return if cellphone use a old samsung keyboard * * @return */ public boolean isAOldSamsungKeyboard() { if (getKeyboardName().equals(EDITTEXT_KEYBOARD_OLD_SAMSUNG)) { return true; } else { return false; } }
/** * XML methods * * @param ctx * @param attrs */ private void setDisableCopyAndPaste(Context ctx, AttributeSet attrs) { boolean disableCopyAndPaste = attrs.getAttributeBooleanValue( PixlUIContants.SCHEMA_URL, EDITTEXT_ATTRIBUTE_COPY_AND_PASTE, true); if (!disableCopyAndPaste && !isInEditMode()) { disableCopyAndPaste(); } }
/** * XML methods * * @param ctx * @param attrs */ private void setCancelClipboard(Context ctx, AttributeSet attrs) { boolean cancelClipboard = attrs.getAttributeBooleanValue( PixlUIContants.SCHEMA_URL, EDITTEXT_ATTRIBUTE_CANCEL_CLIPBOARD_CONTENT, false); if (cancelClipboard && !isInEditMode()) { cancelClipBoardContent(); } }
/** * Used to intercept the focus */ @Override protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { AutoCompleteEditTextFocusListener listener = getFocusListener(); if (listener != null) { if (focused) { listener.requestFocus(this); } else { listener.loseFocus(this); } } super.onFocusChanged(focused, direction, previouslyFocusedRect); if (mAutoFocus) { if (focused) { mImm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT | InputMethodManager.SHOW_FORCED); } else { mImm.hideSoftInputFromWindow(this.getWindowToken(), 0); } mImm.toggleSoftInput(0, 0); } }
/** * Get keyboard name (usefull to know if user used a custom keyboard, like * HackerKeyboard or SenseKeyboard or...) * * @return keyboard name + package */ private String getKeyboardName() { return Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); }
public AutoCompleteEditText(Context context) { super(context); editTextVersion(); }
/** * Return if cellphone use a lg keyboard * * @return */ public boolean isALGKeyboard() { if (getKeyboardName().equals(EDITTEXT_KEYBOARD_LG)) { return true; } else { return false; } }
/** * Test if user use a custom keyboard * * @return */ public boolean isUsingCustomInputMethod() { InputMethodManager imm = (InputMethodManager) getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); List<InputMethodInfo> mInputMethodProperties = imm .getEnabledInputMethodList(); final int N = mInputMethodProperties.size(); for (int i = 0; i < N; i++) { InputMethodInfo imi = mInputMethodProperties.get(i); if (imi.getId().equals( Settings.Secure.getString( getContext().getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD))) { if ((imi.getServiceInfo().applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { return true; } } } return false; }
public AutoCompleteEditText(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); editTextVersion(); setDisableCopyAndPaste(context, attrs); setCancelClipboard(context, attrs); setAutoFocus(context, attrs); if (isOldDeviceTextAllCaps()) { setAllCaps(context, attrs); } PixlUIfaceManager.applyFont(this, attrs, defStyle, context); }
/** * Return if cellphone use a Swype + Dragon * * @return */ public boolean isASwypeDragonKeyboard() { if (getKeyboardName().equals(EDITTEXT_KEYBOARD_SWYPE_DRAGON)) { return true; } else { return false; } }
@SuppressWarnings("deprecation") @SuppressLint("NewApi") /* * Cancel clipboard content */ public void cancelClipBoardContent() { if (android.os.Build.VERSION.SDK_INT < 11) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getContext() .getSystemService(Context.CLIPBOARD_SERVICE); if (clipboard != null) { clipboard.setText(""); } } else { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getContext() .getSystemService(Context.CLIPBOARD_SERVICE); if (clipboard != null && clipboard.getPrimaryClip() != null && clipboard.getPrimaryClip().getItemCount() > 0) { android.content.ClipData clip = android.content.ClipData .newPlainText("", ""); clipboard.setPrimaryClip(clip); } } }
/** * Return if cellphone use a samsung keyboard * * @return */ public boolean isASamsungKeyboard() { if (getKeyboardName().equals(EDITTEXT_KEYBOARD_SAMSUNG)) { return true; } else { return false; } }
/** * Return if cellphone use a SwiftKey * * @return */ public boolean isASwiftKeyKeyboard() { if (getKeyboardName().equals(EDITTEXT_KEYBOARD_SWIFTKEY)) { return true; } else { return false; } }
/** * Return if cellphone use a sense keyboard (HTC) * * @return */ public boolean isASenseKeyboard() { if (getKeyboardName().equals(EDITTEXT_KEYBOARD_SENSE)) { return true; } else { return false; } }
/** * Return if cellphone use a SwiftKeyTrial * * @return */ public boolean isASwiftKeyTrialKeyboard() { if (getKeyboardName().equals(EDITTEXT_KEYBOARD_SWIFTKEY_TRIAL)) { return true; } else { return false; } }