Android Open Source - RoommateManager Keyboard Handler






From Project

Back to project page RoommateManager.

License

The source code is released under:

MIT License

If you think the Android project RoommateManager listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package edu.iupui.gdvander.roommatemanager.handler;
/*  w  w w  .  j a va  2s  .  c  om*/
/**
 * Created by Gerrit VanderLugt
 * Title: KeyboardHandler.java
 * Purpose: Hide the keyboard when the view behind the keyboard is pressed. Create an instance
 *   of this class and pass the view using the keyboard in the constructor to implement.
 */

import android.content.Context;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.RelativeLayout;

public class KeyboardHandler {

    private Context context;

    public KeyboardHandler(RelativeLayout layout, Context applicationContext){
        //Set the context
        context = applicationContext;

        //Essentially, turn the view behind the keyboard into a button by giving it an
        //onTouchListener.
        layout.setOnTouchListener(new View.OnTouchListener(){
            @Override
            public boolean onTouch(View view, MotionEvent ev){
                //Hide the keyboard on button press.
                hideKeyboard(view);
                return false;
            }
        });
    }

    private void hideKeyboard(View view){
        //Hide the keyboard
        InputMethodManager in = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        in.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
}




Java Source Code List

edu.iupui.gdvander.roommatemanager.app.LoginActivity.java
edu.iupui.gdvander.roommatemanager.app.MainActivity.java
edu.iupui.gdvander.roommatemanager.app.NavigationDrawerFragment.java
edu.iupui.gdvander.roommatemanager.app.RegisterActivity.java
edu.iupui.gdvander.roommatemanager.app.SplashActivity.java
edu.iupui.gdvander.roommatemanager.app.VolleySingleton.java
edu.iupui.gdvander.roommatemanager.app.finances.FinancesFragment.java
edu.iupui.gdvander.roommatemanager.app.finances.FinancesPagerAdapter.java
edu.iupui.gdvander.roommatemanager.app.finances.tabs.DebtsTab.java
edu.iupui.gdvander.roommatemanager.app.finances.tabs.ExpensesTab.java
edu.iupui.gdvander.roommatemanager.app.finances.tabs.PersonalTransactionTab.java
edu.iupui.gdvander.roommatemanager.app.finances.tabs.SharedTransactionTab.java
edu.iupui.gdvander.roommatemanager.app.finances.tabs.TransferTab.java
edu.iupui.gdvander.roommatemanager.app.groceries.GroceriesFragment.java
edu.iupui.gdvander.roommatemanager.app.groceries.GroceryArrayAdapter.java
edu.iupui.gdvander.roommatemanager.app.groceries.GroceryItemDialog.java
edu.iupui.gdvander.roommatemanager.app.groceries.GroceryItem.java
edu.iupui.gdvander.roommatemanager.app.home.HomeFragment.java
edu.iupui.gdvander.roommatemanager.app.home.HomePagerAdapter.java
edu.iupui.gdvander.roommatemanager.app.home.tabs.DetailsTab.java
edu.iupui.gdvander.roommatemanager.app.home.tabs.HomeTab.java
edu.iupui.gdvander.roommatemanager.app.todo.ToDoFragment.java
edu.iupui.gdvander.roommatemanager.app.todo.ToDoPagerAdapter.java
edu.iupui.gdvander.roommatemanager.app.todo.tabs.MyToDoTab.java
edu.iupui.gdvander.roommatemanager.app.todo.tabs.SharedToDoTab.java
edu.iupui.gdvander.roommatemanager.handler.JsonObjectRequestHandler.java
edu.iupui.gdvander.roommatemanager.handler.KeyboardHandler.java