forked from hzuapps/android-labs-2018
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0471a9d
commit a040e37
Showing
5 changed files
with
223 additions
and
48 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
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
73 changes: 73 additions & 0 deletions
73
...p/src/main/java/edu/hzuapps/androidlabs/soft1614080902117/Soft1614080902117Activity2.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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package edu.hzuapps.androidlabs.soft1614080902117; | ||
|
||
import android.app.Activity; | ||
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.view.View; | ||
import android.view.View.OnClickListener; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.ImageView; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
public class Soft1614080902117Activity2 extends Activity { | ||
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_soft16140809021172); | ||
editText=(EditText) findViewById(R.id.editweb); | ||
button=(Button) findViewById(R.id.button7); | ||
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()+"/DCIM/"); | ||
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(); | ||
} | ||
}; | ||
}; | ||
|
||
} |
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
82 changes: 82 additions & 0 deletions
82
soft1614080902117/app/src/main/layout/activity_soft16140809021172.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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?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=".Soft1614080902117Activity2"> | ||
|
||
<TextView | ||
android:id="@+id/textView8" | ||
android:layout_width="369dp" | ||
android:layout_height="53dp" | ||
android:layout_marginEnd="8dp" | ||
android:layout_marginLeft="8dp" | ||
android:layout_marginRight="8dp" | ||
android:layout_marginStart="8dp" | ||
android:background="@drawable/background1" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintHorizontal_bias="0.48" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<TextView | ||
android:id="@+id/textView12" | ||
android:layout_width="65dp" | ||
android:layout_height="22dp" | ||
android:layout_marginEnd="8dp" | ||
android:layout_marginLeft="8dp" | ||
android:layout_marginRight="8dp" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="16dp" | ||
android:text="网络下载" | ||
app:layout_constraintEnd_toEndOf="@+id/textView8" | ||
app:layout_constraintHorizontal_bias="0.501" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="@+id/textView8" /> | ||
|
||
<EditText | ||
android:id="@+id/editweb" | ||
android:layout_width="279dp" | ||
android:layout_height="wrap_content" | ||
|
||
android:layout_marginEnd="8dp" | ||
android:layout_marginLeft="8dp" | ||
android:layout_marginRight="8dp" | ||
android:layout_marginStart="8dp" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintHorizontal_bias="0.0" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/textView8" /> | ||
|
||
<Button | ||
android:id="@+id/button7" | ||
android:layout_width="68dp" | ||
android:layout_height="36dp" | ||
android:layout_marginEnd="8dp" | ||
android:layout_marginLeft="8dp" | ||
android:layout_marginRight="8dp" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="56dp" | ||
android:background="#dfd9d9" | ||
android:text="下载" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintHorizontal_bias="0.0" | ||
|
||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<ImageView | ||
android:id="@+id/imageView" | ||
android:layout_width="352dp" | ||
android:layout_height="408dp" | ||
android:layout_marginEnd="8dp" | ||
android:layout_marginLeft="8dp" | ||
android:layout_marginRight="8dp" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="100dp" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
|
||
</android.support.constraint.ConstraintLayout> |