-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1887 from Huanglongsen/master
- Loading branch information
Showing
4 changed files
with
105 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
62 changes: 55 additions & 7 deletions
62
students/soft1709081602232/java/edu/hzuapps/androidlabs/soft1709081602232/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |