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 bitmap, int y) {
    stopDragging();

    if (bitmap.getHeight() > maximumDragViewHeight) {
      bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), maximumDragViewHeight);
    }

    ImageView imageView = getGlowingBorder(bitmap);

    WindowManager.LayoutParams dragViewParameters = createLayoutParameters();
    if (isScrolling) {
      isScrolling = false;

      dragViewParameters.y = getHeight() / 2 - bitmap.getHeight() / 2;
    } else {
      dragViewParameters.y = y - bitmap.getHeight() / 2;
    }
    dragViewParameters.windowAnimations = R.style.brick_new;

    WindowManager windowManager = getWindowManager();

    windowManager.addView(imageView, dragViewParameters);

    dragView = imageView;
  }
    /** アニメーションの処理を行います。 */
    @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;
  }
Beispiel #5
0
  // Update the dynamic parts of mDecorLayoutParams
  // Must be called with mAnchor != NULL.
  private void updateFloatingWindowLayout() {
    int[] anchorPos = new int[2];
    mAnchor.getLocationOnScreen(anchorPos);

    WindowManager.LayoutParams p = mDecorLayoutParams;
    if (p != null) {
      p.width = mAnchor.getWidth();
      p.y = anchorPos[1] + mAnchor.getHeight();
      p.y -= mHeight;
    }
  }
  /**
   * 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");
    }
  }
 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);
   }
 }
Beispiel #8
0
  protected void showErrorDialog(View view, boolean cancelable) {
    if (getActivity().isFinishing()) return;

    if (mErrorDialog == null) {
      mErrorDialog = new AlertDialog.Builder(mContext, R.style.error_dialog).create();
      mErrorDialog.setCancelable(cancelable);
      mErrorDialog.setCanceledOnTouchOutside(cancelable);
    }
    mErrorDialog.show();
    Window window = mErrorDialog.getWindow();
    window.setGravity(Gravity.CENTER | Gravity.BOTTOM);
    window.setContentView(view);
    window.setWindowAnimations(R.style.animation_error_dialog);
    int width = (int) (ScreenUtils.getScreenW(mContext) * 5 / 6f);
    WindowManager.LayoutParams wmlp = window.getAttributes();
    wmlp.gravity = Gravity.CENTER | Gravity.BOTTOM;
    wmlp.y = 200;
    window.setLayout(width, ViewGroup.LayoutParams.WRAP_CONTENT);

    executor.schedule(
        new Runnable() {
          @Override
          public void run() {
            dismissErrorDialog();
          }
        },
        5,
        TimeUnit.SECONDS);
  }
  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;
  }
  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;
  }
 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);
   }
 }
Beispiel #12
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;
  }
  /**
   * 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);
    }
  }
  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);
  }
  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);
      }
    }
  }
  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;
  }
 @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 updateWindowAttributes() {
   final Window window = getWindow();
   final WindowManager.LayoutParams attributes = window.getAttributes();
   attributes.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
   attributes.y = mSystemWindowsInsets.top;
   window.setAttributes(attributes);
 }
Beispiel #19
0
 /*
  * For some reason, it's very difficult to create a layout that covers exactly the entire screen
  * and doesn't move when an unhandled key is pressed. The configuration we're using seems to
  * result in a layout that starts above the screen. So we split initialization into two
  * pieces, and here we find out where the overlay ended up and move it to be at the top
  * of the screen.
  * TODO(pweaver) Separating the menu and highlighting should be a cleaner way to solve this
  * issue
  */
 private void configureOverlayAfterShow() {
   int[] location = new int[2];
   mRelativeLayout.getLocationOnScreen(location);
   WindowManager.LayoutParams layoutParams = mOverlay.getParams();
   layoutParams.y -= location[1];
   mOverlay.setParams(layoutParams);
 }
  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;
  }
Beispiel #21
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();
   }
 }
  /** 画面サイズから自位置を決定します。 */
  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);
    }
  }
 /** 初回描画時の座標設定を行います。 */
 @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;
 }
 protected void reduceToTriggerRegion() {
   mLayoutParams = (WindowManager.LayoutParams) getLayoutParams();
   mLayoutParams.y = mTriggerTop;
   mLayoutParams.height = mTriggerBottom;
   mLayoutParams.width = mTriggerWidth;
   mLayoutParams.flags = disableKeyEvents();
   mWM.updateViewLayout(this, mLayoutParams);
 }
Beispiel #25
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);
 }
    @Override
    /** 监听电话状态 */
    public void onCallStateChanged(int state, String incomingNumber) {
      // TODO Auto-generated method stub
      super.onCallStateChanged(state, incomingNumber);
      switch (state) {
        case TelephonyManager.CALL_STATE_RINGING:
          if (serviceState) {
            boolean falg = new BlackNumDao(ShowAddressService.this).find(incomingNumber);
            if (falg) {
              ringOff();
              getContentResolver()
                  .registerContentObserver(
                      CallLog.Calls.CONTENT_URI,
                      true,
                      new CallLogChangeObserver(new Handler(), incomingNumber));
              return;
            }
          }

          String value = AddressService.getAddressService(incomingNumber);
          view = inflater.inflate(R.layout.show_phone_address, null);
          TextView address_tv = (TextView) view.findViewById(R.id.show_phone_address_address);
          TextView phone_tv = (TextView) view.findViewById(R.id.show_phone_address_phone);
          address_tv.setText(value);
          String phoneName =
              new MyContentProvider(ShowAddressService.this).getPhoneName(incomingNumber);
          if (phoneName != null) {
            phone_tv.setText(phoneName);
          } else {
            phone_tv.setText(incomingNumber);
          }

          WindowManager.LayoutParams params = new LayoutParams();
          params.height = WindowManager.LayoutParams.WRAP_CONTENT + 70;
          params.width = WindowManager.LayoutParams.WRAP_CONTENT + 200;

          params.y = params.y + 23;
          new Thread(new SaveParamsCoord(params.x, params.y, params.width, params.height)).start();
          params.flags =
              WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                  | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                  | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
          params.format = PixelFormat.TRANSLUCENT;
          params.type = WindowManager.LayoutParams.TYPE_TOAST;
          params.setTitle("Toast");

          windowManager.addView(view, params);
          break;
        case TelephonyManager.CALL_STATE_IDLE:
          if (view != null) {
            windowManager.removeView(view);
            view = null;
          }
        default:
          break;
      }
    }
Beispiel #27
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);
 }
Beispiel #28
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);
   }
 }
  /**
   * Adjust vertical {@link WindowManager.LayoutParams} to fit window as best as possible, shifting
   * up to display content as needed.
   */
  private void layoutInScreen() {
    if (!mShowing) return;

    final WindowManager.LayoutParams l = mWindow.getAttributes();
    final int originalY = l.y;

    final int blockHeight = mDecor.getHeight();

    l.y = mRequestedY;
    if (mRequestedY + blockHeight > mScreenHeight) {
      // Shift up from bottom when overflowing
      l.y = mScreenHeight - blockHeight;
    }

    if (originalY != l.y) {
      // Only update when value is changed
      mWindow.setAttributes(l);
    }
  }
 protected void setTopPercentage(float value) {
   mLayoutParams = (WindowManager.LayoutParams) this.getLayoutParams();
   mTriggerTop = (int) (mViewHeight * value);
   mLayoutParams.y = mTriggerTop;
   mLayoutParams.height = mTriggerBottom;
   try {
     mWM.updateViewLayout(this, mLayoutParams);
   } catch (Exception e) {
   }
 }