private void dragView(int x, int y) {
    if (mRemoveMode == SLIDE) {
      float alpha = 1.0f;
      int width = mDragView.getWidth();
      if (x > width / 2) {
        alpha = ((float) (width - x)) / (width / 2);
      }
      mWindowParams.alpha = alpha;
    }

    if (mRemoveMode == FLING || mRemoveMode == TRASH) {
      mWindowParams.x = x - mDragPointX + mXOffset;
    } else {
      mWindowParams.x = 0;
    }
    mWindowParams.y = y - mDragPointY + mYOffset;
    mWindowManager.updateViewLayout(mDragView, mWindowParams);

    if (mTrashcan != null) {
      int width = mDragView.getWidth();
      if (y > getHeight() * 3 / 4) {
        mTrashcan.setLevel(2);
      } else if (width > 0 && x > width / 4) {
        mTrashcan.setLevel(1);
      } else {
        mTrashcan.setLevel(0);
      }
    }
  }
예제 #2
0
  /** 画面サイズから自位置を決定します。 */
  private void updateViewLayout() {
    cancelAnimation();

    // 前の画面座標を保存
    final int oldScreenHeight = mMetrics.heightPixels;
    final int oldScreenWidth = mMetrics.widthPixels;
    final int oldPositionLimitWidth = mPositionLimitRect.width();
    final int oldPositionLimitHeight = mPositionLimitRect.height();

    // 新しい座標情報に切替
    mWindowManager.getDefaultDisplay().getMetrics(mMetrics);
    final int width = getMeasuredWidth();
    final int height = getMeasuredHeight();
    final int newScreenWidth = mMetrics.widthPixels;
    final int newScreenHeight = mMetrics.heightPixels;

    // 移動範囲の設定
    mMoveLimitRect.set(-width, -height * 2, newScreenWidth + width, newScreenHeight + height);
    mPositionLimitRect.set(
        -mOverMargin,
        0,
        newScreenWidth - width + mOverMargin,
        newScreenHeight - mStatusBarHeight - height);

    // 縦横切替の場合
    if (oldScreenWidth != newScreenWidth || oldScreenHeight != newScreenHeight) {
      // 画面端に移動する場合は現在の位置から左右端を設定
      if (mMoveDirection == FloatingViewManager.MOVE_DIRECTION_DEFAULT) {
        // 右半分にある場合
        if (mParams.x > (newScreenWidth - width) / 2) {
          mParams.x = mPositionLimitRect.right;
        }
        // 左半分にある場合
        else {
          mParams.x = mPositionLimitRect.left;
        }
      }
      // 左端に移動
      else if (mMoveDirection == FloatingViewManager.MOVE_DIRECTION_LEFT) {
        mParams.x = mPositionLimitRect.left;
      }
      // 右端に移動
      else if (mMoveDirection == FloatingViewManager.MOVE_DIRECTION_RIGHT) {
        mParams.x = mPositionLimitRect.right;
      }
      // 画面端に移動しない場合は画面座標の比率から計算
      else {
        final int newX =
            (int) (mParams.x * mPositionLimitRect.width() / (float) oldPositionLimitWidth + 0.5f);
        mParams.x = Math.min(Math.max(mPositionLimitRect.left, newX), mPositionLimitRect.right);
      }

      // スクリーン位置の比率からY座標を設定(四捨五入)
      final int newY =
          (int) (mParams.y * mPositionLimitRect.height() / (float) oldPositionLimitHeight + 0.5f);
      mParams.y = Math.min(Math.max(mPositionLimitRect.top, newY), mPositionLimitRect.bottom);
      mWindowManager.updateViewLayout(this, mParams);
    }
  }
