[Unix]
自定义ShareSDK分享平台界面,kotlin静态函数
服务系统
发布于:2021-12-25 13:25
|
阅读数:236
|
评论:0
|
public PlatformActionListener getPlatformActionListener() {
return platformActionListener;
}
public void setPlatformActionListener(
PlatformActionListener platformActionListener) {
this.platformActionListener = platformActionListener;
}
public void showShareWindow() {
View view = LayoutInflater.from(context).inflate(R.layout.share_layout,null);
GridView gridView = (GridView) view.findViewById(R.id.share_gridview);
ShareAdapter adapter = new ShareAdapter(context);
gridView.setAdapter(adapter);
Button btn_cancel = (Button) view.findViewById(R.id.btn_cancel);
// 取消按钮
btn_cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// 销毁弹出框
dismiss();
}
});
// 设置SelectPicPopupWindow的View
this.setContentView(view);
// 设置SelectPicPopupWindow弹出窗体的宽
this.setWidth(LayoutParams.FILL_PARENT);
// 设置SelectPicPopupWindow弹出窗体的高
this.setHeight(LayoutParams.WRAP_CONTENT);
// 设置SelectPicPopupWindow弹出窗体可点击
this.setFocusable(true);
// 设置SelectPicPopupWindow弹出窗体动画效果
this.setAnimationStyle(R.style.AnimBottom);
// 实例化一个ColorDrawable颜色为半透明
ColorDrawable dw = new ColorDrawable(0xb0000000);
// 设置SelectPicPopupWindow弹出窗体的背景
this.setBackgroundDrawable(dw);
gridView.setOnItemClickListener(new ShareItemClickListener(this));
}
private class ShareItemClickListener implements OnItemClickListener {
private PopupWindow pop;
public ShareItemClickListener(PopupWindow pop) {
this.pop = pop;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
share(position);
pop.dismiss();
}
}
/**
*/
private void share(int position) {
if (position == 1) {
qq();
} else if (position == 4) {
qzone();
} else if(position==5){
shortMessage();
}else{
Platform plat = null;
plat = ShareSDK.getPlatform(context, getPlatform(position));
if (platformActionListener != null) {
plat.setPlatformActionListener(platformActionListener);
}
plat.share(shareParams);
}
}
/**
- 初始化分享参数
- @param shareModel
*/
public void initShareParams(ShareModel shareModel) {
if (shareModel != null) {
ShareParams sp = new ShareParams();
sp.setShareType(Platform.SHARE_TEXT);
sp.setShareType(Platform.SHARE_WEBPAGE);
sp.setTitle(shareModel.getText());
sp.setText(shareModel.getText());
sp.setUrl(shareModel.getUrl());
sp.setImageUrl(shareModel.getImageUrl());
shareParams = sp;
}
}
/**
- 获取平台
- @param position
- @return
*/
private String getPlatform(int position) {
String platform = "";
switch (position) {
case 0:
platform = "Wechat";
break;
case 1:
platform = "QQ";
break;
case 2:
platform = "SinaWeibo";
break;
case 3:
platform = "WechatMoments";
break;
case 4:
platform = "QZone";
break;
case 5:
platform = "ShortMessage";
break;
}
return platform;
}
/**
*/
private void qzone() {
ShareParams sp = new ShareParams();
sp.setTitle(shareParams.getTitle());
sp.setTitleUrl(shareParams.getUrl()); // 标题的超链接
sp.setText(shareParams.getText());
sp.setImageUrl(shareParams.getImageUrl());
sp.setComment("我对此分享内容的评论");
sp.setSite(shareParams.getTitle());
sp.setSiteUrl(shareParams.getUrl());
Platform qzone = ShareSDK.getPlatform(context, "QZone");
qzone.setPlatformActionListener(platformActionListener); // 设置分享事件回调 //
// 执行图文分享
qzone.share(sp);
}
private void qq() {
ShareParams sp = new ShareParams();
sp.setTitle(shareParams.getTitle());
sp.setTitleUrl(shareParams.getUrl()); // 标题的超链接
sp.setText(shareParams.getText());
sp.setImageUrl(shareParams.getImageUrl());
sp.setComment("我对此分享内容的评论");
sp.setSite(shareParams.getTitle());
sp.setSiteUrl(shareParams.getUrl());
Platform qq = ShareSDK.getPlatform(context, "QQ");
qq.setPlatformActionListener(platformActionListener);
qq.share(sp);
}
/**
*/
private void shortMessage() {
ShareParams sp = new ShareParams();
sp.setAddress("");
sp.setText(shareParams.getText()+"这是网址《"+shareParams.getUrl()+"》很给力哦!");
Platform circle = ShareSDK.getPlatform(context, "ShortMessage");
circle.setPlatformActionListener(platformActionListener); // 设置分享事件回调
// 执行图文分享
circle.share(sp);
}
}
2.显示九宫格的ShareAdapter .java类
/*
- @Title: ShareAdapter.java
面试复习笔记:
这份资料我从春招开始,就会将各博客、论坛。网站上等优质的Android开发中高级面试题收集起来,然后全网寻找最优的解答方案。每一道面试题都是百分百的大厂面经真题+最优解答。包知识脉络 + 诸多细节。
节省大家在网上搜索资料的时间来学习,也可以分享给身边好友一起学习。
给文章留个小赞,就可以免费领取啦~
戳我领取:GitHub
《960页Android开发笔记》
《1307页Android开发面试宝典》
包含了腾讯、百度、小米、阿里、乐视、美团、58、猎豹、360、新浪、搜狐等一线互联网公司面试被问到的题目。熟悉本文中列出的知识点会大大增加通过前两轮技术面试的几率。
《507页Android开发相关源码解析》
只要是程序员,不管是Java还是Android,如果不去阅读源码,只看API文档,那就只是停留于皮毛,这对我们知识体系的建立和完备以及实战技术的提升都是不利的。
真正最能锻炼能力的便是直接去阅读源码,不仅限于阅读各大系统源码,还包括各种优秀的开源库。
|
免责声明:
1. 本站所有资源来自网络搜集或用户上传,仅作为参考不担保其准确性!
2. 本站内容仅供学习和交流使用,版权归原作者所有!© 查看更多
3. 如有内容侵害到您,请联系我们尽快删除,邮箱:kf@codeae.com
|
|
|
|
|