Java Code Examples for android.graphics.PixelFormat#RGBA_8888

The following examples show how to use android.graphics.PixelFormat#RGBA_8888 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DragGridView.java    From DragGridView with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化window
 */
private void initWindow() {
    if (dragView == null) {
        dragView = View.inflate(getContext(), R.layout.drag_item, null);
        TextView tv_text = (TextView) dragView.findViewById(R.id.tv_text);
        tv_text.setText(((TextView) view.findViewById(R.id.tv_text)).getText());
    }
    if (layoutParams == null) {
        layoutParams = new WindowManager.LayoutParams();
        layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;
        layoutParams.format = PixelFormat.RGBA_8888;
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;  //悬浮窗的行为,比如说不可聚焦,非模态对话框等等
        layoutParams.width = view.getWidth();
        layoutParams.height = view.getHeight();
        layoutParams.x = view.getLeft() + this.getLeft();  //悬浮窗X的位置
        layoutParams.y = view.getTop() + this.getTop();  //悬浮窗Y的位置
        view.setVisibility(INVISIBLE);
    }

    mWindowManager.addView(dragView, layoutParams);
    mode = MODE_DRAG;
}
 
Example 2
Source File: VNCServer.java    From CatVision-io-SDK-Android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void push(Image image, int pixelFormat) {
	Image.Plane[] planes = image.getPlanes();
	ByteBuffer b = planes[0].getBuffer();
	if (pixelFormat == PixelFormat.RGBA_8888) {
		// planes[0].getPixelStride() has to be 4 (32 bit)
		jni_push_pixels_rgba_8888(b, planes[0].getRowStride());
	}
	else if (pixelFormat == PixelFormat.RGB_565)
	{
		// planes[0].getPixelStride() has to be 16 (16 bit)
		jni_push_pixels_rgba_565(b, planes[0].getRowStride());
	}
	else
	{
		Log.e(TAG, "Image reader acquired unsupported image format " + pixelFormat);
	}
}
 
Example 3
Source File: ClickableToast.java    From Overchan-Android with GNU General Public License v3.0 6 votes vote down vote up
public WindowManager.LayoutParams getWmParams(){
    WindowManager.LayoutParams params = new WindowManager.LayoutParams();
    params.height = WindowManager.LayoutParams.WRAP_CONTENT;
    params.width = WindowManager.LayoutParams.WRAP_CONTENT;
    params.alpha = 1;
    params.format = PixelFormat.RGBA_8888;
    if (gravityTop) {
        params.gravity = Gravity.TOP;
    } else {
        params.gravity = Gravity.BOTTOM;
        params.verticalMargin = isNarrow() ? 0.05f : 0.07f;
    }
    params.flags =  WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
    //params.type = WindowManager.LayoutParams.LAST_SYSTEM_WINDOW + 30;
    try {
        if (internalResources == null) internalResources = Resources.getSystem();
        params.windowAnimations = internalResources.getIdentifier("Animation.Toast", "style", "android");
        params.y = getResources().getDimensionPixelSize(internalResources.getIdentifier("toast_y_offset", "dimen", "android"));
    } catch (Exception e) {
        Logger.e(TAG, e);
    }
    return params;
}
 
Example 4
Source File: ActivityTask.java    From ActivityTaskView with Apache License 2.0 6 votes vote down vote up
private static void addViewToWindow(Context context, View view) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    WindowManager.LayoutParams params = new WindowManager.LayoutParams();
    if (Build.VERSION.SDK_INT >= 26) {// Android 8.0
        params.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
    } else {
        params.type = WindowManager.LayoutParams.TYPE_PHONE;
    }
    params.format = PixelFormat.RGBA_8888;
    params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
    params.width = WindowManager.LayoutParams.WRAP_CONTENT;
    params.height = WindowManager.LayoutParams.WRAP_CONTENT;
    params.gravity = Gravity.START | Gravity.TOP;
    params.x = 0;
    params.y = context.getResources().getDisplayMetrics().heightPixels - 500;
    if (windowManager != null) {
        windowManager.addView(view, params);
    }
}
 
Example 5
Source File: SideBarArrow.java    From AndroidSideBar with Apache License 2.0 5 votes vote down vote up
public LinearLayout getView(Context context,boolean left,WindowManager windowManager,SideBarService sideBarService) {
    mContext = context;
    mLeft = left;
    mWindowManager = windowManager;
    mSideBarService = sideBarService;
    mParams = new WindowManager.LayoutParams();
    // compatible
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        mParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
    } else {
        mParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
    }
    // set bg transparent
    mParams.format = PixelFormat.RGBA_8888;
    // can not focusable
    mParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
    mParams.x = 0;
    mParams.y = 0;
    // window size
    mParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
    mParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    // get layout
    LayoutInflater inflater = LayoutInflater.from(context);
    mArrowView = (LinearLayout) inflater.inflate(R.layout.layout_arrow, null);
    AppCompatImageView arrow = mArrowView.findViewById(R.id.arrow);
    arrow.setOnClickListener(this);
    if(left) {
        arrow.setRotation(180);
        mParams.gravity = Gravity.START | Gravity.CENTER_VERTICAL;
        mParams.windowAnimations = R.style.LeftSeekBarAnim;
    }else {
        mParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
        mParams.windowAnimations = R.style.RightSeekBarAnim;
    }
    mWindowManager.addView(mArrowView,mParams);
    return mArrowView;
}
 
Example 6
Source File: DeviceDisplayInfo.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings("deprecation")
private int getPixelFormat() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return getDisplay().getPixelFormat();
    }
    // JellyBean MR1 and later always uses RGBA_8888.
    return PixelFormat.RGBA_8888;
}
 
Example 7
Source File: FloatView.java    From settingscompat with Apache License 2.0 5 votes vote down vote up
public FloatView(Context context) {
    super(context);

    getWindowVisibleDisplayFrame(mRect);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    mTouchSlop = mTouchSlop * mTouchSlop;


    mWm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    mLp.gravity = Gravity.LEFT | Gravity.TOP;
    mLp.format = PixelFormat.RGBA_8888;
    mLp.width = WindowManager.LayoutParams.WRAP_CONTENT;
    mLp.height = WindowManager.LayoutParams.WRAP_CONTENT;
    mLp.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        mLp.type = WindowManager.LayoutParams.TYPE_TOAST;
    } else {
        mLp.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
    }


    setOnClickListener(mClickListener);
    setOnTouchListener(mTouchListener);
    setImageResource(R.mipmap.ic_launcher);

}
 
Example 8
Source File: MainActivity.java    From TeachMask with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);

	windowManager = getWindowManager();

	// 动态初始化图层
	img = new ImageView(this);
	img.setLayoutParams(new LayoutParams(
			android.view.ViewGroup.LayoutParams.MATCH_PARENT,
			android.view.ViewGroup.LayoutParams.MATCH_PARENT));
	img.setScaleType(ScaleType.FIT_XY);
	img.setImageResource(R.drawable.guide);

	// 设置LayoutParams参数
	LayoutParams params = new WindowManager.LayoutParams();
	// 设置显示的类型,TYPE_PHONE指的是来电话的时候会被覆盖,其他时候会在最前端,显示位置在stateBar下面,其他更多的值请查阅文档
	params.type = WindowManager.LayoutParams.TYPE_PHONE;
	// 设置显示格式
	params.format = PixelFormat.RGBA_8888;
	// 设置对齐方式
	params.gravity = Gravity.LEFT | Gravity.TOP;
	// 设置宽高
	params.width = ScreenUtils.getScreenWidth(this);
	params.height = ScreenUtils.getScreenHeight(this);

	// 添加到当前的窗口上
	windowManager.addView(img, params);

	// 点击图层之后,将图层移除
	img.setOnClickListener(new OnClickListener() {

		@Override
		public void onClick(View arg0) {
			windowManager.removeView(img);
		}
	});

}
 
Example 9
Source File: FloatWindowSmallView.java    From FloatWindow with Apache License 2.0 5 votes vote down vote up
/**
 * 构造函数
 * 
 * @param context
 *            上下文对象
 * @param layoutResId
 *            布局资源id
 * @param rootLayoutId
 *            根布局id
 */
