Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#8 #1741 提交实验八 #1801

Merged
merged 3 commits into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions students/soft1714080902331/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

<!-- 写sd卡权限-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- 这个可写可不写
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />-->
<!-- 这个可写可不写-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- 调取摄像头权限 -->
<uses-permission android:name="android.permission.CAMERA" />

Expand All @@ -19,10 +19,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".Soft1714080902331Activity4"
android:label="@string/title_activity_soft17140809023314"
android:theme="@style/AppTheme.NoActionBar"></activity>

<activity
android:name=".Soft1714080902331Activity2"
android:label="@string/title_activity_soft17140809023312"
Expand Down
8 changes: 1 addition & 7 deletions students/soft1714080902331/Soft1714080902331Activity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,14 @@ public void onClick(View v) {
startActivity(new Intent(Soft1714080902331Activity.this,Soft1714080902331Activity2.class));
}
});

ImageView btnOpen2 = (ImageView) findViewById(R.id.imageButton2);
btnOpen2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(Soft1714080902331Activity.this,Soft1714080902331Activity3.class));
}
});
ImageView btnOpen3 = (ImageView) findViewById(R.id.imageButton3);
btnOpen3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(Soft1714080902331Activity.this,Soft1714080902331Activity4.class));
}
});
}

}
20 changes: 14 additions & 6 deletions students/soft1714080902331/Soft1714080902331Activity2.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package edu.hzuapps.androidlabs.soft1714080902331;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
Expand Down Expand Up @@ -28,18 +30,20 @@ public class Soft1714080902331Activity2 extends AppCompatActivity {
private EditText record;
private Button button1;
private Button button2;
private String imageUrl ="https://tu.jiuwa.net/pic/20180120/1516420470729055.gif";
private String imageUrl = "https://tu.jiuwa.net/pic/20180120/1516420470729055.gif";
private ImageView mood;
private Button getmood;
private Handler handle = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case 0:
Bitmap bmp=(Bitmap)msg.obj;
Bitmap bmp = (Bitmap) msg.obj;
mood.setImageBitmap(bmp);
break;
}
};
}

;
};

@Override
Expand All @@ -57,7 +61,7 @@ record = (EditText) findViewById(R.id.record);
button2 = (Button) findViewById(R.id.button2);
button1.setOnClickListener(new ButtonListener());
button2.setOnClickListener(new ButtonListener());
getmood=(Button)findViewById(R.id.getmood);
getmood = (Button) findViewById(R.id.getmood);
mood = (ImageView) findViewById(R.id.mood);
getmood.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -78,6 +82,7 @@ public void run() {
}
});
}

private Bitmap getURLimage(String imageUrl) {
Bitmap bmp = null;
try {
Expand All @@ -98,8 +103,8 @@ private Bitmap getURLimage(String imageUrl) {

}


private class ButtonListener implements View.OnClickListener {
@SuppressLint("WrongConstant")
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
Expand Down Expand Up @@ -131,8 +136,11 @@ public void onClick(View v) {
break;
}
}

}
}




}

132 changes: 114 additions & 18 deletions students/soft1714080902331/Soft1714080902331Activity3.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,133 @@
<<<<<<< HEAD
package edu.hzuapps.androidlabs.soft1714080902331;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
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.FileNotFoundException;
import java.io.IOException;

public class Soft1714080902331Activity3 extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.soft_1714080902331_activity3);
public static final int CUT_PICTURE = 1;

}
public static final int SHOW_PICTURE = 2;

}
=======
package edu.hzuapps.androidlabs.soft1714080902331;
private Button takePhoto;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
private Button chooseFromAlbum;

public class Soft1714080902331Activity3 extends AppCompatActivity {
private ImageView picture;

private Uri imageUri;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.soft_1714080902331_activity3);
takePhoto = (Button) findViewById(R.id.take_photo);
chooseFromAlbum = (Button) findViewById(R.id.choose_from_album);
picture = (ImageView) findViewById(R.id.picture);

takePhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//创建File对象,用于存储拍照后的图片
//将此图片存储于SD卡的根目录下
File outputImage = new File(Environment.getExternalStorageDirectory(),
"output_image.jpg");
try {
if (outputImage.exists()) {
outputImage.delete();
}
outputImage.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
//将File对象转换成Uri对象
//Uri表标识着图片的地址
imageUri = Uri.fromFile(outputImage);
//隐式调用照相机程序
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
//拍下的照片会被输出到output_image.jpg中去
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
//此处是使用的startActivityForResult()
//因此在拍照完后悔有结果返回到onActivityResult()中去,返回值即为<span style="font-size: 13.3333px; font-family: Arial, Helvetica, sans-serif;">CUT_PICTURE</span>
//onActivityResult()中主要是实现图片裁剪
startActivityForResult(intent, CUT_PICTURE);
}
});

chooseFromAlbum.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
File outputImage = new File(Environment.getExternalStorageDirectory(),
"output_image.jpg");
try {
if (outputImage.exists()) {
outputImage.delete();
}
outputImage.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
imageUri = Uri.fromFile(outputImage);
Intent intent = new Intent(Intent.ACTION_PICK,null);
//此处调用了图片选择器
//如果直接写intent.setDataAndType("image/*");
//调用的是系统图库
intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, CUT_PICTURE);
}
});
}

}
>>>>>>> 04de59006bcef14253116cac674bc33ccca7169d

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case CUT_PICTURE:
if (resultCode == RESULT_OK) {
//此处启动裁剪程序
Intent intent = new Intent("com.android.camera.action.CROP");
//此处注释掉的部分是针对android 4.4路径修改的一个测试
//有兴趣的读者可以自己调试看看
// String text=data.getData().toString();
// Toast.makeText(MainActivity.this, text, Toast.LENGTH_SHORT).show();
intent.setDataAndType(data.getData(), "image/*");
intent.putExtra("scale", true);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, SHOW_PICTURE);
}
break;
case SHOW_PICTURE:
if (resultCode == RESULT_OK) {
try {
//将output_image.jpg对象解析成Bitmap对象,然后设置到ImageView中显示出来
Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
picture.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
break;
default:
break;
}
}





}
Loading