Skip to content

Commit

Permalink
hzuapps#6 hzuapps#14 第六次实验
Browse files Browse the repository at this point in the history
  • Loading branch information
zaitao committed May 26, 2018
1 parent ce3afcc commit 65decd4
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 18 deletions.
Binary file added soft1614080902138/shiyan61.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 soft1614080902138/shiyan62.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 11 additions & 4 deletions soft1614080902138/网易云音乐/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.hzuapps.androidlabs.Soft1614080902138">
package="com.example.user.myapplication">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:allowBackup="true"
Expand All @@ -9,14 +16,14 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Soft1614080902138Activity3">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Soft1614080902138Activity5"></activity>
<activity android:name=".Main2Activity" />
</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,13 +1,91 @@
package edu.hzuapps.androidlabs.Soft1614080902138;
package edu.hzuapps.android.Soft1614080902138;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
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.Environment;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

public class Main2Activity extends AppCompatActivity {

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);
}
};
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
//初始化组件
editText=(EditText) findViewById(R.id.imagepath);
button=(Button) findViewById(R.id.upload);
imageView=(ImageView) findViewById(R.id.imageView);

//给下载按钮添加一个监听
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();
}
};
};

}

Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@
tools:context=".Main2Activity">

<ImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_width="276dp"
android:layout_height="125dp"
android:layout_marginBottom="8dp"

android:layout_marginTop="8dp"
android:src="@mipmap/erke"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.105"
tools:layout_editor_absoluteX="0dp" />
app:layout_constraintVertical_bias="0.132"
tools:layout_editor_absoluteX="54dp" />

<SeekBar
android:id="@+id/seekBar"
Expand All @@ -28,7 +27,7 @@
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.957"
app:layout_constraintVertical_bias="0.812"
tools:layout_editor_absoluteX="51dp" />

<Button
Expand All @@ -44,10 +43,10 @@
android:text="播放/暂停"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.464"
app:layout_constraintHorizontal_bias="0.467"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.852" />
app:layout_constraintVertical_bias="0.682" />

<Button
android:id="@+id/button2"
Expand All @@ -62,10 +61,10 @@
android:text="下一首"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.928"
app:layout_constraintHorizontal_bias="0.921"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.852" />
app:layout_constraintVertical_bias="0.682" />

<Button
android:id="@+id/button3"
Expand All @@ -83,7 +82,7 @@
app:layout_constraintHorizontal_bias="0.028"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.852" />
app:layout_constraintVertical_bias="0.682" />

<TextView
android:id="@+id/textView"
Expand All @@ -99,8 +98,36 @@
android:text="带着音乐去旅行"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.434" />

<Button
android:id="@+id/upload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="80dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:text="更换歌曲封面"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.457"
app:layout_constraintStart_toStartOf="parent" />

<EditText
android:id="@+id/imagepath"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.982"
tools:layout_editor_absoluteX="0dp" />


</android.support.constraint.ConstraintLayout>

0 comments on commit 65decd4

Please sign in to comment.