Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

高亮区域大小 #2

Open
Born-alone opened this issue Dec 5, 2018 · 18 comments
Open

高亮区域大小 #2

Born-alone opened this issue Dec 5, 2018 · 18 comments

Comments

@Born-alone
Copy link

刚刚试了一个 小米8全面屏手机
把高亮区域设置在底部的四个 RadioButton 上 高亮区域只有一小块 请问这个怎么解决

@Born-alone
Copy link
Author

_20181205153017

@A-Heavy-Rain
Copy link
Owner

请问demo在小米8上有问题吗?不知道是不是刘海屏的问题,手边暂时没这种机器.

@Born-alone
Copy link
Author

demo 没有发现这种情况

@A-Heavy-Rain
Copy link
Owner

.addView(tv_light2, new CenterRightStyle(deco_view2)) 传的View是否正确呢?

@Born-alone
Copy link
Author

你好 传的View是正确的

@Born-alone
Copy link
Author

default

@Born-alone
Copy link
Author

我找到原因了 是因为那个界面在 setContentView 之前把标题栏和状态栏都去除了 才出现这个问题
但是现在我需求 这个界面是需要调用这两方法把标题栏和状态栏都去除
请问一下有其他的解决办法吗

@A-Heavy-Rain
Copy link
Owner

我觉得可能还是刘海屏的问题,我这边在小米5S上在demo中把标题栏和状态栏都去除也是正常显示的,我回头借一台刘海屏手机在试试.

@Born-alone
Copy link
Author

_20181205171832

@Born-alone
Copy link
Author

在刘海屏上去除了状态拦了通知栏就会显示不全 在另外一个MX5上没问题

@A-Heavy-Rain
Copy link
Owner

是刘海屏的话高亮位置Y坐标减去状态栏的高度 应该可以解决.

@A-Heavy-Rain
Copy link
Owner

@Born-alone
Copy link
Author

瞅了一下大概 感觉有点懵

@A-Heavy-Rain
Copy link
Owner

嗯嗯 等我有时间了去弄下,最近有点忙,你也可以先看下 弄好的话给我提个pr是最好的.

@A-Heavy-Rain
Copy link
Owner

A-Heavy-Rain commented Dec 19, 2018

image
把getLocationOnScreen换成getLocationInWindow 试一下可以不?
我借了一个锤子R1 水滴屏 不存在类似问题,我觉得小米隐藏刘海后DecorView不等于屏幕的大小了.

@SpakeBrony
Copy link

图片
把getLocationOnScreen换成getLocationInWindow试一下可以不?
我借了一个锤子R1水滴屏不存在类似问题,我觉得小米隐藏刘海后DecorView不等于屏幕的大小了。

测试了,可以正常运行,不会出现UI错误了

@SpakeBrony
Copy link

public class GuideViewHelper {
private ViewGroup rootView;
private GuideView guideView;
private Context context;
private List viewInfos;
private List lightViews;
private List layoutStyles;
private int padding;
private LightType lightType = LightType.Rectangle;
private int blurWidth;
private int x = 0;
private int y = 0;

public GuideViewHelper(Activity activity) {
    this.rootView = (ViewGroup) activity.getWindow().getDecorView();
    this.context = activity;
    guideView = new GuideView(context);
    viewInfos = new ArrayList<>();
    lightViews = new ArrayList<>();
    layoutStyles = new ArrayList<>();
}


public GuideViewHelper(Activity activity,int x,int y) {
    this.rootView = (ViewGroup) activity.getWindow().getDecorView();
    this.context = activity;
    guideView = new GuideView(context);
    viewInfos = new ArrayList<>();
    lightViews = new ArrayList<>();
    layoutStyles = new ArrayList<>();
    this.x = x;
    this.y = y;
}



public GuideViewHelper padding(int padding) {
    this.padding = padding;
    return this;
}



public GuideViewHelper addView(View view, LayoutStyle layoutStyle) {
    lightViews.add(view);
    layoutStyles.add(layoutStyle);
    return this;
}

public GuideViewHelper addView(int viewId, LayoutStyle layoutStyle) {
    lightViews.add(rootView.findViewById(viewId));
    layoutStyles.add(layoutStyle);
    return this;
}

public GuideViewHelper type(LightType lightType) {
    this.lightType=lightType;
    guideView.type(lightType);
    return this;
}

public GuideViewHelper alpha(int alpha) {
    guideView.setAlpha(alpha);
    return this;
}

public GuideViewHelper onDismiss(GuideView.OnDismissListener listener) {
    guideView.setOnDismissListener(listener);
    return this;
}

public GuideViewHelper Blur(int radius) {
    this.blurWidth=blurWidth;
    guideView.setBlur(radius);
    return this;
}
public GuideViewHelper Blur() {
    this.blurWidth=10;
    guideView.setBlur(10);
    return this;
}
public void nextLight(){
    guideView.showHighLight();
}

public void show() {
    show(false);
}
public GuideViewHelper autoNext(){
    guideView.setOnClickListener(guideView);
    guideView.setAutoNext(true);
    return this;
}
public void postShow() {
    rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT < 16) {
                rootView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            } else {
                rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
            show();
        }
    });
}

