예제 #1
1
  @Override
  public void onCreate() {

    super.onCreate();

    sp = getSharedPreferences("date", 0);
    sp_setting = PreferenceManager.getDefaultSharedPreferences(this);
    sp_userinfo = getSharedPreferences("userinfo", 0);
    C.FRAME = Integer.parseInt(sp_setting.getString("Frame", "60"));
    Wm = (WindowManager) getApplication().getSystemService(Context.WINDOW_SERVICE);
    wmParams = new WindowManager.LayoutParams();
    wmParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
    // 设置悬浮窗为全屏
    wmParams.flags = 1280;
    wmParams.format = PixelFormat.RGBA_8888;
    wmParams.alpha = 0.8f;
    wmParams.gravity = Gravity.LEFT | Gravity.BOTTOM;
    wmParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
    wmParams.height = ViewGroup.LayoutParams.MATCH_PARENT;

    Wm_control = (WindowManager) getApplication().getSystemService(Context.WINDOW_SERVICE);
    wmParams_control = new WindowManager.LayoutParams();
    wmParams_control.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
    wmParams_control.format = PixelFormat.RGB_888;
    wmParams_control.flags =
        WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
            | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
    wmParams_control.alpha = 0;
    wmParams_control.width = 0;
    wmParams_control.height = 0;
    win_control = new View(this);
    Wm_control.addView(win_control, wmParams_control);

    // 注册系统广播
    sr = new ScreenReceiver();
    sr.registerScreenActionReceiver(MSSService.this);
    registerBattery();

    // 注册自己程序的广播
    IntentFilter inf = new IntentFilter();
    inf.addAction("com.jiusg.mainscreenshow");
    mssr = new MSSReceiver();
    registerReceiver(mssr, inf);

    sa_IsEvent = new SparseBooleanArray();
    sa_Animation = new SparseArray<Integer>();
    animManage = new AnimationManage(Wm, wmParams, getApplicationContext());

    isView = false;

    mHandler = new MssHandler();

    imageCache = new ImageCache(getApplicationContext());

    AVAnalytics.onEvent(MSSService.this, "Server Create", TAG);

    startService(new Intent(this, MSSLiveWallpaper.class));
  }
예제 #2
0
  private void setDimAmount(float alpha, float dimAmount) {
    WindowManager.LayoutParams lp = getWindow().getAttributes();
    lp.alpha = alpha;
    lp.dimAmount = dimAmount;

    getWindow().setAttributes(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);
      }
    }
  }
예제 #4
0
  @SuppressWarnings("deprecation")
  private void ErrorDialog(int icon, int title, int content, int makesur) {
    final Builder builder = new AlertDialog.Builder(LoginActivity.this);
    // 设置对话框的图标
    builder.setIcon(icon);
    // 设置对话框的标题
    builder.setTitle(title);
    // 设置对话框的内容
    builder.setMessage(content);
    // 设置对话框的"确定"按钮
    builder.setNegativeButton(
        makesur,
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            System.out.println("IRoundU");
          }
        });
    AlertDialog alertDialog = builder.create();
    // 设置Dialog透明
    Window window = alertDialog.getWindow();
    WindowManager.LayoutParams lp = window.getAttributes();
    // 设置透明度为0.3
    lp.alpha = 0.8f;
    window.setAttributes(lp);
    // Dialog后面的内容会变得模糊
    window.setFlags(
        WindowManager.LayoutParams.FLAG_BLUR_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
    alertDialog.show();
  }
예제 #5
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    context = this;

    // Params for the window.
    // You can easily set the alpha and the dim behind the window from here
    WindowManager.LayoutParams params = getWindow().getAttributes();
    params.alpha = 0.8f; // lower than one makes it more transparent
    params.dimAmount = 0f; // set it higher if you want to dim behind the window
    getWindow().setAttributes(params);

    // Gets the display size so that you can set the window to a percent of that
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x; // assign device display width to var width
    int height = size.y; // assign device display height to var height

    // set the width and height of the app window to multiples of the display dimensions
    getWindow().setLayout((int) (width * .95), (int) (height * .5));

    // Make sure to set your content view AFTER you have set up the window or it will crash.
    setContentView(R.layout.activity_main);
  }
