Okhttp以及封装

mac2026-01-11  5

Day11.01作业

布局两个接口两个JavaBean Okhttp封装适配器MainMain2Main3

布局

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <EditText android:id="@+id/name" android:hint="用户名" android:layout_width="match_parent" android:layout_height="wrap_content" /> <EditText android:id="@+id/pwd" android:hint="密码" android:layout_width="match_parent" android:layout_height="wrap_content" /> <Button android:id="@+id/login" android:text="登录" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:id="@+id/register" android:text="注册" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".Main2Activity"> <EditText android:id="@+id/name" android:hint="用户名" android:layout_width="match_parent" android:layout_height="wrap_content" /> <EditText android:id="@+id/pwd" android:hint="密码" android:layout_width="match_parent" android:layout_height="wrap_content" /> <Button android:id="@+id/register" android:text="注册" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Main3Activity"> <ListView android:id="@+id/lv" android:layout_width="match_parent" android:layout_height="match_parent"></ListView> </LinearLayout> <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/tv" android:text="这是标题" android:textSize="20sp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>

两个接口

package com.example.day1001homework.listener; public interface MyListener { void onOk(String ok); void onError(String message); } package com.example.day1001homework.listener; public interface MyProgressListener { void setProgress(int s); void finish(); void onError(String s); }

两个JavaBean

