MainActivity整理

This commit is contained in:
huangzhuanghua
2016-09-24 18:34:47 +08:00
parent 3d3b596962
commit ce94de1214
3 changed files with 250 additions and 352 deletions

View File

@ -124,10 +124,17 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
private GameFragment gameFragment;
private NewsFragment newsFragment;
private PersonalFragment personalFragment;
private LinearLayout home1Layout, home2Layout, home3Layout;
private ImageView home1Image, home2Image, home3Image;
private TextView home1Title, home2Title, home3Title;
private LinearLayout home1Layout;
private LinearLayout home2Layout;
private LinearLayout home3Layout;
private ImageView home1Image;
private ImageView home2Image;
private ImageView home3Image;
private TextView home1Title;
private TextView home2Title;
private TextView home3Title;
private AppEntity appEntity;
private SharedPreferences sp;
private ConcernManager concernManager;
@ -137,12 +144,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
private boolean isShowDownload = false;
private boolean isNewFirstLaunch;
private Dialog dialog;
private ProgressBar app_pb_progress;
private TextView app_tv_speed;
private TextView app_tv_percent;
private TextView app_btn_cancel;
private AppEntity appEntity;
private Handler handler = new Handler();
// 黄壮华 添加观察者 修改2015/8/15
private DataWatcher dataWatcher = new DataWatcher() {
@ -164,96 +166,41 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
finish();
}
} else {
Map<String, Object> kv = new HashMap<>();
kv.put("版本", downloadEntity.getPlatform());
kv.put("状态", "下载完成");
if (downloadEntity.isUpdate()) {
DataUtils.onEvent(MainActivity.this, "游戏更新",
downloadEntity.getName(), kv);
} else {
DataUtils.onEvent(MainActivity.this, "游戏下载",
downloadEntity.getName(), kv);
Map<String, Object> kv2 = new HashMap<>();
kv2.put("版本", downloadEntity.getPlatform());
kv2.put("状态", "下载完成");
kv2.put("位置", downloadEntity.getEntrance() + "-完成");
DataUtils.onEvent(MainActivity.this, "游戏下载位置",
downloadEntity.getName(), kv2);
}
if (downloadEntity.isPluggable()) {
Map<String, Object> kv6 = new HashMap<>();
kv6.put("下载", "下载完成");
kv6.put("版本", downloadEntity.getPlatform());
DataUtils.onEvent(MainActivity.this, "插件化",
downloadEntity.getName(), kv6);
}
Map<String, Object> map = new HashMap<>();
map.put("game", downloadEntity.getName());
map.put("game_id", downloadEntity.getGameId());
if (downloadEntity.isPluggable()) {
map.put("method", "插件化");
map.put("btn_status", "插件化");
} else if (downloadEntity.isUpdate()) {
map.put("method", "更新");
map.put("btn_status", "更新");
} else {
map.put("method", "正常");
map.put("btn_status", "下载");
}
map.put("platform", PlatformUtils.getInstance(getApplicationContext())
.getPlatformName(downloadEntity.getPlatform()));
map.put("status", "完成");
map.put("location", downloadEntity.getLocation());
map.put("entrance", downloadEntity.getEntrance());
map.put("network", NetworkUtils.getConnectedType(MainActivity.this));
DataCollectionManager.onEvent(MainActivity.this, "download", map);
statDoneEvent(downloadEntity);
if (RunningUtils.isApplicationBroughtToBackground(getApplicationContext())) {
// 应用程序在后台如果是插件化下载则弹出notification提示用户
if (downloadEntity.isPluggable()) {
NotificationManager nManager = (NotificationManager) getSystemService(
Context.NOTIFICATION_SERVICE);
String path = downloadEntity.getPath();
Intent intent = new Intent();
intent.putExtra("path", path);
intent.setAction("com.gh.gamecenter.UNINSTALL");
PendingIntent pendingIntent = PendingIntent
.getBroadcast(MainActivity.this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
String platform = PlatformUtils
.getInstance(getApplicationContext())
String platform = PlatformUtils.getInstance(getApplicationContext())
.getPlatformName(downloadEntity.getPlatform());
String title = downloadEntity.getName() + " - " + platform;
Notification notification = new NotificationCompat.Builder(
MainActivity.this)
Intent intent = new Intent();
intent.putExtra("path", path);
intent.setAction("com.gh.gamecenter.UNINSTALL");
PendingIntent pendingIntent = PendingIntent.getBroadcast(
MainActivity.this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
Notification notification = new NotificationCompat.Builder(MainActivity.this)
.setSmallIcon(R.drawable.logo)
.setTicker(title)
.setContentTitle(title)
.setContentText("下载完成,点击继续插件化。")
.setContentIntent(pendingIntent)
.build();
notification.defaults = Notification.DEFAULT_SOUND;// 添加系统默认声音
notification.flags |= Notification.FLAG_AUTO_CANCEL; // FLAG_AUTO_CANCEL表明当通知被用户点击时通知将被清除。
nManager.notify(
((int) System.currentTimeMillis() / 1000),
notification);
NotificationManager notificationManager = (NotificationManager) getSystemService(
Context.NOTIFICATION_SERVICE);
notificationManager.notify(((int) System.currentTimeMillis() / 1000), notification);
}
} else {
String platform = PlatformUtils.getInstance(
getApplicationContext())
.getPlatformName(
downloadEntity.getPlatform());
String platform = PlatformUtils.getInstance(getApplicationContext())
.getPlatformName(downloadEntity.getPlatform());
if (platform != null) {
if (downloadEntity.isPluggable()) {
EventBus.getDefault().post(new EBShowDialog("plugin",
downloadEntity.getPath()));
// 弹出插件化提示框
EventBus.getDefault().post(new EBShowDialog("plugin", downloadEntity.getPath()));
} else if (platform.equals("官方版")) {
toast(downloadEntity.getName() + " - 下载完成");
} else {
@ -263,6 +210,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
toast(downloadEntity.getName() + " - 下载完成");
}
if (!downloadEntity.isPluggable()) {
// 是否是自动安装
if (sp.getBoolean("autoinstall", true)) {
if (FileUtils.isEmptyFile(downloadEntity.getPath())) {
toast("解析包出错(可能被误删了),请重新下载");
@ -277,7 +225,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
}
}
}
}
// 统计下载完成
@ -287,19 +234,62 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
}
};
private void processGhAssistDownload(DownloadEntity downloadEntity) {
app_tv_speed.setText(String.format("%s(剩%s)",
SpeedUtils.getSpeed(downloadEntity.getSpeed()),
SpeedUtils.getRemainTime(downloadEntity.getSize(),
downloadEntity.getProgress(), downloadEntity.getSpeed() * 1024)));
app_pb_progress.setProgress((int) (downloadEntity.getPercent() * 10));
app_tv_percent.setText(downloadEntity.getPercent() + "%");
if (DownloadStatus.done.equals(downloadEntity.getStatus())) {
DownloadManager.getInstance(getApplicationContext())
.cancel(downloadEntity.getUrl(), false);
dialog.dismiss();
isShowDownload = false;
// 统计下载
private void uploadData(String id, String platform) {
HashMap<String, String> params = new HashMap<>();
params.put("game", id);
params.put("platform", platform);
JSONObject jsonObject = new JSONObject(params);
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(Method.POST,
Config.HOST + "v2/stat/download", jsonObject.toString(), null, null);
AppController.addToRequestQueue(request, TAG);
}
// 统计下载完成事件
private void statDoneEvent(DownloadEntity downloadEntity) {
Map<String, Object> kv1 = new HashMap<>();
kv1.put("版本", downloadEntity.getPlatform());
kv1.put("状态", "下载完成");
if (downloadEntity.isUpdate()) {
DataUtils.onEvent(MainActivity.this, "游戏更新", downloadEntity.getName(), kv1);
} else {
DataUtils.onEvent(MainActivity.this, "游戏下载", downloadEntity.getName(), kv1);
}
Map<String, Object> kv2 = new HashMap<>();
kv2.put("版本", downloadEntity.getPlatform());
kv2.put("状态", "下载完成");
kv2.put("位置", downloadEntity.getEntrance());
DataUtils.onEvent(MainActivity.this, "游戏下载位置", downloadEntity.getName(), kv2);
if (downloadEntity.isPluggable()) {
Map<String, Object> kv3 = new HashMap<>();
kv3.put("下载", "下载完成");
kv3.put("版本", downloadEntity.getPlatform());
kv3.put("位置", downloadEntity.getEntrance());
DataUtils.onEvent(MainActivity.this, "插件化", downloadEntity.getName(), kv3);
}
Map<String, Object> map = new HashMap<>();
map.put("game", downloadEntity.getName());
map.put("game_id", downloadEntity.getGameId());
if (downloadEntity.isPluggable()) {
map.put("method", "插件化");
map.put("btn_status", "插件化");
} else if (downloadEntity.isUpdate()) {
map.put("method", "更新");
map.put("btn_status", "更新");
} else {
map.put("method", "正常");
map.put("btn_status", "下载");
}
map.put("platform", PlatformUtils.getInstance(getApplicationContext())
.getPlatformName(downloadEntity.getPlatform()));
map.put("status", "完成");
map.put("entrance", downloadEntity.getEntrance());
map.put("location", downloadEntity.getLocation());
map.put("network", NetworkUtils.getConnectedType(MainActivity.this));
DataCollectionManager.onEvent(MainActivity.this, "download", map);
}
private void processHijack(DownloadEntity downloadEntity) {
@ -359,8 +349,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
return super.onKeyDown(keyCode, event);
}
private Handler handler = new Handler();
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
@ -374,42 +362,37 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
// 初始化gameMap
DownloadManager.getInstance(this).initGameMap();
View contentView = View.inflate(this, R.layout.activity_main, null);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setTheme(R.style.AppTheme);
setTranslucentStatus(true);
}
setContentView(contentView);
initViews();
if (savedInstanceState != null) {
currentTab = savedInstanceState.getInt("currentTab");
} else {
currentTab = 0;
}
View contentView = View.inflate(this, R.layout.activity_main, null);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setTheme(R.style.AppTheme);
setTranslucentStatus(true);
}
setContentView(contentView);
initViews();
setTabSelection(currentTab);
getSearchHints();
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
concernManager = new ConcernManager(getApplicationContext());
isNewFirstLaunch = sp.getBoolean("isNewFirstLaunch", true);
getSearchHints();
isNewFirstLaunch = sp.getBoolean("isNewFirstLaunch", true);
if (!isNewFirstLaunch && sp.getBoolean("autoupdate", true)) {
// 检查助手更新
checkUpdate();
}
if (isNewFirstLaunch) {
getPluginUpdate();
sp.edit().putBoolean("isNewFirstLaunch", false).apply();
}
handler.postDelayed(runnable, 500);
// 获取免责声明
getDisclaimer(isNewFirstLaunch);
// 初始化PlatformUtils
@ -427,20 +410,37 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
// 检查是否有权限读取应用列表
checkPermission();
if (isNewFirstLaunch
|| TokenUtils.getDeviceId(this) == null) {
// 注册设备
if (isNewFirstLaunch || TokenUtils.getDeviceId(this) == null) {
new Thread(){
@Override
public void run() {
// 注册设备
TokenUtils.register(MainActivity.this);
}
}.start();
}
// 执行跳转事件
handler.postDelayed(runnable, 500);
Log.e("TD_CHANNEL_ID", (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID"));
}
private void initViews() {
home1Layout = (LinearLayout) findViewById(R.id.main_ll_game);
home2Layout = (LinearLayout) findViewById(R.id.main_ll_news);
home3Layout = (LinearLayout) findViewById(R.id.main_ll_personal);
home1Image = (ImageView) findViewById(R.id.main_iv_game);
home2Image = (ImageView) findViewById(R.id.main_iv_news);
home3Image = (ImageView) findViewById(R.id.main_iv_personal);
home1Title = (TextView) findViewById(R.id.main_tv_game);
home2Title = (TextView) findViewById(R.id.main_tv_news);
home3Title = (TextView) findViewById(R.id.main_tv_personal);
home1Layout.setOnClickListener(this);
home2Layout.setOnClickListener(this);
home3Layout.setOnClickListener(this);
}
private void checkPermission() {
ArrayList<String> list = PackageUtils.getAllPackageName(getApplicationContext());
if (list.isEmpty()) {
@ -523,8 +523,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
private void updateConcern() {
// 移除疑似游戏数据库中所有数据
SuspectedGameManager suspectedGameManager = new SuspectedGameManager(
getApplicationContext());
SuspectedGameManager suspectedGameManager = new SuspectedGameManager(getApplicationContext());
suspectedGameManager.deleteAll();
ArrayList<String> concernIdList = new ArrayList<>();
@ -545,8 +544,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
Gson gson = new Gson();
GameEntity gameEntity = gson.fromJson(response.toString(), GameEntity.class);
ConcernInfo concernInfo = concernManager.findConcernById(gameEntity.getId());
if (concernInfo != null
&& gameEntity.getApk() != null
if (concernInfo != null && gameEntity.getApk() != null
&& gameEntity.getApk().size() != 0) {
HashMap<String, Boolean> packageNames = new HashMap<>();
String packageName;
@ -626,8 +624,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
weight = 1;
}
concernEntity.setTag(tag);
long traffic = spy.getTraffic(new ArrayList<>(concernEntity
.getPackageNames().keySet()));
long traffic = spy.getTraffic(new ArrayList<>(concernEntity.getPackageNames().keySet()));
concernEntity.setTraffic(traffic);
if (traffic > 0) {
weight++;
@ -682,7 +679,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
private void checkGameUpdate() {
ArrayList<String> list = new ArrayList<>();
List<ConcernInfo> infos = concernManager.getInstalledGame();
for (ConcernInfo info : infos) {
for (String packageName : info.getPackageNames().keySet()) {
@ -698,7 +694,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
return lhs.compareTo(rhs);
}
};
Collections.sort(list, comparator);
StringBuilder builder = new StringBuilder();
@ -715,12 +710,9 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
packages = builder.substring(0, builder.length() - 1);
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
Config.HOST + "v1d45/support/package/update?package=" + packages,
// Config.HOST + "v1d45/support/package/latest?package=" + packages,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Utils.log("getUpdateList=" + response.toString());
if (response.length() != 0) {
Gson gson = new Gson();
Type listType = new TypeToken<ArrayList<GameUpdateEntity>>() {}.getType();
@ -729,15 +721,15 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
for (int i = 0; i < games.size(); i++) {
gameUpdateEntity = games.get(i);
// 判断是否gh_version是否相同
String gh_version = (String) PackageUtils
.getMetaData(MainActivity.this, gameUpdateEntity.getPackageName(), "gh_version");
String gh_version = (String) PackageUtils.getMetaData(
MainActivity.this, gameUpdateEntity.getPackageName(), "gh_version");
if (gh_version != null) {
gh_version = gh_version.substring(2);
// 判断gh_version是否相同
if (gh_version.equals(gameUpdateEntity.getGhVersion())) {
// 判断version是否相同
String version = PackageUtils
.getVersionByPackage(MainActivity.this, gameUpdateEntity.getPackageName());
String version = PackageUtils.getVersionByPackage(
MainActivity.this, gameUpdateEntity.getPackageName());
if (version != null && version.equals(gameUpdateEntity.getVersion())) {
// 版本相同,无需显示插件更新,继续查看是否有可更新的游戏包
games.remove(i);
@ -775,8 +767,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
count = 0;
for (ConcernInfo info : infos) {
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
TimestampUtils.addTimestamp(
Config.HOST + "v2d0/game/" + info.getId() + "/digest",
TimestampUtils.addTimestamp(Config.HOST + "v2d0/game/" + info.getId() + "/digest",
Constants.GAME_CD),
new Response.Listener<JSONObject>() {
@Override
@ -840,8 +831,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
}
}
GameManager manager = new GameManager(this);
manager.addOrUpdate(gameEntity.getApk(), gameEntity.getId(),
gameEntity.getName());
manager.addOrUpdate(gameEntity.getApk(), gameEntity.getId(), gameEntity.getName());
}
}
break;
@ -916,7 +906,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Utils.log(response.toString());
if (!isDestroy) {
try {
boolean isShow = response.getBoolean("isShow");
@ -933,14 +922,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
}
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Utils.log(error.toString());
sp.edit().putBoolean("isShowDisclaimer", false).apply();
}
});
}, null);
AppController.addToRequestQueue(request, TAG);
}
@ -959,95 +941,54 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
if (getIntent() != null && getIntent().getExtras() != null) {
String to = getIntent().getExtras().getString("to");
if(!TextUtils.isEmpty(to)){
Intent toIntent = new Intent(getApplicationContext(), intentClass(to));
if ("NewsDetailActivity".equals(to)) {
toIntent.putExtra("newsId", getIntent().getExtras().getString("newsId"));
toIntent.putExtra("entrance", getIntent().getExtras().getString("entrance"));
} else if("DownloadManagerActivity".equals(to)) {
toIntent.putExtra("packageName" , getIntent().getExtras().getString("packageName"));
toIntent.putExtra("currentItem" , 1);
} else if ("GameDetailActivity".equals(to)) {
toIntent.putExtra("gameId", getIntent().getExtras().getString("gameId"));
toIntent.putExtra("entrance", getIntent().getExtras().getString("entrance"));
} else if ("SubjectActivity".equals(to)) {
toIntent.putExtra("id", getIntent().getExtras().getString("id"));
toIntent.putExtra("name", getIntent().getExtras().getString("name"));
toIntent.putExtra("order", getIntent().getExtras().getBoolean("order"));
} else if ("ViewImageActivity".equals(to)) {
toIntent.putExtra("urls" , getIntent().getExtras().getStringArrayList("urls"));
toIntent.putExtra("current" , getIntent().getExtras().getInt("current",0));
toIntent.putExtra("ScaleType" , getIntent().getExtras().getString("ScaleType"));
Class<?> clazz = intentClass(to);
if (clazz != null) {
Intent toIntent = new Intent(MainActivity.this, clazz);
if ("NewsDetailActivity".equals(to)) {
toIntent.putExtra("newsId", getIntent().getExtras().getString("newsId"));
toIntent.putExtra("entrance", getIntent().getExtras().getString("entrance"));
} else if("DownloadManagerActivity".equals(to)) {
toIntent.putExtra("packageName" , getIntent().getExtras().getString("packageName"));
toIntent.putExtra("currentItem" , 1);
} else if ("GameDetailActivity".equals(to)) {
toIntent.putExtra("gameId", getIntent().getExtras().getString("gameId"));
toIntent.putExtra("entrance", getIntent().getExtras().getString("entrance"));
} else if ("SubjectActivity".equals(to)) {
toIntent.putExtra("id", getIntent().getExtras().getString("id"));
toIntent.putExtra("name", getIntent().getExtras().getString("name"));
toIntent.putExtra("order", getIntent().getExtras().getBoolean("order"));
} else if ("ViewImageActivity".equals(to)) {
toIntent.putExtra("urls" , getIntent().getExtras().getStringArrayList("urls"));
toIntent.putExtra("current" , getIntent().getExtras().getInt("current",0));
toIntent.putExtra("ScaleType" , getIntent().getExtras().getString("ScaleType"));
}
startActivity(toIntent);
}
startActivity(toIntent);
} else {
String from = getIntent().getStringExtra("from");
if (!TextUtils.isEmpty(from)) {
if (from.equals("plugin")) {
String packageName = getIntent().getStringExtra(
"packageName");
Intent intent = new Intent(MainActivity.this,
DownloadManagerActivity.class);
String packageName = getIntent().getStringExtra("packageName");
Intent intent = new Intent(MainActivity.this, DownloadManagerActivity.class);
intent.putExtra("currentItem", 1);
intent.putExtra("packageName", packageName);
startActivity(intent);
} else if (from.equals("mipush_news")) {
Intent intent = new Intent(MainActivity.this,
NewsDetailActivity.class);
Intent intent = new Intent(MainActivity.this, NewsDetailActivity.class);
intent.putExtra("entrance", "小米推送");
intent.putExtra("entity",
getIntent().getSerializableExtra("entity"));
intent.putExtra("entity", getIntent().getSerializableExtra("entity"));
startActivity(intent);
} else if (from.equals("mipush_new_game")) {
Intent intent = new Intent(MainActivity.this,
GameDetailActivity.class);
Intent intent = new Intent(MainActivity.this, GameDetailActivity.class);
intent.putExtra("entrance", "小米推送");
startActivity(intent);
} else if (from.equals("mipush_plugin")) {
try {
JSONObject jsonObject = new JSONObject(getIntent()
.getStringExtra("data"));
JSONArray jsonArray = jsonObject.getJSONArray("apk");
ArrayList<String> list = new ArrayList<>();
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject apk = jsonArray.getJSONObject(i);
String packageName = apk.getString("package");
if (PackageManager.isInstalled(packageName)) {
// 判断是否gh_version是否相同
String gh_version = (String) PackageUtils
.getMetaData(getApplicationContext(),
packageName, "gh_version");
if (gh_version != null) {
gh_version = gh_version.substring(2);
// 判断gh_version是否相同
if (gh_version.equals(apk
.getString("gh_version"))) {
// 判断version是否相同
String version = PackageUtils
.getVersionByPackage(
getApplicationContext(),
packageName);
if (version != null && version.equals(apk
.getString("version"))) {
// 版本相同,无需显示插件更新,继续查看是否有可更新的游戏包
continue;
}
}
}
list.add(packageName);
}
}
Intent intent = new Intent(MainActivity.this,
DownloadManagerActivity.class);
intent.putExtra("currentItem", 1);
intent.putExtra("isPushIntent", true);
startActivity(intent);
} catch (JSONException e) {
e.printStackTrace();
}
Intent intent = new Intent(MainActivity.this, DownloadManagerActivity.class);
intent.putExtra("currentItem", 1);
intent.putExtra("isPushIntent", true);
startActivity(intent);
} else if (from.equals("plugin_install")) {
Intent intent = new Intent(MainActivity.this,
DownloadManagerActivity.class);
Intent intent = new Intent(MainActivity.this, DownloadManagerActivity.class);
intent.putExtra("currentItem", 0);
intent.putExtra("path", getIntent().getStringExtra("path"));
startActivity(intent);
@ -1060,105 +1001,79 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
private void getSearchHints() {
final String url = Config.HOST + "v1d45/search/game/default";
JsonArrayExtendedRequest searchRequst = new JsonArrayExtendedRequest(url,
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(url,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
if (!isDestroy) {
if (!isDestroy && response.length() != 0) {
Type listType = new TypeToken<ArrayList<String>>() {}.getType();
Gson gson = new Gson();
List<String> searchHintList = gson.fromJson(
response.toString(), listType);
if (searchHintList != null && !searchHintList.isEmpty()) {
List<String> searchHintList = gson.fromJson(response.toString(), listType);
if (searchHintList != null && searchHintList.size() != 0) {
if (searchHintList.size() == 1) {
searchHint = searchHintList.get(0);
} else {
searchHint = searchHintList.get(RandomUtils.nextInt(searchHintList.size()));
}
EventBus.getDefault().post(
new EBTopStatus("搜索", searchHintList
.get(0)));
EventBus.getDefault().post(new EBTopStatus("搜索", searchHintList.get(0)));
}
}
}
}, null);
AppController.addToRequestQueue(searchRequst, TAG);
AppController.addToRequestQueue(request, TAG);
}
private void checkUpdate() {
String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(this,
getPackageName(), "TD_CHANNEL_ID");
String url = Config.HOST + "v2/version?version_name="
+ PackageUtils.getVersion(getApplicationContext())
String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID");
String url = Config.HOST + "v2/version?version_name=" + PackageUtils.getVersion(getApplicationContext())
+ "&channel=" + TD_CHANNEL_ID;
JsonObjectExtendedRequest updateRequest = new JsonObjectExtendedRequest(url,
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(url,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Utils.log("update=" + response.toString());
if (!isDestroy) {
if (response.length() != 0) {
Gson gson = new Gson();
appEntity = gson.fromJson(response.toString(),
AppEntity.class);
if (!isDestroy && response.length() != 0) {
Gson gson = new Gson();
appEntity = gson.fromJson(response.toString(), AppEntity.class);
float version = Float.valueOf(appEntity
.getVersion());
float currentVersion = Float.valueOf(PackageUtils
.getVersion(getApplicationContext()));
float version = Float.valueOf(appEntity.getVersion());
float currentVersion = Float.valueOf(PackageUtils.getVersion(getApplicationContext()));
if (version > currentVersion) {
// 光环助手 有更新
GameUpdateEntity game = new GameUpdateEntity();
game.setName("光环助手V" + appEntity.getVersion());
game.setPackageName(getPackageName());
game.setSize(appEntity.getSize());
game.setVersion(appEntity.getVersion());
game.setUrl(appEntity.getUrl());
game.setPlatform("官方版");
PackageManager.addUpdate(0, game);
if (version > currentVersion) {
// 光环助手 有更新
GameUpdateEntity game = new GameUpdateEntity();
game.setName("光环助手V"
+ appEntity.getVersion());
game.setPackageName(getPackageName());
game.setSize(appEntity.getSize());
game.setVersion(appEntity.getVersion());
game.setUrl(appEntity.getUrl());
game.setPlatform("官方版");
PackageManager.addUpdate(0, game);
String updateMD5 = MD5Utils.getUpdateMD5(
appEntity.getUrl(),
appEntity.getContent());
if (appEntity.isIs_force()) {
// 强制更新
String updateMD5 = MD5Utils.getUpdateMD5(appEntity.getUrl(), appEntity.getContent());
if (appEntity.isIs_force()) {
// 强制更新
showUpdateDialog(updateMD5);
} else {
// 非强制更新
if ("EVERY_TIME_OPEN".equals(appEntity.getAlet_type())) {
// 每次都提示
showUpdateDialog(updateMD5);
} else {
// 非强制更新
if ("EVERY_TIME_OPEN".equals(appEntity
.getAlet_type())) {
// 每次都提示
// 一天提示一次
String showUpdateTime = sp.getString("show_update_tiem", null);
SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd", Locale.getDefault());
String today = format.format(new Date());
if (!today.equals(showUpdateTime)) {
sp.edit().putString("show_update_tiem", today).apply();
showUpdateDialog(updateMD5);
} else {
// 一天提示一次
String showUpdateTime = sp
.getString(
"show_update_tiem",
null);
SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd", Locale
.getDefault());
String today = format
.format(new Date());
if (!today.equals(showUpdateTime)) {
sp.edit()
.putString(
"show_update_tiem",
today).apply();
showUpdateDialog(updateMD5);
}
}
}
}
}
}
}
}, null);
AppController.addToRequestQueue(updateRequest, TAG);
AppController.addToRequestQueue(request, TAG);
}
private void showUpdateDialog(final String md5) {
@ -1174,11 +1089,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
TextView size = (TextView) view.findViewById(R.id.update_app_size);
size.setText(String.format("大小:%s", appEntity.getSize()));
if (appEntity.isIs_force()) {
updateDialog.setCanceledOnTouchOutside(false);
updateDialog.setCancelable(false);
}
view.findViewById(R.id.update_cannel).setOnClickListener(
new OnClickListener() {
@Override
@ -1190,13 +1100,13 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
}
}
});
view.findViewById(R.id.updeta_confirm).setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
updateDialog.dismiss();
String path = FileUtils.getDownloadPath(
MainActivity.this,
String path = FileUtils.getDownloadPath(MainActivity.this,
"光环助手V" + appEntity.getVersion() + "_" + md5 + ".apk");
File file = new File(path);
if (file.exists() && file.length() > 0) {
@ -1207,28 +1117,36 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
}
}
});
if (appEntity.isIs_force()) {
updateDialog.setCanceledOnTouchOutside(false);
updateDialog.setCancelable(false);
}
updateDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
updateDialog.setContentView(view);
updateDialog.show();
}
private Dialog dialog;
private ProgressBar app_pb_progress;
private TextView app_tv_speed;
private TextView app_tv_percent;
private TextView app_tv_cancel;
private void showDownloadDialog(String md5) {
dialog = new Dialog(this);
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
dialog.closeOptionsMenu();
View view = View.inflate(this, R.layout.app_updating_dialog, null);
app_pb_progress = (ProgressBar) view.findViewById(R.id.app_pb_progress);
app_tv_speed = (TextView) view.findViewById(R.id.app_tv_speed);
app_tv_percent = (TextView) view.findViewById(R.id.app_tv_percent);
app_btn_cancel = (TextView) view.findViewById(R.id.app_btn_cancel);
app_btn_cancel.setOnClickListener(new OnClickListener() {
app_tv_cancel = (TextView) view.findViewById(R.id.app_tv_cancel);
app_tv_cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
DownloadManager.getInstance(getApplicationContext()).cancel(
appEntity.getUrl());
DownloadManager.getInstance(getApplicationContext()).cancel(appEntity.getUrl());
if (appEntity.isIs_force()) {
finish();
} else {
@ -1238,14 +1156,17 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
}
});
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
dialog.closeOptionsMenu();
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(view);
dialog.show();
isShowDownload = true;
String path = FileUtils.getDownloadPath(MainActivity.this, "光环助手V"
+ appEntity.getVersion() + "_" + md5 + ".apk");
String path = FileUtils.getDownloadPath(MainActivity.this,
"光环助手V" + appEntity.getVersion() + "_" + md5 + ".apk");
File file = new File(path);
if (file.exists()) {
file.delete();
@ -1257,15 +1178,24 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
downloadEntity.setPath(path);
downloadEntity.setPlatform("官方版");
downloadEntity.setPackageName(getPackageName());
DownloadManager.getInstance(getApplicationContext()).cancel(
downloadEntity.getUrl(), false);
DownloadManager.getInstance(getApplicationContext()).cancel(downloadEntity.getUrl(), false);
DownloadManager.getInstance(getApplicationContext()).pauseAll();
DownloadManager.getInstance(getApplicationContext()).add(downloadEntity);
}
private void processGhAssistDownload(DownloadEntity downloadEntity) {
app_tv_speed.setText(String.format("%s(剩%s)", SpeedUtils.getSpeed(downloadEntity.getSpeed()),
SpeedUtils.getRemainTime(downloadEntity.getSize(),
downloadEntity.getProgress(), downloadEntity.getSpeed() * 1024)));
app_pb_progress.setProgress((int) (downloadEntity.getPercent() * 10));
app_tv_percent.setText(downloadEntity.getPercent() + "%");
if (DownloadStatus.done.equals(downloadEntity.getStatus())) {
DownloadManager.getInstance(getApplicationContext()).cancel(downloadEntity.getUrl(), false);
dialog.dismiss();
isShowDownload = false;
}
}
// 获取META-INF中的plugin_update 文件判断是否从游戏插件中下载的app是则获取游戏id启动游戏更新下载该游戏
private void getPluginUpdate() {
ApplicationInfo appinfo = getApplicationInfo();
@ -1278,10 +1208,8 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
ZipEntry entry = ((ZipEntry) entries.nextElement());
String entryName = entry.getName();
if (entryName.contains("gh_assist")) {
String packageName = entryName.substring(entryName
.lastIndexOf("_") + 1);
Intent intent = new Intent(MainActivity.this,
DownloadManagerActivity.class);
String packageName = entryName.substring(entryName.lastIndexOf("_") + 1);
Intent intent = new Intent(MainActivity.this, DownloadManagerActivity.class);
intent.putExtra("currentItem", 1);
intent.putExtra("packageName", packageName);
startActivity(intent);
@ -1301,38 +1229,18 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
}
}
private void initViews() {
home1Layout = (LinearLayout) findViewById(R.id.main_ll_game);
home2Layout = (LinearLayout) findViewById(R.id.main_ll_news);
home3Layout = (LinearLayout) findViewById(R.id.main_ll_personal);
home1Image = (ImageView) findViewById(R.id.main_iv_game);
home2Image = (ImageView) findViewById(R.id.main_iv_news);
home3Image = (ImageView) findViewById(R.id.main_iv_personal);
home1Title = (TextView) findViewById(R.id.main_tv_game);
home2Title = (TextView) findViewById(R.id.main_tv_news);
home3Title = (TextView) findViewById(R.id.main_tv_personal);
home1Layout.setOnClickListener(this);
home2Layout.setOnClickListener(this);
home3Layout.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.main_ll_game:
EventBus.getDefault().post(new EBUISwitch("MainActivity", 0));
setTabSelection(0);
break;
case R.id.main_ll_news:
EventBus.getDefault().post(new EBUISwitch("MainActivity", 1));
setTabSelection(1);
break;
case R.id.main_ll_personal:
EventBus.getDefault().post(new EBUISwitch("MainActivity", 2));
setTabSelection(2);
break;
default:
break;
final int id = v.getId();
if (id == R.id.main_ll_game) {
EventBus.getDefault().post(new EBUISwitch("MainActivity", 0));
setTabSelection(0);
} else if (id == R.id.main_ll_news) {
EventBus.getDefault().post(new EBUISwitch("MainActivity", 1));
setTabSelection(1);
} else if (id == R.id.main_ll_personal) {
EventBus.getDefault().post(new EBUISwitch("MainActivity", 2));
setTabSelection(2);
}
}
@ -1450,17 +1358,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
}
}
private void uploadData(String id, String platform) {
HashMap<String, String> params = new HashMap<>();
params.put("game", id);
params.put("platform", platform);
JSONObject jsonObject = new JSONObject(params);
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
Method.POST, Config.HOST + "v2/stat/download", jsonObject.toString(),
null, null);
AppController.addToRequestQueue(request, TAG);
}
public void onEventMainThread(EBSkip skip) {
if ("GameFragment".equals(skip.getType())) {
home1Layout.performClick();
@ -1470,10 +1367,11 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
public void onEventMainThread(EBPackage busFour) {
String packageName = busFour.getPackageName();
// 添加进已安装map中
if ("安装".equals(busFour.getType())) {
// 添加进已安装map中
PackageManager.addInstalled(packageName);
} else if ("卸载".equals(busFour.getType())) {
// 删除map中数据
PackageManager.removeInstalled(packageName);
}
DownloadEntity mDownloadEntity = null;
@ -1620,7 +1518,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
app_pb_progress = null;
app_tv_speed = null;
app_tv_percent = null;
app_btn_cancel = null;
app_tv_cancel = null;
appEntity = null;
handler = null;
dataWatcher = null;

View File

@ -495,7 +495,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
app_pb_progress = (ProgressBar) view.findViewById(R.id.app_pb_progress);
app_tv_speed = (TextView) view.findViewById(R.id.app_tv_speed);
app_tv_percent = (TextView) view.findViewById(R.id.app_tv_percent);
app_btn_cancel = (TextView) view.findViewById(R.id.app_btn_cancel);
app_btn_cancel = (TextView) view.findViewById(R.id.app_tv_cancel);
app_btn_cancel.setOnClickListener(new OnClickListener() {
@Override

View File

@ -64,7 +64,7 @@
</LinearLayout>
<TextView
android:id="@+id/app_btn_cancel"
android:id="@+id/app_tv_cancel"
android:layout_width="48dp"
android:layout_height="27dp"
android:layout_marginBottom="15dp"