Skip to content

Commit

Permalink
Merge pull request #2560 from BoyJDG/master
Browse files Browse the repository at this point in the history
#891 实验4,5,6
  • Loading branch information
zengsn authored Jun 2, 2018
2 parents 0a6309e + d5a5268 commit a5824a9
Show file tree
Hide file tree
Showing 21 changed files with 432 additions and 23 deletions.
33 changes: 33 additions & 0 deletions soft1614080902124/report4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
实验四

一.实验目的

1.根据选题要求设计界面布局及控件使用;

2.布局xml及界面控制操作代码提交并截图;

3.将应用运行结果截图。

二.实验要求

1.使用一种布局方式,设计所选题目的界面:

2.通过控件ID获取界面对象,执行相关操作:

3.实现界面控件的事件处理,例如点击按钮:

三.实验步骤

1.布局选用LinearLayout方式;

2.选用ImageView来显示图片

3.选用Button控件,显示确定调节的按钮;

四.实验截图
![image](https://github.com/BoyJDG/android-labs-2018/blob/master/soft1614080902124/%E5%AE%9E%E9%AA%8C4%20(1).png)

![image](https://github.com/BoyJDG/android-labs-2018/blob/master/soft1614080902124/%E5%AE%9E%E9%AA%8C4(2).png)
五.实验体会

这次实验使用了LinearLayout布局和ImageView组件以及button控件来完成界面的设计
23 changes: 23 additions & 0 deletions soft1614080902124/report5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
第五次实验
1.实验目标
1.掌握在Android App中存储数据。

2.实验内容
1.将应用产生的数据存储到数据库中;
2.使用UML类图描述表结构;
3.将应用运行结果截图。

3.实验步骤
1.在res文件夹中添加一个raw文件,将data.txt文本数据放入
2.利用android系统的Resources类,通过类的openRawResource方法,利用InputStream读取文本数据
3.再利用Scanner读取文件
4.利用ArrayList存储读取的数据
5.在利用ArrayAdapter将数据传送给listView中展现出来

4.实验结果
![image](https://github.com/BoyJDG/android-labs-2018/blob/master/soft1614080902124/shiyan5.jpg)

![image](https://github.com/BoyJDG/android-labs-2018/blob/master/soft1614080902124/shiyan5%20(2).jpg)

5.实验体会
本次实验经过百度,查看别人的代码写出来。大部分功能还未实现在努力实现中。
29 changes: 29 additions & 0 deletions soft1614080902124/report6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
第六次实验 一.实验目的

1.掌握Android网络访问方法;
2.理解XML和JSON表示数据的方法。

二.实验内容

1.通过url下载一张照片
2.将照片显示到ImagView上
3.实验截图

三.实验步骤

1.通过新建一个新线程,加载图片信息
2.将加载的图片信息发送到消息队列中
3.注意点:网络图片通过转化inputStream流,在转化为bitMap,最后将bitMap传给imageView
4.在消息队列中进行UI修改 5.运行代码截图并用git上交相关文件。

四.实验截图
![image](https://github.com/BoyJDG/android-labs-2018/blob/master/soft1614080902124/shiyan6(1).png)

![image](https://github.com/BoyJDG/android-labs-2018/blob/master/soft1614080902124/shiyan6%20(2).jpg)

![image](https://github.com/BoyJDG/android-labs-2018/blob/master/soft1614080902124/shiyan6%20(3).jpg)

![image](https://github.com/BoyJDG/android-labs-2018/blob/master/soft1614080902124/shiyan6.jpg)
五.实验体会

通过这次实验了解了Android网络访问方法,获取权限,android的线程与java是一样的。
Binary file added soft1614080902124/shiyan5 (2).jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added soft1614080902124/shiyan5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added soft1614080902124/shiyan6 (2).jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added soft1614080902124/shiyan6 (3).jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added soft1614080902124/shiyan6(1).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added soft1614080902124/shiyan6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package edu.hzuapps.androidlabs.soft1614080902124;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class Activity2 extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package edu.hzuapps.androidlabs.soft1614080902124;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class Main2Activity extends AppCompatActivity {
private Handler handler=new Handler();
ImageView imageView;
private String url = "http://a.hiphotos.baidu.com/image/h%3D300/sign=13dc7fee3512b31bd86ccb29b6193674/730e0cf3d7ca7bcb6a172486b2096b63f624a82f.jpg";
private String url2="http://d.hiphotos.baidu.com/image/h%3D300/sign=38d65ae4c680653864eaa213a7dca115/8cb1cb13495409237691bcd49e58d109b2de49a4.jpg";
Bitmap bmImg;

//在消息队列中实现对控件的更改
@SuppressLint("HandlerLeak")
private Handler handle = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case 0:
System.out.println("111");
Bitmap bmp=(Bitmap)msg.obj;
imageView.setImageBitmap(bmp);

break;
}
};
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
imageView = (ImageView) findViewById(R.id.mypic);
Button btn=(Button) findViewById(R.id.pre);
btn.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
//新建线程加载图片信息,发送到消息队列中
new Thread(new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub
Bitmap bmp = getURLimage(url);
Message msg = new Message();
msg.what = 0;
msg.obj = bmp;
System.out.println("000");
handle.sendMessage(msg);
}
}).start();
}
});

Button btn1=(Button) findViewById(R.id.next);
btn1.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
//新建线程加载图片信息,发送到消息队列中
new Thread(new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub
Bitmap bmp = getURLimage(url2);
Message msg = new Message();
msg.what = 0;
msg.obj = bmp;
System.out.println("000");
handle.sendMessage(msg);
}
}).start();
}
});
}

//加载图片
public Bitmap getURLimage(String url) {
Bitmap bmp = null;
try {
URL myurl = new URL(url);
// 获得连接
HttpURLConnection conn = (HttpURLConnection) myurl.openConnection();
conn.setConnectTimeout(6000);//设置超时
conn.setDoInput(true);
conn.setUseCaches(false);//不缓存
conn.connect();
InputStream is = conn.getInputStream();//获得图片的数据流
bmp = BitmapFactory.decodeStream(is);
is.close();
} catch (Exception e) {
e.printStackTrace();
}
return bmp;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package edu.hzuapps.androidlabs.soft1614080902124;

import android.content.res.Resources;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Scanner;

public class Main3Activity extends AppCompatActivity {
public ArrayList<String> data = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);

load();
ListView listView=(ListView) findViewById(R.id.listview);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(Main3Activity.this,android.R.layout.simple_list_item_1,data);
listView.setAdapter(adapter);
}

public void load() {
Resources resources = this.getResources();
InputStream StdInfo = null;
try {
// 用InputStream方式读取保存在 /res/raw 下的原始文件
StdInfo = resources.openRawResource(R.raw.data);
if (StdInfo.available() == 0)
return;
if (StdInfo != null) {
//用utf-8读取文件
Scanner input = new Scanner(StdInfo, "GBK");
while (input.hasNext()) {
String Name = input.next();
data.add(Name);
}
}

} catch (Exception e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package edu.hzuapps.androidlabs.soft1614080902124;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.my_in);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
startActivity(intent);
}
});

Button button1 = (Button) findViewById(R.id.two);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, Main3Activity.class);
startActivity(intent);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,19 @@
import android.view.View;
import android.widget.Button;


public class Soft1614080902124Activity extends AppCompatActivity {

Button button = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_soft1614080902124);

button = (Button)findViewById(R.id.button1);
Button button=(Button)findViewById(R.id.my_in);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(Soft1614080902124Activity.this,Soft1614080902124Activity_2.class);
public void onClick(View view) {
Intent intent = new Intent(Soft1614080902124Activity.this,Activity2.class);
startActivity(intent);
}
});


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="edu.hzuapps.androidlabs.soft1614080902124.Activity2">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/mypic"
android:background="@drawable/pic2"/>

<Button
android:id="@+id/pre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="上一张"
tools:layout_editor_absoluteX="41dp"
tools:layout_editor_absoluteY="411dp" />

<Button
android:id="@+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下一张"
tools:layout_editor_absoluteX="245dp"
tools:layout_editor_absoluteY="411dp" />

</android.support.constraint.ConstraintLayout>
Loading

0 comments on commit a5824a9

Please sign in to comment.