package com.example.day1001homework; import java.util.List; public class Douyin { /** * code : 200 * msg : 成功! * data : [{"type":"10","text":"别难过,我们陪你","user_id":"21877435","name":"死神小一生","screen_name":"死神小一生","profile_image":"http://wimg.spriteapp.cn/profile/large/2018/04/22/5adb6ead49ab8_mini.jpg","created_at":"2019-11-01 15:32:02","create_time":null,"passtime":"2019-11-01 15:32:02","love":"77","hate":"3","comment":"1","repost":"0","bookmark":"0","bimageuri":"","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"17083","theme_name":"Gif专区","theme_type":"1","videouri":"","videotime":0,"original_pid":"0","cache_version":2,"playcount":null,"playfcount":null,"cai":"3","weixin_url":null,"image1":"http://wimg.spriteapp.cn/ugc/2019/11/01/5dbb149da6f75.gif","image2":"http://wimg.spriteapp.cn/ugc/2019/11/01/5dbb149da6f75.gif","is_gif":false,"image0":"http://wimg.spriteapp.cn/ugc/2019/11/01/5dbb149da6f75.gif","image_small":null,"cdn_img":"http://wimg.spriteapp.cn/ugc/2019/11/01/5dbb149da6f75.gif","width":"330","height":"241","tag":"","t":1572593522,"ding":"77","favourite":"0","top_cmt":null,"themes":null},{"type":"41","text":"这种情况谁的责任","user_id":"19878428","name":" qhG","screen_name":" qhG","profile_image":"http://wx.qlogo.cn/mmopen/2EzJggZltBM0fXEvQFJakibdmOfCUV2ZrcAKyiahnBXK1dpiaf1cibyhtmPTnC5xqW0c42BZS6IQiaib4b7iabltRED4gCF93QRSk6p/0","created_at":"2019-11-01 15:25:01","create_time":null,"passtime":"2019-11-01 15:25:01","love":"69","hate":"1","comment":"20","repost":"0","bookmark":"0","bimageuri":"http://wimg.spriteapp.cn/picture/2019/1101/5dbb899c6121c_wpd.jpg","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"58191","theme_name":"搞笑视频","theme_type":"1","videouri":"http://uvideo.spriteapp.cn/video/2019/1101/5dbb899c6121c_wpd.mp4","videotime":64,"original_pid":"0","cache_version":2,"playcount":"680","playfcount":"294","cai":"1","weixin_url":null,"image1":"http://wimg.spriteapp.cn/picture/2019/1101/5dbb899c6121c_wpd.jpg","image2":"http://wimg.spriteapp.cn/picture/2019/1101/5dbb899c6121c_wpd.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/picture/2019/1101/5dbb899c6121c_wpd.jpg","image_small":"http://wimg.spriteapp.cn/picture/2019/1101/5dbb899c6121c_wpd.jpg","cdn_img":"http://wimg.spriteapp.cn/picture/2019/1101/5dbb899c6121c_wpd.jpg","width":"640","height":"368","tag":"","t":1572593101,"ding":"69","favourite":"0","top_cmt":null,"themes":null},{"type":"41","text":"牙膏和蜂蜜混合均匀,这个效果太棒了,解决了很多女士的苦恼","user_id":"23132292","name":"闻问切","screen_name":"闻问切","profile_image":"http://wimg.spriteapp.cn/profile/large/2019/07/04/5d1d96330cf44_mini.jpg","created_at":"2019-11-01 14:55:02","create_time":null,"passtime":"2019-11-01 14:55:02","love":"64","hate":"1","comment":"4","repost":"0","bookmark":"0","bimageuri":"http://wimg.spriteapp.cn/picture/2019/1030/5db9a5220a14b_wpd.jpg","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"8466","theme_name":"知识分享","theme_type":"1","videouri":"http://uvideo.spriteapp.cn/video/2019/1030/5db9a5220a14b_wpd.mp4","videotime":53,"original_pid":"0","cache_version":2,"playcount":"319","playfcount":"15","cai":"1","weixin_url":null,"image1":"http://wimg.spriteapp.cn/picture/2019/1030/5db9a5220a14b_wpd.jpg","image2":"http://wimg.spriteapp.cn/picture/2019/1030/5db9a5220a14b_wpd.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/picture/2019/1030/5db9a5220a14b_wpd.jpg","image_small":"http://wimg.spriteapp.cn/picture/2019/1030/5db9a5220a14b_wpd.jpg","cdn_img":"http://wimg.spriteapp.cn/picture/2019/1030/5db9a5220a14b_wpd.jpg","width":"852","height":"480","tag":"","t":1572591302,"ding":"64","favourite":"0","top_cmt":null,"themes":null},{"type":"10","text":"不是说好女生都怕老鼠的嘛!","user_id":"18225455","name":"笑忘丶丶","screen_name":"笑忘丶丶","profile_image":"http://wimg.spriteapp.cn/profile/large/2018/06/05/5b1600459263a_mini.jpg","created_at":"2019-11-01 14:42:01","create_time":null,"passtime":"2019-11-01 14:42:01","love":"78","hate":"6","comment":"17","repost":"0","bookmark":"0","bimageuri":"","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"58240","theme_name":"搞笑图片","theme_type":"1","videouri":"","videotime":0,"original_pid":"0","cache_version":2,"playcount":null,"playfcount":null,"cai":"6","weixin_url":null,"image1":"http://wimg.spriteapp.cn/ugc/2019/11/01/5dbb603257250.gif","image2":"http://wimg.spriteapp.cn/ugc/2019/11/01/5dbb603257250.gif","is_gif":false,"image0":"http://wimg.spriteapp.cn/ugc/2019/11/01/5dbb603257250.gif","image_small":null,"cdn_img":"http://wimg.spriteapp.cn/ugc/2019/11/01/5dbb603257250.gif","width":"256","height":"202","tag":"","t":1572590521,"ding":"78","favourite":"0","top_cmt":null,"themes":null},{"type":"41","text":"杨坤这场又要折?超强素人《世界上不存在的歌》唱哭全场!爱了爱了~","user_id":"23131865","name":"听闻小新新很酷","screen_name":"听闻小新新很酷","profile_image":"http://wimg.spriteapp.cn/profile/large/2019/07/04/5d1d90bd2d2b5_mini.jpg","created_at":"2019-11-01 14:24:02","create_time":null,"passtime":"2019-11-01 14:24:02","love":"68","hate":"4","comment":"2","repost":"1","bookmark":"1","bimageuri":"http://wimg.spriteapp.cn/picture/2019/1031/5dba0a3956792_wpd.jpg","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"22871","theme_name":"音乐汇","theme_type":"1","videouri":"http://uvideo.spriteapp.cn/video/2019/1031/5dba0a3956792_wpd.mp4","videotime":201,"original_pid":"0","cache_version":2,"playcount":"641","playfcount":"25","cai":"4","weixin_url":null,"image1":"http://wimg.spriteapp.cn/picture/2019/1031/5dba0a3956792_wpd.jpg","image2":"http://wimg.spriteapp.cn/picture/2019/1031/5dba0a3956792_wpd.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/picture/2019/1031/5dba0a3956792_wpd.jpg","image_small":"http://wimg.spriteapp.cn/picture/2019/1031/5dba0a3956792_wpd.jpg","cdn_img":"http://wimg.spriteapp.cn/picture/2019/1031/5dba0a3956792_wpd.jpg","width":"852","height":"480","tag":"","t":1572589442,"ding":"68","favourite":"1","top_cmt":null,"themes":null},{"type":"41","text":"耂司机:卧槽,还好损失不大\u2026\u2026","user_id":"11996791","name":"Pescado","screen_name":"Pescado","profile_image":"http://wimg.spriteapp.cn/profile/large/2019/02/10/5c6015142adc7_mini.jpg","created_at":"2019-11-01 13:54:02","create_time":null,"passtime":"2019-11-01 13:54:02","love":"326","hate":"8","comment":"83","repost":"12","bookmark":"2","bimageuri":"http://wimg.spriteapp.cn/picture/2019/1031/5dba5b0f1d532__b.jpg","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"55163","theme_name":"主版块","theme_type":"1","videouri":"http://uvideo.spriteapp.cn/video/2019/1031/5dba5b0f41bac_wpd.mp4","videotime":85,"original_pid":"0","cache_version":2,"playcount":"5777","playfcount":"1427","cai":"8","weixin_url":null,"image1":"http://wimg.spriteapp.cn/picture/2019/1031/5dba5b0f1d532__b.jpg","image2":"http://wimg.spriteapp.cn/picture/2019/1031/5dba5b0f1d532__b.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/picture/2019/1031/5dba5b0f1d532__b.jpg","image_small":"http://wimg.spriteapp.cn/picture/2019/1031/5dba5b0f1d532__b.jpg","cdn_img":"http://wimg.spriteapp.cn/picture/2019/1031/5dba5b0f1d532__b.jpg","width":"368","height":"640","tag":"","t":1572587642,"ding":"326","favourite":"2","top_cmt":null,"themes":null},{"type":"10","text":"如果是你,你会怎么办?","user_id":"23128546","name":"龙涛天津","screen_name":"龙涛天津","profile_image":"http://wimg.spriteapp.cn/profile/large/2019/07/04/5d1d70b5a8e48_mini.jpg","created_at":"2019-11-01 13:52:01","create_time":null,"passtime":"2019-11-01 13:52:01","love":"126","hate":"13","comment":"34","repost":"1","bookmark":"0","bimageuri":"","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"58240","theme_name":"搞笑图片","theme_type":"1","videouri":"","videotime":0,"original_pid":"0","cache_version":2,"playcount":null,"playfcount":null,"cai":"13","weixin_url":null,"image1":"http://wimg.spriteapp.cn/ugc/2019/10/30/5db9683feb330_1.jpg","image2":"http://wimg.spriteapp.cn/ugc/2019/10/30/5db9683feb330_1.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/ugc/2019/10/30/5db9683feb330_1.jpg","image_small":null,"cdn_img":"http://wimg.spriteapp.cn/ugc/2019/10/30/5db9683feb330_1.jpg","width":"1080","height":"1357","tag":"","t":1572587521,"ding":"126","favourite":"0","top_cmt":null,"themes":null},{"type":"41","text":"陈真完整版","user_id":"23178429","name":"陀螺世界养龙","screen_name":"陀螺世界养龙","profile_image":"http://wimg.spriteapp.cn/profile/large/2019/10/30/5db9711f94ef8_mini.jpg","created_at":"2019-11-01 13:24:02","create_time":null,"passtime":"2019-11-01 13:24:02","love":"122","hate":"9","comment":"12","repost":"1","bookmark":"3","bimageuri":"http://wimg.spriteapp.cn/picture/2019/1031/5dbab398622ff_wpd.jpg","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"407","theme_name":"影视分享","theme_type":"1","videouri":"http://uvideo.spriteapp.cn/video/2019/1031/5dbab398622ff_wpd.mp4","videotime":178,"original_pid":"0","cache_version":2,"playcount":"2240","playfcount":"260","cai":"9","weixin_url":null,"image1":"http://wimg.spriteapp.cn/picture/2019/1031/5dbab398622ff_wpd.jpg","image2":"http://wimg.spriteapp.cn/picture/2019/1031/5dbab398622ff_wpd.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/picture/2019/1031/5dbab398622ff_wpd.jpg","image_small":"http://wimg.spriteapp.cn/picture/2019/1031/5dbab398622ff_wpd.jpg","cdn_img":"http://wimg.spriteapp.cn/picture/2019/1031/5dbab398622ff_wpd.jpg","width":"358","height":"636","tag":"","t":1572585842,"ding":"122","favourite":"3","top_cmt":null,"themes":null},{"type":"10","text":"十张老照片","user_id":"7442235","name":"门头包","screen_name":"门头包","profile_image":"http://tp1.sinaimg.cn/3177288052/50/5657880483/1","created_at":"2019-11-01 13:22:02","create_time":null,"passtime":"2019-11-01 13:22:02","love":"112","hate":"10","comment":"13","repost":"0","bookmark":"2","bimageuri":"","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"55163","theme_name":"主版块","theme_type":"1","videouri":"","videotime":0,"original_pid":"0","cache_version":2,"playcount":null,"playfcount":null,"cai":"10","weixin_url":null,"image1":"http://wimg.spriteapp.cn/ugc/2019/10/31/5dba6f8f92df1_1.jpg","image2":"http://wimg.spriteapp.cn/ugc/2019/10/31/5dba6f8f92df1_1.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/ugc/2019/10/31/5dba6f8f92df1_1.jpg","image_small":null,"cdn_img":"http://wimg.spriteapp.cn/ugc/2019/10/31/5dba6f8f92df1_1.jpg","width":"1080","height":"12826","tag":"","t":1572585722,"ding":"112","favourite":"2","top_cmt":null,"themes":null},{"type":"41","text":"当代年轻人的生活,我中招了,你们呢?","user_id":"17800244","name":"唐唐频道","screen_name":"唐唐频道","profile_image":"http://wimg.spriteapp.cn/profile/large/2016/05/10/573192938ef8d_mini.jpg","created_at":"2019-11-01 12:54:01","create_time":null,"passtime":"2019-11-01 12:54:01","love":"89","hate":"12","comment":"6","repost":"2","bookmark":"4","bimageuri":"http://wimg.spriteapp.cn/picture/2019/1031/5dbab17d035ec_wpd.jpg","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"58191","theme_name":"搞笑视频","theme_type":"1","videouri":"http://uvideo.spriteapp.cn/video/2019/1031/5dbab17d035ec_wpd.mp4","videotime":205,"original_pid":"0","cache_version":2,"playcount":"2083","playfcount":"105","cai":"12","weixin_url":null,"image1":"http://wimg.spriteapp.cn/picture/2019/1031/5dbab17d035ec_wpd.jpg","image2":"http://wimg.spriteapp.cn/picture/2019/1031/5dbab17d035ec_wpd.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/picture/2019/1031/5dbab17d035ec_wpd.jpg","image_small":"http://wimg.spriteapp.cn/picture/2019/1031/5dbab17d035ec_wpd.jpg","cdn_img":"http://wimg.spriteapp.cn/picture/2019/1031/5dbab17d035ec_wpd.jpg","width":"270","height":"480","tag":"","t":1572584041,"ding":"89","favourite":"4","top_cmt":null,"themes":null},{"type":"10","text":"如何在不吵醒对方的情况下,确定对方已经睡着?","user_id":"15299575","name":"笑品百味人生","screen_name":"笑品百味人生","profile_image":"http://qzapp.qlogo.cn/qzapp/100336987/D717E1D771EA0C38EE4F8BFC9C02E756/100","created_at":"2019-11-01 12:52:01","create_time":null,"passtime":"2019-11-01 12:52:01","love":"122","hate":"12","comment":"11","repost":"0","bookmark":"0","bimageuri":"","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"58240","theme_name":"搞笑图片","theme_type":"1","videouri":"","videotime":0,"original_pid":"0","cache_version":2,"playcount":null,"playfcount":null,"cai":"12","weixin_url":null,"image1":"http://wimg.spriteapp.cn/ugc/2019/10/31/5dba759daf092_1.jpg","image2":"http://wimg.spriteapp.cn/ugc/2019/10/31/5dba759daf092_1.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/ugc/2019/10/31/5dba759daf092_1.jpg","image_small":null,"cdn_img":"http://wimg.spriteapp.cn/ugc/2019/10/31/5dba759daf092_1.jpg","width":"700","height":"397","tag":"","t":1572583921,"ding":"122","favourite":"0","top_cmt":null,"themes":null},{"type":"41","text":"其实我真的累了!","user_id":"20063164","name":"一段心语","screen_name":"一段心语","profile_image":"http://wimg.spriteapp.cn/profile/large/2019/10/16/5da72eca81af5_mini.jpg","created_at":"2019-11-01 12:44:01","create_time":null,"passtime":"2019-11-01 12:44:01","love":"75","hate":"11","comment":"9","repost":"2","bookmark":"2","bimageuri":"http://wimg.spriteapp.cn/picture/2019/1031/5dbaec9e5ec92_wpd.jpg","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"56781","theme_name":"情感社区","theme_type":"1","videouri":"http://uvideo.spriteapp.cn/video/2019/1031/5dbaec9e5ec92_wpd.mp4","videotime":60,"original_pid":"0","cache_version":2,"playcount":"1386","playfcount":"72","cai":"11","weixin_url":null,"image1":"http://wimg.spriteapp.cn/picture/2019/1031/5dbaec9e5ec92_wpd.jpg","image2":"http://wimg.spriteapp.cn/picture/2019/1031/5dbaec9e5ec92_wpd.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/picture/2019/1031/5dbaec9e5ec92_wpd.jpg","image_small":"http://wimg.spriteapp.cn/picture/2019/1031/5dbaec9e5ec92_wpd.jpg","cdn_img":"http://wimg.spriteapp.cn/picture/2019/1031/5dbaec9e5ec92_wpd.jpg","width":"600","height":"1066","tag":"","t":1572583441,"ding":"75","favourite":"2","top_cmt":null,"themes":null},{"type":"10","text":"男朋友不在身边,女孩子都是这样吃饭的","user_id":"23122982","name":"爱笑的女孩","screen_name":"爱笑的女孩","profile_image":"http://wimg.spriteapp.cn/profile/large/2019/07/03/5d1c79d3d59a1_mini.jpg","created_at":"2019-11-01 12:36:01","create_time":null,"passtime":"2019-11-01 12:36:01","love":"111","hate":"4","comment":"6","repost":"2","bookmark":"3","bimageuri":"","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"58240","theme_name":"搞笑图片","theme_type":"1","videouri":"","videotime":0,"original_pid":"0","cache_version":2,"playcount":null,"playfcount":null,"cai":"4","weixin_url":null,"image1":"http://wimg.spriteapp.cn/ugc/2019/10/30/5db94ca7a761d.gif","image2":"http://wimg.spriteapp.cn/ugc/2019/10/30/5db94ca7a761d.gif","is_gif":false,"image0":"http://wimg.spriteapp.cn/ugc/2019/10/30/5db94ca7a761d.gif","image_small":null,"cdn_img":"http://wimg.spriteapp.cn/ugc/2019/10/30/5db94ca7a761d.gif","width":"214","height":"380","tag":"","t":1572582961,"ding":"111","favourite":"3","top_cmt":null,"themes":null},{"type":"41","text":"这些小窍门真的太腻害了\u2026\u2026","user_id":"11996791","name":"Pescado","screen_name":"Pescado","profile_image":"http://wimg.spriteapp.cn/profile/large/2019/02/10/5c6015142adc7_mini.jpg","created_at":"2019-11-01 12:34:04","create_time":null,"passtime":"2019-11-01 12:34:04","love":"94","hate":"3","comment":"4","repost":"7","bookmark":"47","bimageuri":"http://wimg.spriteapp.cn/picture/2019/1101/5dbb0fdc963d5__b.jpg","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"55163","theme_name":"主版块","theme_type":"1","videouri":"http://uvideo.spriteapp.cn/video/2019/1101/5dbb0fdd362cf_wpd.mp4","videotime":190,"original_pid":"0","cache_version":2,"playcount":"1735","playfcount":"75","cai":"3","weixin_url":null,"image1":"http://wimg.spriteapp.cn/picture/2019/1101/5dbb0fdc963d5__b.jpg","image2":"http://wimg.spriteapp.cn/picture/2019/1101/5dbb0fdc963d5__b.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/picture/2019/1101/5dbb0fdc963d5__b.jpg","image_small":"http://wimg.spriteapp.cn/picture/2019/1101/5dbb0fdc963d5__b.jpg","cdn_img":"http://wimg.spriteapp.cn/picture/2019/1101/5dbb0fdc963d5__b.jpg","width":"400","height":"400","tag":"","t":1572582844,"ding":"94","favourite":"47","top_cmt":null,"themes":null},{"type":"41","text":"健康轻食系类\u2014\u2014战斧牛排","user_id":"22967444","name":"香喷喷的小烤鸡","screen_name":"香喷喷的小烤鸡","profile_image":"http://wimg.spriteapp.cn/profile/large/2018/10/26/5bd2b30317edb_mini.jpg","created_at":"2019-11-01 12:24:02","create_time":null,"passtime":"2019-11-01 12:24:02","love":"125","hate":"22","comment":"12","repost":"1","bookmark":"1","bimageuri":"http://wimg.spriteapp.cn/picture/2019/1031/5dba9d6c2dd86_wpd.jpg","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"0","theme_name":"","theme_type":"0","videouri":"http://uvideo.spriteapp.cn/video/2019/1031/5dba9d6c2dd86_wpd.mp4","videotime":123,"original_pid":"0","cache_version":2,"playcount":"2558","playfcount":"501","cai":"22","weixin_url":null,"image1":"http://wimg.spriteapp.cn/picture/2019/1031/5dba9d6c2dd86_wpd.jpg","image2":"http://wimg.spriteapp.cn/picture/2019/1031/5dba9d6c2dd86_wpd.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/picture/2019/1031/5dba9d6c2dd86_wpd.jpg","image_small":"http://wimg.spriteapp.cn/picture/2019/1031/5dba9d6c2dd86_wpd.jpg","cdn_img":"http://wimg.spriteapp.cn/picture/2019/1031/5dba9d6c2dd86_wpd.jpg","width":"1066","height":"600","tag":"","t":1572582242,"ding":"125","favourite":"1","top_cmt":null,"themes":null},{"type":"10","text":"给你一张演唱会门票你最想去谁的演唱会呢??","user_id":"23127128","name":"黄a鸡","screen_name":"黄a鸡","profile_image":"http://wimg.spriteapp.cn/profile/large/2019/07/04/5d1d6d58c7434_mini.jpg","created_at":"2019-11-01 12:20:02","create_time":null,"passtime":"2019-11-01 12:20:02","love":"76","hate":"14","comment":"60","repost":"1","bookmark":"0","bimageuri":"","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"58240","theme_name":"搞笑图片","theme_type":"1","videouri":"","videotime":0,"original_pid":"0","cache_version":2,"playcount":null,"playfcount":null,"cai":"14","weixin_url":null,"image1":"http://wimg.spriteapp.cn/ugc/2019/10/30/5db95f804f832_1.jpg","image2":"http://wimg.spriteapp.cn/ugc/2019/10/30/5db95f804f832_1.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/ugc/2019/10/30/5db95f804f832_1.jpg","image_small":null,"cdn_img":"http://wimg.spriteapp.cn/ugc/2019/10/30/5db95f804f832_1.jpg","width":"826","height":"536","tag":"","t":1572582002,"ding":"76","favourite":"0","top_cmt":null,"themes":null},{"type":"41","text":"自从学会了,就停不下来了。","user_id":"7801354","name":"Just Now'","screen_name":"Just Now'","profile_image":"http://qzapp.qlogo.cn/qzapp/100336987/8F9AE2AB7DD0A427612876788FD14D4A/100","created_at":"2019-11-01 12:14:01","create_time":null,"passtime":"2019-11-01 12:14:01","love":"90","hate":"9","comment":"7","repost":"1","bookmark":"0","bimageuri":"http://wimg.spriteapp.cn/picture/2019/1031/5dbad5dc2798b_wpd.jpg","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"55163","theme_name":"主版块","theme_type":"1","videouri":"http://uvideo.spriteapp.cn/video/2019/1031/5dbad5dc2798b_wpd.mp4","videotime":19,"original_pid":"0","cache_version":2,"playcount":"2890","playfcount":"187","cai":"9","weixin_url":null,"image1":"http://wimg.spriteapp.cn/picture/2019/1031/5dbad5dc2798b_wpd.jpg","image2":"http://wimg.spriteapp.cn/picture/2019/1031/5dbad5dc2798b_wpd.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/picture/2019/1031/5dbad5dc2798b_wpd.jpg","image_small":"http://wimg.spriteapp.cn/picture/2019/1031/5dbad5dc2798b_wpd.jpg","cdn_img":"http://wimg.spriteapp.cn/picture/2019/1031/5dbad5dc2798b_wpd.jpg","width":"272","height":"480","tag":"","t":1572581641,"ding":"90","favourite":"0","top_cmt":null,"themes":null},{"type":"41","text":"这部魔幻片太燃了,殴打大天使冲死神比中指,上帝和撒旦抢着要他","user_id":"21662883","name":"小冷说电影","screen_name":"小冷说电影","profile_image":"http://wimg.spriteapp.cn/profile/large/2019/09/20/5d849b0fb4678_mini.jpg","created_at":"2019-11-01 12:04:05","create_time":null,"passtime":"2019-11-01 12:04:05","love":"112","hate":"11","comment":"13","repost":"0","bookmark":"15","bimageuri":"http://wimg.spriteapp.cn/picture/2019/1031/5dbab7f22dd04_wpd.jpg","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"407","theme_name":"影视分享","theme_type":"1","videouri":"http://uvideo.spriteapp.cn/video/2019/1031/5dbab7f22dd04_wpd.mp4","videotime":405,"original_pid":"0","cache_version":2,"playcount":"2584","playfcount":"463","cai":"11","weixin_url":null,"image1":"http://wimg.spriteapp.cn/picture/2019/1031/5dbab7f22dd04_wpd.jpg","image2":"http://wimg.spriteapp.cn/picture/2019/1031/5dbab7f22dd04_wpd.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/picture/2019/1031/5dbab7f22dd04_wpd.jpg","image_small":"http://wimg.spriteapp.cn/picture/2019/1031/5dbab7f22dd04_wpd.jpg","cdn_img":"http://wimg.spriteapp.cn/picture/2019/1031/5dbab7f22dd04_wpd.jpg","width":"1024","height":"576","tag":"","t":1572581045,"ding":"112","favourite":"15","top_cmt":null,"themes":null},{"type":"10","text":"拧不开瓶盖的女孩用餐刀的样子!","user_id":"23133883","name":"颜控晚癌","screen_name":"颜控晚癌","profile_image":"http://wimg.spriteapp.cn/profile/large/2019/07/04/5d1da06ea2793_mini.jpg","created_at":"2019-11-01 12:04:02","create_time":null,"passtime":"2019-11-01 12:04:02","love":"94","hate":"4","comment":"8","repost":"1","bookmark":"0","bimageuri":"","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"58240","theme_name":"搞笑图片","theme_type":"1","videouri":"","videotime":0,"original_pid":"0","cache_version":2,"playcount":null,"playfcount":null,"cai":"4","weixin_url":null,"image1":"http://wimg.spriteapp.cn/ugc/2019/10/30/5db94770c27d1.gif","image2":"http://wimg.spriteapp.cn/ugc/2019/10/30/5db94770c27d1.gif","is_gif":false,"image0":"http://wimg.spriteapp.cn/ugc/2019/10/30/5db94770c27d1.gif","image_small":null,"cdn_img":"http://wimg.spriteapp.cn/ugc/2019/10/30/5db94770c27d1.gif","width":"250","height":"444","tag":"","t":1572581042,"ding":"94","favourite":"0","top_cmt":null,"themes":null},{"type":"41","text":"这背景音乐真特么应景","user_id":"22018647","name":"觉醒的哈士奇","screen_name":"觉醒的哈士奇","profile_image":"http://wimg.spriteapp.cn/profile/large/2019/03/21/5c9364c371198_mini.jpg","created_at":"2019-11-01 11:54:01","create_time":null,"passtime":"2019-11-01 11:54:01","love":"169","hate":"9","comment":"9","repost":"8","bookmark":"0","bimageuri":"http://wimg.spriteapp.cn/picture/2019/1031/597edcee-fba2-11e9-9e0c-1866daea6abd_wpd.jpg","voiceuri":null,"voicetime":null,"voicelength":null,"status":"4","theme_id":"55163","theme_name":"主版块","theme_type":"1","videouri":"http://uvideo.spriteapp.cn/video/2019/1031/597edcee-fba2-11e9-9e0c-1866daea6abd_wpd.mp4","videotime":16,"original_pid":"0","cache_version":2,"playcount":"3990","playfcount":"2297","cai":"9","weixin_url":null,"image1":"http://wimg.spriteapp.cn/picture/2019/1031/597edcee-fba2-11e9-9e0c-1866daea6abd_wpd.jpg","image2":"http://wimg.spriteapp.cn/picture/2019/1031/597edcee-fba2-11e9-9e0c-1866daea6abd_wpd.jpg","is_gif":false,"image0":"http://wimg.spriteapp.cn/picture/2019/1031/597edcee-fba2-11e9-9e0c-1866daea6abd_wpd.jpg","image_small":"http://wimg.spriteapp.cn/picture/2019/1031/597edcee-fba2-11e9-9e0c-1866daea6abd_wpd.jpg","cdn_img":"http://wimg.spriteapp.cn/picture/2019/1031/597edcee-fba2-11e9-9e0c-1866daea6abd_wpd.jpg","width":"576","height":"1024","tag":"","t":1572580441,"ding":"169","favourite":"0","top_cmt":null,"themes":null}] */ private int code; private String msg; private List<DataBean> data; public int getCode() { return code; } public void setCode(int code) { this.code = code; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public List<DataBean> getData() { return data; } public void setData(List<DataBean> data) { this.data = data; } public static class DataBean { /** * type : 10 * text : 别难过,我们陪你 * user_id : 21877435 * name : 死神小一生 * screen_name : 死神小一生 * profile_image : http://wimg.spriteapp.cn/profile/large/2018/04/22/5adb6ead49ab8_mini.jpg * created_at : 2019-11-01 15:32:02 * create_time : null * passtime : 2019-11-01 15:32:02 * love : 77 * hate : 3 * comment : 1 * repost : 0 * bookmark : 0 * bimageuri : * voiceuri : null * voicetime : null * voicelength : null * status : 4 * theme_id : 17083 * theme_name : Gif专区 * theme_type : 1 * videouri : * videotime : 0 * original_pid : 0 * cache_version : 2 * playcount : null * playfcount : null * cai : 3 * weixin_url : null * image1 : http://wimg.spriteapp.cn/ugc/2019/11/01/5dbb149da6f75.gif * image2 : http://wimg.spriteapp.cn/ugc/2019/11/01/5dbb149da6f75.gif * is_gif : false * image0 : http://wimg.spriteapp.cn/ugc/2019/11/01/5dbb149da6f75.gif * image_small : null * cdn_img : http://wimg.spriteapp.cn/ugc/2019/11/01/5dbb149da6f75.gif * width : 330 * height : 241 * tag : * t : 1572593522 * ding : 77 * favourite : 0 * top_cmt : null * themes : null */ private String type; private String text; private String user_id; private String name; private String screen_name; private String profile_image; private String created_at; private Object create_time; private String passtime; private String love; private String hate; private String comment; private String repost; private String bookmark; private String bimageuri; private Object voiceuri; private Object voicetime; private Object voicelength; private String status; private String theme_id; private String theme_name; private String theme_type; private String videouri; private int videotime; private String original_pid; private int cache_version; private Object playcount; private Object playfcount; private String cai; private Object weixin_url; private String image1; private String image2; private boolean is_gif; private String image0; private Object image_small; private String cdn_img; private String width; private String height; private String tag; private int t; private String ding; private String favourite; private Object top_cmt; private Object themes; public String getType() { return type; } public void setType(String type) { this.type = type; } public String getText() { return text; } public void setText(String text) { this.text = text; } public String getUser_id() { return user_id; } public void setUser_id(String user_id) { this.user_id = user_id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getScreen_name() { return screen_name; } public void setScreen_name(String screen_name) { this.screen_name = screen_name; } public String getProfile_image() { return profile_image; } public void setProfile_image(String profile_image) { this.profile_image = profile_image; } public String getCreated_at() { return created_at; } public void setCreated_at(String created_at) { this.created_at = created_at; } public Object getCreate_time() { return create_time; } public void setCreate_time(Object create_time) { this.create_time = create_time; } public String getPasstime() { return passtime; } public void setPasstime(String passtime) { this.passtime = passtime; } public String getLove() { return love; } public void setLove(String love) { this.love = love; } public String getHate() { return hate; } public void setHate(String hate) { this.hate = hate; } public String getComment() { return comment; } public void setComment(String comment) { this.comment = comment; } public String getRepost() { return repost; } public void setRepost(String repost) { this.repost = repost; } public String getBookmark() { return bookmark; } public void setBookmark(String bookmark) { this.bookmark = bookmark; } public String getBimageuri() { return bimageuri; } public void setBimageuri(String bimageuri) { this.bimageuri = bimageuri; } public Object getVoiceuri() { return voiceuri; } public void setVoiceuri(Object voiceuri) { this.voiceuri = voiceuri; } public Object getVoicetime() { return voicetime; } public void setVoicetime(Object voicetime) { this.voicetime = voicetime; } public Object getVoicelength() { return voicelength; } public void setVoicelength(Object voicelength) { this.voicelength = voicelength; } public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } public String getTheme_id() { return theme_id; } public void setTheme_id(String theme_id) { this.theme_id = theme_id; } public String getTheme_name() { return theme_name; } public void setTheme_name(String theme_name) { this.theme_name = theme_name; } public String getTheme_type() { return theme_type; } public void setTheme_type(String theme_type) { this.theme_type = theme_type; } public String getVideouri() { return videouri; } public void setVideouri(String videouri) { this.videouri = videouri; } public int getVideotime() { return videotime; } public void setVideotime(int videotime) { this.videotime = videotime; } public String getOriginal_pid() { return original_pid; } public void setOriginal_pid(String original_pid) { this.original_pid = original_pid; } public int getCache_version() { return cache_version; } public void setCache_version(int cache_version) { this.cache_version = cache_version; } public Object getPlaycount() { return playcount; } public void setPlaycount(Object playcount) { this.playcount = playcount; } public Object getPlayfcount() { return playfcount; } public void setPlayfcount(Object playfcount) { this.playfcount = playfcount; } public String getCai() { return cai; } public void setCai(String cai) { this.cai = cai; } public Object getWeixin_url() { return weixin_url; } public void setWeixin_url(Object weixin_url) { this.weixin_url = weixin_url; } public String getImage1() { return image1; } public void setImage1(String image1) { this.image1 = image1; } public String getImage2() { return image2; } public void setImage2(String image2) { this.image2 = image2; } public boolean isIs_gif() { return is_gif; } public void setIs_gif(boolean is_gif) { this.is_gif = is_gif; } public String getImage0() { return image0; } public void setImage0(String image0) { this.image0 = image0; } public Object getImage_small() { return image_small; } public void setImage_small(Object image_small) { this.image_small = image_small; } public String getCdn_img() { return cdn_img; } public void setCdn_img(String cdn_img) { this.cdn_img = cdn_img; } public String getWidth() { return width; } public void setWidth(String width) { this.width = width; } public String getHeight() { return height; } public void setHeight(String height) { this.height = height; } public String getTag() { return tag; } public void setTag(String tag) { this.tag = tag; } public int getT() { return t; } public void setT(int t) { this.t = t; } public String getDing() { return ding; } public void setDing(String ding) { this.ding = ding; } public String getFavourite() { return favourite; } public void setFavourite(String favourite) { this.favourite = favourite; } public Object getTop_cmt() { return top_cmt; } public void setTop_cmt(Object top_cmt) { this.top_cmt = top_cmt; } public Object getThemes() { return themes; } public void setThemes(Object themes) { this.themes = themes; } } } package com.example.day1001homework; public class JavaBean { /** * code : 200 * msg : 成功! * data : {"appId":"com.github.wlsj","appkey":"bee4c4f201553653d4c288a52cd86b11"} */ private int code; private String msg; private DataBean data; public int getCode() { return code; } public void setCode(int code) { this.code = code; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public DataBean getData() { return data; } public void setData(DataBean data) { this.data = data; } public static class DataBean { /** * appId : com.github.wlsj * appkey : bee4c4f201553653d4c288a52cd86b11 */ private String appId; private String appkey; public String getAppId() { return appId; } public void setAppId(String appId) { this.appId = appId; } public String getAppkey() { return appkey; } public void setAppkey(String appkey) { this.appkey = appkey; } } }

Okhttp封装

package com.example.day1001homework; import android.os.Handler; import com.example.day1001homework.listener.MyListener; import com.example.day1001homework.listener.MyProgressListener; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; import okhttp3.Call; import okhttp3.Callback; import okhttp3.FormBody; import okhttp3.MediaType; import okhttp3.MultipartBody; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; public class MyHttpUtils { private static OkHttpClient client ; private static Handler handler = new Handler(); //单例模式 private MyHttpUtils() { client = new OkHttpClient.Builder() .connectTimeout(20, TimeUnit.SECONDS) .connectTimeout(20,TimeUnit.SECONDS) .build(); } private static MyHttpUtils myHttpUtils = null; public static MyHttpUtils getInstance(){ if (myHttpUtils == null){ synchronized (Object.class){ if (myHttpUtils == null){ myHttpUtils = new MyHttpUtils(); } } } return myHttpUtils; } //get public static void doget(String url, final MyListener myListener){ Request request = new Request.Builder() .get() .url(url) .build(); client.newCall(request).enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { final String message = e.getMessage(); handler.post(new Runnable() { @Override public void run() { myListener.onError(message); } }); } @Override public void onResponse(Call call, Response response) throws IOException { final String string = response.body().string(); handler.post(new Runnable() { @Override public void run() { myListener.onOk(string); } }); } }); } //post请求 public static void onpost(String url, HashMap<String,String> map, final MyListener myListener){ FormBody.Builder builder = new FormBody.Builder(); Set<Map.Entry<String, String>> entries = map.entrySet(); for (Map.Entry<String, String> entry : entries) { builder.add(entry.getKey(),entry.getValue()); } Request request = new Request.Builder() .url(url) .post(builder.build()) .build(); client.newCall(request).enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { final String message = e.getMessage(); handler.post(new Runnable() { @Override public void run() { myListener.onError(message); } }); } @Override public void onResponse(Call call, Response response) throws IOException { final String string = response.body().string(); handler.post(new Runnable() { @Override public void run() { myListener.onOk(string); } }); } }); } //upload public static void upload(String url, final String path,String servername,String type, final MyListener myListener){ RequestBody requestBody = RequestBody.create(MediaType.parse(type), new File(path)); MultipartBody build = new MultipartBody.Builder() .addFormDataPart("file",servername,requestBody) .setType(MultipartBody.FORM) .build(); Request request = new Request.Builder() .url(url) .post(build) .build(); client.newCall(request).enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { final String message = e.getMessage(); handler.post(new Runnable() { @Override public void run() { myListener.onError(message); } }); } @Override public void onResponse(Call call, Response response) throws IOException { handler.post(new Runnable() { @Override public void run() { myListener.onOk("上传成功"); } }); } }); } //download public static void dowmload(String url, final String path, final MyProgressListener myProgressListener){ Request request = new Request.Builder() .get() .url(url) .build(); client.newCall(request).enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { final String message = e.getMessage(); handler.post(new Runnable() { @Override public void run() { myProgressListener.onError(message); } }); } @Override public void onResponse(Call call, Response response) throws IOException { long length = response.body().contentLength(); InputStream inputStream = response.body().byteStream(); FileOutputStream fileOutputStream = new FileOutputStream(path); int len = 0; int count = 0; byte[] bytes = new byte[1024]; while ((len = inputStream.read(bytes))!=-1){ fileOutputStream.write(bytes,0,len); count += len; final int progress = (int) (count*100/length); handler.post(new Runnable() { @Override public void run() { myProgressListener.setProgress(progress); } }); } handler.post(new Runnable() { @Override public void run() { myProgressListener.finish(); } }); } }); } }

适配器

package com.example.day1001homework; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; import java.util.List; public class MyAdapter extends BaseAdapter { private List<Douyin.DataBean> list; private Context context; private LayoutInflater layoutInflater; public MyAdapter(List<Douyin.DataBean> list, Context context) { this.list = list; this.context = context; layoutInflater = LayoutInflater.from(context); } @Override public int getCount() { return list.size(); } @Override public Object getItem(int position) { return list.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; if (convertView == null){ holder = new ViewHolder(); convertView = layoutInflater.inflate(R.layout.layout_item,null); holder.tv = convertView.findViewById(R.id.tv); convertView.setTag(holder); }else { holder = (ViewHolder) convertView.getTag(); } holder.tv .setText(list.get(position).getText()); return convertView; } class ViewHolder{ TextView tv; } }

Main

package com.example.day1001homework; import android.Manifest; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import com.example.day1001homework.listener.MyListener; import com.google.gson.Gson; import java.util.HashMap; public class MainActivity extends AppCompatActivity { private EditText name; private EditText pwd; private Button login; private Button register; private String get_url = "https://www.apiopen.top/createUserKey?appId=com.github.wlsj&passwd=123456"; private String post_url="https://www.apiopen.top/login"; private String appkey; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); name = (EditText) findViewById(R.id.name); pwd = (EditText) findViewById(R.id.pwd); login = (Button) findViewById(R.id.login); register = (Button) findViewById(R.id.register); requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.READ_EXTERNAL_STORAGE},100); register.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, Main2Activity.class); startActivity(intent); } }); MyHttpUtils.getInstance().doget(get_url, new MyListener() { @Override public void onOk(String ok) { JavaBean javaBean = new Gson().fromJson(ok, JavaBean.class); JavaBean.DataBean data = javaBean.getData(); appkey = data.getAppkey(); } @Override public void onError(String message) { } }); https://www.apiopen.top/login?key=00d91e8e0cca2b76f515926a36db68f5&phone=13594347817&passwd=123456 login.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String s = name.getText().toString(); String s1 = pwd.getText().toString(); HashMap<String, String> map = new HashMap<>(); map.put("key",appkey); map.put("phone",s); map.put("passwd",s1); MyHttpUtils.getInstance().onpost(post_url, map, new MyListener() { @Override public void onOk(String ok) { finish(); Intent intent = new Intent(MainActivity.this, Main3Activity.class); startActivity(intent); Toast.makeText(MainActivity.this, "登录成功", Toast.LENGTH_SHORT).show(); } @Override public void onError(String message) { } }); } }); } }