예제 #3
0
    /** アニメーションの処理を行います。 */
    @Override
    public void handleMessage(Message msg) {
      final FloatingView floatingView = mFloatingView.get();
      if (floatingView == null) {
        removeMessages(ANIMATION_IN_TOUCH);
        return;
      }

      final int animationCode = msg.what;
      final int animationType = msg.arg1;
      final WindowManager.LayoutParams params = floatingView.mParams;
      final WindowManager windowManager = floatingView.mWindowManager;

      // 状態変更またはアニメーションを開始した場合の初期化
      if (mIsChangeState || animationType == TYPE_FIRST) {
        // 状態変更時のみアニメーション時間を使う
        mStartTime = mIsChangeState ? SystemClock.uptimeMillis() : 0;
        mStartX = params.x;
        mStartY = params.y;
        mStartedCode = animationCode;
        mIsChangeState = false;
      }
      // 経過時間
      final float elapsedTime = SystemClock.uptimeMillis() - mStartTime;
      final float trackingTargetTimeRate = Math.min(elapsedTime / CAPTURE_DURATION_MILLIS, 1.0f);

      // 重なっていない場合のアニメーション
      if (mState == FloatingView.STATE_NORMAL) {
        final float basePosition = calcAnimationPosition(trackingTargetTimeRate);
        // 画面外へのオーバーを認める
        final Rect moveLimitRect = floatingView.mMoveLimitRect;
        // 最終的な到達点
        final float targetPositionX =
            Math.min(Math.max(moveLimitRect.left, (int) mTouchPositionX), moveLimitRect.right);
        final float targetPositionY =
            Math.min(Math.max(moveLimitRect.top, (int) mTouchPositionY), moveLimitRect.bottom);
        params.x = (int) (mStartX + (targetPositionX - mStartX) * basePosition);
        params.y = (int) (mStartY + (targetPositionY - mStartY) * basePosition);
        windowManager.updateViewLayout(floatingView, params);
        sendMessageAtTime(
            newMessage(animationCode, TYPE_UPDATE),
            SystemClock.uptimeMillis() + ANIMATION_REFRESH_TIME_MILLIS);
      }
      // 重なった場合のアニメーション
      else if (mState == FloatingView.STATE_INTERSECTING) {
        final float basePosition = calcAnimationPosition(trackingTargetTimeRate);
        // 最終的な到達点
        final float targetPositionX = mTargetPositionX - floatingView.getWidth() / 2;
        final float targetPositionY = mTargetPositionY - floatingView.getHeight() / 2;
        // 現在地からの移動
        params.x = (int) (mStartX + (targetPositionX - mStartX) * basePosition);
        params.y = (int) (mStartY + (targetPositionY - mStartY) * basePosition);
        windowManager.updateViewLayout(floatingView, params);
        sendMessageAtTime(
            newMessage(animationCode, TYPE_UPDATE),
            SystemClock.uptimeMillis() + ANIMATION_REFRESH_TIME_MILLIS);
      }
    }
  /**
   * Positions the popup window on screen. When the popup window is too tall to fit under the
   * anchor, a parent scroll view is seeked and scrolled up to reclaim space. If scrolling is not
   * possible or not enough, the popup window gets moved on top of the anchor.
   *
   * <p>The height must have been set on the layout parameters prior to calling this method.
   *
   * @param anchor the view on which the popup window must be anchored
   * @param p the layout parameters used to display the drop down
   * @return true if the popup is translated upwards to fit on screen
   */
  private boolean findDropDownPosition(
      View anchor, WindowManager.LayoutParams p, int xoff, int yoff) {
    anchor.getLocationInWindow(mDrawingLocation);
    p.x = mDrawingLocation[0] + xoff;
    p.y = mDrawingLocation[1] + anchor.getMeasuredHeight() + yoff;

    boolean onTop = false;

    p.gravity = Gravity.LEFT | Gravity.TOP;

    anchor.getLocationOnScreen(mScreenLocation);
    final Rect displayFrame = new Rect();
    anchor.getWindowVisibleDisplayFrame(displayFrame);

    final View root = anchor.getRootView();
    if (mScreenLocation[1] + anchor.getMeasuredHeight() + yoff + mPopupHeight > displayFrame.bottom
        || p.x + mPopupWidth - root.getWidth() > 0) {
      // if the drop down disappears at the bottom of the screen. we try to
      // scroll a parent scrollview or move the drop down back up on top of
      // the edit box
      int scrollX = anchor.getScrollX();
      int scrollY = anchor.getScrollY();
      Rect r =
          new Rect(
              scrollX,
              scrollY,
              scrollX + mPopupWidth,
              scrollY + mPopupHeight + anchor.getMeasuredHeight());
      anchor.requestRectangleOnScreen(r, true);

      // now we re-evaluate the space available, and decide from that
      // whether the pop-up will go above or below the anchor.
      anchor.getLocationInWindow(mDrawingLocation);
      p.x = mDrawingLocation[0] + xoff;
      p.y = mDrawingLocation[1] + anchor.getMeasuredHeight() + yoff;

      // determine whether there is more space above or below the anchor
      anchor.getLocationOnScreen(mScreenLocation);

      onTop =
          (displayFrame.bottom - mScreenLocation[1] - anchor.getMeasuredHeight() - yoff)
              < (mScreenLocation[1] - yoff - displayFrame.top);
      if (onTop) {
        p.gravity = Gravity.LEFT | Gravity.BOTTOM;
        p.y = root.getHeight() - mDrawingLocation[1] - yoff;
      } else {
        p.y = mDrawingLocation[1] + anchor.getMeasuredHeight() + yoff;
      }
    }

    p.gravity |= Gravity.DISPLAY_CLIP_VERTICAL;

    return onTop;
  }
  private void initView() {
    mWM = (WindowManager) mContext.getSystemService(WINDOW_SERVICE);
    mTextView =
        new TextView(mContext) {
          @Override
          protected void onDraw(android.graphics.Canvas canvas) {
            int t = getTop();
            int l = getLeft();
            int b = getBottom();
            int r = getRight();
            mRect.top = t;
            mRect.left = t;
            mRect.right = r;
            mRect.bottom = b;
            canvas.drawRect(mRect, mPaint);
            super.onDraw(canvas);
          };
        };

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.type = 2002;
    // wmParams.format=1;
    lp.flags |= 8;

    lp.gravity = Gravity.LEFT | Gravity.TOP; // 调整悬浮窗口至左上角
    // 以屏幕左上角为原点,设置x、y初始值
    lp.x = 0;
    lp.y = 0;

    // 设置悬浮窗口长宽数据
    lp.width = 300;
    lp.height = 25;
    mTextView.setText("");
    mWM.addView(mTextView, lp);
  }
  /**
   * Show the controller on screen. It will go away automatically after 'timeout' milliseconds of
   * inactivity.
   *
   * @param timeout The timeout in milliseconds. Use 0 to show the controller until hide() is
   *     called.
   */
  public void show(int timeout) {

    if (!mShowing && mAnchor != null) {
      setProgress();

      int[] anchorpos = new int[2];
      mAnchor.getLocationOnScreen(anchorpos);

      WindowManager.LayoutParams p = new WindowManager.LayoutParams();
      p.gravity = Gravity.TOP;
      p.width = mAnchor.getWidth();
      p.height = LayoutParams.WRAP_CONTENT;
      p.x = 0;
      p.y = anchorpos[1] + mAnchor.getHeight() - p.height;
      p.format = PixelFormat.TRANSLUCENT;
      p.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
      p.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
      p.token = null;
      p.windowAnimations = 0; // android.R.style.DropDownAnimationDown;
      mWindowManager.addView(mDecor, p);
      mShowing = true;
    }
    updatePausePlay();

    // cause the progress bar to be updated even if mShowing
    // was already true.  This happens, for example, if we're
    // paused with the progress bar showing the user hits play.
    mHandler.sendEmptyMessage(SHOW_PROGRESS);

    Message msg = mHandler.obtainMessage(FADE_OUT);
    if (timeout != 0) {
      mHandler.removeMessages(FADE_OUT);
      mHandler.sendMessageDelayed(msg, timeout);
    }
  }
예제 #7
0
 private boolean findDropDownPosition(View anchor, android.view.WindowManager.LayoutParams p) {
   anchor.getLocationOnScreen(mDrawingLocation);
   p.x = mDrawingLocation[0];
   p.y = mDrawingLocation[1] + anchor.getMeasuredHeight();
   boolean onTop = false;
   View root = anchor.getRootView();
   int delta = (p.y + p.height) - root.getWindowTop() - root.getHeight();
   if (delta > 0) {
     if (p.y != anchor.getWindowBottom()) {
       ScrollView scrollView =
           (ScrollView) anchor.findParentViewOfType(android / widget / ScrollView);
       if (scrollView != null) {
         int bottom = anchor.getWindowBottom() + p.height;
         if (bottom > scrollView.getChildAt(scrollView.getChildCount() - 1).getWindowBottom())
           onTop = true;
         else if (bottom > scrollView.getWindowBottom()) {
           boolean enabled = scrollView.isVerticalScrollBarEnabled();
           if (enabled) scrollView.setVerticalScrollBarEnabled(false);
           scrollView.smoothScrollBy(0, delta);
           if (enabled) scrollView.setVerticalScrollBarEnabled(enabled);
           p.y -= delta;
         } else {
           onTop = true;
         }
       } else {
         onTop = true;
       }
     } else {
       onTop = true;
     }
     if (onTop) p.y -= anchor.getMeasuredHeight() + p.height;
   }
   return onTop;
 }
  private void startDragging(Bitmap bm, int x, int y) {
    stopDragging();

    mWindowParams = new WindowManager.LayoutParams();
    mWindowParams.gravity = Gravity.TOP | Gravity.LEFT;
    mWindowParams.x = x - mDragPointX + mXOffset;
    mWindowParams.y = y - mDragPointY + mYOffset;

    mWindowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    mWindowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
    mWindowParams.flags =
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
            | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
            | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
    mWindowParams.format = PixelFormat.TRANSLUCENT;
    mWindowParams.windowAnimations = 0;

    Context context = getContext();
    ImageView v = new ImageView(context);
    // int backGroundColor = context.getResources().getColor(R.color.dragndrop_background);

    v.setBackgroundColor(0x882211); // !!toa
    // v.setBackgroundResource(R.drawable.playlist_tile_drag);
    v.setPadding(0, 0, 0, 0);
    v.setImageBitmap(bm);
    mDragBitmap = bm;

    mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    mWindowManager.addView(v, mWindowParams);
    mDragView = v;
  }
