package ch.pizzalemon.android.helper;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import ch.pizzalemon.android.activity.BaseActivity;

/**
 * Created by cimenmus on 25/06/2017.
 */

public class ViewHelper {

    public static void toogleKeyboard() {
        InputMethodManager imm = (InputMethodManager) BaseActivity.currentActivity.getSystemService(Activity.INPUT_METHOD_SERVICE);
        if (imm.isActive()) {
            imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); // hide
        } else {
            imm.toggleSoftInput(0, InputMethodManager.HIDE_IMPLICIT_ONLY); // show
        }
    }

    public static void hideKeyboard() {
        View view = BaseActivity.currentActivity.getCurrentFocus();
        if (view != null) {
            InputMethodManager imm = (InputMethodManager) BaseActivity.currentActivity.
                    getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }

    public static void showKeyboard() {
        InputMethodManager imm = (InputMethodManager) BaseActivity.currentActivity.getSystemService(Activity.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(0, InputMethodManager.HIDE_IMPLICIT_ONLY); // show
    }
}
