List of usage examples for android.view View getWindowToken
public IBinder getWindowToken()
From source file:kr.wdream.storyshop.AndroidUtilities.java
public static void hideKeyboard(View view) { if (view == null) { return;//from www . j a v a 2 s .co m } try { InputMethodManager imm = (InputMethodManager) view.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); if (!imm.isActive()) { return; } imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:com.concavenp.artistrymuse.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // If the application has not run before then initialize the preference settings with default values if (savedInstanceState == null) { // These are the "general" preferences (its all this app has) PreferenceManager.setDefaultValues(this, R.xml.pref_general, false); }/*from w ww. j a va 2s . c om*/ // Force the scroll view to fill the area, dunno why this is not the default. NestedScrollView scrollView = findViewById(R.id.nest_scrollview); scrollView.setFillViewport(true); // Get the ViewPager and set it's PagerAdapter so that it can display items ViewPager viewPager = findViewById(R.id.viewpager); mFragmentAdapter = new ArtistryFragmentPagerAdapter(this, getSupportFragmentManager()); viewPager.setAdapter(mFragmentAdapter); viewPager.setOffscreenPageLimit(mFragmentAdapter.getCount()); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { // Do nothing } @Override public void onPageSelected(int position) { // Save off the tab position tabPosition = position; // Perform animations (if needed) animateFab(position); // Close the keyboard if it is open View view = getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } } @Override public void onPageScrollStateChanged(int state) { // Do nothing } }); // Give the TabLayout the ViewPager tabLayout = findViewById(R.id.tabs); tabLayout.setupWithViewPager(viewPager); tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { animateFab(tab.getPosition()); } @Override public void onTabUnselected(TabLayout.Tab tab) { // Do nothing } @Override public void onTabReselected(TabLayout.Tab tab) { // Do nothing } }); // Setup the support for creating a menu (ActionBar functionality) Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Setup the FAB for creating a new user project (only visible in the gallery tab) fabCreateProject = findViewById(R.id.fabCreateProject); fabCreateProject.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Notify 'this' of the Create New Project selection onInteractionSelection(null, null, StorageDataType.PROJECTS, UserInteractionType.EDIT); } }); // Logon button Button loginButton = findViewById(R.id.login_button); loginButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { onLoginInteraction(); } }); // Default will be hidden fabCreateProject.hide(); // Save off the flipper for use in deciding which view to show mFlipper = findViewById(R.id.activity_main_ViewFlipper); // Set the flip view accordingly checkLoginFlipState(); // Start the sign-in activity if nobody is logged in yet if (getUid().isEmpty()) { onLoginInteraction(); } }
From source file:com.rong.library.widget.mapsearchbar.MapSearchBar.java
@Override public void onFocusChange(View v, boolean hasFocus) { InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (hasFocus) { if (!focusCameFromHistory) imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT); focusCameFromHistory = false;//w w w . j a v a 2 s . c o m isSearchEditFocused = true; if (adapter.getItemCount() > 0 && !suggestionsVisible) animateSuggestionList(0, getSuggestionHeight()); } else { imm.hideSoftInputFromWindow(v.getWindowToken(), 0); isSearchEditFocused = false; if (suggestionsVisible) animateSuggestionList(-1, 0); } }
From source file:org.openmrs.mobile.activities.addeditpatient.AddEditPatientFragment.java
@Override public void hideSoftKeys() { View view = this.getActivity().getCurrentFocus(); if (view == null) { view = new View(this.getActivity()); }/* w w w . j a v a 2 s. c o m*/ InputMethodManager inputMethodManager = (InputMethodManager) this.getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); }
From source file:co.taqat.call.assistant.AssistantActivity.java
public void hideKeyboard() { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); View view = this.getCurrentFocus(); if (imm != null && view != null) { imm.hideSoftInputFromWindow(view.getWindowToken(), 0); }/*from w w w . j a va 2s. c om*/ }
From source file:org.cvasilak.jboss.mobile.app.fragments.util.ListEditorFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.add) { // add an empty row adapter.add(new RowModel("")); return true; } else if (item.getItemId() == R.id.done) { RowAdapter adapter = (RowAdapter) getListAdapter(); View v = getActivity().getCurrentFocus(); // handle the case where an editext has focus // and user clicks 'Save'. // update local model and hide the soft keyboard if (v != null && (v instanceof EditText)) { EditText text = (EditText) v; RowModel model = adapter.getItem((Integer) text.getTag()); model.value = ((EditText) v).getText().toString(); // hide the keyboard now InputMethodManager inputMethodManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0); }/*from w w w .jav a2 s . c om*/ // quickly scan for unedited textboxes // if so exit for (int i = 0; i < adapter.getCount(); i++) { if (adapter.getItem(i).value.equals("")) { ErrorDialogFragment errorDialog = ErrorDialogFragment .newInstance(getString(R.string.unedited_field)); errorDialog.show(getActivity().getSupportFragmentManager(), ErrorDialogFragment.TAG); return false; } } if (listener != null) { ArrayList<String> list = new ArrayList<String>(); for (int i = 0; i < adapter.getCount(); i++) { list.add(adapter.getItem(i).value); } // inform our listener for the list listener.onListEditorFinished(list); // close listeditor screen by simulating back button pressed. // this will allow the root activity to remove the fragment // from the back stack getActivity().onBackPressed(); } } return (super.onOptionsItemSelected(item)); }
From source file:com.silentcircle.accounts.AccountStep3.java
@Override public void onClick(View view) { switch (view.getId()) { case R.id.back: { InputMethodManager imm = (InputMethodManager) mParent.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); mParent.backStep();//from ww w . jav a2 s .co m break; } case R.id.create: { createAccount(); break; } case R.id.license_next: { if (mLicenseErrorCode == 1) { mParent.provisioningCancel(); return; } if (mLicenseErrorCode == 2) { // feature (Ronin) code in use, ask for existing account info mParent.clearBackStack(); mParent.accountStep2(); } break; } default: { Log.wtf(TAG, "Unexpected onClick() event from: " + view); break; } } }
From source file:re.serialout.MainScreen.java
public void setID(View view) { //Store pateient information/Keep someone logged in. InputMethodManager inputMethodManager = (InputMethodManager) getSystemService( Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); EditText editText = (EditText) findViewById(R.id.id_text); // LinearLayout linearLayout = (LinearLayout) findViewById(R.id.id_layout); // TextView textView = (TextView) findViewById(R.id.mainText); idText = editText.getText().toString(); if (idText.length() < 1) { return;/*from w w w. j av a 2s . c o m*/ } // textView.setText("Hello, "+idText+"!\nPlease plug in your sensor or take a survey."); System.out.println(idText); settings = dbhelper.getSettings(Integer.parseInt(idText)); hideIDViews(); idSet = true; // linearLayout.setVisibility(View.GONE); if (settings.isSurveyReady()) { (findViewById(R.id.startSurvey)).setVisibility(View.VISIBLE); } if (settings.isFirstTime() || clincMode) { Intent intent = new Intent(this, DemographicActivity.class); intent.putExtra("patientID", idText); startActivity(intent); } Log.i("TAGGERINO", dbhelper.getDemographics(Integer.parseInt(idText)).toString()); if (true || !clincMode) { SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putBoolean("idSet", idSet); editor.putString("idText", idText); editor.commit(); } }
From source file:com.ferdi2005.secondgram.AndroidUtilities.java
public static void hideKeyboard(View view) { if (view == null) { return;// ww w .java2 s . c o m } try { InputMethodManager imm = (InputMethodManager) view.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); if (!imm.isActive()) { return; } imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } catch (Exception e) { FileLog.e(e); } }
From source file:nl.jalava.appostle.AppListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.app_list, container, false); appList = (ListView) view.findViewById(R.id.listView1); progress = (ProgressBar) view.findViewById(R.id.progressBar); progress_loading = (TextView) view.findViewById(R.id.progress_loading); progress.bringToFront();/*from w w w.ja va 2 s.c o m*/ progress_loading.bringToFront(); mContext = view.getContext(); // Make list clickable and fast scrollable. appList.setClickable(true); appList.setFastScrollEnabled(true); // OnClick appList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { AppInfo o = (AppInfo) appList.getItemAtPosition(position); listener.onAppSelected(o); } }); // Swipe to refresh. mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_apps); mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { new UpdateAppList().execute(); } }); mSearchEdit = (RelativeLayout) view.findViewById(R.id.search_layout); // Restore the last visibility state of the text edit. if (mSearchEditOpen) mSearchEdit.setVisibility(View.VISIBLE); else mSearchEdit.setVisibility(View.GONE); mSearchText = (EditText) view.findViewById(R.id.search_app_edit); // Restore text and cursor position. mSearchText.setText(mSearchEditText); mSearchText.setSelection(mSearchEditTextPosition); mSearchText.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { if (mAppInfoAdapter != null) mAppInfoAdapter.getFilter().filter(s); mSearchEditText = s.toString(); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); // Activate keyboard if search text edit is opened. // Close if no focus. mSearchText.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { // Open keyboard ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .showSoftInput(v, InputMethodManager.SHOW_FORCED); } else { // Close keyboard. ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(v.getWindowToken(), 0); } } }); // Clear text button. Button clear = (Button) view.findViewById(R.id.search_clear_button); clear.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mSearchText.setText(""); } }); // Close search. Button close = (Button) view.findViewById(R.id.search_close_button); close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mSearchEdit.setVisibility(View.GONE); mSearchEditOpen = false; } }); // Prevent always refreshing when pulling listview down. appList.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (firstVisibleItem == 0) { mSwipeRefreshLayout.setEnabled(true); } else mSwipeRefreshLayout.setEnabled(false); } }); pm = mContext.getPackageManager(); doUpdate(-1); return view; }