Files
assistant-android/app/src/main/java/com/gh/gamecenter/GameDetailsActivity.java
huangzhuanghua c43a60fe50 。。。
2016-06-21 18:27:51 +08:00

1285 lines
43 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.gh.gamecenter;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.util.ArrayMap;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.android.volley.NoConnectionError;
import com.android.volley.Response;
import com.android.volley.TimeoutError;
import com.android.volley.VolleyError;
import com.gh.base.AppController;
import com.gh.base.BaseFragmentActivity;
import com.gh.common.constant.Config;
import com.gh.common.constant.Constants;
import com.gh.common.util.DataUtils;
import com.gh.common.util.DialogUtils;
import com.gh.common.util.DisplayUtils;
import com.gh.common.util.FileUtils;
import com.gh.common.util.ImageUtils;
import com.gh.common.util.MD5Utils;
import com.gh.common.util.NetworkUtils;
import com.gh.common.util.PackageUtils;
import com.gh.common.util.PlatformUtils;
import com.gh.common.util.RunningUtils;
import com.gh.common.util.TimestampUtils;
import com.gh.common.util.Utils;
import com.gh.common.view.DownloadDialog;
import com.gh.download.DataWatcher;
import com.gh.download.DownloadEntry;
import com.gh.download.DownloadManager;
import com.gh.download.DownloadStatus;
import com.gh.gamecenter.entity.ApkEntity;
import com.gh.gamecenter.entity.DismissEntity;
import com.gh.gamecenter.entity.GameEntity;
import com.gh.gamecenter.eventbus.EBMoveTop;
import com.gh.gamecenter.eventbus.EBNetworkState;
import com.gh.gamecenter.eventbus.EBPWDismiss;
import com.gh.gamecenter.eventbus.EBPackage;
import com.gh.gamecenter.eventbus.EBPutUrl;
import com.gh.gamecenter.eventbus.EBRedDot;
import com.gh.gamecenter.eventbus.EBSlide;
import com.gh.gamecenter.gamedetails.GameDetailsFragment;
import com.gh.gamecenter.gamedetails.GameInformationFragment;
import com.gh.gamecenter.gamedetails.GameStrategyFragment;
import com.gh.gamecenter.manager.ConcernManager;
import com.gh.gamecenter.manager.DataCollectionManager;
import com.gh.gamecenter.manager.PackageManager;
import com.gh.gamecenter.personal.PersonalFragmentAdapter;
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
import com.google.gson.Gson;
import org.json.JSONObject;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import de.greenrobot.event.EventBus;
/**
* 游戏详情页面 如果要启动该页面,需要传 GameEntity 对象进来 对应key game
*
* @author 黄壮华
*
*/
public class GameDetailsActivity extends BaseFragmentActivity implements
OnClickListener, OnPageChangeListener {
private TextView gamedetails_tv_details, gamedetails_tv_information,
gamedetails_tv_strategy, gamedetails_tv_download, top_tv_name,
top_tv_info, top_tv_attention, titlebar_tv_details,
titlebar_tv_information, titlebar_tv_strategy, gamedetails_tv_per,
actionbar_tv_title;
// private TextView gamedetails_tv_database,titlebar_tv_database;
private ImageView top_iv_icon, gamedetails_iv_share;
private View gamedetails_slide_line, titlebar_slide_line;
private LinearLayout gamedetails_ll_top, gamedetails_ll_topbar,
gamedetails_ll_bottom, gamedetails_ll_loading, reuse_no_connection;
private ViewPager gamedetails_vp_show;
private ProgressBar gamedetails_progressbar;
private LinearLayout.LayoutParams lparams;
private RelativeLayout.LayoutParams rparams;
private ConcernManager concernManager;
private DownloadEntry downloadEntry;
private GameEntity entity;
private int currentItem = -1;
private int previous = 0;
private int width;
private String gameId;
private String entrance;
private DismissEntity dismissEntity;
private long start = 0L;
private boolean isShowPluginDialog = false;
private boolean isSentReport = false;
private ArrayMap<String, String> statusMap;
private Handler handler = new Handler();
private DataWatcher dataWatcher = new DataWatcher() {
@Override
public void onDataChanged(
HashMap<String, DownloadEntry> downloadingEntries) {
if (entity != null && entity.getApk().size() == 1) {
String url = entity.getApk().get(0).getUrl();
for (Entry<String, DownloadEntry> entry : downloadingEntries
.entrySet()) {
if (url.equals(entry.getValue().getUrl())) {
if (!"pause".equals(statusMap.get(entry.getValue()
.getUrl()))) {
downloadEntry = entry.getValue();
invalidate();
}
break;
}
}
}
for (Entry<String, DownloadEntry> entry : downloadingEntries
.entrySet()) {
DownloadEntry downloadEntry = entry.getValue();
if (DownloadStatus.done.equals(downloadEntry.getStatus())
&& downloadEntry.getMeta().get("isPlugin") != null) {
if (!RunningUtils
.isApplicationBroughtToBackground(getApplicationContext())
&& RunningUtils.isEqualsTop(
getApplicationContext(),
GameDetailsActivity.class.getName())) {
if (!isShowPluginDialog) {
isShowPluginDialog = true;
showPluginDialog(downloadEntry.getPath(),
downloadEntry.getName());
}
}
}
}
}
};
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Utils.log(this.getClass().getSimpleName() + " onSaveInstanceState");
outState.putInt("CurrentItem", gamedetails_vp_show.getCurrentItem());
AppController.put("GameEntity", entity);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View contentView = View.inflate(this, R.layout.activity_gamedetails,
null);
gameId = getIntent().getStringExtra("gameId");
entrance = getIntent().getStringExtra("entrance");
if (savedInstanceState != null) {
currentItem = savedInstanceState.getInt("CurrentItem");
}
init(contentView);
dismissEntity = new DismissEntity(false);
if (gameId != null) {
reuse_no_connection.setOnClickListener(this);
} else {
entity = (GameEntity) AppController.get("GameEntity", true);
}
statusMap = new ArrayMap<String, String>();
concernManager = new ConcernManager(getApplicationContext());
gamedetails_ll_bottom.setOnClickListener(this);
if (Config.isShow) {
gamedetails_ll_bottom.setVisibility(View.VISIBLE);
} else {
gamedetails_ll_bottom.setVisibility(View.GONE);
}
gamedetails_tv_download.setOnClickListener(this);
gamedetails_progressbar.setOnClickListener(this);
gamedetails_tv_per.setOnClickListener(this);
gamedetails_iv_share.setOnClickListener(this);
gamedetails_tv_details.setOnClickListener(this);
gamedetails_tv_information.setOnClickListener(this);
gamedetails_tv_strategy.setOnClickListener(this);
// gamedetails_tv_database.setOnClickListener(this);
titlebar_tv_details.setOnClickListener(this);
titlebar_tv_information.setOnClickListener(this);
titlebar_tv_strategy.setOnClickListener(this);
// titlebar_tv_database.setOnClickListener(this);
titlebar_tv_details.setClickable(false);
titlebar_tv_information.setClickable(true);
titlebar_tv_strategy.setClickable(true);
// titlebar_tv_database.setClickable(true);
gamedetails_tv_details.setClickable(false);
gamedetails_tv_information.setClickable(true);
gamedetails_tv_strategy.setClickable(true);
// gamedetails_tv_database.setClickable(true);
top_tv_attention.setOnClickListener(this);
DisplayMetrics outMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
width = outMetrics.widthPixels / 3;
lparams = new LinearLayout.LayoutParams(width / 2, DisplayUtils.dip2px(
getApplicationContext(), 2));
lparams.leftMargin = outMetrics.widthPixels / 12;
gamedetails_slide_line.setLayoutParams(lparams);
titlebar_slide_line.setLayoutParams(lparams);
rparams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
start = Calendar.getInstance().getTimeInMillis();
if (entity != null) {
init();
} else {
gamedetails_ll_loading.setVisibility(View.VISIBLE);
gamedetails_vp_show.setVisibility(View.GONE);
gamedetails_ll_top.setVisibility(View.GONE);
gamedetails_ll_bottom.setVisibility(View.GONE);
getGameDetails();
}
}
private void getGameDetails() {
JsonObjectExtendedRequest objectRequest = new JsonObjectExtendedRequest(
TimestampUtils.addTimestamp(Config.HOST + "v1d45/game/"
+ gameId + "/digest", Constants.GAME_CD),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Gson gson = new Gson();
entity = gson.fromJson(response.toString(),
GameEntity.class);
gamedetails_ll_loading.setVisibility(View.GONE);
gamedetails_vp_show.setVisibility(View.VISIBLE);
gamedetails_ll_top.setVisibility(View.VISIBLE);
if (Config.isShow) {
gamedetails_ll_bottom.setVisibility(View.VISIBLE);
} else {
gamedetails_ll_bottom.setVisibility(View.GONE);
}
init();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// 无网络连接和访问超时
if (error.getClass().equals(NoConnectionError.class)
|| error.getClass().equals(TimeoutError.class)) {
toast("网络错误");
reuse_no_connection.setVisibility(View.VISIBLE);
gamedetails_ll_loading.setVisibility(View.GONE);
}
}
});
AppController.addToRequestQueue(objectRequest,
PersonalFragmentAdapter.class);
}
private void init() {
actionbar_tv_title.setText(entity.getName());
top_tv_name.setText(entity.getName());
for (int i = 0, size = entity.getApk().size(); i < size; i++) {
ApkEntity apkEntity = entity.getApk().get(i);
if ("9u".equals(apkEntity.getPlatform())) {
top_tv_info.setText("V" + apkEntity.getVersion() + " | "
+ apkEntity.getSize());
break;
}
if (i == size - 1) {
top_tv_info.setText("V" + apkEntity.getVersion() + " | "
+ apkEntity.getSize());
}
}
if (entity.getApk() == null || entity.getApk().isEmpty()) {
gamedetails_tv_download.setText("暂无下载");
gamedetails_tv_download
.setBackgroundResource(R.drawable.textview_gray_style);
gamedetails_tv_download.setTextColor(0xFF999999);
gamedetails_tv_download.setClickable(false);
} else {
boolean isInstalled = false;
if (entity.getApk() != null
&& entity.getApk().size() == 1
&& PackageManager.isInstalled(entity.getApk().get(0)
.getPackageName())) {
isInstalled = true;
}
gamedetails_tv_download.setVisibility(View.VISIBLE);
gamedetails_progressbar.setVisibility(View.GONE);
gamedetails_tv_per.setVisibility(View.GONE);
if (isInstalled) {
if (TextUtils.isEmpty(entity.getDownloadAddWord())) {
gamedetails_tv_download.setText("启动《" + entity.getName()
+ "");
} else {
gamedetails_tv_download.setText("启动《" + entity.getName()
+ "" + entity.getDownloadAddWord());
}
} else {
if (TextUtils.isEmpty(entity.getDownloadAddWord())) {
gamedetails_tv_download.setText("下载《" + entity.getName()
+ "");
} else {
gamedetails_tv_download.setText("下载《" + entity.getName()
+ "" + entity.getDownloadAddWord());
}
}
}
if (concernManager.isConcern(entity.getId())) {
top_tv_attention.setText("取消关注");
top_tv_attention.setBackgroundResource(R.drawable.border_red_bg);
top_tv_attention.setTextColor(0xffbc2132);
} else {
top_tv_attention.setText("关注");
top_tv_attention
.setBackgroundResource(R.drawable.textview_red_style);
top_tv_attention.setTextColor(0xffffffff);
}
ImageUtils.getInstance(this).display(entity.getIcon(), top_iv_icon);
gamedetails_vp_show.setAdapter(new FragmentAdapter(
getSupportFragmentManager()));
gamedetails_vp_show.setOffscreenPageLimit(3);
gamedetails_vp_show.addOnPageChangeListener(this);
if (currentItem != -1) {
lparams.leftMargin = width * currentItem + width / 4;
gamedetails_slide_line.setLayoutParams(lparams);
titlebar_slide_line.setLayoutParams(lparams);
} else {
int current = getIntent().getIntExtra("current", -1);
if (current != -1) {
gamedetails_vp_show.setCurrentItem(current);
lparams.leftMargin = width * current + width / 4;
gamedetails_slide_line.setLayoutParams(lparams);
titlebar_slide_line.setLayoutParams(lparams);
}
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.actionbar_rl_back:
finish();
break;
case R.id.gamedetails_tv_details:
case R.id.titlebar_tv_details:
gamedetails_vp_show.setCurrentItem(0);
break;
case R.id.gamedetails_tv_information:
case R.id.titlebar_tv_information:
gamedetails_vp_show.setCurrentItem(1);
break;
case R.id.gamedetails_tv_strategy:
case R.id.titlebar_tv_strategy:
gamedetails_vp_show.setCurrentItem(2);
break;
// case R.id.gamedetails_tv_database:
// case R.id.titlebar_tv_database:
// gamedetails_vp_show.setCurrentItem(3);
// break;
case R.id.top_tv_attention:
if ("关注".equals(top_tv_attention.getText().toString())) {
Map<String, Object> kv = new HashMap<String, Object>();
kv.put("状态", "关注");
DataUtils.onEvent(GameDetailsActivity.this, "游戏关注",
entity.getName(), kv);
Map<String, Object> kv2 = new HashMap<String, Object>();
kv2.put("点击", "关注");
DataUtils.onEvent(GameDetailsActivity.this, "插件数据",
entity.getName(), kv2);
Map<String, Object> map = new HashMap<String, Object>();
map.put("game", entity.getName());
map.put("type", "关注");
map.put("createdOn", System.currentTimeMillis() / 1000);
DataCollectionManager.onEvent(GameDetailsActivity.this,
"concern", map);
concernManager.addByEntity(entity);
top_tv_attention.setText("取消关注");
top_tv_attention
.setBackgroundResource(R.drawable.border_red_bg);
top_tv_attention.setTextColor(0xffbc2132);
showSuccessDialog();
} else {
Map<String, Object> kv2 = new HashMap<String, Object>();
kv2.put("点击", "取消关注");
DataUtils.onEvent(GameDetailsActivity.this, "插件数据",
entity.getName(), kv2);
showCancelDialog();
}
break;
case R.id.gamedetails_tv_download:
Map<String, Object> kv0 = new HashMap<String, Object>();
kv0.put("点击", "下载");
DataUtils.onEvent(GameDetailsActivity.this, "插件数据", entity.getName(),
kv0);
if (entity.getApk() != null && !entity.getApk().isEmpty()) {
if (NetworkUtils.isWifiConnected(this)) {
if (entity.getApk().size() == 1) {
if (gamedetails_tv_download.getText().toString()
.contains("启动")) {
Map<String, Object> kv = new HashMap<String, Object>();
kv.put("版本", entity.getApk().get(0).getPlatform());
DataUtils.onEvent(GameDetailsActivity.this, "游戏启动",
entity.getName(), kv);
PackageUtils.launchApplicationByPackageName(
getApplicationContext(), entity.getApk()
.get(0).getPackageName());
} else {
ApkEntity apkEntity = entity.getApk().get(0);
String msg = FileUtils.isCanDownload(apkEntity
.getSize());
if (TextUtils.isEmpty(msg)) {
Map<String, Object> kv = new HashMap<String, Object>();
kv.put("版本", apkEntity.getPlatform());
kv.put("状态", "下载开始");
DataUtils.onEvent(GameDetailsActivity.this,
"游戏下载", entity.getName(), kv);
Map<String, Object> kv2 = new HashMap<String, Object>();
kv2.put("版本", apkEntity.getPlatform());
kv2.put("状态", "下载开始");
kv2.put("位置", entrance + "-游戏详情-开始");
DataUtils.onEvent(GameDetailsActivity.this,
"游戏下载位置", entity.getName(), kv2);
Map<String, Object> kv3 = new HashMap<String, Object>();
kv3.put(entrance, "下载数");
kv3.put(entrance, "下载开始");
DataUtils.onEvent(GameDetailsActivity.this,
"应用数据", entity.getName(), kv3);
Map<String, Object> map = new HashMap<String, Object>();
map.put("game", entity.getName());
map.put("method", "正常");
map.put("platform",
PlatformUtils.getInstance(
getApplicationContext())
.getPlatformName(
entity.getApk().get(0)
.getPlatform()));
map.put("status", "开始");
map.put("location", "游戏详情:" + entity.getName());
map.put("from", entrance);
map.put("network",
NetworkUtils.getConnectedType(this));
map.put("createdOn",
System.currentTimeMillis() / 1000);
DataCollectionManager.onEvent(this, "download", map);
DownloadEntry entry = new DownloadEntry();
entry.setUrl(apkEntity.getUrl());
entry.setName(entity.getName());
entry.setPath(FileUtils.getDownloadPath(
GameDetailsActivity.this,
MD5Utils.getContentMD5(entity.getName()
+ "_"
+ System.currentTimeMillis())
+ ".apk"));
HashMap<String, String> meta = new HashMap<String, String>();
meta.put("ETag", apkEntity.getEtag());
meta.put("icon", entity.getIcon());
meta.put("platform", apkEntity.getPlatform());
meta.put("gameId", entity.getId());
meta.put("entrance", entrance + "-游戏详情");
meta.put("location", "游戏详情:" + entity.getName());
entry.setMeta(meta);
DownloadManager.getInstance(
getApplicationContext()).add(entry);
EventBus.getDefault().post(new EBRedDot(1));
gamedetails_tv_download
.setVisibility(View.GONE);
gamedetails_progressbar
.setVisibility(View.VISIBLE);
gamedetails_tv_per.setVisibility(View.VISIBLE);
gamedetails_progressbar.setProgress(0);
gamedetails_tv_per.setText("0.0%");
statusMap.put(entry.getUrl(), "downloading");
} else {
toast(msg);
}
}
} else {
if (!dismissEntity.isShow()) {
dismissEntity.setShow(true);
DownloadDialog
.getInstance(GameDetailsActivity.this)
.showPopupWindow(v, entity,
entrance + "-游戏详情", statusMap,
"游戏详情:" + entity.getName());
}
}
} else {
final Dialog dialog = new Dialog(this);
View view = View.inflate(this,
R.layout.search_history_delete_dialog, null);
TextView title = (TextView) view
.findViewById(R.id.delete_dialog_title);
title.setText("警告");
TextView content = (TextView) view
.findViewById(R.id.delete_dialog_message);
content.setText("您当前的网络为2G/3G/4G下载将会消耗移动流量是否继续下载");
TextView cancel = (TextView) view
.findViewById(R.id.delete_dialog_cancel);
cancel.setText("取消");
cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
TextView confirem = (TextView) view
.findViewById(R.id.delete_dialog_confirm);
confirem.setText("继续");
confirem.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
if (entity.getApk().size() == 1) {
if (gamedetails_tv_download.getText()
.toString().contains("启动")) {
Map<String, Object> kv = new HashMap<String, Object>();
kv.put("版本", entity.getApk().get(0)
.getPlatform());
DataUtils.onEvent(GameDetailsActivity.this,
"游戏启动", entity.getName(), kv);
PackageUtils
.launchApplicationByPackageName(
getApplicationContext(),
entity.getApk().get(0)
.getPackageName());
} else {
ApkEntity apkEntity = entity.getApk()
.get(0);
String msg = FileUtils
.isCanDownload(apkEntity.getSize());
if (TextUtils.isEmpty(msg)) {
Map<String, Object> kv = new HashMap<String, Object>();
kv.put("版本", apkEntity.getPlatform());
kv.put("状态", "下载开始");
DataUtils.onEvent(
GameDetailsActivity.this,
"游戏下载", entity.getName(), kv);
Map<String, Object> kv2 = new HashMap<String, Object>();
kv2.put("版本", apkEntity.getPlatform());
kv2.put("状态", "下载开始");
kv2.put("位置", entrance + "-游戏详情-开始");
DataUtils.onEvent(
GameDetailsActivity.this,
"游戏下载位置", entity.getName(), kv2);
Map<String, Object> kv3 = new HashMap<String, Object>();
kv3.put("下载", "下载量");
kv3.put("下载", apkEntity.getPlatform());
DataUtils.onEvent(
GameDetailsActivity.this,
"插件数据", entity.getName(), kv3);
Map<String, Object> map = new HashMap<String, Object>();
map.put("game", entity.getName());
map.put("method", "正常");
map.put("platform",
PlatformUtils
.getInstance(
getApplicationContext())
.getPlatformName(
entity.getApk()
.get(0)
.getPlatform()));
map.put("status", "开始");
map.put("location", "游戏详情:" + entity.getName());
map.put("from", entrance);
map.put("network", NetworkUtils.getConnectedType(GameDetailsActivity.this));
map.put("createdOn", System.currentTimeMillis() / 1000);
DataCollectionManager.onEvent(GameDetailsActivity.this, "download", map);
DownloadEntry entry = new DownloadEntry();
entry.setUrl(apkEntity.getUrl());
entry.setName(entity.getName());
entry.setPath(FileUtils
.getDownloadPath(
GameDetailsActivity.this,
MD5Utils.getContentMD5(entity
.getName()
+ "_"
+ System.currentTimeMillis())
+ ".apk"));
HashMap<String, String> meta = new HashMap<String, String>();
meta.put("ETag", apkEntity.getEtag());
meta.put("icon", entity.getIcon());
meta.put("platform",
apkEntity.getPlatform());
meta.put("gameId", entity.getId());
meta.put("entrance", entrance + "-游戏详情");
meta.put("location",
"游戏详情:" + entity.getName());
entry.setMeta(meta);
DownloadManager.getInstance(
getApplicationContext()).add(
entry);
EventBus.getDefault().post(
new EBRedDot(1));
gamedetails_tv_download
.setVisibility(View.GONE);
gamedetails_progressbar
.setVisibility(View.VISIBLE);
gamedetails_tv_per
.setVisibility(View.VISIBLE);
gamedetails_progressbar.setProgress(0);
gamedetails_tv_per.setText("0.0%");
statusMap.put(entry.getUrl(),
"downloading");
} else {
toast(msg);
}
}
} else {
if (!dismissEntity.isShow()) {
dismissEntity.setShow(true);
DownloadDialog.getInstance(
GameDetailsActivity.this)
.showPopupWindow(v, entity,
entrance + "-游戏详情",
statusMap,
"游戏详情:" + entity.getName());
}
}
}
});
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(view);
dialog.show();
}
} else {
toast("稍等片刻~!游戏正在上传中...");
}
break;
case R.id.gamedetails_iv_share:
// http://news.ghzhushou.com
Map<String, Object> kv = new HashMap<String, Object>();
kv.put("点击", "分享");
DataUtils.onEvent(this, "插件数据", entity.getName(), kv);
Map<String, Object> map = new HashMap<String, Object>();
map.put("location", "分享");
map.put("createOn", System.currentTimeMillis() / 1000);
map.put("news", entity.getName());
map.put("page", "游戏详情");
DataCollectionManager.onEvent(this, "click-item", map);
String url = "http://112.124.59.31/game_center/static/game_"
+ entity.getId() + ".html";
showShare(url, entity.getName(), entity.getIcon(), entrance, "游戏");
break;
case R.id.gamedetails_progressbar:
case R.id.gamedetails_tv_per:
String str = gamedetails_tv_per.getText().toString();
if ("继续".equals(str)) {
statusMap.put(downloadEntry.getUrl(), "downloading");
gamedetails_tv_per.setText(downloadEntry.getPercent() + "%");
Message msg = Message.obtain();
msg.what = Constants.CONTINUE_DOWNLOAD_TASK;
msg.obj = downloadEntry.getUrl();
DownloadManager.getInstance(getApplicationContext()).put(downloadEntry.getUrl(),
System.currentTimeMillis());
DownloadManager.getInstance(getApplicationContext()).sendMessageDelayed(msg, 1000);
} else if ("安装".equals(str)) {
String path = downloadEntry.getPath();
PackageManager manager = new PackageManager(
getApplicationContext());
if (manager.launchSetup(path)) {
startActivity(PackageUtils.getInstallIntent(path));
} else {
DialogUtils.showDialog(GameDetailsActivity.this, path);
}
} else if("等待".equals(str)){
} else {
statusMap.put(downloadEntry.getUrl(), "pause");
gamedetails_tv_per.setText("继续");
Message msg = Message.obtain();
msg.what = Constants.PAUSE_DOWNLOAD_TASK;
msg.obj = downloadEntry.getUrl();
DownloadManager.getInstance(getApplicationContext()).put(downloadEntry.getUrl(),
System.currentTimeMillis());
DownloadManager.getInstance(getApplicationContext()).sendMessageDelayed(msg, 1000);
}
break;
case R.id.reuse_no_connection:
gamedetails_ll_loading.setVisibility(View.VISIBLE);
reuse_no_connection.setVisibility(View.GONE);
handler.postDelayed(runnable, 1000);
break;
default:
break;
}
}
private void showSuccessDialog() {
final Dialog dialog = new Dialog(this);
View view = View.inflate(this, R.layout.gamedetails_attention_dialog,
null);
TextView title = (TextView) view.findViewById(R.id.dialog_title);
title.setText("关注成功");
TextView confirm = (TextView) view.findViewById(R.id.dialog_confirm);
confirm.setText("我知道了");
confirm.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
TextView message = (TextView) view.findViewById(R.id.dialog_message);
message.setText("游戏的最新动态消息会优先提醒您,包括攻略、资讯、开服信息、开测信息以及最新的插件。");
view.findViewById(R.id.dialog_rl_cancel).setVisibility(View.GONE);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(view);
dialog.show();
}
private void showCancelDialog() {
final Dialog dialog = new Dialog(this);
View view = View.inflate(this, R.layout.gamedetails_attention_dialog,
null);
TextView title = (TextView) view.findViewById(R.id.dialog_title);
title.setText("取消关注");
TextView cancel = (TextView) view.findViewById(R.id.dialog_cancel);
cancel.setText("取消");
cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
TextView message = (TextView) view.findViewById(R.id.dialog_message);
Spanned content = Html
.fromHtml("取消关注游戏后,您将无法及时收到游戏的<font color='#ff0000'>攻略</font>、<font color='#ff0000'>资讯</font>等最新动态提醒,您确定取消吗?");
message.setText(content);
view.findViewById(R.id.dialog_rl_confirm).setVisibility(View.VISIBLE);
view.findViewById(R.id.dialog_confirm).setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
Map<String, Object> kv = new HashMap<String, Object>();
kv.put("状态", "取消关注");
DataUtils.onEvent(GameDetailsActivity.this, "游戏关注",
entity.getName(), kv);
Map<String, Object> map = new HashMap<String, Object>();
map.put("game", entity.getName());
map.put("type", "关注");
map.put("createdOn", System.currentTimeMillis() / 1000);
DataCollectionManager.onEvent(GameDetailsActivity.this,
"concern", map);
concernManager.deleteConcern(entity.getId());
dialog.dismiss();
top_tv_attention.setText("关注");
top_tv_attention
.setBackgroundResource(R.drawable.textview_red_style);
top_tv_attention.setTextColor(0xffffffff);
}
});
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(view);
dialog.show();
}
private void showPluginDialog(final String path, final String gameName) {
final Dialog dialog = new Dialog(this);
View view = View.inflate(this, R.layout.search_history_delete_dialog,
null);
TextView title = (TextView) view.findViewById(R.id.delete_dialog_title);
title.setText("插件化安装");
TextView content = (TextView) view
.findViewById(R.id.delete_dialog_message);
Spanned spanned = Html.fromHtml("您将进行插件化安装以实现插件功能,此过程将"
+ "<font color=\"#ff0000\">卸载</font>" + "当前使用的版本并"
+ "<font color=\"#ff0000\">安装插件版本</font>" + "");
content.setText(spanned);
TextView cancel = (TextView) view
.findViewById(R.id.delete_dialog_cancel);
cancel.setText("取消");
cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
TextView confirm = (TextView) view
.findViewById(R.id.delete_dialog_confirm);
confirm.setText("确定");
confirm.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
Map<String, Object> kv6 = new HashMap<String, Object>();
kv6.put("操作", "一次性完成");
DataUtils.onEvent(GameDetailsActivity.this, "插件化", gameName, kv6);
if (FileUtils.isEmptyFile(path)) {
toast("解析包错误");
} else {
MainActivity.uninstallMap.put(PackageUtils.getPackageNameByPath(getApplicationContext(), path), path);
startActivity(PackageUtils.getUninstallIntent(getApplicationContext(), path));
}
}
});
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
isShowPluginDialog = false;
}
});
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(view);
dialog.show();
}
@Override
public void onPageSelected(int position) {
switch (position) {
case 0:
if (gamedetails_ll_topbar.getVisibility() == View.VISIBLE) {
EventBus.getDefault().post(new EBSlide(0, previous, true));
}
previous = 0;
titlebar_tv_details.setClickable(false);
titlebar_tv_information.setClickable(true);
titlebar_tv_strategy.setClickable(true);
// titlebar_tv_database.setClickable(true);
gamedetails_tv_details.setClickable(false);
gamedetails_tv_information.setClickable(true);
gamedetails_tv_strategy.setClickable(true);
// gamedetails_tv_database.setClickable(true);
titlebar_tv_details.setTextColor(getResources().getColor(
R.color.theme_colors));
titlebar_tv_information.setTextColor(0xFF333333);
titlebar_tv_strategy.setTextColor(0xFF333333);
// titlebar_tv_database.setTextColor(0xFF333333);
gamedetails_tv_details.setTextColor(getResources().getColor(
R.color.theme_colors));
gamedetails_tv_information.setTextColor(0xFF333333);
gamedetails_tv_strategy.setTextColor(0xFF333333);
// gamedetails_tv_database.setTextColor(0xFF333333);
break;
case 1:
if (gamedetails_ll_topbar.getVisibility() == View.VISIBLE) {
EventBus.getDefault().post(new EBSlide(0, previous, true));
}
previous = 1;
titlebar_tv_details.setClickable(true);
titlebar_tv_information.setClickable(false);
titlebar_tv_strategy.setClickable(true);
// titlebar_tv_database.setClickable(true);
gamedetails_tv_details.setClickable(true);
gamedetails_tv_information.setClickable(false);
gamedetails_tv_strategy.setClickable(true);
// gamedetails_tv_database.setClickable(true);
titlebar_tv_details.setTextColor(0xFF333333);
titlebar_tv_information.setTextColor(getResources().getColor(
R.color.theme_colors));
titlebar_tv_strategy.setTextColor(0xFF333333);
// titlebar_tv_database.setTextColor(0xFF333333);
gamedetails_tv_details.setTextColor(0xFF333333);
gamedetails_tv_information.setTextColor(getResources().getColor(
R.color.theme_colors));
gamedetails_tv_strategy.setTextColor(0xFF333333);
// gamedetails_tv_database.setTextColor(0xFF333333);
break;
case 2:
if (gamedetails_ll_topbar.getVisibility() == View.VISIBLE) {
EventBus.getDefault().post(new EBSlide(0, previous, true));
}
previous = 2;
titlebar_tv_details.setClickable(true);
titlebar_tv_information.setClickable(true);
titlebar_tv_strategy.setClickable(false);
// titlebar_tv_database.setClickable(true);
gamedetails_tv_details.setClickable(true);
gamedetails_tv_information.setClickable(true);
gamedetails_tv_strategy.setClickable(false);
// gamedetails_tv_database.setClickable(true);
titlebar_tv_details.setTextColor(0xFF333333);
titlebar_tv_information.setTextColor(0xFF333333);
titlebar_tv_strategy.setTextColor(getResources().getColor(
R.color.theme_colors));
// titlebar_tv_database.setTextColor(0xFF333333);
gamedetails_tv_details.setTextColor(0xFF333333);
gamedetails_tv_information.setTextColor(0xFF333333);
gamedetails_tv_strategy.setTextColor(getResources().getColor(
R.color.theme_colors));
// gamedetails_tv_database.setTextColor(0xFF333333);
break;
case 3:
titlebar_tv_details.setClickable(true);
titlebar_tv_information.setClickable(true);
titlebar_tv_strategy.setClickable(true);
// titlebar_tv_database.setClickable(false);
gamedetails_tv_details.setClickable(true);
gamedetails_tv_information.setClickable(true);
gamedetails_tv_strategy.setClickable(true);
// gamedetails_tv_database.setClickable(false);
titlebar_tv_details.setTextColor(0xFF333333);
titlebar_tv_information.setTextColor(0xFF333333);
titlebar_tv_strategy.setTextColor(0xFF333333);
// titlebar_tv_database.setTextColor(getResources().getColor(R.color.theme_colors));
gamedetails_tv_details.setTextColor(0xFF333333);
gamedetails_tv_information.setTextColor(0xFF333333);
gamedetails_tv_strategy.setTextColor(0xFF333333);
// gamedetails_tv_database.setTextColor(getResources().getColor(R.color.theme_colors));
break;
}
}
@Override
public void onPageScrolled(int position, float positionOffset,
int positionOffsetPixels) {
if (positionOffset != 0) {
lparams.leftMargin = (int) (width * (positionOffset + position))
+ width / 4;
gamedetails_slide_line.setLayoutParams(lparams);
titlebar_slide_line.setLayoutParams(lparams);
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
private class FragmentAdapter extends FragmentPagerAdapter {
public FragmentAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
Fragment fragment;
if (position == 0) {
GameDetailsFragment gameDetailsFragment = new GameDetailsFragment();
gameDetailsFragment.setParams(entity.getId(),
entity.getName(), entrance);
fragment = gameDetailsFragment;
} else if (position == 1) {
GameInformationFragment gameInformationFragment = new GameInformationFragment();
gameInformationFragment.setParams(entity.getId(),
entity.getName(), entrance);
fragment = gameInformationFragment;
} else {
GameStrategyFragment gameStrategyFragment = new GameStrategyFragment();
gameStrategyFragment.setParams(entity.getId(),
entity.getName(), entrance);
fragment = gameStrategyFragment;;
}
return fragment;
}
@Override
public int getCount() {
return 3;
}
}
private void invalidate() {
gamedetails_progressbar
.setProgress((int) (downloadEntry.getPercent() * 10));
switch (downloadEntry.getStatus()) {
case downloading:
gamedetails_tv_per.setText(downloadEntry.getPercent() + "%");
break;
case pause:
case timeout:
case neterror:
gamedetails_tv_per.setText("继续");
break;
case waiting:
gamedetails_tv_per.setText("等待");
break;
case done:
EventBus.getDefault().post(
new EBPutUrl(entity.getApk().get(0).getPackageName(),
downloadEntry.getUrl()));
gamedetails_tv_per.setText("安装");
break;
case cancel:
case hijack:
gamedetails_tv_download.setVisibility(View.VISIBLE);
gamedetails_progressbar.setVisibility(View.GONE);
gamedetails_tv_per.setVisibility(View.GONE);
if (TextUtils.isEmpty(entity.getDownloadAddWord())) {
gamedetails_tv_download.setText("下载《" + entity.getName() + "");
} else {
gamedetails_tv_download.setText("下载《" + entity.getName() + ""
+ entity.getDownloadAddWord());
}
break;
default:
break;
}
}
@Override
protected void onResume() {
super.onResume();
if (entity != null && entity.getApk().size() == 1) {
if (PackageManager.isInstalled(entity.getApk().get(0)
.getPackageName())) {
gamedetails_tv_download.setVisibility(View.VISIBLE);
gamedetails_progressbar.setVisibility(View.GONE);
gamedetails_tv_per.setVisibility(View.GONE);
gamedetails_tv_download.setText("启动《" + entity.getName() + "");
if (TextUtils.isEmpty(entity.getDownloadAddWord())) {
gamedetails_tv_download.setText("启动《" + entity.getName()
+ "");
} else {
gamedetails_tv_download.setText("启动《" + entity.getName()
+ "" + entity.getDownloadAddWord());
}
} else {
String url = entity.getApk().get(0).getUrl();
for (DownloadEntry entry : DownloadManager.getInstance(
getApplicationContext()).getAll()) {
if (url.equals(entry.getUrl())) {
downloadEntry = entry;
gamedetails_tv_download.setVisibility(View.GONE);
gamedetails_progressbar.setVisibility(View.VISIBLE);
gamedetails_tv_per.setVisibility(View.VISIBLE);
invalidate();
break;
}
}
}
}
DownloadManager.getInstance(getApplicationContext()).addObserver(
dataWatcher);
}
@Override
protected void onPause() {
super.onPause();
statusMap.clear();
DownloadManager.getInstance(getApplicationContext()).removeObserver(dataWatcher);
if (!isSentReport) {
long end = Calendar.getInstance().getTimeInMillis();
int seconds = (int) ((end - start) / 1000);
String cost = "";
if (seconds < 5) {
cost = "小于5秒";
} else if (seconds < 30) {
cost = "5秒30秒";
} else if (seconds < 60) {
cost = "30秒60秒";
} else {
cost = "大于60秒";
}
Map<String, Object> kv = new HashMap<String, Object>();
kv.put("停留时长", cost);
DataUtils.onEvent(this, "插件数据", entity.getName(), kv);
if ("主页-最新插件".equals(entrance)) {
Map<String, Object> kv2 = new HashMap<String, Object>();
kv2.put(entity.getName(), "阅读时长:" + cost);
DataUtils.onEvent(this, "主页数据", "最新插件", kv2);
} else if ("主页-热门卡牌".equals(entrance)) {
Map<String, Object> kv2 = new HashMap<String, Object>();
kv2.put(entity.getName(), "阅读时长:" + cost);
DataUtils.onEvent(this, "主页数据", "热门卡牌", kv2);
} else if ("主页-新测卡牌".equals(entrance)) {
Map<String, Object> kv2 = new HashMap<String, Object>();
kv2.put(entity.getName(), "阅读时长:" + cost);
DataUtils.onEvent(this, "主页数据", "新测卡牌", kv2);
}
if (seconds > 0) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("game", entity.getName());
map.put("time", seconds);
map.put("from", entrance);
map.put("createdOn", System.currentTimeMillis() / 1000);
DataCollectionManager.onEvent(this, "game", map);
}
isSentReport = true;
}
}
public void onEventMainThread(EBPWDismiss dismiss) {
if (dismissEntity != null) {
dismissEntity.setShow(false);
}
}
public void onEventMainThread(EBPackage busFour) {
if (entity.getApk().size() == 1) {
String packageName = entity.getApk().get(0).getPackageName();
if (packageName.equals(busFour.getPackageName())) {
if ("安装".equals(busFour.getType())) {
gamedetails_tv_download.setVisibility(View.VISIBLE);
gamedetails_progressbar.setVisibility(View.GONE);
gamedetails_tv_per.setVisibility(View.GONE);
gamedetails_tv_download.setText("启动《" + entity.getName()
+ "");
} else if ("卸载".equals(busFour.getType())) {
gamedetails_tv_download.setVisibility(View.VISIBLE);
gamedetails_progressbar.setVisibility(View.GONE);
gamedetails_tv_per.setVisibility(View.GONE);
gamedetails_tv_download.setText("下载《" + entity.getName()
+ "");
}
}
}
}
public void onEventMainThread(EBNetworkState busNetworkState) {
if (gameId != null && busNetworkState.isNetworkConnected()
&& reuse_no_connection.getVisibility() == View.VISIBLE) {
gamedetails_ll_loading.setVisibility(View.VISIBLE);
reuse_no_connection.setVisibility(View.GONE);
handler.postDelayed(runnable, 1000);
}
}
public void onEventMainThread(EBMoveTop moveTop) {
if (moveTop.getType().equals("top")) {
if (moveTop.getVisibility() == View.VISIBLE) {
gamedetails_ll_topbar.setVisibility(View.VISIBLE);
} else if (moveTop.getVisibility() == View.GONE) {
gamedetails_ll_topbar.setVisibility( View.GONE);
} else if (moveTop.getVisibility() == View.INVISIBLE) {
gamedetails_ll_topbar.setVisibility(View.INVISIBLE);
}
if (rparams.topMargin != moveTop.getTopMargin()) {
rparams.topMargin = moveTop.getTopMargin();
gamedetails_ll_top.setLayoutParams(rparams);
}
} else if (moveTop.getType().equals("topbar")) {
gamedetails_vp_show.setCurrentItem(2);
}
}
Runnable runnable = new Runnable() {
@Override
public void run() {
getGameDetails();
}
};
@Override
protected void onDestroy() {
super.onDestroy();
gamedetails_tv_details = null;
gamedetails_tv_information = null;
gamedetails_tv_strategy = null;
gamedetails_tv_download = null;
top_tv_name = null;
top_tv_info = null;
top_tv_attention = null;
titlebar_tv_details = null;
titlebar_tv_information = null;
titlebar_tv_strategy = null;
gamedetails_tv_per = null;
actionbar_tv_title = null;
top_iv_icon = null;
gamedetails_iv_share = null;
gamedetails_slide_line = null;
titlebar_slide_line = null;
gamedetails_ll_top = null;
gamedetails_ll_topbar = null;
gamedetails_ll_bottom = null;
gamedetails_ll_loading = null;
reuse_no_connection = null;
gamedetails_vp_show = null;
gamedetails_progressbar = null;
lparams = null;
rparams = null;
concernManager = null;
downloadEntry = null;
entity = null;
gameId = null;
entrance = null;
dismissEntity = null;
statusMap = null;
handler = null;
dataWatcher = null;
}
}