ShareDialog布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:background="@drawable/shape_price_btn"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_20"
android:gravity="center_horizontal">
<LinearLayout
android:id="@+id/ll_share_wxmini"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/wx_login" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_10"
android:text="微信好友"
android:textColor="#FF242424"
android:textSize="@dimen/sp_16" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_share_haibao"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
android:visibility="visible">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/haibao" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_10"
android:text="海报"
android:textColor="#FF242424"
android:textSize="@dimen/sp_16" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/tv_cancleshare"
android:layout_width="336dp"
android:layout_height="@dimen/dp_44"
android:layout_marginTop="@dimen/dp_15"
android:layout_marginBottom="@dimen/dp_15"
android:background="@drawable/bg_cancle_white"
android:gravity="center"
android:text="取消"
android:textColor="#FF999999"
android:textSize="@dimen/sp_21"
/>
</LinearLayout>
ShareDialog代码
public class ShareDialog extends Dialog {
TextView tvCancle;
LinearLayout llShare;
LinearLayout llHaiBao;
private Activity activity;
private int roomsnumber = 1;
public ShareDialog(@NonNull Context context) {
super(context);
}
public ShareDialog(Activity activity) {
super(activity, R.style.ActionSheetDialogStyle);
this.activity = activity;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_share);
tvCancle = findViewById(R.id.tv_cancleshare);
llShare = findViewById(R.id.ll_share_wxmini);
llHaiBao = findViewById(R.id.ll_share_haibao);
ButterKnife.bind(this);
getWindow().setGravity(Gravity.BOTTOM);//设置显示在底部
WindowManager windowManager = getWindow().getWindowManager();
Display display = windowManager.getDefaultDisplay();
WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
layoutParams.width = display.getWidth();//设置Dialog的宽度为屏幕宽度
getWindow().setAttributes(layoutParams);
llShare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
if (null != onSelectNumberClickListener) {
onSelectNumberClickListener.selectNumberClick();
}
}
});
tvCancle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
llHaiBao.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
if (null != onSelectNumberClickListener){
onSelectNumberClickListener.haibaoClick();
}
}
});
}
private OnSelectNumberClickListener onSelectNumberClickListener;
public void setOnSelectNumberClickListener(OnSelectNumberClickListener onSelectNumberClickListener) {
this.onSelectNumberClickListener = onSelectNumberClickListener;
}
public interface OnSelectNumberClickListener {
void selectNumberClick();
void haibaoClick();
}
}
HaiBaoShareDialog布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_presell_indent_gray"
android:orientation="vertical">
<LinearLayout
android:id="@+id/ll_picture"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_55"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="@+id/iv_haibao"
android:layout_width="345dp"
android:layout_height="479dp"
android:layout_marginLeft="@dimen/dp_17"
android:layout_marginRight="@dimen/dp_13" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@drawable/bg_corner6_white"
android:gravity="center_horizontal"
android:orientation="vertical">
<LinearLayout
android:id="@+id/ll_sharetype"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="@dimen/dp_20"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/ll_share_wxmini"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/wx_login" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_10"
android:text="微信好友"
android:textColor="#FF242424"
android:textSize="@dimen/sp_16" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_share_pengyouquan"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
android:visibility="visible">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/pyq" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_10"
android:text="朋友圈"
android:textColor="#FF242424"
android:textSize="@dimen/sp_16" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_savepicture"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
android:visibility="visible">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/savepicture" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_10"
android:text="保存图片"
android:textColor="#FF242424"
android:textSize="@dimen/sp_16" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/tv_cancleshare"
android:layout_width="336dp"
android:layout_height="@dimen/dp_44"
android:layout_marginTop="@dimen/dp_15"
android:layout_marginBottom="@dimen/dp_15"
android:background="@drawable/bg_cancle_white"
android:gravity="center"
android:text="取消"
android:textColor="#FF999999"
android:textSize="@dimen/sp_21"
/>
</LinearLayout>
</RelativeLayout>
HaiBaoShareDialog代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vipshare);
tvCancle = findViewById(R.id.tv_cancleshare);
llShare = findViewById(R.id.ll_share_wxmini);
llSharePengyouquan = findViewById(R.id.ll_share_pengyouquan);
llSavepicture = findViewById(R.id.ll_savepicture);
ivHaibao = findViewById(R.id.iv_haibao);
ButterKnife.bind(this);
getWindow().setGravity(Gravity.BOTTOM);//设置显示在底部
WindowManager windowManager = getWindow().getWindowManager();
Display display = windowManager.getDefaultDisplay();
WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
layoutParams.width = display.getWidth();//设置Dialog的宽度为屏幕宽度
getWindow().setAttributes(layoutParams);
llShare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
if (Util.isWeixinAvilible(activity)) {
// WxUtils.wxToMiniPro(activity, ApiConstant.MINIPRO_BASE_URL, "", ApiConstant.MINIPRO_BASE_PATH + hotelId + inviteCode, titleName, "酒店分享", response.getImg());
WxUtils.shareImageToWx(activity, HaiBaoShareDialog.this.coverUrl, SendMessageToWX.Req.WXSceneSession);//好友
} else {
ToastUtils.show(activity, "请安装微信后分享");
}
}
});
tvCancle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
llSharePengyouquan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
WxUtils.shareImageToWx(activity, HaiBaoShareDialog.this.coverUrl, SendMessageToWX.Req.WXSceneTimeline);//朋友圈
}
});
llSavepicture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
downloadPic(activity);
}
});
}
public void setImage(){
coverUrl= getCoverUrl();
GlideUtils.loadImg(activity,coverUrl,ivHaibao);
}
public void downloadPic(Activity activity) {
//读写权限申请
String[] permission = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
boolean checkResult = PermissionUtils.checkPermissionsGroup(activity, permission);
if (!checkResult) {
// PermissionUtils.requestPermissions(activity, permission, PermissionConfig.PERMISSION_REQUEST_CODE);
ToastUtils.show(activity, "未授予存储文件权限");
PermissionConfig.showPermissionDialog(activity, PermissionConfig.MESSAGE_WRITE_EXTERNAL_PERMISSION);
} else {
String sharePosterUrl = coverUrl;
SaveImageUtils.toSave(activity, sharePosterUrl);
}
}
activity代码
@Override
public void onShare(HotelApplyShareBean hotelApplyShareBean) {
cover = hotelApplyShareBean.getCover();
Log.i("leleleooo", "onShare: " + cover);
if (null == shareDialog) {
shareDialog = new ShareDialog(this);
}
shareDialog.show();
if (null == haiBaoShareDialog) {
haiBaoShareDialog = new HaiBaoShareDialog(this);
}
shareDialog.setOnSelectNumberClickListener(new ShareDialog.OnSelectNumberClickListener() {
@Override
public void selectNumberClick() {
if (Util.isWeixinAvilible(mContext)) {
WxUtils.wxToMiniPro(mContext, ApiConstant.MINIPRO_VIP_PATH, "", ApiConstant.MINIPRO_APPLY_PATH + inviteCode, "酒店入驻", "", cover);
Log.i("leleleleel1", "onShare: " + cover);
} else {
ToastUtils.showShortToast(mContext, "请安装微信后分享");
}
}
@Override
public void haibaoClick() {
if (showId == 1) {
requestDate();
} else {
}
haiBaoShareDialog.show();
}
});
}
@SuppressLint("CheckResult")
private void requestDate() {
Map<String, Object> map = new ArrayMap<>();
map.put("mid",SPUtils.getUserId());
map.put("inviteCode",SPUtils.getInviteCode());
Log.i("000000", "requestDate: "+SPUtils.getInviteCode());
Log.i("000000", "requestDate: "+SPUtils.getUserId());
RetrofitManager.createApi2().hotelApplyShare(Util.getSysHeader(0, ""), map)
.compose(RxSchedulers.applySchedulers())
// .compose(mView.bindToLife())
.subscribe(response -> {
if (response.getCode() == 200) {
img = response.getImg();
Log.i("wpn", "requestDate: "+img);
haiBaoShareDialog.setCoverUrl(img);
haiBaoShareDialog.setImage();
} else {
ToastUtils.showShortToast(mContext, "图片不存在!");
}
}, throwable ->
{
throwable.printStackTrace();
}
);
}