Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How can o draw something on a surface view?
- //this is the preview class
- package my.pack;
- import java.io.IOException;
- import android.content.Context;
- import android.hardware.Camera;
- import android.hardware.Camera.PreviewCallback;
- import android.util.Log;
- import android.view.SurfaceHolder;
- import android.view.SurfaceView;
- class Preview extends SurfaceView implements SurfaceHolder.Callback {
- private static final String TAG = "Preview";
- SurfaceHolder mHolder;
- public Camera camera;
- Preview(Context context) {
- super(context);
- mHolder = getHolder();
- mHolder.addCallback(this);
- //
- mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
- }
- public void surfaceCreated(SurfaceHolder holder) {
- camera = Camera.open();
- try {
- camera.setPreviewDisplay(holder);
- camera.setPreviewCallback(new PreviewCallback() {
- public void onPreviewFrame(byte[] data, Camera camera) { // <11>
- Log.d(TAG, "onPreviewFrame called at: " + System.currentTimeMillis());
- Preview.this.invalidate();
- }
- });
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void surfaceDestroyed(SurfaceHolder holder) {
- camera.stopPreview();
- camera = null;
- }
- public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
- camera.startPreview();
- }
- }
- //this is how i added views on thw preview
- mFrameLayout = (FrameLayout) findViewById(R.id.preview);
- // mLinearLayout = new LinearLayout(this);
- // mLinearLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
- mPreview = new Preview(this);
- sats = getResources().getStringArray(R.array.satellites);
- mMap = new HashMap<Integer,String>();
- mListView = new ListView(this);
- mListView.setLayoutParams(new LayoutParams(400, 250));
- mListView.setFastScrollEnabled(true);
- mListView.setLayoutParams(new LayoutParams(320, 270));
- mTextViewPhoneCoordinates = new TextView(this);
- mTextViewPhoneCoordinates.setGravity(1);
- mTextViewPhoneCoordinates.setTextColor(Color.RED);
- //mToggleButton = (ToggleButton) findViewById(R.id.toggleButton1);
- mArrayList = new ArrayList<String>();
- mArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mArrayList);
- mFrameLayout.addView(mPreview);
- mFrameLayout.addView(mListView);
- mFrameLayout.addView(mTextViewPhoneCoordinates);
Add Comment
Please, Sign In to add comment