content: package com.example.y.mvp.utils;
  
  import android.app.Activity;
  import android.content.Context;
  import android.content.Intent;
  import android.os.Bundle;
  import android.os.Environment;
  import android.support.annotation.NonNull;
  import android.view.WindowManager;
  import android.view.inputmethod.InputMethodManager;
  import android.widget.EditText;
  
  import com.example.y.mvp.R;
  
  import java.io.File;
  
  /**
   * by y on 2016/4/29.
   */
  
  public class ActivityUtils {
  
      public static void startActivity(Class<?> clz) {
          Intent intent;
          intent = new Intent(UIUtils.getContext(), clz);
          intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          UIUtils.getContext().startActivity(intent);
      }
  
      public static void startActivity(Class<?> clz, Bundle bundle) {
          Intent intent = new Intent(UIUtils.getContext(), clz);
          intent.putExtras(bundle);
          intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          UIUtils.getContext().startActivity(intent);
      }
  
      public static void offKeyboard(@NonNull EditText editText) {
          if (detectKeyboard(editText)) {
              InputMethodManager imm = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
              imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
          }
      }
  
      public static void openKeyboard(@NonNull final EditText editText) {
          if (!detectKeyboard(editText)) {
              editText.post(() -> {
                  InputMethodManager imm = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                  imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
              });
          }
      }
  
      private static boolean detectKeyboard(@NonNull EditText editText) {
          InputMethodManager imm = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
          return imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
      }
  
      //隐藏状态栏
      public static void hideStatusBar(Activity activity) {
          WindowManager.LayoutParams attrs = activity.getWindow().getAttributes();
          attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
          activity.getWindow().setAttributes(attrs);
      }
  
      //显示状态栏
      public static void showStatusBar(Activity activity) {
          WindowManager.LayoutParams attrs = activity.getWindow().getAttributes();
          attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
          activity.getWindow().setAttributes(attrs);
      }
  
      //获取图库路径
      public static File ImagePath() {
          String sdcard = Environment.getExternalStorageDirectory().toString();
          File file = new File(sdcard + "/DCIM");
          if (!file.exists()) {
              file.mkdirs();
          }
          File mFile = new File(file + "/Demo");
          if (!mFile.exists()) {
              mFile.mkdirs();
          }
          return mFile.getAbsoluteFile();
      }
  
      public static void share(Activity activity, Object message) {
          Intent intent = new Intent(Intent.ACTION_SEND);
          intent.setType("text/plain");
          intent.putExtra(Intent.EXTRA_TEXT, message.toString());
          intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          activity.startActivity(Intent.createChooser(intent, UIUtils.getString(R.string.share)));
      }
  
  
  }
  