-
Notifications
You must be signed in to change notification settings - Fork 157
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 #726 from Hackergeek/master
lab08 #94
- Loading branch information
Showing
28 changed files
with
2,051 additions
and
0 deletions.
There are no files selected for viewing
172 changes: 172 additions & 0 deletions
172
...c/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/CustomCameraActivity.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,172 @@ | ||
package skyward.com.camera; | ||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.graphics.ImageFormat; | ||
import android.hardware.Camera; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.SurfaceHolder; | ||
import android.view.SurfaceView; | ||
import android.view.View; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
|
||
/** | ||
* 自定义相机 | ||
* 1.创建Camera对象 | ||
* 2.创建SurfaceView对象 | ||
* 3.关联Camera对象和SurfaceView对象 | ||
* 4.调整相机的显示效果 | ||
* 5.自定义相机预览界面 | ||
* Created by skyward on 2016/4/29. | ||
*/ | ||
public class CustomCameraActivity extends Activity implements SurfaceHolder.Callback{ | ||
private static final String TAG = "CustomCameraActivity"; | ||
private Camera mCamera; | ||
private SurfaceView mPreview; | ||
private SurfaceHolder mHolder; | ||
private Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() { | ||
@Override | ||
public void onPictureTaken(byte[] data, Camera camera) { | ||
//生成照片 | ||
File tempFile = new File("/sdcard/temp.png"); | ||
try { | ||
FileOutputStream fos = new FileOutputStream(tempFile); | ||
fos.write(data); | ||
fos.close(); | ||
Intent intent = new Intent(CustomCameraActivity.this, ResultActivity.class); | ||
Log.d(TAG, "onPictureTaken: " + tempFile.getAbsolutePath()); | ||
intent.putExtra("picPath", tempFile.getAbsolutePath()); | ||
startActivity(intent); | ||
CustomCameraActivity.this.finish(); | ||
} catch (FileNotFoundException e) { | ||
e.printStackTrace(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
}; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_custom_camera); | ||
//2.创建SurfaceView对象 | ||
mPreview = (SurfaceView) findViewById(R.id.preview); | ||
// 点击屏幕时自动对焦 | ||
mPreview.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
mCamera.autoFocus(null); | ||
} | ||
}); | ||
//获取SurfaceHolder对象 | ||
mHolder = mPreview.getHolder(); | ||
mHolder.addCallback(this); | ||
} | ||
|
||
/** | ||
* 拍照 | ||
* @param view | ||
*/ | ||
public void capture(View view) { | ||
//4.调整相机的显示效果 | ||
//参数设置 | ||
Camera.Parameters parameters = mCamera.getParameters(); | ||
//设置照片格式 | ||
parameters.setPictureFormat(ImageFormat.JPEG); | ||
parameters.setPreviewSize(1280, 720); | ||
//设置对焦模式为自动对焦 | ||
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); | ||
mCamera.autoFocus(new Camera.AutoFocusCallback() { | ||
@Override | ||
public void onAutoFocus(boolean success, Camera camera) { | ||
//当对焦成功,则拍照 | ||
if (success) { | ||
mCamera.takePicture(null, null, mPictureCallback); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
if(mCamera == null) { | ||
// 1.创建Camera对象 | ||
mCamera = getCamera(); | ||
if (mHolder != null) { | ||
setStartPreview(mCamera, mHolder); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
releaseCamera(); | ||
} | ||
|
||
/** | ||
* 获取系统Camera对象 | ||
* @return | ||
*/ | ||
private Camera getCamera() { | ||
Camera camera; | ||
try { | ||
camera = Camera.open(); | ||
} catch (Exception e) { | ||
camera = null; | ||
e.printStackTrace(); | ||
} | ||
return camera; | ||
} | ||
|
||
/** | ||
* 开始预览相机内容 | ||
*/ | ||
private void setStartPreview(Camera camera, SurfaceHolder holder) { | ||
try { | ||
//3.关联Camera对象和SurfaceView对象 | ||
camera.setPreviewDisplay(holder); | ||
//系统默认横屏显示 | ||
//因此要将系统camera预览角度调整90度 | ||
camera.setDisplayOrientation(90); | ||
camera.startPreview(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
/** | ||
* 释放相机资源 | ||
*/ | ||
private void releaseCamera() { | ||
if (mCamera != null) { | ||
mCamera.setPreviewCallback(null); | ||
mCamera.stopPreview(); | ||
mCamera.release(); | ||
mCamera = null; | ||
} | ||
} | ||
|
||
@Override | ||
public void surfaceCreated(SurfaceHolder holder) { | ||
setStartPreview(mCamera, mHolder); | ||
} | ||
|
||
@Override | ||
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { | ||
mCamera.stopPreview(); | ||
setStartPreview(mCamera, mHolder); | ||
} | ||
|
||
@Override | ||
public void surfaceDestroyed(SurfaceHolder holder) { | ||
releaseCamera(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_BaseActivity.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,24 @@ | ||
package skyward.com.myapplication; | ||
|
||
import android.app.Activity; | ||
import android.content.pm.ActivityInfo; | ||
import android.os.Bundle; | ||
import android.view.Window; | ||
import android.view.WindowManager; | ||
|
||
public class FeiJi_BaseActivity extends Activity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
this.requestWindowFeature(Window.FEATURE_NO_TITLE); | ||
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, | ||
WindowManager.LayoutParams.FLAG_FULLSCREEN); | ||
this.getWindow().setFlags( | ||
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, | ||
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); | ||
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); | ||
|
||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_Main.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,73 @@ | ||
package skyward.com.myapplication; | ||
|
||
import org.cocos2d.layers.CCScene; | ||
import org.cocos2d.nodes.CCDirector; | ||
import org.cocos2d.nodes.CCTextureCache; | ||
import org.cocos2d.opengl.CCGLSurfaceView; | ||
import org.cocos2d.types.ccColor4B; | ||
|
||
import com.baidu.mobstat.StatService; | ||
|
||
import android.os.Bundle; | ||
|
||
public class FeiJi_Main extends FeiJi_BaseActivity { | ||
|
||
private CCGLSurfaceView _FeiJi_Surface; | ||
private CCScene _FeiJi_Scene; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
_FeiJi_Surface = new CCGLSurfaceView(this); | ||
setContentView(_FeiJi_Surface); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
CCDirector.sharedDirector().end(); | ||
CCTextureCache.sharedTextureCache().removeAllTextures(); | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
CCDirector.sharedDirector().pause(); | ||
StatService.onPause(this); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
CCDirector.sharedDirector().resume(); | ||
StatService.onResume(this); | ||
} | ||
|
||
@Override | ||
protected void onStart() { | ||
super.onStart(); | ||
// cocos2d��ϰ�������½���Ϊԭ��,ʱ�䵥λ���� | ||
CCDirector.sharedDirector().attachInView(_FeiJi_Surface);// ��cocos2d����GLSurfaceView��������� | ||
// CCDirector.sharedDirector().setDeviceOrientation( | ||
// CCDirector.kCCDeviceOrientationLandscapeLeft); | ||
// CCDirector.sharedDirector().setDisplayFPS(true);//��ʾ FPS | ||
// CCDirector.sharedDirector().setAnimationInterval(1.0f / 60.0f);// | ||
// ÿ������� | ||
_FeiJi_Scene = CCScene.node(); | ||
|
||
FeiJi_PlayActivity _Layer = new FeiJi_PlayActivity(ccColor4B.ccc4(255, 255, 255, 255)); | ||
// _Layer.GetContext(FeiJi_Main.this); | ||
_FeiJi_Scene.addChild(_Layer); | ||
|
||
CCDirector.sharedDirector().runWithScene(_FeiJi_Scene);// ����� | ||
|
||
CCDirector.sharedDirector().pause(); | ||
} | ||
|
||
@Override | ||
protected void onStop() { | ||
// TODO Auto-generated method stub | ||
super.onStop(); | ||
CCDirector.sharedDirector().end(); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_MenuActivity.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,78 @@ | ||
package skyward.com.myapplication; | ||
|
||
import com.baidu.mobstat.StatService; | ||
|
||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.view.View.OnClickListener; | ||
import android.widget.Button; | ||
|
||
public class FeiJi_MenuActivity extends FeiJi_BaseActivity { | ||
|
||
private Button _FeiJi_Button_New, _FeiJi_Button_Score, | ||
_FeiJi_Button_Exit; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.feiji_menu); | ||
Init(); | ||
} | ||
|
||
private void Init() { | ||
// TODO Auto-generated method stub | ||
_FeiJi_Button_New = (Button) findViewById(R.id.feiji_bu_new); | ||
_FeiJi_Button_Score = (Button) findViewById(R.id.feiji_bu_score); | ||
_FeiJi_Button_Exit = (Button) findViewById(R.id.feiji_bu_exit); | ||
|
||
_FeiJi_Button_New.setOnClickListener(new OnClick()); | ||
_FeiJi_Button_Score.setOnClickListener(new OnClick()); | ||
_FeiJi_Button_Exit.setOnClickListener(new OnClick()); | ||
} | ||
|
||
private class OnClick implements OnClickListener { | ||
|
||
@Override | ||
public void onClick(View v) { | ||
// TODO Auto-generated method stub | ||
switch (v.getId()) { | ||
case R.id.feiji_bu_new: | ||
Intent intent = new Intent(FeiJi_MenuActivity.this, FeiJi_Main.class); | ||
startActivity(intent); | ||
finish(); | ||
break; | ||
|
||
case R.id.feiji_bu_score: | ||
Intent i = new Intent(FeiJi_MenuActivity.this, FeiJi_ScoreActivity.class); | ||
startActivity(i); | ||
break; | ||
|
||
case R.id.feiji_bu_exit: | ||
finish(); | ||
break; | ||
} | ||
} | ||
|
||
} | ||
|
||
public void onResume() { | ||
super.onResume(); | ||
|
||
/** | ||
* ҳ����ʼ��ÿ��Activity�ж���Ҫ��ӣ�����м̳еĸ�Activity���Ѿ�����˸õ��ã���ô��Activity����ز�����ӣ� | ||
* ������StatService.onPageStartһ��onPageEnd��������ʹ�� | ||
*/ | ||
StatService.onResume(this); | ||
} | ||
|
||
public void onPause() { | ||
super.onPause(); | ||
|
||
/** | ||
* ҳ�������ÿ��Activity�ж���Ҫ��ӣ�����м̳еĸ�Activity���Ѿ�����˸õ��ã���ô��Activity����ز�����ӣ� | ||
* ������StatService.onPageStartһ��onPageEnd��������ʹ�� | ||
*/ | ||
StatService.onPause(this); | ||
} | ||
} |
Oops, something went wrong.