From a040e378c11fb117afc77fe84833bdc919ed4376 Mon Sep 17 00:00:00 2001 From: 1614080902117 <1045704637@qq.com> Date: Sat, 26 May 2018 18:02:33 +0800 Subject: [PATCH] =?UTF-8?q?#6=20#881=20=E7=AC=AC=E5=85=AD=E6=AC=A1?= =?UTF-8?q?=E5=AE=9E=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/src/main/AndroidManifest.xml | 3 +- .../Soft1614080902117Activity.java | 19 ++-- .../Soft1614080902117Activity2.java | 73 ++++++++++++++ .../layout/activity_soft1614080902117.xml | 94 +++++++++++-------- .../layout/activity_soft16140809021172.xml | 82 ++++++++++++++++ 5 files changed, 223 insertions(+), 48 deletions(-) create mode 100644 soft1614080902117/app/src/main/java/edu/hzuapps/androidlabs/soft1614080902117/Soft1614080902117Activity2.java create mode 100644 soft1614080902117/app/src/main/layout/activity_soft16140809021172.xml 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 @@ - + - -