public FloatWindowSmallView(Context context, int layoutResId,
		int rootLayoutId) {
	super(context);
	windowManager = (WindowManager) context
			.getSystemService(Context.WINDOW_SERVICE);
	LayoutInflater.from(context).inflate(layoutResId, this);
	View view = findViewById(rootLayoutId);
	viewWidth = view.getLayoutParams().width;
	viewHeight = view.getLayoutParams().height;

	statusBarHeight = getStatusBarHeight();

	TextView percentView = (TextView) findViewById(R.id.percent);
	percentView.setText("悬浮窗");

	smallWindowParams = new WindowManager.LayoutParams();
	// 设置显示类型为phone
	smallWindowParams.type = WindowManager.LayoutParams.TYPE_PHONE;
	// 显示图片格式
	smallWindowParams.format = PixelFormat.RGBA_8888;
	// 设置交互模式
	smallWindowParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
			| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
	// 设置对齐方式为左上
	smallWindowParams.gravity = Gravity.LEFT | Gravity.TOP;
	smallWindowParams.width = viewWidth;
	smallWindowParams.height = viewHeight;
	smallWindowParams.x = ScreenUtils.getScreenWidth(context);
	smallWindowParams.y = ScreenUtils.getScreenHeight(context) / 2;

}
 
Example 10
Source File: FloatWindowsService.java    From ScreenCapture with Apache License 2.0 5 votes vote down vote up
private void createFloatView() {
  mGestureDetector = new GestureDetector(getApplicationContext(), new FloatGestrueTouchListener());
  mLayoutParams = new WindowManager.LayoutParams();
  mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);

  DisplayMetrics metrics = new DisplayMetrics();
  mWindowManager.getDefaultDisplay().getMetrics(metrics);
  mScreenDensity = metrics.densityDpi;
  mScreenWidth = metrics.widthPixels;
  mScreenHeight = metrics.heightPixels;

  mLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
  mLayoutParams.format = PixelFormat.RGBA_8888;
  // 设置Window flag
  mLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
      | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
  mLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
  mLayoutParams.x = mScreenWidth;
  mLayoutParams.y = 100;
  mLayoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
  mLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;


  mFloatView = new ImageView(getApplicationContext());
  mFloatView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_imagetool_crop));
  mWindowManager.addView(mFloatView, mLayoutParams);


  mFloatView.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
      return mGestureDetector.onTouchEvent(event);
    }
  });

}
 
Example 11
Source File: DragView.java    From timecat with Apache License 2.0 5 votes vote down vote up
private void show() {
    mLayoutParams = new WindowManager.LayoutParams();
    mLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL;
    mLayoutParams.format = PixelFormat.RGBA_8888;
    mLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
    mLayoutParams.flags = mLayoutParams.flags | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
    mLayoutParams.flags = mLayoutParams.flags | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
    mLayoutParams.gravity = Gravity.START | Gravity.TOP;

    mLayoutParams.x = 0;
    mLayoutParams.y = 0;

    DisplayMetrics dm = new DisplayMetrics();
    WindowManager manager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    manager.getDefaultDisplay().getMetrics(dm);

    mLayoutParams.width = dm.widthPixels;
    mLayoutParams.height = dm.heightPixels;
    layout = new FrameLayout(getContext());
    mWindowManager.addView(layout, mLayoutParams);

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(layoutWidth, layoutHeight);
    setX(mCreateX);
    setY(mCreateY);
    layout.addView(this, params);

    mTargetView.setVisibility(INVISIBLE);
}
 
Example 12
Source File: FloatbarService.java    From CircleFloatBar with Apache License 2.0 5 votes vote down vote up
private void createFloatBarView() {
    displayHeight = getResources().getDisplayMetrics().heightPixels;
    displayWidth = getResources().getDisplayMetrics().widthPixels;
    defaultX = displayWidth * 0.9f;
    defaultY = displayHeight / 2;

    thresholdX = (int)(getResources().getDisplayMetrics().widthPixels * 0.1f);
    thresholdY = (int)(getResources().getDisplayMetrics().heightPixels * 0.1f);

    wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    params = new WindowManager.LayoutParams();
    if(Build.VERSION.SDK_INT>=26){
        params.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
    }else{
        params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
    }
    params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
    params.gravity = Gravity.LEFT | Gravity.TOP;
    params.x = (int) (displayHeight * 0.9f);
    params.y = displayWidth / 2;
    params.width = WindowManager.LayoutParams.WRAP_CONTENT;
    params.height = WindowManager.LayoutParams.WRAP_CONTENT;
    params.format = PixelFormat.RGBA_8888;
    //for get showmenuview width & height
    wm.addView(showMenuView, params);
    wm.removeView(showMenuView);

    wm.addView(hideMenuView, params);


}
 
Example 13
Source File: FloatView.java    From LLApp with Apache License 2.0 5 votes vote down vote up
private void init(Context mContext) {
    this.mContext = mContext;

    mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    // 更新浮动窗口位置参数 靠边
    DisplayMetrics dm = new DisplayMetrics();
    // 获取屏幕信息
    mWindowManager.getDefaultDisplay().getMetrics(dm);
    mScreenWidth = dm.widthPixels;
    mScreenHeight = dm.heightPixels;
    Log.e("FloatView-----","宽"+mScreenWidth+"----"+"高"+mScreenHeight);
    this.mWmParams = new WindowManager.LayoutParams();
    // 设置window type
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        mWmParams.type = WindowManager.LayoutParams.TYPE_TOAST;
    } else {
        mWmParams.type = WindowManager.LayoutParams.TYPE_PHONE;
    }
    // 设置图片格式,效果为背景透明
    mWmParams.format = PixelFormat.RGBA_8888;
    // 设置浮动窗口不可聚焦(实现操作除浮动窗口外的其他可见窗口的操作)
    mWmParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
    // 调整悬浮窗显示的停靠位置为左侧置�?
    mWmParams.gravity = Gravity.LEFT | Gravity.TOP;

    mScreenHeight = mWindowManager.getDefaultDisplay().getHeight();

    // 以屏幕左上角为原点,设置x、y初始值,相对于gravity
    mWmParams.x = 0;
    mWmParams.y = mScreenHeight / 2;

    // 设置悬浮窗口长宽数据
    mWmParams.width = LayoutParams.WRAP_CONTENT;
    mWmParams.height = LayoutParams.WRAP_CONTENT;
    addView(createView(mContext));
    mWindowManager.addView(this, mWmParams);

    mTimer = new Timer();
    hide();
}
 
Example 14
Source File: LiveMainActivity.java    From KSYMediaPlayer_Android with Apache License 2.0 5 votes vote down vote up
private void createFloatingWindow(Context context) {
    if (context == null)
        return;

    WindowManager windowManager = getWindowManager(context);
    int screenWidth = windowManager.getDefaultDisplay().getWidth();
    int screenHeight = windowManager.getDefaultDisplay().getHeight();
    if (mFloatingView == null) {
        mFloatingView = new FloatWindowView(context);
        mFloatingView.addFloatingWindow(FloatingPlayer.getInstance().getKSYTextureView());
        mFloatingView.setHandler(mHandler);
        if (mFloatingViewParams == null) {
            mFloatingViewParams = new WindowManager.LayoutParams();
            mFloatingViewParams.type = WindowManager.LayoutParams.TYPE_TOAST;
            mFloatingViewParams.format = PixelFormat.RGBA_8888;
            mFloatingViewParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
                    WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
            mFloatingViewParams.gravity = Gravity.LEFT | Gravity.TOP;
            mFloatingViewParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
            mFloatingViewParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
            mFloatingViewParams.x = screenWidth;
            mFloatingViewParams.y = screenHeight;
        }

        mFloatingView.updateViewLayoutParams(mFloatingViewParams);
        windowManager.addView(mFloatingView, mFloatingViewParams);
    }
}
 
Example 15
Source File: FloatingPlayingActivity.java    From KSYMediaPlayer_Android with Apache License 2.0 5 votes vote down vote up
private void createFloatingWindow(Context context) {
    if (context == null)
        return;

    WindowManager windowManager = getWindowManager(context);
    int screenWidth = windowManager.getDefaultDisplay().getWidth();
    int screenHeight = windowManager.getDefaultDisplay().getHeight();
    if (mFloatingView == null) {
        mFloatingView = new KSYFloatingWindowView(context);
        mFloatingView.setHandler(mHandler);
        if (mFloatingViewParams == null) {
            mFloatingViewParams = new WindowManager.LayoutParams();
            mFloatingViewParams.type = WindowManager.LayoutParams.TYPE_TOAST;
            mFloatingViewParams.format = PixelFormat.RGBA_8888;
            mFloatingViewParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
                    WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
            mFloatingViewParams.gravity = Gravity.LEFT | Gravity.TOP;
            mFloatingViewParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
            mFloatingViewParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
            mFloatingViewParams.x = screenWidth;
            mFloatingViewParams.y = screenHeight;
        }

        mFloatingView.updateViewLayoutParams(mFloatingViewParams);
        windowManager.addView(mFloatingView, mFloatingViewParams);
    }
}
 
Example 16
Source File: DeviceDisplayInfo.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @return Bits per component.
 */
@SuppressWarnings("deprecation")
@CalledByNative
public int getBitsPerComponent() {
    int format = getPixelFormat();
    switch (format) {
    case PixelFormat.RGBA_4444:
        return 4;

    case PixelFormat.RGBA_5551:
        return 5;

    case PixelFormat.RGBA_8888:
    case PixelFormat.RGBX_8888:
    case PixelFormat.RGB_888:
        return 8;

    case PixelFormat.RGB_332:
        return 2;

    case PixelFormat.RGB_565:
        return 5;

    // Non-RGB formats.
    case PixelFormat.A_8:
    case PixelFormat.LA_88:
    case PixelFormat.L_8:
        return 0;

    // Unknown format. Use 8 as a sensible default.
    default:
        return 8;
    }
}
 
Example 17
Source File: Sprite.java    From RxTools-master with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("WrongConstant")
@Override
public int getOpacity() {
    return PixelFormat.RGBA_8888;
}
 
Example 18
Source File: StreamConfigurationMap.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private String formatToString(int format) {
    switch (format) {
        case ImageFormat.YV12:
            return "YV12";
        case ImageFormat.YUV_420_888:
            return "YUV_420_888";
        case ImageFormat.NV21:
            return "NV21";
        case ImageFormat.NV16:
            return "NV16";
        case PixelFormat.RGB_565:
            return "RGB_565";
        case PixelFormat.RGBA_8888:
            return "RGBA_8888";
        case PixelFormat.RGBX_8888:
            return "RGBX_8888";
        case PixelFormat.RGB_888:
            return "RGB_888";
        case ImageFormat.JPEG:
            return "JPEG";
        case ImageFormat.YUY2:
            return "YUY2";
        case ImageFormat.Y8:
            return "Y8";
        case ImageFormat.Y16:
            return "Y16";
        case ImageFormat.RAW_SENSOR:
            return "RAW_SENSOR";
        case ImageFormat.RAW_PRIVATE:
            return "RAW_PRIVATE";
        case ImageFormat.RAW10:
            return "RAW10";
        case ImageFormat.DEPTH16:
            return "DEPTH16";
        case ImageFormat.DEPTH_POINT_CLOUD:
            return "DEPTH_POINT_CLOUD";
        case ImageFormat.RAW_DEPTH:
            return "RAW_DEPTH";
        case ImageFormat.PRIVATE:
            return "PRIVATE";
        default:
            return "UNKNOWN";
    }
}
 
