/** * 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); }
/** * 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); }
/** * 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; }
@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); } } }
/** * 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); } }
/** * 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; }