forked from hzuapps/android-labs
-
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.
Merge pull request hzuapps#576 from chenqiuwen/master
#1 hzuapps#88 hzuapps#89 hzuapps#90 实验1、2、3、4
- Loading branch information
Showing
5 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...ava/edu/hzuapps/androidworks/homeworks/net1314080903105/Net1314080903105MainActivity.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,64 @@ | ||
package edu.hzuapps.androidworks.homeworks.net1314080903105; | ||
|
||
import java.io.IOException; | ||
|
||
import android.hardware.Camera; | ||
import android.os.Bundle; | ||
import android.app.Activity; | ||
import android.view.Menu; | ||
import android.view.SurfaceHolder; | ||
import android.view.SurfaceHolder.Callback; | ||
import android.view.SurfaceView; | ||
/*整个预览的流程是建立一个surface, | ||
获取surface得控制器surfaceholder, | ||
设立surface的窗口previewdisplay, | ||
最后开始预览startpreview。 | ||
当然最后还要添加相机相关的权限。*/ | ||
public class Net1314080903105MainActivity extends Activity { | ||
private SurfaceView mView=null; //是建立一个surface | ||
private SurfaceHolder mHolder=null; | ||
private Camera mCamera=null; | ||
@SuppressWarnings("deprecation") | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main_net131408903105); | ||
mView=(SurfaceView)this.findViewById(R.id.surfaceView1); | ||
mHolder=mView.getHolder(); //获取surface得控制器surfaceHolder | ||
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); | ||
// mHolder.setFixedSize(1, 700); // 设置Surface分辨率 | ||
// mHolder.setSizeFromLayout(); | ||
// mHolder.setKeepScreenOn(true);// 屏幕常亮 | ||
mHolder.addCallback(new Callback(){ | ||
|
||
@Override | ||
public void surfaceChanged(SurfaceHolder holder, int format, | ||
int width, int height) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void surfaceCreated(SurfaceHolder holder) { | ||
// TODO Auto-generated method stub | ||
mCamera=Camera.open(1); //若要升级增加摄像头选择则应该设置try,catch | ||
try { | ||
mCamera.setPreviewDisplay(mHolder); //设立surface的窗口PreviewDisplay | ||
mCamera.setDisplayOrientation(90); //设置摄像头角度,以后若有需要可以用来调试手机横竖显示 | ||
} catch (IOException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
mCamera.startPreview(); | ||
} | ||
|
||
@Override | ||
public void surfaceDestroyed(SurfaceHolder holder) { | ||
// TODO Auto-generated method stub | ||
mCamera.startPreview(); | ||
mCamera.release(); | ||
}}); | ||
} | ||
|
||
|
||
} |
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,18 @@ | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:paddingBottom="@dimen/activity_vertical_margin" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingRight="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_vertical_margin" | ||
tools:context=".Net1314080903105MainActivity" > | ||
|
||
<SurfaceView | ||
android:id="@+id/surfaceView1" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
android:layout_alignParentLeft="true" | ||
android:layout_alignParentTop="true" /> | ||
|
||
</RelativeLayout> |
1 change: 1 addition & 0 deletions
1
edu/hzuapps/androidworks/homeworks/net314080903105/Net1314080903105Activity.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 @@ | ||
|