예제 #9
0
  private void startDragging(Bitmap bm, int y) {
    stopDragging();

    mWindowParams = new WindowManager.LayoutParams();
    mWindowParams.gravity = Gravity.TOP;
    mWindowParams.x = 0;
    mWindowParams.y = y - mDragPoint + mCoordOffset;

    mWindowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    mWindowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
    mWindowParams.flags =
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
            | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
    mWindowParams.format = PixelFormat.TRANSLUCENT;
    mWindowParams.windowAnimations = 0;

    ImageView v = new ImageView(getContext());
    //        int backGroundColor =
    // getContext().getResources().getColor(R.color.dragndrop_background);
    v.setBackgroundColor(dragndropBackgroundColor);
    v.setImageBitmap(bm);
    mDragBitmap = bm;

    mWindowManager = (WindowManager) getContext().getSystemService("window");
    mWindowManager.addView(v, mWindowParams);
    mDragView = v;
  }
 @Override
 protected void onPrepareDialog(int id, Dialog dialog) {
   switch (id) {
     case MARKERCONFIG_DIALOG:
       if (markerConfigDialog != null && longTouchGeoPoint != null) {
         Window window = markerConfigDialog.getWindow();
         WindowManager.LayoutParams lp = window.getAttributes();
         // 设置对话框初始位置为左上角
         lp.gravity = Gravity.LEFT | Gravity.TOP;
         // lp.x与lp.y表示相对于原始位置的偏移
         // (touchX, touchY)为触屏位置坐标,坐标系以屏幕左上角为(0, 0)
         lp.x = touchX;
         lp.y = touchY;
         // 重新设置对话框位置
         window.setAttributes(lp);
         markerConfigDialog.setLongTouchGeoPoint(longTouchGeoPoint);
       }
       break;
     case README_DIALOG:
       ReadmeDialog readmeDialog = (ReadmeDialog) dialog;
       readmeDialog.setReadmeText(getResources().getString(R.string.overlayeventdemo_readme));
       break;
     default:
       break;
   }
   super.onPrepareDialog(id, dialog);
 }
  private void startDragging(Bitmap bm, int x, int y) {
    stopDragging();

    mWindowParams = new WindowManager.LayoutParams();
    mWindowParams.gravity = Gravity.TOP | Gravity.LEFT;
    mWindowParams.x = x;
    mWindowParams.y = y - mDragPoint + mCoordOffset;

    mWindowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    mWindowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
    mWindowParams.flags =
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
            | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
            | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
    mWindowParams.format = PixelFormat.TRANSLUCENT;
    mWindowParams.windowAnimations = 0;

    Context context = getContext();
    ImageView v = new ImageView(context);
    int backGroundColor = context.getResources().getColor(android.R.color.holo_blue_dark);
    v.setAlpha((float) 0.7);
    v.setBackgroundColor(backGroundColor);
    v.setImageBitmap(bm);
    mDragBitmap = bm;

    mWindowManager = (WindowManager) context.getSystemService("window");
    mWindowManager.addView(v, mWindowParams);
    mDragView = v;
  }