Main2

package com.example.day1001homework; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import com.example.day1001homework.listener.MyListener; import com.google.gson.Gson; import java.util.HashMap; public class Main2Activity extends AppCompatActivity { private EditText name; private EditText pwd; private Button register; private String appkey; private String get_url = "https://www.apiopen.top/createUserKey?appId=com.github.wlsj&passwd=123456"; private String post_url="https://www.apiopen.top/createUser"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); name = (EditText) findViewById(R.id.name); pwd = (EditText) findViewById(R.id.pwd); register = (Button) findViewById(R.id.register); MyHttpUtils.getInstance().doget(get_url, new MyListener() { @Override public void onOk(String ok) { JavaBean javaBean = new Gson().fromJson(ok, JavaBean.class); JavaBean.DataBean data = javaBean.getData(); appkey = data.getAppkey(); Toast.makeText(Main2Activity.this, ""+appkey, Toast.LENGTH_SHORT).show(); } @Override public void onError(String message) { } }); register.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String s = name.getText().toString(); String s1 = pwd.getText().toString(); HashMap<String, String> map = new HashMap<>(); map.put("key",appkey); map.put("phone",s); map.put("passwd",s1); MyHttpUtils.getInstance().onpost(post_url, map, new MyListener() { @Override public void onOk(String ok) { finish(); Toast.makeText(Main2Activity.this, "注册成功", Toast.LENGTH_SHORT).show(); } @Override public void onError(String message) { Toast.makeText(Main2Activity.this, "注册失败", Toast.LENGTH_SHORT).show(); } }); } }); } }

