List of usage examples for android.view.inputmethod InputMethodManager hideSoftInputFromWindow
public boolean hideSoftInputFromWindow(IBinder windowToken, int flags)
From source file:com.kll.collect.android.activities.FormEntryActivity.java
/** * Displays the View specified by the parameter 'next', animating both the * current view and next appropriately given the AnimationType. Also updates * the progress bar./*from w w w. j a v a 2 s . c o m*/ */ public void showView(View next, AnimationType from) { // disable notifications... if (mInAnimation != null) { mInAnimation.setAnimationListener(null); } if (mOutAnimation != null) { mOutAnimation.setAnimationListener(null); } // logging of the view being shown is already done, as this was handled // by createView() switch (from) { case RIGHT: mInAnimation = AnimationUtils.loadAnimation(this, R.anim.push_left_in); mOutAnimation = AnimationUtils.loadAnimation(this, R.anim.push_left_out); break; case LEFT: mInAnimation = AnimationUtils.loadAnimation(this, R.anim.push_right_in); mOutAnimation = AnimationUtils.loadAnimation(this, R.anim.push_right_out); break; case FADE: mInAnimation = AnimationUtils.loadAnimation(this, R.anim.fade_in); mOutAnimation = AnimationUtils.loadAnimation(this, R.anim.fade_out); break; } // complete setup for animations... mInAnimation.setAnimationListener(this); mOutAnimation.setAnimationListener(this); // drop keyboard before transition... if (mCurrentView != null) { InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(mCurrentView.getWindowToken(), 0); } RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); // adjust which view is in the layout container... mStaleView = mCurrentView; mCurrentView = next; mQuestionHolder.addView(mCurrentView, lp); mAnimationCompletionSet = 0; if (mStaleView != null) { // start OutAnimation for transition... mStaleView.startAnimation(mOutAnimation); // and remove the old view (MUST occur after start of animation!!!) mQuestionHolder.removeView(mStaleView); } else { mAnimationCompletionSet = 2; } // start InAnimation for transition... mCurrentView.startAnimation(mInAnimation); String logString = ""; switch (from) { case RIGHT: logString = "next"; break; case LEFT: logString = "previous"; break; case FADE: logString = "refresh"; break; } Collect.getInstance().getActivityLogger().logInstanceAction(this, "showView", logString); }
From source file:com.aliyun.homeshell.Folder.java
public void hideSoftInputMethod(Activity activity) { View v;// w ww .j ava2 s .c om if (activity == null || activity.getWindow() == null) { v = mFolderName; } else { v = activity.getWindow().peekDecorView(); } // YUNOS END try { if (v != null && v.getWindowToken() != null) { InputMethodManager imm = (InputMethodManager) getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); boolean result = imm.hideSoftInputFromWindow(v.getWindowToken(), 0); Log.d(TAG, "hideSoftInputMethod, ret:" + result); } } catch (RuntimeException e) { // add try catch block due to InputMethod throws // RuntimeException; // BugID:101639 Log.e(TAG, e.toString(), e); } }
From source file:com.android.leanlauncher.LauncherTransitionable.java
@Override protected void onNewIntent(Intent intent) { long startTime = 0; if (DEBUG_RESUME_TIME) { startTime = System.currentTimeMillis(); }/*from www.j a v a2s .c o m*/ super.onNewIntent(intent); // Close the menu if (Intent.ACTION_MAIN.equals(intent.getAction())) { // also will cancel mWaitingForResult. closeSystemDialogs(); final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); if (mWorkspace == null) { // Can be cases where mWorkspace is null, this prevents a NPE return; } // In all these cases, only animate if we're already on home mWorkspace.exitWidgetResizeMode(); mWorkspace.requestFocus(); exitSpringLoadedDragMode(); // If we are already on home, then just animate back to the workspace, // otherwise, just wait until onResume to set the state back to Workspace if (alreadyOnHome) { showWorkspace(true); } else { mOnResumeState = State.WORKSPACE; } final View v = getWindow().peekDecorView(); if (v != null && v.getWindowToken() != null) { InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0); } // Reset the apps customize page if (!alreadyOnHome && mAppsCustomizeTabHost != null) { mAppsCustomizeTabHost.reset(); } } if (DEBUG_RESUME_TIME) { Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime)); } }
From source file:com.amaze.carbonfilemanager.activities.MainActivity.java
/** * hide search view with a circular reveal animation *///from w w w.ja v a 2 s . c om public void hideSearchView() { final int END_RADIUS = 16; int startRadius = Math.max(searchViewLayout.getWidth(), searchViewLayout.getHeight()); Animator animator; if (SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { animator = ViewAnimationUtils.createCircularReveal(searchViewLayout, searchCoords[0] + 32, searchCoords[1] - 16, startRadius, END_RADIUS); } else { // TODO: ViewAnimationUtils.createCircularReveal animator = ObjectAnimator.ofFloat(searchViewLayout, "alpha", 1f, 0f); } // removing background fade view utils.revealShow(fabBgView, false); animator.setInterpolator(new AccelerateDecelerateInterpolator()); animator.setDuration(600); animator.start(); animator.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { searchViewLayout.setVisibility(View.GONE); isSearchViewEnabled = false; InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(searchViewEditText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); }
From source file:com.ichi2.anki2.Reviewer.java
private void displayCardAnswer() { Log.i(AnkiDroidApp.TAG, "displayCardAnswer"); // prevent answering (by e.g. gestures) before card is loaded if (mCurrentCard == null) { return;//from www . j av a2s. c om } sDisplayAnswer = true; setFlipCardAnimation(); String answer = mCurrentCard.getAnswer(mCurrentSimpleInterface); answer = typeAnsAnswerFilter(answer); String displayString = ""; if (mCurrentSimpleInterface) { mCardContent = convertToSimple(answer); if (mCardContent.length() == 0) { SpannableString hint = new SpannableString( getResources().getString(R.string.simple_interface_hint, R.string.card_details_answer)); hint.setSpan(new StyleSpan(Typeface.ITALIC), 0, mCardContent.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); mCardContent = hint; } } else { Sound.stopSounds(); Recorder.stopRecording(); if (mPrefFixArabic) { // reshape answer = ArabicUtilities.reshapeSentence(answer, true); } // If the user wrote an answer if (typeAnswer()) { mAnswerField.setVisibility(View.GONE); if (mCurrentCard != null) { if (mPrefFixArabic) { // reshape mTypeCorrect = ArabicUtilities.reshapeSentence(mTypeCorrect, true); } // Obtain the user answer and the correct answer String userAnswer = mAnswerField.getText().toString(); Matcher matcher = sSpanPattern.matcher(Utils.stripHTMLMedia(mTypeCorrect)); String correctAnswer = matcher.replaceAll(""); matcher = sBrPattern.matcher(correctAnswer); correctAnswer = matcher.replaceAll("\n"); matcher = Sound.sSoundPattern.matcher(correctAnswer); correctAnswer = matcher.replaceAll(""); Log.i(AnkiDroidApp.TAG, "correct answer = " + correctAnswer); // Obtain the diff and send it to updateCard DiffEngine diff = new DiffEngine(); StringBuffer span = new StringBuffer(); span.append("<span style=\"font-family: '").append(mTypeFont).append("'; font-size: ") .append(mTypeSize).append("px\">"); span.append(diff.diff_prettyHtml(diff.diff_main(userAnswer, correctAnswer), mNightMode)); span.append("</span>"); span.append("<br/>").append(answer); displayString = enrichWithQADiv(span.toString(), true); } // Hide soft keyboard InputMethodManager inputMethodManager = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(mAnswerField.getWindowToken(), 0); } else { displayString = enrichWithQADiv(answer, true); } } mIsSelecting = false; updateCard(displayString); showEaseButtons(); // If the user want to show next question automatically if (mPrefUseTimer) { mTimeoutHandler.removeCallbacks(mShowQuestionTask); mTimeoutHandler.postDelayed(mShowQuestionTask, mWaitQuestionSecond * 1000); } }
From source file:com.hichinaschool.flashcards.anki.Reviewer.java
private void displayCardAnswer() { // Log.i(AnkiDroidApp.TAG, "displayCardAnswer"); // prevent answering (by e.g. gestures) before card is loaded if (mCurrentCard == null) { return;//w w w. j a va2s . c om } sDisplayAnswer = true; setFlipCardAnimation(); String answer = mCurrentCard.getAnswer(mCurrentSimpleInterface); answer = typeAnsAnswerFilter(answer); String displayString = ""; if (mCurrentSimpleInterface) { mCardContent = convertToSimple(answer); if (mCardContent.length() == 0) { SpannableString hint = new SpannableString( getResources().getString(R.string.simple_interface_hint, R.string.card_details_answer)); hint.setSpan(new StyleSpan(Typeface.ITALIC), 0, mCardContent.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); mCardContent = hint; } } else { Sound.stopSounds(); if (mPrefFixArabic) { // reshape answer = ArabicUtilities.reshapeSentence(answer, true); } // If the user wrote an answer if (typeAnswer()) { mAnswerField.setVisibility(View.GONE); if (mCurrentCard != null) { if (mPrefFixArabic) { // reshape mTypeCorrect = ArabicUtilities.reshapeSentence(mTypeCorrect, true); } // Obtain the user answer and the correct answer String userAnswer = mAnswerField.getText().toString(); Matcher matcher = sSpanPattern.matcher(Utils.stripHTMLMedia(mTypeCorrect)); String correctAnswer = matcher.replaceAll(""); matcher = sBrPattern.matcher(correctAnswer); correctAnswer = matcher.replaceAll("\n"); matcher = Sound.sSoundPattern.matcher(correctAnswer); correctAnswer = matcher.replaceAll(""); // Log.i(AnkiDroidApp.TAG, "correct answer = " + correctAnswer); // Obtain the diff and send it to updateCard DiffEngine diff = new DiffEngine(); StringBuffer span = new StringBuffer(); span.append("<span style=\"font-family: '").append(mTypeFont).append("'; font-size: ") .append(mTypeSize).append("px\">"); span.append(diff.diff_prettyHtml(diff.diff_main(userAnswer, correctAnswer), mNightMode)); span.append("</span>"); span.append("<br/>").append(answer); displayString = enrichWithQADiv(span.toString(), true); } // Hide soft keyboard InputMethodManager inputMethodManager = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(mAnswerField.getWindowToken(), 0); } else { displayString = enrichWithQADiv(answer, true); } } mIsSelecting = false; updateCard(displayString); showEaseButtons(); // If the user want to show next question automatically if (mPrefUseTimer) { mTimeoutHandler.removeCallbacks(mShowQuestionTask); mTimeoutHandler.postDelayed(mShowQuestionTask, mWaitQuestionSecond * 1000); } }
From source file:com.android.launcher2.Launcher.java
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); // Close the menu if (Intent.ACTION_MAIN.equals(intent.getAction())) { // also will cancel mWaitingForResult. closeSystemDialogs();/*w w w . j a v a2s . c o m*/ final boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); Runnable processIntent = new Runnable() { public void run() { if (mWorkspace == null) { // Can be cases where mWorkspace is null, this prevents a NPE return; } Folder openFolder = mWorkspace.getOpenFolder(); // In all these cases, only animate if we're already on home mWorkspace.exitWidgetResizeMode(); if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() && openFolder == null) { mWorkspace.moveToDefaultScreen(true); } closeFolder(); exitSpringLoadedDragMode(); // If we are already on home, then just animate back to the workspace, // otherwise, just wait until onResume to set the state back to Workspace if (alreadyOnHome) { showWorkspace(true); } else { mOnResumeState = State.WORKSPACE; } final View v = getWindow().peekDecorView(); if (v != null && v.getWindowToken() != null) { InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0); } // Reset AllApps to its initial state if (!alreadyOnHome && mAppsCustomizeTabHost != null) { mAppsCustomizeTabHost.reset(); } } }; if (alreadyOnHome && !mWorkspace.hasWindowFocus()) { // Delay processing of the intent to allow the status bar animation to finish // first in order to avoid janky animations. mWorkspace.postDelayed(processIntent, 350); } else { // Process the intent immediately. processIntent.run(); } } }
From source file:com.nttec.everychan.ui.presentation.BoardFragment.java
private void initSearchBar() { if (searchBarInitialized) return;//w ww . ja v a 2s. co m final EditText field = (EditText) searchBarView.findViewById(R.id.board_search_field); final TextView results = (TextView) searchBarView.findViewById(R.id.board_search_result); if (pageType == TYPE_POSTSLIST) { field.setHint(R.string.search_bar_in_thread_hint); } final View.OnClickListener searchOnClickListener = new View.OnClickListener() { private int lastFound = -1; @Override public void onClick(View v) { if (v != null && v.getId() == R.id.board_search_close) { searchHighlightActive = false; adapter.notifyDataSetChanged(); searchBarView.setVisibility(View.GONE); } else if (listView != null && listView.getChildCount() > 0 && adapter != null && cachedSearchResults != null) { boolean atEnd = listView.getChildAt(listView.getChildCount() - 1).getTop() + listView.getChildAt(listView.getChildCount() - 1).getHeight() == listView.getHeight(); View topView = listView.getChildAt(0); if ((v == null || v.getId() == R.id.board_search_previous) && topView.getTop() < 0 && listView.getChildCount() > 1) topView = listView.getChildAt(1); int currentListPosition = listView.getPositionForView(topView); int newResultIndex = Collections.binarySearch(cachedSearchResults, currentListPosition); if (newResultIndex >= 0) { if (v != null) { if (v.getId() == R.id.board_search_next) ++newResultIndex; else if (v.getId() == R.id.board_search_previous) --newResultIndex; } } else { newResultIndex = -newResultIndex - 1; if (v != null && v.getId() == R.id.board_search_previous) --newResultIndex; } while (newResultIndex < 0) newResultIndex += cachedSearchResults.size(); newResultIndex %= cachedSearchResults.size(); if (v != null && v.getId() == R.id.board_search_next && lastFound == newResultIndex && atEnd) newResultIndex = 0; lastFound = newResultIndex; listView.setSelection(cachedSearchResults.get(newResultIndex)); results.setText((newResultIndex + 1) + "/" + cachedSearchResults.size()); } } }; for (int id : new int[] { R.id.board_search_close, R.id.board_search_previous, R.id.board_search_next }) { searchBarView.findViewById(id).setOnClickListener(searchOnClickListener); } field.setOnKeyListener(new View.OnKeyListener() { private boolean searchUsingChan() { if (pageType != TYPE_THREADSLIST) return false; if (presentationModel != null) if (presentationModel.source != null) if (presentationModel.source.boardModel != null) if (!presentationModel.source.boardModel.searchAllowed) return false; return true; } @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { if (searchUsingChan()) { UrlPageModel model = new UrlPageModel(); model.chanName = chan.getChanName(); model.type = UrlPageModel.TYPE_SEARCHPAGE; model.boardName = tabModel.pageModel.boardName; model.searchRequest = field.getText().toString(); UrlHandler.open(model, activity); } else { int highlightColor = ThemeUtils.getThemeColor(activity.getTheme(), R.attr.searchHighlightBackground, Color.RED); String request = field.getText().toString().toLowerCase(Locale.US); if (cachedSearchRequest == null || !request.equals(cachedSearchRequest)) { cachedSearchRequest = request; cachedSearchResults = new ArrayList<Integer>(); cachedSearchHighlightedSpanables = new SparseArray<Spanned>(); List<PresentationItemModel> safePresentationList = presentationModel .getSafePresentationList(); if (safePresentationList != null) { for (int i = 0; i < safePresentationList.size(); ++i) { PresentationItemModel model = safePresentationList.get(i); if (model.hidden && !staticSettings.showHiddenItems) continue; String comment = model.spannedComment.toString().toLowerCase(Locale.US) .replace('\n', ' '); List<Integer> altFoundPositions = null; if (model.floating) { int floatingpos = FlowTextHelper.getFloatingPosition(model.spannedComment); if (floatingpos != -1 && floatingpos < model.spannedComment.length() && model.spannedComment.charAt(floatingpos) == '\n') { String altcomment = comment.substring(0, floatingpos) + comment.substring(floatingpos + 1, Math.min(model.spannedComment.length(), floatingpos + request.length())); int start = 0; int curpos; while (start < altcomment.length() && (curpos = altcomment.indexOf(request, start)) != -1) { if (altFoundPositions == null) altFoundPositions = new ArrayList<Integer>(); altFoundPositions.add(curpos); start = curpos + request.length(); } } } if (comment.contains(request) || altFoundPositions != null) { cachedSearchResults.add(Integer.valueOf(i)); SpannableStringBuilder spannedHighlited = new SpannableStringBuilder( safePresentationList.get(i).spannedComment); int start = 0; int curpos; while (start < comment.length() && (curpos = comment.indexOf(request, start)) != -1) { start = curpos + request.length(); if (altFoundPositions != null && Collections.binarySearch(altFoundPositions, curpos) >= 0) continue; spannedHighlited.setSpan(new BackgroundColorSpan(highlightColor), curpos, curpos + request.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } if (altFoundPositions != null) { for (Integer pos : altFoundPositions) { spannedHighlited.setSpan(new BackgroundColorSpan(highlightColor), pos, pos + request.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } cachedSearchHighlightedSpanables.put(i, spannedHighlited); } } } } if (cachedSearchResults.size() == 0) { Toast.makeText(activity, R.string.notification_not_found, Toast.LENGTH_LONG).show(); } else { boolean firstTime = !searchHighlightActive; searchHighlightActive = true; adapter.notifyDataSetChanged(); searchBarView.findViewById(R.id.board_search_next).setVisibility(View.VISIBLE); searchBarView.findViewById(R.id.board_search_previous).setVisibility(View.VISIBLE); searchBarView.findViewById(R.id.board_search_result).setVisibility(View.VISIBLE); searchOnClickListener .onClick(firstTime ? null : searchBarView.findViewById(R.id.board_search_next)); } } try { InputMethodManager imm = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(field.getWindowToken(), 0); } catch (Exception e) { Logger.e(TAG, e); } return true; } return false; } }); field.addTextChangedListener(new OnSearchTextChangedListener(this)); field.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); if (resources.getDimensionPixelSize(R.dimen.panel_height) < field.getMeasuredHeight()) searchBarView.getLayoutParams().height = field.getMeasuredHeight(); searchBarInitialized = true; }
From source file:com.lgallardo.qbittorrentclient.RefreshListener.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); // Retrieve the SearchView and plug it into SearchManager final SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search)); SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default // Handle open/close SearchView (using an item menu) final MenuItem menuItem = menu.findItem(R.id.action_search); // When back is pressed or the SearchView is close, delete the query field // and close the SearchView using the item menu searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() { @Override//from ww w.j a va2 s . co m public void onFocusChange(View view, boolean queryTextFocused) { if (!queryTextFocused) { menuItem.collapseActionView(); searchView.setQuery("", false); searchField = ""; refreshSwipeLayout(); refreshCurrent(); } } }); // This must be implemented to override defaul searchview behaviour, in order to // make it work with tablets searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { //Log.d("Debug", "onQueryTextSubmit - searchField: " + query); // false: don't actually send the query. We are going to do something different searchView.setQuery(query, false); // Set the variable we use in the intent to perform the search searchField = query; // Refresh using the search field refreshSwipeLayout(); refreshCurrent(); // Close the soft keyboard InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(menuItem.getActionView().getWindowToken(), 0); // Here true means, override default searchview query return true; } @Override public boolean onQueryTextChange(String newText) { return false; } }); // There is a bug setting the hint from searchable.xml, so force it searchView.setQueryHint(getResources().getString(R.string.search_hint)); return true; }