예제 #12
0
 public void update(int x, int y, int width, int height) {
   if (width != -1) setWidth(width);
   if (height != -1) setHeight(height);
   if (!isShowing() || mContentView == null) return;
   android.view.WindowManager.LayoutParams p =
       (android.view.WindowManager.LayoutParams) mContentView.getLayoutParams();
   boolean update = false;
   if (width != -1 && p.width != width) {
     p.width = width;
     update = true;
   }
   if (height != -1 && p.height != height) {
     p.height = height;
     update = true;
   }
   if (p.x != x) {
     p.x = x;
     update = true;
   }
   if (p.y != y) {
     p.y = y;
     update = true;
   }
   if (update) {
     WindowManagerImpl wm = WindowManagerImpl.getDefault();
     wm.updateViewLayout(mContentView, p);
   }
 }
예제 #13
0
  public ActionSheetDialog builder() {
    View view = LayoutInflater.from(context).inflate(R.layout.dt_view_actionsheet, null);

    view.setMinimumWidth(display.getWidth());

    sLayout_content = (ScrollView) view.findViewById(R.id.sLayout_content);
    lLayout_content = (LinearLayout) view.findViewById(R.id.lLayout_content);
    txt_title = (TextView) view.findViewById(R.id.txt_title);
    txt_cancel = (TextView) view.findViewById(R.id.txt_cancel);
    txt_cancel.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            dialog.dismiss();
          }
        });

    dialog = new Dialog(context, R.style.ActionSheetDialogStyle);
    dialog.setContentView(view);
    Window dialogWindow = dialog.getWindow();
    dialogWindow.setGravity(Gravity.LEFT | Gravity.BOTTOM);
    WindowManager.LayoutParams lp = dialogWindow.getAttributes();
    lp.x = 0;
    lp.y = 0;
    dialogWindow.setAttributes(lp);
    return this;
  }
예제 #14
0
  protected Dialog onCreateDialog() {
    Dialog dialog = null;
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    builder.setTitle("Chose file");
    loadFileList();
    if (mFileList == null) {
      dialog = builder.create();
      return dialog;
    }
    builder.setItems(
        mFileList,
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
            // mChosenFile = mFileList[which];
          }
        });
    dialog = builder.create();
    WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();

    wmlp.gravity = Gravity.TOP | Gravity.LEFT;
    wmlp.x = 100;
    wmlp.y = 100;
    dialog = builder.show();
    return dialog;
  }
예제 #15
0
 private synchronized void handleShow() {
   if (mView != mNextView) {
     // remove the old view if necessary
     handleHide();
     mView = mNextView;
     // / M: we set hint center_horizontal and bottom in xml.
     // final int gravity = mGravity;
     // mParams.gravity = gravity;
     // if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK)
     // == Gravity.FILL_HORIZONTAL) {
     // mParams.horizontalWeight = 1.0f;
     // }
     // if ((gravity & Gravity.VERTICAL_GRAVITY_MASK)
     // == Gravity.FILL_VERTICAL) {
     // mParams.verticalWeight = 1.0f;
     // }
     // mParams.x = mX;
     // mParams.y = mY;
     // mParams.verticalMargin = mVerticalMargin;
     // mParams.horizontalMargin = mHorizontalMargin;
     mParams.x = 0;
     mParams.y = 0;
     mParams.height = WindowManager.LayoutParams.MATCH_PARENT;
     mParams.width = WindowManager.LayoutParams.MATCH_PARENT;
     try {
       if (mView.getParent() != null) {
         mWM.removeView(mView);
       }
       mWM.addView(mView, mParams);
     } catch (BadTokenException ex) {
       ex.printStackTrace();
     }
     Util.fadeIn(mView);
   }
 }
예제 #16
0
 public void handleShow() {
   if (localLOGV)
     Log.v(TAG, "HANDLE SHOW: " + this + " mView=" + mView + " mNextView=" + mNextView);
   if (mView != mNextView) {
     // remove the old view if necessary
     handleHide();
     mView = mNextView;
     mWM = WindowManagerImpl.getDefault();
     final int gravity = mGravity;
     mParams.gravity = gravity;
     if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) {
       mParams.horizontalWeight = 1.0f;
     }
     if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) {
       mParams.verticalWeight = 1.0f;
     }
     mParams.x = mX;
     mParams.y = mY;
     mParams.verticalMargin = mVerticalMargin;
     mParams.horizontalMargin = mHorizontalMargin;
     if (mView.getParent() != null) {
       if (localLOGV) Log.v(TAG, "REMOVE! " + mView + " in " + this);
       mWM.removeView(mView);
     }
     if (localLOGV) Log.v(TAG, "ADD! " + mView + " in " + this);
     mWM.addView(mView, mParams);
     trySendAccessibilityEvent();
   }
 }
예제 #17
0
 public static void setActivitySizePos(Activity activity, int x, int y, int width, int height) {
   WindowManager.LayoutParams p = activity.getWindow().getAttributes();
   p.x = x;
   p.y = y;
   p.width = width;
   p.height = height;
   activity.getWindow().setAttributes(p);
 }
예제 #18
0
 /** 初回描画時の座標設定を行います。 */
 @Override
 public boolean onPreDraw() {
   getViewTreeObserver().removeOnPreDrawListener(this);
   // 画面端に移動しない場合は指定座標に移動
   if (mMoveDirection == FloatingViewManager.MOVE_DIRECTION_NONE) {
     mParams.x = mInitX;
     mParams.y = mInitY;
     moveTo(mInitX, mInitY, mInitX, mInitY, false);
   } else {
     mParams.x = 0;
     mParams.y = mMetrics.heightPixels - mStatusBarHeight - getMeasuredHeight();
     moveToEdge(false);
   }
   mIsDraggable = true;
   mWindowManager.updateViewLayout(this, mParams);
   return true;
 }
예제 #19
0
 @Override
 public void onChanged(int data) {
   WindowManager.LayoutParams lp =
       (WindowManager.LayoutParams) getWindow().getDecorView().getLayoutParams();
   lp.x = -data;
   getWindow().getDecorView().setLayoutParams(lp);
   textView.setText(System.currentTimeMillis() + ":" + data);
 }
예제 #20
0
 /** Set the dialog's position relative to the (0,0) */
 public void setPositon(int xoff, int yoff) {
   Window window = TurnkeyCommFinetune.this.getWindow();
   WindowManager.LayoutParams lp = window.getAttributes();
   lp.x = xoff;
   lp.y = yoff;
   this.xOff = xoff;
   this.yOff = yoff;
   window.setAttributes(lp);
 }
예제 #21
0
 private void onDrag(int x, int y) {
   if (dragImageView != null) {
     windowParams.alpha = 0.8f;
     windowParams.x = (x - mLastX - xtox) + dragItemView.getLeft() + 8;
     windowParams.y =
         (y - mLastY - ytoy) + dragItemView.getTop() + (int) (45 * Configure.screenDensity);
     windowManager.updateViewLayout(dragImageView, windowParams);
   }
 }
 private void updateLayoutParamsForPosiion(
     View anchor, WindowManager.LayoutParams p, int yOffset) {
   measureFloater();
   int measuredHeight = mPopupView.getMeasuredHeight();
   int paddingBottom = mPopupView.mMarker.getPaddingBottom();
   anchor.getLocationInWindow(mDrawingLocation);
   p.x = 0;
   p.y = mDrawingLocation[1] - measuredHeight + yOffset + paddingBottom;
   p.width = screenSize.x;
   p.height = measuredHeight;
 }
예제 #23
0
 public void show(View parent, int x, int y) {
   if (isShowing() || mContentView == null) {
     return;
   } else {
     mIsShowing = true;
     android.view.WindowManager.LayoutParams p = createPopupLayout(parent.getWindowToken());
     p.x = x;
     p.y = y;
     preparePopup(p);
     invokePopup(p);
     return;
   }
 }