Example 19
Source File: FlowLayout.java    From ReadMark with Apache License 2.0 4 votes vote down vote up
private void initWindow(){
    if(mDragView == null){
        mDragView = View.inflate(getContext(), R.layout.textview_tag, null);
        ImageView cross = (ImageView) mDragView.findViewById(R.id.tag_close);
        cross.setVisibility(INVISIBLE);
        TextView tv = (TextView) mDragView.findViewById(R.id.tag_textview);
        tv.setText(((TextView)mOldView.findViewById(R.id.tag_textview)).getText());
    }
    if(mWindowLayoutParams == null){
        mWindowLayoutParams = new WindowManager.LayoutParams();

        mWindowLayoutParams.width = mOldView.getWidth();
        mWindowLayoutParams.height = mOldView.getHeight();

        //这里的坐标取值还是有点问题
        //暂时没有发现问题所在
        Rect rect = new Rect();

        mOldView.getGlobalVisibleRect(rect);
        mWindowLayoutParams.x = rect.left;
        mWindowLayoutParams.y = rect.top;

        /*int[] co = new int[2];
        mOldView.getLocationInWindow(co);
        mWindowLayoutParams.x = co[0];
        mWindowLayoutParams.y = co[1];*/

        /*mWindowLayoutParams.x = mOldView.getLeft() + this.getLeft();
        mWindowLayoutParams.y = mOldView.getTop() + this.getTop();*/

        //系统Window无需Activity的Context
        mWindowLayoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;
        mWindowLayoutParams.format = PixelFormat.RGBA_8888;
        mWindowLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;

        //window外的touch事件交给下层window处理,window内的自身处理。
        //本身不聚焦,将touch事件交给下层window处理。
        mWindowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;

    }
    //该window中的View开始绘制,并通知wms保存window状态
    mWindowManager.addView(mDragView, mWindowLayoutParams);
    mMode = MODE_DRAG;

}
 
Example 20
Source File: WindowPop.java    From zone-sdk with MIT License 4 votes vote down vote up
/**
     * @param layoutId
     */
    public void setPopContentView(int layoutId) {
        this.layoutId = layoutId;
        wmParams = new WindowManager.LayoutParams();
        //获取WindowManagerImpl.CompatModeWrapper
        mWindowManager = (WindowManager) context.getSystemService(context.WINDOW_SERVICE);
        //设置window type  可以设置 屏幕外的层级!
//        wmParams.type = WindowManager.LayoutParams.TYPE_PHONE;
//        wmParams.type = WindowManager.LayoutParams.TYPE_TOAST;
//        https://blog.csdn.net/LoveDou0816/article/details/79172637 正常用第二个就行
        wmParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY ;

        //设置图片格式,效果为背景透明
        wmParams.format = PixelFormat.RGBA_8888;
        //设置浮动窗口不可聚焦(实现操作除浮动窗口外的其他可见窗口的操作)
//        wmParams.flags =
////          LayoutParams.FLAG_NOT_TOUCH_MODAL |
//                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
////          LayoutParams.FLAG_NOT_TOUCHABLE
//        ;
        wmParams.flags =
//                WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
                        WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;

        LayoutInflater inflater = LayoutInflater.from(context);
        //获取浮动窗口视图所在布局
        mFloatLayout = inflater.inflate(layoutId, new FrameLayout(context), false);
        ViewGroup.LayoutParams lp = mFloatLayout.getLayoutParams();
        wmParams.width = lp.width;
        wmParams.height = lp.height;
        initScreen();
        slideViewGroup = new SlideViewGroup(context, new SlideViewGroup.Callback() {
            @Override
            public void update(int x, int y) {
                if (!isSlide)
                    return;
                updateLocation(wmParams.gravity, wmParams.x + x, wmParams.y + y);
                log("11:--->x:" + x + "\t y:" + y);
                log("12--->x:" + wmParams.x + "\t y:" + wmParams.y);
                wmParams.x -= x;
                wmParams.y -= y;
                log("13restore--->x:" + wmParams.x + "\t y:" + wmParams.y);
            }

            @Override
            public void upCancel(int x, int y) {
                if (!isSlide)
                    return;
                wmParams.x += x;
                if (wmParams.x >= windowWidth - slideViewGroup.getWidth())
                    wmParams.x = windowWidth - slideViewGroup.getWidth();
                else if (wmParams.x < 0)
                    wmParams.x = 0;

                wmParams.y += y;
                if (wmParams.y >= windowHeight - slideViewGroup.getHeight())
                    wmParams.y = windowHeight - slideViewGroup.getHeight();
                else if (wmParams.y < 0)
                    wmParams.y = 0;
            }
        });
        slideViewGroup.setLayoutParams(lp);
        slideViewGroup.addView(mFloatLayout);

    }