-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
相机控制APP
- Loading branch information
0 parents
commit 1189953
Showing
38 changed files
with
755 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,17 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto | ||
|
||
# Custom for Visual Studio | ||
*.cs diff=csharp | ||
|
||
# Standard to msysgit | ||
*.doc diff=astextplain | ||
*.DOC diff=astextplain | ||
*.docx diff=astextplain | ||
*.DOCX diff=astextplain | ||
*.dot diff=astextplain | ||
*.DOT diff=astextplain | ||
*.pdf diff=astextplain | ||
*.PDF diff=astextplain | ||
*.rtf diff=astextplain | ||
*.RTF diff=astextplain |
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,8 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures |
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,27 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 23 | ||
buildToolsVersion '26.0.0' | ||
|
||
defaultConfig { | ||
applicationId "com.buaa.camera" | ||
minSdkVersion 15 | ||
targetSdkVersion 23 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation 'com.android.support.constraint:constraint-layout:1.0.2' | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.android.support:appcompat-v7:23.0.0' | ||
} |
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 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in D:\android\sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# 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 *; | ||
#} |
13 changes: 13 additions & 0 deletions
13
app/src/androidTest/java/com/buaa/camera/ApplicationTest.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 com.buaa.camera; | ||
|
||
import android.app.Application; | ||
import android.test.ApplicationTestCase; | ||
|
||
/** | ||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | ||
*/ | ||
public class ApplicationTest extends ApplicationTestCase<Application> { | ||
public ApplicationTest() { | ||
super(Application.class); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.buaa.camera"> | ||
|
||
<uses-permission android:name="android.permission.CAMERA" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".activity.MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity android:name=".activity.instructionActivity"/> | ||
</application> | ||
|
||
</manifest> |
129 changes: 129 additions & 0 deletions
129
app/src/main/java/com/buaa/camera/activity/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,129 @@ | ||
package com.buaa.camera.activity; | ||
|
||
|
||
import android.Manifest; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.os.Build; | ||
import android.support.v4.app.ActivityCompat; | ||
import android.support.v4.content.ContextCompat; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.view.KeyEvent; | ||
import android.view.View; | ||
import android.view.Window; | ||
import android.widget.ImageButton; | ||
import android.widget.Toast; | ||
|
||
import com.buaa.camera.R; | ||
|
||
public class MainActivity extends AppCompatActivity implements View.OnClickListener { | ||
|
||
private final int PERMISSION_CODE = 122; | ||
private ImageButton cameraButton; | ||
private ImageButton instructionButton; | ||
private ImageButton setupButton; | ||
private long exitTime = 0; | ||
|
||
private final int IMAGE_CAMERA = 123; | ||
//private final int CUT_PHOTO = 124; | ||
//private final int PERMISSION_CODE = 122; | ||
//private final int IMAGE_ALBUM = 125; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
requestWindowFeature(Window.FEATURE_NO_TITLE);//加入后Nexus5X闪退 | ||
setContentView(R.layout.activity_main); | ||
intiView(); | ||
} | ||
|
||
private void intiView() { | ||
cameraButton = (ImageButton) findViewById(R.id.ImageButton1); | ||
instructionButton = (ImageButton) findViewById(R.id.ImageButton2); | ||
setupButton = (ImageButton) findViewById(R.id.Setup); | ||
cameraButton.setOnClickListener(this); | ||
instructionButton.setOnClickListener(this); | ||
setupButton.setOnClickListener(this); | ||
} | ||
|
||
|
||
@Override | ||
public void onClick(View view) { | ||
switch (view.getId()) { | ||
case R.id.ImageButton2: | ||
|
||
//打开说明界面 | ||
Intent intent = new Intent(MainActivity.this,instructionActivity.class); | ||
startActivity(intent); | ||
break; | ||
case R.id.ImageButton1: | ||
getPermission(); | ||
break; | ||
case R.id.Setup: | ||
|
||
break; | ||
} | ||
} | ||
|
||
public void getPermission() { | ||
if (Build.VERSION.SDK_INT >= 23) { | ||
//检查应用是否有相机权限,如果有则返回PERMISSION_GRANTED,否则返回PERMISSION_DENIED | ||
int checkPermission = ContextCompat. | ||
checkSelfPermission(this, Manifest.permission.CAMERA); | ||
if (checkPermission != PackageManager.PERMISSION_GRANTED) { | ||
//如果未被赋予权限则弹框请求给予权限 | ||
ActivityCompat.requestPermissions(this, | ||
new String[]{Manifest.permission.CAMERA}, | ||
PERMISSION_CODE); | ||
return; | ||
} else { | ||
//打开相机界面 | ||
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); | ||
startActivityForResult(intent, IMAGE_CAMERA); | ||
} | ||
} else { | ||
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); | ||
startActivityForResult(intent, IMAGE_CAMERA); | ||
} | ||
} | ||
|
||
@Override | ||
public void onRequestPermissionsResult(int requestCode, | ||
String[] permissions, int[] grantResults) { | ||
switch (requestCode) { | ||
case PERMISSION_CODE: | ||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { | ||
Toast.makeText(this, "获取权限成功", Toast.LENGTH_SHORT) | ||
.show(); //checkAnswer(true); | ||
//已经获得授权,打开相机 | ||
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); | ||
startActivityForResult(intent, IMAGE_CAMERA); | ||
} else { | ||
Toast.makeText(this, "获取权限失败", Toast.LENGTH_SHORT) | ||
.show(); | ||
//未获得授权,结束当前活动 | ||
this.finish(); | ||
} | ||
break; | ||
default: | ||
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
} | ||
} | ||
|
||
|
||
|
||
@Override | ||
public boolean onKeyDown(int keyCode, KeyEvent event) { | ||
if (keyCode == KeyEvent.KEYCODE_BACK) { | ||
if (System.currentTimeMillis() - exitTime > 2000) { | ||
exitTime = System.currentTimeMillis(); | ||
Toast.makeText(this, "再按退出", Toast.LENGTH_SHORT).show(); | ||
} else { | ||
finish(); | ||
System.exit(0); | ||
} | ||
} | ||
return true; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/com/buaa/camera/activity/instructionActivity.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,17 @@ | ||
package com.buaa.camera.activity; | ||
|
||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
|
||
import com.buaa.camera.R; | ||
|
||
public class instructionActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_instruction); | ||
} | ||
|
||
|
||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?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" | ||
android:background="@drawable/background" | ||
android:orientation="vertical" | ||
tools:context="com.buaa.camera.activity.instructionActivity"> | ||
|
||
|
||
</android.support.constraint.ConstraintLayout> |
Oops, something went wrong.