//修改代码之后的Log
04/07 20:56:44: Launching 'app' on Nexus 5 API 25.
$ adb shell am start -n "com.example.httptest4/com.example.httptest4.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 11994 on device 'emulator-5554'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/ample.httptest: Not late-enabling -Xcheck:jni (already on)
E/ample.httptest: Unknown bits set in runtime_flags: 0x8000
W/ample.httptest: Unexpected CPU variant for X86 using defaults: x86_64
D/libEGL: Emulator has host GPU support, qemu.gles is set to 1.
W/RenderThread: type=1400 audit(0.0:58): avc: denied { write } for name="property_service" dev="tmpfs" ino=7210 scontext=u:r:untrusted_app:s0:c134,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0 app=com.example.httptest4
W/libc: Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied)
D/libEGL: loaded /vendor/lib64/egl/libEGL_emulation.so
D/libEGL: loaded /vendor/lib64/egl/libGLESv1_CM_emulation.so
D/libEGL: loaded /vendor/lib64/egl/libGLESv2_emulation.so
W/ample.httptest: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
D/HostConnection: HostConnection::get() New Host Connection established 0x7cbca030c2c0, tid 12025
D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0
D/MainActivity: mData.size()-->0
mData.size()-->0
D/EGL_emulation: eglCreateContext: 0x7cbca030c4a0: maj 3 min 0 rcv 3
D/EGL_emulation: eglMakeCurrent: 0x7cbca030c4a0: ver 3 0 (tinfo 0x7cbca0363420)
W/Gralloc3: mapper 3.x is not supported
D/HostConnection: createUnique: call
D/HostConnection: HostConnection::get() New Host Connection established 0x7cbca030c680, tid 12025
D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0
D/eglCodecCommon: allocate: Ask for block of size 0x1000
allocate: ioctl allocate returned offset 0x3ffffa000 size 0x2000
D/EGL_emulation: eglMakeCurrent: 0x7cbca030c4a0: ver 3 0 (tinfo 0x7cbca0363420)
I/OpenGLRenderer: Davey! duration=864ms; Flags=1, IntendedVsync=12739851987586, Vsync=12739851987586, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=12739856290400, AnimationStart=12739856345700, PerformTraversalsStart=12739856390900, DrawStart=12740157226900, SyncQueued=12740160031200, SyncStart=12740168917900, IssueDrawCommandsStart=12740169080200, SwapBuffers=12740606290400, FrameCompleted=12740725062900, DequeueBufferDuration=272000, QueueBufferDuration=6296000,
I/Choreographer: Skipped 57 frames! The application may be doing too much work on its main thread.
I/OpenGLRenderer: Davey! duration=1051ms; Flags=0, IntendedVsync=12739949662374, Vsync=12740899662336, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=12740915532500, AnimationStart=12740915609900, PerformTraversalsStart=12740915887500, DrawStart=12740917161800, SyncQueued=12740917606500, SyncStart=12740918060000, IssueDrawCommandsStart=12740918165400, SwapBuffers=12740942113100, FrameCompleted=12741001279200, DequeueBufferDuration=80000, QueueBufferDuration=16263000,
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/MainActivity: null==[HTTP/1.1 200 ]
Content-Type==[application/json;charset=UTF-8]
D/MainActivity: Date==[Tue, 07 Apr 2020 12:56:49 GMT]
Transfer-Encoding==[chunked]
X-Android-Received-Millis==[1586264206638]
X-Android-Response-Source==[NETWORK 200]
X-Android-Selected-Protocol==[http/1.1]
X-Android-Sent-Millis==[1586264206618]
D/MainActivity: json-->{"success":true,"code":10000,"message":"获取成功","data":[{"id":"1247508627950993408","title":"Android加载大图片,解决OOM问题","viewCount":322,"commentCount":82,"publishTime":"2020-04-07T12:56:49.150+0000","userName":"程序员拉大锯","cover":"/imgs/2.png"},{"id":"1247508627950993409","title":"Volley/Xutils对大图片处理算法源码分析","viewCount":96,"commentCount":18,"publishTime":"2020-04-07T12:56:49.150+0000","userName":"程序员拉大锯","cover":"/imgs/12.png"},{"id":"1247508627950993410","title":"Android开发网络安全配置","viewCount":270,"commentCount":70,"publishTime":"2020-04-07T12:56:49.150+0000","userName":"程序员拉大锯","cover":"/imgs/8.png"},{"id":"1247508627950993411","title":"Android开发网络编程,请求图片","viewCount":182,"commentCount":63,"publishTime":"2020-04-07T12:56:49.150+0000","userName":"程序员拉大锯","cover":"/imgs/12.png"},{"id":"1247508627950993412","title":"Intent页面跳转工具类分享","viewCount":246,"commentCount":29,"publishTime":"2020-04-07T12:56:49.150+0000","userName":"程序员拉大锯","cover":"/imgs/7.png"},{"id":"1247508627950993413","title":"阳光沙滩商城的API文档","viewCount":72,"commentCount":90,"publishTime":"2020-04-07T12:56:49.150+0000","userName":"程序员拉大锯","cover":"/imgs/5.png"},{"id":"1247508627950993414","title":"Android课程视频打包下载","viewCount":250,"commentCount":41,"publishTime":"2020-04-07T12:56:49.150+0000","userName":"程序员拉大锯","cover":"/imgs/16.png"},{"id":"1247508627950993415","title":"非常轻量级的gif录制软件","viewCount":160,"commentCount":107,"publishTime":"2020-04-07T12:56:49.150+0000","userName":"程序员拉大锯","cover":"/imgs/2.png"},{"id":"1247508627950993416","title":"Fiddler抓包工具,墙裂推荐,功能很强大很全的一个工具","viewCount":104,"commentCount":90,"publishTime":"2020-04-07T12:56:49.150+0000","userName":"程序员拉大锯","cover":"/imgs/2.png"},{"id":"1247508627950993417","title":"AndroidStudio奇淫技巧-代码管理","viewCount":325,"commentCount":106,"publishTime":"2020-04-07T12:56:49.150+0000","userName":"程序员拉大锯","cover":"/imgs/4.png"},{"id":"1247508627950993418","title":"OC和Swift混编","viewCount":231,"commentCount":89,"publishTime":"2020-04-07T12:56:49.150+0000","userName":"程序员拉大锯","cover":"/imgs/0.png"},{"id":"1247508627950993419","title":"最新的Android studio是不是没有Android Device Monitor","viewCount":61,"commentCount":74,"publishTime":"2020-04-07T12:56:49.150+0000","userName":"程序员拉大锯","cover":"/imgs/12.png"}]}
D/MainActivity: getTextItem-->[domain.GetTextItem$DataBean@fd98812, domain.GetTextItem$DataBean@7009be3, domain.GetTextItem$DataBean@f53b9e0, domain.GetTextItem$DataBean@c889499, domain.GetTextItem$DataBean@ac4135e, domain.GetTextItem$DataBean@c17133f, domain.GetTextItem$DataBean@f6a940c, domain.GetTextItem$DataBean@6c4e155, domain.GetTextItem$DataBean@b3a076a, domain.GetTextItem$DataBean@bf3a45b, domain.GetTextItem$DataBean@c32e4f8, domain.GetTextItem$DataBean@33f3dd1]
D/MainActivity: mData.size()-->12
I/chatty: uid=10134(com.example.httptest4) identical 1 line
D/MainActivity: mData.size()-->12
D/MainActivity: Android加载大图片,解决OOM问题
//MainActivity
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
private GetResultListAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
RecyclerView recyclerView = this.findViewById(R.id.result_list);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
mAdapter = new GetResultListAdapter();
recyclerView.setAdapter(mAdapter);
}
public void loadJson(View view){
new Thread(new Runnable() {
@Override
public void run() {
try{
URL url = new URL( "http://192.168.3.8:9102/get/text");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(10000);
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept-Language","zh-CN,zh;q=0.9");
// connection.setRequestProperty("Accept-Encoding","gzip,deflate");
connection.setRequestProperty("Accept","*/*");
connection.connect();
int responseCode = connection.getResponseCode();
if(responseCode == 200){
Map<String, List<String>> headerFields = connection.getHeaderFields();
Set<Map.Entry<String,List<String>>> entries = headerFields.entrySet();
for(Map.Entry<String,List<String>> entry : entries){
Log.d(TAG,entry.getKey()+"=="+entry.getValue());
}
InputStream inputStream = connection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String json = bufferedReader.readLine();
Log.d(TAG,"json-->"+json);
Gson gson = new Gson();
GetTextItem getTextItem = gson.fromJson(json,GetTextItem.class);
updateUI(getTextItem);
}
}catch (Exception e){
e.printStackTrace();
}
}
}).start();
}
private void updateUI(final GetTextItem getTextItem) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mAdapter.setData(getTextItem);
}
});
}
}
//GetResultListAdapter
public class GetResultListAdapter extends RecyclerView.Adapter<GetResultListAdapter.InnerHolder> {
private List<GetTextItem.DataBean> mData = new ArrayList<>();
@NonNull
@Override
public InnerHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_get_text,parent,false);
return new InnerHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull InnerHolder holder, int position) {
View itemView = holder.itemView;
TextView tileTv = itemView.findViewById(R.id.item_title);
GetTextItem.DataBean dataBean = mData.get(position);
tileTv.setText(dataBean.getTitle());
Log.d("MainActivity",tileTv.getText().toString());
}
@Override
public int getItemCount() {
return mData.size();
}
public void setData(GetTextItem getTextItem) {
mData.clear();
mData.addAll(getTextItem.getData());
notifyDataSetChanged();
}
public class InnerHolder extends RecyclerView.ViewHolder {
public InnerHolder(@NonNull View itemView) {
super(itemView);
}
}
}
//GetTextItem
public class GetTextItem {
/**
* success : true
* code : 10000
* message : 获取成功
* data : [{"id":"1202177685208530944","title":"Android加载大图片,解决OOM问题","viewCount":104,"commentCount":50,"publishTime":"2019-12-04T10:47:50.192+0000","userName":"程序员拉大锯","cover":"/imgs/14.png"},{"id":"1202177685208530945","title":"Volley/Xutils对大图片处理算法源码分析","viewCount":269,"commentCount":24,"publishTime":"2019-12-04T10:47:50.192+0000","userName":"程序员拉大锯","cover":"/imgs/11.png"}]
*/
private boolean success;
private int code;
private String message;
private List<DataBean> data;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public List<DataBean> getData() {
return data;
}
public void setData(List<DataBean> data) {
this.data = data;
}
public static class DataBean {
/**
* id : 1202177685208530944
* title : Android加载大图片,解决OOM问题
* viewCount : 104
* commentCount : 50
* publishTime : 2019-12-04T10:47:50.192+0000
* userName : 程序员拉大锯
* cover : /imgs/14.png
*/
private String id;
private String title;
private int viewCount;
private int commentCount;
private String publishTime;
private String userName;
private String cover;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getViewCount() {
return viewCount;
}
public void setViewCount(int viewCount) {
this.viewCount = viewCount;
}
public int getCommentCount() {
return commentCount;
}
public void setCommentCount(int commentCount) {
this.commentCount = commentCount;
}
public String getPublishTime() {
return publishTime;
}
public void setPublishTime(String publishTime) {
this.publishTime = publishTime;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getCover() {
return cover;
}
public void setCover(String cover) {
this.cover = cover;
}
}
}
//item_get_text.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:background="#99ff00"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="10dp">
<TextView
android:id="@+id/item_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="我是标题"
android:textSize="18sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="作者名"
android:layout_margin="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="查看数"
android:layout_margin="10dp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
//activicy_main.xml
<?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=".MainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="loadJson"
android:textAllCaps="false"
android:text="load data" />
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/result_list"/>
</LinearLayout>
您的每一个用心回答,都会让这个世界变得更美好一些!