@TargetApi(Build.VERSION_CODES.LOLLIPOP)
  private void takeScreenShot() {
    // call for the projection manager
    mProjectionManager =
        (MediaProjectionManager)
            trainingActivity.getSystemService(Context.MEDIA_PROJECTION_SERVICE);
    // start capture handling thread
    new Thread() {
      @Override
      public void run() {
        Looper.prepare();
        mImageHandler = new Handler();
        Looper.loop();
      }
    }.start();

    trainingActivity.startActivityForResult(
        mProjectionManager.createScreenCaptureIntent(), TrainingActivity.IMAGE_REQUEST_CODE);
  }
 @Override
 public void onCreate(Bundle savedInstanceState) {
   // TODO Auto-generated method stub
   super.onCreate(savedInstanceState);
   setContentView(R.layout.stat_tab);
   DBAdapter dba = new DBAdapter(this);
   dba.open();
   dba.getAllExStat((TableLayout) findViewById(R.id.TableLayoutEx));
   dba.close();
 }
  private PopupWindow popupWindow(final View popUpView, final boolean isVideoPopup) {
    final PopupWindow popupWindow =
        new PopupWindow(
            popUpView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

    final Display defaultDisplay = trainingActivity.getWindowManager().getDefaultDisplay();
    popupWindow.setWidth(defaultDisplay.getWidth() / 2);
    popupWindow.setHeight(defaultDisplay.getHeight() / 2);

    View titlebar = popUpView.findViewById(R.id.titlebar);
    titlebar.setOnTouchListener(
        new View.OnTouchListener() {

          private int dx = 0;
          private int dy = 0;
          int mPosX = 20;
          int mPosY = 50;

          @Override
          public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
              case MotionEvent.ACTION_DOWN:
                dx = (int) (mPosX - motionEvent.getRawX());
                dy = (int) (mPosY - motionEvent.getRawY());
                break;
              case MotionEvent.ACTION_MOVE:
                mPosX = (int) (motionEvent.getRawX() + dx);
                mPosY = (int) (motionEvent.getRawY() + dy);
                popupWindow.update(mPosX, mPosY, -1, -1);
                break;
            }
            return true;
          }
        });
    ImageView close = (ImageView) popUpView.findViewById(R.id.closeIV);
    close.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {

            showDialogBoxAndClosePopup(isVideoPopup, popupWindow);
          }
        });

    popupWindow.showAtLocation(mDrawerLayout, 1, 0, 0);
    popUpView.setOnTouchListener(
        new View.OnTouchListener() {
          int orgX = 0, orgY = 0;
          int offsetX, offsetY;
          int orgWidth, orgHeight;

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction() & MotionEvent.ACTION_MASK) {
              case MotionEvent.ACTION_DOWN:
                orgX = (int) event.getX();
                orgY = (int) event.getY();

                orgWidth = v.getMeasuredWidth();
                orgHeight = v.getMeasuredHeight();
                break;

              case MotionEvent.ACTION_MOVE:
                offsetX = (int) event.getX() - orgX;
                offsetY = (int) event.getY() - orgY;
                int deviceDefaultHeight = defaultDisplay.getHeight();
                int deviceDefaultWidth = defaultDisplay.getWidth();
                int width = orgWidth + offsetX;
                int height = orgHeight + offsetY;
                if (height < deviceDefaultHeight / 3.5) {
                  height = deviceDefaultHeight / 3;
                } else {
                  if (height > deviceDefaultHeight) {
                    height = deviceDefaultHeight;
                  }
                }
                if (width < deviceDefaultWidth / 3) {
                  width = deviceDefaultWidth / 2;
                } else if (width > deviceDefaultWidth) {
                  width = deviceDefaultWidth;
                }
                popupWindow.update(width, height);
                break;
            }
            return true;
          }
        });
    return popupWindow;
  }