如题,根据是否有新版本和是否必须更新来对Dialog进行操作
Activity activity = SlidingSecondaryActivity.this;
if (activity.getParent() != null) {
activity = activity.getParent();
}
final Dialog dialog = new Dialog(activity);
String str = (String) msg.obj;
final Version_Result result = new Gson().fromJson(str, Version_Result.class);
if (result.getOS().equals("Android")) {
if (result.isHasNewVersion()) {
if (result.isMustUpdate()) {
dialog.setContentView(R.layout.version_dialog);
Button version_ok = (Button) dialog.findViewById(R.id.version_ok);
Button version_cancel = (Button) dialog.findViewById(R.id.version_cancel);
TextView tv = (TextView) dialog.findViewById(R.id.version_text);
tv.setText(result.getNote());
version_ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 升级应用
Uri uri = Uri.parse(result.getUrl());
Intent viewIntent = new Intent(Intent.ACTION_VIEW, uri);
SlidingSecondaryActivity.this.startActivity(viewIntent);
}
});
version_cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.exit(0);
}
});
dialog.show();
} else {
dialog.setContentView(R.layout.version_dialog);
Button version_ok = (Button) dialog.findViewById(R.id.version_ok);
Button version_cancel = (Button) dialog.findViewById(R.id.version_cancel);
TextView tv = (TextView) dialog.findViewById(R.id.version_text);
tv.setText(result.getNote());
version_cancel.setText("取消");
version_ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 升级应用
Uri uri = Uri.parse(result.getUrl());
Intent viewIntent = new Intent(Intent.ACTION_VIEW, uri);
SlidingSecondaryActivity.this.startActivity(viewIntent);
}
});
version_cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
} else {
Log.e("!23123", "321312");
dialog.setContentView(R.layout.version_dialog);
Button version_ok = (Button) dialog.findViewById(R.id.version_ok);
Button version_cancel = (Button) dialog.findViewById(R.id.version_cancel);
TextView tv = (TextView) dialog.findViewById(R.id.version_text);
tv.setText("已经是最新的版本");
version_ok.setText("确认");
version_cancel.setText("取消");
version_ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
version_cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
} else {
dialog.setContentView(R.layout.version_dialog);
Button version_ok = (Button) dialog.findViewById(R.id.version_ok);
Button version_cancel = (Button) dialog.findViewById(R.id.version_cancel);
TextView tv = (TextView) dialog.findViewById(R.id.version_text);
tv.setText("已经是最新的版本");
version_ok.setText("确认");
version_cancel.setText("取消");
version_ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
version_cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
只贴代码不写注释不是好的程序员~~
我承认我不是 哈哈哈哈哈