List of usage examples for android.app Activity getSystemService
@Override
public Object getSystemService(@ServiceName @NonNull String name)
From source file:Main.java
/** * Enable bluetooth and get the adapter object * @return A BluetoothAdapter instance/*from ww w .j av a 2 s.co m*/ */ public static BluetoothAdapter getLeAdapter(Activity _this) { // Initializes Bluetooth adapter. final BluetoothManager bluetoothLeManager = (BluetoothManager) _this .getSystemService(Context.BLUETOOTH_SERVICE); final BluetoothAdapter bluetoothLeAdapter = bluetoothLeManager.getAdapter(); // Ensures Bluetooth is available on the device and it is enabled. If not, // displays a dialog requesting user permission to mEnableCharacteristic Bluetooth. // TODO / FIXME currently this bugs if the user doesn't have BT enabled, // TODO / FIXME since it just returns null and doesn't check the result later. if (bluetoothLeAdapter == null || !bluetoothLeAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); _this.startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); return null; } else { return bluetoothLeAdapter; } }
From source file:Main.java
public static void closeSoftPan(Activity act) { View view = act.getWindow().peekDecorView(); if (view != null) { InputMethodManager inputmanger = (InputMethodManager) act .getSystemService(Activity.INPUT_METHOD_SERVICE); inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0); }/*from www . j a v a 2 s . co m*/ }
From source file:Main.java
public static void show(Activity activity, EditText editText) { editText.requestFocus();//from ww w . j a v a 2 s . c o m editText.requestFocusFromTouch(); InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); }
From source file:Main.java
/** * Request to hide the soft input window from the context of the window that * is currently accepting input./* ww w. ja va2 s . c om*/ * * @param activity * The currently activity, which shows the view receives soft * keyboard input */ public static void showKeyboard(Activity activity) { if (null == activity) { return; } InputMethodManager im = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); View v = activity.getCurrentFocus(); if (v != null) { im.showSoftInput(v, InputMethodManager.RESULT_UNCHANGED_SHOWN); } }
From source file:Main.java
/** * Hides the keyboard/*from w ww. j a v a 2s . c om*/ * @param activity The activity currently active */ public static void hideKeyboardFromActivity(Activity activity) { View v = activity.getCurrentFocus(); if (v != null) { InputMethodManager inputManager = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } }
From source file:Main.java
/** * Request to hide the soft input window from the context of the window that * is currently accepting input./* www .ja va2 s . co m*/ * * @param activity * The currently activity, which shows the view receives soft * keyboard input. */ public static void hideKeyboard(Activity activity) { if (null == activity) { return; } InputMethodManager im = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); View v = activity.getCurrentFocus(); if (v != null) { im.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } }
From source file:Main.java
/** * Helper to hide the keyboard/*from w w w. j a va 2 s.c o m*/ * * @param act */ public static void hideKeyboard(Activity act) { if (act != null && act.getCurrentFocus() != null) { InputMethodManager inputMethodManager = (InputMethodManager) act .getSystemService(Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(act.getCurrentFocus().getWindowToken(), 0); } }
From source file:Main.java
public static void KeyBoardCancle(Activity act) { View view = act.getWindow().peekDecorView(); if (view != null) { InputMethodManager inputmanger = (InputMethodManager) act .getSystemService(Activity.INPUT_METHOD_SERVICE); inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0); }// ww w.ja va2 s . co m }
From source file:Main.java
/** * hide soft keyboard// w ww .j a v a 2 s. com * @param activity */ public static void hideSoftKeyboard(Activity activity) { if (null == activity) { return; } InputMethodManager inputMethodManager = (InputMethodManager) activity .getSystemService(Activity.INPUT_METHOD_SERVICE); if (null != inputMethodManager) { View view = activity.getCurrentFocus(); if (null != view) { inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); } } }
From source file:Main.java
public static boolean isSoftInputActive(Activity activity, EditText mEditText) { if (activity == null) { return false; }/*from w w w. jav a2s . co m*/ InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); // imm.showSoftInput(mEditText, InputMethodManager.SHOW_FORCED); if (imm != null) { return imm.isActive(); } return false; }