예제 #6
0
  public void setUpWindow() {

    requestWindowFeature(Window.FEATURE_ACTION_BAR);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_DIM_BEHIND, WindowManager.LayoutParams.FLAG_DIM_BEHIND);

    // Params for the window.
    // You can easily set the alpha and the dim behind the window from here
    WindowManager.LayoutParams params = getWindow().getAttributes();
    params.alpha = 1.0f; // lower than one makes it more transparent
    params.dimAmount = .75f; // set it higher if you want to dim behind the window
    getWindow().setAttributes(params);

    // Gets the display size so that you can set the window to a percent of that
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;

    // You could also easily used an integer value from the shared preferences to set the percent
    if (height > width) {
      getWindow().setLayout((int) (width * .9), (int) (height * .8));
    } else {
      getWindow().setLayout((int) (width * .7), (int) (height * .8));
    }
  }
예제 #7
0
  private void dragView(int x, int y) {
    float alpha = 1.0f;
    int width = mDragView.getWidth();

    if (mRemoveMode == SLIDE_RIGHT) {
      if (x > width / 2) {
        alpha = ((float) (width - x)) / (width / 2);
      }
      mWindowParams.alpha = alpha;
    } else if (mRemoveMode == SLIDE_LEFT) {
      if (x < width / 2) {
        alpha = ((float) x) / (width / 2);
      }
      mWindowParams.alpha = alpha;
    }
    mWindowParams.y = y - mDragPoint + mCoordOffset;
    mWindowManager.updateViewLayout(mDragView, mWindowParams);
  }
예제 #8
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);
   }
 }
예제 #9
0
 private void initDragWindowParams() {
   mWindowParams = new WindowManager.LayoutParams();
   mWindowParams.gravity = Gravity.TOP | Gravity.LEFT;
   mWindowParams.alpha = 1.0f;
   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_NO_LIMITS;
   mWindowParams.format = PixelFormat.TRANSLUCENT;
   mWindowParams.windowAnimations = 0;
 }
예제 #10
0
  private void startDrag(Bitmap bm, int x, int y) {
    stopDrag();
    windowParams = new WindowManager.LayoutParams();
    windowParams.gravity = Gravity.TOP | Gravity.LEFT;
    windowParams.x = dragItemView.getLeft() + 8;
    windowParams.y = dragItemView.getTop() + (int) (45 * Configure.screenDensity);
    windowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    windowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
    windowParams.alpha = 0.8f;

    ImageView iv = new ImageView(getContext());
    iv.setImageBitmap(bm);
    windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    windowManager.addView(iv, windowParams);

    dragImageView = iv;
  }
    private void createWindow() {
      LayoutInflater inflater = LayoutInflater.from(mContext);

      mWindowContent = inflater.inflate(R.layout.overlay_display_window, null);
      mWindowContent.setOnTouchListener(mOnTouchListener);

      mTextureView = (TextureView) mWindowContent.findViewById(R.id.overlay_display_window_texture);
      mTextureView.setPivotX(0);
      mTextureView.setPivotY(0);
      mTextureView.getLayoutParams().width = mWidth;
      mTextureView.getLayoutParams().height = mHeight;
      mTextureView.setOpaque(false);
      mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);

      mNameTextView = (TextView) mWindowContent.findViewById(R.id.overlay_display_window_title);
      mNameTextView.setText(mName);

      mWindowParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
      mWindowParams.flags |=
          WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
              | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
              | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
              | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
              | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
      if (DISABLE_MOVE_AND_RESIZE) {
        mWindowParams.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
      }
      mWindowParams.alpha = WINDOW_ALPHA;
      mWindowParams.gravity = Gravity.TOP | Gravity.LEFT;
      mWindowParams.setTitle(mName);

      mGestureDetector = new GestureDetector(mContext, mOnGestureListener);
      mScaleGestureDetector = new ScaleGestureDetector(mContext, mOnScaleGestureListener);

      // Set the initial position and scale.
      // The position and scale will be clamped when the display is first shown.
      mWindowX = (mGravity & Gravity.LEFT) == Gravity.LEFT ? 0 : mDefaultDisplayMetrics.widthPixels;
      mWindowY = (mGravity & Gravity.TOP) == Gravity.TOP ? 0 : mDefaultDisplayMetrics.heightPixels;
      Log.d(TAG, mDefaultDisplayMetrics.toString());
      mWindowScale = INITIAL_SCALE;

      // calculate and save initial settings
      updateWindowParams();
      saveWindowParams();
    }
