分享光环(普通分享和热点网页分享)

This commit is contained in:
khy
2017-02-07 17:06:32 +08:00
parent 30bb750d94
commit 575ba33e43
27 changed files with 1790 additions and 72 deletions

View File

@ -23,6 +23,8 @@ import com.xiaomi.mipush.sdk.MiPushClient;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
public class AppController extends Application {
@ -39,6 +41,12 @@ public class AppController extends Application {
private boolean isFinish = false;
//快传文件发送单线程
public static Executor FILE_SENDER_EXECUTOR = Executors.newSingleThreadExecutor();
//快传文件发送主要的线程池
public static Executor MAIN_EXECUTOR = Executors.newFixedThreadPool(5);
@Override
public void onCreate() {
super.onCreate();

View File

@ -140,7 +140,7 @@ public class BaseActivity extends Activity implements OnCallBackListener {
}
}
ShareUtils.getInstance(this).showShareWindows(new View(this), url, gameName, icon, newsTitle, isPlugin);
ShareUtils.getInstance(this).showShareWindows(new View(this), url, gameName, icon, newsTitle, isPlugin, true);
if (newsTitle == null) {
DataUtils.onEvent(this, "内容分享", gameName);

View File

@ -133,7 +133,7 @@ public class BaseFragmentActivity extends FragmentActivity {
}
}
ShareUtils.getInstance(this).showShareWindows(new View(this), url, gameName, icon, newsTitle, isPlugin);
ShareUtils.getInstance(this).showShareWindows(new View(this), url, gameName, icon, newsTitle, isPlugin, true);
if (newsTitle == null){
DataUtils.onEvent(this, "内容分享", gameName);

View File

@ -12,7 +12,6 @@ import android.graphics.Color;
import android.graphics.Matrix;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
@ -63,7 +62,7 @@ public class ShareUtils {
private static IWXAPI api;
private static Tencent mTencent;
private Handler handler;
private Boolean ispopupWindow;
private int[] arrLogo = {R.drawable.share_wechat_logo, R.drawable.share_wechatmoments_logo, R.drawable.share_qq_logo
, R.drawable.share_qzone_logo, R.drawable.share_sinaweibo_logo, R.drawable.share_shortmessage_logo
@ -84,21 +83,31 @@ public class ShareUtils {
return instance;
}
public void showShareWindows(View view, String url, String gameName, String icon ,String newsTitle, boolean isPlugin){
/**
*
* @param view ispopupWindow-true是绑定的布局 ispopupWindow-false 则是嵌套的父控件
* @param url 分享链接
* @param gameName 游戏名 与 新闻标题区分
* @param icon 分享图标
* @param newsTitle 新闻标题 与 游戏名区分
* @param isPlugin 判断游戏是否是插件
* @param ispopupWindow 判断是否是 PopupWindow false可直接嵌套进布局分享光环view是父控件
*/
public void showShareWindows(View view, String url, String gameName, String icon ,String newsTitle,
boolean isPlugin, boolean ispopupWindow){
this.shareIcon = icon;
this.shareGameName = gameName;
this.shareUrl = url;
this.shareNewsTitle = newsTitle;
this.isPlugin = isPlugin;
this.ispopupWindow = ispopupWindow;
RelativeLayout contentView = new RelativeLayout(context);
contentView.setBackgroundColor(0x8c000000);
contentView.setFocusable(true);
contentView.setFocusableInTouchMode(true);
RecyclerView shareRecyclerView = new RecyclerView(context);
shareRecyclerView.setPadding(DisplayUtils.dip2px(context, 20), DisplayUtils.dip2px(context, 10), DisplayUtils.dip2px(context, 20), 0);
shareRecyclerView.setBackgroundColor(Color.WHITE);
//RecyclerView禁止滑动
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 4){
@ -116,6 +125,16 @@ public class ShareUtils {
rlParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
contentView.addView(shareRecyclerView,rlParams);
if (!ispopupWindow) {
LinearLayout layout = (LinearLayout) view;
layout.addView(contentView);
arrLabel[7] = "邮件";
arrLogo[7] = R.drawable.share_email_logo;
return;
}
contentView.setBackgroundColor(0x8c000000);
shareRecyclerView.setBackgroundColor(Color.WHITE);
popupWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT
, LinearLayout.LayoutParams.MATCH_PARENT, true);
popupWindow.setAnimationStyle(R.style.mypopwindow_anim_style);
@ -198,10 +217,24 @@ public class ShareUtils {
shortMessageSahre();
break;
case 6:
copyLink(shareUrl);
copyLink("推荐光环助手,绿色安全的手游加速助手:" + shareUrl);
break;
case 7:
popupWindow.dismiss();
if (ispopupWindow) {
popupWindow.dismiss();
} else {
Intent data=new Intent(Intent.ACTION_SENDTO);
data.setData(Uri.parse("mailto:"));
data.putExtra(Intent.EXTRA_SUBJECT, "快来试试光环助手");
data.putExtra(Intent.EXTRA_TEXT, "我用光环助手一段时间了在里面可以下载各种热门卡牌手游的加速版绿色安全超级省心做日常效率提高3-5倍\n" +
"\n" +
"不用肝的感觉真好,快来试试。\n" +
"\n" +
"光环助手官网地址:\n" +
"\n" +
"http://www.ghzhushou.com?source=appshare333");
context.startActivity(data);
}
break;
}
}
@ -228,22 +261,31 @@ public class ShareUtils {
}
//QQ分享
private void qqSahre(){
private void qqSahre() {
Utils.toast(context,"分享跳转中...");
Bundle params = new Bundle();
if (shareNewsTitle != null){
params.putString(QQShare.SHARE_TO_QQ_TITLE, shareNewsTitle);
params.putString(QQShare.SHARE_TO_QQ_SUMMARY, "来自光环助手(最强卡牌神器)");
}else {
params.putString(QQShare.SHARE_TO_QQ_TITLE, "向你推荐:");
if (isPlugin){
params.putString(QQShare.SHARE_TO_QQ_SUMMARY, shareGameName + "(光环加速版)");
}else {
params.putString(QQShare.SHARE_TO_QQ_SUMMARY, shareGameName);
}
}
String title;
String summary;
if (ispopupWindow) {
if (shareNewsTitle != null) {
title = shareNewsTitle;
summary = "来自光环助手(最强卡牌神器)";
} else {
title = "向你推荐:";
if (isPlugin) {
summary = shareGameName + "(光环加速版)";
} else {
summary = shareGameName;
}
}
} else {
title = "不用肝的感觉真好";
summary = "绿色安全的手游加速助手";
}
params.putString(QQShare.SHARE_TO_QQ_TITLE, title);
params.putString(QQShare.SHARE_TO_QQ_SUMMARY, summary);
params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, shareUrl);
params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL, shareIcon);
@ -251,57 +293,84 @@ public class ShareUtils {
mTencent.shareToQQ(
(Activity) context, params,QqShareListener);
popupWindow.dismiss();
if (ispopupWindow) {
popupWindow.dismiss();
}
}
//微信好友分享
private void wechatSahre(){
private void wechatSahre() {
Utils.toast(context,"分享跳转中...");
WXWebpageObject webpage = new WXWebpageObject();
WXMediaMessage msg = new WXMediaMessage(webpage);
webpage.webpageUrl = shareUrl;
if (shareNewsTitle != null){
msg.title = shareNewsTitle;
msg.description = "来自光环助手(最强卡牌神器)";
}else {
if (isPlugin){
msg.title = "向你推荐";
msg.description = shareGameName + "(光环加速版";
}else {
msg.title = "向你推荐";
msg.description = shareGameName;
String title;
String summary;
if (ispopupWindow) {
if (shareNewsTitle != null) {
title = shareNewsTitle;
summary = "来自光环助手(最强卡牌神器";
} else {
title = "向你推荐";
if (isPlugin){
summary = shareGameName + "(光环加速版)";
} else {
summary = shareGameName;
}
}
} else {
title = "不用肝的感觉真好";
summary = "绿色安全的手游加速助手";
}
msg.title = title;
msg.description = summary;
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("webpage");
req.message = msg;
req.scene = SendMessageToWX.Req.WXSceneSession;
loadBitMap(shareIcon, msg, req);
popupWindow.dismiss();
if (ispopupWindow) {
popupWindow.dismiss();
}
}
//QQ空间分享
private void qZoneSahre(){
private void qZoneSahre() {
Utils.toast(context,"分享跳转中...");
Bundle params = new Bundle();
if (shareNewsTitle != null){
params.putString(QzoneShare.SHARE_TO_QQ_TITLE, shareNewsTitle);
}else {
params.putString(QzoneShare.SHARE_TO_QQ_TITLE, "向你推荐:");
if (isPlugin){
params.putString(QzoneShare.SHARE_TO_QQ_SUMMARY, shareGameName + "(光环加速版)");
}else {
params.putString(QzoneShare.SHARE_TO_QQ_SUMMARY, shareGameName);
String title;
String summary = null;
if (ispopupWindow) {
if (shareNewsTitle != null) {
title = shareNewsTitle;
} else {
title = "向你推荐:";
if (isPlugin) {
summary = shareGameName + "(光环加速版)";
} else {
summary = shareGameName;
}
}
} else {
title = "不用肝的感觉真好";
summary = "绿色安全的手游加速助手";
}
ArrayList<String> imageUrls = new ArrayList<String>();
imageUrls.add(shareIcon);
if (summary != null) {
params.putString(QzoneShare.SHARE_TO_QQ_SUMMARY, summary);
}
params.putString(QzoneShare.SHARE_TO_QQ_TITLE, title);
params.putInt(QzoneShare.SHARE_TO_QZONE_KEY_TYPE, QzoneShare.SHARE_TO_QZONE_TYPE_NO_TYPE);
params.putString(QzoneShare.SHARE_TO_QQ_TARGET_URL, shareUrl);
params.putStringArrayList(QzoneShare.SHARE_TO_QQ_IMAGE_URL, imageUrls);
@ -309,26 +378,36 @@ public class ShareUtils {
mTencent.shareToQzone(
(Activity) context, params,QqShareListener);
popupWindow.dismiss();
if (ispopupWindow) {
popupWindow.dismiss();
}
}
//微信朋友圈分享
private void wechatMomentsSahre(){
private void wechatMomentsSahre() {
Utils.toast(context,"分享跳转中...");
WXWebpageObject webpage = new WXWebpageObject();
WXMediaMessage msg = new WXMediaMessage(webpage);
webpage.webpageUrl = shareUrl;
if (shareNewsTitle != null){
msg.title = shareNewsTitle;
}else {
if (isPlugin){
msg.title = "向你推荐:" + shareGameName + "(光环加速版)";
}else {
msg.title = "向你推荐:" + shareGameName;
String title;
if (ispopupWindow) {
if (shareNewsTitle != null) {
title = shareNewsTitle;
} else {
if (isPlugin){
title = shareGameName + "(光环加速版)";
} else {
title = shareGameName;
}
}
} else {
title = "玩手游不用肝的感觉真好";
}
msg.title = title;
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("webpage");
@ -336,12 +415,14 @@ public class ShareUtils {
req.scene = SendMessageToWX.Req.WXSceneTimeline;
loadBitMap(shareIcon, msg, req);
popupWindow.dismiss();
if (ispopupWindow) {
popupWindow.dismiss();
}
}
//新浪微博分享
private void sinaWeiboSahre(){
private void sinaWeiboSahre() {
Intent intent = new Intent(context, WeiBoShareActivity.class);
Bundle bundle = new Bundle();
bundle.putString("shareNewsTitle", shareNewsTitle);
@ -349,23 +430,31 @@ public class ShareUtils {
bundle.putString("shareGameName", shareGameName);
bundle.putString("shareUrl", shareUrl);
bundle.putBoolean("isPlugin",isPlugin);
bundle.putBoolean("ispopupWindow", ispopupWindow);
intent.putExtras(bundle);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
popupWindow.dismiss();
if (ispopupWindow) {
popupWindow.dismiss();
}
}
//短信分享
private void shortMessageSahre(){
private void shortMessageSahre() {
String smsBody;
if (shareNewsTitle != null){
smsBody = shareNewsTitle + shareUrl;
}else {
if (isPlugin){
smsBody = "向你推荐:" + shareGameName + "(光环加速版)" + shareUrl;
if (ispopupWindow) {
if (shareNewsTitle != null){
smsBody = shareNewsTitle + shareUrl;
}else {
smsBody = "向你推荐:" + shareGameName + shareUrl;
if (isPlugin){
smsBody = "向你推荐:" + shareGameName + "(光环加速版)" + shareUrl;
}else {
smsBody = "向你推荐:" + shareGameName + shareUrl;
}
}
} else {
smsBody = "这个App可以下载各种热门卡牌手游的加速版绿色安全超级省心做日常效率提高3-5倍光环助手官网" + shareUrl;
}
Intent sendIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("smsto:"));
@ -379,7 +468,9 @@ public class ShareUtils {
e.printStackTrace();
}
popupWindow.dismiss();
if (ispopupWindow) {
popupWindow.dismiss();
}
}
private String buildTransaction(final String type) {
@ -390,9 +481,12 @@ public class ShareUtils {
private void copyLink(String copyContent) {
ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
cmb.setText(copyContent);
popupWindow.dismiss();
Utils.toast(context,"复制成功");
if (ispopupWindow != null && ispopupWindow) {
popupWindow.dismiss();
Utils.toast(context,"复制成功,请到微信/QQ粘贴分享");
} else {
Utils.toast(context,"复制成功");
}
}
private void loadBitMap(final String iconUrl, final WXMediaMessage msg, final SendMessageToWX.Req req){

View File

@ -0,0 +1,80 @@
package com.gh.gamecenter;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.gh.base.BaseActivity;
import com.gh.common.util.QRCodeUtils;
import com.gh.common.util.ShareUtils;
import com.gh.common.util.Utils;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
/**
* Created by khy on 2017/2/6.
*/
public class ShareGhActivity extends BaseActivity {
@BindView(R.id.gh_address_qrcode) ImageView mGhQrcode;
@BindView(R.id.gh_address_tv) TextView mGhAddress;
@BindView(R.id.wifi_share_btn) Button mWifiShareBtn;
@BindView(R.id.content_ll) LinearLayout mContentLl;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View contentView = View.inflate(this, R.layout.activity_share_gh, null);
init(contentView, "分享光环");
ButterKnife.bind(this);
mGhAddress.setText(Html.fromHtml("<u>"+"www.ghzhushou.com"+"</u>"));
createQrCode();
ShareUtils.getInstance(this).showShareWindows(mContentLl, "http://www.ghzhushou.com?source=appshare300", "光环助手"
, "http://image.ghzhushou.com/pic/57d604808ab49e467d8b4568.png", null, false, false);
}
@OnClick(R.id.wifi_share_btn)
public void skipWifiShare() {
Intent intent = new Intent(this, ShareGhWfifActivity.class);
startActivity(intent);
}
@OnClick(R.id.gh_address_tv)
public void copyAddress() {
ClipboardManager cmb = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
cmb.setText("http://www.ghzhushou.com?source=appshare100");
Utils.toast(this, "网址复制成功");
}
private void createQrCode() {
new Thread(new Runnable() {
@Override
public void run() {
final String filePath = getExternalCacheDir().getPath() + "/ShareImg/ShareQRCode.jpg";
boolean success = QRCodeUtils.createQRImage("www.ghzhushou.com"
, 200, 200, filePath, ShareGhActivity.this);
if (success) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mGhQrcode.setImageBitmap(BitmapFactory.decodeFile(filePath));
}
});
}
}
}).start();
}
}

View File

@ -0,0 +1,257 @@
package com.gh.gamecenter;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.gh.base.AppController;
import com.gh.base.BaseActivity;
import com.gh.common.util.DialogUtils;
import com.gh.common.util.RandomUtils;
import com.gh.common.util.Utils;
import com.gh.gamecenter.entity.KcWebRequestEntity;
import com.gh.gamecenter.kuaichuan.Constant;
import com.gh.gamecenter.kuaichuan.DownloadUriHandler;
import com.gh.gamecenter.kuaichuan.HotspotManager;
import com.gh.gamecenter.kuaichuan.HtmlUriHandler;
import com.gh.gamecenter.kuaichuan.ImageUriHandler;
import com.gh.gamecenter.kuaichuan.KcUriHandler;
import com.gh.gamecenter.kuaichuan.WifiMgr;
import com.gh.gamecenter.kuaichuan.WifiUtils;
import com.gh.gamecenter.receiver.WifiAPBroadcastReceiver;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
/**
* Created by khy on 2017/2/6.
*/
public class ShareGhWfifActivity extends BaseActivity {
@BindView(R.id.hotspot_name) TextView mHotSpotName;
private ServerSocket mServerSocket;
private WifiAPBroadcastReceiver mWifiAPBroadcastReceiver;
private boolean mIsInitialized = false;
private List<KcUriHandler> mUriHandlers;
private boolean isColseActivity;
private boolean isOpenWifi; //记录开热点前的WiFi状态
private String mySsid;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View contentView = View.inflate(this, R.layout.activity_share_gh_wifi, null);
init(contentView, "分享光环");
ButterKnife.bind(this);
mUriHandlers = new ArrayList<>();
mUriHandlers.add(new HtmlUriHandler(this));
mUriHandlers.add(new ImageUriHandler(this));
mUriHandlers.add(new DownloadUriHandler(this));
isColseActivity = false;
if (WifiMgr.getInstance(this).isWifiEnable()) {
isOpenWifi = true;
WifiMgr.getInstance(this).closeWifi();
}
initHotSpot();
}
private void initHotSpot() {
mWifiAPBroadcastReceiver = new WifiAPBroadcastReceiver() {
@Override
public void onWifiApEnabled() {
if(!mIsInitialized){
Utils.log("===初始化热点成功");
AppController.MAIN_EXECUTOR.execute(checkHotSpot());
mIsInitialized = true;
mHotSpotName.setText(mySsid);
}
}
};
IntentFilter filter = new IntentFilter(WifiAPBroadcastReceiver.ACTION_WIFI_AP_STATE_CHANGED);
registerReceiver(mWifiAPBroadcastReceiver, filter);
HotspotManager.isApOn(this);
mySsid = "GHZS-";
int[] randomArray = RandomUtils.getRandomArray(4, 10);
for (int i : randomArray) {
mySsid = mySsid + i;
}
HotspotManager.configApState(this, mySsid); // change Ap state :boolean
}
private Runnable checkHotSpot() {
return new Runnable() {
@Override
public void run() {
try{
// 确保热点开启之后获取得到IP地址
String hotspotIpAddr = WifiMgr.getInstance(ShareGhWfifActivity.this).getHotspotLocalIpAddress();
int count = 0;
while(hotspotIpAddr.equals(Constant.DEFAULT_UNKOWN_IP) && count < Constant.DEFAULT_TRY_TIME){
Thread.sleep(1000);
hotspotIpAddr = WifiMgr.getInstance(ShareGhWfifActivity.this).getIpAddressFromHotspot();
count ++;
}
// 即使热点wifi的IP地址也是无法连接网络 所以采取此策略
count = 0;
while(!WifiUtils.pingIpAddress(hotspotIpAddr) && count < Constant.DEFAULT_TRY_TIME){
Thread.sleep(500);
count ++;
}
} catch(Exception e) {
Utils.log("==热点启动异常::" + e.toString());
}
Utils.log("===热点可用");
initMicroServer();
}
};
}
private void initMicroServer() {
new Thread(new Runnable() {
@Override
public void run() {
try {
Utils.log("===准备开启微型服务器");
if (mServerSocket == null) {
mServerSocket = new ServerSocket();
mServerSocket.setReuseAddress(true);
mServerSocket.bind(new InetSocketAddress(Constant.DEFAULT_MICRO_SERVER_PORT));
}
while (!isColseActivity) {
Utils.log("===循环等待客户端请求");
Socket socket = mServerSocket.accept();
KcWebRequestEntity requestEntity = hanlderSocket(socket);
for (KcUriHandler uriHandler : mUriHandlers) {
if (!uriHandler.matches(requestEntity.getUri())) {
continue;
}
Utils.log("====请求处理::" + requestEntity.getUri() + "==" + uriHandler.getClass().toString());
uriHandler.handler(requestEntity);
}
}
} catch (IOException e) {
Utils.log("===网页传下载出现异常" + e.toString());
e.printStackTrace();
}
}
}).start();
}
private KcWebRequestEntity hanlderSocket(Socket socket) {
KcWebRequestEntity requestEntity = new KcWebRequestEntity();
requestEntity.setSocket(socket);
try {
InputStream is = socket.getInputStream();
StringBuilder sb = new StringBuilder();
int a = 0, b = 0;
while((b != -1) && !(a == '\r' && b == '\n')){
a = b;
b = is.read();
sb.append((char)(b));
}
String[] split = sb.toString().split(" ");
if (split.length > 1) {
String requestUri = split[1];
requestEntity.setUri(requestUri);
Utils.log("===客户端请求链接::" + requestUri);
} else {
requestEntity.setUri("/ERROR");
Utils.log("===客户端请求链接异常::" + sb.toString());
}
} catch (IOException e) {
e.printStackTrace();
}
return requestEntity;
}
@Override
public void onBackPressed() {
backActivity();
}
@OnClick(R.id.actionbar_rl_back)
public void OnBackClikListener() {
backActivity();
}
private void backActivity() {
DialogUtils.showWarningDialog(this, "退出传送", "退出会中断所有游戏的传送,确定要退出吗?"
, "取消", "确定"
, new DialogUtils.ConfiremListener() {
@Override
public void onConfirem() {
isColseActivity = true;
unregisterReceiver(mWifiAPBroadcastReceiver);
try {
if(mWifiAPBroadcastReceiver != null){
unregisterReceiver(mWifiAPBroadcastReceiver);
mWifiAPBroadcastReceiver = null;
}
} catch (Exception e) {
Utils.log("网页传发送异常-关闭广播");
e.printStackTrace();
}
for (KcUriHandler uriHandler : mUriHandlers) {
uriHandler.destroy();
}
if (mServerSocket != null) {
try {
mServerSocket.close();
mServerSocket = null;
} catch (IOException e) {
e.printStackTrace();
}
}
HotspotManager.disableAp(ShareGhWfifActivity.this);
if (isOpenWifi) {
WifiMgr.getInstance(ShareGhWfifActivity.this).openWifi();
}
finish();
}
}, null);
}
}

View File

@ -43,6 +43,7 @@ public class WeiBoShareActivity extends Activity implements IWeiboHandler.Respon
private String shareNewsTitle; // shareNewsTitle不为空就是新闻分享否则是游戏分享
private boolean isPlugin;
private boolean ispopupWindow;
private IWeiboShareAPI mWeiboShareAPI;
@ -55,6 +56,7 @@ public class WeiBoShareActivity extends Activity implements IWeiboHandler.Respon
shareIcon = extras.getString("shareIcon");
shareNewsTitle = extras.getString("shareNewsTitle");
isPlugin = extras.getBoolean("isPlugin");
ispopupWindow = extras.getBoolean("ispopupWindow");
Utils.toast(this, "分享跳转中...");
@ -97,14 +99,18 @@ public class WeiBoShareActivity extends Activity implements IWeiboHandler.Respon
Bitmap bgBitmap = ShareUtils.getInstance(getApplication()).addBackGround(bitmap);
TextObject textObject = new TextObject();
if (shareNewsTitle != null){
textObject.text = shareNewsTitle + "@光环助手";
}else {
if (isPlugin){
textObject.text ="向你推荐:" + shareGameName + "(光环加速版)" + " @光环助手 ";
if (ispopupWindow) {
if (shareNewsTitle != null){
textObject.text = shareNewsTitle + "@光环助手";
}else {
textObject.text ="向你推荐:" + shareGameName + " @光环助手 " ;
if (isPlugin){
textObject.text ="向你推荐:" + shareGameName + "(光环加速版)" + " @光环助手 ";
}else {
textObject.text ="向你推荐:" + shareGameName + " @光环助手 " ;
}
}
} else {
textObject.text = "这个App可以下载各种热门卡牌手游的加速版绿色安全超级省心做日常效率提高3-5倍不用肝的感觉真好 @光环助手";
}
ImageObject imageObject = new ImageObject();

View File

@ -0,0 +1,29 @@
package com.gh.gamecenter.entity;
import java.net.Socket;
/**
* Created by khy on 2017/2/6.
*/
public class KcWebRequestEntity {
private Socket socket;
private String uri;
public Socket getSocket() {
return socket;
}
public void setSocket(Socket socket) {
this.socket = socket;
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
}

View File

@ -0,0 +1,69 @@
package com.gh.gamecenter.kuaichuan;
/**
* 常量类
*/
public class Constant {
/**
* 写文件的请求码
*/
public static final int REQUEST_CODE_WRITE_FILE = 200;
/**
* 读取文件的请求码
*/
public static final int REQUEST_CODE_READ_FILE = 201;
/**
* ServerSocket 默认IP
*/
public static final String DEFAULT_SERVER_IP = "192.168.43.1";
/**
* Wifi连接上时 未分配默认的Ip地址
*/
public static final String DEFAULT_UNKOWN_IP = "0.0.0.0";
/**
* 最大尝试数
*/
public static final int DEFAULT_TRY_TIME = 10;
/**
* 文件传输监听 默认端口
*/
public static final int DEFAULT_SERVER_PORT = 8080;
/**
* UDP通信服务 默认端口
*/
public static final int DEFAULT_SERVER_COM_PORT = 8011;
/**
* UDP通信服务 默认端口
*/
public static final int DEFAULT_SERVER_CANCEL_PORT = 8090;
/**
* Android微型服务器 默认端口
*/
public static final int DEFAULT_MICRO_SERVER_PORT = 3100;
public static final String KEY_IP_PORT_INFO = "KEY_IP_PORT_INFO";
/**
* 文件发送方 与 文件接收方 通信信息
*/
public static final String MSG_FILE_RECEIVER_INIT = "MSG_FILE_RECEIVER_INIT";
public static final String MSG_FILE_RECEIVER_INIT_SUCCESS = "MSG_FILE_RECEIVER_INIT_SUCCESS";
public static final String MSG_FILE_SENDER_START = "MSG_FILE_SENDER_START";
public static final String MSG_RECEIVER_CANCEL = "MSG_RECEIVER_CANCEL";
}

View File

@ -0,0 +1,92 @@
package com.gh.gamecenter.kuaichuan;
import android.app.Activity;
import com.gh.common.util.Utils;
import com.gh.gamecenter.entity.KcWebRequestEntity;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
/**
* Created by khy on 2017/2/6.
* 快传 网页传下载文件处理
*/
public class DownloadUriHandler implements KcUriHandler {
public static final String DOWNLOAD_PREFIX = "/download/";
private Activity mActivity;
public DownloadUriHandler(Activity activity) {
this.mActivity = activity;
}
@Override
public boolean matches(String uri) {
return uri.startsWith(DOWNLOAD_PREFIX);
}
@Override
public void handler(KcWebRequestEntity request) {
String absolutePath = mActivity.getApplicationContext().getPackageResourcePath(); // 光环助手安装包路径
Socket socket = request.getSocket();
File file = new File(absolutePath);
long fileSize = file.length();
OutputStream os;
PrintStream printStream = null;
try {
os = socket.getOutputStream();
printStream = new PrintStream(os);
} catch (IOException e) {
e.printStackTrace();
}
printStream.println("HTTP/1.0 200 OK");
printStream.println("Content-Length:" + fileSize);
printStream.println("Content-Type:application/octet-stream");
printStream.println();
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
int len = 0;
byte[] bytes = new byte[2048];
int count = 0;
while((len = fis.read(bytes)) != -1){
count = count + len;
printStream.write(bytes, 0, len);
}
Utils.log("====写入完成长度::" + count);
Thread.sleep(500);
} catch (Exception e) {
e.printStackTrace();
} finally {
if(fis != null){
try {
fis.close();
fis = null;
} catch (IOException e) {
e.printStackTrace();
}
}
}
printStream.flush();
printStream.close();
}
@Override
public void destroy() {
this.mActivity = null;
}
}

View File

@ -0,0 +1,82 @@
package com.gh.gamecenter.kuaichuan;
import android.content.Context;
import android.net.wifi.WifiConfiguration;
import java.lang.reflect.Method;
/**
* Created by khy on 2017/1/20.
*/
public class HotspotManager {
//检查热点开关
public static boolean isApOn(Context context) {
android.net.wifi.WifiManager wifimanager = (android.net.wifi.WifiManager) context.getSystemService(context.WIFI_SERVICE);
try {
Method method = wifimanager.getClass().getDeclaredMethod("isWifiApEnabled");
method.setAccessible(true);
return (Boolean) method.invoke(wifimanager);
}
catch (Throwable ignored) {
ignored.printStackTrace();
}
return false;
}
//关闭WiFi热点
public static void disableAp(Context context) {
android.net.wifi.WifiManager wifimanager = (android.net.wifi.WifiManager) context.getSystemService(context.WIFI_SERVICE);
try {
Method method = wifimanager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
method.invoke(wifimanager, null, false);
} catch (Throwable ignored) {
ignored.printStackTrace();
}
}
// toggle wifi hotspot on or off
public static boolean configApState(Context context) {
android.net.wifi.WifiManager wifimanager = (android.net.wifi.WifiManager) context.getSystemService(context.WIFI_SERVICE);
WifiConfiguration wificonfiguration = null;
try {
// if WiFi is on, turn it off
if(isApOn(context)) {
wifimanager.setWifiEnabled(false);
// if ap is on and then disable ap
disableAp(context);
}
Method method = wifimanager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
method.invoke(wifimanager, wificonfiguration, !isApOn(context));
return true;
}
catch (Exception e) {
e.printStackTrace();
}
return false;
}
// toggle wifi hotspot on or off, and specify the hotspot name
public static boolean configApState(Context context, String apName) {
android.net.wifi.WifiManager wifimanager = (android.net.wifi.WifiManager) context.getSystemService(context.WIFI_SERVICE);
WifiConfiguration wificonfiguration = null;
try {
wificonfiguration = new WifiConfiguration();
wificonfiguration.SSID = apName;
// if WiFi is on, turn it off
if(isApOn(context)) {
wifimanager.setWifiEnabled(false);
// if ap is on and then disable ap
disableAp(context);
}
Method method = wifimanager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
method.invoke(wifimanager, wificonfiguration, !isApOn(context));
return true;
}
catch (Exception e) {
e.printStackTrace();
}
return false;
}
}

View File

@ -0,0 +1,109 @@
package com.gh.gamecenter.kuaichuan;
import android.app.Activity;
import com.gh.common.util.Utils;
import com.gh.gamecenter.entity.KcWebRequestEntity;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
/**
* Created by khy on 2017/2/6.
* 快传 网页传加载网页
*/
public class HtmlUriHandler implements KcUriHandler{
private Activity mActivity;
public HtmlUriHandler(Activity activity) {
this.mActivity = activity;
}
@Override
public boolean matches(String uri) {
if(uri == null || uri.equals("") || uri.equals("/")){
return true;
}
return false;
}
@Override
public void handler(KcWebRequestEntity request) {
String homeHtml = null;
try {
InputStream is = this.mActivity.getAssets().open("Home.html");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int len = 0;
byte[] bytes = new byte[2048];
while((len = is.read(bytes)) != -1){
baos.write(bytes, 0, len);
}
homeHtml = baos.toString("UTF-8");
} catch (IOException e) {
Utils.log("===加载asset HTML文件异常" + e.toString());
e.printStackTrace();
}
if(request.getSocket() != null && homeHtml != null){
OutputStream outputStream = null;
PrintStream printStream = null;
try {
outputStream = request.getSocket().getOutputStream();
printStream = new PrintStream(outputStream);
printStream.println("HTTP/1.0 200 OK");
printStream.println("Content-Length:" + homeHtml.length());
printStream.println("Content-Type:text/html");
printStream.println("Cache-Control:no-cache");
printStream.println("Pragma:no-cache");
printStream.println("Expires:0");
printStream.println();
byte[] bytes = homeHtml.getBytes("UTF-8");
printStream.write(bytes);
Utils.log("====传输大小::" + homeHtml.length());
} catch (IOException e) {
Utils.log("===快传网页加载异常" + e.toString());
e.printStackTrace();
} finally {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
if(outputStream != null){
try {
outputStream.close();
outputStream = null;
} catch (Exception e) {
e.printStackTrace();
}
}
if(printStream != null){
try {
printStream.flush();
printStream.close();
printStream = null;
} catch (Exception e) {
e.printStackTrace();
}
}
}
} else {
Utils.log("===HTML 或者 Socket为空" );
}
Utils.log("===快传网页加载完成" );
}
@Override
public void destroy() {
mActivity = null;
}
}

View File

@ -0,0 +1,101 @@
package com.gh.gamecenter.kuaichuan;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import com.gh.common.util.Utils;
import com.gh.gamecenter.R;
import com.gh.gamecenter.entity.KcWebRequestEntity;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
/**
* Created by khy on 2017/2/6.
* 快传 网页传加载图片
*/
public class ImageUriHandler implements KcUriHandler {
Activity mActivity;
public static final String IMAGE_PREFIX = "/image/";
public ImageUriHandler(Activity mActivity) {
this.mActivity = mActivity;
}
@Override
public boolean matches(String uri) {
return uri.startsWith(IMAGE_PREFIX);
}
@Override
public void handler(KcWebRequestEntity request) {
Utils.log("====开始加载图片");
Socket socket = request.getSocket();
OutputStream os = null;
PrintStream printStream = null;
try {
os = socket.getOutputStream();
printStream = new PrintStream(os);
} catch (IOException e) {
e.printStackTrace();
}
Bitmap bitmap = BitmapFactory.decodeResource(mActivity.getResources(), R.drawable.logo);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
InputStream inputimage = new ByteArrayInputStream(baos.toByteArray());
BufferedInputStream ips = new BufferedInputStream(inputimage);
int bitmapSize = baos.toByteArray().length;
Utils.log("====开始加载图片大小::" + bitmapSize);
printStream.println("HTTP/1.0 200 OK");
printStream.println("Content-Length:" + bitmapSize);
printStream.println("Content-Type:multipart/mixed,text/html,image/png,image/jpeg,image/gif,image/x-xbitmap,application/vnd.oma.dd+xml,*/*");
printStream.println();
try {
int len = 0;
int i = 0;
byte[] bytes = new byte[1024];
while((len = ips.read(bytes)) != -1){
i = i + len;
printStream.write(bytes, 0, len);
}
Utils.log("====图片传输大小::" + i );
} catch (IOException e) {
Utils.log("====开始加载异常::" + e.toString());
e.printStackTrace();
}finally{
if(ips != null){
try {
ips.close();
ips = null;
} catch (IOException e) {
e.printStackTrace();
}
}
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
printStream.flush();
printStream.close();
Utils.log("====开始加载完成");
}
@Override
public void destroy() {
mActivity = null;
}
}

View File

@ -0,0 +1,27 @@
package com.gh.gamecenter.kuaichuan;
import com.gh.gamecenter.entity.KcWebRequestEntity;
/**
* Created by khy on 2017/2/6.
*/
public interface KcUriHandler {
/**
* 匹配Uri 判断返回请求结果
* @param uri
* @return
*/
boolean matches(String uri);
/**
* 请求链接和Socket对象
* @param request
*/
void handler(KcWebRequestEntity request);
/**
* 销毁
*/
void destroy();
}

View File

@ -0,0 +1,247 @@
package com.gh.gamecenter.kuaichuan;
import android.content.Context;
import android.net.DhcpInfo;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import java.util.List;
public class WifiMgr {
/**
* 创建WifiConfiguration的类型
*/
public static final int WIFICIPHER_NOPASS = 1;
public static final int WIFICIPHER_WEP = 2;
public static final int WIFICIPHER_WPA = 3;
private static WifiMgr mWifiMgr;
private Context mContext;
private android.net.wifi.WifiManager mWifiManager;
//scan the result
List<ScanResult> mScanResultList;
List<WifiConfiguration> mWifiConfigurations;
//current wifi configuration info
WifiInfo mWifiInfo;
private WifiMgr(Context context){
this.mContext = context;
this.mWifiManager = (android.net.wifi.WifiManager) context.getSystemService(Context.WIFI_SERVICE);
}
public static WifiMgr getInstance(Context context){
if(mWifiMgr == null){
synchronized (WifiMgr.class){
if(mWifiMgr == null){
mWifiMgr = new WifiMgr(context);
}
}
}
return mWifiMgr;
}
/**
* 打开wifi
*/
public void openWifi(){
if(!mWifiManager.isWifiEnabled()){
mWifiManager.setWifiEnabled(true);
}
}
/**
* 关闭wifi
*/
public void closeWifi(){
if(mWifiManager.isWifiEnabled()){
mWifiManager.setWifiEnabled(false);
}
}
/**
* 判断wifi是否开启的状态
* @return
*/
public boolean isWifiEnable(){
return mWifiManager == null ? false : mWifiManager.isWifiEnabled();
}
/**
* wifi扫描
*/
public void startScan(){
mWifiManager.startScan();
mScanResultList = mWifiManager.getScanResults();
mWifiConfigurations = mWifiManager.getConfiguredNetworks();
}
public List<ScanResult> getScanResultList() {
return mScanResultList;
}
public List<WifiConfiguration> getWifiConfigurations() {
return mWifiConfigurations;
}
/**
* 添加到指定Wifi网络 /切换到指定Wifi网络
* @param wf
* @return
*/
public boolean addNetwork(WifiConfiguration wf){
//断开当前的连接
disconnectCurrentNetwork();
//连接新的连接
int netId = mWifiManager.addNetwork(wf);
boolean enable = mWifiManager.enableNetwork(netId, true);
return enable;
}
/**
* 关闭当前的Wifi网络
* @return
*/
public boolean disconnectCurrentNetwork(){
if(mWifiManager != null && mWifiManager.isWifiEnabled()){
int netId = mWifiManager.getConnectionInfo().getNetworkId();
mWifiManager.disableNetwork(netId);
return mWifiManager.disconnect();
}
return false;
}
/**
* 创建WifiConfiguration
*
* @param ssid
* @param password
* @param type
* @return
*/
public static WifiConfiguration createWifiCfg(String ssid, String password, int type){
WifiConfiguration config = new WifiConfiguration();
config.allowedAuthAlgorithms.clear();
config.allowedGroupCiphers.clear();
config.allowedKeyManagement.clear();
config.allowedPairwiseCiphers.clear();
config.allowedProtocols.clear();
config.SSID = "\"" + ssid + "\"";
if(type == WIFICIPHER_NOPASS){
// config.wepKeys[0] = "";
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
// config.wepTxKeyIndex = 0;
// 无密码连接WIFI时连接不上wifi需要注释两行代码
// config.wepKeys[0] = "";
// config.wepTxKeyIndex = 0;
}else if(type == WIFICIPHER_WEP){
config.hiddenSSID = true;
config.wepKeys[0]= "\""+password+"\"";
config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
config.wepTxKeyIndex = 0;
}else if(type == WIFICIPHER_WPA){
config.preSharedKey = "\""+password+"\"";
config.hiddenSSID = true;
config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
config.status = WifiConfiguration.Status.ENABLED;
}
return config;
}
/**
* 获取当前WifiInfo
* @return
*/
public WifiInfo getWifiInfo(){
mWifiInfo = mWifiManager.getConnectionInfo();
return mWifiInfo;
}
/**
* 获取当前Wifi所分配的Ip地址
* @return
*/
// when connect the hotspot, is still returning "0.0.0.0".
public String getCurrentIpAddress(){
String ipAddress = "";
int address= mWifiManager.getDhcpInfo().ipAddress;
ipAddress = ((address & 0xFF)
+ "." + ((address >> 8) & 0xFF)
+ "." + ((address >> 16) & 0xFF)
+ "." + ((address >> 24) & 0xFF));
return ipAddress;
}
/**
* 设备连接Wifi之后 设备获取Wifi热点的IP地址
* @return
*/
public String getIpAddressFromHotspot(){
// WifiAP ip address is hardcoded in Android.
/* IP/netmask: 192.168.43.1/255.255.255.0 */
String ipAddress = "192.168.43.1";
DhcpInfo dhcpInfo = mWifiManager.getDhcpInfo();
int address = dhcpInfo.gateway;
ipAddress = ((address & 0xFF)
+ "." + ((address >> 8) & 0xFF)
+ "." + ((address >> 16) & 0xFF)
+ "." + ((address >> 24) & 0xFF));
return ipAddress;
}
/**
* 开启热点之后获取自身热点的IP地址
* @return
*/
public String getHotspotLocalIpAddress(){
// WifiAP ip address is hardcoded in Android.
/* IP/netmask: 192.168.43.1/255.255.255.0 */
String ipAddress = "192.168.43.1";
DhcpInfo dhcpInfo = mWifiManager.getDhcpInfo();
int address = dhcpInfo.serverAddress;
ipAddress = ((address & 0xFF)
+ "." + ((address >> 8) & 0xFF)
+ "." + ((address >> 16) & 0xFF)
+ "." + ((address >> 24) & 0xFF));
return ipAddress;
}
/**
* 关闭Wifi
*/
public void disableWifi(){
if(mWifiManager != null){
mWifiManager.setWifiEnabled(false);
}
}
}

View File

@ -0,0 +1,125 @@
package com.gh.gamecenter.kuaichuan;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;
import android.net.wifi.ScanResult;
import android.text.TextUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* Created by khy on 2017/1/17.
*/
public class WifiUtils {
public static final String NO_PASSWORD = "[ESS]";
public static final String NO_PASSWORD_WPS = "[WPS][ESS]";
/**
* 过滤有密码的Wifi扫描结果集合 和WIFI名称为空 不包含GHZS
* @param scanResultList
* @return
*/
public static List<ScanResult> filterWithNoPassword(List<ScanResult> scanResultList){
if(scanResultList == null || scanResultList.size() == 0){
return scanResultList;
}
List<ScanResult> resultList = new ArrayList<>();
for(ScanResult scanResult : scanResultList){
if(!TextUtils.isEmpty(scanResult.SSID) && scanResult.capabilities != null &&
scanResult.capabilities.equals(NO_PASSWORD) || scanResult.capabilities != null &&
scanResult.capabilities.equals(NO_PASSWORD_WPS)){
if (scanResult.SSID.contains("GHZS")) {
resultList.add(scanResult);
}
}
}
return resultList;
}
/**
* 判断指定的ipAddress是否可以ping
* @param ipAddress
* @return
*/
public static boolean pingIpAddress(String ipAddress) {
try {
Process process = Runtime.getRuntime().exec("/system/bin/ping -c 1 -w 100 " + ipAddress);
int status = process.waitFor();
if (status == 0) {
return true;
} else {
return false;
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
return false;
}
/**
* 获取Apk文件的Log图标
* @param context
* @param apk_path
* @return
*/
public static Drawable getApkThumbnail(Context context, String apk_path){
if(context == null){
return null;
}
PackageManager pm = context.getPackageManager();
PackageInfo packageInfo = pm.getPackageArchiveInfo(apk_path, PackageManager.GET_ACTIVITIES);
ApplicationInfo appInfo = packageInfo.applicationInfo;
/**获取apk的图标 */
appInfo.sourceDir = apk_path;
appInfo.publicSourceDir = apk_path;
if(appInfo != null){
Drawable apk_icon = appInfo.loadIcon(pm);
return apk_icon;
}
return null;
}
/**
* Drawable转Bitmap
*
* @param drawable
* @return
*/
public static Bitmap drawableToBitmap(Drawable drawable){
if(drawable == null){
return null;
}
// 取 drawable 的长宽
int w = drawable.getIntrinsicWidth();
int h = drawable.getIntrinsicHeight();
// 取 drawable 的颜色格式
Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565;
//建立对应的Bitmap
Bitmap bitmap = Bitmap.createBitmap(w, h, config);
// 建立对应 bitmap 的画布
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, w, h);
// 把 drawable 内容画到画布中
drawable.draw(canvas);
return bitmap;
}
}

View File

@ -0,0 +1,44 @@
package com.gh.gamecenter.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.util.Log;
/**
* Wifi AP BroadReciver
* wifi 热点 广播
*
*/
public abstract class WifiAPBroadcastReceiver extends BroadcastReceiver {
public static final String TAG = WifiAPBroadcastReceiver.class.getSimpleName();
public static final String ACTION_WIFI_AP_STATE_CHANGED = "android.net.wifi.WIFI_AP_STATE_CHANGED";
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equals(ACTION_WIFI_AP_STATE_CHANGED)){ //Wifi AP state changed
// get Wi-Fi Hotspot state here
int state = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);
Log.i(TAG, "Wifi Ap state--->>>" + state);
if (WifiManager.WIFI_STATE_ENABLED == state % 10) {
// Wifi is enabled
onWifiApEnabled();
}else if(WifiManager.WIFI_STATE_ENABLING == state % 10){
// Wifi is enabling
}else if(WifiManager.WIFI_STATE_DISABLED == state % 10){
// Wifi is disable
}else if(WifiManager.WIFI_STATE_DISABLING == state % 10){
// Wifi is disabling
}
}
}
/**
* 热点可用
*/
public abstract void onWifiApEnabled();
}