主要是记录一下,显示的Dialog背景带有尖角,尖角位置的显示;
通过Bitmap的getWidth()方法获取位图的像素宽度;然后遍历查询,通过getPixel(int x, int y)方法,判断返回的color色值,是否为0,判断尖角的位置。
贴代码;
@SuppressLint("NewApi")
public class BarHome extends AbsBarUtil {
@BindView(id = R.id.ghlj, click = true)
private ImageView mIv;
private Dialog mDialog;
private int mIvCenterX;
private static int mArrowSelfLeftX;
private int mBarHeight;
private View mContent;
private int mContentWidth;
public BarHome() {
super();
mContent = LayoutInflater.from(mIv.getContext()).inflate(
R.layout.item_pop_win_ghlj, null);
mContent.findViewById(R.id.ll_ihu).setOnClickListener(this);
mContent.findViewById(R.id.ll_qyy).setOnClickListener(this);
mContent.findViewById(R.id.ll_aljk).setOnClickListener(this);
mContent.findViewById(R.id.ll_wxgh).setOnClickListener(this);
mContent.findViewById(R.id.ll_zfbgh).setOnClickListener(this);
mContent.addOnLayoutChangeListener(new OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right,
int bottom, int oldLeft, int oldTop, int oldRight,
int oldBottom) {
mContentWidth = mContent.getMeasuredWidth();
if (mArrowSelfLeftX == 0) {
Drawable d = mContent.getBackground();
Bitmap bmp = ImageUtil.drawable2Bitmap(d);
int bmpW = bmp.getWidth();
int oarrowx = getX(bmp);
int delta = bmpW - oarrowx;
mArrowSelfLeftX = mContentWidth - delta;
mDialog.getWindow().getAttributes().x = mIvCenterX
- mArrowSelfLeftX;
if (mDialog.isShowing()) {
mDialog.dismiss();
}
mDialog.show();
}
}
});
mIv.addOnLayoutChangeListener(new OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right,
int bottom, int oldLeft, int oldTop, int oldRight,
int oldBottom) {
int width = mIv.getMeasuredWidth() / 2;
mIvCenterX = mIv.getLeft() + width;
mBarHeight = getBarView().getMeasuredHeight();
if (mDialog == null) {
mDialog = DialogAssistant.getCustomDialog(mContent,
mIvCenterX - mArrowSelfLeftX, mBarHeight);
// mDialog.show();
}
}
});
}
private String getUrl(Site site) {
String url = null;
if (site != null) {
url = site.getUrl();
}
return url;
}
@Override
protected int getLayoutId() {
return R.layout.actionbar_homepage1;
}
@Override
public void onClick(View v) {
super.onClick(v);
if (mDialog.isShowing()) {
mDialog.dismiss();
} else {
if (R.id.ghlj == v.getId()) {
mDialog.show();
}
}
Site site = null;
switch (v.getId()) {
case R.id.ll_ihu:
site = SiteUtil.getInstance().getIcallAndroid();
SystemUtil.startApp("com.sinldo.aihu",
"com.sinldo.aihu.ui.LauncherUI", getUrl(site));
break;
case R.id.ll_qyy:
site = SiteUtil.getInstance().getBoringHospitalAndroid();
SystemUtil.startApp("com.kingyee.kymh", "com.kingyee.kymh.KYMH",
getUrl(site));
break;
case R.id.ll_aljk:
site = SiteUtil.getInstance().getAliHealthAndroid();
SystemUtil.startApp("com.citic21.user",
"com.taobao.alijk.activity.GuideActivity", getUrl(site));
break;
case R.id.ll_wxgh:
site = SiteUtil.getInstance().getWeChatAndroid();
SystemUtil.startApp("com.tencent.mm",
"com.tencent.mm.ui.LauncherUI", getUrl(site));
break;
case R.id.ll_zfbgh:
site = SiteUtil.getInstance().getAliPayAndroid();
SystemUtil.startApp("com.eg.android.AlipayGphone",
"com.eg.android.AlipayGphone.AlipayLogin", getUrl(site));
break;
default:
break;
}
}
private int getX(Bitmap bmp) {
int pos = 0;
int len = bmp.getWidth();
for (int i = 0; i < len; i++) {
int color = bmp.getPixel(i, 1);
if (color != 0) {
pos = i;
break;
}
}
return pos;
}
}