예제 #24
0
  /**
   * @param context Context.
   * @param title The title of this AlertDialog can be null .
   * @param items button name list.
   * @param alertDo methods call Id:Button + cancel_Button.
   * @param exit Name can be null.It will be Red Color
   * @return A AlertDialog
   */
  public static Dialog showAlert(
      final Context context,
      final String title,
      final String[] items,
      String exit,
      final OnAlertSelectId alertDo,
      OnCancelListener cancelListener) {
    String cancel = context.getString(R.string.app_cancel);
    final Dialog dlg = new Dialog(context, R.style.MMTheme_DataSheet);
    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.alert_dialog_menu_layout, null);
    final int cFullFillWidth = 10000;
    layout.setMinimumWidth(cFullFillWidth);
    final ListView list = (ListView) layout.findViewById(R.id.content_list);
    AlertAdapter adapter = new AlertAdapter(context, title, items, exit, cancel);
    list.setAdapter(adapter);
    list.setDividerHeight(0);

    list.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (!(title == null || title.equals("")) && position - 1 >= 0) {
              alertDo.onClick(position - 1);
              dlg.dismiss();
              list.requestFocus();
            } else {
              alertDo.onClick(position);
              dlg.dismiss();
              list.requestFocus();
            }
          }
        });
    // set a large value put it in bottom
    Window w = dlg.getWindow();
    WindowManager.LayoutParams lp = w.getAttributes();
    lp.x = 0;
    final int cMakeBottom = -1000;
    lp.y = cMakeBottom;
    lp.gravity = Gravity.BOTTOM;
    dlg.onWindowAttributesChanged(lp);
    dlg.setCanceledOnTouchOutside(true);
    if (cancelListener != null) {
      dlg.setOnCancelListener(cancelListener);
    }
    dlg.setContentView(layout);
    dlg.show();
    return dlg;
  }
예제 #25
0
  private CIInfoPwdDialog() {
    super();
    // TODO Auto-generated constructor stub
    setAutoDismiss(false);
    password = TvPluginControler.getInstance().getCilManager().getCIPassword();
    Log.i("gky", getClass().getSimpleName() + "  CIInfoPwdDialog password is " + password);
    super.PASSWORDSIZE = TvPluginControler.getInstance().getCilManager().getCIPasswordLength();
    Log.i(
        "gky",
        getClass().getSimpleName() + "  CIInfoPwdDialog PASSWORDSIZE is " + super.PASSWORDSIZE);

    WindowManager.LayoutParams dialogParams =
        new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    dialogParams.x = 0;
    dialogParams.y = 0;

    this.getWindow().setAttributes(dialogParams);

    passwordView =
        new PasswordView(
            TvContext.context,
            0,
            0,
            edit_Weith,
            edit_Height,
            margin_v,
            margin_h,
            password,
            title,
            25,
            30,
            PASSWORDSIZE) {
          public void passwordwrong(String input) {
            // TODO Auto-generated method stub
            this.clearPassword();
            this.passwordwrongInforText();
            Log.i("gky", getClass().getSimpleName() + "------>passwordwrong input is " + input);
            CIInfoPwdDialog.this.dismissUI();
            TvPluginControler.getInstance().getCilManager().answerEnq(input);
          }

          @Override
          public void passwordright(String input) {
            // TODO Auto-generated method stub
            Log.i("gky", getClass().getSimpleName() + "----->passwordright input is " + input);
            CIInfoPwdDialog.this.dismissUI();
            TvPluginControler.getInstance().getCilManager().answerEnq(input);
          }
        };
    setDialogContentView(passwordView.getlayout(), new LayoutParams(edit_Weith, edit_Height * 2));
  }
