Example usage for android.app Activity getSystemService

List of usage examples for android.app Activity getSystemService

Introduction

In this page you can find the example usage for android.app Activity getSystemService.

Prototype

@Override
    public Object getSystemService(@ServiceName @NonNull String name) 

Source Link

Usage

From source file:Main.java

public static void hideSoftInput(Activity activity) {
    View view = activity.getCurrentFocus();
    if (view == null)
        view = new View(activity);
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

From source file:Main.java

public static void closeKeyboard(Activity activity) {
    View view = activity.getWindow().peekDecorView();
    if (view != null) {
        InputMethodManager inputMethodManager = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }/*from  www .j  a va2  s .  c  o m*/
}

From source file:Main.java

public static void hideKeyboard(Activity activity) {
    if (activity == null || activity.getCurrentFocus() == null) {
        return;/*from  w  w w.j av a  2 s .c  om*/
    }

    InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Activity.INPUT_METHOD_SERVICE);
    if (inputMethodManager != null) {
        inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
    }
}

From source file:Main.java

public static void hideKeyboard(Activity activity) {
    // hide keyboard if it's open
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }/* w  w  w  .j  a  v  a 2  s .  c o m*/
}

From source file:com.mobivery.greent.MVYBatteryManagerActivityFragment.java

public static boolean isApplicationBroughtToBackground(final Activity activity) {
    ActivityManager activityManager = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> tasks = activityManager.getRunningTasks(1);

    // Check the top Activity against the list of Activities contained in the Application's package.
    if (!tasks.isEmpty()) {
        ComponentName topActivity = tasks.get(0).topActivity;
        try {//from w  ww.j ava2s  . c o  m
            PackageInfo pi = activity.getPackageManager().getPackageInfo(activity.getPackageName(),
                    PackageManager.GET_ACTIVITIES);
            for (ActivityInfo activityInfo : pi.activities) {
                if (topActivity.getClassName().equals(activityInfo.name))
                    return false;
            }
        } catch (PackageManager.NameNotFoundException e) {
            return false; // Never happens.
        }
    }
    return true;
}

From source file:com.musevisions.android.SudokuSolver.HttpPostUtils.java

static public boolean isConnected(Activity parent) {
    ConnectivityManager cm = (ConnectivityManager) parent.getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return activeNetwork != null && activeNetwork.getState() == NetworkInfo.State.CONNECTED;
}

From source file:Main.java

public static void minimizeKeyboard(Activity activity) {
    // Check if no view has focus:
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager inputManager = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }//from  w w w.ja v a  2s .  co m
}

From source file:Main.java

/**
 * close the SoftInput// www.j a v  a 2 s  .  c  o  m
 * 
 * @param activity
 */
public static void closeSoftInput(Activity activity, EditText mEditText) {
    if (activity == null || mEditText == null) {
        return;
    }

    InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputMethodManager != null && inputMethodManager.isActive()) {
        inputMethodManager.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);

    }
}

From source file:com.hybris.mobile.app.commerce.utils.UIUtils.java

/**
 * Show/Hide the keyboard/*from  w w  w  . j  a  va 2  s  . c  o m*/
 *
 * @param activity
 */
public static void hideKeyboard(Activity activity) {
    if (activity != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(activity.findViewById(android.R.id.content).getWindowToken(), 0);
    }
}

From source file:Main.java

public static void showKeyboard(Activity activity, View view) {
    if (activity != null) {
        if (view != null) {
            view.requestFocus();//  w  ww  .  j ava 2 s.  com
        }
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
        }
    }
}