diff --git a/soft1614080902117/app/src/main/AndroidManifest.xml b/soft1614080902117/app/src/main/AndroidManifest.xml index bc62d3619..dd9d3f598 100644 --- a/soft1614080902117/app/src/main/AndroidManifest.xml +++ b/soft1614080902117/app/src/main/AndroidManifest.xml @@ -16,7 +16,8 @@ - + + \ No newline at end of file diff --git a/soft1614080902117/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902117/Soft1614080902117Activity.java b/soft1614080902117/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902117/Soft1614080902117Activity.java index 70af752fc..9f4289af7 100644 --- a/soft1614080902117/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902117/Soft1614080902117Activity.java +++ b/soft1614080902117/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902117/Soft1614080902117Activity.java @@ -1,21 +1,16 @@ package edu.hzuapps.androidlabs.soft1614080902117; +import android.app.Activity; import android.content.Intent; - import android.os.Bundle; - import android.view.View; - +import android.widget.ArrayAdapter; import android.widget.Button; -import android.app.Activity; - +import android.widget.ListView; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; -import java.lang.String; -import android.widget.ArrayAdapter; -import android.widget.ListView; public class Soft1614080902117Activity extends Activity { String[] adapterData; @@ -39,6 +34,14 @@ public void onClick(View v) { thisActivity.startActivity(intent); } }); + Button btnDlow = (Button)findViewById(R.id.button8); + btnDlow.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(thisActivity,Soft1614080902117Activity2.class); + thisActivity.startActivity(intent); + } + }); } public String load(){ //读取文件 FileInputStream in =null; diff --git a/soft1614080902117/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902117/Soft1614080902117Activity2.java b/soft1614080902117/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902117/Soft1614080902117Activity2.java new file mode 100644 index 000000000..ac507899b --- /dev/null +++ b/soft1614080902117/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902117/Soft1614080902117Activity2.java @@ -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(); + } + }; + }; + +} \ No newline at end of file diff --git a/soft1614080902117/app/src/main/layout/activity_soft1614080902117.xml b/soft1614080902117/app/src/main/layout/activity_soft1614080902117.xml index 181ce8099..cb1251dec 100644 --- a/soft1614080902117/app/src/main/layout/activity_soft1614080902117.xml +++ b/soft1614080902117/app/src/main/layout/activity_soft1614080902117.xml @@ -33,20 +33,6 @@ - + - -