List of usage examples for android.app Activity getSystemService
@Override
public Object getSystemService(@ServiceName @NonNull String name)
From source file:nth.com.ares.utils.Utils.java
public static void showSoftKeyboard(Activity activity, View view) { try {/*from w w w. j a va 2 s. com*/ InputMethodManager keyboard = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); // keyboard.showSoftInput(view, 0); activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); // inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0); } catch (Exception e) { // e.printStackTrace(); } }
From source file:Main.java
public static void hideKeyBoard(final Activity activity) { if (activity == null) return;/*w w w .j ava 2s .co m*/ activity.runOnUiThread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub InputMethodManager mgr = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); mgr.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0); } }); }
From source file:nth.com.ares.utils.Utils.java
public static void hideSoftKeyboard(Activity activity) { try {//w w w . j a v a 2s .c o m InputMethodManager inputMethodManager = (InputMethodManager) activity .getSystemService(Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0); } catch (Exception e) { // e.printStackTrace(); } // try { // InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); // inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0); // } catch (Exception e) { //// e.printStackTrace(); // } }
From source file:com.arlib.floatingsearchview.util.Util.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); }//from w ww . j a v a 2 s .c o m }
From source file:com.app.opencity.activities.MainActivity.java
public static void hideKeyboard(Activity activity) { InputMethodManager inputMethodManager = (InputMethodManager) activity .getSystemService(Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0); }
From source file:com.davidmiguel.gobees.utils.AndroidUtils.java
/** * Closes / hides soft Android keyboard. * * @param activity current activity.//from ww w.j ava 2 s. c o m */ public static void closeKeyboard(Activity activity) { View view = activity.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } }
From source file:Main.java
public static int getSurfaceOrientation(Activity activity) { // Sanity check: if (activity == null) { return -1; // invalid value }//from ww w.j av a2s . c o m Configuration config = activity.getResources().getConfiguration(); Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int displayRotation; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { displayRotation = display.getRotation(); // only available from Froyo } else { displayRotation = display.getOrientation(); } int activityOrientation = SCREEN_ORIENTATION_UNKNOWN; switch (config.orientation) { case Configuration.ORIENTATION_PORTRAIT: case Configuration.ORIENTATION_SQUARE: activityOrientation = ((displayRotation == Surface.ROTATION_0 || displayRotation == Surface.ROTATION_270) ? SCREEN_ORIENTATION_PORTRAIT : SCREEN_ORIENTATION_PORTRAITUPSIDEDOWN); break; case Configuration.ORIENTATION_LANDSCAPE: activityOrientation = ((displayRotation == Surface.ROTATION_0 || displayRotation == Surface.ROTATION_90) ? SCREEN_ORIENTATION_LANDSCAPELEFT : SCREEN_ORIENTATION_LANDSCAPERIGHT); break; case Configuration.ORIENTATION_UNDEFINED: default: break; } return activityOrientation; }
From source file:me.panpf.tool4a.util.InputMethodUtils.java
/** * ??/* w ww . j a v a 2 s . co m*/ */ public static void hideSoftInput(Activity activity) { View currentFocusView = activity != null ? activity.getCurrentFocus() : null; if (currentFocusView == null) { return; } InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(currentFocusView.getWindowToken(), 0); }
From source file:org.cm.podd.report.util.RequestDataUtil.java
public static boolean hasNetworkConnection(Activity activity) { ConnectivityManager cm = ((ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE)); boolean connected = cm != null && cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected(); if (!connected) { Toast.makeText(activity, R.string.alert_no_network_connection, Toast.LENGTH_LONG).show(); }//from ww w . j a v a 2 s . c o m return connected; }
From source file:Main.java
public static Pair<BluetoothManager, BluetoothAdapter> checkBT(final Activity activity) { // Use this check to determine whether BLE is supported on the device. Then // you can selectively disable BLE-related features. if (!btleSupport(activity)) { return null; }//ww w .j a va 2 s. com final BluetoothManager bluetoothManager = (BluetoothManager) activity .getSystemService(Context.BLUETOOTH_SERVICE); BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter(); //On some devices this does not work try { bluetoothAdapter.getBluetoothLeScanner(); } catch (NoSuchMethodError e) { return null; } // Ensures Bluetooth is available on the device and it is enabled. If not, // displays a dialog requesting user permission to enable Bluetooth. if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); activity.startActivityForResult(enableBtIntent, 1); bluetoothAdapter = bluetoothManager.getAdapter(); } return new Pair<BluetoothManager, BluetoothAdapter>(bluetoothManager, bluetoothAdapter); }