public void showAll() {
    show(true);
}

public void postShowAll() {
    rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT < 16) {
                rootView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            } else {
                rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
            showAll();
        }
    });
}
private ViewInfo obtainViewInfo(View view) {
    int[] loc = new int[2];
    view.getLocationInWindow (loc);
    ViewInfo info = new ViewInfo();
    switch (lightType) {
        case Oval:
        case Rectangle:
            info.offsetX = (loc[0] - padding)+x;
            info.offsetY = (loc[1] - padding)+y;
            info.width = view.getWidth() + 2 * padding;
            info.height = view.getHeight() + 2 * padding;
            break;
        case Circle:
            int diameter = Math.max(view.getWidth() + 2 * padding, view.getHeight() + 2 * padding);
            info.width = diameter;
            info.height = diameter;
            info.offsetX = (loc[0] - padding)+x;
            info.offsetY = (loc[1] - padding - (diameter / 2 - view.getHeight() / 2 - padding))+y;
            break;
    }
    return info;
}

private void show(boolean showAll) {

    for (View lightView : lightViews) {
        viewInfos.add(obtainViewInfo(lightView));
    }
    guideView.setViewInfos(viewInfos);
    if (blurWidth!=0){
        for (LayoutStyle layoutStyle : layoutStyles) {
            layoutStyle.addBlurOffset(blurWidth);
        }
    }
    if (showAll) {
        guideView.showAll();
        for (int i = 0; i < layoutStyles.size(); i++) {
            layoutStyles.get(i).showDecorationOnScreen(viewInfos.get(i), guideView);
        }

    } else {
        layoutStyles.get(0).showDecorationOnScreen(viewInfos.get(0), guideView);
        guideView.setLayoutStyles(layoutStyles);
    }
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    rootView.addView(guideView, params);
}

}

最好可以修改偏移,这样就算有的手机不适配,也能手动修改

new GuideViewHelper(MainActivity.this,50,50)
.addView(suiji, new RightBottomStyle(deco_view1))
.addView(changed, new LeftBottomStyle(deco_view2))
.addView(record, new RightBottomStyle(deco_view3))
.addView(playDrum, new RightTopStyle(deco_view4))
.type(LightType.Circle)
.Blur()
.autoNext()
.onDismiss(new GuideView.OnDismissListener() {
@OverRide
public void dismiss() {
}
})
.show();

@helloconch
Copy link

helloconch commented Oct 24, 2019

感谢作者的提供的code.
针对有的手机,进行蒙层时,会将statusbar 全部盖上。
有的手机,statusbar 未被盖上。

手里几个测试机,华为表象,statusbar 全部盖上, 高亮没有移位。

oppo手机,statusbar 未被盖上,高亮部位移位,出现偏差。

目前采取一个取巧方式, 设置一个空view ,1dp即可,让其位于视图左上角(视图无状态栏)。

获取该空view的y坐标,若为0,则代表statusbar 未被盖上,会占用空间,需要将satusbar高度,传递到GuideViewHelper中。
反之,不传。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants