예제 #1
0
  private void createFloatingWindow() {
    SharedPreferences shared = getSharedPreferences("float_flag", Activity.MODE_PRIVATE);
    SharedPreferences.Editor editor = shared.edit();
    editor.putInt("float", 1);
    editor.commit();
    windowManager = (WindowManager) getApplicationContext().getSystemService("window");
    wmParams = ((ProfilerApplication) getApplication()).getMywmParams();
    wmParams.type = 2002;
    wmParams.flags |= 8;
    wmParams.gravity = Gravity.LEFT | Gravity.TOP;
    wmParams.x = 0;
    wmParams.y = 0;
    wmParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
    wmParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    wmParams.format = 1;
    windowManager.addView(floatingView, wmParams);
    floatingView.setOnTouchListener(
        new View.OnTouchListener() {
          public boolean onTouch(View v, MotionEvent event) {
            x = event.getRawX();
            y = event.getRawY() - 25;
            switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
                mTouchStartX = event.getX();
                mTouchStartY = event.getY();
                break;
              case MotionEvent.ACTION_MOVE:
                updateViewPosition();
                break;

              case MotionEvent.ACTION_UP:
                updateViewPosition();
                mTouchStartX = mTouchStartY = 0;
                break;
            }
            return true;
          }
        });
  }
예제 #2
0
 /** update the position of floating window. */
 private void updateViewPosition() {
   wmParams.x = (int) (x - mTouchStartX);
   wmParams.y = (int) (y - mTouchStartY);
   windowManager.updateViewLayout(floatingView, wmParams);
 }