Main3

package com.example.day1001homework; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ListView; import android.widget.Toast; import com.example.day1001homework.listener.MyListener; import com.example.day1001homework.listener.MyProgressListener; import com.google.gson.Gson; import java.io.File; import java.util.ArrayList; import java.util.List; public class Main3Activity extends AppCompatActivity { private List<Douyin.DataBean> list = new ArrayList<>(); private String get_url="https://www.apiopen.top/satinApi?type=1&page=2"; private String upload_url="http://169.254.66.222/hfs/"; private MyAdapter myAdapter; private ListView lv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main3); lv = (ListView) findViewById(R.id.lv); MyHttpUtils.getInstance().doget(get_url, new MyListener() { @Override public void onOk(String ok) { Douyin douyin = new Gson().fromJson(ok, Douyin.class); List<Douyin.DataBean> data = douyin.getData(); list.addAll(data); myAdapter = new MyAdapter(list,Main3Activity.this); lv.setAdapter(myAdapter); } @Override public void onError(String message) { Toast.makeText(Main3Activity.this, "请求失败", Toast.LENGTH_SHORT).show(); } }); //短点击 lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String videouri = list.get(position).getVideouri(); if (!videouri.equals("")){ MyHttpUtils.getInstance().dowmload(videouri, "/storage/emulated/0/Movies/DouMusic"+position+".mp4", new MyProgressListener() { @Override public void setProgress(int s) { } @Override public void finish() { Toast.makeText(Main3Activity.this, "下载成功", Toast.LENGTH_SHORT).show(); } @Override public void onError(String s) { Toast.makeText(Main3Activity.this, "没有请求到数据", Toast.LENGTH_SHORT).show(); } }); }else { Toast.makeText(Main3Activity.this, "没有地址", Toast.LENGTH_SHORT).show(); } } }); //长点击 lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { String upload_path="/storage/emulated/0/Movies/DouMusic" + position + ".mp4"; File file = new File("/storage/emulated/0/Movies/DouMusic" + position + ".mp4"); if (file.exists()){ MyHttpUtils.getInstance().upload(upload_url, upload_path, "DouMusic" + position+".mp4", "media/mp4", new MyListener() { @Override public void onOk(String ok) { Toast.makeText(Main3Activity.this, "上传成功", Toast.LENGTH_SHORT).show(); } @Override public void onError(String message) { Toast.makeText(Main3Activity.this, "上传失败", Toast.LENGTH_SHORT).show(); } }); }else{ Toast.makeText(Main3Activity.this, "不存在", Toast.LENGTH_SHORT).show(); } return true; } }); } }
最新回复(0)