예제 #26
0
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   int ea = event.getAction();
   switch (ea) {
     case MotionEvent.ACTION_DOWN:
       lastX = (int) event.getRawX(); // 获取触摸事件触摸位置的原始X坐标
       lastY = (int) event.getRawY();
       break;
     case MotionEvent.ACTION_MOVE:
       int dx = (int) event.getRawX() - lastX;
       int dy = (int) event.getRawY() - lastY;
       int cx = (int) event.getX();
       int cy = (int) event.getY();
       if (cy > 0 && cx > 0 && cx < wl.width && cy < wl.height) {
         wl.y += dy; // y小于0上移,大于0下移
         wl.x += dx;
         if (wl.x <= -lLeft) {
           wl.x = -lLeft;
         }
         if (wl.x >= lRight) {
           wl.x = lRight;
         }
         if (wl.y <= -lTop) {
           wl.y = -lTop;
         }
         if (wl.y >= lBottom) {
           wl.y = lBottom;
         }
         window.setAttributes(wl);
       }
       lastX = (int) event.getRawX();
       lastY = (int) event.getRawY();
       break;
     case MotionEvent.ACTION_UP:
       break;
   }
   return true;
 }
예제 #27
0
파일: Main.java 프로젝트: alannet/example
  public void onClick_CustomPositionDialog(View view) {
    AlertDialog alertDialog =
        new AlertDialog.Builder(this)
            .setMessage("在任意位置显示对话框")
            .setPositiveButton("确定", null)
            .create();
    Window window = alertDialog.getWindow();
    WindowManager.LayoutParams lp = window.getAttributes();
    lp.x = -20;
    lp.y = -120;
    window.setAttributes(lp);

    alertDialog.show();
  }
  // move the drag view
  private void drag(int x, int y) {
    if (mDragView != null) {
      WindowManager.LayoutParams layoutParams =
          (WindowManager.LayoutParams) mDragView.getLayoutParams();
      layoutParams.x = x;
      layoutParams.y = y - mDragPointOffset;
      WindowManager mWindowManager =
          (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
      mWindowManager.updateViewLayout(mDragView, layoutParams);

      if (mDragListener != null)
        mDragListener.onDrag(x, y, null); // change null to "this" when ready to use
    }
  }
예제 #29
0
파일: DnDList.java 프로젝트: babatz/android
  private void drag(int x, int y) {
    if (mDragView != null) {
      final WindowManager.LayoutParams layoutParams =
          (WindowManager.LayoutParams) mDragView.getLayoutParams();
      layoutParams.x = x;
      layoutParams.y = y - mDragPointOffset;
      final WindowManager mWindowManager =
          (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);

      mWindowManager.updateViewLayout(mDragView, layoutParams);

      if (mDragListener != null) mDragListener.onDrag(x, y, this);
    }
  }
예제 #30
0
  /**
   * Actual internal method to show this dialog. Called only by {@link #considerShowing()} when all
   * data requirements have been met.
   */
  private void showInternal() {
    mDecor = mWindow.getDecorView();
    mDecor.getViewTreeObserver().addOnGlobalLayoutListener(this);
    WindowManager.LayoutParams l = mWindow.getAttributes();

    l.width = mScreenWidth + mShadowHoriz + mShadowHoriz;
    l.height = WindowManager.LayoutParams.WRAP_CONTENT;

    // Force layout measuring pass so we have baseline numbers
    mDecor.measure(l.width, l.height);
    final int blockHeight = mDecor.getMeasuredHeight();

    l.gravity = Gravity.TOP | Gravity.LEFT;
    l.x = -mShadowHoriz;

    if (mAnchor.top > blockHeight) {
      // Show downwards callout when enough room, aligning bottom block
      // edge with top of anchor area, and adjusting to inset arrow.
      showArrow(R.id.arrow_down, mAnchor.centerX());
      l.y = mAnchor.top - blockHeight + mShadowVert;
      l.windowAnimations = R.style.QuickContactAboveAnimation;

    } else {
      // Otherwise show upwards callout, aligning block top with bottom of
      // anchor area, and adjusting to inset arrow.
      showArrow(R.id.arrow_up, mAnchor.centerX());
      l.y = mAnchor.bottom - mShadowVert;
      l.windowAnimations = R.style.QuickContactBelowAnimation;
    }

    l.flags =
        WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
            | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;

    mRequestedY = l.y;
    mWindowManager.addView(mDecor, l);
    mShowing = true;
    mQuerying = false;
    mDismissed = false;

    mTrack.startAnimation(mTrackAnim);

    if (TRACE_LAUNCH) {
      android.os.Debug.stopMethodTracing();
      Log.d(
          TAG,
          "Window recycled " + mWindowRecycled + " times, chiclets " + mActionRecycled + " times");
    }
  }