-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2636 from quanquanCc/master
- Loading branch information
Showing
10 changed files
with
244 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,4 +54,5 @@ public boolean onOptionsItemSelected(MenuItem item) { | |
|
||
return super.onOptionsItemSelected(item); | ||
} | ||
|
||
} |
80 changes: 78 additions & 2 deletions
80
...14080901214/app/src/main/java/edu/hzuapps/androidlabs/com1614080901214/ThreeActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,89 @@ | ||
package edu.hzuapps.androidlabs.com1614080901214; | ||
|
||
import android.support.v7.app.AppCompatActivity; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.os.Bundle; | ||
import android.os.Environment; | ||
import android.os.Handler; | ||
import android.os.Message; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
import android.view.View.OnClickListener; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.ImageView; | ||
|
||
public class ThreeActivity extends AppCompatActivity { | ||
|
||
@Override | ||
private EditText editText; | ||
private Button button; | ||
private ImageView imageView; | ||
|
||
private Bitmap bitmap; | ||
|
||
Handler handler=new Handler(){ | ||
public void handleMessage(Message msg) { | ||
if(msg.what==111){ | ||
imageView.setImageBitmap(bitmap); | ||
} | ||
}; | ||
}; | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_three); | ||
|
||
|
||
editText=(EditText) findViewById(R.id.editText2); | ||
button=(Button) findViewById(R.id.button3); | ||
imageView=(ImageView) findViewById(R.id.imageView5); | ||
|
||
|
||
button.setOnClickListener(new OnClickListener() { | ||
public void onClick(View arg0) { | ||
new Thread(t).start(); | ||
} | ||
}); | ||
} | ||
|
||
|
||
Thread t=new Thread(){ | ||
public void run() { | ||
|
||
String iPath=editText.getText().toString(); | ||
try { | ||
|
||
URL url=new URL(iPath); | ||
|
||
InputStream inputStream=url.openStream(); | ||
|
||
bitmap=BitmapFactory.decodeStream(inputStream); | ||
handler.sendEmptyMessage(111); | ||
inputStream.close(); | ||
|
||
|
||
inputStream=url.openStream(); | ||
File file=new File(Environment.getExternalStorageDirectory()+"/haha.gif"); | ||
FileOutputStream fileOutputStream=new FileOutputStream(file); | ||
int hasRead=0; | ||
while((hasRead=inputStream.read())!=-1){ | ||
fileOutputStream.write(hasRead); | ||
} | ||
fileOutputStream.close(); | ||
inputStream.close(); | ||
} catch (MalformedURLException e) { | ||
e.printStackTrace(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
}; | ||
}; | ||
} |
93 changes: 86 additions & 7 deletions
93
...614080901214/app/src/main/java/edu/hzuapps/androidlabs/com1614080901214/jumpActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,112 @@ | ||
package edu.hzuapps.androidlabs.com1614080901214; | ||
|
||
import android.content.Context; | ||
import android.content.ContextWrapper; | ||
import android.content.Intent; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.support.design.widget.FloatingActionButton; | ||
import android.support.design.widget.Snackbar; | ||
import android.os.Environment; | ||
import android.support.annotation.RequiresApi; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.Toolbar; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
import android.widget.Toolbar; | ||
|
||
import java.io.BufferedInputStream; | ||
import java.io.BufferedReader; | ||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.io.OutputStreamWriter; | ||
|
||
import edu.hzuapps.androidlabs.*; | ||
|
||
import static android.provider.Telephony.Mms.Part.FILENAME; | ||
|
||
|
||
public class jumpActivity extends AppCompatActivity { | ||
public static final String DIRECTORY = "demo"; | ||
public static final String FILENAME = "demo.txt"; | ||
|
||
public static final String TAG = jumpActivity.class.getSimpleName(); | ||
private Button button; | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_jump); | ||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
|
||
button=(Button)findViewById(R.id.button); | ||
button.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
Intent intent = new Intent(jumpActivity.this, ThreeActivity.class); | ||
startActivity(intent); | ||
String text = ((EditText) findViewById(R.id.editText)).getText().toString(); | ||
save(text); | ||
|
||
} | ||
|
||
|
||
}); | ||
((Button) findViewById(R.id.button2)).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
String text = ((EditText) findViewById(R.id.editText)).getText().toString(); | ||
read(); | ||
deleteFile(FILENAME); | ||
Intent intent = new Intent(jumpActivity.this, ThreeActivity.class); | ||
startActivity(intent); | ||
|
||
|
||
} | ||
} | ||
); | ||
} | ||
public void save(String text) { | ||
FileOutputStream out = null; | ||
BufferedWriter writer = null; | ||
try { | ||
out = openFileOutput("demo.txt", ContextWrapper.MODE_APPEND); | ||
writer = new BufferedWriter(new OutputStreamWriter(out)); | ||
writer.write(text); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} finally { | ||
try { | ||
if (writer != null) { | ||
writer.close(); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
Toast.makeText(jumpActivity.this, "已保存", Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
|
||
public void read() { | ||
String content = ""; | ||
try { | ||
FileInputStream fis = openFileInput("demo.txt"); | ||
byte[] buffer = new byte[fis.available()]; | ||
fis.read(buffer); | ||
content = new String(buffer); | ||
fis.close(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
Toast.makeText(jumpActivity.this, "查询结果:" + content, Toast.LENGTH_SHORT).show(); | ||
|
||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 31 additions & 9 deletions
40
Com1614080901214/app/src/main/res/layout/activity_three.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,38 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
<RelativeLayout 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=".ThreeActivity"> | ||
<TextView | ||
android:id="@+id/textview_01" | ||
android:orientation="vertical" | ||
android:background="@drawable/tupian"> | ||
|
||
<EditText | ||
android:id="@+id/editText2" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentTop="true" | ||
android:layout_centerHorizontal="true" | ||
android:ems="10" | ||
android:inputType="textPersonName" | ||
android:text="输入url" /> | ||
|
||
<Button | ||
android:id="@+id/button3" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:drawableTop="@drawable/jd" | ||
tools:layout_editor_absoluteX="0dp" | ||
tools:layout_editor_absoluteY="0dp" /> | ||
android:layout_alignParentTop="true" | ||
android:layout_centerHorizontal="true" | ||
android:layout_marginTop="87dp" | ||
android:text="下载图片" /> | ||
|
||
<ImageView | ||
android:id="@+id/imageView5" | ||
android:layout_width="328dp" | ||
android:layout_height="299dp" | ||
android:layout_alignParentBottom="true" | ||
android:layout_alignParentStart="true" | ||
android:layout_marginBottom="37dp" | ||
android:layout_marginStart="33dp" /> | ||
|
||
</RelativeLayout> | ||
|
||
</android.support.constraint.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
一、实验目的 | ||
掌握在Android App中存储数据; | ||
|
||
二、实验要求 | ||
1.根据选题要求使用文件存储 | ||
|
||
2.将应用产生的数据保存到文件存储中; | ||
|
||
3.说明使用的文件存储方式:内部 or 外部; | ||
|
||
4.将运行结果截图。 | ||
|
||
三、实验步骤 | ||
|
||
1.新增了两个类,一个用来实现新建歌单收藏功能,输入收藏单名,将输入的数据存储到文件中。另一个类用来从文件中读取收藏单名并显示出来。 | ||
|
||
2.新增了这两个类相应的页面布局。 | ||
|
||
四、实验结果 | ||
https://github.com/quanquanCc/android-labs-2018/blob/master/Com1614080901214/%E5%AE%9E%E9%AA%8C5%E6%88%AA%E5%9B%BE.png | ||
https://github.com/quanquanCc/android-labs-2018/blob/master/Com1614080901214/%E5%AE%9E%E9%AA%8C5%E6%88%AA%E5%9B%BE2.png | ||
|
||
五、实验体会 | ||
通过这次实验我掌握了如何在在Android App中存储数据,也掌握了将应用产生的数据保存到文件存储中,也加深了对布局设计的理解 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
第六次实验报告 | ||
Android网络编程 | ||
一、实验步骤 | ||
1.修改AndroidManifest,加入必要的连接网络的权限。 | ||
2.创建activity_tp.java,其功能为完成图片的下载。 | ||
3.创建activity_tp.xml文件,实现图片的下载和显示 | ||
二、实验结果截图 | ||
https://github.com/quanquanCc/android-labs-2018/blob/master/Com1614080901214/%E5%AE%9E%E9%AA%8C6%E6%88%AA%E5%9B%BE.jpg | ||
三、实验体会 | ||
通过本次实验,我认识到当设置连接超时,如果网络不好,Android系统在超过默认时间会收回资源中断操作.还有就是在对大文件的操作时,要将文件写到SDCard上面, | ||
不要直接写到手机内存上。 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.