修改多版本下载时,使用移动网络的提示方式

This commit is contained in:
huangzhuanghua
2016-09-08 11:05:56 +08:00
parent a22f59aab6
commit cbc543b981
12 changed files with 394 additions and 426 deletions

View File

@ -75,19 +75,16 @@ public class SplashScreenActivity extends BaseActivity {
private ConcernManager concernManager;
private SharedPreferences sp;
private boolean isFirst;
private String from;
private long start = 0L;
private boolean isFirst;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
start = System.currentTimeMillis();
isFirst = true;
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
@ -111,14 +108,12 @@ public class SplashScreenActivity extends BaseActivity {
}
}
setContentView(R.layout.activity_splash);
if (sp.getBoolean("isNewsFirstLaunch", true)) {
findViewById(R.id.splash_ll_normal).setVisibility(View.GONE);
setContentView(R.layout.activity_splash_intro);
ViewPager splash_viewPager = (ViewPager) findViewById(R.id.splash_viewPager);
splash_viewPager.setVisibility(View.VISIBLE);
splash_viewPager.setAdapter(new ViewPagerAdapter());
} else {
setContentView(R.layout.activity_splash_normal);
}
}
@ -134,22 +129,19 @@ public class SplashScreenActivity extends BaseActivity {
@Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView iv = new ImageView(SplashScreenActivity.this);
// iv.setBackgroundResource(pics[position]);
ImageUtils.getInstance(SplashScreenActivity.this).display("drawable://" + pics[position], iv, -1);
ImageView imageView = new ImageView(SplashScreenActivity.this);
ImageUtils.getInstance(SplashScreenActivity.this).
display("drawable://" + pics[position], imageView, -1);
if (position == pics.length - 1) {
iv.setOnClickListener(new View.OnClickListener() {
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(SplashScreenActivity.this,
MainActivity.class);
startActivity(intent);
finish();
launch();
}
});
}
container.addView(iv);
return iv;
container.addView(imageView);
return imageView;
}
@Override
@ -160,7 +152,6 @@ public class SplashScreenActivity extends BaseActivity {
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
object = null;
}
}
@ -169,10 +160,7 @@ public class SplashScreenActivity extends BaseActivity {
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
if (sp.getBoolean("isNewsFirstLaunch", true)) {
Intent intent = new Intent(SplashScreenActivity.this,
MainActivity.class);
startActivity(intent);
finish();
launch();
} else {
return true;
}
@ -186,48 +174,39 @@ public class SplashScreenActivity extends BaseActivity {
if (hasFocus && isFirst) {
isFirst = false;
try {
// 第一次启动把package.txt文件内容加载进数据库
if (!sp.getBoolean("isLoadFilter", false)) {
try {
List<FilterInfo> list = new ArrayList<>();
BufferedReader reader = new BufferedReader(
new InputStreamReader(getAssets().open(
"package.txt")));
String line;
while ((line = reader.readLine()) != null) {
list.add(new FilterInfo(line));
}
reader.close();
FilterManager filterManager = new FilterManager(
getApplicationContext());
filterManager.addAllFilter(list);
sp.edit().putBoolean("isLoadFilter", true).apply();
} catch (IOException e1) {
e1.printStackTrace();
// 第一次启动把package.txt文件内容加载进数据库
if (!sp.getBoolean("isLoadFilter", false)) {
try {
List<FilterInfo> list = new ArrayList<>();
BufferedReader reader = new BufferedReader(
new InputStreamReader(getAssets().open("package.txt")));
String line;
while ((line = reader.readLine()) != null) {
list.add(new FilterInfo(line));
}
reader.close();
FilterManager filterManager = new FilterManager(getApplicationContext());
filterManager.addAllFilter(list);
sp.edit().putBoolean("isLoadFilter", true).apply();
} catch (IOException e1) {
e1.printStackTrace();
}
}
checkUpdateFile();
checkGhFile();
concernManager = new ConcernManager(getApplicationContext());
concernManager = new ConcernManager(getApplicationContext());
/*
* 更新过滤表获取自动刷新的cd获取版本对应表
*/
String time = sp.getString("filter_time", null);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd",
Locale.getDefault());
String today = format.format(new Date());
if (!today.equals(time)) {
FilterManager manager = new FilterManager(
getApplicationContext());
manager.getFilterFromServer(today);
getPlatform();
}
} catch (Exception e) {
e.printStackTrace();
toast("抛出异常");
/*
* 更新过滤表获取自动刷新的cd获取版本对应表
*/
String time = sp.getString("filter_time", null);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
String today = format.format(new Date());
if (!today.equals(time)) {
FilterManager manager = new FilterManager(getApplicationContext());
manager.getFilterFromServer(today);
getPlatform();
}
// 获取下载按钮状态、开启or关闭
@ -257,33 +236,24 @@ public class SplashScreenActivity extends BaseActivity {
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
Config.HOST + "v1d45/support/setting/ui",
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Utils.log(response.toString());
// "platform_order":{"normal":["9u","baidu","360"]}}
try {
Editor editor = sp.edit();
editor.putInt("download_box_row", response
.getJSONObject("download_box")
.getInt("row"));
editor.putInt("download_box_row",
response.getJSONObject("download_box").getInt("row"));
editor.putInt("download_box_column",
response.getJSONObject("download_box")
.getInt("column"));
editor.putInt(
"game_detail_news_type_tab_column",
response.getJSONObject(
"game_detail_news_type_tab")
.getInt("column"));
response.getJSONObject("download_box").getInt("column"));
editor.putInt("game_detail_news_type_tab_column",
response.getJSONObject("game_detail_news_type_tab").getInt("column"));
editor.apply();
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
@ -331,12 +301,12 @@ public class SplashScreenActivity extends BaseActivity {
/*
* 检查下载文件夹下是否有旧版本的光环助手的包,有则删除
*/
private void checkUpdateFile() {
File file = new File(FileUtils.getDownloadDir(this) + File.separator);
if (file.isDirectory()) {
for (File f : file.listFiles()) {
if (!f.isDirectory() && f.getName().startsWith("光环助手V")) {
String name = f.getName();
private void checkGhFile() {
File folder = new File(FileUtils.getDownloadDir(this) + File.separator);
if (folder.isDirectory()) {
for (File file : folder.listFiles()) {
if (!file.isDirectory() && file.getName().startsWith("光环助手V")) {
String name = file.getName();
int index = name.indexOf("_");
if (index != -1) {
float version = Float.valueOf(name.substring(
@ -344,7 +314,7 @@ public class SplashScreenActivity extends BaseActivity {
float currentVersion = Float.valueOf(PackageUtils
.getVersion(getApplicationContext()));
if (version <= currentVersion) {
f.delete();
file.delete();
}
}
}
@ -440,14 +410,13 @@ public class SplashScreenActivity extends BaseActivity {
List<String> useParams) {
List<String> list = new ArrayList<>();
Gson gson = new Gson();
ConcernManager manager = new ConcernManager(getApplicationContext());
for (int i = 0, size = data.size(); i < size; i++) {
GameDigestEntity gameDigestEntity = gson.fromJson(data.get(i)
.toString(), GameDigestEntity.class);
GameInfo gameEntity = new GameInfo();
gameEntity.setId(gameDigestEntity.getId());
gameEntity.setPackageName(useParams.get(i));
manager.updateByEntity(gameEntity, false);
concernManager.updateByEntity(gameEntity, false);
list.add(useParams.get(i));
}
@ -687,8 +656,8 @@ public class SplashScreenActivity extends BaseActivity {
concernManager.updateByConcern(concernEntity);
}
}
// 不是第一次启动
if (!sp.getBoolean("isNewsFirstLaunch", true)) {
int height = sp.getInt("actionbar_height", 0);
if (height == 0) {
final ActionBar actionBar = getActionBar();
@ -697,53 +666,54 @@ public class SplashScreenActivity extends BaseActivity {
}
}
Intent intent = new Intent(SplashScreenActivity.this,
MainActivity.class);
Bundle bundle = getIntent().getExtras();
if(bundle != null &&bundle.getString("to") != null){
intentControl(bundle,intent);
}else {
intent.putExtra("from", from);
if ("plugin".equals(from)) {
intent.putExtra("packageName",
getIntent().getStringExtra("packageName"));
} else if ("mipush_news".equals(from)) {
intent.putExtra("entity",
getIntent().getSerializableExtra("entity"));
} else if ("mipush_plugin".equals(from)) {
intent.putExtra("data", getIntent().getStringExtra("data"));
} else if ("plugin_install".equals(from)) {
intent.putExtra("path", getIntent().getStringExtra("path"));
}
}
Utils.log("time = " + (System.currentTimeMillis() - start));
startActivity(intent);
finish();
launch();
}
}
// 跳转到主界面
private void launch() {
Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
Bundle bundle = getIntent().getExtras();
if (bundle != null && bundle.getString("to") != null) {
intentControl(bundle, intent);
} else {
intent.putExtra("from", from);
if ("plugin".equals(from)) {
intent.putExtra("packageName", getIntent().getStringExtra("packageName"));
} else if ("mipush_news".equals(from)) {
intent.putExtra("entity", getIntent().getSerializableExtra("entity"));
} else if ("mipush_plugin".equals(from)) {
intent.putExtra("data", getIntent().getStringExtra("data"));
} else if ("plugin_install".equals(from)) {
intent.putExtra("path", getIntent().getStringExtra("path"));
}
}
startActivity(intent);
finish();
}
private void intentControl(Bundle bundle, Intent intent) {
String to = bundle.getString("to");
if ("NewsActivity".equals(to)) {
intent.putExtra("newsId" , bundle.getString("newsId"));
intent.putExtra("entrance" , bundle.getString("entrance"));
intent.putExtra("newsId", bundle.getString("newsId"));
intent.putExtra("entrance", bundle.getString("entrance"));
} else if("DownloadManagerActivity".equals(to)) {
intent.putExtra("packageName" , bundle.getString("packageName"));
intent.putExtra("packageName", bundle.getString("packageName"));
} else if ("GameDetailsActivity".equals(to)) {
intent.putExtra("gameId" , bundle.getString("gameId"));
intent.putExtra("entrance" , bundle.getString("entrance"));
intent.putExtra("gameId", bundle.getString("gameId"));
intent.putExtra("entrance", bundle.getString("entrance"));
} else if ("SubjectActivity".equals(to)) {
intent.putExtra("id" , bundle.getString("id"));
intent.putExtra("name" , bundle.getString("name"));
intent.putExtra("order" , bundle.getBoolean("order"));
intent.putExtra("id", bundle.getString("id"));
intent.putExtra("name", bundle.getString("name"));
intent.putExtra("order", bundle.getBoolean("order"));
} else if ("ViewImageActivity".equals(to)) {
intent.putExtra("urls" , bundle.getStringArrayList("urls"));
intent.putExtra("current" , bundle.getInt("current",0));
intent.putExtra("ScaleType" , bundle.getString("ScaleType"));
intent.putExtra("urls", bundle.getStringArrayList("urls"));
intent.putExtra("current", bundle.getInt("current",0));
intent.putExtra("ScaleType", bundle.getString("ScaleType"));
}
intent.putExtra("to" , to);
intent.putExtra("to", to);
}
}