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 hideSoftKeyBoard(Activity activity) {
    final View v = activity.getWindow().peekDecorView();
    if (v != null && v.getWindowToken() != null) {
        try {/*from  www .  j  ava2 s  .c  o  m*/
            ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE))
                    .hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:Main.java

public static void hideSoftInputView(Activity activity) {
    if (activity.getWindow()
            .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
        InputMethodManager manager = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        View currentFocus = activity.getCurrentFocus();
        if (currentFocus != null) {
            manager.hideSoftInputFromWindow(currentFocus.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }//from w w  w  .  j ava  2s  .  c  o m
    }
}

From source file:Main.java

public static boolean hasDefaultSensor(Activity activity, int type) {
    boolean oneShot = false;
    boolean result = false;

    if (sensorManager == null) {
        oneShot = true;/*from  w ww  .jav a 2s . c  o  m*/
        sensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE);
    }
    if (sensorManager != null) {
        result = (sensorManager.getDefaultSensor(type) != null);
        if (oneShot) {
            sensorManager = null;
        }
    }

    return result;
}

From source file:Main.java

/**
 * <pre>/*  w  ww  . j  a va2 s  .  co  m*/
 * Hide keyboard.
 * </pre>
 */
public static void hideKeyboard() {
    Activity activity = (Activity) getCurrentContext();
    View currentFocusedView = activity.getCurrentFocus();
    if (currentFocusedView != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(currentFocusedView.getWindowToken(), 0);
    }
}

From source file:com.photon.phresco.nativeapp.eshop.net.NetworkManager.java

public static boolean checkNetworkConnectivity(final Activity activity) {
    ConnectivityManager cm = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
        return true;
    } else if (netInfo != null && (netInfo.getState() == NetworkInfo.State.DISCONNECTED
            || netInfo.getState() == NetworkInfo.State.DISCONNECTING
            || netInfo.getState() == NetworkInfo.State.SUSPENDED
            || netInfo.getState() == NetworkInfo.State.UNKNOWN)) {
        return false;
    } else {/*  w  ww  .j a v  a2  s .c  o  m*/
        return false;
    }
}

From source file:com.justplay1.shoppist.utils.ViewUtils.java

public static void closeSoftKeyboard(Activity activity) {
    View currentFocusView = activity.getCurrentFocus();
    if (currentFocusView != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(currentFocusView.getWindowToken(), 0);
    }//  w  w w .j a  va2  s  .  co m
}

From source file:Main.java

/**
 * Utility method to check Internet connection availability
 * /*from w ww .  j  a  v a  2  s . c o  m*/
 * @return boolean value indicating the presence of Internet connection
 *         availability
 */
public static boolean isNetworkAvailable(Activity argActivity) {
    if (argActivity == null) {
        return false;
    }

    ConnectivityManager connectivityManager;
    NetworkInfo activeNetworkInfo = null;
    try {
        connectivityManager = (ConnectivityManager) argActivity.getSystemService(Context.CONNECTIVITY_SERVICE);
        activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
    return activeNetworkInfo != null;
}

From source file:com.activiti.android.ui.utils.UIUtils.java

public static void showKeyboard(Activity activity, View v) {
    InputMethodManager mgr = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    mgr.showSoftInput(v, 0);//from   ww w .jav  a 2 s .  co m
}

From source file:com.activiti.android.ui.utils.UIUtils.java

public static void hideKeyboard(Activity activity, View v) {
    InputMethodManager mgr = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    mgr.hideSoftInputFromWindow(v.getWindowToken(), 0);
}

From source file:Main.java

public static void hideSoftInput(Activity activity) {
    View currentFocus = activity.getCurrentFocus();
    if (currentFocus != null) {
        IBinder windowToken = currentFocus.getWindowToken();
        if (windowToken != null) {
            InputMethodManager manager = (InputMethodManager) (activity
                    .getSystemService(Context.INPUT_METHOD_SERVICE));
            if (manager != null) {
                manager.hideSoftInputFromWindow(windowToken, InputMethodManager.HIDE_NOT_ALWAYS);
            }//from  w  w  w  . j av  a2  s  .  c  o  m
        }
    }
}