예제 #12
0
  public void onDrag(int x, int y) {
    if (mViewDragging != null) {
      windowParams.alpha = 0.8f;
      windowParams.x = (x - startDragX - touchOffsetX) + startDragX;
      windowParams.y = (y - startDragY - touchOffsetY) + startDragY;
      mWindowManager.updateViewLayout(mViewDragging, windowParams);
    }

    if (getCurGridView() != null) {
      // 将PagedView的坐标转化为gridView的坐标
      int gridViewX = x - getCurGridView().getDragGridOffsetLeft();
      int gridViewY = y - getCurGridView().getYDragGridOffsetTop();

      int pageX = x;
      int pageY = y;

      if (x > 0 && y > 0 && Configure.isChangingPage == false) {
        getCurGridView().onDrag(mViewDragging, pageX, pageY, gridViewX, gridViewY);
      }
    }
  }
    @Override
    public void show() {
      if (!mWindowVisible) {
        mSurfaceView = new SurfaceView(mContext);

        Display display = mWindowManager.getDefaultDisplay();

        WindowManager.LayoutParams params =
            new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        params.flags |=
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
        params.alpha = WINDOW_ALPHA;
        params.gravity = Gravity.LEFT | Gravity.BOTTOM;
        params.setTitle(mName);

        int width = (int) (display.getWidth() * INITIAL_SCALE);
        int height = (int) (display.getHeight() * INITIAL_SCALE);
        if (mWidth > mHeight) {
          height = mHeight * width / mWidth;
        } else {
          width = mWidth * height / mHeight;
        }
        params.width = width;
        params.height = height;

        mWindowManager.addView(mSurfaceView, params);
        mWindowVisible = true;

        SurfaceHolder holder = mSurfaceView.getHolder();
        holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        mListener.onWindowCreated(holder);
      }
    }
예제 #14
0
 /**
  * 设置dialog的打下和位置 如果 参数为0则不设置
  *
  * @param width 宽度
  * @param height 高度
  * @param x x坐标偏移量
  * @param y y坐标偏移量
  * @param gravity dialog位置 Gravity.CENTER 位于中间 Gravity.TOP位于顶部 等等
  */
 public void setSizeAndPosition(int width, int height, int x, int y, float aplha, int gravity) {
   Window window = getWindow();
   WindowManager.LayoutParams layout = window.getAttributes();
   window.setGravity(gravity);
   if (width == 0) {
     DisplayMetrics dm = new DisplayMetrics();
     window.getWindowManager().getDefaultDisplay().getMetrics(dm);
     width = (int) ((dm.widthPixels) * 0.9); // 宽度height =
   }
   layout.width = width; // 宽度
   if (height > 0) {
     layout.height = height; // 高度
   }
   if (x > 0) {
     layout.x = x; // x坐标
   }
   if (y > 0) {
     layout.y = y; // y坐标
   }
   if (aplha > 0) {
     layout.alpha = 10f; // 透明度
   }
   window.setAttributes(layout);
 }
예제 #15
0
 /** 内容区域变亮 */
 protected void lightOn() {
   WindowManager.LayoutParams lp = getWindow().getAttributes();
   lp.alpha = 1.0f;
   getWindow().setAttributes(lp);
 }
