Skip to content

Commit

Permalink
Merge pull request #1887 from Huanglongsen/master
Browse files Browse the repository at this point in the history
#7 #1886 实验7
  • Loading branch information
zengsn authored May 13, 2019
2 parents 82e9b2b + 3d5ca8e commit 02c02f0
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 22 deletions.
36 changes: 36 additions & 0 deletions students/soft1709081602232/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="soft1709081602232.androidlabs.hzuapps.edu.myapplication">

<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=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="soft1709081602232.androidlabs.hzuapps.edu.myapplication7.fileprovider"
android:exported="false"
android:grantUriPermissions="true"></provider>
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"></meta-data>


</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>





</manifest>
Original file line number Diff line number Diff line change
@@ -1,26 +1,74 @@
package soft1709081602232.androidlabs.hzuapps.edu.myapplication;

import android.app.MediaRouteButton;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.provider.MediaStore;
import android.support.v4.content.FileProvider;
import android.support.v4.content.IntentCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

private Button button;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

public class MainActivity extends AppCompatActivity {
public static final int TAKE_PHOTO=1;
private ImageView picture;
private Uri imageUri;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
Button takePhoto=(Button)findViewById(R.id.take_photo);
picture=(ImageView)findViewById(R.id.picture);
takePhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, Main2Activity.class);
startActivity(i);
File outputImage=new File(getExternalCacheDir(),"output_image.jpg");
try{
if(outputImage.exists()){
outputImage.delete();
}
outputImage.createNewFile();
}catch(IOException e){
e.printStackTrace();
}
if(Build.VERSION.SDK_INT>=24){
imageUri=FileProvider.getUriForFile(MainActivity.this,"com.example.cameraalbumtext.fileprovider",outputImage);

}else{
imageUri=Uri.fromFile(outputImage);

}
Intent intent=new Intent("android.media.IMAGE_CAPTURE");
intent.putExtra(MediaStore.EXTRA_OUTPUT,imageUri);
startActivityForResult(intent,TAKE_PHOTO);
}
});
}
@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data ){
switch (requestCode){
case TAKE_PHOTO:
if (resultCode==RESULT_OK){
try{
Bitmap bitmap=BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
picture.setImageBitmap(bitmap);
}catch(FileNotFoundException e){
e.printStackTrace();
}
}
break;
default:
break;
}
}
}
25 changes: 10 additions & 15 deletions students/soft1709081602232/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
<?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"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" android:background="@drawable/xuezhiquan">

android:layout_height="match_parent">
<Button
android:id="@+id/button"
android:id="@+id/take_photo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="演员" />
<EditText
android:id="@+id/edit"
android:layout_width="match_parent"
android:text="Take photo"/>
<ImageView
android:id="@+id/picture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Type something here"
/>
</android.support.constraint.ConstraintLayout>
android:layout_gravity="center_horizontal"/>
</LinearLayout>
4 changes: 4 additions & 0 deletions students/soft1709081602232/res/xml/file_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external.path name="my_images" path=""/>
</paths>

0 comments on commit 02c02f0

Please sign in to comment.