diff --git a/soft1614080902434/2.app/2.app/src/main/AndroidManifest.xml b/soft1614080902434/2.app/2.app/src/main/AndroidManifest.xml index cf8b69516..cf0d2cfd1 100644 --- a/soft1614080902434/2.app/2.app/src/main/AndroidManifest.xml +++ b/soft1614080902434/2.app/2.app/src/main/AndroidManifest.xml @@ -1,6 +1,12 @@ + package="soft1614080902434.androidlabs.hzuapps.edu.soft1614080902434"> + + + + + + - + + + \ No newline at end of file diff --git a/soft1614080902434/2.app/2.app/src/main/java/edu/hzupps/androidlabs/soft1614080902434/Second_Activity.java b/soft1614080902434/2.app/2.app/src/main/java/edu/hzupps/androidlabs/soft1614080902434/Second_Activity.java index ab0e6e7e4..e9f6f3c8d 100644 --- a/soft1614080902434/2.app/2.app/src/main/java/edu/hzupps/androidlabs/soft1614080902434/Second_Activity.java +++ b/soft1614080902434/2.app/2.app/src/main/java/edu/hzupps/androidlabs/soft1614080902434/Second_Activity.java @@ -1,44 +1,118 @@ package soft1614080902434.androidlabs.hzuapps.edu.soft1614080902434; +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Environment; +import android.os.Handler; +import android.os.Message; +import android.support.annotation.RequiresPermission; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ImageView; import android.widget.TextView; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStreamWriter; +import java.net.MalformedURLException; +import java.net.URL; + public class Second_Activity extends AppCompatActivity implements View.OnClickListener { - TextView t[] = new TextView[12]; + EditText ed; + Button send,down; + public TextView text; + private ImageView imageview; + private Bitmap bitmap; + Handler handler=new Handler(){ + public void handleMessage(Message msg) { + if(msg.what==123){ + imageview.setImageBitmap(bitmap); + } + }; + }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second_); + this.RegisterEcent(); } public void RegisterEcent(){ - t[0]=(TextView) findViewById(R.id.n_0); - t[1]=(TextView) findViewById(R.id.n_1); - t[2]=(TextView) findViewById(R.id.n_2); - t[3]=(TextView) findViewById(R.id.n_3); - t[4]=(TextView) findViewById(R.id.n_4); - t[5]=(TextView) findViewById(R.id.n_5); - t[6]=(TextView) findViewById(R.id.n_6); - t[7]=(TextView) findViewById(R.id.n_7); - t[8]=(TextView) findViewById(R.id.n_8); - t[9]=(TextView) findViewById(R.id.n_9); - t[10]=(TextView) findViewById(R.id.n_10); - t[11]=(TextView) findViewById(R.id.n_11); - t[12]=(TextView) findViewById(R.id.n_12); - t[13]=(TextView) findViewById(R.id.n_13); - t[14]=(TextView) findViewById(R.id.n_14); - t[15]=(TextView) findViewById(R.id.n_15); - t[16]=(TextView) findViewById(R.id.n_16); - for(int i=0;i<17;i++){ - t[i].setOnClickListener(this); - } - + down = (Button)findViewById(R.id.Down); + down.setOnClickListener(this); + imageview=(ImageView) findViewById(R.id.image); + text = (TextView)findViewById(R.id.address); + ed = (EditText)findViewById(R.id.edit_text); + send = (Button)findViewById(R.id.n_12); + send.setOnClickListener(this); + Log.d("dd","789"); } - @Override - public void onClick(View v) { + public void save(String str){ + String data=str; + FileOutputStream out=null; + BufferedWriter writer=null; + + try{ + out =openFileOutput("wechat", Context.MODE_PRIVATE); + writer=new BufferedWriter(new OutputStreamWriter(out)); + Log.d("dd","456"); + writer.write(data); + } catch(IOException e){ + e.printStackTrace(); + } finally { + if (writer !=null){ + try { + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } } + @Override + public void onClick(View view){ + if(view==send) { + String str = ed.getText().toString(); + this.save(str); + Log.d("dd", "123"); + } + if(view==down){ + new Thread(download).start(); + } + } + Thread download = new Thread(){ + + public void run() { + String Path=text.getText().toString();//下载图片的路径 + try { + URL url=new URL(Path);//对资源链接 + InputStream inputStream=url.openStream(); + bitmap= BitmapFactory.decodeStream(inputStream);//转换成位图图片 + handler.sendEmptyMessage(123); + inputStream.close(); + inputStream=url.openStream(); + File file=new File(Environment.getExternalStorageDirectory()+"./DCIM/wechat.jpg"); + 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(); + } + } + }; } diff --git a/soft1614080902434/2.app/2.app/src/main/res/layout/activity_second_.xml b/soft1614080902434/2.app/2.app/src/main/res/layout/activity_second_.xml index 0c1c6934c..00d993669 100644 --- a/soft1614080902434/2.app/2.app/src/main/res/layout/activity_second_.xml +++ b/soft1614080902434/2.app/2.app/src/main/res/layout/activity_second_.xml @@ -10,7 +10,7 @@ android:layout_width="match_parent" android:layout_height="304dp" android:layout_x="0dp" - android:layout_y="2dp" + android:layout_y="0dp" android:background="#EBEBEB" tools:layout_editor_absoluteX="1dp" tools:layout_editor_absoluteY="0dp" /> @@ -142,6 +142,7 @@ android:layout_x="269dp" android:layout_y="262dp" android:text="发送" + android:clickable="true" tools:layout_editor_absoluteX="298dp" tools:layout_editor_absoluteY="538dp" /> @@ -165,15 +166,6 @@ tools:layout_editor_absoluteX="340dp" tools:layout_editor_absoluteY="212dp" /> -