From dbbec2530a302f70ed2f66f13a24eabf2a9ded6e Mon Sep 17 00:00:00 2001 From: jeremyjun <993434265@qq.com> Date: Fri, 1 Jun 2018 23:40:58 +0800 Subject: [PATCH] #6 the sixth report --- Soft1613071002205/main/AndroidManifest.xml | 40 ++++++++ .../soft1613071002205/DownloadActivity.java | 94 +++++++++++++++++++ .../soft1613071002205/Main2Activity.java | 25 +++++ .../soft1613071002205/MainActivity.java | 57 +++++++++++ .../jeremy/soft1613071002205/User.java | 46 +++++++++ ...\344\270\273\347\225\214\351\235\242.java" | 13 +++ ...\346\201\257\345\217\221\345\270\203.java" | 32 +++++++ .../main/res/layout/activity_main.xml | 70 ++++++++++++++ .../main/res/layout/download.xml | 28 ++++++ Soft1613071002205/main/res/layout/home.xml | 64 +++++++++++++ Soft1613071002205/main/res/layout/mynews.xml | 84 +++++++++++++++++ 11 files changed, 553 insertions(+) create mode 100644 Soft1613071002205/main/AndroidManifest.xml create mode 100644 Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/DownloadActivity.java create mode 100644 Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/Main2Activity.java create mode 100644 Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/MainActivity.java create mode 100644 Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/User.java create mode 100644 "Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/\344\270\273\347\225\214\351\235\242.java" create mode 100644 "Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/\344\277\241\346\201\257\345\217\221\345\270\203.java" create mode 100644 Soft1613071002205/main/res/layout/activity_main.xml create mode 100644 Soft1613071002205/main/res/layout/download.xml create mode 100644 Soft1613071002205/main/res/layout/home.xml create mode 100644 Soft1613071002205/main/res/layout/mynews.xml diff --git a/Soft1613071002205/main/AndroidManifest.xml b/Soft1613071002205/main/AndroidManifest.xml new file mode 100644 index 000000000..ae2ff449a --- /dev/null +++ b/Soft1613071002205/main/AndroidManifest.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/DownloadActivity.java b/Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/DownloadActivity.java new file mode 100644 index 000000000..f26ecc968 --- /dev/null +++ b/Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/DownloadActivity.java @@ -0,0 +1,94 @@ +package com.example.jeremy.soft1613071002205; + +import android.app.Application; +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.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.Button; +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 DownloadActivity extends AppCompatActivity{ + private static final String TAG = "MainActivity"; + private Bitmap bitmap; + Handler handler=new Handler(){ + @Override + public void handleMessage(Message msg) { + if(msg.what==111){ + mShowImage.setImageBitmap(bitmap); + } + } + }; + private ImageView mShowImage; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.download); + mShowImage = findViewById(R.id.show_image); + initButton(); + } + + private void initButton() { + Button startDownLoad = findViewById(R.id.start_btn); + startDownLoad.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + t.start(); + } + }); + } + + //为了下载图片资源,开辟一个新的子线程 + Thread t=new Thread(){ + @Override + public void run() { + //下载图片的路径 + String iPath="https://t" + + "imgsa.baidu.com/timg?" + + "image&quality=80&size=b9999_" + + "10000&sec=1527778386587&di=8be823" + + "0eaebdaeaa949d7b73357c2fa2&imgt" + + "ype=0&src=http%3A%2F%2F5b0988e595225.cdn.so" + + "hucs.com%2Fq_70%2Cc_zoom%2Cw_640%2Fimage" + + "s%2F20180415%2Fb86096a5dac244ddbc8d9060eb68e1b0.jpeg"; + 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.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(); + } + }; + }; + +} \ No newline at end of file diff --git a/Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/Main2Activity.java b/Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/Main2Activity.java new file mode 100644 index 000000000..56bc7cc90 --- /dev/null +++ b/Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/Main2Activity.java @@ -0,0 +1,25 @@ +package com.example.jeremy.soft1613071002205; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.widget.TextView; + +public class Main2Activity extends AppCompatActivity { + private TextView mTextViewGetUserName; + private TextView mTextViewGetPassword; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.mynews); + mTextViewGetUserName = (TextView) findViewById(R.id.textView2); + mTextViewGetPassword = (TextView) findViewById(R.id.textView3); + Bundle b = getIntent().getBundleExtra("data"); + String getStringUserName = b.getString("username"); + mTextViewGetUserName.setText(getStringUserName); + String getStringPassword = b.getString("password"); + mTextViewGetPassword.setText(getStringPassword); + + + } +} diff --git a/Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/MainActivity.java b/Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/MainActivity.java new file mode 100644 index 000000000..213b014f7 --- /dev/null +++ b/Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/MainActivity.java @@ -0,0 +1,57 @@ +package com.example.jeremy.soft1613071002205; + + +import android.app.Activity; +import android.content.Intent; +import android.content.SharedPreferences; +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; + +public class MainActivity extends AppCompatActivity { + + private Button 登录; + private EditText 用户名; + private EditText 密码; + private SharedPreferences mSharePreferences; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + mSharePreferences = getSharedPreferences("data", MODE_PRIVATE); + + 用户名 = (EditText) findViewById(R.id.editText); + 密码 = (EditText) findViewById(R.id.editText2); + //取出数据并渲染 + + 登录 = (Button) findViewById(R.id.login); + 登录.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + String stringUsername = 用户名.getText().toString(); + String stringPassword = 密码.getText().toString(); + // 2. 调用SharedPreferences.edit()方法,返回SharedPreferences.Editor对象,用于写入数据; + SharedPreferences.Editor editor = mSharePreferences.edit(); + //3. 调用SharedPreferences.Editor.putXxx(String key, xxx Value)方法以键值对的形式保存数据; + editor.putString("user", stringUsername); + editor.putString("password", stringPassword); + // 4. 调用SharedPreferences.Editor.commit()方法提交数据。 + editor.commit(); + + Intent intent = new Intent(MainActivity.this, User.class); + Bundle bundle = new Bundle(); + bundle.putString("username", stringUsername); + bundle.putString("password", stringPassword); + intent.putExtra("data", bundle); + + startActivity(intent); + } + + }); + } +} diff --git a/Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/User.java b/Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/User.java new file mode 100644 index 000000000..6e8171e7a --- /dev/null +++ b/Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/User.java @@ -0,0 +1,46 @@ +package com.example.jeremy.soft1613071002205; + +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; + +import java.util.Map; + +public class User extends AppCompatActivity { + + private Button mReturnButton; + private Button download; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.mynews); + mReturnButton = (Button) findViewById(R.id.returnback); + + Button download = findViewById(R.id.download); + download.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent i = new Intent(User.this, DownloadActivity.class); + startActivity(i); + } + + }); + } + + + + + public void back_to_login(View view) { + Intent intent3 = new Intent(User.this,MainActivity.class) ; + startActivity(intent3); + finish(); + } + + + + + +} \ No newline at end of file diff --git "a/Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/\344\270\273\347\225\214\351\235\242.java" "b/Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/\344\270\273\347\225\214\351\235\242.java" new file mode 100644 index 000000000..eb3e33721 --- /dev/null +++ "b/Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/\344\270\273\347\225\214\351\235\242.java" @@ -0,0 +1,13 @@ +package com.example.jeremy.soft1613071002205; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; + +public class 主界面 extends AppCompatActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.home); + } + +} \ No newline at end of file diff --git "a/Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/\344\277\241\346\201\257\345\217\221\345\270\203.java" "b/Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/\344\277\241\346\201\257\345\217\221\345\270\203.java" new file mode 100644 index 000000000..7cc2f7e68 --- /dev/null +++ "b/Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/\344\277\241\346\201\257\345\217\221\345\270\203.java" @@ -0,0 +1,32 @@ +package com.example.jeremy.soft1613071002205; + + +import android.app.Activity; +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; + +public class 信息发布 extends AppCompatActivity { + + private Button 信息发布; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.home); + + + 信息发布 = (Button) findViewById(R.id.button); + 信息发布.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(信息发布.this,主界面.class); + startActivity(intent); + } + + }); + } + } \ No newline at end of file diff --git a/Soft1613071002205/main/res/layout/activity_main.xml b/Soft1613071002205/main/res/layout/activity_main.xml new file mode 100644 index 000000000..343af53f0 --- /dev/null +++ b/Soft1613071002205/main/res/layout/activity_main.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + +