-
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 #1768 from hzs2019/master
- Loading branch information
Showing
6 changed files
with
85 additions
and
192 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
students/com1714080901133/app/src/main/AndroidManifest.xml
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="edu.hzuapps.androidlabs.com1714080901133"> | ||
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> | ||
<uses-permission android:name="android.permission.READ_PROFILE" /> | ||
<uses-permission android:name="android.permission.READ_CONTACTS" /> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | ||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> | ||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
<uses-feature | ||
android:name="android.hardware.camera" | ||
android:required="true" /> | ||
<application | ||
android:allowBackup="true" | ||
android:icon="@drawable/bilibili" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".Com1714080901133Activity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity | ||
android:name=".Com1714080901133Activity2" | ||
android:label="@string/title_activity_com17140809011332" /> | ||
</application> | ||
|
||
|
||
</manifest> |
178 changes: 6 additions & 172 deletions
178
.../app/src/main/java/edu/hzuapps/androidlabs/com1714080901133/Com1714080901133Activity.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,192 +1,26 @@ | ||
package edu.hzuapps.androidlabs.com1714080901133; | ||
import android.annotation.TargetApi; | ||
import android.content.ContentUris; | ||
import android.content.Intent; | ||
import android.database.Cursor; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.net.Uri; | ||
import android.os.Build; | ||
import android.os.Environment; | ||
import android.os.StrictMode; | ||
import android.provider.DocumentsContract; | ||
import android.provider.MediaStore; | ||
import android.support.annotation.RequiresApi; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.ImageView; | ||
import android.widget.Toast; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
|
||
public class Com1714080901133Activity extends AppCompatActivity { | ||
import edu.hzuapps.androidlabs.com1714080901133.Com1714080901133Activity; | ||
|
||
public static final int TAKE_PHOTO = 1; | ||
public static final int CROP_PHOTO = 2; | ||
public static final int CHOOSE_PHOTO = 3; | ||
private Button takephoto; | ||
private Button choosephoto; | ||
private ImageView picture; | ||
private Uri imageUri; | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) | ||
public class Com1714080901133Activity extends AppCompatActivity { | ||
Button button; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); | ||
StrictMode.setVmPolicy(builder.build()); | ||
builder.detectFileUriExposure(); | ||
setContentView(R.layout.com_1714080901133_activity); | ||
takephoto = (Button) findViewById(R.id.take_photo); | ||
picture = (ImageView) findViewById(R.id.picture); | ||
choosephoto = (Button) findViewById(R.id.choose_photo); | ||
|
||
takephoto.setOnClickListener(new View.OnClickListener() { | ||
ImageView jmp = findViewById(R.id.hzu); | ||
jmp.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("android.media.action.IMAGE_CAPTURE"); | ||
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); | ||
|
||
startActivityForResult(intent, TAKE_PHOTO); | ||
startActivity(new Intent(Com1714080901133Activity.this,Com1714080901133Activity2.class)); | ||
} | ||
}); | ||
|
||
choosephoto.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Intent intent = new Intent("android.intent.action.GET_CONTENT"); | ||
intent.setType("image/*"); | ||
|
||
startActivityForResult(intent, CHOOSE_PHOTO); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
switch (requestCode) { | ||
|
||
case TAKE_PHOTO: | ||
if (resultCode == RESULT_OK) { | ||
Intent intent = new Intent("com.android.camera.action.CROP"); | ||
intent.setDataAndType(imageUri, "image/*"); | ||
intent.putExtra("scale", true); | ||
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); | ||
|
||
startActivityForResult(intent, CROP_PHOTO); | ||
} | ||
break; | ||
|
||
case CROP_PHOTO: | ||
if (resultCode == RESULT_OK) { | ||
try { | ||
Bitmap bitmap = BitmapFactory.decodeStream( | ||
getContentResolver().openInputStream(imageUri)); | ||
picture.setImageBitmap(bitmap); | ||
} catch (FileNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
break; | ||
|
||
case CHOOSE_PHOTO: | ||
if (resultCode == RESULT_OK) { | ||
if (Build.VERSION.SDK_INT >= 19) { | ||
|
||
handleImageOnKitKat(data); | ||
} else { | ||
|
||
handleImageBeforeKitKat(data); | ||
} | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
|
||
@TargetApi(19) | ||
private void handleImageOnKitKat(Intent data) { | ||
String imagePath = null; | ||
|
||
Uri uri = data.getData(); | ||
|
||
if (DocumentsContract.isDocumentUri(this, uri)) { | ||
String docId = DocumentsContract.getDocumentId(uri); | ||
|
||
if ("com.android.providers.media.documents".equals( | ||
uri.getAuthority())) { | ||
String id = docId.split(":")[1]; | ||
String selection = MediaStore.Images.Media._ID + "=" + id; | ||
|
||
imagePath = getImagePath( | ||
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection); | ||
} else if ("com.android.providers.downloads.documents".equals( | ||
uri.getAuthority())) { | ||
|
||
Uri contentUri = ContentUris.withAppendedId( | ||
Uri.parse("content://downloads/public_downloads"), | ||
Long.valueOf(docId)); | ||
imagePath = getImagePath(contentUri, null); | ||
} | ||
} else if ("content".equalsIgnoreCase(uri.getScheme())) { | ||
|
||
imagePath = getImagePath(uri, null); | ||
} | ||
|
||
displayImage(imagePath); | ||
} | ||
|
||
|
||
private void handleImageBeforeKitKat(Intent data) { | ||
Uri uri = data.getData(); | ||
String imagePath = getImagePath(uri, null); | ||
displayImage(imagePath); | ||
} | ||
|
||
|
||
private String getImagePath(Uri uri, String selection) { | ||
String path = null; | ||
Cursor cursor = getContentResolver().query(uri, null, selection, null, null); | ||
if (cursor != null) { | ||
|
||
if (cursor.moveToFirst()) { | ||
path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA)); | ||
} | ||
|
||
cursor.close(); | ||
} | ||
return path; | ||
} | ||
|
||
|
||
private void displayImage(String imagePath) { | ||
if (imagePath != null) { | ||
|
||
Bitmap bitmap = BitmapFactory.decodeFile(imagePath); | ||
picture.setImageBitmap(bitmap); | ||
} else { | ||
Toast.makeText(this, "failed to get image", Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...app/src/main/java/edu/hzuapps/androidlabs/com1714080901133/Com1714080901133Activity2.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package edu.hzuapps.androidlabs.com1714080901133; | ||
|
||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
|
||
public class Com1714080901133Activity2 extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.com_1714080901133_activity2); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
17 changes: 17 additions & 0 deletions
17
students/com1714080901133/app/src/main/res/layout/com_1714080901133_activity2.xml
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,17 @@ | ||
<?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=".Com1714080901133Activity2"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="第二个界面" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
</android.support.constraint.ConstraintLayout> |