Skip to content

Commit

Permalink
Merge pull request hzuapps#2407 from as6296463/master
Browse files Browse the repository at this point in the history
hzuapps#6 hzuapps#1336 第六次实验
  • Loading branch information
zengsn authored Jun 2, 2018
2 parents 8c2115a + c5d351f commit 9872bc4
Show file tree
Hide file tree
Showing 9 changed files with 403 additions and 0 deletions.
26 changes: 26 additions & 0 deletions com1614080901219/app5/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.hzuapps.androidlabs.com1614080901219">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".com1614080901219activity1"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".com1614080901219activity2" />
<activity android:name=".com1614080901219activity3"></activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package edu.hzuapps.androidlabs.com1614080901219;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import android.os.AsyncTask;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class com1614080901219activity2 extends AppCompatActivity implements OnClickListener{

Button content;
ImageView image;
Bitmap bitmap;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_com1614080901219activity2);
content=(Button)findViewById(R.id.content);
image=(ImageView)findViewById(R.id.image);

content.setOnClickListener(this);
image.setOnClickListener(this);
}

public Bitmap GetImageInputStream(String imageurl){
URL url;
HttpURLConnection connection=null;
Bitmap bitmap=null;
try {
url = new URL(imageurl);
connection=(HttpURLConnection)url.openConnection();
connection.setConnectTimeout(6000);
connection.setDoInput(true);
connection.setUseCaches(false);
InputStream inputStream=connection.getInputStream();
bitmap=BitmapFactory.decodeStream(inputStream);
inputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
return bitmap;
}

public void onClick(View v) {
switch (v.getId()) {
case R.id.content:

new Task().execute("https://raw.githubusercontent.com/as6296463/android-labs-2018/master/com1614080901219/g1.png");
break;

case R.id.image:

SavaImage(bitmap, Environment.getExternalStorageDirectory().getPath()+"/Test");
Toast.makeText(getBaseContext(), "图片保存", Toast.LENGTH_SHORT).show();
break;

default:
break;
}
}

Handler handler=new Handler(){
public void handleMessage(android.os.Message msg) {
if(msg.what==0x123){
image.setImageBitmap(bitmap);
}
};
};


class Task extends AsyncTask<String, Integer, Void>{

protected Void doInBackground(String... params) {
bitmap=GetImageInputStream((String)params[0]);
return null;
}

protected void onPostExecute(Void result) {
super.onPostExecute(result);
Message message=new Message();
message.what=0x123;
handler.sendMessage(message);
}

}

public void SavaImage(Bitmap bitmap, String path){
File file=new File(path);
FileOutputStream fileOutputStream=null;
if(!file.exists()){
file.mkdir();
}
try {
fileOutputStream=new FileOutputStream(path+"/"+System.currentTimeMillis()+".png");
bitmap.compress(Bitmap.CompressFormat.JPEG, 100,fileOutputStream);
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package edu.hzuapps.androidlabs.com1614080901219;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;


public class com1614080901219activity3 extends AppCompatActivity {
private TextView textView1,textView2,bt2,bt3,bt4,bt5,bt6;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_com1614080901219activity3);

textView2 = (TextView) findViewById(R.id.nichen);
bt2 = (TextView) findViewById(R.id.bt2);
bt3 = (TextView) findViewById(R.id.bt3);
bt4 = (TextView) findViewById(R.id.bt4);
bt5 = (TextView) findViewById(R.id.bt5);
bt6 = (TextView) findViewById(R.id.bt6);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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=".com1614080901219activity2">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>

<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="450dp"
android:layout_alignParentTop="true"
android:layout_marginTop="0dp" />

<Button
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="142dp"
android:layout_marginLeft="142dp"
android:layout_marginTop="447dp"
android:text="获取聚豆" />


</RelativeLayout>
</android.support.constraint.ConstraintLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?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=".com1614080901219activity3">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="508dp"
android:background="#C0C0C0"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginBottom="20dp"
android:background="#FFFFFF"
android:orientation="horizontal">


<ImageView
android:id="@+id/touxiang"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
android:src="@drawable/touxiang" />

</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="90dp"
android:orientation="vertical">

<TextView
android:id="@+id/nichen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="0.1dp"
android:background="#FFFFFF"
android:gravity="left"
android:paddingTop="12dp"
android:text="@string/nichen"
android:textSize="20sp" />

<TextView
android:id="@+id/bt2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="0.1dp"
android:background="#FFFFFF"
android:gravity="left"
android:paddingTop="12dp"
android:text="@string/text1"
android:textSize="20sp" />

<TextView
android:id="@+id/bt3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:gravity="left"
android:paddingTop="12dp"
android:text="@string/text2"
android:textSize="20sp" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="140dp"
android:orientation="vertical">

<TextView
android:id="@+id/bt4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="0.1dp"
android:background="#FFFFFF"
android:gravity="left"
android:paddingTop="12dp"
android:text="@string/text3"
android:textSize="20sp" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="0.1dp"
android:background="#FFFFFF"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:gravity="left"
android:paddingTop="12dp"
android:text="@string/diqu"
android:textSize="20sp" />
</LinearLayout>

<TextView
android:id="@+id/bt5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:gravity="left"
android:paddingTop="12dp"
android:text="@string/text4"
android:textSize="20sp" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_marginTop="10dp"
android:orientation="vertical">

<TextView
android:id="@+id/bt6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:gravity="left"
android:paddingTop="12dp"
android:text="@string/text5"
android:textSize="20sp" />

<TextView
android:id="@+id/bt7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:gravity="left"
android:paddingTop="12dp"
android:text="@string/text6"
android:textSize="20sp" />
</LinearLayout>

</LinearLayout>


</android.support.constraint.ConstraintLayout>
Binary file added com1614080901219/g1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added com1614080901219/g2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added com1614080901219/g3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9872bc4

Please sign in to comment.