예제 #16
0
 /**
  * 设置添加屏幕的背景透明度
  *
  * @param bgAlpha
  */
 public void backgroundAlpha(float bgAlpha) {
   WindowManager.LayoutParams lp = getWindow().getAttributes();
   lp.alpha = bgAlpha; // 0.0-1.0
   getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
   getWindow().setAttributes(lp);
 }
예제 #17
0
 public void backgroundAlpha(float bgAlpha) {
   WindowManager.LayoutParams lp = getWindow().getAttributes();
   lp.alpha = bgAlpha; // 0.0-1.0
   getWindow().setAttributes(lp);
 }
예제 #18
0
  @Override
  public void onCreate() {
    Log.v(TAG, "onCreate");

    // start specialized listener, depending on how the systembar should
    // show up
    switch (HideBarPreferences.methodToShowBar(this)) {
      case BOTTOM_TOUCH:
        {
          WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
          WindowManager.LayoutParams params =
              new WindowManager.LayoutParams(
                  LayoutParams.MATCH_PARENT,
                  LayoutParams.WRAP_CONTENT,
                  LayoutParams.TYPE_SYSTEM_ALERT,
                  LayoutParams.FLAG_NOT_FOCUSABLE
                      | LayoutParams.FLAG_NOT_TOUCH_MODAL
                      | LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                  PixelFormat.OPAQUE);
          params.alpha = 0.0f;
          params.height = 25;
          params.gravity = Gravity.BOTTOM;
          params.x = 0;
          params.y = 0;
          LinearLayout touchLayout = new LinearLayout(this);
          touchLayout.setBackgroundColor(0x00FFFFFF);
          touchLayout.setLayoutParams(
              new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
          if (HideBarPreferences.ghostbackButton(this)) {
            View backArea = new View(this);
            backArea.setOnTouchListener(
                new View.OnTouchListener() {
                  @Override
                  public boolean onTouch(View v, MotionEvent event) {
                    Log.d(TAG, "backArea touched");
                    Device device = Device.getInstance();
                    device.sendBackEvent();
                    return false;
                  }
                });
            touchLayout.addView(backArea, 40, 25);
          }
          View restoreArea = new View(this);
          restoreArea.setOnTouchListener(
              new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                  Log.d(TAG, "touchArea touched");
                  Device device = Device.getInstance();
                  device.showSystembar(true);
                  return false;
                }
              });
          touchLayout.addView(restoreArea);
          wm.addView(touchLayout, params);
          mTouchAreas.add(touchLayout);
          break;
        }
      case BOTTOM_TOP_TOUCH:
        {
          WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
          WindowManager.LayoutParams params =
              new WindowManager.LayoutParams(
                  LayoutParams.MATCH_PARENT,
                  LayoutParams.WRAP_CONTENT,
                  LayoutParams.TYPE_SYSTEM_ALERT,
                  LayoutParams.FLAG_NOT_FOCUSABLE
                      | LayoutParams.FLAG_NOT_TOUCH_MODAL
                      | LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                  PixelFormat.OPAQUE);
          params.alpha = 0.0f;
          params.height = 25;
          params.gravity = Gravity.BOTTOM;
          params.x = 0;
          params.y = 0;
          LinearLayout bottomLayout = new LinearLayout(this);
          bottomLayout.setBackgroundColor(0x00FFFFFF);
          bottomLayout.setLayoutParams(
              new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
          if (HideBarPreferences.ghostbackButton(this)) {
            View backArea = new View(this);
            backArea.setOnTouchListener(
                new View.OnTouchListener() {
                  @Override
                  public boolean onTouch(View v, MotionEvent event) {
                    Log.d(TAG, "backArea touched");
                    Device device = Device.getInstance();
                    device.sendBackEvent();
                    return false;
                  }
                });
            bottomLayout.addView(backArea, 40, 25);
          }
          View bottomArea = new View(this);
          bottomArea.setOnTouchListener(
              new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                  Log.d(TAG, "bottomArea touched");
                  mBottomTouchTime = SystemClock.uptimeMillis();
                  if (Math.abs(mBottomTouchTime - mTopTouchTime) < 2000) {
                    Device device = Device.getInstance();
                    device.showSystembar(true);
                  }
                  return false;
                }
              });
          bottomLayout.addView(bottomArea);
          wm.addView(bottomLayout, params);
          mTouchAreas.add(bottomLayout);

          params.gravity = Gravity.TOP;
          LinearLayout topLayout = new LinearLayout(this);
          topLayout.setBackgroundColor(0x00FFFFFF);
          topLayout.setLayoutParams(
              new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
          View topArea = new View(this);
          topArea.setOnTouchListener(
              new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                  Log.d(TAG, "topArea touched");
                  mTopTouchTime = SystemClock.uptimeMillis();
                  if (Math.abs(mBottomTouchTime - mTopTouchTime) < 2000) {
                    Device device = Device.getInstance();
                    device.showSystembar(true);
                  }
                  return false;
                }
              });
          topLayout.addView(topArea);
          wm.addView(topLayout, params);
          mTouchAreas.add(topLayout);
          break;
        }
      case NONE:
        break;
    }
  }
예제 #19
0
 /**
  * 设置activity透明度
  *
  * @param context
  * @param alpha
  */
 public static void setActivityAlpha(final Context context, float alpha) {
   // 还原透明效果
   WindowManager.LayoutParams params = ((Activity) context).getWindow().getAttributes();
   params.alpha = alpha;
   ((Activity) context).getWindow().setAttributes(params);
 }
예제 #20
0
 protected void windowdismiss() {
   param.alpha = 1f;
   context.getWindow().setAttributes(param);
   this.dismiss();
 }
예제 #21
0
  protected void init() {
    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    view = inflater.inflate(R.layout.popupwindow, null);
    this.setContentView(view);
    // 设置SelectPicPopupWindow弹出窗体的宽
    this.setWidth(LayoutParams.MATCH_PARENT);
    // 设置SelectPicPopupWindow弹出窗体的高
    this.setHeight(LayoutParams.WRAP_CONTENT);

    this.setFocusable(true);

    this.setAnimationStyle(R.style.popupwin); // 设置进出动画

    param = context.getWindow().getAttributes();
    param.alpha = 0.7f;
    context.getWindow().setAttributes(param);

    button1 = (Button) view.findViewById(R.id.button1);
    button2 = (Button) view.findViewById(R.id.button2);
    dismiss = (Button) view.findViewById(R.id.dismissbutton);

    switch (id) {
      case REPLY:
        button1.setText("回复");
        button2.setText("转发");
        break;
      case SIGN:
        button1.setText("标为未读");
        button2.setText("添加星标");
        break;

      default:
        break;
    }

    button1.setOnClickListener(onClickListener);
    button2.setOnClickListener(onClickListener);

    dismiss.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            windowdismiss();
          }
        });

    view.setOnTouchListener(
        new View.OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            int heigth = view.findViewById(R.id.popupwinlayout).getTop();
            int ydown = (int) event.getRawY();
            System.out.println(heigth + "   " + ydown);
            if (event.getAction() == MotionEvent.ACTION_UP) {
              if (ydown > heigth) {
                windowdismiss();
              }
            }
            return false;
          }
        });
  }
  private void dragView(int x, int y) {
    // Log.d("mobeta", "float view pure x=" + x + " y=" + y);
    if (mRemoveMode == SLIDE) {
      float alpha = 1.0f;
      int width = mFloatView.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 = mXOffset + getPaddingLeft();
    }

    // keep floating view from going past bottom of last header view
    final int numHeaders = getHeaderViewsCount();
    final int numFooters = getFooterViewsCount();
    final int firstPos = getFirstVisiblePosition();
    final int lastPos = getLastVisiblePosition();
    // Log.d("mobeta",
    // "nHead="+numHeaders+" nFoot="+numFooters+" first="+firstPos+" last="+lastPos);
    int limit = getPaddingTop();
    if (firstPos < numHeaders) {
      limit = getChildAt(numHeaders - firstPos - 1).getBottom();
    }
    int footerLimit = getHeight() - getPaddingBottom();
    if (lastPos >= getCount() - numFooters) {
      // get top-most footer view
      footerLimit = getChildAt(getCount() - numFooters - firstPos).getTop();
      // footerLimit = getChildAt(getChildCount() - 1 - lastPos +
      // getCount() - numFooters).getTop();
    }

    // Log.d("mobeta", "dragView top=" + (y - mDragPointY));
    // Log.d("mobeta", "limit=" + limit);
    // Log.d("mobeta", "mDragPointY=" + mDragPointY);
    if (y - mDragPointY < limit) {
      mWindowParams.y = mYOffset + limit;
    } else if (y - mDragPointY + mFloatViewHeight > footerLimit) {
      mWindowParams.y = mYOffset + footerLimit - mFloatViewHeight;
    } else {
      mWindowParams.y = y - mDragPointY + mYOffset;
    }
    // Log.d("mobeta", "float view taint x=" + mWindowParams.x + " y=" +
    // mWindowParams.y);
    mWindowManager.updateViewLayout(mFloatView, mWindowParams);

    if (mTrashcan != null) {
      int width = mFloatView.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 backgroundDarken() {
   // 设置背景颜色变暗
   WindowManager.LayoutParams lp = getWindow().getAttributes();
   lp.alpha = 0.6f;
   getWindow().setAttributes(lp);
 }
예제 #24
0
 /** Create the custom dialog */
 public CustomDialog create() {
   LayoutInflater inflater =
       (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   // instantiate the dialog with the custom Theme
   final CustomDialog dialog = new CustomDialog(context, R.style.Dialog);
   WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
   lp.alpha = 0.9f;
   dialog.getWindow().setAttributes(lp);
   dialog.setCanceledOnTouchOutside(false);
   View layout = inflater.inflate(R.layout.custom_dialog_layout, null);
   dialog.addContentView(
       layout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
   // set the dialog title
   ((TextView) layout.findViewById(R.id.title)).setText(title);
   ((LinearLayout) layout.findViewById(R.id.lineGray)).setVisibility(isGone);
   ;
   // set the confirm button
   if (positiveButtonText != null) {
     ((Button) layout.findViewById(R.id.positiveButton)).setText(positiveButtonText);
     if (positiveButtonClickListener != null) {
       ((Button) layout.findViewById(R.id.positiveButton))
           .setOnClickListener(
               new View.OnClickListener() {
                 public void onClick(View v) {
                   positiveButtonClickListener.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
                 }
               });
     }
   } else {
     // if no confirm button just set the visibility to GONE
     layout.findViewById(R.id.positiveButton).setVisibility(View.GONE);
   }
   // set the cancel button
   if (negativeButtonText != null) {
     ((Button) layout.findViewById(R.id.negativeButton)).setText(negativeButtonText);
     if (negativeButtonClickListener != null) {
       ((Button) layout.findViewById(R.id.negativeButton))
           .setOnClickListener(
               new View.OnClickListener() {
                 public void onClick(View v) {
                   negativeButtonClickListener.onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
                 }
               });
     }
   } else {
     // if no confirm button just set the visibility to GONE
     layout.findViewById(R.id.negativeButton).setVisibility(View.GONE);
   }
   // set the content message
   if (message != null) {
     ((TextView) layout.findViewById(R.id.message)).setText(message);
   } else if (contentView != null) {
     // if no message set
     // add the contentView to the dialog body
     ((LinearLayout) layout.findViewById(R.id.content)).removeAllViews();
     ((LinearLayout) layout.findViewById(R.id.content))
         .addView(
             contentView,
             new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
   }
   dialog.setContentView(layout);
   return dialog;
 }
 private void backgroundRecovery() {
   WindowManager.LayoutParams lp = getWindow().getAttributes();
   lp.alpha = 1.0f;
   getWindow().setAttributes(lp);
 }
예제 #26
0
 public static void backgroundAlpha(float bgAlpha, Activity ctx) {
   WindowManager.LayoutParams lp = ctx.getWindow().getAttributes();
   lp.alpha = bgAlpha; // 0.0-1.0
   ctx.getWindow().setAttributes(lp);
 }