xListView+下载安装apk+跳转设置WIFI界面
来源:互联网 发布:帝国时代3兵种数据 编辑:程序博客网 时间:2024/05/23 23:27
public class MainActivity extends AppCompatActivity implements XListView.IXListViewListener { private XListView xLV; private int index = 1; private boolean flag; private MyBaseAdapter adapter; private ProgressDialog progressDialog; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //显示当前页面布局 setContentView(R.layout.activity_main); //获取资源ID xLV = (XListView) findViewById(R.id.main_xListView); xLV.setPullLoadEnable(true); xLV.setXListViewListener(this); getData(); } @Override public void onRefresh() { ++index; getData(); flag = true; xLV.stopRefresh(true); } @Override public void onLoadMore() { ++index; getData(); flag = false; xLV.stopLoadMore(); } private void getData() { RequestParams params = new RequestParams("http://v.juhe.cn/toutiao/index?key=da161b40c11f8792fa176785dca00c0f"); x.http().post(params, new Callback.CommonCallback<String>() { @Override public void onSuccess(String result) { Gson gson = new Gson(); MenuInFo menuInFo = gson.fromJson(result, MenuInFo.class); List<MenuInFo.ResultBean.DataBean> results = menuInFo.getResult().getData(); //适配数据 if (adapter == null) { adapter = new MyBaseAdapter(results); xLV.setAdapter(adapter); } else { adapter.loadMore(results, flag); adapter.notifyDataSetChanged(); } } @Override public void onError(Throwable ex, boolean isOnCallback) { } @Override public void onCancelled(CancelledException cex) { } @Override public void onFinished() { } }); } private void getImage(String path, ImageView imageView) { //自定义配置 DisplayImageOptions options = new DisplayImageOptions.Builder() .cacheInMemory(true)//让图片进行内存缓存 .cacheOnDisk(true)//让图片进行sdcard缓存// .showImageForEmptyUri(R.mipmap.ic_empty)//图片地址有误// .showImageOnFail(R.mipmap.ic_error)//当图片加载出现错误的时候显示的图片// .showImageOnLoading(R.mipmap.loading)//图片正在加载的时候显示的图片 .build(); //ImageLoader.getInstance().loadImage(path,options,new Ima);//加载图片 //参数1:加载的图片地址 //参数2:将图片设置到那个图片控件上面 //参数3:加载图片配置选项,意思是指明对这张图片的是否进行缓存(内存、sdcard) ImageLoader.getInstance().displayImage(path, imageView, options); } class MyBaseAdapter extends BaseAdapter { ImageOptions imageOptions = new ImageOptions.Builder() .setLoadingDrawableId(R.mipmap.ic_launcher) .setUseMemCache(true) .setSize(200, 200) .build(); private List<MenuInFo.ResultBean.DataBean> results; public MyBaseAdapter(List<MenuInFo.ResultBean.DataBean> results) { this.results = results; } public void loadMore(List<MenuInFo.ResultBean.DataBean> data, boolean flag) { for (MenuInFo.ResultBean.DataBean bean : data) { if (flag) { results.add(0, bean); } else { results.add(bean); } } } @Override public int getCount() { return results != null ? results.size() : 0; } @Override public Object getItem(int position) { return results.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { convertView = convertView.inflate(MainActivity.this, R.layout.item1_type1, null); holder = new ViewHolder(); holder.finally1_title = (TextView) convertView.findViewById(R.id.finally1_title); holder.finally1_author_name = (TextView) convertView.findViewById(R.id.finally1_author_name); holder.finally1_category = (TextView) convertView.findViewById(R.id.finally1_category); holder.finally1_data = (TextView) convertView.findViewById(R.id.finally1_data); holder.finally1_image = (ImageView) convertView.findViewById(R.id.finally1_image); holder.finally1_pop = (ImageView) convertView.findViewById(R.id.finally1_pop); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.finally1_title.setText(results.get(position).getTitle()); holder.finally1_author_name.setText(results.get(position).getAuthor_name()); holder.finally1_data.setText(results.get(position).getDate()); holder.finally1_category.setText(results.get(position).getCategory());// x.image().bind(holder.finally1_image, results.get(position).getThumbnail_pic_s(), imageOptions); getImage(results.get(position).getThumbnail_pic_s(), holder.finally1_image); xLV.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle("网络选择"); builder.setNegativeButton("取消", null); builder.setSingleChoiceItems(new String[]{"WIFI", "手机流量"}, 2, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { //WIFI case 0: AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle("系统更新"); builder.setMessage("现已检测到新版本,是否更新?"); builder.setNegativeButton("取消", null); builder.setPositiveButton("确认", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { downLoad(); } }); builder.create().show(); break; //手机流量 case 1: startActivity(new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS)); break; } } }); builder.create().show(); } }); return convertView; } class ViewHolder { TextView finally1_title, finally1_category, finally1_author_name, finally1_data; ImageView finally1_image, finally1_pop; } } public void downLoad() { String wangzhi = "http://down11.zol.com.cn/suyan/lulutong3.6.5g.apk"; String path = Environment.getExternalStorageDirectory().getPath() + "/teme1/myapk.apk"; File file = new File(path); File parentFile = file.getParentFile(); if (!parentFile.exists()) { parentFile.mkdir(); } RequestParams params = new RequestParams(wangzhi); params.setAutoRename(false); params.setAutoResume(true); params.setSaveFilePath(path); x.http().get(params, new Callback.ProgressCallback<File>() { @Override public void onSuccess(File result) { Toast.makeText(MainActivity.this, "下载成功", Toast.LENGTH_SHORT).show(); installDownloadApk(result); } @Override public void onError(Throwable ex, boolean isOnCallback) { Toast.makeText(MainActivity.this, "下载失败", Toast.LENGTH_SHORT).show(); } @Override public void onCancelled(CancelledException cex) { } @Override public void onFinished() { cancleProgressDialog(); } @Override public void onWaiting() { } @Override public void onStarted() { showProgressDialog(); } @Override public void onLoading(long total, long current, boolean isDownloading) { int progress = (int) (current * 100/ total ); if (progress >= 0 && progress <= 100) { updataProgressDialog(progress); } } }); } private void installDownloadApk(File result) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(Uri.fromFile(result), "application/vnd.android.package-archive"); startActivity(intent); } private void cancleProgressDialog() { if (progressDialog == null) { return; } if (progressDialog.isShowing()) { progressDialog.dismiss(); } } private void showProgressDialog() { progressDialog = new ProgressDialog(this); //设置progressDialog显示样式 progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setMessage("我正在下载东西"); progressDialog.setTitle("请等待"); progressDialog.setProgress(0); progressDialog.show(); } private void updataProgressDialog(int progress) { if (progressDialog == null) { return; } progressDialog.setProgress(progress); }}
阅读全文
0 0
- xListView+下载安装apk+跳转设置WIFI界面
- 实现apk下载+跳转WiFi设置页面+xlistview加载数据
- 跳转到wifi设置界面
- 跳转到系统WIFI设置界面
- iOS跳转到系统设置wifi界面
- apk 内部下载 完成后直接跳转系统安装界面 android
- iOS应用跳转到设置界面设置wifi
- 下载安装apk 与webview 百度界面
- iOS 跳转到系统的wifi or 设置界面
- 应用跳转到系统设置的WiFi界面
- iOS10从app跳转到WiFi设置界面
- APP跳转到系统Wifi设置界面方式
- 跳转WIFi设置
- xlistview+跳转
- ios 界面跳转设置
- IOS 跳转设置界面
- iOS 跳转设置界面
- iOS 跳转设置界面
- 【线下沙龙免费报名】像阿里巴巴一样工作_听干货分享欣赏阿里西溪园区风景
- Host '*' is not allowed to connect to this MariaDB server
- Apache+tomcat的整合
- C#发送邮件类
- BIEE迁移后服务报错:Server not initialized. Please make sure the repository is ready
- xListView+下载安装apk+跳转设置WIFI界面
- Android高效加载大图、多图解决方案,有效避免程序OOM
- 嵌入系统概论-常见问题
- Neural Response Generation via GAN with an Approximate Embedding Layer 的一些理解
- C++动态创建二维数组,memset()初始化二维数组
- 爬取并下载国家地理杂志官网8月份照片
- Android 高级混淆和代码保护技术
- 广播判断网络状态
- 广播监听网络状态