0

actually i'm trying to use camera action(like a 'take a photo') in another activity. i mean. i got a activity(CameraPreviewActivity). it shows CameraPreview. if user put the 'draw' button. and then new activity(CanvasActivity) starts. and it show a transparent Canvas. so user can draw on the Camera preview.

all i want to do is make a 'take a picture' button in the CanvasActivity. actually its a different activity so i couldn't make a 'take a picture' button in the CavasActivity. so i use intent.putExtra method to send Camera information. but it's not working at all.

how can i control the CameraPreviewActivity at CanvasActivity. is my idea wrong ? or is there any good way to figure out this problem.

here's my code.

CameraPreviewActivity.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.ex1);
    cameraObject = isCameraAvailiable();
    showCamera = new ShowCamera(this, cameraObject);

    setCameraDisplayOrientation(this, 0, cameraObject);

    FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
    preview.addView(showCamera);

}

public void snapIt(View view) {
    cameraObject.takePicture(null, null, capturedIt);

}

public void drawIt(View view) {

    Intent intent = new Intent(this, DrawingActivity.class);
    startActivity(intent);
}

and it's XML.

    <FrameLayout
        android:id="@+id/camera_preview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </FrameLayout>

    <Button
        android:id="@+id/button_capture"
        android:layout_width="136dp"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:onClick="snapIt"
        android:text="@string/Capture" />

    <Button
        android:id="@+id/button_draw"
        android:layout_width="126dp"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:onClick="drawIt"
        android:text="@string/Draw" />
</FrameLayout>

CanvasActivity.

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.ex2);

     findViewById(R.id.myDrawing).setBackgroundColor
       (getResources().getColor(android.R.color.transparent));  

        FrameLayout layout = (FrameLayout) findViewById(R.id.drawingView);

        mView = new DrawingView(this);

        layout.addView(mView, new LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT));

        init();
    }

and it's XML.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/myDrawing"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:color="#00000000" >

        <FrameLayout
            android:id="@+id/drawingView"
            android:layout_width="318dp"
            android:layout_height="match_parent"
            android:layout_gravity="bottom"
            android:layout_weight="0.99" >
        </FrameLayout>

    </LinearLayout>

thanks a lot !!

nus
  • 5
  • 2

1 Answers1

0

how can i control the CameraPreviewActivity at CanvasActivity

You don't. Allow the user to take a picture by some means on the CanvasActivity, such as:

  • via a button, as you originally proposed
  • via an action bar item
  • via clicking on the preview itself
  • via long-clicking on the preview itself
  • via some other sort of gesture
  • etc.
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • so how can i make the button in CanvasActivity. i mean. the button in the CanvasActivity how it control the camera action. thanks your answer.! – nus Aug 18 '14 at 15:21
  • @nus: "so how can i make the button in CanvasActivity" -- put a button in the layout. Attach an `OnClickListener` to it. Do something for "the camera action" in the `onClick()` method of the `OnClickListener`. – CommonsWare Aug 18 '14 at 15:22
  • i did it. but it returns RunTimeError. i wonder in CanvasActivity. how i can call the camera's function. i'm sorry. i'm newbie at android. Thanks – nus Aug 18 '14 at 15:38
  • i mean. the camera control functions are in CameraPreviewActivity. but i have to control it in CanvasActivity. how can i do this thing. – nus Aug 18 '14 at 15:41
  • @nus: "it returns RunTimeError" -- then you need to debug the error, by [looking at LogCat and examining the Java stack trace](http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this). "i'm newbie at android" -- writing a camera application is **very difficult**. "the camera control functions are in CameraPreviewActivity. but i have to control it in CanvasActivity" -- combine the two into a single activity. – CommonsWare Aug 18 '14 at 15:44
  • thanks. but i tried combine the tow into a single activity. but canvas's back ground color is not transparent. so i changed the plan. anyway is there any way to control camera functions in CanvasActivity. by using intent or some kind of things. if there is no way. i have to combine two. thanks – nus Aug 18 '14 at 15:50
  • @nus: "anyway is there any way to control camera functions in CanvasActivity. by using intent or some kind of things" -- no, because your `Camera` needs to be closed when the other activity comes to the foreground. "i have to combine two" -- yes. – CommonsWare Aug 18 '14 at 15:53