-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cfe2a68
Showing
92 changed files
with
4,089 additions
and
0 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,9 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
/build |
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,28 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 27 | ||
defaultConfig { | ||
applicationId "com.zhongjh.cameraviewsoundrecorder" | ||
minSdkVersion 14 | ||
targetSdkVersion 27 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation 'com.android.support:appcompat-v7:27.1.1' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.2' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | ||
compile project(path: ':library') | ||
} |
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,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
app/src/androidTest/java/com/zhongjh/cameraapp/ExampleInstrumentedTest.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,26 @@ | ||
package com.zhongjh.cameraapp; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.zhongjh.cameraviewsoundrecorder", appContext.getPackageName()); | ||
} | ||
} |
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,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.zhongjh.cameraapp"> | ||
|
||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
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> | ||
</application> | ||
|
||
</manifest> |
116 changes: 116 additions & 0 deletions
116
app/src/main/java/com/zhongjh/cameraapp/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 |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package com.zhongjh.cameraapp; | ||
|
||
import android.Manifest; | ||
import android.annotation.TargetApi; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.graphics.BitmapFactory; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.support.v4.app.ActivityCompat; | ||
import android.support.v4.content.ContextCompat; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import com.zhongjh.cameraviewsoundrecorder.CameraActivity; | ||
import com.zhongjh.cameraviewsoundrecorder.util.DeviceUtil; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
private final int GET_PERMISSION_REQUEST = 100; //权限申请自定义码 | ||
private ImageView photo; | ||
private TextView device; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
getPermissions(); | ||
} | ||
}); | ||
photo = findViewById(R.id.image_photo); | ||
device = findViewById(R.id.device); | ||
device.setText(DeviceUtil.getDeviceInfo()); | ||
} | ||
|
||
/** | ||
* 获取权限 | ||
*/ | ||
private void getPermissions() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager | ||
.PERMISSION_GRANTED && | ||
ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager | ||
.PERMISSION_GRANTED && | ||
ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager | ||
.PERMISSION_GRANTED) { | ||
startActivityForResult(new Intent(MainActivity.this, CameraActivity.class), 100); | ||
} else { | ||
//不具有获取权限,需要进行权限申请 | ||
ActivityCompat.requestPermissions(MainActivity.this, new String[]{ | ||
Manifest.permission.WRITE_EXTERNAL_STORAGE, | ||
Manifest.permission.RECORD_AUDIO, | ||
Manifest.permission.CAMERA}, GET_PERMISSION_REQUEST); | ||
} | ||
} else { | ||
startActivityForResult(new Intent(MainActivity.this, CameraActivity.class), 100); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
super.onActivityResult(requestCode, resultCode, data); | ||
if (resultCode == 101) { | ||
Log.i("CJT", "picture"); | ||
String path = data.getStringExtra("path"); | ||
photo.setImageBitmap(BitmapFactory.decodeFile(path)); | ||
} | ||
if (resultCode == 102) { | ||
Log.i("CJT", "video"); | ||
String path = data.getStringExtra("path"); | ||
} | ||
if (resultCode == 103) { | ||
Toast.makeText(this, "请检查相机权限~", Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
|
||
@TargetApi(23) | ||
@Override | ||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { | ||
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
if (requestCode == GET_PERMISSION_REQUEST) { | ||
int size = 0; | ||
if (grantResults.length >= 1) { | ||
int writeResult = grantResults[0]; | ||
//读写内存权限 | ||
boolean writeGranted = writeResult == PackageManager.PERMISSION_GRANTED;//读写内存权限 | ||
if (!writeGranted) { | ||
size++; | ||
} | ||
//录音权限 | ||
int recordPermissionResult = grantResults[1]; | ||
boolean recordPermissionGranted = recordPermissionResult == PackageManager.PERMISSION_GRANTED; | ||
if (!recordPermissionGranted) { | ||
size++; | ||
} | ||
//相机权限 | ||
int cameraPermissionResult = grantResults[2]; | ||
boolean cameraPermissionGranted = cameraPermissionResult == PackageManager.PERMISSION_GRANTED; | ||
if (!cameraPermissionGranted) { | ||
size++; | ||
} | ||
if (size == 0) { | ||
startActivityForResult(new Intent(MainActivity.this, CameraActivity.class), 100); | ||
} else { | ||
Toast.makeText(this, "请到设置-权限管理中开启", Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
} | ||
} | ||
} |
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,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24.0" | ||
android:viewportHeight="24.0"> | ||
<path | ||
android:fillColor="#FFFFFFFF" | ||
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"/> | ||
</vector> |
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,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24.0" | ||
android:viewportHeight="24.0"> | ||
<path | ||
android:fillColor="#FFFFFFFF" | ||
android:pathData="M9,3L7.17,5L4,5c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,7c0,-1.1 -0.9,-2 -2,-2h-3.17L15,3L9,3zM12,18c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5zM12,17l1.25,-2.75L16,13l-2.75,-1.25L12,9l-1.25,2.75L8,13l2.75,1.25z"/> | ||
</vector> |
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 @@ | ||
<vector android:height="48dp" android:viewportHeight="1024.0" | ||
android:viewportWidth="1024.0" android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="#2c2c2c" android:pathData="M411.8,408.1c-3.7,3.5 -7.3,6.9 -10.6,10.6l-1,1 0.1,0.1c-20.2,23.9 -33,54.3 -34.1,87.9L134,275.4C213,149.5 352.7,65.5 512.3,65.5c70.5,0 137,16.7 196.2,45.9L411.8,408.1zM410.4,615.5l3.6,3.6 0.3,-0.4c15.6,13.9 34.3,24.1 54.8,30.3l-285.7,165C110.4,734.4 65.5,628.8 65.5,512.3c0,-70.4 16.8,-136.7 45.8,-196l294.7,294.7C407.4,612.6 408.9,614.1 410.4,615.5zM583.7,634.9l-0.2,-0.4c19.5,-11.8 35.7,-28.4 47.7,-47.7l86.3,322.2c-61.5,31.9 -131.1,50.2 -205.1,50.2 -113.6,0 -216.8,-42.7 -295.6,-112.4L583.7,634.9zM757.8,885.5 L642.2,454l-1.7,0.5c-6.7,-15 -15.6,-28.8 -26.7,-40.6l334.2,0c7.1,31.7 11.2,64.6 11.2,98.5C959.2,668.4 879.1,805.6 757.8,885.5zM514.9,368.8l234.6,-234.6c86.1,54.2 152.3,136.6 185.6,234.6L514.9,368.8z"/> | ||
</vector> |
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,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24.0" | ||
android:viewportHeight="24.0"> | ||
<path | ||
android:fillColor="#FFFFFFFF" | ||
android:pathData="M21,19V5c0,-1.1 -0.9,-2 -2,-2H5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2zM8.5,13.5l2.5,3.01L14.5,12l4.5,6H5l3.5,-4.5z"/> | ||
</vector> |
Oops, something went wrong.