List of usage examples for android.app Activity getSystemService
@Override
public Object getSystemService(@ServiceName @NonNull String name)
From source file:menion.android.whereyougo.gui.extension.activity.CustomActivity.java
public static void setStatusbar(Activity activity) { try {//from w w w .ja va 2s. c om NotificationManager mNotificationManager = (NotificationManager) activity .getSystemService(Context.NOTIFICATION_SERVICE); // set statusbar if (Preferences.APPEARANCE_STATUSBAR) { Context context = activity.getApplicationContext(); Intent intent = new Intent(context, menion.android.whereyougo.gui.activity.MainActivity.class); // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setAction(Intent.ACTION_MAIN); PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, 0); final int sdkVersion = Integer.parseInt(android.os.Build.VERSION.SDK); Notification notif = null; if (sdkVersion < android.os.Build.VERSION_CODES.HONEYCOMB) { notif = new Notification(R.drawable.ic_title_logo, A.getAppName(), System.currentTimeMillis()); notif.setLatestEventInfo(activity, A.getAppName(), "", pIntent); } else { NotificationCompat.Builder builder = new NotificationCompat.Builder(activity) .setContentTitle(A.getAppName()).setSmallIcon(R.drawable.ic_title_logo) .setContentIntent(pIntent); notif = builder.build(); } notif.flags = Notification.FLAG_ONGOING_EVENT; mNotificationManager.notify(0, notif); } else { mNotificationManager.cancel(0); } } catch (Exception e) { // Logger.e(TAG, "setStatusbar(" + activity + ")", e); } }
From source file:io.digibyte.tools.util.Utils.java
public static boolean isUsingCustomInputMethod(Activity context) { if (context == null) return false; InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); if (imm == null) { return false; }// w ww . j a va2 s . c o m List<InputMethodInfo> mInputMethodProperties = imm.getEnabledInputMethodList(); final int N = mInputMethodProperties.size(); for (int i = 0; i < N; i++) { InputMethodInfo imi = mInputMethodProperties.get(i); if (imi.getId().equals(Settings.Secure.getString(context.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD))) { if ((imi.getServiceInfo().applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { return true; } } } return false; }
From source file:im.neon.activity.MXCActionBarActivity.java
/** * Dismiss the soft keyboard if one view in the activity has the focus. * @param activity the activity//from ww w.j a v a2 s . c o m */ public static void dismissKeyboard(Activity activity) { // hide the soft keyboard 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 source file:com.app.sample.chatting.widget.KJChatKeyboard.java
/** * /*from w w w .j a v a 2 s.c om*/ */ public static void showKeyboard(Context context) { Activity activity = (Activity) context; if (activity != null) { InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInputFromInputMethod(activity.getCurrentFocus().getWindowToken(), 0); imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); } }
From source file:com.hangulo.powercontact.util.Utils.java
public static void hideSoftKeyboard(Activity activity) { View view = activity.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); view.clearFocus();//w w w .j av a 2s. c o m } }
From source file:com.github.rutvijkumar.twittfuse.Util.java
public static void hideSoftKeyboard(View view, Activity activity) { InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); }
From source file:com.github.rutvijkumar.twittfuse.Util.java
public static void showSoftKeyboard(View view, Activity activity) { if (view.requestFocus()) { InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); }//w w w . ja v a 2s.co m }
From source file:com.joeyturczak.jtscanner.utils.Utility.java
/** * Hides the keyboard//from w w w . ja v a 2s. c om * Credit: http://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard */ public static void hideKeyboard(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 source file:longism.com.api.APIUtils.java
/** * TODO Function: check network connected, * * @param activity//from w w w . ja v a 2 s . c o m * @return true if Network is connected * @require: android.Manifest.permission.ACCESS_NETWORK_STATE * @author: Nguyen Long * @date: July 08, 2016 */ public static boolean isNetworkConnected(Activity activity) { try { ConnectivityManager cm = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnected()) { return true; } return false; } catch (Exception e) { return false; } }
From source file:com.nextgis.maplibui.util.ControlHelper.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD) public static void lockScreenOrientation(Activity activity) { WindowManager windowManager = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE); Configuration configuration = activity.getResources().getConfiguration(); int rotation = windowManager.getDefaultDisplay().getRotation(); // Search for the natural position of the device if (configuration.orientation == Configuration.ORIENTATION_LANDSCAPE && (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) || configuration.orientation == Configuration.ORIENTATION_PORTRAIT && (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270)) { // Natural position is Landscape switch (rotation) { case Surface.ROTATION_0: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); break; case Surface.ROTATION_90: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); break; case Surface.ROTATION_180: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); break; case Surface.ROTATION_270: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); break; }/*from ww w . java 2 s . c o m*/ } else { // Natural position is Portrait switch (rotation) { case Surface.ROTATION_0: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); break; case Surface.ROTATION_90: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); break; case Surface.ROTATION_180: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); break; case Surface.ROTATION_270: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); break; } } }