private PopupWindow popupWindow;
// 微信分享
private IWXAPI api;
public static final int DLG_SHARE = 3004;
private void showWindow(View parent) {
api = WXAPIFactory.createWXAPI(this, WEIXIN_APPID, false);
api.registerApp(WEIXIN_APPID);
View shareView = LayoutInflater.from(this).inflate(
R.layout.personinfo_gengduo_click, null);
ImageView report = (ImageView) shareView.findViewById(R.id.btn_personinfo_item_reportimg);
report.setImageResource(R.drawable.icon_share_pyq);
TextView reporttxt = (TextView) shareView.findViewById(R.id.btn_personinfo_item_report);
reporttxt.setText("朋友圈");
ImageView lahei = (ImageView) shareView.findViewById(R.id.btn_personinfo_item_laheiimg);
lahei.setImageResource(R.drawable.activity_contacts_wx);
TextView laheitxt = (TextView) shareView.findViewById(R.id.btn_personinfo_item_lahei);
laheitxt.setText("微信好友");
View weixin_haoyou_send = (View) shareView
.findViewById(R.id.btn_persioninfo_itemreport_layout);
View weixin_pengyouquan_send = (View) shareView
.findViewById(R.id.btn_persioninfo_itemlahei_layout);
popupWindow = new PopupWindow(shareView,LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,true);
// 使其聚集
popupWindow.setFocusable(true);
// 设置允许在外点击消失
popupWindow.setOutsideTouchable(true);
//刷新状态
popupWindow.update();
// 这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景
popupWindow.setBackgroundDrawable(new BitmapDrawable());
WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
// 显示的位置为:屏幕的宽度的一半-PopupWindow的高度的一半
int xPos = windowManager.getDefaultDisplay().getWidth() / 2
- popupWindow.getWidth() / 2;
popupWindow.showAsDropDown(parent, xPos,0);
weixin_haoyou_send.setOnClickListener(new View.OnClickListener() {
public void onClick(View paramView) {
showDialog(DLG_LOADING);
popupWindow.dismiss();
WXWebpageObject webpage = new WXWebpageObject();
webpage.webpageUrl = url;
WXMediaMessage msg = new WXMediaMessage(webpage);
msg.title = title;
if (bitmap == null) {
Bitmap thumb = BitmapFactory.decodeResource(
getResources(), R.drawable.send_yuefan);
msg.thumbData = MealInfoActivity.bmpToByteArray(thumb, false);
} else {
msg.thumbData = Utils.bmpToByteArray(bitmap, false);
if(msg.thumbData.length/1024>=32){
Log.e("WXshare", "bitmap =========================== >32");
Bitmap thumb = BitmapFactory.decodeResource(
getResources(), R.drawable.send_yuefan);
msg.thumbData = Utils.bmpToByteArray(thumb, false);
}
}
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("webpage");
req.message = msg;
req.scene = SendMessageToWX.Req.WXSceneTimeline;
dismisDialog(DLG_LOADING);
api.sendReq(req);
}
});
weixin_pengyouquan_send
.setOnClickListener(new View.OnClickListener() {
public void onClick(View paramView) {
showDialog(DLG_LOADING);
popupWindow.dismiss();
WXWebpageObject webpage = new WXWebpageObject();
webpage.webpageUrl = url;
WXMediaMessage msg = new WXMediaMessage(webpage);
msg.title = title;
if (bitmap == null) {
Bitmap thumb = BitmapFactory.decodeResource(
getResources(), R.drawable.send_yuefan);
msg.thumbData = MealInfoActivity.bmpToByteArray(thumb, false);
} else {
msg.thumbData = Utils.bmpToByteArray(bitmap, false);
if(msg.thumbData.length/1024>=32){
Log.e("WXshare", "bitmap =========================== >32");
Bitmap thumb = BitmapFactory.decodeResource(
getResources(), R.drawable.send_yuefan);
msg.thumbData = Utils.bmpToByteArray(thumb, false);
}
}
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("webpage");
req.message = msg;
req.scene = SendMessageToWX.Req.WXSceneSession;
dismisDialog(DLG_LOADING);
api.sendReq(req);
}
});
}
private String buildTransaction(final String type) {
return (type == null) ? String.valueOf(System.currentTimeMillis())
: type + System.currentTimeMillis();
}
// 获取指定路径的图片
public void getImage(String urlpath) throws Exception {
URL url = new URL(urlpath);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5 * 1000);
if (conn.getResponseCode() == 200) {
InputStream inputStream = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(inputStream);
Log.e("ADActivity", "bitmap =========================== bitmap");
}
}
class MygetImage implements Runnable {
@Override
public void run() {
// while (true) {
try {
getImage(img);
//break;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//}
}
}
// 微信分享
private IWXAPI api;
public static final int DLG_SHARE = 3004;
private void showWindow(View parent) {
api = WXAPIFactory.createWXAPI(this, WEIXIN_APPID, false);
api.registerApp(WEIXIN_APPID);
View shareView = LayoutInflater.from(this).inflate(
R.layout.personinfo_gengduo_click, null);
ImageView report = (ImageView) shareView.findViewById(R.id.btn_personinfo_item_reportimg);
report.setImageResource(R.drawable.icon_share_pyq);
TextView reporttxt = (TextView) shareView.findViewById(R.id.btn_personinfo_item_report);
reporttxt.setText("朋友圈");
ImageView lahei = (ImageView) shareView.findViewById(R.id.btn_personinfo_item_laheiimg);
lahei.setImageResource(R.drawable.activity_contacts_wx);
TextView laheitxt = (TextView) shareView.findViewById(R.id.btn_personinfo_item_lahei);
laheitxt.setText("微信好友");
View weixin_haoyou_send = (View) shareView
.findViewById(R.id.btn_persioninfo_itemreport_layout);
View weixin_pengyouquan_send = (View) shareView
.findViewById(R.id.btn_persioninfo_itemlahei_layout);
popupWindow = new PopupWindow(shareView,LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,true);
// 使其聚集
popupWindow.setFocusable(true);
// 设置允许在外点击消失
popupWindow.setOutsideTouchable(true);
//刷新状态
popupWindow.update();
// 这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景
popupWindow.setBackgroundDrawable(new BitmapDrawable());
WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
// 显示的位置为:屏幕的宽度的一半-PopupWindow的高度的一半
int xPos = windowManager.getDefaultDisplay().getWidth() / 2
- popupWindow.getWidth() / 2;
popupWindow.showAsDropDown(parent, xPos,0);
weixin_haoyou_send.setOnClickListener(new View.OnClickListener() {
public void onClick(View paramView) {
showDialog(DLG_LOADING);
popupWindow.dismiss();
WXWebpageObject webpage = new WXWebpageObject();
webpage.webpageUrl = url;
WXMediaMessage msg = new WXMediaMessage(webpage);
msg.title = title;
if (bitmap == null) {
Bitmap thumb = BitmapFactory.decodeResource(
getResources(), R.drawable.send_yuefan);
msg.thumbData = MealInfoActivity.bmpToByteArray(thumb, false);
} else {
msg.thumbData = Utils.bmpToByteArray(bitmap, false);
if(msg.thumbData.length/1024>=32){
Log.e("WXshare", "bitmap =========================== >32");
Bitmap thumb = BitmapFactory.decodeResource(
getResources(), R.drawable.send_yuefan);
msg.thumbData = Utils.bmpToByteArray(thumb, false);
}
}
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("webpage");
req.message = msg;
req.scene = SendMessageToWX.Req.WXSceneTimeline;
dismisDialog(DLG_LOADING);
api.sendReq(req);
}
});
weixin_pengyouquan_send
.setOnClickListener(new View.OnClickListener() {
public void onClick(View paramView) {
showDialog(DLG_LOADING);
popupWindow.dismiss();
WXWebpageObject webpage = new WXWebpageObject();
webpage.webpageUrl = url;
WXMediaMessage msg = new WXMediaMessage(webpage);
msg.title = title;
if (bitmap == null) {
Bitmap thumb = BitmapFactory.decodeResource(
getResources(), R.drawable.send_yuefan);
msg.thumbData = MealInfoActivity.bmpToByteArray(thumb, false);
} else {
msg.thumbData = Utils.bmpToByteArray(bitmap, false);
if(msg.thumbData.length/1024>=32){
Log.e("WXshare", "bitmap =========================== >32");
Bitmap thumb = BitmapFactory.decodeResource(
getResources(), R.drawable.send_yuefan);
msg.thumbData = Utils.bmpToByteArray(thumb, false);
}
}
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("webpage");
req.message = msg;
req.scene = SendMessageToWX.Req.WXSceneSession;
dismisDialog(DLG_LOADING);
api.sendReq(req);
}
});
}
private String buildTransaction(final String type) {
return (type == null) ? String.valueOf(System.currentTimeMillis())
: type + System.currentTimeMillis();
}
// 获取指定路径的图片
public void getImage(String urlpath) throws Exception {
URL url = new URL(urlpath);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5 * 1000);
if (conn.getResponseCode() == 200) {
InputStream inputStream = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(inputStream);
Log.e("ADActivity", "bitmap =========================== bitmap");
}
}
class MygetImage implements Runnable {
@Override
public void run() {
// while (true) {
try {
getImage(img);
//break;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//}
}
}